Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface ICrossChainMessenger

Handles L1/L2 interactions.

Hierarchy

  • ICrossChainMessenger

Implemented by

Index

Properties

List of custom bridges for the given network.

contracts: OEContracts

Contract objects attached to their respective providers and addresses.

depositConfirmationBlocks: number

Number of blocks before a deposit is considered confirmed.

estimateGas: { approveERC20: any; depositERC20: any; depositETH: any; finalizeMessage: any; resendMessage: any; sendMessage: any; withdrawERC20: any; withdrawETH: any }

Object that holds the functions that estimates the gas required for a given transaction. Follows the pattern used by ethers.js.

Type declaration

  • approveERC20:function
    • Estimates gas required to approve some tokens to deposit into the L2 chain.

      Parameters

      • l1Token: AddressLike

        The L1 token address.

      • l2Token: AddressLike

        The L2 token address.

      • amount: NumberLike

        Amount of the token to approve.

      • Optional opts: { overrides?: CallOverrides }

        Additional options.

        • Optional overrides?: CallOverrides

          Optional transaction overrides.

      Returns Promise<BigNumber>

      Transaction response for the approval transaction.

  • depositERC20:function
    • Estimates gas required to deposit some ERC20 tokens into the L2 chain.

      Parameters

      • l1Token: AddressLike

        Address of the L1 token.

      • l2Token: AddressLike

        Address of the L2 token.

      • amount: NumberLike

        Amount to deposit.

      • Optional opts: { l2GasLimit?: NumberLike; overrides?: CallOverrides; recipient?: AddressLike }

        Additional options.

        • Optional l2GasLimit?: NumberLike

          Optional gas limit to use for the transaction on L2.

        • Optional overrides?: CallOverrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L2. Defaults to sender.

      Returns Promise<BigNumber>

      Gas estimate for the transaction.

  • depositETH:function
    • Estimates gas required to deposit some ETH into the L2 chain.

      Parameters

      • amount: NumberLike

        Amount of ETH to deposit.

      • Optional opts: { l2GasLimit?: NumberLike; overrides?: CallOverrides; recipient?: AddressLike }

        Additional options.

        • Optional l2GasLimit?: NumberLike

          Optional gas limit to use for the transaction on L2.

        • Optional overrides?: CallOverrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L2. Defaults to sender.

      Returns Promise<BigNumber>

      Gas estimate for the transaction.

  • finalizeMessage:function
    • finalizeMessage(message: MessageLike, opts?: { overrides?: CallOverrides }): Promise<BigNumber>
    • Estimates gas required to finalize a cross chain message. Only applies to L2 to L1 messages.

      Parameters

      • message: MessageLike

        Message to generate the finalization transaction for.

      • Optional opts: { overrides?: CallOverrides }

        Additional options.

        • Optional overrides?: CallOverrides

          Optional transaction overrides.

      Returns Promise<BigNumber>

      Gas estimate for the transaction.

  • resendMessage:function
    • resendMessage(message: MessageLike, messageGasLimit: NumberLike, opts?: { overrides?: CallOverrides }): Promise<BigNumber>
    • Estimates gas required to resend a cross chain message. Only applies to L1 to L2 messages.

      Parameters

      • message: MessageLike

        Cross chain message to resend.

      • messageGasLimit: NumberLike

        New gas limit to use for the message.

      • Optional opts: { overrides?: CallOverrides }

        Additional options.

        • Optional overrides?: CallOverrides

          Optional transaction overrides.

      Returns Promise<BigNumber>

      Gas estimate for the transaction.

  • sendMessage:function
  • withdrawERC20:function
    • Estimates gas required to withdraw some ERC20 tokens back to the L1 chain.

      Parameters

      • l1Token: AddressLike

        Address of the L1 token.

      • l2Token: AddressLike

        Address of the L2 token.

      • amount: NumberLike

        Amount to withdraw.

      • Optional opts: { overrides?: CallOverrides; recipient?: AddressLike }

        Additional options.

        • Optional overrides?: CallOverrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L1. Defaults to sender.

      Returns Promise<BigNumber>

      Gas estimate for the transaction.

  • withdrawETH:function
    • withdrawETH(amount: NumberLike, opts?: { overrides?: CallOverrides; recipient?: AddressLike }): Promise<BigNumber>
    • Estimates gas required to withdraw some ETH back to the L1 chain.

      Parameters

      • amount: NumberLike

        Amount of ETH to withdraw.

      • Optional opts: { overrides?: CallOverrides; recipient?: AddressLike }

        Additional options.

        • Optional overrides?: CallOverrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L1. Defaults to sender.

      Returns Promise<BigNumber>

      Gas estimate for the transaction.

l1BlockTimeSeconds: number

Estimated average L1 block time in seconds.

l1ChainId: number

Chain ID for the L1 network.

l1Provider: Provider

Provider connected to the L1 chain.

l1Signer: Signer

Signer connected to the L1 chain.

l1SignerOrProvider: Signer | Provider

Provider connected to the L1 chain.

l2ChainId: number

Chain ID for the L2 network.

l2Provider: Provider

Provider connected to the L2 chain.

l2Signer: Signer

Signer connected to the L2 chain.

l2SignerOrProvider: Signer | Provider

Provider connected to the L2 chain.

populateTransaction: { approveERC20: any; depositERC20: any; depositETH: any; finalizeMessage: any; resendMessage: any; sendMessage: any; withdrawERC20: any; withdrawETH: any }

Object that holds the functions that generate transactions to be signed by the user. Follows the pattern used by ethers.js.

Type declaration

  • approveERC20:function
    • Generates a transaction for approving some tokens to deposit into the L2 chain.

      Parameters

      • l1Token: AddressLike

        The L1 token address.

      • l2Token: AddressLike

        The L2 token address.

      • amount: NumberLike

        Amount of the token to approve.

      • Optional opts: { overrides?: Overrides }

        Additional options.

        • Optional overrides?: Overrides

          Optional transaction overrides.

      Returns Promise<TransactionRequest>

      Transaction response for the approval transaction.

  • depositERC20:function
    • Generates a transaction for depositing some ERC20 tokens into the L2 chain.

      Parameters

      • l1Token: AddressLike

        Address of the L1 token.

      • l2Token: AddressLike

        Address of the L2 token.

      • amount: NumberLike

        Amount to deposit.

      • Optional opts: { l2GasLimit?: NumberLike; overrides?: Overrides; recipient?: AddressLike }

        Additional options.

        • Optional l2GasLimit?: NumberLike

          Optional gas limit to use for the transaction on L2.

        • Optional overrides?: Overrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L2. Defaults to sender.

      Returns Promise<TransactionRequest>

      Transaction that can be signed and executed to deposit the tokens.

  • depositETH:function
    • Generates a transaction for depositing some ETH into the L2 chain.

      Parameters

      • amount: NumberLike

        Amount of ETH to deposit.

      • Optional opts: { l2GasLimit?: NumberLike; overrides?: Overrides; recipient?: AddressLike }

        Additional options.

        • Optional l2GasLimit?: NumberLike

          Optional gas limit to use for the transaction on L2.

        • Optional overrides?: Overrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L2. Defaults to sender.

      Returns Promise<TransactionRequest>

      Transaction that can be signed and executed to deposit the ETH.

  • finalizeMessage:function
    • finalizeMessage(message: MessageLike, opts?: { overrides?: Overrides }): Promise<TransactionRequest>
    • Generates a message finalization transaction that can be signed and executed. Only applicable for L2 to L1 messages. Will throw an error if the message has not completed its challenge period yet.

      Parameters

      • message: MessageLike

        Message to generate the finalization transaction for.

      • Optional opts: { overrides?: Overrides }

        Additional options.

        • Optional overrides?: Overrides

          Optional transaction overrides.

      Returns Promise<TransactionRequest>

      Transaction that can be signed and executed to finalize the message.

  • resendMessage:function
    • resendMessage(message: MessageLike, messageGasLimit: NumberLike, opts?: { overrides?: Overrides }): Promise<TransactionRequest>
    • Generates a transaction that resends a given cross chain message. Only applies to L1 to L2 messages. This transaction can be signed and executed by a signer.

      Parameters

      • message: MessageLike

        Cross chain message to resend.

      • messageGasLimit: NumberLike

        New gas limit to use for the message.

      • Optional opts: { overrides?: Overrides }

        Additional options.

        • Optional overrides?: Overrides

          Optional transaction overrides.

      Returns Promise<TransactionRequest>

      Transaction that can be signed and executed to resend the message.

  • sendMessage:function
    • Generates a transaction that sends a given cross chain message. This transaction can be signed and executed by a signer.

      Parameters

      • message: CrossChainMessageRequest

        Cross chain message to send.

      • Optional opts: { l2GasLimit?: NumberLike; overrides?: Overrides }

        Additional options.

        • Optional l2GasLimit?: NumberLike

          Optional gas limit to use for the transaction on L2.

        • Optional overrides?: Overrides

          Optional transaction overrides.

      Returns Promise<TransactionRequest>

      Transaction that can be signed and executed to send the message.

  • withdrawERC20:function
    • Generates a transaction for withdrawing some ERC20 tokens back to the L1 chain.

      Parameters

      • l1Token: AddressLike

        Address of the L1 token.

      • l2Token: AddressLike

        Address of the L2 token.

      • amount: NumberLike

        Amount to withdraw.

      • Optional opts: { overrides?: Overrides; recipient?: AddressLike }

        Additional options.

        • Optional overrides?: Overrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L1. Defaults to sender.

      Returns Promise<TransactionRequest>

      Transaction that can be signed and executed to withdraw the tokens.

  • withdrawETH:function
    • withdrawETH(amount: NumberLike, opts?: { overrides?: Overrides; recipient?: AddressLike }): Promise<TransactionRequest>
    • Generates a transaction for withdrawing some ETH back to the L1 chain.

      Parameters

      • amount: NumberLike

        Amount of ETH to withdraw.

      • Optional opts: { overrides?: Overrides; recipient?: AddressLike }

        Additional options.

        • Optional overrides?: Overrides

          Optional transaction overrides.

        • Optional recipient?: AddressLike

          Optional address to receive the funds on L1. Defaults to sender.

      Returns Promise<TransactionRequest>

      Transaction that can be signed and executed to withdraw the ETH.

Methods

  • Queries the account's approval amount for a given L1 token.

    Parameters

    • l1Token: AddressLike

      The L1 token address.

    • l2Token: AddressLike

      The L2 token address.

    • Optional opts: { signer?: Signer }

      Additional options.

      • Optional signer?: Signer

        Optional signer to get the approval for.

    Returns Promise<BigNumber>

    Amount of tokens approved for deposits from the account.

  • Approves a deposit into the L2 chain.

    Parameters

    • l1Token: AddressLike

      The L1 token address.

    • l2Token: AddressLike

      The L2 token address.

    • amount: NumberLike

      Amount of the token to approve.

    • Optional opts: { overrides?: Overrides; signer?: Signer }

      Additional options.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the approval transaction.

  • Deposits some ERC20 tokens into the L2 chain.

    Parameters

    • l1Token: AddressLike

      Address of the L1 token.

    • l2Token: AddressLike

      Address of the L2 token.

    • amount: NumberLike

      Amount to deposit.

    • Optional opts: { l2GasLimit?: NumberLike; overrides?: Overrides; recipient?: AddressLike; signer?: Signer }

      Additional options.

      • Optional l2GasLimit?: NumberLike

        Optional gas limit to use for the transaction on L2.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional recipient?: AddressLike

        Optional address to receive the funds on L2. Defaults to sender.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the deposit transaction.

  • depositETH(amount: NumberLike, opts?: { l2GasLimit?: NumberLike; overrides?: Overrides; recipient?: AddressLike; signer?: Signer }): Promise<TransactionResponse>
  • Deposits some ETH into the L2 chain.

    Parameters

    • amount: NumberLike

      Amount of ETH to deposit (in wei).

    • Optional opts: { l2GasLimit?: NumberLike; overrides?: Overrides; recipient?: AddressLike; signer?: Signer }

      Additional options.

      • Optional l2GasLimit?: NumberLike

        Optional gas limit to use for the transaction on L2.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional recipient?: AddressLike

        Optional address to receive the funds on L2. Defaults to sender.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the deposit transaction.

  • estimateL2MessageGasLimit(message: MessageRequestLike, opts?: { bufferPercent?: number; from?: string }): Promise<BigNumber>
  • Estimates the amount of gas required to fully execute a given message on L2. Only applies to L1 => L2 messages. You would supply this gas limit when sending the message to L2.

    Parameters

    • message: MessageRequestLike

      Message get a gas estimate for.

    • Optional opts: { bufferPercent?: number; from?: string }

      Options object.

      • Optional bufferPercent?: number

        Percentage of gas to add to the estimate. Defaults to 20.

      • Optional from?: string

        Address to use as the sender.

    Returns Promise<BigNumber>

    Estimates L2 gas limit.

  • estimateMessageWaitTimeSeconds(message: MessageLike): Promise<number>
  • Returns the estimated amount of time before the message can be executed. When this is a message being sent to L1, this will return the estimated time until the message will complete its challenge period. When this is a message being sent to L2, this will return the estimated amount of time until the message will be picked up and executed on L2.

    Parameters

    • message: MessageLike

      Message to estimate the time remaining for.

    Returns Promise<number>

    Estimated amount of time remaining (in seconds) before the message can be executed.

  • finalizeMessage(message: MessageLike, opts?: { overrides?: Overrides; signer?: Signer }): Promise<TransactionResponse>
  • Finalizes a cross chain message that was sent from L2 to L1. Only applicable for L2 to L1 messages. Will throw an error if the message has not completed its challenge period yet.

    Parameters

    • message: MessageLike

      Message to finalize.

    • Optional opts: { overrides?: Overrides; signer?: Signer }

      Additional options.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the finalization transaction.

  • getChallengePeriodSeconds(): Promise<number>
  • Gets all deposits for a given address.

    Parameters

    • address: AddressLike

      Address to search for messages from.

    • Optional opts: { fromBlock?: BlockTag; toBlock?: BlockTag }

      Options object.

      • Optional fromBlock?: BlockTag

        Block to start searching for messages from. If not provided, will start from the first block (block #0).

      • Optional toBlock?: BlockTag

        Block to stop searching for messages at. If not provided, will stop at the latest known block ("latest").

    Returns Promise<TokenBridgeMessage[]>

    All deposit token bridge messages sent by the given address.

  • Returns the state root that corresponds to a given message. This is the state root for the block in which the transaction was included, as published to the StateCommitmentChain. If the state root for the given message has not been published yet, this function returns null.

    Parameters

    • message: MessageLike

      Message to find a state root for.

    Returns Promise<StateRoot>

    State root for the block in which the message was created.

  • Retrieves all cross chain messages sent within a given transaction.

    Parameters

    • transaction: TransactionLike

      Transaction hash or receipt to find messages from.

    • Optional opts: { direction?: MessageDirection }

      Options object.

      • Optional direction?: MessageDirection

        Direction to search for messages in. If not provided, will attempt to automatically search both directions under the assumption that a transaction hash will only exist on one chain. If the hash exists on both chains, will throw an error.

    Returns Promise<CrossChainMessage[]>

    All cross chain messages sent within the transaction.

  • getStateBatchAppendedEventByBatchIndex(batchIndex: number): Promise<Event>
  • Returns the StateBatchAppended event that was emitted when the batch with a given index was created. Returns null if no such event exists (the batch has not been submitted).

    Parameters

    • batchIndex: number

      Index of the batch to find an event for.

    Returns Promise<Event>

    StateBatchAppended event for the batch, or null if no such batch exists.

  • getStateBatchAppendedEventByTransactionIndex(transactionIndex: number): Promise<Event>
  • Returns the StateBatchAppended event for the batch that includes the transaction with the given index. Returns null if no such event exists.

    Parameters

    • transactionIndex: number

      Index of the L2 transaction to find an event for.

    Returns Promise<Event>

    StateBatchAppended event for the batch that includes the given transaction by index.

  • getStateRootBatchByTransactionIndex(transactionIndex: number): Promise<StateRootBatch>
  • Returns information about the state root batch that included the state root for the given transaction by index. Returns null if no such state root has been published yet.

    Parameters

    • transactionIndex: number

      Index of the L2 transaction to find a state root batch for.

    Returns Promise<StateRootBatch>

    State root batch for the given transaction index, or null if none exists yet.

  • Gets all withdrawals for a given address.

    Parameters

    • address: AddressLike

      Address to search for messages from.

    • Optional opts: { fromBlock?: BlockTag; toBlock?: BlockTag }

      Options object.

      • Optional fromBlock?: BlockTag

        Block to start searching for messages from. If not provided, will start from the first block (block #0).

      • Optional toBlock?: BlockTag

        Block to stop searching for messages at. If not provided, will stop at the latest known block ("latest").

    Returns Promise<TokenBridgeMessage[]>

    All withdrawal token bridge messages sent by the given address.

  • resendMessage(message: MessageLike, messageGasLimit: NumberLike, opts?: { overrides?: Overrides; signer?: Signer }): Promise<TransactionResponse>
  • Resends a given cross chain message with a different gas limit. Only applies to L1 to L2 messages. If provided an L2 to L1 message, this function will throw an error.

    Parameters

    • message: MessageLike

      Cross chain message to resend.

    • messageGasLimit: NumberLike

      New gas limit to use for the message.

    • Optional opts: { overrides?: Overrides; signer?: Signer }

      Additional options.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the message resending transaction.

  • Sends a given cross chain message. Where the message is sent depends on the direction attached to the message itself.

    Parameters

    • message: CrossChainMessageRequest

      Cross chain message to send.

    • Optional opts: { l2GasLimit?: NumberLike; overrides?: Overrides; signer?: Signer }

      Additional options.

      • Optional l2GasLimit?: NumberLike

        Optional gas limit to use for the transaction on L2.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the message sending transaction.

  • Resolves a MessageLike into a CrossChainMessage object. Unlike other coercion functions, this function is stateful and requires making additional requests. For now I'm going to keep this function here, but we could consider putting a similar function inside of utils/coercion.ts if people want to use this without having to create an entire CrossChainProvider object.

    Parameters

    • message: MessageLike

      MessageLike to resolve into a CrossChainMessage.

    Returns Promise<CrossChainMessage>

    Message coerced into a CrossChainMessage.

  • waitForMessageReceipt(message: MessageLike, opts?: { confirmations?: number; pollIntervalMs?: number; timeoutMs?: number }): Promise<MessageReceipt>
  • Waits for a message to be executed and returns the receipt of the transaction that executed the given message.

    Parameters

    • message: MessageLike

      Message to wait for.

    • Optional opts: { confirmations?: number; pollIntervalMs?: number; timeoutMs?: number }

      Options to pass to the waiting function.

      • Optional confirmations?: number

        Number of transaction confirmations to wait for before returning.

      • Optional pollIntervalMs?: number

        Number of milliseconds to wait between polling for the receipt.

      • Optional timeoutMs?: number

        Milliseconds to wait before timing out.

    Returns Promise<MessageReceipt>

    CrossChainMessage receipt including receipt of the transaction that relayed the given message.

  • waitForMessageStatus(message: MessageLike, status: MessageStatus, opts?: { pollIntervalMs?: number; timeoutMs?: number }): Promise<void>
  • Waits until the status of a given message changes to the expected status. Note that if the status of the given message changes to a status that implies the expected status, this will still return. If the status of the message changes to a status that exclues the expected status, this will throw an error.

    Parameters

    • message: MessageLike

      Message to wait for.

    • status: MessageStatus

      Expected status of the message.

    • Optional opts: { pollIntervalMs?: number; timeoutMs?: number }

      Options to pass to the waiting function.

      • Optional pollIntervalMs?: number

        Number of milliseconds to wait when polling.

      • Optional timeoutMs?: number

        Milliseconds to wait before timing out.

    Returns Promise<void>

  • Withdraws some ERC20 tokens back to the L1 chain.

    Parameters

    • l1Token: AddressLike

      Address of the L1 token.

    • l2Token: AddressLike

      Address of the L2 token.

    • amount: NumberLike

      Amount to withdraw.

    • Optional opts: { overrides?: Overrides; recipient?: AddressLike; signer?: Signer }

      Additional options.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional recipient?: AddressLike

        Optional address to receive the funds on L1. Defaults to sender.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the withdraw transaction.

  • withdrawETH(amount: NumberLike, opts?: { overrides?: Overrides; recipient?: AddressLike; signer?: Signer }): Promise<TransactionResponse>
  • Withdraws some ETH back to the L1 chain.

    Parameters

    • amount: NumberLike

      Amount of ETH to withdraw.

    • Optional opts: { overrides?: Overrides; recipient?: AddressLike; signer?: Signer }

      Additional options.

      • Optional overrides?: Overrides

        Optional transaction overrides.

      • Optional recipient?: AddressLike

        Optional address to receive the funds on L1. Defaults to sender.

      • Optional signer?: Signer

        Optional signer to use to send the transaction.

    Returns Promise<TransactionResponse>

    Transaction response for the withdraw transaction.

Generated using TypeDoc