mirror of
https://github.com/alexgo-io/DefiLlama-Adapters.git
synced 2026-04-29 21:36:44 +08:00
fix near helper
This commit is contained in:
@@ -90,16 +90,13 @@ function sumSingleBalance(balances, token, balance) {
|
||||
|
||||
if (name) {
|
||||
if (decimals)
|
||||
balance = BigNumber(balance).shiftedBy(-1 * decimals)
|
||||
balance = balance / (10 ** decimals)
|
||||
|
||||
if (!balances[name])
|
||||
balances[name] = BigNumber(0)
|
||||
|
||||
balances[name] = balances[name].plus(balance)
|
||||
balances[name] = BigNumber(+(balances[name] || 0) + balance).toFixed(0)
|
||||
return
|
||||
}
|
||||
|
||||
sdk.util.sumSingleBalance(balances, transformAddress(token), balance)
|
||||
sdk.util.sumSingleBalance(balances, transformAddress(token), BigNumber(balance).toFixed(0))
|
||||
return balances
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { BigNumber } = require('bignumber.js');
|
||||
const { call, addTokenBalances, sumSingleBalance } = require('./helper/near');
|
||||
const { call, addTokenBalances, sumSingleBalance } = require('../helper/near');
|
||||
|
||||
const PEMBROCK_CONTRACT = "v1.pembrock.near";
|
||||
const REF_FINANCE_CONTRACT = "v2.ref-finance.near";
|
||||
15
test.js
15
test.js
@@ -321,19 +321,6 @@ const ethereumAddress = "0x0000000000000000000000000000000000000000";
|
||||
const weth = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
||||
const DAY = 24 * 3600;
|
||||
|
||||
function sumSingleBalance(balances, token, balance) {
|
||||
if (typeof balance === 'number') {
|
||||
const prevBalance = balances[token] ?? 0
|
||||
if (typeof prevBalance !== 'number') {
|
||||
throw new Error(`Trying to merge token balance and coingecko amount for ${token}`)
|
||||
}
|
||||
balances[token] = prevBalance + balance;
|
||||
} else {
|
||||
const prevBalance = BigNumber(balances[token] ?? "0");
|
||||
balances[token] = prevBalance.plus(balance);
|
||||
}
|
||||
}
|
||||
|
||||
function fixBalances(balances) {
|
||||
Object.entries(balances).forEach(([token, value]) => {
|
||||
let newKey
|
||||
@@ -341,7 +328,7 @@ function fixBalances(balances) {
|
||||
else if (!token.includes(':')) newKey = `coingecko:${token}`
|
||||
if (newKey) {
|
||||
delete balances[token]
|
||||
sumSingleBalance(balances, newKey, value)
|
||||
sdk.util.sumSingleBalance(balances, newKey, value)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user