Skip to content

Commit 35bacc9

Browse files
committed
1 parent 7aa69b3 commit 35bacc9

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

projects/latch/index.js

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,26 @@
1-
const BN = require('bn.js');
2-
const sdk = require('@defillama/sdk');
3-
4-
const atUSD = '0xc4af68Dd5b96f0A544c4417407773fEFDc97F58d';
5-
const atETH = '0xc314b8637B05A294Ae9D9C29300d5f667c748baD';
6-
const NAV = '0x5D3920CCC068039E5B6FE680CaB7Aa09fE8E053C';
7-
const abi = 'function getNavByTimestamp(address,uint48) view returns (uint256 , uint48 )';
1+
const { sumTokens2 } = require('../helper/unwrapLPs');
82

93
const tvl = async (api) => {
10-
const chainEth = 'ethereum';
11-
const chainGravity = 'gravity';
12-
13-
const ethApi = new sdk.ChainApi({ chain: chainEth, timestamp: api.timestamp });
14-
const gravityApi = new sdk.ChainApi({ chain: chainGravity });
15-
16-
await Promise.all([ethApi.getBlock(), gravityApi.getBlock()]);
17-
18-
const [usdNav, ethNav, usdtSupply, ethSupply] = await Promise.all([
19-
ethApi.call({ target: NAV, params: [atUSD, api.timestamp], abi }),
20-
ethApi.call({ target: NAV, params: [atETH, api.timestamp], abi }),
21-
gravityApi.call({ abi: 'erc20:totalSupply', target: atUSD }),
22-
gravityApi.call({ abi: 'erc20:totalSupply', target: atETH }),
23-
]);
24-
25-
// Convert results to BN
26-
const usdNavBN = new BN(usdNav[0].toString());
27-
const ethNavBN = new BN(ethNav[0].toString());
28-
const usdtSupplyBN = new BN(usdtSupply.toString());
29-
const ethSupplyBN = new BN(ethSupply.toString());
30-
31-
// Perform calculations
32-
const usdtResult = usdtSupplyBN.mul(usdNavBN).div(new BN('10').pow(new BN(30)));
33-
const ethResult = ethSupplyBN.mul(ethNavBN).div(new BN('10').pow(new BN(18)));
34-
35-
// Add results to API
36-
api.add('0xdac17f958d2ee523a2206206994597c13d831ec7', usdtResult.toString());
37-
api.add('0x0000000000000000000000000000000000000000', ethResult.toString());
4+
const depositPools = [
5+
'0xFE606EEc8Eb8e6Ad8E8654968a15650F5331a023',
6+
'0x7cC08f23a6E8222c86a62fCE3d4d252dd1b8f90C',
7+
]
8+
9+
const proxies = [
10+
'0xa116b4680b52973426B6D2a92DcC972b8DbcB46F',
11+
]
12+
13+
const tokens = await api.multiCall({ abi: 'address:ASSET_TOKEN', calls: depositPools })
14+
const stakingPools = await api.multiCall({ abi: 'address:treasury', calls: depositPools })
15+
const nextTreasuries = await api.multiCall({ abi: 'address:nextTreasury', calls: stakingPools })
16+
const withdrawPools = await api.multiCall({ abi: 'address:withdrawPool', calls: stakingPools })
17+
18+
await sumTokens2({ api, tokens, owners: depositPools.concat(withdrawPools), })
19+
return sumTokens2({ api, tokens, owners: nextTreasuries.concat(stakingPools).concat(proxies), fetchCoValentTokens: true, tokenConfig: { onlyWhitelisted: false, } })
3820
};
3921

4022
module.exports = {
41-
ethereum: {
42-
tvl: tvl,
43-
},
23+
ethereum: {
24+
tvl,
25+
},
4426
};

0 commit comments

Comments
 (0)