Options
All
  • Public
  • Public/Protected
  • All
Menu

@eth-optimism/sdk

Index

Type Aliases

AddressLike: string | Contract

Stuff that can be coerced into an address.

DeepPartial<T>: { [ P in keyof T]?: DeepPartial<T[P]> }

Utility type for deep partials.

Type Parameters

  • T

L2Provider<TProvider>: TProvider & { _isL2Provider: true; estimateL1Gas: any; estimateL1GasCost: any; estimateL2GasCost: any; estimateTotalGasCost: any; getL1GasPrice: any }

Represents an extended version of an normal ethers Provider that returns additional L2 info and has special functions for L2-specific interactions.

Type Parameters

  • TProvider extends Provider

LowLevelMessage: CoreCrossChainMessage

Describes messages sent inside the L2ToL1MessagePasser on L2. Happens to be the same structure as the CoreCrossChainMessage so we'll reuse the type for now.

Stuff that can be coerced into a CrossChainMessage.

Stuff that can be coerced into a CrossChainMessageRequest.

NumberLike: string | number | BigNumber

Stuff that can be coerced into a number.

OEL1ContractsLike: { [ K in keyof OEL1Contracts]: AddressLike }

Convenience type for something that looks like the L1 OE contract interface but could be addresses instead of actual contract objects.

OEL2ContractsLike: { [ K in keyof OEL2Contracts]: AddressLike }

Convenience type for something that looks like the L2 OE contract interface but could be addresses instead of actual contract objects.

ProviderLike: string | Provider

Stuff that can be coerced into a provider.

SignerLike: string | Signer

Stuff that can be coerced into a signer.

SignerOrProviderLike: SignerLike | ProviderLike

Stuff that can be coerced into a signer or provider.

TransactionLike: string | TransactionReceipt | TransactionResponse

Stuff that can be coerced into a transaction.

Variables

BRIDGE_ADAPTER_DATA: { [ ChainID in L2ChainID]?: BridgeAdapterData } = ...

Mapping of L1 chain IDs to the list of custom bridge addresses for each chain.

CHAIN_BLOCK_TIMES: { [ ChainID in L1ChainID]: number } = ...
CONTRACT_ADDRESSES: { [ ChainID in L2ChainID]: OEContractsLike } = ...

Mapping of L1 chain IDs to the appropriate contract addresses for the OE deployments to the given network. Simplifies the process of getting the correct contract addresses for a given contract name.

DEFAULT_L2_CONTRACT_ADDRESSES: OEL2ContractsLike = ...

Full list of default L2 contract addresses. TODO(tynes): migrate to predeploys from contracts-bedrock

DEPOSIT_CONFIRMATION_BLOCKS: { [ ChainID in L2ChainID]: number } = ...

Functions

  • asL2Provider<TProvider>(provider: TProvider): L2Provider<TProvider>
  • Returns an provider wrapped as an Optimism L2 provider. Adds a few extra helper functions to simplify the process of estimating the gas usage for a transaction on Optimism. Returns a COPY of the original provider.

    Type Parameters

    • TProvider extends Provider<TProvider>

    Parameters

    • provider: TProvider

      Provider to wrap into an L2 provider.

    Returns L2Provider<TProvider>

    Provider wrapped as an L2 provider.

  • estimateL1Gas(l2Provider: ProviderLike, tx: TransactionRequest): Promise<BigNumber>
  • Estimates the amount of L1 gas required for a given L2 transaction.

    Parameters

    • l2Provider: ProviderLike

      L2 provider to query the gas usage from.

    • tx: TransactionRequest

      Transaction to estimate L1 gas for.

    Returns Promise<BigNumber>

    Estimated L1 gas.

  • estimateL1GasCost(l2Provider: ProviderLike, tx: TransactionRequest): Promise<BigNumber>
  • Estimates the amount of L1 gas cost for a given L2 transaction in wei.

    Parameters

    • l2Provider: ProviderLike

      L2 provider to query the gas usage from.

    • tx: TransactionRequest

      Transaction to estimate L1 gas cost for.

    Returns Promise<BigNumber>

    Estimated L1 gas cost.

  • estimateL2GasCost(l2Provider: ProviderLike, tx: TransactionRequest): Promise<BigNumber>
  • Estimates the L2 gas cost for a given L2 transaction in wei.

    Parameters

    • l2Provider: ProviderLike

      L2 provider to query the gas usage from.

    • tx: TransactionRequest

      Transaction to estimate L2 gas cost for.

    Returns Promise<BigNumber>

    Estimated L2 gas cost.

  • estimateTotalGasCost(l2Provider: ProviderLike, tx: TransactionRequest): Promise<BigNumber>
  • Estimates the total gas cost for a given L2 transaction in wei.

    Parameters

    • l2Provider: ProviderLike

      L2 provider to query the gas usage from.

    • tx: TransactionRequest

      Transaction to estimate total gas cost for.

    Returns Promise<BigNumber>

    Estimated total gas cost.

  • Automatically connects to all contract addresses, both L1 and L2, for the given L2 chain ID. The user can provide custom contract address overrides for L1 or L2 contracts. If the given chain ID is not known then the user MUST provide custom contract addresses for ALL L1 contracts or this function will throw an error.

    Parameters

    • l2ChainId: number

      Chain ID for the L2 network.

    • opts: { l1SignerOrProvider?: Provider | Signer; l2SignerOrProvider?: Provider | Signer; overrides?: DeepPartial<OEContractsLike> } = {}

      Additional options for connecting to the contracts.

      • Optional l1SignerOrProvider?: Provider | Signer
      • Optional l2SignerOrProvider?: Provider | Signer
      • Optional overrides?: DeepPartial<OEContractsLike>

        Custom contract address overrides for L1 or L2 contracts.

    Returns OEContracts

    An object containing ethers.Contract objects connected to the appropriate addresses on both L1 and L2.

  • Gets the current L1 gas price as seen on L2.

    Parameters

    • l2Provider: ProviderLike

      L2 provider to query the L1 gas price from.

    Returns Promise<BigNumber>

    Current L1 gas price as seen on L2.

  • Returns an ethers.Contract object for the given name, connected to the appropriate address for the given L2 chain ID. Users can also provide a custom address to connect the contract to instead. If the chain ID is not known then the user MUST provide a custom address or this function will throw an error.

    Parameters

    • contractName: keyof OEL1Contracts | keyof OEL2Contracts

      Name of the contract to connect to.

    • l2ChainId: number

      Chain ID for the L2 network.

    • opts: { address?: AddressLike; signerOrProvider?: Provider | Signer } = {}

      Additional options for connecting to the contract.

      • Optional address?: AddressLike

        Custom address to connect to the contract.

      • Optional signerOrProvider?: Provider | Signer

        Signer or provider to connect to the contract.

    Returns Contract

    An ethers.Contract object connected to the appropriate address and interface.

  • hashMessageHash(messageHash: string): string
  • Utility for hashing a message hash. This computes the storage slot where the message hash will be stored in state. HashZero is used because the first mapping in the contract is used.

    Parameters

    • messageHash: string

      Message hash to hash.

    Returns string

    Hash of the given message hash.

  • isL2Provider<TProvider>(provider: TProvider): provider is L2Provider<TProvider>
  • Determines if a given Provider is an L2Provider. Will coerce type if true

    example

    if (isL2Provider(provider)) { // typescript now knows it is of type L2Provider const gasPrice = await provider.estimateL2GasPrice(tx) }

    Type Parameters

    • TProvider extends Provider<TProvider>

    Parameters

    • provider: TProvider

      The provider to check

    Returns provider is L2Provider<TProvider>

    Boolean

  • makeMerkleTreeProof(leaves: string[], index: number): string[]
  • Generates a Merkle proof (using the particular scheme we use within Lib_MerkleTree).

    Parameters

    • leaves: string[]

      Leaves of the merkle tree.

    • index: number

      Index to generate a proof for.

    Returns string[]

    Merkle proof sibling leaves, as hex strings.

  • makeStateTrieProof(provider: JsonRpcProvider, blockNumber: number, address: string, slot: string): Promise<{ accountProof: string[]; storageProof: string[]; storageRoot: string; storageValue: BigNumber }>
  • Generates a Merkle-Patricia trie proof for a given account and storage slot.

    Parameters

    • provider: JsonRpcProvider

      RPC provider attached to an EVM-compatible chain.

    • blockNumber: number

      Block number to generate the proof at.

    • address: string

      Address to generate the proof for.

    • slot: string

      Storage slot to generate the proof for.

    Returns Promise<{ accountProof: string[]; storageProof: string[]; storageRoot: string; storageValue: BigNumber }>

    Account proof and storage proof.

  • migratedWithdrawalGasLimit(data: string, chainID: number): BigNumber
  • Compute the min gas limit for a migrated withdrawal.

    Parameters

    • data: string
    • chainID: number

    Returns BigNumber

  • omit<T, K>(obj: T, ...keys: K[]): Omit<T, K>
  • Returns a copy of the given object ({ ...obj }) with the given keys omitted.

    Type Parameters

    • T extends object

    • K extends string | number | symbol

    Parameters

    • obj: T

      Object to return with the keys omitted.

    • Rest ...keys: K[]

      Keys to omit from the returned object.

    Returns Omit<T, K>

    A copy of the given object with the given keys omitted.

  • Converts an address-like into a 0x-prefixed address string.

    Parameters

    • addr: AddressLike

      Address-like to convert into an address.

    Returns string

    Address-like as an address.

  • Converts a number-like into an ethers BigNumber.

    Parameters

    • num: NumberLike

      Number-like to convert into a BigNumber.

    Returns BigNumber

    Number-like as a BigNumber.

  • Converts a number-like into a number.

    Parameters

    • num: NumberLike

      Number-like to convert into a number.

    Returns number

    Number-like as a number.

  • Converts a ProviderLike into a Provider. Assumes that if the input is a string then it is a JSON-RPC url.

    Parameters

    • provider: ProviderLike

      ProviderLike to turn into a Provider.

    Returns Provider

    Input as a Provider.

  • Converts a SignerOrProviderLike into a Signer or a Provider. Assumes that if the input is a string then it is a JSON-RPC url.

    Parameters

    Returns Provider | Signer

    Input as a Signer or Provider.

  • Pulls a transaction hash out of a TransactionLike object.

    Parameters

    • transaction: TransactionLike

      TransactionLike to convert into a transaction hash.

    Returns string

    Transaction hash corresponding to the TransactionLike input.

Generated using TypeDoc