client

package
v0.0.0-...-a4145b4 Latest Latest
Warning

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

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

Documentation

Overview

Package client provides the mediator for processing incoming AiOperations 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 AiOperations 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,
	supportedAiMiddlewares []common.Address,
	opLookupLimit uint64,
) *Client

New initializes a new ERC-4337 client which can be extended with modules for validating AiOperations 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) EstimateAiOperationGas

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

EstimateAiOperationGas returns estimates for PreVerificationGas, VerificationGasLimit, and CallGasLimit given a AiOperation, AiMiddleware 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) GetAiOperationByHash

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

GetAiOperationByHash returns a AiOperation based on a given aiOpHash returned by *Client.SendAiOperation.

func (*Client) GetAiOperationReceipt

func (i *Client) GetAiOperationReceipt(
	hash string,
) (*filter.AiOperationReceipt, error)

GetAiOperationReceipt fetches a AiOperation receipt based on a aiOpHash returned by *Client.SendAiOperation.

func (*Client) SendAiOperation

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

SendAiOperation implements the method call for eth_sendAiOperation. It returns true if aiOp was accepted otherwise returns an error.

func (*Client) SetGetAiOpByHashFunc

func (i *Client) SetGetAiOpByHashFunc(fn GetAiOpByHashFunc)

SetGetAiOpByHashFunc defines a general function for fetching a aiOp given a aiOpHash, AiMiddleware address, and chain ID. This function is called in *Client.GetAiOperationByHash.

func (*Client) SetGetAiOpReceiptFunc

func (i *Client) SetGetAiOpReceiptFunc(fn GetAiOpReceiptFunc)

SetGetAiOpReceiptFunc defines a general function for fetching a AiOpReceipt given a aiOpHash and AiMiddleware address. This function is called in *Client.GetAiOperationReceipt.

func (*Client) SetGetGasEstimateFunc

func (i *Client) SetGetGasEstimateFunc(fn GetGasEstimateFunc)

SetGetGasEstimateFunc defines a general function for fetching an estimate for verificationGasLimit and callGasLimit given a aiOp and AiMiddleware address. This function is called in *Client.EstimateAiOperationGas.

func (*Client) SetGetGasPricesFunc

func (i *Client) SetGetGasPricesFunc(fn GetGasPricesFunc)

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

func (*Client) SetGetStakeFunc

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

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

func (*Client) SupportedAiMiddlewares

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

SupportedAiMiddlewares implements the method call for eth_supportedAiMiddlewares. It returns the array of AiMiddleware addresses that is supported by the client. The first address in the array is the preferred AiMiddleware.

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.AiOpHandlerFunc)

UseModules defines the AiOpHandlers to process a aiOp after it has gone through the standard checks.

type Debug

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

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

func (*Debug) ClearState

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

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

func (*Debug) DumpMempool

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

DumpMempool dumps the current AiOperations mempool in order of arrival.

func (*Debug) DumpReputation

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

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

func (*Debug) SendBundleNow

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

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

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

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

type GetAiOpByHashFunc

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

GetAiOpByHashFunc is a general interface for fetching a AiOperation given a aiOpHash, AiMiddleware address, chain ID, and block range.

func GetAiOpByHashWithEthClient

func GetAiOpByHashWithEthClient(eth *ethclient.Client) GetAiOpByHashFunc

GetAiOpByHashWithEthClient returns an implementation of GetAiOpByHashFunc that relies on an eth client to fetch a AiOperation.

type GetAiOpReceiptFunc

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

GetAiOpReceiptFunc is a general interface for fetching a AiOperationReceipt given a aiOpHash, AiMiddleware address, and block range.

func GetAiOpReceiptWithEthClient

func GetAiOpReceiptWithEthClient(eth *ethclient.Client) GetAiOpReceiptFunc

GetAiOpReceiptWithEthClient returns an implementation of GetAiOpReceiptFunc that relies on an eth client to fetch a AiOperationReceipt.

type GetGasEstimateFunc

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

GetGasEstimateFunc is a general interface for fetching an estimate for verificationGasLimit and callGasLimit given a aiOp and AiMiddleware address.

func GetGasEstimateWithEthClient

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

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

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

func GetGasPricesWithEthClient

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 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

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

Debug_bundler_clearState routes method calls to *Debug.ClearState.

func (*RpcAdapter) Debug_bundler_dumpMempool

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

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

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

Debug_bundler_sendBundleNow routes method calls to *Debug.SendBundleNow.

func (*RpcAdapter) Debug_bundler_setBundlingMode

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

Debug_bundler_setBundlingMode routes method calls to *Debug.SetBundlingMode.

func (*RpcAdapter) Debug_bundler_setReputation

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_estimateAiOperationGas

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

Eth_estimateAiOperationGas routes method calls to *Client.EstimateAiOperationGas.

func (*RpcAdapter) Eth_getAiOperationByHash

func (r *RpcAdapter) Eth_getAiOperationByHash(
	aiOpHash string,
) (*filter.HashLookupResult, error)

Eth_getAiOperationByHash routes method calls to *Client.GetAiOperationByHash.

func (*RpcAdapter) Eth_getAiOperationReceipt

func (r *RpcAdapter) Eth_getAiOperationReceipt(
	aiOpHash string,
) (*filter.AiOperationReceipt, error)

Eth_getAiOperationReceipt routes method calls to *Client.GetAiOperationReceipt.

func (*RpcAdapter) Eth_sendAiOperation

func (r *RpcAdapter) Eth_sendAiOperation(op aiOperation, ep string) (string, error)

Eth_sendAiOperation routes method calls to *Client.SendAiOperation.

func (*RpcAdapter) Eth_supportedAiMiddlewares

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

Eth_supportedAiMiddlewares routes method calls to *Client.SupportedAiMiddlewares.

Jump to

Keyboard shortcuts

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