etherman

package
v0.6.8-RC1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2024 License: AGPL-3.0, AGPL-3.0-or-later Imports: 43 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGasRequiredExceedsAllowance gas required exceeds the allowance
	ErrGasRequiredExceedsAllowance = errors.New("gas required exceeds allowance")
	// ErrContentLengthTooLarge content length is too large
	ErrContentLengthTooLarge = errors.New("content length too large")
	//ErrTimestampMustBeInsideRange Timestamp must be inside range
	ErrTimestampMustBeInsideRange = errors.New("timestamp must be inside range")
	//ErrInsufficientAllowance insufficient allowance
	ErrInsufficientAllowance = errors.New("insufficient allowance")
	// ErrBothGasPriceAndMaxFeeGasAreSpecified both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified
	ErrBothGasPriceAndMaxFeeGasAreSpecified = errors.New("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
	// ErrMaxFeeGasAreSpecifiedButLondonNotActive maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet
	ErrMaxFeeGasAreSpecifiedButLondonNotActive = errors.New("maxFeePerGas or maxPriorityFeePerGas specified but london is not active yet")
	// ErrNoSigner no signer to authorize the transaction with
	ErrNoSigner = errors.New("no signer to authorize the transaction with")
	// ErrMissingTrieNode means that a node is missing on the trie
	ErrMissingTrieNode = errors.New("missing trie node")
)
View Source
var (

	// ErrNotFound is used when the object is not found
	ErrNotFound = errors.New("not found")
	// ErrIsReadOnlyMode is used when the EtherMan client is in read-only mode.
	ErrIsReadOnlyMode = errors.New("etherman client in read-only mode: no account configured to send transactions to L1. " +
		"please check the [Etherman] PrivateKeyPath and PrivateKeyPassword configuration")
	// ErrPrivateKeyNotFound used when the provided sender does not have a private key registered to be used
	ErrPrivateKeyNotFound = errors.New("can't find sender private key to sign tx")
)

Functions

func SequencedBatchesSigHash

func SequencedBatchesSigHash() common.Hash

SequencedBatchesSigHash returns the hash for the `SequenceBatches` event.

func TrustedVerifyBatchesSigHash

func TrustedVerifyBatchesSigHash() common.Hash

TrustedVerifyBatchesSigHash returns the hash for the `TrustedVerifyBatches` event.

Types

type Block

type Block struct {
	BlockNumber           uint64
	BlockHash             common.Hash
	ParentHash            common.Hash
	ForcedBatches         []ForcedBatch
	SequencedBatches      [][]SequencedBatch
	UpdateEtrogSequence   UpdateEtrogSequence
	VerifiedBatches       []VerifiedBatch
	SequencedForceBatches [][]SequencedForceBatch
	ForkIDs               []ForkID
	ReceivedAt            time.Time
	// GER data
	GlobalExitRoots, L1InfoTree []GlobalExitRoot
}

Block struct

type Client

type Client struct {
	EthClient                ethereumClient
	OldZkEVM                 *oldpolygonzkevm.Oldpolygonzkevm
	EtrogZKEVM               *etrogpolygonzkevm.Etrogpolygonzkevm
	ZkEVM                    *polygonzkevm.Polygonzkevm
	RollupManager            *polygonrollupmanager.Polygonrollupmanager
	GlobalExitRootManager    *polygonzkevmglobalexitroot.Polygonzkevmglobalexitroot
	OldGlobalExitRootManager *oldpolygonzkevmglobalexitroot.Oldpolygonzkevmglobalexitroot
	Pol                      *pol.Pol
	SCAddresses              []common.Address

	RollupID uint32

	GasProviders externalGasProviders
	// contains filtered or unexported fields
}

Client is a simple implementation of EtherMan.

func NewClient

func NewClient(cfg Config, l1Config L1Config) (*Client, error)

NewClient creates a new etherman.

func NewSimulatedEtherman

NewSimulatedEtherman creates an etherman that uses a simulated blockchain. It's important to notice that the ChainID of the auth must be 1337. The address that holds the auth will have an initial balance of 10 ETH

func (*Client) AddOrReplaceAuth

func (etherMan *Client) AddOrReplaceAuth(auth bind.TransactOpts) error

AddOrReplaceAuth adds an authorization or replace an existent one to the same account

func (*Client) ApprovePol added in v0.5.0

func (etherMan *Client) ApprovePol(ctx context.Context, account common.Address, polAmount *big.Int, to common.Address) (*types.Transaction, error)

ApprovePol function allow to approve tokens in pol smc

func (*Client) BuildSequenceBatchesTxData

func (etherMan *Client) BuildSequenceBatchesTxData(sender common.Address, sequences []ethmanTypes.Sequence, maxSequenceTimestamp uint64, lastSequencedBatchNumber uint64, l2Coinbase common.Address) (to *common.Address, data []byte, err error)

BuildSequenceBatchesTxData builds a []bytes to be sent to the PoE SC method SequenceBatches.

func (*Client) BuildTrustedVerifyBatchesTxData

func (etherMan *Client) BuildTrustedVerifyBatchesTxData(lastVerifiedBatch, newVerifiedBatch uint64, inputs *ethmanTypes.FinalProofInputs, beneficiary common.Address) (to *common.Address, data []byte, err error)

BuildTrustedVerifyBatchesTxData builds a []bytes to be sent to the PoE SC method TrustedVerifyBatches.

func (*Client) CheckTxWasMined

func (etherMan *Client) CheckTxWasMined(ctx context.Context, txHash common.Hash) (bool, *types.Receipt, error)

CheckTxWasMined check if a tx was already mined

func (*Client) CurrentNonce

func (etherMan *Client) CurrentNonce(ctx context.Context, account common.Address) (uint64, error)

CurrentNonce returns the current nonce for the provided account

func (*Client) DepositCount added in v0.6.6

func (etherman *Client) DepositCount(ctx context.Context, blockNumber *uint64) (*big.Int, error)

DepositCount returns deposits count

func (*Client) EstimateGas

func (etherMan *Client) EstimateGas(ctx context.Context, from common.Address, to *common.Address, value *big.Int, data []byte) (uint64, error)

EstimateGas returns the estimated gas for the tx

func (*Client) EstimateGasSequenceBatches

func (etherMan *Client) EstimateGasSequenceBatches(sender common.Address, sequences []ethmanTypes.Sequence, maxSequenceTimestamp uint64, lastSequencedBatchNumber uint64, l2Coinbase common.Address) (*types.Transaction, error)

EstimateGasSequenceBatches estimates gas for sending batches

func (*Client) EthBlockByNumber

func (etherMan *Client) EthBlockByNumber(ctx context.Context, blockNumber uint64) (*types.Block, error)

EthBlockByNumber function retrieves the ethereum block information by ethereum block number.

func (*Client) GetFinalizedBlockNumber added in v0.0.990

func (etherMan *Client) GetFinalizedBlockNumber(ctx context.Context) (uint64, error)

GetFinalizedBlockNumber gets the Finalized block number from the ethereum

func (*Client) GetForks

func (etherMan *Client) GetForks(ctx context.Context, genBlockNumber uint64, lastL1BlockSynced uint64) ([]state.ForkIDInterval, error)

GetForks returns fork information

func (*Client) GetL1GasPrice

func (etherMan *Client) GetL1GasPrice(ctx context.Context) *big.Int

GetL1GasPrice gets the l1 gas price

func (*Client) GetL2ChainID

func (etherMan *Client) GetL2ChainID() (uint64, error)

GetL2ChainID returns L2 Chain ID

func (*Client) GetLatestBatchNumber

func (etherMan *Client) GetLatestBatchNumber() (uint64, error)

GetLatestBatchNumber function allows to retrieve the latest proposed batch in the smc

func (*Client) GetLatestBlockHeader added in v0.5.3

func (etherMan *Client) GetLatestBlockHeader(ctx context.Context) (*types.Header, error)

GetLatestBlockHeader gets the latest block header from the ethereum

func (*Client) GetLatestBlockNumber

func (etherMan *Client) GetLatestBlockNumber(ctx context.Context) (uint64, error)

GetLatestBlockNumber gets the latest block number from the ethereum

func (*Client) GetLatestBlockTimestamp

func (etherMan *Client) GetLatestBlockTimestamp(ctx context.Context) (uint64, error)

GetLatestBlockTimestamp gets the latest block timestamp from the ethereum

func (*Client) GetLatestVerifiedBatchNum

func (etherMan *Client) GetLatestVerifiedBatchNum() (uint64, error)

GetLatestVerifiedBatchNum gets latest verified batch from ethereum

func (*Client) GetRevertMessage

func (etherMan *Client) GetRevertMessage(ctx context.Context, tx *types.Transaction) (string, error)

GetRevertMessage tries to get a revert message of a transaction

func (*Client) GetRollupInfoByBlockRange

func (etherMan *Client) GetRollupInfoByBlockRange(ctx context.Context, fromBlock uint64, toBlock *uint64) ([]Block, map[common.Hash][]Order, error)

GetRollupInfoByBlockRange function retrieves the Rollup information that are included in all this ethereum blocks from block x to block y.

func (*Client) GetSafeBlockNumber added in v0.0.990

func (etherMan *Client) GetSafeBlockNumber(ctx context.Context) (uint64, error)

GetSafeBlockNumber gets the safe block number from the ethereum

func (*Client) GetSendSequenceFee

func (etherMan *Client) GetSendSequenceFee(numBatches uint64) (*big.Int, error)

GetSendSequenceFee get super/trusted sequencer fee

func (*Client) GetTrustedSequencerURL

func (etherMan *Client) GetTrustedSequencerURL() (string, error)

GetTrustedSequencerURL Gets the trusted sequencer url from rollup smc

func (*Client) GetTx

func (etherMan *Client) GetTx(ctx context.Context, txHash common.Hash) (*types.Transaction, bool, error)

GetTx function get ethereum tx

func (*Client) GetTxReceipt

func (etherMan *Client) GetTxReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

GetTxReceipt function gets ethereum tx receipt

func (*Client) HeaderByNumber

func (etherMan *Client) HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error)

HeaderByNumber returns a block header from the current canonical chain. If number is nil, the latest known header is returned.

func (*Client) LoadAuthFromKeyStore

func (etherMan *Client) LoadAuthFromKeyStore(path, password string) (*bind.TransactOpts, error)

LoadAuthFromKeyStore loads an authorization from a key store file

func (*Client) SendTx

func (etherMan *Client) SendTx(ctx context.Context, tx *types.Transaction) error

SendTx sends a tx to L1

func (*Client) SignTx

func (etherMan *Client) SignTx(ctx context.Context, sender common.Address, tx *types.Transaction) (*types.Transaction, error)

SignTx tries to sign a transaction accordingly to the provided sender

func (*Client) SuggestedGasPrice

func (etherMan *Client) SuggestedGasPrice(ctx context.Context) (*big.Int, error)

SuggestedGasPrice returns the suggest nonce for the network at the moment

func (*Client) TrustedSequencer

func (etherMan *Client) TrustedSequencer() (common.Address, error)

TrustedSequencer gets trusted sequencer address

func (*Client) VerifyGenBlockNumber

func (etherMan *Client) VerifyGenBlockNumber(ctx context.Context, genBlockNumber uint64) (bool, error)

VerifyGenBlockNumber verifies if the genesis Block Number is valid

func (*Client) WaitTxToBeMined

func (etherMan *Client) WaitTxToBeMined(ctx context.Context, tx *types.Transaction, timeout time.Duration) (bool, error)

WaitTxToBeMined waits for an L1 tx to be mined. It will return error if the tx is reverted or timeout is exceeded

type Config

type Config struct {
	// URL is the URL of the Ethereum node for L1
	URL string `mapstructure:"URL"`

	// ForkIDChunkSize is the max interval for each call to L1 provider to get the forkIDs
	ForkIDChunkSize uint64 `mapstructure:"ForkIDChunkSize"`

	// allow that L1 gas price calculation use multiples sources
	MultiGasProvider bool `mapstructure:"MultiGasProvider"`
	// Configuration for use Etherscan as used as gas provider, basically it needs the API-KEY
	Etherscan etherscan.Config
}

Config represents the configuration of the etherman

type EventOrder

type EventOrder string

EventOrder is the the type used to identify the events order

const (
	// GlobalExitRootsOrder identifies a GlobalExitRoot event
	GlobalExitRootsOrder EventOrder = "GlobalExitRoots"
	// L1InfoTreeOrder identifies a L1InTree event
	L1InfoTreeOrder EventOrder = "L1InfoTreeOrder"
	// SequenceBatchesOrder identifies a VerifyBatch event
	SequenceBatchesOrder EventOrder = "SequenceBatches"
	// UpdateEtrogSequenceOrder identifies a VerifyBatch event
	UpdateEtrogSequenceOrder EventOrder = "UpdateEtrogSequence"
	// ForcedBatchesOrder identifies a ForcedBatches event
	ForcedBatchesOrder EventOrder = "ForcedBatches"
	// TrustedVerifyBatchOrder identifies a TrustedVerifyBatch event
	TrustedVerifyBatchOrder EventOrder = "TrustedVerifyBatch"
	// VerifyBatchOrder identifies a VerifyBatch event
	VerifyBatchOrder EventOrder = "VerifyBatch"
	// SequenceForceBatchesOrder identifies a SequenceForceBatches event
	SequenceForceBatchesOrder EventOrder = "SequenceForceBatches"
	// ForkIDsOrder identifies an updateZkevmVersion event
	ForkIDsOrder EventOrder = "forkIDs"
	// InitialSequenceBatchesOrder identifies a VerifyBatch event
	InitialSequenceBatchesOrder EventOrder = "InitialSequenceBatches"
)

type ForcedBatch

type ForcedBatch struct {
	BlockNumber       uint64
	ForcedBatchNumber uint64
	Sequencer         common.Address
	GlobalExitRoot    common.Hash
	RawTxsData        []byte
	ForcedAt          time.Time
}

ForcedBatch represents a ForcedBatch

type ForkID

type ForkID struct {
	BatchNumber uint64
	ForkID      uint64
	Version     string
}

ForkID is a sturct to track the ForkID event.

type GlobalExitRoot

type GlobalExitRoot struct {
	BlockNumber       uint64
	MainnetExitRoot   common.Hash
	RollupExitRoot    common.Hash
	GlobalExitRoot    common.Hash
	Timestamp         time.Time
	PreviousBlockHash common.Hash
}

GlobalExitRoot struct

type L1Config added in v0.0.990

type L1Config struct {
	// Chain ID of the L1 network
	L1ChainID uint64 `json:"chainId"`
	// ZkEVMAddr Address of the L1 contract polygonZkEVMAddress
	ZkEVMAddr common.Address `json:"polygonZkEVMAddress"`
	// RollupManagerAddr Address of the L1 contract
	RollupManagerAddr common.Address `json:"polygonRollupManagerAddress"`
	// PolAddr Address of the L1 Pol token Contract
	PolAddr common.Address `json:"polTokenAddress"`
	// GlobalExitRootManagerAddr Address of the L1 GlobalExitRootManager contract
	GlobalExitRootManagerAddr common.Address `json:"polygonZkEVMGlobalExitRootAddress"`
}

L1Config represents the configuration of the network used in L1

type Order

type Order struct {
	Name EventOrder
	Pos  int
}

Order contains the event order to let the synchronizer store the information following this order.

type SequencedBatch

type SequencedBatch struct {
	BatchNumber   uint64
	L1InfoRoot    *common.Hash
	SequencerAddr common.Address
	TxHash        common.Hash
	Nonce         uint64
	Coinbase      common.Address
	// Struct used in preEtrog forks
	*oldpolygonzkevm.PolygonZkEVMBatchData
	// Struct used in Etrog
	*polygonzkevm.PolygonRollupBaseEtrogBatchData
	// Struct used in Elderberry
	*SequencedBatchElderberryData
}

SequencedBatch represents virtual batch

type SequencedBatchElderberryData added in v0.6.0

type SequencedBatchElderberryData struct {
	MaxSequenceTimestamp     uint64
	InitSequencedBatchNumber uint64 // Last sequenced batch number
}

SequencedBatchElderberryData represents an Elderberry sequenced batch data

type SequencedForceBatch

type SequencedForceBatch struct {
	BatchNumber uint64
	Coinbase    common.Address
	TxHash      common.Hash
	Timestamp   time.Time
	Nonce       uint64
	polygonzkevm.PolygonRollupBaseEtrogBatchData
}

SequencedForceBatch is a sturct to track the ForceSequencedBatches event.

type UpdateEtrogSequence added in v0.5.0

type UpdateEtrogSequence struct {
	BatchNumber   uint64
	SequencerAddr common.Address
	TxHash        common.Hash
	Nonce         uint64
	// Struct used in Etrog
	*polygonzkevm.PolygonRollupBaseEtrogBatchData
}

UpdateEtrogSequence represents the first etrog sequence

type VerifiedBatch

type VerifiedBatch struct {
	BlockNumber uint64
	BatchNumber uint64
	Aggregator  common.Address
	StateRoot   common.Hash
	TxHash      common.Hash
}

VerifiedBatch represents a VerifiedBatch

Jump to

Keyboard shortcuts

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