Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Aug 15, 2024
1 parent a4b0501 commit df339b2
Showing 1 changed file with 9 additions and 37 deletions.
46 changes: 9 additions & 37 deletions projects/jones-dao/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,19 @@ async function tvl(api) {
api.addTokens(metavaultTokens, metavaultBalances);
api.addTokens(optionVaultTokens, optionVaultBalances);
api.addTokens(addresses.tokens.usdc, jusdcTvl.output);
const getLPManagerContractsABI = "function getLPManagerContracts(uint256 _nonce) view returns (address lp,address viewer,address swapper,address receiver,address priceHelper,address lpManager,address doubleTracker,address singleTrackerZero,address singleTrackerOne,address compounder,address router)"

for (const factoryAddress of addresses.smartLpArbFactories) {
const nonce = await api.call({
target: factoryAddress,
abi: "uint256:nonce",
});

const contracts = await api.multiCall({
abi: "function getLPManagerContracts(uint256 _nonce) view returns (address lp,address viewer,address swapper,address receiver,address priceHelper,address lpManager,address doubleTracker,address singleTrackerZero,address singleTrackerOne,address compounder,address router)",
calls: Array.from({ length: nonce }, (_n, i) => i + 1).map((i) => ({
target: factoryAddress,
params: [i],
})),
});
const lpManagers = contracts.map((c) => c.lpManager);

const [token0s, token1s, aums] = await Promise.all([
api.multiCall({
abi: "address:token0",
calls: lpManagers,
}),
api.multiCall({
abi: "address:token1",
calls: lpManagers,
}),
api.multiCall({
abi: "function aum() returns (uint256 amount0, uint256 amount1)",
calls: lpManagers,
}),
]);

const balancesMap = aums.reduce((acc, { amount0, amount1 }, i) => {
acc[token0s[i]] = (acc[token0s[i]] ?? BigInt(0)) + BigInt(amount0);
acc[token1s[i]] = (acc[token1s[i]] ?? BigInt(0)) + BigInt(amount1);
return acc;
}, {});
for (const factoryAddress of addresses.smartLpArbFactories) {
const contracts = await api.fetchList({ lengthAbi: 'nonce', itemAbi: getLPManagerContractsABI, target: factoryAddress, startFromOne: true })
const lpManagers = contracts.map(c => c.lpManager)

const tokens = Object.keys(balancesMap);
const balances = Object.values(balancesMap);
const token0s = await api.multiCall({ abi: "address:token0", calls: lpManagers })
const token1s = await api.multiCall({ abi: "address:token1", calls: lpManagers })
const aums = await api.multiCall({ abi: "function aum() returns (uint256 amount0, uint256 amount1)", calls: lpManagers })

api.addTokens(tokens, balances);
api.add(token0s, aums.map(a => a.amount0))
api.add(token1s, aums.map(a => a.amount1))
}

const tokensAndOwners = [
Expand Down

0 comments on commit df339b2

Please sign in to comment.