diff --git a/projects/candycity/index.js b/projects/candycity/index.js index 5b3ee12ee..c4926a756 100644 --- a/projects/candycity/index.js +++ b/projects/candycity/index.js @@ -1,8 +1,4 @@ -const sdk = require("@defillama/sdk"); -const BigNumber = require("bignumber.js"); -const { toUSDTBalances } = require('../helper/balances') -const { get } = require('../helper/http'); -const { staking, stakings } = require("../helper/staking"); +const { staking, } = require("../helper/staking"); const { getUniTVL } = require('../helper/unknownTokens') const chainTvl = getUniTVL({ @@ -12,8 +8,6 @@ const chainTvl = getUniTVL({ const CANDY_TOKEN = '0x06C04B0AD236e7Ca3B3189b1d049FE80109C7977'; -const CMC_API_URL = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/market-pairs/latest?slug=bored-candy-city' - const STAKING_CONTRACTS = [ '0xDAf7c0e2882818b46c36AdBCe95399821Eca08F8', // masterchef '0x8FEf43b1f3046F8f58A76c64aD01Bc8d82ff0ad1', // candy vault @@ -28,32 +22,13 @@ const VESTING_CONTRACTS = [ '0x427f1230A547566a51F5Ffd5698BB65c06acA2D2', // candy vesting ] -async function fetchTvl(timestamp, ethBlock, chainBlocks) { - let cmc_response = await get(CMC_API_URL) - const candyPrice = cmc_response.data.marketPairs[0].price - const balances = await stakings(STAKING_CONTRACTS, CANDY_TOKEN)(timestamp, ethBlock, chainBlocks) - const candyBalances = Object.values(balances)[0] - - return toUSDTBalances(BigNumber(candyBalances).times(BigNumber(candyPrice)).div(1e18)); -} - -async function fetchVesting(timestamp, ethBlock, chainBlocks) { - let cmc_response = await get(CMC_API_URL) - const candyPrice = cmc_response.data.marketPairs[0].price - const balances = await stakings(VESTING_CONTRACTS, CANDY_TOKEN)(timestamp, ethBlock, chainBlocks) - const candyBalances = Object.values(balances)[0] - - return toUSDTBalances(BigNumber(candyBalances).times(BigNumber(candyPrice)).div(1e18)); -} - module.exports = { misrepresentedTokens: true, methodology: "Factory address (0x84343b84EEd78228CCFB65EAdEe7659F246023bf) is used to find the LP pairs. TVL is equal to the liquidity on the AMM and the candy tokens in the staking pools / vault / vesting contract / lock contract.", cronos: { tvl: chainTvl, - staking: fetchTvl, - vesting: fetchVesting - + staking: staking(STAKING_CONTRACTS, CANDY_TOKEN), + vesting: staking(VESTING_CONTRACTS, CANDY_TOKEN), }, -}; // node test.js projects/crodex/index.js +} \ No newline at end of file diff --git a/projects/championfinance/index.js b/projects/championfinance/index.js index 077249308..8883c5934 100644 --- a/projects/championfinance/index.js +++ b/projects/championfinance/index.js @@ -1,8 +1,6 @@ -const sdk = require("@defillama/sdk"); -const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); +const { pool2 } = require('../helper/pool2') const { stakings } = require("../helper/staking"); -const avicTokenAddress = "0x59B18817CA9f4ad2dEE6FBf30132dF6AEb9D763d"; const chamTokenAddress = "0xc65bC1E906771e105fBAcBD8dfE3862Ee7BE378E"; const chamRewardPoolAddress = "0x649EfBF7D96B06a2bD0fB134621AC9dD031923A4"; const boardroomAddress = [ @@ -16,49 +14,11 @@ const lps = [ "0xd6F18CDe9A52A9D815dd3C03C2325D453E32BDef", //CHAMUsdcLpAddress "0x8392a728aEe00a26E99AF8e837c33591944e033a", // EVIC-WETH.e Address ]; -const shareLps = "0xd6F18CDe9A52A9D815dd3C03C2325D453E32BDef"; -async function calcPool2(masterchef, lps, block, chain) { - let balances = {}; - const lpBalances = ( - await sdk.api.abi.multiCall({ - calls: lps.map((p) => ({ - target: p, - params: masterchef, - })), - abi: "erc20:balanceOf", - block, - chain, - }) - ).output; - let lpPositions = []; - lpBalances.forEach((p) => { - lpPositions.push({ - balance: p.output, - token: p.input.target, - }); - }); - await unwrapUniswapLPs( - balances, - lpPositions, - block, - chain, - (addr) => `${chain}:${addr}` - ); - return balances; -} - -async function pool2(timestamp, block, chainBlocks) { - return await calcPool2(chamRewardPoolAddress, lps, chainBlocks.avax); -} -async function tvl(timestamp, block, chainBlocks) { - let balances = {}; - return balances; -} module.exports = { avax: { - tvl: tvl, - pool2: pool2, + tvl: () => ({}), + pool2: pool2(chamRewardPoolAddress, lps), staking: stakings(boardroomAddress, chamTokenAddress) } }; diff --git a/projects/hyperliquid-spot/index.js b/projects/hyperliquid-spot/index.js index 01158e510..ce0db61f4 100644 --- a/projects/hyperliquid-spot/index.js +++ b/projects/hyperliquid-spot/index.js @@ -3,7 +3,7 @@ const { post } = require('../helper/http') async function tvl(api) { let data= await post('https://api.hyperliquid.xyz/info', {"type":"tvlBreakdown"}) data = data.find(i => i.protocol === "Hyperliquid Spot DEX") - data.tokens.forEach(i => api.addCGToken('tether', api.usdcValue)) + data.tokens.forEach(i => api.addCGToken('tether', +i.usdcValue)) } module.exports = { diff --git a/projects/init-capital/index.js b/projects/init-capital/index.js index e8416f152..1e8092082 100644 --- a/projects/init-capital/index.js +++ b/projects/init-capital/index.js @@ -14,7 +14,7 @@ const tvl = async (api) => { if (chainId === 81457) { pools = Object.keys(allPoolData[chainId]).map( - (pool) => allPoolData[chainId][pool].rebaseWrapperAddress + (pool) => allPoolData[chainId][pool].rebaseWrapperAddress ?? allPoolData[chainId][pool].poolAddress ); } else { pools = Object.keys(allPoolData[chainId]); @@ -36,7 +36,7 @@ const borrowed = async (api) => { if (chainId === 81457) { debts = await api.multiCall({ calls: debts.map((debt, i) => ({ - target: allPoolData[chainId][pools[i]].rebaseWrapperAddress, + target: allPoolData[chainId][pools[i]].rebaseWrapperAddress ?? allPoolData[chainId][pools[i]].poolAddress, params: [debt], })), abi: "function toAmt(uint256) returns (uint256)", diff --git a/projects/kittyfinance/index.js b/projects/kittyfinance/index.js index 398ee3a71..96279eddd 100644 --- a/projects/kittyfinance/index.js +++ b/projects/kittyfinance/index.js @@ -1,9 +1,6 @@ -const sdk = require("@defillama/sdk"); -const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); -const { stakingUnknownPricedLP, staking } = require("../helper/staking"); +const { staking } = require("../helper/staking"); +const { pool2 } = require("../helper/pool2"); -const avaxKitty = "0x788AE3b5D153d49F8DB649aacbA1857f744b739e"; -const polyKitty = "0x182dB1252C39073eeC9d743F13b5eeb80FDE314e"; const avaxCat = "0x094BFaC9894d2A2A35771D0BD6d2447689190F32"; const polyCat = "0xB932D203f83B8417Be0F61D9dAFad09cc24a4715"; const polyChef = "0xc17c09f7615c660dd5A7C1051E096240CF75685a"; @@ -19,59 +16,15 @@ const avaxLPs = [ "0x2d9A57C484C60241f5340a145a3004c7E4cfE040", // CAT-AVAX LP ]; -async function calcPool2(masterchef, lps, block, chain) { - let balances = {}; - const lpBalances = ( - await sdk.api.abi.multiCall({ - calls: lps.map((p) => ({ - target: p, - params: masterchef, - })), - abi: "erc20:balanceOf", - block, - chain, - }) - ).output; - let lpPositions = []; - lpBalances.forEach((p) => { - lpPositions.push({ - balance: p.output, - token: p.input.target, - }); - }); - await unwrapUniswapLPs( - balances, - lpPositions, - block, - chain, - (addr) => `${chain}:${addr}` - ); - return balances; -} - -async function polyPool2(timestamp, block, chainBlocks) { - return await calcPool2(polyChef, polyLPs, chainBlocks.polygon); -} - -async function avaxPool2(timestamp, block, chainBlocks) { - return await calcPool2(avaxChef, avaxLPs, chainBlocks.avax); -} - module.exports = { polygon: { tvl: async () => ({}), - pool2: polyPool2, - staking: stakingUnknownPricedLP( - polyNursery, - polyCat, - "polygon", - polyLPs[1], - (addr) => `polygon:${addr}` - ), + pool2: pool2(polyChef, polyLPs), + staking: staking(polyNursery, polyCat), }, avax: { tvl: async () => ({}), - pool2: avaxPool2, + pool2: pool2(avaxChef, avaxLPs), staking: staking(avaxNursery, avaxCat), }, }; diff --git a/projects/nacho-finance/index.js b/projects/nacho-finance/index.js index d4b285de1..353f79af4 100644 --- a/projects/nacho-finance/index.js +++ b/projects/nacho-finance/index.js @@ -1,8 +1,6 @@ -const sdk = require("@defillama/sdk"); -const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); const { staking } = require("../helper/staking"); +const { pool2 } = require("../helper/pool2"); -const tombTokenAddress = "0xcD86152047e800d67BDf00A4c635A8B6C0e5C4c2"; const tshareTokenAddress = "0x948D0a28b600BDBd77AF4ea30E6F338167034181"; const tshareRewardPoolAddress = "0xdD694F459645eb6EfAE934FE075403760eEb9aA1"; const masonryAddress = "0x1ad667aCe03875fe48534c65BFE14191CF81fd64"; @@ -12,50 +10,13 @@ const ftmLPs = [ "0x2c97767BFa132E3785943cf14F31ED3f025405Ea", // NSHARE-MATIC "0xcD90217f76F3d8d5490FD0434F597516767DaDe1", // ETH-MATIC "0x354789e7bBAC6E3d3143A0457324cD80bD0BE050", // ETH-USDC - "0xfc4a30f328E946ef3E727BD294a93e84c2e43c24" // NBOND ]; -async function calcPool2(masterchef, lps, block, chain) { - let balances = {}; - const lpBalances = ( - await sdk.api.abi.multiCall({ - calls: lps.map((p) => ({ - target: p, - params: masterchef, - })), - abi: "erc20:balanceOf", - block, - chain, - }) - ).output; - let lpPositions = []; - lpBalances.forEach((p) => { - if (p.input.target != '0xfc4a30f328E946ef3E727BD294a93e84c2e43c24') { - lpPositions.push({ - balance: p.output, - token: p.input.target, - }); - } - }); - await unwrapUniswapLPs( - balances, - lpPositions, - block, - chain, - (addr) => `${chain}:${addr}` - ); - return balances; -} - -async function ftmPool2(timestamp, block, chainBlocks) { - return await calcPool2(tshareRewardPoolAddress, ftmLPs, chainBlocks.polygon); -} - module.exports = { methodology: "Pool2 deposits consist of NACHO/ETH, NSHARE/MATIC LP, ETH/MATIC LP, ETH/USDC LP and NBOND tokens deposits while the staking TVL consists of the NSHARE tokens locked within the Bowl contract.", polygon: { tvl: async () => ({}), - pool2: ftmPool2, + pool2: pool2(tshareRewardPoolAddress, ftmLPs), staking: staking(masonryAddress, tshareTokenAddress), }, }; diff --git a/projects/partialfinance/index.js b/projects/partialfinance/index.js index e7d213f97..09f3dfb99 100644 --- a/projects/partialfinance/index.js +++ b/projects/partialfinance/index.js @@ -1,68 +1,21 @@ -const sdk = require("@defillama/sdk"); -const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); -const { staking, stakingPricedLP } = require("../helper/staking"); +const { staking, } = require("../helper/staking"); +const { pool2 } = require('../helper/pool2') -const partialTokenAddress = "0x9486fDA4C1192db69a08CA7235E2E6bAf31B467B"; const pshareTokenAddress = "0x8C64D18E9d4A7b8e8c10C5c5a4b8D6D83cb15002"; const pshareRewardPoolAddress = "0xd5f73D588C3CaCd45B334f873b7B2E7DfaA4cCc7"; const boardroomAddress = "0x5FcE757a1aa5C489B008a4Df6CA2ef9088B5bCA4"; -const treasuryAddress = "0x5Cf2EB28083B95A7c0E73FE0F1312e4497FC2A53"; const ftmLPs = [ "0xe78c2b734F0e7BD708B1a6d79a0cF8937C4DA278", // partialFtmLpAddress "0x802ed580E7b48abBfaBf6edC73009705CE210d0b", // pshareFtmLpAddress -]; +] -async function calcPool2(masterchef, lps, block, chain) { - let balances = {}; - const lpBalances = ( - await sdk.api.abi.multiCall({ - calls: lps.map((p) => ({ - target: p, - params: masterchef, - })), - abi: "erc20:balanceOf", - block, - chain, - }) - ).output; - let lpPositions = []; - lpBalances.forEach((p) => { - lpPositions.push({ - balance: p.output, - token: p.input.target, - }); - }); - await unwrapUniswapLPs( - balances, - lpPositions, - block, - chain, - (addr) => `${chain}:${addr}` - ); - return balances; -} - -async function ftmPool2(timestamp, block, chainBlocks) { - return await calcPool2(pshareRewardPoolAddress, ftmLPs, chainBlocks.fantom); -} - -async function treasury(timestamp, block, chainBlocks) { - let balance = (await sdk.api.erc20.balanceOf({ - target: partialTokenAddress, - owner: treasuryAddress, - block: chainBlocks.fantom, - chain: 'fantom' - })).output; - - return { [`fantom:${partialTokenAddress}`] : balance } -} module.exports = { + deadFrom: "2024-04-01", methodology: "Pool2 deposits consist of PARTIAL/FTM and PSHARE/FTM LP tokens deposits while the staking TVL consists of the PSHARES tokens locked within the Boardroom contract(0x5FcE757a1aa5C489B008a4Df6CA2ef9088B5bCA4).", fantom: { tvl: async () => ({}), - pool2: ftmPool2, - staking: stakingPricedLP(boardroomAddress, pshareTokenAddress, "fantom", "0x802ed580E7b48abBfaBf6edC73009705CE210d0b", "fantom"), - treasury + pool2: pool2(pshareRewardPoolAddress, ftmLPs), + staking: staking(boardroomAddress, pshareTokenAddress), }, }; \ No newline at end of file diff --git a/projects/pdollar/index.js b/projects/pdollar/index.js index 9846cc5be..a8e0b1461 100644 --- a/projects/pdollar/index.js +++ b/projects/pdollar/index.js @@ -1,68 +1,20 @@ -const sdk = require("@defillama/sdk"); -const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); -const { staking, stakingPricedLP } = require("../helper/staking"); +const { staking, } = require("../helper/staking"); +const { pool2 } = require('../helper/pool2') -const pdoTokenAddress = "0xb9D62c829fbF7eAff1EbA4E50F3D0480b66c1748"; const spdoTokenAddress = "0x1D3918043d22de2D799a4d80f72Efd50Db90B5Af"; const spdoRewardPoolAddress = "0xe8E0f521433028718baa338467151A3D43974292"; const boardroomAddress = "0x82D868D99747fbF9FDff367Bb9f1c55112B05c7F"; -const treasuryAddress = "0x25231b57030e795e1A12E10315cD9b779E395AaD"; const ftmLPs = [ "0xd339d12C6096Cb8E16a2BcCB5ACacA362bE78EA7", // pdoDaiLpAddress "0x5FBbd691e7d998fe6D5059B9BFa841223c018c31", // spdoDaiLpAddress ]; -async function calcPool2(masterchef, lps, block, chain) { - let balances = {}; - const lpBalances = ( - await sdk.api.abi.multiCall({ - calls: lps.map((p) => ({ - target: p, - params: masterchef, - })), - abi: "erc20:balanceOf", - block, - chain, - }) - ).output; - let lpPositions = []; - lpBalances.forEach((p) => { - lpPositions.push({ - balance: p.output, - token: p.input.target, - }); - }); - await unwrapUniswapLPs( - balances, - lpPositions, - block, - chain, - (addr) => `${chain}:${addr}` - ); - return balances; -} - -async function ftmPool2(timestamp, block, chainBlocks) { - return await calcPool2(spdoRewardPoolAddress, ftmLPs, chainBlocks.fantom); -} - -async function treasury(timestamp, block, chainBlocks) { - let balance = (await sdk.api.erc20.balanceOf({ - target: pdoTokenAddress, - owner: treasuryAddress, - block: chainBlocks.fantom, - chain: 'fantom' - })).output; - - return { [`fantom:${pdoTokenAddress}`] : balance } -} module.exports = { methodology: "Pool2 deposits consist of PDO/DAI and sPDO/DAI LP tokens deposits while the staking TVL consists of the sPDO tokens locked within the Boardroom contract(0x82D868D99747fbF9FDff367Bb9f1c55112B05c7F).", fantom: { tvl: async () => ({}), - pool2: ftmPool2, - staking: stakingPricedLP(boardroomAddress, spdoTokenAddress, "fantom", "0x5FBbd691e7d998fe6D5059B9BFa841223c018c31", "fantom"), - treasury + pool2: pool2(spdoRewardPoolAddress, ftmLPs), + staking: staking(boardroomAddress, spdoTokenAddress), }, }; \ No newline at end of file diff --git a/projects/toxicdeer/index.js b/projects/toxicdeer/index.js index 6350fd1e3..80fec0b47 100644 --- a/projects/toxicdeer/index.js +++ b/projects/toxicdeer/index.js @@ -1,9 +1,6 @@ +const { staking } = require('../helper/staking') +const { pool2 } = require('../helper/pool2') -const sdk = require("@defillama/sdk"); -const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); -const { stakingUnknownPricedLP, stakingPricedLP } = require("../helper/staking"); - -const DEER = "0x8efbaa6080412d7832025b03b9239d0be1e2aa3b"; const XDSHARE = "0x6f715158d4b1468528da002f5941c72fe4159520"; const boardroom = "0x85b60750761d0e170237700Ce1e94213E1742A34"; const rewardPool = "0xf6c3e1B489c1e634a3c66876d5A8E19B1A65B252"; @@ -12,41 +9,7 @@ const lps = [ "0x18cD20C6CA9Ccfe1C8b48516e6d5e0055a0271D2", "0x40d85d01f8b8E4A8cEa6F552e47Cf8F88A42db54" ]; -const shareLps = "0x18cD20C6CA9Ccfe1C8b48516e6d5e0055a0271D2"; -async function calcPool2(masterchef, lps, block, chain) { - let balances = {}; - const lpBalances = ( - await sdk.api.abi.multiCall({ - calls: lps.map((p) => ({ - target: p, - params: masterchef, - })), - abi: "erc20:balanceOf", - block, - chain, - }) - ).output; - let lpPositions = []; - lpBalances.forEach((p) => { - lpPositions.push({ - balance: p.output, - token: p.input.target, - }); - }); - await unwrapUniswapLPs( - balances, - lpPositions, - block, - chain, - (addr) => `${chain}:${addr}` - ); - return balances; -} - -async function pool2(timestamp, block, chainBlocks) { - return await calcPool2(rewardPool, lps, chainBlocks.cronos); -} async function tvl(timestamp, block, chainBlocks) { let balances = {}; return balances; @@ -54,7 +17,7 @@ async function tvl(timestamp, block, chainBlocks) { module.exports = { cronos: { tvl: tvl, - pool2: pool2, - staking: stakingPricedLP(boardroom, XDSHARE, "cronos", shareLps, "usd-coin", null, 6) + pool2: pool2(rewardPool, lps), + staking: staking(boardroom, XDSHARE) } }; // node test.js projects/toxicdeer.js diff --git a/test.js b/test.js index 071450af0..05aef5f0d 100644 --- a/test.js +++ b/test.js @@ -425,8 +425,8 @@ setTimeout(() => { async function initCache() { let currentCache = await sdk.cache.readCache(INTERNAL_CACHE_FILE) - if (process.env.NO_EXIT_ON_LONG_RUN_RPC) - sdk.log('cache size:', JSON.stringify(currentCache).length, 'chains:', Object.keys(currentCache).length) + // if (process.env.NO_EXIT_ON_LONG_RUN_RPC) + // sdk.log('cache size:', JSON.stringify(currentCache).length, 'chains:', Object.keys(currentCache).length) const ONE_WEEK = 60 * 60 * 24 * 31 if (!currentCache || !currentCache.startTime || (Date.now() / 1000 - currentCache.startTime > ONE_WEEK)) { currentCache = {