accounts

package
v0.0.0-...-f1447cf Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

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

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 BaseDeployer

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

BaseDeployer implements the Deployer interface.

func NewBaseDeployer

func NewBaseDeployer(adapter *AdapterL2) *BaseDeployer

NewBaseDeployer creates an instance of BaseDeployer.

func (*BaseDeployer) Deploy

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

func (*BaseDeployer) DeployAccount

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

func (*BaseDeployer) DeployAccountWithCreate

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

func (*BaseDeployer) DeployWithCreate

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

type BaseSigner

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

BaseSigner represents basis implementation of Signer interface.

func NewBaseSignerFromMnemonic

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

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

func NewBaseSignerFromMnemonicAndAccountId

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

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

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

func NewRandomBaseSigner

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

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

func (*BaseSigner) Address

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

func (*BaseSigner) Domain

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

func (*BaseSigner) HashTypedData

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

func (*BaseSigner) PrivateKey

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

func (*BaseSigner) SignHash

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

func (*BaseSigner) SignTypedData

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

type CallMsg

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

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

type CallOpts

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

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

type Create2Transaction

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

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

type CreateTransaction

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

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

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

Deprecated: Deprecated in favor of BaseSigner.Address

func (*DefaultEthSigner) Domain deprecated

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

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

type DeploymentType string

DeploymentType represents an enumeration of deployment types.

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

type DepositCallMsg

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

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

func (*DepositCallMsg) ToCallMsg

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

func (*DepositCallMsg) ToDepositTransaction

func (m *DepositCallMsg) ToDepositTransaction() DepositTransaction

func (*DepositCallMsg) ToRequestExecuteCallMsg

func (m *DepositCallMsg) ToRequestExecuteCallMsg() RequestExecuteCallMsg

func (*DepositCallMsg) ToTransactOpts

func (m *DepositCallMsg) ToTransactOpts() TransactOpts

type DepositTransaction

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

	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.

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

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

func (*DepositTransaction) PopulateEmptyFields

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

func (*DepositTransaction) ToDepositCallMsg

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

func (*DepositTransaction) ToRequestExecuteTransaction

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

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 RequestExecuteCallMsg

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

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

func (*RequestExecuteCallMsg) ToRequestExecuteTransaction

func (m *RequestExecuteCallMsg) ToRequestExecuteTransaction() RequestExecuteTransaction

func (*RequestExecuteCallMsg) ToTransactOpts

func (m *RequestExecuteCallMsg) ToTransactOpts() TransactOpts

type RequestExecuteTransaction

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

func (*RequestExecuteTransaction) ToRequestExecuteCallMsg

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

type Signer

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 TransactOpts

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

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

type Transaction

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

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

func (*Transaction) ToTransaction712

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

type TransferCallMsg

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

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

type TransferTransaction

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

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

func (*TransferTransaction) ToTransaction

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

func (*TransferTransaction) ToTransferCallMsg

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

type Wallet

type Wallet struct {
	AdapterL1
	AdapterL2
	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

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

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

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

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

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

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

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

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

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

WalletL1 implements the AdapterL1 interface.

func NewWalletL1

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

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

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

func (*WalletL1) ApproveERC20

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

func (*WalletL1) BalanceL1

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

func (*WalletL1) BaseCost

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

func (*WalletL1) ClaimFailedDeposit

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

func (*WalletL1) Deposit

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

func (*WalletL1) EstimateCustomBridgeDepositL2Gas

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

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

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

func (*WalletL1) EstimateGasRequestExecute

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

func (*WalletL1) FinalizeWithdraw

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

func (*WalletL1) FullRequiredDepositFee

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

func (*WalletL1) IsWithdrawFinalized

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

func (*WalletL1) L1BridgeContracts

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

func (*WalletL1) L2TokenAddress

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

func (*WalletL1) MainContract

func (a *WalletL1) MainContract(_ context.Context) (*zksync.IZkSync, error)

func (*WalletL1) RequestExecute

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

type WalletL2

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

WalletL2 implements the AdapterL2 interface.

func NewWalletL2

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

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

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

func (*WalletL2) AllBalances

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

func (*WalletL2) Balance

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

func (*WalletL2) CallContract

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

func (*WalletL2) EstimateGasTransfer

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

func (*WalletL2) EstimateGasWithdraw

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

func (*WalletL2) L2BridgeContracts

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

func (*WalletL2) PopulateTransaction

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

func (*WalletL2) SendTransaction

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

func (*WalletL2) SignTransaction

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

func (*WalletL2) Signer

func (a *WalletL2) Signer() Signer

func (*WalletL2) Transfer

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

func (*WalletL2) Withdraw

type WithdrawalCallMsg

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

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

type WithdrawalTransaction

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.

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

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