userop

package
v0.0.117 Latest Latest
Warning

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

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

README

UserOp Golang Library

Overview

The UserOp library is a Golang package designed to simplify the creation and interaction with user operations in a decentralized application. It provides functionalities to work with smart walets, create user operations, and send them to the client bundler for execution.

Features

  • Smart Wallet Support: Enables the use of smart wallets for transactions, including deploying new wallets and performing transactions through them.
  • Multi-Call Operations: Supports bundling multiple operations into a single userOp, reducing the need for multiple transactions.
  • Gas Optimization: Offers configurable gas pricing strategies to optimize transaction costs.
  • Paymaster Integration: Integrates with paymasters to enable gasless transactions, where transaction fees can be paid using ERC20 tokens.
  • Infrastructure Flexibility: Allows configuration for different infrastructure providers by setting the provider and bundler URLs.
  • Account abstraction interoperability: Provides a unified interface for interacting with smart wallets, regardless of the underlying smart wallet implementation.
Currently supported Smart Contract providers
Smart Wallets
Paymasters
Signers

Installation

To use this library in your Golang project, you can install it using the following command:

go get github.com/layer-3/clearsync/pkg/userop

Usage

UserOp Client

All the functionalities provided by the UserOp library are accessed through the UserOp client. The client is responsible for checking smart account information, creating user operations and sending them to the client bundler.

UserOp client implements the following interface:

type Client interface {
  IsAccountDeployed(ctx context.Context, owner common.Address, index decimal.Decimal) (bool, error)
  GetAccountAddress(ctx context.Context, owner common.Address, index decimal.Decimal) (common.Address, error)
  NewUserOp(
    ctx context.Context,
    sender common.Address,
    signer Signer,
    calls []Call,
    walletDeploymentOpts *WalletDeploymentOpts,
    gasLimitOverrides *GasLimitOverrides,
  ) (UserOperation, error)
  SendUserOp(ctx context.Context, op UserOperation) (done <-chan Receipt, err error)
}
Configuration

The UserOp client requires a configuration struct to be created. The configuration struct allows you to specify the provider, bundler, wallet, paymaster and other details.

Below is an example of a configuration struct (testing/config.example.go):

var (
  exampleConfig = userop.ClientConfig{
    ProviderURL: "https://YOUR_PROVIDER_URL",
    BundlerURL:  "https://YOUR_BUNDLER_URL",
    PollPeriod:  100 * time.Millisecond,
    EntryPoint:  common.HexToAddress("ENTRY_POINT_ADDRESS"),
    SmartWallet: userop.SmartWalletConfig{
      // Example of a Kernel Smart Wallet config with Kernel v2.2.
      Type: &userop.SmartWalletKernel,
      Factory: common.HexToAddress("0x5de4839a76cf55d0c90e2061ef4386d962E15ae3"), // Zerodev Kernel factory address:
      Logic:          common.HexToAddress("0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5"), // Zerodev Kernel implementation (logic) address:
      ECDSAValidator: common.HexToAddress("0xd9AB5096a832b9ce79914329DAEE236f8Eea0390"),
    },
    Paymaster: userop.PaymasterConfig{
      // Example of a Pimlico USDC.e ERC20 Paymaster config.
      Type:    &userop.PaymasterPimlicoERC20,
      URL:     "", // Pimlico ERC20 Paymaster does not require a URL.
      Address: common.HexToAddress("0xa683b47e447De6c8A007d9e294e87B6Db333Eb18"),
      PimlicoERC20: userop.PimlicoERC20Config{
        VerificationGasOverhead: decimal.RequireFromString("10000"), // verification gas overhead to be added to user op verification gas limit
      },
    },
    Gas: userop.GasConfig{
      // These are default values.
      MaxPriorityFeePerGasMultiplier: decimal.RequireFromString("1.13"),
      MaxFeePerGasMultiplier:         decimal.RequireFromString("2"),
    },
  }

  // wallet deployment options are used when creating a new user op for the smart wallet that is not deployed yet
  walletDeploymentOpts = &userop.WalletDeploymentOpts{
    Owner: common.HexToAddress("YOUR_OWNER_ADDRESS"),
    Index: decimal.NewFromInt(0),
  }

  // You can set either of gas limits when creating an user op to override the bundler's estimation.
  // Or you can set all of them to disable the bundler's estimation.
  gasLimitOverrides = &userop.GasLimitOverrides{
    CallGasLimit:         big.NewInt(42),
    VerificationGasLimit: big.NewInt(42),
    PreVerificationGas:   big.NewInt(42),
  }

  // signer is used to sign the user op upon creation
  exampleSigner = userop.SignerForKernel(must(crypto.HexToECDSA(
  "0xYOUR_PRIVATE_KEY")))
)
Creating a UserOp Client

To create a UserOp client, you need to provide a configuration struct. If you want to change any of configuration components, you should modify the configuration and create a new client.

import "github.com/layer-3/clearsync/pkg/userop"

// Create a UserOp client
client, err := userop.NewClient(exampleConfig)
if err != nil {
    panic(errors.New("Error creating UserOp client:", err))
}
Smart Account Operations

The UserOp client provides the following smart account-related functionalities:

Check if Smart Account is Deployed

Use client.IsAccountDeployed to check if a smart account is deployed for a given owner and index.

// IsAccountDeployed checks whether the smart wallet for the specified owner EOA and index is deployed.
//
// Parameters:
//   - owner - is the EOA address of the smart wallet owner.
//   - index - is the index of the smart wallet, 0 by default. SW index allows to deploy multiple smart wallets for the same owner.
//
// Returns:
//   - bool - true if the smart wallet is deployed, false if not
//   - error - if failed to check.
func (c *backend) IsAccountDeployed(ctx context.Context, owner common.Address, index decimal.Decimal) (bool, error)

Usage example:

ownerEOA := "0xEOAownerAddress"
accountIndex := 0 // Index of the smart wallet, 0 by default. EOA can have multiple smart wallets.

ctx := context.Background()
deployed, err := client.IsAccountDeployed(ctx, ownerEOA, accountIndex)
if err != nil {
    log.Fatal("Error checking if Smart Account is deployed:", err)
}
fmt.Printf("Smart Account for owner %s and index %d is deployed: %t\n", ownerEOA, accountIndex, deployed)
Calculate Smart Account Address

Use client.GetAccountAddress to calculate the address of a smart account for a given owner and index.

// GetAccountAddress returns the address of the smart wallet for the specified owner EOA and index.
//
// Parameters:
//   - owner - is the EOA address of the smart wallet owner.
//   - index - is the index of the smart wallet, 0 by default. SW index allows to deploy multiple smart wallets for the same owner.
//
// Returns:
//   - common.Address - an address of the smart wallet
//   - error - if failed to calculate it.
func (c *backend) GetAccountAddress(ctx context.Context, owner common.Address, index decimal.Decimal) (common.Address, error)

Usage example:

ownerEOA := "0xEOAownerAddress"
accountIndex := 0

ctx := context.Background()
address, err := client.GetAccountAddress(ctx, ownerEOA, accountIndex)
if err != nil {
    log.Fatal("Error calculating Smart Account address:", err)
}
fmt.Printf("Smart Account address for owner %s and index %d is %s\n", ownerEOA, accountIndex, address)
User Operation Creation and Execution
Create User Operation

Use client.NewUserOp to create a new user operation.

// NewUserOp builds a new UserOperation and fills all the fields.
//
// Parameters:
//   - ctx - is the context of the operation.
//   - smartWallet - is the address of the smart wallet that will execute the user operation.
//   - signer - is the signer function that will sign the user operation.
//   - calls - is the list of calls to be executed in the user operation.
//   - walletDeploymentOpts - are the options for the smart wallet deployment. Can be nil if the smart wallet is already deployed.
//
// Returns:
//   - UserOperation - user operation with all fields filled in.
//   - error - if failed to build the user operation.
func (c *backend) NewUserOp(
  ctx context.Context,
  smartWallet common.Address,
  signer Signer,
  calls []Call,
  walletDeploymentOpts *WalletDeploymentOpts,
) (UserOperation, error)

Usage example:

sender := common.HexToAddress("0xsmartWalletAddress")
call := userop.Call{
    To:      common.HexToAddress("0xtoAddress"),
    Value:   1000000000000000000, // 1 ETH in wei
}

ctx := context.Background()
userOp, err := client.NewUserOp(ctx, sender, signer, userop.Call[]{call}, nil)
if err != nil {
    log.Fatal("Error creating User Operation:", err)
}
fmt.Printf("User Operation created: %v\n", userOp)
Send User Operation to Bundler

Use client.SendUserOp to send a user operation to the client bundler for execution.

type Receipt struct {
  UserOpHash    common.Hash
  TxHash        common.Hash
  Sender        common.Address
  Nonce         decimal.Decimal
  Success       bool
  ActualGasCost decimal.Decimal
  ActualGasUsed decimal.Decimal
  RevertData    []byte // non-empty if Success is false and EntryPoint was able to catch revert reason.
}

// SendUserOp submits a user operation to a bundler and returns a channel to await for the userOp receipt.
//
// Parameters:
//   - ctx - is the context of the operation.
//   - op - is the user operation to be sent.
//
// Returns:
//   - <-chan Receipt - a channel to await for the userOp receipt.
//   - error - if failed to send the user operation
func SendUserOp(ctx context.Context, op UserOperation) (done <-chan Receipt, err error)

Usage example:

ctx := context.Background()
receiptChannel, err := client.SendUserOp(ctx, userOp)
if err != nil {
    log.Fatal("Error sending User Operation to bundler:", err)
}

// Await the receipt from the channel
result := <-receiptChannel
fmt.Printf("User Operation result: %v\n", result)

Contributing

Feel free to contribute by opening issues or submitting pull requests to this repository.

License

This UserOp library is licensed under the MIT License.

Documentation

Overview

Package userop provides an ERC-4337 pseudo-transaction object called a UserOperation which is used to execute actions through a smart contract account. This isn't to be mistaken for a regular transaction type.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoWalletDeploymentOpts is returned when the wallet deployment opts
	// are required to build and submit userop, but they are not specified.
	ErrNoWalletDeploymentOpts = errors.New("wallet deployment opts not specified")
	// ErrNoWalletOwnerInWDO is returned when the wallet owner is not specified.
	ErrNoWalletOwnerInWDO = errors.New("wallet deployment opts: wallet owner not specified")
	// ErrInvalidPollDuration is returned when blockchain poll duration is non-present or its format is invalid.
	ErrInvalidPollDuration = errors.New("invalid blockchain poll duration")
	// ErrInvalidEntryPointAddress is returned when the entrypoint address is invalid.
	ErrInvalidEntryPointAddress = errors.New("invalid entry point address")
	// ErrInvalidFactoryAddress is returned when the factory address is invalid.
	ErrInvalidFactoryAddress = errors.New("invalid factory address")
	// ErrInvalidLogicAddress is returned when the logic address is invalid.
	ErrInvalidLogicAddress = errors.New("invalid logic address")
	// ErrInvalidECDSAValidatorAddress is returned when the ECDSA validator address is invalid.
	ErrInvalidECDSAValidatorAddress = errors.New("invalid ECDSA validator address")
	// ErrInvalidPaymasterURL is returned when the paymaster URL is invalid.
	ErrInvalidPaymasterURL = errors.New("invalid paymaster URL")
	// ErrInvalidPaymasterAddress is returned when the paymaster address is invalid.
	ErrInvalidPaymasterAddress = errors.New("invalid paymaster address")
	// ErrNoSigner is returned when the signer is not specified.
	ErrNoSigner = errors.New("signer not specified")
	// ErrNoCalls is returned when the calls are not specified.
	ErrNoCalls = errors.New("calls not specified")
	// ErrPaymasterNotSupported is returned on attempt to build client with an unsupported paymaster type.
	// Make sure that the paymaster type you are trying to use
	// has no `unsupported` or `untested` tags in `paymaster_type.go` source file.
	ErrPaymasterNotSupported = errors.New("paymaster type not supported")
)
View Source
var (
	PaymasterDisabled           = PaymasterType{"off"}
	PaymasterPimlicoERC20       = PaymasterType{"pimlico_erc20"}
	PaymasterPimlicoVerifying   = PaymasterType{"pimlico_verifying"}
	PaymasterBiconomyERC20      = PaymasterType{"biconomy_erc20"}      // not tested
	PaymasterBiconomySponsoring = PaymasterType{"biconomy_sponsoring"} // not tested

)

Functions

This section is empty.

Types

type BiconomyERC20Config

type BiconomyERC20Config struct {
	Mode               string            `yaml:"mode" env:"MODE"`
	CalculateGasLimits bool              `yaml:"calculate_gas_limits" env:"CALCULATE_GAS_LIMITS"`
	TokenInfo          BiconomyTokenInfo `yaml:"token_info" env-prefix:"TOKEN_INFO_"`
}

BiconomyERC20Config represents the configuration for the Biconomy ERC20 paymaster. See the RPC endpoint docs at https://docs.biconomy.io/Paymaster/api/sponsor-useroperation#2-mode-is-erc20-

func (*BiconomyERC20Config) Init

func (config *BiconomyERC20Config) Init()

type BiconomySmartAccountInfo

type BiconomySmartAccountInfo struct {
	Name    string `yaml:"name" env:"NAME"`
	Version string `yaml:"version" env:"VERSION"`
}

BiconomySmartAccountInfo represents the configuration for the Biconomy smart contract that sponsors transactions.

type BiconomySponsoringConfig

type BiconomySponsoringConfig struct {
	Mode               string                        `yaml:"mode" env:"MODE"`
	CalculateGasLimits bool                          `yaml:"calculate_gas_limits" env:"CALCULATE_GAS_LIMITS"`
	ExpiryDuration     int                           `yaml:"expiry_duration" env:"EXPIRY_DURATION"`
	SponsorshipInfo    BiconomySponsorshipInfoConfig `yaml:"sponsorship_info" env-prefix:"SPONSORSHIP_INFO_"`
}

BiconomySponsoringConfig represents the configuration for the Biconomy Sponsoring paymaster. See the RPC endpoint docs at https://docs.biconomy.io/Paymaster/api/sponsor-useroperation#1-mode-is-sponsored-

func (*BiconomySponsoringConfig) Init

func (config *BiconomySponsoringConfig) Init()

type BiconomySponsorshipInfoConfig

type BiconomySponsorshipInfoConfig struct {
	WebhookData      map[string]any           `yaml:"webhook_data" env:"WEBHOOK_DATA"`
	SmartAccountInfo BiconomySmartAccountInfo `yaml:"smart_account_info" env-prefix:"SMART_ACCOUNT_INFO_"`
}

BiconomySponsorshipInfoConfig represents the configuration for transaction sponsoring for the Biconomy Sponsoring paymaster. More about webhooks: https://docs.biconomy.io/Paymaster/api/webhookapi

type BiconomyTokenInfo

type BiconomyTokenInfo struct {
	FeeTokenAddress common.Address `yaml:"fee_token_address" env:"FEE_TOKEN"`
}

BiconomyTokenInfo represents the token used to pay for fees for the Biconomy paymaster.

type Client

type Client interface {
	// IsAccountDeployed checks whether the smart wallet for the specified owner EOA and index is deployed.
	//
	// Parameters:
	//   - owner - is the EOA address of the smart wallet owner.
	//   - index - is the index of the smart wallet, 0 by default. SW index allows to deploy multiple smart wallets for the same owner.
	//
	// Returns:
	//   - bool - true if the smart wallet is deployed, false if not
	//   - error - if failed to check.
	IsAccountDeployed(ctx context.Context, owner common.Address, index decimal.Decimal) (bool, error)

	// GetAccountAddress returns the address of the smart wallet for the specified owner EOA and index.
	//
	// Parameters:
	//   - owner - is the EOA address of the smart wallet owner.
	//   - index - is the index of the smart wallet, 0 by default. SW index allows to deploy multiple smart wallets for the same owner.
	//
	// Returns:
	//   - common.Address - an address of the smart wallet
	//   - error - if failed to calculate it.
	GetAccountAddress(ctx context.Context, owner common.Address, index decimal.Decimal) (common.Address, error)

	// NewUserOp builds a new UserOperation and fills all the fields.
	//
	// NOTE: only `executeBatch` is supported for now.
	//
	// Parameters:
	//   - ctx - is the context of the operation.
	//   - smartWallet - is the address of the smart wallet that will execute the user operation.
	//   - signer - is the signer function that will sign the user operation.
	//   - calls - is the list of calls to be executed in the user operation. Must not be empty.
	//   - walletDeploymentOpts - are the options for the smart wallet deployment. Can be nil if the smart wallet is already deployed.
	// 	 - overrides - are the overrides for the middleware during the user operation creation. Can be nil.
	//
	// Returns:
	//   - UserOperation - user operation with all fields filled in.
	//   - error - if failed to build the user operation.
	NewUserOp(
		ctx context.Context,
		sender common.Address,
		signer Signer,
		calls smart_wallet.Calls,
		walletDeploymentOpts *WalletDeploymentOpts,
		overrides *Overrides,
	) (UserOperation, error)

	// SignUserOp signs the user operation with the provided signer.
	//
	// Parameters:
	//   - ctx - is the context of the operation.
	//   - op - is the user operation to be signed.
	//   - signer - is the signer function that will sign the user operation.
	//
	// Returns:
	//   - UserOperation - user operation with modified signature.
	//   - error - if failed to sign the user operation
	SignUserOp(
		ctx context.Context,
		op UserOperation,
		signer Signer,
	) (UserOperation, error)

	// SendUserOp submits a user operation to a bundler and returns a channel to await for the userOp receipt.
	//
	// Parameters:
	//   - ctx - is the context of the operation.
	//   - op - is the user operation to be sent.
	//
	// Returns:
	//   - <-chan Receipt - a channel to await for the userOp receipt.
	//   - error - if failed to send the user operation
	SendUserOp(ctx context.Context, op UserOperation) (done <-chan Receipt, err error)
}

Client represents a client for creating and posting user operations.

func NewClient

func NewClient(config ClientConfig) (Client, error)

NewClient is a factory that builds a new user operation client based on the provided configuration.

type ClientConfig

type ClientConfig struct {
	ProviderURL string              `yaml:"provider_url" env:"USEROP_CLIENT_PROVIDER_URL"`
	BundlerURL  string              `yaml:"bundler_url" env:"USEROP_CLIENT_BUNDLER_URL"`
	EntryPoint  common.Address      `yaml:"entry_point" env:"USEROP_CLIENT_ENTRY_POINT"`
	Gas         GasConfig           `yaml:"gas"`
	SmartWallet smart_wallet.Config `yaml:"smart_wallet"`
	Paymaster   PaymasterConfig     `yaml:"paymaster"`
	LoggerLevel string              `yaml:"logger_level" env:"USEROP_CLIENT_LOGGER_LEVEL"`
}

ClientConfig represents the configuration for the user operation client.

func NewClientConfigFromEnv

func NewClientConfigFromEnv() (config ClientConfig, err error)

NewClientConfigFromEnv reads the client configuration from environment variables.

func NewClientConfigFromFile

func NewClientConfigFromFile(path string) (config ClientConfig, err error)

NewClientConfigFromFile reads the client configuration from a file.

func (*ClientConfig) Init

func (conf *ClientConfig) Init()

type ECDSASigner

type ECDSASigner interface {
	Sign(msg []byte) ([]byte, error)
}

ECDSASigner represents a handler that signs a message using ecdsa private key.

type EthBackend

type EthBackend interface {
	ethereum.ChainReader
	ethereum.ChainStateReader
	ethereum.TransactionReader
	ethereum.TransactionSender
	ethereum.ContractCaller

	ChainID(ctx context.Context) (*big.Int, error)
	BlockNumber(ctx context.Context) (uint64, error)
	WaitMinedPeriod() time.Duration
	RPC() *rpc.Client
	bind.ContractBackend
}

func NewEthBackend

func NewEthBackend(rpcURL url.URL) (EthBackend, error)

type GasConfig

type GasConfig struct {
	MaxPriorityFeePerGasMultiplier decimal.Decimal `yaml:"max_priority_fee_per_gas_multiplier" env:"GAS_CONFIG_MAX_PRIORITY_FEE_PER_GAS_MULTIPLIER"` // percentage, 2.42 means 242% increase
	MaxFeePerGasMultiplier         decimal.Decimal `yaml:"max_fee_per_gas_multiplier" env:"GAS_CONFIG_MAX_FEE_PER_GAS_MULTIPLIER"`                   // percentage
}

GasConfig represents the configuration for the userop transaction gas fees.

func (*GasConfig) Init

func (c *GasConfig) Init()

Init initializes the GasConfig with default values.

type GasLimitOverrides added in v0.0.32

type GasLimitOverrides struct {
	CallGasLimit         *big.Int
	VerificationGasLimit *big.Int
	PreVerificationGas   *big.Int
}

These override the bundler's estimation. NOTE: if all are supplied, bundler's estimation is NOT performed.

type GasPriceOverrides added in v0.0.44

type GasPriceOverrides struct {
	MaxFeePerGas         *big.Int
	MaxPriorityFeePerGas *big.Int
}

These override provider's estimation. NOTE: if all are supplied, provider's estimation is NOT performed.

type MockUserOperationClient

type MockUserOperationClient struct {
	mock.Mock
}

func (*MockUserOperationClient) NewUserOp

func (*MockUserOperationClient) SendUserOp

func (c *MockUserOperationClient) SendUserOp(ctx context.Context, op UserOperation) (<-chan struct{}, error)

type NonceKeyRotator added in v0.0.54

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

Implements a nonce key rotation for 2d nonces. https://docs.stackup.sh/docs/useroperation-nonce

func NewNonceKeyRotator added in v0.0.54

func NewNonceKeyRotator() NonceKeyRotator

func (*NonceKeyRotator) Next added in v0.0.54

func (r *NonceKeyRotator) Next() *big.Int

type Overrides added in v0.0.44

type Overrides struct {
	Nonce     *big.Int
	InitCode  []byte
	GasPrices *GasPriceOverrides
	GasLimits *GasLimitOverrides
}

Each field overrides the corresponding middleware during the user operation creation.

type PaymasterConfig

type PaymasterConfig struct {
	Type    *PaymasterType `yaml:"type" env:"PAYMASTER_CONFIG_TYPE"` // nil is equivalent to PaymasterDisabled
	URL     string         `yaml:"url" env:"PAYMASTER_CONFIG_URL"`
	Address common.Address `yaml:"address" env:"PAYMASTER_CONFIG_ADDRESS"`

	PimlicoERC20       PimlicoERC20Config       `yaml:"pimlico_erc20" env-prefix:"PAYMASTER_CONFIG_PIMLICO_ERC20_"`
	PimlicoVerifying   PimlicoVerifyingConfig   `yaml:"pimlico_verifying" env-prefix:"PAYMASTER_CONFIG_PIMLICO_VERIFYING_"`
	BiconomyERC20      BiconomyERC20Config      `yaml:"biconomy_erc20" env-prefix:"PAYMASTER_CONFIG_BICONOMY_ERC20_"`
	BiconomySponsoring BiconomySponsoringConfig `yaml:"biconomy_sponsoring" env-prefix:"PAYMASTER_CONFIG_BICONOMY_SPONSORING_"`
}

PaymasterConfig represents the configuration for the paymaster to be used with the client.

func (*PaymasterConfig) Init

func (c *PaymasterConfig) Init()

Init initializes the PaymasterConfig with default values.

type PaymasterType

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

PaymasterType represents an enum for supported ERC-4337 paymaster that can be used with the client to sponsor user operations.

func (*PaymasterType) SetValue

func (t *PaymasterType) SetValue(s string) error

SetValue implements the cleanenv.Setter interface.

func (PaymasterType) String

func (t PaymasterType) String() string

func (*PaymasterType) UnmarshalJSON

func (t *PaymasterType) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshalls the JSON representation of a PaymasterType.

func (*PaymasterType) UnmarshalYAML

func (t *PaymasterType) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshalls the YAML representation of a PaymasterType.

type PimlicoERC20Config

type PimlicoERC20Config struct {
	// MaxTokenCost specifies the limit for tokens to spend.
	// Operations requiring user to pay more
	// than specified amount of tokens for gas will fail.
	MaxTokenCost            decimal.Decimal `json:"maxTokenCost" env:"MAX_TOKEN_COST"` // unused for now
	VerificationGasOverhead decimal.Decimal `yaml:"verification_gas_overhead" env:"VERIFICATION_GAS_OVERHEAD"`
}

PimlicoERC20Config represents the configuration for the Pimlico ERC20 paymaster.

func (*PimlicoERC20Config) Init

func (config *PimlicoERC20Config) Init()

type PimlicoVerifyingConfig

type PimlicoVerifyingConfig struct {
	SponsorshipPolicyID string `json:"sponsorshipPolicyId" yaml:"sponsorship_policy_id" env:"SPONSORSHIP_POLICY_ID"`
}

PimlicoVerifyingConfig represents the configuration for the Pimlico Verifying paymaster. See the RPC endpoint docs at https://docs.pimlico.io/paymaster/verifying-paymaster/reference/endpoints#pm_sponsoruseroperation-v2

func (*PimlicoVerifyingConfig) Init

func (config *PimlicoVerifyingConfig) Init()

type RPCBackend

type RPCBackend interface {
	CallContext(ctx context.Context, result interface{}, method string, args ...interface{}) error
}

func NewRPCBackend

func NewRPCBackend(rpcURL url.URL) (RPCBackend, error)

type Receipt

type Receipt struct {
	UserOpHash    common.Hash
	TxHash        common.Hash
	Sender        common.Address
	Nonce         decimal.Decimal
	Success       bool
	ActualGasCost decimal.Decimal
	ActualGasUsed decimal.Decimal
	RevertData    []byte // non-empty if Success is false and EntryPoint was able to catch revert reason.
}

type Signer

type Signer func(op UserOperation, entryPoint common.Address, chainID *big.Int) ([]byte, error)

Signer represents a handler that signs a user operation. The handler DOES NOT modify the operation itself, but rather builds and returns the signature.

func SignerForBiconomy

func SignerForBiconomy(ecdsaSigner signer.Signer) Signer

func SignerForKernel

func SignerForKernel(ecdsaSigner signer.Signer) Signer

type UserOperation

type UserOperation struct {
	Sender               common.Address  `json:"sender"`
	Nonce                decimal.Decimal `json:"nonce"`
	InitCode             []byte          `json:"initCode"`
	CallData             []byte          `json:"callData"`
	CallGasLimit         decimal.Decimal `json:"callGasLimit"`
	VerificationGasLimit decimal.Decimal `json:"verificationGasLimit"`
	PreVerificationGas   decimal.Decimal `json:"preVerificationGas"`
	MaxFeePerGas         decimal.Decimal `json:"maxFeePerGas"`
	MaxPriorityFeePerGas decimal.Decimal `json:"maxPriorityFeePerGas"`
	PaymasterAndData     []byte          `json:"paymasterAndData"`
	Signature            []byte          `json:"signature,omitempty"`
}

UserOperation represents an EIP-4337 style transaction for a smart contract account.

func (*UserOperation) GetFactory

func (op *UserOperation) GetFactory() common.Address

GetFactory returns the address portion of InitCode if applicable. Otherwise, it returns the zero address.

func (*UserOperation) GetFactoryData

func (op *UserOperation) GetFactoryData() []byte

GetFactoryData returns the data portion of InitCode if applicable. Otherwise, it returns an empty byte array.

func (UserOperation) MarshalJSON

func (op UserOperation) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON encoding of the UserOperation.

func (*UserOperation) UserOpHash

func (op *UserOperation) UserOpHash(entryPoint common.Address, chainID *big.Int) (common.Hash, error)

UserOpHash returns the hash of the userOp + entryPoint address + chainID.

type WalletDeploymentOpts

type WalletDeploymentOpts struct {
	Owner common.Address
	Index decimal.Decimal
}

WalletDeploymentOpts represents data required 1. to deploy a new smart wallet 2. to get the address of the already deployed wallet.

Directories

Path Synopsis
testing

Jump to

Keyboard shortcuts

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