Skip to main content

BridgeDepositBoxMock

BridgeDepositBoxMock#

Functions#

constructor(address _bridgeAdmin, uint64 _minimumBridgingDelay, address _l1Weth, address timerAddress) (public)

Ownable bridge deposit box. Used for testing environments that don't have specific l1/l2 messaging logic.

setCrossDomainAdmin(address _bridgeAdmin) (public)

Changes the L1 administrator associated with this L2 deposit deposit box.

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

Parameters:#

  • _bridgeAdmin: address of the new L1 admin contract.
setMinimumBridgingDelay(uint64 _minimumBridgingDelay) (public)

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

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

Parameters:#

  • _minimumBridgingDelay: 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 bridgeAdmin 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 bridgeAdmin 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.
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.

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.
_setBridgeAdmin(address _l1BridgeAdmin) (internal)
_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#

SetBridgeAdmin(address newBridgeAdmin)
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#

onlyBridgeAdmin()
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.