Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add generic factory interface #14

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/contracts-bedrock/src/L2/IOptimismERC20Factory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

/// @title IOptimismERC20Factory
/// @notice Generic interface for IOptimismMintableERC20Factory and ISuperchainERC20Factory. Used to
/// determine if a ERC20 contract is deployed by a factory.
interface IOptimismERC20Factory {
/// @notice Checks if a ERC20 token is deployed by the factory.
/// @param _token The address of the ERC20 token to check the deployment.
/// @return _remoteToken The address of the remote token if it is deployed or `address(0)` if not.
function deployments(address _token) external view returns (address _remoteToken);
Comment on lines +10 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On their guidelines, they say they use suffixed returned args (remoteToken_).
Even though I don't like that, should we follow that standard for his new contracts as well?
Or the new contracts developed are not following that particular way?

}
15 changes: 3 additions & 12 deletions packages/contracts-bedrock/src/L2/L2StandardBridgeInterop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Predeploys } from "src/libraries/Predeploys.sol";
import { L2StandardBridge } from "src/L2/L2StandardBridge.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { IOptimismERC20Factory } from "src/L2/IOptimismERC20Factory.sol";

/// @notice Thrown when the decimals of the tokens are not the same.
error InvalidDecimals();
Expand All @@ -18,16 +19,6 @@ error InvalidSuperchainAddress();
/// @notice Thrown when the remote addresses of the tokens are not the same.
error InvalidTokenPair();

// TODO: Use OptimismMintableERC20Factory contract instead of interface
interface IOptimismMintableERC20Factory {
function deployments(address) external view returns (address);
}

// TODO: Move to a separate file
interface ISuperchainERC20Factory {
function deployments(address) external view returns (address);
}

// TODO: Use an existing interface with `mint` and `burn`?
interface MintableAndBurnable is IERC20 {
function mint(address, uint256) external;
Expand Down Expand Up @@ -82,12 +73,12 @@ contract L2StandardBridgeInterop is L2StandardBridge {
function _validateFactories(address _legacyAddr, address _superAddr) internal view {
// 2. Valid legacy check
address _legacyRemoteToken =
IOptimismMintableERC20Factory(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY).deployments(_legacyAddr);
IOptimismERC20Factory(Predeploys.OPTIMISM_MINTABLE_ERC20_FACTORY).deployments(_legacyAddr);
if (_legacyRemoteToken == address(0)) revert InvalidLegacyAddress();

// 3. Valid SuperchainERC20 check
address _superRemoteToken =
ISuperchainERC20Factory(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_FACTORY).deployments(_superAddr);
IOptimismERC20Factory(Predeploys.OPTIMISM_SUPERCHAIN_ERC20_FACTORY).deployments(_superAddr);
if (_superRemoteToken == address(0)) revert InvalidSuperchainAddress();

// 4. Same remote address check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
InvalidLegacyAddress,
InvalidSuperchainAddress,
InvalidTokenPair,
IOptimismMintableERC20Factory,
IOptimismERC20Factory,
MintableAndBurnable
} from "src/L2/L2StandardBridgeInterop.sol";
import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
Expand Down Expand Up @@ -47,9 +47,7 @@ contract L2StandardBridgeInterop_Test is Bridge_Initializer {
/// @notice Mock factory deployment
function _mockDeployments(address _factory, address _token, address _deployed) internal {
_mockAndExpect(
_factory,
abi.encodeWithSelector(IOptimismMintableERC20Factory.deployments.selector, _token),
abi.encode(_deployed)
_factory, abi.encodeWithSelector(IOptimismERC20Factory.deployments.selector, _token), abi.encode(_deployed)
);
}
}
Expand Down