From ecd3a61a86f2fd90217f958a6dc9888f918c6b84 Mon Sep 17 00:00:00 2001 From: Ahmed Castro Date: Tue, 18 Jul 2023 01:58:10 -0600 Subject: [PATCH] refactor(contracts): add token interfaces extensions (#654) --- .../src/libraries/token/IScrollERC1155.sol | 58 ++---------------- .../token/IScrollERC1155Extension.sol | 60 +++++++++++++++++++ .../src/libraries/token/IScrollERC20.sol | 28 +-------- .../libraries/token/IScrollERC20Extension.sol | 33 ++++++++++ .../src/libraries/token/IScrollERC721.sol | 21 ++----- .../token/IScrollERC721Extension.sol | 23 +++++++ contracts/src/package.json | 4 ++ 7 files changed, 132 insertions(+), 95 deletions(-) create mode 100644 contracts/src/libraries/token/IScrollERC1155Extension.sol create mode 100644 contracts/src/libraries/token/IScrollERC20Extension.sol create mode 100644 contracts/src/libraries/token/IScrollERC721Extension.sol diff --git a/contracts/src/libraries/token/IScrollERC1155.sol b/contracts/src/libraries/token/IScrollERC1155.sol index 1ccde145b..f11eeeb35 100644 --- a/contracts/src/libraries/token/IScrollERC1155.sol +++ b/contracts/src/libraries/token/IScrollERC1155.sol @@ -3,59 +3,11 @@ pragma solidity ^0.8.0; import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol"; +import {IScrollERC1155Extension} from "./IScrollERC1155Extension.sol"; -interface IScrollERC1155 is IERC1155 { - /// @notice Return the address of Gateway the token belongs to. - function gateway() external view returns (address); +// The recommended ERC1155 implementation for bridge token. +// deployed in L2 when original token is on L1 +// deployed in L1 when original token is on L2 +interface IScrollERC1155 is IERC1155, IScrollERC1155Extension { - /// @notice Return the address of counterpart token. - function counterpart() external view returns (address); - - /// @notice Mint some token to recipient's account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _to The address of recipient. - /// @param _tokenId The token id to mint. - /// @param _amount The amount of token to mint. - /// @param _data The data passed to recipient - function mint( - address _to, - uint256 _tokenId, - uint256 _amount, - bytes memory _data - ) external; - - /// @notice Burn some token from account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _from The address of account to burn token. - /// @param _tokenId The token id to burn. - /// @param _amount The amount of token to burn. - function burn( - address _from, - uint256 _tokenId, - uint256 _amount - ) external; - - /// @notice Batch mint some token to recipient's account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _to The address of recipient. - /// @param _tokenIds The token id to mint. - /// @param _amounts The list of corresponding amount of token to mint. - /// @param _data The data passed to recipient - function batchMint( - address _to, - uint256[] calldata _tokenIds, - uint256[] calldata _amounts, - bytes calldata _data - ) external; - - /// @notice Batch burn some token from account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _from The address of account to burn token. - /// @param _tokenIds The list of token ids to burn. - /// @param _amounts The list of corresponding amount of token to burn. - function batchBurn( - address _from, - uint256[] calldata _tokenIds, - uint256[] calldata _amounts - ) external; } diff --git a/contracts/src/libraries/token/IScrollERC1155Extension.sol b/contracts/src/libraries/token/IScrollERC1155Extension.sol new file mode 100644 index 000000000..45176bb7d --- /dev/null +++ b/contracts/src/libraries/token/IScrollERC1155Extension.sol @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +// Functions needed on top of the ERC1155 standard to be compliant with the Scroll bridge +interface IScrollERC1155Extension { + /// @notice Return the address of Gateway the token belongs to. + function gateway() external view returns (address); + + /// @notice Return the address of counterpart token. + function counterpart() external view returns (address); + + /// @notice Mint some token to recipient's account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _to The address of recipient. + /// @param _tokenId The token id to mint. + /// @param _amount The amount of token to mint. + /// @param _data The data passed to recipient + function mint( + address _to, + uint256 _tokenId, + uint256 _amount, + bytes memory _data + ) external; + + /// @notice Burn some token from account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _from The address of account to burn token. + /// @param _tokenId The token id to burn. + /// @param _amount The amount of token to burn. + function burn( + address _from, + uint256 _tokenId, + uint256 _amount + ) external; + + /// @notice Batch mint some token to recipient's account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _to The address of recipient. + /// @param _tokenIds The token id to mint. + /// @param _amounts The list of corresponding amount of token to mint. + /// @param _data The data passed to recipient + function batchMint( + address _to, + uint256[] calldata _tokenIds, + uint256[] calldata _amounts, + bytes calldata _data + ) external; + + /// @notice Batch burn some token from account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _from The address of account to burn token. + /// @param _tokenIds The list of token ids to burn. + /// @param _amounts The list of corresponding amount of token to burn. + function batchBurn( + address _from, + uint256[] calldata _tokenIds, + uint256[] calldata _amounts + ) external; +} diff --git a/contracts/src/libraries/token/IScrollERC20.sol b/contracts/src/libraries/token/IScrollERC20.sol index d967e5318..582a92dfd 100644 --- a/contracts/src/libraries/token/IScrollERC20.sol +++ b/contracts/src/libraries/token/IScrollERC20.sol @@ -4,35 +4,11 @@ pragma solidity ^0.8.0; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {IERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol"; +import {IScrollERC20Extension} from "./IScrollERC20Extension.sol"; // The recommended ERC20 implementation for bridge token. // deployed in L2 when original token is on L1 // deployed in L1 when original token is on L2 -interface IScrollERC20 is IERC20, IERC20Permit { - /// @notice Return the address of Gateway the token belongs to. - function gateway() external view returns (address); +interface IScrollERC20 is IERC20, IERC20Permit, IScrollERC20Extension { - /// @notice Return the address of counterpart token. - function counterpart() external view returns (address); - - /// @dev ERC677 Standard, see https://github.com/ethereum/EIPs/issues/677 - /// Defi can use this method to transfer L1/L2 token to L2/L1, - /// and deposit to L2/L1 contract in one transaction - function transferAndCall( - address receiver, - uint256 amount, - bytes calldata data - ) external returns (bool success); - - /// @notice Mint some token to recipient's account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _to The address of recipient. - /// @param _amount The amount of token to mint. - function mint(address _to, uint256 _amount) external; - - /// @notice Mint some token from account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _from The address of account to burn token. - /// @param _amount The amount of token to mint. - function burn(address _from, uint256 _amount) external; } diff --git a/contracts/src/libraries/token/IScrollERC20Extension.sol b/contracts/src/libraries/token/IScrollERC20Extension.sol new file mode 100644 index 000000000..d6f3999b4 --- /dev/null +++ b/contracts/src/libraries/token/IScrollERC20Extension.sol @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +// Functions needed on top of the ERC20 standard to be compliant with the Scroll bridge +interface IScrollERC20Extension { + /// @notice Return the address of Gateway the token belongs to. + function gateway() external view returns (address); + + /// @notice Return the address of counterpart token. + function counterpart() external view returns (address); + + /// @dev ERC677 Standard, see https://github.com/ethereum/EIPs/issues/677 + /// Defi can use this method to transfer L1/L2 token to L2/L1, + /// and deposit to L2/L1 contract in one transaction + function transferAndCall( + address receiver, + uint256 amount, + bytes calldata data + ) external returns (bool success); + + /// @notice Mint some token to recipient's account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _to The address of recipient. + /// @param _amount The amount of token to mint. + function mint(address _to, uint256 _amount) external; + + /// @notice Mint some token from account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _from The address of account to burn token. + /// @param _amount The amount of token to mint. + function burn(address _from, uint256 _amount) external; +} diff --git a/contracts/src/libraries/token/IScrollERC721.sol b/contracts/src/libraries/token/IScrollERC721.sol index bbb6d3f6a..b7dccd06d 100644 --- a/contracts/src/libraries/token/IScrollERC721.sol +++ b/contracts/src/libraries/token/IScrollERC721.sol @@ -3,22 +3,11 @@ pragma solidity ^0.8.0; import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol"; +import {IScrollERC721Extension} from "./IScrollERC721Extension.sol"; -interface IScrollERC721 is IERC721 { - /// @notice Return the address of Gateway the token belongs to. - function gateway() external view returns (address); +// The recommended ERC721 implementation for bridge token. +// deployed in L2 when original token is on L1 +// deployed in L1 when original token is on L2 +interface IScrollERC721 is IERC721, IScrollERC721Extension { - /// @notice Return the address of counterpart token. - function counterpart() external view returns (address); - - /// @notice Mint some token to recipient's account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _to The address of recipient. - /// @param _tokenId The token id to mint. - function mint(address _to, uint256 _tokenId) external; - - /// @notice Burn some token from account. - /// @dev Gateway Utilities, only gateway contract can call - /// @param _tokenId The token id to burn. - function burn(uint256 _tokenId) external; } diff --git a/contracts/src/libraries/token/IScrollERC721Extension.sol b/contracts/src/libraries/token/IScrollERC721Extension.sol new file mode 100644 index 000000000..14e2ce5e7 --- /dev/null +++ b/contracts/src/libraries/token/IScrollERC721Extension.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +// Functions needed on top of the ERC721 standard to be compliant with the Scroll bridge +interface IScrollERC721Extension { + /// @notice Return the address of Gateway the token belongs to. + function gateway() external view returns (address); + + /// @notice Return the address of counterpart token. + function counterpart() external view returns (address); + + /// @notice Mint some token to recipient's account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _to The address of recipient. + /// @param _tokenId The token id to mint. + function mint(address _to, uint256 _tokenId) external; + + /// @notice Burn some token from account. + /// @dev Gateway Utilities, only gateway contract can call + /// @param _tokenId The token id to burn. + function burn(uint256 _tokenId) external; +} diff --git a/contracts/src/package.json b/contracts/src/package.json index d83a958ad..51566006f 100644 --- a/contracts/src/package.json +++ b/contracts/src/package.json @@ -20,8 +20,12 @@ "libraries/callbacks", "libraries/gateway", "libraries/oracle/IGasOracle.sol", + "libraries/token/IScrollERC20.sol", + "libraries/token/IScrollERC20Extension.sol", "libraries/token/IScrollERC1155.sol", + "libraries/token/IScrollERC1155Extension.sol", "libraries/token/IScrollERC721.sol", + "libraries/token/IScrollERC721Extension.sol", "libraries/token/IScrollStandardERC20.sol", "libraries/token/IScrollStandardERC20Factory.sol", "libraries/IScrollMessenger.sol"