Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.30 KB | None | 0 0
  1. pragma solidity 0.5.8;
  2.  
  3. import 'github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol';
  4. import 'github.com/OpenZeppelin/openzeppelin-solidity/contracts/lifecycle/Pausable.sol';
  5. import 'github.com/OpenZeppelin/openzeppelin-solidity/contracts/ownership/Ownable.sol';
  6.  
  7. contract BlackListableToken is Ownable, ERC20 {
  8.  
  9. /////// Getters to allow the same blacklist to be used also by other contracts (including upgraded Tether) ///////
  10. function getBlackListStatus(address _maker) external view returns (bool) {
  11. return isBlackListed[_maker];
  12. }
  13.  
  14. mapping (address => bool) public isBlackListed;
  15.  
  16. function addBlackList(address _evilUser) public onlyOwner {
  17. require(!isBlackListed[_evilUser], "_evilUser is already in black list");
  18.  
  19. isBlackListed[_evilUser] = true;
  20. emit AddedBlackList(_evilUser);
  21. }
  22.  
  23. function removeBlackList(address _clearedUser) public onlyOwner {
  24. require(isBlackListed[_clearedUser], "_clearedUser isn't in black list");
  25.  
  26. isBlackListed[_clearedUser] = false;
  27. emit RemovedBlackList(_clearedUser);
  28. }
  29.  
  30. function destroyBlackFunds(address _blackListedUser) public onlyOwner {
  31. require(_blackListedUser != address(0x0), "_blackListedUser is the zero address");
  32. require(isBlackListed[_blackListedUser], "_blackListedUser isn't in black list");
  33.  
  34. uint256 dirtyFunds = balanceOf(_blackListedUser);
  35. super._burn(_blackListedUser, dirtyFunds);
  36. emit DestroyedBlackFunds(_blackListedUser, dirtyFunds);
  37. }
  38.  
  39. event DestroyedBlackFunds(address indexed _blackListedUser, uint256 _balance);
  40.  
  41. event AddedBlackList(address indexed _user);
  42.  
  43. event RemovedBlackList(address indexed _user);
  44.  
  45. }
  46.  
  47. contract UpgradedStandardToken is ERC20 {
  48. // those methods are called by the legacy contract
  49. // and they must ensure msg.sender to be the contract address
  50. function transferByLegacy(address from, address to, uint256 value) public returns (bool);
  51. function transferFromByLegacy(address sender, address from, address to, uint256 value) public returns (bool);
  52. function approveByLegacy(address owner, address spender, uint256 value) public returns (bool);
  53. function increaseAllowanceByLegacy(address owner, address spender, uint256 addedValue) public returns (bool);
  54. function decreaseAllowanceByLegacy(address owner, address spender, uint256 subtractedValue) public returns (bool);
  55. }
  56.  
  57. contract BGBPToken is ERC20, Pausable, BlackListableToken {
  58.  
  59. string public name;
  60. string public symbol;
  61. uint8 public decimals;
  62. address public upgradedAddress;
  63. bool public deprecated;
  64.  
  65. // The contract can be initialized with a number of tokens
  66. // All the tokens are deposited to the owner address
  67. //
  68. // @param _balance Initial supply of the contract
  69. // @param _name Token Name
  70. // @param _symbol Token symbol
  71. // @param _decimals Token decimals
  72. constructor(uint256 _initialSupply, string memory _name, string memory _symbol, uint8 _decimals) public {
  73. name = _name;
  74. symbol = _symbol;
  75. decimals = _decimals;
  76. deprecated = false;
  77. super._mint(msg.sender, _initialSupply);
  78. }
  79.  
  80. // Forward ERC20 methods to upgraded contract if this one is deprecated
  81. function transfer(address _to, uint256 _value) public whenNotPaused returns (bool success) {
  82. require(!isBlackListed[msg.sender], "can't transfer token from address in black list");
  83. require(!isBlackListed[_to], "can't transfer token to address in black list");
  84. if (deprecated) {
  85. success = UpgradedStandardToken(upgradedAddress).transferByLegacy(msg.sender, _to, _value);
  86. require(success, "failed to call upgraded contract");
  87. return true;
  88. } else {
  89. return super.transfer(_to, _value);
  90. }
  91. }
  92.  
  93. // Forward ERC20 methods to upgraded contract if this one is deprecated
  94. function transferFrom(address _from, address _to, uint256 _value) public whenNotPaused returns (bool success) {
  95. require(!isBlackListed[_from], "can't transfer token from address in black list");
  96. require(!isBlackListed[_to], "can't transfer token to address in black list");
  97. if (deprecated) {
  98. success = UpgradedStandardToken(upgradedAddress).transferFromByLegacy(msg.sender, _from, _to, _value);
  99. require(success, "failed to call upgraded contract");
  100. return true;
  101. } else {
  102. return super.transferFrom(_from, _to, _value);
  103. }
  104. }
  105.  
  106. // Forward ERC20 methods to upgraded contract if this one is deprecated
  107. function balanceOf(address who) public view returns (uint256) {
  108. if (deprecated) {
  109. return UpgradedStandardToken(upgradedAddress).balanceOf(who);
  110. } else {
  111. return super.balanceOf(who);
  112. }
  113. }
  114.  
  115. // Forward ERC20 methods to upgraded contract if this one is deprecated
  116. function approve(address _spender, uint256 _value) public whenNotPaused returns (bool success) {
  117. if (deprecated) {
  118. success = UpgradedStandardToken(upgradedAddress).approveByLegacy(msg.sender, _spender, _value);
  119. require(success, "failed to call upgraded contract");
  120. return true;
  121. } else {
  122. return super.approve(_spender, _value);
  123. }
  124. }
  125.  
  126. // Forward ERC20 methods to upgraded contract if this one is deprecated
  127. function increaseAllowance(address _spender, uint256 _addedValue) public whenNotPaused returns (bool success) {
  128. if (deprecated) {
  129. success = UpgradedStandardToken(upgradedAddress).increaseAllowanceByLegacy(msg.sender, _spender, _addedValue);
  130. require(success, "failed to call upgraded contract");
  131. return true;
  132. } else {
  133. return super.increaseAllowance(_spender, _addedValue);
  134. }
  135. }
  136.  
  137. // Forward ERC20 methods to upgraded contract if this one is deprecated
  138. function decreaseAllowance(address _spender, uint256 _subtractedValue) public whenNotPaused returns (bool success) {
  139. if (deprecated) {
  140. success = UpgradedStandardToken(upgradedAddress).decreaseAllowanceByLegacy(msg.sender, _spender, _subtractedValue);
  141. require(success, "failed to call upgraded contract");
  142. return true;
  143. } else {
  144. return super.decreaseAllowance(_spender, _subtractedValue);
  145. }
  146. }
  147.  
  148. // Forward ERC20 methods to upgraded contract if this one is deprecated
  149. function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
  150. if (deprecated) {
  151. return UpgradedStandardToken(upgradedAddress).allowance(_owner, _spender);
  152. } else {
  153. return super.allowance(_owner, _spender);
  154. }
  155. }
  156.  
  157. // deprecate current contract in favour of a new one
  158. function deprecate(address _upgradedAddress) public onlyOwner {
  159. require(_upgradedAddress != address(0x0), "_upgradedAddress is a zero address");
  160. require(!deprecated, "this contract has been deprecated");
  161.  
  162. deprecated = true;
  163. upgradedAddress = _upgradedAddress;
  164. emit Deprecate(_upgradedAddress);
  165. }
  166.  
  167. function totalSupply() public view returns (uint256) {
  168. if (deprecated) {
  169. return UpgradedStandardToken(upgradedAddress).totalSupply();
  170. } else {
  171. return super.totalSupply();
  172. }
  173. }
  174.  
  175. // Issue a new amount of tokens
  176. // these tokens are deposited into the owner address
  177. //
  178. // @param _amount Number of tokens to be issued
  179. function issue(uint256 amount) public onlyOwner whenNotPaused {
  180. require(!deprecated, "this contract has been deprecated");
  181.  
  182. super._mint(msg.sender, amount);
  183. emit Issue(amount);
  184. }
  185.  
  186. // Redeem tokens.
  187. // These tokens are withdrawn from the owner address
  188. // if the balance must be enough to cover the redeem
  189. // or the call will fail.
  190. // @param _amount Number of tokens to be issued
  191. function redeem(uint256 amount) public onlyOwner whenNotPaused {
  192. require(!deprecated, "this contract has been deprecated");
  193.  
  194. super._burn(msg.sender, amount);
  195. emit Redeem(amount);
  196. }
  197.  
  198. // Called when new token are issued
  199. event Issue(uint256 amount);
  200.  
  201. // Called when tokens are redeemed
  202. event Redeem(uint256 amount);
  203.  
  204. // Called when contract is deprecated
  205. event Deprecate(address indexed newAddress);
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement