Skip to content

Instantly share code, notes, and snippets.

@youfoundron
Created November 21, 2018 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youfoundron/862531f27d176e6768b66669d2f80359 to your computer and use it in GitHub Desktop.
Save youfoundron/862531f27d176e6768b66669d2f80359 to your computer and use it in GitHub Desktop.
ERC-1404: When Investors Can’t Trade -- Example Code

InvestorTypesToken.sol Explained

Draft

pragma solidity ^0.4.24;
import "zeppelin-solidity/contracts/ownership/Ownable.sol";
import "simple-restricted-token/contracts/token/ERC1404/SimpleRestrictedToken.sol";
contract InvestorTypesToken is SimpleRestrictedToken, Ownable {
mapping (address => bool) public investorsTypeA;
mapping (address => bool) public investorsTypeB;
uint8 public INVESTOR_TYPES_MISMATCHED_CODE = 1;
string public constant INVESTOR_TYPES_MISMATCHED_ERROR = "INVESTOR_TYPES_ARE_MISMATCHED";
function detectTransferRestriction (address from, address to, uint256 value) public view returns (uint8) {
bool investorTypesMismatched = (
(investorsTypeA[to] && !investorsTypeA[from]) ||
(investorsTypeB[to] && !investorsTypeB[from])
);
if (investorTypesMismatched) {
return INVESTOR_TYPES_MISMATCH_CODE;
} else {
return super.detectTransferRestriction(from, to, value);
}
}
function messageForTransferRestriction (uint8 restrictionCode) public view returns (string) {
if (restrictionCode == INVESTOR_TYPES_MISMATCHED_CODE) {
return INVESTOR_TYPES_MISMATCHED_ERROR;
} else {
return super.messageForTransferRestriction(restrictionCode);
}
}
function listInvestorTypeA (address investor) public onlyOwner returns (bool) {
investorsTypeA[investor] = true;
return true;
}
function delistInvestorTypeA (address investor) public onlyOwner returns (bool) {
investorsTypeA[investor] = false;
return true;
}
function listInvestorTypeB (address investor) public onlyOwner returns (bool) {
investorsTypeB[investor] = true;
return true;
}
function delistInvestorTypeB (address investor) public onlyOwner returns (bool) {
investorsTypeB[investor] = false;
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment