|
| 1 | +package changesets |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" |
| 7 | + "github.com/smartcontractkit/chainlink-deployments-framework/operations" |
| 8 | + "github.com/smartcontractkit/chainlink-sui/bindings/bind" |
| 9 | + "github.com/smartcontractkit/chainlink-sui/deployment" |
| 10 | + sui_ops "github.com/smartcontractkit/chainlink-sui/deployment/ops" |
| 11 | + ccip_ops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip" |
| 12 | + ccip_offramp_ops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip_offramp" |
| 13 | + ccip_onramp_ops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip_onramp" |
| 14 | +) |
| 15 | + |
| 16 | +type ConnectSuiToEVMConfig struct { |
| 17 | + SuiChainSelector uint64 |
| 18 | + FeeQuoterApplyTokenTransferFeeConfigUpdatesInput ccip_ops.FeeQuoterApplyTokenTransferFeeConfigUpdatesInput |
| 19 | + FeeQuoterApplyDestChainConfigUpdatesInput ccip_ops.FeeQuoterApplyDestChainConfigUpdatesInput |
| 20 | + FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput ccip_ops.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput |
| 21 | + ApplyDestChainConfigureOnRampInput ccip_onramp_ops.ApplyDestChainConfigureOnRampInput |
| 22 | + ApplySourceChainConfigUpdateInput ccip_offramp_ops.ApplySourceChainConfigUpdateInput |
| 23 | +} |
| 24 | + |
| 25 | +// ConnectSuiToEVM connects sui chain with EVM |
| 26 | +type ConnectSuiToEVM struct{} |
| 27 | + |
| 28 | +var _ cldf.ChangeSetV2[ConnectSuiToEVMConfig] = ConnectSuiToEVM{} |
| 29 | + |
| 30 | +// Apply implements deployment.ChangeSetV2. |
| 31 | +func (d ConnectSuiToEVM) Apply(e cldf.Environment, config ConnectSuiToEVMConfig) (cldf.ChangesetOutput, error) { |
| 32 | + state, err := deployment.LoadOnchainStatesui(e) |
| 33 | + if err != nil { |
| 34 | + return cldf.ChangesetOutput{}, err |
| 35 | + } |
| 36 | + |
| 37 | + seqReports := make([]operations.Report[any, any], 0) |
| 38 | + |
| 39 | + suiChains := e.BlockChains.SuiChains() |
| 40 | + suiChain := suiChains[config.SuiChainSelector] |
| 41 | + |
| 42 | + deps := sui_ops.OpTxDeps{ |
| 43 | + Client: suiChain.Client, |
| 44 | + Signer: suiChain.Signer, |
| 45 | + GetCallOpts: func() *bind.CallOpts { |
| 46 | + b := uint64(400_000_000) |
| 47 | + return &bind.CallOpts{ |
| 48 | + WaitForExecution: true, |
| 49 | + GasBudget: &b, |
| 50 | + } |
| 51 | + }, |
| 52 | + } |
| 53 | + |
| 54 | + // Configure FeeQuoter |
| 55 | + config.FeeQuoterApplyTokenTransferFeeConfigUpdatesInput.CCIPPackageId = state[config.SuiChainSelector].CCIPAddress |
| 56 | + config.FeeQuoterApplyTokenTransferFeeConfigUpdatesInput.StateObjectId = state[config.SuiChainSelector].CCIPObjectRef |
| 57 | + config.FeeQuoterApplyTokenTransferFeeConfigUpdatesInput.OwnerCapObjectId = state[config.SuiChainSelector].CCIPOwnerCapObjectId |
| 58 | + reportFeeQuoterApplyTokenTransferFeeConfigUpdatesOp, err := operations.ExecuteOperation(e.OperationsBundle, ccip_ops.FeeQuoterApplyTokenTransferFeeConfigUpdatesOp, deps, config.FeeQuoterApplyTokenTransferFeeConfigUpdatesInput) |
| 59 | + if err != nil { |
| 60 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to run FeeQuoterApplyTokenTransferFeeConfigUpdatesOp for Sui chain %d: %w", config.SuiChainSelector, err) |
| 61 | + } |
| 62 | + seqReports = append(seqReports, []operations.Report[any, any]{reportFeeQuoterApplyTokenTransferFeeConfigUpdatesOp.ToGenericReport()}...) |
| 63 | + |
| 64 | + config.FeeQuoterApplyDestChainConfigUpdatesInput.CCIPPackageId = state[config.SuiChainSelector].CCIPAddress |
| 65 | + config.FeeQuoterApplyDestChainConfigUpdatesInput.StateObjectId = state[config.SuiChainSelector].CCIPObjectRef |
| 66 | + config.FeeQuoterApplyDestChainConfigUpdatesInput.OwnerCapObjectId = state[config.SuiChainSelector].CCIPOwnerCapObjectId |
| 67 | + reportFeeQuoterApplyDestChainConfigUpdatesOp, err := operations.ExecuteOperation(e.OperationsBundle, ccip_ops.FeeQuoterApplyDestChainConfigUpdatesOp, deps, config.FeeQuoterApplyDestChainConfigUpdatesInput) |
| 68 | + if err != nil { |
| 69 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to run FeeQuoterApplyDestChainConfigUpdatesOp for Sui chain %d: %w", config.SuiChainSelector, err) |
| 70 | + } |
| 71 | + seqReports = append(seqReports, []operations.Report[any, any]{reportFeeQuoterApplyDestChainConfigUpdatesOp.ToGenericReport()}...) |
| 72 | + |
| 73 | + config.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput.CCIPPackageId = state[config.SuiChainSelector].CCIPAddress |
| 74 | + config.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput.StateObjectId = state[config.SuiChainSelector].CCIPObjectRef |
| 75 | + config.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput.OwnerCapObjectId = state[config.SuiChainSelector].CCIPOwnerCapObjectId |
| 76 | + reportFeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesOp, err := operations.ExecuteOperation(e.OperationsBundle, ccip_ops.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesOp, deps, config.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput) |
| 77 | + if err != nil { |
| 78 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to run FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesOp for Sui chain %d: %w", config.SuiChainSelector, err) |
| 79 | + } |
| 80 | + seqReports = append(seqReports, []operations.Report[any, any]{reportFeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesOp.ToGenericReport()}...) |
| 81 | + |
| 82 | + // Configure OnRamp |
| 83 | + config.ApplyDestChainConfigureOnRampInput.OnRampPackageId = state[config.SuiChainSelector].OnRampAddress |
| 84 | + config.ApplyDestChainConfigureOnRampInput.OwnerCapObjectId = state[config.SuiChainSelector].OnRampOwnerCapObjectId |
| 85 | + config.ApplyDestChainConfigureOnRampInput.StateObjectId = state[config.SuiChainSelector].OnRampStateObjectId |
| 86 | + config.ApplyDestChainConfigureOnRampInput.CCIPObjectRefId = state[config.SuiChainSelector].CCIPObjectRef |
| 87 | + reportApplyDestChainConfigUpdateOp, err := operations.ExecuteOperation(e.OperationsBundle, ccip_onramp_ops.ApplyDestChainConfigUpdateOp, deps, config.ApplyDestChainConfigureOnRampInput) |
| 88 | + if err != nil { |
| 89 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to run ApplyDestChainConfigUpdateOp for Sui chain %d: %w", config.SuiChainSelector, err) |
| 90 | + } |
| 91 | + seqReports = append(seqReports, []operations.Report[any, any]{reportApplyDestChainConfigUpdateOp.ToGenericReport()}...) |
| 92 | + |
| 93 | + // Configure OffRamp |
| 94 | + config.ApplySourceChainConfigUpdateInput.CCIPObjectRef = state[config.SuiChainSelector].CCIPObjectRef |
| 95 | + config.ApplySourceChainConfigUpdateInput.OffRampPackageId = state[config.SuiChainSelector].OffRampAddress |
| 96 | + config.ApplySourceChainConfigUpdateInput.OffRampStateId = state[config.SuiChainSelector].OffRampStateObjectId |
| 97 | + config.ApplySourceChainConfigUpdateInput.OwnerCapObjectId = state[config.SuiChainSelector].OffRampOwnerCapId |
| 98 | + reportApplySourceChainConfigUpdatesOp, err := operations.ExecuteOperation(e.OperationsBundle, ccip_offramp_ops.ApplySourceChainConfigUpdatesOp, deps, config.ApplySourceChainConfigUpdateInput) |
| 99 | + if err != nil { |
| 100 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to run ApplySourceChainConfigUpdatesOp for Sui chain %d: %w", config.SuiChainSelector, err) |
| 101 | + } |
| 102 | + seqReports = append(seqReports, []operations.Report[any, any]{reportApplySourceChainConfigUpdatesOp.ToGenericReport()}...) |
| 103 | + |
| 104 | + return cldf.ChangesetOutput{ |
| 105 | + Reports: seqReports, |
| 106 | + }, nil |
| 107 | +} |
| 108 | + |
| 109 | +// VerifyPreconditions implements deployment.ChangeSetV2. |
| 110 | +func (d ConnectSuiToEVM) VerifyPreconditions(e cldf.Environment, config ConnectSuiToEVMConfig) error { |
| 111 | + return nil |
| 112 | +} |
0 commit comments