models.ts

Overview

The [models.ts](/projects/291/68901) file defines TypeScript interfaces that extend existing gas estimation and fee models to accommodate the specifics of the Optimism Layer 2 (L2) scaling solution for Ethereum. Specifically, it introduces additional gas-related fields relevant to transactions that involve both Layer 1 (L1) and Layer 2 layers in the Optimism network.

This file serves as a type definition module to ensure that gas estimation and fee data structures used throughout the application accurately reflect the dual-layer nature of Optimism transactions. It enables type-safe handling of these enhanced gas models in the application’s logic, UI, and API interactions.


Detailed Explanations

Interfaces

1. OptimismGasEstimate

export interface OptimismGasEstimate extends GasEstimate {
  l1GasLimit: string
}
const estimate: OptimismGasEstimate = {
  gasLimit: "21000",
  gasPrice: "1000000000",
  l1GasLimit: "5000"
};

This interface would typically be used when estimating the total gas required for a transaction that will be executed on Optimism, including the L1 gas needed for finalization or rollup proofs.


2. OptimismGasFees

export interface OptimismGasFees extends GasFees {
  l1GasPrice: string
}
const fees: OptimismGasFees = {
  maxFeePerGas: "2000000000",
  maxPriorityFeePerGas: "1000000000",
  l1GasPrice: "1500000000"
};

This interface is helpful for calculating the total fee to be paid for a transaction that involves both layers, ensuring the user or system accounts for L1 cost in addition to L2 fees.


Important Implementation Details


Interaction with Other Parts of the System


Mermaid Class Diagram

classDiagram
    class GasEstimate {
        <<imported>>
        +gasLimit: string
        +gasPrice: string
        ...
    }

    class GasFees {
        <<imported>>
        +maxFeePerGas: string
        +maxPriorityFeePerGas: string
        ...
    }

    class OptimismGasEstimate {
        +l1GasLimit: string
    }
    OptimismGasEstimate --|> GasEstimate

    class OptimismGasFees {
        +l1GasPrice: string
    }
    OptimismGasFees --|> GasFees

Summary