accounts

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: Apache-2.0, MIT Imports: 35 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter added in v0.3.0

type Adapter interface {
	AdapterL1
	AdapterL2
	Deployer
}

Adapter is associated with an account and provides common functionalities on both L1 and L2 network as well as deployment of smart contracts and smart accounts for the associated account.

type AdapterL1 added in v0.3.0

type AdapterL1 interface {
	// MainContract returns the ZKsync L1 smart contract.
	MainContract(ctx context.Context) (*zksync.IZkSync, error)
	// L1BridgeContracts returns L1 bridge contracts.
	L1BridgeContracts(ctx context.Context) (*zkTypes.L1BridgeContracts, error)
	// BalanceL1 returns the balance of the specified token on L1 that can be
	// either ETH or any ERC20 token.
	BalanceL1(opts *CallOpts, token common.Address) (*big.Int, error)
	// AllowanceL1 returns the amount of approved tokens for a specific L1 bridge.
	AllowanceL1(opts *CallOpts, token common.Address, bridgeAddress common.Address) (*big.Int, error)
	// L2TokenAddress returns the corresponding address on the L2 network for the token on the L1 network.
	L2TokenAddress(ctx context.Context, token common.Address) (common.Address, error)
	// ApproveERC20 approves the specified amount of tokens for the specified L1 bridge.
	ApproveERC20(auth *TransactOpts, token common.Address, amount *big.Int, bridgeAddress common.Address) (*types.Transaction, error)
	// BaseCost returns base cost for L2 transaction.
	BaseCost(opts *CallOpts, gasLimit, gasPerPubdataByte, gasPrice *big.Int) (*big.Int, error)
	// Deposit transfers the specified token from the associated account on the L1 network
	// to the target account on the L2 network. The token can be either ETH or any ERC20 token.
	// For ERC20 tokens, enough approved tokens must be associated with the specified L1 bridge
	// (default one or the one defined in DepositTransaction.BridgeAddress). In this case,
	// DepositTransaction.ApproveERC20 can be enabled to perform token approval.
	// If there are already enough approved tokens for the L1 bridge, token approval will be skipped.
	// To check the amount of approved tokens for a specific bridge, use the AdapterL1.AllowanceL1 method.
	Deposit(auth *TransactOpts, tx DepositTransaction) (*types.Transaction, error)
	// EstimateGasDeposit estimates the amount of gas required for a deposit transaction on L1 network.
	// Gas of approving ERC20 token is not included in estimation.
	EstimateGasDeposit(ctx context.Context, msg DepositCallMsg) (uint64, error)
	// FullRequiredDepositFee retrieves the full needed ETH fee for the deposit on both L1 and L2 networks.
	FullRequiredDepositFee(ctx context.Context, msg DepositCallMsg) (*FullDepositFee, error)
	// FinalizeWithdraw proves the inclusion of the L2 -> L1 withdrawal message.
	FinalizeWithdraw(auth *TransactOpts, withdrawalHash common.Hash, index int) (*types.Transaction, error)
	// IsWithdrawFinalized checks if the withdrawal finalized on L1 network.
	IsWithdrawFinalized(opts *CallOpts, withdrawalHash common.Hash, index int) (bool, error)
	// ClaimFailedDeposit withdraws funds from the initiated deposit, which failed when finalizing on L2.
	// If the deposit L2 transaction has failed, it sends an L1 transaction calling ClaimFailedDeposit method
	// of the L1 bridge, which results in returning L1 tokens back to the depositor, otherwise throws the error.
	ClaimFailedDeposit(auth *TransactOpts, depositHash common.Hash) (*types.Transaction, error)
	// RequestExecute request execution of L2 transaction from L1.
	RequestExecute(auth *TransactOpts, tx RequestExecuteTransaction) (*types.Transaction, error)
	// EstimateGasRequestExecute estimates the amount of gas required for a request execute transaction.
	EstimateGasRequestExecute(ctx context.Context, msg RequestExecuteCallMsg) (uint64, error)
}

AdapterL1 is associated with an account and provides common operations on the L1 network for the associated account.

type AdapterL2 added in v0.3.0

type AdapterL2 interface {
	// Address returns the address of the associated account.
	Address() common.Address
	// Signer returns the signer of the associated account.
	Signer() Signer
	// Balance returns the balance of the specified token that can be either ETH or any ERC20 token.
	// The block number can be nil, in which case the balance is taken from the latest known block.
	Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error)
	// AllBalances returns all balances for confirmed tokens given by an associated
	// account.
	AllBalances(ctx context.Context) (map[common.Address]*big.Int, error)
	// L2BridgeContracts returns L2 bridge contracts.
	L2BridgeContracts(ctx context.Context) (*zkTypes.L2BridgeContracts, error)
	// Withdraw initiates the withdrawal process which withdraws ETH or any ERC20
	// token from the associated account on L2 network to the target account on L1
	// network.
	Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (*types.Transaction, error)
	// EstimateGasWithdraw estimates the amount of gas required for a withdrawal
	// transaction.
	EstimateGasWithdraw(ctx context.Context, msg WithdrawalCallMsg) (uint64, error)
	// Transfer moves the ETH or any ERC20 token from the associated account to the
	// target account.
	Transfer(auth *TransactOpts, tx TransferTransaction) (*types.Transaction, error)
	// EstimateGasTransfer estimates the amount of gas required for a transfer
	// transaction.
	EstimateGasTransfer(ctx context.Context, msg TransferCallMsg) (uint64, error)
	// CallContract executes a message call for EIP-712 transaction, which is
	// directly executed in the VM of the node, but never mined into the blockchain.
	//
	// blockNumber selects the block height at which the call runs. It can be nil, in
	// which case the code is taken from the latest known block. Note that state from
	// very old blocks might not be available.
	CallContract(ctx context.Context, msg CallMsg, blockNumber *big.Int) ([]byte, error)
	// PopulateTransaction is designed for users who prefer a simplified approach by
	// providing only the necessary data to create a valid transaction. The only
	// required fields are Transaction.To and either Transaction.Data or
	// Transaction.Value (or both, if the method is payable). Any other fields that
	// are not set will be prepared by this method.
	PopulateTransaction(ctx context.Context, tx Transaction) (*zkTypes.Transaction712, error)
	// SignTransaction returns a signed transaction that is ready to be broadcast to
	// the network. The input transaction must be a valid transaction with all fields
	// having appropriate values. To obtain a valid transaction, you can use the
	// PopulateTransaction method.
	SignTransaction(tx *zkTypes.Transaction712) ([]byte, error)
	// SendTransaction injects a transaction into the pending pool for execution. Any
	// unset transaction fields are prepared using the PopulateTransaction method.
	SendTransaction(ctx context.Context, tx *Transaction) (common.Hash, error)
}

AdapterL2 is associated with an account and provides common operations on the L2 network for the associated account.

type AllowanceParams added in v0.5.0

type AllowanceParams struct {
	Token     common.Address // Token address
	Allowance *big.Int       // Allowance amount
}

AllowanceParams contains the parameters required for approval of an ERC20 token.

type BaseDeployer added in v0.3.0

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

BaseDeployer implements the Deployer interface.

func NewBaseDeployer added in v0.3.0

func NewBaseDeployer(adapter *AdapterL2) *BaseDeployer

NewBaseDeployer creates an instance of BaseDeployer.

func (*BaseDeployer) Deploy added in v0.3.0

func (a *BaseDeployer) Deploy(auth *TransactOpts, tx Create2Transaction) (common.Hash, error)

func (*BaseDeployer) DeployAccount added in v0.3.0

func (a *BaseDeployer) DeployAccount(auth *TransactOpts, tx Create2Transaction) (common.Hash, error)

func (*BaseDeployer) DeployAccountWithCreate added in v0.3.0

func (a *BaseDeployer) DeployAccountWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error)

func (*BaseDeployer) DeployWithCreate added in v0.3.0

func (a *BaseDeployer) DeployWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error)

type BaseSigner added in v0.3.0

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

BaseSigner represents basis implementation of Signer interface.

func NewBaseSignerFromMnemonic added in v0.3.0

func NewBaseSignerFromMnemonic(mnemonic string, chainId int64) (*BaseSigner, error)

NewBaseSignerFromMnemonic creates a new instance of BaseSigner based on the provided mnemonic phrase.

func NewBaseSignerFromMnemonicAndAccountId added in v0.3.0

func NewBaseSignerFromMnemonicAndAccountId(mnemonic string, accountId uint32, chainId int64) (*BaseSigner, error)

NewBaseSignerFromMnemonicAndAccountId creates a new instance of BaseSigner based on the provided mnemonic phrase and account ID.

func NewBaseSignerFromRawPrivateKey added in v0.3.0

func NewBaseSignerFromRawPrivateKey(rawPk []byte, chainId int64) (*BaseSigner, error)

NewBaseSignerFromRawPrivateKey creates a new instance of BaseSigner based on the provided raw private key.

func NewRandomBaseSigner added in v0.3.0

func NewRandomBaseSigner(chainId int64) (*BaseSigner, error)

NewRandomBaseSigner creates an instance of Signer with a randomly generated private key.

func (*BaseSigner) Address added in v0.3.0

func (s *BaseSigner) Address() common.Address

func (*BaseSigner) Domain added in v0.3.0

func (s *BaseSigner) Domain() *eip712.Domain

func (*BaseSigner) HashTypedData added in v0.3.0

func (s *BaseSigner) HashTypedData(data apitypes.TypedData) ([]byte, error)

func (*BaseSigner) PrivateKey added in v0.3.0

func (s *BaseSigner) PrivateKey() *ecdsa.PrivateKey

func (*BaseSigner) SignHash added in v0.3.0

func (s *BaseSigner) SignHash(msg []byte) ([]byte, error)

func (*BaseSigner) SignTypedData added in v0.3.0

func (s *BaseSigner) SignTypedData(domain *eip712.Domain, data eip712.TypedData) ([]byte, error)

type CallMsg added in v0.3.0

type CallMsg struct {
	To         *common.Address     // The address of the recipient.
	Gas        uint64              // If 0, the call executes with near-infinite gas.
	GasPrice   *big.Int            // Wei <-> gas exchange ratio.
	GasFeeCap  *big.Int            // EIP-1559 fee cap per gas.
	GasTipCap  *big.Int            // EIP-1559 tip per gas.
	Value      *big.Int            // Amount of wei sent along with the call.
	Data       []byte              // Input data, usually an ABI-encoded contract method invocation
	AccessList types.AccessList    // EIP-2930 access list.
	Meta       *zkTypes.Eip712Meta // EIP-712 metadata.
}

CallMsg contains parameters for contract call from a specific account associated with AdapterL1, AdapterL2 or Deployer. Its primary purpose is to be transformed into types.CallMsg, wherein the 'From' field represents the associated account.

func (*CallMsg) ToCallMsg added in v0.3.0

func (m *CallMsg) ToCallMsg(from common.Address) zkTypes.CallMsg

type CallOpts added in v0.3.0

type CallOpts struct {
	Pending     bool            // Whether to operate on the pending state or the last known one
	BlockNumber *big.Int        // Optional the block number on which the call should be performed
	Context     context.Context // Network context to support cancellation and timeouts (nil = no timeout)
}

CallOpts is the collection of options to fine tune a contract call request from a specific account associated with AdapterL1. Its primary purpose is to be transformed into bind.CallOpts, wherein the 'From' field represents the associated account.

func (*CallOpts) ToCallOpts added in v0.3.0

func (o *CallOpts) ToCallOpts(from common.Address) *bind.CallOpts

type Create2Transaction added in v0.3.0

type Create2Transaction struct {
	Bytecode     []byte   // The bytecode of smart contract or smart account.
	Calldata     []byte   // The constructor calldata.
	Salt         []byte   // The create2 salt.
	Dependencies [][]byte // The bytecode of dependent smart contracts or smart accounts.
}

Create2Transaction represents the parameters for deploying a contract or account using the CREATE2 opcode. This transaction is initiated by the account associated with Deployer.

func (*Create2Transaction) ToTransaction added in v0.3.0

func (t *Create2Transaction) ToTransaction(deploymentType DeploymentType, opts *TransactOpts) (*Transaction, error)

type CreateTransaction added in v0.3.0

type CreateTransaction struct {
	Bytecode     []byte   // The bytecode of smart contract or smart account.
	Calldata     []byte   // The constructor calldata.
	Dependencies [][]byte // The bytecode of dependent smart contracts or smart accounts.
}

CreateTransaction represents the parameters for deploying a contract or account using the CREATE opcode. This transaction is initiated by the account associated with Deployer.

func (*CreateTransaction) ToTransaction added in v0.3.0

func (t *CreateTransaction) ToTransaction(deploymentType DeploymentType, opts *TransactOpts) (*Transaction, error)

type DefaultEthSigner deprecated

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

Deprecated: Deprecated in favor of BaseSigner

func NewEthSignerFromMnemonic deprecated

func NewEthSignerFromMnemonic(mnemonic string, chainId int64) (*DefaultEthSigner, error)

Deprecated: Deprecated in favor of NewBaseSignerFromMnemonic

func NewEthSignerFromMnemonicAndAccountId deprecated

func NewEthSignerFromMnemonicAndAccountId(mnemonic string, accountId uint32, chainId int64) (*DefaultEthSigner, error)

Deprecated: Deprecated in favor of NewBaseSignerFromMnemonicAndAccountId

func NewEthSignerFromRawPrivateKey deprecated

func NewEthSignerFromRawPrivateKey(rawPk []byte, chainId int64) (*DefaultEthSigner, error)

Deprecated: Deprecated in favor of NewBaseSignerFromRawPrivateKey

func (*DefaultEthSigner) Address deprecated added in v0.3.0

func (s *DefaultEthSigner) Address() common.Address

Deprecated: Deprecated in favor of BaseSigner.Address

func (*DefaultEthSigner) Domain deprecated added in v0.3.0

func (s *DefaultEthSigner) Domain() *eip712.Domain

Deprecated: Deprecated in favor of BaseSigner.Domain

func (*DefaultEthSigner) HashTypedData deprecated

func (s *DefaultEthSigner) HashTypedData(data apitypes.TypedData) ([]byte, error)

Deprecated: Deprecated in favor of BaseSigner.HashTypedData

func (*DefaultEthSigner) SignHash deprecated

func (s *DefaultEthSigner) SignHash(msg []byte) ([]byte, error)

Deprecated: Deprecated in favor of BaseSigner.SignHash

func (*DefaultEthSigner) SignTypedData deprecated

func (s *DefaultEthSigner) SignTypedData(domain *eip712.Domain, data eip712.TypedData) ([]byte, error)

Deprecated: Deprecated in favor of BaseSigner.SignTypedData

type Deployer added in v0.3.0

type Deployer interface {
	// Deploy deploys smart contract using CREATE2 opcode.
	Deploy(auth *TransactOpts, tx Create2Transaction) (common.Hash, error)
	// DeployWithCreate deploys smart contract using CREATE opcode.
	DeployWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error)
	// DeployAccount deploys smart account using CREATE2 opcode.
	DeployAccount(auth *TransactOpts, tx Create2Transaction) (common.Hash, error)
	// DeployAccountWithCreate deploys smart account using CREATE opcode.
	DeployAccountWithCreate(auth *TransactOpts, tx CreateTransaction) (common.Hash, error)
}

Deployer is associated with an account and provides deployment of smart contracts and smart accounts on L2 network for the associated account.

type DeploymentType added in v0.3.0

type DeploymentType string

DeploymentType represents an enumeration of deployment types.

const (
	DeployContract DeploymentType = "CONTRACT"
	DeployAccount  DeploymentType = "ACCOUNT"
)

type DepositCallMsg added in v0.3.0

type DepositCallMsg struct {
	To     common.Address // The address that will receive the deposited tokens on L2.
	Token  common.Address // The address of the token to deposit.
	Amount *big.Int       // The amount of the token to be deposited.

	// If the ETH value passed with the transaction is not explicitly stated Value,
	// this field will be equal to the tip the operator will receive on top of the base cost
	// of the transaction.
	OperatorTip *big.Int

	// The address of the bridge contract to be used. Defaults to the default ZKsync bridge
	// (either L1EthBridge or L1Erc20Bridge).
	BridgeAddress *common.Address

	L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2.

	// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
	GasPerPubdataByte *big.Int

	// The address on L2 that will receive the refund for the transaction.
	// If the transaction fails, it will also be the address to receive L2Value.
	RefundRecipient common.Address

	CustomBridgeData []byte // Additional data that can be sent to a bridge.

	Value     *big.Int // The amount of wei sent along with the call.
	Gas       uint64   // If 0, the call executes with near-infinite gas.
	GasPrice  *big.Int // Wei <-> gas exchange ratio.
	GasFeeCap *big.Int // EIP-1559 fee cap per gas.
	GasTipCap *big.Int // EIP-1559 tip per gas.

	AccessList types.AccessList // EIP-2930 access list.
}

DepositCallMsg contains the common data required to execute a deposit call on L2 from L1. This execution is initiated by the account associated with AdapterL1.

func (*DepositCallMsg) PopulateEmptyFields added in v0.3.0

func (m *DepositCallMsg) PopulateEmptyFields(from common.Address)

func (*DepositCallMsg) ToCallMsg added in v0.3.0

func (m *DepositCallMsg) ToCallMsg(from, l1Bridge common.Address) (ethereum.CallMsg, error)

func (*DepositCallMsg) ToDepositTransaction added in v0.3.0

func (m *DepositCallMsg) ToDepositTransaction() DepositTransaction

func (*DepositCallMsg) ToRequestExecuteCallMsg added in v0.3.0

func (m *DepositCallMsg) ToRequestExecuteCallMsg() RequestExecuteCallMsg

func (*DepositCallMsg) ToTransactOpts added in v0.3.0

func (m *DepositCallMsg) ToTransactOpts() TransactOpts

type DepositTransaction added in v0.3.0

type DepositTransaction struct {
	To     common.Address // The address of the token to deposit.
	Token  common.Address // The address of the token to deposit.
	Amount *big.Int       // The amount of the token to be deposited.

	// If the ETH value passed with the transaction is not explicitly stated Auth.Value,
	// this field will be equal to the tip the operator will receive on top of the base cost
	// of the transaction.
	OperatorTip *big.Int

	// The address of the bridge contract to be used. Defaults to the default zkSync bridge
	// (either L1EthBridge or L1Erc20Bridge).
	BridgeAddress *common.Address

	// Whether should the token approval be performed under the hood. Set this flag to true if you
	// bridge an ERC20 token and didn't call the approveERC20 function beforehand.
	ApproveERC20 bool

	// Whether should the base token approval be performed under the hood. Set this flag to true if you
	// bridge an ERC20 token and didn't call the approveERC20 function beforehand.
	ApproveBaseERC20 bool

	L2GasLimit *big.Int // Maximum amount of L2 gas that transaction can consume during execution on L2.

	// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
	GasPerPubdataByte *big.Int

	// The address on L2 that will receive the refund for the transaction.
	// If the transaction fails, it will also be the address to receive L2Value.
	RefundRecipient common.Address

	CustomBridgeData []byte // Additional data that can be sent to the bridge.

	ApproveAuth     *TransactOpts // Authorization data for the token approval transaction.
	ApproveBaseAuth *TransactOpts // Authorization data for the base token approval transaction.

}

DepositTransaction represents a deposit transaction on L2 from L1 initiated by the account associated with AdapterL1.

func (*DepositTransaction) PopulateEmptyFields added in v0.3.0

func (t *DepositTransaction) PopulateEmptyFields(from common.Address)

func (*DepositTransaction) ToDepositCallMsg added in v0.3.0

func (t *DepositTransaction) ToDepositCallMsg(opts *TransactOpts) DepositCallMsg

func (*DepositTransaction) ToRequestExecuteTransaction added in v0.3.0

func (t *DepositTransaction) ToRequestExecuteTransaction() *RequestExecuteTransaction

type EthSigner deprecated

type EthSigner interface {
	Address() common.Address
	Domain() *eip712.Domain
	SignHash(msg []byte) ([]byte, error)
	SignTypedData(d *eip712.Domain, data eip712.TypedData) ([]byte, error)
}

Deprecated: Deprecated in favor of Signer

type FullDepositFee added in v0.3.0

type FullDepositFee struct {
	MaxFeePerGas,
	MaxPriorityFeePerGas,
	GasPrice,
	BaseCost,
	L1GasLimit,
	L2GasLimit *big.Int // Gas limit of the L2 transaction.
}

FullDepositFee represents the total ETH fee required for performing the deposit on both L1 and L2 networks.

type PayloadSigner added in v0.5.0

type PayloadSigner func(ctx context.Context, payload []byte, secret interface{}, client *clients.BaseClient) ([]byte, error)

PayloadSigner signs various types of payloads, optionally using a some kind of secret. Returns the serialized signature. The client is used to fetch data from the network if it is required for signing.

var SignPayloadWithECDSA PayloadSigner = func(ctx context.Context, payload []byte, secret interface{}, client *clients.BaseClient) ([]byte, error) {
	privateKeyHex, ok := (secret).(string)
	if !ok {
		return nil, errors.New("secret should be hex of ECDSA private key")
	}
	privateKey, err := crypto.HexToECDSA(privateKeyHex)
	if err != nil {
		return nil, err
	}
	signature, err := crypto.Sign(payload, privateKey)
	if err != nil {
		return nil, err
	}

	if signature[64] < 27 {
		signature[64] += 27
	}
	return signature, nil
}

SignPayloadWithECDSA signs the payload using an ECDSA private key.

var SignPayloadWithMultipleECDSA PayloadSigner = func(ctx context.Context, payload []byte, secret interface{}, client *clients.BaseClient) ([]byte, error) {
	privateKeys, ok := (secret).([]string)
	if !ok {
		return nil, errors.New("secret should be a slice of ECDSA private keys")
	}
	if len(privateKeys) < 2 {
		return nil, errors.New("secret should be a slice of ECDSA private keys")
	}
	multiSig := make([]byte, len(privateKeys)*65)
	for i, privateKeyHex := range privateKeys {
		privateKey, err := crypto.HexToECDSA(privateKeyHex)
		if err != nil {
			return nil, err
		}
		signature, err := crypto.Sign(payload, privateKey)
		if err != nil {
			return nil, err
		}

		if signature[64] < 27 {
			signature[64] += 27
		}
		copy(multiSig[i*65:(i+1)*65], signature)
	}
	return multiSig, nil
}

SignPayloadWithMultipleECDSA signs the payload using multiple ECDSA private keys. The signature is generated by concatenating signatures created by signing with each key individually. The length of the resulting signature is len(secret) * 65.

type RequestExecuteCallMsg added in v0.3.0

type RequestExecuteCallMsg struct {
	ContractAddress common.Address // The L2 receiver address.
	Calldata        []byte         // The input of the L2 transaction.
	L2GasLimit      *big.Int       // Maximum amount of L2 gas that transaction can consume during execution on L2.
	MintValue       *big.Int       // The amount of base token that needs to be minted on non-ETH-based L2.
	L2Value         *big.Int       // `msg.value` of L2 transaction.
	FactoryDeps     [][]byte       // An array of L2 bytecodes that will be marked as known on L2.

	// If the ETH value passed with the transaction is not explicitly stated Value,
	// this field will be equal to the tip the operator will receive on top of the base cost
	// of the transaction.
	OperatorTip *big.Int

	// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
	GasPerPubdataByte *big.Int

	// The address on L2 that will receive the refund for the transaction.
	// If the transaction fails, it will also be the address to receive L2Value.
	RefundRecipient common.Address

	Value     *big.Int // The amount of wei sent along with the call.
	Gas       uint64   // If 0, the call executes with near-infinite gas.
	GasPrice  *big.Int // Wei <-> gas exchange ratio.
	GasFeeCap *big.Int // EIP-1559 fee cap per gas.
	GasTipCap *big.Int // EIP-1559 tip per gas.

	AccessList types.AccessList // EIP-2930 access list.
}

RequestExecuteCallMsg contains the common data required to execute a call for a request execution of an L2 transaction from L1. This execution is initiated by the account associated with AdapterL1.

func (*RequestExecuteCallMsg) ToCallMsg added in v0.3.0

func (m *RequestExecuteCallMsg) ToCallMsg(from common.Address) (ethereum.CallMsg, error)

Deprecated in favor of ToCallMsgWithChainID

func (*RequestExecuteCallMsg) ToCallMsgWithChainID added in v0.5.0

func (m *RequestExecuteCallMsg) ToCallMsgWithChainID(from common.Address, chainID *big.Int) (ethereum.CallMsg, error)

func (*RequestExecuteCallMsg) ToRequestExecuteTransaction added in v0.3.0

func (m *RequestExecuteCallMsg) ToRequestExecuteTransaction() RequestExecuteTransaction

func (*RequestExecuteCallMsg) ToTransactOpts added in v0.3.0

func (m *RequestExecuteCallMsg) ToTransactOpts() TransactOpts

type RequestExecuteTransaction added in v0.3.0

type RequestExecuteTransaction struct {
	ContractAddress common.Address // The L2 receiver address.
	Calldata        []byte         // The input of the L2 transaction.
	L2GasLimit      *big.Int       // Maximum amount of L2 gas that transaction can consume during execution on L2.
	MintValue       *big.Int       // The amount of base token that needs to be minted on non-ETH-based L2.
	L2Value         *big.Int       // `msg.value` of L2 transaction.
	FactoryDeps     [][]byte       // An array of L2 bytecodes that will be marked as known on L2.

	// If the ETH value passed with the transaction is not explicitly stated Auth.Value,
	// this field will be equal to the tip the operator will receive on top of the base cost
	// of the transaction.
	OperatorTip *big.Int

	// The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
	GasPerPubdataByte *big.Int

	// The address on L2 that will receive the refund for the transaction.
	// If the transaction fails, it will also be the address to receive L2Value.
	RefundRecipient common.Address
}

RequestExecuteTransaction represents a request execution of L2 transaction from L1 initiated by the account associated with AdapterL1.

func (*RequestExecuteTransaction) ToCallMsg added in v0.3.0

func (*RequestExecuteTransaction) ToRequestExecuteCallMsg added in v0.3.0

func (t *RequestExecuteTransaction) ToRequestExecuteCallMsg(opts *TransactOpts) RequestExecuteCallMsg

type Signer added in v0.3.0

type Signer interface {
	// Address returns the  address associated with the signer.
	Address() common.Address
	// Domain returns the EIP-712 domain used for signing.
	Domain() *eip712.Domain
	// PrivateKey returns the private key associated with the signer.
	PrivateKey() *ecdsa.PrivateKey
	// SignHash signs the given hash using the signer's private key and returns the signature.
	// The hash should be the 32-byte hash of the data to be signed.
	SignHash(msg []byte) ([]byte, error)
	// SignTypedData signs the given EIP-712 typed data using the signer's private key and returns the signature.
	// The domain parameter is the EIP-712 domain separator, and the data parameter is the EIP-712 typed data.
	SignTypedData(d *eip712.Domain, data eip712.TypedData) ([]byte, error)
}

Signer provides support for signing EIP-712 transactions as well as other types of transactions supported by types.Signer.

type SmartAccount added in v0.5.0

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

SmartAccount is a signer which can be configured to sign various payloads using a provided secret. The secret can be in any form, allowing for flexibility when working with different account implementations. The SmartAccount is bound to a specific address and provides the ability to define custom method for populating transactions and custom signing method used for signing messages, typed data, and transactions.

func NewECDSASmartAccount added in v0.5.0

func NewECDSASmartAccount(address common.Address, privateKey string, client *clients.BaseClient) *SmartAccount

NewECDSASmartAccount creates a SmartAccount instance that uses single ECDSA key for signing payload.

func NewMultisigECDSASmartAccount added in v0.5.0

func NewMultisigECDSASmartAccount(address common.Address, privateKeys []string, client *clients.BaseClient) *SmartAccount

NewMultisigECDSASmartAccount creates a SmartAccount instance that uses multiple ECDSA keys for signing payloads. The signature is generated by concatenating signatures created by signing with each key individually.

func NewSmartAccount added in v0.5.0

func NewSmartAccount(
	address common.Address,
	secret interface{},
	signer *PayloadSigner,
	builder *TransactionBuilder,
	client *clients.BaseClient) *SmartAccount

NewSmartAccount creates a new SmartAccount instance. By default, it uses SignPayloadWithECDSA as a signer and PopulateTransactionECDSA as a builder and requires private key in hex format to be provided.

func (*SmartAccount) Address added in v0.5.0

func (a *SmartAccount) Address() common.Address

Address returns the address of the associated account.

func (*SmartAccount) AllBalances added in v0.5.0

func (a *SmartAccount) AllBalances(ctx context.Context) (map[common.Address]*big.Int, error)

AllBalances returns all balances for confirmed tokens given by an associated account.

func (*SmartAccount) Balance added in v0.5.0

func (a *SmartAccount) Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error)

Balance returns the balance of the specified token that can be either base token or any ERC20 token. The block number can be nil, in which case the balance is taken from the latest known block.

func (*SmartAccount) Connect added in v0.5.0

func (a *SmartAccount) Connect(client *clients.BaseClient) *SmartAccount

Connect creates a new instance of SmartAccount connected to a client or detached from any provider if nil is provided.

func (*SmartAccount) DeploymentNonce added in v0.5.0

func (a *SmartAccount) DeploymentNonce(opts *CallOpts) (*big.Int, error)

DeploymentNonce returns the deployment nonce of the account.

func (*SmartAccount) Nonce added in v0.5.0

func (a *SmartAccount) Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error)

Nonce returns the account nonce of the associated account. The block number can be nil, in which case the nonce is taken from the latest known block.

func (*SmartAccount) PopulateTransaction added in v0.5.0

func (a *SmartAccount) PopulateTransaction(ctx context.Context, tx *zkTypes.Transaction712) error

PopulateTransaction populates the transaction tx using the provided TransactionBuilder function. If tx.From is not set, it sets the value from the Address method which can be utilized in the TransactionBuilder function.

func (*SmartAccount) SendTransaction added in v0.5.0

func (a *SmartAccount) SendTransaction(ctx context.Context, tx *zkTypes.Transaction712) (common.Hash, error)

SendTransaction injects a transaction into the pending pool for execution. The SignTransaction is called first to ensure transaction is properly signed.

func (*SmartAccount) SignMessage added in v0.5.0

func (a *SmartAccount) SignMessage(ctx context.Context, message []byte) ([]byte, error)

SignMessage signs a message using the provided PayloadSigner function.

func (*SmartAccount) SignTransaction added in v0.5.0

func (a *SmartAccount) SignTransaction(ctx context.Context, tx *zkTypes.Transaction712) ([]byte, error)

SignTransaction returns a signed transaction that is ready to be broadcast to the network. The PopulateTransaction method is called first to ensure that all necessary properties for the transaction to be valid have been populated.

func (*SmartAccount) SignTypedData added in v0.5.0

func (a *SmartAccount) SignTypedData(ctx context.Context, typedData apitypes.TypedData) ([]byte, error)

SignTypedData signs a typed data using the provided PayloadSigner function.

func (*SmartAccount) Transfer added in v0.5.0

func (a *SmartAccount) Transfer(auth *TransactOpts, tx TransferTransaction) (common.Hash, error)

Transfer moves the ETH or any ERC20 token from the associated account to the target account.

func (*SmartAccount) Withdraw added in v0.5.0

func (a *SmartAccount) Withdraw(auth *TransactOpts, tx WithdrawalTransaction) (common.Hash, error)

Withdraw initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network to the target account on L1 network.

type TransactOpts added in v0.3.0

type TransactOpts struct {
	Nonce     *big.Int        // Nonce to use for the transaction execution (nil = use pending state).
	Value     *big.Int        // Funds to transfer along the transaction (nil = 0 = no funds).
	GasPrice  *big.Int        // Gas price to use for the transaction execution (nil = gas price oracle).
	GasFeeCap *big.Int        // Gas fee cap to use for the 1559 transaction execution (nil = gas price oracle).
	GasTipCap *big.Int        // Gas priority fee cap to use for the 1559 transaction execution (nil = gas price oracle).
	GasLimit  uint64          // Gas limit to set for the transaction execution (0 = estimate).
	Context   context.Context // Network context to support cancellation and timeouts (nil = no timeout).
}

TransactOpts contains common data required to create a valid transaction on both L1 and L2 using the account associated with AdapterL1, AdapterL2 or Deployer. Its primary purpose is to be transformed into bind.TransactOpts, wherein the 'From' and 'Signer' fields are linked to the associated account.

func (*TransactOpts) ToTransactOpts added in v0.3.0

func (t *TransactOpts) ToTransactOpts(from common.Address, signer bind.SignerFn) *bind.TransactOpts

type Transaction added in v0.3.0

type Transaction struct {
	To        *common.Address // The address of the recipient.
	Data      hexutil.Bytes   // Input data, usually an ABI-encoded contract method invocation.
	Value     *big.Int        // Funds to transfer along the transaction (nil = 0 = no funds).
	Nonce     *big.Int        // Nonce to use for the transaction execution.
	GasTipCap *big.Int        // EIP-1559 tip per gas.
	GasFeeCap *big.Int        // EIP-1559 fee cap per gas.
	Gas       uint64          // Gas limit to set for the transaction execution.

	AccessList types.AccessList // EIP-2930 access list.

	ChainID *big.Int            // Chain ID of the network.
	Meta    *zkTypes.Eip712Meta // EIP-712 metadata.
}

Transaction is similar to types.Transaction712 but does not include the From field. This design is intended for use with AdapterL1, AdapterL2, or Deployer, which already have an associated account. The From field is bound to their associated account, and thus, it is not included in this type.

func (*Transaction) ToCallMsg added in v0.3.0

func (t *Transaction) ToCallMsg(from common.Address) zkTypes.CallMsg

func (*Transaction) ToTransaction712 added in v0.3.0

func (t *Transaction) ToTransaction712(from common.Address) *zkTypes.Transaction712

type TransactionBuilder added in v0.5.0

type TransactionBuilder func(ctx context.Context, tx *zkTypes.Transaction712, secret interface{}, client *clients.BaseClient) error

TransactionBuilder populates missing fields in a tx with default values. The client is used to fetch data from the network if it is required.

var PopulateTransactionECDSA TransactionBuilder = func(ctx context.Context, tx *zkTypes.Transaction712, secret interface{}, client *clients.BaseClient) error {
	var err error
	if client == nil {
		return errors.New("client is required but is not provided")
	}

	if tx.ChainID == nil {
		if tx.ChainID, err = client.ChainID(ensureContext(ctx)); err != nil {
			return err
		}
	}
	if tx.Nonce == nil {
		nonce, err := client.NonceAt(ensureContext(ctx), *tx.From, nil)
		if err != nil {
			return fmt.Errorf("failed to get nonce: %w", err)
		}
		tx.Nonce = new(big.Int).SetUint64(nonce)
	}
	if tx.GasTipCap == nil {
		tx.GasTipCap = common.Big0
	}
	if tx.Meta == nil {
		tx.Meta = &zkTypes.Eip712Meta{GasPerPubdata: utils.NewBig(utils.DefaultGasPerPubdataLimit.Int64())}
	} else if tx.Meta.GasPerPubdata == nil {
		tx.Meta.GasPerPubdata = utils.NewBig(utils.DefaultGasPerPubdataLimit.Int64())
	}
	if (tx.Gas == nil || tx.Gas.Uint64() == 0) || (tx.GasFeeCap == nil) {
		from := *tx.From

		if bytecode, err := client.CodeAt(ensureContext(ctx), *tx.From, nil); len(bytecode) > 0 {
			privateKeyHex, ok := (secret).(string)
			if !ok {
				return errors.New("secret should be hex of ECDSA private key")
			}
			privateKey, err := crypto.HexToECDSA(privateKeyHex)
			if err != nil {
				return err
			}
			publicKey := privateKey.Public().(*ecdsa.PublicKey)
			from = crypto.PubkeyToAddress(*publicKey)
		} else if err != nil {
			return err
		}

		fee, err := client.EstimateFee(ensureContext(ctx), zkTypes.CallMsg{
			CallMsg: ethereum.CallMsg{
				From:      from,
				To:        tx.To,
				GasFeeCap: tx.GasFeeCap,
				GasTipCap: tx.GasTipCap,
				Value:     tx.Value,
				Data:      tx.Data,
			},
			Meta: tx.Meta,
		})
		if err != nil {
			return fmt.Errorf("failed to EstimateFee: %w", err)
		}

		if tx.Gas == nil || tx.Gas.Uint64() == 0 {
			tx.Gas = fee.GasLimit.ToInt()
		}
		if tx.GasFeeCap == nil || tx.GasFeeCap.Uint64() == 0 {
			tx.GasFeeCap = fee.MaxFeePerGas.ToInt()
		}
	}
	if tx.Data == nil {
		tx.Data = hexutil.Bytes{}
	}
	return nil
}

PopulateTransactionECDSA Populates missing properties meant for signing using an ECDSA private key:

  • Populates tx.From using the address derived from the ECDSA private key.
  • Populates tx.Nonce via client.NonceAt().
  • Populates tx.Gas via client.EstimateFee().GasLimit. If tx.From is not EOA, the estimation is done with address derived from the ECDSA private key.
  • Populates tx.GasFeeCap via client.EstimateFee().MaxFeePerGas.
  • Populates tx.GasTipCap with 0 if is not set.
  • Populates tx.ChainID via client.ChainID().
  • Populates tx.Data with "0x".
  • Populates tx.Meta.GasPerPubdata with utils.DefaultGasPerPubdataLimit.

Expects the secret to be ECDSA private in hex format.

var PopulateTransactionMultipleECDSA TransactionBuilder = func(ctx context.Context, tx *zkTypes.Transaction712, secret interface{}, client *clients.BaseClient) error {
	privateKeys, ok := (secret).([]string)
	if !ok {
		return errors.New("secret should be a slice of ECDSA private keys")
	}
	if len(privateKeys) < 2 {
		return errors.New("secret should be a slice of ECDSA private keys")
	}

	return PopulateTransactionECDSA(ctx, tx, privateKeys[0], client)
}

PopulateTransactionMultipleECDSA populates missing properties meant for signing using multiple ECDSA private keys. It uses PopulateTransactionECDSA, where the address of the first ECDSA key is set as the secret argument. Expects the secret to be a slice of ECDSA private in hex format.

type TransferCallMsg added in v0.3.0

type TransferCallMsg struct {
	To     common.Address // The address of the recipient.
	Amount *big.Int       // The amount of the token to transfer.
	Token  common.Address // The address of the token. ETH by default.

	Gas       uint64   // If 0, the call executes with near-infinite gas.
	GasPrice  *big.Int // Wei <-> gas exchange ratio.
	GasFeeCap *big.Int // EIP-1559 fee cap per gas.
	GasTipCap *big.Int // EIP-1559 tip per gas.

	AccessList types.AccessList // EIP-2930 access list.
}

TransferCallMsg contains the common data required to execute a transfer call on L2. This execution is initiated by the account associated with AdapterL2.

func (*TransferCallMsg) ToTransferCallMsg added in v0.3.0

func (m *TransferCallMsg) ToTransferCallMsg(from common.Address) clients.TransferCallMsg

type TransferTransaction added in v0.3.0

type TransferTransaction struct {
	To              common.Address           // The address of the recipient.
	Amount          *big.Int                 // The amount of the token to transfer.
	Token           common.Address           // The address of the token. ETH by default.
	PaymasterParams *zkTypes.PaymasterParams // The paymaster parameters.
}

TransferTransaction represents a transfer transaction on L2 initiated by the account associated with AdapterL2.

func (*TransferTransaction) ToTransaction added in v0.3.0

func (t *TransferTransaction) ToTransaction(opts *TransactOpts) *Transaction

func (*TransferTransaction) ToTransferCallMsg added in v0.3.0

func (t *TransferTransaction) ToTransferCallMsg(from common.Address, opts *TransactOpts) clients.TransferCallMsg

type Wallet

type Wallet struct {
	WalletL1
	WalletL2
	Deployer
	// contains filtered or unexported fields
}

Wallet wraps all operations that interact with an associated account. An account typically contains a private key, allowing it to sign various types of payloads. Wallet implements the Adapter interface.

func NewRandomWallet added in v0.3.0

func NewRandomWallet(chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error)

NewRandomWallet creates an instance of Wallet with a randomly generated account. The clientL2 and clientL1 parameters are optional, and can be configured with Wallet.Connect and Wallet.ConnectL1, respectively.

func NewWallet

func NewWallet(rawPrivateKey []byte, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error)

NewWallet creates an instance of Wallet associated with the account provided by the rawPrivateKey. The clientL1 parameters is optional; if not provided, only method form AdapterL2 and Deployer can be used, as the rest of the functionalities require communication with the L1 network. A Wallet can be configured to communicate with L1 networks by using and Wallet.ConnectL1 method.

func NewWalletFromMnemonic added in v0.3.0

func NewWalletFromMnemonic(mnemonic string, chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error)

NewWalletFromMnemonic creates a new instance of Wallet based on the provided mnemonic phrase. The clientL2 and clientL1 parameters are optional, and can be configured with Wallet.Connect and Wallet.ConnectL1, respectively.

func NewWalletFromRawPrivateKey added in v0.3.0

func NewWalletFromRawPrivateKey(rawPk []byte, chainId int64, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error)

NewWalletFromRawPrivateKey creates a new instance of Wallet based on the provided private key of the account and chain ID. The clientL2 and clientL1 parameters are optional, and can be configured with Wallet.Connect and Wallet.ConnectL1, respectively.

func NewWalletFromSigner added in v0.3.0

func NewWalletFromSigner(signer *Signer, clientL2 *clients.Client, clientL1 *ethclient.Client) (*Wallet, error)

NewWalletFromSigner creates an instance of Wallet associated with the account provided by the signer. The clientL2 and clientL1 parameters are optional; if not provided, only AdapterL2.SignTransaction, AdapterL2.Address, AdapterL2.Signer methods can be used, as the rest of the functionalities require communication with the network. A wallet that contains only a signer can be configured to communicate with L2 and L1 networks by using Wallet.Connect and Wallet.ConnectL1, respectively.

func (*Wallet) Connect added in v0.3.0

func (w *Wallet) Connect(client *clients.Client) (*Wallet, error)

Connect returns a new instance of Wallet with the provided client for the L2 network.

func (*Wallet) ConnectL1 added in v0.3.0

func (w *Wallet) ConnectL1(client *ethclient.Client) (*Wallet, error)

ConnectL1 returns a new instance of Wallet with the provided client for the L1 network.

func (*Wallet) CreateEthereumProvider deprecated

func (w *Wallet) CreateEthereumProvider(rpcClient *rpc.Client) (clients.EthProvider, error)

Deprecated: Will be removed in future releases.

func (*Wallet) GetAddress deprecated

func (w *Wallet) GetAddress() common.Address

Deprecated: Deprecated in favor of Wallet.Address.

func (*Wallet) GetBalance deprecated

func (w *Wallet) GetBalance() (*big.Int, error)

Deprecated: Deprecated in favor of Wallet.Balance.

func (*Wallet) GetBalanceOf deprecated

func (w *Wallet) GetBalanceOf(token *zkTypes.Token, blockNumber *big.Int) (*big.Int, error)

Deprecated: Deprecated in favor of Wallet.Balance.

func (*Wallet) GetEthSigner deprecated

func (w *Wallet) GetEthSigner() Signer

Deprecated: Deprecated in favor of Wallet.Signer.

func (*Wallet) GetNonce deprecated

func (w *Wallet) GetNonce() (*big.Int, error)

Deprecated: Deprecated in favor of Wallet.Nonce.

func (*Wallet) GetNonceAt deprecated

func (w *Wallet) GetNonceAt(blockNumber *big.Int) (*big.Int, error)

Deprecated: Deprecated in favor of Wallet.Nonce.

func (*Wallet) GetProvider deprecated

func (w *Wallet) GetProvider() clients.Client

Deprecated: Will be removed in the future releases.

func (*Wallet) GetTokenBalance deprecated

func (w *Wallet) GetTokenBalance(token *zkTypes.Token) (*big.Int, error)

Deprecated: Deprecated in favor of Wallet.Balance.

func (*Wallet) Nonce added in v0.3.0

func (w *Wallet) Nonce(ctx context.Context, blockNumber *big.Int) (uint64, error)

Nonce returns the account nonce of the associated account. The block number can be nil, in which case the nonce is taken from the latest known block.

func (*Wallet) PendingNonce added in v0.3.0

func (w *Wallet) PendingNonce(ctx context.Context) (uint64, error)

PendingNonce returns the account nonce of the associated account in the pending state. This is the nonce that should be used for the next transaction.

type WalletL1 added in v0.3.0

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

WalletL1 implements the AdapterL1 interface.

func NewWalletL1 added in v0.3.0

func NewWalletL1(rawPrivateKey []byte, clientL1 *ethclient.Client, clientL2 *clients.Client) (*WalletL1, error)

NewWalletL1 creates an instance of WalletL1 associated with the account provided by the raw private key.

func NewWalletL1FromSigner added in v0.3.0

func NewWalletL1FromSigner(signer *Signer, clientL1 *ethclient.Client, clientL2 *clients.Client) (*WalletL1, error)

NewWalletL1FromSigner creates an instance of WalletL1 associated with the account provided by the signer.

func (*WalletL1) AllowanceL1 added in v0.3.0

func (a *WalletL1) AllowanceL1(opts *CallOpts, token common.Address, bridgeAddress common.Address) (*big.Int, error)

AllowanceL1 returns the amount of approved tokens for a specific L1 bridge.

func (*WalletL1) ApproveERC20 added in v0.3.0

func (a *WalletL1) ApproveERC20(auth *TransactOpts, token common.Address, amount *big.Int,
	bridgeAddress common.Address) (*types.Transaction, error)

ApproveERC20 approves the specified amount of tokens for the specified L1 bridge.

func (*WalletL1) BalanceL1 added in v0.3.0

func (a *WalletL1) BalanceL1(opts *CallOpts, token common.Address) (*big.Int, error)

BalanceL1 returns the balance of the specified token on L1 that can be either base token or any ERC20 token.

func (*WalletL1) BaseCost added in v0.3.0

func (a *WalletL1) BaseCost(opts *CallOpts, gasLimit, gasPerPubdataByte, gasPrice *big.Int) (*big.Int, error)

BaseCost returns base cost for L2 transaction.

func (*WalletL1) BaseToken added in v0.5.0

func (a *WalletL1) BaseToken(opts *CallOpts) (common.Address, error)

BaseToken returns the address of the base token on L1.

func (*WalletL1) BridgehubContract added in v0.5.0

func (a *WalletL1) BridgehubContract(_ context.Context) (*bridgehub.IBridgehub, error)

BridgehubContract returns the Bridgehub L1 smart contract.

func (*WalletL1) ClaimFailedDeposit added in v0.3.0

func (a *WalletL1) ClaimFailedDeposit(auth *TransactOpts, depositHash common.Hash) (*types.Transaction, error)

ClaimFailedDeposit withdraws funds from the initiated deposit, which failed when finalizing on L2. If the deposit L2 transaction has failed, it sends an L1 transaction calling ClaimFailedDeposit method of the L1 bridge, which results in returning L1 tokens back to the depositor, otherwise throws the error.

func (*WalletL1) Deposit added in v0.3.0

func (a *WalletL1) Deposit(auth *TransactOpts, tx DepositTransaction) (*types.Transaction, error)

Deposit transfers the specified token from the associated account on the L1 network to the target account on the L2 network. The token can be either ETH or any ERC20 token. For ERC20 tokens, enough approved tokens must be associated with the specified L1 bridge (default one or the one defined in DepositTransaction.BridgeAddress). In this case, depending on is the chain ETH-based or not DepositTransaction.ApproveERC20 or DepositTransaction.ApproveBaseERC20 can be enabled to perform token approval. If there are already enough approved tokens for the L1 bridge, token approval will be skipped. To check the amount of approved tokens for a specific bridge, use the AdapterL1.AllowanceL1 method.

func (*WalletL1) DepositAllowanceParams added in v0.5.0

func (a *WalletL1) DepositAllowanceParams(opts *CallOpts, msg DepositCallMsg) ([]struct {
	Token     common.Address
	Allowance *big.Int
}, error)

DepositAllowanceParams returns the parameters for the approval token transaction based on the deposit token and amount. Some deposit transactions require multiple approvals. Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified amount.

func (*WalletL1) EstimateCustomBridgeDepositL2Gas added in v0.3.0

func (a *WalletL1) EstimateCustomBridgeDepositL2Gas(ctx context.Context, l1BridgeAddress, l2BridgeAddress, token common.Address,
	amount *big.Int, to common.Address, bridgeData []byte, from common.Address, gasPerPubdataByte *big.Int) (uint64, error)

EstimateCustomBridgeDepositL2Gas used by EstimateDefaultBridgeDepositL2Gas to estimate L2 gas required for token bridging via a custom ERC20 bridge.

func (*WalletL1) EstimateDefaultBridgeDepositL2Gas added in v0.3.0

func (a *WalletL1) EstimateDefaultBridgeDepositL2Gas(ctx context.Context, token common.Address, amount *big.Int,
	to, from common.Address, gasPerPubdataByte *big.Int) (uint64, error)

EstimateDefaultBridgeDepositL2Gas returns an estimation of L2 gas required for token bridging via the default ERC20 bridge.

func (*WalletL1) EstimateGasDeposit added in v0.3.0

func (a *WalletL1) EstimateGasDeposit(ctx context.Context, msg DepositCallMsg) (uint64, error)

EstimateGasDeposit estimates the amount of gas required for a deposit transaction on L1 network. Gas of approving ERC20 token is not included in estimation.

func (*WalletL1) EstimateGasRequestExecute added in v0.3.0

func (a *WalletL1) EstimateGasRequestExecute(ctx context.Context, msg RequestExecuteCallMsg) (uint64, error)

EstimateGasRequestExecute estimates the amount of gas required for a request execute transaction.

func (*WalletL1) FinalizeWithdraw added in v0.3.0

func (a *WalletL1) FinalizeWithdraw(auth *TransactOpts, withdrawalHash common.Hash, index int) (*types.Transaction, error)

FinalizeWithdraw proves the inclusion of the L2 -> L1 withdrawal message.

func (*WalletL1) FullRequiredDepositFee added in v0.3.0

func (a *WalletL1) FullRequiredDepositFee(ctx context.Context, msg DepositCallMsg) (*FullDepositFee, error)

FullRequiredDepositFee retrieves the full needed ETH fee for the deposit on both L1 and L2 networks.

func (*WalletL1) IsEthBasedChain added in v0.5.0

func (a *WalletL1) IsEthBasedChain(ctx context.Context) (bool, error)

IsEthBasedChain returns whether the chain is ETH-based.

func (*WalletL1) IsWithdrawFinalized added in v0.3.0

func (a *WalletL1) IsWithdrawFinalized(opts *CallOpts, withdrawalHash common.Hash, index int) (bool, error)

IsWithdrawFinalized checks if the withdrawal finalized on L1 network.

func (*WalletL1) L1BridgeContracts added in v0.3.0

func (a *WalletL1) L1BridgeContracts(_ context.Context) (*zkTypes.L1BridgeContracts, error)

L1BridgeContracts returns L1 bridge contracts.

func (*WalletL1) L2TokenAddress added in v0.3.0

func (a *WalletL1) L2TokenAddress(ctx context.Context, token common.Address) (common.Address, error)

L2TokenAddress returns the corresponding address on the L2 network for the token on the L1 network.

func (*WalletL1) MainContract added in v0.3.0

MainContract returns the ZKsync L1 smart contract.

func (*WalletL1) PriorityOpConfirmation added in v0.5.0

func (a *WalletL1) PriorityOpConfirmation(ctx context.Context, txHash common.Hash, index int) (*zkTypes.PriorityOpConfirmation, error)

PriorityOpConfirmation returns the transaction confirmation data that is part of `L2->L1` message. The txHash is the hash of the L2 transaction where the message was initiated. The index is used in case there were multiple transactions in one message, you may pass an index of the transaction which confirmation data should be fetched.

func (*WalletL1) RequestExecute added in v0.3.0

func (a *WalletL1) RequestExecute(auth *TransactOpts, tx RequestExecuteTransaction) (*types.Transaction, error)

RequestExecute request execution of L2 transaction from L1.

func (*WalletL1) RequestExecuteAllowanceParams added in v0.5.0

func (a *WalletL1) RequestExecuteAllowanceParams(opts *CallOpts, msg RequestExecuteCallMsg) (AllowanceParams, error)

RequestExecuteAllowanceParams returns the parameters for the approval token transaction based on the request execute transaction. Existing allowance for the bridge is not checked; allowance is calculated solely based on the specified transaction.

type WalletL2 added in v0.3.0

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

WalletL2 implements the AdapterL2 interface.

func NewWalletL2 added in v0.3.0

func NewWalletL2(rawPrivateKey []byte, client *clients.Client) (*WalletL2, error)

NewWalletL2 creates an instance of WalletL2 associated with the account provided by the raw private key.

func NewWalletL2FromSigner added in v0.3.0

func NewWalletL2FromSigner(signer *Signer, client *clients.Client) (*WalletL2, error)

NewWalletL2FromSigner creates an instance of WalletL2. The client can be optional; if it is not provided, only AdapterL2.SignTransaction, AdapterL2.Address, AdapterL2.Signer can be performed, as the rest of the functionalities require communication to the network.

func (*WalletL2) Address added in v0.3.0

func (a *WalletL2) Address() common.Address

Address returns the address of the associated account.

func (*WalletL2) AllBalances added in v0.3.0

func (a *WalletL2) AllBalances(ctx context.Context) (map[common.Address]*big.Int, error)

AllBalances returns all balances for confirmed tokens given by an associated account.

func (*WalletL2) Balance added in v0.3.0

func (a *WalletL2) Balance(ctx context.Context, token common.Address, at *big.Int) (*big.Int, error)

Balance returns the balance of the specified token that can be either base token or any ERC20 token. The block number can be nil, in which case the balance is taken from the latest known block.

func (*WalletL2) CallContract added in v0.3.0

func (a *WalletL2) CallContract(ctx context.Context, msg CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract executes a message call for EIP-712 transaction, which is directly executed in the VM of the node, but never mined into the blockchain.

blockNumber selects the block height at which the call runs. It can be nil, in which case the code is taken from the latest known block. Note that state from very old blocks might not be available.

func (*WalletL2) DeploymentNonce added in v0.4.0

func (a *WalletL2) DeploymentNonce(opts *CallOpts) (*big.Int, error)

DeploymentNonce returns the deployment nonce of the account.

func (*WalletL2) EstimateGasTransfer added in v0.3.0

func (a *WalletL2) EstimateGasTransfer(ctx context.Context, msg TransferCallMsg) (uint64, error)

EstimateGasTransfer estimates the amount of gas required for a transfer transaction.

func (*WalletL2) EstimateGasWithdraw added in v0.3.0

func (a *WalletL2) EstimateGasWithdraw(ctx context.Context, msg WithdrawalCallMsg) (uint64, error)

EstimateGasWithdraw estimates the amount of gas required for a withdrawal transaction.

func (*WalletL2) IsBaseToken added in v0.5.0

func (a *WalletL2) IsBaseToken(ctx context.Context, token common.Address) (bool, error)

IsBaseToken returns whether the token is the base token.

func (*WalletL2) L2BridgeContracts added in v0.3.0

func (a *WalletL2) L2BridgeContracts(_ context.Context) (*zkTypes.L2BridgeContracts, error)

L2BridgeContracts returns L2 bridge contracts.

func (*WalletL2) PopulateTransaction added in v0.3.0

func (a *WalletL2) PopulateTransaction(ctx context.Context, tx Transaction) (*zkTypes.Transaction712, error)

PopulateTransaction is designed for users who prefer a simplified approach by providing only the necessary data to create a valid transaction. The only required fields are Transaction.To and either Transaction.Data or Transaction.Value (or both, if the method is payable). Any other fields that are not set will be prepared by this method.

func (*WalletL2) SendTransaction added in v0.3.0

func (a *WalletL2) SendTransaction(ctx context.Context, tx *Transaction) (common.Hash, error)

SendTransaction injects a transaction into the pending pool for execution. Any unset transaction fields are prepared using the PopulateTransaction method.

func (*WalletL2) SignTransaction added in v0.3.0

func (a *WalletL2) SignTransaction(tx *zkTypes.Transaction712) ([]byte, error)

SignTransaction returns a signed transaction that is ready to be broadcast to the network. The input transaction must be a valid transaction with all fields having appropriate values. To obtain a valid transaction, you can use the PopulateTransaction method.

func (*WalletL2) Signer added in v0.3.0

func (a *WalletL2) Signer() Signer

Signer returns the signer of the associated account.

func (*WalletL2) Transfer added in v0.3.0

func (a *WalletL2) Transfer(auth *TransactOpts, tx TransferTransaction) (*types.Transaction, error)

Transfer moves the base token or any ERC20 token from the associated account to the target account.

func (*WalletL2) Withdraw added in v0.3.0

Withdraw initiates the withdrawal process which withdraws ETH or any ERC20 token from the associated account on L2 network to the target account on L1 network.

type WithdrawalCallMsg added in v0.3.0

type WithdrawalCallMsg struct {
	To            common.Address  // The address of the recipient on L1.
	Amount        *big.Int        // The amount of the token to transfer.
	Token         common.Address  // The address of the token. ETH by default.
	BridgeAddress *common.Address // The address of the bridge contract to be used.

	Gas       uint64   // If 0, the call executes with near-infinite gas.
	GasPrice  *big.Int // Wei <-> gas exchange ratio.
	GasFeeCap *big.Int // EIP-1559 fee cap per gas.
	GasTipCap *big.Int // EIP-1559 tip per gas.

	AccessList types.AccessList // EIP-2930 access list.
}

WithdrawalCallMsg contains the common data required to execute a withdrawal call on L1 from L2. This execution is initiated by the account associated with AdapterL2.

func (*WithdrawalCallMsg) ToWithdrawalCallMsg added in v0.3.0

func (m *WithdrawalCallMsg) ToWithdrawalCallMsg(from common.Address) clients.WithdrawalCallMsg

type WithdrawalTransaction added in v0.3.0

type WithdrawalTransaction struct {
	To              common.Address           // The address that will receive the withdrawn tokens on L1.
	Token           common.Address           // The address of the token to withdraw.
	Amount          *big.Int                 // The amount of the token to withdraw.
	PaymasterParams *zkTypes.PaymasterParams // The paymaster parameters.

	// The address of the bridge contract to be used. Defaults to the default ZKsync bridge
	// (either L2EthBridge or L2Erc20Bridge).
	BridgeAddress *common.Address
}

WithdrawalTransaction represents a withdrawal transaction on L1 from L2 initiated by the account associated with AdapterL2.

func (*WithdrawalTransaction) ToWithdrawalCallMsg added in v0.3.0

func (t *WithdrawalTransaction) ToWithdrawalCallMsg(from common.Address, opts *TransactOpts) *clients.WithdrawalCallMsg

Jump to

Keyboard shortcuts

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