Skip to content

Commit

Permalink
Add Alchemix arbitrum contracts (#10811)
Browse files Browse the repository at this point in the history
* Add Alchemix arbitrum contracts

* minor fix

---------

Co-authored-by: g1nt0ki <[email protected]>
  • Loading branch information
imimim-username and g1nt0ki authored Jun 28, 2024
1 parent ffcdd18 commit 4fecd1b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
14 changes: 14 additions & 0 deletions projects/alchemix/contracts.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
{
"arbitrum": {
"tokenHolders": {
"alUSDAlchemist": "0xb46eE2E4165F629b4aBCE04B7Eb4237f951AC66F",
"alUSDTransmuterBuffer": "0x00E33722ba54545667E76a18CE9D544130eEAbcC",
"alUSDTransmuter": "0xe7ec71B894583E9C1b07873fA86A7e81f3940eA8",
"alETHAlchemist": "0x654e16a0b161b150F5d1C8a5ba6E7A7B7760703A",
"alETHTransmuterBuffer": "0xECAd08EE07f1AA87f3E080997eBa6d02d28bb9D2",
"alETHTransmuter": "0x1EB7D78d7f6D73e5de67Fa62Fd8b55c54Aa9c0D4"
},
"underlyingTokens": {
"USDC": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
"WETH": "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1"
}
},
"fantom": {
"tokenHolders": {
"alUSDAlchemist": "0x76b2E3c5a183970AAAD2A48cF6Ae79E3e16D3A0E",
Expand Down
56 changes: 26 additions & 30 deletions projects/alchemix/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,41 @@ const { sumTokens2 } = require("../helper/unwrapLPs");
const { staking } = require("../helper/staking.js");
const contracts = require("./contracts");

function tvl(chain) {
return async (api) => {
const tokens = Object.values(contracts[chain].underlyingTokens).concat(Object.values(contracts[chain].yvTokens))
await sumTokens2({ tokens, api, owners: Object.values(contracts[chain].tokenHolders) })
if (api.chain !== 'ethereum') return api.getBalances()
async function tvl(api) {
const chain = api.chain
const tokens = Object.values(contracts[chain].underlyingTokens).concat(Object.values(contracts[chain].yvTokens ?? []))
await sumTokens2({ tokens, api, owners: Object.values(contracts[chain].tokenHolders) })
if (api.chain !== 'ethereum') return api.getBalances()

await Promise.all(
Object.values(contracts.cvxLPpools).map(async ({ poolAddress, holder, tokenAddress, alToken }) => {
const lpTokenBalance = await api.call({ target: poolAddress, abi: "erc20:balanceOf", params: holder, })
const supply = await api.call({ target: tokenAddress, abi: "erc20:totalSupply", })
// console.log({poolAddress, holder, tokenAddress, alToken, lpTokenBalance, supply, ratio: lpTokenBalance / supply})
if (+supply === 0) return;
const ratio = lpTokenBalance / supply
const tokenBalances = await api.multiCall({ target: tokenAddress, abi: 'function balances(uint256) view returns (uint256)', calls: [0, 1] })
const tokens = await api.multiCall({ target: tokenAddress, abi: 'function coins(uint256) view returns (address)', calls: [0, 1] })
alToken = alToken.toLowerCase()
tokens.forEach((token, i) => {
if (token.toLowerCase() !== alToken) {
if (!isNaN(tokenBalances[i] * ratio))api.add(token, tokenBalances[i] * ratio)
}
})
await Promise.all(
Object.values(contracts.cvxLPpools).map(async ({ poolAddress, holder, tokenAddress, alToken }) => {
const lpTokenBalance = await api.call({ target: poolAddress, abi: "erc20:balanceOf", params: holder, })
const supply = await api.call({ target: tokenAddress, abi: "erc20:totalSupply", })
// console.log({poolAddress, holder, tokenAddress, alToken, lpTokenBalance, supply, ratio: lpTokenBalance / supply})
if (+supply === 0) return;
const ratio = lpTokenBalance / supply
const tokenBalances = await api.multiCall({ target: tokenAddress, abi: 'function balances(uint256) view returns (uint256)', calls: [0, 1] })
const tokens = await api.multiCall({ target: tokenAddress, abi: 'function coins(uint256) view returns (address)', calls: [0, 1] })
alToken = alToken.toLowerCase()
tokens.forEach((token, i) => {
if (token.toLowerCase() !== alToken) {
if (!isNaN(tokenBalances[i] * ratio)) api.add(token, tokenBalances[i] * ratio)
}
})
);
};
}
})
);
};

module.exports = {
doublecounted: true,
ethereum: {
tvl: tvl("ethereum"),
tvl,
staking: staking(
contracts.ethereum.staking.holder,
contracts.ethereum.staking.token
),
},
fantom: {
tvl: tvl("fantom"),
},
optimism: {
tvl: tvl("optimism"),
},
fantom: { tvl, },
optimism: { tvl, },
arbitrum: { tvl },
};

0 comments on commit 4fecd1b

Please sign in to comment.