diff --git a/packages/checkout/sdk/src/smartCheckout/fees/fees.test.ts b/packages/checkout/sdk/src/smartCheckout/fees/fees.test.ts index 3e56d2826a..714e7a726a 100644 --- a/packages/checkout/sdk/src/smartCheckout/fees/fees.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/fees/fees.test.ts @@ -1,4 +1,4 @@ -import { parseUnits } from 'ethers/lib/utils'; +import { utils } from 'ethers'; import { calculateFees } from './fees'; import { BuyToken, ItemType } from '../../types'; import { CheckoutErrorType } from '../../errors'; @@ -9,7 +9,7 @@ jest.mock('../actions'); describe.only('orderbook fees', () => { it('should calculate the fees as a percentageDecimal', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.025 }, recipient: '0x222', @@ -25,7 +25,7 @@ describe.only('orderbook fees', () => { it('should return empty array when fee is zero', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0 }, recipient: '0x222', @@ -38,7 +38,7 @@ describe.only('orderbook fees', () => { it('should return empty array when fee is smaller than 6 decimal places', async () => { const decimals = 6; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.0000001 }, recipient: '0x222', @@ -51,7 +51,7 @@ describe.only('orderbook fees', () => { it('should return the fee when the amount and fee is small', async () => { const decimals = 18; - const amount = parseUnits('0.000001', 18).toString(); + const amount = utils.parseUnits('0.000001', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.000001 }, recipient: '0x222', @@ -67,7 +67,7 @@ describe.only('orderbook fees', () => { it('should return empty array when the amount and fee are small enough to go below 1 wei', async () => { const decimals = 18; - const amount = parseUnits('0.0000000000001', 18).toString(); + const amount = utils.parseUnits('0.0000000000001', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.000001 }, recipient: '0x222', @@ -80,7 +80,7 @@ describe.only('orderbook fees', () => { it('should work when the amount is a decimal', async () => { const decimals = 18; - const amount = parseUnits('0.5', 18).toString(); + const amount = utils.parseUnits('0.5', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.025 }, recipient: '0x222', @@ -96,7 +96,7 @@ describe.only('orderbook fees', () => { it('should calculate the fees with multiple percentageDecimals', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.025 }, recipient: '0x222', @@ -118,7 +118,7 @@ describe.only('orderbook fees', () => { it('should calculate the fees with multiple percentageDecimals that add to the max fee amount', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.7 }, recipient: '0x222', @@ -140,7 +140,7 @@ describe.only('orderbook fees', () => { it('should fail to calculate the fees as a percentageDecimal because the fee is too high', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 1.000001 }, recipient: '0x222', @@ -163,7 +163,7 @@ describe.only('orderbook fees', () => { it('should calculate the fees as a token amount', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { token: '1' }, recipient: '0x222', @@ -179,7 +179,7 @@ describe.only('orderbook fees', () => { it('should work when the amount is a decimal', async () => { const decimals = 18; - const amount = parseUnits('0.5', 18).toString(); + const amount = utils.parseUnits('0.5', 18).toString(); const makerFees = [{ amount: { token: '0.1' }, recipient: '0x222', @@ -195,7 +195,7 @@ describe.only('orderbook fees', () => { it('should calculate the fees with multiple token amounts', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { token: '1' }, recipient: '0x222', @@ -217,7 +217,7 @@ describe.only('orderbook fees', () => { it('should fail to calculate the fees as a token value because the fee is too high', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { token: '11' }, recipient: '0x222', @@ -240,7 +240,7 @@ describe.only('orderbook fees', () => { it('should calculate the fees with a combination of percentageDecimals and token amounts', async () => { const decimals = 18; - const amount = parseUnits('10', 18).toString(); + const amount = utils.parseUnits('10', 18).toString(); const makerFees = [{ amount: { percentageDecimal: 0.025 }, recipient: '0x222', diff --git a/packages/checkout/sdk/src/smartCheckout/fees/fees.ts b/packages/checkout/sdk/src/smartCheckout/fees/fees.ts index f6831a5719..f0b8f27e8a 100644 --- a/packages/checkout/sdk/src/smartCheckout/fees/fees.ts +++ b/packages/checkout/sdk/src/smartCheckout/fees/fees.ts @@ -1,6 +1,5 @@ import { FeeValue } from '@imtbl/orderbook'; -import { BigNumber } from 'ethers'; -import { parseUnits } from 'ethers/lib/utils'; +import { BigNumber, utils } from 'ethers'; import { FeePercentage, FeeToken, OrderFee } from '../../types/fees'; import { CheckoutError, CheckoutErrorType } from '../../errors'; @@ -28,7 +27,7 @@ const calculateFeesToken = ( decimals: number, ): BigNumber => { const feeToken = orderFee.amount as FeeToken; - const bnFeeAmount = parseUnits(feeToken.token, decimals); + const bnFeeAmount = utils.parseUnits(feeToken.token, decimals); return bnFeeAmount; }; diff --git a/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.test.ts b/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.test.ts index 16b4495739..28eb92c88a 100644 --- a/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.test.ts +++ b/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.test.ts @@ -1,5 +1,5 @@ import { Web3Provider } from '@ethersproject/providers'; -import { parseUnits } from 'ethers/lib/utils'; +import { utils } from 'ethers'; import { getTokenContract } from '../../instance'; import { getItemRequirementsFromRequirements } from './itemRequirements'; import { @@ -42,18 +42,18 @@ describe('itemRequirements', () => { expect(itemRequirements).toEqual([ { type: ItemType.NATIVE, - amount: parseUnits('2.0', 18), + amount: utils.parseUnits('2.0', 18), }, { type: ItemType.ERC20, spenderAddress: '0xSPENDER', - amount: parseUnits('1.5', 18), + amount: utils.parseUnits('1.5', 18), contractAddress: '0xCONTRACTADDRESS1', }, { type: ItemType.ERC20, spenderAddress: '0xSPENDER', - amount: parseUnits('0.5', 18), + amount: utils.parseUnits('0.5', 18), contractAddress: '0xCONTRACTADDRESS2', }, { diff --git a/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.ts b/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.ts index 096ad391a5..66022b27cb 100644 --- a/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.ts +++ b/packages/checkout/sdk/src/smartCheckout/itemRequirements/itemRequirements.ts @@ -1,5 +1,5 @@ import { Web3Provider } from '@ethersproject/providers'; -import { parseUnits } from 'ethers/lib/utils'; +import { utils } from 'ethers'; import { ERC20ABI, ERC20Item, @@ -33,12 +33,12 @@ export async function getItemRequirementsFromRequirements( if (itemRequirementParam.type === ItemType.NATIVE) { return { ...itemRequirementParam, - amount: parseUnits(itemRequirementParam.amount, 18), + amount: utils.parseUnits(itemRequirementParam.amount, 18), } as NativeItem; } if (itemRequirementParam.type === ItemType.ERC20) { return { ...itemRequirementParam, - amount: parseUnits(itemRequirementParam.amount, decimals[index]), + amount: utils.parseUnits(itemRequirementParam.amount, decimals[index]), } as ERC20Item; } return itemRequirementParam as ERC721Item; diff --git a/packages/checkout/sdk/src/smartCheckout/sell/sell.ts b/packages/checkout/sdk/src/smartCheckout/sell/sell.ts index 110328f1d5..7df6d7e138 100644 --- a/packages/checkout/sdk/src/smartCheckout/sell/sell.ts +++ b/packages/checkout/sdk/src/smartCheckout/sell/sell.ts @@ -7,8 +7,7 @@ import { PrepareListingResponse, constants, } from '@imtbl/orderbook'; -import { BigNumber, Contract } from 'ethers'; -import { parseUnits } from 'ethers/lib/utils'; +import { BigNumber, Contract, utils } from 'ethers'; import { BuyToken, SellOrder, SellResult, SellStatusType, } from '../../types/sell'; @@ -47,7 +46,7 @@ export const getBuyToken = ( buyToken: BuyToken, decimals: number = 18, ): ERC20Item | NativeItem => { - const bnAmount = parseUnits(buyToken.amount, decimals); + const bnAmount = utils.parseUnits(buyToken.amount, decimals); if (buyToken.type === ItemType.NATIVE) { return { diff --git a/packages/checkout/widgets-lib/src/lib/validations/widgetValidators.ts b/packages/checkout/widgets-lib/src/lib/validations/widgetValidators.ts index 90b31a93b8..5997b4fc58 100644 --- a/packages/checkout/widgets-lib/src/lib/validations/widgetValidators.ts +++ b/packages/checkout/widgets-lib/src/lib/validations/widgetValidators.ts @@ -1,5 +1,5 @@ import { WalletProviderName } from '@imtbl/checkout-sdk'; -import { isAddress } from 'ethers/lib/utils'; +import { utils } from 'ethers'; import { amountInputValidation } from './amountInputValidations'; import { NATIVE } from '../constants'; @@ -22,5 +22,5 @@ export function isValidAddress(address: string | undefined) { if (address === undefined) return false; if (address === '') return true; if (address === NATIVE || address === NATIVE.toLowerCase()) return true; - return isAddress(address); + return utils.isAddress(address); } diff --git a/packages/checkout/widgets-lib/src/widgets/bridge/components/BridgeForm.tsx b/packages/checkout/widgets-lib/src/widgets/bridge/components/BridgeForm.tsx index 4aaef2bb16..a0a6334da2 100644 --- a/packages/checkout/widgets-lib/src/widgets/bridge/components/BridgeForm.tsx +++ b/packages/checkout/widgets-lib/src/widgets/bridge/components/BridgeForm.tsx @@ -9,7 +9,6 @@ import { } from 'react'; import { ApproveDepositBridgeResponse, BridgeDepositResponse } from '@imtbl/bridge-sdk'; import { BigNumber, utils } from 'ethers'; -import { parseEther } from 'ethers/lib/utils'; import { amountInputValidation } from '../../../lib/validations/amountInputValidations'; import { BridgeContext } from '../context/BridgeContext'; import { SharedViews, ViewActions, ViewContext } from '../../../context/view-context/ViewContext'; @@ -229,9 +228,9 @@ export function BridgeForm(props: BridgeFormProps) { } const tokenIsEth = isNativeToken(token?.token.address); - const gasAmount = parseEther(gasFee.length !== 0 ? gasFee : '0'); + const gasAmount = utils.parseEther(gasFee.length !== 0 ? gasFee : '0'); const additionalAmount = tokenIsEth && !Number.isNaN(parseFloat(amount)) - ? parseEther(amount) + ? utils.parseEther(amount) : BigNumber.from('0'); return gasAmount.add(additionalAmount).gt(ethBalance.balance); diff --git a/packages/checkout/widgets-lib/src/widgets/swap/components/SwapForm.tsx b/packages/checkout/widgets-lib/src/widgets/swap/components/SwapForm.tsx index 5cf5125aed..e77a8e60d3 100644 --- a/packages/checkout/widgets-lib/src/widgets/swap/components/SwapForm.tsx +++ b/packages/checkout/widgets-lib/src/widgets/swap/components/SwapForm.tsx @@ -8,7 +8,6 @@ import { import { BigNumber, utils } from 'ethers'; import { TokenInfo } from '@imtbl/checkout-sdk'; import { TransactionResponse } from '@imtbl/dex-sdk'; -import { parseEther, parseUnits } from 'ethers/lib/utils'; import { text } from '../../../resources/text/textConfig'; import { amountInputValidation as textInputValidator } from '../../../lib/validations/amountInputValidations'; import { SwapContext } from '../context/SwapContext'; @@ -443,9 +442,9 @@ export function SwapForm({ data }: SwapFromProps) { if (!imxBalance) return true; const fromTokenIsImx = fromToken?.address === IMX_ADDRESS_ZKEVM; - const gasAmount = parseEther(gasFeeValue.length !== 0 ? gasFeeValue : '0'); + const gasAmount = utils.parseEther(gasFeeValue.length !== 0 ? gasFeeValue : '0'); const additionalAmount = fromTokenIsImx && !Number.isNaN(parseFloat(fromAmount)) - ? parseUnits(fromAmount, fromToken?.decimals || 18) + ? utils.parseUnits(fromAmount, fromToken?.decimals || 18) : BigNumber.from('0'); return gasAmount.add(additionalAmount).gt(imxBalance.balance);