diff --git a/app/components/Nav/Main/RootRPCMethodsUI.js b/app/components/Nav/Main/RootRPCMethodsUI.js index 086d3c3a61f..310fa254e2e 100644 --- a/app/components/Nav/Main/RootRPCMethodsUI.js +++ b/app/components/Nav/Main/RootRPCMethodsUI.js @@ -25,7 +25,7 @@ import { getIsSwapApproveOrSwapTransaction, isApprovalTransaction, } from '../../../util/transactions'; -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; import Logger from '../../../util/Logger'; import TransactionTypes from '../../../core/TransactionTypes'; import { swapsUtils } from '@metamask/swaps-controller'; diff --git a/app/components/UI/ConfirmAddAsset/ConfirmAddAsset.test.tsx b/app/components/UI/ConfirmAddAsset/ConfirmAddAsset.test.tsx index ed1a2f5fdc3..b3109f95aa8 100644 --- a/app/components/UI/ConfirmAddAsset/ConfirmAddAsset.test.tsx +++ b/app/components/UI/ConfirmAddAsset/ConfirmAddAsset.test.tsx @@ -7,7 +7,7 @@ import renderWithProvider, { import useBalance from '../Ramp/hooks/useBalance'; import { toTokenMinimalUnit } from '../../../util/number'; import { fireEvent } from '@testing-library/react-native'; -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { RootState } from '../../../reducers'; import { mockNetworkState } from '../../../util/test/network'; import { CHAIN_IDS } from '@metamask/transaction-controller'; @@ -48,7 +48,7 @@ jest.mock('../../../util/navigation/navUtils', () => ({ const mockUseBalanceInitialValue: Partial> = { balanceFiat: '$27.02', - balanceBN: toTokenMinimalUnit('5.36385', 18) as BN, + balanceBN: toTokenMinimalUnit('5.36385', 18) as BN4, }; const mockUseBalanceValues: Partial> = { diff --git a/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.test.tsx b/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.test.tsx index 9fb61eadebc..0a1eaf58221 100644 --- a/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.test.tsx +++ b/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import { Limits, Payment } from '@consensys/on-ramp-sdk'; import { act, fireEvent, screen } from '@testing-library/react-native'; -import { BN } from 'ethereumjs-util'; +import type BN4 from 'bnjs4'; import { renderScreen } from '../../../../../util/test/renderWithProvider'; import BuildQuote from './BuildQuote'; import useRegions from '../../hooks/useRegions'; @@ -191,7 +191,7 @@ jest.mock('../../../../hooks/useAddressBalance/useAddressBalance', () => const mockUseBalanceInitialValue: Partial> = { balanceFiat: '$27.02', - balanceBN: toTokenMinimalUnit('5.36385', 18) as BN, + balanceBN: toTokenMinimalUnit('5.36385', 18) as BN4, }; let mockUseBalanceValues: Partial> = { @@ -242,7 +242,7 @@ const mockUseGasPriceEstimationInitialValue: ReturnType< estimatedGasFee: toTokenMinimalUnit( '0.01', mockUseRampSDKInitialValues.selectedAsset?.decimals || 18, - ) as BN, + ) as BN4, }; let mockUseGasPriceEstimationValue: ReturnType = @@ -669,7 +669,7 @@ describe('BuildQuote View', () => { mockUseBalanceValues.balanceBN = toTokenMinimalUnit( '5', mockUseRampSDKValues.selectedAsset?.decimals || 18, - ) as BN; + ) as BN4; render(BuildQuote); const initialAmount = '0'; const overBalanceAmout = '6'; @@ -688,7 +688,7 @@ describe('BuildQuote View', () => { mockUseBalanceValues.balanceBN = toTokenMinimalUnit( '1', mockUseRampSDKValues.selectedAsset?.decimals || 18, - ) as BN; + ) as BN4; const symbol = mockUseRampSDKValues.selectedAsset?.symbol; fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`)); fireEvent.press(getByRoleButton('25%')); @@ -719,13 +719,13 @@ describe('BuildQuote View', () => { balanceBN: toTokenMinimalUnit( '1', mockUseRampSDKValues.selectedAsset?.decimals || 18, - ) as BN, + ) as BN4, }; mockUseGasPriceEstimationValue = { estimatedGasFee: toTokenMinimalUnit( '0.27', mockUseRampSDKValues.selectedAsset?.decimals || 18, - ) as BN, + ) as BN4, }; const symbol = mockUseRampSDKValues.selectedAsset?.symbol; fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`)); @@ -752,13 +752,13 @@ describe('BuildQuote View', () => { balanceBN: toTokenMinimalUnit( '1', mockUseRampSDKValues.selectedAsset?.decimals || 18, - ) as BN, + ) as BN4, }; mockUseGasPriceEstimationValue = { estimatedGasFee: toTokenMinimalUnit( '0.27', mockUseRampSDKValues.selectedAsset?.decimals || 18, - ) as BN, + ) as BN4, }; const symbol = mockUseRampSDKValues.selectedAsset?.symbol; fireEvent.press(getByRoleButton(`${initialAmount} ${symbol}`)); diff --git a/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.tsx b/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.tsx index 04727253c4b..565210a8e3d 100644 --- a/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.tsx +++ b/app/components/UI/Ramp/Views/BuildQuote/BuildQuote.tsx @@ -12,7 +12,7 @@ import Animated, { withTiming, } from 'react-native-reanimated'; import { useNavigation } from '@react-navigation/native'; -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { useRampSDK } from '../../sdk'; import usePaymentMethods from '../../hooks/usePaymentMethods'; @@ -104,7 +104,7 @@ const BuildQuote = () => { const [amountFocused, setAmountFocused] = useState(false); const [amount, setAmount] = useState('0'); const [amountNumber, setAmountNumber] = useState(0); - const [amountBNMinimalUnit, setAmountBNMinimalUnit] = useState(); + const [amountBNMinimalUnit, setAmountBNMinimalUnit] = useState(); const [error, setError] = useState(null); const keyboardHeight = useRef(1000); const keypadOffset = useSharedValue(1000); @@ -341,7 +341,7 @@ const BuildQuote = () => { setAmountNumber(valueAsNumber); if (isSell) { setAmountBNMinimalUnit( - toTokenMinimalUnit(`${value}`, selectedAsset?.decimals ?? 0) as BN, + toTokenMinimalUnit(`${value}`, selectedAsset?.decimals ?? 0) as BN4, ); } }, @@ -356,8 +356,8 @@ const BuildQuote = () => { } else { const percentage = value * 100; const amountPercentage = balanceBN - ?.mul(new BN(percentage)) - .div(new BN(100)); + ?.mul(new BN4(percentage)) + .div(new BN4(100)); if (!amountPercentage) { return; @@ -698,7 +698,7 @@ const BuildQuote = () => { value: quickAmount, label: currentFiatCurrency?.denomSymbol + quickAmount.toString(), })) ?? []; - } else if (balanceBN && !balanceBN.isZero() && maxSellAmount?.gt(new BN(0))) { + } else if (balanceBN && !balanceBN.isZero() && maxSellAmount?.gt(new BN4(0))) { quickAmounts = [ { value: 0.25, label: '25%' }, { value: 0.5, label: '50%' }, diff --git a/app/components/UI/Ramp/Views/SendTransaction/SendTransaction.tsx b/app/components/UI/Ramp/Views/SendTransaction/SendTransaction.tsx index ac4927aa503..a0197dad4a2 100644 --- a/app/components/UI/Ramp/Views/SendTransaction/SendTransaction.tsx +++ b/app/components/UI/Ramp/Views/SendTransaction/SendTransaction.tsx @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { ImageSourcePropType, View } from 'react-native'; import { useDispatch, useSelector } from 'react-redux'; import { useNavigation } from '@react-navigation/native'; -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { SellOrder } from '@consensys/on-ramp-sdk/dist/API'; import { TransactionParams, @@ -132,7 +132,7 @@ function SendTransaction() { setIsConfirming(true); let transactionParams: TransactionParams; const amount = addHexPrefix( - new BN( + new BN4( toTokenMinimalUnit( orderData.cryptoAmount || '0', orderData.cryptoCurrency.decimals, diff --git a/app/components/UI/Ramp/hooks/useBalance.ts b/app/components/UI/Ramp/hooks/useBalance.ts index 4c2e52afecb..93d9ee02ff8 100644 --- a/app/components/UI/Ramp/hooks/useBalance.ts +++ b/app/components/UI/Ramp/hooks/useBalance.ts @@ -1,5 +1,4 @@ import { useSelector } from 'react-redux'; -import { hexToBN } from '@metamask/controller-utils'; import { NATIVE_ADDRESS } from '../../../../constants/on-ramp'; import { selectAccountsByChainId } from '../../../../selectors/accountTrackerController'; import { @@ -13,6 +12,7 @@ import { selectChainId } from '../../../../selectors/networkController'; import { safeToChecksumAddress } from '../../../../util/address'; import { balanceToFiat, + hexToBN, renderFromTokenMinimalUnit, renderFromWei, toHexadecimal, diff --git a/app/components/UI/Ramp/hooks/useGasPriceEstimation.ts b/app/components/UI/Ramp/hooks/useGasPriceEstimation.ts index 6c9565b94f6..f0c6b69ad82 100644 --- a/app/components/UI/Ramp/hooks/useGasPriceEstimation.ts +++ b/app/components/UI/Ramp/hooks/useGasPriceEstimation.ts @@ -5,7 +5,7 @@ import { type GasFeeController as GasFeeControllerType, } from '@metamask/gas-fee-controller'; -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; import Engine from '../../../../core/Engine'; import { decGWEIToHexWEI } from '../../../../util/conversions'; import { selectGasFeeControllerState } from '../../../../selectors/gasFeeController'; diff --git a/app/components/UI/Ramp/hooks/useIntentAmount.ts b/app/components/UI/Ramp/hooks/useIntentAmount.ts index 7b024731c3d..6a084053c3a 100644 --- a/app/components/UI/Ramp/hooks/useIntentAmount.ts +++ b/app/components/UI/Ramp/hooks/useIntentAmount.ts @@ -1,5 +1,5 @@ import { useEffect } from 'react'; -import { type BN } from 'ethereumjs-util'; +import type BN4 from 'bnjs4'; import { useRampSDK } from '../sdk'; import parseAmount from '../utils/parseAmount'; import { toTokenMinimalUnit } from '../../../../util/number'; @@ -21,7 +21,7 @@ export default function useIntentAmount( setAmount: (amount: React.SetStateAction) => void, setAmountNumber: (amount: React.SetStateAction) => void, setAmountBNMinimalUnit: ( - amount: React.SetStateAction, + amount: React.SetStateAction, ) => void, currentFiatCurrency: FiatCurrency | null, ) { @@ -53,7 +53,7 @@ export default function useIntentAmount( toTokenMinimalUnit( `${parsedAmount}`, selectedAsset?.decimals ?? 0, - ) as BN, + ) as BN4, ); } } diff --git a/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx b/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx index e70630ab901..1f5dd15f15f 100644 --- a/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx +++ b/app/components/UI/Stake/components/StakingBalance/StakingBalance.tsx @@ -24,7 +24,7 @@ import { strings } from '../../../../../../locales/i18n'; import { renderFromWei } from '../../../../../util/number'; import { getTimeDifferenceFromNow } from '../../../../../util/date'; import { filterExitRequests } from './utils'; -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import bn from 'bignumber.js'; import { CommonPercentageInputUnits, @@ -82,8 +82,8 @@ const StakingBalanceContent = ({ asset }: StakingBalanceProps) => { renderFromWei( claimableRequests.reduce( (acc, { claimedAssets }) => - claimedAssets ? acc.add(new BN(claimedAssets)) : acc, - new BN(0), + claimedAssets ? acc.add(new BN4(claimedAssets)) : acc, + new BN4(0), ), ), [claimableRequests], diff --git a/app/components/UI/Stake/hooks/useInputHandler.ts b/app/components/UI/Stake/hooks/useInputHandler.ts index 881b4678e79..ac551c07147 100644 --- a/app/components/UI/Stake/hooks/useInputHandler.ts +++ b/app/components/UI/Stake/hooks/useInputHandler.ts @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { useState, useMemo, useCallback } from 'react'; import { useSelector } from 'react-redux'; import { @@ -15,19 +15,19 @@ import { import { strings } from '../../../../../locales/i18n'; interface InputHandlerParams { - balance: BN; + balance: BN4; } const useInputHandler = ({ balance }: InputHandlerParams) => { const [amountEth, setAmountEth] = useState('0'); - const [amountWei, setAmountWei] = useState(new BN(0)); + const [amountWei, setAmountWei] = useState(new BN4(0)); const [fiatAmount, setFiatAmount] = useState('0'); const [isEth, setIsEth] = useState(true); const currentCurrency = useSelector(selectCurrentCurrency); const conversionRate = useSelector(selectConversionRate) || 1; - const isNonZeroAmount = useMemo(() => amountWei.gt(new BN(0)), [amountWei]); + const isNonZeroAmount = useMemo(() => amountWei.gt(new BN4(0)), [amountWei]); const isOverMaximum = useMemo( () => amountWei.gt(balance), @@ -90,7 +90,7 @@ const useInputHandler = ({ balance }: InputHandlerParams) => { const handleAmountPress = useCallback( ({ value }: { value: number }) => { const percentage = value * 100; - const amountPercentage = balance.mul(new BN(percentage)).div(new BN(100)); + const amountPercentage = balance.mul(new BN4(percentage)).div(new BN4(100)); let newEthAmount; try { @@ -112,7 +112,7 @@ const useInputHandler = ({ balance }: InputHandlerParams) => { ); const handleMaxInput = useCallback( - (maxStakeableWei: BN) => { + (maxStakeableWei: BN4) => { setAmountWei(maxStakeableWei); let ethValue; diff --git a/app/components/UI/Stake/hooks/useStakingGasFee.test.tsx b/app/components/UI/Stake/hooks/useStakingGasFee.test.tsx index 8c972717182..85439c65a3b 100644 --- a/app/components/UI/Stake/hooks/useStakingGasFee.test.tsx +++ b/app/components/UI/Stake/hooks/useStakingGasFee.test.tsx @@ -2,7 +2,7 @@ import { act, waitFor } from '@testing-library/react-native'; import { renderHookWithProvider } from '../../../../util/test/renderWithProvider'; import useStakingGasFee from './useStakingGasFee'; import Engine from '../../../../core/Engine'; -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { backgroundState } from '../../../../util/test/initial-root-state'; import { createMockAccountsControllerState } from '../../../../util/test/accountsControllerTestUtils'; @@ -93,7 +93,7 @@ describe('useStakingGasFee', () => { expect(result.current.isLoadingStakingGasFee).toBe(true); expect(result.current.isStakingGasFeeError).toBe(false); - expect(result.current.estimatedGasFeeWei).toEqual(new BN(0)); + expect(result.current.estimatedGasFeeWei).toEqual(new BN4(0)); }); it('should fetch gas limit and calculate gas fee correctly', async () => { @@ -113,7 +113,7 @@ describe('useStakingGasFee', () => { '0x0000000000000000000000000000000000000000', ); expect(result.current.estimatedGasFeeWei).toEqual( - new BN('5094922637614180'), + new BN4('5094922637614180'), ); }); }); @@ -132,7 +132,7 @@ describe('useStakingGasFee', () => { await waitFor(() => { expect(result.current.isStakingGasFeeError).toBe(true); - expect(result.current.estimatedGasFeeWei).toEqual(new BN(0)); + expect(result.current.estimatedGasFeeWei).toEqual(new BN4(0)); }); }); diff --git a/app/components/UI/Stake/hooks/useStakingGasFee.ts b/app/components/UI/Stake/hooks/useStakingGasFee.ts index 4d3111307f9..f41c22d1901 100644 --- a/app/components/UI/Stake/hooks/useStakingGasFee.ts +++ b/app/components/UI/Stake/hooks/useStakingGasFee.ts @@ -4,13 +4,13 @@ import { useSelector } from 'react-redux'; import { selectSelectedInternalAccountChecksummedAddress } from '../../../../selectors/accountsController'; import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller'; import { decGWEIToHexWEI } from '../../../../util/conversions'; -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { formatEther } from 'ethers/lib/utils'; import Engine from '../../../../core/Engine'; import { hexToBN } from '../../../../util/number'; interface StakingGasFee { - estimatedGasFeeWei: BN; + estimatedGasFeeWei: BN4; isLoadingStakingGasFee: boolean; isStakingGasFeeError: boolean; refreshGasValues: () => void; @@ -28,7 +28,7 @@ const useStakingGasFee = (depositValueWei: string): StakingGasFee => { useState(true); const [isStakingGasFeeError, setIsStakingGasFeeError] = useState(false); - const [estimatedGasFeeWei, setEstimatedGasFeeWei] = useState(new BN(0)); + const [estimatedGasFeeWei, setEstimatedGasFeeWei] = useState(new BN4(0)); const fetchDepositGasValues = useCallback(async () => { const { GasFeeController } = Engine.context; diff --git a/app/components/UI/Stake/hooks/useStakingInput.ts b/app/components/UI/Stake/hooks/useStakingInput.ts index 3193c1a7002..d34e65aa079 100644 --- a/app/components/UI/Stake/hooks/useStakingInput.ts +++ b/app/components/UI/Stake/hooks/useStakingInput.ts @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { useState, useMemo, useCallback } from 'react'; import { limitToMaximumDecimalPlaces, @@ -38,14 +38,14 @@ const useStakingInputHandlers = () => { () => !isStakingGasFeeError && balance.gt(estimatedGasFeeWei) ? balance.sub(estimatedGasFeeWei) - : new BN(0), + : new BN4(0), [balance, estimatedGasFeeWei, isStakingGasFeeError], ); const isOverMaximum = useMemo(() => { const additionalFundsRequired = amountWei.sub(maxStakeableAmountWei); - return isNonZeroAmount && additionalFundsRequired.gt(new BN(0)); + return isNonZeroAmount && additionalFundsRequired.gt(new BN4(0)); }, [amountWei, isNonZeroAmount, maxStakeableAmountWei]); const { annualRewardRate, annualRewardRateDecimal, isLoadingVaultData } = diff --git a/app/components/UI/Stake/hooks/useUnstakingInput.ts b/app/components/UI/Stake/hooks/useUnstakingInput.ts index 8fb6bc229cf..540cf8b35fe 100644 --- a/app/components/UI/Stake/hooks/useUnstakingInput.ts +++ b/app/components/UI/Stake/hooks/useUnstakingInput.ts @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import useBalance from './useBalance'; import useInputHandler from './useInputHandler'; @@ -22,7 +22,7 @@ const useUnstakingInputHandlers = () => { percentageOptions, handleAmountPress, currentCurrency, - } = useInputHandler({ balance: new BN(stakedBalanceWei) }); + } = useInputHandler({ balance: new BN4(stakedBalanceWei) }); const stakedBalanceValue = isEth ? formattedStakedBalanceETH diff --git a/app/components/UI/Tokens/TokenList/PortfolioBalance/index.test.tsx b/app/components/UI/Tokens/TokenList/PortfolioBalance/index.test.tsx index e1e1f694376..680d8184300 100644 --- a/app/components/UI/Tokens/TokenList/PortfolioBalance/index.test.tsx +++ b/app/components/UI/Tokens/TokenList/PortfolioBalance/index.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; import { fireEvent } from '@testing-library/react-native'; -import { BN } from 'ethereumjs-util'; +import BN5 from 'bnjs5'; import renderWithProvider from '../../../../../util/test/renderWithProvider'; import { backgroundState } from '../../../../../util/test/initial-root-state'; import AppConstants from '../../../../../../app/core/AppConstants'; @@ -70,9 +70,9 @@ const initialState = { }, TokenBalancesController: { contractBalances: { - '0x00': new BN(2), - '0x01': new BN(2), - '0x02': new BN(0), + '0x00': new BN5(2), + '0x01': new BN5(2), + '0x02': new BN5(0), }, }, }, diff --git a/app/components/UI/Tokens/index.test.tsx b/app/components/UI/Tokens/index.test.tsx index bea1653f8ad..a53f0c2bccc 100644 --- a/app/components/UI/Tokens/index.test.tsx +++ b/app/components/UI/Tokens/index.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; // eslint-disable-next-line @typescript-eslint/no-shadow import { fireEvent, waitFor } from '@testing-library/react-native'; import Tokens from './'; -import { BN } from 'ethereumjs-util'; +import BN5 from 'bnjs5'; import renderWithProvider from '../../../util/test/renderWithProvider'; import { createStackNavigator } from '@react-navigation/stack'; import { getAssetTestId } from '../../../../wdio/screen-objects/testIDs/Screens/WalletView.testIds'; @@ -110,9 +110,9 @@ const initialState = { }, TokenBalancesController: { contractBalances: { - '0x00': new BN(2), - '0x01': new BN(2), - '0x02': new BN(0), + '0x00': new BN5(2), + '0x01': new BN5(2), + '0x02': new BN5(0), }, }, }, @@ -265,7 +265,7 @@ describe('Tokens', () => { }, TokenBalancesController: { contractBalances: { - '0x02': new BN(1), + '0x02': new BN5(1), }, }, }, diff --git a/app/components/Views/confirmations/Approval/components/TransactionEditor/index.js b/app/components/Views/confirmations/Approval/components/TransactionEditor/index.js index 5e607dfbef8..69863ccdfb1 100644 --- a/app/components/Views/confirmations/Approval/components/TransactionEditor/index.js +++ b/app/components/Views/confirmations/Approval/components/TransactionEditor/index.js @@ -9,7 +9,8 @@ import { renderFromWei, toHexadecimal, } from '../../../../../../util/number'; -import { isValidAddress, BN, addHexPrefix } from 'ethereumjs-util'; +import { isValidAddress, addHexPrefix } from 'ethereumjs-util'; +import BN from 'bnjs4'; import { strings } from '../../../../../../../locales/i18n'; import { connect } from 'react-redux'; import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'; diff --git a/app/components/Views/confirmations/SendFlow/Amount/index.js b/app/components/Views/confirmations/SendFlow/Amount/index.js index f2bd09ddc3a..7b883765321 100644 --- a/app/components/Views/confirmations/SendFlow/Amount/index.js +++ b/app/components/Views/confirmations/SendFlow/Amount/index.js @@ -60,7 +60,6 @@ import CollectibleMedia from '../../../../UI/CollectibleMedia'; import collectiblesTransferInformation from '../../../../../util/collectibles-transfer'; import { strings } from '../../../../../../locales/i18n'; import Device from '../../../../../util/device'; -import { BN } from 'ethereumjs-util'; import { MetaMetricsEvents } from '../../../../../core/Analytics'; import dismissKeyboard from 'react-native/Libraries/Utilities/dismissKeyboard'; import NetworkMainAssetLogo from '../../../../UI/NetworkMainAssetLogo'; @@ -893,7 +892,7 @@ class Amount extends PureComponent { const balanceBN = hexToBN(accounts[selectedAddress].balance); const realMaxValue = balanceBN.sub(estimatedTotalGas); const maxValue = - balanceBN.isZero() || realMaxValue.isNeg() ? new BN(0) : realMaxValue; + balanceBN.isZero() || realMaxValue.isNeg() ? hexToBN('0x0') : realMaxValue; if (internalPrimaryCurrencyIsCrypto) { input = fromWei(maxValue); } else { diff --git a/app/components/Views/confirmations/SendFlow/Confirm/validation.test.ts b/app/components/Views/confirmations/SendFlow/Confirm/validation.test.ts index e9ed1b98278..8da1c4c3ac3 100644 --- a/app/components/Views/confirmations/SendFlow/Confirm/validation.test.ts +++ b/app/components/Views/confirmations/SendFlow/Confirm/validation.test.ts @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; import { validateSufficientBalance, validateSufficientTokenBalance } from './validation'; import { renderFromWei, hexToBN } from '../../../../../util/number'; import { diff --git a/app/components/Views/confirmations/SendFlow/Confirm/validation.ts b/app/components/Views/confirmations/SendFlow/Confirm/validation.ts index 884c939441e..461ffd62e96 100644 --- a/app/components/Views/confirmations/SendFlow/Confirm/validation.ts +++ b/app/components/Views/confirmations/SendFlow/Confirm/validation.ts @@ -4,7 +4,7 @@ import { decodeTransferData, } from '../../../../../util/transactions'; import { strings } from '../../../../../../locales/i18n'; -import { BN } from 'ethereumjs-util'; +import type BN4 from 'bnjs4'; interface SelectedAsset { address: string; @@ -13,8 +13,8 @@ interface SelectedAsset { } export const generateInsufficientBalanceMessage = ( - weiBalance: BN, - transactionValue: BN, + weiBalance: BN4, + transactionValue: BN4, ticker: string, ) => { const amount = renderFromWei(transactionValue.sub(weiBalance)); @@ -25,7 +25,7 @@ export const generateInsufficientBalanceMessage = ( }); }; -export const validateBalance = (weiBalance: BN, transactionValue: BN) => +export const validateBalance = (weiBalance: BN4, transactionValue: BN4) => !weiBalance.gte(transactionValue) || weiBalance.isZero(); export const validateSufficientTokenBalance = ( @@ -49,8 +49,8 @@ export const validateSufficientTokenBalance = ( }; export const validateSufficientBalance = ( - weiBalance: BN, - totalTransactionValue: BN, + weiBalance: BN4, + totalTransactionValue: BN4, ticker: string, ) => { if (validateBalance(weiBalance, totalTransactionValue)) { diff --git a/app/components/hooks/useAddressBalance/useAddressBalance.test.tsx b/app/components/hooks/useAddressBalance/useAddressBalance.test.tsx index f3f8592d8a8..769ce5db067 100644 --- a/app/components/hooks/useAddressBalance/useAddressBalance.test.tsx +++ b/app/components/hooks/useAddressBalance/useAddressBalance.test.tsx @@ -8,7 +8,7 @@ import { Asset } from './useAddressBalance.types'; import useAddressBalance from './useAddressBalance'; import backgroundState from '../../../util/test/initial-root-state'; import { createMockAccountsControllerState } from '../../../util/test/accountsControllerTestUtils'; -import { BN } from 'ethereumjs-util'; +import type BN5 from 'bnjs5'; const MOCK_ADDRESS_1 = '0x0'; const MOCK_ADDRESS_2 = '0x1'; @@ -65,7 +65,7 @@ describe('useAddressBalance', () => { address: string, selectedAddress: string, networkClientId?: string | undefined, - ) => Promise; + ) => Promise; beforeEach(() => { mockGetERC20BalanceOf = jest .fn() diff --git a/app/components/hooks/useAddressBalance/useAddressBalance.ts b/app/components/hooks/useAddressBalance/useAddressBalance.ts index af95e0187e3..dcdf9e1acc5 100644 --- a/app/components/hooks/useAddressBalance/useAddressBalance.ts +++ b/app/components/hooks/useAddressBalance/useAddressBalance.ts @@ -1,6 +1,7 @@ import { ERC1155, ERC721 } from '@metamask/controller-utils'; import { useEffect, useState } from 'react'; import { useSelector } from 'react-redux'; +import BN4 from 'bnjs4'; import Engine from '../../../core/Engine'; import { getTicker } from '../../../util/transactions'; @@ -110,7 +111,8 @@ const useAddressBalance = ( address, ); fromAccBalance = `${renderFromTokenMinimalUnit( - fromAccBalance || '0', + // This is to work around incompatibility between bn.js v4/v5 - should be removed when migration to v5 is complete + new BN4(fromAccBalance?.toString(10) || '0', 10), decimals, )} ${symbol}`; setAddressBalance(fromAccBalance); diff --git a/app/components/hooks/useTokenBalance.tsx b/app/components/hooks/useTokenBalance.tsx index 8962c9ce352..f4d84786a61 100644 --- a/app/components/hooks/useTokenBalance.tsx +++ b/app/components/hooks/useTokenBalance.tsx @@ -1,6 +1,6 @@ import { useState, useEffect, Dispatch, SetStateAction } from 'react'; import Engine from '../../core/Engine'; -import { BN } from 'ethereumjs-util'; +import type BN4 from 'bnjs4'; /** * Hook to handle the balance of ERC20 tokens @@ -12,12 +12,12 @@ import { BN } from 'ethereumjs-util'; const useTokenBalance = ( requestedTokenAddress: string, userCurrentAddress: string, -): [BN | null, boolean, boolean] => { +): [BN4 | null, boolean, boolean] => { // This hook should be only used with ERC20 tokens const [tokenBalance, setTokenBalance]: [ - BN | null, - Dispatch>, - ] = useState(null); + BN4 | null, + Dispatch>, + ] = useState(null); const [loading, setLoading]: [boolean, Dispatch>] = useState(true); const [error, setError]: [boolean, Dispatch>] = @@ -31,7 +31,7 @@ const useTokenBalance = ( userAddress: string, ): Promise => { AssetsContractController.getERC20BalanceOf(tokenAddress, userAddress) - .then((balance: BN) => setTokenBalance(balance)) + .then((balance: BN4) => setTokenBalance(balance)) .catch(() => setError(true)) .finally(() => setLoading(false)); }; diff --git a/app/components/hooks/useTokenBalancesController/useTokenBalancesController.test.tsx b/app/components/hooks/useTokenBalancesController/useTokenBalancesController.test.tsx index b575c66c4cc..aaf33d56db3 100644 --- a/app/components/hooks/useTokenBalancesController/useTokenBalancesController.test.tsx +++ b/app/components/hooks/useTokenBalancesController/useTokenBalancesController.test.tsx @@ -4,7 +4,7 @@ import { Provider } from 'react-redux'; import { createStore, Store } from 'redux'; import { act, render, waitFor } from '@testing-library/react-native'; import useTokenBalancesController from './useTokenBalancesController'; -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { cloneDeep } from 'lodash'; import { backgroundState } from '../../../util/test/initial-root-state'; @@ -15,7 +15,7 @@ const mockInitialState = { ...backgroundState, TokenBalancesController: { contractBalances: { - '0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': new BN(0x2a), + '0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': new BN4(0x2a), }, }, }, @@ -104,7 +104,7 @@ describe('useTokenBalancesController()', () => { testStore.dispatch({ type: 'add-balances', value: { - '0x326836cc6cd09B5aa59B81A7F72F25FcC0136b96': new BN(0x539), + '0x326836cc6cd09B5aa59B81A7F72F25FcC0136b96': new BN4(0x539), }, }); }); @@ -122,7 +122,7 @@ describe('useTokenBalancesController()', () => { testStore.dispatch({ type: 'add-balances', value: { - '0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': new BN(0x2a), + '0x326836cc6cd09B5aa59B81A7F72F25FcC0136b95': new BN4(0x2a), }, }); }); diff --git a/app/constants/transaction.ts b/app/constants/transaction.ts index 92bde7b1648..38612646e43 100644 --- a/app/constants/transaction.ts +++ b/app/constants/transaction.ts @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; // Transaction Status export const TX_UNAPPROVED = 'unapproved'; diff --git a/app/store/migrations/029.ts b/app/store/migrations/029.ts index af4f1ebf1ba..28f56e47092 100644 --- a/app/store/migrations/029.ts +++ b/app/store/migrations/029.ts @@ -2,7 +2,6 @@ import { toHex } from '@metamask/controller-utils'; import { Hex, hasProperty, isObject } from '@metamask/utils'; import { regex } from '../../../app/util/regex'; -//@ts-expect-error - This error is expected, but ethereumjs-util exports this function import { isHexString } from 'ethereumjs-util'; import { TransactionParams } from '@metamask/transaction-controller'; import { captureException } from '@sentry/react-native'; @@ -466,7 +465,7 @@ export default async function migrate(stateAsync: unknown) { if (Array.isArray(transactionControllerState.transactions)) { transactionControllerState.transactions.forEach( (transaction: TransactionParams, index: number) => { - if (transaction && !isHexString(transaction.chainId)) { + if (transaction && (!transaction.chainId || (transaction.chainId && !isHexString(transaction.chainId)))) { if ( Array.isArray(transactionControllerState.transactions) && isObject(transactionControllerState.transactions[index]) diff --git a/app/store/migrations/031.ts b/app/store/migrations/031.ts index ba4b06ca119..0ad5dcdf64e 100644 --- a/app/store/migrations/031.ts +++ b/app/store/migrations/031.ts @@ -6,7 +6,6 @@ import { TokensControllerState, } from '@metamask/assets-controllers'; import { toHex } from '@metamask/controller-utils'; -//@ts-expect-error - This error is expected, but ethereumjs-util exports this function import { isHexString } from 'ethereumjs-util'; /** diff --git a/app/util/address/index.ts b/app/util/address/index.ts index 34071c0579a..10c09ebae63 100644 --- a/app/util/address/index.ts +++ b/app/util/address/index.ts @@ -3,7 +3,6 @@ import { isValidAddress, addHexPrefix, isValidChecksumAddress, - //@ts-expect-error - This error is expected, but ethereumjs-util exports this function isHexPrefixed, } from 'ethereumjs-util'; import punycode from 'punycode/punycode'; diff --git a/app/util/confirmation/transactions.test.ts b/app/util/confirmation/transactions.test.ts index 1c124ff1fd6..1bda3144e94 100644 --- a/app/util/confirmation/transactions.test.ts +++ b/app/util/confirmation/transactions.test.ts @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; import { buildTransactionParams } from './transactions'; import { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller'; import { TransactionEnvelopeType } from '@metamask/transaction-controller'; diff --git a/app/util/conversion/index.js b/app/util/conversion/index.js index 4046c727724..d65cb685397 100644 --- a/app/util/conversion/index.js +++ b/app/util/conversion/index.js @@ -22,8 +22,9 @@ */ import BigNumber from 'bignumber.js'; +import BN from 'bnjs4'; -import { stripHexPrefix, BN } from 'ethereumjs-util'; +import { stripHexPrefix } from 'ethereumjs-util'; // Big Number Constants const BIG_NUMBER_WEI_MULTIPLIER = new BigNumber('1000000000000000000'); diff --git a/app/util/custom-gas/index.js b/app/util/custom-gas/index.js index 3583b88fab3..b8c611c6be9 100644 --- a/app/util/custom-gas/index.js +++ b/app/util/custom-gas/index.js @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; import { renderFromWei, weiToFiat, toWei, conversionUtil } from '../number'; import { strings } from '../../../locales/i18n'; import TransactionTypes from '../../core/TransactionTypes'; diff --git a/app/util/dappTransactions/index.test.ts b/app/util/dappTransactions/index.test.ts index f4c625d0518..150e559b98d 100644 --- a/app/util/dappTransactions/index.test.ts +++ b/app/util/dappTransactions/index.test.ts @@ -1,4 +1,4 @@ -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; import { strings } from '../../../locales/i18n'; import Engine from '../../core/Engine'; diff --git a/app/util/dappTransactions/index.ts b/app/util/dappTransactions/index.ts index d2d93d8fd74..62f438f291a 100644 --- a/app/util/dappTransactions/index.ts +++ b/app/util/dappTransactions/index.ts @@ -1,11 +1,11 @@ +import { remove0x } from '@metamask/utils'; import { isBN, hexToBN } from '../number'; import { safeToChecksumAddress } from '../address'; import Engine from '../../core/Engine'; import TransactionTypes from '../../core/TransactionTypes'; import { toLowerCaseEquals } from '../general'; import { strings } from '../../../locales/i18n'; -import { BN } from 'ethereumjs-util'; -import { lt } from '../lodash'; +import BN4 from 'bnjs4'; import { estimateGas as controllerEstimateGas } from '../transaction-controller'; interface opts { @@ -25,8 +25,8 @@ interface Transaction { data: string; ensRecipient: string | undefined; from: string; - gas: BN; - gasPrice: BN; + gas: BN4; + gasPrice: BN4; id: string; nonce: string | undefined; origin: string; @@ -97,7 +97,7 @@ export const estimateGas = async ( * @returns {string} - String containing error message whether the Ether transaction amount is valid or not */ export const validateEtherAmount = ( - value: BN, + value: BN4, from: string, allowEmpty = true, ): string | undefined => { @@ -115,6 +115,32 @@ interface ContractBalances { [key: string]: string; } +const getTokenBalance = async ( + from: string, + selectedAsset: SelectedAsset, + selectedAddress: string, + contractBalances: ContractBalances, +): Promise => { + const checksummedFrom = safeToChecksumAddress(from) || ''; + if (selectedAddress === from && contractBalances[selectedAsset.address]) { + return hexToBN( + remove0x(contractBalances[selectedAsset.address].toString()), + ); + } + try { + const { AssetsContractController } = Engine.context; + // TODO: Roundtrip string conversion can be removed when bn.js v4 is superseded with v5 + const contractBalanceForAddress = await AssetsContractController.getERC20BalanceOf( + selectedAsset.address, + checksummedFrom, + ); + const contractBalanceForAddressBN = hexToBN(contractBalanceForAddress.toString(16)); + return contractBalanceForAddressBN; + } catch (e) { + // Don't validate balance if error + } +}; + /** * Validates asset (ERC20) transaction amount * @@ -122,8 +148,8 @@ interface ContractBalances { * @returns {string} - String containing error message whether the Ether transaction amount is valid or not */ export const validateTokenAmount = async ( - value: BN, - gas: BN, + value: BN4, + gas: BN4, from: string, selectedAsset: SelectedAsset, selectedAddress: string, @@ -131,7 +157,6 @@ export const validateTokenAmount = async ( allowEmpty = true, ): Promise => { if (!allowEmpty) { - const checksummedFrom = safeToChecksumAddress(from) || ''; if (!value) { return strings('transaction.invalid_amount'); @@ -144,33 +169,15 @@ export const validateTokenAmount = async ( if (!from) { return strings('transaction.invalid_from_address'); } - // If user trying to send a token that doesn't own, validate balance querying contract - // If it fails, skip validation - let contractBalanceForAddress: BN | undefined | number; - if (selectedAddress === from && contractBalances[selectedAsset.address]) { - contractBalanceForAddress = hexToBN( - contractBalances[selectedAsset.address].toString(), - ); - } else { - try { - const { AssetsContractController } = Engine.context; - contractBalanceForAddress = - await AssetsContractController.getERC20BalanceOf( - selectedAsset.address, - checksummedFrom, - ); - } catch (e) { - // Don't validate balance if error - } + + if (value && !isBN(value)) { + return strings('transaction.invalid_amount'); + } + + const contractBalanceForAddress = await getTokenBalance(from, selectedAsset, selectedAddress, contractBalances); + if (contractBalanceForAddress?.lt(value)) { + return strings('transaction.insufficient'); } - if (value && !isBN(value)) return strings('transaction.invalid_amount'); - const validateAssetAmount = - contractBalanceForAddress && - lt( - contractBalanceForAddress as unknown as number, - value as unknown as number, - ); - if (validateAssetAmount) return strings('transaction.insufficient'); } }; @@ -216,10 +223,10 @@ export const validateAmount = async ( const { value, from, gas, selectedAsset } = transaction; const validations: Validations = { - ETH: () => validateEtherAmount(value as unknown as BN, from, allowEmpty), + ETH: () => validateEtherAmount(value as unknown as BN4, from, allowEmpty), ERC20: async () => await validateTokenAmount( - value as unknown as BN, + value as unknown as BN4, gas, from, selectedAsset, @@ -276,8 +283,8 @@ type setTransactionObjectType = ( * @param {function} setTransactionObject - Sets any attribute in transaction object */ export const handleGasFeeSelection = ( - gasLimit: BN, - gasPrice: BN, + gasLimit: BN4, + gasPrice: BN4, setTransactionObject: setTransactionObjectType, ): void => { const transactionObject = { @@ -297,5 +304,5 @@ export const handleGetGasLimit = async ( ): Promise => { if (!Object.keys(transaction.selectedAsset).length) return; const { gas } = await estimateGas({}, transaction); - setTransactionObject({ gas: hexToBN(gas) as BN }); + setTransactionObject({ gas: hexToBN(gas) as BN4 }); }; diff --git a/app/util/number/index.js b/app/util/number/index.js index 28027c52b7a..c3a76e42206 100644 --- a/app/util/number/index.js +++ b/app/util/number/index.js @@ -1,20 +1,17 @@ /** * Collection of utility functions for consistent formatting and conversion */ -import { BN, stripHexPrefix } from 'ethereumjs-util'; +import { stripHexPrefix } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; import { utils as ethersUtils } from 'ethers'; import convert from '@metamask/ethjs-unit'; -import { - BNToHex, - hexToBN as controllerHexToBN, -} from '@metamask/controller-utils'; +import { add0x, remove0x } from '@metamask/utils'; import numberToBN from 'number-to-bn'; import BigNumber from 'bignumber.js'; import currencySymbols from '../currency-symbols.json'; import { isZero } from '../lodash'; import { regex } from '../regex'; -export { BNToHex }; // Big Number Constants const BIG_NUMBER_WEI_MULTIPLIER = new BigNumber('1000000000000000000'); @@ -30,8 +27,20 @@ const BIG_NUMBER_ETH_MULTIPLIER = new BigNumber('1'); */ export const hexToBN = (inputHex) => typeof inputHex !== 'string' - ? new BN(inputHex, 16) - : controllerHexToBN(inputHex); + ? new BN4(inputHex, 16) + : (inputHex ? new BN4(remove0x(inputHex), 16) : new BN4(0)); + +/** + * Converts a BN object to a hex string with a '0x' prefix. + * + * @param inputBn - BN instance to convert to a hex string. + * @returns A '0x'-prefixed hex string. + */ +// TODO: Either fix this lint violation or explain why it's necessary to ignore. +// eslint-disable-next-line @typescript-eslint/naming-convention +export function BNToHex(inputBn) { + return add0x(inputBn.toString(16)); +} // Setter Maps const toBigNumber = { @@ -55,7 +64,7 @@ const toSpecifiedDenomination = { const baseChange = { hex: (n) => n.toString(16), dec: (n) => new BigNumber(n).toString(10), - BN: (n) => new BN(n.toString(16)), + BN: (n) => new BN4(n.toString(16)), }; /** @@ -107,7 +116,7 @@ export function fromTokenMinimalUnit( minimalInput = isRounding ? Number(minimalInput) : minimalInput; const prefixedInput = addHexPrefix(minimalInput.toString(16)); let minimal = safeNumberToBN(prefixedInput); - const negative = minimal.lt(new BN(0)); + const negative = minimal.lt(new BN4(0)); const base = toBN(Math.pow(10, decimals).toString()); if (negative) { @@ -151,7 +160,7 @@ export function fromTokenMinimalUnitString(minimalInput, decimals) { /** * Converts some unit to token minimal unit * - * @param {number|string|BN} tokenValue - Value to convert + * @param {number|string|BN4} tokenValue - Value to convert * @param {number} decimals - Unit to convert from, ether by default * @returns {Object} - BN instance containing the new number */ @@ -196,19 +205,19 @@ export function toTokenMinimalUnit(tokenValue, decimals) { while (fraction.length < decimals) { fraction += '0'; } - whole = new BN(whole); - fraction = new BN(fraction); + whole = new BN4(whole); + fraction = new BN4(fraction); let tokenMinimal = whole.mul(base).add(fraction); if (negative) { tokenMinimal = tokenMinimal.mul(negative); } - return new BN(tokenMinimal.toString(10), 10); + return new BN4(tokenMinimal.toString(10), 10); } /** * Converts some token minimal unit to render format string, showing 5 decimals * - * @param {Number|String|BN} tokenValue - Token value to convert + * @param {Number|String|BN4} tokenValue - Token value to convert * @param {Number} decimals - Token decimals to convert * @param {Number} decimalsToShow - Decimals to 5 * @returns {String} - Number of token minimal unit, in render format @@ -304,7 +313,7 @@ export function fiatNumberToTokenMinimalUnit( /** * Converts wei to render format string, showing 5 decimals * - * @param {Number|String|BN} value - Wei to convert + * @param {Number|String|BN4} value - Wei to convert * @param {Number} decimalsToShow - Decimals to 5 * @returns {String} - Number of token minimal unit, in render format * If value is less than 5 precision decimals will show '< 0.00001' @@ -343,7 +352,7 @@ export function calcTokenValueToSend(value, decimals) { * @returns {boolean} - True if the value is a BN instance */ export function isBN(value) { - return BN.isBN(value); + return BN4.isBN(value); } /** @@ -367,7 +376,7 @@ export function isDecimal(value) { * @returns {Object} - BN instance */ export function toBN(value) { - return new BN(value); + return new BN4(value); } /** @@ -408,9 +417,9 @@ export const isNumberScientificNotationWhenString = (value) => { /** * Converts some unit to wei * - * @param {number|string|BN} value - Value to convert + * @param {number|string|BN4} value - Value to convert * @param {string} unit - Unit to convert from, ether by default - * @returns {BN} - BN instance containing the new number + * @returns {BN4} - BN instance containing the new number */ export function toWei(value, unit = 'ether') { // check the posibilty to convert to BN @@ -424,7 +433,7 @@ export function toWei(value, unit = 'ether') { /** * Converts some unit to Gwei * - * @param {number|string|BN} value - Value to convert + * @param {number|string|BN4} value - Value to convert * @param {string} unit - Unit to convert from, ether by default * @returns {Object} - BN instance containing the new number */ @@ -435,7 +444,7 @@ export function toGwei(value, unit = 'ether') { /** * Converts some unit to Gwei and return it in render format * - * @param {number|string|BN} value - Value to convert + * @param {number|string|BN4} value - Value to convert * @param {string} unit - Unit to convert from, ether by default * @returns {string} - String instance containing the renderable number */ @@ -450,7 +459,7 @@ export function renderToGwei(value, unit = 'ether') { * Converts wei expressed as a BN instance into a human-readable fiat string * TODO: wei should be a BN instance, but we're not sure if it's always the case // - * @param {number | BN} wei - BN corresponding to an amount of wei + * @param {number | BN4} wei - BN corresponding to an amount of wei * @param {number | null} conversionRate - ETH to current currency conversion rate * @param {string} currencyCode - Current currency code to display * @returns {string} - Currency-formatted string @@ -528,7 +537,7 @@ export function addCurrencySymbol( /** * Converts wei expressed as a BN instance into a human-readable fiat string * - * @param {number|string|BN} wei - BN corresponding to an amount of wei + * @param {number|string|BN4} wei - BN corresponding to an amount of wei * @param {number} conversionRate - ETH to current currency conversion rate * @param {Number} decimalsToShow - Decimals to 5 * @returns {Number} - The converted balance diff --git a/app/util/number/index.test.ts b/app/util/number/index.test.ts index 436f18c0c29..db8904ef7a9 100644 --- a/app/util/number/index.test.ts +++ b/app/util/number/index.test.ts @@ -1,4 +1,5 @@ -import { BN } from 'ethereumjs-util'; +import BN4 from 'bnjs4'; +import BN5 from 'bnjs5'; import { addCurrencySymbol, @@ -39,7 +40,7 @@ import { describe('Number utils :: BNToHex', () => { it('BNToHex', () => { - expect(BNToHex(new BN('1337'))).toEqual('0x539'); + expect(BNToHex(new BN5('1337'))).toEqual('0x539'); }); }); @@ -53,7 +54,7 @@ describe('Number utils :: fromWei', () => { }); it('fromWei using BN number', () => { - expect(fromWei(new BN('1337'))).toEqual('0.000000000000001337'); + expect(fromWei(new BN4('1337'))).toEqual('0.000000000000001337'); }); }); @@ -87,19 +88,19 @@ describe('Number utils :: toWei', () => { expect(() => toWei('1.337e-15')).toThrow(Error); }); - // bn.js do not support decimals, so tests here only cover integers + // bnjs4 do not support decimals, so tests here only cover integers it('toWei using BN number', () => { - expect(toWei(new BN(1337)).toString()).toEqual('1337000000000000000000'); + expect(toWei(new BN4(1337)).toString()).toEqual('1337000000000000000000'); // Tests for expected limitations of BN.js // BN.js do not support decimals - expect(toWei(new BN(1.337e-15)).toString()).toEqual('0'); + expect(toWei(new BN4(1.337e-15)).toString()).toEqual('0'); // BN.js do not support such big numbers - expect(() => toWei(new BN(1.337e18))).toThrow(Error); - expect(() => toWei(new BN(1337000000000000000))).toThrow(Error); + expect(() => toWei(new BN4(1.337e18))).toThrow(Error); + expect(() => toWei(new BN4(1337000000000000000))).toThrow(Error); // For some reason this returns 8338418000000000000000000 wei - expect(toWei(new BN('1.337e18'))).not.toEqual( + expect(toWei(new BN4('1.337e18'))).not.toEqual( '1337000000000000000000000000000000000', ); }); @@ -119,9 +120,9 @@ describe('Number utils :: fromTokenMinimalUnit', () => { }); it('fromTokenMinimalUnit using BN number', () => { - expect(fromTokenMinimalUnit(new BN('1337'), 6)).toEqual('0.001337'); - expect(fromTokenMinimalUnit(new BN('1337'), 0)).toEqual('1337'); - expect(fromTokenMinimalUnit(new BN('1337'), 18)).toEqual( + expect(fromTokenMinimalUnit(new BN4('1337'), 6)).toEqual('0.001337'); + expect(fromTokenMinimalUnit(new BN4('1337'), 0)).toEqual('1337'); + expect(fromTokenMinimalUnit(new BN4('1337'), 18)).toEqual( '0.000000000000001337', ); }); @@ -134,24 +135,24 @@ describe('Number utils :: fromTokenMinimalUnit', () => { }); it('rounds number by default', () => { - expect(fromTokenMinimalUnit(new BN('1000000000000000000'), 18)).toEqual( + expect(fromTokenMinimalUnit(new BN4('1000000000000000000'), 18)).toEqual( '1', ); - expect(fromTokenMinimalUnit(new BN('10000000000000000000'), 18)).toEqual( + expect(fromTokenMinimalUnit(new BN4('10000000000000000000'), 18)).toEqual( '10', ); - expect(fromTokenMinimalUnit(new BN('100000000000000000000'), 18)).toEqual( + expect(fromTokenMinimalUnit(new BN4('100000000000000000000'), 18)).toEqual( '100', ); - expect(fromTokenMinimalUnit(new BN('1000000000000000000000'), 18)).toEqual( + expect(fromTokenMinimalUnit(new BN4('1000000000000000000000'), 18)).toEqual( '1000', ); - expect(fromTokenMinimalUnit(new BN('10000000000000000000000'), 18)).toEqual( + expect(fromTokenMinimalUnit(new BN4('10000000000000000000000'), 18)).toEqual( '10000', ); // test decimal greater than 30,000 - expect(fromTokenMinimalUnit(new BN('50000000000000000000000'), 18)).toEqual( + expect(fromTokenMinimalUnit(new BN4('50000000000000000000000'), 18)).toEqual( '49999.999999999995805696', ); @@ -163,24 +164,24 @@ describe('Number utils :: fromTokenMinimalUnit', () => { it('does not round number if isRounding is false', () => { expect( - fromTokenMinimalUnit(new BN('1000000000000000000'), 18, false), + fromTokenMinimalUnit(new BN4('1000000000000000000'), 18, false), ).toEqual('1'); expect( - fromTokenMinimalUnit(new BN('10000000000000000000'), 18, false), + fromTokenMinimalUnit(new BN4('10000000000000000000'), 18, false), ).toEqual('10'); expect( - fromTokenMinimalUnit(new BN('100000000000000000000'), 18, false), + fromTokenMinimalUnit(new BN4('100000000000000000000'), 18, false), ).toEqual('100'); expect( - fromTokenMinimalUnit(new BN('1000000000000000000000'), 18, false), + fromTokenMinimalUnit(new BN4('1000000000000000000000'), 18, false), ).toEqual('1000'); expect( - fromTokenMinimalUnit(new BN('10000000000000000000000'), 18, false), + fromTokenMinimalUnit(new BN4('10000000000000000000000'), 18, false), ).toEqual('10000'); // test decimal greater than 30,000 expect( - fromTokenMinimalUnit(new BN('50000000000000000000000'), 18, false), + fromTokenMinimalUnit(new BN4('50000000000000000000000'), 18, false), ).toEqual('50000'); // test decimal less than 1e-14 @@ -281,67 +282,67 @@ describe('Number utils :: fromTokenMinimalUnitString', () => { }); it('fromTokenMinimalUnitString using BN number', () => { - expect(fromTokenMinimalUnitString(new BN('1337').toString(10), 6)).toEqual( + expect(fromTokenMinimalUnitString(new BN4('1337').toString(10), 6)).toEqual( '0.001337', ); - expect(fromTokenMinimalUnitString(new BN('1337').toString(10), 0)).toEqual( + expect(fromTokenMinimalUnitString(new BN4('1337').toString(10), 0)).toEqual( '1337', ); - expect(fromTokenMinimalUnitString(new BN('1337').toString(10), 18)).toEqual( + expect(fromTokenMinimalUnitString(new BN4('1337').toString(10), 18)).toEqual( '0.000000000000001337', ); - expect(fromTokenMinimalUnitString(new BN('123456').toString(), 5)).toEqual( + expect(fromTokenMinimalUnitString(new BN4('123456').toString(), 5)).toEqual( '1.23456', ); - expect(fromTokenMinimalUnitString(new BN('123456').toString(), 5)).toEqual( + expect(fromTokenMinimalUnitString(new BN4('123456').toString(), 5)).toEqual( '1.23456', ); expect( - fromTokenMinimalUnitString(new BN('1234560000000000000').toString(), 18), + fromTokenMinimalUnitString(new BN4('1234560000000000000').toString(), 18), ).toEqual('1.23456'); expect( - fromTokenMinimalUnitString(new BN('1000000000000000000').toString(), 18), + fromTokenMinimalUnitString(new BN4('1000000000000000000').toString(), 18), ).toEqual('1'); - expect(fromTokenMinimalUnitString(new BN('1').toString(), 18)).toEqual( + expect(fromTokenMinimalUnitString(new BN4('1').toString(), 18)).toEqual( '0.000000000000000001', ); - expect(fromTokenMinimalUnitString(new BN('0').toString(), 18)).toEqual('0'); + expect(fromTokenMinimalUnitString(new BN4('0').toString(), 18)).toEqual('0'); expect( - fromTokenMinimalUnitString(new BN('123456789').toString(), 5), + fromTokenMinimalUnitString(new BN4('123456789').toString(), 5), ).toEqual('1234.56789'); expect( fromTokenMinimalUnitString( - new BN('1234567890000000000987654321').toString(), + new BN4('1234567890000000000987654321').toString(), 18, ), ).toEqual('1234567890.000000000987654321'); expect( fromTokenMinimalUnitString( - new BN('10000000000000000000000000000001').toString(), + new BN4('10000000000000000000000000000001').toString(), 18, ), ).toEqual('10000000000000.000000000000000001'); expect( fromTokenMinimalUnitString( - new BN('10000000000000000000000000000000').toString(), + new BN4('10000000000000000000000000000000').toString(), 18, ), ).toEqual('10000000000000'); expect( - fromTokenMinimalUnitString(new BN('3900229504248293869').toString(), 18), + fromTokenMinimalUnitString(new BN4('3900229504248293869').toString(), 18), ).toEqual('3.900229504248293869'); expect( fromTokenMinimalUnitString( - new BN('92836465327282987373728723').toString(), + new BN4('92836465327282987373728723').toString(), 18, ), ).toEqual('92836465.327282987373728723'); expect( - fromTokenMinimalUnitString(new BN('6123512631253').toString(), 16), + fromTokenMinimalUnitString(new BN4('6123512631253').toString(), 16), ).toEqual('0.0006123512631253'); expect( fromTokenMinimalUnitString( - new BN('92836465327282987373728723').toString(), + new BN4('92836465327282987373728723').toString(), 0, ), ).toEqual('92836465327282987373728723'); @@ -350,20 +351,20 @@ describe('Number utils :: fromTokenMinimalUnitString', () => { describe('Number utils :: toTokenMinimalUnit', () => { it('toTokenMinimalUnit using number', () => { - expect(toTokenMinimalUnit(1337, 6)).toEqual(new BN('1337000000', 10)); - expect(toTokenMinimalUnit(1337, 0)).toEqual(new BN('1337')); - expect(toTokenMinimalUnit(1337.1, 1)).toEqual(new BN('13371')); + expect(toTokenMinimalUnit(1337, 6)).toEqual(new BN4('1337000000', 10)); + expect(toTokenMinimalUnit(1337, 0)).toEqual(new BN4('1337')); + expect(toTokenMinimalUnit(1337.1, 1)).toEqual(new BN4('13371')); }); it('toTokenMinimalUnit using string', () => { - expect(toTokenMinimalUnit('1337', 6)).toEqual(new BN('1337000000')); - expect(toTokenMinimalUnit('1337', 0)).toEqual(new BN('1337')); - expect(toTokenMinimalUnit('1337.1', 2)).toEqual(new BN('133710')); + expect(toTokenMinimalUnit('1337', 6)).toEqual(new BN4('1337000000')); + expect(toTokenMinimalUnit('1337', 0)).toEqual(new BN4('1337')); + expect(toTokenMinimalUnit('1337.1', 2)).toEqual(new BN4('133710')); }); it('toTokenMinimalUnit using BN number', () => { - expect(toTokenMinimalUnit(new BN('1337'), 0)).toEqual(new BN('1337')); - expect(toTokenMinimalUnit(new BN('1337'), 6)).toEqual(new BN('1337000000')); + expect(toTokenMinimalUnit(new BN4('1337'), 0)).toEqual(new BN4('1337')); + expect(toTokenMinimalUnit(new BN4('1337'), 6)).toEqual(new BN4('1337000000')); }); it('toTokenMinimalUnit using invalid inputs', () => { @@ -389,10 +390,10 @@ describe('Number utils :: renderFromTokenMinimalUnit', () => { }); it('renderFromTokenMinimalUnit using BN number', () => { - expect(renderFromTokenMinimalUnit(new BN('1337'), 0)).toEqual('1337'); - expect(renderFromTokenMinimalUnit(new BN('1337'), 6)).toEqual('0.00134'); - expect(renderFromTokenMinimalUnit(new BN('1337'), 10)).toEqual('< 0.00001'); - expect(renderFromTokenMinimalUnit(new BN('0'), 10)).toEqual('0'); + expect(renderFromTokenMinimalUnit(new BN4('1337'), 0)).toEqual('1337'); + expect(renderFromTokenMinimalUnit(new BN4('1337'), 6)).toEqual('0.00134'); + expect(renderFromTokenMinimalUnit(new BN4('1337'), 10)).toEqual('< 0.00001'); + expect(renderFromTokenMinimalUnit(new BN4('0'), 10)).toEqual('0'); }); }); @@ -410,9 +411,9 @@ describe('Number utils :: renderFromWei', () => { }); it('renderFromWei using BN number', () => { - expect(renderFromWei(new BN('133700000000000000'))).toEqual('0.1337'); - expect(renderFromWei(new BN('1337'))).toEqual('< 0.00001'); - expect(renderFromWei(new BN('0'))).toEqual('0'); + expect(renderFromWei(new BN4('133700000000000000'))).toEqual('0.1337'); + expect(renderFromWei(new BN4('1337'))).toEqual('< 0.00001'); + expect(renderFromWei(new BN4('0'))).toEqual('0'); }); }); @@ -478,9 +479,9 @@ describe('Number utils :: localizeLargeNumber', () => { describe('Number utils :: calcTokenValueToSend', () => { it('calcTokenValueToSend', () => { - expect(calcTokenValueToSend(new BN(1337), 0)).toEqual('539'); - expect(calcTokenValueToSend(new BN(1337), 9)).toEqual('1374b68fa00'); - expect(calcTokenValueToSend(new BN(1337), 18)).toEqual( + expect(calcTokenValueToSend(new BN4(1337), 0)).toEqual('539'); + expect(calcTokenValueToSend(new BN4(1337), 9)).toEqual('1374b68fa00'); + expect(calcTokenValueToSend(new BN4(1337), 18)).toEqual( '487a9a304539440000', ); }); @@ -491,7 +492,7 @@ describe('Number utils :: hexToBN', () => { expect(hexToBN('0x539').toNumber()).toBe(1337); }); it('should handle non string values', () => { - const newBN = new BN(1); + const newBN = new BN4(1); expect(hexToBN(newBN)).toBe(newBN); }); }); @@ -500,7 +501,7 @@ describe('Number utils :: isBN', () => { it('isBN', () => { const notABN = '0x539'; expect(isBN(notABN)).toEqual(false); - expect(isBN(new BN(1337))).toEqual(true); + expect(isBN(new BN4(1337))).toEqual(true); }); }); @@ -697,7 +698,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('1650000007.7'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('1650000007'); + const expected: any = new BN4('1650000007'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -710,7 +711,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN(1650000007.7); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('1650000007'); + const expected: any = new BN4('1650000007'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -723,7 +724,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('16500'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('16500'); + const expected: any = new BN4('16500'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -736,7 +737,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN(16500); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('16500'); + const expected: any = new BN4('16500'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -749,7 +750,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('-1650000007.7'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('-1650000007'); + const expected: any = new BN4('-1650000007'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -762,7 +763,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN(-1650000007.7); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('-1650000007'); + const expected: any = new BN4('-1650000007'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -775,7 +776,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('-16500'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('-16500'); + const expected: any = new BN4('-16500'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -788,7 +789,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN(-16500); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('-16500'); + const expected: any = new BN4('-16500'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -801,7 +802,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('75BCD15'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('123456789'); + const expected: any = new BN4('123456789'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -814,7 +815,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('0x75BCD15'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('123456789'); + const expected: any = new BN4('123456789'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -827,7 +828,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('-75BCD15'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('-123456789'); + const expected: any = new BN4('-123456789'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -840,7 +841,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('-0x75BCD15'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('-123456789'); + const expected: any = new BN4('-123456789'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -853,7 +854,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('0'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('0'); + const expected: any = new BN4('0'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -866,7 +867,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('0x0'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('0'); + const expected: any = new BN4('0'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -879,7 +880,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN('0xNaN'); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('0'); + const expected: any = new BN4('0'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -892,7 +893,7 @@ describe('Number utils :: safeNumberToBN', () => { const result: any = safeNumberToBN(NaN); // TODO: Replace "any" with type // eslint-disable-next-line @typescript-eslint/no-explicit-any - const expected: any = new BN('0'); + const expected: any = new BN4('0'); expect(result.words[0]).toEqual(expected.words[0]); expect(result.words[1]).toEqual(expected.words[1]); expect(result.negative).toEqual(expected.negative); @@ -1053,7 +1054,7 @@ describe('Number utils :: formatValueToMatchTokenDecimals', () => { describe('Number utils :: safeBNToHex', () => { it('returns hex string', () => { - expect(safeBNToHex(new BN('255'))).toBe('0xff'); + expect(safeBNToHex(new BN4('255'))).toBe('0xff'); }); it.each([undefined, null])( diff --git a/app/util/transaction-reducer-helpers.ts b/app/util/transaction-reducer-helpers.ts index 562fa6db9a7..769b4ae05e0 100644 --- a/app/util/transaction-reducer-helpers.ts +++ b/app/util/transaction-reducer-helpers.ts @@ -1,5 +1,5 @@ import { SecurityAlertResponse } from '@metamask/transaction-controller'; -import { BN } from 'ethereumjs-util'; +import type BN from 'bnjs4'; interface TxMeta { data?: string; diff --git a/app/util/transactions/index.js b/app/util/transactions/index.js index 71614e75e97..c78a43790c3 100644 --- a/app/util/transactions/index.js +++ b/app/util/transactions/index.js @@ -1,4 +1,5 @@ -import { addHexPrefix, toChecksumAddress, BN } from 'ethereumjs-util'; +import { addHexPrefix, toChecksumAddress } from 'ethereumjs-util'; +import BN from 'bnjs4'; import { rawEncode, rawDecode } from 'ethereumjs-abi'; import BigNumber from 'bignumber.js'; import humanizeDuration from 'humanize-duration'; diff --git a/app/util/transactions/index.test.ts b/app/util/transactions/index.test.ts index 2f8415f8871..d6040f10f35 100644 --- a/app/util/transactions/index.test.ts +++ b/app/util/transactions/index.test.ts @@ -1,5 +1,5 @@ import { swapsUtils } from '@metamask/swaps-controller'; -import { BN } from 'ethereumjs-util'; +import BN from 'bnjs4'; /* eslint-disable-next-line import/no-namespace */ import * as controllerUtilsModule from '@metamask/controller-utils'; @@ -1082,7 +1082,7 @@ describe('Transactions utils :: isApprovalTransaction', () => { }); describe('Transactions utils :: getTransactionReviewActionKey', () => { - const transaction = { to: '0xContractAddress' }; + const transaction = { to: '0xdeadbeef' }; const chainId = '1'; it('returns `Unknown Method` review action key when transaction action key exists', async () => { const expectedReviewActionKey = 'Unknown Method'; diff --git a/package.json b/package.json index f35e69939e9..aab4f5b2621 100644 --- a/package.json +++ b/package.json @@ -230,6 +230,8 @@ "axios": "^1.6.8", "base-64": "1.0.0", "bignumber.js": "^9.0.1", + "bnjs4": "npm:bn.js@^4.12.0", + "bnjs5": "npm:bn.js@^5.2.1", "buffer": "6.0.3", "cockatiel": "^3.1.2", "compare-versions": "^3.6.0", @@ -242,8 +244,8 @@ "eth-block-tracker": "^7.0.1", "eth-ens-namehash": "2.0.8", "eth-url-parser": "1.0.4", - "ethereumjs-abi": "0.6.6", - "ethereumjs-util": "6.1.0", + "ethereumjs-abi": "^0.6.8", + "ethereumjs-util": "^7.1.5", "ethers": "^5.0.14", "ethjs-ens": "2.0.1", "eventemitter2": "^6.4.9", @@ -392,6 +394,8 @@ "@testing-library/react": "14.0.0", "@testing-library/react-hooks": "^8.0.1", "@testing-library/react-native": "12.1.2", + "@types/bnjs4": "npm:@types/bn.js@^4.11.6", + "@types/bnjs5": "npm:@types/bn.js@^5.1.6", "@types/crypto-js": "^4.1.1", "@types/enzyme": "^3.10.12", "@types/eth-url-parser": "^1.0.0", @@ -575,7 +579,8 @@ "@metamask/sdk-communication-layer>eciesjs>secp256k1": false, "detox>ws>utf-8-validate": false, "ganache>@trufflesuite/uws-js-unofficial>utf-8-validate": false, - "@react-native-firebase/app>firebase>@firebase/firestore>@grpc/proto-loader>protobufjs": false + "@react-native-firebase/app>firebase>@firebase/firestore>@grpc/proto-loader>protobufjs": false, + "ethereumjs-util>ethereum-cryptography>keccak": true } }, "packageManager": "yarn@1.22.22" diff --git a/yarn.lock b/yarn.lock index a7730cef374..51ac2260bf7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9506,6 +9506,13 @@ dependencies: "@types/node" "*" +"@types/bn.js@^4.11.3": + version "4.11.6" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c" + integrity sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg== + dependencies: + "@types/node" "*" + "@types/bn.js@^5.1.0", "@types/bn.js@^5.1.5": version "5.1.5" resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.5.tgz#2e0dacdcce2c0f16b905d20ff87aedbc6f7b4bf0" @@ -9513,6 +9520,20 @@ dependencies: "@types/node" "*" +"@types/bnjs4@npm:@types/bn.js@^4.11.6": + version "4.11.6" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-4.11.6.tgz#c306c70d9358aaea33cd4eda092a742b9505967c" + integrity sha512-pqr857jrp2kPuO9uRjZ3PwnJTjoQy+fcdxvBTvHm6dkmEL9q+hDD/2j/0ELOBPtPnS8LjCX0gI9nbl8lVkadpg== + dependencies: + "@types/node" "*" + +"@types/bnjs5@npm:@types/bn.js@^5.1.6": + version "5.1.6" + resolved "https://registry.yarnpkg.com/@types/bn.js/-/bn.js-5.1.6.tgz#9ba818eec0c85e4d3c679518428afdf611d03203" + integrity sha512-Xh8vSwUeMKeYYrj3cX4lGQgFSF/N03r+tv4AiLl1SucqV+uTQpxRcnM8AkXKHwYP9ZPXOYXRr2KPXpVlIvqh9w== + dependencies: + "@types/node" "*" + "@types/body-parser@*": version "1.19.2" resolved "https://registry.yarnpkg.com/@types/body-parser/-/body-parser-1.19.2.tgz#aea2059e28b7658639081347ac4fab3de166e6f0" @@ -13352,7 +13373,7 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -bindings@^1.2.1, bindings@^1.5.0: +bindings@^1.5.0: version "1.5.0" resolved "https://registry.yarnpkg.com/bindings/-/bindings-1.5.0.tgz#10353c9e945334bc0511a6d90b38fbc7c9c504df" integrity sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ== @@ -13413,11 +13434,21 @@ bn.js@5.2.1, bn.js@^5.0.0, bn.js@^5.1.2, bn.js@^5.2.0, bn.js@^5.2.1: resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== -bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.10.0, bn.js@^4.11.0, bn.js@^4.11.8, bn.js@^4.11.9: +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.0, bn.js@^4.11.8, bn.js@^4.11.9: version "4.12.0" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== +"bnjs4@npm:bn.js@^4.12.0": + version "4.12.0" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88" + integrity sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA== + +"bnjs5@npm:bn.js@^5.2.1": + version "5.2.1" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70" + integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ== + body-parser@1.20.3, body-parser@^1.15.2, body-parser@^1.18.2, body-parser@^1.19.0: version "1.20.3" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.20.3.tgz#1953431221c6fb5cd63c4b36d53fab0928e548c6" @@ -17085,41 +17116,28 @@ ethereum-ens-network-map@^1.0.0: resolved "https://registry.yarnpkg.com/ethereum-ens-network-map/-/ethereum-ens-network-map-1.0.2.tgz#4e27bad18dae7bd95d84edbcac2c9e739fc959b9" integrity sha512-5qwJ5n3YhjSpE6O/WEBXCAb2nagUgyagJ6C0lGUBWC4LjKp/rRzD+pwtDJ6KCiITFEAoX4eIrWOjRy0Sylq5Hg== -ethereumjs-abi@0.6.6: - version "0.6.6" - resolved "https://registry.yarnpkg.com/ethereumjs-abi/-/ethereumjs-abi-0.6.6.tgz#f8ba3413a98478173f5a00f7f1316819db1d09ec" - integrity sha512-w8KubDsA/+OAuqtIR9RGsMcoZ5nhM8vxwjJAJvEIY+clhxA3BHoLG3+ClYQaQhD0n3mlDt3U5rBrmSVJvI3c8A== - dependencies: - bn.js "^4.10.0" - ethereumjs-util "^5.0.0" - -ethereumjs-util@6.1.0: - version "6.1.0" - resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-6.1.0.tgz#e9c51e5549e8ebd757a339cc00f5380507e799c8" - integrity sha512-URESKMFbDeJxnAxPppnk2fN6Y3BIatn9fwn76Lm8bQlt+s52TpG8dN9M66MLPuRAiAOIqL3dfwqWJf0sd0fL0Q== +ethereumjs-abi@^0.6.8: + version "0.6.8" + resolved "https://registry.yarnpkg.com/ethereumjs-abi/-/ethereumjs-abi-0.6.8.tgz#71bc152db099f70e62f108b7cdfca1b362c6fcae" + integrity sha512-Tx0r/iXI6r+lRsdvkFDlut0N08jWMnKRZ6Gkq+Nmw75lZe4e6o3EkSnkaBP5NF6+m5PTGAr9JP43N3LyeoglsA== dependencies: - bn.js "^4.11.0" - create-hash "^1.1.2" - ethjs-util "0.1.6" - keccak "^1.0.2" - rlp "^2.0.0" - safe-buffer "^5.1.1" - secp256k1 "^3.0.1" + bn.js "^4.11.8" + ethereumjs-util "^6.0.0" -ethereumjs-util@^5.0.0: - version "5.2.1" - resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-5.2.1.tgz#a833f0e5fca7e5b361384dc76301a721f537bf65" - integrity sha512-v3kT+7zdyCm1HIqWlLNrHGqHGLpGYIhjeHxQjnDXjLT2FyGJDsd3LWMYUo7pAFRrk86CR3nUJfhC81CCoJNNGQ== +ethereumjs-util@^6.0.0: + version "6.2.1" + resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-6.2.1.tgz#fcb4e4dd5ceacb9d2305426ab1a5cd93e3163b69" + integrity sha512-W2Ktez4L01Vexijrm5EB6w7dg4n/TgpoYU4avuT5T3Vmnw/eCRtiBrJfQYS/DCSvDIOLn2k57GcHdeBcgVxAqw== dependencies: + "@types/bn.js" "^4.11.3" bn.js "^4.11.0" create-hash "^1.1.2" elliptic "^6.5.2" ethereum-cryptography "^0.1.3" - ethjs-util "^0.1.3" - rlp "^2.0.0" - safe-buffer "^5.1.1" + ethjs-util "0.1.6" + rlp "^2.2.3" -ethereumjs-util@^7.0.10, ethereumjs-util@^7.0.8, ethereumjs-util@^7.1.2: +ethereumjs-util@^7.0.10, ethereumjs-util@^7.0.8, ethereumjs-util@^7.1.2, ethereumjs-util@^7.1.5: version "7.1.5" resolved "https://registry.yarnpkg.com/ethereumjs-util/-/ethereumjs-util-7.1.5.tgz#9ecf04861e4fbbeed7465ece5f23317ad1129181" integrity sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg== @@ -17266,7 +17284,7 @@ ethjs-util@0.1.3: is-hex-prefixed "1.0.0" strip-hex-prefix "1.0.0" -ethjs-util@0.1.6, ethjs-util@^0.1.3, ethjs-util@^0.1.6: +ethjs-util@0.1.6, ethjs-util@^0.1.6: version "0.1.6" resolved "https://registry.yarnpkg.com/ethjs-util/-/ethjs-util-0.1.6.tgz#f308b62f185f9fe6237132fb2a9818866a5cd536" integrity sha512-CUnVOQq7gSpDHZVVrQW8ExxUETWrnrvXYvYz55wOU8Uj4VCgw56XC2B/fVqQN+f7gmrnRHSLVnFAwsCuNwji8w== @@ -21068,16 +21086,6 @@ keccak@3.0.2, keccak@^3.0.0: node-gyp-build "^4.2.0" readable-stream "^3.6.0" -keccak@^1.0.2: - version "1.4.0" - resolved "https://registry.yarnpkg.com/keccak/-/keccak-1.4.0.tgz#572f8a6dbee8e7b3aa421550f9e6408ca2186f80" - integrity sha512-eZVaCpblK5formjPjeTBik7TAg+pqnDrMHIffSvi9Lh7PQgM1+hSzakUeZFCk9DVVG0dacZJuaz2ntwlzZUIBw== - dependencies: - bindings "^1.2.1" - inherits "^2.0.3" - nan "^2.2.1" - safe-buffer "^5.1.0" - keygrip@~1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/keygrip/-/keygrip-1.1.0.tgz#871b1681d5e159c62a445b0c74b615e0917e7226" @@ -22757,7 +22765,7 @@ mz@^2.7.0: object-assign "^4.0.1" thenify-all "^1.0.0" -nan@^2.14.0, nan@^2.2.1: +nan@^2.14.0: version "2.20.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.20.0.tgz#08c5ea813dd54ed16e5bd6505bf42af4f7838ca3" integrity sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw== @@ -26465,7 +26473,7 @@ ripemd160@^2.0.0, ripemd160@^2.0.1, ripemd160@^2.0.2: hash-base "^3.0.0" inherits "^2.0.1" -rlp@^2.0.0, rlp@^2.2.4, rlp@^2.2.6: +rlp@^2.2.3, rlp@^2.2.4, rlp@^2.2.6: version "2.2.7" resolved "https://registry.yarnpkg.com/rlp/-/rlp-2.2.7.tgz#33f31c4afac81124ac4b283e2bd4d9720b30beaf" integrity sha512-d5gdPmgQ0Z+AklL2NVXr/IoSjNZFfTVvQWzL/AM2AOcSzYP2xjlb0AC8YyCLc41MSNf6P6QVtjgPdmVtzb+4lQ== @@ -26656,7 +26664,7 @@ scrypt-js@3.0.1, scrypt-js@^3.0.0, scrypt-js@^3.0.1: resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-3.0.1.tgz#d314a57c2aef69d1ad98a138a21fe9eafa9ee312" integrity sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA== -secp256k1@3.8.1, secp256k1@^3.0.1: +secp256k1@3.8.1: version "3.8.1" resolved "https://registry.yarnpkg.com/secp256k1/-/secp256k1-3.8.1.tgz#b62a62a882d6b16f9b51fe599c6b3a861e36c59f" integrity sha512-tArjQw2P0RTdY7QmkNehgp6TVvQXq6ulIhxv8gaH6YubKG/wxxAoNKcbuXjDhybbc+b2Ihc7e0xxiGN744UIiQ==