smart_wallet

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

README

SmartWallet GoLang library

Overview

SmartWallet is a golang library that provides helper functions to user operations.

Features

This package introduces the following types and helper functionality:

  • Config - A struct that holds the configuration for the SmartWallet.
  • Type - an enum that represents the type of the wallet. Currently only ZeroDev Kernel v2.2, Biconomy v2.0 and eth-infinitism SimpleAccount v0.6 (still in progress) are supported.
  • IsAccountDeployed(swAddress) - a function that checks if the smart wallet is deployed.
  • GetAccountAddress(owner, index) - a function that calculates the address of the smart wallet.
  • GetInitCode(smartWalletConfig) - a function that returns the init code of the smart wallet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SimpleAccountType represents a smart wallet type for a Simple Account wallet.
	SimpleAccountType = Type{"simple_account"}
	// BiconomyType represents a type for BiconomyType Smart Account wallet.
	BiconomyType = Type{"biconomy"}
	// KernelType represents a type for Zerodev KernelType wallet.
	KernelType = Type{"kernel"}
)
View Source
var (
	// ErrSmartWalletNotSupported is returned on attempt to perform some actions with an unsupported smart wallet type.
	// Make sure that the smart wallet type you are trying to use
	// has no `unsupported` or `untested` tags in the source files.
	ErrSmartWalletNotSupported = errors.New("smart wallet not supported")
)
View Source
var KernelExecuteABI = must(abi.JSON(strings.NewReader(`[
  {
    "inputs": [
      {
        "internalType": "address",
        "name": "to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "value",
        "type": "uint256"
      },
      {
        "internalType": "bytes",
        "name": "data",
        "type": "bytes"
      },
      {
        "internalType": "enum Operation",
        "name": "",
        "type": "uint8"
      }
    ],
    "name": "execute",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function"
  },
  {
    "inputs": [{
      "components": [
        {
          "internalType": "address",
          "name": "to",
          "type": "address"
        },
        {
          "internalType": "uint256",
          "name": "value",
          "type": "uint256"
        },
        {
          "internalType": "bytes",
          "name": "data",
          "type": "bytes"
        }
      ],
      "internalType": "struct Call[]",
      "name": "calls",
      "type": "tuple[]"
    }],
    "name": "executeBatch",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function"
  }
]`)))

kernelExecuteABI is used to execute a transaction on Zerodev Kernel smart account.

Functions

func BuildCallData

func BuildCallData(swt Type, calls Calls) ([]byte, error)

func GetAccountAddress

func GetAccountAddress(ctx context.Context, provider ethereum.ContractCaller, config Config, entryPointAddress, owner common.Address, index decimal.Decimal) (common.Address, error)

func GetBiconomyInitCode

func GetBiconomyInitCode(owner common.Address, index decimal.Decimal, factory, ecdsaValidator common.Address) ([]byte, error)

getBiconomyInitCode returns a middleware that sets the init code for a Biconomy smart account. The init code deploys a smart account if it is not already deployed. NOTE: this was NOT tested. Use at your own risk or wait for the package to be updated.

func GetInitCode

func GetInitCode(smartWalletConfig Config, ownerAddress common.Address, index decimal.Decimal) ([]byte, error)

func GetKernelInitCode

func GetKernelInitCode(owner common.Address, index decimal.Decimal, factory, accountLogic, ecdsaValidator common.Address) ([]byte, error)

getKernelInitCode returns a middleware that sets the init code for a Zerodev Kernel smart account. The init code deploys a smart account if it is not already deployed.

func IsAccountDeployed

func IsAccountDeployed(ctx context.Context, provider ethereum.ChainStateReader, swAddress common.Address) (bool, error)

Types

type Call

type Call struct {
	To       common.Address
	Value    *big.Int // wei
	CallData []byte
}

Call represents sufficient data to build a single transaction, which is a part of a user operation to be executed in a batch with other ones.

type Calls

type Calls []Call

func UnpackCallsForKernel

func UnpackCallsForKernel(data []byte) (Calls, error)

UnpackCallsForKernel unpacks CallData for Zerodev Kernel smart wallet.

func UnpackCallsForSimpleAccount

func UnpackCallsForSimpleAccount(data []byte) (Calls, error)

UnpackCallsForSimpleAccount unpacks CallData for SimpleAccount smart wallet.

func (Calls) PackForKernel

func (calls Calls) PackForKernel() ([]byte, error)

handleCallKernel packs calldata for Zerodev Kernel smart wallet.

func (Calls) PackForSimpleAccount

func (calls Calls) PackForSimpleAccount() ([]byte, error)

PackForSimpleAccount packs CallData for SimpleAccount smart wallet.

type Config

type Config struct {
	Type           *Type          `yaml:"type" env:"SMART_WALLET_TYPE"`
	ECDSAValidator common.Address `yaml:"ecdsa_validator" env:"SMART_WALLET_ECDSA_VALIDATOR"`
	Logic          common.Address `yaml:"logic" env:"SMART_WALLET_LOGIC"`
	Factory        common.Address `yaml:"factory" env:"SMART_WALLET_FACTORY"`
}

SmartWalletConfig represents the configuration for the smart wallet to be used with the client.

func (*Config) Init

func (sw *Config) Init()

type Type

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

Type represents an enum for supported ERC-4337 smart wallets that can be used with the client to send user operations from.

func (*Type) SetValue

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

SetValue implements the cleanenv.Setter interface.

func (Type) String

func (t Type) String() string

String returns the string representation of a SmartWalletType.

func (*Type) UnmarshalJSON

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

UnmarshalJSON unmarshals the JSON representation of a SmartWalletType.

func (*Type) UnmarshalYAML

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

UnmarshalYAML unmarshals the YAML representation of a SmartWalletType.

Jump to

Keyboard shortcuts

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