diff --git a/projects/duet/bsc.js b/projects/duet/bsc.js index c833afef31ad..3480ab750bf2 100644 --- a/projects/duet/bsc.js +++ b/projects/duet/bsc.js @@ -1,14 +1,11 @@ const { getConfig } = require("../helper/cache"); -const collateralReaderContractABI = require("./abis/collateral-reader.json"); const ebcakeReaderContractABI = require("./abis/ebcake-reader.json"); const { getUniqueAddresses } = require('../helper/utils') -const BigNumber = require("bignumber.js"); const { sumTokens2 } = require("../helper/unwrapLPs"); const { staking } = require("../helper/staking"); const TOKEN_LIST_URL = "https://app.duet.finance/tokens.json"; -const COLLATERAL_READER_CONTRACT = "0xFfB8FD0E5eA13bb71401B19e00f9F934746f0b7A"; const DUET = '0x95EE03e1e2C5c4877f9A298F1C0D6c98698FAB7B' async function getEBCakeTvl(api) { @@ -51,16 +48,9 @@ async function tvl(api) { if (!tokens[i]) return; tokensAndOwners.push([tokens[i], underlyingMap[v]]) }) - // api.add('tether', (await getEBCakeTvl(api)) / 1e8, { skipChain: true }) await getEBCakeTvl(api) return sumTokens2({ tokensAndOwners, api, resolveLP: true, blacklistedTokens: [DUET]}) - - // const tokenTvls = await api.multiCall({ abi: collateralReaderContractABI.depositVaultValues, target: COLLATERAL_READER_CONTRACT, calls: uniqueVaults.map(i => ({ params: [[i], false] })) }) - // api.add('tether', (await getEBCakeTvl(api)) / 1e8, { skipChain: true }) - // tokenTvls.forEach(v => { - // if (v) api.add('tether', v[1][0] / 1e8, { skipChain: true }) - // }) } module.exports = { diff --git a/projects/ease/index.js b/projects/ease/index.js index 953cbceadcbf..266eca108145 100644 --- a/projects/ease/index.js +++ b/projects/ease/index.js @@ -1,5 +1,3 @@ -const sdk = require('@defillama/sdk'); -const { default: BigNumber } = require('bignumber.js'); const { stakings } = require("../helper/staking"); const { getConfig } = require('../helper/cache') @@ -9,17 +7,11 @@ const NXM = "0xd7c49CEE7E9188cCa6AD8FF264C1DA2e69D4Cf3B"; // const ARNXM_VAULT = "0x1337DEF1FC06783D4b03CB8C1Bf3EBf7D0593FC4"; const STAKING_CONTRACTS = [ //BRIBE_POT - "0xEA5EdeF17C9be57228389962ba50b98397f1E28C", + "0xEA5EdeF17C9be57228389962ba50b98397f1E28C", //GV_EASE "0xEa5edeF1eDB2f47B9637c029A6aC3b80a7ae1550", ]; -const RCA_SHIELD = { - abis: { - uBalance: "uint256:uBalance" - }, -}; - const ARNXM_VAULT = { abis: { aum: "uint256:aum", @@ -31,17 +23,17 @@ async function tvl(api) { //get TVL of Uninsurance vaults let resp = await getConfig('ease', VAULT_LIST_URL); let vaults = resp.map(i => i.address.toLowerCase()).filter(i => i !== '0x8f247eb2d71beeacdf212f8bc748f09cdf7144c0') - const bals = await api.multiCall({ abi: 'uint256:uBalance', calls: vaults }) - const tokens = await api.multiCall({ abi: 'address:uToken', calls: vaults }) - const decimals = await api.multiCall({ abi: 'erc20:decimals', calls: tokens }) + const bals = await api.multiCall({ abi: 'uint256:uBalance', calls: vaults }) + const tokens = await api.multiCall({ abi: 'address:uToken', calls: vaults }) + const decimals = await api.multiCall({ abi: 'erc20:decimals', calls: tokens }) api.addTokens(tokens, bals.map((v, i) => v / 10 ** (18 - decimals[i]))) //get TVL of arNXM vault - const balNXM = await api.call({ target: ARNXM_VAULT.address, abi: ARNXM_VAULT.abis.aum, }); + const balNXM = await api.call({ target: ARNXM_VAULT.address, abi: ARNXM_VAULT.abis.aum, }); api.add(NXM, balNXM) } module.exports = { - ethereum:{ + ethereum: { tvl, staking: stakings(STAKING_CONTRACTS, EASE), }, diff --git a/projects/econia.js b/projects/econia.js index 43682d065cee..c6fc3d330e78 100644 --- a/projects/econia.js +++ b/projects/econia.js @@ -1,5 +1,4 @@ const axios = require("axios"); -const BigNumber = require("bignumber.js"); const URL = 'https://aptos-mainnet-econia.nodeinfra.com'; diff --git a/projects/primitive/abi.json b/projects/primitive/abi.json deleted file mode 100644 index bb002254d713..000000000000 --- a/projects/primitive/abi.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "risky": "address:risky", - "stable": "address:stable" -} \ No newline at end of file diff --git a/projects/primitive/index.js b/projects/primitive/index.js index 4ef2810089dd..92c9ae42a13b 100644 --- a/projects/primitive/index.js +++ b/projects/primitive/index.js @@ -5,6 +5,6 @@ const v1TVL = require('./v1') module.exports = { ethereum: { start: 1647932400, // unix timestamp (utc 0) specifying when the project began, or where live data begins - tvl: sdk.util.sumChainTvls([rmmTVL, v1TVL]), // + tvl: sdk.util.sumChainTvls([rmmTVL, v1TVL, ]), // }, } \ No newline at end of file diff --git a/projects/primitive/rmm.js b/projects/primitive/rmm.js index 74bfe74e2274..2656aace690e 100644 --- a/projects/primitive/rmm.js +++ b/projects/primitive/rmm.js @@ -1,29 +1,11 @@ -const sdk = require('@defillama/sdk') -const {sumTokens} = require("../helper/unwrapLPs"); -const abi = require("./abi.json"); - const engine_weth_usdc = '0xd3541aD19C9523c268eDe8792310867C57BE39e4' // WETH-USDC Pair const engines = [engine_weth_usdc] -module.exports = async function tvl(time, ethBlock, chainBlocks) { - const [{output: risky}, {output: stable}] = await Promise.all([ - sdk.api.abi.multiCall({ - abi: abi['risky'], - calls: engines.map(e => ({target: e})), - block: ethBlock, - }), - sdk.api.abi.multiCall({ - abi: abi['stable'], - calls: engines.map(e => ({target: e})), - block: ethBlock, - }) - ]) - - const tokensAndOwners = risky.map((call, idx) => [ - [call.output, call.input.target], - [stable[idx].output, call.input.target] - ]).flat() - const balances = {} - await sumTokens(balances, tokensAndOwners, ethBlock, 'ethereum') - return balances +module.exports = async function tvl(api) { + const risky = await api.multiCall({ abi: 'address:risky', calls: engines}) + const stable = await api.multiCall({ abi: 'address:stable', calls: engines}) + const toa = [] + risky.forEach((v, i) => toa.push([v, engines[i]])) + stable.forEach((v, i) => toa.push([v, engines[i]])) + return api.sumTokens({ tokensAndOwners: toa }) } \ No newline at end of file diff --git a/projects/primitive/v1.js b/projects/primitive/v1.js index da4c2082b7f8..ecf1b391b98f 100644 --- a/projects/primitive/v1.js +++ b/projects/primitive/v1.js @@ -1,270 +1,24 @@ -const ADDRESSES = require('../helper/coreAssets.json') -const sdk = require('@defillama/sdk') -const BigNumber = require('bignumber.js') -const getCacheBalances = 'function getCacheBalances() view returns (uint256, uint256)' const getUnderlyingTokenAddress = "address:getUnderlyingTokenAddress" const getStrikeTokenAddress = "address:getStrikeTokenAddress" -const redeemToken = "address:redeemToken" -const getPair = 'function getPair(address, address) view returns (address)' -const token0 = 'address:token0' -const token1 = 'address:token1' -const getReserves = 'function getReserves() view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)' const { getLogs } = require('../helper/cache/getLogs') const START_BLOCK = 11142900 const REGISTRY = '0x16274044dab9635Df2B5AeAF7CeCb5f381c71680' -const FACTORY = '0xC0AEe478e3658e2610c5F7A4A2E1777cE9e4f2Ac' -const ZERO_ADDRESS = ADDRESSES.null module.exports = async function tvl(api) { - const block = api.block - - const logs = ( - await getLogs({ - api, - target: REGISTRY, - fromBlock: START_BLOCK, - topic: 'DeployedOptionClone(address,address,address)', - }) - ) - - const optionAddresses = logs - .map((log) => `0x${log.topics[2].substring(26)}`) - .map((optionAddress) => optionAddress.toLowerCase()) - - const allRedeemAddresses = logs - .map((log) => `0x${log.topics[3].substring(26)}`) - .map((redeemAddress) => redeemAddress.toLowerCase()) - - const [ - underlyingAddresses, - strikeAddresses, - redeemAddresses, - ] = await Promise.all([ - sdk.api.abi - .multiCall({ - abi: getUnderlyingTokenAddress, - calls: optionAddresses.map((optionAddress) => ({ - target: optionAddress, - })), - block, - }) - .then(({ output }) => output), - sdk.api.abi - .multiCall({ - abi: getStrikeTokenAddress, - calls: optionAddresses.map((optionAddress) => ({ - target: optionAddress, - })), - block, - }) - .then(({ output }) => output), - sdk.api.abi - .multiCall({ - abi: redeemToken, - calls: optionAddresses.map((optionAddress) => ({ - target: optionAddress, - })), - block, - }) - .then(({ output }) => output), - ]) - - const options = {} - // add underlyingAddresses - underlyingAddresses.forEach((underlyingAddress) => { - const tokenAddress = underlyingAddress.output.toLowerCase() - - const optionAddress = underlyingAddress.input.target.toLowerCase() - options[optionAddress] = { - underlyingAddress: tokenAddress, - } - }) - - // add strikeAddresses - strikeAddresses.forEach((strikeAddress) => { - const tokenAddress = strikeAddress.output.toLowerCase() - const optionAddress = strikeAddress.input.target.toLowerCase() - options[optionAddress] = { - ...(options[optionAddress] || {}), - strikeAddress: tokenAddress, - } - }) - - redeemAddresses.forEach((redeemAddress) => { - const tokenAddress = redeemAddress.output.toLowerCase() - const optionAddress = redeemAddress.input.target.toLowerCase() - options[optionAddress] = { - ...(options[optionAddress] || {}), - redeemAddress: tokenAddress, - } - }) - - // The internally tracked balances of underlying and strike tokens in the Primitive option contracts - const caches = ( - await sdk.api.abi.multiCall({ - abi: getCacheBalances, - calls: Object.keys(options).map((optionAddress) => ({ - target: optionAddress, - })), - block, - }) - ).output - - // ===== Sushiswap Pools ===== - - const optionPairAddresses = ( - await sdk.api.abi.multiCall({ - abi: getPair, - calls: Object.keys(options).map((optionAddress, i) => ({ - target: FACTORY, - params: [ - options[optionAddress].underlyingAddress, - options[optionAddress].redeemAddress, - ], - })), - block, - }) - ).output - - const optionPairs = [] - - optionPairAddresses.forEach((optionPairAddress) => { - const marketAddress = optionPairAddress.output.toLowerCase() - if (marketAddress !== ZERO_ADDRESS) optionPairs.push(marketAddress) - }) - - const [token0Addresses, token1Addresses] = await Promise.all([ - sdk.api.abi - .multiCall({ - abi: token0, - calls: optionPairs.map((marketAddress) => ({ - target: marketAddress, - })), - block, - }) - .then(({ output }) => output), - sdk.api.abi - .multiCall({ - abi: token1, - calls: optionPairs.map((marketAddress) => ({ - target: marketAddress, - })), - block, - }) - .then(({ output }) => output), - ]) - - const pairs = {} - // add token0Addresses - token0Addresses.forEach((token0Address) => { - const tokenAddress = token0Address.output.toLowerCase() - - if ( - allRedeemAddresses.indexOf(tokenAddress) != -1 - ) { - const pairAddress = token0Address.input.target.toLowerCase() - pairs[pairAddress] = { - token0Address: tokenAddress, - } - } - }) - - // add token1Addresses - token1Addresses.forEach((token1Address) => { - const tokenAddress = token1Address.output.toLowerCase() - if ( - allRedeemAddresses.indexOf(tokenAddress) != -1 - ) { - const pairAddress = token1Address.input.target.toLowerCase() - pairs[pairAddress] = { - ...(pairs[pairAddress] || {}), - token1Address: tokenAddress, - } - } - }) - - // Reserves of option pools in Sushiswap - const reserves = ( - await sdk.api.abi.multiCall({ - abi: getReserves, - calls: Object.keys(pairs).map((pairAddress) => ({ - target: pairAddress, - })), - block, - }) - ).output - - // ===== Accumulators ===== - - // accumulate the balances in the Sushiswap option pools - const inSushiSwap = reserves.reduce((accumulator, reserve, i) => { - const pairAddress = reserve.input.target.toLowerCase() - const pair = pairs[pairAddress] || {} - - // handle reserve0 - if (pair.token0Address) { - const reserve0 = new BigNumber(reserve.output['0']) - if (!reserve0.isZero()) { - const existingBalance = new BigNumber( - accumulator[pair.token0Address] || '0' - ) - - accumulator[pair.token0Address] = existingBalance - .plus(reserve0) - .toFixed() - } - } - - // handle reserve1 - if (pair.token1Address) { - const reserve1 = new BigNumber(reserve.output['1']) - - if (!reserve1.isZero()) { - const existingBalance = new BigNumber( - accumulator[pair.token1Address] || '0' - ) - - accumulator[pair.token1Address] = existingBalance - .plus(reserve1) - .toFixed() - } - } - - return accumulator - }, {}) - - // accumulate the caches of Primitive with the reserves of Sushiswap - return caches.reduce((accumulator, cache, i) => { - const optionAddress = cache.input.target.toLowerCase() - const option = options[optionAddress] || {} - - // handle underlyingCache - if (option.underlyingAddress) { - const underlyingCache = new BigNumber(cache.output['0']) - - const existingBalance = new BigNumber( - accumulator[option.underlyingAddress] || '0' - ) - - accumulator[option.underlyingAddress] = existingBalance - .plus(underlyingCache) - .toFixed() - } - - // handle strikeCache - if (option.strikeAddress) { - const strikeCache = new BigNumber(cache.output['1']) - - const existingBalance = new BigNumber( - accumulator[option.strikeAddress] || '0' - ) - - accumulator[option.strikeAddress] = existingBalance - .plus(strikeCache) - .toFixed() - } - - return accumulator - }, inSushiSwap) + const logs = (await getLogs({ + api, + target: REGISTRY, + fromBlock: START_BLOCK, + onlyArgs: true, + eventAbi: 'event DeployedOptionClone (address indexed from, address indexed optionAddress, address indexed redeemAddress)' + })) + + const tokensAndOwners = [] + const options = logs.map(i => i.optionAddress) + const underlying = await api.multiCall({ abi: getUnderlyingTokenAddress, calls: options}) + const strikes = await api.multiCall({ abi: getStrikeTokenAddress, calls: options}) + underlying.forEach((v, i) => tokensAndOwners.push([v, options[i]])) + strikes.forEach((v, i) => tokensAndOwners.push([v, options[i]])) + return api.sumTokens({ tokensAndOwners }) } diff --git a/projects/prosper/index.js b/projects/prosper/index.js deleted file mode 100644 index f4ee0239426b..000000000000 --- a/projects/prosper/index.js +++ /dev/null @@ -1,20 +0,0 @@ -const utils = require('../helper/utils') -const BigNumber = require('bignumber.js') - -const currentPoolEndpoint = 'https://avax.prosper.so/api/actualPool?chainId=43114&asset=AVAX%2FUSD&duration=60&token=AVAX' -const avaxCoingeckoId = 'avalanche-2' - -async function tvl(timestamp, block) { - const currentPool = await utils.fetchURL(currentPoolEndpoint) - const tvl = BigNumber(currentPool.data.bearsQuote).plus(currentPool.data.bullsQuote).div(1e18) - - return { - [avaxCoingeckoId]: tvl.toNumber() - } -} - -module.exports = { - avax:{ - tvl, - }, -} \ No newline at end of file diff --git a/projects/radial/index.js b/projects/radial/index.js index 3ba2035c4e1d..f3d6c0ce01e4 100644 --- a/projects/radial/index.js +++ b/projects/radial/index.js @@ -1,243 +1,18 @@ const { - standardPoolInfoAbi, - getPoolInfo, - getSymbolsAndBalances, - isLP, - isYV, - } = require("../helper/masterchef"); - const sdk = require("@defillama/sdk"); - const { default: BigNumber } = require("bignumber.js"); - const { handleYearnTokens } = require("../creditum/helper.js"); - const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); - - const tokenAbi = 'address:token' - const token0Abi = 'address:token0' - const token1Abi = 'address:token1' - const getReservesAbi = 'function getReserves() view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast)' - 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"; - const masterChef = "0x6f536B36d02F362CfF4278190f922582d59E7e08"; - const chain = "fantom"; - const tokenIsOnCoingecko = true; - const includeYVTokens = true; - const stakingToken = "0xf04d7f53933becbf51ddf1f637fe7ecaf3d4ff94"; - - async function tvl(timestamp, ethBlock, {[chain]: block}) { - const transform = i => `fantom:${i}`; - - const poolInfo = await getPoolInfo( - masterChef, - block, - chain, - standardPoolInfoAbi - ); - const [symbols, tokenBalances] = await getSymbolsAndBalances( - masterChef, - block, - chain, - poolInfo - ); - - const balances = {}; - - const lpPositions = []; - - await Promise.all( - symbols.output.map(async (symbol, idx) => { - const balance = tokenBalances.output[idx].output; - const token = symbol.input.target.toLowerCase(); - if (token === stakingToken) { - return; - } else if (isLP(symbol.output, token, chain)) { - lpPositions.push({ - balance, - token, - }); - } else if (includeYVTokens && isYV(symbol.output)) { - let underlyingToken = ( - await sdk.api.abi.call({ - target: token, - abi: tokenAbi, - block, - chain, - }) - ).output; - sdk.util.sumSingleBalance( - balances, - transform(underlyingToken), - balance - ); - } else { - sdk.util.sumSingleBalance(balances, transform(token), balance); - } - }) - ); - - const [token0, token1] = await Promise.all([ - sdk.api.abi.multiCall({ - calls: lpPositions.map((p) => ({ - target: p.token, - })), - abi: token0Abi, - block, - chain, - }), - sdk.api.abi.multiCall({ - calls: lpPositions.map((p) => ({ - target: p.token, - })), - abi: token1Abi, - block, - chain, - }), - ]); - - const pool2LpPositions = []; - const outsideLpPositions = []; - lpPositions.forEach((position, idx) => { - if ( - token0.output[idx].output.toLowerCase() === stakingToken || - token1.output[idx].output.toLowerCase() === stakingToken - ) { - pool2LpPositions.push(position); - } else { - outsideLpPositions.push(position); - } - }); - await unwrapUniswapLPs(balances, outsideLpPositions, block, chain, transform); - - if (!tokenIsOnCoingecko) { - const maxPool2ByToken = ( - await sdk.api.abi.multiCall({ - calls: pool2LpPositions.map((p) => ({ - target: stakingToken, - params: [p.token], - })), - abi: "erc20:balanceOf", - block, - chain, - }) - ).output.reduce((max, curr) => { - if (BigNumber(curr.output).gt(max.output)) { - return curr; - } - return max; - }); - const poolAddress = maxPool2ByToken.input.params[0].toLowerCase(); - const poolReserves = await sdk.api.abi.call({ - block, - chain, - abi: getReservesAbi, - target: poolAddress, - }); - const posToken0 = token0.output.find( - (t) => t.input.target.toLowerCase() === poolAddress - ).output; - const posToken1 = token1.output.find( - (t) => t.input.target.toLowerCase() === poolAddress - ).output; - let price, otherToken; - if (posToken0.toLowerCase() === stakingToken) { - price = poolReserves.output[1] / poolReserves.output[0]; - otherToken = transform(posToken1); - } else { - price = poolReserves.output[0] / poolReserves.output[1]; - otherToken = transform(posToken0); - } - const transformedStakingToken = transform(stakingToken); - Object.values(balances).forEach((balance) => { - Object.entries(balance).forEach(([addr, bal]) => { - if (addr.toLowerCase() === transformedStakingToken) { - balance[otherToken] = BigNumber(bal).times(price).toFixed(0); - delete balance[addr]; - } - }); - }); - } - const calldata = { - chain, - block, - }; - - await handleYearnTokens( - balances, - [ - "0x637ec617c86d24e421328e6caea1d92114892439", - "0xef0210eb96c7eb36af8ed1c20306462764935607", - "0x0dec85e74a92c52b7f708c4b10207d9560cefaf0", - "0x0A0b23D9786963DE69CB2447dC125c49929419d8", - "0xCe2Fc0bDc18BD6a4d9A725791A3DEe33F3a23BB7", - "0x2C850cceD00ce2b14AA9D658b7Cad5dF659493Db", - "0xd817A100AB8A29fE3DBd925c2EB489D67F758DA9", - ], - "0x6f536B36d02F362CfF4278190f922582d59E7e08", - block, - chain, - transform - ); - - const screamShare = await sdk.api.abi.call({ - ...calldata, - target: xSCREAM, - abi: shareValue, - }); - - sdk.util.sumSingleBalance( - balances, - transform("0xe0654C8e6fd4D733349ac7E09f6f23DA256bF475"), - BigNumber(screamShare.output) - .times(balances['fantom:0xe3d17c7e840ec140a7a51aca351a482231760824']) - .div(1e18) - .toFixed(0) - ); - delete balances[transform(xSCREAM)]; - // node test.js projects/radial/index.js - const creditShare = await sdk.api.abi.call({ - ...calldata, - target: xCREDIT, - abi: shareValue, - }); - sdk.util.sumSingleBalance( - balances, - transform("0x77128dfdd0ac859b33f44050c6fa272f34872b5e"), - BigNumber(creditShare.output) - .times(balances['fantom:0xd9e28749e80d867d5d14217416bff0e668c10645']) - .div(1e18) - .toFixed(0) - ); - delete balances[transform(xCREDIT)]; - - const tarotShare = await sdk.api.abi.call({ - ...calldata, - target: xTAROT, - abi: shareTarot, - params: balances['fantom:0x74d1d2a851e339b8cb953716445be7e8abdf92f4'], - }); - sdk.util.sumSingleBalance( - balances, - transform("0xc5e2b037d30a390e62180970b3aa4e91868764cd"), - tarotShare.output - ); - delete balances[transform(xTAROT)]; - - sdk.util.sumSingleBalance( - balances, - transform("0xf24bcf4d1e507740041c9cfd2dddb29585adce1e"), - balances['fantom:0xfcef8a994209d6916eb2c86cdd2afd60aa6f54b1'] - ); - delete balances[transform(fBEET)]; - return balances; - } - - module.exports = { - fantom: { - tvl, - }, - }; - - // node test.js projects/radial/index.js - \ No newline at end of file + standardPoolInfoAbi, +} = require("../helper/masterchef"); +const { sumTokens2 } = require("../helper/unwrapLPs"); + +const masterChef = "0x6f536B36d02F362CfF4278190f922582d59E7e08"; +const stakingToken = "0xf04d7f53933becbf51ddf1f637fe7ecaf3d4ff94"; + +async function tvl(api) { + const info = await api.fetchList({ lengthAbi: 'poolLength', itemAbi: standardPoolInfoAbi, target: masterChef }) + return sumTokens2({ api, owner: masterChef, tokens: info.map(i => i.lpToken), blacklistedTokens: [stakingToken] }) +} + +module.exports = { + fantom: { + tvl, + }, +} \ No newline at end of file diff --git a/projects/rose/abi.json b/projects/rose/abi.json deleted file mode 100644 index 5df5018200b8..000000000000 --- a/projects/rose/abi.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "balanceOf": "function balanceOf(address, address) view returns (uint256)", - "balances": "function balances(uint256 arg0) view returns (uint256)", - "totalBorrow": "function totalBorrow() view returns (uint128 elastic, uint128 base)" -} \ No newline at end of file diff --git a/projects/rose/index.js b/projects/rose/index.js index 3f6d920792ba..51ec625430e4 100644 --- a/projects/rose/index.js +++ b/projects/rose/index.js @@ -1,181 +1,47 @@ const ADDRESSES = require('../helper/coreAssets.json') -const sdk = require("@defillama/sdk"); -const { default: BigNumber } = require("bignumber.js"); +const { staking } = require('../helper/staking') + +const stablesPool = "0xc90dB0d8713414d78523436dC347419164544A3f" +const fraxPool = "0xa34315F1ef49392387Dd143f4578083A9Bd33E94" +const atustPool = "0x8fe44f5cce02D5BE44e3446bBc2e8132958d22B8" +const maiPool = "0x65a761136815B45A9d78d9781d22d47247B49D23" + +const DAI = "0xe3520349F477A5F6EB06107066048508498A291b" +const USDC = ADDRESSES.aurora.USDC_e +const USDT = ADDRESSES.aurora.USDT_e +const FRAX = ADDRESSES.aurora.FRAX +const UST = "0x5ce9F0B6AFb36135b5ddBF11705cEB65E634A9dC" +const MAI = ADDRESSES.moonbeam.MAI +const ROSE = "0xdcD6D4e2B3e1D1E1E6Fa8C21C8A323DcbecfF970" +const STROSE = "0xe23d2289FBca7De725DC21a13fC096787A85e16F" +const NEAR = ADDRESSES.aurora.NEAR +const WETH = "0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB" +const WBTC = "0xf4eb217ba2454613b15dbdea6e5f22276410e89e" + +const VASE = "0xee793001Ce9Fa988712B15a59CCf5dC7d54b22FF" -const abi = require("./abi.json"); - -// pool addresses -const stablesPool = "0xc90dB0d8713414d78523436dC347419164544A3f"; -const fraxPool = "0xa34315F1ef49392387Dd143f4578083A9Bd33E94"; -const atustPool = "0x8fe44f5cce02D5BE44e3446bBc2e8132958d22B8"; -const maiPool = "0x65a761136815B45A9d78d9781d22d47247B49D23"; -// const busdPool = "0xD6cb7Bb7D63f636d1cA72A1D3ed6f7F67678068a"; -const rusdPool = "0x79B0a67a4045A7a8DC04b17456F4fe15339cBA34"; - -// token addresses -const DAI = "0xe3520349F477A5F6EB06107066048508498A291b"; -const USDC = ADDRESSES.aurora.USDC_e; -const USDT = ADDRESSES.aurora.USDT_e; -const FRAX = ADDRESSES.aurora.FRAX; -const UST = "0x5ce9F0B6AFb36135b5ddBF11705cEB65E634A9dC"; -const MAI = ADDRESSES.moonbeam.MAI; -// const BUSD = "0x5C92A4A7f59A9484AFD79DbE251AD2380E589783"; -const RUSD = "0x19cc40283B057D6608C22F1D20F17e16C245642E"; -const ROSE = "0xdcD6D4e2B3e1D1E1E6Fa8C21C8A323DcbecfF970"; -const STROSE = "0xe23d2289FBca7De725DC21a13fC096787A85e16F"; -const NEAR = ADDRESSES.aurora.NEAR; -const WETH = "0xC9BdeEd33CD01541e1eeD10f90519d2C06Fe3feB"; -const WBTC = "0xf4eb217ba2454613b15dbdea6e5f22276410e89e"; - -// garden addresses -const gardenNear = "0x64C922E3824ab40cbbEdd6C8092d148C283d3D3D"; -const gardenUsdc = "0xfbAF3eBF228eB712b1267285787e51aDd70086bB"; -const gardenUsdt = "0x0F44fCD177098Cb2B063B50f6C62e4F1E1f9d596"; -const gardenWeth = "0x084355FDd5fcfd55d60C5B8626756a6906576f13"; -const gardenAtust = "0xe8F7F08D50e12145Cb722cfF861e6A9b43EADBA1"; -const gardenWbtc = "0x6bA5B45149996597d96e6dB19E4E1eFA81a6df97"; - -const VASE = "0xee793001Ce9Fa988712B15a59CCf5dC7d54b22FF"; - -// pool to underlying tokens map const poolToTokensMap = { [stablesPool]: [DAI, USDC, USDT], [fraxPool]: [FRAX], [atustPool]: [UST], [maiPool]: [MAI], - // [busdPool]: [BUSD], - [rusdPool]: [RUSD], -}; - -// garden to underlying tokens map -const gardenToTokensMap = { - [gardenNear]: [NEAR], - [gardenUsdc]: [USDC], - [gardenUsdt]: [USDT], - [gardenWeth]: [WETH], - [gardenAtust]: [UST], - [gardenWbtc]: [WBTC], -}; - -// tvl calculation -const tvl = async (timestamp, ethBlock, chainBlock) => { - let tvl = {}; - let calls = []; - - const block = chainBlock.aurora; - - Object.entries(poolToTokensMap).forEach(([poolAddress, poolTokens]) => { - poolTokens.forEach((_, tokenIndex) => { - calls.push({ - target: poolAddress, - params: tokenIndex, - }); - }); - }); - - // pool balances - const balances = await sdk.api.abi.multiCall({ - calls: calls, - block, - abi: abi.balances, - chain: "aurora", - }); - - balances.output.forEach((res) => { - const amount = res.output; - const poolAddress = res.input.target; - const tokenAddress = poolToTokensMap[poolAddress][res.input.params[0]]; - sdk.util.sumSingleBalance(tvl, `aurora:${tokenAddress}`, amount); - }); - - // unsupported stablecoin tokens - tvl["FRAX"] = new BigNumber(tvl[`aurora:${FRAX}`]) - .div(new BigNumber(10).pow(18)) - .toNumber(); - delete tvl[`aurora:${FRAX}`]; - tvl["RUSD"] = new BigNumber(tvl[`aurora:${RUSD}`]) - .div(new BigNumber(10).pow(18)) - .toNumber(); - delete tvl[`aurora:${RUSD}`]; - - // format calls to vase for collateral - calls = []; - Object.entries(gardenToTokensMap).forEach(([gardenAddress, gardenTokens]) => { - gardenTokens.forEach((gardenToken) => { - calls.push({ - target: VASE, - params: [gardenToken, gardenAddress], - }); - }); - }); - - const vaseCollateralBalances = await sdk.api.abi.multiCall({ - calls: calls, - block, - abi: abi.balanceOf, - chain: "aurora", - }); - - vaseCollateralBalances.output.forEach((res) => { - const amount = res.output; - const tokenAddress = res.input.params[0]; - sdk.util.sumSingleBalance(tvl, `aurora:${tokenAddress}`, amount); - }); - - return tvl; -}; - -// staking calculation -const staking = async (timestamp, ethBlock, chainBlock) => { - const balances = {}; - const stRoseTvl = await sdk.api.erc20.balanceOf({ - target: ROSE, - owner: STROSE, - chain: "aurora", - block: chainBlock.aurora, - }); - - sdk.util.sumSingleBalance(balances, `aurora:${ROSE}`, stRoseTvl.output); - return balances; -}; - -const borrowed = async (timestamp, ethBlock, chainBlock) => { - const calls = []; - Object.entries(gardenToTokensMap).forEach(([gardenAddress, gardenTokens]) => { - gardenTokens.forEach((_) => { - calls.push({ - target: gardenAddress, - params: [], - }); - }); - }); - - const borrowedAmounts = await sdk.api.abi.multiCall({ - calls: calls, - block: chainBlock.aurora, - abi: abi.totalBorrow, - chain: "aurora", - }); +} - borrowedAmounts.output.forEach((res) => { - const amount = res.output[0]; - sdk.util.sumSingleBalance(borrowed, `aurora:${RUSD}`, amount); - }); +const tvl = async (api) => { + const ownerTokens = [] - borrowed["RUSD"] = new BigNumber(borrowed[`aurora:${RUSD}`]) - .div(new BigNumber(10).pow(18)) - .toNumber(); - delete borrowed[`aurora:${RUSD}`]; + Object.entries(poolToTokensMap).forEach(([pool, tokens]) => ownerTokens.push([tokens, pool])) + const gardenTokens = [NEAR, USDC, USDT, WETH, UST, WBTC] + ownerTokens.push([gardenTokens, VASE]) - return borrowed; -}; + return api.sumTokens({ ownerTokens}) +} module.exports = { methodology: - "TVL is computed as the sum of the underlying token balances on all Rose liquidity pools. Staking accounts for total ROSE token staked. Borrowed accounts for debt in RUSD for all open collateralized debt positions.", + "TVL is computed as the sum of the underlying token balances on all Rose liquidity pools", aurora: { tvl, - staking, - borrowed + staking: staking(STROSE, ROSE), }, -}; +} diff --git a/projects/stablekoi/abi.json b/projects/stablekoi/abi.json deleted file mode 100644 index 7e8058d689af..000000000000 --- a/projects/stablekoi/abi.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "totalSupply": "uint256:totalSupply" -} \ No newline at end of file diff --git a/projects/stablekoi/index.js b/projects/stablekoi/index.js index 1d575933f521..a4d6392f42a2 100644 --- a/projects/stablekoi/index.js +++ b/projects/stablekoi/index.js @@ -1,76 +1,28 @@ const ADDRESSES = require('../helper/coreAssets.json') -const { sumTokens } = require("../helper/unwrapLPs"); -const { GraphQLClient, gql } = require("graphql-request"); -const abi = require("./abi.json"); -const sdk = require("@defillama/sdk"); -const { default: BigNumber } = require("bignumber.js"); -const { toUSDTBalances } = require("../helper/balances"); const { getConfig } = require('../helper/cache') -const chain = "godwoken"; - -async function tvl(ts, _block, chainBlocks) { - const balances = {}; +async function tvl(api) { const tokensAndOwners = []; const poolInfo = await getConfig('stable-koi-v0', "https://app.stablekoi.com/lists/poollist.json"); poolInfo.forEach((pool) => { pool.tokens.forEach((token) => tokensAndOwners.push([token, pool.address])); }); - await sumTokens(balances, tokensAndOwners, chainBlocks[chain], chain); - return balances + return api.sumTokens({ tokensAndOwners }) } -async function tvl_v1(ts, _block, chainBlocks) { - const balances = {}; - const chain = "godwoken_v1"; +async function tvl_v1(api) { const tokensAndOwners = []; - // const poolInfo = await get('https://app-v1.stablekoi.com/api/pools'); v1Pools.forEach((pool) => { pool.tokens.forEach((token) => tokensAndOwners.push([token.address, pool.address])); }); - await sumTokens(balances, tokensAndOwners, chainBlocks[chain], chain); - return balances + return api.sumTokens({ tokensAndOwners }) } -const yokaiInfoAPI = - "https://www.yokaiswap.com/subgraphs/name/yokaiswap/exchange"; -async function fetchTokenPriceFromYokaiSwap(token) { - const graphQLClient = new GraphQLClient(yokaiInfoAPI); - - const query = gql` - query tokens { - tokens(where:{id:\"${token.toLowerCase()}\"}) { - derivedUSD - } - } - `; - - const data = await graphQLClient.request(query); - - return (data.tokens[0] || { derivedUSD: 0 }).derivedUSD; -} - -const koi = "0xd66eb642eE33837531FdA61eb7Ab15B15658BcaB"; -const koiStakingRewards = "0x9d7AACf560e493A7B0666d85BDE216d6d38Ec429"; -async function staking(ts, _block, chainBlocks) { - const [{ output: totalStakedKOI }, { output: koiDecimals }, koiPrice] = - await Promise.all([ - sdk.api.abi.call({ - abi: abi.totalSupply, - target: koiStakingRewards, - chain, - block: chainBlocks[chain], - }), - sdk.api.erc20.decimals(koi, chain), - fetchTokenPriceFromYokaiSwap(koi), - ]); - - return toUSDTBalances( - BigNumber(totalStakedKOI) - .multipliedBy(BigNumber(koiPrice)) - .dividedBy(BigNumber(10).pow(BigNumber(koiDecimals))) - .toFixed(0) - ); +async function staking(api) { + const koi = "0xd66eb642eE33837531FdA61eb7Ab15B15658BcaB"; + const koiStakingRewards = "0x9d7AACf560e493A7B0666d85BDE216d6d38Ec429"; + const totalStakedKOI = await api.call({ abi: 'erc20:totalSupply', target: koiStakingRewards }) + api.add(koi, totalStakedKOI) } module.exports = { @@ -82,65 +34,39 @@ module.exports = { tvl: tvl_v1, }, hallmarks: [ - [Math.floor(new Date('2022-08-26')/1e3), "Add godwoken v1 chain tvl"], + [Math.floor(new Date('2022-08-26') / 1e3), "Add godwoken v1 chain tvl"], ], } const v1Pools = [ { - "name": "USDC|eth↔USDC|bsc", "address": "0xB76B94bA69f0C2c556ee86F57e57F5F20A705d18", "tokens": [ { - "name": "USD Coin (Ethereum)", "address": "0x186181e225dc1Ad85a4A94164232bD261e351C33", }, - { - "symbol": "USDC|bsc", - "address": ADDRESSES.godwoken_v1.USDC_bsc, - } + { "address": ADDRESSES.godwoken_v1.USDC_bsc, } ] }, { - "name": "USDC|eth↔USDT|eth", "address": "0xA1F83F8F142c1069d33a898498AFEA6257387133", "tokens": [ - { - "symbol": "USDC|eth", - "address": "0x186181e225dc1Ad85a4A94164232bD261e351C33", - }, - { - "symbol": "USDT|eth", - "address": "0x8E019acb11C7d17c26D334901fA2ac41C1f44d50", - } + { "address": "0x186181e225dc1Ad85a4A94164232bD261e351C33", }, + { "address": "0x8E019acb11C7d17c26D334901fA2ac41C1f44d50", } ] }, { - "name": "USDT|eth↔USDT|bsc", "address": "0x2c13f5DB105C6ab13ba183Abb7c0CBe38bE45A92", "tokens": [ - { - "symbol": "USDT|eth", - "address": "0x8E019acb11C7d17c26D334901fA2ac41C1f44d50", - }, - { - "symbol": "USDT|bsc", - "address": ADDRESSES.godwoken_v1.USDT_bsc, - } + { "address": "0x8E019acb11C7d17c26D334901fA2ac41C1f44d50", }, + { "address": ADDRESSES.godwoken_v1.USDT_bsc, } ] }, { - "name": "WBTC|eth↔BTCB|bsc", "address": "0x2360D9699dc82b684F986fBcc2ddf3Ab54Ff60dD", "tokens": [ - { - "symbol": "WBTC|eth", - "address": ADDRESSES.godwoken_v1.WBTC_eth, - }, - { - "symbol": "BTCB|bsc", - "address": ADDRESSES.godwoken_v1.BTCB_bsc, - } + { "address": ADDRESSES.godwoken_v1.WBTC_eth, }, + { "address": ADDRESSES.godwoken_v1.BTCB_bsc, } ] } ] \ No newline at end of file diff --git a/projects/stakedicp/index.js b/projects/stakedicp/index.js index 1f9728e2c097..54a68c79086f 100644 --- a/projects/stakedicp/index.js +++ b/projects/stakedicp/index.js @@ -1,4 +1,3 @@ -const BigNumber = require("bignumber.js"); const { get } = require("../helper/http"); const url = 'https://h6uvl-xiaaa-aaaap-qaawa-cai.raw.ic0.app/tvl'; @@ -10,7 +9,7 @@ async function tvl(_timestamp, _block) { throw new Error("Unknown"); } return { - "coingecko:internet-computer": BigNumber(tvl).div(1e8).toFixed(0), + "coingecko:internet-computer": tvl/1e8, }; }