@@ -13,6 +13,7 @@ const {
13
13
const connectBridge = async ( {
14
14
l1Network,
15
15
l2Network,
16
+ l2ProviderUrl,
16
17
l1DeploymentPath,
17
18
l2DeploymentPath,
18
19
l1PrivateKey,
@@ -21,11 +22,16 @@ const connectBridge = async ({
21
22
l2UseFork,
22
23
l1Messenger,
23
24
l2Messenger,
25
+ dryRun,
26
+ l1GasPrice,
27
+ l2GasPrice,
28
+ gasLimit,
24
29
} ) => {
25
30
console . log ( gray ( '> Connecting with L1 instance...' ) ) ;
26
31
const {
27
32
AddressResolver : AddressResolverL1 ,
28
33
SynthetixBridge : SynthetixBridgeToOptimism ,
34
+ account : accountL1 ,
29
35
} = await connectInstance ( {
30
36
network : l1Network ,
31
37
deploymentPath : l1DeploymentPath ,
@@ -39,46 +45,103 @@ const connectBridge = async ({
39
45
const {
40
46
AddressResolver : AddressResolverL2 ,
41
47
SynthetixBridge : SynthetixBridgeToBase ,
48
+ account : accountL2 ,
42
49
} = await connectInstance ( {
43
50
network : l2Network ,
51
+ providerUrl : l2ProviderUrl ,
44
52
deploymentPath : l2DeploymentPath ,
45
53
privateKey : l2PrivateKey ,
46
54
useFork : l2UseFork ,
47
55
messenger : l2Messenger ,
48
56
useOvm : true ,
49
57
} ) ;
50
58
59
+ let tx ;
60
+ let names ;
61
+ let addresses ;
62
+
51
63
console . log ( gray ( '> Connecting bridge on L1...' ) ) ;
52
- await AddressResolverL1 . importAddresses (
53
- [ toBytes32 ( 'ext:Messenger' ) , toBytes32 ( 'ovm:SynthetixBridgeToBase' ) ] ,
54
- l1Messenger ,
55
- SynthetixBridgeToBase . options . address
56
- ) ;
57
- await SynthetixBridgeToBase . setResolverAndSyncCache ( AddressResolverL1 . options . address ) ;
64
+ names = [ 'ext:Messenger' , 'ovm:SynthetixBridgeToBase' ] ;
65
+ addresses = [ l1Messenger , SynthetixBridgeToBase . options . address ] ;
66
+ console . log ( gray ( names , addresses ) ) ;
67
+ if ( ! dryRun ) {
68
+ const params = {
69
+ from : accountL1 ,
70
+ gasPrice : Web3 . utils . toWei ( l1GasPrice . toString ( ) , 'gwei' ) ,
71
+ gas : gasLimit ,
72
+ } ;
73
+ console . log ( gray ( '> tx params:' , JSON . stringify ( params ) ) ) ;
74
+
75
+ console . log ( 'AddressResolverL1.importAddresses()...' ) ;
76
+ tx = await AddressResolverL1 . methods
77
+ . importAddresses ( names . map ( toBytes32 ) , addresses )
78
+ . send ( params ) ;
79
+ console . log ( JSON . stringify ( tx , null , 2 ) ) ;
80
+
81
+ console . log ( 'SynthetixBridgeToOptimism.setResolverAndSyncCache()...' ) ;
82
+ tx = await SynthetixBridgeToOptimism . methods
83
+ . setResolverAndSyncCache ( AddressResolverL1 . options . address )
84
+ . send ( params ) ;
85
+ console . log ( JSON . stringify ( tx , null , 2 ) ) ;
86
+ }
58
87
59
88
console . log ( gray ( '> Connecting bridge on L2...' ) ) ;
60
- await AddressResolverL2 . importAddresses (
61
- [ toBytes32 ( 'ext:Messenger' ) , toBytes32 ( 'base:SynthetixBridgeToOptimism' ) ] ,
62
- l2Messenger ,
63
- SynthetixBridgeToOptimism . options . address
64
- ) ;
65
- await SynthetixBridgeToOptimism . setResolverAndSyncCache ( AddressResolverL2 . options . address ) ;
89
+ names = [ 'ext:Messenger' , 'base:SynthetixBridgeToOptimism' ] ;
90
+ addresses = [ l2Messenger , SynthetixBridgeToOptimism . options . address ] ;
91
+ console . log ( gray ( names , addresses ) ) ;
92
+ if ( ! dryRun ) {
93
+ const params = {
94
+ from : accountL2 ,
95
+ gasPrice : Web3 . utils . toWei ( l2GasPrice . toString ( ) , 'gwei' ) ,
96
+ gas : gasLimit ,
97
+ } ;
98
+ console . log ( gray ( '> tx params:' , JSON . stringify ( params ) ) ) ;
99
+
100
+ console . log ( 'AddressResolverL2.importAddresses()...' ) ;
101
+ tx = await AddressResolverL2 . methods
102
+ . importAddresses ( names . map ( toBytes32 ) , addresses )
103
+ . send ( params ) ;
104
+ console . log ( JSON . stringify ( tx , null , 2 ) ) ;
105
+
106
+ console . log ( 'SynthetixBridgeToBase.setResolverAndSyncCache()...' ) ;
107
+ tx = await SynthetixBridgeToBase . methods
108
+ . setResolverAndSyncCache ( AddressResolverL2 . options . address )
109
+ . send ( params ) ;
110
+ console . log ( JSON . stringify ( tx , null , 2 ) ) ;
111
+ }
66
112
} ;
67
113
68
- const connectInstance = async ( { network, deploymentPath, privateKey, useFork, useOvm } ) => {
114
+ const connectInstance = async ( {
115
+ network,
116
+ providerUrl : specifiedProviderUrl ,
117
+ deploymentPath,
118
+ privateKey,
119
+ useFork,
120
+ useOvm,
121
+ } ) => {
69
122
console . log ( gray ( ' > network:' , network ) ) ;
70
123
console . log ( gray ( ' > deploymentPath:' , deploymentPath ) ) ;
71
124
console . log ( gray ( ' > privateKey:' , privateKey ) ) ;
72
125
console . log ( gray ( ' > useFork:' , useFork ) ) ;
73
126
console . log ( gray ( ' > useOvm:' , useOvm ) ) ;
74
127
75
- const { web3, getSource, getTarget } = bootstrapConnection ( {
128
+ const { web3, getSource, getTarget, providerUrl } = bootstrapConnection ( {
76
129
network,
130
+ providerUrl : specifiedProviderUrl ,
77
131
deploymentPath,
78
132
privateKey,
79
133
useFork,
80
134
useOvm,
81
135
} ) ;
136
+ console . log ( gray ( ' > provider:' , providerUrl ) ) ;
137
+
138
+ let account ;
139
+ if ( privateKey ) {
140
+ web3 . eth . accounts . wallet . add ( privateKey ) ;
141
+ web3 . eth . defaultAccount = web3 . eth . accounts . wallet [ 0 ] . address ;
142
+ account = web3 . eth . defaultAccount ;
143
+ }
144
+ console . log ( gray ( ' > account:' , account ) ) ;
82
145
83
146
const AddressResolver = getContract ( {
84
147
contract : 'AddressResolver' ,
@@ -102,15 +165,23 @@ const connectInstance = async ({ network, deploymentPath, privateKey, useFork, u
102
165
return {
103
166
AddressResolver,
104
167
SynthetixBridge,
168
+ account,
105
169
} ;
106
170
} ;
107
171
108
- const bootstrapConnection = ( { network, deploymentPath, privateKey, useFork, useOvm } ) => {
172
+ const bootstrapConnection = ( {
173
+ network,
174
+ providerUrl : specifiedProviderUrl ,
175
+ deploymentPath,
176
+ privateKey,
177
+ useFork,
178
+ useOvm,
179
+ } ) => {
109
180
ensureNetwork ( network ) ;
110
181
deploymentPath = deploymentPath || getDeploymentPathForNetwork ( { network, useOvm } ) ;
111
182
ensureDeploymentPath ( deploymentPath ) ;
112
183
113
- const { providerUrl, privateKey : envPrivateKey } = loadConnections ( {
184
+ const { providerUrl : defaultProviderUrl , privateKey : envPrivateKey } = loadConnections ( {
114
185
network,
115
186
useFork,
116
187
} ) ;
@@ -120,6 +191,7 @@ const bootstrapConnection = ({ network, deploymentPath, privateKey, useFork, use
120
191
privateKey = envPrivateKey ;
121
192
}
122
193
194
+ const providerUrl = specifiedProviderUrl || defaultProviderUrl ;
123
195
const web3 = new Web3 ( new Web3 . providers . HttpProvider ( providerUrl ) ) ;
124
196
125
197
const { getUsers, getTarget, getSource } = wrap ( { network, useOvm, fs, path } ) ;
@@ -134,6 +206,7 @@ const bootstrapConnection = ({ network, deploymentPath, privateKey, useFork, use
134
206
135
207
return {
136
208
deploymentPath,
209
+ providerUrl,
137
210
privateKey,
138
211
web3,
139
212
account,
@@ -165,6 +238,7 @@ module.exports = {
165
238
. description ( 'Configures the bridge between an L1-L2 instance pair.' )
166
239
. option ( '--l1-network <value>' , 'The name of the target L1 network' , 'goerli' )
167
240
. option ( '--l2-network <value>' , 'The name of the target L2 network' , 'goerli' )
241
+ . option ( '--l2-provider-url <value>' , 'The L2 provider to use' , 'https://goerli.optimism.io' )
168
242
. option ( '--l1-deployment-path <value>' , 'The path of the L1 deployment to target' )
169
243
. option ( '--l2-deployment-path <value>' , 'The path of the L2 deployment to target' )
170
244
. option ( '--l1-private-key <value>' , 'Optional private key for signing L1 transactions' )
@@ -173,6 +247,10 @@ module.exports = {
173
247
. option ( '--l2-use-fork' , 'Wether to use a fork for the L2 connection' , false )
174
248
. option ( '--l1-messenger <value>' , 'L1 cross domain messenger to use' )
175
249
. option ( '--l2-messenger <value>' , 'L2 cross domain messenger to use' )
250
+ . option ( '-g, --l1-gas-price <value>' , 'Gas price to set when performing transfers in L1' , 1 )
251
+ . option ( '-g, --l2-gas-price <value>' , 'Gas price to set when performing transfers in L2' , 1 )
252
+ . option ( '-l, --gas-limit <value>' , 'Max gas to use when signing transactions' , 8000000 )
253
+ . option ( '--dry-run' , 'Do not execute any transactions' )
176
254
. action ( async ( ...args ) => {
177
255
try {
178
256
await connectBridge ( ...args ) ;
0 commit comments