models.ts
Overview
The [models.ts](/projects/291/69105) file defines TypeScript interfaces related to gas estimations and fee recommendations for blockchain transactions involving both Layer 1 (L1) and Layer 2 (L2) networks. Specifically, it extends base types imported from an external EVM (Ethereum Virtual Machine) API module to include additional properties pertinent to Layer 1 gas metrics. This enables the application to handle and represent combined gas data spanning both layers, which is crucial for accurate transaction cost calculations and fee recommendations in multi-layer blockchain environments.
Interfaces
BaseGasEstimate
export interface BaseGasEstimate extends GasEstimate {
l1GasLimit: string
}
Description
`BaseGasEstimate` extends the `GasEstimate` interface imported from an external EVM API module. It adds the `l1GasLimit` property to provide information about the estimated gas limit specifically for Layer 1 transactions, complementing the existing gas estimation data.
Properties
Property | Type | Description |
|---|---|---|
*Inherited* | All properties from `GasEstimate` (e.g., `gasLimit`, `gasUsed`, etc.) | |
`l1GasLimit` | `string` | The estimated gas limit for the Layer 1 transaction. Represents the maximum amount of gas the L1 transaction is expected to consume. |
Usage Example
const estimate: BaseGasEstimate = {
gasLimit: "21000", // from GasEstimate
gasUsed: "20000",
l1GasLimit: "15000" // additional L1 gas limit
};
BaseGasFees
export interface BaseGasFees extends GasFees {
l1GasPrice: string
}
Description
`BaseGasFees` extends the `GasFees` interface imported from the EVM API module. It adds an `l1GasPrice` property to indicate the current recommended gas price for Layer 1 transactions. This allows fee calculations to consider both L2 and L1 gas prices, which is important in contexts where the cost of executing on L1 must be factored into overall transaction fees.
Properties
Property | Type | Description |
|---|---|---|
*Inherited* | All properties from `GasFees` (e.g., `maxFeePerGas`, `maxPriorityFeePerGas`, etc.) | |
`l1GasPrice` | `string` | The recommended gas price for Layer 1 transactions, typically expressed in wei or gwei. |
Usage Example
const fees: BaseGasFees = {
maxFeePerGas: "1000000000", // from GasFees
maxPriorityFeePerGas: "200000000",
l1GasPrice: "500000000" // additional L1 gas price
};
Implementation Details
Extension of External Types: Both interfaces extend types imported from
'../../../common/api/src/evm'. This promotes reuse of common EVM-related data structures while allowing augmentation with Layer 1-specific details.String Types for Gas Values: The properties like
l1GasLimitandl1GasPriceusestringdatatype. This is common in blockchain applications to avoid precision errors inherent to floating-point arithmetic and to handle very large numbers safely (often represented as strings to be parsed by big number libraries).Separation of L1 and L2 Gas Data: By explicitly including L1 gas fields alongside inherited L2 gas data, these interfaces facilitate clear, combined reporting of gas usage and fees in multi-layer blockchain solutions (e.g., rollups, sidechains).
Interaction with Other System Components
EVM API Module: The file depends on the EVM API module for the base interfaces (
GasEstimateandGasFees). This indicates its role in a larger system that interacts with Ethereum-compatible blockchains.Transaction Cost Calculation: These interfaces are likely used wherever transaction gas estimation and fee recommendation logic is implemented, such as services preparing transactions or UI components displaying cost information to users.
Cross-Layer Fee Management: By incorporating both L1 and L2 gas parameters, these models support workflows that require coordinated fee estimation and optimization across blockchain layers, typical in systems leveraging Layer 2 scalability solutions.
Mermaid Class Diagram
classDiagram
class GasEstimate {
<<interface>>
+gasLimit: string
+gasUsed: string
+... (other EVM gas properties)
}
class BaseGasEstimate {
+l1GasLimit: string
}
BaseGasEstimate --|> GasEstimate
class GasFees {
<<interface>>
+maxFeePerGas: string
+maxPriorityFeePerGas: string
+... (other EVM fee properties)
}
class BaseGasFees {
+l1GasPrice: string
}
BaseGasFees --|> GasFees
Summary
The [models.ts](/projects/291/69105) file provides enhanced gas estimation and fee interfaces tailored for multi-layer blockchain environments by extending base EVM types with Layer 1-specific gas data. This modular approach simplifies handling cross-layer transaction cost details and integrates smoothly with broader transaction processing and fee recommendation services in the system.