forked from Team-Kujira/kujira.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibc.mjs
54 lines (51 loc) · 1.69 KB
/
ibc.mjs
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
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import fs from "fs";
import { fetchTokens, kujiraQueryClient } from "./lib/cjs/index.js";
import chains from "./src/resources/chains.json" assert { type: "json" };
import tokens from "./src/resources/tokens.json" assert { type: "json" };
const go = async (rpc) => {
const tm = await Tendermint34Client.connect(rpc);
const client = kujiraQueryClient({ client: tm });
return fetchTokens(client)
.then((supply) => {
if (rpc.includes("mars")) {
console.log(supply);
}
return supply.map((s) => {
return (
s.denom &&
!tokens[s.denom] &&
s.denom.startsWith("ibc") &&
client.ibc.transfer
.denomTrace(s.denom.replace("ibc/", ""))
.then(async ({ denomTrace }) => {
console.log(denomTrace);
if (denomTrace && denomTrace.baseDenom) {
tokens[s.denom] = {
path: denomTrace.path,
base_denom: denomTrace.baseDenom,
};
fs.writeFileSync(
"./src/resources/tokens.json",
JSON.stringify(tokens, null, 2)
);
}
return;
})
.catch(() => {})
);
});
})
.catch((err) => {
console.log(rpc);
console.error(err);
});
};
await go("https://test-rpc-kujira.mintthemoon.xyz");
await go("https://rpc.kaiyo.kujira.setten.io");
await go("https://terra-testnet-rpc.polkachu.com");
await Promise.all(
chains.mainnet.map(({ chain_name }) => {
return go(`https://rpc.cosmos.directory/${chain_name}`).catch(() => {});
})
).catch(() => {});