Skip to content

Commit

Permalink
Merge pull request #201 from OffchainLabs/e2e-decimals
Browse files Browse the repository at this point in the history
Add 6-decimals fee token chain to CI
  • Loading branch information
gvladika authored Jul 3, 2024
2 parents 870566d + 34751a7 commit f4bf96e
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .github/workflows/contract-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 27 additions & 1 deletion scripts/rollupCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -338,3 +342,25 @@ async function _getDevRollupConfig(
})
}
}

async function _getPrescaledAmount(
nativeToken: ERC20,
amount: BigNumber
): Promise<BigNumber> {
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
}

0 comments on commit f4bf96e

Please sign in to comment.