-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfactory.go
More file actions
374 lines (330 loc) · 14.7 KB
/
Copy pathfactory.go
File metadata and controls
374 lines (330 loc) · 14.7 KB
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
package factory
import (
"bytes"
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/smartcontractkit/chainlink-deployments-framework/deployment"
"github.com/smartcontractkit/go-daml/pkg/bind"
"github.com/smartcontractkit/go-daml/pkg/types"
"github.com/smartcontractkit/chainlink-canton/bindings/generated/latest/ccip/core"
factorybindings "github.com/smartcontractkit/chainlink-canton/bindings/generated/latest/ccip/factory"
"github.com/smartcontractkit/chainlink-canton/contracts"
"github.com/smartcontractkit/chainlink-canton/deployment/utils/operations/contract"
)
var ContractType = deployment.ContractType("CCIPFactory")
var Version = semver.MustParse("2.0.0")
var factoryEncoder = factorybindings.NewContract("", "CCIP.Factory", "CCIPFactory").Encoder()
var Deploy = contract.NewDeploy(contract.DeployParams[factorybindings.CCIPFactory]{
Name: "canton/ccip/factory/deploy",
TypeAndVersion: deployment.NewTypeAndVersion(ContractType, *Version),
Description: "Deploys a CCIPFactory contract on Canton",
Validate: func(template factorybindings.CCIPFactory) error {
if template.Owner == "" {
return errors.New("owner cannot be empty")
}
if template.McmsParty == "" {
return errors.New("mcmsParty cannot be empty")
}
return nil
},
PackageName: string(contracts.CCIPFactory),
Prefix: "factory",
})
var DeployRMNRemote = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployRMNRemote]{
Name: "canton/ccip/factory/deploy_rmn_remote",
Version: Version,
Description: "Deploys an RMNRemote through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployRMNRemote,
EncodeMethod: encodeDeployRMNRemote,
})
var DeployGlobalConfig = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployGlobalConfig]{
Name: "canton/ccip/factory/deploy_global_config",
Version: Version,
Description: "Deploys a GlobalConfig through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployGlobalConfig,
EncodeMethod: encodeDeployGlobalConfig,
})
var DeployTokenAdminRegistry = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployTokenAdminRegistry]{
Name: "canton/ccip/factory/deploy_token_admin_registry",
Version: Version,
Description: "Deploys a TokenAdminRegistry through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployTokenAdminRegistry,
EncodeMethod: encodeDeployTokenAdminRegistry,
})
var DeployFeeQuoter = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployFeeQuoter]{
Name: "canton/ccip/factory/deploy_fee_quoter",
Version: Version,
Description: "Deploys a FeeQuoter through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployFeeQuoter,
EncodeMethod: encodeDeployFeeQuoter,
})
var DeployLinkToken = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployLinkToken]{
Name: "canton/ccip/factory/deploy_link_token",
Version: Version,
Description: "Deploys a LinkRegistry token through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployLinkToken,
EncodeMethod: encodeDeployLinkToken,
})
var DeployCommitteeVerifier = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployCommitteeVerifier]{
Name: "canton/ccip/factory/deploy_committee_verifier",
Version: Version,
Description: "Deploys a CommitteeVerifier through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployCommitteeVerifier,
EncodeMethod: encodeDeployCommitteeVerifier,
})
var DeployOffRamp = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployOffRamp]{
Name: "canton/ccip/factory/deploy_offramp",
Version: Version,
Description: "Deploys an OffRamp through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployOffRamp,
EncodeMethod: encodeDeployOffRamp,
})
var DeployOnRamp = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployOnRamp]{
Name: "canton/ccip/factory/deploy_onramp",
Version: Version,
Description: "Deploys an OnRamp through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployOnRamp,
EncodeMethod: encodeDeployOnRamp,
})
var DeployPerPartyRouterFactory = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployPerPartyRouterFactory]{
Name: "canton/ccip/factory/deploy_per_party_router_factory",
Version: Version,
Description: "Deploys a PerPartyRouterFactory through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployPerPartyRouterFactory,
EncodeMethod: encodeDeployPerPartyRouterFactory,
})
var SetOwnerToMCMS = contract.NewExercise(contract.ExerciseParams[factorybindings.SetOwnerToMCMS]{
Name: "canton/ccip/factory/set_owner_to_mcms",
Version: Version,
Description: "Transfers CCIPFactory ownership to mcmsParty (SetOwnerToMCMS)",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.SetOwnerToMCMS,
EncodeMethod: factoryEncoder.SetOwnerToMCMS,
})
var DeployExecutor = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployExecutor]{
Name: "canton/ccip/factory/deploy_executor",
Version: Version,
Description: "Deploys an Executor through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployExecutor,
EncodeMethod: encodeDeployExecutor,
})
var DeployLockReleaseTokenPool = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployLockReleaseTokenPool]{
Name: "canton/ccip/factory/deploy_lock_release_token_pool",
Version: Version,
Description: "Deploys a LockReleaseTokenPool through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployLockReleaseTokenPool,
EncodeMethod: encodeDeployLockReleaseTokenPool,
})
var DeployBurnMintTokenPool = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployBurnMintTokenPool]{
Name: "canton/ccip/factory/deploy_burn_mint_token_pool",
Version: Version,
Description: "Deploys a BurnMintTokenPool through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployBurnMintTokenPool,
EncodeMethod: encodeDeployBurnMintTokenPool,
})
var DeployRateLimiter = contract.NewExercise(contract.ExerciseParams[factorybindings.DeployRateLimiter]{
Name: "canton/ccip/factory/deploy_rate_limiter",
Version: Version,
Description: "Deploys a token pool rate limiter through the CCIPFactory",
ContractType: ContractType,
Template: factorybindings.CCIPFactory{},
Method: factorybindings.CCIPFactory{}.DeployRateLimiter,
EncodeMethod: encodeDeployRateLimiter,
})
func encodeDeployRMNRemote(args factorybindings.DeployRMNRemote) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployRMNRemoteParams(factorybindings.DeployRMNRemoteParams{
InstanceId: args.Contract.InstanceId,
RmnOwner: args.Contract.RmnOwner,
CcipOwner: args.Contract.CcipOwner,
CustomObservers: args.Contract.CustomObservers,
CursedSubjects: args.Contract.CursedSubjects,
})
}
func encodeDeployGlobalConfig(args factorybindings.DeployGlobalConfig) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployGlobalConfigParams(factorybindings.DeployGlobalConfigParams{
InstanceId: args.Contract.InstanceId,
ChainSelector: args.Contract.ChainSelector,
})
}
func encodeDeployTokenAdminRegistry(args factorybindings.DeployTokenAdminRegistry) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployTokenAdminRegistryParams(factorybindings.DeployTokenAdminRegistryParams{
InstanceId: args.Contract.InstanceId,
})
}
func encodeDeployFeeQuoter(args factorybindings.DeployFeeQuoter) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployFeeQuoterParams(factorybindings.DeployFeeQuoterParams{
InstanceId: args.Contract.InstanceId,
LinkTokenInstrumentId: args.Contract.LinkTokenInstrumentId,
})
}
func encodeDeployLinkToken(args factorybindings.DeployLinkToken) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployLinkTokenParams(factorybindings.DeployLinkTokenParams{
InstanceId: args.Contract.InstanceId,
InstrumentId: args.Contract.RegistryInstrumentId,
})
}
func encodeDeployCommitteeVerifier(args factorybindings.DeployCommitteeVerifier) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployCommitteeVerifierParams(factorybindings.DeployCommitteeVerifierParams{
InstanceId: args.Contract.InstanceId,
Owner: args.Contract.Owner,
CcipOwner: args.Contract.CcipOwner,
VersionTag: args.Contract.VersionTag,
AllowListAdmin: args.Contract.AllowListAdmin,
MessageSentObservers: args.Contract.MessageSentObservers,
RmnRemote: args.Contract.Deps.RmnRemote,
StorageLocations: args.Contract.StorageLocations,
StorageLocationsAdmin: args.Contract.StorageLocationsAdmin,
PendingStorageLocationsAdmin: args.Contract.PendingStorageLocationsAdmin,
})
}
func encodeDeployOffRamp(args factorybindings.DeployOffRamp) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployOffRampParams(factorybindings.DeployOffRampParams{
InstanceId: args.Contract.InstanceId,
GlobalConfig: args.Contract.Deps.GlobalConfig,
RmnRemote: args.Contract.Deps.RmnRemote,
TokenAdminRegistry: args.Contract.Deps.TokenAdminRegistry,
})
}
func encodeDeployOnRamp(args factorybindings.DeployOnRamp) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployOnRampParams(factorybindings.DeployOnRampParams{
InstanceId: args.Contract.InstanceId,
GlobalConfig: args.Contract.Deps.GlobalConfig,
RmnRemote: args.Contract.Deps.RmnRemote,
TokenAdminRegistry: args.Contract.Deps.TokenAdminRegistry,
FeeQuoter: args.Contract.Deps.FeeQuoter,
CcvRegistry: args.Contract.Deps.CcvRegistry,
MaxUSDCentsPerMsg: args.Contract.MaxUSDCentsPerMsg,
})
}
func encodeDeployPerPartyRouterFactory(args factorybindings.DeployPerPartyRouterFactory) (*bind.EncodedChoice, error) {
return factoryEncoder.DeployPerPartyRouterFactoryParams(factorybindings.DeployPerPartyRouterFactoryParams{
InstanceId: args.Contract.InstanceId,
OnRamp: args.Contract.Deps.OnRamp,
OffRamp: args.Contract.Deps.OffRamp,
GlobalConfig: args.Contract.Deps.GlobalConfig,
TokenAdminRegistry: args.Contract.Deps.TokenAdminRegistry,
FeeQuoter: args.Contract.Deps.FeeQuoter,
RmnRemote: args.Contract.Deps.RmnRemote,
})
}
func encodeDeployLockReleaseTokenPool(args factorybindings.DeployLockReleaseTokenPool) (*bind.EncodedChoice, error) {
c := args.Contract
return factoryEncoder.DeployLockReleaseTokenPoolParams(factorybindings.DeployLockReleaseTokenPoolParams{
InstanceId: c.InstanceId,
PoolOwner: c.PoolOwner,
CcipOwner: c.CcipOwner,
InstrumentId: c.InstrumentId,
Decimals: c.Decimals,
RateLimitAdmin: c.RateLimitAdmin,
TokenAdminRegistry: c.Deps.TokenAdminRegistry,
FeeQuoter: c.Deps.FeeQuoter,
RmnRemote: c.Deps.RmnRemote,
PoolReceiveContext: c.PoolReceiveContext,
TransferTimeout: c.TransferTimeout,
})
}
func encodeDeployBurnMintTokenPool(args factorybindings.DeployBurnMintTokenPool) (*bind.EncodedChoice, error) {
c := args.Contract
return factoryEncoder.DeployBurnMintTokenPoolParams(factorybindings.DeployBurnMintTokenPoolParams{
InstanceId: c.InstanceId,
PoolOwner: c.PoolOwner,
CcipOwner: c.CcipOwner,
InstrumentId: c.InstrumentId,
Decimals: c.Decimals,
RateLimitAdmin: c.RateLimitAdmin,
TokenAdminRegistry: c.Deps.TokenAdminRegistry,
FeeQuoter: c.Deps.FeeQuoter,
RmnRemote: c.Deps.RmnRemote,
PoolReceiveContext: c.PoolReceiveContext,
TransferTimeout: c.TransferTimeout,
})
}
func encodeDeployRateLimiter(args factorybindings.DeployRateLimiter) (*bind.EncodedChoice, error) {
c := args.Contract
return factoryEncoder.DeployRateLimiterParams(factorybindings.DeployRateLimiterParams{
InstanceId: c.InstanceId,
PoolInstanceId: c.PoolInstanceId,
PoolOwner: c.PoolOwner,
RemoteChainSelector: c.RemoteChainSelector,
Direction: c.Direction,
Mode: c.Mode,
IsEnabled: c.IsEnabled,
Capacity: c.Capacity,
Rate: c.Rate,
})
}
func encodeDeployExecutor(args factorybindings.DeployExecutor) (*bind.EncodedChoice, error) {
var payload bytes.Buffer
writeLenPrefixedText(&payload, args.Contract.InstanceId)
writeLenPrefixedText(&payload, types.TEXT(args.Contract.Owner))
writeInt64(&payload, args.Contract.MaxCCVsPerMsg)
if err := writeRequestedFinality(&payload, args.Contract.DynamicConfig.AllowedFinalityConfig); err != nil {
return nil, err
}
writeBool(&payload, args.Contract.DynamicConfig.CcvAllowlistEnabled)
return &bind.EncodedChoice{
Choice: "DeployExecutor",
OperationData: hex.EncodeToString(payload.Bytes()),
}, nil
}
func writeLenPrefixedText(buf *bytes.Buffer, value types.TEXT) {
writeUvarint(buf, uint64(len(value)))
buf.WriteString(string(value))
}
func writeUvarint(buf *bytes.Buffer, value uint64) {
var scratch [binary.MaxVarintLen64]byte
n := binary.PutUvarint(scratch[:], value)
buf.Write(scratch[:n])
}
func writeInt64(buf *bytes.Buffer, value types.INT64) {
_ = binary.Write(buf, binary.BigEndian, int64(value))
}
func writeBool(buf *bytes.Buffer, value types.BOOL) {
if value {
buf.WriteByte(0x01)
return
}
buf.WriteByte(0x00)
}
func writeRequestedFinality(buf *bytes.Buffer, finality core.FinalityConfig) error {
switch {
case finality.WaitForFinality != nil:
buf.WriteByte(0x00)
case finality.WaitForSafe != nil:
buf.WriteByte(0x01)
case finality.BlockDepth != nil:
buf.WriteByte(0x02)
writeInt64(buf, *finality.BlockDepth)
default:
return fmt.Errorf("unsupported executor finality config: %+v", finality)
}
return nil
}