Skip to content

Commit 5878eee

Browse files
authored
Merge pull request #804 from graphprotocol/pcv/legacy-grt-to-l1
feat(cli): allow bridging legacy GRT to L1
2 parents 92cf084 + 03a75a3 commit 5878eee

File tree

1 file changed

+69
-11
lines changed

1 file changed

+69
-11
lines changed

cli/commands/bridge/to-l1.ts

Lines changed: 69 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import { JsonRpcProvider } from '@ethersproject/providers'
1111
import { providers } from 'ethers'
1212
import { L2GraphToken } from '../../../build/types/L2GraphToken'
1313
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'
1419

1520
const FOURTEEN_DAYS_IN_SECONDS = 24 * 3600 * 14
1621

@@ -78,21 +83,37 @@ export const startSendToL1 = async (cli: CLIEnvironment, cliArgs: CLIArgs): Prom
7883
const l2Wallet = cli.wallet.connect(l2Provider)
7984
const l2AddressBook = getAddressBook(cliArgs.addressBook, l2ChainId.toString())
8085

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+
}
83103

84-
const l1Gateway = cli.contracts['L1GraphTokenGateway']
85104
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}`)
87106

88107
const senderBalance = await l2GRT.balanceOf(cli.wallet.address)
89108
if (senderBalance.lt(amount)) {
90109
throw new Error('Sender balance is insufficient for the transfer')
91110
}
92111

93112
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+
}
96117
logger.info('Sending outbound transfer transaction')
97118
const receipt = await sendTransaction(
98119
l2Wallet,
@@ -135,11 +156,20 @@ export const finishSendToL1 = async (
135156

136157
const l2AddressBook = getAddressBook(cliArgs.addressBook, l2ChainId.toString())
137158

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+
}
143173
let txHash: string
144174
if (cliArgs.txHash) {
145175
txHash = cliArgs.txHash
@@ -193,6 +223,22 @@ export const finishSendToL1 = async (
193223
export const startSendToL1Command = {
194224
command: 'start-send-to-l1 <amount> [recipient]',
195225
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+
},
196242
handler: async (argv: CLIArgs): Promise<void> => {
197243
return startSendToL1(await loadEnv(argv), argv)
198244
},
@@ -203,6 +249,18 @@ export const finishSendToL1Command = {
203249
describe:
204250
'Finish an L2-to-L1 Graph Token transaction. L2 dispute period must have completed. ' +
205251
'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+
},
206264
handler: async (argv: CLIArgs): Promise<void> => {
207265
return finishSendToL1(await loadEnv(argv), argv, false)
208266
},

0 commit comments

Comments
 (0)