Skip to main content

BridgeDepositBox

BridgeDepositBox#

Accepts deposits on Optimism L2 to relay to Ethereum L1 as part of the UMA insured bridge system.

Functions#

constructor(uint64 _minimumBridgingDelay, uint256 _chainId, address _l1Weth, address timerAddress) (internal)

Construct the Bridge Deposit Box

Parameters:#

  • _minimumBridgingDelay: Minimum seconds that must elapse between L2 -> L1 token transfer to prevent dos.
  • _chainId: Chain identifier for the Bridge deposit box.
  • _l1Weth: Address of Weth on L1. Used to inform if the deposit should wrap ETH to WETH, if deposit is ETH.
  • timerAddress: Timer used to synchronize contract time in testing. Set to 0x000... in production.
_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.
bridgeTokens(address l2Token, uint32 l2Gas) (public)
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#

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#

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.