zerodev

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2025 License: Apache-2.0 Imports: 16 Imported by: 1

README

go-zerodev

Basic Go SDK for executing transactions with zerodev paymaster and bundler

Limitations

  • Only entrypoint 0.7 is supported
  • AA wallet has to be already deployed, the SDK does not support walled deployment at this point
  • Only single call is supported

Usage

package main

import (
	"fmt"
	"math/big"

	"github.com/DIMO-Network/go-zerodev"
	"github.com/ethereum/go-ethereum"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/common/hexutil"
	"github.com/ethereum/go-ethereum/crypto"
)

func main() {
	// Create a signer for the AA wallet (only private key is supported right now)
	signer := zerodev.NewPrivateKeySigner(<YOUR_AA_WALLET_ECDSA_PK>)
	walletAddress := common.HexToAddress("YOUR_AA_WALLET_ADDRESS")

	// Create config for zerodev client
	clientConfig := zerodev.ClientConfig{
		Signer:             signer,
		EntryPointVersion:  zerodev.EntryPointVersion07,
		RpcURL:             <RPC_URL>,
		PaymasterURL:       <PAYMASTER_URL>,
		BundlerURL:         <BUNDLER_URL>,
		ChainID:            <CHAIN_ID>,
	}

	// Create a client
	client, _ := zerodev.NewClient(&clientConfig)
	defer client.Close()

	// Prepare call data
	zeroAddress := common.HexToAddress(zerodev.AddressZero)
	encodedCall, _ := zerodev.EncodeExecuteCall(&ethereum.CallMsg{
		To:    &zeroAddress,
		Value: big.NewInt(0),
		Data:  common.FromHex("0x"),
	})

	// Execute the call as user operation
	result, _ := client.SendUserOperation(walletAddress, encodedCall)
    
	// Get transaction hash
	fmt.Println(hexutil.Encode(*result.TxHash))
}

Documentation

Index

Constants

View Source
const (
	ChainPolygon     = int64(137)
	ChainPolygonAmoy = int64(80_002)
)

ChainPolygon Polygon ChainID ChainPolygonAmoy Polygon Amoy Testnet ChainID

View Source
const (
	AddressZero = "0x0000000000000000000000000000000000000000"
)

Addresses

View Source
const (
	EntryPointVersion07 = "0.7"
)
View Source
const (
	SignatureDummy = "" /* 132-byte string literal not displayed */
)

SignatureDummy Signature used in interaction with paymaster to calculate fees

Variables

This section is empty.

Functions

func EncodeExecuteCall

func EncodeExecuteCall(msg *ethereum.CallMsg) (*[]byte, error)

Types

type BundlerClient

type BundlerClient struct {
	URL        *url.URL
	Client     *rpc.Client
	EntryPoint Entrypoint
	ChainID    *big.Int
}

func NewBundlerClient

func NewBundlerClient(url *url.URL, entrypoint Entrypoint, chainID *big.Int) (*BundlerClient, error)

func (*BundlerClient) Close

func (b *BundlerClient) Close()

func (*BundlerClient) GetChainID

func (b *BundlerClient) GetChainID() *big.Int

func (*BundlerClient) GetClient

func (b *BundlerClient) GetClient() *rpc.Client

func (*BundlerClient) GetEntryPoint

func (b *BundlerClient) GetEntryPoint() Entrypoint

func (*BundlerClient) GetURL

func (b *BundlerClient) GetURL() *url.URL

func (*BundlerClient) GetUserOperationGasPrice

func (b *BundlerClient) GetUserOperationGasPrice() (*GetUserOperationGasPriceResponse, error)

func (*BundlerClient) SendUserOperation

func (b *BundlerClient) SendUserOperation(op *UserOperation) (*[]byte, error)

type Client

type Client struct {
	Signer          Signer
	EntryPoint      Entrypoint
	PaymasterClient *PaymasterClient
	BundlerClient   *BundlerClient
	ChainID         *big.Int
}

func NewClient

func NewClient(config *ClientConfig) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) SendUserOperation

func (c *Client) SendUserOperation(sender common.Address, callData *[]byte) (*UserOperationResult, error)

type ClientConfig

type ClientConfig struct {
	Signer            Signer
	EntryPointVersion string
	RpcURL            *url.URL
	PaymasterURL      *url.URL
	BundlerURL        *url.URL
	ChainID           *big.Int
}

type Entrypoint

type Entrypoint interface {
	GetAddress() *common.Address
	GetNonce(account *common.Address) (*big.Int, error)
	GetUserOperationHash(op *UserOperation) (*common.Hash, error)
	Close()
}

type EntrypointClient07

type EntrypointClient07 struct {
	Client  *rpc.Client
	Address *common.Address
	Abi     *abi.ABI
	ChainID *big.Int
}

func NewEntrypoint07

func NewEntrypoint07(rpcUrl *url.URL, chainID *big.Int) (*EntrypointClient07, error)

func (*EntrypointClient07) Close

func (e *EntrypointClient07) Close()

func (*EntrypointClient07) GetAddress

func (e *EntrypointClient07) GetAddress() *common.Address

func (*EntrypointClient07) GetNonce

func (e *EntrypointClient07) GetNonce(account *common.Address) (*big.Int, error)

func (*EntrypointClient07) GetUserOperationHash

func (e *EntrypointClient07) GetUserOperationHash(op *UserOperation) (*common.Hash, error)

func (*EntrypointClient07) PackUserOperation

func (*EntrypointClient07) PackUserOperation(op *UserOperation) ([]byte, error)

type GasPriceSpecification

type GasPriceSpecification struct {
	MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas"`
	MaxFeePerGas         *big.Int `json:"maxFeePerGas"`
}

func (*GasPriceSpecification) UnmarshalJSON

func (g *GasPriceSpecification) UnmarshalJSON(b []byte) error

type GasPriceSpecificationHex

type GasPriceSpecificationHex struct {
	MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas"`
	MaxFeePerGas         string `json:"maxFeePerGas"`
}

type GetUserOperationGasPriceResponse

type GetUserOperationGasPriceResponse struct {
	Slow     *GasPriceSpecification `json:"slow"`
	Standard *GasPriceSpecification `json:"standard"`
	Fast     *GasPriceSpecification `json:"fast"`
}

type PaymasterClient

type PaymasterClient struct {
	URL        *url.URL
	Client     *rpc.Client
	EntryPoint Entrypoint
	ChainID    *big.Int
}

func NewPaymasterClient

func NewPaymasterClient(url *url.URL, entrypoint Entrypoint, chainID *big.Int) (*PaymasterClient, error)

func (*PaymasterClient) Close

func (p *PaymasterClient) Close()

func (*PaymasterClient) GetChainID

func (p *PaymasterClient) GetChainID() *big.Int

func (*PaymasterClient) GetClient

func (p *PaymasterClient) GetClient() *rpc.Client

func (*PaymasterClient) GetEntryPoint

func (p *PaymasterClient) GetEntryPoint() Entrypoint

func (*PaymasterClient) GetURL

func (p *PaymasterClient) GetURL() *url.URL

func (*PaymasterClient) SponsorUserOperation

func (p *PaymasterClient) SponsorUserOperation(op *UserOperation) (*SponsorUserOperationResponse, error)

type PrivateKeySigner

type PrivateKeySigner struct {
	PrivateKey *ecdsa.PrivateKey
}

func (*PrivateKeySigner) SignHash

func (s *PrivateKeySigner) SignHash(hash common.Hash) ([]byte, error)

func (*PrivateKeySigner) SignMessage

func (s *PrivateKeySigner) SignMessage(message []byte) ([]byte, error)

func (*PrivateKeySigner) SignTypedData

func (s *PrivateKeySigner) SignTypedData(typedData *signer.TypedData) ([]byte, error)

type SendUserOperationRequest

type SendUserOperationRequest struct {
	ChainID           *uint64         `json:"chainId"`
	Operation         *UserOperation  `json:"userOp"`
	EntryPointAddress *common.Address `json:"entryPointAddress"`
	GasToken          *common.Address `json:"gasToken,omitempty"`
	ShouldOverrideFee bool            `json:"shouldOverrideFee"`
	ShouldConsume     bool            `json:"shouldConsume"`
}

type SendUserOperationResponse

type SendUserOperationResponse struct {
	TxHash *hexutil.Bytes `json:"txHash"`
}

type Signer

type Signer interface {
	SignMessage(message []byte) ([]byte, error)
	SignTypedData(typedData *signer.TypedData) ([]byte, error)
	SignHash(hash common.Hash) ([]byte, error)
}

func NewPrivateKeySigner

func NewPrivateKeySigner(privateKey *ecdsa.PrivateKey) Signer

type SponsorUserOperationRequest

type SponsorUserOperationRequest struct {
	ChainID           *big.Int        `json:"chainId"`
	Operation         *UserOperation  `json:"userOp"`
	EntryPointAddress *common.Address `json:"entryPointAddress"`
	GasToken          *common.Address `json:"gasToken,omitempty"`
	ShouldOverrideFee bool            `json:"shouldOverrideFee"`
	ShouldConsume     bool            `json:"shouldConsume"`
}

type SponsorUserOperationResponse

type SponsorUserOperationResponse struct {
	CallGasLimit                  *big.Int `json:"callGasLimit"`
	PaymasterVerificationGasLimit *big.Int `json:"paymasterVerificationGasLimit"`
	PaymasterPostOpGasLimit       *big.Int `json:"paymasterPostOpGasLimit"`
	VerificationGasLimit          *big.Int `json:"verificationGasLimit"`
	MaxPriorityFeePerGas          *big.Int `json:"maxPriorityFeePerGas"`
	Paymaster                     []byte   `json:"paymaster"`
	MaxFeePerGas                  *big.Int `json:"maxFeePerGas"`
	PaymasterData                 []byte   `json:"paymasterData"`
	PreVerificationGas            *big.Int `json:"preVerificationGas"`
}

func (*SponsorUserOperationResponse) MarshalJSON

func (r *SponsorUserOperationResponse) MarshalJSON() ([]byte, error)

func (*SponsorUserOperationResponse) UnmarshalJSON

func (r *SponsorUserOperationResponse) UnmarshalJSON(b []byte) error

type SponsorUserOperationResponseHex

type SponsorUserOperationResponseHex struct {
	CallGasLimit                  string `json:"callGasLimit"`
	PaymasterVerificationGasLimit string `json:"paymasterVerificationGasLimit"`
	PaymasterPostOpGasLimit       string `json:"paymasterPostOpGasLimit"`
	VerificationGasLimit          string `json:"verificationGasLimit"`
	MaxPriorityFeePerGas          string `json:"maxPriorityFeePerGas"`
	Paymaster                     string `json:"paymaster"`
	MaxFeePerGas                  string `json:"maxFeePerGas"`
	PaymasterData                 string `json:"paymasterData"`
	PreVerificationGas            string `json:"preVerificationGas"`
}

type UserOperation

type UserOperation struct {
	Sender                        *common.Address `json:"sender"`
	Nonce                         *big.Int        `json:"nonce"`
	CallData                      []byte          `json:"callData"`
	CallGasLimit                  *big.Int        `json:"callGasLimit,omitempty"`
	VerificationGasLimit          *big.Int        `json:"verificationGasLimit,omitempty"`
	PreVerificationGas            *big.Int        `json:"preVerificationGas,omitempty"`
	MaxFeePerGas                  *big.Int        `json:"maxFeePerGas"`
	MaxPriorityFeePerGas          *big.Int        `json:"maxPriorityFeePerGas"`
	Paymaster                     []byte          `json:"paymaster,omitempty"`
	PaymasterData                 []byte          `json:"paymasterData,omitempty"`
	PaymasterVerificationGasLimit *big.Int        `json:"paymasterVerificationGasLimit,omitempty"`
	PaymasterPostOpGasLimit       *big.Int        `json:"paymasterPostOpGasLimit,omitempty"`
	Signature                     []byte          `json:"signature,omitempty"`
}

func (*UserOperation) MarshalJSON

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

type UserOperationHex

type UserOperationHex struct {
	Sender                        string `json:"sender"`
	Nonce                         string `json:"nonce"`
	CallData                      string `json:"callData"`
	CallGasLimit                  string `json:"callGasLimit,omitempty"`
	VerificationGasLimit          string `json:"verificationGasLimit,omitempty"`
	PreVerificationGas            string `json:"preVerificationGas,omitempty"`
	MaxFeePerGas                  string `json:"maxFeePerGas"`
	MaxPriorityFeePerGas          string `json:"maxPriorityFeePerGas"`
	Paymaster                     string `json:"paymaster,omitempty"`
	PaymasterData                 string `json:"paymasterData,omitempty"`
	PaymasterVerificationGasLimit string `json:"paymasterVerificationGasLimit,omitempty"`
	PaymasterPostOpGasLimit       string `json:"paymasterPostOpGasLimit,omitempty"`
	Signature                     string `json:"signature,omitempty"`
}

type UserOperationResult

type UserOperationResult struct {
	TxHash *[]byte `json:"txHash"`
}

Jump to

Keyboard shortcuts

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