-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
125 lines (116 loc) · 2.74 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import axios from "axios";
import {
mainnet,
sepolia,
optimism,
optimismSepolia,
base,
baseSepolia,
polygon,
polygonAmoy,
arbitrum,
arbitrumSepolia,
} from "viem/chains";
const ETHEREUM = mainnet.id;
const OPTIMISM = optimism.id;
const POLYGON = polygon.id;
const BASE = base.id;
const ARBITRUM = arbitrum.id;
const POLYGON_AMOY = polygonAmoy.id;
const BASE_SEPOLIA = baseSepolia.id;
const ARBITRUM_SEPOLIA = arbitrumSepolia.id;
const SEPOLIA = sepolia.id;
const OPTIMISM_SEPOLIA = optimismSepolia.id;
const CHAINS: ChainId[] = [
ETHEREUM,
SEPOLIA,
OPTIMISM,
OPTIMISM_SEPOLIA,
POLYGON,
POLYGON_AMOY,
BASE,
BASE_SEPOLIA,
ARBITRUM,
ARBITRUM_SEPOLIA,
];
type ChainId =
| typeof ETHEREUM
| typeof SEPOLIA
| typeof OPTIMISM
| typeof OPTIMISM_SEPOLIA
| typeof POLYGON
| typeof POLYGON_AMOY
| typeof BASE
| typeof BASE_SEPOLIA
| typeof ARBITRUM
| typeof ARBITRUM_SEPOLIA;
const githubClient = axios.create({
baseURL: "https://api.github.com/repos/trustwallet/assets/git/trees/",
});
interface TreeResponse {
sha: string;
url: string;
tree: Tree[];
}
interface Tree {
path: string;
sha: string;
}
async function getAssets(chainId: ChainId): Promise<string[]> {
console.log("Getting assets for chain", chainId);
function getChainName(chainId: ChainId): string | null {
switch (chainId) {
case ETHEREUM:
return "ethereum";
case OPTIMISM:
return "optimism";
case POLYGON:
return "polygon";
case BASE:
return "base";
case ARBITRUM:
return "arbitrum";
case POLYGON_AMOY:
return null;
case BASE_SEPOLIA:
return null;
case ARBITRUM_SEPOLIA:
return null;
case SEPOLIA:
return "sepolia";
case OPTIMISM_SEPOLIA:
return null;
}
}
const rootDir = await githubClient.get<TreeResponse>("master");
const blockchainsSha = rootDir.data.tree.find(
(item) => item.path === "blockchains"
)?.sha;
if (!blockchainsSha) {
return [];
}
const blockchainsDir = await githubClient.get<TreeResponse>(blockchainsSha);
const chainName = getChainName(chainId);
if (!chainName) {
return [];
}
const chainSha = blockchainsDir.data.tree.find(
(item) => item.path === chainName
)?.sha;
if (!chainSha) {
return [];
}
const chainDir = await githubClient.get<TreeResponse>(chainSha);
const assetsSha = chainDir.data.tree.find(
(item) => item.path === "assets"
)?.sha;
if (!assetsSha) {
return [];
}
const assetsDir = await githubClient.get<TreeResponse>(assetsSha);
return assetsDir.data.tree.map((item) => item.path.toLowerCase());
}
for (const chainId of CHAINS) {
const assets = await getAssets(chainId);
console.log(chainId, assets.length);
}