Skip to content

Commit

Permalink
fix: onchain data defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
gmbronco committed Sep 28, 2023
1 parent a727d66 commit f0356e3
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions balancer-js/src/modules/data/pool/onchain-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,32 @@ const poolTypeCalls = (poolType: string, poolTypeVersion = 1) => {

const merge = (pool: SubgraphPoolBase, result: OnchainData) => ({
...pool,
tokens: pool.tokens.map((token) => {
const idx = result.poolTokens[0]
.map((t) => t.toLowerCase())
.indexOf(token.address);
const wrappedToken =
pool.wrappedIndex && pool.tokensList[pool.wrappedIndex];
return {
...token,
balance: formatFixed(result.poolTokens[1][idx], token.decimals || 18),
weight:
(result.weights && formatFixed(result.weights[idx], 18)) ||
token.weight,
priceRate:
(result.wrappedTokenRate &&
wrappedToken &&
wrappedToken.toLowerCase() === token.address.toLowerCase() &&
formatFixed(result.wrappedTokenRate, 18)) ||
token.priceRate,
} as SubgraphToken;
}),
tokens: result.poolTokens
? pool.tokens.map((token) => {
const idx = result.poolTokens[0]
.map((t) => t.toLowerCase())
.indexOf(token.address);
const wrappedToken =
pool.wrappedIndex && pool.tokensList[pool.wrappedIndex];
return {
...token,
balance: formatFixed(result.poolTokens[1][idx], token.decimals || 18),
weight:
(result.weights && formatFixed(result.weights[idx], 18)) ||
token.weight,
priceRate:
(result.wrappedTokenRate &&
wrappedToken &&
wrappedToken.toLowerCase() === token.address.toLowerCase() &&
formatFixed(result.wrappedTokenRate, 18)) ||
token.priceRate,
} as SubgraphToken;
})
: pool.tokens,
totalShares: result.totalShares
? formatFixed(result.totalShares, 18)
: pool.totalShares,
swapFee: formatFixed(result.swapFee, 18),
swapFee: result.swapFee ? formatFixed(result.swapFee, 18) : pool.swapFee,
amp:
(result.amp &&
result.amp[0] &&
Expand Down

0 comments on commit f0356e3

Please sign in to comment.