diff --git a/evm/generators.go b/evm/generators.go index 87ee528..231a933 100644 --- a/evm/generators.go +++ b/evm/generators.go @@ -1629,7 +1629,7 @@ func {{.HandlerName}}() *cobra.Command { var TransactMethodCommandsTemplate string = `{{$structName := .StructName}} {{range .TransactHandlers}} func {{.HandlerName}}() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -1727,11 +1727,22 @@ func {{.HandlerName}}() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.{{.MethodName}}( - {{range .MethodArgs}} - {{.CLIVar}}, - {{- end}} + abi, err := {{$structName}}MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "{{ToLowerCamel .MethodName}}" + if safeFunction != "" { + methodName = safeFunction + } + + transaction, err := abi.Pack( + methodName, + {{- range .MethodArgs}} + {{.CLIVar}}, + {{- end}} ) if err != nil { @@ -1743,7 +1754,7 @@ func {{.HandlerName}}() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -1806,6 +1817,7 @@ func {{.HandlerName}}() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") {{range .MethodArgs}} cmd.Flags().{{.Flag}} diff --git a/examples/ownable-erc-721/OwnableERC721.go b/examples/ownable-erc-721/OwnableERC721.go index 6e0151f..ba166b0 100644 --- a/examples/ownable-erc-721/OwnableERC721.go +++ b/examples/ownable-erc-721/OwnableERC721.go @@ -1,5 +1,5 @@ // This file was generated by seer: https://github.com/moonstream-to/seer. -// seer version: 0.2.0 +// seer version: 0.2.2 // seer command: seer evm generate --package main --cli --includemain --abi fixtures/OwnableERC721.json --bytecode fixtures/OwnableERC721.bin --struct OwnableERC721 --output examples/ownable-erc-721/OwnableERC721.go // Code generated - DO NOT EDIT. // This file is a generated binding and any manual changes will be lost. @@ -8,6 +8,7 @@ package main import ( "bytes" + "crypto/rand" "errors" "math/big" "net/http" @@ -1311,7 +1312,8 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { var timeout uint var safeAddress, safeApi, safeCreateCall, safeSaltRaw string var safeOperationType uint8 - var safeSalt []byte + var salt [32]byte + var predictAddress bool var name_0 string @@ -1364,9 +1366,22 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { } if safeSaltRaw == "" { - return fmt.Errorf("--safe-salt not specified") + fmt.Println("--safe-salt not specified, generating random salt") + _, err := rand.Read(salt[:]) + if err != nil { + return fmt.Errorf("failed to generate random salt: %v", err) + } + // prompt user to accept random salt + fmt.Println("Generated salt:", common.Bytes2Hex(salt[:])) + fmt.Println("Please check the salt and confirm (y/n)") + var confirm string + fmt.Scanln(&confirm) + if confirm != "y" && confirm != "Y" && confirm != "\n" && confirm != "" { + return fmt.Errorf("salt not accepted, please specify a valid salt") + } + } else { + copy(salt[:], safeSaltRaw) } - safeSalt = common.Hex2Bytes(safeSaltRaw) } if ownerRaw == "" { @@ -1419,9 +1434,25 @@ func CreateOwnableERC721DeploymentCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = DeployWithSafe(client, key, common.HexToAddress(safeAddress), common.HexToAddress(safeCreateCall), value, safeApi, deployBytecode, SafeOperationType(safeOperationType), safeSalt) - 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 @@ -1484,6 +1515,7 @@ func CreateOwnableERC721DeploymentCommand() *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)") cmd.Flags().StringVar(&name_0, "name-0", "", "name-0 argument") cmd.Flags().StringVar(&symbol, "symbol", "", "symbol argument") @@ -2179,7 +2211,7 @@ func CreateTokenUriCommand() *cobra.Command { } func CreateApproveCommand() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -2286,9 +2318,19 @@ func CreateApproveCommand() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.Approve( + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "approve" + if safeFunction != "" { + methodName = safeFunction + } + transaction, err := abi.Pack( + methodName, to0, tokenId, ) @@ -2302,7 +2344,7 @@ func CreateApproveCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -2365,6 +2407,7 @@ func CreateApproveCommand() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") cmd.Flags().StringVar(&tokenIdRaw, "token-id", "", "token-id argument") @@ -2372,7 +2415,7 @@ func CreateApproveCommand() *cobra.Command { return cmd } func CreateMintCommand() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -2479,9 +2522,19 @@ func CreateMintCommand() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.Mint( + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + // Generate transaction data (override method name if safe function is specified) + methodName := "mint" + if safeFunction != "" { + methodName = safeFunction + } + + transaction, err := abi.Pack( + methodName, to0, tokenId, ) @@ -2495,7 +2548,7 @@ func CreateMintCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -2558,6 +2611,7 @@ func CreateMintCommand() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") cmd.Flags().StringVar(&tokenIdRaw, "token-id", "", "token-id argument") @@ -2565,7 +2619,7 @@ func CreateMintCommand() *cobra.Command { return cmd } func CreateRenounceOwnershipCommand() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -2654,8 +2708,20 @@ func CreateRenounceOwnershipCommand() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.RenounceOwnership() + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "renounceOwnership" + if safeFunction != "" { + methodName = safeFunction + } + + transaction, err := abi.Pack( + methodName, + ) if err != nil { return err @@ -2666,7 +2732,7 @@ func CreateRenounceOwnershipCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -2725,11 +2791,12 @@ func CreateRenounceOwnershipCommand() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") return cmd } func CreateSafeTransferFromCommand() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -2845,9 +2912,19 @@ func CreateSafeTransferFromCommand() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.SafeTransferFrom( + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "safeTransferFrom" + if safeFunction != "" { + methodName = safeFunction + } + transaction, err := abi.Pack( + methodName, from0, to0, tokenId, @@ -2862,7 +2939,7 @@ func CreateSafeTransferFromCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -2926,6 +3003,7 @@ func CreateSafeTransferFromCommand() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&from0Raw, "from-0", "", "from-0 argument (common.Address)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") @@ -2934,7 +3012,7 @@ func CreateSafeTransferFromCommand() *cobra.Command { return cmd } func CreateSafeTransferFrom0Command() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -3062,9 +3140,19 @@ func CreateSafeTransferFrom0Command() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.SafeTransferFrom0( + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "safeTransferFrom0" + if safeFunction != "" { + methodName = safeFunction + } + transaction, err := abi.Pack( + methodName, from0, to0, tokenId, @@ -3080,7 +3168,7 @@ func CreateSafeTransferFrom0Command() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3145,6 +3233,7 @@ func CreateSafeTransferFrom0Command() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&from0Raw, "from-0", "", "from-0 argument (common.Address)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") @@ -3154,7 +3243,7 @@ func CreateSafeTransferFrom0Command() *cobra.Command { return cmd } func CreateSetApprovalForAllCommand() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -3265,9 +3354,19 @@ func CreateSetApprovalForAllCommand() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.SetApprovalForAll( + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + // Generate transaction data (override method name if safe function is specified) + methodName := "setApprovalForAll" + if safeFunction != "" { + methodName = safeFunction + } + + transaction, err := abi.Pack( + methodName, operator, approved, ) @@ -3281,7 +3380,7 @@ func CreateSetApprovalForAllCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3344,6 +3443,7 @@ func CreateSetApprovalForAllCommand() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&operatorRaw, "operator", "", "operator argument (common.Address)") cmd.Flags().StringVar(&approvedRaw, "approved", "", "approved argument (true, t, y, yes, 1 OR false, f, n, no, 0)") @@ -3351,7 +3451,7 @@ func CreateSetApprovalForAllCommand() *cobra.Command { return cmd } func CreateTransferFromCommand() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -3467,9 +3567,19 @@ func CreateTransferFromCommand() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.TransferFrom( + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + + // Generate transaction data (override method name if safe function is specified) + methodName := "transferFrom" + if safeFunction != "" { + methodName = safeFunction + } + transaction, err := abi.Pack( + methodName, from0, to0, tokenId, @@ -3484,7 +3594,7 @@ func CreateTransferFromCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3548,6 +3658,7 @@ func CreateTransferFromCommand() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&from0Raw, "from-0", "", "from-0 argument (common.Address)") cmd.Flags().StringVar(&to0Raw, "to-0", "", "to-0 argument (common.Address)") @@ -3556,7 +3667,7 @@ func CreateTransferFromCommand() *cobra.Command { return cmd } func CreateTransferOwnershipCommand() *cobra.Command { - var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw string + var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction string var gasLimit uint64 var simulate bool var timeout uint @@ -3655,9 +3766,19 @@ func CreateTransferOwnershipCommand() *cobra.Command { } if safeAddress != "" { - // Generate transaction data - transaction, err := session.TransferOwnership( + abi, err := OwnableERC721MetaData.GetAbi() + if err != nil { + return fmt.Errorf("failed to get ABI: %v", err) + } + // Generate transaction data (override method name if safe function is specified) + methodName := "transferOwnership" + if safeFunction != "" { + methodName = safeFunction + } + + transaction, err := abi.Pack( + methodName, newOwner, ) @@ -3670,7 +3791,7 @@ func CreateTransferOwnershipCommand() *cobra.Command { if value == nil { value = big.NewInt(0) } - err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction.Data(), value, safeApi, SafeOperationType(safeOperationType)) + err = CreateSafeProposal(client, key, common.HexToAddress(safeAddress), contractAddress, transaction, value, safeApi, SafeOperationType(safeOperationType)) if err != nil { return fmt.Errorf("failed to create Safe proposal: %v", err) } @@ -3732,6 +3853,7 @@ func CreateTransferOwnershipCommand() *cobra.Command { cmd.Flags().StringVar(&safeAddress, "safe", "", "Address of the Safe contract") cmd.Flags().StringVar(&safeApi, "safe-api", "", "Safe API for the Safe Transaction Service (optional)") cmd.Flags().Uint8Var(&safeOperationType, "safe-operation", 0, "Safe operation type: 0 (Call) or 1 (DelegateCall)") + cmd.Flags().StringVar(&safeFunction, "safe-function", "", "Safe function overrider to use for the transaction (optional)") cmd.Flags().StringVar(&newOwnerRaw, "new-owner", "", "new-owner argument (common.Address)") @@ -3970,7 +4092,7 @@ const ( NativeTokenAddress = "0x0000000000000000000000000000000000000000" ) -func DeployWithSafe(client *ethclient.Client, key *keystore.Key, safeAddress common.Address, factoryAddress common.Address, value *big.Int, safeApi string, deployBytecode []byte, safeOperationType SafeOperationType, salt []byte) error { +func DeployWithSafe(client *ethclient.Client, key *keystore.Key, safeAddress common.Address, factoryAddress common.Address, value *big.Int, safeApi string, deployBytecode []byte, safeOperationType SafeOperationType, salt [32]byte) error { abi, err := CreateCall.CreateCallMetaData.GetAbi() if err != nil { return fmt.Errorf("failed to get ABI: %v", err) @@ -3984,6 +4106,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 { diff --git a/version/version.go b/version/version.go index 73d2f4f..c261165 100644 --- a/version/version.go +++ b/version/version.go @@ -1,3 +1,3 @@ package version -var SeerVersion string = "0.2.1" +var SeerVersion string = "0.2.2"