Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions projects/kasu/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { cachedGraphQuery } = require('../helper/cache')
const ADDRESSES = require('../helper/coreAssets.json')

const GRAPH_URLS = {
base: {
uri: 'https://subgraph.satsuma-prod.com/3ed46ea711d3/kasu-finance--314476/kasu-base/api',
query: `{
lendingPools (where:{isStopped: false}){
id
balance
}
}`
},
plume: {
uri: 'https://api.goldsky.com/api/public/project_cm9t3064xeuyn01tgctdo3c17/subgraphs/kasu-plume/prod/gn',
query: `{
lendingPools {
id
balance
}
}`
}
};

const CHAIN_ASSET = {
base: {
asset: ADDRESSES.base.USDC,
decimals: 6
},
plume: {
asset: ADDRESSES.plume_mainnet.pUSD,
decimals: 6
},
}

function offChainPoolTVL(api, poolAddress) {
return api.call({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use api.multiCall() here instead of Promise.all(call()) please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

abi: 'function externalTVLOfPool(address) view returns (uint256)',
target: '0x662379FEBb3e4F91400B5f7d4f7F7ce4699F3c9F',
params: [poolAddress],
});
}

function tvl(chain) {
return async (api) => {
const result = await cachedGraphQuery('kasu/' + chain, GRAPH_URLS[chain].uri, GRAPH_URLS[chain].query);
const tvl = result.lendingPools.map((pool => pool.balance)).reduce((a,b) => a + b * (10 ** CHAIN_ASSET[chain].decimals), 0);
let externalTvl = 0;
if (chain === 'base') {
//add externally managed TVL on Base
const externalTvlResults = await Promise.all(
result.lendingPools.map(async (pool) => Number(await offChainPoolTVL(api, pool.id)))
);
externalTvl = externalTvlResults.reduce((a, b) => a + b || 0, 0);
}
api.addTokens([CHAIN_ASSET[chain].asset], [tvl + externalTvl]);
return api.getBalances()
};
}

module.exports = {
methodology: 'Count all assets deposited to Kasu Lending Pools',
base: {
tvl: tvl('base'),
},
plume: {
tvl: tvl('plume'),
},
};
Loading