Skip to main content

AVM_BridgeDepositBox

AVM_BridgeDepositBox#

AVM specific bridge deposit box.

Uses AVM cross-domain-enabled logic for access control.

Functions#

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

Construct the Arbitrum Bridge Deposit Box

Parameters:#

  • _l2GatewayRouter: Address of the Arbitrum L2 token gateway router for sending tokens from L2->L1.
  • _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 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.
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 Arbitrum_Messenger. Only callable by the existing crossDomainAdmin via the Arbitrum 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 Arbitrum 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 Arbitrum 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 Arbitrum.
  • 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 Arbitrum 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 Arbitrum, but included for potential forward compatibility considerations.
_setCrossDomainAdmin(address newCrossDomainAdmin) (internal)
applyL1ToL2Alias(address l1Address) โ†’ address l2Address (internal)
sendCrossDomainMessage(address user, address to, bytes data) โ†’ uint256 (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#

SetXDomainAdmin(address newAdmin)
SentCrossDomainMessage(address from, address to, uint256 id, bytes data)
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 l1Counterpart)
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.