mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-01-10 22:48:14 -05:00
refactor(contracts): add token interfaces extensions (#654)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
60
contracts/src/libraries/token/IScrollERC1155Extension.sol
Normal file
60
contracts/src/libraries/token/IScrollERC1155Extension.sol
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
33
contracts/src/libraries/token/IScrollERC20Extension.sol
Normal file
33
contracts/src/libraries/token/IScrollERC20Extension.sol
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
23
contracts/src/libraries/token/IScrollERC721Extension.sol
Normal file
23
contracts/src/libraries/token/IScrollERC721Extension.sol
Normal file
@@ -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;
|
||||
}
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user