Skip to content

Commit 9c8535b

Browse files
authored
Merge branch 'develop' into mcms-rebalancer-cap
2 parents f60556c + 9565751 commit 9c8535b

File tree

6 files changed

+450
-182
lines changed

6 files changed

+450
-182
lines changed

deployment/ops/ccip/op_token_admin_registry.go

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var TokenAdminRegistryInitializeOp = cld_ops.NewOperation(
6868

6969
type UnregisterPoolInput struct {
7070
CCIPPackageId string
71-
StateObjectId string
71+
CCIPObjectRef string
7272
CoinMetadataAddress string
7373
}
7474

@@ -78,16 +78,33 @@ var unregisterPoolHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input
7878
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to create token admin registry contract: %w", err)
7979
}
8080

81+
encodedCall, err := contract.Encoder().UnregisterPool(bind.Object{Id: input.CCIPObjectRef}, input.CoinMetadataAddress)
82+
if err != nil {
83+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to encode UnregisterPool call: %w", err)
84+
}
85+
call, err := sui_ops.ToTransactionCall(encodedCall, input.CCIPObjectRef)
86+
if err != nil {
87+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to convert encoded call to TransactionCall: %w", err)
88+
}
89+
if deps.Signer == nil {
90+
b.Logger.Infow("Skipping execution of UnregisterPool on TokenAdminRegistry as per no Signer provided", "CoinMetadataAddress", input.CoinMetadataAddress)
91+
return sui_ops.OpTxResult[NoObjects]{
92+
Digest: "",
93+
PackageId: input.CCIPPackageId,
94+
Objects: NoObjects{},
95+
Call: call,
96+
}, nil
97+
}
98+
8199
opts := deps.GetCallOpts()
82100
opts.Signer = deps.Signer
83-
tx, err := contract.UnregisterPool(
101+
tx, err := contract.Bound().ExecuteTransaction(
84102
b.GetContext(),
85103
opts,
86-
bind.Object{Id: input.StateObjectId},
87-
input.CoinMetadataAddress,
104+
encodedCall,
88105
)
89106
if err != nil {
90-
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to execute unregister pool: %w", err)
107+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to execute UnregisterPool on TokenAdminRegistry: %w", err)
91108
}
92109

93110
b.Logger.Infow("UnregisterPool on TokenAdminRegistry", "PackageId:", input.CCIPPackageId, "CoinMetadataAddress:", input.CoinMetadataAddress)
@@ -96,6 +113,7 @@ var unregisterPoolHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input
96113
Digest: tx.Digest,
97114
PackageId: input.CCIPPackageId,
98115
Objects: NoObjects{},
116+
Call: call,
99117
}, nil
100118
}
101119

@@ -112,7 +130,7 @@ var TokenAdminRegistryUnregisterPoolOp = cld_ops.NewOperation(
112130

113131
type TransferAdminRoleInput struct {
114132
CCIPPackageId string
115-
StateObjectId string
133+
CCIPObjectRef string
116134
CoinMetadataAddress string
117135
NewAdmin string
118136
}
@@ -123,17 +141,33 @@ var transferAdminRoleHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, inp
123141
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to create token admin registry contract: %w", err)
124142
}
125143

144+
encodedCall, err := contract.Encoder().TransferAdminRole(bind.Object{Id: input.CCIPObjectRef}, input.CoinMetadataAddress, input.NewAdmin)
145+
if err != nil {
146+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to encode TransferAdminRole call: %w", err)
147+
}
148+
call, err := sui_ops.ToTransactionCall(encodedCall, input.CCIPObjectRef)
149+
if err != nil {
150+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to convert encoded call to TransactionCall: %w", err)
151+
}
152+
if deps.Signer == nil {
153+
b.Logger.Infow("Skipping execution of TransferAdminRole on TokenAdminRegistry as per no Signer provided", "CoinMetadataAddress", input.CoinMetadataAddress, "NewAdmin", input.NewAdmin)
154+
return sui_ops.OpTxResult[NoObjects]{
155+
Digest: "",
156+
PackageId: input.CCIPPackageId,
157+
Objects: NoObjects{},
158+
Call: call,
159+
}, nil
160+
}
161+
126162
opts := deps.GetCallOpts()
127163
opts.Signer = deps.Signer
128-
tx, err := contract.TransferAdminRole(
164+
tx, err := contract.Bound().ExecuteTransaction(
129165
b.GetContext(),
130166
opts,
131-
bind.Object{Id: input.StateObjectId},
132-
input.CoinMetadataAddress,
133-
input.NewAdmin,
167+
encodedCall,
134168
)
135169
if err != nil {
136-
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to execute transfer admin role: %w", err)
170+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to execute TransferAdminRole on TokenAdminRegistry: %w", err)
137171
}
138172

139173
b.Logger.Infow("TransferAdminRole on TokenAdminRegistry", "PackageId:", input.CCIPPackageId, "CoinMetadataAddress:", input.CoinMetadataAddress, "NewAdmin:", input.NewAdmin)
@@ -142,6 +176,7 @@ var transferAdminRoleHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, inp
142176
Digest: tx.Digest,
143177
PackageId: input.CCIPPackageId,
144178
Objects: NoObjects{},
179+
Call: call,
145180
}, nil
146181
}
147182

@@ -158,7 +193,7 @@ var TokenAdminRegistryTransferAdminRoleOp = cld_ops.NewOperation(
158193

159194
type AcceptAdminRoleInput struct {
160195
CCIPPackageId string
161-
StateObjectId string
196+
CCIPObjectRef string
162197
CoinMetadataAddress string
163198
}
164199

@@ -168,16 +203,33 @@ var acceptAdminRoleHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input
168203
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to create token admin registry contract: %w", err)
169204
}
170205

206+
encodedCall, err := contract.Encoder().AcceptAdminRole(bind.Object{Id: input.CCIPObjectRef}, input.CoinMetadataAddress)
207+
if err != nil {
208+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to encode AcceptAdminRole call: %w", err)
209+
}
210+
call, err := sui_ops.ToTransactionCall(encodedCall, input.CCIPObjectRef)
211+
if err != nil {
212+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to convert encoded call to TransactionCall: %w", err)
213+
}
214+
if deps.Signer == nil {
215+
b.Logger.Infow("Skipping execution of AcceptAdminRole on TokenAdminRegistry as per no Signer provided", "CoinMetadataAddress", input.CoinMetadataAddress)
216+
return sui_ops.OpTxResult[NoObjects]{
217+
Digest: "",
218+
PackageId: input.CCIPPackageId,
219+
Objects: NoObjects{},
220+
Call: call,
221+
}, nil
222+
}
223+
171224
opts := deps.GetCallOpts()
172225
opts.Signer = deps.Signer
173-
tx, err := contract.AcceptAdminRole(
226+
tx, err := contract.Bound().ExecuteTransaction(
174227
b.GetContext(),
175228
opts,
176-
bind.Object{Id: input.StateObjectId},
177-
input.CoinMetadataAddress,
229+
encodedCall,
178230
)
179231
if err != nil {
180-
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to execute accept admin role: %w", err)
232+
return sui_ops.OpTxResult[NoObjects]{}, fmt.Errorf("failed to execute AcceptAdminRole on TokenAdminRegistry: %w", err)
181233
}
182234

183235
b.Logger.Infow("AcceptAdminRole on TokenAdminRegistry", "PackageId:", input.CCIPPackageId, "CoinMetadataAddress:", input.CoinMetadataAddress)
@@ -186,6 +238,7 @@ var acceptAdminRoleHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input
186238
Digest: tx.Digest,
187239
PackageId: input.CCIPPackageId,
188240
Objects: NoObjects{},
241+
Call: call,
189242
}, nil
190243
}
191244

deployment/ops/mcms/op_proposal_generate.go

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package mcmsops
22

33
import (
4+
"encoding/json"
45
"fmt"
5-
"reflect"
66
"time"
77

88
"github.com/Masterminds/semver/v3"
@@ -39,6 +39,35 @@ type ProposalGenerateInput struct {
3939
ChainSelector uint64 `json:"chainSelector"`
4040
}
4141

42+
func extractTransactionCall(output interface{}, operationID string) (sui_ops.TransactionCall, error) {
43+
jsonBytes, err := json.Marshal(output)
44+
if err != nil {
45+
return sui_ops.TransactionCall{}, fmt.Errorf("failed to marshal operation %s output: %w", operationID, err)
46+
}
47+
48+
var outputMap map[string]interface{}
49+
if err := json.Unmarshal(jsonBytes, &outputMap); err != nil {
50+
return sui_ops.TransactionCall{}, fmt.Errorf("failed to unmarshal operation %s output: %w", operationID, err)
51+
}
52+
53+
callInterface, exists := outputMap["Call"]
54+
if !exists {
55+
return sui_ops.TransactionCall{}, fmt.Errorf("operation %s output does not have a Call field", operationID)
56+
}
57+
58+
callBytes, err := json.Marshal(callInterface)
59+
if err != nil {
60+
return sui_ops.TransactionCall{}, fmt.Errorf("failed to marshal Call field for operation %s: %w", operationID, err)
61+
}
62+
63+
var call sui_ops.TransactionCall
64+
if err := json.Unmarshal(callBytes, &call); err != nil {
65+
return sui_ops.TransactionCall{}, fmt.Errorf("failed to unmarshal Call field for operation %s: %w", operationID, err)
66+
}
67+
68+
return call, nil
69+
}
70+
4271
var generateProposalHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, input ProposalGenerateInput) (output mcms.TimelockProposal, err error) {
4372
if len(input.Defs) != len(input.Inputs) {
4473
return mcms.TimelockProposal{}, fmt.Errorf("number of definitions (%d) does not match number of inputs (%d)", len(input.Defs), len(input.Inputs))
@@ -73,20 +102,10 @@ var generateProposalHandler = func(b cld_ops.Bundle, deps sui_ops.OpTxDeps, inpu
73102
if err != nil {
74103
return mcms.TimelockProposal{}, fmt.Errorf("failed to execute operation %s: %w", def.ID, err)
75104
}
76-
// Use reflection to extract the Call field from the OpTxResult regardless of its specific type
77-
outputValue := reflect.ValueOf(res.Output)
78-
if outputValue.Kind() != reflect.Struct {
79-
return mcms.TimelockProposal{}, fmt.Errorf("operation %s did not return a struct output", def.ID)
80-
}
81-
82-
callField := outputValue.FieldByName("Call")
83-
if !callField.IsValid() {
84-
return mcms.TimelockProposal{}, fmt.Errorf("operation %s output does not have a Call field", def.ID)
85-
}
86-
87-
call, ok := callField.Interface().(sui_ops.TransactionCall)
88-
if !ok {
89-
return mcms.TimelockProposal{}, fmt.Errorf("operation %s Call field is not a TransactionCall", def.ID)
105+
// Extract the Call field
106+
call, err := extractTransactionCall(res.Output, def.ID)
107+
if err != nil {
108+
return mcms.TimelockProposal{}, err
90109
}
91110

92111
tx, err := suisdk.NewTransactionWithStateObj(

0 commit comments

Comments
 (0)