-
Notifications
You must be signed in to change notification settings - Fork 2k
[VAULT] EthBalMon migration into CLD #22361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bitrider23
wants to merge
37
commits into
develop
Choose a base branch
from
feat/deploy_ethbalmon
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
0b607bb
Add deploy + setKeeperRegistry changesets
bitrider23 5f11f43
Add constant to set the eth bal mon contract type
bitrider23 098e534
Change files names
bitrider23 497d267
Remove renounceRole logic since it is not neccesary
bitrider23 b5fa134
Improve setKeeperRegistryAddress changeset strcuture
bitrider23 97ce85d
add setWatchList changeset
bitrider23 45d7569
fix import error
bitrider23 a25ed4b
Change logic on setKeeperRegistryAddress to use new proposal builder
bitrider23 4610db7
Add withdraw changeset
bitrider23 57bde83
add transferOwnership changeset
bitrider23 f4116b5
Add deploy ethbalmon testing
bitrider23 4bb993a
Add more deploy tests
bitrider23 c3b46d0
Add ethBalMon setWatchList validate configuration function
bitrider23 20a33c5
Merge branch 'develop' into feat/deploy_ethbalmon
bitrider23 87fb2e9
Remove unused package
bitrider23 5edb5ab
Fix lint feedback
bitrider23 aae63ef
Fix lint feedback
bitrider23 99955d2
Merge branch 'develop' into feat/deploy_ethbalmon
bitrider23 01006e9
Fix lint
bitrider23 88960cb
Remove unnecesary conversion
bitrider23 04d17aa
Remove wrong comment
bitrider23 8711270
Add useful comments for types
bitrider23 666ecaa
Change log info
bitrider23 8dbcab1
Get output after check error
bitrider23 466268a
Fix validations
bitrider23 0b44240
Change withdraw config amount type
bitrider23 27a9267
leave the inspector as nil and complete on proposalutils functions
bitrider23 9699421
Rename files from camel case to snake
bitrider23 147cc2e
Change action based on mcmc config input
bitrider23 4cbd039
Fix lint
bitrider23 68cb16b
Format structures
bitrider23 57663e6
Format file
bitrider23 7933f54
Validate balance >0
bitrider23 ee1d25f
Validate MCMS is on datastore
bitrider23 558faf6
Add zero address check after check if is valid hex
bitrider23 0db1992
Format file
bitrider23 730d65d
Fix copilot feedback
bitrider23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package changeset | ||
|
|
||
| import ( | ||
| mcmstypes "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
|
|
||
| "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" | ||
| commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" | ||
| ) | ||
|
|
||
| // ethBalMonMCMSContractTypeForAction selects the MCMS contract type in the datastore for EthBalMon | ||
| // timelock proposals, matching operations.generateMCMSProposals. | ||
| func ethBalMonMCMSContractTypeForAction(action mcmstypes.TimelockAction) cldf.ContractType { | ||
| if action == mcmstypes.TimelockActionBypass { | ||
| return commontypes.BypasserManyChainMultisig | ||
| } | ||
| return commontypes.ProposerManyChainMultisig | ||
| } | ||
|
|
||
| // ethBalMonMCMSContractTypeForProposal resolves MCMS datastore type from optional timelock config. | ||
| // When cfg is nil or MCMSAction is empty, the action is treated as schedule (non-bypass), so the proposer MCM is used. | ||
| func ethBalMonMCMSContractTypeForProposal(cfg *proposalutils.TimelockConfig) cldf.ContractType { | ||
| action := mcmstypes.TimelockActionSchedule | ||
| if cfg != nil && cfg.MCMSAction != "" { | ||
| action = cfg.MCMSAction | ||
| } | ||
| return ethBalMonMCMSContractTypeForAction(action) | ||
| } | ||
|
|
||
| func ethBalMonProposalTimelockConfig(cfg *proposalutils.TimelockConfig) proposalutils.TimelockConfig { | ||
| if cfg == nil { | ||
| return proposalutils.TimelockConfig{MinDelay: 0} | ||
| } | ||
| return *cfg | ||
| } | ||
|
|
||
| // deployEthBalMonAcceptOwnershipMCMSAction returns the MCMS timelock action for the post-deploy accept-ownership proposal. | ||
| // When cfg is nil or MCMSAction is unset, the deploy flow defaults to bypass. | ||
| func deployEthBalMonAcceptOwnershipMCMSAction(cfg *proposalutils.TimelockConfig) mcmstypes.TimelockAction { | ||
| if cfg == nil || cfg.MCMSAction == "" { | ||
| return mcmstypes.TimelockActionBypass | ||
| } | ||
| return cfg.MCMSAction | ||
| } | ||
|
|
||
| func deployEthBalMonAcceptOwnershipTimelockConfig(cfg *proposalutils.TimelockConfig) proposalutils.TimelockConfig { | ||
| out := proposalutils.TimelockConfig{MinDelay: 0} | ||
| if cfg != nil { | ||
| out = *cfg | ||
| } | ||
| if out.MCMSAction == "" { | ||
| out.MCMSAction = mcmstypes.TimelockActionBypass | ||
| } | ||
| return out | ||
| } |
257 changes: 257 additions & 0 deletions
257
deployment/vault/changeset/ethbalmon_set_keeper_registry_address.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,257 @@ | ||
| package changeset | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
|
|
||
| "github.com/Masterminds/semver/v3" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "github.com/smartcontractkit/mcms" | ||
| mcmstypes "github.com/smartcontractkit/mcms/types" | ||
|
|
||
| cldf_evm "github.com/smartcontractkit/chainlink-deployments-framework/chain/evm" | ||
| cldf "github.com/smartcontractkit/chainlink-deployments-framework/deployment" | ||
| "github.com/smartcontractkit/chainlink-deployments-framework/operations" | ||
| "github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/eth_balance_monitor_wrapper" | ||
| "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" | ||
| commontypes "github.com/smartcontractkit/chainlink/deployment/common/types" | ||
| vaulttypes "github.com/smartcontractkit/chainlink/deployment/vault/changeset/types" | ||
| ) | ||
|
|
||
| type setKeeperRegistryAddress struct{} | ||
|
|
||
| var SetKeeperRegistryAddress cldf.ChangeSetV2[vaulttypes.EthBalMonSetKeeperRegistryAddressInput] = setKeeperRegistryAddress{} | ||
|
|
||
| func (sk setKeeperRegistryAddress) VerifyPreconditions(env cldf.Environment, config vaulttypes.EthBalMonSetKeeperRegistryAddressInput) error { | ||
| return ValidateSetKeeperRegistryAddressConfig(env.GetContext(), env, config) | ||
| } | ||
|
|
||
| func (sk setKeeperRegistryAddress) Apply( | ||
| e cldf.Environment, | ||
| config vaulttypes.EthBalMonSetKeeperRegistryAddressInput, | ||
| ) (cldf.ChangesetOutput, error) { | ||
| logger := e.Logger | ||
| logger.Infow("Generating SetKeeperRegistryAddress proposal for Ethereum Balance Monitor", | ||
| "numChains", len(config.Chains), | ||
| ) | ||
|
|
||
| evmChains := e.BlockChains.EVMChains() | ||
|
|
||
| var primaryChain cldf_evm.Chain | ||
| for chainSelector := range config.Chains { | ||
| primaryChain = evmChains[chainSelector] | ||
| break | ||
| } | ||
|
|
||
| deps := VaultDeps{ | ||
| Auth: primaryChain.DeployerKey, | ||
| Chain: primaryChain, | ||
| Environment: e, | ||
| DataStore: e.DataStore, | ||
| } | ||
|
|
||
| seqInput := EthBalMonSetKeeperRegistryAddressSequenceInput{ | ||
| Chains: config.Chains, | ||
| MCMSConfig: config.MCMSConfig, | ||
| } | ||
|
|
||
| seqReport, err := operations.ExecuteSequence( | ||
| e.OperationsBundle, | ||
| SetKeeperRegistrySequence, | ||
| deps, | ||
| seqInput, | ||
| ) | ||
| if err != nil { | ||
| return cldf.ChangesetOutput{}, fmt.Errorf("failed to set keeper registry address sequence: %w", err) | ||
| } | ||
|
|
||
| return cldf.ChangesetOutput{ | ||
| MCMSTimelockProposals: seqReport.Output.MCMSTimelockProposals, | ||
| }, nil | ||
| } | ||
|
|
||
| type EthBalMonSetKeeperRegistryAddressSequenceInput struct { | ||
| Chains map[uint64]vaulttypes.SetKeeperRegistryChainConfig `json:"chains"` | ||
| MCMSConfig *proposalutils.TimelockConfig `json:"mcms_config,omitempty"` | ||
| } | ||
|
|
||
| type EthBalMonSetKeeperRegistryAddressSequenceOutput struct { | ||
| MCMSTimelockProposals []mcms.TimelockProposal | ||
| } | ||
|
|
||
| var SetKeeperRegistrySequence = operations.NewSequence( | ||
| "ethbalmon-set-keeper-registry", | ||
| semver.MustParse("1.0.0"), | ||
| "Generate MCMS timelock proposal to set Keeper Registry address on EthBalMon across chains", | ||
| func( | ||
| b operations.Bundle, | ||
| deps VaultDeps, | ||
| input EthBalMonSetKeeperRegistryAddressSequenceInput, | ||
| ) (EthBalMonSetKeeperRegistryAddressSequenceOutput, error) { | ||
| b.Logger.Infow("Starting EthBalMon set keeper registry sequence", | ||
| "chains", len(input.Chains), | ||
| ) | ||
|
|
||
| if len(input.Chains) == 0 { | ||
| return EthBalMonSetKeeperRegistryAddressSequenceOutput{}, errors.New("no chains provided") | ||
| } | ||
|
|
||
| var batches []mcmstypes.BatchOperation | ||
| timelockAddresses := make(map[uint64]string) | ||
| mcmAddressByChain := make(map[uint64]string) | ||
|
|
||
| for chainSelector, chainConfig := range input.Chains { | ||
| opReport, err := operations.ExecuteOperation( | ||
| b, | ||
| SetKeeperRegistryOperation, | ||
| deps, | ||
| SetKeeperRegistryOperationInput{ | ||
| ChainSelector: chainSelector, | ||
| NewKeeperRegistryAddress: chainConfig.NewKeeperRegistryAddress, | ||
| MCMSConfig: input.MCMSConfig, | ||
| }, | ||
| ) | ||
| if err != nil { | ||
| return EthBalMonSetKeeperRegistryAddressSequenceOutput{}, | ||
| fmt.Errorf("chain %d: failed to generate set keeper registry batch: %w", chainSelector, err) | ||
| } | ||
|
|
||
| opOut := opReport.Output | ||
|
|
||
| batches = append(batches, opOut.BatchOperation) | ||
| timelockAddresses[chainSelector] = opOut.TimelockAddress | ||
| mcmAddressByChain[chainSelector] = opOut.MCMSAddress | ||
| } | ||
|
|
||
| proposal, err := proposalutils.BuildProposalFromBatchesV2( | ||
| deps.Environment, | ||
| timelockAddresses, | ||
| mcmAddressByChain, | ||
| nil, | ||
| batches, | ||
| "EthBalMon SetKeeperRegistryAddress", | ||
| ethBalMonProposalTimelockConfig(input.MCMSConfig), | ||
| ) | ||
| if err != nil { | ||
| return EthBalMonSetKeeperRegistryAddressSequenceOutput{}, | ||
| fmt.Errorf("failed to build timelock proposal: %w", err) | ||
| } | ||
|
|
||
| b.Logger.Infow("Generated EthBalMon set keeper registry proposal", | ||
| "chains", len(input.Chains), | ||
| "operations", len(batches), | ||
| ) | ||
|
|
||
| return EthBalMonSetKeeperRegistryAddressSequenceOutput{ | ||
| MCMSTimelockProposals: []mcms.TimelockProposal{*proposal}, | ||
| }, nil | ||
| }, | ||
| ) | ||
|
|
||
| type SetKeeperRegistryOperationInput struct { | ||
| ChainSelector uint64 `json:"chain_selector"` | ||
| NewKeeperRegistryAddress string `json:"new_keeper_registry_address"` | ||
| MCMSConfig *proposalutils.TimelockConfig `json:"mcms_config,omitempty"` | ||
| } | ||
|
|
||
| type SetKeeperRegistryOperationOutput struct { | ||
| ChainSelector uint64 `json:"chain_selector"` | ||
| BatchOperation mcmstypes.BatchOperation `json:"batch_operation"` | ||
| TimelockAddress string `json:"timelock_address"` | ||
| MCMSAddress string `json:"mcms_address"` | ||
| } | ||
|
|
||
| var SetKeeperRegistryOperation = operations.NewOperation( | ||
| "ethbalmon-set-keeper-registry-op", | ||
| semver.MustParse("1.0.0"), | ||
| "Generate batch operation to set Keeper Registry address on the Ethereum Balance Monitor contract", | ||
| func( | ||
| b operations.Bundle, | ||
| deps VaultDeps, | ||
| input SetKeeperRegistryOperationInput, | ||
| ) (SetKeeperRegistryOperationOutput, error) { | ||
| chain, ok := deps.Environment.BlockChains.EVMChains()[input.ChainSelector] | ||
| if !ok { | ||
| return SetKeeperRegistryOperationOutput{}, fmt.Errorf("chain not found in environment: %d", input.ChainSelector) | ||
| } | ||
|
|
||
| ethBalMonAddr, err := mustGetContractAddress( | ||
| deps.DataStore, | ||
| input.ChainSelector, | ||
| cldf.ContractType(vaulttypes.EthBalMonContractType), | ||
| ) | ||
| if err != nil { | ||
| return SetKeeperRegistryOperationOutput{}, | ||
| fmt.Errorf("failed to get EthBalMon address: %w", err) | ||
| } | ||
|
|
||
| timelockAddr, err := mustGetContractAddress( | ||
| deps.DataStore, | ||
| input.ChainSelector, | ||
| commontypes.RBACTimelock, | ||
| ) | ||
| if err != nil { | ||
| return SetKeeperRegistryOperationOutput{}, | ||
| fmt.Errorf("failed to get timelock address: %w", err) | ||
| } | ||
|
|
||
| mcmsAddr, err := mustGetContractAddress( | ||
| deps.DataStore, | ||
| input.ChainSelector, | ||
| ethBalMonMCMSContractTypeForProposal(input.MCMSConfig), | ||
| ) | ||
| if err != nil { | ||
| return SetKeeperRegistryOperationOutput{}, | ||
| fmt.Errorf("failed to get MCMS address: %w", err) | ||
| } | ||
|
|
||
| ethBalMon, err := eth_balance_monitor_wrapper.NewEthBalanceMonitor( | ||
| common.HexToAddress(ethBalMonAddr), | ||
| chain.Client, | ||
| ) | ||
| if err != nil { | ||
| return SetKeeperRegistryOperationOutput{}, | ||
| fmt.Errorf("failed to instantiate EthBalanceMonitor at %s: %w", ethBalMonAddr, err) | ||
| } | ||
|
|
||
| setKeeperRegistryTx, err := ethBalMon.SetKeeperRegistryAddress( | ||
| cldf.SimTransactOpts(), | ||
| common.HexToAddress(input.NewKeeperRegistryAddress), | ||
| ) | ||
| if err != nil { | ||
| return SetKeeperRegistryOperationOutput{}, | ||
| fmt.Errorf("failed to generate setKeeperRegistryAddress calldata: %w", err) | ||
| } | ||
|
|
||
| batch := mcmstypes.BatchOperation{ | ||
| ChainSelector: mcmstypes.ChainSelector(input.ChainSelector), | ||
| Transactions: []mcmstypes.Transaction{ | ||
| { | ||
| OperationMetadata: mcmstypes.OperationMetadata{ | ||
| ContractType: vaulttypes.EthBalMonContractType, | ||
| Tags: []string{ | ||
| "setKeeperRegistryAddress", | ||
| }, | ||
| }, | ||
| To: ethBalMonAddr, | ||
| Data: setKeeperRegistryTx.Data(), | ||
| AdditionalFields: json.RawMessage(`{"value": 0}`), | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| b.Logger.Infow("Generated EthBalMon set keeper registry batch", | ||
| "chainSelector", input.ChainSelector, | ||
| "ethBalMon", ethBalMonAddr, | ||
| "newKeeperRegistry", input.NewKeeperRegistryAddress, | ||
| ) | ||
|
|
||
| return SetKeeperRegistryOperationOutput{ | ||
| ChainSelector: input.ChainSelector, | ||
| BatchOperation: batch, | ||
| TimelockAddress: timelockAddr, | ||
| MCMSAddress: mcmsAddr, | ||
| }, nil | ||
| }, | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.