Skip to content

Commit f74b539

Browse files
committed
update v3 pre launch
1 parent c9c293f commit f74b539

File tree

1 file changed

+67
-12
lines changed

1 file changed

+67
-12
lines changed

projects/centrifuge/index.js

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,47 @@
11
const ADDRESSES = require('../helper/coreAssets.json')
22

3+
const nullAddress = ADDRESSES.null
4+
35
const CONFIG = {
46
ethereum: {
5-
factory: { START_BLOCK: 20432393, TOKEN_FACTORY: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' },
6-
assets: { USDC: ADDRESSES.ethereum.USDC },
7+
factories : [
8+
{ START_BLOCK: 20432393, TOKEN_FACTORY_V2: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' }, // v2
9+
{ START_BLOCK: 22924277, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
10+
],
11+
assets: { USDC: ADDRESSES.ethereum.USDC }
712
},
813
base: {
9-
factory: { START_BLOCK: 17854404, TOKEN_FACTORY: '0x7f192F34499DdB2bE06c4754CFf2a21c4B056994' },
14+
factories : [
15+
{ START_BLOCK: 17854404, TOKEN_FACTORY_V2: '0x7f192F34499DdB2bE06c4754CFf2a21c4B056994' }, // v2
16+
{ START_BLOCK: 32901390, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
17+
],
1018
assets: { USDC: ADDRESSES.base.USDC }
1119
},
1220
arbitrum: {
13-
factory: { START_BLOCK: 238245701, TOKEN_FACTORY: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' },
21+
factories : [
22+
{ START_BLOCK: 238245701, TOKEN_FACTORY_V2: '0x91808B5E2F6d7483D41A681034D7c9DbB64B9E29' }, // v2
23+
{ START_BLOCK: 357984300, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
24+
],
1425
assets: { USDC: ADDRESSES.arbitrum.USDC_CIRCLE }
1526
},
27+
avax: {
28+
factories : [
29+
{ START_BLOCK: 65493376, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
30+
],
31+
assets: { USDC: ADDRESSES.avax.USDC }
32+
},
33+
bsc: {
34+
factories : [
35+
{ START_BLOCK: 54801665, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
36+
],
37+
assets: { USDC: ADDRESSES.bsc.USDC }
38+
},
39+
plume_mainnet: {
40+
factories : [
41+
{ START_BLOCK: 15715268, TOKEN_FACTORY_V3: '0xd30Da1d7F964E5f6C2D9fE2AAA97517F6B23FA2B' }, // v3
42+
],
43+
assets: { USDC: ADDRESSES.plume_mainnet.USDC_e }
44+
},
1645
}
1746

1847
const abis = {
@@ -21,20 +50,46 @@ const abis = {
2150
};
2251

2352
const eventAbis = {
24-
deployTranches: 'event DeployTranche(uint64 indexed poolId, bytes16 indexed trancheId, address indexed tranche)'
53+
deployTranches: 'event DeployTranche(uint64 indexed poolId, bytes16 indexed trancheId, address indexed tranche)',
54+
addShareClass: 'event AddShareClass(uint64 indexed poolId, bytes16 indexed scId, address token)'
2555
}
2656

27-
const getTokens = async (api, block, START_BLOCK, TOKEN_FACTORY) => {
28-
const tranches = await api.getLogs({ target: TOKEN_FACTORY, fromBlock: START_BLOCK, toBlock: block, eventAbi: eventAbis.deployTranches, onlyArgs: true })
29-
return tranches.map(({ tranche }) => tranche)
30-
}
57+
const getTokens = async (api, block, factories) => {
58+
const logs = await Promise.all(
59+
factories.map(async (factory) => {
60+
let allTranches = []
3161

62+
if (factory.TOKEN_FACTORY_V2) {
63+
const tranches = await api.getLogs({ target: factory.TOKEN_FACTORY_V2, fromBlock: factory.START_BLOCK, toBlock: block, eventAbi: eventAbis.deployTranches, onlyArgs: true })
64+
allTranches.push(...tranches.map(({ tranche }) => tranche))
65+
}
66+
67+
if (factory.TOKEN_FACTORY_V3) {
68+
const [tranches, shareClasses] = await Promise.all([
69+
api.getLogs({ target: factory.TOKEN_FACTORY_V3, fromBlock: factory.START_BLOCK, toBlock: block, eventAbi: eventAbis.deployTranches, onlyArgs: true }),
70+
api.getLogs({ target: factory.TOKEN_FACTORY_V3, fromBlock: factory.START_BLOCK, toBlock: block, eventAbi: eventAbis.addShareClass, onlyArgs: true })
71+
])
72+
73+
allTranches.push(
74+
...tranches.map(({ tranche }) => tranche),
75+
...shareClasses.map(({ token }) => token)
76+
)
77+
}
78+
79+
return allTranches
80+
})
81+
)
82+
83+
return [...new Set(logs.flat())]
84+
}
85+
3286
const tvl = async (api) => {
3387
const chain = api.chain
3488
const block = await api.getBlock() - 100
35-
const { factory: { START_BLOCK, TOKEN_FACTORY }, assets: { USDC } } = CONFIG[chain]
36-
const tokens = await getTokens(api, block, START_BLOCK, TOKEN_FACTORY)
37-
const vaults = await api.multiCall({ calls: tokens.map((t) => ({ target: t, params: [USDC] })), abi: abis.getVault })
89+
const { factories, assets: { USDC } } = CONFIG[chain]
90+
const tokens = await getTokens(api, block, factories)
91+
if (!tokens) return;
92+
const vaults = (await api.multiCall({ calls: tokens.map((t) => ({ target: t, params: [USDC] })), abi: abis.getVault })).filter(addr => addr.toLowerCase() !== nullAddress)
3893
await api.erc4626Sum({ calls: vaults, tokenAbi: 'address:asset', balanceAbi: 'uint256:totalAssets' })
3994
}
4095

0 commit comments

Comments
 (0)