Skip to content

Commit

Permalink
feat: add IERC20 interface support (#124)
Browse files Browse the repository at this point in the history
* feat: add IERC20 interface support

* fix: interfaces tests
  • Loading branch information
agusduha authored Nov 4, 2024
1 parent 9fd55c6 commit 98f0c1e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions packages/contracts-bedrock/semver-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"sourceCodeHash": "0xa76133db7f449ae742f9ba988ad86ccb5672475f61298b9fefe411b63b63e9f6"
},
"src/L2/OptimismSuperchainERC20.sol": {
"initCodeHash": "0x1c7ffba96b28d8c92e1e15515286cbb392b1d0b165c65756b06d5c79587d0590",
"initCodeHash": "0x5bc5824030ecdb531e1f615d207cb73cdaa702e198769445d0ddbe717271eba9",
"sourceCodeHash": "0x0819c9411a155dca592d19b60c4176954202e4fe5d632a4ffbf88d465461252c"
},
"src/L2/OptimismSuperchainERC20Beacon.sol": {
Expand All @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions packages/contracts-bedrock/src/L2/SuperchainERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion packages/contracts-bedrock/src/L2/SuperchainWETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion packages/contracts-bedrock/test/L2/SuperchainERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -120,13 +120,15 @@ 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
/// `IERC7802` one.
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));
}
}
3 changes: 3 additions & 0 deletions packages/contracts-bedrock/test/L2/SuperchainWETH.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -463,13 +464,15 @@ 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
/// `IERC7802` one.
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));
}
}

0 comments on commit 98f0c1e

Please sign in to comment.