forked from Team-Kujira/kujira.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontracts.mjs
116 lines (112 loc) · 3.19 KB
/
contracts.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
113
114
115
116
import { HttpBatchClient, Tendermint34Client } from "@cosmjs/tendermint-rpc";
import fs from "fs";
import { MAINNET, RPCS, TESTNET, kujiraQueryClient } from "./lib/cjs/index.js";
const IDS = {
[MAINNET]: {
fin: [63, 56, 92, 94],
bow: [36, 46, 54],
bowStaking: [61, 88],
orca: [59],
uskMarket: [73],
uskMarginSwap: [72, 74, 87],
uskMarginLimit: [],
calc: [104],
ghostVault: [106],
ghostMarket: [],
pilot: [95],
},
[TESTNET]: {
fin: [6, 7, 30, 31, 88, 129, 860, 1367, 1397, 1398],
bow: [308, 468, 644, 858],
bowStaking: [439, 855],
orca: [994, 1577],
uskMarket: [66, 136],
uskMarginSwap: [131, 133],
uskMarginLimit: [1271, 1272],
calc: [1273, 1387],
ghostVault: [1634],
ghostMarket: [1593, 1594, 1616],
pilot: [1476],
},
};
const res = await Promise.all(
Object.entries(IDS).map(async ([chain, protocols]) => {
const rpc = RPCS[chain][1];
const tm = await Tendermint34Client.create(
new HttpBatchClient(rpc, {
dispatchInterval: 100,
batchSizeLimit: 200,
})
);
const client = kujiraQueryClient({ client: tm });
return {
chain,
protocols: await Promise.all(
Object.entries(protocols).map(async ([protocol, ids]) => {
return {
protocol,
ids: await Promise.all(
ids.map(async (id) => ({
id,
contracts: await client.wasm
.listContractsByCodeId(id)
.then((x) =>
Promise.all(
x.contracts.map(async (address) => ({
address,
config: await client.wasm
.queryContractSmart(address, {
config: {},
})
.catch(() => null),
pairs:
protocol === "calc" &&
(await client.wasm
.queryContractSmart(address, {
get_pairs: {},
})
.then(({ pairs }) => pairs)),
markets:
protocol === "ghostVault" &&
(await client.wasm
.queryContractSmart(address, {
markets: {},
})
.then(({ markets }) => markets)
.catch((err) => {
console.log(err);
return null;
})),
}))
)
),
}))
),
};
})
),
};
})
);
const flattened = res.reduce(
(a, m) => ({
...a,
[m.chain]: m.protocols.reduce(
(b, n) => ({
...b,
[n.protocol]: n.ids.flatMap((id) =>
id.contracts.map((contract) => ({
id: id.id,
...contract,
}))
),
}),
{}
),
}),
{}
);
fs.writeFileSync(
"./src/resources/contracts.json",
JSON.stringify(flattened, null, 2)
);