fees

package
v0.0.0-...-50b04ad Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 License: GPL-3.0, MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrGasPriceTooLow represents the error case of then the user pays too little
	ErrGasPriceTooLow = errors.New("gas price too low")
	// ErrGasPriceTooHigh represents the error case of when the user pays too much
	ErrGasPriceTooHigh = errors.New("gas price too high")
	// ErrInsufficientFunds represents the error case of when the user doesn't
	// have enough funds to cover the transaction
	ErrInsufficientFunds = errors.New("insufficient funds for l1Fee + l2Fee + value")

	// ErrL2GasLimitTooLow represents the error case of when a user sends a
	// transaction to the sequencer with a L2 gas limit that is too small
	ErrL2GasLimitTooLow = errors.New("L2 gas limit too low")
)

Functions

func CalculateL1Fee

func CalculateL1Fee(data []byte, overhead, l1GasPrice *big.Int, scalar *big.Float) *big.Int

CalculateL1Fee computes the L1 fee

func CalculateL1GasUsed

func CalculateL1GasUsed(data []byte, overhead *big.Int) *big.Int

CalculateL1GasUsed computes the L1 gas used based on the calldata and constant sized overhead. The overhead can be decreased as the cost of the batch submission goes down via contract optimizations. This will not overflow under standard network conditions.

func CalculateL1MsgFee

func CalculateL1MsgFee(msg Message, state StateDB, gpo *common.Address) (*big.Int, error)

CalculateL1MsgFee computes the L1 portion of the fee given a Message and a StateDB

func CalculateTotalFee

func CalculateTotalFee(tx *types.Transaction, gpo RollupOracle) (*big.Int, error)

CalculateTotalFee will calculate the total fee given a transaction. This function is used at the RPC layer to ensure that users have enough ETH to cover their fee

func CalculateTotalMsgFee

func CalculateTotalMsgFee(msg Message, state StateDB, gasUsed *big.Int, gpo *common.Address) (*big.Int, error)

CalculateMsgFee will calculate the total fee given a Message. This function is used during the state transition to transfer value to the sequencer. Since Messages do not have a signature and the signature is submitted to L1 in a batch, extra bytes are padded to the raw transaction

func DeriveL1GasInfo

func DeriveL1GasInfo(msg Message, state StateDB) (*big.Int, *big.Int, *big.Int, *big.Float, error)

DeriveL1GasInfo reads L1 gas related information to be included on the receipt

func PaysEnough

func PaysEnough(opts *PaysEnoughOpts) error

PaysEnough returns an error if the fee is not large enough `GasPrice` and `Fee` are required arguments.

func ScaleDecimals

func ScaleDecimals(scalar, decimals *big.Int) *big.Float

ScaleDecimals will scale a value by decimals

Types

type Message

type Message interface {
	From() common.Address
	To() *common.Address
	GasPrice() *big.Int
	Gas() uint64
	Value() *big.Int
	Nonce() uint64
	Data() []byte
}

Message represents the interface of a message. It should be a subset of the methods found on types.Message

type PaysEnoughOpts

type PaysEnoughOpts struct {
	UserGasPrice, ExpectedGasPrice *big.Int
	ThresholdUp, ThresholdDown     *big.Float
}

PaysEnoughOpts represent the options to PaysEnough

type RollupOracle

type RollupOracle interface {
	SuggestL1GasPrice(ctx context.Context) (*big.Int, error)
	SuggestL2GasPrice(ctx context.Context) (*big.Int, error)
	SuggestOverhead(ctx context.Context) (*big.Int, error)
	SuggestScalar(ctx context.Context) (*big.Float, error)
}

RollupOracle represents the interface of the in memory cache of the gas price oracle

type StateDB

type StateDB interface {
	GetState(common.Address, common.Hash) common.Hash
}

StateDB represents the StateDB interface required to compute the L1 fee

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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