Skip to content

Commit

Permalink
Add LM Optimism L1 to L2 bridge interface (#840)
Browse files Browse the repository at this point in the history
This PR adds the Optimism bridge interface for L1 to L2 transfers. Some
important things to note:
- The Optimism L1 bridge adapter increments a nonce with each transfer
and each time `sendERC20` is called. This nonce is included in multiple
events throughout the transfer's lifecycle and is how we "match" and
link events together to confirm they've reached the various states.
- The `GetTransfers()` function makes use of this nonce and implements
the matching logic to link these 3 events together and partition
transfers into categories:
- L1's LiquidityManager `LiquidityTransferred.bridgeReturnData`, which
should equal
- OP's StandardBridge event `ERC20BridgeFinalized.extraData` which
should equal
  - L2's LiquidityManager `LiquidityTransferred.bridgeSpecificData`
- See the `TODO: Applying the 1.2x gas...` comment on how we should
think about adjusting the gas limit appropriately to account for how
OP's native bridge dynamically burns gas
  • Loading branch information
ogtownsend authored Jun 24, 2024
1 parent 2b4df02 commit 3211e83
Show file tree
Hide file tree
Showing 35 changed files with 3,646 additions and 226 deletions.
2 changes: 2 additions & 0 deletions contracts/scripts/native_solc_compile_all_liquiditymanager
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ compileContract liquiditymanager/interfaces/optimism/IOptimismL2ToL1MessagePasse
compileContract liquiditymanager/interfaces/optimism/IOptimismCrossDomainMessenger.sol
compileContract liquiditymanager/interfaces/optimism/IOptimismPortal2.sol
compileContract liquiditymanager/interfaces/optimism/IOptimismDisputeGameFactory.sol
compileContract liquiditymanager/interfaces/optimism/IOptimismStandardBridge.sol
compileContract liquiditymanager/interfaces/optimism/IOptimismL1StandardBridge.sol
compileContract liquiditymanager/encoders/OptimismL1BridgeAdapterEncoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,22 @@ interface IOptimismCrossDomainMessenger {
/// @param messageNonce Unique nonce attached to the message.
/// @param gasLimit Minimum gas limit that the message can be executed with.
event SentMessage(address indexed target, address sender, bytes message, uint256 messageNonce, uint256 gasLimit);

/// @notice Relays a message that was sent by the other CrossDomainMessenger contract. Can only
/// be executed via cross-chain call from the other messenger OR if the message was
/// already received once and is currently being replayed.
/// @param _nonce Nonce of the message being relayed.
/// @param _sender Address of the user who sent the message.
/// @param _target Address that the message is targeted at.
/// @param _value ETH value to send with the message.
/// @param _minGasLimit Minimum amount of gas that the message can be executed with.
/// @param _message Message to send to the target.
function relayMessage(
uint256 _nonce,
address _sender,
address _target,
uint256 _value,
uint256 _minGasLimit,
bytes calldata _message
) external payable;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
// Copied from https://github.com/ethereum-optimism/optimism/blob/f707883038d527cbf1e9f8ea513fe33255deadbc/packages/contracts-bedrock/src/L1/L1StandardBridge.sol
pragma solidity ^0.8.0;

interface IOptimismL1StandardBridge {
/// @custom:legacy
/// @notice Deposits some amount of ETH into a target account on L2.
/// Note that if ETH is sent to a contract on L2 and the call fails, then that ETH will
/// be locked in the L2StandardBridge. ETH may be recoverable if the call can be
/// successfully replayed by increasing the amount of gas supplied to the call. If the
/// call will fail for any amount of gas, then the ETH will be locked permanently.
/// @param _to Address of the recipient on L2.
/// @param _minGasLimit Minimum gas limit for the deposit message on L2.
/// @param _extraData Optional data to forward to L2.
/// Data supplied here will not be used to execute any code on L2 and is
/// only emitted as extra data for the convenience of off-chain tooling.
function depositETHTo(address _to, uint32 _minGasLimit, bytes calldata _extraData) external payable;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
// Copied from https://github.com/ethereum-optimism/optimism/blob/f707883038d527cbf1e9f8ea513fe33255deadbc/packages/contracts-bedrock/src/universal/StandardBridge.sol#L88
pragma solidity ^0.8.0;

interface IOptimismStandardBridge {
/// @notice Emitted when an ERC20 bridge is finalized on this chain.
/// @param localToken Address of the ERC20 on this chain.
/// @param remoteToken Address of the ERC20 on the remote chain.
/// @param from Address of the sender.
/// @param to Address of the receiver.
/// @param amount Amount of the ERC20 sent.
/// @param extraData Extra data sent with the transaction.
event ERC20BridgeFinalized(
address indexed localToken,
address indexed remoteToken,
address indexed from,
address to,
uint256 amount,
bytes extraData
);

/// @notice Finalizes an ERC20 bridge on this chain. Can only be triggered by the other
/// StandardBridge contract on the remote chain.
/// @param _localToken Address of the ERC20 on this chain.
/// @param _remoteToken Address of the corresponding token on the remote chain.
/// @param _from Address of the sender.
/// @param _to Address of the receiver.
/// @param _amount Amount of the ERC20 being bridged.
/// @param _extraData Extra data to be sent with the transaction. Note that the recipient will
/// not be triggered with this data, but it will be emitted and can be used
/// to identify the transaction.
function finalizeBridgeERC20(
address _localToken,
address _remoteToken,
address _from,
address _to,
uint256 _amount,
bytes calldata _extraData
) external;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3211e83

Please sign in to comment.