Skip to content
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

Feat: Add predict safe deployment addres flag #82

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions evm/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,16 @@ func DeployWithSafe(client *ethclient.Client, key *keystore.Key, safeAddress com
return CreateSafeProposal(client, key, safeAddress, factoryAddress, safeCreateCallTxData, value, safeApi, SafeOperationType(safeOperationType))
}

func PredictDeploymentAddressSafe(from common.Address, salt [32]byte, deployBytecode []byte) (common.Address, error) {
// Calculate the hash of the init code (deployment bytecode)
initCodeHash := crypto.Keccak256(deployBytecode)

// Calculate the CREATE2 address
deployedAddress := crypto.CreateAddress2(from, salt, initCodeHash)

return deployedAddress, nil
}

func CreateSafeProposal(client *ethclient.Client, key *keystore.Key, safeAddress common.Address, to common.Address, data []byte, value *big.Int, safeApi string, safeOperationType SafeOperationType) error {
chainID, err := client.ChainID(context.Background())
if err != nil {
Expand Down Expand Up @@ -1291,6 +1301,7 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
var safeAddress, safeApi, safeCreateCall, safeSaltRaw string
var safeOperationType uint8
var salt [32]byte
var predictAddress bool

{{range .DeployHandler.MethodArgs}}
var {{.CLIVar}} {{.CLIType}}
Expand Down Expand Up @@ -1407,9 +1418,24 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
value = big.NewInt(0)
}

err = DeployWithSafe(client, key, common.HexToAddress(safeAddress), common.HexToAddress(safeCreateCall), value, safeApi, deployBytecode, SafeOperationType(safeOperationType), salt)
if err != nil {
return fmt.Errorf("failed to create Safe proposal: %v", err)
if predictAddress {
fmt.Println("Predicting deployment address...")
from := common.HexToAddress(safeAddress)
if safeOperationType == 0 {
from = common.HexToAddress(safeCreateCall)
}
deploymentAddress, err := PredictDeploymentAddressSafe(from, salt, deployBytecode)
if err != nil {
return fmt.Errorf("failed to predict deployment address: %v", err)
}
fmt.Println("Predicted deployment address:", deploymentAddress.Hex())
return nil
} else {
fmt.Println("Creating Safe proposal...")
err = DeployWithSafe(client, key, common.HexToAddress(safeAddress), common.HexToAddress(safeCreateCall), value, safeApi, deployBytecode, SafeOperationType(safeOperationType), salt)
if err != nil {
return fmt.Errorf("failed to create Safe proposal: %v", err)
}
}

return nil
Expand Down Expand Up @@ -1473,6 +1499,7 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
cmd.Flags().StringVar(&safeCreateCall, "safe-create-call", "", "Address of the CreateCall contract (optional)")
cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 1, "Safe operation type: 0 (Call) or 1 (DelegateCall) - default is 1")
cmd.Flags().StringVar(&safeSaltRaw, "safe-salt", "", "Salt to use for the Safe transaction")
cmd.Flags().BoolVar(&predictAddress, "safe-predict-address", false, "Predict the deployment address (only works for Safe transactions)")

{{range .DeployHandler.MethodArgs}}
cmd.Flags().{{.Flag}}
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package version

var SeerVersion string = "0.2.0"
var SeerVersion string = "0.2.1"
Loading