-
Notifications
You must be signed in to change notification settings - Fork 23
/
deployers.go
417 lines (355 loc) · 17.8 KB
/
deployers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
package testutil
import (
"context"
"fmt"
"github.com/synapsecns/sanguine/agents/contracts/bondingmanager"
"github.com/synapsecns/sanguine/agents/contracts/gasoracle"
"github.com/synapsecns/sanguine/agents/contracts/inbox"
"github.com/synapsecns/sanguine/agents/contracts/lightinbox"
"github.com/synapsecns/sanguine/agents/contracts/lightmanager"
"github.com/synapsecns/sanguine/ethergo/contracts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/synapsecns/sanguine/agents/contracts/destination"
"github.com/synapsecns/sanguine/agents/contracts/origin"
"github.com/synapsecns/sanguine/agents/contracts/summit"
"github.com/synapsecns/sanguine/ethergo/backends"
"github.com/synapsecns/sanguine/ethergo/deployer"
)
// SynChainID the id of the SynChain.
// TODO: no longer needs to be hardcoded: https://github.com/synapsecns/sanguine/pull/1280#discussion_r1320882617
const SynChainID uint = 10
// LightInboxDeployer deploys the light inbox contract.
type LightInboxDeployer struct {
*deployer.BaseDeployer
}
// NewLightInboxDeployer deploys the light inbox contract.
func NewLightInboxDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return LightInboxDeployer{deployer.NewSimpleDeployer(registry, backend, LightInboxType)}
}
// Deploy deploys the light manager contract.
//
//nolint:dupword,dupl,cyclop
func (d LightInboxDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
/*originContract := d.Registry().Get(ctx, OriginType)
destinationContract := d.Registry().Get(ctx, DestinationType)
originAddress := originContract.Address()
destinationAddress := destinationContract.Address()*/
return d.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (address common.Address, tx *types.Transaction, data interface{}, err error) {
if d.Backend().GetChainID() == SynChainID {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s on synchain", d.ContractType().ContractName())
}
// deploy the light inbox contract
var rawHandle *lightinbox.LightInbox
address, tx, rawHandle, err = lightinbox.DeployLightInbox(transactOps, backend, SynapseChainID)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s: %w", d.ContractType().ContractName(), err)
}
d.Backend().WaitForConfirmation(ctx, tx)
// initialize the origin contract
/*initializationTx, err := rawHandle.Initialize(transactOps, originAddress, destinationAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize contract: %w", err)
}
d.Backend().WaitForConfirmation(ctx, initializationTx)*/
return address, tx, rawHandle, err
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return lightinbox.NewLightInboxRef(address, backend)
})
}
// Dependencies gets a list of dependencies used to deploy the light inbox contract.
func (d LightInboxDeployer) Dependencies() []contracts.ContractType {
return []contracts.ContractType{}
}
// LightManagerDeployer deploys the light manager contract.
type LightManagerDeployer struct {
*deployer.BaseDeployer
}
// NewLightManagerDeployer deploys the light manager contract.
func NewLightManagerDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return LightManagerDeployer{deployer.NewSimpleDeployer(registry, backend, LightManagerType)}
}
// Deploy deploys the light manager contract.
//
//nolint:dupword,dupl,cyclop
func (d LightManagerDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
/*originContract := d.Registry().Get(ctx, OriginType)
destinationContract := d.Registry().Get(ctx, DestinationType)
originAddress := originContract.Address()
destinationAddress := destinationContract.Address()*/
return d.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (address common.Address, tx *types.Transaction, data interface{}, err error) {
if d.Backend().GetChainID() == SynChainID {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s on synchain", d.ContractType().ContractName())
}
// deploy the light manager contract
var rawHandle *lightmanager.LightManager
address, tx, rawHandle, err = lightmanager.DeployLightManager(transactOps, backend, SynapseChainID)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s: %w", d.ContractType().ContractName(), err)
}
d.Backend().WaitForConfirmation(ctx, tx)
// initialize the origin contract
/*initializationTx, err := rawHandle.Initialize(transactOps, originAddress, destinationAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize contract: %w", err)
}
d.Backend().WaitForConfirmation(ctx, initializationTx)*/
return address, tx, rawHandle, err
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return lightmanager.NewLightManagerRef(address, backend)
})
}
// Dependencies gets a list of dependencies used to deploy the light manager contract.
func (d LightManagerDeployer) Dependencies() []contracts.ContractType {
return []contracts.ContractType{}
}
// InboxDeployer deploys the inbox contract.
type InboxDeployer struct {
*deployer.BaseDeployer
}
// NewInboxDeployer deploys the inbox contract.
func NewInboxDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return InboxDeployer{deployer.NewSimpleDeployer(registry, backend, InboxType)}
}
// Deploy deploys the inbox contract.
// nolint:dupl,cyclop,dupword
func (d InboxDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
/*originContract := d.Registry().Get(ctx, OriginType)
destinationContract := d.Registry().Get(ctx, DestinationType)
originAddress := originContract.Address()
destinationAddress := destinationContract.Address()*/
return d.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (address common.Address, tx *types.Transaction, data interface{}, err error) {
if d.Backend().GetChainID() != SynChainID {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s on non-synchain", d.ContractType().ContractName())
}
// deploy the inbox contract
var rawHandle *inbox.Inbox
address, tx, rawHandle, err = inbox.DeployInbox(transactOps, backend, SynapseChainID)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s: %w", d.ContractType().ContractName(), err)
}
d.Backend().WaitForConfirmation(ctx, tx)
// initialize the origin contract
/*initializationTx, err := rawHandle.Initialize(transactOps, originAddress, destinationAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize contract: %w", err)
}
d.Backend().WaitForConfirmation(ctx, initializationTx)*/
return address, tx, rawHandle, err
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return inbox.NewInboxRef(address, backend)
})
}
// Dependencies gets a list of dependencies used to deploy the inbox contract.
func (d InboxDeployer) Dependencies() []contracts.ContractType {
return []contracts.ContractType{}
}
// BondingManagerDeployer deploys the bonding manager contract.
type BondingManagerDeployer struct {
*deployer.BaseDeployer
}
// NewBondingManagerDeployer deploys the bonding manager contract.
func NewBondingManagerDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return BondingManagerDeployer{deployer.NewSimpleDeployer(registry, backend, BondingManagerType)}
}
// Deploy deploys the bonding manager contract.
// nolint:dupl,cyclop,dupword
func (d BondingManagerDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
/*originContract := d.Registry().Get(ctx, OriginType)
destinationContract := d.Registry().Get(ctx, DestinationType)
originAddress := originContract.Address()
destinationAddress := destinationContract.Address()*/
return d.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (address common.Address, tx *types.Transaction, data interface{}, err error) {
if d.Backend().GetChainID() != SynChainID {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s on a chain that is not synchain", d.ContractType().ContractName())
}
// deploy the bonding manager contract
var rawHandle *bondingmanager.BondingManager
address, tx, rawHandle, err = bondingmanager.DeployBondingManager(transactOps, backend, SynapseChainID)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s: %w", d.ContractType().ContractName(), err)
}
d.Backend().WaitForConfirmation(ctx, tx)
// initialize the origin contract
/*initializationTx, err := rawHandle.Initialize(transactOps, originAddress, destinationAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize contract: %w", err)
}
d.Backend().WaitForConfirmation(ctx, initializationTx)*/
return address, tx, rawHandle, err
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return bondingmanager.NewBondingManagerRef(address, backend)
})
}
// Dependencies gets a list of dependencies used to deploy the bonding manager contract.
func (d BondingManagerDeployer) Dependencies() []contracts.ContractType {
return []contracts.ContractType{}
}
// GasOracleDeployer deploys the gas oracle contract.
type GasOracleDeployer struct {
*deployer.BaseDeployer
}
// NewGasOracleDeployer deploys the gas oracle contract.
func NewGasOracleDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return GasOracleDeployer{deployer.NewSimpleDeployer(registry, backend, GasOracleType)}
}
// Deploy deploys the gas oracle contract.
// nolint:dupl,cyclop,dupword
func (d GasOracleDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
/*originContract := d.Registry().Get(ctx, OriginType)
originAddress := originContract.Address()*/
destinationContract := d.Registry().Get(ctx, DestinationType)
destinationAddress := destinationContract.Address()
return d.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (address common.Address, tx *types.Transaction, data interface{}, err error) {
// deploy the bonding manager contract
var rawHandle *gasoracle.GasOracle
address, tx, rawHandle, err = gasoracle.DeployGasOracle(transactOps, backend, SynapseChainID, destinationAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s: %w", d.ContractType().ContractName(), err)
}
d.Backend().WaitForConfirmation(ctx, tx)
// initialize the origin contract
/*initializationTx, err := rawHandle.Initialize(transactOps, originAddress, destinationAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize contract: %w", err)
}
d.Backend().WaitForConfirmation(ctx, initializationTx)*/
return address, tx, rawHandle, err
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return gasoracle.NewGasOracleRef(address, backend)
})
}
// Dependencies gets a list of dependencies used to deploy the gas oracle contract.
func (d GasOracleDeployer) Dependencies() []contracts.ContractType {
return []contracts.ContractType{}
}
// OriginDeployer deploys the origin contract.
type OriginDeployer struct {
*deployer.BaseDeployer
}
// NewOriginDeployer deploys the origin contract.
func NewOriginDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return OriginDeployer{deployer.NewSimpleDeployer(registry, backend, OriginType)}
}
// Deploy deploys the origin contract.
// nolint:dupl,cyclop
func (d OriginDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
var agentAddress common.Address
var inboxAddress common.Address
if d.Backend().GetChainID() == SynChainID {
bondingManagerContract := d.Registry().Get(ctx, BondingManagerType)
agentAddress = bondingManagerContract.Address()
inboxContract := d.Registry().Get(ctx, InboxType)
inboxAddress = inboxContract.Address()
} else {
lightManagerContract := d.Registry().Get(ctx, LightManagerType)
agentAddress = lightManagerContract.Address()
lightInboxContract := d.Registry().Get(ctx, LightInboxType)
inboxAddress = lightInboxContract.Address()
}
gasOracleContract := d.Registry().Get(ctx, GasOracleType)
gasOracleAddress := gasOracleContract.Address()
return d.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (address common.Address, tx *types.Transaction, data interface{}, err error) {
// deploy the origin contract
var rawHandle *origin.Origin
address, tx, rawHandle, err = origin.DeployOrigin(transactOps, backend, SynapseChainID, agentAddress, inboxAddress, gasOracleAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s: %w", d.ContractType().ContractName(), err)
}
d.Backend().WaitForConfirmation(ctx, tx)
// initialize the origin contract
initializationTx, err := rawHandle.Initialize(transactOps)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize contract: %w", err)
}
d.Backend().WaitForConfirmation(ctx, initializationTx)
return address, tx, rawHandle, err
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return origin.NewOriginRef(address, backend)
})
}
// Dependencies gets a list of dependencies used to deploy the origin contract.
func (d OriginDeployer) Dependencies() []contracts.ContractType {
return []contracts.ContractType{}
}
// SummitDeployer deploys the summit.
type SummitDeployer struct {
*deployer.BaseDeployer
}
// NewSummitDeployer creates the deployer for the summit.
func NewSummitDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return SummitDeployer{deployer.NewSimpleDeployer(registry, backend, SummitType)}
}
// Deploy deploys the summit.
//
//nolint:dupword,dupl,cyclop
func (a SummitDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
bondingManagerContract := a.Registry().Get(ctx, BondingManagerType)
bondingManagerAddress := bondingManagerContract.Address()
inboxContract := a.Registry().Get(ctx, InboxType)
inboxAddress := inboxContract.Address()
return a.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, interface{}, error) {
if a.Backend().GetChainID() != SynChainID {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy %s on nonsynchain", a.ContractType().ContractName())
}
summitAddress, summitTx, summit, err := summit.DeploySummit(transactOps, backend, uint32(a.Backend().GetChainID()), bondingManagerAddress, inboxAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy summit: %w", err)
}
auth := a.Backend().GetTxContext(ctx, &transactOps.From)
initTx, err := summit.Initialize(auth.TransactOpts)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize attestation collector: %w", err)
}
a.Backend().WaitForConfirmation(ctx, initTx)
return summitAddress, summitTx, summit, nil
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return summit.NewSummitRef(address, backend)
})
}
// DestinationDeployer deploys the destination.
type DestinationDeployer struct {
*deployer.BaseDeployer
}
// NewDestinationDeployer creates the deployer for the destination.
func NewDestinationDeployer(registry deployer.GetOnlyContractRegistry, backend backends.SimulatedTestBackend) deployer.ContractDeployer {
return DestinationDeployer{deployer.NewSimpleDeployer(registry, backend, DestinationType)}
}
// Deploy deploys the destination.
//
//nolint:dupl,dupword
func (d DestinationDeployer) Deploy(ctx context.Context) (contracts.DeployedContract, error) {
var agentManagerAddress common.Address
var inboxAddress common.Address
if d.Backend().GetChainID() == 10 {
bondingManagerContract := d.Registry().Get(ctx, BondingManagerType)
agentManagerAddress = bondingManagerContract.Address()
inboxContract := d.Registry().Get(ctx, InboxType)
inboxAddress = inboxContract.Address()
} else {
lightManagerContract := d.Registry().Get(ctx, LightManagerType)
agentManagerAddress = lightManagerContract.Address()
lightInboxContract := d.Registry().Get(ctx, LightInboxType)
inboxAddress = lightInboxContract.Address()
}
return d.DeploySimpleContract(ctx, func(transactOps *bind.TransactOpts, backend bind.ContractBackend) (common.Address, *types.Transaction, interface{}, error) {
destinationAddress, destinationTx, destination, err := destination.DeployDestination(transactOps, backend, SynapseChainID, agentManagerAddress, inboxAddress)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not deploy destination: %w", err)
}
/*auth := d.Backend().GetTxContext(ctx, &transactOps.From)
initTx, err := destination.Initialize(auth.TransactOpts)
if err != nil {
return common.Address{}, nil, nil, fmt.Errorf("could not initialize destination: %w", err)
}
d.Backend().WaitForConfirmation(ctx, initTx)*/
return destinationAddress, destinationTx, destination, nil
}, func(address common.Address, backend bind.ContractBackend) (interface{}, error) {
return destination.NewDestinationRef(address, backend)
})
}
// Dependencies gets a list of dependencies used to deploy the destination contract.
func (d DestinationDeployer) Dependencies() []contracts.ContractType {
return []contracts.ContractType{OriginType}
}