diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index d6e08261..4f49e4ee 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -59,8 +59,17 @@ jobs: run: yarn test:unit test-integration: - name: Test (Integration) + name: Test (Integration) - ${{ matrix.config.name }} runs-on: ubuntu-latest + strategy: + matrix: + config: + - name: Default + args: --tokenbridge --l3node --l3-token-bridge --l3-fee-token + decimals: 18 + - name: Custom Decimals + args: --tokenbridge --l3node --l3-token-bridge --l3-fee-token --l3-fee-token-decimals 12 + decimals: 12 steps: - name: Checkout uses: actions/checkout@v4 @@ -72,7 +81,7 @@ jobs: uses: OffchainLabs/actions/run-nitro-test-node@feat-simplify with: nitro-testnode-ref: release - args: --tokenbridge --l3node --l3-token-bridge --l3-fee-token + args: ${{ matrix.config.args }} - name: Copy .env run: cp ./.env.example ./.env @@ -81,4 +90,4 @@ jobs: run: yarn build - name: Test - run: yarn test:integration + run: DECIMALS=${{decimals}} yarn test:integration diff --git a/src/createRollup.integration.test.ts b/src/createRollup.integration.test.ts index 9f30b032..261d0077 100644 --- a/src/createRollup.integration.test.ts +++ b/src/createRollup.integration.test.ts @@ -8,6 +8,7 @@ import { getInformationFromTestnode, } from './testHelpers'; import { createRollupFetchTransactionHash } from './createRollupFetchTransactionHash'; +import { nativeTokenDecimalsTo18Decimals } from './utils/decimals'; const parentChainPublicClient = createPublicClient({ chain: nitroTestnodeL2, @@ -19,6 +20,7 @@ const testnodeAccounts = getNitroTestnodePrivateKeyAccounts(); const l3TokenBridgeDeployer = testnodeAccounts.l3TokenBridgeDeployer; const batchPosters = [testnodeAccounts.deployer.address]; const validators = [testnodeAccounts.deployer.address]; +const nativeTokenDecimals = Number(process.env.DECIMALS) ?? 18; describe(`create an AnyTrust chain that uses ETH as gas token`, async () => { const { createRollupConfig, createRollupInformation } = await createRollupHelper({ @@ -68,7 +70,7 @@ describe(`create an AnyTrust chain that uses a custom gas token`, async () => { client: parentChainPublicClient, }); - it(`successfully deploys core contracts through rollup creator (18 decimals)`, async () => { + it(`successfully deploys core contracts through rollup creator`, async () => { // assert all inputs are correct const [arg] = createRollupInformation.transaction.getInputs(); expect(arg.config).toEqual(createRollupConfig); @@ -77,7 +79,9 @@ describe(`create an AnyTrust chain that uses a custom gas token`, async () => { expect(arg.maxDataSize).toEqual(104_857n); expect(arg.nativeToken).toEqual(nativeToken); expect(arg.deployFactoriesToL2).toEqual(true); - expect(arg.maxFeePerGasForRetryables).toEqual(parseGwei('0.1')); + expect(arg.maxFeePerGasForRetryables).toEqual( + nativeTokenDecimalsTo18Decimals({ amount: 100n, decimals: nativeTokenDecimals }), + ); // assert the transaction executed successfully expect(createRollupInformation.transactionReceipt.status).toEqual('success'); diff --git a/src/createRollup.ts b/src/createRollup.ts index 4a0cbc27..0112c2e3 100644 --- a/src/createRollup.ts +++ b/src/createRollup.ts @@ -15,6 +15,8 @@ import { } from './createRollupPrepareTransaction'; import { CreateRollupParams } from './types/createRollupTypes'; import { validateParentChain } from './types/ParentChain'; +import { getNativeTokenDecimals, nativeTokenDecimalsTo18Decimals } from './utils/decimals'; +import { defaults as createRollupDefaults } from './createRollupDefaults'; type EnsureCustomGasTokenAllowanceGrantedToRollupCreatorParams = { nativeToken: Address; @@ -170,9 +172,21 @@ export async function createRollup({ }); } + const decimals = await getNativeTokenDecimals({ + publicClient: parentChainPublicClient, + nativeTokenAddress: nativeToken ?? zeroAddress, + }); + const maxFeePerGas = nativeTokenDecimalsTo18Decimals({ + amount: params.maxFeePerGasForRetryables ?? createRollupDefaults.maxFeePerGasForRetryables, + decimals, + }); + // prepare the transaction for deploying the core contracts const txRequest = await createRollupPrepareTransactionRequest({ - params, + params: { + ...params, + maxFeePerGasForRetryables: maxFeePerGas, + }, account: account.address, publicClient: parentChainPublicClient, }); diff --git a/src/createRollupGetRetryablesFees.ts b/src/createRollupGetRetryablesFees.ts index 53d6fb9a..4b73e562 100644 --- a/src/createRollupGetRetryablesFees.ts +++ b/src/createRollupGetRetryablesFees.ts @@ -7,7 +7,6 @@ import { EstimateGasParameters, encodeFunctionData, decodeFunctionResult, - zeroAddress, } from 'viem'; import { rollupCreatorABI } from './contracts/RollupCreator'; @@ -16,7 +15,6 @@ import { isCustomFeeTokenAddress } from './utils/isCustomFeeTokenAddress'; import { defaults as createRollupDefaults } from './createRollupDefaults'; import { applyPercentIncrease } from './utils/gasOverrides'; import { createRollupDefaultRetryablesFees } from './constants'; -import { getNativeTokenDecimals, scaleToNativeTokenDecimals } from './utils/decimals'; const deployHelperABI = [ { @@ -102,14 +100,7 @@ export async function createRollupGetRetryablesFees { it(`successfully deploys token bridge contracts through token bridge creator`, async () => { const testnodeInformation = getInformationFromTestnode(); @@ -218,7 +221,10 @@ describe('createTokenBridge utils function', () => { data: encodeFunctionData({ abi: erc20ABI, functionName: 'transfer', - args: [l3RollupOwner.address, parseEther('500')], + args: [ + l3RollupOwner.address, + scaleToNativeTokenDecimals({ amount: 500n, decimals: nativeTokenDecimals }), + ], }), value: BigInt(0), account: l3TokenBridgeDeployer, @@ -368,7 +374,7 @@ describe('createTokenBridge', () => { checkWethGateways(tokenBridgeContracts, { customFeeToken: false }); }); - it('successfully deploys token bridge contracts with a custom fee token (18 decimals)', async () => { + it('successfully deploys token bridge contracts with a custom fee token', async () => { const testnodeInformation = getInformationFromTestnode(); // deploy a fresh token bridge creator, because it is only possible to deploy one token bridge per rollup per token bridge creator @@ -384,7 +390,10 @@ describe('createTokenBridge', () => { data: encodeFunctionData({ abi: erc20ABI, functionName: 'transfer', - args: [l3RollupOwner.address, parseEther('500')], + args: [ + l3RollupOwner.address, + scaleToNativeTokenDecimals({ amount: 500n, decimals: nativeTokenDecimals }), + ], }), value: BigInt(0), account: l3TokenBridgeDeployer, @@ -437,10 +446,6 @@ describe('createTokenBridge', () => { checkWethGateways(tokenBridgeContracts, { customFeeToken: true }); }); - it('successfully deploys token bridge contracts with a custom fee token (non-18 decimals)', async () => { - // Deploy a custom chain with non-18 decimals - }); - it('should throw when createTokenBridge is called multiple times', async () => { const testnodeInformation = getInformationFromTestnode();