diff --git a/src/lib/assetBridger/erc20Bridger.ts b/src/lib/assetBridger/erc20Bridger.ts index 3eff3b8f0..12bb9db51 100644 --- a/src/lib/assetBridger/erc20Bridger.ts +++ b/src/lib/assetBridger/erc20Bridger.ts @@ -79,7 +79,7 @@ import { ParentToChildMessageGasParams } from '../message/ParentToChildMessageCr import { getNativeTokenDecimals, isArbitrumChain, - scaleToNativeTokenDecimals, + scaleFrom18DecimalsToNativeTokenDecimals, } from '../utils/lib' import { L2ERC20Gateway__factory } from '../abi/factories/L2ERC20Gateway__factory' import { getErc20ParentAddressFromParentToChildTxRequest } from '../utils/calldata' @@ -626,7 +626,7 @@ export class Erc20Bridger extends AssetBridger< // callHookData '0x', // nativeTokenTotalFee - scaleToNativeTokenDecimals({ + scaleFrom18DecimalsToNativeTokenDecimals({ amount: depositParams.gasLimit .mul(depositParams.maxFeePerGas) .add(depositParams.maxSubmissionCost), // will be zero @@ -1134,11 +1134,11 @@ export class AdminErc20Bridger extends Erc20Bridger { setTokenGas.gasLimit, setGatewayGas.gasLimit, doubleFeePerGas, - scaleToNativeTokenDecimals({ + scaleFrom18DecimalsToNativeTokenDecimals({ amount: setTokenDeposit, decimals: nativeTokenDecimals, }), - scaleToNativeTokenDecimals({ + scaleFrom18DecimalsToNativeTokenDecimals({ amount: setGatewayDeposit, decimals: nativeTokenDecimals, }), diff --git a/src/lib/assetBridger/ethBridger.ts b/src/lib/assetBridger/ethBridger.ts index 4f6c03bbf..f6f037c5a 100644 --- a/src/lib/assetBridger/ethBridger.ts +++ b/src/lib/assetBridger/ethBridger.ts @@ -51,7 +51,7 @@ import { ERC20__factory } from '../abi/factories/ERC20__factory' import { getNativeTokenDecimals, isArbitrumChain, - nativeTokenDecimalsTo18Decimals, + scaleFromNativeTokenDecimalsTo18Decimals, } from '../utils/lib' export type ApproveGasTokenParams = { @@ -321,10 +321,11 @@ export class EthBridger extends AssetBridger< childNetwork: this.childNetwork, }) - const amountToBeMintedOnChildChain = nativeTokenDecimalsTo18Decimals({ - amount: params.amount, - decimals, - }) + const amountToBeMintedOnChildChain = + scaleFromNativeTokenDecimalsTo18Decimals({ + amount: params.amount, + decimals, + }) const requestParams = { ...params, diff --git a/src/lib/message/ParentToChildMessageGasEstimator.ts b/src/lib/message/ParentToChildMessageGasEstimator.ts index 7df903790..ac5fea657 100644 --- a/src/lib/message/ParentToChildMessageGasEstimator.ts +++ b/src/lib/message/ParentToChildMessageGasEstimator.ts @@ -15,7 +15,7 @@ import { getBaseFee, getNativeTokenDecimals, isDefined, - scaleToNativeTokenDecimals, + scaleFrom18DecimalsToNativeTokenDecimals, } from '../utils/lib' import { OmitTyped } from '../utils/types' import { @@ -271,7 +271,7 @@ export class ParentToChildMessageGasEstimator { const deposit = options?.deposit?.base || - scaleToNativeTokenDecimals({ + scaleFrom18DecimalsToNativeTokenDecimals({ amount: gasLimit .mul(maxFeePerGas) .add(maxSubmissionFee) diff --git a/src/lib/utils/lib.ts b/src/lib/utils/lib.ts index f466eb7b3..aaee6ef39 100644 --- a/src/lib/utils/lib.ts +++ b/src/lib/utils/lib.ts @@ -222,7 +222,7 @@ export async function getNativeTokenDecimals({ } } -export function scaleToNativeTokenDecimals({ +export function scaleFrom18DecimalsToNativeTokenDecimals({ amount, decimals, }: { @@ -253,7 +253,7 @@ export function scaleToNativeTokenDecimals({ return amount.mul(BigNumber.from(10).pow(BigNumber.from(decimals - 18))) } -export function nativeTokenDecimalsTo18Decimals({ +export function scaleFromNativeTokenDecimalsTo18Decimals({ amount, decimals, }: { diff --git a/tests/integration/eth.test.ts b/tests/integration/eth.test.ts index 418460b18..6c2aacedc 100644 --- a/tests/integration/eth.test.ts +++ b/tests/integration/eth.test.ts @@ -40,7 +40,7 @@ import { itOnlyWhenEth } from './custom-fee-token/mochaExtensions' import { ParentTransactionReceipt } from '../../src' import { getNativeTokenDecimals, - scaleToNativeTokenDecimals, + scaleFrom18DecimalsToNativeTokenDecimals, } from '../../src/lib/utils/lib' import { parseUnits } from 'ethers/lib/utils' @@ -458,7 +458,10 @@ describe('Ether', async () => { ).balanceOf(randomAddress) : await parentSigner.provider!.getBalance(randomAddress) expect(finalRandomBalance.toString(), 'L1 final balance').to.eq( - scaleToNativeTokenDecimals({ amount: ethToWithdraw, decimals }).toString() + scaleFrom18DecimalsToNativeTokenDecimals({ + amount: ethToWithdraw, + decimals, + }).toString() ) }) }) diff --git a/tests/integration/retryableData.test.ts b/tests/integration/retryableData.test.ts index 9120c6f81..4797a1e82 100644 --- a/tests/integration/retryableData.test.ts +++ b/tests/integration/retryableData.test.ts @@ -32,7 +32,7 @@ import { ERC20Inbox__factory } from '../../src/lib/abi/factories/ERC20Inbox__fac import { isArbitrumNetworkWithCustomFeeToken } from './custom-fee-token/customFeeTokenTestHelpers' import { getNativeTokenDecimals, - scaleToNativeTokenDecimals, + scaleFrom18DecimalsToNativeTokenDecimals, } from '../../src/lib/utils/lib' describe('RevertData', () => { @@ -57,7 +57,7 @@ describe('RevertData', () => { l2CallValue, data: hexlify(randomBytes(32)), maxSubmissionCost: maxSubmissionCost, - value: scaleToNativeTokenDecimals({ + value: scaleFrom18DecimalsToNativeTokenDecimals({ amount: l2CallValue .add(maxSubmissionCost) .add(RetryableDataTools.ErrorTriggeringParams.gasLimit) diff --git a/tests/integration/testHelpers.ts b/tests/integration/testHelpers.ts index d4543b981..50e8b2c9a 100644 --- a/tests/integration/testHelpers.ts +++ b/tests/integration/testHelpers.ts @@ -37,7 +37,7 @@ import { ArbSdkError } from '../../src/lib/dataEntities/errors' import { ERC20 } from '../../src/lib/abi/ERC20' import { isArbitrumNetworkWithCustomFeeToken } from './custom-fee-token/customFeeTokenTestHelpers' import { ERC20__factory } from '../../src/lib/abi/factories/ERC20__factory' -import { scaleToNativeTokenDecimals } from '../../src/lib/utils/lib' +import { scaleFrom18DecimalsToNativeTokenDecimals } from '../../src/lib/utils/lib' const preFundAmount = parseEther('0.1') @@ -355,7 +355,7 @@ export const depositToken = async ({ const MAX_BASE_ESTIMATED_GAS_FEE = BigNumber.from(1_000_000_000_000_000) - const maxScaledEstimatedGasFee = scaleToNativeTokenDecimals({ + const maxScaledEstimatedGasFee = scaleFrom18DecimalsToNativeTokenDecimals({ amount: MAX_BASE_ESTIMATED_GAS_FEE, decimals: feeTokenDecimals, }) diff --git a/tests/unit/nativeToken.test.ts b/tests/unit/nativeToken.test.ts index 239d1f19a..281804c6b 100644 --- a/tests/unit/nativeToken.test.ts +++ b/tests/unit/nativeToken.test.ts @@ -5,8 +5,8 @@ import { expect } from 'chai' import { BigNumber } from 'ethers' import { parseEther } from 'ethers/lib/utils' import { - nativeTokenDecimalsTo18Decimals, - scaleToNativeTokenDecimals, + scaleFromNativeTokenDecimalsTo18Decimals, + scaleFrom18DecimalsToNativeTokenDecimals, } from '../../src/lib/utils/lib' const AMOUNT_TO_SCALE = parseEther('1.23456789') @@ -18,31 +18,34 @@ describe('Native token', () => { it('scales to native token decimals', () => { expect( - scaleToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 18 }).eq( - BigNumber.from('1234567890000000000') - ), + scaleFrom18DecimalsToNativeTokenDecimals({ + amount: AMOUNT_TO_SCALE, + decimals: 18, + }).eq(BigNumber.from('1234567890000000000')), decimalsToError(18) ).to.be.true // Rounds up the last digit - in this case no decimals so rounds up 1 to 2 expect( - scaleToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 0 }).eq( - BigNumber.from('2') - ), + scaleFrom18DecimalsToNativeTokenDecimals({ + amount: AMOUNT_TO_SCALE, + decimals: 0, + }).eq(BigNumber.from('2')), decimalsToError(0) ).to.be.true // Rounds up the last digit expect( - scaleToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 1 }).eq( - BigNumber.from('13') - ), + scaleFrom18DecimalsToNativeTokenDecimals({ + amount: AMOUNT_TO_SCALE, + decimals: 1, + }).eq(BigNumber.from('13')), decimalsToError(1) ).to.be.true // Rounds up the last digit expect( - scaleToNativeTokenDecimals({ + scaleFrom18DecimalsToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 6, }).eq(BigNumber.from('1234568')), @@ -51,31 +54,34 @@ describe('Native token', () => { // Rounds up the last digit expect( - scaleToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 7 }).eq( - BigNumber.from('12345679') - ), + scaleFrom18DecimalsToNativeTokenDecimals({ + amount: AMOUNT_TO_SCALE, + decimals: 7, + }).eq(BigNumber.from('12345679')), decimalsToError(7) ).to.be.true // Does not round up the last digit because all original decimals are included expect( - scaleToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 8 }).eq( - BigNumber.from('123456789') - ), + scaleFrom18DecimalsToNativeTokenDecimals({ + amount: AMOUNT_TO_SCALE, + decimals: 8, + }).eq(BigNumber.from('123456789')), decimalsToError(8) ).to.be.true // Does not round up the last digit because all original decimals are included expect( - scaleToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 9 }).eq( - BigNumber.from('1234567890') - ), + scaleFrom18DecimalsToNativeTokenDecimals({ + amount: AMOUNT_TO_SCALE, + decimals: 9, + }).eq(BigNumber.from('1234567890')), decimalsToError(9) ).to.be.true // Does not round up the last digit because all original decimals are included expect( - scaleToNativeTokenDecimals({ + scaleFrom18DecimalsToNativeTokenDecimals({ amount: AMOUNT_TO_SCALE, decimals: 24, }).eq(BigNumber.from('1234567890000000000000000')), @@ -85,7 +91,7 @@ describe('Native token', () => { it('scales native token decimals to 18 decimals', () => { expect( - nativeTokenDecimalsTo18Decimals({ + scaleFromNativeTokenDecimalsTo18Decimals({ amount: AMOUNT_TO_SCALE, decimals: 16, }).eq(BigNumber.from('123456789000000000000')), @@ -93,7 +99,7 @@ describe('Native token', () => { ).to.be.true expect( - nativeTokenDecimalsTo18Decimals({ + scaleFromNativeTokenDecimalsTo18Decimals({ amount: AMOUNT_TO_SCALE, decimals: 18, }).eq(BigNumber.from('1234567890000000000')), @@ -101,7 +107,7 @@ describe('Native token', () => { ).to.be.true expect( - nativeTokenDecimalsTo18Decimals({ + scaleFromNativeTokenDecimalsTo18Decimals({ amount: AMOUNT_TO_SCALE, decimals: 20, }).eq(BigNumber.from('12345678900000000')), diff --git a/yarn.lock b/yarn.lock index d710e1c2e..1776ed237 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2760,10 +2760,10 @@ electron-to-chromium@^1.4.535: resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.556.tgz#97385917eb6ea3ac6a3378cf87bb39ee1db96e76" integrity sha512-6RPN0hHfzDU8D56E72YkDvnLw5Cj2NMXZGg3UkgyoHxjVhG99KZpsKgBWMmTy0Ei89xwan+rbRsVB9yzATmYzQ== -elliptic@6.5.4, elliptic@6.5.6, elliptic@^6.5.2, elliptic@^6.5.4: - version "6.5.6" - resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.6.tgz#ee5f7c3a00b98a2144ac84d67d01f04d438fa53e" - integrity sha512-mpzdtpeCLuS3BmE3pO3Cpp5bbjlOPY2Q0PgoF+Od1XZrHLYI28Xe3ossCmYCQt11FQKEYd9+PF8jymTvtWJSHQ== +elliptic@6.5.4, elliptic@6.5.7, elliptic@^6.5.2, elliptic@^6.5.4: + version "6.5.7" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.5.7.tgz#8ec4da2cb2939926a1b9a73619d768207e647c8b" + integrity sha512-ESVCtTwiA+XhY3wyh24QqRGBoP3rEdDUl3EDUUo9tft074fi19IrdpH7hLCMMP3CIj7jb3W96rn8lt/BqIlt5Q== dependencies: bn.js "^4.11.9" brorand "^1.1.0"