refactor yield-basis

This commit is contained in:
g1nt0ki
2025-11-05 14:17:58 +01:00
parent beb2355927
commit 0e59dc73f2
2 changed files with 10 additions and 6 deletions

View File

@@ -19,8 +19,7 @@
"biggest-files": "node utils/scripts/sortTopFilesByLines.js", "biggest-files": "node utils/scripts/sortTopFilesByLines.js",
"check-bitcoin-duplicates": "node utils/scripts/checkBTCDupsv2.js", "check-bitcoin-duplicates": "node utils/scripts/checkBTCDupsv2.js",
"string-timestamp": "node utils/scripts/stringTimestamp.js", "string-timestamp": "node utils/scripts/stringTimestamp.js",
"sort-chains": "node projects/helper/getChainList.js", "sort-chains": "node projects/helper/getChainList.js"
"postinstall": "echo 'run \"npm update @defillama/sdk\" if you want lastest sdk changes' "
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",

View File

@@ -6,24 +6,28 @@ const abi = {
} }
const config = { const config = {
ethereum: { factory: '0x370a449FeBb9411c95bf897021377fe0B7D100c0' } ethereum: { factory: '0x370a449FeBb9411c95bf897021377fe0B7D100c0', crvUSD: '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E' }
} }
Object.keys(config).forEach(chain => { Object.keys(config).forEach(chain => {
const { factory, } = config[chain] const { factory, crvUSD, } = config[chain]
module.exports[chain] = { module.exports[chain] = {
tvl: async (api) => { tvl: async (api) => {
const markets = await api.fetchList({ lengthAbi: abi.market_count, itemAbi: abi.markets, target: factory }) const markets = await api.fetchList({ lengthAbi: abi.market_count, itemAbi: abi.markets, target: factory })
const lpBalances = await api.multiCall({ abi: 'erc20:balanceOf', calls: markets.map(i => ({ target: i.cryptopool, params: i.amm })) }) const lpBalances = await api.multiCall({ abi: 'erc20:balanceOf', calls: markets.map(i => ({ target: i.cryptopool, params: i.amm })) })
const crvUSDDebt = await api.multiCall({ abi: 'uint256:get_debt', calls: markets.map(i => i.amm) })
const lpSupply = await api.multiCall({ abi: 'erc20:totalSupply', calls: markets.map(i => i.cryptopool) }) const lpSupply = await api.multiCall({ abi: 'erc20:totalSupply', calls: markets.map(i => i.cryptopool) })
const balanceInLpPools = await api.multiCall({ abi: 'erc20:balanceOf', calls: markets.map(lp => ({ target: lp.asset_token, params: lp.cryptopool })) }) const balanceInLpPools = await api.multiCall({ abi: 'erc20:balanceOf', calls: markets.map(lp => ({ target: lp.asset_token, params: lp.cryptopool })) })
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 const crvUSDbalanceInLpPools = await api.multiCall({ abi: 'erc20:balanceOf', calls: markets.map(lp => ({ target: crvUSD, params: lp.cryptopool })) })
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
balanceInLpPools.forEach((v, i) => { balanceInLpPools.forEach((v, i) => {
const ratio = lpBalances[i] / lpSupply[i] const ratio = lpBalances[i] / lpSupply[i]
api.add(markets[i].asset_token, v * ratio) api.add(markets[i].asset_token, v * ratio)
api.add(crvUSD, crvUSDbalanceInLpPools[i] * ratio)
api.add(crvUSD, crvUSDDebt[i] * -1)
}) })
@@ -32,4 +36,5 @@ Object.keys(config).forEach(chain => {
} }
}) })
module.exports.doublecounted = true // all the tokens end up on curve module.exports.doublecounted = true // all the tokens end up on curve
module.exports.methodology = `Tvl is the value of LP tokens in curve pools minus the value of borrowed crvUSD tokens`