1// SPDX-License-Identifier: MIT2 3pragma solidity ^0.8.6;4 5/**6 * @dev External interface of AccessControl declared to support ERC165 detection.7 */8interface IAccessControl {9 /**10 * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`11 *12 * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite13 * {RoleAdminChanged} not being emitted signaling this.14 *15 * _Available since v3.1._16 */17 event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);18 19 /**20 * @dev Emitted when `account` is granted `role`.21 *22 * `sender` is the account that originated the contract call, an admin role23 * bearer except when using {AccessControl-_setupRole}.24 */25 event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);26 27 /**28 * @dev Emitted when `account` is revoked `role`.29 *30 * `sender` is the account that originated the contract call:31 * - if using `revokeRole`, it is the admin role bearer32 * - if using `renounceRole`, it is the role bearer (i.e. `account`)33 */34 event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);35 36 /**37 * @dev Returns `true` if `account` has been granted `role`.38 */39 function hasRole(bytes32 role, address account) external view returns (bool);40 41 /**42 * @dev Returns the admin role that controls `role`. See {grantRole} and43 * {revokeRole}.44 *45 * To change a role's admin, use {AccessControl-_setRoleAdmin}.46 */47 function getRoleAdmin(bytes32 role) external view returns (bytes32);48 49 /**50 * @dev Grants `role` to `account`.51 *52 * If `account` had not been already granted `role`, emits a {RoleGranted}53 * event.54 *55 * Requirements:56 *57 * - the caller must have ``role``'s admin role.58 */59 function grantRole(bytes32 role, address account) external;60 61 /**62 * @dev Revokes `role` from `account`.63 *64 * If `account` had been granted `role`, emits a {RoleRevoked} event.65 *66 * Requirements:67 *68 * - the caller must have ``role``'s admin role.69 */70 function revokeRole(bytes32 role, address account) external;71 72 /**73 * @dev Revokes `role` from the calling account.74 *75 * Roles are often managed via {grantRole} and {revokeRole}: this function's76 * purpose is to provide a mechanism for accounts to lose their privileges77 * if they are compromised (such as when a trusted device is misplaced).78 *79 * If the calling account had been granted `role`, emits a {RoleRevoked}80 * event.81 *82 * Requirements:83 *84 * - the caller must be `account`.85 */86 function renounceRole(bytes32 role, address account) external;87}88 89/**90 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.91 */92interface IAccessControlEnumerable is IAccessControl {93 /**94 * @dev Returns one of the accounts that have `role`. `index` must be a95 * value between 0 and {getRoleMemberCount}, non-inclusive.96 *97 * Role bearers are not sorted in any particular way, and their ordering may98 * change at any point.99 *100 * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure101 * you perform all queries on the same block. See the following102 * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]103 * for more information.104 */105 function getRoleMember(bytes32 role, uint256 index) external view returns (address);106 107 /**108 * @dev Returns the number of accounts that have `role`. Can be used109 * together with {getRoleMember} to enumerate all bearers of a role.110 */111 function getRoleMemberCount(bytes32 role) external view returns (uint256);112}113 114/**115 * @dev Provides information about the current execution context, including the116 * sender of the transaction and its data. While these are generally available117 * via msg.sender and msg.data, they should not be accessed in such a direct118 * manner, since when dealing with meta-transactions the account sending and119 * paying for execution may not be the actual sender (as far as an application120 * is concerned).121 *122 * This contract is only required for intermediate, library-like contracts.123 */124abstract contract Context {125 function _msgSender() internal view virtual returns (address) {126 return msg.sender;127 }128 129 function _msgData() internal view virtual returns (bytes calldata) {130 return msg.data;131 }132}133 134/**135 * @dev String operations.136 */137library Strings {138 bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";139 140 /**141 * @dev Converts a `uint256` to its ASCII `string` decimal representation.142 */143 function toString(uint256 value) internal pure returns (string memory) {144 // Inspired by OraclizeAPI's implementation - MIT licence145 // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol146 147 if (value == 0) {148 return "0";149 }150 uint256 temp = value;151 uint256 digits;152 while (temp != 0) {153 digits++;154 temp /= 10;155 }156 bytes memory buffer = new bytes(digits);157 while (value != 0) {158 digits -= 1;159 buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));160 value /= 10;161 }162 return string(buffer);163 }164 165 /**166 * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.167 */168 function toHexString(uint256 value) internal pure returns (string memory) {169 if (value == 0) {170 return "0x00";171 }172 uint256 temp = value;173 uint256 length = 0;174 while (temp != 0) {175 length++;176 temp >>= 8;177 }178 return toHexString(value, length);179 }180 181 /**182 * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.183 */184 function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {185 bytes memory buffer = new bytes(2 * length + 2);186 buffer[0] = "0";187 buffer[1] = "x";188 for (uint256 i = 2 * length + 1; i > 1; --i) {189 buffer[i] = _HEX_SYMBOLS[value & 0xf];190 value >>= 4;191 }192 require(value == 0, "Strings: hex length insufficient");193 return string(buffer);194 }195}196 197interface IERC165 {198 /**199 * @dev Returns true if this contract implements the interface defined by200 * `interfaceId`. See the corresponding201 * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]202 * to learn more about how these ids are created.203 *204 * This function call must use less than 30 000 gas.205 */206 function supportsInterface(bytes4 interfaceId) external view returns (bool);207}208 209/**210 * @dev Implementation of the {IERC165} interface.211 *212 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check213 * for the additional interface id that will be supported. For example:214 *215 * ```solidity216 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {217 * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);218 * }219 * ```220 *221 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.222 */223abstract contract ERC165 is IERC165 {224 /**225 * @dev See {IERC165-supportsInterface}.226 */227 function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {228 return interfaceId == type(IERC165).interfaceId;229 }230}231 232/**233 * @dev Contract module that allows children to implement role-based access234 * control mechanisms. This is a lightweight version that doesn't allow enumerating role235 * members except through off-chain means by accessing the contract event logs. Some236 * applications may benefit from on-chain enumerability, for those cases see237 * {AccessControlEnumerable}.238 *239 * Roles are referred to by their `bytes32` identifier. These should be exposed240 * in the external API and be unique. The best way to achieve this is by241 * using `public constant` hash digests:242 *243 * ```244 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");245 * ```246 *247 * Roles can be used to represent a set of permissions. To restrict access to a248 * function call, use {hasRole}:249 *250 * ```251 * function foo() public {252 * require(hasRole(MY_ROLE, msg.sender));253 * ...254 * }255 * ```256 *257 * Roles can be granted and revoked dynamically via the {grantRole} and258 * {revokeRole} functions. Each role has an associated admin role, and only259 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.260 *261 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means262 * that only accounts with this role will be able to grant or revoke other263 * roles. More complex role relationships can be created by using264 * {_setRoleAdmin}.265 *266 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to267 * grant and revoke this role. Extra precautions should be taken to secure268 * accounts that have been granted it.269 */270abstract contract AccessControl is Context, IAccessControl, ERC165 {271 struct RoleData {272 mapping(address => bool) members;273 bytes32 adminRole;274 }275 276 mapping(bytes32 => RoleData) private _roles;277 278 bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;279 280 /**281 * @dev Modifier that checks that an account has a specific role. Reverts282 * with a standardized message including the required role.283 *284 * The format of the revert reason is given by the following regular expression:285 *286 * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/287 *288 * _Available since v4.1._289 */290 modifier onlyRole(bytes32 role) {291 _checkRole(role, _msgSender());292 _;293 }294 295 /**296 * @dev See {IERC165-supportsInterface}.297 */298 function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {299 return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);300 }301 302 /**303 * @dev Returns `true` if `account` has been granted `role`.304 */305 function hasRole(bytes32 role, address account) public view override returns (bool) {306 return _roles[role].members[account];307 }308 309 /**310 * @dev Revert with a standard message if `account` is missing `role`.311 *312 * The format of the revert reason is given by the following regular expression:313 *314 * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/315 */316 function _checkRole(bytes32 role, address account) internal view {317 if (!hasRole(role, account)) {318 revert(319 string(320 abi.encodePacked(321 "AccessControl: account ",322 Strings.toHexString(uint160(account), 20),323 " is missing role ",324 Strings.toHexString(uint256(role), 32)325 )326 )327 );328 }329 }330 331 /**332 * @dev Returns the admin role that controls `role`. See {grantRole} and333 * {revokeRole}.334 *335 * To change a role's admin, use {_setRoleAdmin}.336 */337 function getRoleAdmin(bytes32 role) public view override returns (bytes32) {338 return _roles[role].adminRole;339 }340 341 /**342 * @dev Grants `role` to `account`.343 *344 * If `account` had not been already granted `role`, emits a {RoleGranted}345 * event.346 *347 * Requirements:348 *349 * - the caller must have ``role``'s admin role.350 */351 function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {352 _grantRole(role, account);353 }354 355 /**356 * @dev Revokes `role` from `account`.357 *358 * If `account` had been granted `role`, emits a {RoleRevoked} event.359 *360 * Requirements:361 *362 * - the caller must have ``role``'s admin role.363 */364 function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {365 _revokeRole(role, account);366 }367 368 /**369 * @dev Revokes `role` from the calling account.370 *371 * Roles are often managed via {grantRole} and {revokeRole}: this function's372 * purpose is to provide a mechanism for accounts to lose their privileges373 * if they are compromised (such as when a trusted device is misplaced).374 *375 * If the calling account had been granted `role`, emits a {RoleRevoked}376 * event.377 *378 * Requirements:379 *380 * - the caller must be `account`.381 */382 function renounceRole(bytes32 role, address account) public virtual override {383 require(account == _msgSender(), "AccessControl: can only renounce roles for self");384 385 _revokeRole(role, account);386 }387 388 /**389 * @dev Grants `role` to `account`.390 *391 * If `account` had not been already granted `role`, emits a {RoleGranted}392 * event. Note that unlike {grantRole}, this function doesn't perform any393 * checks on the calling account.394 *395 * [WARNING]396 * ====397 * This function should only be called from the constructor when setting398 * up the initial roles for the system.399 *400 * Using this function in any other way is effectively circumventing the admin401 * system imposed by {AccessControl}.402 * ====403 */404 function _setupRole(bytes32 role, address account) internal virtual {405 _grantRole(role, account);406 }407 408 /**409 * @dev Sets `adminRole` as ``role``'s admin role.410 *411 * Emits a {RoleAdminChanged} event.412 */413 function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {414 bytes32 previousAdminRole = getRoleAdmin(role);415 _roles[role].adminRole = adminRole;416 emit RoleAdminChanged(role, previousAdminRole, adminRole);417 }418 419 function _grantRole(bytes32 role, address account) private {420 if (!hasRole(role, account)) {421 _roles[role].members[account] = true;422 emit RoleGranted(role, account, _msgSender());423 }424 }425 426 function _revokeRole(bytes32 role, address account) private {427 if (hasRole(role, account)) {428 _roles[role].members[account] = false;429 emit RoleRevoked(role, account, _msgSender());430 }431 }432}433 434/**435 * @dev Library for managing436 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive437 * types.438 *439 * Sets have the following properties:440 *441 * - Elements are added, removed, and checked for existence in constant time442 * (O(1)).443 * - Elements are enumerated in O(n). No guarantees are made on the ordering.444 *445 * ```446 * contract Example {447 * // Add the library methods448 * using EnumerableSet for EnumerableSet.AddressSet;449 *450 * // Declare a set state variable451 * EnumerableSet.AddressSet private mySet;452 * }453 * ```454 *455 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)456 * and `uint256` (`UintSet`) are supported.457 */458library EnumerableSet {459 // To implement this library for multiple types with as little code460 // repetition as possible, we write it in terms of a generic Set type with461 // bytes32 values.462 // The Set implementation uses private functions, and user-facing463 // implementations (such as AddressSet) are just wrappers around the464 // underlying Set.465 // This means that we can only create new EnumerableSets for types that fit466 // in bytes32.467 468 struct Set {469 // Storage of set values470 bytes32[] _values;471 // Position of the value in the `values` array, plus 1 because index 0472 // means a value is not in the set.473 mapping(bytes32 => uint256) _indexes;474 }475 476 /**477 * @dev Add a value to a set. O(1).478 *479 * Returns true if the value was added to the set, that is if it was not480 * already present.481 */482 function _add(Set storage set, bytes32 value) private returns (bool) {483 if (!_contains(set, value)) {484 set._values.push(value);485 // The value is stored at length-1, but we add 1 to all indexes486 // and use 0 as a sentinel value487 set._indexes[value] = set._values.length;488 return true;489 } else {490 return false;491 }492 }493 494 /**495 * @dev Removes a value from a set. O(1).496 *497 * Returns true if the value was removed from the set, that is if it was498 * present.499 */500 function _remove(Set storage set, bytes32 value) private returns (bool) {501 // We read and store the value's index to prevent multiple reads from the same storage slot502 uint256 valueIndex = set._indexes[value];503 504 if (valueIndex != 0) {505 // Equivalent to contains(set, value)506 // To delete an element from the _values array in O(1), we swap the element to delete with the last one in507 // the array, and then remove the last element (sometimes called as 'swap and pop').508 // This modifies the order of the array, as noted in {at}.509 510 uint256 toDeleteIndex = valueIndex - 1;511 uint256 lastIndex = set._values.length - 1;512 513 if (lastIndex != toDeleteIndex) {514 bytes32 lastvalue = set._values[lastIndex];515 516 // Move the last value to the index where the value to delete is517 set._values[toDeleteIndex] = lastvalue;518 // Update the index for the moved value519 set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex520 }521 522 // Delete the slot where the moved value was stored523 set._values.pop();524 525 // Delete the index for the deleted slot526 delete set._indexes[value];527 528 return true;529 } else {530 return false;531 }532 }533 534 /**535 * @dev Returns true if the value is in the set. O(1).536 */537 function _contains(Set storage set, bytes32 value) private view returns (bool) {538 return set._indexes[value] != 0;539 }540 541 /**542 * @dev Returns the number of values on the set. O(1).543 */544 function _length(Set storage set) private view returns (uint256) {545 return set._values.length;546 }547 548 /**549 * @dev Returns the value stored at position `index` in the set. O(1).550 *551 * Note that there are no guarantees on the ordering of values inside the552 * array, and it may change when more values are added or removed.553 *554 * Requirements:555 *556 * - `index` must be strictly less than {length}.557 */558 function _at(Set storage set, uint256 index) private view returns (bytes32) {559 return set._values[index];560 }561 562 /**563 * @dev Return the entire set in an array564 *565 * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed566 * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that567 * this function has an unbounded cost, and using it as part of a state-changing function may render the function568 * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.569 */570 function _values(Set storage set) private view returns (bytes32[] memory) {571 return set._values;572 }573 574 // Bytes32Set575 576 struct Bytes32Set {577 Set _inner;578 }579 580 /**581 * @dev Add a value to a set. O(1).582 *583 * Returns true if the value was added to the set, that is if it was not584 * already present.585 */586 function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {587 return _add(set._inner, value);588 }589 590 /**591 * @dev Removes a value from a set. O(1).592 *593 * Returns true if the value was removed from the set, that is if it was594 * present.595 */596 function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {597 return _remove(set._inner, value);598 }599 600 /**601 * @dev Returns true if the value is in the set. O(1).602 */603 function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {604 return _contains(set._inner, value);605 }606 607 /**608 * @dev Returns the number of values in the set. O(1).609 */610 function length(Bytes32Set storage set) internal view returns (uint256) {611 return _length(set._inner);612 }613 614 /**615 * @dev Returns the value stored at position `index` in the set. O(1).616 *617 * Note that there are no guarantees on the ordering of values inside the618 * array, and it may change when more values are added or removed.619 *620 * Requirements:621 *622 * - `index` must be strictly less than {length}.623 */624 function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {625 return _at(set._inner, index);626 }627 628 /**629 * @dev Return the entire set in an array630 *631 * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed632 * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that633 * this function has an unbounded cost, and using it as part of a state-changing function may render the function634 * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.635 */636 function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {637 return _values(set._inner);638 }639 640 // AddressSet641 642 struct AddressSet {643 Set _inner;644 }645 646 /**647 * @dev Add a value to a set. O(1).648 *649 * Returns true if the value was added to the set, that is if it was not650 * already present.651 */652 function add(AddressSet storage set, address value) internal returns (bool) {653 return _add(set._inner, bytes32(uint256(uint160(value))));654 }655 656 /**657 * @dev Removes a value from a set. O(1).658 *659 * Returns true if the value was removed from the set, that is if it was660 * present.661 */662 function remove(AddressSet storage set, address value) internal returns (bool) {663 return _remove(set._inner, bytes32(uint256(uint160(value))));664 }665 666 /**667 * @dev Returns true if the value is in the set. O(1).668 */669 function contains(AddressSet storage set, address value) internal view returns (bool) {670 return _contains(set._inner, bytes32(uint256(uint160(value))));671 }672 673 /**674 * @dev Returns the number of values in the set. O(1).675 */676 function length(AddressSet storage set) internal view returns (uint256) {677 return _length(set._inner);678 }679 680 /**681 * @dev Returns the value stored at position `index` in the set. O(1).682 *683 * Note that there are no guarantees on the ordering of values inside the684 * array, and it may change when more values are added or removed.685 *686 * Requirements:687 *688 * - `index` must be strictly less than {length}.689 */690 function at(AddressSet storage set, uint256 index) internal view returns (address) {691 return address(uint160(uint256(_at(set._inner, index))));692 }693 694 /**695 * @dev Return the entire set in an array696 *697 * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed698 * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that699 * this function has an unbounded cost, and using it as part of a state-changing function may render the function700 * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.701 */702 function values(AddressSet storage set) internal view returns (address[] memory) {703 bytes32[] memory store = _values(set._inner);704 address[] memory result;705 706 assembly {707 result := store708 }709 710 return result;711 }712 713 // UintSet714 715 struct UintSet {716 Set _inner;717 }718 719 /**720 * @dev Add a value to a set. O(1).721 *722 * Returns true if the value was added to the set, that is if it was not723 * already present.724 */725 function add(UintSet storage set, uint256 value) internal returns (bool) {726 return _add(set._inner, bytes32(value));727 }728 729 /**730 * @dev Removes a value from a set. O(1).731 *732 * Returns true if the value was removed from the set, that is if it was733 * present.734 */735 function remove(UintSet storage set, uint256 value) internal returns (bool) {736 return _remove(set._inner, bytes32(value));737 }738 739 /**740 * @dev Returns true if the value is in the set. O(1).741 */742 function contains(UintSet storage set, uint256 value) internal view returns (bool) {743 return _contains(set._inner, bytes32(value));744 }745 746 /**747 * @dev Returns the number of values on the set. O(1).748 */749 function length(UintSet storage set) internal view returns (uint256) {750 return _length(set._inner);751 }752 753 /**754 * @dev Returns the value stored at position `index` in the set. O(1).755 *756 * Note that there are no guarantees on the ordering of values inside the757 * array, and it may change when more values are added or removed.758 *759 * Requirements:760 *761 * - `index` must be strictly less than {length}.762 */763 function at(UintSet storage set, uint256 index) internal view returns (uint256) {764 return uint256(_at(set._inner, index));765 }766 767 /**768 * @dev Return the entire set in an array769 *770 * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed771 * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that772 * this function has an unbounded cost, and using it as part of a state-changing function may render the function773 * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.774 */775 function values(UintSet storage set) internal view returns (uint256[] memory) {776 bytes32[] memory store = _values(set._inner);777 uint256[] memory result;778 779 assembly {780 result := store781 }782 783 return result;784 }785}786 787/**788 * @dev Extension of {AccessControl} that allows enumerating the members of each role.789 */790abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {791 using EnumerableSet for EnumerableSet.AddressSet;792 793 mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;794 795 /**796 * @dev See {IERC165-supportsInterface}.797 */798 function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {799 return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);800 }801 802 /**803 * @dev Returns one of the accounts that have `role`. `index` must be a804 * value between 0 and {getRoleMemberCount}, non-inclusive.805 *806 * Role bearers are not sorted in any particular way, and their ordering may807 * change at any point.808 *809 * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure810 * you perform all queries on the same block. See the following811 * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]812 * for more information.813 */814 function getRoleMember(bytes32 role, uint256 index) public view override returns (address) {815 return _roleMembers[role].at(index);816 }817 818 /**819 * @dev Returns the number of accounts that have `role`. Can be used820 * together with {getRoleMember} to enumerate all bearers of a role.821 */822 function getRoleMemberCount(bytes32 role) public view override returns (uint256) {823 return _roleMembers[role].length();824 }825 826 /**827 * @dev Overload {grantRole} to track enumerable memberships828 */829 function grantRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {830 super.grantRole(role, account);831 _roleMembers[role].add(account);832 }833 834 /**835 * @dev Overload {revokeRole} to track enumerable memberships836 */837 function revokeRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {838 super.revokeRole(role, account);839 _roleMembers[role].remove(account);840 }841 842 /**843 * @dev Overload {renounceRole} to track enumerable memberships844 */845 function renounceRole(bytes32 role, address account) public virtual override(AccessControl, IAccessControl) {846 super.renounceRole(role, account);847 _roleMembers[role].remove(account);848 }849 850 /**851 * @dev Overload {_setupRole} to track enumerable memberships852 */853 function _setupRole(bytes32 role, address account) internal virtual override {854 super._setupRole(role, account);855 _roleMembers[role].add(account);856 }857}858 859contract KYCContract is AccessControlEnumerable {860 861 // Simple mapping, 0 means the user has not passed anything.862 mapping(address => uint) public level;863 864 // Prices for every KYC-Tier.865 mapping(uint => uint) public levelPrices;866 867 // KYC centre which is allowed to change users' kyc levels.868 bytes32 public constant KYCCentre = keccak256("KYCCentre");869 870 event KYCLevelChanged(address indexed _address, uint indexed level);871 event RequestCreated(uint indexed index);872 event RequestApproved(uint indexed index);873 event RequestDeclined(uint indexed index);874 event RequestWithdrawn(uint indexed index);875 event SetLevelPrice(uint indexed level, uint indexed price);876 877 878 // So centre can view requests assigned to him.879 mapping(address => uint[]) public kycCentreRequests;880 881 // so user can view his own requests.882 mapping(address => uint[]) public userKYCRequests;883 884 enum Status {885 Pending,886 Declined,887 Approved,888 Withdrawn889 }890 891 // Request from user to KYC centre.892 struct KYCRequest {893 address user;894 bytes32 data;895 uint level;896 Status status;897 address centre;898 uint deposit;899 }900 901 // All requests from users to KYC centres.902 KYCRequest[] public kycRequests;903 904 /**905 * Checks if the user has enough deposit and returns the change.906 */907 modifier costs(uint _amount) {908 require(msg.value >= _amount, "G001");909 _;910 if (msg.value > _amount)911 payable(msg.sender).transfer(msg.value - _amount);912 }913 914 /**915 * Setter of the KYC-Tier prices.916 */917 function setLevelPrice(uint _level, uint price) external {918 require(hasRole(DEFAULT_ADMIN_ROLE, msg.sender), "G053");919 levelPrices[_level] = price;920 emit SetLevelPrice(_level, price);921 }922 923 /**924 * Creates user request and sends it to the random chosen KYC centre.925 */926 function createKYCRequest(uint _level, bytes32 _data) external payable costs(levelPrices[_level]) {927 require(level[msg.sender] < _level, "G002");928 929 uint length = userKYCRequests[msg.sender].length;930 if (length > 0) {931 uint requestIndex = userKYCRequests[msg.sender][length-1];932 require(kycRequests[requestIndex].status != Status.Pending, "G120");933 }934 935 uint count = getRoleMemberCount(KYCCentre);936 require(count > 0, "G111");937 938 uint index = uint(blockhash(block.number-1)) % count;939 address chosenKYCCentre = getRoleMember(KYCCentre, index);940 941 KYCRequest memory request = KYCRequest({942 user: msg.sender,943 data: _data,944 level: _level,945 status: Status.Pending,946 centre: chosenKYCCentre,947 deposit: levelPrices[_level]948 });949 950 kycRequests.push(request);951 952 uint indexInAll = kycRequests.length-1;953 954 kycCentreRequests[chosenKYCCentre].push(indexInAll);955 956 // Store the index in the all list.957 userKYCRequests[msg.sender].push(indexInAll);958 emit RequestCreated(kycRequests.length-1);959 }960 961 /**962 * KYC centre function. 963 * Approve users request by a global index.964 */965 function approveKYCRequest(uint _index) external {966 require(hasRole(KYCCentre, msg.sender), "G052");967 KYCRequest storage request = kycRequests[_index];968 969 require(msg.sender == request.centre, "G114");970 require(request.status == Status.Pending, "G121");971 request.status = Status.Approved;972 level[request.user] = request.level;973 974 // We pay half of the deposit back to user if KYC centre approved request975 uint halvedDeposit = request.deposit / 2;976 payable(request.user).transfer(halvedDeposit);977 payable(msg.sender).transfer(request.deposit - halvedDeposit);978 979 emit KYCLevelChanged(request.user, request.level);980 emit RequestApproved(_index);981 }982 983 /**984 * KYC centre function. 985 * Decline users request. 986 */987 function declineKYCRequest(uint _index) external {988 require(hasRole(KYCCentre, msg.sender), "G050");989 KYCRequest storage request = kycRequests[_index];990 991 require(msg.sender == request.centre, "G114");992 require(request.status == Status.Pending, "G121");993 request.status = Status.Declined;994 995 payable(msg.sender).transfer(request.deposit);996 emit RequestDeclined(_index);997 }998 999 /**1000 * KYC centre function. 1001 * Decrease users KYC level.1002 */1003 function decreaseKYCLevel(address user, uint _level) external {1004 require(hasRole(KYCCentre, msg.sender), "G051");1005 1006 uint length = userKYCRequests[user].length;1007 uint requestIndex = userKYCRequests[user][length-1];1008 require(msg.sender == kycRequests[requestIndex].centre, "G114");1009 1010 require(_level < level[user], "G112");1011 level[user] = _level;1012 1013 emit KYCLevelChanged(user, _level);1014 }1015 1016 /**1017 * Users function. 1018 * In case the KYCCentre has been renounced user may withdraw his request.1019 */1020 function repairLostRequest() external {1021 uint length = userKYCRequests[msg.sender].length;1022 uint requestIndex = userKYCRequests[msg.sender][length-1];1023 1024 KYCRequest storage request = kycRequests[requestIndex];1025 require(msg.sender == request.user, "G053");1026 require(!hasRole(KYCCentre, request.centre), "G110");1027 require(request.status == Status.Pending, "G122");1028 1029 request.status = Status.Withdrawn;1030 1031 payable(request.user).transfer(request.deposit);1032 emit RequestWithdrawn(requestIndex);1033 }1034 1035 /**1036 * Users function. 1037 * User may cancel its KYC request.1038 */1039 function cancelUsersRequest() external {1040 uint length = userKYCRequests[msg.sender].length;1041 uint requestIndex = userKYCRequests[msg.sender][length-1];1042 1043 KYCRequest storage request = kycRequests[requestIndex];1044 require(msg.sender == request.user, "G053");1045 require(hasRole(KYCCentre, request.centre), "G113");1046 require(request.status == Status.Pending, "G123");1047 1048 request.status = Status.Withdrawn;1049 1050 payable(request.centre).transfer(request.deposit);1051 emit RequestWithdrawn(requestIndex);1052 }1053 1054 /**1055 * Getter of the user requests and their statuses.1056 */1057 function viewMyRequest(uint userIndex) external view returns(KYCRequest memory) {1058 uint indexInAll = userKYCRequests[msg.sender][userIndex];1059 return kycRequests[indexInAll];1060 }1061 1062 /**1063 * Getter of the user requests assigned to KYC centre.1064 */1065 function viewRequestAssignedToCentre(address _centre, uint _localIndex) external view returns (KYCRequest memory, uint) {1066 uint globalIndex = kycCentreRequests[_centre][_localIndex];1067 KYCRequest memory request = kycRequests[globalIndex];1068 return (request, globalIndex);1069 }1070 1071 /**1072 * Getter of the last user request.1073 */1074 function viewMyLastRequest() external view returns(KYCRequest memory) {1075 uint len = userKYCRequests[msg.sender].length;1076 uint indexInAll = userKYCRequests[msg.sender][len-1];1077 return kycRequests[indexInAll];1078 }1079 1080 /**1081 * Getter of the global index of a users last KYC-request.1082 */1083 function getLastGlobalRequestIndexOfAddress(address _address) external view returns(uint){1084 uint len = userKYCRequests[_address].length;1085 uint index = userKYCRequests[_address][len-1];1086 return index;1087 }1088}
[ { "name": "KYCLevelChanged", "type": "event", "inputs": [ { "name": "_address", "type": "address", "indexed": true, "internalType": "address" }, { "name": "level", "type": "uint256", "indexed": true, "internalType": "uint256" } ], "anonymous": false }, { "name": "RequestApproved", "type": "event", "inputs": [ { "name": "index", "type": "uint256", "indexed": true, "internalType": "uint256" } ], "anonymous": false }, { "name": "RequestCreated", "type": "event", "inputs": [ { "name": "index", "type": "uint256", "indexed": true, "internalType": "uint256" } ], "anonymous": false }, { "name": "RequestDeclined", "type": "event", "inputs": [ { "name": "index", "type": "uint256", "indexed": true, "internalType": "uint256" } ], "anonymous": false }, { "name": "RequestWithdrawn", "type": "event", "inputs": [ { "name": "index", "type": "uint256", "indexed": true, "internalType": "uint256" } ], "anonymous": false }, { "name": "RoleAdminChanged", "type": "event", "inputs": [ { "name": "role", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "previousAdminRole", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "newAdminRole", "type": "bytes32", "indexed": true, "internalType": "bytes32" } ], "anonymous": false }, { "name": "RoleGranted", "type": "event", "inputs": [ { "name": "role", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "account", "type": "address", "indexed": true, "internalType": "address" }, { "name": "sender", "type": "address", "indexed": true, "internalType": "address" } ], "anonymous": false }, { "name": "RoleRevoked", "type": "event", "inputs": [ { "name": "role", "type": "bytes32", "indexed": true, "internalType": "bytes32" }, { "name": "account", "type": "address", "indexed": true, "internalType": "address" }, { "name": "sender", "type": "address", "indexed": true, "internalType": "address" } ], "anonymous": false }, { "name": "SetLevelPrice", "type": "event", "inputs": [ { "name": "level", "type": "uint256", "indexed": true, "internalType": "uint256" }, { "name": "price", "type": "uint256", "indexed": true, "internalType": "uint256" } ], "anonymous": false }, { "name": "DEFAULT_ADMIN_ROLE", "type": "function", "inputs": [], "outputs": [ { "name": "", "type": "bytes32", "internalType": "bytes32" } ], "stateMutability": "view" }, { "name": "KYCCentre", "type": "function", "inputs": [], "outputs": [ { "name": "", "type": "bytes32", "internalType": "bytes32" } ], "stateMutability": "view" }, { "name": "approveKYCRequest", "type": "function", "inputs": [ { "name": "_index", "type": "uint256", "internalType": "uint256" } ], "outputs": [], "stateMutability": "nonpayable" }, { "name": "cancelUsersRequest", "type": "function", "inputs": [], "outputs": [], "stateMutability": "nonpayable" }, { "name": "createKYCRequest", "type": "function", "inputs": [ { "name": "_level", "type": "uint256", "internalType": "uint256" }, { "name": "_data", "type": "bytes32", "internalType": "bytes32" } ], "outputs": [], "stateMutability": "payable" }, { "name": "declineKYCRequest", "type": "function", "inputs": [ { "name": "_index", "type": "uint256", "internalType": "uint256" } ], "outputs": [], "stateMutability": "nonpayable" }, { "name": "decreaseKYCLevel", "type": "function", "inputs": [ { "name": "user", "type": "address", "internalType": "address" }, { "name": "_level", "type": "uint256", "internalType": "uint256" } ], "outputs": [], "stateMutability": "nonpayable" }, { "name": "getLastGlobalRequestIndexOfAddress", "type": "function", "inputs": [ { "name": "_address", "type": "address", "internalType": "address" } ], "outputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }, { "name": "getRoleAdmin", "type": "function", "inputs": [ { "name": "role", "type": "bytes32", "internalType": "bytes32" } ], "outputs": [ { "name": "", "type": "bytes32", "internalType": "bytes32" } ], "stateMutability": "view" }, { "name": "getRoleMember", "type": "function", "inputs": [ { "name": "role", "type": "bytes32", "internalType": "bytes32" }, { "name": "index", "type": "uint256", "internalType": "uint256" } ], "outputs": [ { "name": "", "type": "address", "internalType": "address" } ], "stateMutability": "view" }, { "name": "getRoleMemberCount", "type": "function", "inputs": [ { "name": "role", "type": "bytes32", "internalType": "bytes32" } ], "outputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }, { "name": "grantRole", "type": "function", "inputs": [ { "name": "role", "type": "bytes32", "internalType": "bytes32" }, { "name": "account", "type": "address", "internalType": "address" } ], "outputs": [], "stateMutability": "nonpayable" }, { "name": "hasRole", "type": "function", "inputs": [ { "name": "role", "type": "bytes32", "internalType": "bytes32" }, { "name": "account", "type": "address", "internalType": "address" } ], "outputs": [ { "name": "", "type": "bool", "internalType": "bool" } ], "stateMutability": "view" }, { "name": "kycCentreRequests", "type": "function", "inputs": [ { "name": "", "type": "address", "internalType": "address" }, { "name": "", "type": "uint256", "internalType": "uint256" } ], "outputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }, { "name": "kycRequests", "type": "function", "inputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "outputs": [ { "name": "user", "type": "address", "internalType": "address" }, { "name": "data", "type": "bytes32", "internalType": "bytes32" }, { "name": "level", "type": "uint256", "internalType": "uint256" }, { "name": "status", "type": "uint8", "internalType": "enum KYCContract.Status" }, { "name": "centre", "type": "address", "internalType": "address" }, { "name": "deposit", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }, { "name": "level", "type": "function", "inputs": [ { "name": "", "type": "address", "internalType": "address" } ], "outputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }, { "name": "levelPrices", "type": "function", "inputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "outputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }, { "name": "renounceRole", "type": "function", "inputs": [ { "name": "role", "type": "bytes32", "internalType": "bytes32" }, { "name": "account", "type": "address", "internalType": "address" } ], "outputs": [], "stateMutability": "nonpayable" }, { "name": "repairLostRequest", "type": "function", "inputs": [], "outputs": [], "stateMutability": "nonpayable" }, { "name": "revokeRole", "type": "function", "inputs": [ { "name": "role", "type": "bytes32", "internalType": "bytes32" }, { "name": "account", "type": "address", "internalType": "address" } ], "outputs": [], "stateMutability": "nonpayable" }, { "name": "setLevelPrice", "type": "function", "inputs": [ { "name": "_level", "type": "uint256", "internalType": "uint256" }, { "name": "price", "type": "uint256", "internalType": "uint256" } ], "outputs": [], "stateMutability": "nonpayable" }, { "name": "supportsInterface", "type": "function", "inputs": [ { "name": "interfaceId", "type": "bytes4", "internalType": "bytes4" } ], "outputs": [ { "name": "", "type": "bool", "internalType": "bool" } ], "stateMutability": "view" }, { "name": "userKYCRequests", "type": "function", "inputs": [ { "name": "", "type": "address", "internalType": "address" }, { "name": "", "type": "uint256", "internalType": "uint256" } ], "outputs": [ { "name": "", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }, { "name": "viewMyLastRequest", "type": "function", "inputs": [], "outputs": [ { "name": "", "type": "tuple", "components": [ { "name": "user", "type": "address", "internalType": "address" }, { "name": "data", "type": "bytes32", "internalType": "bytes32" }, { "name": "level", "type": "uint256", "internalType": "uint256" }, { "name": "status", "type": "uint8", "internalType": "enum KYCContract.Status" }, { "name": "centre", "type": "address", "internalType": "address" }, { "name": "deposit", "type": "uint256", "internalType": "uint256" } ], "internalType": "struct KYCContract.KYCRequest" } ], "stateMutability": "view" }, { "name": "viewMyRequest", "type": "function", "inputs": [ { "name": "userIndex", "type": "uint256", "internalType": "uint256" } ], "outputs": [ { "name": "", "type": "tuple", "components": [ { "name": "user", "type": "address", "internalType": "address" }, { "name": "data", "type": "bytes32", "internalType": "bytes32" }, { "name": "level", "type": "uint256", "internalType": "uint256" }, { "name": "status", "type": "uint8", "internalType": "enum KYCContract.Status" }, { "name": "centre", "type": "address", "internalType": "address" }, { "name": "deposit", "type": "uint256", "internalType": "uint256" } ], "internalType": "struct KYCContract.KYCRequest" } ], "stateMutability": "view" }, { "name": "viewRequestAssignedToCentre", "type": "function", "inputs": [ { "name": "_centre", "type": "address", "internalType": "address" }, { "name": "_localIndex", "type": "uint256", "internalType": "uint256" } ], "outputs": [ { "name": "", "type": "tuple", "components": [ { "name": "user", "type": "address", "internalType": "address" }, { "name": "data", "type": "bytes32", "internalType": "bytes32" }, { "name": "level", "type": "uint256", "internalType": "uint256" }, { "name": "status", "type": "uint8", "internalType": "enum KYCContract.Status" }, { "name": "centre", "type": "address", "internalType": "address" }, { "name": "deposit", "type": "uint256", "internalType": "uint256" } ], "internalType": "struct KYCContract.KYCRequest" }, { "name": "", "type": "uint256", "internalType": "uint256" } ], "stateMutability": "view" }]
0x6080604052600436106101815760003560e01c8063847192d9116100d1578063b74091e81161008a578063d547741f11610064578063d547741f146104ac578063d56f5003146104cc578063e3fe29ee146104ee578063f5eb43521461050357600080fd5b8063b74091e81461043f578063ca15c8731461045f578063d41b6db61461047f57600080fd5b8063847192d9146103705780638e6156a1146103925780639010d07c146103b257806390ec8f7e146103ea57806391d148541461040a578063a217fddf1461042a57600080fd5b8063248a9ca31161013e57806348135df01161011857806348135df0146102ee578063599bd4e31461031b578063620472cf1461033b57806375e4107f1461035b57600080fd5b8063248a9ca31461027e5780632f2ff15d146102ae57806336568abe146102ce57600080fd5b806301ffc9a7146101865780630e8723dc146101bb5780631019c5a3146101e9578063192416cb1461020b5780631a710673146102395780632470cfe01461024c575b600080fd5b34801561019257600080fd5b506101a66101a1366004611bde565b610523565b60405190151581526020015b60405180910390f35b3480156101c757600080fd5b506101db6101d6366004611c24565b61054e565b6040516101b2929190611cd2565b3480156101f557600080fd5b50610209610204366004611ced565b61064a565b005b34801561021757600080fd5b5061022b610226366004611c24565b6107cd565b6040519081526020016101b2565b610209610247366004611d06565b6107fe565b34801561025857600080fd5b5061026c610267366004611ced565b610c1e565b6040516101b296959493929190611d28565b34801561028a57600080fd5b5061022b610299366004611ced565b60009081526020819052604090206001015490565b3480156102ba57600080fd5b506102096102c9366004611d6a565b610c76565b3480156102da57600080fd5b506102096102e9366004611d6a565b610c98565b3480156102fa57600080fd5b5061022b610309366004611ced565b60036020526000908152604090205481565b34801561032757600080fd5b5061022b610336366004611c24565b610cba565b34801561034757600080fd5b5061022b610356366004611d96565b610cd6565b34801561036757600080fd5b50610209610d22565b34801561037c57600080fd5b50610385610edf565b6040516101b29190611db1565b34801561039e57600080fd5b506102096103ad366004611c24565b610fd5565b3480156103be57600080fd5b506103d26103cd366004611d06565b611152565b6040516001600160a01b0390911681526020016101b2565b3480156103f657600080fd5b50610209610405366004611ced565b611171565b34801561041657600080fd5b506101a6610425366004611d6a565b6113ac565b34801561043657600080fd5b5061022b600081565b34801561044b57600080fd5b5061038561045a366004611ced565b6113d5565b34801561046b57600080fd5b5061022b61047a366004611ced565b6113fe565b34801561048b57600080fd5b5061022b61049a366004611d96565b60026020526000908152604090205481565b3480156104b857600080fd5b506102096104c7366004611d6a565b611415565b3480156104d857600080fd5b5061022b600080516020611fb283398151915281565b3480156104fa57600080fd5b5061020961141f565b34801561050f57600080fd5b5061020961051e366004611d06565b6115ae565b60006001600160e01b03198216635a05180f60e01b1480610548575061054882611614565b92915050565b610556611ba8565b6001600160a01b038316600090815260046020526040812080548291908590811061058357610583611dbf565b906000526020600020015490506000600682815481106105a5576105a5611dbf565b60009182526020918290206040805160c081018252600590930290910180546001600160a01b03168352600181015493830193909352600283015490820152600380830154919291606084019160ff9091169081111561060757610607611c4e565b600381111561061857610618611c4e565b8152600382015461010090046001600160a01b0316602082015260049091015460409091015296919550909350505050565b610662600080516020611fb2833981519152336113ac565b6106a05760405162461bcd60e51b8152600401610697906020808252600490820152630473035360e41b604082015260600190565b60405180910390fd5b6000600682815481106106b5576106b5611dbf565b906000526020600020906005020190508060030160019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b03161461070d5760405162461bcd60e51b815260040161069790611dd5565b600060038083015460ff169081111561072857610728611c4e565b1461075e5760405162461bcd60e51b8152600401610697906020808252600490820152634731323160e01b604082015260600190565b60038101805460ff19166001179055600481015460405133916108fc811502916000818181858888f1935050505015801561079d573d6000803e3d6000fd5b5060405182907fb04b82d30acceb062562e2eefee6f28c38f71cf9c6d4fce7884b883fe038825890600090a25050565b600460205281600052604060002081815481106107e957600080fd5b90600052602060002001600091509150505481565b600082815260036020526040902054348111156108465760405162461bcd60e51b8152600401610697906020808252600490820152634730303160e01b604082015260600190565b33600090815260026020526040902054831161088d5760405162461bcd60e51b8152600401610697906020808252600490820152632398181960e11b604082015260600190565b33600090815260056020526040902054801561094d573360009081526005602052604081206108bd600184611e09565b815481106108cd576108cd611dbf565b60009182526020822001549150600682815481106108ed576108ed611dbf565b60009182526020909120600360059092020181015460ff169081111561091557610915611c4e565b0361094b5760405162461bcd60e51b8152600401610697906020808252600490820152630473132360e41b604082015260600190565b505b6000610966600080516020611fb28339815191526113fe565b9050600081116109a15760405162461bcd60e51b8152600401610697906020808252600490820152634731313160e01b604082015260600190565b6000816109af600143611e09565b6109ba919040611e32565b905060006109d6600080516020611fb283398151915283611152565b6040805160c08101825233815260208082018a81528284018c81526000606085018181526001600160a01b0388811660808801528f83526003958690529682205460a087015260068054600180820183559190935286517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f600590940293840180546001600160a01b0319169190991617885593517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d4083015591517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d4182015590517ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d42909101805496975093958695949193919260ff19909116918490811115610b0157610b01611c4e565b021790555060808201516003820180546001600160a01b0390921661010002610100600160a81b031990921691909117905560a090910151600490910155600654600090610b5190600190611e09565b6001600160a01b03841660009081526004602090815260408083208054600181810183559185528385200185905533845260058352908320805480830182559084529190922001829055600654919250610baa91611e09565b6040517f97890542421e06ad80deca7ba945fd211a48ec6d89da2510960446025b78e32490600090a250505050505080341115610c1957336108fc610bef8334611e09565b6040518115909202916000818181858888f19350505050158015610c17573d6000803e3d6000fd5b505b505050565b60068181548110610c2e57600080fd5b6000918252602090912060059091020180546001820154600283015460038401546004909401546001600160a01b0393841695509193909260ff821692610100909204169086565b610c808282611649565b6000828152600160205260409020610c19908261166f565b610ca28282611684565b6000828152600160205260409020610c199082611702565b600560205281600052604060002081815481106107e957600080fd5b6001600160a01b03811660009081526005602052604081208054908290610cfe600184611e09565b81548110610d0e57610d0e611dbf565b600091825260209091200154949350505050565b33600090815260056020526040812080549190610d40600184611e09565b81548110610d5057610d50611dbf565b90600052602060002001549050600060068281548110610d7257610d72611dbf565b6000918252602090912060059091020180549091506001600160a01b03163314610dae5760405162461bcd60e51b815260040161069790611e46565b6003810154610dda90600080516020611fb28339815191529061010090046001600160a01b03166113ac565b15610e105760405162461bcd60e51b8152600401610697906020808252600490820152630473131360e41b604082015260600190565b600060038083015460ff1690811115610e2b57610e2b611c4e565b14610e615760405162461bcd60e51b8152600401610697906020808252600490820152632398991960e11b604082015260600190565b6003818101805460ff19169091179055805460048201546040516001600160a01b03909216916108fc82150291906000818181858888f19350505050158015610eae573d6000803e3d6000fd5b5060405182907fa96b5d0d7f26bd7262aefaa969b62e7b98f59439bca50822d598df9c16a20d6790600090a2505050565b610ee7611ba8565b33600090815260056020526040812080549190610f05600184611e09565b81548110610f1557610f15611dbf565b9060005260206000200154905060068181548110610f3557610f35611dbf565b60009182526020918290206040805160c081018252600590930290910180546001600160a01b03168352600181015493830193909352600283015490820152600380830154919291606084019160ff90911690811115610f9757610f97611c4e565b6003811115610fa857610fa8611c4e565b8152600382015461010090046001600160a01b031660208201526004909101546040909101529392505050565b610fed600080516020611fb2833981519152336113ac565b6110225760405162461bcd60e51b8152600401610697906020808252600490820152634730353160e01b604082015260600190565b6001600160a01b038216600090815260056020526040812080549190611049600184611e09565b8154811061105957611059611dbf565b906000526020600020015490506006818154811061107957611079611dbf565b600091825260209091206005909102016003015461010090046001600160a01b031633146110b95760405162461bcd60e51b815260040161069790611dd5565b6001600160a01b03841660009081526002602052604090205483106111095760405162461bcd60e51b8152600401610697906020808252600490820152632398989960e11b604082015260600190565b6001600160a01b038416600081815260026020526040808220869055518592917fc3ef28acb401a3dc5b2e85f6179659f2a493effb762b56133e7b69bc49c9570791a350505050565b600082815260016020526040812061116a9083611717565b9392505050565b611189600080516020611fb2833981519152336113ac565b6111be5760405162461bcd60e51b81526004016106979060208082526004908201526323981a9960e11b604082015260600190565b6000600682815481106111d3576111d3611dbf565b906000526020600020906005020190508060030160019054906101000a90046001600160a01b03166001600160a01b0316336001600160a01b03161461122b5760405162461bcd60e51b815260040161069790611dd5565b600060038083015460ff169081111561124657611246611c4e565b1461127c5760405162461bcd60e51b8152600401610697906020808252600490820152634731323160e01b604082015260600190565b60038101805460ff191660029081179091558082015482546001600160a01b0316600090815260208390526040812091909155600483015490916112bf91611e64565b82546040519192506001600160a01b03169082156108fc029083906000818181858888f193505050501580156112f9573d6000803e3d6000fd5b50336001600160a01b03166108fc8284600401546113179190611e09565b6040518115909202916000818181858888f1935050505015801561133f573d6000803e3d6000fd5b50600282015482546040516001600160a01b03909116907fc3ef28acb401a3dc5b2e85f6179659f2a493effb762b56133e7b69bc49c9570790600090a360405183907fbecbbd7543b68baaaf7e9c3fd12e4719f1f506f4253abef4a6573d0adf3a73ed90600090a2505050565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b6113dd611ba8565b336000908152600560205260408120805484908110610f1557610f15611dbf565b600081815260016020526040812061054890611723565b610ca2828261172d565b3360009081526005602052604081208054919061143d600184611e09565b8154811061144d5761144d611dbf565b9060005260206000200154905060006006828154811061146f5761146f611dbf565b6000918252602090912060059091020180549091506001600160a01b031633146114ab5760405162461bcd60e51b815260040161069790611e46565b60038101546114d790600080516020611fb28339815191529061010090046001600160a01b03166113ac565b61150c5760405162461bcd60e51b8152600401610697906020808252600490820152634731313360e01b604082015260600190565b600060038083015460ff169081111561152757611527611c4e565b1461155d5760405162461bcd60e51b8152600401610697906020808252600490820152634731323360e01b604082015260600190565b6003818101805460ff19169091179081905560048201546040516101009092046001600160a01b0316916108fc82150291906000818181858888f19350505050158015610eae573d6000803e3d6000fd5b6115b96000336113ac565b6115d55760405162461bcd60e51b815260040161069790611e46565b60008281526003602052604080822083905551829184917f3f88291f93d4b81e09bd18b48548609fd00030880a5fc63ce32049867eaf49da9190a35050565b60006001600160e01b03198216637965db0b60e01b148061054857506301ffc9a760e01b6001600160e01b0319831614610548565b6000828152602081905260409020600101546116658133611753565b610c1983836117b7565b600061116a836001600160a01b03841661183b565b6001600160a01b03811633146116f45760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610697565b6116fe828261188a565b5050565b600061116a836001600160a01b0384166118ef565b600061116a83836119e2565b6000610548825490565b6000828152602081905260409020600101546117498133611753565b610c19838361188a565b61175d82826113ac565b6116fe57611775816001600160a01b03166014611a0c565b611780836020611a0c565b604051602001611791929190611e9c565b60408051601f198184030181529082905262461bcd60e51b825261069791600401611f11565b6117c182826113ac565b6116fe576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556117f73390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b600081815260018301602052604081205461188257508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610548565b506000610548565b61189482826113ac565b156116fe576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b600081815260018301602052604081205480156119d8576000611913600183611e09565b855490915060009061192790600190611e09565b905081811461198c57600086600001828154811061194757611947611dbf565b906000526020600020015490508087600001848154811061196a5761196a611dbf565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061199d5761199d611f44565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610548565b6000915050610548565b60008260000182815481106119f9576119f9611dbf565b9060005260206000200154905092915050565b60606000611a1b836002611f5a565b611a26906002611f71565b67ffffffffffffffff811115611a3e57611a3e611f84565b6040519080825280601f01601f191660200182016040528015611a68576020820181803683370190505b509050600360fc1b81600081518110611a8357611a83611dbf565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110611ab257611ab2611dbf565b60200101906001600160f81b031916908160001a9053506000611ad6846002611f5a565b611ae1906001611f71565b90505b6001811115611b59576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110611b1557611b15611dbf565b1a60f81b828281518110611b2b57611b2b611dbf565b60200101906001600160f81b031916908160001a90535060049490941c93611b5281611f9a565b9050611ae4565b50831561116a5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610697565b6040805160c081018252600080825260208201819052918101829052906060820190815260006020820181905260409091015290565b600060208284031215611bf057600080fd5b81356001600160e01b03198116811461116a57600080fd5b80356001600160a01b0381168114611c1f57600080fd5b919050565b60008060408385031215611c3757600080fd5b611c4083611c08565b946020939093013593505050565b634e487b7160e01b600052602160045260246000fd5b60048110611c8257634e487b7160e01b600052602160045260246000fd5b9052565b60018060a01b0380825116835260208201516020840152604082015160408401526060820151611cb96060850182611c64565b506080828101519091169083015260a090810151910152565b60e08101611ce08285611c86565b8260c08301529392505050565b600060208284031215611cff57600080fd5b5035919050565b60008060408385031215611d1957600080fd5b50508035926020909101359150565b6001600160a01b038781168252602082018790526040820186905260c0820190611d556060840187611c64565b93909316608082015260a00152949350505050565b60008060408385031215611d7d57600080fd5b82359150611d8d60208401611c08565b90509250929050565b600060208284031215611da857600080fd5b61116a82611c08565b60c081016105488284611c86565b634e487b7160e01b600052603260045260246000fd5b60208082526004908201526311cc4c4d60e21b604082015260600190565b634e487b7160e01b600052601160045260246000fd5b8181038181111561054857610548611df3565b634e487b7160e01b600052601260045260246000fd5b600082611e4157611e41611e1c565b500690565b6020808252600490820152634730353360e01b604082015260600190565b600082611e7357611e73611e1c565b500490565b60005b83811015611e93578181015183820152602001611e7b565b50506000910152565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351611ed4816017850160208801611e78565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351611f05816028840160208801611e78565b01602801949350505050565b6020815260008251806020840152611f30816040850160208701611e78565b601f01601f19169190910160400192915050565b634e487b7160e01b600052603160045260246000fd5b808202811582820484141761054857610548611df3565b8082018082111561054857610548611df3565b634e487b7160e01b600052604160045260246000fd5b600081611fa957611fa9611df3565b50600019019056fe79fce87046aae5e678100c84cc5c4708df4209fab036250bb81408ada9b857efa26469706673582212208409034ef128e8ba4357e44d36db46639221dc82467277c29472d57ad2a95d8264736f6c63430008130033