Commit 30b8f83d authored by Maurelian's avatar Maurelian

feat(ctb): forge fmt

parent 938b1a3a
...@@ -19,10 +19,7 @@ contract L1CrossDomainMessenger is CrossDomainMessenger, Semver { ...@@ -19,10 +19,7 @@ contract L1CrossDomainMessenger is CrossDomainMessenger, Semver {
/// @custom:semver 1.4.1 /// @custom:semver 1.4.1
/// @notice Constructs the L1CrossDomainMessenger contract. /// @notice Constructs the L1CrossDomainMessenger contract.
/// @param _portal Address of the OptimismPortal contract on this network. /// @param _portal Address of the OptimismPortal contract on this network.
constructor(OptimismPortal _portal) constructor(OptimismPortal _portal) Semver(1, 4, 1) CrossDomainMessenger(Predeploys.L2_CROSS_DOMAIN_MESSENGER) {
Semver(1, 4, 1)
CrossDomainMessenger(Predeploys.L2_CROSS_DOMAIN_MESSENGER)
{
PORTAL = _portal; PORTAL = _portal;
initialize(); initialize();
} }
...@@ -33,12 +30,7 @@ contract L1CrossDomainMessenger is CrossDomainMessenger, Semver { ...@@ -33,12 +30,7 @@ contract L1CrossDomainMessenger is CrossDomainMessenger, Semver {
} }
/// @inheritdoc CrossDomainMessenger /// @inheritdoc CrossDomainMessenger
function _sendMessage( function _sendMessage(address _to, uint64 _gasLimit, uint256 _value, bytes memory _data) internal override {
address _to,
uint64 _gasLimit,
uint256 _value,
bytes memory _data
) internal override {
PORTAL.depositTransaction{ value: _value }(_to, _value, _gasLimit, false, _data); PORTAL.depositTransaction{ value: _value }(_to, _value, _gasLimit, false, _data);
} }
......
...@@ -22,10 +22,7 @@ contract L1ERC721Bridge is ERC721Bridge, Semver { ...@@ -22,10 +22,7 @@ contract L1ERC721Bridge is ERC721Bridge, Semver {
/// @notice Constructs the L1ERC721Bridge contract. /// @notice Constructs the L1ERC721Bridge contract.
/// @param _messenger Address of the CrossDomainMessenger on this network. /// @param _messenger Address of the CrossDomainMessenger on this network.
/// @param _otherBridge Address of the ERC721 bridge on the other network. /// @param _otherBridge Address of the ERC721 bridge on the other network.
constructor(address _messenger, address _otherBridge) constructor(address _messenger, address _otherBridge) Semver(1, 1, 2) ERC721Bridge(_messenger, _otherBridge) { }
Semver(1, 1, 2)
ERC721Bridge(_messenger, _otherBridge)
{}
/// @notice Completes an ERC721 bridge from the other domain and sends the ERC721 token to the /// @notice Completes an ERC721 bridge from the other domain and sends the ERC721 token to the
/// recipient on this domain. /// recipient on this domain.
...@@ -44,7 +41,10 @@ contract L1ERC721Bridge is ERC721Bridge, Semver { ...@@ -44,7 +41,10 @@ contract L1ERC721Bridge is ERC721Bridge, Semver {
address _to, address _to,
uint256 _tokenId, uint256 _tokenId,
bytes calldata _extraData bytes calldata _extraData
) external onlyOtherBridge { )
external
onlyOtherBridge
{
require(_localToken != address(this), "L1ERC721Bridge: local token cannot be self"); require(_localToken != address(this), "L1ERC721Bridge: local token cannot be self");
// Checks that the L1/L2 NFT pair has a token ID that is escrowed in the L1 Bridge. // Checks that the L1/L2 NFT pair has a token ID that is escrowed in the L1 Bridge.
...@@ -74,18 +74,15 @@ contract L1ERC721Bridge is ERC721Bridge, Semver { ...@@ -74,18 +74,15 @@ contract L1ERC721Bridge is ERC721Bridge, Semver {
uint256 _tokenId, uint256 _tokenId,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) internal override { )
internal
override
{
require(_remoteToken != address(0), "L1ERC721Bridge: remote token cannot be address(0)"); require(_remoteToken != address(0), "L1ERC721Bridge: remote token cannot be address(0)");
// Construct calldata for _l2Token.finalizeBridgeERC721(_to, _tokenId) // Construct calldata for _l2Token.finalizeBridgeERC721(_to, _tokenId)
bytes memory message = abi.encodeWithSelector( bytes memory message = abi.encodeWithSelector(
L2ERC721Bridge.finalizeBridgeERC721.selector, L2ERC721Bridge.finalizeBridgeERC721.selector, _remoteToken, _localToken, _from, _to, _tokenId, _extraData
_remoteToken,
_localToken,
_from,
_to,
_tokenId,
_extraData
); );
// Lock token into bridge // Lock token into bridge
......
...@@ -24,12 +24,7 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -24,12 +24,7 @@ contract L1StandardBridge is StandardBridge, Semver {
/// @param to Address of the recipient on L2. /// @param to Address of the recipient on L2.
/// @param amount Amount of ETH deposited. /// @param amount Amount of ETH deposited.
/// @param extraData Extra data attached to the deposit. /// @param extraData Extra data attached to the deposit.
event ETHDepositInitiated( event ETHDepositInitiated(address indexed from, address indexed to, uint256 amount, bytes extraData);
address indexed from,
address indexed to,
uint256 amount,
bytes extraData
);
/// @custom:legacy /// @custom:legacy
/// @notice Emitted whenever a withdrawal of ETH from L2 to L1 is finalized. /// @notice Emitted whenever a withdrawal of ETH from L2 to L1 is finalized.
...@@ -37,12 +32,7 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -37,12 +32,7 @@ contract L1StandardBridge is StandardBridge, Semver {
/// @param to Address of the recipient on L1. /// @param to Address of the recipient on L1.
/// @param amount Amount of ETH withdrawn. /// @param amount Amount of ETH withdrawn.
/// @param extraData Extra data attached to the withdrawal. /// @param extraData Extra data attached to the withdrawal.
event ETHWithdrawalFinalized( event ETHWithdrawalFinalized(address indexed from, address indexed to, uint256 amount, bytes extraData);
address indexed from,
address indexed to,
uint256 amount,
bytes extraData
);
/// @custom:legacy /// @custom:legacy
/// @notice Emitted whenever an ERC20 deposit is initiated. /// @notice Emitted whenever an ERC20 deposit is initiated.
...@@ -84,7 +74,7 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -84,7 +74,7 @@ contract L1StandardBridge is StandardBridge, Semver {
constructor(address payable _messenger) constructor(address payable _messenger)
Semver(1, 1, 1) Semver(1, 1, 1)
StandardBridge(_messenger, payable(Predeploys.L2_STANDARD_BRIDGE)) StandardBridge(_messenger, payable(Predeploys.L2_STANDARD_BRIDGE))
{} { }
/// @notice Allows EOAs to bridge ETH by sending directly to the bridge. /// @notice Allows EOAs to bridge ETH by sending directly to the bridge.
receive() external payable override onlyEOA { receive() external payable override onlyEOA {
...@@ -112,11 +102,7 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -112,11 +102,7 @@ contract L1StandardBridge is StandardBridge, Semver {
/// @param _extraData Optional data to forward to L2. /// @param _extraData Optional data to forward to L2.
/// Data supplied here will not be used to execute any code on L2 and is /// 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. /// only emitted as extra data for the convenience of off-chain tooling.
function depositETHTo( function depositETHTo(address _to, uint32 _minGasLimit, bytes calldata _extraData) external payable {
address _to,
uint32 _minGasLimit,
bytes calldata _extraData
) external payable {
_initiateETHDeposit(msg.sender, _to, _minGasLimit, _extraData); _initiateETHDeposit(msg.sender, _to, _minGasLimit, _extraData);
} }
...@@ -135,16 +121,12 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -135,16 +121,12 @@ contract L1StandardBridge is StandardBridge, Semver {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) external virtual onlyEOA { )
_initiateERC20Deposit( external
_l1Token, virtual
_l2Token, onlyEOA
msg.sender, {
msg.sender, _initiateERC20Deposit(_l1Token, _l2Token, msg.sender, msg.sender, _amount, _minGasLimit, _extraData);
_amount,
_minGasLimit,
_extraData
);
} }
/// @custom:legacy /// @custom:legacy
...@@ -164,16 +146,11 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -164,16 +146,11 @@ contract L1StandardBridge is StandardBridge, Semver {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) external virtual { )
_initiateERC20Deposit( external
_l1Token, virtual
_l2Token, {
msg.sender, _initiateERC20Deposit(_l1Token, _l2Token, msg.sender, _to, _amount, _minGasLimit, _extraData);
_to,
_amount,
_minGasLimit,
_extraData
);
} }
/// @custom:legacy /// @custom:legacy
...@@ -187,7 +164,10 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -187,7 +164,10 @@ contract L1StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes calldata _extraData bytes calldata _extraData
) external payable { )
external
payable
{
finalizeBridgeETH(_from, _to, _amount, _extraData); finalizeBridgeETH(_from, _to, _amount, _extraData);
} }
...@@ -206,7 +186,9 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -206,7 +186,9 @@ contract L1StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes calldata _extraData bytes calldata _extraData
) external { )
external
{
finalizeBridgeERC20(_l1Token, _l2Token, _from, _to, _amount, _extraData); finalizeBridgeERC20(_l1Token, _l2Token, _from, _to, _amount, _extraData);
} }
...@@ -222,12 +204,7 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -222,12 +204,7 @@ contract L1StandardBridge is StandardBridge, Semver {
/// @param _to Address of the recipient on L2. /// @param _to Address of the recipient on L2.
/// @param _minGasLimit Minimum gas limit for the deposit message on L2. /// @param _minGasLimit Minimum gas limit for the deposit message on L2.
/// @param _extraData Optional data to forward to L2. /// @param _extraData Optional data to forward to L2.
function _initiateETHDeposit( function _initiateETHDeposit(address _from, address _to, uint32 _minGasLimit, bytes memory _extraData) internal {
address _from,
address _to,
uint32 _minGasLimit,
bytes memory _extraData
) internal {
_initiateBridgeETH(_from, _to, msg.value, _minGasLimit, _extraData); _initiateBridgeETH(_from, _to, msg.value, _minGasLimit, _extraData);
} }
...@@ -247,7 +224,9 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -247,7 +224,9 @@ contract L1StandardBridge is StandardBridge, Semver {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes memory _extraData bytes memory _extraData
) internal { )
internal
{
_initiateBridgeERC20(_l1Token, _l2Token, _from, _to, _amount, _minGasLimit, _extraData); _initiateBridgeERC20(_l1Token, _l2Token, _from, _to, _amount, _minGasLimit, _extraData);
} }
...@@ -259,7 +238,10 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -259,7 +238,10 @@ contract L1StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
internal
override
{
emit ETHDepositInitiated(_from, _to, _amount, _extraData); emit ETHDepositInitiated(_from, _to, _amount, _extraData);
super._emitETHBridgeInitiated(_from, _to, _amount, _extraData); super._emitETHBridgeInitiated(_from, _to, _amount, _extraData);
} }
...@@ -272,7 +254,10 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -272,7 +254,10 @@ contract L1StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
internal
override
{
emit ETHWithdrawalFinalized(_from, _to, _amount, _extraData); emit ETHWithdrawalFinalized(_from, _to, _amount, _extraData);
super._emitETHBridgeFinalized(_from, _to, _amount, _extraData); super._emitETHBridgeFinalized(_from, _to, _amount, _extraData);
} }
...@@ -287,7 +272,10 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -287,7 +272,10 @@ contract L1StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
internal
override
{
emit ERC20DepositInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData); emit ERC20DepositInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData);
super._emitERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData); super._emitERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData);
} }
...@@ -302,7 +290,10 @@ contract L1StandardBridge is StandardBridge, Semver { ...@@ -302,7 +290,10 @@ contract L1StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
internal
override
{
emit ERC20WithdrawalFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData); emit ERC20WithdrawalFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData);
super._emitERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData); super._emitERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData);
} }
......
...@@ -44,10 +44,7 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -44,10 +44,7 @@ contract L2OutputOracle is Initializable, Semver {
/// @param l2BlockNumber The L2 block number of the output root. /// @param l2BlockNumber The L2 block number of the output root.
/// @param l1Timestamp The L1 timestamp when proposed. /// @param l1Timestamp The L1 timestamp when proposed.
event OutputProposed( event OutputProposed(
bytes32 indexed outputRoot, bytes32 indexed outputRoot, uint256 indexed l2OutputIndex, uint256 indexed l2BlockNumber, uint256 l1Timestamp
uint256 indexed l2OutputIndex,
uint256 indexed l2BlockNumber,
uint256 l1Timestamp
); );
/// @notice Emitted when outputs are deleted. /// @notice Emitted when outputs are deleted.
...@@ -71,12 +68,11 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -71,12 +68,11 @@ contract L2OutputOracle is Initializable, Semver {
address _proposer, address _proposer,
address _challenger, address _challenger,
uint256 _finalizationPeriodSeconds uint256 _finalizationPeriodSeconds
) Semver(1, 3, 1) { )
Semver(1, 3, 1)
{
require(_l2BlockTime > 0, "L2OutputOracle: L2 block time must be greater than 0"); require(_l2BlockTime > 0, "L2OutputOracle: L2 block time must be greater than 0");
require( require(_submissionInterval > 0, "L2OutputOracle: submission interval must be greater than 0");
_submissionInterval > 0,
"L2OutputOracle: submission interval must be greater than 0"
);
SUBMISSION_INTERVAL = _submissionInterval; SUBMISSION_INTERVAL = _submissionInterval;
L2_BLOCK_TIME = _l2BlockTime; L2_BLOCK_TIME = _l2BlockTime;
...@@ -90,10 +86,7 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -90,10 +86,7 @@ contract L2OutputOracle is Initializable, Semver {
/// @notice Initializer. /// @notice Initializer.
/// @param _startingBlockNumber Block number for the first recoded L2 block. /// @param _startingBlockNumber Block number for the first recoded L2 block.
/// @param _startingTimestamp Timestamp for the first recoded L2 block. /// @param _startingTimestamp Timestamp for the first recoded L2 block.
function initialize(uint256 _startingBlockNumber, uint256 _startingTimestamp) function initialize(uint256 _startingBlockNumber, uint256 _startingTimestamp) public initializer {
public
initializer
{
require( require(
_startingTimestamp <= block.timestamp, _startingTimestamp <= block.timestamp,
"L2OutputOracle: starting L2 timestamp must be less than current time" "L2OutputOracle: starting L2 timestamp must be less than current time"
...@@ -109,15 +102,11 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -109,15 +102,11 @@ contract L2OutputOracle is Initializable, Semver {
/// All outputs after this output will also be deleted. /// All outputs after this output will also be deleted.
// solhint-disable-next-line ordering // solhint-disable-next-line ordering
function deleteL2Outputs(uint256 _l2OutputIndex) external { function deleteL2Outputs(uint256 _l2OutputIndex) external {
require( require(msg.sender == CHALLENGER, "L2OutputOracle: only the challenger address can delete outputs");
msg.sender == CHALLENGER,
"L2OutputOracle: only the challenger address can delete outputs"
);
// Make sure we're not *increasing* the length of the array. // Make sure we're not *increasing* the length of the array.
require( require(
_l2OutputIndex < l2Outputs.length, _l2OutputIndex < l2Outputs.length, "L2OutputOracle: cannot delete outputs after the latest output index"
"L2OutputOracle: cannot delete outputs after the latest output index"
); );
// Do not allow deleting any outputs that have already been finalized. // Do not allow deleting any outputs that have already been finalized.
...@@ -148,11 +137,11 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -148,11 +137,11 @@ contract L2OutputOracle is Initializable, Semver {
uint256 _l2BlockNumber, uint256 _l2BlockNumber,
bytes32 _l1BlockHash, bytes32 _l1BlockHash,
uint256 _l1BlockNumber uint256 _l1BlockNumber
) external payable { )
require( external
msg.sender == PROPOSER, payable
"L2OutputOracle: only the proposer address can propose new outputs" {
); require(msg.sender == PROPOSER, "L2OutputOracle: only the proposer address can propose new outputs");
require( require(
_l2BlockNumber == nextBlockNumber(), _l2BlockNumber == nextBlockNumber(),
...@@ -164,10 +153,7 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -164,10 +153,7 @@ contract L2OutputOracle is Initializable, Semver {
"L2OutputOracle: cannot propose L2 output in the future" "L2OutputOracle: cannot propose L2 output in the future"
); );
require( require(_outputRoot != bytes32(0), "L2OutputOracle: L2 output proposal cannot be the zero hash");
_outputRoot != bytes32(0),
"L2OutputOracle: L2 output proposal cannot be the zero hash"
);
if (_l1BlockHash != bytes32(0)) { if (_l1BlockHash != bytes32(0)) {
// This check allows the proposer to propose an output based on a given L1 block, // This check allows the proposer to propose an output based on a given L1 block,
...@@ -198,11 +184,7 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -198,11 +184,7 @@ contract L2OutputOracle is Initializable, Semver {
/// @notice Returns an output by index. Needed to return a struct instead of a tuple. /// @notice Returns an output by index. Needed to return a struct instead of a tuple.
/// @param _l2OutputIndex Index of the output to return. /// @param _l2OutputIndex Index of the output to return.
/// @return The output at the given index. /// @return The output at the given index.
function getL2Output(uint256 _l2OutputIndex) function getL2Output(uint256 _l2OutputIndex) external view returns (Types.OutputProposal memory) {
external
view
returns (Types.OutputProposal memory)
{
return l2Outputs[_l2OutputIndex]; return l2Outputs[_l2OutputIndex];
} }
...@@ -219,10 +201,7 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -219,10 +201,7 @@ contract L2OutputOracle is Initializable, Semver {
); );
// Make sure there's at least one output proposed. // Make sure there's at least one output proposed.
require( require(l2Outputs.length > 0, "L2OutputOracle: cannot get output as no outputs have been proposed yet");
l2Outputs.length > 0,
"L2OutputOracle: cannot get output as no outputs have been proposed yet"
);
// Find the output via binary search, guaranteed to exist. // Find the output via binary search, guaranteed to exist.
uint256 lo = 0; uint256 lo = 0;
...@@ -244,11 +223,7 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -244,11 +223,7 @@ contract L2OutputOracle is Initializable, Semver {
/// block. /// block.
/// @param _l2BlockNumber L2 block number to find a checkpoint for. /// @param _l2BlockNumber L2 block number to find a checkpoint for.
/// @return First checkpoint that commits to the given L2 block number. /// @return First checkpoint that commits to the given L2 block number.
function getL2OutputAfter(uint256 _l2BlockNumber) function getL2OutputAfter(uint256 _l2BlockNumber) external view returns (Types.OutputProposal memory) {
external
view
returns (Types.OutputProposal memory)
{
return l2Outputs[getL2OutputIndexAfter(_l2BlockNumber)]; return l2Outputs[getL2OutputIndexAfter(_l2BlockNumber)];
} }
...@@ -270,10 +245,7 @@ contract L2OutputOracle is Initializable, Semver { ...@@ -270,10 +245,7 @@ contract L2OutputOracle is Initializable, Semver {
/// block number. /// block number.
/// @return Latest submitted L2 block number. /// @return Latest submitted L2 block number.
function latestBlockNumber() public view returns (uint256) { function latestBlockNumber() public view returns (uint256) {
return return l2Outputs.length == 0 ? startingBlockNumber : l2Outputs[l2Outputs.length - 1].l2BlockNumber;
l2Outputs.length == 0
? startingBlockNumber
: l2Outputs[l2Outputs.length - 1].l2BlockNumber;
} }
/// @notice Computes the block number of the next L2 block that needs to be checkpointed. /// @notice Computes the block number of the next L2 block that needs to be checkpointed.
......
...@@ -76,16 +76,16 @@ abstract contract ResourceMetering is Initializable { ...@@ -76,16 +76,16 @@ abstract contract ResourceMetering is Initializable {
uint256 blockDiff = block.number - params.prevBlockNum; uint256 blockDiff = block.number - params.prevBlockNum;
ResourceConfig memory config = _resourceConfig(); ResourceConfig memory config = _resourceConfig();
int256 targetResourceLimit = int256(uint256(config.maxResourceLimit)) / int256 targetResourceLimit =
int256(uint256(config.elasticityMultiplier)); int256(uint256(config.maxResourceLimit)) / int256(uint256(config.elasticityMultiplier));
if (blockDiff > 0) { if (blockDiff > 0) {
// Handle updating EIP-1559 style gas parameters. We use EIP-1559 to restrict the rate // Handle updating EIP-1559 style gas parameters. We use EIP-1559 to restrict the rate
// at which deposits can be created and therefore limit the potential for deposits to // at which deposits can be created and therefore limit the potential for deposits to
// spam the L2 system. Fee scheme is very similar to EIP-1559 with minor changes. // spam the L2 system. Fee scheme is very similar to EIP-1559 with minor changes.
int256 gasUsedDelta = int256(uint256(params.prevBoughtGas)) - targetResourceLimit; int256 gasUsedDelta = int256(uint256(params.prevBoughtGas)) - targetResourceLimit;
int256 baseFeeDelta = (int256(uint256(params.prevBaseFee)) * gasUsedDelta) / int256 baseFeeDelta = (int256(uint256(params.prevBaseFee)) * gasUsedDelta)
(targetResourceLimit * int256(uint256(config.baseFeeMaxChangeDenominator))); / (targetResourceLimit * int256(uint256(config.baseFeeMaxChangeDenominator)));
// Update base fee by adding the base fee delta and clamp the resulting value between // Update base fee by adding the base fee delta and clamp the resulting value between
// min and max. // min and max.
...@@ -155,10 +155,6 @@ abstract contract ResourceMetering is Initializable { ...@@ -155,10 +155,6 @@ abstract contract ResourceMetering is Initializable {
/// child contract. /// child contract.
// solhint-disable-next-line func-name-mixedcase // solhint-disable-next-line func-name-mixedcase
function __ResourceMetering_init() internal onlyInitializing { function __ResourceMetering_init() internal onlyInitializing {
params = ResourceParams({ params = ResourceParams({ prevBaseFee: 1 gwei, prevBoughtGas: 0, prevBlockNum: uint64(block.number) });
prevBaseFee: 1 gwei,
prevBoughtGas: 0,
prevBlockNum: uint64(block.number)
});
} }
} }
...@@ -76,7 +76,9 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -76,7 +76,9 @@ contract SystemConfig is OwnableUpgradeable, Semver {
uint64 _gasLimit, uint64 _gasLimit,
address _unsafeBlockSigner, address _unsafeBlockSigner,
ResourceMetering.ResourceConfig memory _config ResourceMetering.ResourceConfig memory _config
) Semver(1, 3, 1) { )
Semver(1, 3, 1)
{
initialize({ initialize({
_owner: _owner, _owner: _owner,
_overhead: _overhead, _overhead: _overhead,
...@@ -105,7 +107,10 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -105,7 +107,10 @@ contract SystemConfig is OwnableUpgradeable, Semver {
uint64 _gasLimit, uint64 _gasLimit,
address _unsafeBlockSigner, address _unsafeBlockSigner,
ResourceMetering.ResourceConfig memory _config ResourceMetering.ResourceConfig memory _config
) public initializer { )
public
initializer
{
__Ownable_init(); __Ownable_init();
transferOwnership(_owner); transferOwnership(_owner);
overhead = _overhead; overhead = _overhead;
...@@ -212,29 +217,19 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -212,29 +217,19 @@ contract SystemConfig is OwnableUpgradeable, Semver {
function _setResourceConfig(ResourceMetering.ResourceConfig memory _config) internal { function _setResourceConfig(ResourceMetering.ResourceConfig memory _config) internal {
// Min base fee must be less than or equal to max base fee. // Min base fee must be less than or equal to max base fee.
require( require(
_config.minimumBaseFee <= _config.maximumBaseFee, _config.minimumBaseFee <= _config.maximumBaseFee, "SystemConfig: min base fee must be less than max base"
"SystemConfig: min base fee must be less than max base"
); );
// Base fee change denominator must be greater than 1. // Base fee change denominator must be greater than 1.
require( require(_config.baseFeeMaxChangeDenominator > 1, "SystemConfig: denominator must be larger than 1");
_config.baseFeeMaxChangeDenominator > 1,
"SystemConfig: denominator must be larger than 1"
);
// Max resource limit plus system tx gas must be less than or equal to the L2 gas limit. // Max resource limit plus system tx gas must be less than or equal to the L2 gas limit.
// The gas limit must be increased before these values can be increased. // The gas limit must be increased before these values can be increased.
require( require(_config.maxResourceLimit + _config.systemTxMaxGas <= gasLimit, "SystemConfig: gas limit too low");
_config.maxResourceLimit + _config.systemTxMaxGas <= gasLimit,
"SystemConfig: gas limit too low"
);
// Elasticity multiplier must be greater than 0. // Elasticity multiplier must be greater than 0.
require( require(_config.elasticityMultiplier > 0, "SystemConfig: elasticity multiplier cannot be 0");
_config.elasticityMultiplier > 0,
"SystemConfig: elasticity multiplier cannot be 0"
);
// No precision loss when computing target resource limit. // No precision loss when computing target resource limit.
require( require(
((_config.maxResourceLimit / _config.elasticityMultiplier) * ((_config.maxResourceLimit / _config.elasticityMultiplier) * _config.elasticityMultiplier)
_config.elasticityMultiplier) == _config.maxResourceLimit, == _config.maxResourceLimit,
"SystemConfig: precision loss with target resource limit" "SystemConfig: precision loss with target resource limit"
); );
......
...@@ -24,10 +24,7 @@ contract L2ERC721Bridge is ERC721Bridge, Semver { ...@@ -24,10 +24,7 @@ contract L2ERC721Bridge is ERC721Bridge, Semver {
/// @notice Constructs the L2ERC721Bridge contract. /// @notice Constructs the L2ERC721Bridge contract.
/// @param _messenger Address of the CrossDomainMessenger on this network. /// @param _messenger Address of the CrossDomainMessenger on this network.
/// @param _otherBridge Address of the ERC721 bridge on the other network. /// @param _otherBridge Address of the ERC721 bridge on the other network.
constructor(address _messenger, address _otherBridge) constructor(address _messenger, address _otherBridge) Semver(1, 1, 1) ERC721Bridge(_messenger, _otherBridge) { }
Semver(1, 1, 1)
ERC721Bridge(_messenger, _otherBridge)
{}
/// @notice Completes an ERC721 bridge from the other domain and sends the ERC721 token to the /// @notice Completes an ERC721 bridge from the other domain and sends the ERC721 token to the
/// recipient on this domain. /// recipient on this domain.
...@@ -46,7 +43,10 @@ contract L2ERC721Bridge is ERC721Bridge, Semver { ...@@ -46,7 +43,10 @@ contract L2ERC721Bridge is ERC721Bridge, Semver {
address _to, address _to,
uint256 _tokenId, uint256 _tokenId,
bytes calldata _extraData bytes calldata _extraData
) external onlyOtherBridge { )
external
onlyOtherBridge
{
require(_localToken != address(this), "L2ERC721Bridge: local token cannot be self"); require(_localToken != address(this), "L2ERC721Bridge: local token cannot be self");
// Note that supportsInterface makes a callback to the _localToken address which is user // Note that supportsInterface makes a callback to the _localToken address which is user
...@@ -78,7 +78,10 @@ contract L2ERC721Bridge is ERC721Bridge, Semver { ...@@ -78,7 +78,10 @@ contract L2ERC721Bridge is ERC721Bridge, Semver {
uint256 _tokenId, uint256 _tokenId,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) internal override { )
internal
override
{
require(_remoteToken != address(0), "L2ERC721Bridge: remote token cannot be address(0)"); require(_remoteToken != address(0), "L2ERC721Bridge: remote token cannot be address(0)");
// Check that the withdrawal is being initiated by the NFT owner // Check that the withdrawal is being initiated by the NFT owner
...@@ -90,10 +93,7 @@ contract L2ERC721Bridge is ERC721Bridge, Semver { ...@@ -90,10 +93,7 @@ contract L2ERC721Bridge is ERC721Bridge, Semver {
// Construct calldata for l1ERC721Bridge.finalizeBridgeERC721(_to, _tokenId) // Construct calldata for l1ERC721Bridge.finalizeBridgeERC721(_to, _tokenId)
// slither-disable-next-line reentrancy-events // slither-disable-next-line reentrancy-events
address remoteToken = IOptimismMintableERC721(_localToken).remoteToken(); address remoteToken = IOptimismMintableERC721(_localToken).remoteToken();
require( require(remoteToken == _remoteToken, "L2ERC721Bridge: remote token does not match given value");
remoteToken == _remoteToken,
"L2ERC721Bridge: remote token does not match given value"
);
// When a withdrawal is initiated, we burn the withdrawer's NFT to prevent subsequent L2 // When a withdrawal is initiated, we burn the withdrawer's NFT to prevent subsequent L2
// usage // usage
...@@ -101,13 +101,7 @@ contract L2ERC721Bridge is ERC721Bridge, Semver { ...@@ -101,13 +101,7 @@ contract L2ERC721Bridge is ERC721Bridge, Semver {
IOptimismMintableERC721(_localToken).burn(_from, _tokenId); IOptimismMintableERC721(_localToken).burn(_from, _tokenId);
bytes memory message = abi.encodeWithSelector( bytes memory message = abi.encodeWithSelector(
L1ERC721Bridge.finalizeBridgeERC721.selector, L1ERC721Bridge.finalizeBridgeERC721.selector, remoteToken, _localToken, _from, _to, _tokenId, _extraData
remoteToken,
_localToken,
_from,
_to,
_tokenId,
_extraData
); );
// Send message to L1 bridge // Send message to L1 bridge
......
...@@ -58,17 +58,12 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -58,17 +58,12 @@ contract L2StandardBridge is StandardBridge, Semver {
constructor(address payable _otherBridge) constructor(address payable _otherBridge)
Semver(1, 1, 1) Semver(1, 1, 1)
StandardBridge(payable(Predeploys.L2_CROSS_DOMAIN_MESSENGER), _otherBridge) StandardBridge(payable(Predeploys.L2_CROSS_DOMAIN_MESSENGER), _otherBridge)
{} { }
/// @notice Allows EOAs to bridge ETH by sending directly to the bridge. /// @notice Allows EOAs to bridge ETH by sending directly to the bridge.
receive() external payable override onlyEOA { receive() external payable override onlyEOA {
_initiateWithdrawal( _initiateWithdrawal(
Predeploys.LEGACY_ERC20_ETH, Predeploys.LEGACY_ERC20_ETH, msg.sender, msg.sender, msg.value, RECEIVE_DEFAULT_GAS_LIMIT, bytes("")
msg.sender,
msg.sender,
msg.value,
RECEIVE_DEFAULT_GAS_LIMIT,
bytes("")
); );
} }
...@@ -85,7 +80,12 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -85,7 +80,12 @@ contract L2StandardBridge is StandardBridge, Semver {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) external payable virtual onlyEOA { )
external
payable
virtual
onlyEOA
{
_initiateWithdrawal(_l2Token, msg.sender, msg.sender, _amount, _minGasLimit, _extraData); _initiateWithdrawal(_l2Token, msg.sender, msg.sender, _amount, _minGasLimit, _extraData);
} }
...@@ -108,7 +108,11 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -108,7 +108,11 @@ contract L2StandardBridge is StandardBridge, Semver {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) external payable virtual { )
external
payable
virtual
{
_initiateWithdrawal(_l2Token, msg.sender, _to, _amount, _minGasLimit, _extraData); _initiateWithdrawal(_l2Token, msg.sender, _to, _amount, _minGasLimit, _extraData);
} }
...@@ -128,7 +132,11 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -128,7 +132,11 @@ contract L2StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes calldata _extraData bytes calldata _extraData
) external payable virtual { )
external
payable
virtual
{
if (_l1Token == address(0) && _l2Token == Predeploys.LEGACY_ERC20_ETH) { if (_l1Token == address(0) && _l2Token == Predeploys.LEGACY_ERC20_ETH) {
finalizeBridgeETH(_from, _to, _amount, _extraData); finalizeBridgeETH(_from, _to, _amount, _extraData);
} else { } else {
...@@ -158,7 +166,9 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -158,7 +166,9 @@ contract L2StandardBridge is StandardBridge, Semver {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes memory _extraData bytes memory _extraData
) internal { )
internal
{
if (_l2Token == Predeploys.LEGACY_ERC20_ETH) { if (_l2Token == Predeploys.LEGACY_ERC20_ETH) {
_initiateBridgeETH(_from, _to, _amount, _minGasLimit, _extraData); _initiateBridgeETH(_from, _to, _amount, _minGasLimit, _extraData);
} else { } else {
...@@ -175,15 +185,11 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -175,15 +185,11 @@ contract L2StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
emit WithdrawalInitiated( internal
address(0), override
Predeploys.LEGACY_ERC20_ETH, {
_from, emit WithdrawalInitiated(address(0), Predeploys.LEGACY_ERC20_ETH, _from, _to, _amount, _extraData);
_to,
_amount,
_extraData
);
super._emitETHBridgeInitiated(_from, _to, _amount, _extraData); super._emitETHBridgeInitiated(_from, _to, _amount, _extraData);
} }
...@@ -195,15 +201,11 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -195,15 +201,11 @@ contract L2StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
emit DepositFinalized( internal
address(0), override
Predeploys.LEGACY_ERC20_ETH, {
_from, emit DepositFinalized(address(0), Predeploys.LEGACY_ERC20_ETH, _from, _to, _amount, _extraData);
_to,
_amount,
_extraData
);
super._emitETHBridgeFinalized(_from, _to, _amount, _extraData); super._emitETHBridgeFinalized(_from, _to, _amount, _extraData);
} }
...@@ -217,7 +219,10 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -217,7 +219,10 @@ contract L2StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
internal
override
{
emit WithdrawalInitiated(_remoteToken, _localToken, _from, _to, _amount, _extraData); emit WithdrawalInitiated(_remoteToken, _localToken, _from, _to, _amount, _extraData);
super._emitERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData); super._emitERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData);
} }
...@@ -232,7 +237,10 @@ contract L2StandardBridge is StandardBridge, Semver { ...@@ -232,7 +237,10 @@ contract L2StandardBridge is StandardBridge, Semver {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal override { )
internal
override
{
emit DepositFinalized(_remoteToken, _localToken, _from, _to, _amount, _extraData); emit DepositFinalized(_remoteToken, _localToken, _from, _to, _amount, _extraData);
super._emitERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData); super._emitERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData);
} }
......
...@@ -104,7 +104,9 @@ abstract contract ERC721Bridge { ...@@ -104,7 +104,9 @@ abstract contract ERC721Bridge {
uint256 _tokenId, uint256 _tokenId,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) external { )
external
{
// Modifier requiring sender to be EOA. This prevents against a user error that would occur // Modifier requiring sender to be EOA. This prevents against a user error that would occur
// if the sender is a smart contract wallet that has a different address on the remote chain // if the sender is a smart contract wallet that has a different address on the remote chain
// (or doesn't have an address on the remote chain at all). The user would fail to receive // (or doesn't have an address on the remote chain at all). The user would fail to receive
...@@ -113,15 +115,7 @@ abstract contract ERC721Bridge { ...@@ -113,15 +115,7 @@ abstract contract ERC721Bridge {
// care of the user error we want to avoid. // care of the user error we want to avoid.
require(!Address.isContract(msg.sender), "ERC721Bridge: account is not externally owned"); require(!Address.isContract(msg.sender), "ERC721Bridge: account is not externally owned");
_initiateBridgeERC721( _initiateBridgeERC721(_localToken, _remoteToken, msg.sender, msg.sender, _tokenId, _minGasLimit, _extraData);
_localToken,
_remoteToken,
msg.sender,
msg.sender,
_tokenId,
_minGasLimit,
_extraData
);
} }
/// @notice Initiates a bridge of an NFT to some recipient's account on the other chain. Note /// @notice Initiates a bridge of an NFT to some recipient's account on the other chain. Note
...@@ -146,18 +140,12 @@ abstract contract ERC721Bridge { ...@@ -146,18 +140,12 @@ abstract contract ERC721Bridge {
uint256 _tokenId, uint256 _tokenId,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) external { )
external
{
require(_to != address(0), "ERC721Bridge: nft recipient cannot be address(0)"); require(_to != address(0), "ERC721Bridge: nft recipient cannot be address(0)");
_initiateBridgeERC721( _initiateBridgeERC721(_localToken, _remoteToken, msg.sender, _to, _tokenId, _minGasLimit, _extraData);
_localToken,
_remoteToken,
msg.sender,
_to,
_tokenId,
_minGasLimit,
_extraData
);
} }
/// @notice Internal function for initiating a token bridge to the other domain. /// @notice Internal function for initiating a token bridge to the other domain.
...@@ -178,5 +166,7 @@ abstract contract ERC721Bridge { ...@@ -178,5 +166,7 @@ abstract contract ERC721Bridge {
uint256 _tokenId, uint256 _tokenId,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) internal virtual; )
internal
virtual;
} }
...@@ -51,24 +51,14 @@ abstract contract StandardBridge { ...@@ -51,24 +51,14 @@ abstract contract StandardBridge {
/// @param to Address of the receiver. /// @param to Address of the receiver.
/// @param amount Amount of ETH sent. /// @param amount Amount of ETH sent.
/// @param extraData Extra data sent with the transaction. /// @param extraData Extra data sent with the transaction.
event ETHBridgeInitiated( event ETHBridgeInitiated(address indexed from, address indexed to, uint256 amount, bytes extraData);
address indexed from,
address indexed to,
uint256 amount,
bytes extraData
);
/// @notice Emitted when an ETH bridge is finalized on this chain. /// @notice Emitted when an ETH bridge is finalized on this chain.
/// @param from Address of the sender. /// @param from Address of the sender.
/// @param to Address of the receiver. /// @param to Address of the receiver.
/// @param amount Amount of ETH sent. /// @param amount Amount of ETH sent.
/// @param extraData Extra data sent with the transaction. /// @param extraData Extra data sent with the transaction.
event ETHBridgeFinalized( event ETHBridgeFinalized(address indexed from, address indexed to, uint256 amount, bytes extraData);
address indexed from,
address indexed to,
uint256 amount,
bytes extraData
);
/// @notice Emitted when an ERC20 bridge is initiated to the other chain. /// @notice Emitted when an ERC20 bridge is initiated to the other chain.
/// @param localToken Address of the ERC20 on this chain. /// @param localToken Address of the ERC20 on this chain.
...@@ -106,18 +96,14 @@ abstract contract StandardBridge { ...@@ -106,18 +96,14 @@ abstract contract StandardBridge {
/// calling code within their constructors, but also doesn't really matter since we're /// calling code within their constructors, but also doesn't really matter since we're
/// just trying to prevent users accidentally depositing with smart contract wallets. /// just trying to prevent users accidentally depositing with smart contract wallets.
modifier onlyEOA() { modifier onlyEOA() {
require( require(!Address.isContract(msg.sender), "StandardBridge: function can only be called from an EOA");
!Address.isContract(msg.sender),
"StandardBridge: function can only be called from an EOA"
);
_; _;
} }
/// @notice Ensures that the caller is a cross-chain message from the other bridge. /// @notice Ensures that the caller is a cross-chain message from the other bridge.
modifier onlyOtherBridge() { modifier onlyOtherBridge() {
require( require(
msg.sender == address(MESSENGER) && msg.sender == address(MESSENGER) && MESSENGER.xDomainMessageSender() == address(OTHER_BRIDGE),
MESSENGER.xDomainMessageSender() == address(OTHER_BRIDGE),
"StandardBridge: function can only be called from the other bridge" "StandardBridge: function can only be called from the other bridge"
); );
_; _;
...@@ -162,11 +148,7 @@ abstract contract StandardBridge { ...@@ -162,11 +148,7 @@ abstract contract StandardBridge {
/// @param _extraData Extra data to be sent with the transaction. Note that the recipient will /// @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 /// not be triggered with this data, but it will be emitted and can be used
/// to identify the transaction. /// to identify the transaction.
function bridgeETHTo( function bridgeETHTo(address _to, uint32 _minGasLimit, bytes calldata _extraData) public payable {
address _to,
uint32 _minGasLimit,
bytes calldata _extraData
) public payable {
_initiateBridgeETH(msg.sender, _to, msg.value, _minGasLimit, _extraData); _initiateBridgeETH(msg.sender, _to, msg.value, _minGasLimit, _extraData);
} }
...@@ -187,16 +169,12 @@ abstract contract StandardBridge { ...@@ -187,16 +169,12 @@ abstract contract StandardBridge {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) public virtual onlyEOA { )
_initiateBridgeERC20( public
_localToken, virtual
_remoteToken, onlyEOA
msg.sender, {
msg.sender, _initiateBridgeERC20(_localToken, _remoteToken, msg.sender, msg.sender, _amount, _minGasLimit, _extraData);
_amount,
_minGasLimit,
_extraData
);
} }
/// @notice Sends ERC20 tokens to a receiver's address on the other chain. Note that if the /// @notice Sends ERC20 tokens to a receiver's address on the other chain. Note that if the
...@@ -218,16 +196,11 @@ abstract contract StandardBridge { ...@@ -218,16 +196,11 @@ abstract contract StandardBridge {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes calldata _extraData bytes calldata _extraData
) public virtual { )
_initiateBridgeERC20( public
_localToken, virtual
_remoteToken, {
msg.sender, _initiateBridgeERC20(_localToken, _remoteToken, msg.sender, _to, _amount, _minGasLimit, _extraData);
_to,
_amount,
_minGasLimit,
_extraData
);
} }
/// @notice Finalizes an ETH bridge on this chain. Can only be triggered by the other /// @notice Finalizes an ETH bridge on this chain. Can only be triggered by the other
...@@ -243,7 +216,11 @@ abstract contract StandardBridge { ...@@ -243,7 +216,11 @@ abstract contract StandardBridge {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes calldata _extraData bytes calldata _extraData
) public payable onlyOtherBridge { )
public
payable
onlyOtherBridge
{
require(msg.value == _amount, "StandardBridge: amount sent does not match amount required"); require(msg.value == _amount, "StandardBridge: amount sent does not match amount required");
require(_to != address(this), "StandardBridge: cannot send to self"); require(_to != address(this), "StandardBridge: cannot send to self");
require(_to != address(MESSENGER), "StandardBridge: cannot send to messenger"); require(_to != address(MESSENGER), "StandardBridge: cannot send to messenger");
...@@ -273,7 +250,10 @@ abstract contract StandardBridge { ...@@ -273,7 +250,10 @@ abstract contract StandardBridge {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes calldata _extraData bytes calldata _extraData
) public onlyOtherBridge { )
public
onlyOtherBridge
{
if (_isOptimismMintableERC20(_localToken)) { if (_isOptimismMintableERC20(_localToken)) {
require( require(
_isCorrectTokenPair(_localToken, _remoteToken), _isCorrectTokenPair(_localToken, _remoteToken),
...@@ -305,11 +285,10 @@ abstract contract StandardBridge { ...@@ -305,11 +285,10 @@ abstract contract StandardBridge {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes memory _extraData bytes memory _extraData
) internal { )
require( internal
msg.value == _amount, {
"StandardBridge: bridging ETH must include sufficient ETH value" require(msg.value == _amount, "StandardBridge: bridging ETH must include sufficient ETH value");
);
// Emit the correct events. By default this will be _amount, but child // Emit the correct events. By default this will be _amount, but child
// contracts may override this function in order to emit legacy events as well. // contracts may override this function in order to emit legacy events as well.
...@@ -317,13 +296,7 @@ abstract contract StandardBridge { ...@@ -317,13 +296,7 @@ abstract contract StandardBridge {
MESSENGER.sendMessage{ value: _amount }( MESSENGER.sendMessage{ value: _amount }(
address(OTHER_BRIDGE), address(OTHER_BRIDGE),
abi.encodeWithSelector( abi.encodeWithSelector(this.finalizeBridgeETH.selector, _from, _to, _amount, _extraData),
this.finalizeBridgeETH.selector,
_from,
_to,
_amount,
_extraData
),
_minGasLimit _minGasLimit
); );
} }
...@@ -345,7 +318,9 @@ abstract contract StandardBridge { ...@@ -345,7 +318,9 @@ abstract contract StandardBridge {
uint256 _amount, uint256 _amount,
uint32 _minGasLimit, uint32 _minGasLimit,
bytes memory _extraData bytes memory _extraData
) internal { )
internal
{
if (_isOptimismMintableERC20(_localToken)) { if (_isOptimismMintableERC20(_localToken)) {
require( require(
_isCorrectTokenPair(_localToken, _remoteToken), _isCorrectTokenPair(_localToken, _remoteToken),
...@@ -385,9 +360,8 @@ abstract contract StandardBridge { ...@@ -385,9 +360,8 @@ abstract contract StandardBridge {
/// @param _token Address of the token to check. /// @param _token Address of the token to check.
/// @return True if the token is an OptimismMintableERC20. /// @return True if the token is an OptimismMintableERC20.
function _isOptimismMintableERC20(address _token) internal view returns (bool) { function _isOptimismMintableERC20(address _token) internal view returns (bool) {
return return ERC165Checker.supportsInterface(_token, type(ILegacyMintableERC20).interfaceId)
ERC165Checker.supportsInterface(_token, type(ILegacyMintableERC20).interfaceId) || || ERC165Checker.supportsInterface(_token, type(IOptimismMintableERC20).interfaceId);
ERC165Checker.supportsInterface(_token, type(IOptimismMintableERC20).interfaceId);
} }
/// @notice Checks if the "other token" is the correct pair token for the OptimismMintableERC20. /// @notice Checks if the "other token" is the correct pair token for the OptimismMintableERC20.
...@@ -396,14 +370,8 @@ abstract contract StandardBridge { ...@@ -396,14 +370,8 @@ abstract contract StandardBridge {
/// @param _mintableToken OptimismMintableERC20 to check against. /// @param _mintableToken OptimismMintableERC20 to check against.
/// @param _otherToken Pair token to check. /// @param _otherToken Pair token to check.
/// @return True if the other token is the correct pair token for the OptimismMintableERC20. /// @return True if the other token is the correct pair token for the OptimismMintableERC20.
function _isCorrectTokenPair(address _mintableToken, address _otherToken) function _isCorrectTokenPair(address _mintableToken, address _otherToken) internal view returns (bool) {
internal if (ERC165Checker.supportsInterface(_mintableToken, type(ILegacyMintableERC20).interfaceId)) {
view
returns (bool)
{
if (
ERC165Checker.supportsInterface(_mintableToken, type(ILegacyMintableERC20).interfaceId)
) {
return _otherToken == ILegacyMintableERC20(_mintableToken).l1Token(); return _otherToken == ILegacyMintableERC20(_mintableToken).l1Token();
} else { } else {
return _otherToken == IOptimismMintableERC20(_mintableToken).remoteToken(); return _otherToken == IOptimismMintableERC20(_mintableToken).remoteToken();
...@@ -421,7 +389,10 @@ abstract contract StandardBridge { ...@@ -421,7 +389,10 @@ abstract contract StandardBridge {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal virtual { )
internal
virtual
{
emit ETHBridgeInitiated(_from, _to, _amount, _extraData); emit ETHBridgeInitiated(_from, _to, _amount, _extraData);
} }
...@@ -436,7 +407,10 @@ abstract contract StandardBridge { ...@@ -436,7 +407,10 @@ abstract contract StandardBridge {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal virtual { )
internal
virtual
{
emit ETHBridgeFinalized(_from, _to, _amount, _extraData); emit ETHBridgeFinalized(_from, _to, _amount, _extraData);
} }
...@@ -455,7 +429,10 @@ abstract contract StandardBridge { ...@@ -455,7 +429,10 @@ abstract contract StandardBridge {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal virtual { )
internal
virtual
{
emit ERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData); emit ERC20BridgeInitiated(_localToken, _remoteToken, _from, _to, _amount, _extraData);
} }
...@@ -474,7 +451,10 @@ abstract contract StandardBridge { ...@@ -474,7 +451,10 @@ abstract contract StandardBridge {
address _to, address _to,
uint256 _amount, uint256 _amount,
bytes memory _extraData bytes memory _extraData
) internal virtual { )
internal
virtual
{
emit ERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData); emit ERC20BridgeFinalized(_localToken, _remoteToken, _from, _to, _amount, _extraData);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment