Skip to content

Commit

Permalink
update tokemak to include autopilot tvl (#11658)
Browse files Browse the repository at this point in the history
Co-authored-by: g1nt0ki <[email protected]>
  • Loading branch information
codenutt and g1nt0ki authored Sep 17, 2024
1 parent 5b15a25 commit 7183fb7
Showing 1 changed file with 40 additions and 12 deletions.
52 changes: 40 additions & 12 deletions projects/tokemak/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const ADDRESSES = require('../helper/coreAssets.json')
const sdk = require('@defillama/sdk')
const { sumTokens2, } = require('../helper/unwrapLPs')
const abi = require("../pendle/abi.json");
const positions = require('./positions.json');
Expand All @@ -15,6 +14,26 @@ const cvx_abi = {
stkcvxFRAXBP_lockedStakesOf: "function lockedStakesOf(address account) view returns (tuple(bytes32 kek_id, uint256 start_timestamp, uint256 liquidity, uint256 ending_timestamp, uint256 lock_multiplier)[])",
}

const v2Gen3EthMainnet = {
systemRegistry: {
address: "0x2218F90A98b0C070676f249EF44834686dAa4285",
abi: {
autoPoolRegistry: "function autoPoolRegistry() view returns (address)"
}
},
autoPoolRegistry: {
abi: {
listVaults: "function listVaults() view returns (address[] memory)"
}
},
autopool: {
abi: {
totalAssets: "function totalAssets() view returns (uint256)",
asset: "function asset() view returns (address)"
}
}
}

const degenesisContract = "0xc803737D3E12CC4034Dde0B2457684322100Ac38";
const wethPool = "0xD3D13a578a53685B4ac36A1Bab31912D2B2A2F36";
const usdcPool = "0x04bda0cf6ad025948af830e75228ed420b0e860d";
Expand All @@ -31,9 +50,9 @@ const fxs = ADDRESSES.ethereum.FXS;
const tcrPool = "0x15A629f0665A3Eb97D7aE9A7ce7ABF73AeB79415";
const tcr = "0x9C4A4204B79dd291D6b6571C5BE8BbcD0622F050";
const toke = ADDRESSES.ethereum.TOKE;
const rtoke1 = "0xa760e26aA76747020171fCF8BdA108dFdE8Eb930";
const rtoke2 = "0x96f98ed74639689c3a11daf38ef86e59f43417d3";
const rtoke3 = "0xA374A62DdBd21e3d5716cB04821CB710897c0972";
const tTokeReactor = "0xa760e26aA76747020171fCF8BdA108dFdE8Eb930";
const stakingVestingV1 = "0x96f98ed74639689c3a11daf38ef86e59f43417d3";
const accTokeV1 = "0xA374A62DdBd21e3d5716cB04821CB710897c0972";
const sushiPool = "0xf49764c9C5d644ece6aE2d18Ffd9F1E902629777";
const sushi = ADDRESSES.ethereum.SUSHI;
const fraxPool = "0x94671A3ceE8C7A12Ea72602978D1Bb84E920eFB2";
Expand Down Expand Up @@ -110,7 +129,6 @@ async function tvl(api) {
[cvxFRAXPool, tokeManager],
[cvxalUSDPool, tokeManager],
]
const balances = {}

// cvxcrvFRAX
const cvxFraxUsdcPool = "0x7e880867363A7e321f5d260Cade2B0Bb2F717B02";
Expand All @@ -133,9 +151,9 @@ async function tvl(api) {
target: cvxcvxFxsPool,
params: [tokeTreasury],
});
sdk.util.sumSingleBalance(balances, cvxcrvFrax, cvxcrvFraxBal)
sdk.util.sumSingleBalance(balances, cvxcrvFrax, treasuryFraxBal[0]['liquidity'])
sdk.util.sumSingleBalance(balances, cvxcvxFxs, cvxcvxFxsBal)
api.add(cvxcrvFrax, cvxcrvFraxBal)
api.add(cvxcrvFrax, treasuryFraxBal[0]['liquidity'])
api.add(cvxcvxFxs, cvxcvxFxsBal)

let curveHoldings = positions.exchanges.filter(
pool => pool.type == 'Curve')
Expand All @@ -147,10 +165,20 @@ async function tvl(api) {
lpBalances(curveHoldings, toa, tokens, calls,)
lpBalances(uniHoldings, toa, tokens, calls)
const amountRes = await api.multiCall({ abi: abi.userInfo, calls })
tokens.forEach((val, i) => sdk.util.sumSingleBalance(balances, val, amountRes[i].amount, api.chain))
tokens.forEach((val, i) => api.add(val, amountRes[i].amount))


// ================================================
// Autopilot
// ================================================

// Get the instance of the Autopool Registry from the System Registry
const autopoolRegistry = await api.call({ abi: v2Gen3EthMainnet.systemRegistry.abi.autoPoolRegistry, target: v2Gen3EthMainnet.systemRegistry.address, });
// Use the Autopool Registry to get all the Autopools in the system
const autopools = await api.call({ abi: v2Gen3EthMainnet.autoPoolRegistry.abi.listVaults, target: autopoolRegistry, });
await api.erc4626Sum2({ calls: autopools})

return sumTokens2({ balances, api, tokensAndOwners: toa, })
return sumTokens2({ api, tokensAndOwners: toa, })
}

function lpBalances(holdings, toa, tokens, calls) {
Expand All @@ -175,11 +203,11 @@ function lpBalances(holdings, toa, tokens, calls) {
}

async function staking(api) {
let vestedToke = '57238445'
let vestedToke = '1438444'
api.add(ADDRESSES.ethereum.TOKE, vestedToke * 1e18 * -1)
return sumTokens2({
api, tokensAndOwners: [
[toke, rtoke1], [toke, rtoke2], [toke, rtoke3]
[toke, tTokeReactor], [toke, stakingVestingV1], [toke, accTokeV1]
]
})
}
Expand Down

0 comments on commit 7183fb7

Please sign in to comment.