-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity >=0.6.0 <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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity >=0.6.0 <0.8.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); | ||
} |