Skip to content

Commit 68fdb01

Browse files
committed
feat: wip nitro testnode support
Signed-off-by: Tomás Migone <[email protected]>
1 parent 0e8c64f commit 68fdb01

File tree

8 files changed

+84
-195
lines changed

8 files changed

+84
-195
lines changed

arbitrum-addresses.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,10 @@
3838
"L2GatewayRouter": {
3939
"address": "0xE5B9d8d42d656d1DcB8065A6c012FE3780246041"
4040
}
41+
},
42+
"1337": {
43+
"IInbox": {
44+
"address": "0x793f25377a9f2f07787ae0cf282ebe7f41d399fc"
45+
}
4146
}
4247
}

cli/commands/bridge/to-l2.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Argv } from 'yargs'
2-
import { utils } from 'ethers'
2+
import { BigNumber, utils } from 'ethers'
33
import { L1TransactionReceipt, L1ToL2MessageStatus, L1ToL2MessageWriter } from '@arbitrum/sdk'
44

55
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
@@ -45,7 +45,8 @@ export const sendToL2 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
4545

4646
// parse provider
4747
const l1Provider = cli.wallet.provider
48-
const l2Provider = getProvider(cliArgs.l2ProviderUrl)
48+
// TODO: fix this hack for usage with hardhat
49+
const l2Provider = cliArgs.l2Provider ? cliArgs.l2Provider : getProvider(cliArgs.l2ProviderUrl)
4950
const l1ChainId = cli.chainId
5051
const l2ChainId = (await l2Provider.getNetwork()).chainId
5152
if (chainIdIsL2(l1ChainId) || !chainIdIsL2(l2ChainId)) {
@@ -100,6 +101,7 @@ export const sendToL2 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
100101
const txReceipt = await sendTransaction(cli.wallet, l1Gateway, 'outboundTransfer', txParams, {
101102
value: ethValue,
102103
})
104+
103105
// get l2 ticket status
104106
if (txReceipt.status == 1) {
105107
logger.info('Waiting for message to propagate to L2...')

cli/cross-chain.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { L1ToL2MessageGasEstimator } from '@arbitrum/sdk'
2+
import { L1ToL2MessageNoGasParams } from '@arbitrum/sdk/dist/lib/message/L1ToL2MessageCreator'
23
import { BigNumber, providers } from 'ethers'
34
import { parseEther } from 'ethers/lib/utils'
45

@@ -44,20 +45,24 @@ export const estimateRetryableTxGas = async (
4445
logger.info('Estimating retryable ticket gas:')
4546
const baseFee = (await l1Provider.getBlock('latest')).baseFeePerGas
4647
const gasEstimator = new L1ToL2MessageGasEstimator(l2Provider)
48+
const retryableEstimateData: L1ToL2MessageNoGasParams = {
49+
from: gatewayAddress,
50+
to: l2Dest,
51+
data: depositCalldata,
52+
l2CallValue: parseEther('0'),
53+
excessFeeRefundAddress: gatewayAddress,
54+
callValueRefundAddress: gatewayAddress,
55+
}
4756
const gasParams = await gasEstimator.estimateAll(
48-
gatewayAddress,
49-
l2Dest,
50-
depositCalldata,
51-
parseEther('0'),
57+
retryableEstimateData,
5258
baseFee as BigNumber,
53-
gatewayAddress,
54-
gatewayAddress,
5559
l1Provider,
5660
)
61+
5762
// override fixed values
5863
return {
5964
maxGas: opts.maxGas ?? gasParams.gasLimit,
6065
gasPriceBid: opts.gasPriceBid ?? gasParams.maxFeePerGas,
61-
maxSubmissionCost: opts.maxSubmissionCost ?? gasParams.maxSubmissionFee,
66+
maxSubmissionCost: opts.maxSubmissionCost ?? gasParams.maxSubmissionCost,
6267
}
6368
}

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const SKIP_LOAD = process.env.SKIP_LOAD === 'true'
2929

3030
function loadTasks() {
3131
require('./gre/gre')
32-
;['contracts', 'misc', 'deployment', 'actions', 'verify', 'e2e'].forEach((folder) => {
32+
;['contracts', 'bridge', 'misc', 'deployment', 'actions', 'verify', 'e2e'].forEach((folder) => {
3333
const tasksPath = path.join(__dirname, 'tasks', folder)
3434
fs.readdirSync(tasksPath)
3535
.filter((pth) => pth.includes('.ts'))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"ethers": "^5.6.0"
1616
},
1717
"devDependencies": {
18-
"@arbitrum/sdk": "^3.0.0-beta.6",
18+
"@arbitrum/sdk": "3.0.0-rc.0",
1919
"@commitlint/cli": "^13.2.1",
2020
"@commitlint/config-conventional": "^13.2.0",
2121
"@defi-wonderland/smock": "^2.0.7",

scripts/e2e

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ function test_e2e_scenarios () {
8888
local GRAPH_CONFIG=$2
8989
local ADDRESS_BOOK=$3
9090

91+
npx hardhat e2e:scenario send-grt-to-l2 --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
92+
9193
# Skip GRT based scenarios as L2 doesnt have tokens yet...
9294
if [[ "$NETWORK" != "localnitrol2" ]]; then
9395
npx hardhat e2e:scenario create-subgraphs --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
@@ -100,6 +102,15 @@ function test_e2e_scenarios () {
100102
fi
101103
}
102104

105+
function test_e2e_scenarios_l1 () {
106+
local NETWORK=$1
107+
local GRAPH_CONFIG=$2
108+
local ADDRESS_BOOK=$3
109+
110+
npx hardhat e2e:scenario send-grt-to-l2 --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
111+
112+
}
113+
103114
# Allow overriding config
104115
# By default run only L1 tests on localhost network
105116
ADDRESS_BOOK=${ADDRESS_BOOK:-"addresses.json"}

tasks/bridge/to-l2.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { task } from 'hardhat/config'
2+
import { cliOpts } from '../../cli/defaults'
3+
import { sendToL2 } from '../../cli/commands/bridge/to-l2'
4+
import { loadEnv } from '../../cli/env'
5+
import { BigNumber } from 'ethers'
6+
7+
task('bridge:send-to-l2', 'Bridge GRT tokens from L1 to L2')
8+
.addParam('amount', 'Amount of tokens to bridge')
9+
.addOptionalParam('sender', 'Address of the sender. L1 deployer if empty.')
10+
.addOptionalParam('recipient', 'Receiving address in L2. Same to L1 address if empty.')
11+
.addOptionalParam('addressBook', cliOpts.addressBook.description)
12+
.addOptionalParam('l1GraphConfig', cliOpts.graphConfig.description)
13+
.addOptionalParam('l2GraphConfig', cliOpts.graphConfig.description)
14+
.setAction(async (taskArgs, hre) => {
15+
const graph = hre.graph(taskArgs)
16+
17+
console.log('> Sending GRT to L2')
18+
19+
// Get the sender, use L1 deployer if non provided
20+
const l1Deployer = await graph.l1.getDeployer()
21+
const sender: string = taskArgs.sender ?? l1Deployer.address
22+
23+
const wallets = await graph.l1.getWallets()
24+
let wallet = wallets.find((w) => w.address === sender)
25+
26+
if (!wallet) {
27+
throw new Error(`No wallet found for address ${sender}`)
28+
} else {
29+
console.log(`> Using wallet ${wallet.address}`)
30+
wallet = wallet.connect(graph.l1.provider)
31+
}
32+
33+
// Patch sendToL2 opts
34+
taskArgs.l2Provider = graph.l2.provider
35+
36+
// Arbitrum SDK does not support local testnode so we hardcode estimations
37+
if (graph.l2.chainId === 412346) {
38+
taskArgs.maxGas = BigNumber.from(200_000)
39+
taskArgs.gasPriceBid = BigNumber.from(300_000_000)
40+
taskArgs.maxSubmissionCost = BigNumber.from(500_000)
41+
}
42+
43+
await sendToL2(await loadEnv(taskArgs, wallet), taskArgs)
44+
45+
console.log('Done!')
46+
})

0 commit comments

Comments
 (0)