status-go/services/wallet/requests/tx_custom_params.go
Sale Djenic b91c5fd29c feat(wallet)!: allowing client to set custom values for fees, nonce, gas
Removed properties from `Path` type:
- `MaxFeesPerGas`, based on the sending flow progress appropriate new properties (`TxMaxFeesPerGas`, `ApprovalMaxFeesPerGas`) should be used

Added new properties to `Path` type:
- `RouterInputParamsUuid`, used to identify from which router input params this path was created
- `TxNonce`, used to set nonce for the tx
- `TxMaxFeesPerGas`, used to set max fees per gas for the tx
- `TxEstimatedTime`, used to estimate time for executing the tx
- `ApprovalTxNonce`, used to set nonce for the approval tx
- `ApprovalTxMaxFeesPerGas`, used to set max fees per gas for the approval tx
- `ApprovalTxEstimatedTime`, used to estimate time for executing the approval tx

New request types added:
- `PathTxCustomParams`, used to pass tx custom params from the client
- `PathTxIdentity`, used to uniquely identify path (tx) to which the custom params need to be applied

New endpoints added:
- `SetFeeMode` used to set fee mode (`GasFeeLow`, `GasFeeMedium` or `GasFeeHigh`)
- `SetCustomTxDetails` used to set custom fee mode (`SetCustomTxDetails`), if this mode is set, client needs to provide:
  - Max fees per gas
  - Max priority fee
  - Nonce
  - Gas amount
2025-01-08 17:22:50 +01:00

51 lines
1.5 KiB
Go

package requests
import (
"fmt"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/status-im/status-go/errors"
"github.com/status-im/status-go/services/wallet/router/fees"
)
var (
ErrMaxFeesPerGasRequired = &errors.ErrorResponse{Code: errors.ErrorCode("WRC-001"), Details: "maxFeesPerGas is required"}
ErrPriorityFeeRequired = &errors.ErrorResponse{Code: errors.ErrorCode("WRC-002"), Details: "priorityFee is required"}
)
type PathTxCustomParams struct {
GasFeeMode fees.GasFeeMode `json:"gasFeeMode" validate:"required"`
Nonce uint64 `json:"nonce"`
GasAmount uint64 `json:"gasAmount"`
MaxFeesPerGas *hexutil.Big `json:"maxFeesPerGas"`
PriorityFee *hexutil.Big `json:"priorityFee"`
}
type PathTxIdentity struct {
RouterInputParamsUuid string `json:"routerInputParamsUuid" validate:"required"`
PathName string `json:"pathName" validate:"required"`
ChainID uint64 `json:"chainID" validate:"required"`
IsApprovalTx bool `json:"isApprovalTx"`
}
func (p *PathTxIdentity) PathIdentity() string {
return fmt.Sprintf("%s-%s-%d", p.RouterInputParamsUuid, p.PathName, p.ChainID)
}
func (p *PathTxIdentity) TxIdentityKey() string {
return fmt.Sprintf("%s-%v", p.PathIdentity(), p.IsApprovalTx)
}
func (p *PathTxCustomParams) Validate() error {
if p.GasFeeMode != fees.GasFeeCustom {
return nil
}
if p.MaxFeesPerGas == nil {
return ErrMaxFeesPerGasRequired
}
if p.PriorityFee == nil {
return ErrPriorityFeeRequired
}
return nil
}