Skip to content

Commit db38ee3

Browse files
authored
update add package id and block features (#362)
1 parent 5ea9f26 commit db38ee3

3 files changed

Lines changed: 94 additions & 47 deletions

File tree

deployment/changesets/cs_add_ccip_package_id.go

Lines changed: 73 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@ import (
99
"github.com/smartcontractkit/chainlink-sui/bindings/bind"
1010
sui_ops "github.com/smartcontractkit/chainlink-sui/deployment/ops"
1111
ccipops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip"
12+
offrampops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip_offramp"
13+
onrampops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip_onramp"
14+
)
15+
16+
type AddPackageIdTarget string
17+
18+
const (
19+
AddPackageIdTargetCCIP AddPackageIdTarget = "ccip"
20+
AddPackageIdTargetOnRamp AddPackageIdTarget = "onramp"
21+
AddPackageIdTargetOffRamp AddPackageIdTarget = "offramp"
1222
)
1323

1424
type AddCCIPPackageIdConfig struct {
15-
SuiChainSelector uint64 `yaml:"suiChainSelector"`
16-
CCIPPackageId string `yaml:"ccipPackageId"`
17-
CCIPObjectRefObjectId string `yaml:"ccipObjectRefObjectId"`
18-
OwnerCapObjectId string `yaml:"ownerCapObjectId"`
19-
PackageId string `yaml:"packageId"`
25+
SuiChainSelector uint64 `yaml:"suiChainSelector"`
26+
Target AddPackageIdTarget `yaml:"target"`
27+
ModulePackageId string `yaml:"modulePackageId"`
28+
StateObjectId string `yaml:"stateObjectId"`
29+
OwnerCapObjectId string `yaml:"ownerCapObjectId"`
30+
PackageId string `yaml:"packageId"`
2031
}
2132

2233
var _ cldf.ChangeSetV2[AddCCIPPackageIdConfig] = AddCCIPPackageId{}
@@ -25,7 +36,6 @@ type AddCCIPPackageId struct{}
2536

2637
func (d AddCCIPPackageId) Apply(e cldf.Environment, config AddCCIPPackageIdConfig) (cldf.ChangesetOutput, error) {
2738
ab := cldf.NewMemoryAddressBook()
28-
seqReports := make([]operations.Report[any, any], 0)
2939

3040
suiChain := e.BlockChains.SuiChains()[config.SuiChainSelector]
3141

@@ -42,24 +52,71 @@ func (d AddCCIPPackageId) Apply(e cldf.Environment, config AddCCIPPackageIdConfi
4252
SuiRPC: suiChain.URL,
4353
}
4454

45-
addPackageIdReport, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.AddPackageIdStateObjectOp, deps, ccipops.AddPackageIdStateObjectInput{
46-
CCIPPackageId: config.CCIPPackageId,
47-
CCIPObjectRefObjectId: config.CCIPObjectRefObjectId,
48-
OwnerCapObjectId: config.OwnerCapObjectId,
49-
PackageId: config.PackageId,
50-
})
55+
report, err := executeAddPackageId(e, config, deps)
5156
if err != nil {
52-
return cldf.ChangesetOutput{}, fmt.Errorf("failed to add CCIP package ID for Sui chain %d: %w", config.SuiChainSelector, err)
57+
return cldf.ChangesetOutput{}, err
5358
}
5459

55-
seqReports = append(seqReports, addPackageIdReport.ToGenericReport())
56-
5760
return cldf.ChangesetOutput{
5861
AddressBook: ab,
59-
Reports: seqReports,
62+
Reports: []operations.Report[any, any]{report},
6063
}, nil
6164
}
6265

66+
func executeAddPackageId(e cldf.Environment, config AddCCIPPackageIdConfig, deps sui_ops.OpTxDeps) (operations.Report[any, any], error) {
67+
target := config.Target
68+
if target == "" {
69+
target = AddPackageIdTargetCCIP
70+
}
71+
72+
switch target {
73+
case AddPackageIdTargetCCIP:
74+
r, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.AddPackageIdStateObjectOp, deps, ccipops.AddPackageIdStateObjectInput{
75+
CCIPPackageId: config.ModulePackageId,
76+
CCIPObjectRefObjectId: config.StateObjectId,
77+
OwnerCapObjectId: config.OwnerCapObjectId,
78+
PackageId: config.PackageId,
79+
})
80+
if err != nil {
81+
return operations.Report[any, any]{}, fmt.Errorf("failed to add package ID to CCIP state object for Sui chain %d: %w", config.SuiChainSelector, err)
82+
}
83+
return r.ToGenericReport(), nil
84+
85+
case AddPackageIdTargetOnRamp:
86+
r, err := operations.ExecuteOperation(e.OperationsBundle, onrampops.AddPackageIdOp, deps, onrampops.AddPackageIdInput{
87+
OnRampPackageId: config.ModulePackageId,
88+
StateObjectId: config.StateObjectId,
89+
OwnerCapObjectId: config.OwnerCapObjectId,
90+
PackageId: config.PackageId,
91+
})
92+
if err != nil {
93+
return operations.Report[any, any]{}, fmt.Errorf("failed to add package ID to OnRamp for Sui chain %d: %w", config.SuiChainSelector, err)
94+
}
95+
return r.ToGenericReport(), nil
96+
97+
case AddPackageIdTargetOffRamp:
98+
r, err := operations.ExecuteOperation(e.OperationsBundle, offrampops.AddPackageIdOffRampOp, deps, offrampops.AddPackageIdOffRampInput{
99+
OffRampPackageId: config.ModulePackageId,
100+
StateObjectId: config.StateObjectId,
101+
OwnerCapObjectId: config.OwnerCapObjectId,
102+
PackageId: config.PackageId,
103+
})
104+
if err != nil {
105+
return operations.Report[any, any]{}, fmt.Errorf("failed to add package ID to OffRamp for Sui chain %d: %w", config.SuiChainSelector, err)
106+
}
107+
return r.ToGenericReport(), nil
108+
109+
default:
110+
return operations.Report[any, any]{}, fmt.Errorf("unknown target %q: must be one of %q, %q, %q",
111+
config.Target, AddPackageIdTargetCCIP, AddPackageIdTargetOnRamp, AddPackageIdTargetOffRamp)
112+
}
113+
}
114+
63115
func (d AddCCIPPackageId) VerifyPreconditions(e cldf.Environment, config AddCCIPPackageIdConfig) error {
116+
if config.Target != "" && config.Target != AddPackageIdTargetCCIP &&
117+
config.Target != AddPackageIdTargetOnRamp && config.Target != AddPackageIdTargetOffRamp {
118+
return fmt.Errorf("invalid target %q: must be one of %q, %q, %q",
119+
config.Target, AddPackageIdTargetCCIP, AddPackageIdTargetOnRamp, AddPackageIdTargetOffRamp)
120+
}
64121
return nil
65122
}

deployment/changesets/cs_block_function.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@ import (
1111
)
1212

1313
type BlockFunctionConfig struct {
14-
SuiChainSelector uint64
15-
CCIPPackageId string
16-
StateObjectId string
17-
OwnerCapObjectId string
18-
ModuleName string
19-
FunctionName string
20-
Version uint8
14+
SuiChainSelector uint64 `yaml:"suiChainSelector"`
15+
CCIPPackageId string `yaml:"ccipPackageId"`
16+
CCIPObjectRefObjectId string `yaml:"ccipObjectRefObjectId"`
17+
OwnerCapObjectId string `yaml:"ownerCapObjectId"`
18+
ModuleName string `yaml:"moduleName"`
19+
FunctionName string `yaml:"functionName"`
20+
Version uint8 `yaml:"version"`
2121
}
2222

2323
var _ cldf.ChangeSetV2[BlockFunctionConfig] = BlockFunction{}
2424

2525
type BlockFunction struct{}
2626

27-
// Apply implements deployment.ChangeSetV2.
2827
func (d BlockFunction) Apply(e cldf.Environment, config BlockFunctionConfig) (cldf.ChangesetOutput, error) {
2928
ab := cldf.NewMemoryAddressBook()
30-
seqReports := make([]operations.Report[any, any], 0)
3129

3230
suiChain := e.BlockChains.SuiChains()[config.SuiChainSelector]
3331

@@ -44,27 +42,24 @@ func (d BlockFunction) Apply(e cldf.Environment, config BlockFunctionConfig) (cl
4442
SuiRPC: suiChain.URL,
4543
}
4644

47-
BlockFunctionInitializeOp, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.BlockFunctionOp, deps, ccipops.BlockFunctionInput{
45+
report, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.BlockFunctionOp, deps, ccipops.BlockFunctionInput{
4846
CCIPPackageId: config.CCIPPackageId,
49-
StateObjectId: config.StateObjectId,
47+
StateObjectId: config.CCIPObjectRefObjectId,
5048
OwnerCapObjectId: config.OwnerCapObjectId,
5149
ModuleName: config.ModuleName,
5250
FunctionName: config.FunctionName,
5351
Version: config.Version,
5452
})
5553
if err != nil {
56-
return cldf.ChangesetOutput{}, fmt.Errorf("failed to block Functionname for Sui chain %d: %w", config.SuiChainSelector, err)
54+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to block function for Sui chain %d: %w", config.SuiChainSelector, err)
5755
}
5856

59-
seqReports = append(seqReports, []operations.Report[any, any]{BlockFunctionInitializeOp.ToGenericReport()}...)
60-
6157
return cldf.ChangesetOutput{
6258
AddressBook: ab,
63-
Reports: seqReports,
59+
Reports: []operations.Report[any, any]{report.ToGenericReport()},
6460
}, nil
6561
}
6662

67-
// VerifyPreconditions implements deployment.ChangeSetV2.
6863
func (d BlockFunction) VerifyPreconditions(e cldf.Environment, config BlockFunctionConfig) error {
6964
return nil
7065
}

deployment/changesets/cs_block_version.go

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,20 @@ import (
1111
)
1212

1313
type BlockVersionConfig struct {
14-
SuiChainSelector uint64
15-
CCIPPackageId string
16-
StateObjectId string
17-
OwnerCapObjectId string
18-
ModuleName string
19-
Version uint8
14+
SuiChainSelector uint64 `yaml:"suiChainSelector"`
15+
CCIPPackageId string `yaml:"ccipPackageId"`
16+
CCIPObjectRefObjectId string `yaml:"ccipObjectRefObjectId"`
17+
OwnerCapObjectId string `yaml:"ownerCapObjectId"`
18+
ModuleName string `yaml:"moduleName"`
19+
Version uint8 `yaml:"version"`
2020
}
2121

2222
var _ cldf.ChangeSetV2[BlockVersionConfig] = BlockVersion{}
2323

2424
type BlockVersion struct{}
2525

26-
// Apply implements deployment.ChangeSetV2.
2726
func (d BlockVersion) Apply(e cldf.Environment, config BlockVersionConfig) (cldf.ChangesetOutput, error) {
2827
ab := cldf.NewMemoryAddressBook()
29-
seqReports := make([]operations.Report[any, any], 0)
3028

3129
suiChain := e.BlockChains.SuiChains()[config.SuiChainSelector]
3230

@@ -43,26 +41,23 @@ func (d BlockVersion) Apply(e cldf.Environment, config BlockVersionConfig) (cldf
4341
SuiRPC: suiChain.URL,
4442
}
4543

46-
BlockVersionInitializeOp, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.BlockVersionOp, deps, ccipops.BlockVersionInput{
44+
report, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.BlockVersionOp, deps, ccipops.BlockVersionInput{
4745
CCIPPackageId: config.CCIPPackageId,
48-
StateObjectId: config.StateObjectId,
46+
StateObjectId: config.CCIPObjectRefObjectId,
4947
OwnerCapObjectId: config.OwnerCapObjectId,
5048
ModuleName: config.ModuleName,
5149
Version: config.Version,
5250
})
5351
if err != nil {
54-
return cldf.ChangesetOutput{}, fmt.Errorf("failed to initialize upgrade registry for Sui chain %d: %w", config.SuiChainSelector, err)
52+
return cldf.ChangesetOutput{}, fmt.Errorf("failed to block version for Sui chain %d: %w", config.SuiChainSelector, err)
5553
}
5654

57-
seqReports = append(seqReports, []operations.Report[any, any]{BlockVersionInitializeOp.ToGenericReport()}...)
58-
5955
return cldf.ChangesetOutput{
6056
AddressBook: ab,
61-
Reports: seqReports,
57+
Reports: []operations.Report[any, any]{report.ToGenericReport()},
6258
}, nil
6359
}
6460

65-
// VerifyPreconditions implements deployment.ChangeSetV2.
6661
func (d BlockVersion) VerifyPreconditions(e cldf.Environment, config BlockVersionConfig) error {
6762
return nil
6863
}

0 commit comments

Comments
 (0)