|
| 1 | +package deploy |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/ethereum/go-ethereum/common" |
| 7 | + chain_selectors "github.com/smartcontractkit/chain-selectors" |
| 8 | + ccipocr3 "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" |
| 9 | + "github.com/smartcontractkit/chainlink-deployments-framework/datastore" |
| 10 | + cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" |
| 11 | + cldf_ops "github.com/smartcontractkit/chainlink-deployments-framework/operations" |
| 12 | + |
| 13 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/gobindings/generated/v1_6_0/ccip_home" |
| 14 | + "github.com/smartcontractkit/chainlink-ccip/chains/evm/deployment/internal" |
| 15 | + deploycore "github.com/smartcontractkit/chainlink-ccip/deployment/deploy" |
| 16 | + "github.com/smartcontractkit/chainlink-ccip/deployment/utils" |
| 17 | + "github.com/smartcontractkit/chainlink-ccip/deployment/utils/changesets" |
| 18 | + datastore_utils "github.com/smartcontractkit/chainlink-ccip/deployment/utils/datastore" |
| 19 | + capabilities_registry "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/capabilities_registry_1_1_0" |
| 20 | + |
| 21 | + mcms_types "github.com/smartcontractkit/mcms/types" |
| 22 | +) |
| 23 | + |
| 24 | +func SetOCR3Config(deployerReg *deploycore.DeployerRegistry, mcmsReg *changesets.MCMSReaderRegistry) cldf.ChangeSetV2[deploycore.SetOCR3ConfigArgs] { |
| 25 | + return cldf.CreateChangeSet(setOCR3ConfigApply(deployerReg, mcmsReg), setOCR3ConfigVerify(deployerReg, mcmsReg)) |
| 26 | +} |
| 27 | + |
| 28 | +func setOCR3ConfigVerify(_ *deploycore.DeployerRegistry, _ *changesets.MCMSReaderRegistry) func(cldf.Environment, deploycore.SetOCR3ConfigArgs) error { |
| 29 | + return func(e cldf.Environment, cfg deploycore.SetOCR3ConfigArgs) error { |
| 30 | + // TODO: implement |
| 31 | + return nil |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +func ocr3ConfigArgs(e cldf.Environment, homeChainSelector uint64, chainSelector uint64, configType utils.ConfigType) ([]deploycore.OCR3ConfigArgs, error) { |
| 36 | + ccipHomeAddr, err := datastore_utils.FindAndFormatRef(e.DataStore, datastore.AddressRef{ |
| 37 | + ChainSelector: homeChainSelector, |
| 38 | + Type: datastore.ContractType(utils.CCIPHome), |
| 39 | + Version: &deploycore.OCR3Version, |
| 40 | + }, homeChainSelector, datastore_utils.FullRef) |
| 41 | + if err != nil { |
| 42 | + return nil, fmt.Errorf("failed to find CCIPHome address in datastore: %w", err) |
| 43 | + } |
| 44 | + |
| 45 | + ccipHome, err := ccip_home.NewCCIPHome(common.HexToAddress(ccipHomeAddr.Address), e.BlockChains.EVMChains()[homeChainSelector].Client) |
| 46 | + if err != nil { |
| 47 | + return nil, fmt.Errorf("failed to instantiate CCIPHome contract: %w", err) |
| 48 | + } |
| 49 | + |
| 50 | + crAddr, err := datastore_utils.FindAndFormatRef(e.DataStore, datastore.AddressRef{ |
| 51 | + ChainSelector: homeChainSelector, |
| 52 | + Type: datastore.ContractType(utils.CapabilitiesRegistry), |
| 53 | + Version: &deploycore.CapabilitiesRegistryVersion, |
| 54 | + }, homeChainSelector, datastore_utils.FullRef) |
| 55 | + if err != nil { |
| 56 | + return nil, fmt.Errorf("failed to find CapabilitiesRegistry address in datastore: %w", err) |
| 57 | + } |
| 58 | + |
| 59 | + cr, err := capabilities_registry.NewCapabilitiesRegistry(common.HexToAddress(crAddr.Address), e.BlockChains.EVMChains()[homeChainSelector].Client) |
| 60 | + if err != nil { |
| 61 | + return nil, fmt.Errorf("failed to instantiate CapabilitiesRegistry contract: %w", err) |
| 62 | + } |
| 63 | + donID, err := internal.DonIDForChain( |
| 64 | + cr, |
| 65 | + ccipHome, |
| 66 | + chainSelector, |
| 67 | + ) |
| 68 | + if err != nil { |
| 69 | + return nil, fmt.Errorf("failed to get DON ID: %w", err) |
| 70 | + } |
| 71 | + |
| 72 | + if configType == "" { |
| 73 | + configType = utils.ConfigTypeActive |
| 74 | + } |
| 75 | + |
| 76 | + ocr3Args, err := internal.BuildSetOCR3ConfigArgs( |
| 77 | + donID, |
| 78 | + ccipHome, |
| 79 | + chainSelector, |
| 80 | + configType, |
| 81 | + ) |
| 82 | + if err != nil { |
| 83 | + return nil, fmt.Errorf("failed to build OCR3 config args: %w", err) |
| 84 | + } |
| 85 | + |
| 86 | + var args []deploycore.OCR3ConfigArgs |
| 87 | + for _, arg := range ocr3Args { |
| 88 | + args = append(args, deploycore.OCR3ConfigArgs{ |
| 89 | + ConfigDigest: arg.ConfigDigest, |
| 90 | + PluginType: ccipocr3.PluginType(arg.OcrPluginType), |
| 91 | + F: arg.F, |
| 92 | + IsSignatureVerificationEnabled: arg.IsSignatureVerificationEnabled, |
| 93 | + Signers: arg.Signers, |
| 94 | + Transmitters: arg.Transmitters, |
| 95 | + }) |
| 96 | + } |
| 97 | + return args, nil |
| 98 | +} |
| 99 | + |
| 100 | +func setOCR3ConfigApply(d *deploycore.DeployerRegistry, mcmsRegistry *changesets.MCMSReaderRegistry) func(cldf.Environment, deploycore.SetOCR3ConfigArgs) (cldf.ChangesetOutput, error) { |
| 101 | + return func(e cldf.Environment, cfg deploycore.SetOCR3ConfigArgs) (cldf.ChangesetOutput, error) { |
| 102 | + reports := make([]cldf_ops.Report[any, any], 0) |
| 103 | + batchOps := make([]mcms_types.BatchOperation, 0) |
| 104 | + for _, selector := range cfg.RemoteChainSels { |
| 105 | + family, err := chain_selectors.GetSelectorFamily(selector) |
| 106 | + if err != nil { |
| 107 | + return cldf.ChangesetOutput{}, err |
| 108 | + } |
| 109 | + adapter, exists := d.GetDeployer(family, &deploycore.OCR3Version) |
| 110 | + if !exists { |
| 111 | + return cldf.ChangesetOutput{}, fmt.Errorf("no deployer registered for chain family %s and version %s", family, deploycore.OCR3Version.String()) |
| 112 | + } |
| 113 | + args, err := ocr3ConfigArgs(e, cfg.HomeChainSel, selector, cfg.ConfigType) |
| 114 | + if err != nil { |
| 115 | + return cldf.ChangesetOutput{}, err |
| 116 | + } |
| 117 | + configs := make(map[ccipocr3.PluginType]deploycore.OCR3ConfigArgs, 2) |
| 118 | + for _, arg := range args { |
| 119 | + configs[arg.PluginType] = arg |
| 120 | + } |
| 121 | + ocrReport, err := cldf_ops.ExecuteSequence(e.OperationsBundle, adapter.SetOCR3Config(), e.BlockChains, |
| 122 | + deploycore.SetOCR3ConfigInput{ |
| 123 | + ChainSelector: selector, |
| 124 | + Datastore: e.DataStore, |
| 125 | + Configs: configs, |
| 126 | + }) |
| 127 | + if err != nil { |
| 128 | + return cldf.ChangesetOutput{}, fmt.Errorf("failed to deploy Contract on chain with selector %d: %w", selector, err) |
| 129 | + } |
| 130 | + reports = append(reports, ocrReport.ExecutionReports...) |
| 131 | + batchOps = append(batchOps, ocrReport.Output.BatchOps...) |
| 132 | + } |
| 133 | + |
| 134 | + return changesets.NewOutputBuilder(e, mcmsRegistry). |
| 135 | + WithReports(reports). |
| 136 | + WithBatchOps(batchOps). |
| 137 | + Build(cfg.MCMS) |
| 138 | + } |
| 139 | +} |
0 commit comments