Update Spool TVL fetching

adapter is validated by team
This commit is contained in:
Jonathan Chemla
2022-05-09 12:28:14 +02:00
parent dcfb9df58a
commit 44cb93d5de

View File

@@ -2,10 +2,11 @@ const sdk = require("@defillama/sdk")
const { getBlock } = require("../helper/getBlock");
const {sumTokens, unwrapCrv} = require("../helper/unwrapLPs.js")
const {staking} = require("../helper/staking.js")
const abi = require("./abi.json")
const abi = require("./abi.json");
const { sumMultiBalanceOf } = require("@defillama/sdk/build/generalUtil");
const spoolController = '0xe5b126ae9540809488990a9813e1a2732f678047'
const masterSpool = '0x534ef1c63cc191076ea8252f25bbd29d9db6e635'
const spoolController = '0xdd4051c3571c143b989c3227e8eb50983974835c'
const masterSpool = '0xe140bb5f424a53e0687bfc10f6845a5672d7e242'
const SPOOL = '0x40803cea2b2a32bda1be61d3604af6a814e70976'
const SPOOL_staking = '0xc3160C5cc63B6116DD182faA8393d3AD9313e213'
@@ -15,7 +16,7 @@ const chain = 'ethereum'
// TVL is asset holdings of the masterSpool + all capital deployed via each strategy
async function tvl (timestamp, ethBlock, chainBlocks) {
const balances = {}
const block = 14501309 // await getBlock(timestamp, chain, chainBlocks)
const block = await getBlock(timestamp, chain, chainBlocks) // 14501309 //
// Get strategies contract addresses and underlying tokens
let {output: strategies} = await sdk.api.abi.call({
@@ -32,13 +33,13 @@ async function tvl (timestamp, ethBlock, chainBlocks) {
chain,
})
const underlyings = [... new Set(underlyings_nonunique.map(u => u.output))];
console.log('strategies', strategies, 'underlyings', underlyings)
// console.log('strategies', strategies, 'underlyings', underlyings)
// Balances of tokens pending to be deployed in strategies
const tokensAndOwners = underlyings.map(t => [t, masterSpool])
await sumTokens(balances, tokensAndOwners, block, chain)
const {output: underlyingBalances} = await sdk.api.abi.multiCall({
const underlyingBalances = await sdk.api.abi.multiCall({
abi: abi['masterSpool_getStratUnderlying'],
calls: strategies.map(strat => ({
target: masterSpool,
@@ -47,9 +48,13 @@ async function tvl (timestamp, ethBlock, chainBlocks) {
block,
chain,
})
console.log('underlyingBalances', underlyingBalances)
// console.log('underlyingBalances', underlyingBalances)
// Since tvl is deployed to aave, yearn, compound, use masterSpool_getStratUnderlying method
// For simplicity, trick sumMultiBalanceOf into thinking the calls were erc20 balanceOf
underlyingBalances.output.forEach((c, i) => c.input.target = underlyings_nonunique[i].output)
await sumMultiBalanceOf(balances, underlyingBalances)
console.log(`balances `, balances)
// console.log(`balances `, balances)
return balances
}