diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f57c842316..c786607c35 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,9 +32,9 @@ jobs: { node ${{ github.workspace }}/test.js ${{ github.workspace }}/${i} 2>&1 | tee output.txt node ${{ github.workspace }}/.github/workflows/commentResult.js /home/runner/work/DefiLlama-Adapters/DefiLlama-Adapters/output.txt "${{ github.repository_owner }}" "${{ github.event.repository.name }}" "${{ github.event.number }}" ${i} - if grep -q "\-\-\-\- ERROR \-\-\-\-" output.txt; then - exit 1; - fi + # if grep -q "\-\-\-\- ERROR \-\-\-\-" output.txt; then + # exit 1; + # fi } || { echo -n $i echo ' doesnt run' diff --git a/package-lock.json b/package-lock.json index 75c4be5f17..c854f34fea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,8 +32,7 @@ "js-sha512": "^0.8.0", "miscreant": "^0.3.2", "secure-random": "^1.1.2", - "tron-format-address": "^0.1.8", - "underscore": "^1.13.1" + "tron-format-address": "^0.1.8" }, "devDependencies": { "inquirer": "^8.2.4", @@ -3780,11 +3779,6 @@ "is-typedarray": "^1.0.0" } }, - "node_modules/underscore": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.3.tgz", - "integrity": "sha512-QvjkYpiD+dJJraRA8+dGAU4i7aBbb2s0S3jA45TFOvg2VgqvdCDd/3N6CqA8gluk1W91GLoXg5enMUx560QzuA==" - }, "node_modules/utf-8-validate": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.9.tgz", @@ -6728,11 +6722,6 @@ "is-typedarray": "^1.0.0" } }, - "underscore": { - "version": "1.13.3", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.3.tgz", - "integrity": "sha512-QvjkYpiD+dJJraRA8+dGAU4i7aBbb2s0S3jA45TFOvg2VgqvdCDd/3N6CqA8gluk1W91GLoXg5enMUx560QzuA==" - }, "utf-8-validate": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.9.tgz", diff --git a/package.json b/package.json index 574ff042a1..5970ea33aa 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,7 @@ "js-sha512": "^0.8.0", "miscreant": "^0.3.2", "secure-random": "^1.1.2", - "tron-format-address": "^0.1.8", - "underscore": "^1.13.1" + "tron-format-address": "^0.1.8" }, "overrides": { "ansi-regex": "5.0.1", diff --git a/projects/88mph/index.js b/projects/88mph/index.js index 0c09e26b56..5ebcbe4e57 100644 --- a/projects/88mph/index.js +++ b/projects/88mph/index.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk') const abi = require('./abi') -const _ = require('underscore') + const BigNumber = require('bignumber.js') const { default: axios } = require('axios') const { chainExports } = require('../helper/exports') @@ -78,7 +78,7 @@ function chainTvl(chain) { // Get deposit pools' underlying tokens const poolUnderlyingAddressResults = await sdk.api.abi.multiCall({ - calls: _.map(dInterestAddresses, (address) => ({ + calls: dInterestAddresses.map((address) => ({ target: address })), block, @@ -86,7 +86,7 @@ function chainTvl(chain) { abi: abi.stablecoin }) - _.each(poolUnderlyingAddressResults.output, (token) => { + poolUnderlyingAddressResults.output.forEach((token) => { const underlyingTokenAddress = token.output if(underlyingTokenAddress === null){ throw new Error(`token ${token} is broken`) @@ -98,14 +98,14 @@ function chainTvl(chain) { // Get deposit pools' balances in underlying token const poolDepositBalanceResults = await sdk.api.abi.multiCall({ block, - calls: _.map(dInterestAddresses, (address) => ({ + calls: dInterestAddresses.map((address) => ({ target: address })), chain, abi: abi.totalDeposit }) - _.each(poolDepositBalanceResults.output, (tokenBalanceResult) => { + poolDepositBalanceResults.output.forEach((tokenBalanceResult) => { let valueInToken = tokenBalanceResult.output const poolAddress = tokenBalanceResult.input.target let underlyingTokenAddress = poolToUnderlyingToken[poolAddress] diff --git a/projects/acoconut/index.js b/projects/acoconut/index.js index 2ab7e30c51..e2fadb612c 100644 --- a/projects/acoconut/index.js +++ b/projects/acoconut/index.js @@ -1,7 +1,7 @@ const sdk = require('@defillama/sdk'); const vaultAbi = require('./abis/vault'); const singlePlusAbi = require('./abis/singlePlus'); -const _ = require('underscore'); + const BigNumber = require('bignumber.js'); const tokensInacBTC = [ @@ -45,14 +45,14 @@ async function bsc(timestamp, block, chainBlocks) { const totalUnderlyingResults = await sdk.api.abi.multiCall({ block: bscBlock.block, - calls: _.map(bscSingleTokens, (address) => ({ + calls: bscSingleTokens.map((address) => ({ target: address })), abi: singlePlusAbi["totalUnderlying"], chain: 'bsc' }); - _.each(totalUnderlyingResults.output, (tokenBalanceResult) => { + totalUnderlyingResults.output.forEach((tokenBalanceResult) => { const valueInToken = tokenBalanceResult.output; const singleTokenAddress = tokenBalanceResult.input.target; balances[btcb] = BigNumber(balances[btcb]).plus(valueInToken).toFixed(0); diff --git a/projects/auctus/index.js b/projects/auctus/index.js index 7e25145f71..07d3ca4d8d 100644 --- a/projects/auctus/index.js +++ b/projects/auctus/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); + const abi = require('./abi.json'); const { default: BigNumber } = require('bignumber.js'); @@ -74,7 +74,7 @@ let collateralResult = await sdk.api.abi.multiCall({ block, - calls: _.map(acoOptionsAddresses, (option) => ({ + calls: acoOptionsAddresses.map((option) => ({ target: option })), abi: abi.collateral, @@ -82,13 +82,13 @@ let collateralAddressMap = {} - _.each(collateralResult.output, (result) => { + collateralResult.output.forEach((result) => { collateralAddressMap[result.input.target] = result.output; }); let totalCollateralResult = await sdk.api.abi.multiCall({ block, - calls: _.map(acoOptionsAddresses, (option) => ({ + calls: acoOptionsAddresses.map((option) => ({ target: option })), abi: abi.totalCollateral, @@ -97,7 +97,7 @@ let balances = {} balances[ETHER_ADDRESS] = "0" - _.each(totalCollateralResult.output, (result) => { + totalCollateralResult.output.forEach((result) => { var colateralAddress = collateralAddressMap[result.input.target].toLowerCase() if (!balances[colateralAddress]) { balances[colateralAddress] = "0" @@ -116,12 +116,12 @@ acoPools[address] = {underlying: underlyingAddress, strikeAsset: strikeAssetAddress} }); - let poolCallsMap = _.map(acoPools, (poolData, poolAddress) => ({ + let poolCallsMap = acoPools.map((poolData, poolAddress) => ({ target: poolData.underlying, params: poolAddress, })) - poolCallsMap = poolCallsMap.concat(_.map(acoPools, (poolData, poolAddress) => ({ + poolCallsMap = poolCallsMap.concat(acoPools.map((poolData, poolAddress) => ({ target: poolData.strikeAsset, params: poolAddress, }))) @@ -153,7 +153,7 @@ let balancesResult = await sdk.api.abi.multiCall({ block, - calls: _.map(acoVaultsAddresses, (vault) => ({ + calls: acoVaultsAddresses.map((vault) => ({ target: vault })), abi: abi.balance, @@ -161,13 +161,13 @@ let tokensResult = await sdk.api.abi.multiCall({ block, - calls: _.map(acoVaultsAddresses, (vault) => ({ + calls: acoVaultsAddresses.map((vault) => ({ target: vault })), abi: abi.token, }); - _.each(balancesResult.output, (result, index) => { + balancesResult.output.forEach((result, index) => { var token = tokensResult.output[index].output.toLowerCase() var balance = result.output; balances[token] = BigNumber(balances[token]).plus(new BigNumber(balance)).toFixed(); diff --git a/projects/balancer/onchain.js b/projects/balancer/onchain.js index a2257d303d..7872f8e58b 100644 --- a/projects/balancer/onchain.js +++ b/projects/balancer/onchain.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); -const _ = require('underscore'); + const { request, gql } = require("graphql-request"); const { transformArbitrumAddress } = require('../helper/portedTokens') const { requery } = require('../helper/requery') @@ -31,7 +31,7 @@ async function v1(timestamp, block) { let poolCalls = []; - let pools = _.map(poolLogs.output, (poolLog) => { + let pools = poolLogs.output.map((poolLog) => { if (poolLog.topics) { return `0x${poolLog.topics[2].slice(26)}` } else { @@ -40,15 +40,15 @@ async function v1(timestamp, block) { }); const poolTokenData = (await sdk.api.abi.multiCall({ - calls: _.map(pools, (poolAddress) => ({ target: poolAddress })), + calls: pools.map((poolAddress) => ({ target: poolAddress })), abi: abi.getCurrentTokens, })).output; - _.forEach(poolTokenData, (poolToken) => { + poolTokenData.forEach((poolToken) => { let poolTokens = poolToken.output; let poolAddress = poolToken.input.target; - _.forEach(poolTokens, (token) => { + poolTokens.forEach((token) => { if(ignored.includes(token)){ return } @@ -94,7 +94,7 @@ function v2(chain) { tokenAddresses.push(address.address) } } - tokenAddresses = _.uniq(tokenAddresses); + tokenAddresses = [...new Set(tokenAddresses)] let v2Calls = tokenAddresses.map((address) => { return { diff --git a/projects/bearnfi/index.js b/projects/bearnfi/index.js index 479c2bc932..c8ef42493e 100644 --- a/projects/bearnfi/index.js +++ b/projects/bearnfi/index.js @@ -1,5 +1,5 @@ const sdk = require("@defillama/sdk"); -const _ = require("underscore"); + const { unwrapUniswapLPs } = require("../helper/unwrapLPs"); const { transformBscAddress } = require("../helper/portedTokens"); const tvlOnPairs = require("../helper/processPairs.js"); @@ -101,7 +101,7 @@ async function bscTvl(timestamp, chainBlocks) { await sdk.api.abi.multiCall({ block: chainBlocks["bsc"], chain: "bsc", - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market, })), abi: abiFork.getCash, @@ -112,7 +112,7 @@ async function bscTvl(timestamp, chainBlocks) { await sdk.api.abi.multiCall({ block: chainBlocks["bsc"], chain: "bsc", - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market, })), abi: abiFork.underlying, diff --git a/projects/bprotocol/index.js b/projects/bprotocol/index.js index bafe6068f4..81dff34177 100644 --- a/projects/bprotocol/index.js +++ b/projects/bprotocol/index.js @@ -2,7 +2,7 @@ Modules ==================================================*/ - const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const abi = require('./abi.json'); const BigNumber = require("bignumber.js"); @@ -209,7 +209,8 @@ // combine balances for Maker and Compound B.Protocol's TVL const allLendingPlatformBalances = {} // all assets in B.Protocol - _.uniq(Object.keys(cTvl).concat(Object.keys(mTvl)).concat(Object.keys(lTvl))).forEach(asset => { + const uniq = arry => [... new Set(arry)] + uniq(Object.keys(cTvl).concat(Object.keys(mTvl)).concat(Object.keys(lTvl))).forEach(asset => { allLendingPlatformBalances[asset] = new BigNumber(cTvl[asset] || "0").plus(new BigNumber(mTvl[asset] || "0")).plus(new BigNumber(lTvl[asset] || "0")).toString(10) }) diff --git a/projects/complifi/index.js b/projects/complifi/index.js index d49fef727a..20307a14e6 100644 --- a/projects/complifi/index.js +++ b/projects/complifi/index.js @@ -1,4 +1,4 @@ -const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const abi = require('./abi.json'); @@ -28,7 +28,7 @@ async function chainTvlV2(chain, block, transformAddr) { let poolCollaterals = (await sdk.api.abi.multiCall({ block, - calls: _.map(pools, (pool) => ({ + calls: pools.map((pool) => ({ target: pool, })), chain, @@ -37,7 +37,7 @@ async function chainTvlV2(chain, block, transformAddr) { let poolBalances = await sdk.api.abi.multiCall({ block, - calls: _.map(pools, (pool, index) => ({ + calls: pools.map((pool, index) => ({ target: poolCollaterals[index], params: pool, })), @@ -76,7 +76,7 @@ async function chainTvl(chain, block, transformAddr) { let vaultCollaterals = (await sdk.api.abi.multiCall({ block, - calls: _.map(vaults, (vault) => ({ + calls: vaults.map((vault) => ({ target: vault, })), chain, @@ -85,7 +85,7 @@ async function chainTvl(chain, block, transformAddr) { let vaultBalances = await sdk.api.abi.multiCall({ block, - calls: _.map(vaults, (vault,index) => ({ + calls: vaults.map((vault,index) => ({ target: vaultCollaterals[index].output, params: vault, })), diff --git a/projects/compound-onchain/index.js b/projects/compound-onchain/index.js index 1232649fe9..cb90ce56d2 100644 --- a/projects/compound-onchain/index.js +++ b/projects/compound-onchain/index.js @@ -1,4 +1,4 @@ -const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const abi = require('./abi.json'); const v1abi = require('./v1Abi.json'); @@ -157,7 +157,7 @@ async function v2Tvl(balances, block, borrowed){ // Get V1 tokens locked let v1Locked = await sdk.api.abi.multiCall({ block, - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.underlying, params: '0x3FDA67f7583380E67ef93072294a7fAc882FD7E7', })), @@ -169,14 +169,14 @@ async function v2Tvl(balances, block, borrowed){ // Get V2 tokens locked let v2Locked = await sdk.api.abi.multiCall({ block, - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.cToken, })), abi: borrowed?abi.totalBorrows: abi['getCash'], }); - _.each(markets, (market) => { - let getCash = _.find(v2Locked.output, (result) => result.input.target === market.cToken); + markets.forEach((market) => { + let getCash = v2Locked.output.find((result) => result.input.target === market.cToken); balances[market.underlying] = BigNumber(balances[market.underlying] || 0) .plus(getCash.output) .toFixed(); @@ -197,7 +197,7 @@ async function tvl(timestamp, block) { // Get V1 tokens locked let v1Locked = await sdk.api.abi.multiCall({ block, - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.underlying, params: v1Contract, })), diff --git a/projects/core/index.js b/projects/core/index.js index 8b93d5c4df..ae74bd66fe 100644 --- a/projects/core/index.js +++ b/projects/core/index.js @@ -1,4 +1,4 @@ -const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const BigNumber = require("bignumber.js"); const getReserves = require('./abis/uniswap/getReserves.json'); @@ -42,7 +42,7 @@ async function getUniswapPairInfo(pairAddresses, timestamp, block) { .then(({ output }) => output.map(value => value.output)), sdk.api.abi.multiCall({ abi: token1, - calls: _.map(pairAddresses, (pairAddress) => ({ + calls: pairAddresses.map((pairAddress) => ({ target: pairAddress, })), block, @@ -50,7 +50,7 @@ async function getUniswapPairInfo(pairAddresses, timestamp, block) { .then(({ output }) => output.map(value => value.output)), sdk.api.abi.multiCall({ abi: getReserves, - calls: _.map(pairAddresses, (pairAddress) => ({ + calls: pairAddresses.map((pairAddress) => ({ target: pairAddress, })), block, @@ -58,7 +58,7 @@ async function getUniswapPairInfo(pairAddresses, timestamp, block) { .then(({ output }) => output.map(value => value.output)), sdk.api.abi.multiCall({ block, - calls: _.map(pairAddresses, pairAddress => ({ + calls: pairAddresses.map(pairAddress => ({ target: pairAddress })), abi: 'erc20:totalSupply', @@ -112,12 +112,14 @@ async function getTokenUnderlyingReserves(token, defaultReserve, _timestamp, blo }); const wrappedTokenCount = parseInt(numTokensWrappedResponse.output); - const getTokenInfoCalls = _.range(wrappedTokenCount).map(i => ({ - target: token, - params: [i], - abi: getTokenInfo, - block - })); + const getTokenInfoCalls = [] + for (let i = 0;i < wrappedTokenCount; i++) + getTokenInfoCalls.push({ + target: token, + params: [i], + abi: getTokenInfo, + block + }) const tokenInfoResponse = await sdk.api.abi.multiCall({ block, @@ -141,10 +143,10 @@ async function getTokenUnderlyingReserves(token, defaultReserve, _timestamp, blo function flattenUnderlyingReserves(underlyingReserves) { const reserves = {}; - _.each(underlyingReserves, pairReserves => { - _.each(pairReserves, tokenReserves => { - _.each(tokenReserves, underlyingReserves => { - _.each(Object.keys(underlyingReserves), address => { + underlyingReserves.forEach(pairReserves => { + pairReserves.forEach(tokenReserves => { + tokenReserves.forEach(underlyingReserves => { + Object.keys(underlyingReserves).forEach(address => { const tokenReserve = new BigNumber(underlyingReserves[address]); reserves[address] = (reserves[address] || zero).plus(tokenReserve); }); @@ -152,7 +154,7 @@ function flattenUnderlyingReserves(underlyingReserves) { }); }); - _.each(Object.keys(reserves), address => { + Object.keys(reserves).forEach(address => { reserves[address] = reserves[address].toFixed(); }); diff --git a/projects/creamswap/index.js b/projects/creamswap/index.js index 64d80c3deb..5ced8414df 100644 --- a/projects/creamswap/index.js +++ b/projects/creamswap/index.js @@ -2,7 +2,7 @@ Modules ==================================================*/ - const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const abi = require('./abi.json'); const BigNumber = require('bignumber.js'); @@ -68,20 +68,20 @@ let poolCalls = []; - let pools = _.map(poolLogs.output, (poolLog) => { + let pools = poolLogs.output.map((poolLog) => { return `0x${poolLog[2].slice(26)}` }); const poolTokenData = (await sdk.api.abi.multiCall({ - calls: _.map(pools, (poolAddress) => ({ target: poolAddress })), + calls: pools.map((poolAddress) => ({ target: poolAddress })), abi: abi.getCurrentTokens, })).output; - _.forEach(poolTokenData, (poolToken) => { + poolTokenData.forEach((poolToken) => { let poolTokens = poolToken.output; let poolAddress = poolToken.input.target; - _.forEach(poolTokens, (token) => { + poolTokens.forEach((token) => { poolCalls.push({ target: token, params: poolAddress, @@ -95,7 +95,7 @@ abi: 'erc20:balanceOf' })).output; - _.each(poolBalances, (balanceOf) => { + poolBalances.forEach((balanceOf) => { let balance = balanceOf.output; let address = balanceOf.input.target; @@ -108,7 +108,7 @@ let underlyingBalanceCalls = []; let underlyingAddressCalls = []; - _.filter(poolBalances, (poolBalance) => isCrToken(poolBalance.input.target)).forEach(pooBalance => { + poolBalances.filter((poolBalance) => isCrToken(poolBalance.input.target)).forEach(pooBalance => { underlyingBalanceCalls.push({ target: pooBalance.input.target, params: pooBalance.input.params, @@ -149,7 +149,7 @@ yCrvPrice = yCrvPrice.output; // convert cTokens into underlying tokens - _.each(underlyingBalances, (underlying, i) => { + underlyingBalances.forEach((underlying, i) => { let balance = underlying.output; let address = underlyingAddress[i].output; let cAddress = underlying.input.target; @@ -158,7 +158,7 @@ }) // convert vault tokens into underlying values - _.each(poolBalances, (balanceOf, i) => { + poolBalances.forEach((balanceOf, i) => { let balance = balanceOf.output; let address = balanceOf.input.target; diff --git a/projects/curve/historical.js b/projects/curve/historical.js index e8875a4de0..f7b32ddb8d 100644 --- a/projects/curve/historical.js +++ b/projects/curve/historical.js @@ -1,7 +1,5 @@ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); - _.flatMap = _.compose(_.flatten, _.map); /*================================================== TVL @@ -39,9 +37,9 @@ let coins = [2, 2, 2, 3, 4, 4, 2, 4, 4, 2, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2] - let balancesCalls = _.flatMap(swaps, (token, i) => { + let balancesCalls = swaps.flatMap((token, i) => { return Array.from(Array(coins[i]), (e, idx) =>({target: token, params: idx})) - }) + }).flat() balancesCalls = balancesCalls.filter(call => !(call.target == '0xeDf54bC005bc2Df0Cc6A675596e843D28b16A966' && call.params == 1)) let balancesResults = await sdk.api.abi.multiCall({ @@ -92,9 +90,9 @@ }, }) - let coinsCalls = _.flatMap(swaps, (token, i) => { + let coinsCalls = swaps.flatMap((token, i) => { return Array.from(Array(coins[i]), (e, idx) =>({target: token, params: idx})) - }) + }).flat() coinsCalls = coinsCalls.filter(call => !(call.target == '0xeDf54bC005bc2Df0Cc6A675596e843D28b16A966' && call.params == 1)) let coinsResults = await sdk.api.abi.multiCall({ diff --git a/projects/ddex/index.js b/projects/ddex/index.js index d3dd313ee0..505b615971 100644 --- a/projects/ddex/index.js +++ b/projects/ddex/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require('@defillama/sdk'); -const _ = require('underscore'); + const axios = require('axios'); const BigNumber = require('bignumber.js'); const ddexMarginContractAddress = '0x241e82c79452f51fbfc89fac6d912e021db1a3b7' @@ -15,13 +15,13 @@ const ddexMarginContractAddress = '0x241e82c79452f51fbfc89fac6d912e021db1a3b7' async function GenerateCallList() { let assets = await axios.get('https://api.ddex.io/v4/assets'); assets = assets.data.data.assets; - assets = _.filter(assets, (asset) => { + assets = assets.filter((asset) => { let symbol = asset.symbol; return symbol !== "ETH"; }); let calls = []; - _.each(assets, (asset) => { + assets.forEach((asset) => { calls.push({ target: asset.address, params: ddexMarginContractAddress diff --git a/projects/defrost/index.js b/projects/defrost/index.js index 07577c9d94..282e9af715 100644 --- a/projects/defrost/index.js +++ b/projects/defrost/index.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js'); -const _ = require('underscore'); + const abi = require('./abi'); const {gql, request} = require('graphql-request') const {getApiTvl} = require('../helper/historicalApi') diff --git a/projects/derivadex/index.js b/projects/derivadex/index.js index 7611789332..f238348721 100644 --- a/projects/derivadex/index.js +++ b/projects/derivadex/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require("@defillama/sdk"); -const _ = require("underscore"); + /*================================================== Settings @@ -32,8 +32,8 @@ async function tvl(timestamp, block) { let calls = []; - _.each(addressList, (address) => { - _.each(tokenAddresses, (tokenAddress) => { + addressList.forEach((address) => { + tokenAddresses.forEach((tokenAddress) => { calls.push({ target: tokenAddress, params: address, diff --git a/projects/dextf/v1.js b/projects/dextf/v1.js index a0b2349b1a..fbad986d2d 100644 --- a/projects/dextf/v1.js +++ b/projects/dextf/v1.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js'); -const _ = require('underscore'); + const axios = require('axios'); /*================================================== @@ -35,7 +35,7 @@ module.exports = async function tvl(timestamp, block) { // Vault Asset Balances let balanceOfResults = await sdk.api.abi.multiCall({ block, - calls: _.map(tokensList, (token) => { + calls: tokensList.map((token) => { return { target: token, params: vaultAddress @@ -47,7 +47,7 @@ module.exports = async function tvl(timestamp, block) { // cToken Exchange Rates let cTokenConversionRatesMap = (await sdk.api.abi.multiCall({ block, - calls: _.map(Object.keys(cTokensMap), (cToken) => { + calls: Object.keys(cTokensMap).map((cToken) => { return { target: cToken } @@ -70,7 +70,7 @@ module.exports = async function tvl(timestamp, block) { }, {}); // Compute Balances - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target if (address in cTokensMap) { diff --git a/projects/dextf/v2.js b/projects/dextf/v2.js index b2191173e4..9b9398a687 100644 --- a/projects/dextf/v2.js +++ b/projects/dextf/v2.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js'); -const _ = require('underscore'); + const SUPPLY_SCALE = BigNumber("10").pow(18) const START_BLOCK = 12783638; @@ -43,7 +43,7 @@ module.exports = async function tvl(timestamp, block) { let supplies = (await sdk.api.abi.multiCall({ abi: totalSupply, block, - calls: _.map(setAddresses, (setAddress) => { + calls: setAddresses.map((setAddress) => { return { target: setAddress, } @@ -53,7 +53,7 @@ module.exports = async function tvl(timestamp, block) { let positionsForSets = (await sdk.api.abi.multiCall({ abi: getPositions, block, - calls: _.map(setAddresses, (setAddress) => { + calls: setAddresses.map((setAddress) => { return { target: setAddress, } @@ -61,9 +61,9 @@ module.exports = async function tvl(timestamp, block) { })).output; let uniswapPositions = {}; - _.each(positionsForSets, function(positionForSet, i) { + positionsForSets.forEach(function(positionForSet, i) { const setSupply = BigNumber(supplies[i].output); - _.each(positionForSet.output, (position) => { + positionForSet.output.forEach((position) => { const componentAddress = position[0]; const positionUnits = BigNumber(position[2]); @@ -88,14 +88,14 @@ module.exports = async function tvl(timestamp, block) { let reserveSupplies = (await sdk.api.abi.multiCall({ abi: totalSupply, block, - calls: _.map(Object.keys(uniswapPositions), (pairAddress) => { + calls: Object.keys(uniswapPositions).map((pairAddress) => { return { target: pairAddress, } }), })).output; - _.each(reserves, function(reserve, i) { + reserves.forEach(function(reserve, i) { const pairAddress = reserve.input.target; const tokenPair = pairAddresses[pairAddress]; const setSupplyRatio = new BigNumber(uniswapPositions[pairAddress]).div(new BigNumber(reserveSupplies[i].output)).div(SUPPLY_SCALE); diff --git a/projects/dforce/index.js b/projects/dforce/index.js index 8b06b55574..deaac605e8 100644 --- a/projects/dforce/index.js +++ b/projects/dforce/index.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); + const BigNumber = require('bignumber.js'); const abi = require('./abi.json'); const BASE = BigNumber(10 ** 18) diff --git a/projects/dydx/index.js b/projects/dydx/index.js index 3f6a379d3e..0e173d45b1 100644 --- a/projects/dydx/index.js +++ b/projects/dydx/index.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); + const BigNumber = require("bignumber.js"); const contracts = [ @@ -19,10 +19,10 @@ const balances = {}; let balanceOfCalls = []; - _.forEach(contracts, (contract) => { + contracts.forEach((contract) => { balanceOfCalls = [ ...balanceOfCalls, - ..._.map(tokens, (token) => ({ + ...tokens.map((token) => ({ target: token, params: contract })) diff --git a/projects/erasure/index.js b/projects/erasure/index.js index bc4ed302e4..77f4213f65 100644 --- a/projects/erasure/index.js +++ b/projects/erasure/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require("@defillama/sdk"); - const _ = require("underscore"); + const BigNumber = require("bignumber.js"); const abi = require('./abi.json'); @@ -35,7 +35,7 @@ // instances count for each registry const instanceCounts = ( await sdk.api.abi.multiCall({ - calls: _.map(registryAddresses, (registryAddress) => { + calls: registryAddresses.map((registryAddress) => { return { target: registryAddress } @@ -46,7 +46,7 @@ let paginatedInstancesCalls = []; - _.each(instanceCounts, (instanceCount) => { + instanceCounts.forEach((instanceCount) => { const registryAddress = instanceCount.input.target; const count = Number(instanceCount.output); @@ -75,19 +75,19 @@ let instanceAddresses = []; - _.each(paginatedInstances, (instances) => { + paginatedInstances.forEach((instances) => { instanceAddresses = [ ...instanceAddresses, ...instances.output ] }); - instanceAddresses = _.uniq(instanceAddresses); + instanceAddresses = [... new Set(instanceAddresses)] let balanceOfCalls = []; - _.each(instanceAddresses, (instanceAddress) => { - _.each(tokenAddresses, (tokenAddress) => { + instanceAddresses.forEach((instanceAddress) => { + tokenAddresses.forEach((tokenAddress) => { balanceOfCalls.push({ target: tokenAddress, params: [instanceAddress] @@ -103,7 +103,7 @@ }); // sum token balances across contracts - _.each(balanceOfResults.output, balanceOf => { + balanceOfResults.output.forEach(balanceOf => { let balance = balanceOf.output; let address = balanceOf.input.target; diff --git a/projects/evolutionland/index.js b/projects/evolutionland/index.js index 8f787643b5..aaed0d5b5e 100644 --- a/projects/evolutionland/index.js +++ b/projects/evolutionland/index.js @@ -1,6 +1,6 @@ const BigNumber = require('bignumber.js') const sdk = require('@defillama/sdk') -const _ = require('underscore'); + const gold = { "ethereum": "0x358dBA28848cca268BA8a76B65E5b3eF9Ef92238", @@ -238,7 +238,7 @@ async function ethTvl(timestamp, blocks) { async function stakingBalanceTvl(timestamp, block, chain, lps) { const balancesOfResult = await sdk.api.abi.multiCall({ - calls: _.map(lps, (lp) => ({ + calls: lps.map((lp) => ({ target: lp.target, params: lp.params })), diff --git a/projects/filda/index.js b/projects/filda/index.js index 32e5575ea9..05dd6978bb 100644 --- a/projects/filda/index.js +++ b/projects/filda/index.js @@ -1,4 +1,4 @@ -const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const abi = require('./abi.json'); const { getBlock } = require('../helper/getBlock') @@ -83,7 +83,7 @@ function lending(borrowed) { let v2Locked = await sdk.api.abi.multiCall({ block, - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.cToken, })), chain: 'heco', @@ -92,7 +92,7 @@ function lending(borrowed) { const symbols = await sdk.api.abi.multiCall({ block, - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.cToken, })), chain: 'heco', @@ -100,9 +100,9 @@ function lending(borrowed) { }); const lps = [] - _.each(markets, (market, idx) => { - let getCash = _.find(v2Locked.output, (result) => result.input.target === market.cToken); - const symbol = _.find(symbols.output, (result) => result.input.target === market.cToken); + markets.forEach((market, idx) => { + let getCash = v2Locked.output.find((result) => result.input.target === market.cToken); + const symbol = symbols.output.find((result) => result.input.target === market.cToken); if (getCash.output === null) { throw new Error("getCash failed") } diff --git a/projects/fortube/index.js b/projects/fortube/index.js index 51a55e87a5..e78ef93cd2 100644 --- a/projects/fortube/index.js +++ b/projects/fortube/index.js @@ -1,5 +1,5 @@ const sdk = require("@defillama/sdk"); - const _ = require("underscore"); + const abi = require("./abi.json"); const BigNumber = require("bignumber.js"); const axios = require("axios") @@ -40,7 +40,7 @@ calls: calls, abi: abi["collateralTokens"], }); - _.each(erc20AssetResults.output, (result) => { + erc20AssetResults.output.forEach((result) => { if (result.output != EthAddress) { erc20Assets.push(result.output); } @@ -54,14 +54,14 @@ let erc20AssetsV2 = []; let underlyings = await sdk.api.abi.multiCall({ block, - calls: _.map(fTokens, (fToken) => ({ + calls: fTokens.map((fToken) => ({ target: fToken, params: [], })), abi: abi['underlying'] }); - _.each(underlyings.output, (result) => { + underlyings.output.forEach((result) => { if (result.output != EthAddressV2) { erc20AssetsV2.push(result.output); } @@ -84,7 +84,7 @@ // Get erc20 assets locked let balanceOfResults = await sdk.api.abi.multiCall({ block, - calls: _.map(erc20Assets, (asset) => ({ + calls: erc20Assets.map((asset) => ({ target: asset, params: ForTube, })), @@ -104,7 +104,7 @@ let erc20AssetsV2 = await allUnderlyingMarkets(block); let balanceOfResultsV2 = await sdk.api.abi.multiCall({ block, - calls: _.map(erc20AssetsV2, (assetV2) => ({ + calls: erc20AssetsV2.map((assetV2) => ({ target: assetV2, params: ForTubeV2, })), diff --git a/projects/futureswap/index.js b/projects/futureswap/index.js index 8aac3810d4..1235a855e3 100644 --- a/projects/futureswap/index.js +++ b/projects/futureswap/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require("@defillama/sdk"); -const _ = require("underscore"); + const BigNumber = require("bignumber.js"); /*================================================== @@ -29,10 +29,10 @@ async function tvl(timestamp, block) { const balances = {}; let balanceOfCalls = []; - _.forEach(contracts, (contract) => { + contracts.forEach((contract) => { balanceOfCalls = [ ...balanceOfCalls, - ..._.map(tokens, (token) => ({ + ...tokens.map((token) => ({ target: token, params: contract, })), @@ -48,7 +48,7 @@ async function tvl(timestamp, block) { ).output; /* combine token volumes on multiple contracts */ - _.forEach(balanceOfResult, (result) => { + balanceOfResult.forEach((result) => { let balance = new BigNumber(result.output || 0); if (balance <= 0) return; diff --git a/projects/helper/compound.js b/projects/helper/compound.js index f28623d12c..c0a437ecab 100644 --- a/projects/helper/compound.js +++ b/projects/helper/compound.js @@ -1,4 +1,4 @@ -const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const abi = require('./abis/compound.json'); const { getBlock } = require('./getBlock'); @@ -95,7 +95,7 @@ function getCompoundV2Tvl(comptroller, chain = "ethereum", transformAdress = add let v2Locked = await sdk.api.abi.multiCall({ block, chain, - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.cToken, })), abi: borrowed ? abi.totalBorrows : abi['getCash'], @@ -106,7 +106,7 @@ function getCompoundV2Tvl(comptroller, chain = "ethereum", transformAdress = add symbols = await sdk.api.abi.multiCall({ block, chain, - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.cToken, })), abi: "erc20:symbol", @@ -114,8 +114,8 @@ function getCompoundV2Tvl(comptroller, chain = "ethereum", transformAdress = add } const lpPositions = [] - _.each(markets, (market, idx) => { - let getCash = _.find(v2Locked.output, (result) => result.input.target === market.cToken); + markets.forEach((market, idx) => { + let getCash = v2Locked.output.find((result) => result.input.target === market.cToken); if (checkForLPTokens !== undefined && checkForLPTokens(symbols.output[idx].output)) { lpPositions.push({ token: market.underlying, diff --git a/projects/insurace/index.js b/projects/insurace/index.js index fb8df64e48..f7b02680ca 100644 --- a/projects/insurace/index.js +++ b/projects/insurace/index.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk'); const abi = require('./abi.json'); -const _ = require('underscore'); + const BigNumber = require('bignumber.js'); const axios = require("axios"); const polygonPools = require('./polygonPools.json') @@ -29,7 +29,7 @@ async function eth(timestamp, ethBlock) { ); const balances = {}; - _.each(_tvlList, (element) => { + _tvlList.forEach((element) => { let address = element.input.params[0].toLowerCase(); if (address == "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") { address = "0x0000000000000000000000000000000000000000"; @@ -74,7 +74,7 @@ async function bsc(timestamp, ethBlock, chainBlocks){ ); const balances = {}; - _.each(_tvlList, (element) => { + _tvlList.forEach((element) => { let address = element.input.params[0].toLowerCase(); if (address == "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") { address = "bsc:0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c"; @@ -106,7 +106,7 @@ async function polygon(timestamp, ethBlock, chainBlocks) { }); const balances = {}; - _.each(_tvlList, (element) => { + _tvlList.forEach((element) => { let address = element.input.params[0].toLowerCase(); if(address === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"){ address = "0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270" @@ -132,7 +132,7 @@ async function avax(timestamp, ethBlock, chainBlocks) { }); const balances = {}; - _.each(_tvlList, (element) => { + _tvlList.forEach((element) => { let address = element.input.params[0].toLowerCase(); if(address === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"){ address = "0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7" diff --git a/projects/insuredefi/index.js b/projects/insuredefi/index.js index 8434db6420..a7973daf60 100644 --- a/projects/insuredefi/index.js +++ b/projects/insuredefi/index.js @@ -1,6 +1,6 @@ const sdk = require("@defillama/sdk"); const abi = require("./abi.json"); -const _ = require('underscore'); + const BigNumber = require("bignumber.js"); const constant = { diff --git a/projects/inverse/index.js b/projects/inverse/index.js index 1517c6488c..111d7ba255 100644 --- a/projects/inverse/index.js +++ b/projects/inverse/index.js @@ -1,4 +1,4 @@ -const _ = require("underscore"); + const sdk = require("@defillama/sdk"); const abi = require("./abi.json"); const BigNumber = require("bignumber.js"); @@ -42,8 +42,7 @@ async function getAllUnderlying(block, tokens) { let allUnderlying = ( await sdk.api.abi.multiCall({ block, - calls: _.map( - tokens.filter((token) => token !== anETH), + calls: tokens.filter((token) => token !== anETH).map( (token) => ({ target: token, }) @@ -66,7 +65,7 @@ async function getCashes(block, tokens) { return ( await sdk.api.abi.multiCall({ block, - calls: _.map(tokens, (token) => ({ + calls: tokens.map((token) => ({ target: token, })), abi: abi["getCash"], @@ -78,7 +77,7 @@ async function getTotalSupplies(block, tokens) { return ( await sdk.api.abi.multiCall({ block, - calls: _.map(tokens, (token) => ({ + calls: tokens.map((token) => ({ target: token, })), abi: abi["totalSupply"], @@ -98,13 +97,11 @@ async function anchorTVL(block) { getCashes(block, tokens), ]); - _.each(tokens, (token) => { - let cash = _.find( - cashes, + tokens.forEach((token) => { + let cash = cashes.find( (result) => result.input.target === token ); - let underlying = _.find( - allUnderlying, + let underlying = allUnderlying.find( (result) => result.input.target === token ); if (cash && underlying) { @@ -125,13 +122,11 @@ async function vaultsTVL(block) { getTotalSupplies(block, vaults), ]); - _.each(vaults, (token) => { - let totalSupply = _.find( - totalSupplies, + vaults.forEach((token) => { + let totalSupply = totalSupplies.find( (result) => result.input.target === token ); - let underlying = _.find( - allUnderlying, + let underlying = allUnderlying.find( (result) => result.input.target === token ); if (totalSupply && underlying) { @@ -176,7 +171,7 @@ async function tvl(timestamp, block) { ]); const lps = [] - _.each(_.pairs(anchorBalances), ([token, value]) => { + Object.entries(anchorBalances).forEach(([token, value]) => { const balance = BigNumber(balances[token] || 0); if(token === '0xAA5A67c256e27A5d80712c51971408db3370927D'){ token = "0x865377367054516e17014ccded1e7d814edc9ce4" @@ -191,12 +186,12 @@ async function tvl(timestamp, block) { } }); - _.each(_.pairs(vaultBalances), ([token, value]) => { + Object.entries(vaultBalances).forEach(([token, value]) => { const balance = BigNumber(balances[token] || 0); balances[token] = balance.plus(BigNumber(value)).toFixed(); }); - _.each(_.pairs(stabilizerBalances), ([token, value]) => { + Object.entries(stabilizerBalances).forEach(([token, value]) => { const balance = BigNumber(balances[token] || 0); balances[token] = balance.plus(BigNumber(value)).toFixed(); }); diff --git a/projects/iotube/index.js b/projects/iotube/index.js index 03e0b13e8d..194a4ccc77 100644 --- a/projects/iotube/index.js +++ b/projects/iotube/index.js @@ -1,6 +1,5 @@ const retry = require("../helper/retry"); const { request, gql } = require("graphql-request"); -const _ = require("lodash"); const apiURL = "https://smart-graph.iotex.me/iotube/graphql"; @@ -188,8 +187,8 @@ const loadTvl = async () => { ? cache : await retry(async (fail) => await request(apiURL, query, variables)).then( (res) => { - _.each(res, (v, k) => { - res[k] = _.sum([ + Object.entries(res).forEach(([k, v]) => { + res[k] = [ ...(v.CIOTX?.filter((i) => i.balance > 0).map((i) => Number(i.balance) ) || []), @@ -202,7 +201,7 @@ const loadTvl = async () => { ...(v.TokenSafe?.filter((i) => i.balance > 0).map((i) => Number(i.balance) ) || []), - ]); + ].reduce((acc, i) => acc + i, 0) if (!cache) cache = {}; cache[res] = res[k]; }); @@ -226,6 +225,6 @@ module.exports = { ...allChains, fetch: async () => { const tvl = await loadTvl(); - return _.sum(Object.values(tvl)); + return Object.values(tvl).reduce((acc, i) => acc + i, 0) }, }; diff --git a/projects/keeper-dao/index.js b/projects/keeper-dao/index.js index dac18c06dc..12ef83bba7 100644 --- a/projects/keeper-dao/index.js +++ b/projects/keeper-dao/index.js @@ -1,8 +1,9 @@ -const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js'); const liquidityAbi = require('./abi/liquidity.json'); + const ETH = '0x0000000000000000000000000000000000000000'; const LIQUIDITY_POOL_CONTRACTS = { @@ -121,12 +122,14 @@ async function getHidingVaultBalances(timestamp, block) { })).output; // numberRange to iterate over indexes of NFTs. Can migrate to any supported util func of erc721 when it is supported. - const indexRange = _.range(0, parseInt(noOfHidingVaults)); + const indexRange = []; + for (let i = 0;i < +noOfHidingVaults; i++) + indexRange.push(i) // Query Hiding Vault Contract's 'tokenByIndex' with index to get individual HidingVaultNFTs let totalHidingVaultNFTs = (await sdk.api.abi.multiCall({ target: HIDING_VAULT_CONTRACT, - calls: _.map(indexRange, (index) => ({ + calls: indexRange.map((index) => ({ params: [index], })), abi: liquidityAbi['tokenByIndex'], @@ -198,7 +201,7 @@ async function getLiquidityPoolBalances(timestamp, block) { // Get token balances let balances = await sdk.api.abi.multiCall({ block, - calls: _.map(markets, (data, token) => ({ + calls: markets.map((data, token) => ({ target: token, params: liquidityPool, })).filter(m => m.target !== "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"), @@ -220,7 +223,8 @@ async function tvl(timestamp, block) { const totalBalances = {}; - _.uniq(Object.keys(hidingVaultBalances).concat(Object.keys(liquidityPoolBalances))).forEach(asset => { + const uniq = arry => [... new Set(arry)] + uniq(Object.keys(hidingVaultBalances).concat(Object.keys(liquidityPoolBalances))).forEach(asset => { totalBalances[asset] = new BigNumber(hidingVaultBalances[asset] || "0").plus(new BigNumber(liquidityPoolBalances[asset] || "0")).toString(10); }); diff --git a/projects/kinesis/index.js b/projects/kinesis/index.js index a502479670..34c76d5e2f 100644 --- a/projects/kinesis/index.js +++ b/projects/kinesis/index.js @@ -4,7 +4,7 @@ const axios = require("axios"); const sdk = require("@defillama/sdk"); const BigNumber = require("bignumber.js"); - const _ = require("underscore"); + const { sumTokensAndLPsSharedOwners } = require("../helper/unwrapLPs"); // const { // transformEvmosAddress diff --git a/projects/lendhub/index.js b/projects/lendhub/index.js index 40b9a31168..a050f87e92 100644 --- a/projects/lendhub/index.js +++ b/projects/lendhub/index.js @@ -1,4 +1,4 @@ -const _ = require('underscore'); + const sdk = require('@defillama/sdk'); const cAbis = require('./abi.json'); const { unwrapUniswapLPs } = require('../helper/unwrapLPs'); @@ -78,7 +78,7 @@ return async () => { let markets = await getMarkets(); let lpPositions = []; let cashInfo = await sdk.api.abi.multiCall({ - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.cToken, })), chain: chain, @@ -86,14 +86,14 @@ return async () => { }); const symbols = await sdk.api.abi.multiCall({ - calls: _.map(markets, (market) => ({ + calls: markets.map((market) => ({ target: market.underlying.split(':')[1], })), chain: chain, abi: "erc20:symbol", }); - _.each(markets, async (market, idx) => { - const getCash = _.find(cashInfo.output, (result) => result.input.target === market.cToken); + markets.forEach(async (market, idx) => { + const getCash = cashInfo.output.find((result) => result.input.target === market.cToken); if (getCash.output === null) { throw new Error("failed") } diff --git a/projects/lien/index.js b/projects/lien/index.js index e35b871ff8..b9fc1258b7 100644 --- a/projects/lien/index.js +++ b/projects/lien/index.js @@ -1,6 +1,6 @@ const sdk = require("@defillama/sdk"); const BigNumber = require("bignumber.js"); -const _ = require("underscore"); + const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000"; const contracts = [ "0xE446158503d0F5c70579FCCE774C00E8Db544559", // aggregator1 @@ -19,7 +19,7 @@ async function tvl(timestamp, block) { block: block, }); let balance = new BigNumber(0); - _.forEach(ethBalances.output, (ethBalance) => { + ethBalances.output.forEach((ethBalance) => { balance = balance.plus(ethBalance.balance); }); return { [ZERO_ADDRESS]: balance.toFixed() }; diff --git a/projects/lightning-network/index.js b/projects/lightning-network/index.js index 4382f14d81..22ebc14c3f 100644 --- a/projects/lightning-network/index.js +++ b/projects/lightning-network/index.js @@ -1,5 +1,5 @@ const axios = require("axios"); -const _ = require("underscore"); + const dayHistory = {}; @@ -62,5 +62,13 @@ module.exports = { function parseCSV(csvData) { csvData = csvData.replaceAll('\r', '').split('\n').map(i => i.split(',')) const headers = csvData.shift() - return csvData.map(row => _.object(headers, row)) + return csvData.map(row => toObject(headers, row)) +} + +function toObject(keys, values) { + const res = {} + keys.forEach((key, i) => { + res[key] = values[i] + }) + return res } \ No newline at end of file diff --git a/projects/liqee/index.js b/projects/liqee/index.js index ed82c0bdb1..624c99e19c 100644 --- a/projects/liqee/index.js +++ b/projects/liqee/index.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); + const BigNumber = require('bignumber.js'); const abi = require('./abi.json'); const BASE = BigNumber(10 ** 18) diff --git a/projects/loopring/index.js b/projects/loopring/index.js index 4037781e24..5029f5f51e 100644 --- a/projects/loopring/index.js +++ b/projects/loopring/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); + const BigNumber = require('bignumber.js'); /*================================================== @@ -37,7 +37,7 @@ }; let calls = []; - _.each(listedTokens, (token) => { + listedTokens.forEach((token) => { calls.push({ target: token, params: oldLoopringExchange diff --git a/projects/mcdex/index.js b/projects/mcdex/index.js index 5d08c063e1..fb990bbb25 100644 --- a/projects/mcdex/index.js +++ b/projects/mcdex/index.js @@ -3,20 +3,20 @@ const {gql} = require('graphql-request') const { blockQuery } = require('../helper/graph') const {toUSDTBalances} = require('../helper/balances'); const {getBlock} = require('../helper/getBlock'); -const _ = require('underscore'); + const axios = require('axios'); async function GenerateCallList() { const markets = (await axios.get('https://mcdex.io/api/markets')).data.data.markets; const marketStatus = (await axios.get('https://mcdex.io/api/markets/status')).data.data; let id2Info = {}; - _.forEach(markets, market => { + markets.forEach(market => { const id = market.id; if (market.contractType === 'Perpetual') { id2Info[id] = {perpetualAddress: market.perpetualAddress}; } }); - _.forEach(marketStatus, status => { + marketStatus.forEach(status => { if (status === null) { return; } @@ -26,7 +26,7 @@ async function GenerateCallList() { } }); let calls = [] - _.map(id2Info, (info, id) => { + id2Info.map((info, id) => { if (info.collateralTokenAddress && info.perpetualAddress) { calls.push({ target: info.collateralTokenAddress, diff --git a/projects/mensa/index.js b/projects/mensa/index.js index 783235cca1..5b161cf567 100644 --- a/projects/mensa/index.js +++ b/projects/mensa/index.js @@ -1,5 +1,5 @@ const sdk = require("@defillama/sdk"); -const _us = require('underscore'); + const abi = require('./abi.json'); const {transformFantomAddress} = require('../helper/portedTokens') diff --git a/projects/metronome/index.js b/projects/metronome/index.js index 733636ed82..8ed80e30b9 100644 --- a/projects/metronome/index.js +++ b/projects/metronome/index.js @@ -4,7 +4,7 @@ const sdk = require('@defillama/sdk'); const BigNumber = require("bignumber.js"); - const _ = require('underscore'); + /*================================================== TVL ==================================================*/ diff --git a/projects/minmax-finance/index.js b/projects/minmax-finance/index.js index 61ca22cbea..784d6acc58 100644 --- a/projects/minmax-finance/index.js +++ b/projects/minmax-finance/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js') -const _ = require('underscore'); + const abi = require("./abi.json"); const IOTEX_CG_MAPPING = require("./iotex_cg_stablecoin_mapping.json") @@ -111,7 +111,7 @@ async function tvl(block) { }); // Compute Balances - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target let amount = balanceOf.output @@ -154,7 +154,7 @@ async function tvl(block) { }); // Compute Balances - _.each(lpBalanceOfResults.output, (balanceOf) => { + lpBalanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target let amount = balanceOf.output diff --git a/projects/mobius/index.js b/projects/mobius/index.js index ef1c764670..9deb5eee9a 100644 --- a/projects/mobius/index.js +++ b/projects/mobius/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require("@defillama/sdk"); const BigNumber = require("bignumber.js"); -const _ = require("underscore"); + const { getBlock } = require("../helper/getBlock"); //added module /*================================================== diff --git a/projects/nerve/index.js b/projects/nerve/index.js index 8dd2dc2f65..67bea42440 100644 --- a/projects/nerve/index.js +++ b/projects/nerve/index.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk') const BigNumber = require('bignumber.js') -const _ = require('underscore') + const { staking } = require('../helper/staking') const {unwrapCrv} = require('../helper/unwrapLPs') @@ -66,7 +66,7 @@ async function tvl(timestamp, block, chainBlocks) { }) // Compute Balances - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = `bsc:${balanceOf.input.target}`.toLowerCase(); if(address === "bsc:0x54261774905f3e6e9718f2abb10ed6555cae308a"){ balances["bitcoin"] = Number(balanceOf.output)/1e8 diff --git a/projects/nexus/index.js b/projects/nexus/index.js index 39b3dd7e56..79b2a4c81a 100644 --- a/projects/nexus/index.js +++ b/projects/nexus/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); + const BigNumber = require('bignumber.js'); /*================================================== @@ -28,8 +28,8 @@ let calls = []; - _.each(pools, (pool) => { - _.each(tokensAddresses, (tokenAddress) => { + pools.forEach((pool) => { + tokensAddresses.forEach((tokenAddress) => { calls.push({ target: tokenAddress, params: pool diff --git a/projects/nsure/index.js b/projects/nsure/index.js index b4b9201f9e..aefee89d20 100644 --- a/projects/nsure/index.js +++ b/projects/nsure/index.js @@ -1,6 +1,6 @@ const sdk = require("@defillama/sdk"); const abi = require("./abi.json"); -const _ = require('underscore'); + const BigNumber = require("bignumber.js"); const constant = { diff --git a/projects/opium.js b/projects/opium.js index 4315e064f5..95c13b70b6 100644 --- a/projects/opium.js +++ b/projects/opium.js @@ -1,6 +1,6 @@ const sdk = require("@defillama/sdk"); const BigNumber = require("bignumber.js"); -const _ = require('underscore'); + const utils = require('./helper/utils'); const { unwrapUniswapLPs } = require('./helper/unwrapLPs'); @@ -30,8 +30,8 @@ const tvl = (url, chain) => async (timestamp, blockETH, chainBlocks) => { // Prepare multiCall structure const calls = [] - _.each(tokens, (token) => { - _.each(contracts, (contract) => { + tokens.forEach((token) => { + contracts.forEach((contract) => { calls.push({ target: token, params: contract @@ -47,7 +47,7 @@ const tvl = (url, chain) => async (timestamp, blockETH, chainBlocks) => { }); // Sum all balances - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { const address = balanceOf.input.target; const balance = balances[address] ? BigNumber(balanceOf.output).plus(BigNumber(balances[address])).toFixed().toString(): balanceOf.output; diff --git a/projects/opyn/convexity.js b/projects/opyn/convexity.js index acd7685790..b55b99ee0d 100644 --- a/projects/opyn/convexity.js +++ b/projects/opyn/convexity.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); -const _ = require('underscore'); + const BigNumber = require('bignumber.js'); const getNumberOfOptionsContractsAbi = require('./abis/convexity/getNumberOfOptionsContracts.json'); @@ -44,7 +44,7 @@ module.exports.tvl = async function tvl(timestamp, block) { // list of options addresses let optionsAddresses = [] - _.each(optionsContracts, async (contracts) => { + optionsContracts.forEach(async (contracts) => { if(contracts.output != null) { optionsAddresses = [ ...optionsAddresses, @@ -56,7 +56,7 @@ module.exports.tvl = async function tvl(timestamp, block) { // batch getCollateralAsset calls let getCollateralAssetCalls = []; - _.each(optionsAddresses, (optionAddress) => { + optionsAddresses.forEach((optionAddress) => { getCollateralAssetCalls.push({ target: optionAddress }) @@ -73,7 +73,7 @@ module.exports.tvl = async function tvl(timestamp, block) { let optionsCollateralAddresses = [] - _.each(optionsCollateral, async (collateralAsset) => { + optionsCollateral.forEach(async (collateralAsset) => { // only consider supported tokens if((collateralAsset.output.toLowerCase() != null) && (collateralAsset.output.toLowerCase() !== "0x0000000000000000000000000000000000000000") && (!optionsCollateralAddresses.includes(collateralAsset.output.toLowerCase())) ) { optionsCollateralAddresses = [ @@ -84,7 +84,7 @@ module.exports.tvl = async function tvl(timestamp, block) { }); // get ETH balance - _.each(optionsAddresses, async (optionAddress) => { + optionsAddresses.forEach(async (optionAddress) => { let balance = (await sdk.api.eth.getBalance({target: optionAddress, block})).output; sdk.util.sumSingleBalance(balances, "0x0000000000000000000000000000000000000000", balance) }) @@ -92,7 +92,7 @@ module.exports.tvl = async function tvl(timestamp, block) { // batch balanceOf calls let balanceOfCalls = []; - _.each(optionsCollateralAddresses, async (optionCollateralAddress) => { + optionsCollateralAddresses.forEach(async (optionCollateralAddress) => { optionsAddresses.forEach((optionAddress) => { balanceOfCalls.push({ target: optionCollateralAddress, diff --git a/projects/peakdefi/index.js b/projects/peakdefi/index.js index 52efd7f35c..80545300fb 100644 --- a/projects/peakdefi/index.js +++ b/projects/peakdefi/index.js @@ -1,4 +1,4 @@ - const _ = require('underscore'); + const sdk = require("@defillama/sdk") const BigNumber = require('bignumber.js'); const { staking } = require('../helper/staking'); @@ -83,7 +83,7 @@ const { staking } = require('../helper/staking'); let fundsAddresses = []; // Prepare funds balances - _.each(funds, (fund) => { + funds.forEach((fund) => { let fundTokens = fund.tokens let fundAddress = fund.address @@ -91,7 +91,7 @@ const { staking } = require('../helper/staking'); fundsAddresses.push(fundAddress) // Calculate ERC20 balance for every token of the fund - _.each(fundTokens, (tokenAddress) => { + fundTokens.forEach((tokenAddress) => { calls.push({ target: tokenAddress, params: fundAddress diff --git a/projects/perlinx/index.js b/projects/perlinx/index.js index 21939aeac6..a0b7609173 100644 --- a/projects/perlinx/index.js +++ b/projects/perlinx/index.js @@ -4,7 +4,7 @@ const sdk = require('@defillama/sdk'); const abi = require('./abi'); -const _ = require('underscore'); + const BigNumber = require('bignumber.js'); /*================================================== @@ -42,7 +42,7 @@ async function tvl(timestamp, block) { } const synths = await sdk.api.abi.multiCall({ block, - calls: _.map(counts, (count) => { + calls: counts.map((count) => { return { target: perlinX, params: count @@ -50,10 +50,10 @@ async function tvl(timestamp, block) { }), abi: abi.arraySynths }) - const synthAddresses = _.map(synths.output, (item) => item.output) + const synthAddresses = synths.output.map((item) => item.output) const emps = (await sdk.api.abi.multiCall({ - calls: _.map(synthAddresses, (address) => { + calls: synthAddresses.map((address) => { return { target: perlinX, params: address @@ -62,11 +62,11 @@ async function tvl(timestamp, block) { abi: abi.mapSynth_EMP, })); - const empAddresses = _.map(emps.output, (item) => item.output) + const empAddresses = emps.output.map((item) => item.output) let calls = []; - _.forEach(empAddresses, (empAddress) => { + empAddresses.forEach((empAddress) => { calls.push({ target: perlErc20, params: empAddress, @@ -79,7 +79,7 @@ async function tvl(timestamp, block) { abi: 'erc20:balanceOf' })).output; - _.each(synthBalances, (balanceOf) => { + synthBalances.forEach((balanceOf) => { let balance = balanceOf.output; let address = balanceOf.input.target; diff --git a/projects/phoenix/index.js b/projects/phoenix/index.js index 24f5cd0ebd..e79eb4a992 100644 --- a/projects/phoenix/index.js +++ b/projects/phoenix/index.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js'); -const _ = require('underscore'); + const abi = require('./abi'); const ploypool = '0x7751ff8c091b60cd51219ea244f9760d21fda041'; diff --git a/projects/powerindex/index.js b/projects/powerindex/index.js index b3d96b0da3..2f3dcbae78 100644 --- a/projects/powerindex/index.js +++ b/projects/powerindex/index.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); -const _ = require('underscore'); + const BigNumber = require('bignumber.js'); const curvePools = require('../convex/pools-crv.js') @@ -38,11 +38,11 @@ async function getBscTvl(time, ethBlock, chainBlocks) { chain: 'bsc', block, abi: 'erc20:balanceOf', - calls: _.map(poolTokens.output, + calls: poolTokens.output.map( (poolToken) => ({ target: poolToken, params: poolAddress})) }) - _.each(poolBalances.output, (poolBalance) => { + poolBalances.output.forEach((poolBalance) => { bscBalances[`bsc:${poolBalance.input.target}`] = poolBalance.output }) @@ -70,23 +70,23 @@ async function eth(timestamp, block) { let poolCalls = []; - let pools = _.map(poolLogs, (poolLog) => { + let pools = poolLogs.map((poolLog) => { return `0x${poolLog[2].slice(26)}` }); const poolTokenData = (await sdk.api.abi.multiCall({ - calls: _.map(pools, (poolAddress) => ({ target: poolAddress })), + calls: pools.map((poolAddress) => ({ target: poolAddress })), abi: abi.getCurrentTokens, })).output; - _.forEach(poolTokenData, (poolToken) => { + poolTokenData.forEach((poolToken) => { let poolTokens = poolToken.output; if(poolTokens === null){ throw new Error("poolTokens failed call") } let poolAddress = poolToken.input.target; - _.forEach(poolTokens, (token) => { + poolTokens.forEach((token) => { poolCalls.push({ target: token, params: poolAddress, @@ -105,7 +105,7 @@ async function eth(timestamp, block) { for (let i = 0; i < poolBalances.length; i++) { const balanceOf = poolBalances[i]; const tokenAddress = balanceOf.input.target; - let underlying = _.find(tokensUnderlyings, t => t.input.target === tokenAddress); + let underlying = tokensUnderlyings.find(t => t.input.target === tokenAddress); let pricePerFullShare = pricesPerFullShare[i]; if (v2PricePerShare[i].success) { pricePerFullShare = v2PricePerShare[i]; diff --git a/projects/psyoptions/index.js b/projects/psyoptions/index.js index 7c30a63437..ecd317ace4 100644 --- a/projects/psyoptions/index.js +++ b/projects/psyoptions/index.js @@ -11,7 +11,6 @@ const { NodeWallet } = require("@project-serum/anchor/dist/cjs/provider"); const PsyAmericanIdl = require("./idl.json"); const axios = require("axios"); const { toUSDTBalances } = require("../helper/balances"); -const { isArray } = require("underscore"); const textEncoder = new TextEncoder(); @@ -106,7 +105,7 @@ async function getTokenizedEurosControlledAccounts(anchorProvider) { // Add the mint to the mint keys object mintKeys[mintAddress] = true; // Add the token account to the mintTokenAccountsMap - if (isArray(mintTokenAccountsMap[mintAddress])) { + if (Array.isArray(mintTokenAccountsMap[mintAddress])) { mintTokenAccountsMap[mintAddress].push(tokenProgramAccount.pubkey); } else { mintTokenAccountsMap[mintAddress] = [tokenProgramAccount.pubkey]; @@ -146,7 +145,7 @@ async function tvl() { tokenAccounts = [...tokenAccounts, ...protocolTokenAccounts]; // Consolidate the mint to token accounts map Object.keys(protocolAccountMap).forEach((mintAddress) => { - if (isArray(mintTokenAccountsMap[mintAddress])) { + if (Array.isArray(mintTokenAccountsMap[mintAddress])) { // Concat the two arrays mintTokenAccountsMap[mintAddress] = [ ...mintTokenAccountsMap[mintAddress], diff --git a/projects/ray/index.js b/projects/ray/index.js index bd80762afc..36aa43de06 100644 --- a/projects/ray/index.js +++ b/projects/ray/index.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); + const BigNumber = require('bignumber.js'); const opportunityAbi = require('./abis/Opportunity'); @@ -60,7 +60,7 @@ ((allPortfolioManagers[i].endTimestamp == null) || timestamp <= allPortfolioManagers[i].endTimestamp)) { - let calls = _.reduce(tokenAddresses, (accum, tokenAddress) => [...accum, { + let calls = tokenAddresses.reduce((accum, tokenAddress) => [...accum, { target: tokenAddress, params: allPortfolioManagers[i].address }], []); @@ -93,7 +93,7 @@ supportedTokens = removeTokens(timestamp, supportedTokens, allOpportunities[i].added); } - let calls = _.reduce(supportedTokens, (accum, tokenAddress) => [...accum, + let calls = supportedTokens.reduce((accum, tokenAddress) => [...accum, { target: allOpportunities[i].address, params: tokenAddress @@ -128,7 +128,7 @@ let { pmCalls, portfolioManagers } = getPmCalls(timestamp); let opportunityCalls = getOpportunityCalls(timestamp); - await Promise.all(_.map(portfolioManagers, (portfolioManager) => { + await Promise.all(portfolioManagers.map((portfolioManager) => { return new Promise(async (resolve, reject) => { try { let balance = (await sdk.api.eth.getBalance({target: portfolioManager, block})).output; @@ -147,7 +147,7 @@ abi: 'erc20:balanceOf' })).output; - _.each(pmBalances, (result) => { + pmBalances.forEach((result) => { let balance = result.output; let address = result.input.target; @@ -164,7 +164,7 @@ abi: opportunityAbi.getBalance })).output; - _.each(opportunityBalances, (result) => { + opportunityBalances.forEach((result) => { if(result.input.params[0] === '0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359' && result.input.target === "0x759A728653C4d0483D897DCCf3a343fe2bBbb54A"){ return } diff --git a/projects/rose/index.js b/projects/rose/index.js index ba25151b63..685d4c4359 100644 --- a/projects/rose/index.js +++ b/projects/rose/index.js @@ -1,6 +1,6 @@ const sdk = require("@defillama/sdk"); const { default: BigNumber } = require("bignumber.js"); -const _ = require("underscore"); + const abi = require("./abi.json"); // pool addresses @@ -80,7 +80,7 @@ const tvl = async (timestamp, ethBlock, chainBlock) => { chain: "aurora", }); - _.each(balances.output, (res) => { + balances.output.forEach((res) => { const amount = res.output; const poolAddress = res.input.target; const tokenAddress = poolToTokensMap[poolAddress][res.input.params[0]]; @@ -115,7 +115,7 @@ const tvl = async (timestamp, ethBlock, chainBlock) => { chain: "aurora", }); - _.each(vaseCollateralBalances.output, (res) => { + vaseCollateralBalances.output.forEach((res) => { const amount = res.output; const tokenAddress = res.input.params[0]; sdk.util.sumSingleBalance(tvl, `aurora:${tokenAddress}`, amount); @@ -158,7 +158,7 @@ const borrowed = async (timestamp, ethBlock, chainBlock) => { chain: "aurora", }); - _.each(borrowedAmounts.output, (res) => { + borrowedAmounts.output.forEach((res) => { const amount = res.output[0]; sdk.util.sumSingleBalance(borrowed, `aurora:${RUSD}`, amount); }); diff --git a/projects/sablier/index.js b/projects/sablier/index.js index eec3f296a6..18b1590352 100644 --- a/projects/sablier/index.js +++ b/projects/sablier/index.js @@ -1,4 +1,4 @@ - const _ = require('underscore') + const axios = require("axios"); const sdk = require('@defillama/sdk'); @@ -31,7 +31,7 @@ async function tvl(timestamp, block) { }; const calls = []; - _.each(allTokens, (token) => { + allTokens.forEach((token) => { calls.push( { target: token, diff --git a/projects/saddle/index.js b/projects/saddle/index.js index fecb636308..faa274abd5 100644 --- a/projects/saddle/index.js +++ b/projects/saddle/index.js @@ -4,7 +4,7 @@ const axios = require("axios"); const sdk = require("@defillama/sdk"); const BigNumber = require("bignumber.js"); -const _ = require("underscore"); + const { sumTokensAndLPsSharedOwners } = require("../helper/unwrapLPs"); const { transformArbitrumAddress, @@ -133,7 +133,7 @@ async function tvl(timestamp, block) { }); // Compute Balances - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target; let amount = balanceOf.output; if (balanceOf.input.params[0] === veth2PoolAddress) { @@ -196,7 +196,7 @@ async function tvlFantom(timestamp, block) { }); // Compute Balances - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target; let amount = balanceOf.output; rawBalances[address] = BigNumber(rawBalances[address] || 0) diff --git a/projects/set-protocol/v1.js b/projects/set-protocol/v1.js index 754b9f0087..591d5fe2a1 100644 --- a/projects/set-protocol/v1.js +++ b/projects/set-protocol/v1.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js'); -const _ = require('underscore'); + /*================================================== Settings @@ -34,7 +34,7 @@ module.exports = async function tvl(timestamp, block) { // Vault Asset Balances let balanceOfResults = await sdk.api.abi.multiCall({ block, - calls: _.map(tokens, (token) => { + calls: tokens.map((token) => { return { target: token, params: '0x5B67871C3a857dE81A1ca0f9F7945e5670D986Dc' @@ -46,7 +46,7 @@ module.exports = async function tvl(timestamp, block) { // cToken Exchange Rates let cTokenConversionRatesMap = (await sdk.api.abi.multiCall({ block, - calls: _.map(Object.keys(cTokensMap), (cToken) => { + calls: Object.keys(cTokensMap).map((cToken) => { return { target: cToken } @@ -69,7 +69,7 @@ module.exports = async function tvl(timestamp, block) { }, {}); // Compute Balances - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target if (address in cTokensMap) { diff --git a/projects/set-protocol/v2.js b/projects/set-protocol/v2.js index 3d73d9716a..fc5ef66047 100644 --- a/projects/set-protocol/v2.js +++ b/projects/set-protocol/v2.js @@ -1,6 +1,6 @@ const sdk = require('@defillama/sdk'); const BigNumber = require('bignumber.js'); -const _ = require('underscore'); + const SUPPLY_SCALE = BigNumber("10").pow(18) const START_BLOCK = 10830496; @@ -43,7 +43,7 @@ module.exports = async function tvl(timestamp, block) { let supplies = (await sdk.api.abi.multiCall({ abi: totalSupply, block, - calls: _.map(setAddresses, (setAddress) => { + calls: setAddresses.map((setAddress) => { return { target: setAddress, } @@ -53,7 +53,7 @@ module.exports = async function tvl(timestamp, block) { let positionsForSets = (await sdk.api.abi.multiCall({ abi: getPositions, block, - calls: _.map(setAddresses, (setAddress) => { + calls: setAddresses.map((setAddress) => { return { target: setAddress, } @@ -61,12 +61,12 @@ module.exports = async function tvl(timestamp, block) { })).output; let uniswapPositions = {}; - _.each(positionsForSets, function(positionForSet, i) { + positionsForSets.forEach(function(positionForSet, i) { const setSupply = BigNumber(supplies[i].output); if(positionForSet.output === null){ throw new Error("positionForSet call failed") } - _.each(positionForSet.output, (position) => { + positionForSet.output.forEach((position) => { const componentAddress = position[0]; const positionUnits = BigNumber(position[2]); diff --git a/projects/sfinance/index.js b/projects/sfinance/index.js index 17b6b10431..9c399ede86 100644 --- a/projects/sfinance/index.js +++ b/projects/sfinance/index.js @@ -3,8 +3,7 @@ ==================================================*/ const sdk = require('@defillama/sdk'); - const _ = require('underscore'); - _.flatMap = _.compose(_.flatten, _.map); + /*================================================== Settings @@ -55,12 +54,12 @@ let swaps = [...swapsA, ...swapsB] - let balancesCalls = _.flatMap(swaps, (swap, i) => { + let balancesCalls = swaps.map((swap, i) => { return Array.from(Array(swap.coinNums), (e, idx) =>({target: swap.address, params: idx})) - }) + }).flat() - const swapsA_coinSum = _.reduce(swapsA, (memo, num) => memo + num.coinNums, 0); - const swapsB_coinSum = _.reduce(swapsB, (memo, num) => memo + num.coinNums, 0); + const swapsA_coinSum = swapsA.reduce((memo, num) => memo + num.coinNums, 0); + const swapsB_coinSum = swapsB.reduce((memo, num) => memo + num.coinNums, 0); let balancesResultsA = await sdk.api.abi.multiCall({ block, @@ -112,9 +111,9 @@ let balancesResults = [...balancesResultsA.output, ...balancesResultsB.output] - let coinsCalls = _.flatMap(swaps, (swap, i) => { + let coinsCalls = swaps.map((swap, i) => { return Array.from(Array(swap.coinNums), (e, idx) =>({target: swap.address, params: idx})) - }) + }).flat() let coinsResultsA = await sdk.api.abi.multiCall({ block, @@ -161,10 +160,7 @@ if(!balance || !balance.output) continue; // coin address const out = coinsResults[i].output; - // init - if(balances[out] == null) balances[out] = 0; - // update - balances[out] = String(parseFloat(balances[out]) + parseFloat(balance.output)); + sdk.util.sumSingleBalance(balances, out, balance.output) } return balances; @@ -180,5 +176,7 @@ // #2 dfi pool started // start: 1602345600, // 10/10/2020 @ 04:00:00pm +UTC start: 1602374400, // 10/11/2020 @ 00:00:00am +UTC - tvl + ethereum: { + tvl + } } diff --git a/projects/sirius-finance/index.js b/projects/sirius-finance/index.js index 9cb368ee9a..0d1daef9b2 100644 --- a/projects/sirius-finance/index.js +++ b/projects/sirius-finance/index.js @@ -3,7 +3,7 @@ ==================================================*/ const sdk = require("@defillama/sdk"); const BigNumber = require("bignumber.js"); - const _ = require("underscore"); + const { requery } = require("../helper/requery"); /*** Astar Addresses ***/ diff --git a/projects/valueliquid/index.js b/projects/valueliquid/index.js index fd2b82021f..73978d1be6 100644 --- a/projects/valueliquid/index.js +++ b/projects/valueliquid/index.js @@ -4,7 +4,7 @@ const sdk = require('@defillama/sdk'); const getCurrentTokens = require('./abis/getCurrentTokens.json'); -const _ = require('underscore'); + const BigNumber = require("bignumber.js"); async function valueLiquidTvl(timestamp, block) { @@ -22,20 +22,20 @@ async function valueLiquidTvl(timestamp, block) { let poolCalls = []; - let pools = _.map(poolLogs.output, (poolLog) => { + let pools = poolLogs.output.map((poolLog) => { return `0x${poolLog[2].slice(26)}` }); const poolTokenData = (await sdk.api.abi.multiCall({ - calls: _.map(pools, (poolAddress) => ({target: poolAddress})), + calls: pools.map((poolAddress) => ({target: poolAddress})), abi: getCurrentTokens, })).output; - _.forEach(poolTokenData, (poolToken) => { + poolTokenData.forEach((poolToken) => { let poolTokens = poolToken.output; let poolAddress = poolToken.input.target; - _.forEach(poolTokens, (token) => { + poolTokens.forEach((token) => { poolCalls.push({ target: token, params: poolAddress, @@ -49,7 +49,7 @@ async function valueLiquidTvl(timestamp, block) { abi: 'erc20:balanceOf' })).output; - _.each(poolBalances, (balanceOf) => { + poolBalances.forEach((balanceOf) => { let balance = balanceOf.output; let address = balanceOf.input.target; diff --git a/projects/wasabix/index.js b/projects/wasabix/index.js index d9afc393c4..df8a38a47a 100644 --- a/projects/wasabix/index.js +++ b/projects/wasabix/index.js @@ -1,8 +1,7 @@ const sdk = require("@defillama/sdk"); const abi = require("./abi.json"); const BigNumber = require("bignumber.js"); -const _ = require("lodash"); -const { unwrapUniswapLPs } = require("../helper/unwrapLPs") +const { unwrapUniswapLPs, sumTokens } = require("../helper/unwrapLPs") const utils = require('../helper/utils'); const getReserves = require('../helper/abis/getReserves.json'); const { transformBscAddress, transformPolygonAddress } = require('../helper/portedTokens'); @@ -290,7 +289,7 @@ async function eth(timestamp, block) { 8: tokens.lusd.address, 9: tokens.weth.address } - const calls = _.map(poolIds, function(pid) { + const calls = poolIds.map(function(pid) { return {target: contracts.stakingPools.address, params: [pid]} }); const { output: poolsInfo } = await sdk.api.abi.multiCall({ @@ -330,7 +329,7 @@ async function eth(timestamp, block) { 4: tokens.lusd.address, 5: tokens.weth.address } - const callsV4 = _.map(poolIdsV4, function(pid) { + const callsV4 = poolIdsV4.map(function(pid) { return {target: contracts.stakingPoolsV4.address, params: [pid]} }); @@ -368,27 +367,15 @@ async function eth(timestamp, block) { } } - const { output: vaultsInfo } = await sdk.api.abi.multiCall({ + const vaultsInfo = await sdk.api.abi.multiCall({ calls: vaultCalls, abi: abi['totalDeposited'] }) - for(let vault of vaultsInfo) { - let totalDeposited = vault.output - let poolAddr = vault.input.target - sdk.util.sumSingleBalance(balances, _.find(vaultCalls, {target: poolAddr}).token, totalDeposited); - } + sdk.util.sumMultiBalanceOf(balances, vaultsInfo) - //collectors - for(let collector of collectors) { - let tokenLocked = await sdk.api.erc20.balanceOf({ - owner: collector.pool, - target: collector.token, - ethBlock - }); - sdk.util.sumSingleBalance(balances, collector.token, tokenLocked.output); - } - return balances + const toa = collectors.map(c => [c.token, c.pool]) + return sumTokens(balances, toa, ethBlock) } const contractsBSC = { @@ -537,7 +524,7 @@ async function bsc(timestamp, block, chainBlocks) { 1: tokensBSC.busd.address, 2: tokensBSC.busd.address, } - const calls = _.map(poolIds, function(pid) { + const calls = poolIds.map(function(pid) { return {target: contractsBSC.stakingPools.address, params: [pid]} }); const { output: poolsInfo } = await sdk.api.abi.multiCall({ @@ -676,7 +663,7 @@ async function polygon(timestamp, block, chainBlocks) { 5: tokensPolygon.pusd.address, 6: tokensPolygon.pusd.address, } - const calls = _.map(poolIds, function(pid) { + const calls = poolIds.map(function(pid) { return {target: contractsPolygon.stakingPools.address, params: [pid]} }); const { output: poolsInfo } = await sdk.api.abi.multiCall({ diff --git a/projects/xdai/index.js b/projects/xdai/index.js index d76bbee2a3..0e7061f710 100644 --- a/projects/xdai/index.js +++ b/projects/xdai/index.js @@ -1,5 +1,5 @@ const sdk = require('@defillama/sdk'); -const _ = require('underscore'); + const axios = require('axios') async function balancesInAddress(address, chain, chainId, block) { @@ -9,7 +9,7 @@ async function balancesInAddress(address, chain, chainId, block) { const balanceOfOmniBridge = block > 10590093 ? await sdk.api.abi.multiCall({ block, - calls: _.map(allTokens, (token) => ({ + calls: allTokens.map((token) => ({ target: token.contract_address, params: omniBridge })), @@ -40,7 +40,7 @@ async function eth(timestamp, block) { } const balanceOfXdaiBridge = await sdk.api.abi.multiCall({ block, - calls: _.map(tokenAddresses, (token) => ({ + calls: tokenAddresses.map((token) => ({ target: token, params: xDaiBridge })), diff --git a/projects/xdollar-finance/index.js b/projects/xdollar-finance/index.js index fcc4801b3b..2917513d6d 100644 --- a/projects/xdollar-finance/index.js +++ b/projects/xdollar-finance/index.js @@ -2,7 +2,7 @@ const sdk = require("@defillama/sdk"); const BigNumber = require('bignumber.js') const { transformIotexAddress } = require('../helper/portedTokens.js') const getEntireSystemCollAbi = require("./getEntireSystemColl.abi.json") -const _ = require('underscore'); + const {getLiquityTvl} = require('../helper/liquity') const ETH_ADDR = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; @@ -42,7 +42,7 @@ const iotexTvl = async (timestamp, ethBlock, chainBlocks) => { chain: 'iotex' }); - _.each(getCollResults.output, (getColl) => { + getCollResults.output.forEach((getColl) => { let address = iotexTMs[getColl.input.target] let amount = getColl.output @@ -70,7 +70,7 @@ const iotexTvl = async (timestamp, ethBlock, chainBlocks) => { chain: 'iotex' }); - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target let amount = balanceOf.output @@ -101,7 +101,7 @@ const ethStableCollat = async (timestamp, ethBlock, chainBlocks) => { chain: 'ethereum' }); - _.each(balanceOfResults.output, (balanceOf) => { + balanceOfResults.output.forEach((balanceOf) => { let address = balanceOf.input.target let amount = balanceOf.output diff --git a/projects/xensa/index.js b/projects/xensa/index.js index f9e5957b96..4e3a42fa71 100644 --- a/projects/xensa/index.js +++ b/projects/xensa/index.js @@ -1,5 +1,4 @@ const sdk = require("@defillama/sdk"); -const _us = require('underscore'); const abi = require('./abi.json'); const { getBlock } = require("../helper/getBlock"); @@ -28,7 +27,7 @@ async function tvl(timestamp, _ethBlock, chainBlocks) { const balanceOfResults = await sdk.api.abi.multiCall({ block, chain: 'okexchain', - calls: _us.map(reserves_xensa, (reserve) => ({ + calls: reserves_xensa.map((reserve) => ({ target: reserve, params: _xensaCoreAddress, })), diff --git a/projects/yfii/index.js b/projects/yfii/index.js index 0980600eb5..62c183c59a 100644 --- a/projects/yfii/index.js +++ b/projects/yfii/index.js @@ -4,7 +4,7 @@ const sdk = require('@defillama/sdk'); const abi = require('./abi'); -const _ = require('underscore'); + const BigNumber = require('bignumber.js'); /*================================================== @@ -42,13 +42,13 @@ async function tvl(timestamp, block) { // Get iVault's underlying tokens const underlyingIVaultAddressResults = await sdk.api.abi.multiCall({ - calls: _.map(iVaultAddresses, (address) => ({ + calls: iVaultAddresses.map((address) => ({ target: address })), abi: abi["token"] }); - _.each(underlyingIVaultAddressResults.output, (token) => { + underlyingIVaultAddressResults.output.forEach((token) => { const underlyingTokenAddress = token.output; const iVaultAddress = token.input.target; iVaultToUnderlyingToken[iVaultAddress] = underlyingTokenAddress; @@ -60,13 +60,13 @@ async function tvl(timestamp, block) { // Get iVault's balances in underlying token const iVaultBalanceResults = await sdk.api.abi.multiCall({ block, - calls: _.map(iVaultAddresses, (address) => ({ + calls: iVaultAddresses.map((address) => ({ target: address })), abi: abi["balance"] }); - _.each(iVaultBalanceResults.output, (tokenBalanceResult) => { + iVaultBalanceResults.output.forEach((tokenBalanceResult) => { const valueInToken = tokenBalanceResult.output; const iVaultAddress = tokenBalanceResult.input.target; balances[iVaultToUnderlyingToken[iVaultAddress]] = BigNumber(balances[iVaultToUnderlyingToken[iVaultAddress]]).plus(valueInToken); @@ -76,7 +76,7 @@ async function tvl(timestamp, block) { // Get reward pool const yfiiRewardBalanceResults = await sdk.api.abi.multiCall({ block, - calls: _.map(rewardPool, (address) => ({ + calls: rewardPool.map((address) => ({ target: yfii, params: address, })), @@ -84,7 +84,7 @@ async function tvl(timestamp, block) { }); balances[yfii] = new BigNumber(0); - _.each(yfiiRewardBalanceResults.output, (tokenBalanceResult) => { + yfiiRewardBalanceResults.output.forEach((tokenBalanceResult) => { const target = tokenBalanceResult.input.target; const output = tokenBalanceResult.output;