Skip to content

Commit

Permalink
send normalized token address to price api
Browse files Browse the repository at this point in the history
  • Loading branch information
g1nt0ki committed Feb 26, 2023
1 parent 594ba75 commit bab6f43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion projects/helper/tokenMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ function getCoreAssets(chain = 'ethereum') {
return addresses
}

function normalizeAddress(address, chain) {
function normalizeAddress(address, chain, extractChain = false) {
if (!chain && extractChain && address.includes(':')) chain = address.split(':')[0]
if (caseSensitiveChains.includes(chain)) return address
return address.toLowerCase()
}
Expand Down
14 changes: 6 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const whitelistedExportKeys = require('./projects/helper/whitelistedExportKeys.j
const chainList = require('./projects/helper/chains.json')
const handleError = require('./utils/handleError')
const { log, diplayUnknownTable, sliceIntoChunks } = require('./projects/helper/utils')
const { normalizeAddress } = require('./projects/helper/tokenMapping')
const { PromisePool } = require('@supercharge/promise-pool')

const locks = [];
Expand Down Expand Up @@ -324,15 +325,12 @@ async function computeTVL(balances, timestamp) {
fixBalances(balances)

Object.keys(balances).map(k => {
if (+balances[k] === 0) {
delete balances[k]
return;
}
if (k.toLowerCase() === k || k.startsWith("solana:")) return;
balances[k.toLowerCase()] = (k.toLowerCase() in balances)
? Number(balances[k.toLowerCase()])
+ Number(balances[k]) : balances[k];
const balance = balances[k]
delete balances[k]
if (+balance === 0)
return;
const normalizedAddress = normalizeAddress(k, undefined, true)
sdk.util.sumSingleBalance(balances, normalizedAddress, balance)
})

const eth = balances[ethereumAddress];
Expand Down

0 comments on commit bab6f43

Please sign in to comment.