Skip to content

Commit

Permalink
remove npm dependency: underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed May 20, 2022
1 parent 81e6df0 commit 0f06835
Show file tree
Hide file tree
Showing 67 changed files with 295 additions and 317 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
13 changes: 1 addition & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions projects/88mph/index.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -78,15 +78,15 @@ 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,
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`)
Expand All @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions projects/acoconut/index.js
Original file line number Diff line number Diff line change
@@ -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 = [
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions projects/auctus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
==================================================*/

const sdk = require('@defillama/sdk');
const _ = require('underscore');

const abi = require('./abi.json');
const { default: BigNumber } = require('bignumber.js');

Expand Down Expand Up @@ -74,21 +74,21 @@

let collateralResult = await sdk.api.abi.multiCall({
block,
calls: _.map(acoOptionsAddresses, (option) => ({
calls: acoOptionsAddresses.map((option) => ({
target: option
})),
abi: abi.collateral,
});

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,
Expand All @@ -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"
Expand All @@ -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,
})))
Expand Down Expand Up @@ -153,21 +153,21 @@

let balancesResult = await sdk.api.abi.multiCall({
block,
calls: _.map(acoVaultsAddresses, (vault) => ({
calls: acoVaultsAddresses.map((vault) => ({
target: vault
})),
abi: abi.balance,
});

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();
Expand Down
12 changes: 6 additions & 6 deletions projects/balancer/onchain.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -94,7 +94,7 @@ function v2(chain) {
tokenAddresses.push(address.address)
}
}
tokenAddresses = _.uniq(tokenAddresses);
tokenAddresses = [...new Set(tokenAddresses)]

let v2Calls = tokenAddresses.map((address) => {
return {
Expand Down
6 changes: 3 additions & 3 deletions projects/bearnfi/index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions projects/bprotocol/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Modules
==================================================*/

const _ = require('underscore');

const sdk = require('@defillama/sdk');
const abi = require('./abi.json');
const BigNumber = require("bignumber.js");
Expand Down Expand Up @@ -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)
})

Expand Down
10 changes: 5 additions & 5 deletions projects/complifi/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('underscore');

const sdk = require('@defillama/sdk');
const abi = require('./abi.json');

Expand Down Expand Up @@ -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,
Expand All @@ -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,
})),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
})),
Expand Down
12 changes: 6 additions & 6 deletions projects/compound-onchain/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const _ = require('underscore');

const sdk = require('@defillama/sdk');
const abi = require('./abi.json');
const v1abi = require('./v1Abi.json');
Expand Down Expand Up @@ -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',
})),
Expand All @@ -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();
Expand All @@ -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,
})),
Expand Down
Loading

0 comments on commit 0f06835

Please sign in to comment.