Skip to content

Commit 968f6c7

Browse files
committed
history update
0 parents  commit 968f6c7

File tree

14 files changed

+372
-0
lines changed

14 files changed

+372
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
.env

bun.lockb

3.06 KB
Binary file not shown.

chains.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"eth": { "name": "Ethereum", "color": "#131313" },
3+
"bsc": { "name": "Binance Smart Chain", "color": "#f0b90a" },
4+
"ada": { "name": "Cardano", "color": "#274eba" },
5+
"algo": { "name": "Algorand", "color": "#201f21" },
6+
"ark": { "name": "Ark", "color": "#d20202" },
7+
"atom": { "name": "Cosmos", "color": "#2e3148" },
8+
"bnb": { "name": "BNB", "color": "#f0b90a" },
9+
"bcd": { "name": "Bitcoin Diamond", "color": "#fcc339" },
10+
"bch": { "name": "Bitcoin Cash", "color": "#8cc351" },
11+
"beam": { "name": "Beam", "color": "#ff4b4b" },
12+
"btc": { "name": "Bitcoin", "color": "#f6931a" },
13+
"btg": { "name": "Bitcoin Gold", "color": "#eba809" },
14+
"trx": { "name": "TRON", "color": "#ff0013" },
15+
"dash": { "name": "Dash", "color": "#008ce7" },
16+
"dcr": { "name": "Decred", "color": "#296fff" },
17+
"dgb": { "name": "DigiByte", "color": "#0069d2" },
18+
"divi": { "name": "Divi", "color": "#ec2050" },
19+
"doge": { "name": "Dogecoin", "color": "#b59b31" },
20+
"dot": { "name": "Polkadot", "color": "#e6007a" },
21+
"egld": { "name": "MultiversX", "color": "#010101" },
22+
"eos": { "name": "EOS", "color": "#000000" },
23+
"etc": { "name": "Ethereum Classic", "color": "#0a8412" },
24+
"ethw": { "name": "EthereumPoW", "color": "#677ef0" },
25+
"fil": { "name": "Filecoin", "color": "#0090ff" },
26+
"firo": { "name": "Firo", "color": "#9a1c2e" },
27+
"ftm": { "name": "Fantom", "color": "#1968ff" },
28+
"neo": { "name": "NEO", "color": "#00e599" },
29+
"grs": { "name": "Groestlcoin", "color": "#017fa0" },
30+
"hbar": { "name": "Hedera", "color": "#000000" },
31+
"icx": { "name": "ICON", "color": "#48bed1" },
32+
"iota": { "name": "IOTA", "color": "#000000" },
33+
"iotx": { "name": "IoTeX", "color": "#161f26" },
34+
"klay": { "name": "Klaytn", "color": "#d60b3f" },
35+
"kmd": { "name": "Komodo", "color": "#2b667f" },
36+
"lsk": { "name": "Lisk", "color": "#3f70f4" },
37+
"ltc": { "name": "Litecoin", "color": "#345d9c" },
38+
"luna": { "name": "Terra", "color": "#e98046" },
39+
"lunc": { "name": "Terra Classic", "color": "#fed73d" },
40+
"matic": { "name": "Polygon", "color": "#7d3ce2" },
41+
"nano": { "name": "Nano", "color": "#1e9ce9" },
42+
"near": { "name": "NEAR Protocol", "color": "#010101" },
43+
"one": { "name": "Harmony", "color": "#6cdee7" },
44+
"ont": { "name": "Ontology", "color": "#4da8fe" },
45+
"qtum": { "name": "Qtum", "color": "#0745f7" },
46+
"rvn": { "name": "Ravencoin", "color": "#384182" },
47+
"sol": { "name": "Solana", "color": "#6c76e3" },
48+
"strax": { "name": "Stratis", "color": "#85b9dc" },
49+
"sxp": { "name": "Swipe", "color": "#f54a27" },
50+
"theta": { "name": "Theta", "color": "#2bb7e5" },
51+
"ton": { "name": "TON Crystal", "color": "#0088cb" },
52+
"waves": { "name": "Waves", "color": "#0154fe" },
53+
"xdc": { "name": "XDC Network", "color": "#244b81" },
54+
"xem": { "name": "NEM", "color": "#24af9f" },
55+
"xlm": { "name": "Stellar", "color": "#24af9f" },
56+
"xmr": { "name": "Monero", "color": "#fa6800" },
57+
"xrp": { "name": "XRP", "color": "#fa6800" },
58+
"xtz": { "name": "Tezos", "color": "#0162ff" },
59+
"xvg": { "name": "Verge", "color": "#010202" },
60+
"xym": { "name": "Symbol", "color": "#6d00da" },
61+
"zec": { "name": "Zcash", "color": "#ecb144" },
62+
"zen": { "name": "Horizen", "color": "#17b2c3" },
63+
"zil": { "name": "Zilliqa", "color": "#2e969a" },
64+
"apt": { "name": "Aptos", "color": "#000000" },
65+
"arbitrum": { "name": "Arbitrum", "color": "#2a405e" },
66+
"base": { "name": "Base", "color": "#1552f0" },
67+
"brisemainnet": { "name": "Bitgert", "color": "#8437fa" },
68+
"bsv": { "name": "Bitcoin SV", "color": "#eab300" },
69+
"cro": { "name": "Cronos", "color": "#2b3865" },
70+
"cspr": { "name": "Casper", "color": "#ff2c2e" },
71+
"celo": { "name": "Celo", "color": "#22230b" },
72+
"epic": { "name": "Epic Cash", "color": "#111418" },
73+
"avaxc": { "name": "Avalanche C-Chain", "color": "#e84141" },
74+
"cchain": { "name": "Avalanche C-Chain", "color": "#e84141" },
75+
"xchain": { "name": "Avalanche C-Chain", "color": "#e84141" },
76+
"lna": { "name": "Linea", "color": "#000000" },
77+
"ftn": { "name": "Fastex", "color": "#a60163" },
78+
"kas": { "name": "Kaspa", "color": "#70c9bb" },
79+
"klvmainnet": { "name": "Klever", "color": "#bf41ef" },
80+
"pivx": { "name": "PIVX", "color": "#412965" },
81+
"pulse": { "name": "PulseChain", "color": "#7265fd" },
82+
"rune": { "name": "THORChain", "color": "#19e3d1" },
83+
"sei": { "name": "Sei", "color": "#c73748" },
84+
"sys": { "name": "Syscoin", "color": "#1e5eff" },
85+
"kcc": { "name": "KCC", "color": "#43e6af" },
86+
"op": { "name": "Optimism", "color": "#fe0521" },
87+
"kavaevm": { "name": "Kava", "color": "#ff554f" },
88+
"xec": { "name": "eCash", "color": "#0b63b7" },
89+
"zksync": { "name": "zkSync", "color": "#000000" }
90+
}

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "@better-giving/assets",
3+
"version": "1.0.8",
4+
"description": "",
5+
"keywords": [],
6+
"author": "",
7+
"license": "ISC",
8+
"scripts": {
9+
"generate-tokens": "rm ./tokens/* && bun run ./scripts/build.ts"
10+
},
11+
"devDependencies": {
12+
"@types/bun": "1.1.6",
13+
"typescript": "5.5.4"
14+
}
15+
}

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
publishing
3+
1. npm login
4+
2. npm publish --access public

scripts/build.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { type RawToken } from "../types";
2+
import existing_chains from "../chains.json";
3+
import {
4+
process_tokens,
5+
to_processed,
6+
token_filter,
7+
write_json,
8+
} from "./helpers";
9+
10+
const base_url = process.env.api_base_url;
11+
12+
const tokens: RawToken[] = await fetch(
13+
`${base_url}/v1/crypto/v1/full-currencies`
14+
)
15+
.then((res) => res.json())
16+
.then((data: any) => data.currencies);
17+
18+
const test_tokens: RawToken[] = await fetch(
19+
`${base_url}/staging/crypto/v1/full-currencies`
20+
)
21+
.then((res) => res.json())
22+
.then((data: any) => data.currencies);
23+
24+
const filtered_tokens = tokens.filter(token_filter);
25+
const filtered_test_tokens = test_tokens.filter(token_filter);
26+
27+
/// prod tokens override test tokens in maps ///
28+
const all_filtered_tokens = filtered_test_tokens.concat(filtered_tokens);
29+
30+
/// CHECK FOR NEW CHAINS ///
31+
const new_chains: string[] = [];
32+
for (const token of all_filtered_tokens) {
33+
if (!token.network) continue;
34+
35+
if (!(existing_chains as any)[token.network]) {
36+
new_chains.push(token.network);
37+
}
38+
}
39+
40+
if (new_chains.length > 0) {
41+
console.log({ new_chains });
42+
throw "New chains found. addt them before proceeding";
43+
}
44+
45+
/// generate tokens list ///
46+
const id1 = process_tokens(filtered_tokens, "./tokens/prod.json");
47+
const id2 = process_tokens(filtered_test_tokens, "./tokens/test.json");
48+
49+
/// generate tokens map ///
50+
const tokens_map = all_filtered_tokens.reduce((prev, curr) => {
51+
prev[curr.code] = to_processed(curr);
52+
return prev;
53+
}, {} as any);
54+
55+
const id3 = write_json(tokens_map, "./tokens/map.json");
56+
57+
// also write hashes to monitor change
58+
write_json([id1, id2, id3], "./tokens/hash.json");

scripts/helpers.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import fs from "fs";
2+
import crypto from "crypto";
3+
import type { Ensure, RawToken, Token } from "../types";
4+
import chains from "../chains.json";
5+
6+
type Filtered = Ensure<RawToken, "network">;
7+
8+
export const token_filter = (token: RawToken): token is Filtered => {
9+
return token.enable && !!token.network;
10+
};
11+
12+
export function write_json(json: object, file_path: string) {
13+
const str = JSON.stringify(json);
14+
const hash = crypto.createHash("sha256").update(str).digest("hex");
15+
fs.writeFileSync(file_path, str);
16+
console.log({ file_path });
17+
const file_name = file_path.split("/").at(-1)?.split(".")[0];
18+
return `${file_name}:${hash}`;
19+
}
20+
21+
export const to_processed = (t: Filtered): Token => {
22+
return {
23+
id: t.id.toString(),
24+
code: t.code,
25+
name: t.name,
26+
precision: t.precision,
27+
logo: t.logo_url,
28+
network: t.network,
29+
color: (chains as any)[t.network].color,
30+
cg_id: t.cg_id,
31+
};
32+
};
33+
34+
export function process_tokens(tokens: RawToken[], file_path: string) {
35+
const processed = tokens
36+
.filter(token_filter)
37+
.toSorted((a, b) => a.priority - b.priority)
38+
.map<Token>(to_processed);
39+
40+
return write_json(processed, file_path);
41+
}

tokens.d.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
declare module "@better-giving/assets/tokens/map.json" {
2+
const map: {
3+
[token_symbol: string]: import("./types.ts").ProcessedToken;
4+
};
5+
export default map;
6+
}
7+
declare module "@better-giving/assets/tokens/prod.json" {
8+
const tokens: import("./types.ts").ProcessedToken[];
9+
export default tokens;
10+
}
11+
declare module "@better-giving/assets/tokens/test.json" {
12+
const tokens: import("./types.ts").ProcessedToken[];
13+
export default tokens;
14+
}
15+
16+
declare module "@better-giving/assets/chains.json" {
17+
const map: {
18+
[network_id: string]: import("./types.ts").ChainInfo;
19+
};
20+
export default map;
21+
}

tokens/hash.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["prod:f9f8c307f6cd15befad3b30307f46e4db08bd45c86a970c583f42ed3da762ff1","test:8afbbccec043b72f7ac5eefa16c2cee5c8b621b6a1ff4e1551140752091cec66","map:53fb6ae70667eb0b39669d3874d195aa0039dbfdea1209583cafd02e8087285e"]

tokens/map.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)