Skip to content

Commit 970847f

Browse files
authored
Merge branch 'develop' into ownable-state
2 parents c43b305 + 216529d commit 970847f

File tree

8 files changed

+403
-54
lines changed

8 files changed

+403
-54
lines changed

bindings/bind/bcs_decoder_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ func TestDeserializer(t *testing.T) {
333333
}
334334

335335
func TestDeserializer_ShouldFail(t *testing.T) {
336+
// TODO: this test will fail when https://github.com/block-vision/sui-go-sdk/pull/78
337+
// is released and will have to be removed
338+
336339
// mystenbcs encoder has an issue where fixed-size byte arrays ([n]byte) are treated as regular slices.
337340
// so encoding a u128 via their encoder will result in failure to decode it back.
338341
// We're using this behavior to test our DeserializeBCS error handling.

bindings/bind/type_converter.go

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -585,20 +585,62 @@ func convertVectorToBCS(innerType string, value any) (any, error) {
585585
type SuiAddressBytes [32]byte
586586

587587
func bcsEncode(value any) ([]byte, error) {
588-
if addrs, ok := value.([][32]byte); ok {
589-
suiAddrs := make([]SuiAddressBytes, len(addrs))
590-
for i, addr := range addrs {
591-
suiAddrs[i] = SuiAddressBytes(addr)
592-
}
593-
value = suiAddrs
588+
// Normalize value before encoding
589+
normalized, err := normalizeValue(value)
590+
if err != nil {
591+
return nil, err
594592
}
595593

596594
bcsEncodedMsg := bytes.Buffer{}
597595
bcsEncoder := mystenbcs.NewEncoder(&bcsEncodedMsg)
598-
err := bcsEncoder.Encode(value)
596+
err = bcsEncoder.Encode(normalized)
599597
if err != nil {
600598
return nil, err
601599
}
602600

603601
return bcsEncodedMsg.Bytes(), nil
604602
}
603+
604+
// normalizeValue converts special Go types into the correct BCS-friendly form.
605+
// TODO: This is a temporary solution until sui-go-sdk addresses [n]bytes bug
606+
// https://github.com/block-vision/sui-go-sdk/issues/75 won't be necessary after release
607+
// fixes vector<address> and vector<vector<address>> encoding.
608+
func normalizeValue(value any) (any, error) {
609+
switch v := value.(type) {
610+
case [][32]byte:
611+
// Single-level vector<address>
612+
return convertToSliceSuiAddressBytes(v), nil
613+
case []interface{}:
614+
// Possible nested address vectors: [][][32]byte (wrapped as []interface{}) (vector<vector<address>>)
615+
if len(v) == 0 {
616+
return v, nil
617+
}
618+
// Check if the first element matches the pattern
619+
if _, ok := v[0].([][32]byte); !ok {
620+
return value, nil
621+
}
622+
result := make([][]SuiAddressBytes, len(v))
623+
for i, item := range v {
624+
// Make sure all the items are of the expected type
625+
addrs, ok := item.([][32]byte)
626+
if !ok {
627+
return nil, fmt.Errorf("expected [][32]byte at index %d, got %T", i, item)
628+
}
629+
result[i] = convertToSliceSuiAddressBytes(addrs)
630+
}
631+
632+
return result, nil
633+
}
634+
635+
return value, nil
636+
}
637+
638+
// convertToSuiAddressBytes converts a slice of [32]byte into []SuiAddressBytes.
639+
func convertToSliceSuiAddressBytes(addresses [][32]byte) []SuiAddressBytes {
640+
out := make([]SuiAddressBytes, len(addresses))
641+
for i, addr := range addresses {
642+
out[i] = SuiAddressBytes(addr)
643+
}
644+
645+
return out
646+
}

deployment/ops/ccip_offramp/op_deploy.go

Lines changed: 69 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,7 @@ var setOCR3ConfigHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input S
126126
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, err
127127
}
128128

129-
opts := deps.GetCallOpts()
130-
opts.Signer = deps.Signer
131-
tx, err := offRampPackage.SetOcr3Config(
132-
b.GetContext(),
133-
opts,
129+
encodedCall, err := offRampPackage.Encoder().SetOcr3Config(
134130
bind.Object{Id: input.CCIPObjectRefId},
135131
bind.Object{Id: input.OffRampStateId},
136132
bind.Object{Id: input.OwnerCapObjectId},
@@ -142,25 +138,52 @@ var setOCR3ConfigHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input S
142138
input.Transmitters,
143139
)
144140
if err != nil {
145-
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to execute set ocr3 config in offramp: %w", err)
141+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to encode SetOcr3Config call: %w", err)
142+
}
143+
call, err := sui_ops.ToTransactionCall(encodedCall, input.OffRampStateId)
144+
if err != nil {
145+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to convert encoded call to TransactionCall: %w", err)
146+
}
147+
if deps.Signer == nil {
148+
b.Logger.Infow("Skipping execution of SetOcr3Config on OffRamp as per no Signer provided")
149+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{
150+
Digest: "",
151+
PackageId: input.OffRampPackageId,
152+
Objects: DeployCCIPOffRampObjects{},
153+
Call: call,
154+
}, nil
146155
}
147156

157+
opts := deps.GetCallOpts()
158+
opts.Signer = deps.Signer
159+
tx, err := offRampPackage.Bound().ExecuteTransaction(
160+
b.GetContext(),
161+
opts,
162+
encodedCall,
163+
)
164+
if err != nil {
165+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to execute SetOcr3Config on OffRamp: %w", err)
166+
}
167+
168+
b.Logger.Infow("OCR3 config set on OffRamp")
169+
148170
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{
149171
Digest: tx.Digest,
150172
PackageId: input.OffRampPackageId,
151173
Objects: DeployCCIPOffRampObjects{},
152-
}, err
174+
Call: call,
175+
}, nil
153176
}
154177

155178
type ApplySourceChainConfigUpdateInput struct {
156-
CCIPObjectRef string
157-
OffRampPackageId string
158-
OffRampStateId string
159-
OwnerCapObjectId string
160-
SourceChainsSelectors []uint64
161-
SourceChainsIsEnabled []bool
162-
SouceChainsIsRMNVerificationDisabled []bool
163-
SourceChainsOnRamp [][]byte
179+
CCIPObjectRef string
180+
OffRampPackageId string
181+
OffRampStateId string
182+
OwnerCapObjectId string
183+
SourceChainsSelectors []uint64
184+
SourceChainsIsEnabled []bool
185+
SourceChainsIsRMNVerificationDisabled []bool
186+
SourceChainsOnRamp [][]byte
164187
}
165188

166189
var applySourceChainConfigUpdateHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input ApplySourceChainConfigUpdateInput) (output sui_ops.OpTxResult[DeployCCIPOffRampObjects], err error) {
@@ -169,28 +192,51 @@ var applySourceChainConfigUpdateHandler = func(b cld_ops.Bundle, deps sui_ops.Op
169192
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, err
170193
}
171194

172-
opts := deps.GetCallOpts()
173-
opts.Signer = deps.Signer
174-
tx, err := offRampPackage.ApplySourceChainConfigUpdates(
175-
b.GetContext(),
176-
opts,
195+
encodedCall, err := offRampPackage.Encoder().ApplySourceChainConfigUpdates(
177196
bind.Object{Id: input.CCIPObjectRef},
178197
bind.Object{Id: input.OffRampStateId},
179198
bind.Object{Id: input.OwnerCapObjectId},
180199
input.SourceChainsSelectors,
181200
input.SourceChainsIsEnabled,
182-
input.SouceChainsIsRMNVerificationDisabled,
201+
input.SourceChainsIsRMNVerificationDisabled,
183202
input.SourceChainsOnRamp,
184203
)
185204
if err != nil {
186-
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to execute applySourceChainConfigUpdate in offramp: %w", err)
205+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to encode ApplySourceChainConfigUpdates call: %w", err)
206+
}
207+
call, err := sui_ops.ToTransactionCall(encodedCall, input.OffRampStateId)
208+
if err != nil {
209+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to convert encoded call to TransactionCall: %w", err)
210+
}
211+
if deps.Signer == nil {
212+
b.Logger.Infow("Skipping execution of ApplySourceChainConfigUpdates on OffRamp as per no Signer provided")
213+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{
214+
Digest: "",
215+
PackageId: input.OffRampPackageId,
216+
Objects: DeployCCIPOffRampObjects{},
217+
Call: call,
218+
}, nil
219+
}
220+
221+
opts := deps.GetCallOpts()
222+
opts.Signer = deps.Signer
223+
tx, err := offRampPackage.Bound().ExecuteTransaction(
224+
b.GetContext(),
225+
opts,
226+
encodedCall,
227+
)
228+
if err != nil {
229+
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{}, fmt.Errorf("failed to execute ApplySourceChainConfigUpdates on OffRamp: %w", err)
187230
}
188231

232+
b.Logger.Infow("Source chain config updates applied on OffRamp")
233+
189234
return sui_ops.OpTxResult[DeployCCIPOffRampObjects]{
190235
Digest: tx.Digest,
191236
PackageId: input.OffRampPackageId,
192237
Objects: DeployCCIPOffRampObjects{},
193-
}, err
238+
Call: call,
239+
}, nil
194240
}
195241

196242
type AddPackageIdOffRampInput struct {

deployment/ops/ccip_offramp/op_registry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ var AllOperationsOfframp = []cld_ops.Operation[any, any, any]{
66
*TransferOwnershipOffRampOp.AsUntyped(),
77
*AcceptOwnershipOffRampOp.AsUntyped(),
88
*ExecuteOwnershipTransferToMcmsOffRampOp.AsUntyped(),
9+
*ApplySourceChainConfigUpdatesOp.AsUntyped(),
10+
*SetOCR3ConfigOp.AsUntyped(),
911
}

0 commit comments

Comments
 (0)