|
1 |
| -const {sumTokens2 } = require("../helper/unwrapLPs.js") |
2 |
| -const { |
3 |
| - config, |
4 |
| - } = require("./config.js"); |
5 |
| - |
6 |
| -module.exports = { |
7 |
| - methodology: `TVL is retrieved on-chain by getting the total assets managed by the Parallelizer contracts`, |
8 |
| -}; |
9 |
| - |
10 |
| -async function tvl(api) { |
11 |
| - const chainConfig = config[api.chain] |
12 |
| - const ownerTokens = [] |
13 |
| - if(chainConfig.vaultCore){ |
14 |
| - const v2TokensAndOwners = await getOwnerTokensV2(api, chainConfig.vaultCore) |
15 |
| - ownerTokens.push(...v2TokensAndOwners) |
| 1 | +const config = { |
| 2 | + ethereum: |
| 3 | + { |
| 4 | + vaultCore: [ |
| 5 | + '0x173AE6283A717b6cdD5491EAc5F82C082A8c674b', //PAR |
| 6 | + '0xE26348D30694aa7E879b9335252362Df3df93204', //paUSD |
| 7 | + ], |
| 8 | + }, |
| 9 | + polygon: { |
| 10 | + vaultCore: [ |
| 11 | + '0x0a9202C6417A7B6B166e7F7fE2719b09261b400f', //PAR |
| 12 | + '0xcABAbC1Feb7C5298F69B635099D75975aD5E6e5f', //paUSD |
| 13 | + ], |
| 14 | + }, |
| 15 | + fantom: { |
| 16 | + vaultCore: ['0xF6aBf8a89b3dA7C254bb3207e2eBA9810bc51f58'], //PAR |
16 | 17 | }
|
17 |
| - if(chainConfig.parallelizer){ |
18 |
| - const v3TokensAndOwners = await getOwnerTokensV3(api, chainConfig.parallelizer) |
19 |
| - ownerTokens.push(v3TokensAndOwners) |
20 |
| - } |
21 |
| - return sumTokens2({ api, ownerTokens }) |
22 |
| -} |
23 |
| - |
24 |
| -async function getOwnerTokensV2(api, vaultCore){ |
25 |
| - const ownerTokens = [] |
26 |
| - for (const vault of vaultCore) { |
27 |
| - const addressProvider = await api.call({ abi: 'address:a', target: vault}) |
28 |
| - const config = await api.call({ abi: 'address:config', target: addressProvider}) |
29 |
| - const tokenConfig = await api.fetchList({ lengthAbi: 'numCollateralConfigs', itemAbi: "function collateralConfigs(uint256 _id) view returns ((address collateralType, uint256 debtLimit, uint256 liquidationRatio, uint256 minCollateralRatio, uint256 borrowRate, uint256 originationFee, uint256 liquidationBonus, uint256 liquidationFee))", target: config}) |
30 |
| - const tokens = tokenConfig.map(t => t.collateralType) |
31 |
| - ownerTokens.push([tokens, vault]) |
32 |
| - } |
33 |
| - return ownerTokens |
34 |
| -} |
35 |
| - |
36 |
| -async function getOwnerTokensV3(api, parallelizer){ |
37 |
| - const {address: parallelizerAddress, fromBlock} = parallelizer |
38 |
| - const collaterals = await api.call({ abi: 'address[]:getCollateralList', target: parallelizerAddress, block: fromBlock}) |
39 |
| - return [collaterals, parallelizerAddress] |
40 |
| -} |
41 |
| - |
42 |
| - |
43 |
| -Object.keys(config).forEach(chain => { |
| 18 | + } |
| 19 | + |
| 20 | + |
| 21 | + Object.keys(config).forEach(chain => { |
| 22 | + const { vaultCore } = config[chain] |
44 | 23 | module.exports[chain] = { tvl }
|
45 |
| -}); |
| 24 | + |
| 25 | + async function tvl(api) { |
| 26 | + const ownerTokens = [] |
| 27 | + for (const vault of vaultCore) { |
| 28 | + const addressProvider = await api.call({ abi: 'address:a', target: vault}) |
| 29 | + const config = await api.call({ abi: 'address:config', target: addressProvider}) |
| 30 | + const tokenConfig = await api.fetchList({ lengthAbi: 'numCollateralConfigs', itemAbi: "function collateralConfigs(uint256 _id) view returns ((address collateralType, uint256 debtLimit, uint256 liquidationRatio, uint256 minCollateralRatio, uint256 borrowRate, uint256 originationFee, uint256 liquidationBonus, uint256 liquidationFee))", target: config}) |
| 31 | + const tokens = tokenConfig.map(t => t.collateralType) |
| 32 | + ownerTokens.push([tokens, vault]) |
| 33 | + } |
| 34 | + return api.sumTokens({ ownerTokens }) |
| 35 | + } |
| 36 | + }) |
0 commit comments