diff --git a/projects/avax/index.js b/projects/avax/index.js index 9dd7d44ae..a9863f101 100644 --- a/projects/avax/index.js +++ b/projects/avax/index.js @@ -1,6 +1,6 @@ const ADDRESSES = require('../helper/coreAssets.json') -const { call } = require("@defillama/sdk/build/abi/abi2"); const { sumTokens2 } = require("../helper/unwrapLPs"); +const sdk = require('@defillama/sdk') module.exports = { ethereum: { @@ -14,7 +14,7 @@ module.exports = { bitcoin: { tvl: async (_, _b, chainBlocks) => ({ bitcoin: - (await call({ + (await sdk.api2.abi.call({ chain: "avax", abi: "erc20:totalSupply", target: ADDRESSES.avax.BTC_b, diff --git a/projects/cygnusdao/index.js b/projects/cygnusdao/index.js index fa267b64c..4ba07f226 100644 --- a/projects/cygnusdao/index.js +++ b/projects/cygnusdao/index.js @@ -1,7 +1,7 @@ const FACTORY_CONTRACT = "0x8796747946871B6b8ea495CCE8d7814b17959296"; const vaultAbi = require('../charmfinance/vaultAbi.json') const { getLogs } = require('../helper/cache/getLogs'); -const { getUniqueAddresses } = require("@defillama/sdk/build/generalUtil"); +const { getUniqueAddresses } = require('../helper/utils'); async function tvl(api) { let fromBlock = 0; diff --git a/projects/knightrade/index.js b/projects/knightrade/index.js index eaa7a1db8..10bc54c8e 100644 --- a/projects/knightrade/index.js +++ b/projects/knightrade/index.js @@ -1,4 +1,3 @@ -const { ETHER_ADDRESS } = require('@defillama/sdk/build/general') const ADDRESSES = require('../helper/coreAssets.json') const { getMultipleAccounts, getProvider } = require('../helper/solana') const { Program, BN } = require("@project-serum/anchor") @@ -144,7 +143,7 @@ async function tvlArbitrum(api) { [ADDRESSES.arbitrum.USDT, vault], [ADDRESSES.arbitrum.USDC_CIRCLE, vault], [ADDRESSES.arbitrum.WETH, vault], - [ETHER_ADDRESS, vault], + [ADDRESSES.null, vault], [ADDRESSES.arbitrum.WBTC, vault], // GMXv2 Earn [addresses.gmWeth, vault], diff --git a/projects/paladinfinance/abi.json b/projects/paladinfinance/abi.json deleted file mode 100644 index 24eaf5be6..000000000 --- a/projects/paladinfinance/abi.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "underlying": "address:underlying", - "underlyingBalance": "uint256:underlyingBalance", - "totalBorrowed": "uint256:totalBorrowed", - "totalReserve": "uint256:totalReserve" -} \ No newline at end of file diff --git a/projects/paladinfinance/index.js b/projects/paladinfinance/index.js index f38de2ad1..8a4fe5f02 100644 --- a/projects/paladinfinance/index.js +++ b/projects/paladinfinance/index.js @@ -1,8 +1,10 @@ const ADDRESSES = require('../helper/coreAssets.json') -const sdk = require("@defillama/sdk"); -const { sumSingleBalance } = require("@defillama/sdk/build/generalUtil"); -const abi = require("./abi.json"); -const BigNumber = require("bignumber.js"); +const abi = { + "underlying": "address:underlying", + "underlyingBalance": "uint256:underlyingBalance", + "totalBorrowed": "uint256:totalBorrowed", + "totalReserve": "uint256:totalReserve" +} const poolAddresses = [ "0x50bE5fE4de4efC3A0adAc6587254836972055423", //palCOMP @@ -11,51 +13,25 @@ const poolAddresses = [ "0xCDc3DD86C99b58749de0F697dfc1ABE4bE22216d" //palStkAAVE ] -async function ethTvl(timestamp, block) { +async function ethTvl(api) { - let balances = {}; + let calls = poolAddresses - let calls = []; - for(let i = 0; i < poolAddresses.length; i++) { - calls.push({target: poolAddresses[i]}) - } + let underlyingTokens = await api.multiCall({ calls, abi: abi["underlying"], }) + let underlyingBalances = await api.multiCall({ calls, abi: abi["underlyingBalance"], }); + let totalBorrowed = await api.multiCall({ calls, abi: abi["totalBorrowed"], }); + let totalReserve = await api.multiCall({ calls, abi: abi["totalReserve"], }) - let underlyingTokens = await sdk.api.abi.multiCall({ - calls, - abi: abi["underlying"], - block:block - }) + for (let i = 0; i < poolAddresses.length; i++) { + let token = underlyingTokens[i]; - let underlyingBalances = await sdk.api.abi.multiCall({ - calls, - abi: abi["underlyingBalance"], - block: block - }); - - let totalBorrowed = await sdk.api.abi.multiCall({ - calls, - abi: abi["totalBorrowed"], - block: block - }); - - let totalReserve = await sdk.api.abi.multiCall({ - calls, - abi: abi["totalReserve"], - block: block - }) - - for(let i = 0; i < poolAddresses.length; i++) { - let token = underlyingTokens.output[i].output; - //If stkAAVE address then change token address to AAVE address if (token === "0x4da27a545c0c5B758a6BA100e3a049001de870f5") { token = ADDRESSES.ethereum.AAVE; } - let tvl = BigNumber(underlyingBalances.output[i].output).plus(totalBorrowed.output[i].output).minus(totalReserve.output[i].output).toFixed(0); - sumSingleBalance(balances, token, tvl) + const tvl = +underlyingBalances[i] + +totalBorrowed[i] - +totalReserve[i]; + api.add(token, tvl) } - - return balances; } module.exports = { diff --git a/projects/rolldex/index.js b/projects/rolldex/index.js index 6c3a0d8ff..e51530171 100644 --- a/projects/rolldex/index.js +++ b/projects/rolldex/index.js @@ -1,35 +1,22 @@ -const { decimals } = require("@defillama/sdk/build/erc20"); -const { ethers, formatUnits } = require("ethers"); - const abi = { - totalValue: "function totalValue() view returns ((address tokenAddress, int256 value, uint8 decimals, int256 valueUsd, uint16 targetWeight,uint16 feeBasisPoints,uint16 taxBasisPoints, bool dynamicFee)[])", + totalValue: "function totalValue() view returns ((address tokenAddress, int256 value, uint8 decimals, int256 valueUsd, uint16 targetWeight,uint16 feeBasisPoints,uint16 taxBasisPoints, bool dynamicFee)[])", }; - const CONFIG = { - btr: '0x3d0E678776e4287BEfB0449d344D195ad1A2C418', - base: '0xa67998d867cd4b64fe9ecc1549341f1d86389c0f', +const CONFIG = { + btr: '0x3d0E678776e4287BEfB0449d344D195ad1A2C418', + base: '0xa67998d867cd4b64fe9ecc1549341f1d86389c0f', +}; + +const tvl = async (api) => { + const tokenInfo = await api.call({ abi: abi.totalValue, target: CONFIG[api.chain], }); + const tokens = tokenInfo.map(i => i.tokenAddress); + return api.sumTokens({ tokens, owners: [CONFIG[api.chain]] }); +} + +module.exports.methodology = "RollDex functions as a decentralized exchange for crypto derivatives. It offers on-chain perpetuals, providing traders and stakers with exceptional opportunities." + +Object.keys(CONFIG).forEach((chain) => { + module.exports[chain] = { + tvl, }; - - const queryTvlData = async (api,chain) => { - const tokenInfo = await api.call({ - abi: abi.totalValue, - target: CONFIG[chain], - params: [], - }); - - const bals = await api.multiCall({ abi: 'erc20:balanceOf', calls: tokenInfo.map(i => ({ target: i.tokenAddress, params: CONFIG[chain]})) }) - tokenInfo.forEach(async (item,key)=>{ - api.add(item.tokenAddress, bals[key]) - }) - return - } - module.exports.methodology = "RollDex functions as a decentralized exchange for crypto derivatives. It offers on-chain perpetuals, providing traders and stakers with exceptional opportunities." - - Object.keys(CONFIG).forEach((chain) => { - module.exports[chain] = { - tvl: (api) => queryTvlData(api, chain), - }; - }); - - - \ No newline at end of file +}) \ No newline at end of file diff --git a/projects/rsk-bridge/index.js b/projects/rsk-bridge/index.js index 9870f9d69..a5e54805c 100644 --- a/projects/rsk-bridge/index.js +++ b/projects/rsk-bridge/index.js @@ -1,20 +1,15 @@ const ADDRESSES = require("../helper/coreAssets.json"); const { sumTokensExport } = require("../helper/unwrapLPs"); -const { getBalance } = require("@defillama/sdk/build/eth"); -const { getBlock } = require("@defillama/sdk/build/util/blocks"); +const sdk = require('@defillama/sdk') module.exports = { bitcoin: { tvl: async (api) => { - const block = (await getBlock("rsk", api.timestamp)).block; - const unminted = - ( - await getBalance({ - target: "0x0000000000000000000000000000000001000006", - chain: "rsk", - block, - }) - ).output / 1e18; + const rskApi = new sdk.ChainApi({ chain: "rsk", timestamp: api.timestamp }); + const block = await rskApi.getBlock() + const unminted = ( + await sdk.api.eth.getBalance({ target: "0x0000000000000000000000000000000001000006", chain: "rsk", block, }) + ).output / 1e18; const minted = 21e6 - unminted; diff --git a/projects/syncnetwork/index.js b/projects/syncnetwork/index.js index 427c71fa9..3ba7856c8 100644 --- a/projects/syncnetwork/index.js +++ b/projects/syncnetwork/index.js @@ -1,54 +1,19 @@ -const sdk = require("@defillama/sdk"); -const { sumSingleBalance } = require("@defillama/sdk/build/generalUtil"); -const abi = require("./abi.json"); +const { pool2 } = require("../helper/pool2"); const syncToken = "0xB6ff96B8A8d214544Ca0dBc9B33f7AD6503eFD32" // SYNC const uniPair = "0xFb2F545A9AD62F38fe600E24f75ecD790d30a7Ba"; // SYNC-ETH PAIR const cBond = "0xC6c11F32D3ccC3BEaac68793bC3BFBe82838ca9F"; // CBOND contract -async function pool2(timestamp, block) { - let balances = {}; - let { output: token0 } = await sdk.api.abi.call({ - target: uniPair, - abi: abi["token0"], - block, - }); - - let { output: token1 } = await sdk.api.abi.call({ - target: uniPair, - abi: abi["token1"], - block, - }); - - let { output: tokenBalances } = await sdk.api.abi.call({ - target: uniPair, - abi: abi["getReserves"], - block, - }); - - sdk.util.sumSingleBalance(balances, token0, tokenBalances._reserve0); - sdk.util.sumSingleBalance(balances, token1, tokenBalances._reserve1); - return balances; -} - -async function staked(timestamp, block) { - let balances = {}; - - let { output: lockedSync } = await sdk.api.abi.call({ - target: cBond, - abi: abi["totalSYNCLocked"], - block, - }); - - sumSingleBalance(balances, syncToken, lockedSync); - return balances; +async function staking(api) { + let lockedSync = await api.call({ target: cBond, abi: "uint256:totalSYNCLocked" }); + api.add(syncToken, lockedSync); } module.exports = { methodology:"Pool2 is the SYNC-ETH pair on UNI and staking according to their FAQ are SYNC tokens locked into CBOND contracts", ethereum:{ - pool2, - staking: staked, + pool2: pool2('0xc6c11f32d3ccc3beaac68793bc3bfbe82838ca9f', uniPair), + staking, tvl: async () => ({}), } }; diff --git a/projects/wbtc.js b/projects/wbtc.js index dfee59136..bac409c6e 100644 --- a/projects/wbtc.js +++ b/projects/wbtc.js @@ -2,7 +2,6 @@ const { sumTokens } = require("./helper/sumTokens"); const ADDRESSES = require('./helper/coreAssets.json') const bitcoinAddressBook = require('./helper/bitcoin-book/index.js') const sdk = require('@defillama/sdk'); -const { getBlock } = require("@defillama/sdk/build/util/blocks.js"); // WALLETS FROM HERE https://wbtc.network/dashboard/audit const owners = bitcoinAddressBook.wbtc @@ -12,7 +11,7 @@ async function tvl(api){ return sumTokens({ owners, api }) } else { // get WBTC supply on Ethereum blockchain - const block = await getBlock('ethereum', api.timestamp) + const block = await sdk.blocks.getBlock('ethereum', api.timestamp) const supply = await sdk.api2.abi.call({ chain: 'ethereum', target: ADDRESSES.ethereum.WBTC, abi: 'erc20:totalSupply', block: block.number }) api.add(ADDRESSES.ethereum.WBTC, supply) return {[`ethereum:${ADDRESSES.ethereum.WBTC}`]: supply} diff --git a/projects/wormhole.js b/projects/wormhole.js index 2ccdf78f2..0714b0860 100644 --- a/projects/wormhole.js +++ b/projects/wormhole.js @@ -2,7 +2,6 @@ const { get } = require("./helper/http"); const url = "https://europe-west3-wormhole-message-db-mainnet.cloudfunctions.net/tvl"; let _response; -const { sumSingleBalance } = require("@defillama/sdk/build/generalUtil"); const chainMap = { solana: "1", @@ -43,18 +42,16 @@ module.exports = { Object.keys(chainMap).forEach((chain) => { module.exports[chain] = { - tvl: async () => { + tvl: async (api) => { if (!_response) _response = get(url); const res = await _response; const chainId = chainMap[chain]; if (!(chainId in res.AllTime)) return; - const balances = {}; Object.values(res.AllTime[chainId]).map((c) => { - sumSingleBalance(balances, c.CoinGeckoId, c.Amount, ""); + api.addCGToken(c.CoinGeckoId, c.Amount) }); - return balances; }, }; }); diff --git a/utils/scripts/testTokenMapping.js b/utils/scripts/testTokenMapping.js index e9fab0b92..7462f4063 100644 --- a/utils/scripts/testTokenMapping.js +++ b/utils/scripts/testTokenMapping.js @@ -1,7 +1,7 @@ -const { sliceIntoChunks } = require('@defillama/sdk/build/util') const { default: PromisePool } = require('@supercharge/promise-pool/dist') const { default: axios } = require('axios') const mapping = require('../../../server/coins/src/adapters/tokenMapping.json') +const { sliceIntoChunks } = require('../../projects/helper/utils') const tokens = Object.entries(mapping).map(i => { const [chain, obj] = i