Skip to main content

OVM_OETH_BridgeDepositBox

OVM_OETH_BridgeDepositBox#

Modified version of OVM_BridgeDepositBox that supports Optimism ETH being sent over the canonical bridge as ETH. This is re-wrapped to WETH on L2. All other functionality remains the same.

Functions#

constructor(address _crossDomainAdmin, uint64 _minimumBridgingDelay, uint256 _chainId, address _l1Weth, address _l2Eth, address _l1EthWrapper, address timerAddress) (public)

Construct the Optimism Bridge Deposit Box

Parameters:#

  • _crossDomainAdmin: Address of the L1 contract that can call admin functions on this contract from L1.
  • _minimumBridgingDelay: Minimum second that must elapse between L2->L1 token transfer to prevent dos.
  • _chainId: L2 Chain identifier this deposit box is deployed on.
  • _l1Weth: Address of Weth on L1. Used to inform if a bridging action should wrap ETH to WETH, if the desired asset-to-bridge is for a whitelisted token mapped to this L1 Weth token.
  • _l2Eth: Address of ETH on L2. If someone wants to bridge L2 Weth from this contract to L1, then L2 ETH should be sent over the Optimism bridge.
  • _l1EthWrapper: Address of custom ETH wrapper on L1. Any ETH sent to this contract will be wrapped to WETH and sent to the WETH Bridge Pool.
  • timerAddress: Timer used to synchronize contract time in testing. Set to 0x000... in production.
bridgeTokens(address l2Token, uint32 l1Gas) (public)

Called by relayer (or any other EOA) to move a batch of funds from the deposit box, through the canonical token bridge, to the L1 Withdraw box. Implementation is exactly the same as the standard OVM_BridgeDepositBox except constructed to work with Optimism ETH by first unwrapping WETH then bridging OETH. The target on L1 is not the bridgePool but to the l1EthWrapper that takes any ETH sent to it, wraps it and sends to the BridgePool.

The frequency that this function can be called is rate limited by the minimumBridgingDelay to prevent spam on L1 as the finalization of a L2->L1 tx is quite expensive.

Parameters:#

  • l2Token: L2 token to relay over the canonical bridge.
  • l1Gas: Unused by optimism, but included for potential forward compatibility considerations.
receive() (external)
fallback() (external)
setCrossDomainAdmin(address newCrossDomainAdmin) (public)

Changes the L1 contract that can trigger admin functions on this L2 deposit deposit box.

This should be set to the address of the L1 contract that ultimately relays a cross-domain message, which is expected to be the Optimism_Messenger. Only callable by the existing admin via the Optimism cross domain messenger.

Parameters:#

  • newCrossDomainAdmin: address of the new L1 admin contract.
setMinimumBridgingDelay(uint64 newMinimumBridgingDelay) (public)

Changes the minimum time in seconds that must elapse between withdraws from L2->L1.

Only callable by the existing crossDomainAdmin via the optimism cross domain messenger.

Parameters:#

  • newMinimumBridgingDelay: the new minimum delay.
whitelistToken(address l1Token, address l2Token, address l1BridgePool) (public)

Enables L1 owner to whitelist a L1 Token <-> L2 Token pair for bridging.

Only callable by the existing crossDomainAdmin via the optimism cross domain messenger.

Parameters:#

  • l1Token: Address of the canonical L1 token. This is the token users will receive on Ethereum.
  • l2Token: Address of the L2 token representation. This is the token users would deposit on optimism.
  • l1BridgePool: Address of the L1 withdrawal pool linked to this L2+L1 token.
setEnableDeposits(address l2Token, bool depositsEnabled) (public)

L1 owner can enable/disable deposits for a whitelisted token.

Only callable by the existing crossDomainAdmin via the optimism cross domain messenger.

Parameters:#

  • l2Token: address of L2 token to enable/disable deposits for.
  • depositsEnabled: bool to set if the deposit box should accept/reject deposits.
_setCrossDomainAdmin(address newCrossDomainAdmin) (internal)
getCrossDomainMessenger() โ†’ contract ICrossDomainMessenger (internal)

Gets the messenger, usually from storage. This function is exposed in case a child contract needs to override.

sendCrossDomainMessage(address _crossDomainTarget, uint32 _gasLimit, bytes _message) (internal)

q Sends a message to an account on another domain

Parameters:#

  • _crossDomainTarget: The intended recipient on the destination domain
  • _message: The data to send to the target (usually calldata to a function with onlyFromCrossDomainAccount())
  • _gasLimit: The gasLimit for the receipt of the message on the target domain.
_setMinimumBridgingDelay(uint64 newMinimumBridgingDelay) (internal)

Changes the minimum time in seconds that must elapse between withdraws from L2 -> L1.

Parameters:#

  • newMinimumBridgingDelay: the new minimum delay.
_whitelistToken(address l1Token, address l2Token, address l1BridgePool) (internal)

Enables L1 owner to whitelist a L1 Token <-> L2 Token pair for bridging.

Parameters:#

  • l1Token: Address of the canonical L1 token. This is the token users will receive on Ethereum.
  • l2Token: Address of the L2 token representation. This is the token users would deposit on optimism.
  • l1BridgePool: Address of the L1 withdrawal pool linked to this L2+L1 token.
_setEnableDeposits(address l2Token, bool depositsEnabled) (internal)

L1 owner can enable/disable deposits for a whitelisted token.

Parameters:#

  • l2Token: address of L2 token to enable/disable deposits for.
  • depositsEnabled: bool to set if the deposit box should accept/reject deposits.
deposit(address l1Recipient, address l2Token, uint256 amount, uint64 slowRelayFeePct, uint64 instantRelayFeePct, uint64 quoteTimestamp) (public)

Called by L2 user to bridge funds between L2 and L1.

Emits the FundsDeposited event which relayers listen for as part of the bridging action. The caller must first approve this contract to spend amount of l2Token.

Parameters:#

  • l1Recipient: L1 address that should receive the tokens.
  • l2Token: L2 token to deposit.
  • amount: How many L2 tokens should be deposited.
  • slowRelayFeePct: Max fraction of amount that the depositor is willing to pay as a slow relay fee.
  • instantRelayFeePct: Fraction of amount that the depositor is willing to pay as an instant relay fee.
  • quoteTimestamp: Timestamp, at which the depositor will be quoted for L1 liquidity. This enables the depositor to know the L1 fees before submitting their deposit. Must be within 10 mins of the current time.
isWhitelistToken(address l2Token) โ†’ bool (public)

Checks if a given L2 token is whitelisted.

Check the whitelisted token's lastBridgeTime parameter since its guaranteed to be != 0 once the token has been whitelisted.

Parameters:#

  • l2Token: L2 token to check against the whitelist.
_hasEnoughTimeElapsedToBridge(address l2Token) โ†’ bool (internal)
canBridge(address l2Token) โ†’ bool (public)

Designed to be called by implementing contract in bridgeTokens method which sends this contract's balance of tokens from L2 to L1 via the canonical token bridge. Tokens that can be bridged are whitelisted and have had enough time elapsed since the latest bridge (or the time at which at was whitelisted).

This function is also public for caller convenience.

Parameters:#

  • l2Token: L2 token to check bridging status.
_preEntranceCheck() (internal)
_preEntranceSet() (internal)
_postEntranceReset() (internal)
setCurrentTime(uint256 time) (external)

Sets the current time.

Will revert if not running in test mode.

Parameters:#

  • time: timestamp to set current Testable time to.
getCurrentTime() โ†’ uint256 (public)

Gets the current time. Will return the last time set in setCurrentTime if running in test mode. Otherwise, it will return the block timestamp.

Events#

SetXDomainAdmin(address newAdmin)
SetMinimumBridgingDelay(uint64 newMinimumBridgingDelay)
WhitelistToken(address l1Token, address l2Token, uint64 lastBridgeTime, address bridgePool)
DepositsEnabled(address l2Token, bool depositsEnabled)
FundsDeposited(uint256 chainId, uint256 depositId, address l1Recipient, address l2Sender, address l1Token, address l2Token, uint256 amount, uint64 slowRelayFeePct, uint64 instantRelayFeePct, uint64 quoteTimestamp)
TokensBridged(address l2Token, uint256 numberOfTokensBridged, uint256 l1Gas, address caller)

Modifiers#

onlyFromCrossDomainAccount(address _sourceDomainAccount)

Enforces that the modified function is only callable by a specific cross-domain account.

Parameters:

  • _sourceDomainAccount: The only account on the originating domain which is authenticated to call this function.
onlyIfDepositsEnabled(address l2Token)
nonReentrant()

Prevents a contract from calling itself, directly or indirectly. Calling a nonReentrant function from another nonReentrant function is not supported. It is possible to prevent this from happening by making the nonReentrant function external, and making it call a private function that does the actual state modification.

nonReentrantView()

Designed to prevent a view-only method from being re-entered during a call to a nonReentrant() state-changing method.

onlyIfTest()

Reverts if not running in test mode.