|
| 1 | +const { cachedGraphQuery } = require('../helper/cache') |
| 2 | +const ADDRESSES = require('../helper/coreAssets.json') |
| 3 | + |
| 4 | +const GRAPH_URLS = { |
| 5 | + base: { |
| 6 | + uri: 'https://subgraph.satsuma-prod.com/3ed46ea711d3/kasu-finance--314476/kasu-base/api', |
| 7 | + query: `{ |
| 8 | + lendingPools (where:{isStopped: false}){ |
| 9 | + id |
| 10 | + balance |
| 11 | + } |
| 12 | + }` |
| 13 | + }, |
| 14 | + plume: { |
| 15 | + uri: 'https://api.goldsky.com/api/public/project_cm9t3064xeuyn01tgctdo3c17/subgraphs/kasu-plume/prod/gn', |
| 16 | + query: `{ |
| 17 | + lendingPools { |
| 18 | + id |
| 19 | + balance |
| 20 | + } |
| 21 | + }` |
| 22 | + } |
| 23 | +}; |
| 24 | + |
| 25 | +const CHAIN_ASSET = { |
| 26 | + base: { |
| 27 | + asset: ADDRESSES.base.USDC, |
| 28 | + decimals: 6 |
| 29 | + }, |
| 30 | + plume: { |
| 31 | + asset: ADDRESSES.plume_mainnet.pUSD, |
| 32 | + decimals: 6 |
| 33 | + }, |
| 34 | +} |
| 35 | + |
| 36 | +function tvl(chain) { |
| 37 | + return async (api) => { |
| 38 | + const result = await cachedGraphQuery('kasu/' + chain, GRAPH_URLS[chain].uri, GRAPH_URLS[chain].query); |
| 39 | + const tvl = result.lendingPools.map((pool => pool.balance)).reduce((a,b) => a + b * (10 ** CHAIN_ASSET[chain].decimals), 0); |
| 40 | + let externalTvl = 0; |
| 41 | + if (chain === 'base') { |
| 42 | + //add externally managed TVL on Base |
| 43 | + const externalTvlResults = await api.multiCall({ |
| 44 | + abi: 'function externalTVLOfPool(address) view returns (uint256)', |
| 45 | + calls: result.lendingPools.map(pool => ({ |
| 46 | + target: '0x662379FEBb3e4F91400B5f7d4f7F7ce4699F3c9F', |
| 47 | + params: [pool.id], |
| 48 | + })), |
| 49 | + }); |
| 50 | + externalTvl = externalTvlResults.reduce((a, b) => a + Number(b || 0), 0); |
| 51 | + } |
| 52 | + api.addTokens([CHAIN_ASSET[chain].asset], [tvl + externalTvl]); |
| 53 | + return api.getBalances() |
| 54 | + }; |
| 55 | +} |
| 56 | + |
| 57 | +module.exports = { |
| 58 | + methodology: 'Count all assets deposited to Kasu Lending Pools', |
| 59 | + base: { |
| 60 | + tvl: tvl('base'), |
| 61 | + }, |
| 62 | + plume: { |
| 63 | + tvl: tvl('plume'), |
| 64 | + }, |
| 65 | +}; |
0 commit comments