Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update Reserve adapter to dynamically fetch TVL #5408

Merged
merged 5 commits into from
Feb 24, 2023
Merged
Changes from all commits
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
60 changes: 45 additions & 15 deletions projects/reserve/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,49 @@
const { sumTokensAndLPsSharedOwners} = require('../helper/unwrapLPs')
const { getLogs } = require('../helper/cache/getLogs')
const { sumTokens2 } = require("../helper/unwrapLPs.js");

const vault = "0xaedcfcdd80573c2a312d15d6bb9d921a01e4fb0f"
const vault = "0xaedcfcdd80573c2a312d15d6bb9d921a01e4fb0f";
const deployerAddress = "0xFd6CC4F251eaE6d02f9F7B41D1e80464D3d2F377";
const rsr = "0x320623b8E4fF03373931769A31Fc52A4E78B5d70";

async function tvl(time, block){
const balances = {}
await sumTokensAndLPsSharedOwners(balances, [
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", //usdc
"0x8e870d67f660d95d5be530380d0ec0bd388289e1", //pax
"0x0000000000085d4780B73119b644AE5ecd22b376", //tusd
"0x4Fabb145d64652a948d72533023f6E7A623C7C53", //busd
].map(t=>[t, false]), [vault], block)
return balances
}
async function tvl(_time, block, _, { api }) {
// First section is for RSV which will soon be deprecated
const ownerTokens = [[[
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", //usdc
"0x8e870d67f660d95d5be530380d0ec0bd388289e1", //pax
"0x0000000000085d4780B73119b644AE5ecd22b376", //tusd
"0x4Fabb145d64652a948d72533023f6E7A623C7C53", //busd
], vault]]
const creationLogs = await getLogs({
api,
target: deployerAddress,
topic: 'RTokenCreated(address,address,address,address,string)',
fromBlock: 16680995,
eventAbi: 'event RTokenCreated(address indexed main, address indexed rToken, address stRSR, address indexed owner, string version)',
onlyArgs: true,
})

const mains = creationLogs.map(i => i.main)
const rTokens = creationLogs.map(i => i.rToken)
const stRsrs = creationLogs.map(i => i.stRsrs)

module.exports={
ethereum: { tvl },
methodology: `Gets the tokens on ${vault}`
const backingManagers = await api.multiCall({ abi: 'address:backingManager', calls: mains })
const basketHandlers = await api.multiCall({ abi: 'address:basketHandler', calls: mains })
const basketRes = await api.multiCall({ abi: "function quote(uint192, uint8) view returns (address[], uint256[])", calls: basketHandlers.map(i => ({ target: i, params: [0, 0] })) })
const basketTokens = await Promise.all(basketRes.map(async ([tokens]) => {
const aTokens = await api.multiCall({ abi: 'address:ATOKEN', calls: tokens })
aTokens.forEach((v, i) => v && ownerTokens.push([[v], tokens[i]]))
return tokens.filter((_, i) => !aTokens[i])
}))
basketTokens.forEach((tokens, i) => {
ownerTokens.push([tokens, rTokens[i]])
// ownerTokens.push([tokens, stRsrs[i]])
ownerTokens.push([tokens, backingManagers[i]])
})

return sumTokens2({ api, ownerTokens, blacklistedTokens: [rsr] })
}

module.exports = {
ethereum: { tvl },
methodology: `Gets the tokens on ${vault}`,
};