@@ -11,6 +11,11 @@ import { JsonRpcProvider } from '@ethersproject/providers'
11
11
import { providers } from 'ethers'
12
12
import { L2GraphToken } from '../../../build/types/L2GraphToken'
13
13
import { getL2ToL1MessageReader , getL2ToL1MessageWriter } from '../../arbitrum'
14
+ import { getContractAt } from '../../network'
15
+ import { Argv } from 'yargs'
16
+
17
+ const LEGACY_L2_GRT_ADDRESS = '0x23A941036Ae778Ac51Ab04CEa08Ed6e2FE103614'
18
+ const LEGACY_L2_GATEWAY_ADDRESS = '0x09e9222e96e7b4ae2a407b98d48e330053351eee'
14
19
15
20
const FOURTEEN_DAYS_IN_SECONDS = 24 * 3600 * 14
16
21
@@ -78,21 +83,37 @@ export const startSendToL1 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Prom
78
83
const l2Wallet = cli . wallet . connect ( l2Provider )
79
84
const l2AddressBook = getAddressBook ( cliArgs . addressBook , l2ChainId . toString ( ) )
80
85
81
- const gateway = loadAddressBookContract ( 'L2GraphTokenGateway' , l2AddressBook , l2Wallet )
82
- const l2GRT = loadAddressBookContract ( 'L2GraphToken' , l2AddressBook , l2Wallet ) as L2GraphToken
86
+ let gateway : L2GraphTokenGateway
87
+ let l2GRT : L2GraphToken
88
+ if ( cliArgs . legacyToken ) {
89
+ gateway = getContractAt (
90
+ 'L2GraphTokenGateway' ,
91
+ LEGACY_L2_GATEWAY_ADDRESS ,
92
+ l2Wallet ,
93
+ ) as L2GraphTokenGateway
94
+ l2GRT = getContractAt ( 'L2GraphToken' , LEGACY_L2_GRT_ADDRESS , l2Wallet ) as L2GraphToken
95
+ } else {
96
+ gateway = loadAddressBookContract (
97
+ 'L2GraphTokenGateway' ,
98
+ l2AddressBook ,
99
+ l2Wallet ,
100
+ ) as L2GraphTokenGateway
101
+ l2GRT = loadAddressBookContract ( 'L2GraphToken' , l2AddressBook , l2Wallet ) as L2GraphToken
102
+ }
83
103
84
- const l1Gateway = cli . contracts [ 'L1GraphTokenGateway' ]
85
104
logger . info ( `Will send ${ cliArgs . amount } GRT to ${ recipient } ` )
86
- logger . info ( `Using L2 gateway ${ gateway . address } and L1 gateway ${ l1Gateway . address } ` )
105
+ logger . info ( `Using L2 gateway ${ gateway . address } ` )
87
106
88
107
const senderBalance = await l2GRT . balanceOf ( cli . wallet . address )
89
108
if ( senderBalance . lt ( amount ) ) {
90
109
throw new Error ( 'Sender balance is insufficient for the transfer' )
91
110
}
92
111
93
112
const params = [ l1GRTAddress , recipient , amount , '0x' ]
94
- logger . info ( 'Approving token transfer' )
95
- await sendTransaction ( l2Wallet , l2GRT , 'approve' , [ gateway . address , amount ] )
113
+ if ( ! cliArgs . legacyToken ) {
114
+ logger . info ( 'Approving token transfer' )
115
+ await sendTransaction ( l2Wallet , l2GRT , 'approve' , [ gateway . address , amount ] )
116
+ }
96
117
logger . info ( 'Sending outbound transfer transaction' )
97
118
const receipt = await sendTransaction (
98
119
l2Wallet ,
@@ -135,11 +156,20 @@ export const finishSendToL1 = async (
135
156
136
157
const l2AddressBook = getAddressBook ( cliArgs . addressBook , l2ChainId . toString ( ) )
137
158
138
- const gateway = loadAddressBookContract (
139
- 'L2GraphTokenGateway' ,
140
- l2AddressBook ,
141
- l2Provider ,
142
- ) as L2GraphTokenGateway
159
+ let gateway : L2GraphTokenGateway
160
+ if ( cliArgs . legacyToken ) {
161
+ gateway = getContractAt (
162
+ 'L2GraphTokenGateway' ,
163
+ LEGACY_L2_GATEWAY_ADDRESS ,
164
+ l2Provider ,
165
+ ) as L2GraphTokenGateway
166
+ } else {
167
+ gateway = loadAddressBookContract (
168
+ 'L2GraphTokenGateway' ,
169
+ l2AddressBook ,
170
+ l2Provider ,
171
+ ) as L2GraphTokenGateway
172
+ }
143
173
let txHash : string
144
174
if ( cliArgs . txHash ) {
145
175
txHash = cliArgs . txHash
@@ -193,6 +223,22 @@ export const finishSendToL1 = async (
193
223
export const startSendToL1Command = {
194
224
command : 'start-send-to-l1 <amount> [recipient]' ,
195
225
describe : 'Start an L2-to-L1 Graph Token transaction' ,
226
+ builder : ( yargs : Argv ) : Argv => {
227
+ return yargs
228
+ . option ( 'legacy-token' , {
229
+ type : 'boolean' ,
230
+ default : false ,
231
+ description : 'Use the legacy GRT token' ,
232
+ } )
233
+ . positional ( 'amount' , {
234
+ type : 'string' ,
235
+ description : 'The amount of tokens to send' ,
236
+ } )
237
+ . positional ( 'recipient' , {
238
+ type : 'string' ,
239
+ description : 'The recipient of the tokens on L1. Same as the L2 sender if empty.' ,
240
+ } )
241
+ } ,
196
242
handler : async ( argv : CLIArgs ) : Promise < void > => {
197
243
return startSendToL1 ( await loadEnv ( argv ) , argv )
198
244
} ,
@@ -203,6 +249,18 @@ export const finishSendToL1Command = {
203
249
describe :
204
250
'Finish an L2-to-L1 Graph Token transaction. L2 dispute period must have completed. ' +
205
251
'If txHash is not specified, the last withdrawal from the main account in the past 14 days will be redeemed.' ,
252
+ builder : ( yargs : Argv ) : Argv => {
253
+ return yargs
254
+ . option ( 'legacy-token' , {
255
+ type : 'boolean' ,
256
+ default : false ,
257
+ description : 'Use the legacy GRT token' ,
258
+ } )
259
+ . positional ( 'txHash' , {
260
+ type : 'string' ,
261
+ description : 'The transaction hash of the withdrawal on L2' ,
262
+ } )
263
+ } ,
206
264
handler : async ( argv : CLIArgs ) : Promise < void > => {
207
265
return finishSendToL1 ( await loadEnv ( argv ) , argv , false )
208
266
} ,
0 commit comments