@@ -6,24 +6,28 @@ const abi = {
66}
77
88const config = {
9- ethereum : { factory : '0x370a449FeBb9411c95bf897021377fe0B7D100c0' }
9+ ethereum : { factory : '0x370a449FeBb9411c95bf897021377fe0B7D100c0' , crvUSD : '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E' }
1010}
1111
1212Object . keys ( config ) . forEach ( chain => {
13- const { factory, } = config [ chain ]
13+ const { factory, crvUSD , } = config [ chain ]
1414 module . exports [ chain ] = {
1515 tvl : async ( api ) => {
1616 const markets = await api . fetchList ( { lengthAbi : abi . market_count , itemAbi : abi . markets , target : factory } )
1717
1818 const lpBalances = await api . multiCall ( { abi : 'erc20:balanceOf' , calls : markets . map ( i => ( { target : i . cryptopool , params : i . amm } ) ) } )
19+ const crvUSDDebt = await api . multiCall ( { abi : 'uint256:get_debt' , calls : markets . map ( i => i . amm ) } )
1920 const lpSupply = await api . multiCall ( { abi : 'erc20:totalSupply' , calls : markets . map ( i => i . cryptopool ) } )
2021 const balanceInLpPools = await api . multiCall ( { abi : 'erc20:balanceOf' , calls : markets . map ( lp => ( { target : lp . asset_token , params : lp . cryptopool } ) ) } )
21- const tokensAndOwners = markets . map ( ( m , i ) => [ m . asset_token , m . amm ] ) // check if any token is retain in amm contract and put in curve lp contract
22+ const crvUSDbalanceInLpPools = await api . multiCall ( { abi : 'erc20:balanceOf' , calls : markets . map ( lp => ( { target : crvUSD , params : lp . cryptopool } ) ) } )
23+ const tokensAndOwners = markets . map ( ( m , ) => [ m . asset_token , m . amm ] ) // check if any token is retain in amm contract and put in curve lp contract
2224
2325
2426 balanceInLpPools . forEach ( ( v , i ) => {
2527 const ratio = lpBalances [ i ] / lpSupply [ i ]
2628 api . add ( markets [ i ] . asset_token , v * ratio )
29+ api . add ( crvUSD , crvUSDbalanceInLpPools [ i ] * ratio )
30+ api . add ( crvUSD , crvUSDDebt [ i ] * - 1 )
2731 } )
2832
2933
@@ -32,4 +36,5 @@ Object.keys(config).forEach(chain => {
3236 }
3337} )
3438
35- module . exports . doublecounted = true // all the tokens end up on curve
39+ module . exports . doublecounted = true // all the tokens end up on curve
40+ module . exports . methodology = `Tvl is the value of LP tokens in curve pools minus the value of borrowed crvUSD tokens`
0 commit comments