├── LICENSE ├── README.md └── contracts └── LexSecurityTokenFactory.sol /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 lexDAO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Security Token Codebase 2 | Simple Restricted Funds Distribution Token (ERC-1404 + ERC-2222) 3 | 4 | [Mainnet Factory Deployment 🏭](https://etherscan.io/address/0x697D15d97af389A5f7922eFECEab39A688A74A99#code) 5 | Fee: 0.001 ETH (input into top payable field on etherscan) 6 | 7 | # How to use whitelisting 8 | 9 | Whitelists are made up of series of addresses. 10 | 11 | To create a whitelist, assign a series of addresses with a whitelist number. 12 | 13 | function addToWhitelist(address[] memory addressToAdd, uint8 whitelist) public onlyAdministrator { 14 | 15 | To add more addresses to the whitelist, call function with new addresses alongside the specified whitelist name. 16 | 17 | With every new whitelist number is a new set of addresses. 18 | 19 | # How to control whitelist interactions 20 | 21 | function updateOutboundWhitelistEnabled(uint8 sourceWhitelist, uint8 destinationWhitelist, bool newEnabledValue) public onlyAdministrator { 22 | 23 | Call this function to enable/disable the directional interaction of various addresses from certain assigned whitelists. 24 | -------------------------------------------------------------------------------- /contracts/LexSecurityTokenFactory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity 0.5.14; 2 | 3 | /* 4 | * @dev Provides information about the current execution context, including the 5 | * sender of the transaction and its data. While these are generally available 6 | * via msg.sender and msg.data, they should not be accessed in such a direct 7 | * manner, since when dealing with GSN meta-transactions the account sending and 8 | * paying for execution may not be the actual sender (as far as an application 9 | * is concerned). 10 | * 11 | * This contract is only required for intermediate, library-like contracts. 12 | */ 13 | contract Context { 14 | // Empty internal constructor, to prevent people from mistakenly deploying 15 | // an instance of this contract, which should be used via inheritance. 16 | constructor () internal { } 17 | 18 | function _msgSender() internal view returns (address payable) { 19 | return msg.sender; 20 | } 21 | 22 | function _msgData() internal view returns (bytes memory) { 23 | this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 24 | return msg.data; 25 | } 26 | } 27 | 28 | /** 29 | * @title Roles 30 | * @dev Library for managing addresses assigned to a Role. 31 | */ 32 | library Roles { 33 | struct Role { 34 | mapping (address => bool) bearer; 35 | } 36 | 37 | /** 38 | * @dev Give an account access to this role. 39 | */ 40 | function add(Role storage role, address account) internal { 41 | require(!has(role, account), "Roles: account already has role"); 42 | role.bearer[account] = true; 43 | } 44 | 45 | /** 46 | * @dev Remove an account's access to this role. 47 | */ 48 | function remove(Role storage role, address account) internal { 49 | require(has(role, account), "Roles: account does not have role"); 50 | role.bearer[account] = false; 51 | } 52 | 53 | /** 54 | * @dev Check if an account has this role. 55 | * @return bool 56 | */ 57 | function has(Role storage role, address account) internal view returns (bool) { 58 | require(account != address(0), "Roles: account is the zero address"); 59 | return role.bearer[account]; 60 | } 61 | } 62 | 63 | contract MinterRole is Context { 64 | using Roles for Roles.Role; 65 | 66 | event MinterAdded(address indexed account); 67 | event MinterRemoved(address indexed account); 68 | 69 | Roles.Role private _minters; 70 | 71 | modifier onlyMinter() { 72 | require(isMinter(_msgSender()), "MinterRole: caller does not have the Minter role"); 73 | _; 74 | } 75 | 76 | function isMinter(address account) public view returns (bool) { 77 | return _minters.has(account); 78 | } 79 | 80 | function addMinter(address account) public onlyMinter { 81 | _addMinter(account); 82 | } 83 | 84 | function renounceMinter() public { 85 | _removeMinter(_msgSender()); 86 | } 87 | 88 | function _addMinter(address account) internal { 89 | _minters.add(account); 90 | emit MinterAdded(account); 91 | } 92 | 93 | function _removeMinter(address account) internal { 94 | _minters.remove(account); 95 | emit MinterRemoved(account); 96 | } 97 | } 98 | 99 | /** 100 | * @dev Contract module which provides a basic access control mechanism, where 101 | * there is an account (an owner) that can be granted exclusive access to 102 | * specific functions. 103 | * 104 | * This module is used through inheritance. It will make available the modifier 105 | * `onlyOwner`, which can be applied to your functions to restrict their use to 106 | * the owner. 107 | */ 108 | contract Ownable is Context { 109 | address private _owner; 110 | 111 | event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); 112 | 113 | /** 114 | * @dev Returns the address of the current owner. 115 | */ 116 | function owner() public view returns (address) { 117 | return _owner; 118 | } 119 | 120 | /** 121 | * @dev Throws if called by any account other than the owner. 122 | */ 123 | modifier onlyOwner() { 124 | require(isOwner(), "Ownable: caller is not the owner"); 125 | _; 126 | } 127 | 128 | /** 129 | * @dev Returns true if the caller is the current owner. 130 | */ 131 | function isOwner() public view returns (bool) { 132 | return _msgSender() == _owner; 133 | } 134 | 135 | /** 136 | * @dev Leaves the contract without owner. It will not be possible to call 137 | * `onlyOwner` functions anymore. Can only be called by the current owner. 138 | * 139 | * NOTE: Renouncing ownership will leave the contract without an owner, 140 | * thereby removing any functionality that is only available to the owner. 141 | */ 142 | function renounceOwnership() public onlyOwner { 143 | emit OwnershipTransferred(_owner, address(0)); 144 | _owner = address(0); 145 | } 146 | 147 | /** 148 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 149 | * Can only be called by the current owner. 150 | */ 151 | function transferOwnership(address newOwner) public onlyOwner { 152 | _transferOwnership(newOwner); 153 | } 154 | 155 | /** 156 | * @dev Transfers ownership of the contract to a new account (`newOwner`). 157 | */ 158 | function _transferOwnership(address newOwner) internal { 159 | require(newOwner != address(0), "Ownable: new owner is the zero address"); 160 | emit OwnershipTransferred(_owner, newOwner); 161 | _owner = newOwner; 162 | } 163 | } 164 | 165 | /** 166 | Restrictions start off as enabled. 167 | Once they are disabled, they cannot be re-enabled. 168 | Only the owner may disable restrictions. 169 | */ 170 | contract Restrictable is Ownable { 171 | // State variable to track whether restrictions are enabled. Defaults to true. 172 | bool private _restrictionsEnabled = true; 173 | 174 | // Event emitted when flag is disabled 175 | event RestrictionsDisabled(address indexed owner); 176 | 177 | /** 178 | View function to determine if restrictions are enabled 179 | */ 180 | function isRestrictionEnabled() public view returns (bool) { 181 | return _restrictionsEnabled; 182 | } 183 | 184 | /** 185 | Function to update the enabled flag on restrictions to disabled. Only the owner should be able to call. 186 | This is a permanent change that cannot be undone 187 | */ 188 | function disableRestrictions() public onlyOwner { 189 | require(_restrictionsEnabled, "Restrictions are already disabled."); 190 | 191 | // Set the flag 192 | _restrictionsEnabled = false; 193 | 194 | // Trigger the event 195 | emit RestrictionsDisabled(msg.sender); 196 | } 197 | } 198 | 199 | /** 200 | This contract allows a list of administrators to be tracked. This list can then be enforced 201 | on functions with administrative permissions. Only the owner of the contract should be allowed 202 | to modify the administrator list. 203 | */ 204 | contract Administratable is Ownable { 205 | // The mapping to track administrator accounts - true is reserved for admin addresses. 206 | mapping (address => bool) public administrators; 207 | 208 | // Events to allow tracking add/remove. 209 | event AdminAdded(address indexed addedAdmin, address indexed addedBy); 210 | event AdminRemoved(address indexed removedAdmin, address indexed removedBy); 211 | 212 | /** 213 | Function modifier to enforce administrative permissions. 214 | */ 215 | modifier onlyAdministrator() { 216 | require(isAdministrator(msg.sender), "Calling account is not an administrator."); 217 | _; 218 | } 219 | 220 | /** 221 | Determine if the message sender is in the administrators list. 222 | */ 223 | function isAdministrator(address addressToTest) public view returns (bool) { 224 | return administrators[addressToTest]; 225 | } 226 | 227 | /** 228 | Add an admin to the list. This should only be callable by the owner of the contract. 229 | */ 230 | function addAdmin(address adminToAdd) public onlyOwner { 231 | // Verify the account is not already an admin 232 | require(administrators[adminToAdd] == false, "Account to be added to admin list is already an admin"); 233 | 234 | // Set the address mapping to true to indicate it is an administrator account. 235 | administrators[adminToAdd] = true; 236 | 237 | // Emit the event for any watchers. 238 | emit AdminAdded(adminToAdd, msg.sender); 239 | } 240 | 241 | /** 242 | Remove an admin from the list. This should only be callable by the owner of the contract. 243 | */ 244 | function removeAdmin(address adminToRemove) public onlyOwner { 245 | // Verify the account is an admin 246 | require(administrators[adminToRemove] == true, "Account to be removed from admin list is not already an admin"); 247 | 248 | // Set the address mapping to false to indicate it is NOT an administrator account. 249 | administrators[adminToRemove] = false; 250 | 251 | // Emit the event for any watchers. 252 | emit AdminRemoved(adminToRemove, msg.sender); 253 | } 254 | } 255 | 256 | /** 257 | Keeps track of whitelists and can check if sender and reciever are configured to allow a transfer. 258 | Only administrators can update the whitelists. 259 | Any address can only be a member of one whitelist at a time. 260 | */ 261 | contract Whitelistable is Administratable { 262 | /** 263 | Sets an address's whitelist ID. Only administrators should be allowed to update this. 264 | If an address is on an existing whitelist, it will just get updated to the new value (removed from previous). 265 | */ 266 | function addToWhitelist(address[] memory addressToAdd, uint8 whitelist) public onlyAdministrator { 267 | for (uint256 i = 0; i < addressToAdd.length; i++) { 268 | // Verify the whitelist is valid 269 | require(whitelist != NO_WHITELIST, "Invalid whitelist ID supplied"); 270 | 271 | // Save off the previous whitelist 272 | uint8 previousWhitelist = addressWhitelists[addressToAdd[i]]; 273 | 274 | // Set the address's whitelist ID 275 | addressWhitelists[addressToAdd[i]] = whitelist; 276 | 277 | // If the previous whitelist existed then we want to indicate it has been removed 278 | if(previousWhitelist != NO_WHITELIST) { 279 | // Emit the event for tracking 280 | emit AddressRemovedFromWhitelist(addressToAdd[i], previousWhitelist, msg.sender); 281 | } 282 | 283 | // Emit the event for new whitelist 284 | emit AddressAddedToWhitelist(addressToAdd[i], whitelist, msg.sender); 285 | } 286 | } 287 | 288 | /** 289 | Clears out an address's whitelist ID. Only administrators should be allowed to update this. 290 | */ 291 | function removeFromWhitelist(address[] memory addressToRemove) public onlyAdministrator { 292 | for (uint256 i = 0; i < addressToRemove.length; i++) { 293 | // Save off the previous whitelist 294 | uint8 previousWhitelist = addressWhitelists[addressToRemove[i]]; 295 | 296 | // Zero out the previous whitelist 297 | addressWhitelists[addressToRemove[i]] = NO_WHITELIST; 298 | 299 | // Emit the event for tracking 300 | emit AddressRemovedFromWhitelist(addressToRemove[i], previousWhitelist, msg.sender); 301 | } 302 | } 303 | 304 | // Zero is reserved for indicating it is not on a whitelist 305 | uint8 constant NO_WHITELIST = 0; 306 | 307 | // The mapping to keep track of which whitelist any address belongs to. 308 | // 0 is reserved for no whitelist and is the default for all addresses. 309 | mapping (address => uint8) public addressWhitelists; 310 | 311 | // The mapping to keep track of each whitelist's outbound whitelist flags. 312 | // Boolean flag indicates whether outbound transfers are enabled. 313 | mapping(uint8 => mapping (uint8 => bool)) public outboundWhitelistsEnabled; 314 | 315 | // Events to allow tracking add/remove. 316 | event AddressAddedToWhitelist(address indexed addedAddress, uint8 indexed whitelist, address indexed addedBy); 317 | event AddressRemovedFromWhitelist(address indexed removedAddress, uint8 indexed whitelist, address indexed removedBy); 318 | event OutboundWhitelistUpdated(address indexed updatedBy, uint8 indexed sourceWhitelist, uint8 indexed destinationWhitelist, bool from, bool to); 319 | 320 | /** 321 | Sets the flag to indicate whether source whitelist is allowed to send to destination whitelist. 322 | Only administrators should be allowed to update this. 323 | */ 324 | function updateOutboundWhitelistEnabled(uint8 sourceWhitelist, uint8 destinationWhitelist, bool newEnabledValue) public onlyAdministrator { 325 | // Get the old enabled flag 326 | bool oldEnabledValue = outboundWhitelistsEnabled[sourceWhitelist][destinationWhitelist]; 327 | 328 | // Update to the new value 329 | outboundWhitelistsEnabled[sourceWhitelist][destinationWhitelist] = newEnabledValue; 330 | 331 | // Emit event for tracking 332 | emit OutboundWhitelistUpdated(msg.sender, sourceWhitelist, destinationWhitelist, oldEnabledValue, newEnabledValue); 333 | } 334 | 335 | /** 336 | Determine if the sender is allowed to send to the receiver. 337 | The source whitelist must be enabled to send to the whitelist where the receiver exists. 338 | */ 339 | function checkWhitelistAllowed(address sender, address receiver) public view returns (bool) { 340 | // First get each address whitelist 341 | uint8 senderWhiteList = addressWhitelists[sender]; 342 | uint8 receiverWhiteList = addressWhitelists[receiver]; 343 | 344 | // If either address is not on a whitelist then the check should fail 345 | if(senderWhiteList == NO_WHITELIST || receiverWhiteList == NO_WHITELIST){ 346 | return false; 347 | } 348 | 349 | // Determine if the sending whitelist is allowed to send to the destination whitelist 350 | return outboundWhitelistsEnabled[senderWhiteList][receiverWhiteList]; 351 | } 352 | } 353 | 354 | /** 355 | * @dev Wrappers over Solidity's arithmetic operations with added overflow 356 | * checks. 357 | * 358 | * Arithmetic operations in Solidity wrap on overflow. This can easily result 359 | * in bugs, because programmers usually assume that an overflow raises an 360 | * error, which is the standard behavior in high level programming languages. 361 | * `SafeMath` restores this intuition by reverting the transaction when an 362 | * operation overflows. 363 | * 364 | * Using this library instead of the unchecked operations eliminates an entire 365 | * class of bugs, so it's recommended to use it always. 366 | */ 367 | library SafeMath { 368 | /** 369 | * @dev Returns the addition of two unsigned integers, reverting on 370 | * overflow. 371 | * 372 | * Counterpart to Solidity's `+` operator. 373 | * 374 | * Requirements: 375 | * - Addition cannot overflow. 376 | */ 377 | function add(uint256 a, uint256 b) internal pure returns (uint256) { 378 | uint256 c = a + b; 379 | require(c >= a, "SafeMath: addition overflow"); 380 | 381 | return c; 382 | } 383 | 384 | /** 385 | * @dev Returns the subtraction of two unsigned integers, reverting on 386 | * overflow (when the result is negative). 387 | * 388 | * Counterpart to Solidity's `-` operator. 389 | * 390 | * Requirements: 391 | * - Subtraction cannot overflow. 392 | */ 393 | function sub(uint256 a, uint256 b) internal pure returns (uint256) { 394 | return sub(a, b, "SafeMath: subtraction overflow"); 395 | } 396 | 397 | /** 398 | * @dev Returns the subtraction of two unsigned integers, reverting with custom message on 399 | * overflow (when the result is negative). 400 | * 401 | * Counterpart to Solidity's `-` operator. 402 | * 403 | * Requirements: 404 | * - Subtraction cannot overflow. 405 | */ 406 | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 407 | require(b <= a, errorMessage); 408 | uint256 c = a - b; 409 | 410 | return c; 411 | } 412 | 413 | /** 414 | * @dev Returns the multiplication of two unsigned integers, reverting on 415 | * overflow. 416 | * 417 | * Counterpart to Solidity's `*` operator. 418 | * 419 | * Requirements: 420 | * - Multiplication cannot overflow. 421 | */ 422 | function mul(uint256 a, uint256 b) internal pure returns (uint256) { 423 | // Gas optimization: this is cheaper than requiring 'a' not being zero, but the 424 | // benefit is lost if 'b' is also tested. 425 | // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 426 | if (a == 0) { 427 | return 0; 428 | } 429 | 430 | uint256 c = a * b; 431 | require(c / a == b, "SafeMath: multiplication overflow"); 432 | 433 | return c; 434 | } 435 | 436 | /** 437 | * @dev Returns the integer division of two unsigned integers. Reverts on 438 | * division by zero. The result is rounded towards zero. 439 | * 440 | * Counterpart to Solidity's `/` operator. Note: this function uses a 441 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 442 | * uses an invalid opcode to revert (consuming all remaining gas). 443 | * 444 | * Requirements: 445 | * - The divisor cannot be zero. 446 | */ 447 | function div(uint256 a, uint256 b) internal pure returns (uint256) { 448 | return div(a, b, "SafeMath: division by zero"); 449 | } 450 | 451 | /** 452 | * @dev Returns the integer division of two unsigned integers. Reverts with custom message on 453 | * division by zero. The result is rounded towards zero. 454 | * 455 | * Counterpart to Solidity's `/` operator. Note: this function uses a 456 | * `revert` opcode (which leaves remaining gas untouched) while Solidity 457 | * uses an invalid opcode to revert (consuming all remaining gas). 458 | * 459 | * Requirements: 460 | * - The divisor cannot be zero. 461 | */ 462 | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 463 | // Solidity only automatically asserts when dividing by 0 464 | require(b > 0, errorMessage); 465 | uint256 c = a / b; 466 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 467 | 468 | return c; 469 | } 470 | 471 | /** 472 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 473 | * Reverts when dividing by zero. 474 | * 475 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 476 | * opcode (which leaves remaining gas untouched) while Solidity uses an 477 | * invalid opcode to revert (consuming all remaining gas). 478 | * 479 | * Requirements: 480 | * - The divisor cannot be zero. 481 | */ 482 | function mod(uint256 a, uint256 b) internal pure returns (uint256) { 483 | return mod(a, b, "SafeMath: modulo by zero"); 484 | } 485 | 486 | /** 487 | * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), 488 | * Reverts with custom message when dividing by zero. 489 | * 490 | * Counterpart to Solidity's `%` operator. This function uses a `revert` 491 | * opcode (which leaves remaining gas untouched) while Solidity uses an 492 | * invalid opcode to revert (consuming all remaining gas). 493 | * 494 | * Requirements: 495 | * - The divisor cannot be zero. 496 | */ 497 | function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { 498 | require(b != 0, errorMessage); 499 | return a % b; 500 | } 501 | } 502 | 503 | /** 504 | * @title SafeMathUint 505 | * @dev Math operations with safety checks that revert on error 506 | */ 507 | library SafeMathUint { 508 | function toInt256Safe(uint256 a) internal pure returns (int256) { 509 | int256 b = int256(a); 510 | require(b >= 0); 511 | return b; 512 | } 513 | } 514 | 515 | /** 516 | * @title SafeMathInt 517 | * @dev Math operations with safety checks that revert on error 518 | * @dev SafeMath adapted for int256 519 | * Based on code of https://github.com/RequestNetwork/requestNetwork/blob/master/packages/requestNetworkSmartContracts/contracts/base/math/SafeMathInt.sol 520 | */ 521 | library SafeMathInt { 522 | function mul(int256 a, int256 b) internal pure returns (int256) { 523 | // Prevent overflow when multiplying INT256_MIN with -1 524 | // https://github.com/RequestNetwork/requestNetwork/issues/43 525 | require(!(a == - 2**255 && b == -1) && !(b == - 2**255 && a == -1)); 526 | 527 | int256 c = a * b; 528 | require((b == 0) || (c / b == a)); 529 | return c; 530 | } 531 | 532 | function div(int256 a, int256 b) internal pure returns (int256) { 533 | // Prevent overflow when dividing INT256_MIN by -1 534 | // https://github.com/RequestNetwork/requestNetwork/issues/43 535 | require(!(a == - 2**255 && b == -1) && (b > 0)); 536 | 537 | return a / b; 538 | } 539 | 540 | function sub(int256 a, int256 b) internal pure returns (int256) { 541 | require((b >= 0 && a - b <= a) || (b < 0 && a - b > a)); 542 | 543 | return a - b; 544 | } 545 | 546 | function add(int256 a, int256 b) internal pure returns (int256) { 547 | int256 c = a + b; 548 | require((b >= 0 && c >= a) || (b < 0 && c < a)); 549 | return c; 550 | } 551 | 552 | function toUint256Safe(int256 a) internal pure returns (uint256) { 553 | require(a >= 0); 554 | return uint256(a); 555 | } 556 | } 557 | 558 | /** 559 | * @dev Interface of the ERC20 standard as defined in the EIP. 560 | */ 561 | interface IERC20 { 562 | /** 563 | * @dev Returns the amount of tokens in existence. 564 | */ 565 | function totalSupply() external view returns (uint256); 566 | 567 | /** 568 | * @dev Returns the amount of tokens owned by `account`. 569 | */ 570 | function balanceOf(address account) external view returns (uint256); 571 | 572 | /** 573 | * @dev Moves `amount` tokens from the caller's account to `recipient`. 574 | * 575 | * Returns a boolean value indicating whether the operation succeeded. 576 | * 577 | * Emits a {Transfer} event. 578 | */ 579 | function transfer(address recipient, uint256 amount) external returns (bool); 580 | 581 | /** 582 | * @dev Returns the remaining number of tokens that `spender` will be 583 | * allowed to spend on behalf of `owner` through {transferFrom}. This is 584 | * zero by default. 585 | * 586 | * This value changes when {approve} or {transferFrom} are called. 587 | */ 588 | function allowance(address owner, address spender) external view returns (uint256); 589 | 590 | /** 591 | * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. 592 | * 593 | * Returns a boolean value indicating whether the operation succeeded. 594 | * 595 | * IMPORTANT: Beware that changing an allowance with this method brings the risk 596 | * that someone may use both the old and the new allowance by unfortunate 597 | * transaction ordering. One possible solution to mitigate this race 598 | * condition is to first reduce the spender's allowance to 0 and set the 599 | * desired value afterwards: 600 | * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 601 | * 602 | * Emits an {Approval} event. 603 | */ 604 | function approve(address spender, uint256 amount) external returns (bool); 605 | 606 | /** 607 | * @dev Moves `amount` tokens from `sender` to `recipient` using the 608 | * allowance mechanism. `amount` is then deducted from the caller's 609 | * allowance. 610 | * 611 | * Returns a boolean value indicating whether the operation succeeded. 612 | * 613 | * Emits a {Transfer} event. 614 | */ 615 | function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); 616 | 617 | /** 618 | * @dev Emitted when `value` tokens are moved from one account (`from`) to 619 | * another (`to`). 620 | * 621 | * Note that `value` may be zero. 622 | */ 623 | event Transfer(address indexed from, address indexed to, uint256 value); 624 | 625 | /** 626 | * @dev Emitted when the allowance of a `spender` for an `owner` is set by 627 | * a call to {approve}. `value` is the new allowance. 628 | */ 629 | event Approval(address indexed owner, address indexed spender, uint256 value); 630 | } 631 | 632 | /** 633 | * @dev Implementation of the {IERC20} interface. 634 | * 635 | * This implementation is agnostic to the way tokens are created. This means 636 | * that a supply mechanism has to be added in a derived contract using {_mint}. 637 | * For a generic mechanism see {ERC20Mintable}. 638 | * 639 | * TIP: For a detailed writeup see our guide 640 | * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How 641 | * to implement supply mechanisms]. 642 | * 643 | * We have followed general OpenZeppelin guidelines: functions revert instead 644 | * of returning `false` on failure. This behavior is nonetheless conventional 645 | * and does not conflict with the expectations of ERC20 applications. 646 | * 647 | * Additionally, an {Approval} event is emitted on calls to {transferFrom}. 648 | * This allows applications to reconstruct the allowance for all accounts just 649 | * by listening to said events. Other implementations of the EIP may not emit 650 | * these events, as it isn't required by the specification. 651 | * 652 | * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} 653 | * functions have been added to mitigate the well-known issues around setting 654 | * allowances. See {IERC20-approve}. 655 | */ 656 | contract ERC20 is Context, IERC20 { 657 | using SafeMath for uint256; 658 | 659 | mapping (address => uint256) private _balances; 660 | 661 | mapping (address => mapping (address => uint256)) private _allowances; 662 | 663 | uint256 private _totalSupply; 664 | 665 | /** 666 | * @dev See {IERC20-totalSupply}. 667 | */ 668 | function totalSupply() public view returns (uint256) { 669 | return _totalSupply; 670 | } 671 | 672 | /** 673 | * @dev See {IERC20-balanceOf}. 674 | */ 675 | function balanceOf(address account) public view returns (uint256) { 676 | return _balances[account]; 677 | } 678 | 679 | /** 680 | * @dev See {IERC20-transfer}. 681 | * 682 | * Requirements: 683 | * 684 | * - `recipient` cannot be the zero address. 685 | * - the caller must have a balance of at least `amount`. 686 | */ 687 | function transfer(address recipient, uint256 amount) public returns (bool) { 688 | _transfer(_msgSender(), recipient, amount); 689 | return true; 690 | } 691 | 692 | /** 693 | * @dev See {IERC20-allowance}. 694 | */ 695 | function allowance(address owner, address spender) public view returns (uint256) { 696 | return _allowances[owner][spender]; 697 | } 698 | 699 | /** 700 | * @dev See {IERC20-approve}. 701 | * 702 | * Requirements: 703 | * 704 | * - `spender` cannot be the zero address. 705 | */ 706 | function approve(address spender, uint256 amount) public returns (bool) { 707 | _approve(_msgSender(), spender, amount); 708 | return true; 709 | } 710 | 711 | /** 712 | * @dev See {IERC20-transferFrom}. 713 | * 714 | * Emits an {Approval} event indicating the updated allowance. This is not 715 | * required by the EIP. See the note at the beginning of {ERC20}; 716 | * 717 | * Requirements: 718 | * - `sender` and `recipient` cannot be the zero address. 719 | * - `sender` must have a balance of at least `amount`. 720 | * - the caller must have allowance for `sender`'s tokens of at least 721 | * `amount`. 722 | */ 723 | function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) { 724 | _transfer(sender, recipient, amount); 725 | _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance")); 726 | return true; 727 | } 728 | 729 | /** 730 | * @dev Atomically increases the allowance granted to `spender` by the caller. 731 | * 732 | * This is an alternative to {approve} that can be used as a mitigation for 733 | * problems described in {IERC20-approve}. 734 | * 735 | * Emits an {Approval} event indicating the updated allowance. 736 | * 737 | * Requirements: 738 | * 739 | * - `spender` cannot be the zero address. 740 | */ 741 | function increaseAllowance(address spender, uint256 addedValue) public returns (bool) { 742 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); 743 | return true; 744 | } 745 | 746 | /** 747 | * @dev Atomically decreases the allowance granted to `spender` by the caller. 748 | * 749 | * This is an alternative to {approve} that can be used as a mitigation for 750 | * problems described in {IERC20-approve}. 751 | * 752 | * Emits an {Approval} event indicating the updated allowance. 753 | * 754 | * Requirements: 755 | * 756 | * - `spender` cannot be the zero address. 757 | * - `spender` must have allowance for the caller of at least 758 | * `subtractedValue`. 759 | */ 760 | function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) { 761 | _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); 762 | return true; 763 | } 764 | 765 | /** 766 | * @dev Moves tokens `amount` from `sender` to `recipient`. 767 | * 768 | * This is internal function is equivalent to {transfer}, and can be used to 769 | * e.g. implement automatic token fees, slashing mechanisms, etc. 770 | * 771 | * Emits a {Transfer} event. 772 | * 773 | * Requirements: 774 | * 775 | * - `sender` cannot be the zero address. 776 | * - `recipient` cannot be the zero address. 777 | * - `sender` must have a balance of at least `amount`. 778 | */ 779 | function _transfer(address sender, address recipient, uint256 amount) internal { 780 | require(sender != address(0), "ERC20: transfer from the zero address"); 781 | require(recipient != address(0), "ERC20: transfer to the zero address"); 782 | 783 | _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance"); 784 | _balances[recipient] = _balances[recipient].add(amount); 785 | emit Transfer(sender, recipient, amount); 786 | } 787 | 788 | /** @dev Creates `amount` tokens and assigns them to `account`, increasing 789 | * the total supply. 790 | * 791 | * Emits a {Transfer} event with `from` set to the zero address. 792 | * 793 | * Requirements 794 | * 795 | * - `to` cannot be the zero address. 796 | */ 797 | function _mint(address account, uint256 amount) internal { 798 | require(account != address(0), "ERC20: mint to the zero address"); 799 | 800 | _totalSupply = _totalSupply.add(amount); 801 | _balances[account] = _balances[account].add(amount); 802 | emit Transfer(address(0), account, amount); 803 | } 804 | 805 | /** 806 | * @dev Destroys `amount` tokens from `account`, reducing the 807 | * total supply. 808 | * 809 | * Emits a {Transfer} event with `to` set to the zero address. 810 | * 811 | * Requirements 812 | * 813 | * - `account` cannot be the zero address. 814 | * - `account` must have at least `amount` tokens. 815 | */ 816 | function _burn(address account, uint256 amount) internal { 817 | require(account != address(0), "ERC20: burn from the zero address"); 818 | 819 | _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance"); 820 | _totalSupply = _totalSupply.sub(amount); 821 | emit Transfer(account, address(0), amount); 822 | } 823 | 824 | /** 825 | * @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens. 826 | * 827 | * This is internal function is equivalent to `approve`, and can be used to 828 | * e.g. set automatic allowances for certain subsystems, etc. 829 | * 830 | * Emits an {Approval} event. 831 | * 832 | * Requirements: 833 | * 834 | * - `owner` cannot be the zero address. 835 | * - `spender` cannot be the zero address. 836 | */ 837 | function _approve(address owner, address spender, uint256 amount) internal { 838 | require(owner != address(0), "ERC20: approve from the zero address"); 839 | require(spender != address(0), "ERC20: approve to the zero address"); 840 | 841 | _allowances[owner][spender] = amount; 842 | emit Approval(owner, spender, amount); 843 | } 844 | 845 | /** 846 | * @dev Destroys `amount` tokens from `account`.`amount` is then deducted 847 | * from the caller's allowance. 848 | * 849 | * See {_burn} and {_approve}. 850 | */ 851 | function _burnFrom(address account, uint256 amount) internal { 852 | _burn(account, amount); 853 | _approve(account, _msgSender(), _allowances[account][_msgSender()].sub(amount, "ERC20: burn amount exceeds allowance")); 854 | } 855 | } 856 | 857 | /** 858 | * @dev Optional functions from the ERC20 standard. 859 | */ 860 | contract ERC20Detailed is IERC20 { 861 | string private _name; 862 | string private _symbol; 863 | uint8 private _decimals; 864 | 865 | /** 866 | * @dev Sets the values for `name`, `symbol`, and `decimals`. All three of 867 | * these values are immutable: they can only be set once during 868 | * construction. 869 | */ 870 | constructor (string memory name, string memory symbol, uint8 decimals) public { 871 | _name = name; 872 | _symbol = symbol; 873 | _decimals = decimals; 874 | } 875 | 876 | /** 877 | * @dev Returns the name of the token. 878 | */ 879 | function name() public view returns (string memory) { 880 | return _name; 881 | } 882 | 883 | /** 884 | * @dev Returns the symbol of the token, usually a shorter version of the 885 | * name. 886 | */ 887 | function symbol() public view returns (string memory) { 888 | return _symbol; 889 | } 890 | 891 | /** 892 | * @dev Returns the number of decimals used to get its user representation. 893 | * For example, if `decimals` equals `2`, a balance of `505` tokens should 894 | * be displayed to a user as `5,05` (`505 / 10 ** 2`). 895 | * 896 | * Tokens usually opt for a value of 18, imitating the relationship between 897 | * Ether and Wei. 898 | * 899 | * > Note that this information is only used for _display_ purposes: it in 900 | * no way affects any of the arithmetic of the contract, including 901 | * `IERC20.balanceOf` and `IERC20.transfer`. 902 | */ 903 | function decimals() public view returns (uint8) { 904 | return _decimals; 905 | } 906 | } 907 | 908 | /** 909 | * @dev Extension of `ERC20` that adds a set of accounts with the `MinterRole`, 910 | * which have permission to mint (create) new tokens as they see fit. 911 | * 912 | * At construction, the deployer of the contract is the only minter. 913 | */ 914 | contract ERC20Mintable is MinterRole, ERC20 { 915 | /** 916 | * @dev See `ERC20._mint`. 917 | * 918 | * Requirements: 919 | * 920 | * - the caller must have the `MinterRole`. 921 | */ 922 | function mint(address account, uint256 amount) public onlyMinter returns (bool) { 923 | _mint(account, amount); 924 | return true; 925 | } 926 | } 927 | 928 | contract ERC1404 is IERC20 { 929 | /// @notice Detects if a transfer will be reverted and if so returns an appropriate reference code 930 | /// @param from Sending address 931 | /// @param to Receiving address 932 | /// @param value Amount of tokens being transferred 933 | /// @return Code by which to reference message for rejection reasoning 934 | /// @dev Overwrite with your custom transfer restriction logic 935 | function detectTransferRestriction (address from, address to, uint256 value) public view returns (uint8); 936 | 937 | /// @notice Returns a human-readable message for a given restriction code 938 | /// @param restrictionCode Identifier for looking up a message 939 | /// @return Text showing the restriction's reasoning 940 | /// @dev Overwrite with your custom message and restrictionCode handling 941 | function messageForTransferRestriction (uint8 restrictionCode) public view returns (string memory); 942 | } 943 | 944 | interface IFundsDistributionToken { 945 | /** 946 | * @dev Returns the total amount of funds a given address is able to withdraw currently. 947 | * @param owner Address of FundsDistributionToken holder 948 | * @return A uint256 representing the available funds for a given account 949 | */ 950 | function withdrawableFundsOf(address owner) external view returns (uint256); 951 | 952 | /** 953 | * @dev Withdraws all available funds for a FundsDistributionToken holder. 954 | */ 955 | function withdrawFunds() external; 956 | 957 | /** 958 | * @dev This event emits when new funds are distributed 959 | * @param by the address of the sender who distributed funds 960 | * @param fundsDistributed the amount of funds received for distribution 961 | */ 962 | event FundsDistributed(address indexed by, uint256 fundsDistributed); 963 | 964 | /** 965 | * @dev This event emits when distributed funds are withdrawn by a token holder. 966 | * @param by the address of the receiver of funds 967 | * @param fundsWithdrawn the amount of funds that were withdrawn 968 | */ 969 | event FundsWithdrawn(address indexed by, uint256 fundsWithdrawn); 970 | } 971 | 972 | /** 973 | * @title FundsDistributionToken 974 | * @author Johannes Escherich 975 | * @author Roger-Wu 976 | * @author Johannes Pfeffer 977 | * @author Tom Lam 978 | * @dev A mintable token that can represent claims on cash flow of arbitrary assets such as dividends, loan repayments, 979 | * fee or revenue shares among large numbers of token holders. Anyone can deposit funds, token holders can withdraw 980 | * their claims. 981 | * FundsDistributionToken (FDT) implements the accounting logic. FDT-Extension contracts implement methods for depositing and 982 | * withdrawing funds in Ether or according to a token standard such as ERC20, ERC223, ERC777. 983 | */ 984 | contract FundsDistributionToken is ERC20Mintable, IFundsDistributionToken { 985 | using SafeMath for uint256; 986 | using SafeMathUint for uint256; 987 | using SafeMathInt for int256; 988 | 989 | // optimize, see https://github.com/ethereum/EIPs/issues/1726#issuecomment-472352728 990 | uint256 constant internal pointsMultiplier = 2**128; 991 | uint256 internal pointsPerShare; 992 | 993 | mapping(address => int256) internal pointsCorrection; 994 | mapping(address => uint256) internal withdrawnFunds; 995 | 996 | /** 997 | * prev. distributeDividends 998 | * @notice Distributes funds to token holders. 999 | * @dev It reverts if the total supply of tokens is 0. 1000 | * It emits the `FundsDistributed` event if the amount of received ether is greater than 0. 1001 | * About undistributed funds: 1002 | * In each distribution, there is a small amount of funds which does not get distributed, 1003 | * which is `(msg.value * pointsMultiplier) % totalSupply()`. 1004 | * With a well-chosen `pointsMultiplier`, the amount funds that are not getting distributed 1005 | * in a distribution can be less than 1 (base unit). 1006 | * We can actually keep track of the undistributed ether in a distribution 1007 | * and try to distribute it in the next distribution ....... todo implement 1008 | */ 1009 | function _distributeFunds(uint256 value) internal { 1010 | require(totalSupply() > 0, "FundsDistributionToken._distributeFunds: SUPPLY_IS_ZERO"); 1011 | 1012 | if (value > 0) { 1013 | pointsPerShare = pointsPerShare.add( 1014 | value.mul(pointsMultiplier) / totalSupply() 1015 | ); 1016 | emit FundsDistributed(msg.sender, value); 1017 | } 1018 | } 1019 | 1020 | /** 1021 | * prev. withdrawDividend 1022 | * @notice Prepares funds withdrawal 1023 | * @dev It emits a `FundsWithdrawn` event if the amount of withdrawn ether is greater than 0. 1024 | */ 1025 | function _prepareWithdraw() internal returns (uint256) { 1026 | uint256 _withdrawableDividend = withdrawableFundsOf(msg.sender); 1027 | 1028 | withdrawnFunds[msg.sender] = withdrawnFunds[msg.sender].add(_withdrawableDividend); 1029 | 1030 | emit FundsWithdrawn(msg.sender, _withdrawableDividend); 1031 | 1032 | return _withdrawableDividend; 1033 | } 1034 | 1035 | /** 1036 | * prev. withdrawableDividendOf 1037 | * @notice View the amount of funds that an address can withdraw. 1038 | * @param _owner The address of a token holder. 1039 | * @return The amount funds that `_owner` can withdraw. 1040 | */ 1041 | function withdrawableFundsOf(address _owner) public view returns(uint256) { 1042 | return accumulativeFundsOf(_owner).sub(withdrawnFunds[_owner]); 1043 | } 1044 | 1045 | /** 1046 | * prev. withdrawnDividendOf 1047 | * @notice View the amount of funds that an address has withdrawn. 1048 | * @param _owner The address of a token holder. 1049 | * @return The amount of funds that `_owner` has withdrawn. 1050 | */ 1051 | function withdrawnFundsOf(address _owner) public view returns(uint256) { 1052 | return withdrawnFunds[_owner]; 1053 | } 1054 | 1055 | /** 1056 | * prev. accumulativeDividendOf 1057 | * @notice View the amount of funds that an address has earned in total. 1058 | * @dev accumulativeFundsOf(_owner) = withdrawableFundsOf(_owner) + withdrawnFundsOf(_owner) 1059 | * = (pointsPerShare * balanceOf(_owner) + pointsCorrection[_owner]) / pointsMultiplier 1060 | * @param _owner The address of a token holder. 1061 | * @return The amount of funds that `_owner` has earned in total. 1062 | */ 1063 | function accumulativeFundsOf(address _owner) public view returns(uint256) { 1064 | return pointsPerShare.mul(balanceOf(_owner)).toInt256Safe() 1065 | .add(pointsCorrection[_owner]).toUint256Safe() / pointsMultiplier; 1066 | } 1067 | 1068 | /** 1069 | * @dev Internal function that transfer tokens from one address to another. 1070 | * Update pointsCorrection to keep funds unchanged. 1071 | * @param from The address to transfer from. 1072 | * @param to The address to transfer to. 1073 | * @param value The amount to be transferred. 1074 | */ 1075 | function _transfer(address from, address to, uint256 value) internal { 1076 | super._transfer(from, to, value); 1077 | 1078 | int256 _magCorrection = pointsPerShare.mul(value).toInt256Safe(); 1079 | pointsCorrection[from] = pointsCorrection[from].add(_magCorrection); 1080 | pointsCorrection[to] = pointsCorrection[to].sub(_magCorrection); 1081 | } 1082 | 1083 | /** 1084 | * @dev Internal function that mints tokens to an account. 1085 | * Update pointsCorrection to keep funds unchanged. 1086 | * @param account The account that will receive the created tokens. 1087 | * @param value The amount that will be created. 1088 | */ 1089 | function _mint(address account, uint256 value) internal { 1090 | super._mint(account, value); 1091 | 1092 | pointsCorrection[account] = pointsCorrection[account] 1093 | .sub( (pointsPerShare.mul(value)).toInt256Safe() ); 1094 | } 1095 | 1096 | /** 1097 | * @dev Internal function that burns an amount of the token of a given account. 1098 | * Update pointsCorrection to keep funds unchanged. 1099 | * @param account The account whose tokens will be burnt. 1100 | * @param value The amount that will be burnt. 1101 | */ 1102 | function _burn(address account, uint256 value) internal { 1103 | super._burn(account, value); 1104 | 1105 | pointsCorrection[account] = pointsCorrection[account] 1106 | .add( (pointsPerShare.mul(value)).toInt256Safe() ); 1107 | } 1108 | } 1109 | 1110 | interface IUniswap { // brief interface to call Uniswap protocol ( . . . ) 1111 | function createExchange(address token) external returns (address payable); 1112 | function getExchange(address token) external view returns (address payable); 1113 | } 1114 | 1115 | contract LexSecurityToken is Restrictable, Whitelistable, ERC20Detailed, ERC1404, FundsDistributionToken { 1116 | using SafeMathUint for uint256; 1117 | using SafeMathInt for int256; 1118 | 1119 | // contextualizes token deployment 1120 | string public stamp; 1121 | 1122 | // ERC1404 Error codes and messages 1123 | uint8 public constant SUCCESS_CODE = 0; 1124 | uint8 public constant FAILURE_NON_WHITELIST = 1; 1125 | string public constant SUCCESS_MESSAGE = "SUCCESS"; 1126 | string public constant FAILURE_NON_WHITELIST_MESSAGE = "The transfer was restricted due to whitelist configuration."; 1127 | string public constant UNKNOWN_ERROR = "Unknown Error Code"; 1128 | 1129 | // token in which the funds can be sent to the FundsDistributionToken 1130 | IERC20 public fundsToken; 1131 | 1132 | // balance of fundsToken that the FundsDistributionToken currently holds 1133 | uint256 public fundsTokenBalance; 1134 | 1135 | // Uniswap exchange protocol references 1136 | IUniswap private uniswapFactory = IUniswap(0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95); 1137 | address public uniswapExchange; 1138 | 1139 | constructor( 1140 | string memory name, 1141 | string memory symbol, 1142 | string memory _stamp, 1143 | uint8 decimals, 1144 | address _fundsToken, 1145 | address[] memory ownership, 1146 | uint256[] memory issuance 1147 | ) 1148 | public 1149 | ERC20Detailed(name, symbol, decimals) 1150 | { 1151 | require(address(_fundsToken) != address(0), "LexSecurityToken: INVALID_FUNDS_TOKEN_ADDRESS"); 1152 | 1153 | for (uint256 i = 0; i < ownership.length; i++) { 1154 | _mint(ownership[i], issuance[i]); 1155 | addressWhitelists[ownership[i]] = 1; 1156 | } 1157 | 1158 | stamp = _stamp; 1159 | fundsToken = IERC20(_fundsToken); 1160 | 1161 | uniswapFactory.createExchange(address(this)); 1162 | address _uniswapExchange = uniswapFactory.getExchange(address(this)); 1163 | uniswapExchange = _uniswapExchange; 1164 | 1165 | administrators[ownership[0]] = true; 1166 | addressWhitelists[uniswapExchange] = 1; 1167 | outboundWhitelistsEnabled[1][1] = true; 1168 | _addMinter(ownership[0]); 1169 | _transferOwnership(ownership[0]); 1170 | } 1171 | 1172 | /** 1173 | This function detects whether a transfer should be restricted and not allowed. 1174 | If the function returns SUCCESS_CODE (0) then it should be allowed. 1175 | */ 1176 | function detectTransferRestriction (address from, address to, uint256) 1177 | public 1178 | view 1179 | returns (uint8) 1180 | { 1181 | // If the restrictions have been disabled by the owner, then just return success 1182 | // Logic defined in Restrictable parent class 1183 | if(!isRestrictionEnabled()) { 1184 | return SUCCESS_CODE; 1185 | } 1186 | 1187 | // If the contract owner is transferring, then ignore restrictions 1188 | if(from == owner()) { 1189 | return SUCCESS_CODE; 1190 | } 1191 | 1192 | // Restrictions are enabled, so verify the whitelist config allows the transfer. 1193 | // Logic defined in Whitelistable parent class 1194 | if(!checkWhitelistAllowed(from, to)) { 1195 | return FAILURE_NON_WHITELIST; 1196 | } 1197 | 1198 | // If no restrictions were triggered return success 1199 | return SUCCESS_CODE; 1200 | } 1201 | 1202 | /** 1203 | This function allows a wallet or other client to get a human readable string to show 1204 | a user if a transfer was restricted. It should return enough information for the user 1205 | to know why it failed. 1206 | */ 1207 | function messageForTransferRestriction (uint8 restrictionCode) 1208 | public 1209 | view 1210 | returns (string memory) 1211 | { 1212 | if (restrictionCode == SUCCESS_CODE) { 1213 | return SUCCESS_MESSAGE; 1214 | } 1215 | 1216 | if (restrictionCode == FAILURE_NON_WHITELIST) { 1217 | return FAILURE_NON_WHITELIST_MESSAGE; 1218 | } 1219 | 1220 | // An unknown error code was passed in. 1221 | return UNKNOWN_ERROR; 1222 | } 1223 | 1224 | /** 1225 | Evaluates whether a transfer should be allowed or not. 1226 | */ 1227 | modifier notRestricted (address from, address to, uint256 value) { 1228 | uint8 restrictionCode = detectTransferRestriction(from, to, value); 1229 | require(restrictionCode == SUCCESS_CODE, messageForTransferRestriction(restrictionCode)); 1230 | _; 1231 | } 1232 | 1233 | /** 1234 | Overrides the parent class token transfer function to enforce restrictions. 1235 | */ 1236 | function transfer (address to, uint256 value) 1237 | public 1238 | notRestricted(msg.sender, to, value) 1239 | returns (bool success) 1240 | { 1241 | success = super.transfer(to, value); 1242 | } 1243 | 1244 | /** 1245 | Overrides the parent class token transferFrom function to enforce restrictions. 1246 | */ 1247 | function transferFrom (address from, address to, uint256 value) 1248 | public 1249 | notRestricted(from, to, value) 1250 | returns (bool success) 1251 | { 1252 | success = super.transferFrom(from, to, value); 1253 | } 1254 | 1255 | /** 1256 | * @notice Withdraws all available funds for a token holder 1257 | */ 1258 | function withdrawFunds() 1259 | external 1260 | { 1261 | uint256 withdrawableFunds = _prepareWithdraw(); 1262 | 1263 | require(fundsToken.transfer(msg.sender, withdrawableFunds), "LexSecurityToken: TRANSFER_FAILED"); 1264 | 1265 | _updateFundsTokenBalance(); 1266 | } 1267 | 1268 | /** 1269 | * @dev Updates the current funds token balance 1270 | * and returns the difference of new and previous funds token balances 1271 | * @return A int256 representing the difference of the new and previous funds token balance 1272 | */ 1273 | function _updateFundsTokenBalance() internal returns (int256) { 1274 | uint256 prevFundsTokenBalance = fundsTokenBalance; 1275 | 1276 | fundsTokenBalance = fundsToken.balanceOf(address(this)); 1277 | 1278 | return int256(fundsTokenBalance).sub(int256(prevFundsTokenBalance)); 1279 | } 1280 | 1281 | /** 1282 | * @notice Register a payment of funds in tokens. May be called directly after a deposit is made. 1283 | * @dev Calls _updateFundsTokenBalance(), whereby the contract computes the delta of the previous and the new 1284 | * funds token balance and increments the total received funds (cumulative) by delta by calling _registerFunds() 1285 | */ 1286 | function updateFundsReceived() external { 1287 | int256 newFunds = _updateFundsTokenBalance(); 1288 | 1289 | if (newFunds > 0) { 1290 | _distributeFunds(newFunds.toUint256Safe()); 1291 | } 1292 | } 1293 | 1294 | /*************** 1295 | LEXDAO RECOVERY 1296 | ***************/ 1297 | function lexDAOtransfer(address from, address to, uint256 amount) public returns (bool) { 1298 | require(msg.sender == 0x97103fda00a2b47EaC669568063C00e65866a633); 1299 | _transfer(from, to, amount); // lexDAO governance transfers token balance 1300 | return true; 1301 | } 1302 | } 1303 | 1304 | contract LexSecurityTokenFactory { 1305 | // presented by OpenESQ || lexDAO LLC ~ DAO-Governed ERC-1404_2222 Factory ~ Use at own risk! 1306 | uint8 public version = 1; 1307 | uint256 public factoryFee; 1308 | address payable public lexDAO; 1309 | 1310 | constructor(uint256 _factoryFee, address payable _lexDAO) public { 1311 | factoryFee = _factoryFee; 1312 | lexDAO = _lexDAO; 1313 | } 1314 | 1315 | function newLexSecurityToken( 1316 | string memory name, 1317 | string memory symbol, 1318 | string memory _stamp, 1319 | uint8 decimals, 1320 | address _fundsToken, 1321 | address[] memory ownership, 1322 | uint256[] memory issuance 1323 | ) payable public { 1324 | require(msg.value == factoryFee); 1325 | 1326 | new LexSecurityToken( 1327 | name, 1328 | symbol, 1329 | _stamp, 1330 | decimals, 1331 | _fundsToken, 1332 | ownership, 1333 | issuance); 1334 | 1335 | lexDAO.transfer(msg.value); 1336 | } 1337 | } 1338 | --------------------------------------------------------------------------------