-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathethbalmon_accept_ownership.go
More file actions
206 lines (177 loc) · 7.51 KB
/
Copy pathethbalmon_accept_ownership.go
File metadata and controls
206 lines (177 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
package changeset
import (
"encoding/json"
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/ethereum/go-ethereum/common"
proposeutils "github.com/smartcontractkit/cld-changesets/legacy/mcms/proposeutils"
"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"
proposalutils "github.com/smartcontractkit/chainlink-deployments-framework/engine/cld/mcms/proposalutils"
"github.com/smartcontractkit/chainlink-deployments-framework/operations"
"github.com/smartcontractkit/chainlink-evm/gethwrappers/generated/eth_balance_monitor_wrapper"
commontypes "github.com/smartcontractkit/chainlink/deployment/common/types"
vaulttypes "github.com/smartcontractkit/chainlink/deployment/vault/changeset/types"
)
type ethBalMonAcceptOwnership struct{}
var EthBalMonAcceptOwnership cldf.ChangeSetV2[vaulttypes.EthBalMonAcceptOwnershipInput] = ethBalMonAcceptOwnership{}
func (tw ethBalMonAcceptOwnership) VerifyPreconditions(env cldf.Environment, config vaulttypes.EthBalMonAcceptOwnershipInput) error {
return ValidateEthBalMonAcceptOwnershipConfig(env.GetContext(), env, config)
}
func (tw ethBalMonAcceptOwnership) Apply(e cldf.Environment, config vaulttypes.EthBalMonAcceptOwnershipInput) (cldf.ChangesetOutput, error) {
logger := e.Logger
logger.Infow("Generating EthBalMon acceptOwnership proposal", "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 := EthBalMonAcceptOwnershipSeqInput{
Chains: config.Chains,
MCMSConfig: config.MCMSConfig,
}
seqReport, err := operations.ExecuteSequence(e.OperationsBundle, EthBalMonAcceptOwnershipSequence, deps, seqInput)
if err != nil {
return cldf.ChangesetOutput{}, fmt.Errorf("failed on EthBalMonAcceptOwnershipSequence sequence: %w", err)
}
return cldf.ChangesetOutput{
MCMSTimelockProposals: seqReport.Output.MCMSTimelockProposals,
}, nil
}
type EthBalMonAcceptOwnershipSeqInput struct {
Chains []uint64 `json:"chains"`
MCMSConfig *proposalutils.TimelockConfig `json:"mcms_config,omitempty"`
}
type EthBalMonAcceptOwnershipSeqOutput struct {
MCMSTimelockProposals []mcms.TimelockProposal `json:"mcms_timelock_proposals"`
}
var EthBalMonAcceptOwnershipSequence = operations.NewSequence(
"ethbalmon-acceptownership-sequence",
semver.MustParse("1.0.0"),
"Sequence to create acceptOwnership EthBalMon batch transaction",
func(b operations.Bundle, deps VaultDeps, input EthBalMonAcceptOwnershipSeqInput) (EthBalMonAcceptOwnershipSeqOutput, error) {
b.Logger.Infow("Starting EthBalMon acceptOwnership sequence",
"chains", len(input.Chains),
)
var batches []mcmstypes.BatchOperation
timelockAddresses := make(map[uint64]string)
mcmAddressByChain := make(map[uint64]string)
for _, chainSelector := range input.Chains {
opReport, err := operations.ExecuteOperation(b, EthBalMonAcceptOwnershipOperation, deps, EthBalMonAcceptOwnershipOpInput{
ChainSelector: chainSelector,
MCMSConfig: input.MCMSConfig,
})
if err != nil {
return EthBalMonAcceptOwnershipSeqOutput{}, fmt.Errorf("chain %d: failed to generate acceptOwnership batch: %w", chainSelector, err)
}
opOutput := opReport.Output
batches = append(batches, opOutput.BatchOperation)
timelockAddresses[chainSelector] = opOutput.TimelockAddress
mcmAddressByChain[chainSelector] = opOutput.MCMSAddress
}
proposal, err := proposeutils.BuildProposalFromBatchesV2(deps.Environment, timelockAddresses, mcmAddressByChain, nil, batches, "EthBalMon acceptOwnership", ethBalMonProposalTimelockConfig(input.MCMSConfig))
if err != nil {
return EthBalMonAcceptOwnershipSeqOutput{}, fmt.Errorf("failed to build timelock proposal: %w", err)
}
b.Logger.Infow("Generated EthBalMon acceptOwnership proposal",
"chains", len(input.Chains), "operations", len(batches))
return EthBalMonAcceptOwnershipSeqOutput{
MCMSTimelockProposals: []mcms.TimelockProposal{*proposal},
}, nil
},
)
type EthBalMonAcceptOwnershipOpInput struct {
ChainSelector uint64 `json:"chain_selector"`
MCMSConfig *proposalutils.TimelockConfig `json:"mcms_config,omitempty"`
}
type EthBalMonAcceptOwnershipOpOutput struct {
ChainSelector uint64 `json:"chain_selector"`
BatchOperation mcmstypes.BatchOperation `json:"batch_operation"`
TimelockAddress string `json:"timelock_address"`
MCMSAddress string `json:"mcms_address"`
}
var EthBalMonAcceptOwnershipOperation = operations.NewOperation(
"ethbalmon-acceptownership-operation",
semver.MustParse("1.0.0"),
"Operation to create acceptOwnership EthBalMon batch transaction",
func(b operations.Bundle, deps VaultDeps, input EthBalMonAcceptOwnershipOpInput) (EthBalMonAcceptOwnershipOpOutput, error) {
b.Logger.Infow("Starting EthBalMon acceptOwnership operation",
"chainsel", input.ChainSelector,
)
chain, ok := deps.Environment.BlockChains.EVMChains()[input.ChainSelector]
if !ok {
return EthBalMonAcceptOwnershipOpOutput{}, fmt.Errorf("chain not found in environment: %d", input.ChainSelector)
}
ethBalMonAddr, err := getRequiredContractAddress(
deps.DataStore,
input.ChainSelector,
cldf.ContractType(vaulttypes.EthBalMonContractType),
)
if err != nil {
return EthBalMonAcceptOwnershipOpOutput{},
fmt.Errorf("failed to get EthBalMon address: %w", err)
}
timelockAddr, err := getRequiredContractAddress(
deps.DataStore,
input.ChainSelector,
commontypes.RBACTimelock,
)
if err != nil {
return EthBalMonAcceptOwnershipOpOutput{},
fmt.Errorf("failed to get timelock address: %w", err)
}
mcmsAddr, err := getRequiredContractAddress(
deps.DataStore,
input.ChainSelector,
ethBalMonMCMSContractTypeForProposal(input.MCMSConfig),
)
if err != nil {
return EthBalMonAcceptOwnershipOpOutput{},
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 EthBalMonAcceptOwnershipOpOutput{},
fmt.Errorf("failed to instantiate EthBalanceMonitor at %s: %w", ethBalMonAddr, err)
}
acceptOwnershipTx, err := ethBalMon.AcceptOwnership(cldf.SimTransactOpts())
if err != nil {
return EthBalMonAcceptOwnershipOpOutput{}, fmt.Errorf("failed to generate acceptOwnership calldata on chain %d: %w", input.ChainSelector, err)
}
batch := mcmstypes.BatchOperation{
ChainSelector: mcmstypes.ChainSelector(input.ChainSelector),
Transactions: []mcmstypes.Transaction{
{
OperationMetadata: mcmstypes.OperationMetadata{
ContractType: vaulttypes.EthBalMonContractType,
Tags: []string{
"acceptOwnership",
},
},
To: ethBalMonAddr,
Data: acceptOwnershipTx.Data(),
AdditionalFields: json.RawMessage(`{"value": 0}`),
},
},
}
b.Logger.Infow("Generated EthBalMon acceptOwnership batch",
"chainSelector", input.ChainSelector,
"ethBalMon", ethBalMonAddr,
)
return EthBalMonAcceptOwnershipOpOutput{
ChainSelector: input.ChainSelector,
BatchOperation: batch,
TimelockAddress: timelockAddr,
MCMSAddress: mcmsAddr,
}, nil
},
)