From 90bc7969dc07d39656d48447ec8c5d209c9f9ee7 Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Mon, 16 May 2022 19:01:56 +0530 Subject: [PATCH] update bastion --- projects/bastion/index.js | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/projects/bastion/index.js b/projects/bastion/index.js index 844a0fe71..75a5067c8 100644 --- a/projects/bastion/index.js +++ b/projects/bastion/index.js @@ -1,5 +1,5 @@ const { compoundExports } = require("../helper/compound"); -const { bigNumberify } = require("../mobiusfinance/utilities/utilities"); +const sdk = require('@defillama/sdk') const mainHubExport = compoundExports( "0x6De54724e128274520606f038591A00C5E94a1F6", @@ -35,38 +35,18 @@ module.exports = { aurora: { tvl: async (...args) => { let balances = {}; - for (const realm of bastion) { - const realmBalances = await realm.tvl(...args); - for (const underlyingAddress of Object.keys(realmBalances)) { - if (underlyingAddress in balances) { - balances[underlyingAddress] = bigNumberify( - balances[underlyingAddress] - ) - .add(bigNumberify(realmBalances[underlyingAddress])) - .toString(); - } else { - balances[underlyingAddress] = realmBalances[underlyingAddress]; - } - } - } + const tvls = await Promise.all(bastion.map(realm => realm.tvl(...args))) + tvls.forEach(tvl => { + Object.keys(tvl).forEach(key => sdk.util.sumSingleBalance(balances, key, tvl[key])) + }) return balances; }, borrowed: async (...args) => { let balances = {}; - for (const realm of bastion) { - const realmBalances = await realm.borrowed(...args); - for (const underlyingAddress of Object.keys(realmBalances)) { - if (underlyingAddress in balances) { - balances[underlyingAddress] = bigNumberify( - balances[underlyingAddress] - ) - .add(bigNumberify(realmBalances[underlyingAddress])) - .toString(); - } else { - balances[underlyingAddress] = realmBalances[underlyingAddress]; - } - } - } + const tvls = await Promise.all(bastion.map(realm => realm.borrowed(...args))) + tvls.forEach(tvl => { + Object.keys(tvl).forEach(key => sdk.util.sumSingleBalance(balances, key, tvl[key])) + }) return balances; }, },