Documentation ¶
Index ¶
- Variables
- func CalculateL1Fee(data []byte, overhead, l1GasPrice *big.Int, scalar *big.Float) *big.Int
- func CalculateL1GasUsed(data []byte, overhead *big.Int) *big.Int
- func CalculateL1MsgFee(msg Message, state StateDB, gpo *common.Address) (*big.Int, error)
- func CalculateTotalFee(tx *types.Transaction, gpo RollupOracle) (*big.Int, error)
- func CalculateTotalMsgFee(msg Message, state StateDB, gasUsed *big.Int, gpo *common.Address) (*big.Int, error)
- func DeriveL1GasInfo(msg Message, state StateDB) (*big.Int, *big.Int, *big.Int, *big.Float, error)
- func PaysEnough(opts *PaysEnoughOpts) error
- func ScaleDecimals(scalar, decimals *big.Int) *big.Float
- type Message
- type PaysEnoughOpts
- type RollupOracle
- type StateDB
Constants ¶
This section is empty.
Variables ¶
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 ¶
CalculateL1Fee computes the L1 fee
func CalculateL1GasUsed ¶
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 ¶
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 ¶
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.
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