|
| 1 | +package changesets |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "math/big" |
| 6 | + |
| 7 | + cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" |
| 8 | + "github.com/smartcontractkit/chainlink-deployments-framework/operations" |
| 9 | + |
| 10 | + "github.com/smartcontractkit/chainlink-sui/bindings/bind" |
| 11 | + "github.com/smartcontractkit/chainlink-sui/deployment" |
| 12 | + sui_ops "github.com/smartcontractkit/chainlink-sui/deployment/ops" |
| 13 | + ccipops "github.com/smartcontractkit/chainlink-sui/deployment/ops/ccip" |
| 14 | +) |
| 15 | + |
| 16 | +type NewFeeTokenConfig struct { |
| 17 | + SuiChainSelector uint64 |
| 18 | + FeeTokensToRemove []string |
| 19 | + FeeTokensToAdd []string // should be the objectID |
| 20 | + |
| 21 | + // update price |
| 22 | + SourceUsdPerToken []*big.Int |
| 23 | + |
| 24 | + // premium multiplier wei per eth |
| 25 | + PremiumMultiplierWeiPerEth []uint64 |
| 26 | +} |
| 27 | + |
| 28 | +// ConnectSuiToEVM connects sui chain with EVM |
| 29 | +type NewFeeToken struct{} |
| 30 | + |
| 31 | +var _ cldf.ChangeSetV2[NewFeeTokenConfig] = NewFeeToken{} |
| 32 | + |
| 33 | +// Apply implements deployment.ChangeSetV2. |
| 34 | +func (d NewFeeToken) Apply(e cldf.Environment, config NewFeeTokenConfig) (cldf.ChangesetOutput, error) { |
| 35 | + ab := cldf.NewMemoryAddressBook() |
| 36 | + state, err := deployment.LoadOnchainStatesui(e) |
| 37 | + if err != nil { |
| 38 | + return cldf.ChangesetOutput{}, err |
| 39 | + } |
| 40 | + |
| 41 | + seqReports := make([]operations.Report[any, any], 0) |
| 42 | + |
| 43 | + suiChains := e.BlockChains.SuiChains() |
| 44 | + suiChain := suiChains[config.SuiChainSelector] |
| 45 | + |
| 46 | + deps := sui_ops.OpTxDeps{ |
| 47 | + Client: suiChain.Client, |
| 48 | + Signer: suiChain.Signer, |
| 49 | + GetCallOpts: func() *bind.CallOpts { |
| 50 | + b := uint64(400_000_000) |
| 51 | + return &bind.CallOpts{ |
| 52 | + WaitForExecution: true, |
| 53 | + GasBudget: &b, |
| 54 | + } |
| 55 | + }, |
| 56 | + SuiRPC: suiChain.URL, |
| 57 | + } |
| 58 | + |
| 59 | + // Run ApplyFeeTokenUpdate Operation |
| 60 | + applyFeeTokenUpdateOP, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.FeeQuoterApplyFeeTokenUpdatesOp, deps, ccipops.FeeQuoterApplyFeeTokenUpdatesInput{ |
| 61 | + CCIPPackageId: state[suiChain.Selector].CCIPAddress, |
| 62 | + StateObjectId: state[suiChain.Selector].CCIPObjectRef, |
| 63 | + OwnerCapObjectId: state[suiChain.Selector].CCIPOwnerCapObjectId, |
| 64 | + FeeTokensToRemove: config.FeeTokensToRemove, |
| 65 | + FeeTokensToAdd: config.FeeTokensToAdd, |
| 66 | + }) |
| 67 | + if err != nil { |
| 68 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to register receiver for Sui chain %d: %w", config.SuiChainSelector, err) |
| 69 | + } |
| 70 | + |
| 71 | + seqReports = append(seqReports, []operations.Report[any, any]{applyFeeTokenUpdateOP.ToGenericReport()}...) |
| 72 | + |
| 73 | + // Run ApplyPremiumMultiplier |
| 74 | + applyPremiumMultiplierOP, err := operations.ExecuteOperation(e.OperationsBundle, ccipops.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesOp, deps, ccipops.FeeQuoterApplyPremiumMultiplierWeiPerEthUpdatesInput{ |
| 75 | + CCIPPackageId: state[suiChain.Selector].CCIPAddress, |
| 76 | + StateObjectId: state[suiChain.Selector].CCIPObjectRef, |
| 77 | + OwnerCapObjectId: state[suiChain.Selector].CCIPOwnerCapObjectId, |
| 78 | + Tokens: config.FeeTokensToAdd, |
| 79 | + PremiumMultiplierWeiPerEth: config.PremiumMultiplierWeiPerEth, |
| 80 | + }) |
| 81 | + if err != nil { |
| 82 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to register receiver for Sui chain %d: %w", config.SuiChainSelector, err) |
| 83 | + } |
| 84 | + |
| 85 | + seqReports = append(seqReports, []operations.Report[any, any]{applyPremiumMultiplierOP.ToGenericReport()}...) |
| 86 | + |
| 87 | + return cldf.ChangesetOutput{ |
| 88 | + AddressBook: ab, |
| 89 | + Reports: seqReports, |
| 90 | + }, nil |
| 91 | +} |
| 92 | + |
| 93 | +// VerifyPreconditions implements deployment.ChangeSetV2. |
| 94 | +func (d NewFeeToken) VerifyPreconditions(e cldf.Environment, config NewFeeTokenConfig) error { |
| 95 | + return nil |
| 96 | +} |
0 commit comments