Skip to content

Commit

Permalink
Merge pull request #82 from G7DAO/feat/predict-safe
Browse files Browse the repository at this point in the history
Feat: Add predict safe deployment addres flag
  • Loading branch information
karacurt authored Oct 4, 2024
2 parents 619e223 + 6bca013 commit b0b48c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
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"

0 comments on commit b0b48c6

Please sign in to comment.