From 941b24c722e811f885f0188fdb1a9e3e8e650ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Est=C3=A1cio=20=7C=20stacio=2Eeth?= Date: Mon, 18 Jul 2022 10:17:37 -0300 Subject: [PATCH] fix: bignumber overflow use native bigint (#370) --- docker/fuel-core/Dockerfile | 2 +- .../scripts/contracts-init/initializePool.ts | 35 ++++++++++--------- .../Core/hooks/__mocks__/useBalances.ts | 2 +- packages/app/src/systems/Core/utils/math.ts | 11 +++--- .../Pool/hooks/__mocks__/useAddLiquidity.ts | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docker/fuel-core/Dockerfile b/docker/fuel-core/Dockerfile index 061da84f..9d54f64d 100644 --- a/docker/fuel-core/Dockerfile +++ b/docker/fuel-core/Dockerfile @@ -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 diff --git a/packages/app/scripts/contracts-init/initializePool.ts b/packages/app/scripts/contracts-init/initializePool.ts index 6d3469e0..94b262e9 100644 --- a/packages/app/scripts/contracts-init/initializePool.ts +++ b/packages/app/scripts/contracts-init/initializePool.ts @@ -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, + } + ); } diff --git a/packages/app/src/systems/Core/hooks/__mocks__/useBalances.ts b/packages/app/src/systems/Core/hooks/__mocks__/useBalances.ts index c39bd984..70840a29 100644 --- a/packages/app/src/systems/Core/hooks/__mocks__/useBalances.ts +++ b/packages/app/src/systems/Core/hooks/__mocks__/useBalances.ts @@ -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 = { diff --git a/packages/app/src/systems/Core/utils/math.ts b/packages/app/src/systems/Core/utils/math.ts index af20b7ba..1fb615bd 100644 --- a/packages/app/src/systems/Core/utils/math.ts +++ b/packages/app/src/systems/Core/utils/math.ts @@ -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; @@ -24,11 +23,11 @@ export function toFixed(number: Maybe, maxDecimals: number = FIXED } export function toNumber(number: Maybe) { - 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) { @@ -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 { diff --git a/packages/app/src/systems/Pool/hooks/__mocks__/useAddLiquidity.ts b/packages/app/src/systems/Pool/hooks/__mocks__/useAddLiquidity.ts index 1fef2654..42ff0a6a 100644 --- a/packages/app/src/systems/Pool/hooks/__mocks__/useAddLiquidity.ts +++ b/packages/app/src/systems/Pool/hooks/__mocks__/useAddLiquidity.ts @@ -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(