forked from Team-Kujira/kujira.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibc.mjs
112 lines (100 loc) · 3.21 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
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
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { ClientState } from "cosmjs-types/ibc/lightclients/tendermint/v1/tendermint.js";
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 runConnections = async (rpc) => {
const tm = await Tendermint34Client.connect(rpc);
const client = kujiraQueryClient({ client: tm });
const channels = await client.ibc.channel
.allChannels()
.then((x) => x.channels);
const connections = await client.ibc.connection.allConnections().then((x) =>
Promise.all(
x.connections.map(async (c) => ({
...c,
clientState: await client.ibc.connection
.clientState(c.id)
.then((x) =>
ClientState.decode(x.identifiedClientState.clientState.value)
),
}))
)
);
return { channels, connections };
};
const runTokens = async (rpc) => {
const tm = await Tendermint34Client.connect(rpc);
const client = kujiraQueryClient({ client: tm });
return fetchTokens(client)
.then((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 }) => {
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 runTokens("https://kujira-testnet-rpc.polkachu.com");
// await runTokens("https://rpc-kujira.mintthemoon.xyz");
const testnet = await runConnections("https://kujira-testnet-rpc.polkachu.com");
const mainnet = await runConnections("https://rpc-kujira.mintthemoon.xyz");
// fs.writeFileSync(
// "./src/resources/channels.json",
// JSON.stringify(
// { testnet: testnet.channels, mainnet: mainnet.channels },
// null,
// 2
// )
// );
fs.writeFileSync(
"./src/resources/connections.json",
JSON.stringify(
{ testnet: testnet.connections, mainnet: mainnet.connections },
(a, x) => (typeof x === "bigint" ? x.toString() : x),
2
)
);
await runTokens("https://terra-testnet-rpc.polkachu.com");
await Promise.all(
chains.mainnet.map(({ chain_name }) => {
return runTokens(`https://rpc.cosmos.directory/${chain_name}`).catch(
() => {}
);
})
).catch(() => {});
const res = await fetch(
"https://rest.cosmos.directory/osmosis/osmosis/gamm/v1beta1/pools?pagination.limit=100000"
);
const { pools } = await res.json();
fs.writeFileSync(
"./src/resources/osmosis.json",
JSON.stringify(
pools.map((p) => ({ id: p.id, address: p.address, assets: p.pool_assets })),
null,
2
)
);