Documentation
¶
Overview ¶
Package model provides common data structures shared among blndgs projects. This file has been copied from the Bundler project. It is included in the model package to avoid introducing a cyclical dependency between the Model and Bundler projects and accommodate Bundler<->Solver communication. Any modifications made to the Bundler file should be reflected here as well to maintain consistency.
Note: In the future, this file may move here as the single source of truth.
Package model provides structures and methods for the communication between the Bundler and Solver. This file defines extensions to the UserOperation struct and methods for extracting and inserting Intent JSON from/to the CallData and Signature fields.
The CallData field in a userOperation is expected to contain either the Intent JSON or the EVM instructions but not both. The Intent JSON is expected to be appended to the signature value within the Signature field when the Calldata field contains the EVM instructions. The Signature field is expected to contain only the signature when the userOperation is unsolved.
Index ¶
- Constants
- Variables
- func ExtractJSONFromField(fieldData string) (string, bool)
- func NewValidator() error
- type Asset
- type AssetType
- type Body
- type BodyOfUserOps
- type ExtraData
- type Intent
- type ProcessingStatus
- type Stake
- type Transactional
- type UserOpSolvedStatus
- type UserOperation
- func (op *UserOperation) GetDynamicGasPrice(basefee *big.Int) *big.Int
- func (op *UserOperation) GetEVMInstructions() ([]byte, error)
- func (op *UserOperation) GetFactory() common.Address
- func (op *UserOperation) GetIntent() (*Intent, error)
- func (op *UserOperation) GetIntentJSON() (string, error)
- func (op *UserOperation) GetMaxGasAvailable() *big.Int
- func (op *UserOperation) GetMaxPrefund() *big.Int
- func (op *UserOperation) GetPaymaster() common.Address
- func (op *UserOperation) GetUserOpHash(entryPoint common.Address, chainID *big.Int) common.Hash
- func (op *UserOperation) HasIntent() bool
- func (op *UserOperation) HasSignature() bool
- func (op *UserOperation) MarshalJSON() ([]byte, error)
- func (op *UserOperation) Pack() []byte
- func (op *UserOperation) PackForSignature() []byte
- func (op *UserOperation) SetEVMInstructions(callDataValue []byte) error
- func (op *UserOperation) SetIntent(intentJSON string) error
- func (op *UserOperation) String() string
- func (op *UserOperation) ToMap() (map[string]any, error)
- func (op *UserOperation) UnmarshalJSON(data []byte) error
- func (op *UserOperation) Validate() (UserOpSolvedStatus, error)
- type UserOperationExt
Constants ¶
const ( ErrNoIntentFound userOperationError = "no Intent found" ErrIntentInvalidJSON userOperationError = "invalid Intent JSON" ErrNoSignatureValue userOperationError = "signature value is not found" ErrNoCallData userOperationError = "no CallData found" ErrInvalidCallData userOperationError = "invalid hex-encoded CallData" ErrInvalidSignature userOperationError = "invalid hex-encoded signature" ErrInvalidUserOp userOperationError = "ambiguous UserOperation solved state" ErrDoubleIntentDef userOperationError = "intent JSON is set in both calldata and signature fields" )
Define error constants
const SignatureLength = 65
Variables ¶
var ( // UserOpPrimitives is the primitive ABI types for each UserOperation field. UserOpPrimitives = []abi.ArgumentMarshaling{ {Name: "sender", InternalType: "Sender", Type: "address"}, {Name: "nonce", InternalType: "Nonce", Type: "uint256"}, {Name: "initCode", InternalType: "InitCode", Type: "bytes"}, {Name: "callData", InternalType: "CallData", Type: "bytes"}, {Name: "callGasLimit", InternalType: "CallGasLimit", Type: "uint256"}, {Name: "verificationGasLimit", InternalType: "VerificationGasLimit", Type: "uint256"}, {Name: "preVerificationGas", InternalType: "PreVerificationGas", Type: "uint256"}, {Name: "maxFeePerGas", InternalType: "MaxFeePerGas", Type: "uint256"}, {Name: "maxPriorityFeePerGas", InternalType: "MaxPriorityFeePerGas", Type: "uint256"}, {Name: "paymasterAndData", InternalType: "PaymasterAndData", Type: "bytes"}, {Name: "signature", InternalType: "Signature", Type: "bytes"}, } // UserOpType is the ABI type of a UserOperation. UserOpType, _ = abi.NewType("tuple", "op", UserOpPrimitives) // UserOpArr is the ABI type for an array of UserOperations. UserOpArr, _ = abi.NewType("tuple[]", "ops", UserOpPrimitives) )
Functions ¶
func ExtractJSONFromField ¶ added in v0.14.0
ExtractJSONFromField tries to unmarshal the provided field data into an Intent struct. If successful, it assumes the field data is a valid JSON string of the Intent.
Returns:
- string: The JSON data if unmarshalling is successful.
- bool: A boolean indicating if the unmarshalling was successful.
Types ¶
type Body ¶
type Body struct {
Intents []*Intent `json:"intents" binding:"required,dive"`
}
Body wraps a list of Intents for batch processing.
type BodyOfUserOps ¶ added in v0.4.0
type BodyOfUserOps struct { UserOps []*UserOperation `json:"user_ops" binding:"required,dive"` UserOpsExt []UserOperationExt `json:"user_ops_ext" binding:"required,dive"` }
BodyOfUserOps represents the request body for HTTP requests sent to the Solver. It contains slices of UserOperation and UserOperationExt, representing the primary data and its extended information required for processing by the Solver.
type ExtraData ¶ added in v0.17.0
type ExtraData struct {
PartiallyFillable bool `json:"partiallyFillable"`
}
type Intent ¶
type Intent struct { Sender string `json:"sender" binding:"required,eth_addr"` From Transactional `json:"from"` // asset or un stake To Transactional `json:"to"` // asset or stake ExtraData *ExtraData `json:"extraData,omitempty"` Status ProcessingStatus `json:"status,omitempty"` CreatedAt int64 `json:"createdAt,omitempty"` ExpirationAt int64 `json:"expirationAt,omitempty"` }
Intent represents a user's intention to perform a transaction, which could be a swap, buy, sell, staking, or restaking action.
func (*Intent) UnmarshalJSON ¶ added in v0.17.0
UnmarshalJSON custom method for Intent.
func (*Intent) ValidateIntent ¶ added in v0.17.0
Validation logic for the Intent structure.
type ProcessingStatus ¶
type ProcessingStatus string
const ( Received ProcessingStatus = "Received" SentToSolver ProcessingStatus = "SentToSolver" Solved ProcessingStatus = "Solved" Unsolved ProcessingStatus = "Unsolved" Expired ProcessingStatus = "Expired" OnChain ProcessingStatus = "OnChain" Invalid ProcessingStatus = "Invalid" )
Enumeration of possible processing statuses.
type Transactional ¶ added in v0.17.0
type Transactional interface{}
Transactional interface to be implemented by Asset and Stake.
type UserOpSolvedStatus ¶ added in v0.16.0
type UserOpSolvedStatus int
UserOpSolvedStatus is an enum type that defines the possible states of a UserOperation's resolution.It indicates whether an operation is unsolved, solved, conventional, or in an unknown state.
const ( UnsolvedUserOp UserOpSolvedStatus = iota SolvedUserOp // ConventionalUserOp indicates that the UserOperation does not contain Intent JSON and follows conventional // processing without Intent handling. ConventionalUserOp // UnknownUserOp indicates that the UserOperation's state is unknown or ambiguous. UnknownUserOp )
type UserOperation ¶ added in v0.4.0
type UserOperation struct { Sender common.Address `json:"sender" mapstructure:"sender" validate:"required"` Nonce *big.Int `json:"nonce" mapstructure:"nonce" validate:"required"` InitCode []byte `json:"initCode" mapstructure:"initCode" validate:"required"` CallData []byte `json:"callData" mapstructure:"callData" validate:"required"` CallGasLimit *big.Int `json:"callGasLimit" mapstructure:"callGasLimit" validate:"required"` VerificationGasLimit *big.Int `json:"verificationGasLimit" mapstructure:"verificationGasLimit" validate:"required"` PreVerificationGas *big.Int `json:"preVerificationGas" mapstructure:"preVerificationGas" validate:"required"` MaxFeePerGas *big.Int `json:"maxFeePerGas" mapstructure:"maxFeePerGas" validate:"required"` MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas" mapstructure:"maxPriorityFeePerGas" validate:"required"` PaymasterAndData []byte `json:"paymasterAndData" mapstructure:"paymasterAndData" validate:"required"` Signature []byte `json:"signature" mapstructure:"signature"` }
UserOperation represents an EIP-4337 style transaction for a smart contract account.
func (*UserOperation) GetDynamicGasPrice ¶ added in v0.4.0
func (op *UserOperation) GetDynamicGasPrice(basefee *big.Int) *big.Int
GetDynamicGasPrice returns the effective gas price paid by the UserOperation given a basefee. If basefee is nil, it will assume a value of 0.
func (*UserOperation) GetEVMInstructions ¶ added in v0.6.0
func (op *UserOperation) GetEVMInstructions() ([]byte, error)
GetEVMInstructions returns the Ethereum EVM instructions from the CallData field. It returns an error if the EVM instructions value does not exist or is not a valid hex encoded string.
func (*UserOperation) GetFactory ¶ added in v0.4.0
func (op *UserOperation) GetFactory() common.Address
GetFactory returns the address portion of InitCode if applicable. Otherwise it returns the zero address.
func (*UserOperation) GetIntent ¶ added in v0.4.0
func (op *UserOperation) GetIntent() (*Intent, error)
GetIntent takes the Intent Type from the CallData or Signature field, decodes it into an Intent struct, and returns the struct.
func (*UserOperation) GetIntentJSON ¶ added in v0.4.0
func (op *UserOperation) GetIntentJSON() (string, error)
GetIntentJSON returns the Intent JSON from the CallData or signature fields, if present.
func (*UserOperation) GetMaxGasAvailable ¶ added in v0.4.0
func (op *UserOperation) GetMaxGasAvailable() *big.Int
GetMaxGasAvailable returns the max amount of gas that can be consumed by this UserOperation.
func (*UserOperation) GetMaxPrefund ¶ added in v0.4.0
func (op *UserOperation) GetMaxPrefund() *big.Int
GetMaxPrefund returns the max amount of wei required to pay for gas fees by either the sender or paymaster.
func (*UserOperation) GetPaymaster ¶ added in v0.4.0
func (op *UserOperation) GetPaymaster() common.Address
GetPaymaster returns the address portion of PaymasterAndData if applicable. Otherwise it returns the zero address.
func (*UserOperation) GetUserOpHash ¶ added in v0.4.0
GetUserOpHash returns the hash of the userOp + entryPoint address + chainID.
func (*UserOperation) HasIntent ¶ added in v0.4.0
func (op *UserOperation) HasIntent() bool
HasIntent checks if the CallData or signature field contains a valid Intent JSON that decodes successfully into an Intent struct.
func (*UserOperation) HasSignature ¶ added in v0.13.0
func (op *UserOperation) HasSignature() bool
HasSignature checks if the signature field contains a fixed length hex-encoded signature value that is hex-encoded.
func (*UserOperation) MarshalJSON ¶ added in v0.4.0
func (op *UserOperation) MarshalJSON() ([]byte, error)
MarshalJSON returns a JSON encoding of the UserOperation.
func (*UserOperation) Pack ¶ added in v0.4.0
func (op *UserOperation) Pack() []byte
Pack returns a standard message of the userOp. This cannot be used to generate a userOpHash.
func (*UserOperation) PackForSignature ¶ added in v0.4.0
func (op *UserOperation) PackForSignature() []byte
PackForSignature returns a minimal message of the userOp. This can be used to generate a userOpHash.
func (*UserOperation) SetEVMInstructions ¶ added in v0.6.0
func (op *UserOperation) SetEVMInstructions(callDataValue []byte) error
SetEVMInstructions sets the EVM instructions in the CallData field of the UserOperation. It appropriately handles the Intent JSON based on the operation's solution state. The function first checks the solved status of the operation. For solved operations, it ensures that the signature has the required length. For unsolved operations, it moves the Intent JSON to the Signature field if present and valid, and then sets the provided EVM instructions in the CallData field.
Parameters:
- callDataValue: A hex-encoded or byte-level representation containing the EVM instructions to be set in the CallData field.
Returns:
- error: An error is returned if the operation's status is invalid, if there is no signature in the UserOperation when required, or if any other issue arises during the process. Otherwise, nil is returned, indicating successful setting of the EVM instructions in byte-level representation.
func (*UserOperation) SetIntent ¶ added in v0.4.0
func (op *UserOperation) SetIntent(intentJSON string) error
SetIntent sets the Intent JSON in the appropriate field of the UserOperation based on the operation's solution state. The function first validates the Intent JSON. If the userOp CallData field does not contain EVM instructions (indicating an unsolved userOp), the intentJSON is set directly in the CallData field. If the CallData field contains EVM instructions (indicating a solved userOp), the function then checks the length of the Signature field. If the length of the Signature is less than the required signature length an error is returned. If the Signature is of the appropriate length, the intentJSON is appended to the Signature field starting at the SignatureLength index.
Returns: - error: An error is returned if the intentJSON is invalid, if there is no signature in the UserOperation when required, or if any other issue arises during the process. Otherwise, nil is returned indicating successful setting of the intent JSON.
func (*UserOperation) String ¶ added in v0.7.0
func (op *UserOperation) String() string
func (*UserOperation) ToMap ¶ added in v0.4.0
func (op *UserOperation) ToMap() (map[string]any, error)
ToMap returns the current UserOp struct as a map type.
func (*UserOperation) UnmarshalJSON ¶ added in v0.6.0
func (op *UserOperation) UnmarshalJSON(data []byte) error
UnmarshalJSON does the reverse of the provided bundler custom JSON marshaler for a UserOperation.
func (*UserOperation) Validate ¶ added in v0.16.0
func (op *UserOperation) Validate() (UserOpSolvedStatus, error)
Validate checks the status of the UserOperation and returns its userOpSolvedStatus. It determines if the operation is conventional, unsolved, or solved based on the presence and content of CallData and Signature.
Returns:
- userOpSolvedStatus: The solved status of the UserOperation.
- error: An error if there's an issue with the operation's state, contents.
type UserOperationExt ¶ added in v0.4.0
type UserOperationExt struct { OriginalHashValue string `json:"original_hash_value" mapstructure:"original_hash_value" validate:"required"` ProcessingStatus ProcessingStatus `json:"processing_status" mapstructure:"processing_status" validate:"required"` }
UserOperationExt extends the UserOperation with additional information necessary for processing by the Solver.This includes the original hash value of the UserOperation and its processing status.The sequence of UserOperationExt instances must correspond to the sequence in the UserOps slice.