Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix: bignumber overflow use native bigint (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio authored Jul 18, 2022
1 parent 57974bb commit 941b24c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docker/fuel-core/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/fuellabs/fuel-core:v0.9.2
FROM ghcr.io/fuellabs/fuel-core:v0.9.6

ARG IP=0.0.0.0
ARG PORT=4000
Expand Down
35 changes: 18 additions & 17 deletions packages/app/scripts/contracts-init/initializePool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,23 @@ export async function initializePool(
variableOutputs: 1,
});

process.stdout.write('Initialize pool\n');
const deadline = await wallet.provider.getBlockNumber();

process.stdout.write('Depositing ETH\n');
await exchangeContract.submit.deposit({
forward: [ethAmount, NativeAssetId],
...overrides,
});
process.stdout.write('Depositing Token\n');
await exchangeContract.submit.deposit({
forward: [tokenAmount, tokenContract.id],
...overrides,
});
process.stdout.write('Add liquidity\n');
await exchangeContract.submit.add_liquidity(1, deadline + BigInt(1000), {
...overrides,
variableOutputs: 2,
gasLimit: 100_000_000,
});
await exchangeContract.submitMulticall(
[
exchangeContract.prepareCall.deposit({
forward: [ethAmount, NativeAssetId],
}),
exchangeContract.prepareCall.deposit({
forward: [tokenAmount, tokenContract.id],
}),
exchangeContract.prepareCall.add_liquidity(1, deadline + BigInt(1000), {
variableOutputs: 2,
}),
],
{
...overrides,
gasLimit: 100_000_000,
}
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as useBalances from '../useBalances';

import { DECIMAL_UNITS } from '~/config';

const FAKE_BALANCE = [{ amount: parseUnits('3', DECIMAL_UNITS).toBigInt(), assetId: COIN_ETH }];
const FAKE_BALANCE = [{ amount: parseUnits('3', DECIMAL_UNITS), assetId: COIN_ETH }];

export function mockUseBalances(balances?: CoinQuantity[]) {
const mock = {
Expand Down
11 changes: 5 additions & 6 deletions packages/app/src/systems/Core/utils/math.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { BigNumberish } from '@ethersproject/bignumber';
import { BigNumber } from '@ethersproject/bignumber';
import * as ethers from '@ethersproject/units';
import { Decimal } from 'decimal.js';
import type { BigNumberish } from 'fuels';

import { DECIMAL_UNITS, FIXED_UNITS } from '~/config';
import type { Maybe } from '~/types';

export const ZERO = toBigInt(0);

export const ONE_ASSET = parseUnits('1', DECIMAL_UNITS).toBigInt();
export const ONE_ASSET = parseUnits('1', DECIMAL_UNITS);
// Max value supported
// eslint-disable-next-line @typescript-eslint/no-loss-of-precision
export const MAX_U64_VALUE = 0xffff_ffff_ffff_ffff;
Expand All @@ -24,11 +23,11 @@ export function toFixed(number: Maybe<BigNumberish>, maxDecimals: number = FIXED
}

export function toNumber(number: Maybe<BigNumberish>) {
return BigNumber.from(number || 0).toNumber();
return Number(BigInt(number || '0'));
}

export function parseUnits(number: string, precision: number = DECIMAL_UNITS) {
return ethers.parseUnits(number, precision);
return ethers.parseUnits(number, precision).toBigInt();
}

export function parseInputValueBigInt(value: string) {
Expand All @@ -40,7 +39,7 @@ export function parseInputValueBigInt(value: string) {
}

export function toBigInt(number: BigNumberish) {
return BigNumber.from(number).toBigInt();
return BigInt(number);
}

export function formatUnits(number: BigNumberish, precision: number = DECIMAL_UNITS): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getOverrides } from '~/systems/Core/utils/gas';
import { ExchangeContractAbi__factory } from '~/types/contracts';

function parseToBigInt(amount: string) {
return parseUnits(amount, DECIMAL_UNITS).toBigInt();
return parseUnits(amount, DECIMAL_UNITS);
}

export async function addLiquidity(
Expand Down

0 comments on commit 941b24c

Please sign in to comment.