-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor helper to use in cli in CLD
- Loading branch information
1 parent
bb66cc2
commit c392124
Showing
4 changed files
with
77 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,71 @@ | ||
package changeset | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
owner_helpers "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" | ||
"github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" | ||
"github.com/smartcontractkit/chainlink/deployment" | ||
) | ||
|
||
// ExecuteProposal executes all the operation in the given executor on the given chain. | ||
// It is an error if there are no operations for the given chain. | ||
func ExecuteProposal(env deployment.Environment, executor *mcms.Executor, timelockContracts *TimelockExecutionContracts, sel uint64) error { | ||
// TODO: This sort of helper probably should move to the MCMS lib. | ||
// Execute all the transactions in the proposal which are for this chain. | ||
if len(executor.Operations[mcms.ChainIdentifier(sel)]) == 0 { | ||
return fmt.Errorf("no operations for chain %d", sel) | ||
} | ||
for _, chainOp := range executor.Operations[mcms.ChainIdentifier(sel)] { | ||
for idx, op := range executor.ChainAgnosticOps { | ||
if bytes.Equal(op.Data, chainOp.Data) && op.To == chainOp.To { | ||
opTx, err2 := executor.ExecuteOnChain(env.Chains[sel].Client, env.Chains[sel].DeployerKey, idx) | ||
if err2 != nil { | ||
return fmt.Errorf("error executing on chain: %w", err2) | ||
} | ||
block, err2 := env.Chains[sel].Confirm(opTx) | ||
if err2 != nil { | ||
return fmt.Errorf("error confirming on chain: %w", err2) | ||
} | ||
it, err2 := timelockContracts.Timelock.FilterCallScheduled(&bind.FilterOpts{ | ||
Start: block, | ||
End: &block, | ||
Context: env.GetContext(), | ||
}, nil, nil) | ||
if err2 != nil { | ||
return fmt.Errorf("error filtering call scheduled: %w", err2) | ||
} | ||
var calls []owner_helpers.RBACTimelockCall | ||
var pred, salt [32]byte | ||
for it.Next() { | ||
// Note these are the same for the whole batch, can overwrite | ||
pred = it.Event.Predecessor | ||
salt = it.Event.Salt | ||
env.Logger.Info("scheduled", "event", it.Event) | ||
calls = append(calls, owner_helpers.RBACTimelockCall{ | ||
Target: it.Event.Target, | ||
Data: it.Event.Data, | ||
Value: it.Event.Value, | ||
}) | ||
} | ||
|
||
timelockExecutorProxy, err := owner_helpers.NewRBACTimelock(timelockContracts.CallProxy.Address(), env.Chains[sel].Client) | ||
if err != nil { | ||
return fmt.Errorf("error creating timelock executor proxy: %w", err) | ||
} | ||
tx, err := timelockExecutorProxy.ExecuteBatch( | ||
env.Chains[sel].DeployerKey, calls, pred, salt) | ||
if err != nil { | ||
return fmt.Errorf("error executing batch: %w", err) | ||
} | ||
_, err = env.Chains[sel].Confirm(tx) | ||
if err != nil { | ||
return fmt.Errorf("error confirming batch: %w", err) | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
} |
This file contains 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
This file contains 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