client

package
v0.6.47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package client provides the mediator for processing incoming UserOperations to the bundler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client controls the end to end process of adding incoming UserOperations to the mempool. It also implements the required RPC methods as specified in EIP-4337.

func New

func New(
	mempool *mempool.Mempool,
	ov *gas.Overhead,
	chainID *big.Int,
	supportedEntryPoints []common.Address,
	opLookupLimit uint64,
) *Client

New initializes a new ERC-4337 client which can be extended with modules for validating UserOperations that are allowed to be added to the mempool.

func (*Client) ChainID

func (i *Client) ChainID() (string, error)

ChainID implements the method call for eth_chainId. It returns the current chainID used by the client. This method is used to validate that the client's chainID is in sync with the caller.

func (*Client) EstimateUserOperationGas added in v0.2.0

func (i *Client) EstimateUserOperationGas(
	op map[string]any,
	ep string,
	os map[string]any,
) (*gas.GasEstimates, error)

EstimateUserOperationGas returns estimates for PreVerificationGas, VerificationGasLimit, and CallGasLimit given a UserOperation, EntryPoint address, and state OverrideSet. The signature field and current gas values will not be validated although there should be dummy values in place for the most reliable results (e.g. a signature with the correct length).

func (*Client) GetUserOperationByHash added in v0.3.0

func (i *Client) GetUserOperationByHash(hash string) (*filter.HashLookupResult, error)

GetUserOperationByHash returns a UserOperation based on a given userOpHash returned by *Client.SendUserOperation.

func (*Client) GetUserOperationReceipt added in v0.2.0

func (i *Client) GetUserOperationReceipt(
	hash string,
) (*filter.UserOperationReceipt, error)

GetUserOperationReceipt fetches a UserOperation receipt based on a userOpHash returned by *Client.SendUserOperation.

func (*Client) SendUserOperation

func (i *Client) SendUserOperation(op map[string]any, ep string) (string, error)

SendUserOperation implements the method call for eth_sendUserOperation. It returns true if userOp was accepted otherwise returns an error.

func (*Client) SetGetGasEstimateFunc added in v0.6.0

func (i *Client) SetGetGasEstimateFunc(fn GetGasEstimateFunc)

SetGetGasEstimateFunc defines a general function for fetching an estimate for verificationGasLimit and callGasLimit given a userOp and EntryPoint address. This function is called in *Client.EstimateUserOperationGas.

func (*Client) SetGetGasPricesFunc added in v0.6.27

func (i *Client) SetGetGasPricesFunc(fn GetGasPricesFunc)

SetGetGasPricesFunc defines a general function for fetching values for maxFeePerGas and maxPriorityFeePerGas. This function is called in *Client.EstimateUserOperationGas if given fee values are 0.

func (*Client) SetGetStakeFunc added in v0.6.33

func (i *Client) SetGetStakeFunc(fn stake.GetStakeFunc)

SetGetStakeFunc defines a general function for retrieving the EntryPoint stake for a given address. This function is called in *Client.SendUserOperation to create a context.

func (*Client) SetGetUserOpByHashFunc added in v0.3.0

func (i *Client) SetGetUserOpByHashFunc(fn GetUserOpByHashFunc)

SetGetUserOpByHashFunc defines a general function for fetching a userOp given a userOpHash, EntryPoint address, and chain ID. This function is called in *Client.GetUserOperationByHash.

func (*Client) SetGetUserOpReceiptFunc added in v0.2.0

func (i *Client) SetGetUserOpReceiptFunc(fn GetUserOpReceiptFunc)

SetGetUserOpReceiptFunc defines a general function for fetching a UserOpReceipt given a userOpHash and EntryPoint address. This function is called in *Client.GetUserOperationReceipt.

func (*Client) SupportedEntryPoints

func (i *Client) SupportedEntryPoints() ([]string, error)

SupportedEntryPoints implements the method call for eth_supportedEntryPoints. It returns the array of EntryPoint addresses that is supported by the client. The first address in the array is the preferred EntryPoint.

func (*Client) UseLogger

func (i *Client) UseLogger(logger logr.Logger)

UseLogger defines the logger object used by the Client instance based on the go-logr/logr interface.

func (*Client) UseModules

func (i *Client) UseModules(handlers ...modules.UserOpHandlerFunc)

UseModules defines the UserOpHandlers to process a userOp after it has gone through the standard checks.

type Debug added in v0.2.0

type Debug struct {
	// contains filtered or unexported fields
}

Debug exposes methods used for testing the bundler. These should not be made available in production.

func NewDebug added in v0.2.0

func NewDebug(
	eoa *signer.EOA,
	eth *ethclient.Client,
	mempool *mempool.Mempool,
	rep *entities.Reputation,
	bundler *bundler.Bundler,
	chainID *big.Int,
	entrypoint common.Address,
	beneficiary common.Address,
) *Debug

func (*Debug) ClearState added in v0.2.0

func (d *Debug) ClearState() (string, error)

ClearState clears the bundler mempool and reputation data of paymasters/accounts/factories/aggregators.

func (*Debug) DumpMempool added in v0.2.0

func (d *Debug) DumpMempool(ep string) ([]map[string]any, error)

DumpMempool dumps the current UserOperations mempool in order of arrival.

func (*Debug) DumpReputation added in v0.6.33

func (d *Debug) DumpReputation(ep string) ([]map[string]any, error)

DumpReputation returns the reputation data of all known addresses. TODO: Implement

func (*Debug) SendBundleNow added in v0.2.0

func (d *Debug) SendBundleNow() (string, error)

SendBundleNow forces the bundler to build and execute a bundle from the mempool as handleOps() transaction.

func (*Debug) SetBundlingMode added in v0.2.0

func (d *Debug) SetBundlingMode(mode string) (string, error)

SetBundlingMode allows the bundler to be stopped so that an explicit call to debug_bundler_sendBundleNow is required to send a bundle.

func (*Debug) SetReputation added in v0.6.33

func (d *Debug) SetReputation(entries []any, ep string) (string, error)

SetReputation allows the bundler to set the reputation of given addresses.

type GetGasEstimateFunc added in v0.6.0

type GetGasEstimateFunc = func(
	ep common.Address,
	op *userop.UserOperation,
	sos state.OverrideSet,
) (verificationGas uint64, callGas uint64, err error)

GetGasEstimateFunc is a general interface for fetching an estimate for verificationGasLimit and callGasLimit given a userOp and EntryPoint address.

func GetGasEstimateWithEthClient added in v0.6.0

func GetGasEstimateWithEthClient(
	rpc *rpc.Client,
	ov *gas.Overhead,
	chain *big.Int,
	maxGasLimit *big.Int,
	tracer string,
) GetGasEstimateFunc

GetGasEstimateWithEthClient returns an implementation of GetGasEstimateFunc that relies on an eth client to fetch an estimate for verificationGasLimit and callGasLimit.

type GetGasPricesFunc added in v0.6.27

type GetGasPricesFunc = func() (*fees.GasPrices, error)

GetGasPricesFunc is a general interface for fetching values for maxFeePerGas and maxPriorityFeePerGas.

func GetGasPricesWithEthClient added in v0.6.27

func GetGasPricesWithEthClient(eth *ethclient.Client) GetGasPricesFunc

GetGasPricesWithEthClient returns an implementation of GetGasPricesFunc that relies on an eth client to fetch values for maxFeePerGas and maxPriorityFeePerGas.

type GetUserOpByHashFunc added in v0.3.0

type GetUserOpByHashFunc func(hash string, ep common.Address, chain *big.Int, blkRange uint64) (*filter.HashLookupResult, error)

GetUserOpByHashFunc is a general interface for fetching a UserOperation given a userOpHash, EntryPoint address, chain ID, and block range.

func GetUserOpByHashWithEthClient added in v0.3.0

func GetUserOpByHashWithEthClient(eth *ethclient.Client) GetUserOpByHashFunc

GetUserOpByHashWithEthClient returns an implementation of GetUserOpByHashFunc that relies on an eth client to fetch a UserOperation.

type GetUserOpReceiptFunc added in v0.2.0

type GetUserOpReceiptFunc = func(hash string, ep common.Address, blkRange uint64) (*filter.UserOperationReceipt, error)

GetUserOpReceiptFunc is a general interface for fetching a UserOperationReceipt given a userOpHash, EntryPoint address, and block range.

func GetUserOpReceiptWithEthClient added in v0.2.0

func GetUserOpReceiptWithEthClient(eth *ethclient.Client) GetUserOpReceiptFunc

GetUserOpReceiptWithEthClient returns an implementation of GetUserOpReceiptFunc that relies on an eth client to fetch a UserOperationReceipt.

type RpcAdapter

type RpcAdapter struct {
	// contains filtered or unexported fields
}

RpcAdapter is an adapter for routing JSON-RPC method calls to the correct client functions.

func NewRpcAdapter

func NewRpcAdapter(client *Client, debug *Debug) *RpcAdapter

NewRpcAdapter initializes a new RpcAdapter which can be used with a JSON-RPC server.

func (*RpcAdapter) Debug_bundler_clearState added in v0.2.0

func (r *RpcAdapter) Debug_bundler_clearState() (string, error)

Debug_bundler_clearState routes method calls to *Debug.ClearState.

func (*RpcAdapter) Debug_bundler_dumpMempool added in v0.2.0

func (r *RpcAdapter) Debug_bundler_dumpMempool(ep string) ([]map[string]any, error)

Debug_bundler_dumpMempool routes method calls to *Debug.DumpMempool.

func (*RpcAdapter) Debug_bundler_dumpReputation added in v0.6.33

func (r *RpcAdapter) Debug_bundler_dumpReputation(ep string) ([]map[string]any, error)

Debug_bundler_dumpReputation routes method calls to *Debug.DumpReputation.

func (*RpcAdapter) Debug_bundler_sendBundleNow added in v0.2.0

func (r *RpcAdapter) Debug_bundler_sendBundleNow() (string, error)

Debug_bundler_sendBundleNow routes method calls to *Debug.SendBundleNow.

func (*RpcAdapter) Debug_bundler_setBundlingMode added in v0.2.0

func (r *RpcAdapter) Debug_bundler_setBundlingMode(mode string) (string, error)

Debug_bundler_setBundlingMode routes method calls to *Debug.SetBundlingMode.

func (*RpcAdapter) Debug_bundler_setReputation added in v0.6.33

func (r *RpcAdapter) Debug_bundler_setReputation(entries []any, ep string) (string, error)

Debug_bundler_setReputation routes method calls to *Debug.SetReputation.

func (*RpcAdapter) Eth_chainId

func (r *RpcAdapter) Eth_chainId() (string, error)

Eth_chainId routes method calls to *Client.ChainID.

func (*RpcAdapter) Eth_estimateUserOperationGas added in v0.2.0

func (r *RpcAdapter) Eth_estimateUserOperationGas(
	op userOperation,
	ep string,
	os optional_stateOverride,
) (*gas.GasEstimates, error)

Eth_estimateUserOperationGas routes method calls to *Client.EstimateUserOperationGas.

func (*RpcAdapter) Eth_getUserOperationByHash added in v0.3.0

func (r *RpcAdapter) Eth_getUserOperationByHash(
	userOpHash string,
) (*filter.HashLookupResult, error)

Eth_getUserOperationByHash routes method calls to *Client.GetUserOperationByHash.

func (*RpcAdapter) Eth_getUserOperationReceipt added in v0.2.0

func (r *RpcAdapter) Eth_getUserOperationReceipt(
	userOpHash string,
) (*filter.UserOperationReceipt, error)

Eth_getUserOperationReceipt routes method calls to *Client.GetUserOperationReceipt.

func (*RpcAdapter) Eth_sendUserOperation

func (r *RpcAdapter) Eth_sendUserOperation(op userOperation, ep string) (string, error)

Eth_sendUserOperation routes method calls to *Client.SendUserOperation.

func (*RpcAdapter) Eth_supportedEntryPoints

func (r *RpcAdapter) Eth_supportedEntryPoints() ([]string, error)

Eth_supportedEntryPoints routes method calls to *Client.SupportedEntryPoints.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL