From 9c7b487ebd7018422f055b286860f4530332d8a0 Mon Sep 17 00:00:00 2001 From: Makram Date: Thu, 28 Nov 2024 08:17:28 +0400 Subject: [PATCH] deployment/ccip/changeset: add transfer/accept ownership changeset (#15409) * wip * add test * make the proposal multichain * add transfer ownership changeset use these changesets in other tests and axe duplicate code * fix add_chain_test.go * extract common code to func * move changeset to common Refactor the proposal helpers a bit * move transfer ownership cs to common * fix * bump boost significantly the AddChainInbound test is consistently failing with a "message too costly" error in exec; increasing the relative boost per wait hour causes exec to significantly boost the paid fee so we can execute the message. --- .../ccip/changeset/accept_ownership_test.go | 207 ++++++++++++++++++ deployment/ccip/changeset/active_candidate.go | 49 ++++- .../ccip/changeset/active_candidate_test.go | 43 +++- deployment/ccip/changeset/add_chain.go | 44 +++- deployment/ccip/changeset/add_chain_test.go | 62 ++---- .../changeset/internal/deploy_home_chain.go | 2 +- deployment/ccip/changeset/ownership.go | 37 ---- deployment/ccip/changeset/propose.go | 128 ----------- deployment/ccip/changeset/test_helpers.go | 6 +- .../common/changeset/accept_ownership.go | 104 +++++++++ .../common/changeset/accept_ownership_test.go | 75 +++++++ deployment/common/changeset/internal/mcms.go | 2 +- .../common/changeset/transfer_ownership.go | 70 ++++++ deployment/common/proposalutils/propose.go | 77 +++++++ 14 files changed, 674 insertions(+), 232 deletions(-) create mode 100644 deployment/ccip/changeset/accept_ownership_test.go delete mode 100644 deployment/ccip/changeset/ownership.go delete mode 100644 deployment/ccip/changeset/propose.go create mode 100644 deployment/common/changeset/accept_ownership.go create mode 100644 deployment/common/changeset/accept_ownership_test.go create mode 100644 deployment/common/changeset/transfer_ownership.go create mode 100644 deployment/common/proposalutils/propose.go diff --git a/deployment/ccip/changeset/accept_ownership_test.go b/deployment/ccip/changeset/accept_ownership_test.go new file mode 100644 index 00000000000..c3407e0e6e7 --- /dev/null +++ b/deployment/ccip/changeset/accept_ownership_test.go @@ -0,0 +1,207 @@ +package changeset + +import ( + "math/big" + "testing" + "time" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" + "github.com/smartcontractkit/chainlink/deployment" + commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" + commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" + + "github.com/smartcontractkit/chainlink/v2/core/logger" + "github.com/stretchr/testify/require" + "golang.org/x/exp/maps" +) + +func Test_NewAcceptOwnershipChangeset(t *testing.T) { + e := NewMemoryEnvironmentWithJobs(t, logger.TestLogger(t), 2, 4) + state, err := LoadOnchainState(e.Env) + require.NoError(t, err) + + allChains := maps.Keys(e.Env.Chains) + source := allChains[0] + dest := allChains[1] + + newAddresses := deployment.NewMemoryAddressBook() + err = deployPrerequisiteChainContracts(e.Env, newAddresses, allChains, nil) + require.NoError(t, err) + require.NoError(t, e.Env.ExistingAddresses.Merge(newAddresses)) + + mcmConfig := commontypes.MCMSWithTimelockConfig{ + Canceller: commonchangeset.SingleGroupMCMS(t), + Bypasser: commonchangeset.SingleGroupMCMS(t), + Proposer: commonchangeset.SingleGroupMCMS(t), + TimelockExecutors: e.Env.AllDeployerKeys(), + TimelockMinDelay: big.NewInt(0), + } + out, err := commonchangeset.DeployMCMSWithTimelock(e.Env, map[uint64]commontypes.MCMSWithTimelockConfig{ + source: mcmConfig, + dest: mcmConfig, + }) + require.NoError(t, err) + require.NoError(t, e.Env.ExistingAddresses.Merge(out.AddressBook)) + newAddresses = deployment.NewMemoryAddressBook() + tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds) + ocrParams := make(map[uint64]CCIPOCRParams) + for _, chain := range allChains { + ocrParams[chain] = DefaultOCRParams(e.FeedChainSel, nil) + } + err = deployCCIPContracts(e.Env, newAddresses, NewChainsConfig{ + HomeChainSel: e.HomeChainSel, + FeedChainSel: e.FeedChainSel, + ChainsToDeploy: allChains, + TokenConfig: tokenConfig, + OCRSecrets: deployment.XXXGenerateTestOCRSecrets(), + OCRParams: ocrParams, + }) + require.NoError(t, err) + + // at this point we have the initial deploys done, now we need to transfer ownership + // to the timelock contract + state, err = LoadOnchainState(e.Env) + require.NoError(t, err) + + // compose the transfer ownership and accept ownership changesets + _, err = commonchangeset.ApplyChangesets(t, e.Env, map[uint64]*gethwrappers.RBACTimelock{ + source: state.Chains[source].Timelock, + dest: state.Chains[dest].Timelock, + }, []commonchangeset.ChangesetApplication{ + // note this doesn't have proposals. + { + Changeset: commonchangeset.WrapChangeSet(commonchangeset.NewTransferOwnershipChangeset), + Config: genTestTransferOwnershipConfig(e, allChains, state), + }, + // this has proposals, ApplyChangesets will sign & execute them. + // in practice, signing and executing are separated processes. + { + Changeset: commonchangeset.WrapChangeSet(commonchangeset.NewAcceptOwnershipChangeset), + Config: genTestAcceptOwnershipConfig(e, allChains, state), + }, + }) + require.NoError(t, err) + + assertTimelockOwnership(t, e, allChains, state) +} + +func genTestTransferOwnershipConfig( + e DeployedEnv, + chains []uint64, + state CCIPOnChainState, +) commonchangeset.TransferOwnershipConfig { + var ( + timelocksPerChain = make(map[uint64]common.Address) + contracts = make(map[uint64][]commonchangeset.OwnershipTransferrer) + ) + + // chain contracts + for _, chain := range chains { + timelocksPerChain[chain] = state.Chains[chain].Timelock.Address() + contracts[chain] = []commonchangeset.OwnershipTransferrer{ + state.Chains[chain].OnRamp, + state.Chains[chain].OffRamp, + state.Chains[chain].FeeQuoter, + state.Chains[chain].NonceManager, + state.Chains[chain].RMNRemote, + } + } + + // home chain + homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address() + timelocksPerChain[e.HomeChainSel] = homeChainTimelockAddress + contracts[e.HomeChainSel] = append(contracts[e.HomeChainSel], + state.Chains[e.HomeChainSel].CapabilityRegistry, + state.Chains[e.HomeChainSel].CCIPHome, + state.Chains[e.HomeChainSel].RMNHome, + ) + + return commonchangeset.TransferOwnershipConfig{ + TimelocksPerChain: timelocksPerChain, + Contracts: contracts, + } +} + +func genTestAcceptOwnershipConfig( + e DeployedEnv, + chains []uint64, + state CCIPOnChainState, +) commonchangeset.AcceptOwnershipConfig { + var ( + timelocksPerChain = make(map[uint64]common.Address) + proposerMCMses = make(map[uint64]*gethwrappers.ManyChainMultiSig) + contracts = make(map[uint64][]commonchangeset.OwnershipAcceptor) + ) + for _, chain := range chains { + timelocksPerChain[chain] = state.Chains[chain].Timelock.Address() + proposerMCMses[chain] = state.Chains[chain].ProposerMcm + contracts[chain] = []commonchangeset.OwnershipAcceptor{ + state.Chains[chain].OnRamp, + state.Chains[chain].OffRamp, + state.Chains[chain].FeeQuoter, + state.Chains[chain].NonceManager, + state.Chains[chain].RMNRemote, + } + } + + // add home chain contracts. + // this overwrite should be fine. + timelocksPerChain[e.HomeChainSel] = state.Chains[e.HomeChainSel].Timelock.Address() + proposerMCMses[e.HomeChainSel] = state.Chains[e.HomeChainSel].ProposerMcm + contracts[e.HomeChainSel] = append(contracts[e.HomeChainSel], + state.Chains[e.HomeChainSel].CapabilityRegistry, + state.Chains[e.HomeChainSel].CCIPHome, + state.Chains[e.HomeChainSel].RMNHome, + ) + + return commonchangeset.AcceptOwnershipConfig{ + TimelocksPerChain: timelocksPerChain, + ProposerMCMSes: proposerMCMses, + Contracts: contracts, + MinDelay: time.Duration(0), + } +} + +// assertTimelockOwnership asserts that the ownership of the contracts has been transferred +// to the appropriate timelock contract on each chain. +func assertTimelockOwnership( + t *testing.T, + e DeployedEnv, + chains []uint64, + state CCIPOnChainState, +) { + ctx := tests.Context(t) + // check that the ownership has been transferred correctly + for _, chain := range chains { + for _, contract := range []commonchangeset.OwnershipTransferrer{ + state.Chains[chain].OnRamp, + state.Chains[chain].OffRamp, + state.Chains[chain].FeeQuoter, + state.Chains[chain].NonceManager, + state.Chains[chain].RMNRemote, + } { + owner, err := contract.Owner(&bind.CallOpts{ + Context: ctx, + }) + require.NoError(t, err) + require.Equal(t, state.Chains[chain].Timelock.Address(), owner) + } + } + + // check home chain contracts ownership + homeChainTimelockAddress := state.Chains[e.HomeChainSel].Timelock.Address() + for _, contract := range []commonchangeset.OwnershipTransferrer{ + state.Chains[e.HomeChainSel].CapabilityRegistry, + state.Chains[e.HomeChainSel].CCIPHome, + state.Chains[e.HomeChainSel].RMNHome, + } { + owner, err := contract.Owner(&bind.CallOpts{ + Context: ctx, + }) + require.NoError(t, err) + require.Equal(t, homeChainTimelockAddress, owner) + } +} diff --git a/deployment/ccip/changeset/active_candidate.go b/deployment/ccip/changeset/active_candidate.go index bc2ac2a208c..bc65cef71e7 100644 --- a/deployment/ccip/changeset/active_candidate.go +++ b/deployment/ccip/changeset/active_candidate.go @@ -3,16 +3,20 @@ package changeset import ( "fmt" + "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" ) // PromoteAllCandidatesChangeset generates a proposal to call promoteCandidate on the CCIPHome through CapReg. // This needs to be called after SetCandidateProposal is executed. +// TODO: make it conform to the ChangeSet interface. func PromoteAllCandidatesChangeset( state CCIPOnChainState, homeChainSel, newChainSel uint64, @@ -28,10 +32,24 @@ func PromoteAllCandidatesChangeset( return deployment.ChangesetOutput{}, err } - prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ - ChainIdentifier: mcms.ChainIdentifier(homeChainSel), - Batch: promoteCandidateOps, - }}, "promoteCandidate for commit and execution", 0) + var ( + timelocksPerChain = map[uint64]common.Address{ + homeChainSel: state.Chains[homeChainSel].Timelock.Address(), + } + proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{ + homeChainSel: state.Chains[homeChainSel].ProposerMcm, + } + ) + prop, err := proposalutils.BuildProposalFromBatches( + timelocksPerChain, + proposerMCMSes, + []timelock.BatchChainOperation{{ + ChainIdentifier: mcms.ChainIdentifier(homeChainSel), + Batch: promoteCandidateOps, + }}, + "promoteCandidate for commit and execution", + 0, // minDelay + ) if err != nil { return deployment.ChangesetOutput{}, err } @@ -43,6 +61,7 @@ func PromoteAllCandidatesChangeset( } // SetCandidateExecPluginProposal calls setCandidate on the CCIPHome for setting up OCR3 exec Plugin config for the new chain. +// TODO: make it conform to the ChangeSet interface. func SetCandidatePluginChangeset( state CCIPOnChainState, e deployment.Environment, @@ -86,10 +105,24 @@ func SetCandidatePluginChangeset( return deployment.ChangesetOutput{}, err } - prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ - ChainIdentifier: mcms.ChainIdentifier(homeChainSel), - Batch: setCandidateMCMSOps, - }}, "SetCandidate for execution", 0) + var ( + timelocksPerChain = map[uint64]common.Address{ + homeChainSel: state.Chains[homeChainSel].Timelock.Address(), + } + proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{ + homeChainSel: state.Chains[homeChainSel].ProposerMcm, + } + ) + prop, err := proposalutils.BuildProposalFromBatches( + timelocksPerChain, + proposerMCMSes, + []timelock.BatchChainOperation{{ + ChainIdentifier: mcms.ChainIdentifier(homeChainSel), + Batch: setCandidateMCMSOps, + }}, + "SetCandidate for execution", + 0, // minDelay + ) if err != nil { return deployment.ChangesetOutput{}, err } diff --git a/deployment/ccip/changeset/active_candidate_test.go b/deployment/ccip/changeset/active_candidate_test.go index baa051385e6..70280a33bb0 100644 --- a/deployment/ccip/changeset/active_candidate_test.go +++ b/deployment/ccip/changeset/active_candidate_test.go @@ -4,8 +4,10 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" + "golang.org/x/exp/maps" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" @@ -18,6 +20,7 @@ import ( "github.com/stretchr/testify/require" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/v2/core/logger" ) @@ -30,6 +33,7 @@ func TestActiveCandidate(t *testing.T) { e := tenv.Env state, err := LoadOnchainState(tenv.Env) require.NoError(t, err) + allChains := maps.Keys(e.Chains) // Add all lanes require.NoError(t, AddLanesForAll(e, state)) @@ -80,14 +84,25 @@ func TestActiveCandidate(t *testing.T) { //Wait for all exec reports to land ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks) - // transfer ownership - TransferAllOwnership(t, state, tenv.HomeChainSel, e) - acceptOwnershipProposal, err := GenerateAcceptOwnershipProposal(state, tenv.HomeChainSel, e.AllChainSelectors()) - require.NoError(t, err) - acceptOwnershipExec := commonchangeset.SignProposal(t, e, acceptOwnershipProposal) - for _, sel := range e.AllChainSelectors() { - commonchangeset.ExecuteProposal(t, e, acceptOwnershipExec, state.Chains[sel].Timelock, sel) + // compose the transfer ownership and accept ownership changesets + timelocks := make(map[uint64]*gethwrappers.RBACTimelock) + for _, chain := range allChains { + timelocks[chain] = state.Chains[chain].Timelock } + _, err = commonchangeset.ApplyChangesets(t, e, timelocks, []commonchangeset.ChangesetApplication{ + // note this doesn't have proposals. + { + Changeset: commonchangeset.WrapChangeSet(commonchangeset.NewTransferOwnershipChangeset), + Config: genTestTransferOwnershipConfig(tenv, allChains, state), + }, + // this has proposals, ApplyChangesets will sign & execute them. + // in practice, signing and executing are separated processes. + { + Changeset: commonchangeset.WrapChangeSet(commonchangeset.NewAcceptOwnershipChangeset), + Config: genTestAcceptOwnershipConfig(tenv, allChains, state), + }, + }) + require.NoError(t, err) // Apply the accept ownership proposal to all the chains. err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 2) @@ -139,6 +154,14 @@ func TestActiveCandidate(t *testing.T) { ) require.NoError(t, err) + var ( + timelocksPerChain = map[uint64]common.Address{ + tenv.HomeChainSel: state.Chains[tenv.HomeChainSel].Timelock.Address(), + } + proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{ + tenv.HomeChainSel: state.Chains[tenv.HomeChainSel].ProposerMcm, + } + ) setCommitCandidateOp, err := SetCandidateOnExistingDon( ocr3ConfigMap[cctypes.PluginTypeCCIPCommit], state.Chains[tenv.HomeChainSel].CapabilityRegistry, @@ -147,7 +170,7 @@ func TestActiveCandidate(t *testing.T) { nodes.NonBootstraps(), ) require.NoError(t, err) - setCommitCandidateProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + setCommitCandidateProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), Batch: setCommitCandidateOp, }}, "set new candidates on commit plugin", 0) @@ -165,7 +188,7 @@ func TestActiveCandidate(t *testing.T) { ) require.NoError(t, err) - setExecCandidateProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + setExecCandidateProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), Batch: setExecCandidateOp, }}, "set new candidates on commit and exec plugins", 0) @@ -192,7 +215,7 @@ func TestActiveCandidate(t *testing.T) { promoteOps, err := PromoteAllCandidatesForChainOps(state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps()) require.NoError(t, err) - promoteProposal, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ + promoteProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), Batch: promoteOps, }}, "promote candidates and revoke actives", 0) diff --git a/deployment/ccip/changeset/add_chain.go b/deployment/ccip/changeset/add_chain.go index b129fefaea0..d97915c4022 100644 --- a/deployment/ccip/changeset/add_chain.go +++ b/deployment/ccip/changeset/add_chain.go @@ -4,9 +4,12 @@ import ( "fmt" "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" @@ -17,6 +20,7 @@ import ( // NewChainInboundChangeset generates a proposal // to connect the new chain to the existing chains. +// TODO: doesn't implement the ChangeSet interface. func NewChainInboundChangeset( e deployment.Environment, state CCIPOnChainState, @@ -77,7 +81,21 @@ func NewChainInboundChangeset( }, }) - prop, err := BuildProposalFromBatches(state, batches, "proposal to set new chains", 0) + var ( + timelocksPerChain = make(map[uint64]common.Address) + proposerMCMSes = make(map[uint64]*gethwrappers.ManyChainMultiSig) + ) + for _, chain := range append(sources, homeChainSel) { + timelocksPerChain[chain] = state.Chains[chain].Timelock.Address() + proposerMCMSes[chain] = state.Chains[chain].ProposerMcm + } + prop, err := proposalutils.BuildProposalFromBatches( + timelocksPerChain, + proposerMCMSes, + batches, + "proposal to set new chains", + 0, + ) if err != nil { return deployment.ChangesetOutput{}, err } @@ -133,12 +151,26 @@ func AddDonAndSetCandidateChangeset( return deployment.ChangesetOutput{}, err } - prop, err := BuildProposalFromBatches(state, []timelock.BatchChainOperation{{ - ChainIdentifier: mcms.ChainIdentifier(homeChainSel), - Batch: []mcms.Operation{addDonOp}, - }}, "setCandidate for commit and AddDon on new Chain", 0) + var ( + timelocksPerChain = map[uint64]common.Address{ + homeChainSel: state.Chains[homeChainSel].Timelock.Address(), + } + proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{ + homeChainSel: state.Chains[homeChainSel].ProposerMcm, + } + ) + prop, err := proposalutils.BuildProposalFromBatches( + timelocksPerChain, + proposerMCMSes, + []timelock.BatchChainOperation{{ + ChainIdentifier: mcms.ChainIdentifier(homeChainSel), + Batch: []mcms.Operation{addDonOp}, + }}, + "setCandidate for commit and AddDon on new Chain", + 0, // minDelay + ) if err != nil { - return deployment.ChangesetOutput{}, err + return deployment.ChangesetOutput{}, fmt.Errorf("failed to build proposal from batch: %w", err) } return deployment.ChangesetOutput{ diff --git a/deployment/ccip/changeset/add_chain_test.go b/deployment/ccip/changeset/add_chain_test.go index db19cd5fa41..39ae27f9444 100644 --- a/deployment/ccip/changeset/add_chain_test.go +++ b/deployment/ccip/changeset/add_chain_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" @@ -107,18 +108,9 @@ func TestAddChainInbound(t *testing.T) { state, err = LoadOnchainState(e.Env) require.NoError(t, err) - // Transfer onramp/fq ownership to timelock. - // Enable the new dest on the test router. + // configure the testrouter appropriately on each chain for _, source := range initialDeploy { - tx, err := state.Chains[source].OnRamp.TransferOwnership(e.Env.Chains[source].DeployerKey, state.Chains[source].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) - require.NoError(t, err) - tx, err = state.Chains[source].FeeQuoter.TransferOwnership(e.Env.Chains[source].DeployerKey, state.Chains[source].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) - require.NoError(t, err) - tx, err = state.Chains[source].TestRouter.ApplyRampUpdates(e.Env.Chains[source].DeployerKey, []router.RouterOnRamp{ + tx, err := state.Chains[source].TestRouter.ApplyRampUpdates(e.Env.Chains[source].DeployerKey, []router.RouterOnRamp{ { DestChainSelector: newChain, OnRamp: state.Chains[source].OnRamp.Address(), @@ -127,34 +119,28 @@ func TestAddChainInbound(t *testing.T) { _, err = deployment.ConfirmIfNoError(e.Env.Chains[source], tx, err) require.NoError(t, err) } - // Transfer CR contract ownership - tx, err := state.Chains[e.HomeChainSel].CapabilityRegistry.TransferOwnership(e.Env.Chains[e.HomeChainSel].DeployerKey, state.Chains[e.HomeChainSel].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[e.HomeChainSel], tx, err) - require.NoError(t, err) - tx, err = state.Chains[e.HomeChainSel].CCIPHome.TransferOwnership(e.Env.Chains[e.HomeChainSel].DeployerKey, state.Chains[e.HomeChainSel].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Env.Chains[e.HomeChainSel], tx, err) - require.NoError(t, err) - acceptOwnershipProposal, err := GenerateAcceptOwnershipProposal(state, e.HomeChainSel, initialDeploy) - require.NoError(t, err) - acceptOwnershipExec := commonchangeset.SignProposal(t, e.Env, acceptOwnershipProposal) - // Apply the accept ownership proposal to all the chains. - for _, sel := range initialDeploy { - commonchangeset.ExecuteProposal(t, e.Env, acceptOwnershipExec, state.Chains[sel].Timelock, sel) - } - for _, chain := range initialDeploy { - owner, err2 := state.Chains[chain].OnRamp.Owner(nil) - require.NoError(t, err2) - require.Equal(t, state.Chains[chain].Timelock.Address(), owner) - } - cfgOwner, err := state.Chains[e.HomeChainSel].CCIPHome.Owner(nil) - require.NoError(t, err) - crOwner, err := state.Chains[e.HomeChainSel].CapabilityRegistry.Owner(nil) + // transfer ownership to timelock + _, err = commonchangeset.ApplyChangesets(t, e.Env, map[uint64]*gethwrappers.RBACTimelock{ + initialDeploy[0]: state.Chains[initialDeploy[0]].Timelock, + initialDeploy[1]: state.Chains[initialDeploy[1]].Timelock, + initialDeploy[2]: state.Chains[initialDeploy[2]].Timelock, + }, []commonchangeset.ChangesetApplication{ + // note this doesn't have proposals. + { + Changeset: commonchangeset.WrapChangeSet(commonchangeset.NewTransferOwnershipChangeset), + Config: genTestTransferOwnershipConfig(e, initialDeploy, state), + }, + // this has proposals, ApplyChangesets will sign & execute them. + // in practice, signing and executing are separated processes. + { + Changeset: commonchangeset.WrapChangeSet(commonchangeset.NewAcceptOwnershipChangeset), + Config: genTestAcceptOwnershipConfig(e, initialDeploy, state), + }, + }) require.NoError(t, err) - require.Equal(t, state.Chains[e.HomeChainSel].Timelock.Address(), cfgOwner) - require.Equal(t, state.Chains[e.HomeChainSel].Timelock.Address(), crOwner) + + assertTimelockOwnership(t, e, initialDeploy, state) nodes, err := deployment.NodeInfo(e.Env.NodeIDs, e.Env.Offchain) require.NoError(t, err) @@ -202,7 +188,7 @@ func TestAddChainInbound(t *testing.T) { OnRamp: common.LeftPadBytes(state.Chains[source].OnRamp.Address().Bytes(), 32), }) } - tx, err = state.Chains[newChain].OffRamp.ApplySourceChainConfigUpdates(e.Env.Chains[newChain].DeployerKey, offRampEnables) + tx, err := state.Chains[newChain].OffRamp.ApplySourceChainConfigUpdates(e.Env.Chains[newChain].DeployerKey, offRampEnables) require.NoError(t, err) _, err = deployment.ConfirmIfNoError(e.Env.Chains[newChain], tx, err) require.NoError(t, err) diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index 7b45a52a436..27052b04d07 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -30,7 +30,7 @@ const ( RemoteGasPriceBatchWriteFrequency = 30 * time.Minute TokenPriceBatchWriteFrequency = 30 * time.Minute BatchGasLimit = 6_500_000 - RelativeBoostPerWaitHour = 1.5 + RelativeBoostPerWaitHour = 10000.5 InflightCacheExpiry = 10 * time.Minute RootSnoozeTime = 30 * time.Minute BatchingStrategyID = 0 diff --git a/deployment/ccip/changeset/ownership.go b/deployment/ccip/changeset/ownership.go deleted file mode 100644 index 4287363b8a6..00000000000 --- a/deployment/ccip/changeset/ownership.go +++ /dev/null @@ -1,37 +0,0 @@ -package changeset - -import ( - "testing" - - "github.com/stretchr/testify/require" - - "github.com/smartcontractkit/chainlink/deployment" -) - -func TransferAllOwnership(t *testing.T, state CCIPOnChainState, homeCS uint64, e deployment.Environment) { - for _, source := range e.AllChainSelectors() { - if state.Chains[source].OnRamp != nil { - tx, err := state.Chains[source].OnRamp.TransferOwnership(e.Chains[source].DeployerKey, state.Chains[source].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Chains[source], tx, err) - require.NoError(t, err) - } - if state.Chains[source].FeeQuoter != nil { - tx, err := state.Chains[source].FeeQuoter.TransferOwnership(e.Chains[source].DeployerKey, state.Chains[source].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Chains[source], tx, err) - require.NoError(t, err) - } - // TODO: add offramp and commit stores - - } - // Transfer CR contract ownership - tx, err := state.Chains[homeCS].CapabilityRegistry.TransferOwnership(e.Chains[homeCS].DeployerKey, state.Chains[homeCS].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Chains[homeCS], tx, err) - require.NoError(t, err) - tx, err = state.Chains[homeCS].CCIPHome.TransferOwnership(e.Chains[homeCS].DeployerKey, state.Chains[homeCS].Timelock.Address()) - require.NoError(t, err) - _, err = deployment.ConfirmIfNoError(e.Chains[homeCS], tx, err) - require.NoError(t, err) -} diff --git a/deployment/ccip/changeset/propose.go b/deployment/ccip/changeset/propose.go deleted file mode 100644 index 1b7d928f414..00000000000 --- a/deployment/ccip/changeset/propose.go +++ /dev/null @@ -1,128 +0,0 @@ -package changeset - -import ( - "fmt" - "math/big" - "time" - - mapset "github.com/deckarep/golang-set/v2" - "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" - "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" - chainsel "github.com/smartcontractkit/chain-selectors" - - "github.com/smartcontractkit/chainlink/deployment" -) - -func GenerateAcceptOwnershipProposal( - state CCIPOnChainState, - homeChain uint64, - chains []uint64, -) (*timelock.MCMSWithTimelockProposal, error) { - // TODO: Accept rest of contracts - var batches []timelock.BatchChainOperation - for _, sel := range chains { - chain, _ := chainsel.ChainBySelector(sel) - acceptOnRamp, err := state.Chains[sel].OnRamp.AcceptOwnership(deployment.SimTransactOpts()) - if err != nil { - return nil, err - } - acceptFeeQuoter, err := state.Chains[sel].FeeQuoter.AcceptOwnership(deployment.SimTransactOpts()) - if err != nil { - return nil, err - } - chainSel := mcms.ChainIdentifier(chain.Selector) - batches = append(batches, timelock.BatchChainOperation{ - ChainIdentifier: chainSel, - Batch: []mcms.Operation{ - { - To: state.Chains[sel].OnRamp.Address(), - Data: acceptOnRamp.Data(), - Value: big.NewInt(0), - }, - { - To: state.Chains[sel].FeeQuoter.Address(), - Data: acceptFeeQuoter.Data(), - Value: big.NewInt(0), - }, - }, - }) - } - - acceptCR, err := state.Chains[homeChain].CapabilityRegistry.AcceptOwnership(deployment.SimTransactOpts()) - if err != nil { - return nil, err - } - acceptCCIPConfig, err := state.Chains[homeChain].CCIPHome.AcceptOwnership(deployment.SimTransactOpts()) - if err != nil { - return nil, err - } - homeChainID := mcms.ChainIdentifier(homeChain) - batches = append(batches, timelock.BatchChainOperation{ - ChainIdentifier: homeChainID, - Batch: []mcms.Operation{ - { - To: state.Chains[homeChain].CapabilityRegistry.Address(), - Data: acceptCR.Data(), - Value: big.NewInt(0), - }, - { - To: state.Chains[homeChain].CCIPHome.Address(), - Data: acceptCCIPConfig.Data(), - Value: big.NewInt(0), - }, - }, - }) - - return BuildProposalFromBatches(state, batches, "accept ownership operations", 0) -} - -func BuildProposalMetadata(state CCIPOnChainState, chains []uint64) (map[mcms.ChainIdentifier]common.Address, map[mcms.ChainIdentifier]mcms.ChainMetadata, error) { - tlAddressMap := make(map[mcms.ChainIdentifier]common.Address) - metaDataPerChain := make(map[mcms.ChainIdentifier]mcms.ChainMetadata) - for _, sel := range chains { - chainId := mcms.ChainIdentifier(sel) - tlAddressMap[chainId] = state.Chains[sel].Timelock.Address() - mcm := state.Chains[sel].ProposerMcm - opCount, err := mcm.GetOpCount(nil) - if err != nil { - return nil, nil, err - } - metaDataPerChain[chainId] = mcms.ChainMetadata{ - StartingOpCount: opCount.Uint64(), - MCMAddress: mcm.Address(), - } - } - return tlAddressMap, metaDataPerChain, nil -} - -// Given batches of operations, we build the metadata and timelock addresses of those opartions -// We then return a proposal that can be executed and signed -func BuildProposalFromBatches(state CCIPOnChainState, batches []timelock.BatchChainOperation, description string, minDelay time.Duration) (*timelock.MCMSWithTimelockProposal, error) { - if len(batches) == 0 { - return nil, fmt.Errorf("no operations in batch") - } - - chains := mapset.NewSet[uint64]() - for _, op := range batches { - chains.Add(uint64(op.ChainIdentifier)) - } - - tls, mcmsMd, err := BuildProposalMetadata(state, chains.ToSlice()) - if err != nil { - return nil, err - } - - return timelock.NewMCMSWithTimelockProposal( - "1", - 2004259681, // TODO: should be parameterized and based on current block timestamp. - []mcms.Signature{}, - false, - mcmsMd, - tls, - description, - batches, - timelock.Schedule, - minDelay.String(), - ) -} diff --git a/deployment/ccip/changeset/test_helpers.go b/deployment/ccip/changeset/test_helpers.go index f7cc812b2e3..a0bd3a0f56d 100644 --- a/deployment/ccip/changeset/test_helpers.go +++ b/deployment/ccip/changeset/test_helpers.go @@ -432,14 +432,14 @@ func retryCcipSendUntilNativeFeeIsSufficient( for { fee, err := r.GetFee(&bind.CallOpts{Context: context.Background()}, dest, msg) if err != nil { - return nil, 0, errors.Wrap(deployment.MaybeDataErr(err), "failed to get fee") + return nil, 0, fmt.Errorf("failed to get fee: %w", deployment.MaybeDataErr(err)) } e.Chains[src].DeployerKey.Value = fee tx, err := r.CcipSend(e.Chains[src].DeployerKey, dest, msg) if err != nil { - return nil, 0, errors.Wrap(err, "failed to send CCIP message") + return nil, 0, fmt.Errorf("failed to send CCIP message: %w", err) } blockNum, err := e.Chains[src].Confirm(tx) @@ -447,7 +447,7 @@ func retryCcipSendUntilNativeFeeIsSufficient( if strings.Contains(err.Error(), errCodeInsufficientFee) { continue } - return nil, 0, errors.Wrap(err, "failed to confirm CCIP message") + return nil, 0, fmt.Errorf("failed to confirm CCIP message: %w", deployment.MaybeDataErr(err)) } return tx, blockNum, nil diff --git a/deployment/common/changeset/accept_ownership.go b/deployment/common/changeset/accept_ownership.go new file mode 100644 index 00000000000..7f89e5cb75f --- /dev/null +++ b/deployment/common/changeset/accept_ownership.go @@ -0,0 +1,104 @@ +package changeset + +import ( + "fmt" + "math/big" + "time" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + gethtypes "github.com/ethereum/go-ethereum/core/types" + + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" + "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" +) + +type OwnershipAcceptor interface { + AcceptOwnership(opts *bind.TransactOpts) (*gethtypes.Transaction, error) + Address() common.Address +} + +type AcceptOwnershipConfig struct { + // TimelocksPerChain is a mapping from chain selector to the timelock contract address on that chain. + TimelocksPerChain map[uint64]common.Address + + // ProposerMCMSes is a mapping from chain selector to the proposer MCMS contract on that chain. + ProposerMCMSes map[uint64]*gethwrappers.ManyChainMultiSig + + // Contracts is a mapping from chain selector to the ownership acceptors on that chain. + // Proposal will be generated for these contracts. + Contracts map[uint64][]OwnershipAcceptor + + // MinDelay is the minimum amount of time that must pass before the proposal + // can be executed onchain. + // This is typically set to 3 hours but can be set to 0 for immediate execution (useful for tests). + MinDelay time.Duration +} + +func (a AcceptOwnershipConfig) Validate() error { + // check that we have timelocks and proposer mcmses for the chains + // in the Contracts field. + for chainSelector := range a.Contracts { + if _, ok := a.TimelocksPerChain[chainSelector]; !ok { + return fmt.Errorf("missing timelock for chain %d", chainSelector) + } + if _, ok := a.ProposerMCMSes[chainSelector]; !ok { + return fmt.Errorf("missing proposer MCMS for chain %d", chainSelector) + } + } + + return nil +} + +// type assertion - comply with deployment.ChangeSet interface +var _ deployment.ChangeSet[AcceptOwnershipConfig] = NewAcceptOwnershipChangeset + +// NewAcceptOwnershipChangeset creates a changeset that contains a proposal to accept ownership of the contracts +// provided in the configuration. +func NewAcceptOwnershipChangeset( + e deployment.Environment, + cfg AcceptOwnershipConfig, +) (deployment.ChangesetOutput, error) { + if err := cfg.Validate(); err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("invalid accept ownership config: %w", err) + } + + var batches []timelock.BatchChainOperation + for chainSelector, ownershipAcceptors := range cfg.Contracts { + var ops []mcms.Operation + for _, ownershipAcceptor := range ownershipAcceptors { + tx, err := ownershipAcceptor.AcceptOwnership(deployment.SimTransactOpts()) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to generate accept ownership calldata of %T: %w", ownershipAcceptor, err) + } + + ops = append(ops, mcms.Operation{ + To: ownershipAcceptor.Address(), + Data: tx.Data(), + Value: big.NewInt(0), + }) + } + batches = append(batches, timelock.BatchChainOperation{ + ChainIdentifier: mcms.ChainIdentifier(chainSelector), + Batch: ops, + }) + } + + proposal, err := proposalutils.BuildProposalFromBatches( + cfg.TimelocksPerChain, + cfg.ProposerMCMSes, + batches, + "Accept ownership of contracts", + cfg.MinDelay, + ) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to build proposal from batch: %w, batches: %+v", err, batches) + } + + return deployment.ChangesetOutput{ + Proposals: []timelock.MCMSWithTimelockProposal{*proposal}, + }, nil +} diff --git a/deployment/common/changeset/accept_ownership_test.go b/deployment/common/changeset/accept_ownership_test.go new file mode 100644 index 00000000000..27feb6389bc --- /dev/null +++ b/deployment/common/changeset/accept_ownership_test.go @@ -0,0 +1,75 @@ +package changeset_test + +import ( + "testing" + "time" + + "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" + "github.com/smartcontractkit/chainlink/deployment/common/changeset" + "github.com/stretchr/testify/assert" +) + +func TestAcceptOwnershipConfig_Validate(t *testing.T) { + tests := []struct { + name string + config changeset.AcceptOwnershipConfig + wantErr bool + }{ + { + name: "valid config", + config: changeset.AcceptOwnershipConfig{ + TimelocksPerChain: map[uint64]common.Address{ + 1: common.HexToAddress("0x1"), + }, + ProposerMCMSes: map[uint64]*gethwrappers.ManyChainMultiSig{ + 1: {}, + }, + Contracts: map[uint64][]changeset.OwnershipAcceptor{ + 1: {}, + }, + MinDelay: 3 * time.Hour, + }, + wantErr: false, + }, + { + name: "missing timelock", + config: changeset.AcceptOwnershipConfig{ + TimelocksPerChain: map[uint64]common.Address{}, + ProposerMCMSes: map[uint64]*gethwrappers.ManyChainMultiSig{ + 1: {}, + }, + Contracts: map[uint64][]changeset.OwnershipAcceptor{ + 1: {}, + }, + MinDelay: 3 * time.Hour, + }, + wantErr: true, + }, + { + name: "missing proposer MCMS", + config: changeset.AcceptOwnershipConfig{ + TimelocksPerChain: map[uint64]common.Address{ + 1: common.HexToAddress("0x1"), + }, + ProposerMCMSes: map[uint64]*gethwrappers.ManyChainMultiSig{}, + Contracts: map[uint64][]changeset.OwnershipAcceptor{ + 1: {}, + }, + MinDelay: 3 * time.Hour, + }, + wantErr: true, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.config.Validate() + if tt.wantErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +} diff --git a/deployment/common/changeset/internal/mcms.go b/deployment/common/changeset/internal/mcms.go index 1e2fb958aae..5694f83786b 100644 --- a/deployment/common/changeset/internal/mcms.go +++ b/deployment/common/changeset/internal/mcms.go @@ -95,7 +95,7 @@ func DeployMCMSWithTimelockContracts( return nil, err } - timelock, err := deployment.DeployContract[*owner_helpers.RBACTimelock](lggr, chain, ab, + timelock, err := deployment.DeployContract(lggr, chain, ab, func(chain deployment.Chain) deployment.ContractDeploy[*owner_helpers.RBACTimelock] { timelock, tx2, cc, err2 := owner_helpers.DeployRBACTimelock( chain.DeployerKey, diff --git a/deployment/common/changeset/transfer_ownership.go b/deployment/common/changeset/transfer_ownership.go new file mode 100644 index 00000000000..a0085fb61ca --- /dev/null +++ b/deployment/common/changeset/transfer_ownership.go @@ -0,0 +1,70 @@ +package changeset + +import ( + "fmt" + + "github.com/ethereum/go-ethereum/accounts/abi/bind" + "github.com/ethereum/go-ethereum/common" + gethtypes "github.com/ethereum/go-ethereum/core/types" + "github.com/smartcontractkit/chainlink/deployment" +) + +type OwnershipTransferrer interface { + TransferOwnership(opts *bind.TransactOpts, newOwner common.Address) (*gethtypes.Transaction, error) + Owner(opts *bind.CallOpts) (common.Address, error) +} + +type TransferOwnershipConfig struct { + // TimelocksPerChain is a mapping from chain selector to the timelock contract address on that chain. + TimelocksPerChain map[uint64]common.Address + + // Contracts is a mapping from chain selector to the ownership transferrers on that chain. + Contracts map[uint64][]OwnershipTransferrer +} + +func (t TransferOwnershipConfig) Validate() error { + // check that we have timelocks for the chains in the Contracts field. + for chainSelector := range t.Contracts { + if _, ok := t.TimelocksPerChain[chainSelector]; !ok { + return fmt.Errorf("missing timelock for chain %d", chainSelector) + } + } + + return nil +} + +var _ deployment.ChangeSet[TransferOwnershipConfig] = NewTransferOwnershipChangeset + +// NewTransferOwnershipChangeset creates a changeset that transfers ownership of all the +// contracts in the provided configuration to the the appropriate timelock on that chain. +// If the owner is already the timelock contract, no transaction is sent. +func NewTransferOwnershipChangeset( + e deployment.Environment, + cfg TransferOwnershipConfig, +) (deployment.ChangesetOutput, error) { + if err := cfg.Validate(); err != nil { + return deployment.ChangesetOutput{}, err + } + + for chainSelector, contracts := range cfg.Contracts { + timelock := cfg.TimelocksPerChain[chainSelector] + for _, contract := range contracts { + owner, err := contract.Owner(nil) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to get owner of contract %T: %v", contract, err) + } + if owner != timelock { + tx, err := contract.TransferOwnership(e.Chains[chainSelector].DeployerKey, timelock) + _, err = deployment.ConfirmIfNoError(e.Chains[chainSelector], tx, err) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to transfer ownership of contract %T: %v", contract, err) + } + } + } + } + + // no new addresses or proposals or jobspecs, so changeset output is empty. + // NOTE: onchain state has technically changed for above contracts, maybe that should + // be captured? + return deployment.ChangesetOutput{}, nil +} diff --git a/deployment/common/proposalutils/propose.go b/deployment/common/proposalutils/propose.go new file mode 100644 index 00000000000..b4cb54af891 --- /dev/null +++ b/deployment/common/proposalutils/propose.go @@ -0,0 +1,77 @@ +package proposalutils + +import ( + "fmt" + "time" + + mapset "github.com/deckarep/golang-set/v2" + "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" + "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" +) + +func buildProposalMetadata( + chainSelectors []uint64, + proposerMcmsesPerChain map[uint64]*gethwrappers.ManyChainMultiSig, +) (map[mcms.ChainIdentifier]mcms.ChainMetadata, error) { + metaDataPerChain := make(map[mcms.ChainIdentifier]mcms.ChainMetadata) + for _, selector := range chainSelectors { + proposerMcms, ok := proposerMcmsesPerChain[selector] + if !ok { + return nil, fmt.Errorf("missing proposer mcm for chain %d", selector) + } + chainId := mcms.ChainIdentifier(selector) + opCount, err := proposerMcms.GetOpCount(nil) + if err != nil { + return nil, fmt.Errorf("failed to get op count for chain %d: %w", selector, err) + } + metaDataPerChain[chainId] = mcms.ChainMetadata{ + StartingOpCount: opCount.Uint64(), + MCMAddress: proposerMcms.Address(), + } + } + return metaDataPerChain, nil +} + +// Given batches of operations, we build the metadata and timelock addresses of those opartions +// We then return a proposal that can be executed and signed +func BuildProposalFromBatches( + timelocksPerChain map[uint64]common.Address, + proposerMcmsesPerChain map[uint64]*gethwrappers.ManyChainMultiSig, + batches []timelock.BatchChainOperation, + description string, + minDelay time.Duration, +) (*timelock.MCMSWithTimelockProposal, error) { + if len(batches) == 0 { + return nil, fmt.Errorf("no operations in batch") + } + + chains := mapset.NewSet[uint64]() + for _, op := range batches { + chains.Add(uint64(op.ChainIdentifier)) + } + + mcmsMd, err := buildProposalMetadata(chains.ToSlice(), proposerMcmsesPerChain) + if err != nil { + return nil, err + } + + tlsPerChainId := make(map[mcms.ChainIdentifier]common.Address) + for chainId, tl := range timelocksPerChain { + tlsPerChainId[mcms.ChainIdentifier(chainId)] = tl + } + + return timelock.NewMCMSWithTimelockProposal( + "1", + 2004259681, // TODO: should be parameterized and based on current block timestamp. + []mcms.Signature{}, + false, + mcmsMd, + tlsPerChainId, + description, + batches, + timelock.Schedule, + minDelay.String(), + ) +}