Skip to content

Commit d9aafd1

Browse files
authored
Merge pull request #889 from graphprotocol/mde/update-bridge-config
fix: add gns and staking counter part addresses when configuring bridge
2 parents 215db2b + 68069c2 commit d9aafd1

File tree

8 files changed

+203
-7
lines changed

8 files changed

+203
-7
lines changed

packages/contracts/cli/commands/protocol/configure-bridge.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,20 @@ export const configureL1Bridge = async (cli: CLIEnvironment, cliArgs: CLIArgs):
1515
const l2AddressBook = getAddressBook(cliArgs.addressBook, l2ChainId)
1616
const arbAddressBook = getAddressBook(cliArgs.arbAddressBook, cli.chainId.toString())
1717

18+
// Gateway
1819
const gateway = cli.contracts['L1GraphTokenGateway']
1920

2021
const l2GRT = l2AddressBook.getEntry('L2GraphToken')
2122
logger.info('L2 GRT address: ' + l2GRT.address)
2223
await sendTransaction(cli.wallet, gateway, 'setL2TokenAddress', [l2GRT.address])
2324

24-
const l2Counterpart = l2AddressBook.getEntry('L2GraphTokenGateway')
25-
logger.info('L2 Gateway address: ' + l2Counterpart.address)
26-
await sendTransaction(cli.wallet, gateway, 'setL2CounterpartAddress', [l2Counterpart.address])
25+
const l2GatewayCounterpart = l2AddressBook.getEntry('L2GraphTokenGateway')
26+
logger.info('L2 Gateway address: ' + l2GatewayCounterpart.address)
27+
await sendTransaction(cli.wallet, gateway, 'setL2CounterpartAddress', [
28+
l2GatewayCounterpart.address,
29+
])
2730

31+
// Escrow
2832
const bridgeEscrow = cli.contracts.BridgeEscrow
2933
logger.info('Escrow address: ' + bridgeEscrow.address)
3034
await sendTransaction(cli.wallet, gateway, 'setEscrowAddress', [bridgeEscrow.address])
@@ -39,6 +43,22 @@ export const configureL1Bridge = async (cli: CLIEnvironment, cliArgs: CLIArgs):
3943
l1Inbox.address,
4044
l1Router.address,
4145
])
46+
47+
// GNS
48+
const gns = cli.contracts.L1GNS
49+
const l2GNSCounterpart = l2AddressBook.getEntry('L2GNS')
50+
logger.info('L2 GNS address: ' + l2GNSCounterpart.address)
51+
await sendTransaction(cli.wallet, gns, 'setCounterpartGNSAddress', [l2GNSCounterpart.address])
52+
await sendTransaction(cli.wallet, gateway, 'addToCallhookAllowlist', [gns.address])
53+
54+
// Staking
55+
const staking = cli.contracts.L1Staking
56+
const l2StakingCounterpart = l2AddressBook.getEntry('L2Staking')
57+
logger.info('L2 Staking address: ' + l2StakingCounterpart.address)
58+
await sendTransaction(cli.wallet, staking, 'setCounterpartStakingAddress', [
59+
l2StakingCounterpart.address,
60+
])
61+
await sendTransaction(cli.wallet, gateway, 'addToCallhookAllowlist', [staking.address])
4262
}
4363

4464
export const configureL2Bridge = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
@@ -52,6 +72,7 @@ export const configureL2Bridge = async (cli: CLIEnvironment, cliArgs: CLIArgs):
5272
const l1AddressBook = getAddressBook(cliArgs.addressBook, l1ChainId)
5373
const arbAddressBook = getAddressBook(cliArgs.arbAddressBook, cli.chainId.toString())
5474

75+
// Gateway
5576
const gateway = cli.contracts['L2GraphTokenGateway']
5677
const token = cli.contracts['L2GraphToken']
5778

@@ -70,6 +91,20 @@ export const configureL2Bridge = async (cli: CLIEnvironment, cliArgs: CLIArgs):
7091

7192
logger.info('L2 Gateway address: ' + gateway.address)
7293
await sendTransaction(cli.wallet, token, 'setGateway', [gateway.address])
94+
95+
// GNS
96+
const gns = cli.contracts.L2GNS
97+
const l1GNSCounterpart = l1AddressBook.getEntry('L1GNS')
98+
logger.info('L1 GNS address: ' + l1GNSCounterpart.address)
99+
await sendTransaction(cli.wallet, gns, 'setCounterpartGNSAddress', [l1GNSCounterpart.address])
100+
101+
// Staking
102+
const staking = cli.contracts.L2Staking
103+
const l1StakingCounterpart = l1AddressBook.getEntry('L1Staking')
104+
logger.info('L1 Staking address: ' + l1StakingCounterpart.address)
105+
await sendTransaction(cli.wallet, staking, 'setCounterpartStakingAddress', [
106+
l1StakingCounterpart.address,
107+
])
73108
}
74109

75110
export const configureL1BridgeCommand = {

packages/contracts/e2e/deployment/config/l1/graphToken.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isGraphChainId } from '@graphprotocol/sdk'
1+
import { isGraphL2ChainId } from '@graphprotocol/sdk'
22
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
33
import { expect } from 'chai'
44
import hre from 'hardhat'
@@ -10,7 +10,7 @@ describe('[L1] GraphToken', () => {
1010
let unauthorized: SignerWithAddress
1111

1212
before(async function () {
13-
if (isGraphChainId(graph.chainId)) this.skip()
13+
if (isGraphL2ChainId(graph.chainId)) this.skip()
1414
unauthorized = (await graph.getTestAccounts())[0]
1515
})
1616

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { expect } from 'chai'
3+
import hre from 'hardhat'
4+
import { isGraphL2ChainId } from '@graphprotocol/sdk'
5+
6+
describe('[L1] GNS', () => {
7+
const graph = hre.graph()
8+
const { L1GNS, L1GraphTokenGateway } = graph.contracts
9+
10+
let unauthorized: SignerWithAddress
11+
12+
before(async function () {
13+
if (isGraphL2ChainId(graph.chainId)) this.skip()
14+
unauthorized = (await graph.getTestAccounts())[0]
15+
})
16+
17+
describe('L1GNS', () => {
18+
it('counterpartGNSAddress should match the L2GNS address', async () => {
19+
const l2GNS = await L1GNS.counterpartGNSAddress()
20+
expect(l2GNS).eq(graph.l2.contracts.L2GNS.address)
21+
})
22+
23+
it('should be added to callhookAllowlist', async () => {
24+
const isAllowed = await L1GraphTokenGateway.callhookAllowlist(L1GNS.address)
25+
expect(isAllowed).true
26+
})
27+
})
28+
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { expect } from 'chai'
3+
import hre from 'hardhat'
4+
import { isGraphL2ChainId } from '@graphprotocol/sdk'
5+
6+
describe('[L1] Staking', () => {
7+
const graph = hre.graph()
8+
const { L1Staking, L1GraphTokenGateway } = graph.contracts
9+
10+
let unauthorized: SignerWithAddress
11+
12+
before(async function () {
13+
if (isGraphL2ChainId(graph.chainId)) this.skip()
14+
unauthorized = (await graph.getTestAccounts())[0]
15+
})
16+
17+
describe('L1Staking', () => {
18+
it('counterpartStakingAddress should match the L2Staking address', async () => {
19+
// counterpartStakingAddress is internal so we access the storage directly
20+
const l2StakingData = await hre.ethers.provider.getStorageAt(L1Staking.address, 24)
21+
const l2Staking = hre.ethers.utils.defaultAbiCoder.decode(['address'], l2StakingData)[0]
22+
expect(l2Staking).eq(graph.l2.contracts.L2Staking.address)
23+
})
24+
25+
it('should be added to callhookAllowlist', async () => {
26+
const isAllowed = await L1GraphTokenGateway.callhookAllowlist(L1Staking.address)
27+
expect(isAllowed).true
28+
})
29+
})
30+
})
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { expect } from 'chai'
3+
import hre from 'hardhat'
4+
import { isGraphL1ChainId } from '@graphprotocol/sdk'
5+
6+
describe('[L2] GNS', () => {
7+
const graph = hre.graph()
8+
const { L2GNS } = graph.l2.contracts
9+
10+
let unauthorized: SignerWithAddress
11+
12+
before(async function () {
13+
if (isGraphL1ChainId(graph.chainId)) this.skip()
14+
unauthorized = (await graph.getTestAccounts())[0]
15+
})
16+
17+
describe('L2GNS', () => {
18+
it('counterpartGNSAddress should match the L1GNS address', async () => {
19+
const l1GNS = await L2GNS.counterpartGNSAddress()
20+
expect(l1GNS).eq(graph.l1.contracts.L1GNS.address)
21+
})
22+
})
23+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { expect } from 'chai'
3+
import hre from 'hardhat'
4+
import { isGraphL1ChainId } from '@graphprotocol/sdk'
5+
6+
describe('[L2] Staking', () => {
7+
const graph = hre.graph()
8+
const { L2Staking } = graph.l2.contracts
9+
10+
let unauthorized: SignerWithAddress
11+
12+
before(async function () {
13+
if (isGraphL1ChainId(graph.chainId)) this.skip()
14+
unauthorized = (await graph.getTestAccounts())[0]
15+
})
16+
17+
describe('L2Staking', () => {
18+
it('counterpartStakingAddress should match the L1Staking address', async () => {
19+
// counterpartStakingAddress is internal so we access the storage directly
20+
const l1StakingData = await hre.ethers.provider.getStorageAt(L2Staking.address, 24)
21+
const l1Staking = hre.ethers.utils.defaultAbiCoder.decode(['address'], l1StakingData)[0]
22+
expect(l1Staking).eq(graph.l1.contracts.L1Staking.address)
23+
})
24+
})
25+
})

packages/contracts/tasks/bridge/configure.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ task(TASK_BRIDGE_CONFIGURE_L1, 'Configure L1 bridge')
3232
await configureL1Bridge(graph.contracts, governor, {
3333
l2GRTAddress: graph.l2.contracts.GraphToken.address,
3434
l2GRTGatewayAddress: graph.l2.contracts.L2GraphTokenGateway.address,
35+
l2GNSAddress: graph.l2.contracts.L2GNS.address,
36+
l2StakingAddress: graph.l2.contracts.L2Staking.address,
3537
arbAddressBookPath: taskArgs.arbitrumAddressBook,
3638
chainId: graph.chainId,
3739
})
@@ -60,6 +62,8 @@ task(TASK_BRIDGE_CONFIGURE_L2, 'Configure L2 bridge')
6062
await configureL2Bridge(graph.contracts, governor, {
6163
l1GRTAddress: graph.l1.contracts.GraphToken.address,
6264
l1GRTGatewayAddress: graph.l1.contracts.L1GraphTokenGateway.address,
65+
l1GNSAddress: graph.l1.contracts.L1GNS.address,
66+
l1StakingAddress: graph.l1.contracts.L1Staking.address,
6367
arbAddressBookPath: taskArgs.arbitrumAddressBook,
6468
chainId: graph.chainId,
6569
})

packages/sdk/src/deployments/network/actions/bridge-config.ts

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { SimpleAddressBook } from '../../lib/address-book'
66
export const configureL1Bridge: GraphNetworkAction<{
77
l2GRTAddress: string
88
l2GRTGatewayAddress: string
9+
l2GNSAddress: string
10+
l2StakingAddress: string
911
arbAddressBookPath: string
1012
chainId: number
1113
}> = async (
@@ -14,23 +16,34 @@ export const configureL1Bridge: GraphNetworkAction<{
1416
args: {
1517
l2GRTAddress: string
1618
l2GRTGatewayAddress: string
19+
l2GNSAddress: string
20+
l2StakingAddress: string
1721
arbAddressBookPath: string
1822
chainId: number
1923
},
2024
): Promise<void> => {
21-
const { l2GRTAddress, l2GRTGatewayAddress, arbAddressBookPath, chainId } = args
25+
const {
26+
l2GRTAddress,
27+
l2GRTGatewayAddress,
28+
l2GNSAddress,
29+
l2StakingAddress,
30+
arbAddressBookPath,
31+
chainId,
32+
} = args
2233
console.info(`>>> Setting L1 Bridge Configuration <<<\n`)
2334

2435
const arbAddressBook = new SimpleAddressBook(arbAddressBookPath, chainId)
2536

2637
const gateway = contracts.L1GraphTokenGateway!
2738

39+
// Gateway
2840
console.info('L2 GRT address: ' + l2GRTAddress)
2941
await gateway.connect(signer).setL2TokenAddress(l2GRTAddress)
3042

3143
console.info('L2 Gateway address: ' + l2GRTGatewayAddress)
3244
await gateway.connect(signer).setL2CounterpartAddress(l2GRTGatewayAddress)
3345

46+
// Escrow
3447
const bridgeEscrow = contracts.BridgeEscrow!
3548
console.info('Escrow address: ' + bridgeEscrow.address)
3649
await gateway.connect(signer).setEscrowAddress(bridgeEscrow.address)
@@ -42,11 +55,27 @@ export const configureL1Bridge: GraphNetworkAction<{
4255
'L1 Inbox address: ' + l1Inbox.address + ' and L1 Router address: ' + l1Router.address,
4356
)
4457
await gateway.connect(signer).setArbitrumAddresses(l1Inbox.address, l1Router.address)
58+
59+
// GNS
60+
const gns = contracts.L1GNS!
61+
console.info('GNS address: ' + gns.address)
62+
console.info('L2 GNS address: ' + l2GNSAddress)
63+
await gns.connect(signer).setCounterpartGNSAddress(l2GNSAddress)
64+
await gateway.connect(signer).addToCallhookAllowlist(gns.address)
65+
66+
// Staking
67+
const staking = contracts.L1Staking!
68+
console.info('Staking address: ' + staking.address)
69+
console.info('L2 Staking address: ' + l2StakingAddress)
70+
await staking.connect(signer).setCounterpartStakingAddress(l2StakingAddress)
71+
await gateway.connect(signer).addToCallhookAllowlist(staking.address)
4572
}
4673

4774
export const configureL2Bridge: GraphNetworkAction<{
4875
l1GRTAddress: string
4976
l1GRTGatewayAddress: string
77+
l1GNSAddress: string
78+
l1StakingAddress: string
5079
arbAddressBookPath: string
5180
chainId: number
5281
}> = async (
@@ -55,18 +84,28 @@ export const configureL2Bridge: GraphNetworkAction<{
5584
args: {
5685
l1GRTAddress: string
5786
l1GRTGatewayAddress: string
87+
l1GNSAddress: string
88+
l1StakingAddress: string
5889
arbAddressBookPath: string
5990
chainId: number
6091
},
6192
): Promise<void> => {
62-
const { l1GRTAddress, l1GRTGatewayAddress, arbAddressBookPath, chainId } = args
93+
const {
94+
l1GRTAddress,
95+
l1GRTGatewayAddress,
96+
l1GNSAddress,
97+
l1StakingAddress,
98+
arbAddressBookPath,
99+
chainId,
100+
} = args
63101
console.info(`>>> Setting L2 Bridge Configuration <<<\n`)
64102

65103
const arbAddressBook = new SimpleAddressBook(arbAddressBookPath, chainId)
66104

67105
const gateway = contracts.L2GraphTokenGateway!
68106
const token = contracts.L2GraphToken!
69107

108+
// Gateway
70109
console.info('L1 GRT address: ' + l1GRTAddress)
71110
await gateway.connect(signer).setL1TokenAddress(l1GRTAddress)
72111
await token.connect(signer).setL1Address(l1GRTAddress)
@@ -80,4 +119,16 @@ export const configureL2Bridge: GraphNetworkAction<{
80119

81120
console.info('L2 Gateway address: ' + gateway.address)
82121
await token.connect(signer).setGateway(gateway.address)
122+
123+
// GNS
124+
const gns = contracts.L2GNS!
125+
console.info('GNS address: ' + gns.address)
126+
console.info('L1 GNS address: ' + l1GNSAddress)
127+
await gns.connect(signer).setCounterpartGNSAddress(l1GNSAddress)
128+
129+
// Staking
130+
const staking = contracts.L2Staking!
131+
console.info('Staking address: ' + staking.address)
132+
console.info('L1 Staking address: ' + l1StakingAddress)
133+
await staking.connect(signer).setCounterpartStakingAddress(l1StakingAddress)
83134
}

0 commit comments

Comments
 (0)