Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mrben1 authored Sep 30, 2024
2 parents 76e8762 + 7691af7 commit 75eccd9
Show file tree
Hide file tree
Showing 1,145 changed files with 15,148 additions and 17,878 deletions.
1,908 changes: 1,016 additions & 892 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions projects/0xDAO/erc20.json

This file was deleted.

243 changes: 51 additions & 192 deletions projects/0xDAO/index.js
Original file line number Diff line number Diff line change
@@ -1,209 +1,68 @@
const oxLensAbi = require("./oxLens.json");
const solidlyLensAbi = require("./solidlyLens.json");
const veAbi = require("./ve.json");
const oxLensAbi = {
"oxPoolsAddresses": "address[]:oxPoolsAddresses",
"oxPoolsData": "function oxPoolsData(address[] _oxPoolsAddresses) view returns (tuple(address id, address stakingAddress, uint256 stakedTotalSupply, uint256 totalSupply, tuple(address id, string symbol, bool stable, address token0Address, address token1Address, address gaugeAddress, address bribeAddress, address[] bribeTokensAddresses, address fees, uint256 totalSupply) poolData)[])"
}

const veAbi = {
"locked": "function locked(uint256) view returns (int128 amount, uint256 end)"
}

const partnerRewardsPoolAddress = "0xDA006E87DB89e1C5213D4bfBa771e53c91D920aC";
const oxdV1RewardsPoolAddress = "0xDA000779663501df3C9Bc308E7cEc70cE6F04211";
const oxSolidRewardPoolAddress = "0xDA0067ec0925eBD6D583553139587522310Bec60";
const vlOxdAddress = "0xDA00527EDAabCe6F97D89aDb10395f719E5559b9";
const oxdAddress = "0xc5A9848b9d145965d821AaeC8fA32aaEE026492d";
const solidAddress = "0x888EF71766ca594DED1F0FA3AE64eD2941740A20";
const veAddress = "0xcBd8fEa77c2452255f59743f55A3Ea9d83b3c72b";
const oxSolidAddress = "0xDA0053F0bEfCbcaC208A3f867BB243716734D809";
const sanitize = require("./sanitizeWeb3Response.js");

const { standardPoolInfoAbi, addFundsInMasterChef } = require('../helper/masterchef')
const sdk = require('@defillama/sdk')

const shareValue = "uint256:getShareValue"
const xSCREAM = "0xe3D17C7e840ec140a7A51ACA351a482231760824"
const xCREDIT = "0xd9e28749e80D867d5d14217416BFf0e668C10645"
const shareTarot = "function shareValuedAsUnderlying(uint256 _share) returns (uint256 underlyingAmount_)"
const xTAROT = "0x74D1D2A851e339B8cB953716445Be7E8aBdf92F4"

const fBEET = "0xfcef8a994209d6916EB2C86cDD2AFD60Aa6F54b1"

async function tvl(_, __, chainBlocks) {
// 0xDAO Master Chef
const balances = {}
const chain = 'fantom'
const block = chainBlocks[chain]
const calldata = {
chain, block
const { standardPoolInfoAbi } = require('../helper/masterchef')
const { sumTokens2 } = require("../helper/unwrapLPs.js");

async function tvl(api) {
const masterchef = "0xa7821c3e9fc1bf961e280510c471031120716c3d"
const oxd = "0xc165d941481e68696f43ee6e99bfb2b23e0e3114"
const tokens = (await api.fetchList({ lengthAbi: 'poolLength', itemAbi: standardPoolInfoAbi, target: masterchef })).map(i => i.lpToken)
await api.sumTokens({ owner: masterchef, tokens, blacklistedTokens: [oxd] })

// 0xDAO Core
const oxLensAddress = "0xDA00137c79B30bfE06d04733349d98Cf06320e69";

// Fetch pools addresses
const oxPoolsAddresses = await api.call({ target: oxLensAddress, abi: oxLensAbi.oxPoolsAddresses })
const pageSize = 200;
let currentPage = 0;

let addresses = []
while (addresses) {
const start = currentPage * pageSize;
const end = start + pageSize;
addresses = oxPoolsAddresses.slice(start, end);
if (addresses.length === 0) {
break;
}
const transform = addr => `fantom:${addr}`
await addFundsInMasterChef(balances, "0xa7821c3e9fc1bf961e280510c471031120716c3d", block, chain,
transform, standardPoolInfoAbi, [], true, true, "0xc165d941481e68696f43ee6e99bfb2b23e0e3114")

const screamShare = await sdk.api.abi.call({
...calldata,
target: xSCREAM,
abi: shareValue
})
sdk.util.sumSingleBalance(balances, transform("0xe0654C8e6fd4D733349ac7E09f6f23DA256bF475"),
screamShare.output *balances[transform(xSCREAM)] /1e18)
delete balances[transform(xSCREAM)]

const creditShare = await sdk.api.abi.call({
...calldata,
target: xCREDIT,
abi: shareValue
})
sdk.util.sumSingleBalance(balances, transform("0x77128dfdd0ac859b33f44050c6fa272f34872b5e"),
creditShare.output * balances[transform(xCREDIT)] / 1e18)
delete balances[transform(xCREDIT)]

const tarotShare = await sdk.api.abi.call({
...calldata,
target: xTAROT,
abi: shareTarot,
params: sdk.util.convertToBigInt(balances[transform(xTAROT)])
})
sdk.util.sumSingleBalance(balances, transform("0xc5e2b037d30a390e62180970b3aa4e91868764cd"),
tarotShare.output)
delete balances[transform(xTAROT)]
currentPage += 1;

sdk.util.sumSingleBalance(balances, transform("0xf24bcf4d1e507740041c9cfd2dddb29585adce1e"),
balances[transform(fBEET)])
delete balances[transform(fBEET)]
const poolsData = await api.call({ params: [addresses], target: oxLensAddress, abi: oxLensAbi.oxPoolsData })
poolsData.forEach(pool => api.add(pool.poolData.id, pool.totalSupply))
}

// 0xDAO Core
const oxLensAddress = "0xDA00137c79B30bfE06d04733349d98Cf06320e69";
const solidlyLensAddress = "0xDA0024F99A9889E8F48930614c27Ba41DD447c45";
// const oxd = new web3.eth.Contract(erc20Abi, oxdAddress);
// Add locked SOLID
const { amount: lockedSolidAmount } = await api.call({ target: veAddress, params: 2, abi: veAbi.locked })
api.add(solidAddress, lockedSolidAmount);

// Fetch pools addresses
const { output: oxPoolsAddresses } = await sdk.api.abi.call({
block,
chain: 'fantom',
target: oxLensAddress,
abi: oxLensAbi.oxPoolsAddresses
})
const pageSize = 200;
const poolsMap = {};
let currentPage = 0;
// Add staking pools TVL
const oxdV1RewardsPoolBalance = await api.call({ target: oxdV1RewardsPoolAddress, abi: 'erc20:totalSupply' })
const oxSolidRewardsPoolBalance = await api.call({ target: oxSolidRewardPoolAddress, abi: 'erc20:totalSupply' })
const partnerRewardsPoolBalance = await api.call({ target: partnerRewardsPoolAddress, abi: 'erc20:totalSupply' })

// Add pools
const addPools = (pools, reservesData) => {
pools.forEach((pool) => {
const solidlyPoolAddress = pool.poolData.id;
const reserveData = reservesData.find(
(data) => data.id === solidlyPoolAddress
);
const newPool = pool;
newPool.poolData = {
...pool.poolData,
...reserveData,
};
const shareOfTotalSupply = newPool.totalSupply / newPool.poolData.totalSupply
newPool.shareOfTotalSupply = shareOfTotalSupply;
let token0Reserve = newPool.poolData.token0Reserve * shareOfTotalSupply
let token1Reserve = newPool.poolData.token1Reserve * shareOfTotalSupply
if (isNaN(token0Reserve)) {
token0Reserve = "0"
}
if (isNaN(token1Reserve)) {
token1Reserve = "0"
}
newPool.token0Reserve = token0Reserve;
newPool.token1Reserve = token1Reserve;
poolsMap[pool.id] = newPool;
});
};
let addresses = []
while (addresses) {
const start = currentPage * pageSize;
const end = start + pageSize;
addresses = oxPoolsAddresses.slice(start, end);
if (addresses.length === 0) {
break;
}
currentPage += 1;
api.add(oxSolidAddress, oxdV1RewardsPoolBalance);
api.add(oxSolidAddress, partnerRewardsPoolBalance);
api.add(oxSolidAddress, oxSolidRewardsPoolBalance);

const { output: poolsData } = await sdk.api.abi.call({
block,
chain: 'fantom',
params: [addresses],
target: oxLensAddress,
abi: oxLensAbi.oxPoolsData
})
const solidlyPoolsAddresses = poolsData.map((pool) => pool.poolData.id);
const { output: reservesData } = await sdk.api.abi.call({
block,
chain: 'fantom',
target: solidlyLensAddress,
params: [solidlyPoolsAddresses],
abi: solidlyLensAbi.poolsReservesInfo
})
addPools(
sanitize(poolsData),
sanitize(reservesData)
);
}
const pools = Object.values(poolsMap);

// Add TVL from pools to balances
const addBalance = (tokenAddress, amount) => {
const fantomTokenAddress = `fantom:${tokenAddress}`
sdk.util.sumSingleBalance(balances, fantomTokenAddress, amount)
}
pools.forEach(pool => {
const token0 = pool.poolData.token0Address;
const token1 = pool.poolData.token1Address;
const amount0 = pool.token0Reserve;
const amount1 = pool.token1Reserve;
addBalance(token0, amount0);
addBalance(token1, amount1);
});

// Add locked SOLID
const { output: { amount: lockedSolidAmount } } = await sdk.api.abi.call({
block,
chain: 'fantom',
target: veAddress,
params: 2,
abi: veAbi.locked
})
addBalance(solidAddress, lockedSolidAmount);

// Add staking pools TVL
const { output: oxdV1RewardsPoolBalance } = await sdk.api.abi.call({
block,
chain: 'fantom',
target: oxdV1RewardsPoolAddress,
abi: 'erc20:totalSupply'
})
const { output: oxSolidRewardsPoolBalance } = await sdk.api.abi.call({
block,
chain: 'fantom',
target: oxSolidRewardPoolAddress,
abi: 'erc20:totalSupply'
})
const { output: partnerRewardsPoolBalance } = await sdk.api.abi.call({
block,
chain: 'fantom',
target: partnerRewardsPoolAddress,
abi: 'erc20:totalSupply'
})

addBalance(oxSolidAddress, oxdV1RewardsPoolBalance);
addBalance(oxSolidAddress, partnerRewardsPoolBalance);
addBalance(oxSolidAddress, oxSolidRewardsPoolBalance);

// Add vote locked OXD
const { output: voteLockedOxdBalance } = await sdk.api.abi.call({
block,
chain: 'fantom',
target: oxdAddress,
params: vlOxdAddress,
abi: 'erc20:balanceOf'
})
addBalance(oxdAddress, voteLockedOxdBalance);

return balances
return sumTokens2({ api, resolveLP: true, })
}

module.exports = {
fantom: {
tvl
}
fantom: {
tvl
}
}
4 changes: 0 additions & 4 deletions projects/0xDAO/oxLens.json

This file was deleted.

45 changes: 0 additions & 45 deletions projects/0xDAO/sanitizeWeb3Response.js

This file was deleted.

3 changes: 0 additions & 3 deletions projects/0xDAO/solidlyLens.json

This file was deleted.

3 changes: 0 additions & 3 deletions projects/0xDAO/ve.json

This file was deleted.

3 changes: 2 additions & 1 deletion projects/2doge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ module.exports = {
},
hallmarks: [
[1646179200, "Rug Pull"]
]
],
deadFrom: 1646179200
};
35 changes: 18 additions & 17 deletions projects/2pi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@ const fetchChainAddresses = async chain => {
return getUniqueAddresses(archimedes)
}

const fetchTvl = chain => {
return async (api) => {
const addresses = await fetchChainAddresses(chains[chain])
let pools = await Promise.all(addresses.map(i => api.fetchList({ withMetadata: true, target: i, lengthAbi: archimedesAbi['poolLength'], itemAbi: archimedesAbi['poolInfo'] })))
pools = pools.flat()
const wantTokens = pools.map(i => i.output.want)
const calls = pools.map(i => i.input)
const bal = await api.multiCall({ abi: archimedesAbi.balance, calls, })
api.add(wantTokens, bal)
const tvl = async (api) => {
const addresses = await fetchChainAddresses(chains[api.chain])
const res = await api.fetchList({ lengthAbi: 'poolLength', itemAbi: archimedesAbi['poolInfo'], calls: addresses, groupedByInput: true })
const calls = []
const tokens = []
for (let i = 0; i < res.length; i++) {
const pool = addresses[i]
for (let j = 0; j < res[i].length; j++) {
calls.push({ target: pool, params: j })
tokens.push(res[i][j].want)
}
}
console.log(res, api.chain)
const bals = await api.multiCall({ abi: archimedesAbi.balance, calls})
api.add(tokens, bals)
}

module.exports = {
timetravel: false,
...Object.fromEntries(
Object.keys(chains).map(chain => [
chain, { tvl: fetchTvl(chain) }
])
)
}

Object.keys(chains).forEach(chain => {
module.exports[chain] = { tvl }
})
13 changes: 13 additions & 0 deletions projects/Astra/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { getUniTVL } = require('../helper/unknownTokens')

const FACTORY = "0x2b6852CeDEF193ece9814Ee99BE4A4Df7F463557" // This factory is on AirDAO Mainnet (Chain Id: 16718)

const dexTVL = getUniTVL({ factory: FACTORY, useDefaultCoreAssets: true, })

module.exports = {
misrepresentedTokens: true,
methodology: `Uses factory(${FACTORY}) address to find and price Liquidity Pool pairs.`,
airdao: {
tvl: dexTVL
}
};
Loading

0 comments on commit 75eccd9

Please sign in to comment.