1
1
const ADDRESSES = require ( '../helper/coreAssets.json' )
2
2
3
+ const nullAddress = ADDRESSES . null
4
+
3
5
const CONFIG = {
4
6
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 }
7
12
} ,
8
13
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
+ ] ,
10
18
assets : { USDC : ADDRESSES . base . USDC }
11
19
} ,
12
20
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
+ ] ,
14
25
assets : { USDC : ADDRESSES . arbitrum . USDC_CIRCLE }
15
26
} ,
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
+ } ,
16
45
}
17
46
18
47
const abis = {
@@ -21,20 +50,46 @@ const abis = {
21
50
} ;
22
51
23
52
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)'
25
55
}
26
56
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 = [ ]
31
61
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
+
32
86
const tvl = async ( api ) => {
33
87
const chain = api . chain
34
88
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 )
38
93
await api . erc4626Sum ( { calls : vaults , tokenAbi : 'address:asset' , balanceAbi : 'uint256:totalAssets' } )
39
94
}
40
95
0 commit comments