-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch-pools.js
99 lines (89 loc) · 3.02 KB
/
fetch-pools.js
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
const { providers } = require('ethers');
const { core, truncate } = require('./dist');
const sdk = require('./dist');
const { config } = require('dotenv');
const { writeJson } = require('fs-extra');
config();
async function main() {
const poolsList = await getPoolsList();
const defaultPool = await getDefaultPool(poolsList);
await writeJson('./src/default_pools.json', defaultPool, { spaces: 2 });
await writeJson('./dist/default_pools.json', defaultPool, { spaces: 2 });
await writeJson('./src/pools.json', poolsList, { spaces: 2 });
await writeJson('./dist/pools.json', poolsList, { spaces: 2 });
}
main().catch(console.error);
async function getDefaultPool(poolsList) {
const defaultPool = {};
for (const [chainName] of Object.entries(sdk.chainIds)) {
const defaultPoolForChain = poolsList[chainName]?.[0];
if (defaultPoolForChain) {
defaultPool[chainName] = defaultPoolForChain;
}
}
return defaultPool;
}
async function getPoolsList() {
const poolsList = {};
for (const [chainName] of Object.entries(sdk.chainIds)) {
let poolsListForChain = [];
const provider = sdk.getProvider(chainName);
if (provider) {
try {
const { rageTradeFactory } = await core.getContractsSync(
chainName,
provider
);
const events = await rageTradeFactory.queryFilter(
rageTradeFactory.filters.PoolInitialized()
);
const poolContracts = events.map(
({ blockNumber, args: { vToken, vPool, vPoolWrapper } }) => {
const signerOrProvider =
rageTradeFactory.signer ?? rageTradeFactory.provider;
return {
vToken: sdk.typechain.VToken__factory.connect(
vToken,
signerOrProvider
),
vPool: sdk.typechain.IUniswapV3Pool__factory.connect(
vPool,
signerOrProvider
),
vPoolWrapper: sdk.typechain.VPoolWrapper__factory.connect(
vPoolWrapper,
signerOrProvider
),
creationBlockNumber: blockNumber,
};
}
);
poolsListForChain = await Promise.all(
poolContracts.map(
async ({ vToken, vPool, vPoolWrapper, creationBlockNumber }) => ({
poolId: truncate(vToken.address),
name: await vToken.name(),
symbol: await vToken.symbol(),
decimals: await vToken.decimals(),
vTokenAddress: vToken.address,
vPoolAddress: vPool.address,
vPoolWrapperAddress: vPoolWrapper.address,
creationBlockNumber,
})
)
);
} catch (e) {
if (!e.message.includes('does not contain the deployment')) {
console.error(e);
}
}
}
poolsList[chainName] = poolsListForChain;
}
return poolsList;
}
function getArbiscanProvider(chainName) {
try {
return new sdk.ArbiscanProvider(chainName, process.env.ARBISCAN_KEY);
} catch {}
}