|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | +pragma solidity 0.6.10; |
| 3 | + |
| 4 | +import {BurnableTokenWithBounds} from "./common/BurnableTokenWithBounds.sol"; |
| 5 | + |
| 6 | +/** |
| 7 | + * @title TrueCurrency |
| 8 | + * @dev TrueCurrency is an ERC20 with blacklist & redemption addresses |
| 9 | + * |
| 10 | + * TrueCurrency is a compliant stablecoin with blacklist and redemption |
| 11 | + * addresses. Only the owner can blacklist accounts. Redemption addresses |
| 12 | + * are assigned automatically to the first 0x100000 addresses. Sending |
| 13 | + * tokens to the redemption address will trigger a burn operation. Only |
| 14 | + * the owner can mint or blacklist accounts. |
| 15 | + * |
| 16 | + * This contract is owned by the TokenController, which manages token |
| 17 | + * minting & admin functionality. See TokenController.sol |
| 18 | + * |
| 19 | + * See also: BurnableTokenWithBounds.sol |
| 20 | + * |
| 21 | + * ~~~~ Features ~~~~ |
| 22 | + * |
| 23 | + * Redemption Addresses |
| 24 | + * - The first 0x100000 addresses are redemption addresses |
| 25 | + * - Tokens sent to redemption addresses are burned |
| 26 | + * - Redemptions are tracked off-chain |
| 27 | + * - Cannot mint tokens to redemption addresses |
| 28 | + * |
| 29 | + * Blacklist |
| 30 | + * - Owner can blacklist accounts in accordance with local regulatory bodies |
| 31 | + * - Only a court order will merit a blacklist; blacklisting is extremely rare |
| 32 | + * |
| 33 | + * Burn Bounds & CanBurn |
| 34 | + * - Owner can set min & max burn amounts |
| 35 | + * - Only accounts flagged in canBurn are allowed to burn tokens |
| 36 | + * - canBurn prevents tokens from being sent to the incorrect address |
| 37 | + * |
| 38 | + * Reclaimer Token |
| 39 | + * - ERC20 Tokens and Ether sent to this contract can be reclaimed by the owner |
| 40 | + */ |
| 41 | +abstract contract TrueCurrency is BurnableTokenWithBounds { |
| 42 | + uint256 constant CENT = 10**16; |
| 43 | + uint256 constant REDEMPTION_ADDRESS_COUNT = 0x100000; |
| 44 | + |
| 45 | + /** |
| 46 | + * @dev Emitted when account blacklist status changes |
| 47 | + */ |
| 48 | + event Blacklisted(address indexed account, bool isBlacklisted); |
| 49 | + |
| 50 | + /** |
| 51 | + * @dev Emitted when `value` tokens are minted for `to` |
| 52 | + * @param to address to mint tokens for |
| 53 | + * @param value amount of tokens to be minted |
| 54 | + */ |
| 55 | + event Mint(address indexed to, uint256 value); |
| 56 | + |
| 57 | + /** |
| 58 | + * @dev Creates `amount` tokens and assigns them to `account`, increasing |
| 59 | + * the total supply. |
| 60 | + * @param account address to mint tokens for |
| 61 | + * @param amount amount of tokens to be minted |
| 62 | + * |
| 63 | + * Emits a {Mint} event |
| 64 | + * |
| 65 | + * Requirements |
| 66 | + * |
| 67 | + * - `account` cannot be the zero address. |
| 68 | + * - `account` cannot be blacklisted. |
| 69 | + * - `account` cannot be a redemption address. |
| 70 | + */ |
| 71 | + function mint(address account, uint256 amount) external onlyOwner { |
| 72 | + require(!isBlacklisted[account], "TrueCurrency: account is blacklisted"); |
| 73 | + require(!isRedemptionAddress(account), "TrueCurrency: account is a redemption address"); |
| 74 | + _mint(account, amount); |
| 75 | + emit Mint(account, amount); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * @dev Set blacklisted status for the account. |
| 80 | + * @param account address to set blacklist flag for |
| 81 | + * @param _isBlacklisted blacklist flag value |
| 82 | + * |
| 83 | + * Requirements: |
| 84 | + * |
| 85 | + * - `msg.sender` should be owner. |
| 86 | + */ |
| 87 | + function setBlacklisted(address account, bool _isBlacklisted) external onlyOwner { |
| 88 | + require(uint256(account) >= REDEMPTION_ADDRESS_COUNT, "TrueCurrency: blacklisting of redemption address is not allowed"); |
| 89 | + isBlacklisted[account] = _isBlacklisted; |
| 90 | + emit Blacklisted(account, _isBlacklisted); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @dev Set canBurn status for the account. |
| 95 | + * @param account address to set canBurn flag for |
| 96 | + * @param _canBurn canBurn flag value |
| 97 | + * |
| 98 | + * Requirements: |
| 99 | + * |
| 100 | + * - `msg.sender` should be owner. |
| 101 | + */ |
| 102 | + function setCanBurn(address account, bool _canBurn) external onlyOwner { |
| 103 | + canBurn[account] = _canBurn; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @dev Check if neither account is blacklisted before performing transfer |
| 108 | + * If transfer recipient is a redemption address, burns tokens |
| 109 | + * @notice Transfer to redemption address will burn tokens with a 1 cent precision |
| 110 | + * @param sender address of sender |
| 111 | + * @param recipient address of recipient |
| 112 | + * @param amount amount of tokens to transfer |
| 113 | + */ |
| 114 | + function _transfer( |
| 115 | + address sender, |
| 116 | + address recipient, |
| 117 | + uint256 amount |
| 118 | + ) internal virtual override { |
| 119 | + require(!isBlacklisted[sender], "TrueCurrency: sender is blacklisted"); |
| 120 | + require(!isBlacklisted[recipient], "TrueCurrency: recipient is blacklisted"); |
| 121 | + |
| 122 | + if (isRedemptionAddress(recipient)) { |
| 123 | + super._transfer(sender, recipient, amount.sub(amount.mod(CENT))); |
| 124 | + _burn(recipient, amount.sub(amount.mod(CENT))); |
| 125 | + } else { |
| 126 | + super._transfer(sender, recipient, amount); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * @dev Requere neither accounts to be blacklisted before approval |
| 132 | + * @param owner address of owner giving approval |
| 133 | + * @param spender address of spender to approve for |
| 134 | + * @param amount amount of tokens to approve |
| 135 | + */ |
| 136 | + function _approve( |
| 137 | + address owner, |
| 138 | + address spender, |
| 139 | + uint256 amount |
| 140 | + ) internal override { |
| 141 | + require(!isBlacklisted[owner], "TrueCurrency: tokens owner is blacklisted"); |
| 142 | + require(!isBlacklisted[spender] || amount == 0, "TrueCurrency: tokens spender is blacklisted"); |
| 143 | + |
| 144 | + super._approve(owner, spender, amount); |
| 145 | + } |
| 146 | + |
| 147 | + /** |
| 148 | + * @dev Check if tokens can be burned at address before burning |
| 149 | + * @param account account to burn tokens from |
| 150 | + * @param amount amount of tokens to burn |
| 151 | + */ |
| 152 | + function _burn(address account, uint256 amount) internal override { |
| 153 | + require(canBurn[account], "TrueCurrency: cannot burn from this address"); |
| 154 | + super._burn(account, amount); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * @dev First 0x100000-1 addresses (0x0000000000000000000000000000000000000001 to 0x00000000000000000000000000000000000fffff) |
| 159 | + * are the redemption addresses. |
| 160 | + * @param account address to check is a redemption address |
| 161 | + * |
| 162 | + * All transfers to redemption address will trigger token burn. |
| 163 | + * |
| 164 | + * @notice For transfer to succeed, canBurn must be true for redemption address |
| 165 | + * |
| 166 | + * @return is `account` a redemption address |
| 167 | + */ |
| 168 | + function isRedemptionAddress(address account) internal pure returns (bool) { |
| 169 | + return uint256(account) < REDEMPTION_ADDRESS_COUNT && uint256(account) != 0; |
| 170 | + } |
| 171 | +} |
0 commit comments