From 9a225ab7b5d0d1242450b33110c4e7b31b7bd7a1 Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Mon, 8 Feb 2021 23:19:44 +0100 Subject: [PATCH] add an interface folder that lists common interfaces --- contracts/interfaces/ERC1155.sol | 7 ++ contracts/interfaces/ERC1271.sol | 8 ++ contracts/interfaces/ERC1363.sol | 123 +++++++++++++++++++++++++++++++ contracts/interfaces/ERC165.sol | 5 ++ contracts/interfaces/ERC173.sol | 19 +++++ contracts/interfaces/ERC1820.sol | 6 ++ contracts/interfaces/ERC20.sol | 5 ++ contracts/interfaces/ERC2612.sol | 7 ++ contracts/interfaces/ERC3156.sol | 58 +++++++++++++++ contracts/interfaces/ERC721.sol | 8 ++ contracts/interfaces/ERC725.sol | 13 ++++ contracts/interfaces/ERC777.sol | 7 ++ 12 files changed, 266 insertions(+) create mode 100644 contracts/interfaces/ERC1155.sol create mode 100644 contracts/interfaces/ERC1271.sol create mode 100644 contracts/interfaces/ERC1363.sol create mode 100644 contracts/interfaces/ERC165.sol create mode 100644 contracts/interfaces/ERC173.sol create mode 100644 contracts/interfaces/ERC1820.sol create mode 100644 contracts/interfaces/ERC20.sol create mode 100644 contracts/interfaces/ERC2612.sol create mode 100644 contracts/interfaces/ERC3156.sol create mode 100644 contracts/interfaces/ERC721.sol create mode 100644 contracts/interfaces/ERC725.sol create mode 100644 contracts/interfaces/ERC777.sol diff --git a/contracts/interfaces/ERC1155.sol b/contracts/interfaces/ERC1155.sol new file mode 100644 index 00000000000..77c8c70ff10 --- /dev/null +++ b/contracts/interfaces/ERC1155.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../token/ERC1155/IERC1155.sol"; +import "../token/ERC1155/IERC1155MetadataURI.sol"; +import "../token/ERC1155/IERC1155Receiver.sol"; diff --git a/contracts/interfaces/ERC1271.sol b/contracts/interfaces/ERC1271.sol new file mode 100644 index 00000000000..53051b38331 --- /dev/null +++ b/contracts/interfaces/ERC1271.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +interface IERC1271 +{ + function isValidSignature(bytes calldata data, bytes calldata signature) external view returns (bytes4 magicValue); +} diff --git a/contracts/interfaces/ERC1363.sol b/contracts/interfaces/ERC1363.sol new file mode 100644 index 00000000000..471d2bb69fb --- /dev/null +++ b/contracts/interfaces/ERC1363.sol @@ -0,0 +1,123 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../token/ERC20/IERC20.sol"; +import "../introspection/IERC165.sol"; + +interface IERC1363 is IERC20, IERC165 { + /* + * Note: the ERC-165 identifier for this interface is 0x4bbee2df. + * 0x4bbee2df === + * bytes4(keccak256('transferAndCall(address,uint256)')) ^ + * bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^ + * bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^ + * bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) + */ + + /* + * Note: the ERC-165 identifier for this interface is 0xfb9ec8ce. + * 0xfb9ec8ce === + * bytes4(keccak256('approveAndCall(address,uint256)')) ^ + * bytes4(keccak256('approveAndCall(address,uint256,bytes)')) + */ + + /** + * @notice Transfer tokens from `msg.sender` to another address and then call `onTransferReceived` on receiver + * @param to address The address which you want to transfer to + * @param value uint256 The amount of tokens to be transferred + * @return true unless throwing + */ + function transferAndCall(address to, uint256 value) external returns (bool); + + /** + * @notice Transfer tokens from `msg.sender` to another address and then call `onTransferReceived` on receiver + * @param to address The address which you want to transfer to + * @param value uint256 The amount of tokens to be transferred + * @param data bytes Additional data with no specified format, sent in call to `to` + * @return true unless throwing + */ + function transferAndCall(address to, uint256 value, bytes memory data) external returns (bool); + + /** + * @notice Transfer tokens from one address to another and then call `onTransferReceived` on receiver + * @param from address The address which you want to send tokens from + * @param to address The address which you want to transfer to + * @param value uint256 The amount of tokens to be transferred + * @return true unless throwing + */ + function transferFromAndCall(address from, address to, uint256 value) external returns (bool); + + + /** + * @notice Transfer tokens from one address to another and then call `onTransferReceived` on receiver + * @param from address The address which you want to send tokens from + * @param to address The address which you want to transfer to + * @param value uint256 The amount of tokens to be transferred + * @param data bytes Additional data with no specified format, sent in call to `to` + * @return true unless throwing + */ + function transferFromAndCall(address from, address to, uint256 value, bytes memory data) external returns (bool); + + /** + * @notice Approve the passed address to spend the specified amount of tokens on behalf of msg.sender + * and then call `onApprovalReceived` on spender. + * @param spender address The address which will spend the funds + * @param value uint256 The amount of tokens to be spent + */ + function approveAndCall(address spender, uint256 value) external returns (bool); + + /** + * @notice Approve the passed address to spend the specified amount of tokens on behalf of msg.sender + * and then call `onApprovalReceived` on spender. + * @param spender address The address which will spend the funds + * @param value uint256 The amount of tokens to be spent + * @param data bytes Additional data with no specified format, sent in call to `spender` + */ + function approveAndCall(address spender, uint256 value, bytes memory data) external returns (bool); +} + +interface IERC1363Receiver { + /* + * Note: the ERC-165 identifier for this interface is 0x88a7ca5c. + * 0x88a7ca5c === bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)")) + */ + + /** + * @notice Handle the receipt of ERC1363 tokens + * @dev Any ERC1363 smart contract calls this function on the recipient + * after a `transfer` or a `transferFrom`. This function MAY throw to revert and reject the + * transfer. Return of other than the magic value MUST result in the + * transaction being reverted. + * Note: the token contract address is always the message sender. + * @param operator address The address which called `transferAndCall` or `transferFromAndCall` function + * @param from address The address which are token transferred from + * @param value uint256 The amount of tokens transferred + * @param data bytes Additional data with no specified format + * @return `bytes4(keccak256("onTransferReceived(address,address,uint256,bytes)"))` + * unless throwing + */ + function onTransferReceived(address operator, address from, uint256 value, bytes memory data) external returns (bytes4); +} + +interface IERC1363Spender { + /* + * Note: the ERC-165 identifier for this interface is 0x7b04a2d0. + * 0x7b04a2d0 === bytes4(keccak256("onApprovalReceived(address,uint256,bytes)")) + */ + + /** + * @notice Handle the approval of ERC1363 tokens + * @dev Any ERC1363 smart contract calls this function on the recipient + * after an `approve`. This function MAY throw to revert and reject the + * approval. Return of other than the magic value MUST result in the + * transaction being reverted. + * Note: the token contract address is always the message sender. + * @param owner address The address which called `approveAndCall` function + * @param value uint256 The amount of tokens to be spent + * @param data bytes Additional data with no specified format + * @return `bytes4(keccak256("onApprovalReceived(address,uint256,bytes)"))` + * unless throwing + */ + function onApprovalReceived(address owner, uint256 value, bytes memory data) external returns (bytes4); +} diff --git a/contracts/interfaces/ERC165.sol b/contracts/interfaces/ERC165.sol new file mode 100644 index 00000000000..381a93926cc --- /dev/null +++ b/contracts/interfaces/ERC165.sol @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../introspection/IERC165.sol"; diff --git a/contracts/interfaces/ERC173.sol b/contracts/interfaces/ERC173.sol new file mode 100644 index 00000000000..ea32a1cce04 --- /dev/null +++ b/contracts/interfaces/ERC173.sol @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../introspection/IERC165.sol"; + +interface IERC173 is IERC165 { + /// @dev This emits when ownership of a contract changes. + event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); + + /// @notice Get the address of the owner + /// @return The address of the owner. + function owner() view external returns(address); + + /// @notice Set the address of the new owner of the contract + /// @dev Set _newOwner to address(0) to renounce any ownership. + /// @param _newOwner The address of the new owner of the contract + function transferOwnership(address _newOwner) external; +} diff --git a/contracts/interfaces/ERC1820.sol b/contracts/interfaces/ERC1820.sol new file mode 100644 index 00000000000..2b4fd352003 --- /dev/null +++ b/contracts/interfaces/ERC1820.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../introspection/IERC1820Implementer.sol"; +import "../introspection/IERC1820Registry.sol"; diff --git a/contracts/interfaces/ERC20.sol b/contracts/interfaces/ERC20.sol new file mode 100644 index 00000000000..0072add5e29 --- /dev/null +++ b/contracts/interfaces/ERC20.sol @@ -0,0 +1,5 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../token/ERC20/IERC20.sol"; diff --git a/contracts/interfaces/ERC2612.sol b/contracts/interfaces/ERC2612.sol new file mode 100644 index 00000000000..1bedd6165f1 --- /dev/null +++ b/contracts/interfaces/ERC2612.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../drafts/IERC20Permit.sol"; + +interface IERC2612 is IERC20Permit {} diff --git a/contracts/interfaces/ERC3156.sol b/contracts/interfaces/ERC3156.sol new file mode 100644 index 00000000000..e149145c8f2 --- /dev/null +++ b/contracts/interfaces/ERC3156.sol @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +interface IERC3156FlashLender { + /** + * @dev The amount of currency available to be lent. + * @param token The loan currency. + * @return The amount of `token` that can be borrowed. + */ + function maxFlashLoan( + address token + ) external view returns (uint256); + + /** + * @dev The fee to be charged for a given loan. + * @param token The loan currency. + * @param amount The amount of tokens lent. + * @return The amount of `token` to be charged for the loan, on top of the returned principal. + */ + function flashFee( + address token, + uint256 amount + ) external view returns (uint256); + + /** + * @dev Initiate a flash loan. + * @param receiver The receiver of the tokens in the loan, and the receiver of the callback. + * @param token The loan currency. + * @param amount The amount of tokens lent. + * @param data Arbitrary data structure, intended to contain user-defined parameters. + */ + function flashLoan( + address receiver, + address token, + uint256 amount, + bytes calldata data + ) external returns (bool); +} + +interface IERC3156FlashBorrower { + /** + * @dev Receive a flash loan. + * @param initiator The initiator of the loan. + * @param token The loan currency. + * @param amount The amount of tokens lent. + * @param fee The additional amount of tokens to repay. + * @param data Arbitrary data structure, intended to contain user-defined parameters. + * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan" + */ + function onFlashLoan( + address initiator, + address token, + uint256 amount, + uint256 fee, + bytes calldata data + ) external returns (bytes32); +} diff --git a/contracts/interfaces/ERC721.sol b/contracts/interfaces/ERC721.sol new file mode 100644 index 00000000000..ea42ced18e6 --- /dev/null +++ b/contracts/interfaces/ERC721.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../token/ERC721/IERC721.sol"; +import "../token/ERC721/IERC721Enumerable.sol"; +import "../token/ERC721/IERC721Metadata.sol"; +import "../token/ERC721/IERC721Receiver.sol"; diff --git a/contracts/interfaces/ERC725.sol b/contracts/interfaces/ERC725.sol new file mode 100644 index 00000000000..354afe693af --- /dev/null +++ b/contracts/interfaces/ERC725.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +interface IERC725 +{ + event DataChanged(bytes32 indexed key, bytes32 indexed value); + event ContractCreated(address indexed contractAddress); + + function getData(bytes32 key) external view returns (bytes32 value); + function setData(bytes32 key, bytes32 value) external; + function execute(uint256 operationType, address to, uint256 value, bytes calldata _data) external; +} diff --git a/contracts/interfaces/ERC777.sol b/contracts/interfaces/ERC777.sol new file mode 100644 index 00000000000..c0498eada20 --- /dev/null +++ b/contracts/interfaces/ERC777.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import "../token/ERC777/IERC777.sol"; +import "../token/ERC777/IERC777Recipient.sol"; +import "../token/ERC777/IERC777Sender.sol";