Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ERC1404 (extention of ERC20) #2466

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions contracts/token/ERC20/ERC1404.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./ERC20.sol";
import "./IERC1404.sol";
import "../../utils/Strings.sol";

/**
* @title ERC-1404: Simple Restricted Token Standard
* @dev see https://github.com/ethereum/eips/issues/1404
*/
abstract contract ERC1404 is ERC20, IERC1404 {
/**
* @dev Implement transfer restriction codes. Override this function to
* implement your restriction policy.
*/
function detectTransferRestriction(address /*from*/, address /*to*/, uint256 /*amount*/) public virtual override view returns (uint8) {
return uint8(0);
}

/**
* @dev Provides error messages for each restriction codes. Override this
* function to return meaningfull revert reasons.
*/
function messageForTransferRestriction(uint8 restrictionCode) public virtual override view returns (string memory) {
return string(abi.encodePacked("ERC1404: Transfer restriction with code ", Strings.toString(uint256(restrictionCode))));
}

/**
* @dev See {ERC20-_beforeTokenTransfer}.
*
* Requirements:
*
* - transfer must abide by the transfer restriction rules.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual override {
uint8 restrictionCode = detectTransferRestriction(from, to, amount);
if (restrictionCode != uint8(0)) {
revert(messageForTransferRestriction(restrictionCode));
}
super._beforeTokenTransfer(from, to, amount);
}
}
13 changes: 13 additions & 0 deletions contracts/token/ERC20/IERC1404.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.9.0;

import "./IERC20.sol";

/**
* @dev Interface of the ERC1404 standard as defined in the EIP.
*/
interface IERC1404 is IERC20 {
function detectTransferRestriction(address from, address to, uint256 amount) external view returns (uint8);
function messageForTransferRestriction(uint8 restrictionCode) external view returns (string memory);
}