@@ -10,6 +10,7 @@ import {
1010 L1ToL2MessageGasEstimator ,
1111} from '@arbitrum/sdk'
1212import { chainIdIsL2 } from '../../utils'
13+ import { Argv } from 'yargs'
1314
1415const logAutoRedeemReason = ( autoRedeemRec ) => {
1516 if ( autoRedeemRec == null ) {
@@ -72,24 +73,44 @@ export const sendToL2 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
7273 '0x' ,
7374 )
7475
75- // Comment from Offchain Labs' implementation:
76- // we add a 0.05 ether "deposit" buffer to pay for execution in the gas estimation
77- logger . info ( 'Estimating retryable ticket gas:' )
78- const baseFee = ( await cli . wallet . provider . getBlock ( 'latest' ) ) . baseFeePerGas
79- const gasEstimator = new L1ToL2MessageGasEstimator ( l2Provider )
80- const gasParams = await gasEstimator . estimateAll (
81- gateway . address ,
82- l2Dest ,
83- depositCalldata ,
84- parseEther ( '0' ) ,
85- baseFee as BigNumber ,
86- gateway . address ,
87- gateway . address ,
88- cli . wallet . provider ,
89- )
90- const maxGas = gasParams . gasLimit
91- const gasPriceBid = gasParams . maxFeePerGas
92- const maxSubmissionPrice = gasParams . maxSubmissionFee
76+ const senderBalance = await l1GRT . balanceOf ( cli . wallet . address )
77+ if ( senderBalance . lt ( amount ) ) {
78+ throw new Error ( 'Sender balance is insufficient for the transfer' )
79+ }
80+ logger . info ( 'Approving token transfer' )
81+ await sendTransaction ( cli . wallet , l1GRT , 'approve' , [ gateway . address , amount ] )
82+
83+ let maxGas : BigNumber
84+ let gasPriceBid : BigNumber
85+ let maxSubmissionPrice : BigNumber
86+
87+ if ( ! cliArgs . maxGas || ! cliArgs . gasPrice || ! cliArgs . maxSubmissionCost ) {
88+ // Comment from Offchain Labs' implementation:
89+ // we add a 0.05 ether "deposit" buffer to pay for execution in the gas estimation
90+ logger . info ( 'Estimating retryable ticket gas:' )
91+ const baseFee = ( await cli . wallet . provider . getBlock ( 'latest' ) ) . baseFeePerGas
92+ const gasEstimator = new L1ToL2MessageGasEstimator ( l2Provider )
93+ const gasParams = await gasEstimator . estimateAll (
94+ gateway . address ,
95+ l2Dest ,
96+ depositCalldata ,
97+ parseEther ( '0' ) ,
98+ baseFee as BigNumber ,
99+ gateway . address ,
100+ gateway . address ,
101+ cli . wallet . provider ,
102+ )
103+ maxGas = cliArgs . maxGas ? BigNumber . from ( cliArgs . maxGas ) : gasParams . gasLimit
104+ gasPriceBid = cliArgs . gasPrice ? BigNumber . from ( cliArgs . gasPrice ) : gasParams . maxFeePerGas
105+ maxSubmissionPrice = cliArgs . maxSubmissionCost
106+ ? BigNumber . from ( cliArgs . maxSubmissionCost )
107+ : gasParams . maxSubmissionFee
108+ } else {
109+ maxGas = BigNumber . from ( cliArgs . maxGas )
110+ gasPriceBid = BigNumber . from ( cliArgs . gasPrice )
111+ maxSubmissionPrice = BigNumber . from ( cliArgs . maxSubmissionCost )
112+ }
113+
93114 logger . info (
94115 `Using max gas: ${ maxGas } , gas price bid: ${ gasPriceBid } , max submission price: ${ maxSubmissionPrice } ` ,
95116 )
@@ -99,14 +120,13 @@ export const sendToL2 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<v
99120 const data = utils . defaultAbiCoder . encode ( [ 'uint256' , 'bytes' ] , [ maxSubmissionPrice , '0x' ] )
100121
101122 const params = [ l1GRTAddress , recipient , amount , maxGas , gasPriceBid , data ]
102- logger . info ( 'Approving token transfer' )
103- await sendTransaction ( cli . wallet , l1GRT , 'approve' , [ gateway . address , amount ] )
104123 logger . info ( 'Sending outbound transfer transaction' )
105124 const receipt = await sendTransaction ( cli . wallet , gateway , 'outboundTransfer' , params , {
106125 value : ethValue ,
107126 } )
108127 const l1Receipt = new L1TransactionReceipt ( receipt )
109- const l1ToL2Message = await l1Receipt . getL1ToL2Messages ( cli . wallet . connect ( l2Provider ) ) [ 0 ]
128+ const l1ToL2Messages = await l1Receipt . getL1ToL2Messages ( cli . wallet . connect ( l2Provider ) )
129+ const l1ToL2Message = l1ToL2Messages [ 0 ]
110130
111131 logger . info ( 'Waiting for message to propagate to L2...' )
112132 try {
@@ -143,6 +163,26 @@ export const redeemSendToL2 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Pro
143163export const sendToL2Command = {
144164 command : 'send-to-l2 <amount> [recipient]' ,
145165 describe : 'Perform an L1-to-L2 Graph Token transaction' ,
166+ builder : ( yargs : Argv ) : Argv => {
167+ return yargs
168+ . option ( 'max-gas' , {
169+ description : 'Max gas for the L2 redemption attempt' ,
170+ requiresArg : true ,
171+ type : 'string' ,
172+ } )
173+ . option ( 'gas-price' , {
174+ description : 'Gas price for the L2 redemption attempt' ,
175+ requiresArg : true ,
176+ type : 'string' ,
177+ } )
178+ . option ( 'max-submission-cost' , {
179+ description : 'Max submission cost for the retryable ticket' ,
180+ requiresArg : true ,
181+ type : 'string' ,
182+ } )
183+ . positional ( 'amount' , { demandOption : true } )
184+ . positional ( 'recipient' , { demandOption : false } )
185+ } ,
146186 handler : async ( argv : CLIArgs ) : Promise < void > => {
147187 return sendToL2 ( await loadEnv ( argv ) , argv )
148188 } ,
0 commit comments