diff --git a/.github/workflows/contract-tests.yml b/.github/workflows/contract-tests.yml index f6fa3602..9e0ec1fe 100644 --- a/.github/workflows/contract-tests.yml +++ b/.github/workflows/contract-tests.yml @@ -196,3 +196,35 @@ jobs: - name: Run e2e tests run: yarn test:e2e + test-e2e-fee-token-6-decimals: + name: Test e2e fee token with 6 decimals + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - uses: OffchainLabs/actions/run-nitro-test-node@main + with: + l3-node: true + args: --l3-fee-token --l3-fee-token-decimals 6 + no-token-bridge: true + no-l3-token-bridge: true + nitro-contracts-branch: '${{ github.head_ref }}' + nitro-testnode-ref: 'non18-decimal-token' + + - name: Setup node/yarn + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install packages + run: yarn + + - name: Compile contracts + run: yarn build + + - name: Run e2e tests + run: yarn test:e2e diff --git a/scripts/rollupCreation.ts b/scripts/rollupCreation.ts index 752b480a..e70b82dc 100644 --- a/scripts/rollupCreation.ts +++ b/scripts/rollupCreation.ts @@ -4,7 +4,7 @@ import { run } from 'hardhat' import { abi as rollupCreatorAbi } from '../build/contracts/src/rollup/RollupCreator.sol/RollupCreator.json' import { config, maxDataSize } from './config' import { BigNumber, Signer } from 'ethers' -import { IERC20__factory } from '../build/types' +import { ERC20, ERC20__factory, IERC20__factory } from '../build/types' import { sleep } from './testSetup' import { promises as fs } from 'fs' import { _isRunningOnArbitrum } from './deploymentUtils' @@ -85,6 +85,10 @@ export async function createRollup( let feeCost = ethers.utils.parseEther('0.13') if (feeToken != ethers.constants.AddressZero) { // in case fees are paid via fee token, then approve rollup cretor to spend required amount + feeCost = await _getPrescaledAmount( + ERC20__factory.connect(feeToken, signer), + feeCost + ) await ( await IERC20__factory.connect(feeToken, signer).approve( rollupCreator.address, @@ -338,3 +342,25 @@ async function _getDevRollupConfig( }) } } + +async function _getPrescaledAmount( + nativeToken: ERC20, + amount: BigNumber +): Promise { + const decimals = BigNumber.from(await nativeToken.decimals()) + if (decimals.lt(BigNumber.from(18))) { + const scalingFactor = BigNumber.from(10).pow( + BigNumber.from(18).sub(decimals) + ) + let prescaledAmount = amount.div(scalingFactor) + // round up if needed + if (prescaledAmount.mul(scalingFactor).lt(amount)) { + prescaledAmount = prescaledAmount.add(BigNumber.from(1)) + } + return prescaledAmount + } else if (decimals.gt(BigNumber.from(18))) { + return amount.mul(BigNumber.from(10).pow(decimals.sub(BigNumber.from(18)))) + } + + return amount +}