From 98f0c1e0b90bb8fe38923c6ea57d04928a054b42 Mon Sep 17 00:00:00 2001 From: AgusDuha <81362284+agusduha@users.noreply.github.com> Date: Mon, 4 Nov 2024 16:19:24 -0300 Subject: [PATCH] feat: add IERC20 interface support (#124) * feat: add IERC20 interface support * fix: interfaces tests --- packages/contracts-bedrock/semver-lock.json | 8 ++++---- packages/contracts-bedrock/src/L2/SuperchainERC20.sol | 9 +++++---- packages/contracts-bedrock/src/L2/SuperchainWETH.sol | 4 +++- packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol | 4 +++- packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol | 3 +++ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/contracts-bedrock/semver-lock.json b/packages/contracts-bedrock/semver-lock.json index 2b09f99cade6..80ab6ef1cd41 100644 --- a/packages/contracts-bedrock/semver-lock.json +++ b/packages/contracts-bedrock/semver-lock.json @@ -108,7 +108,7 @@ "sourceCodeHash": "0xa76133db7f449ae742f9ba988ad86ccb5672475f61298b9fefe411b63b63e9f6" }, "src/L2/OptimismSuperchainERC20.sol": { - "initCodeHash": "0x1c7ffba96b28d8c92e1e15515286cbb392b1d0b165c65756b06d5c79587d0590", + "initCodeHash": "0x5bc5824030ecdb531e1f615d207cb73cdaa702e198769445d0ddbe717271eba9", "sourceCodeHash": "0x0819c9411a155dca592d19b60c4176954202e4fe5d632a4ffbf88d465461252c" }, "src/L2/OptimismSuperchainERC20Beacon.sol": { @@ -125,15 +125,15 @@ }, "src/L2/SuperchainERC20.sol": { "initCodeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", - "sourceCodeHash": "0x1f6e8972082c03da692e1273eefc59c9a2b5a316aaf4f81b952a4a6899072a81" + "sourceCodeHash": "0xcf39c16893cace1e7d61350bfff05a27f3ce8da8eb0ac02cb5ac7bf603f163fa" }, "src/L2/SuperchainTokenBridge.sol": { "initCodeHash": "0x1cd2afdae6dd1b6ebc17f1d529e7d74c9b8b21b02db8589b8e389e2d5523d775", "sourceCodeHash": "0x617aa994f659c5d8ebd54128d994f86f5b175ceca095b024b8524a7898e8ae62" }, "src/L2/SuperchainWETH.sol": { - "initCodeHash": "0xc2cb1c20157498a62859c5868f037070087838e2986b9e3ba8d065ecb50214b7", - "sourceCodeHash": "0xee35d5d54444ca8df211db964c72dd374e73cc311a3430b40c95dd60dd0b86aa" + "initCodeHash": "0x5aef986a7c9c102b1e9b3068e2a2b66adce0a71dd5f39e03694622bf494f8d97", + "sourceCodeHash": "0xa62101a23b860e97f393027c898082a1c73d50679eceb6c6793844af29702359" }, "src/L2/WETH.sol": { "initCodeHash": "0x17ea1b1c5d5a622d51c2961fde886a5498de63584e654ed1d69ee80dddbe0b17", diff --git a/packages/contracts-bedrock/src/L2/SuperchainERC20.sol b/packages/contracts-bedrock/src/L2/SuperchainERC20.sol index eaac6078ce63..b9e6bbfbf780 100644 --- a/packages/contracts-bedrock/src/L2/SuperchainERC20.sol +++ b/packages/contracts-bedrock/src/L2/SuperchainERC20.sol @@ -5,12 +5,12 @@ import { IERC7802, IERC165 } from "src/L2/interfaces/IERC7802.sol"; import { ISemver } from "src/universal/interfaces/ISemver.sol"; import { Predeploys } from "src/libraries/Predeploys.sol"; import { ERC20 } from "@solady-v0.0.245/tokens/ERC20.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { Unauthorized } from "src/libraries/errors/CommonErrors.sol"; /// @title SuperchainERC20 -/// @notice SuperchainERC20 is a standard extension of the base ERC20 token contract that unifies ERC20 token -/// bridging to make it fungible across the Superchain. This construction allows the SuperchainTokenBridge to -/// burn and mint tokens. +/// @notice A standard ERC20 extension implementing IERC7802 for unified cross-chain fungibility across +/// the Superchain. Allows the SuperchainTokenBridge to mint and burn tokens as needed. abstract contract SuperchainERC20 is ERC20, IERC7802, ISemver { /// @notice Semantic version. /// @custom:semver 1.0.0-beta.5 @@ -42,6 +42,7 @@ abstract contract SuperchainERC20 is ERC20, IERC7802, ISemver { /// @inheritdoc IERC165 function supportsInterface(bytes4 _interfaceId) public view virtual returns (bool) { - return _interfaceId == type(IERC7802).interfaceId || _interfaceId == type(IERC165).interfaceId; + return _interfaceId == type(IERC7802).interfaceId || _interfaceId == type(IERC20).interfaceId + || _interfaceId == type(IERC165).interfaceId; } } diff --git a/packages/contracts-bedrock/src/L2/SuperchainWETH.sol b/packages/contracts-bedrock/src/L2/SuperchainWETH.sol index 0baecab1705c..29e179eba82c 100644 --- a/packages/contracts-bedrock/src/L2/SuperchainWETH.sol +++ b/packages/contracts-bedrock/src/L2/SuperchainWETH.sol @@ -13,6 +13,7 @@ import { ISemver } from "src/universal/interfaces/ISemver.sol"; import { IL1Block } from "src/L2/interfaces/IL1Block.sol"; import { IETHLiquidity } from "src/L2/interfaces/IETHLiquidity.sol"; import { IERC7802, IERC165 } from "src/L2/interfaces/IERC7802.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { Unauthorized, NotCustomGasToken } from "src/libraries/errors/CommonErrors.sol"; /// @custom:proxied true @@ -94,6 +95,7 @@ contract SuperchainWETH is WETH98, IERC7802, ISemver { /// @inheritdoc IERC165 function supportsInterface(bytes4 _interfaceId) public view virtual returns (bool) { - return _interfaceId == type(IERC7802).interfaceId || _interfaceId == type(IERC165).interfaceId; + return _interfaceId == type(IERC7802).interfaceId || _interfaceId == type(IERC20).interfaceId + || _interfaceId == type(IERC165).interfaceId; } } diff --git a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol index 8910b79f52b7..a9aa3b501618 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol @@ -6,11 +6,11 @@ import { Test } from "forge-std/Test.sol"; // Libraries import { Predeploys } from "src/libraries/Predeploys.sol"; -import { IERC20Solady as IERC20 } from "src/vendor/interfaces/IERC20Solady.sol"; // Target contract import { SuperchainERC20 } from "src/L2/SuperchainERC20.sol"; import { IERC7802, IERC165 } from "src/L2/interfaces/IERC7802.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import { ISuperchainERC20 } from "src/L2/interfaces/ISuperchainERC20.sol"; import { MockSuperchainERC20Implementation } from "test/mocks/SuperchainERC20Implementation.sol"; @@ -120,6 +120,7 @@ contract SuperchainERC20Test is Test { function test_supportInterface_succeeds() public view { assertTrue(superchainERC20.supportsInterface(type(IERC165).interfaceId)); assertTrue(superchainERC20.supportsInterface(type(IERC7802).interfaceId)); + assertTrue(superchainERC20.supportsInterface(type(IERC20).interfaceId)); } /// @notice Tests that the `supportsInterface` function returns false for any other interface than the @@ -127,6 +128,7 @@ contract SuperchainERC20Test is Test { function testFuzz_supportInterface_returnFalse(bytes4 _interfaceId) public view { vm.assume(_interfaceId != type(IERC165).interfaceId); vm.assume(_interfaceId != type(IERC7802).interfaceId); + vm.assume(_interfaceId != type(IERC20).interfaceId); assertFalse(superchainERC20.supportsInterface(_interfaceId)); } } diff --git a/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol b/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol index 6b23dbfcd2b8..4d4109b6885a 100644 --- a/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol +++ b/packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol @@ -13,6 +13,7 @@ import { Preinstalls } from "src/libraries/Preinstalls.sol"; import { IETHLiquidity } from "src/L2/interfaces/IETHLiquidity.sol"; import { ISuperchainWETH } from "src/L2/interfaces/ISuperchainWETH.sol"; import { IERC7802, IERC165 } from "src/L2/interfaces/IERC7802.sol"; +import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /// @title SuperchainWETH_Test /// @notice Contract for testing the SuperchainWETH contract. @@ -463,6 +464,7 @@ contract SuperchainWETH_Test is CommonTest { function test_supportInterface_succeeds() public view { assertTrue(superchainWeth.supportsInterface(type(IERC165).interfaceId)); assertTrue(superchainWeth.supportsInterface(type(IERC7802).interfaceId)); + assertTrue(superchainWeth.supportsInterface(type(IERC20).interfaceId)); } /// @notice Tests that the `supportsInterface` function returns false for any other interface than the @@ -470,6 +472,7 @@ contract SuperchainWETH_Test is CommonTest { function testFuzz_supportInterface_returnFalse(bytes4 _interfaceId) public view { vm.assume(_interfaceId != type(IERC165).interfaceId); vm.assume(_interfaceId != type(IERC7802).interfaceId); + vm.assume(_interfaceId != type(IERC20).interfaceId); assertFalse(superchainWeth.supportsInterface(_interfaceId)); } }