Skip to content

Commit

Permalink
Fix: change safe nonce from uint64 to bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
karacurt committed Oct 8, 2024
1 parent 884d384 commit e142737
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 44 deletions.
44 changes: 33 additions & 11 deletions evm/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ type SafeTransactionData struct {
GasPrice string ` + "`" + `json:"gasPrice"` + "`" + `
GasToken string ` + "`" + `json:"gasToken"` + "`" + `
RefundReceiver string ` + "`" + `json:"refundReceiver"` + "`" + `
Nonce uint64 ` + "`" + `json:"nonce"` + "`" + `
Nonce *big.Int ` + "`" + `json:"nonce"` + "`" + `
SafeTxHash string ` + "`" + `json:"safeTxHash"` + "`" + `
Sender string ` + "`" + `json:"sender"` + "`" + `
Signature string ` + "`" + `json:"signature"` + "`" + `
Expand All @@ -1119,7 +1119,7 @@ const (
)
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, safeNonce uint64) 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, safeNonce *big.Int) error {
abi, err := CreateCall.CreateCallMetaData.GetAbi()
if err != nil {
return fmt.Errorf("failed to get ABI: %v", err)
Expand All @@ -1143,7 +1143,7 @@ func PredictDeploymentAddressSafe(from common.Address, salt [32]byte, deployByte
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, safeNonce uint64) error {
func CreateSafeProposal(client *ethclient.Client, key *keystore.Key, safeAddress common.Address, to common.Address, data []byte, value *big.Int, safeApi string, safeOperationType SafeOperationType, safeNonce *big.Int) error {
chainID, err := client.ChainID(context.Background())
if err != nil {
return fmt.Errorf("failed to get chain ID: %v", err)
Expand All @@ -1156,13 +1156,13 @@ func CreateSafeProposal(client *ethclient.Client, key *keystore.Key, safeAddress
}
nonce := safeNonce
if safeNonce == 0 {
if safeNonce == nil {
// Fetch the current nonce from the Safe contract
fetchedNonce, err := safeInstance.Nonce(&bind.CallOpts{})
if err != nil {
return fmt.Errorf("failed to fetch nonce from Safe contract: %v", err)
}
nonce = fetchedNonce.Uint64()
nonce = fetchedNonce
} else {
nonce = safeNonce
}
Expand Down Expand Up @@ -1304,11 +1304,11 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
var gasLimit uint64
var simulate bool
var timeout uint
var safeAddress, safeApi, safeCreateCall, safeSaltRaw string
var safeAddress, safeApi, safeCreateCall, safeSaltRaw, safeNonceRaw string
var safeOperationType uint8
var salt [32]byte
var predictAddress bool
var safeNonce uint64
var safeNonce *big.Int
{{range .DeployHandler.MethodArgs}}
var {{.CLIVar}} {{.CLIType}}
{{if (ne .CLIRawVar .CLIVar)}}var {{.CLIRawVar}} {{.CLIRawType}}{{end}}
Expand Down Expand Up @@ -1374,6 +1374,17 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
} else {
copy(salt[:], safeSaltRaw)
}
if safeNonceRaw == "" {
fmt.Println("--safe-nonce not specified, using default (0)")
safeNonce = big.NewInt(0)
} else {
safeNonce = new(big.Int)
_, ok := safeNonce.SetString(safeNonceRaw, 10)
if !ok {
return fmt.Errorf("--safe-nonce is not a valid big integer")
}
}
}
{{range .DeployHandler.MethodArgs}}
Expand Down Expand Up @@ -1506,7 +1517,7 @@ func {{.DeployHandler.HandlerName}}() *cobra.Command {
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().Uint64Var(&safeNonce, "safe-nonce", 0, "Safe nonce overrider for the transaction (optional)")
cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)")
{{range .DeployHandler.MethodArgs}}
cmd.Flags().{{.Flag}}
Expand Down Expand Up @@ -1636,14 +1647,14 @@ 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, safeFunction string
var keyfile, nonce, password, value, gasPrice, maxFeePerGas, maxPriorityFeePerGas, rpc, contractAddressRaw, safeFunction, safeNonceRaw string
var gasLimit uint64
var simulate bool
var timeout uint
var contractAddress common.Address
var safeAddress, safeApi string
var safeOperationType uint8
var safeNonce uint64
var safeNonce *big.Int
{{range .MethodArgs}}
var {{.CLIVar}} {{.CLIType}}
Expand Down Expand Up @@ -1691,6 +1702,17 @@ func {{.HandlerName}}() *cobra.Command {
if SafeOperationType(safeOperationType).String() == "Unknown" {
return fmt.Errorf("--safe-operation must be 0 (Call) or 1 (DelegateCall)")
}
if safeNonceRaw == "" {
fmt.Println("--safe-nonce not specified, using default (0)")
safeNonce = big.NewInt(0)
} else {
safeNonce = new(big.Int)
_, ok := safeNonce.SetString(safeNonceRaw, 10)
if !ok {
return fmt.Errorf("--safe-nonce is not a valid big integer")
}
}
}
{{range .MethodArgs}}
Expand Down Expand Up @@ -1827,7 +1849,7 @@ func {{.HandlerName}}() *cobra.Command {
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().Uint64Var(&safeNonce, "safe-nonce", 0, "Safe nonce overrider for the transaction (optional)")
cmd.Flags().StringVar(&safeNonceRaw, "safe-nonce", "", "Safe nonce overrider for the transaction (optional)")
{{range .MethodArgs}}
cmd.Flags().{{.Flag}}
Expand Down
Loading

0 comments on commit e142737

Please sign in to comment.