Skip to content

Commit

Permalink
use bigint (#995)
Browse files Browse the repository at this point in the history
  • Loading branch information
franzns authored Oct 2, 2024
1 parent 56b06a5 commit e96b9be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/ninety-zoos-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'backend': patch
---

use bigint in tokenpair sync
9 changes: 4 additions & 5 deletions modules/pool/lib/pool-on-chain-tokenpair-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Multicaller3Viem, IMulticaller } from '../../web3/multicaller-viem';
import { BigNumber } from '@ethersproject/bignumber';
import BalancerQueries from '../abi/BalancerQueries.json';
import { MathSol, WAD, ZERO_ADDRESS } from '@balancer/sdk';
import { parseEther, parseUnits } from 'viem';
Expand Down Expand Up @@ -61,9 +60,9 @@ interface Token {
}

interface OnchainData {
effectivePriceAmountOut: BigNumber;
aToBAmountOut: BigNumber;
bToAAmountOut: BigNumber;
effectivePriceAmountOut: bigint;
aToBAmountOut: bigint;
bToAAmountOut: bigint;
}

export async function fetchTokenPairData(pools: PoolInput[], balancerQueriesAddress: string, batchSize = 1024) {
Expand Down Expand Up @@ -290,7 +289,7 @@ function addBToAPriceCallsToMulticaller(
function getAmountOutAndEffectivePriceFromResult(tokenPair: TokenPair, onchainResults: { [id: string]: OnchainData }) {
const result = onchainResults[`${tokenPair.poolId}-${tokenPair.tokenA.address}-${tokenPair.tokenB.address}`];

if (result?.effectivePriceAmountOut && result.effectivePriceAmountOut.gt(0) && result.aToBAmountOut) {
if (result?.effectivePriceAmountOut && result.effectivePriceAmountOut > 0n && result.aToBAmountOut) {
tokenPair.aToBAmountOut = BigInt(result.aToBAmountOut.toString());
// MathSol expects all values with 18 decimals, need to scale them
tokenPair.effectivePrice = MathSol.divDownFixed(
Expand Down

0 comments on commit e96b9be

Please sign in to comment.