Skip to content

Commit

Permalink
logArrays gone
Browse files Browse the repository at this point in the history
  • Loading branch information
waynebruce0x committed Dec 19, 2023
1 parent 278dc63 commit 80248cc
Show file tree
Hide file tree
Showing 39 changed files with 95 additions and 118 deletions.
6 changes: 3 additions & 3 deletions projects/alexar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const chainListTotal = ['avax', 'bsc', 'moonbeam', 'polygon', 'fantom', 'arbitru

chainListSupply.concat(chainListTotal).forEach(chain => {
module.exports[chain] = { tvl };
async function tvl(_, _b, _cb, { api, logArray }) {
async function tvl(_, _b, _cb, { api }) {
const config = await getConfig('alexar', 'https://api.axelarscan.io/cross-chain/tvl')
const tokensAndOwners = []
const owners = []
Expand All @@ -34,8 +34,8 @@ chainListSupply.concat(chainListTotal).forEach(chain => {
}
})
if (tokensAndOwners.length > 0)
return api.sumTokens({ tokensAndOwners, logArray })
return sumTokens({ chain, owners, logArray })
return api.sumTokens({ tokensAndOwners })
return sumTokens({ chain, owners })
}
});

Expand Down
4 changes: 2 additions & 2 deletions projects/allbridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ const nearData = {
const toNumber = (decimals, n) => BigNumber(n/(10 ** decimals)).toFixed(0)

function getTVLFunction(chain) {
return async function tvl(timestamp, ethBlock, {[chain]: block }, { logArray }) {
return async function tvl(timestamp, ethBlock, {[chain]: block }) {
const balances = {}
const chainData = data[chain];
const tokens = chainData.tokens.map(i => i.address)
return sumTokens2({ chain, block, tokens, owner: chainData.contractAddress, logArray })
return sumTokens2({ chain, block, tokens, owner: chainData.contractAddress })
}
}

Expand Down
4 changes: 2 additions & 2 deletions projects/allchainbridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ const tokensConf = {
* END OF CONFIGURATION
*/

const createTvlFunction = (chain) => async (timestamp, block, chainBlocks, { logArray }) => {
const createTvlFunction = (chain) => async (timestamp, block, chainBlocks) => {
const bridgeContract = getBridgeContract(chain);
const tokens = Object.values(tokensConf[chain])
const owners = [bridgeContract]
return sumTokens2({ chain, block:chainBlocks[chain], tokens, owners, logArray })
return sumTokens2({ chain, block:chainBlocks[chain], tokens, owners })
};

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions projects/anyswap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const EXECUTOR = '0x2A038e100F8B85DF21e4d44121bdBfE0c288A869'
const NEW_ADDR = '0x1eed63efba5f81d95bfe37d82c8e736b974f477b'

function fetchChain(chain) {
return async (_, _1, _2, { api, logArray }) => {
return async (_, _1, _2, { api }) => {
const data = await getChainData()
const protocolsInChain = chain === null ? data : data.filter(p => p.srcChainId.toString() === chain.toString())
const tokensAndOwners = []
Expand All @@ -100,7 +100,7 @@ function fetchChain(chain) {
}
})

return sumTokens({ api, tokensAndOwners, blacklistedTokens, logArray })
return sumTokens({ api, tokensAndOwners, blacklistedTokens })
}
}

Expand Down
3 changes: 1 addition & 2 deletions projects/arbitrum/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { sumTokens2 } = require("../helper/unwrapLPs");

module.exports = {
ethereum: {
tvl: (_, _b, _c, { api, logArray }) =>
tvl: (_, _b, _c, { api }) =>
sumTokens2({
api,
owners: [
Expand All @@ -12,7 +12,6 @@ module.exports = {
"0xA10c7CE4b876998858b1a9E12b10092229539400",
],
fetchCoValentTokens: true,
logArray,
}),
},
};
3 changes: 1 addition & 2 deletions projects/arbitrumNova/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { sumTokens2 } = require("../helper/unwrapLPs");

module.exports = {
ethereum: {
tvl: (_, _b, _c, { api, logArray }) =>
tvl: (_, _b, _c, { api }) =>
sumTokens2({
api,
owners: [
Expand All @@ -12,7 +12,6 @@ module.exports = {
"0xA2e996f0cb33575FA0E36e8f62fCd4a9b897aAd3"
],
fetchCoValentTokens: true,
logArray,
}),
},
};
6 changes: 2 additions & 4 deletions projects/avax/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ const { sumTokens2 } = require("../helper/unwrapLPs");

module.exports = {
ethereum: {
tvl: (_, _b, _c, { api, logArray }) =>
tvl: (_, _b, _c, { api }) =>
sumTokens2({
api,
owner: "0x8EB8a3b98659Cce290402893d0123abb75E3ab28",
fetchCoValentTokens: true,
logArray,
}),
},
bitcoin: {
tvl: async (_, _b, chainBlocks, { logArray }) => ({
tvl: async (_, _b, chainBlocks) => ({
bitcoin:
(await call({
chain: "avax",
abi: "erc20:totalSupply",
target: ADDRESSES.avax.BTC_b,
block: chainBlocks.avax,
logArray,
})) /
10 ** 8,
}),
Expand Down
3 changes: 1 addition & 2 deletions projects/base/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ const { sumTokens2 } = require("../helper/unwrapLPs");

module.exports = {
ethereum: {
tvl: (_, _b, _c, { api, logArray }) =>
tvl: (_, _b, _c, { api }) =>
sumTokens2({
api,
owners: [
"0x3154Cf16ccdb4C6d922629664174b904d80F2C35",
"0x49048044D57e1C92A77f79988d21Fa8fAF74E97e",
],
fetchCoValentTokens: true,
logArray,
}),
},
};
4 changes: 2 additions & 2 deletions projects/biconomy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ module.exports = {
}

Object.keys(config).forEach(chain => module.exports[chain] = {
tvl: async (time, _, { [chain]: block }, { logArray }) => {
tvl: async (time, _, { [chain]: block }) => {
const { bridges, tokens, } = config[chain]
return sumTokens2({ chain, block, owners: bridges, tokens, logArray });
return sumTokens2({ chain, block, owners: bridges, tokens });
}
})
3 changes: 1 addition & 2 deletions projects/boba/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ const { sumTokens2 } = require("../helper/unwrapLPs");

module.exports = {
ethereum: {
tvl: (_, _b, _c, { api, logArray }) =>
tvl: (_, _b, _c, { api }) =>
sumTokens2({
api,
owners: [
"0xdc1664458d2f0B6090bEa60A8793A4E66c2F1c00",
"0x1A26ef6575B7BBB864d984D9255C069F6c361a14",
],
fetchCoValentTokens: true,
logArray,
}),
},
};
4 changes: 2 additions & 2 deletions projects/celerbridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ const liquidityBridgeTokens = [
];

function chainTvl(chain) {
return async (time, _, {[chain]: block}, { logArray }) => {
return async (time, _, {[chain]: block}) => {
const toa = []
liquidityBridgeTokens.forEach(token => {
if (!token[chain])
Expand All @@ -519,7 +519,7 @@ function chainTvl(chain) {
liquidityBridgeContractsV2[chain].filter(owner => owner.toLowerCase() !== bridgeContractV1.toLowerCase())
.forEach(owner => toa.push([token[chain], owner]))
})
const balances = await sumTokens({}, toa, block, chain, undefined, { logArray })
const balances = await sumTokens({}, toa, block, chain, undefined)
return balances
};
}
Expand Down
4 changes: 2 additions & 2 deletions projects/cennz-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const sdk = require("@defillama/sdk");
const target = '0x76BAc85e1E82cd677faa2b3f00C4a2626C4c6E32';
const WETH = ADDRESSES.ethereum.WETH;

async function tvl(timestamp, block, _, { logArray }) {
async function tvl(timestamp, block, _) {
return { [ WETH ]:
(await sdk.api.eth.getBalance({ target, block, logArray })).output
(await sdk.api.eth.getBalance({ target, block })).output
};
}

Expand Down
4 changes: 2 additions & 2 deletions projects/debridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const chainIds = {
};

function chainTvl(chain) {
return async (timestamp, ethBlock, {[chain]: block}, { logArray }) => {
return async (timestamp, ethBlock, {[chain]: block}) => {
const balances = {};
const transformAddress = id=>`${chain}:${id}`;

Expand All @@ -24,7 +24,7 @@ function chainTvl(chain) {
.filter(t => !t.tokenName.startsWith('deBridge '))
.map(t => [t.tokenAddress, debridgeGate]);

await sumTokens(balances, tokensAndOwners, block, chain, transformAddress, { logArray });
await sumTokens(balances, tokensAndOwners, block, chain, transformAddress);

return balances
};
Expand Down
4 changes: 2 additions & 2 deletions projects/dotoracle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ module.exports = {

Object.keys(config).forEach(chain => {
module.exports[chain] = {
tvl: (_, _b, {[chain]: block}, { logArray }) => {
tvl: (_, _b, {[chain]: block}) => {
const { bridges: owners, tokens } = config[chain]
return sumTokens2({ tokens: Object.values(tokens), owners, chain, block, logArray })
return sumTokens2({ tokens: Object.values(tokens), owners, chain, block })
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions projects/elysiumBridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ module.exports = {

Object.keys(config).forEach(chain => {
module.exports[chain] = {
tvl: (_, _b, {[chain]: block, logArray }) => {
tvl: (_, _b, {[chain]: block }) => {
const { bridges: owners, tokens } = config[chain]
return sumTokens2({ tokens: Object.values(tokens), owners, chain, block, logArray })
return sumTokens2({ tokens: Object.values(tokens), owners, chain, block })
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion projects/gravity-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ module.exports = {
}
};

async function tvl(_, _b, _cb, { api, logArray }) {
async function tvl(_, _b, _cb, { api }) {
const bals = await getBalance2({ chain: 'gravitybridge', owner: 'gravity16n3lc7cywa68mg50qhp847034w88pntqzx3ksm'})
Object.entries(bals).forEach(([key, val]) => {
if (key.startsWith('gravity0x')) {
Expand Down
4 changes: 2 additions & 2 deletions projects/helper/sumTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ async function getBalance(chain, account) {
}

function sumTokensExport(options) {
return async (_, _b, _cb, { api, logArray }) => sumTokens(
{ ...api, api, logArray: options.logCalls ? logArray : undefined, ...options }
return async (_, _b, _cb, { api }) => sumTokens(
{ ...api, api, ...options }
)
}

Expand Down
22 changes: 9 additions & 13 deletions projects/helper/unwrapLPs.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ tokensAndOwners [
[token, owner] - eg ["0xaaa", "0xbbb"]
]
*/
async function sumTokens(balances = {}, tokensAndOwners, block, chain = "ethereum", transformAddress, { resolveLP = false, unwrapAll = false, blacklistedLPs = [], skipFixBalances = false, abis = {}, permitFailure = false, logArray, sumChunkSize = undefined } = {}) {
async function sumTokens(balances = {}, tokensAndOwners, block, chain = "ethereum", transformAddress, { resolveLP = false, unwrapAll = false, blacklistedLPs = [], skipFixBalances = false, abis = {}, permitFailure = false, sumChunkSize = undefined } = {}) {
if (!transformAddress)
transformAddress = await getChainTransform(chain)

Expand All @@ -405,7 +405,7 @@ async function sumTokens(balances = {}, tokensAndOwners, block, chain = "ethereu
// const ethBalances = await Promise.all(ethBalanceInputs.map(getTrxBalance))
// ethBalances.forEach(balance => sdk.util.sumSingleBalance(balances, transformAddress(nullAddress), balance))
// } else {
const { output: ethBalances } = await sdk.api.eth.getBalances({ targets: ethBalanceInputs, chain, block, logArray })
const { output: ethBalances } = await sdk.api.eth.getBalances({ targets: ethBalanceInputs, chain, block })
ethBalances.forEach(({ balance }) => sdk.util.sumSingleBalance(balances, transformAddress(nullAddress), balance))
// }
}
Expand All @@ -424,7 +424,6 @@ async function sumTokens(balances = {}, tokensAndOwners, block, chain = "ethereu
abi: 'erc20:balanceOf',
block,
chain,
logArray
})
balanceOfTokens.output.forEach((result) => {
const token = transformAddress(result.input.target)
Expand All @@ -444,7 +443,7 @@ async function sumTokens(balances = {}, tokensAndOwners, block, chain = "ethereu
})

if (resolveLP || unwrapAll)
await unwrapLPsAuto({ balances, block, chain, transformAddress, blacklistedLPs, abis, logArray })
await unwrapLPsAuto({ balances, block, chain, transformAddress, blacklistedLPs, abis })

if (!skipFixBalances && ['astar', 'harmony', 'kava', 'thundercore', 'klaytn', 'evmos'].includes(chain)) {
const fixBalances = await getFixBalances(chain)
Expand Down Expand Up @@ -550,7 +549,7 @@ async function genericUnwrapCvxRewardPool({ api, owner, pool, balances }) {
return balances
}

async function unwrapLPsAuto({ api, balances, block, chain = "ethereum", transformAddress, excludePool2 = false, onlyPool2 = false, pool2Tokens = [], blacklistedLPs = [], abis = {}, logArray }) {
async function unwrapLPsAuto({ api, balances, block, chain = "ethereum", transformAddress, excludePool2 = false, onlyPool2 = false, pool2Tokens = [], blacklistedLPs = [], abis = {} }) {
if (api) {
chain = api.chain ?? chain
block = api.block ?? block
Expand Down Expand Up @@ -588,7 +587,7 @@ async function unwrapLPsAuto({ api, balances, block, chain = "ethereum", transfo

async function _addTokensAndLPs(balances, tokens, amounts) {
const symbols = (await sdk.api.abi.multiCall({
calls: tokens.map(t => ({ target: t.output })), abi: symbol, block, chain, permitFailure: true, logArray
calls: tokens.map(t => ({ target: t.output })), abi: symbol, block, chain, permitFailure: true,
})).output
const lpBalances = []
symbols.forEach(({ output }, idx) => {
Expand All @@ -599,11 +598,11 @@ async function unwrapLPsAuto({ api, balances, block, chain = "ethereum", transfo
else
sdk.util.sumSingleBalance(balances, transformAddress(token), balance);
})
await _unwrapUniswapLPs(balances, lpBalances, logArray)
await _unwrapUniswapLPs(balances, lpBalances)
return balances
}

async function _unwrapUniswapLPs(balances, lpPositions, logArray) {
async function _unwrapUniswapLPs(balances, lpPositions) {
const lpTokenCalls = lpPositions.map(lpPosition => ({ target: lpPosition.token }))
const { output: lpReserves } = await sdk.api.abi.multiCall({ block, abi: abis.getReservesABI || lpReservesAbi, calls: lpTokenCalls, chain, })
const { output: lpSupplies } = await sdk.api.abi.multiCall({ block, abi: lpSuppliesAbi, calls: lpTokenCalls, chain, })
Expand All @@ -617,7 +616,6 @@ async function unwrapLPsAuto({ api, balances, block, chain = "ethereum", transfo
const token0_ = tokens0.find(call => call.input.target === lpToken)
const token1_ = tokens1.find(call => call.input.target === lpToken)
const supply_ = lpSupplies.find(call => call.input.target === lpToken)
if (logArray) logArray.push(...[{ token: token0_, holder: lpToken }, { token: token1_, holder: lpToken }])
try {
token0 = token0_.output.toLowerCase()
token1 = token1_.output.toLowerCase()
Expand Down Expand Up @@ -685,7 +683,6 @@ async function sumTokens2({
permitFailure = false,
fetchCoValentTokens = false,
tokenConfig = {},
logArray,
sumChunkSize = undefined,
}) {
if (api) {
Expand All @@ -708,7 +705,6 @@ async function sumTokens2({
}

if (resolveVlCVX && owners.length && chain === 'ethereum') {
if (logArray) logArray.push(...owners.map(owner => ({ token: ADDRESSES.ethereum.vlCVX, owner })))
const vlCVXBals = await api.multiCall({ abi: 'erc20:balanceOf', calls: owners, target: ADDRESSES.ethereum.vlCVX })
vlCVXBals.forEach((v) => sdk.util.sumSingleBalance(balances, ADDRESSES.ethereum.vlCVX, v, chain))
}
Expand Down Expand Up @@ -746,7 +742,7 @@ async function sumTokens2({
tokensAndOwners = getUniqueToA(tokensAndOwners)
log(chain, 'summing tokens', tokensAndOwners.length)

await sumTokens(balances, tokensAndOwners, block, chain, transformAddress, { resolveLP, unwrapAll, blacklistedLPs, skipFixBalances: true, abis, permitFailure, logArray, sumChunkSize, })
await sumTokens(balances, tokensAndOwners, block, chain, transformAddress, { resolveLP, unwrapAll, blacklistedLPs, skipFixBalances: true, abis, permitFailure, sumChunkSize, })


if (!skipFixBalances) {
Expand All @@ -763,7 +759,7 @@ async function sumTokens2({
}

function sumTokensExport({ balances, tokensAndOwners, tokensAndOwners2, tokens, owner, owners, transformAddress, unwrapAll, resolveLP, blacklistedLPs, blacklistedTokens, skipFixBalances, ownerTokens, resolveUniV3, resolveArtBlocks, resolveNFTs, fetchCoValentTokens, logCalls, ...args }) {
return async (_, _b, _cb, { api, logArray }) => sumTokens2({ api, balances, tokensAndOwners, tokensAndOwners2, tokens, owner, owners, transformAddress, unwrapAll, resolveLP, blacklistedLPs, blacklistedTokens, skipFixBalances, ownerTokens, resolveUniV3, resolveArtBlocks, resolveNFTs, fetchCoValentTokens, logArray: logCalls ? logArray : undefined, ...args, })
return async (_, _b, _cb, { api }) => sumTokens2({ api, balances, tokensAndOwners, tokensAndOwners2, tokens, owner, owners, transformAddress, unwrapAll, resolveLP, blacklistedLPs, blacklistedTokens, skipFixBalances, ownerTokens, resolveUniV3, resolveArtBlocks, resolveNFTs, fetchCoValentTokens, ...args, })
}

async function unwrapBalancerToken({ api, chain, block, balancerToken, owner, balances = {}, isBPool = false, isV2 = true }) {
Expand Down
4 changes: 2 additions & 2 deletions projects/hotcross/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const chainKeys = {
};

function tvl(chain, get) {
return async (_t, _e, { [chain]: block }, { logArray }) => {
return async (_t, _e, { [chain]: block }) => {
const assets = (await get).data;
const tokensAndOwners = assets.map((data) => [
data[chainKeys[chain].asset],
data[`${chainKeys[chain].chain}BridgeAddress`],
]);
return sumTokens2({ tokensAndOwners, block, chain, logArray });
return sumTokens2({ tokensAndOwners, block, chain });
};
}

Expand Down
Loading

0 comments on commit 80248cc

Please sign in to comment.