ETH Price: $3,318.00 (+1.74%)
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To

There are no matching entries

> 10 Internal Transactions found.

Latest 17 internal transactions

Advanced mode:
Parent Transaction Hash Block
From
To
215870852025-01-09 13:01:1122 days ago1736427671
0xD77B5601...0025EE4A5
0 ETH
215870852025-01-09 13:01:1122 days ago1736427671
0xD77B5601...0025EE4A5
0 ETH
215870852025-01-09 13:01:1122 days ago1736427671
0xD77B5601...0025EE4A5
0 ETH
215870832025-01-09 13:00:4722 days ago1736427647
0xD77B5601...0025EE4A5
0 ETH
215870212025-01-09 12:48:2322 days ago1736426903
0xD77B5601...0025EE4A5
0 ETH
215870212025-01-09 12:48:2322 days ago1736426903
0xD77B5601...0025EE4A5
0 ETH
215870212025-01-09 12:48:2322 days ago1736426903
0xD77B5601...0025EE4A5
0 ETH
215870192025-01-09 12:47:5922 days ago1736426879
0xD77B5601...0025EE4A5
0 ETH
215870072025-01-09 12:45:3522 days ago1736426735
0xD77B5601...0025EE4A5
0 ETH
215869952025-01-09 12:43:1122 days ago1736426591
0xD77B5601...0025EE4A5
0 ETH
215869882025-01-09 12:41:4722 days ago1736426507
0xD77B5601...0025EE4A5
0 ETH
215869712025-01-09 12:38:2322 days ago1736426303
0xD77B5601...0025EE4A5
0 ETH
215869712025-01-09 12:38:2322 days ago1736426303
0xD77B5601...0025EE4A5
0 ETH
215869712025-01-09 12:38:2322 days ago1736426303
0xD77B5601...0025EE4A5
0 ETH
215869692025-01-09 12:37:5922 days ago1736426279
0xD77B5601...0025EE4A5
0 ETH
215867172025-01-09 11:47:2322 days ago1736423243
0xD77B5601...0025EE4A5
0 ETH
215867002025-01-09 11:43:5922 days ago1736423039
0xD77B5601...0025EE4A5
0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
UtilityTraitCoupon

Compiler Version
v0.8.25+commit.b61c2a91

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 52 : UtilityTraitCoupon.sol
// SPDX-License-Identifier: UNLICENCED
pragma solidity 0.8.25;

import "@openzeppelin/contracts/utils/Strings.sol";
//import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

import "./SolidState/ERC1155/ERC1155FullyEnumerable.sol";
import "./SolidState/ERC1155/enumerable/IERC1155Enumerable.sol";

import "./SolidState/ERC1155/metadata/ERC1155Metadata.sol";
import "./SolidState/ERC1155/metadata/IERC1155Metadata.sol";

import "../@galaxis/registries/contracts/ICommunityList.sol";
import "../@galaxis/registries/contracts/UsesGalaxisRegistry.sol";
import {traitProperty, GenericTrait} from "../Traits/Implementers/Generic/GenericTrait.sol";
import {GTRegistry} from  "../Traits/Registry/GTRegistry.sol";

interface ITraitCouponURI {
    function getURI(address _traitCoupon, uint32 _communityId, uint256 _tokenId) external view returns (string memory);
}

interface ICommunityRegistry {
    function getRegistryAddress(string calldata) external view returns (address);
    function hasRole(bytes32,address) external view returns (bool);
    function isUserCommunityAdmin(bytes32,address) external view returns (bool);
}


contract UtilityTraitCoupon is ERC1155FullyEnumerable,  UsesGalaxisRegistry {
    using Strings  for uint256;
    using EnumerableSet for EnumerableSet.UintSet;


    function version() external pure returns(uint256) {
        return 2024120401; // Happy Birthday to me!
    }

    bytes32                             constant    public  UTILITY_TRAIT_COUPON_ADMIN = keccak256("UTILITY_TRAIT_COUPON_ADMIN");
    string                              constant            GOLDEN_UTILITY_TRAIT_COUPON = "GOLDEN_UTILITY_TRAIT_COUPON";
    string                              constant            UTILITY_TRAIT_COUPON = "UTILITY_TRAIT_COUPON";
    string                              constant            TRAIT_COUPON_MINTER = "TRAIT_COUPON_MINTER";
    string                              constant            COMMUNITY_LIST = "COMMUNITY_LIST";
    string                              constant            TRAIT_COUPON_URI = "TRAIT_COUPON_URI";
    

    bool                                                    initialised;
    uint32                                          public  communityId;

    mapping(uint32 =>                               // tokenNum
            mapping(uint16 =>                       // traitNum
                mapping(uint256 =>                  // value
                                    bytes)))         public  configurationData;
    mapping(uint32 => 
            mapping(uint16 => uint256))             public  configurationMaxPointer;

    mapping(uint32 => uint256)                      public tokenNumberQty;
    mapping(uint32 =>
            mapping(uint16 => uint256))                     public tokenTraitQty;

    EnumerableSet.UintSet                            tokenNumberSet;
    mapping(uint32 => EnumerableSet.UintSet)         tokenTraitSet;
    mapping(uint32 =>
            mapping(uint16 => EnumerableSet.UintSet)) tokenTraitIdz;

    mapping(uint256 => uint256) public counterByPointer; // for reference only

    constructor(address _galaxisRegistry) UsesGalaxisRegistry(_galaxisRegistry) {
        _init(GOLDEN_UTILITY_TRAIT_COUPON);
        _setSupportsInterface(type(IERC1155Enumerable).interfaceId, true);
    }

    function init(uint32 _communityId, string calldata _uri) external {
        _setSupportsInterface(type(IERC1155Enumerable).interfaceId, true);
        require(
            address(this) != galaxisRegistry.getRegistryAddress(GOLDEN_UTILITY_TRAIT_COUPON),
            "UtilityTraitCoupon: Golden contracts cannot be initialised"
        );
        require(
            !initialised,
            "UtilityTraitCoupon: contract already initialised"
        );
        initialised = true;
         require(
            getCommunityRegistry(_communityId).getRegistryAddress(UTILITY_TRAIT_COUPON) == address(0),
            "UtilityTraitCoupon: community already has a Teleport Token"
        );
        communityId = _communityId;
        super._init(_uri);
    }

    function setURI(string calldata _uri) external {
        require(
            (getCommunityRegistry(communityId).hasRole(UTILITY_TRAIT_COUPON_ADMIN,msg.sender)),
            "UtilityTraitCoupon: unauthorised minter"
        );
        _setURI(_uri);
    }

    function getCommunityRegistry(uint32 _communityId) internal view returns (ICommunityRegistry) {
        ICommunityList CL = ICommunityList(galaxisRegistry.getRegistryAddress(COMMUNITY_LIST));
        (,address crAddr,) = CL.communities(_communityId);
        return ICommunityRegistry(crAddr);
    }

    function mint(
        uint32 _tokenNumber,
        uint16 _traitNumber,
        address _recipient,
        uint256 _numberToMint,
        bytes calldata data,
        uint256 _counter // ignored if no data
    ) external {
        require(
            (msg.sender == galaxisRegistry.getRegistryAddress(TRAIT_COUPON_MINTER)) ||
            (getCommunityRegistry(communityId).hasRole(UTILITY_TRAIT_COUPON_ADMIN,msg.sender)) ||
            (getCommunityRegistry(communityId).isUserCommunityAdmin(UTILITY_TRAIT_COUPON_ADMIN,msg.sender)),
            "UtilityTraitCoupon: unauthorised minter"
        );
        uint256 pointer; // = 0
        if (data.length > 0) {
            pointer = ++configurationMaxPointer[_tokenNumber][_traitNumber];
            configurationData[_tokenNumber][_traitNumber][pointer] = data;
            counterByPointer[pointer] = _counter;
        }
        uint256 tokenId = _makeId(_tokenNumber,_traitNumber,pointer);
        bytes memory emptyData;
        updateDetailedListByParts(_tokenNumber, _traitNumber,tokenId, _numberToMint);
        _mint(_recipient,tokenId,_numberToMint,emptyData);
    }

    function updateDetailedListByParts(uint32 _tokenNumber, uint16 _traitNumber,uint256 _tokenId, uint256 _quantity) internal {
        tokenNumberSet.add(_tokenNumber);
        tokenTraitSet[_tokenNumber].add(_traitNumber);
        tokenNumberQty[_tokenNumber] += _quantity;
        tokenTraitQty[_tokenNumber][_traitNumber] += _quantity;
        tokenTraitIdz[_tokenNumber][_traitNumber].add(_tokenId);
    }

    function _getId(uint256 tokenId) internal pure returns (uint32 tokenNumber, uint16 traitNumber, uint256 pointer) {
        traitNumber = uint16(
            tokenId & 0xffff
        );
        tokenNumber = uint32(
            (tokenId >> 16) & 0xffffffff
        );
        pointer = tokenId >> 16+32;
    }

    function updateDetailedListById(uint256 _tokenId, uint256 _quantity) internal {
        (
            uint32 _tokenNumber,
            uint16 _traitNumber,
            
        ) = _getId(_tokenId);
        uint256 tnq = (tokenNumberQty[_tokenNumber] -= _quantity);
        uint256 ttq = (tokenTraitQty[_tokenNumber][_traitNumber] -= _quantity);
        if (tnq == 0)
            tokenNumberSet.remove(_tokenNumber);
        if (ttq == 0)
            tokenTraitSet[_tokenNumber].remove(_traitNumber);
        if (totalSupply(_tokenId) == 0)
            tokenTraitIdz[_tokenNumber][_traitNumber].remove(_tokenId);
    }


    function getData(uint32 tokenNum, uint16 traitNum, uint256 pointer) external view returns (bytes memory) {
        return configurationData[tokenNum][traitNum][pointer];
    }

    function burn(uint256 _tokenId, uint256 quantity) external {
        _burn(msg.sender,_tokenId,quantity);
    }

    function makeId(uint32 tokenNumber, uint16 traitNumber, uint256 value) external pure returns (uint256) {
        return _makeId(tokenNumber,traitNumber,value);
    }

    function _makeId(uint32 tokenNumber, uint16 traitNumber, uint256 value) internal pure returns (uint256) {
        return 
            uint256(traitNumber) +
            (uint256(tokenNumber) << 16) +
            (value << (16 + 32));
    }

    function collectionIDs() external view returns (uint256[] memory) {
        return tokenNumberSet.toArray();
    }

    function collectionTraitNumbers(uint32 _tokenNumber) external view returns (uint256[] memory) {
        return tokenTraitSet[_tokenNumber].toArray();
    }

    function collectionTraitNumberIds(uint32 _tokenNumber, uint16 _traitID) external view returns (uint256[] memory) {
        return tokenTraitIdz[_tokenNumber][_traitID].toArray();
    }

    function numberOfTraitNumberIds(uint32 _tokenNumber, uint16 _traitID) external view returns (uint256) {
        return tokenTraitIdz[_tokenNumber][_traitID].length();
    }

    function collectionTraitNumberIdsByPage(uint32 _tokenNumber, uint16 _traitID, uint256 start, uint256 length) external view returns (uint256[] memory) {
        uint256 len = tokenTraitIdz[_tokenNumber][_traitID].length();
        if (start + length > len) {
            length = len - start;
        }
        uint256[] memory reply = new uint256[](length);
        for (uint relpos = 0; relpos < length; relpos++) {
            uint pos = start+relpos;
            reply[relpos] = tokenTraitIdz[_tokenNumber][_traitID].at(pos);
        }
        return reply;
    }

    function name() external view returns (string memory) {
        return string.concat(
            "Galaxis Utility Trait Coupon for community ",
            uint256(communityId).toString()
        );
    }

    function symbol() external view returns (string memory) {
        return "GUTC";
    }

    function getInfo(uint256 _tokenId) 
        external view 
        returns (
            uint32 tokenNum, 
            uint16 traitNum, 
            uint256 pointer,
            bytes memory _configurationData,
            traitProperty[] memory traitProperties
        ) 
    {
        (tokenNum,traitNum,pointer) = _getId(_tokenId);
        _configurationData = configurationData[tokenNum][traitNum][pointer];
        string memory trString = string.concat(
            "TRAIT_REGISTRY_",
            (uint256(tokenNum)).toString()
        );
        ICommunityRegistry cr = getCommunityRegistry(communityId);
        address trAddress = cr.getRegistryAddress(trString);
        GTRegistry tr = GTRegistry(trAddress);
        GenericTrait gt = GenericTrait(tr.getImplementer(traitNum));
        traitProperties = gt.getSchema();
    }

    function uri(uint256 tokenId) public view override (ERC1155Metadata,IERC1155Metadata) returns (string memory) {
        address tcURI = galaxisRegistry.getRegistryAddress(TRAIT_COUPON_URI);
        require (tcURI != address(0),"TRAIT_COUPON_URI not set") ; 
        return ITraitCouponURI(tcURI).getURI(address(this), communityId,tokenId);
    }

}

File 2 of 52 : AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";

/**
 * @dev Contract module that allows children to implement role-based access
 * control mechanisms. This is a lightweight version that doesn't allow enumerating role
 * members except through off-chain means by accessing the contract event logs. Some
 * applications may benefit from on-chain enumerability, for those cases see
 * {AccessControlEnumerable}.
 *
 * Roles are referred to by their `bytes32` identifier. These should be exposed
 * in the external API and be unique. The best way to achieve this is by
 * using `public constant` hash digests:
 *
 * ```
 * bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
 * ```
 *
 * Roles can be used to represent a set of permissions. To restrict access to a
 * function call, use {hasRole}:
 *
 * ```
 * function foo() public {
 *     require(hasRole(MY_ROLE, msg.sender));
 *     ...
 * }
 * ```
 *
 * Roles can be granted and revoked dynamically via the {grantRole} and
 * {revokeRole} functions. Each role has an associated admin role, and only
 * accounts that have a role's admin role can call {grantRole} and {revokeRole}.
 *
 * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
 * that only accounts with this role will be able to grant or revoke other
 * roles. More complex role relationships can be created by using
 * {_setRoleAdmin}.
 *
 * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
 * grant and revoke this role. Extra precautions should be taken to secure
 * accounts that have been granted it.
 */
abstract contract AccessControl is Context, IAccessControl, ERC165 {
    struct RoleData {
        mapping(address => bool) members;
        bytes32 adminRole;
    }

    mapping(bytes32 => RoleData) private _roles;

    bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;

    /**
     * @dev Modifier that checks that an account has a specific role. Reverts
     * with a standardized message including the required role.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     *
     * _Available since v4.1._
     */
    modifier onlyRole(bytes32 role) {
        _checkRole(role);
        _;
    }

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
        return _roles[role].members[account];
    }

    /**
     * @dev Revert with a standard message if `_msgSender()` is missing `role`.
     * Overriding this function changes the behavior of the {onlyRole} modifier.
     *
     * Format of the revert message is described in {_checkRole}.
     *
     * _Available since v4.6._
     */
    function _checkRole(bytes32 role) internal view virtual {
        _checkRole(role, _msgSender());
    }

    /**
     * @dev Revert with a standard message if `account` is missing `role`.
     *
     * The format of the revert reason is given by the following regular expression:
     *
     *  /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
     */
    function _checkRole(bytes32 role, address account) internal view virtual {
        if (!hasRole(role, account)) {
            revert(
                string(
                    abi.encodePacked(
                        "AccessControl: account ",
                        Strings.toHexString(uint160(account), 20),
                        " is missing role ",
                        Strings.toHexString(uint256(role), 32)
                    )
                )
            );
        }
    }

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
        return _roles[role].adminRole;
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleGranted} event.
     */
    function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _grantRole(role, account);
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     *
     * May emit a {RoleRevoked} event.
     */
    function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
        _revokeRole(role, account);
    }

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been revoked `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     *
     * May emit a {RoleRevoked} event.
     */
    function renounceRole(bytes32 role, address account) public virtual override {
        require(account == _msgSender(), "AccessControl: can only renounce roles for self");

        _revokeRole(role, account);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event. Note that unlike {grantRole}, this function doesn't perform any
     * checks on the calling account.
     *
     * May emit a {RoleGranted} event.
     *
     * [WARNING]
     * ====
     * This function should only be called from the constructor when setting
     * up the initial roles for the system.
     *
     * Using this function in any other way is effectively circumventing the admin
     * system imposed by {AccessControl}.
     * ====
     *
     * NOTE: This function is deprecated in favor of {_grantRole}.
     */
    function _setupRole(bytes32 role, address account) internal virtual {
        _grantRole(role, account);
    }

    /**
     * @dev Sets `adminRole` as ``role``'s admin role.
     *
     * Emits a {RoleAdminChanged} event.
     */
    function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
        bytes32 previousAdminRole = getRoleAdmin(role);
        _roles[role].adminRole = adminRole;
        emit RoleAdminChanged(role, previousAdminRole, adminRole);
    }

    /**
     * @dev Grants `role` to `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleGranted} event.
     */
    function _grantRole(bytes32 role, address account) internal virtual {
        if (!hasRole(role, account)) {
            _roles[role].members[account] = true;
            emit RoleGranted(role, account, _msgSender());
        }
    }

    /**
     * @dev Revokes `role` from `account`.
     *
     * Internal function without access restriction.
     *
     * May emit a {RoleRevoked} event.
     */
    function _revokeRole(bytes32 role, address account) internal virtual {
        if (hasRole(role, account)) {
            _roles[role].members[account] = false;
            emit RoleRevoked(role, account, _msgSender());
        }
    }
}

File 3 of 52 : AccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControlEnumerable.sol";
import "./AccessControl.sol";
import "../utils/structs/EnumerableSet.sol";

/**
 * @dev Extension of {AccessControl} that allows enumerating the members of each role.
 */
abstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {
    using EnumerableSet for EnumerableSet.AddressSet;

    mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;

    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);
    }

    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {
        return _roleMembers[role].at(index);
    }

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {
        return _roleMembers[role].length();
    }

    /**
     * @dev Overload {_grantRole} to track enumerable memberships
     */
    function _grantRole(bytes32 role, address account) internal virtual override {
        super._grantRole(role, account);
        _roleMembers[role].add(account);
    }

    /**
     * @dev Overload {_revokeRole} to track enumerable memberships
     */
    function _revokeRole(bytes32 role, address account) internal virtual override {
        super._revokeRole(role, account);
        _roleMembers[role].remove(account);
    }
}

File 4 of 52 : IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)

pragma solidity ^0.8.0;

/**
 * @dev External interface of AccessControl declared to support ERC165 detection.
 */
interface IAccessControl {
    /**
     * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
     *
     * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
     * {RoleAdminChanged} not being emitted signaling this.
     *
     * _Available since v3.1._
     */
    event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);

    /**
     * @dev Emitted when `account` is granted `role`.
     *
     * `sender` is the account that originated the contract call, an admin role
     * bearer except when using {AccessControl-_setupRole}.
     */
    event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Emitted when `account` is revoked `role`.
     *
     * `sender` is the account that originated the contract call:
     *   - if using `revokeRole`, it is the admin role bearer
     *   - if using `renounceRole`, it is the role bearer (i.e. `account`)
     */
    event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);

    /**
     * @dev Returns `true` if `account` has been granted `role`.
     */
    function hasRole(bytes32 role, address account) external view returns (bool);

    /**
     * @dev Returns the admin role that controls `role`. See {grantRole} and
     * {revokeRole}.
     *
     * To change a role's admin, use {AccessControl-_setRoleAdmin}.
     */
    function getRoleAdmin(bytes32 role) external view returns (bytes32);

    /**
     * @dev Grants `role` to `account`.
     *
     * If `account` had not been already granted `role`, emits a {RoleGranted}
     * event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function grantRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from `account`.
     *
     * If `account` had been granted `role`, emits a {RoleRevoked} event.
     *
     * Requirements:
     *
     * - the caller must have ``role``'s admin role.
     */
    function revokeRole(bytes32 role, address account) external;

    /**
     * @dev Revokes `role` from the calling account.
     *
     * Roles are often managed via {grantRole} and {revokeRole}: this function's
     * purpose is to provide a mechanism for accounts to lose their privileges
     * if they are compromised (such as when a trusted device is misplaced).
     *
     * If the calling account had been granted `role`, emits a {RoleRevoked}
     * event.
     *
     * Requirements:
     *
     * - the caller must be `account`.
     */
    function renounceRole(bytes32 role, address account) external;
}

File 5 of 52 : IAccessControlEnumerable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)

pragma solidity ^0.8.0;

import "./IAccessControl.sol";

/**
 * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.
 */
interface IAccessControlEnumerable is IAccessControl {
    /**
     * @dev Returns one of the accounts that have `role`. `index` must be a
     * value between 0 and {getRoleMemberCount}, non-inclusive.
     *
     * Role bearers are not sorted in any particular way, and their ordering may
     * change at any point.
     *
     * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure
     * you perform all queries on the same block. See the following
     * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]
     * for more information.
     */
    function getRoleMember(bytes32 role, uint256 index) external view returns (address);

    /**
     * @dev Returns the number of accounts that have `role`. Can be used
     * together with {getRoleMember} to enumerate all bearers of a role.
     */
    function getRoleMemberCount(bytes32 role) external view returns (uint256);
}

File 6 of 52 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 7 of 52 : IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.0;

import "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId,
        bytes calldata data
    ) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the caller.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool _approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 8 of 52 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

File 9 of 52 : ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)

pragma solidity ^0.8.0;

import "./IERC165.sol";

/**
 * @dev Implementation of the {IERC165} interface.
 *
 * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
 * for the additional interface id that will be supported. For example:
 *
 * ```solidity
 * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
 *     return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
 * }
 * ```
 *
 * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
 */
abstract contract ERC165 is IERC165 {
    /**
     * @dev See {IERC165-supportsInterface}.
     */
    function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
        return interfaceId == type(IERC165).interfaceId;
    }
}

File 10 of 52 : IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 11 of 52 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
    uint8 private constant _ADDRESS_LENGTH = 20;

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _HEX_SYMBOLS[value & 0xf];
            value >>= 4;
        }
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
    }
}

File 12 of 52 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 *  Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
 *  See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 *  In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        return _values(set._inner);
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 13 of 52 : CommunityList.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "./Versionable/IVersionable.sol";

contract CommunityList is AccessControlEnumerable, IVersionable { 

    function version() external pure returns (uint256) {
        return 2024040301;
    }

    bytes32 public constant CONTRACT_ADMIN = keccak256("CONTRACT_ADMIN");


    uint256                              public numberOfEntries;

    struct community_entry {
        string      name;
        address     registry;
        uint32      id;
    }
    
    mapping(uint32 => community_entry)  public communities;   // community_id => record
    mapping(uint256 => uint32)           public index;         // entryNumber => community_id for enumeration

    event CommunityAdded(uint256 pos, string community_name, address community_registry, uint32 community_id);

    constructor() {
        _setupRole(DEFAULT_ADMIN_ROLE, msg.sender);
        _setupRole(CONTRACT_ADMIN,msg.sender);
    }

    function addCommunity(uint32 community_id, string memory community_name, address community_registry) external onlyRole(CONTRACT_ADMIN) {
        uint256 pos = numberOfEntries++;
        index[pos]  = community_id;
        communities[community_id] = community_entry(community_name, community_registry, community_id);
        emit CommunityAdded(pos, community_name, community_registry, community_id);
    }

}

File 14 of 52 : CommunityRegistry.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import "@openzeppelin/contracts/access/AccessControlEnumerable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./Versionable/IVersionable.sol";
import "./UsesGalaxisRegistry.sol";

contract CommunityRegistry is AccessControlEnumerable, UsesGalaxisRegistry, IVersionable  {

    function version() virtual external pure returns(uint256) {
        return 2024040401;
    }

    bytes32 public constant COMMUNITY_REGISTRY_ADMIN = keccak256("COMMUNITY_REGISTRY_ADMIN");

    uint32                      public  community_id;
    string                      public  community_name;
    

    mapping(bytes32 => address)         addresses;
    mapping(bytes32 => uint256)         uints;
    mapping(bytes32 => bool)            booleans;
    mapping(bytes32 => string)          strings;

    mapping (uint => string)    public  addressEntries;
    mapping (uint => string)    public  uintEntries;
    mapping (uint => string)    public  boolEntries;
    mapping (uint => string)    public  stringEntries;
    uint                        public  numberOfAddresses;
    uint                        public  numberOfUINTs;
    uint                        public  numberOfBooleans;
    uint                        public  numberOfStrings;

    bool                                initialised;

    bool                        public  independant;

    event IndependanceDay(bool gain_independance);

    modifier onlyAdmin() {
        require(
            isUserCommunityAdmin(COMMUNITY_REGISTRY_ADMIN,msg.sender)
            ,"CommunityRegistry : Unauthorised");
        _;
    }

    modifier onlyPropertyAdmin() {
        require(
            isUserCommunityAdmin(COMMUNITY_REGISTRY_ADMIN,msg.sender) ||
            hasRole(COMMUNITY_REGISTRY_ADMIN,msg.sender)
            ,"CommunityRegistry : Unauthorised");
        _;
    }



    function isUserCommunityAdmin(bytes32 role, address user) public view returns (bool) {
        if (hasRole(DEFAULT_ADMIN_ROLE,user) ) return true; // community_admin can do anything
        if (independant){        
            return(
                hasRole(role,user)
            );
        } else { // for Factories
           return(roleManager().hasRole(role,user));
        }
    }

    function roleManager() internal view returns (IAccessControlEnumerable) {
        address addr = galaxisRegistry.getRegistryAddress("ROLE_MANAGER"); // universal
        if (addr != address(0)) return IAccessControlEnumerable(addr);
        addr = galaxisRegistry.getRegistryAddress("MAINNET_CHAIN_IMPLEMENTER"); // mainnet
        if (addr != address(0)) return IAccessControlEnumerable(addr);
        addr = galaxisRegistry.getRegistryAddress("L2_RECEIVER"); // mainnet
        require(addr != address(0),"CommunityRegistry : no higher authority found");
        return IAccessControlEnumerable(addr);
    }

    function grantRole(bytes32 key, address user) public override(AccessControl,IAccessControl) onlyAdmin {
        _grantRole(key,user); // need to be able to grant it
    }


 
    constructor (
        address _galaxisRegistry,
        uint32  _community_id, 
        address _community_admin, 
        string memory _community_name
    ) UsesGalaxisRegistry(_galaxisRegistry){
        _init(_community_id,_community_admin,_community_name);
    }

    
    function init(
        uint32  _community_id, 
        address _community_admin, 
        string memory _community_name
    ) external {
        _init(_community_id,_community_admin,_community_name);
    }

    function _init(
        uint32  _community_id, 
        address _community_admin, 
        string memory _community_name
    ) internal {
        require(!initialised,"This can only be called once");
        initialised = true;
        community_id = _community_id;
        community_name  = _community_name;
        _setupRole(DEFAULT_ADMIN_ROLE, _community_admin); // default admin = launchpad
    }



    event AdminUpdated(address user, bool isAdmin);
    event AppAdminChanged(address app,address user,bool state);
    //===
    event AddressChanged(string key, address value);
    event UintChanged(string key, uint256 value);
    event BooleanChanged(string key, bool value);
    event StringChanged(string key, string value);

    function setIndependant(bool gain_independance) external onlyAdmin {
        if (independant != gain_independance) {
                independant = gain_independance;
                emit IndependanceDay(gain_independance);
        }
    }


    function setAdmin(address user,bool status ) external onlyAdmin {
        if (status)
            _grantRole(COMMUNITY_REGISTRY_ADMIN,user);
        else
            _revokeRole(COMMUNITY_REGISTRY_ADMIN,user);
    }

    function hash(string memory field) internal pure returns (bytes32) {
        return keccak256(abi.encode(field));
    }

    function setRegistryAddress(string memory fn, address value) external onlyPropertyAdmin {
        bytes32 hf = hash(fn);
        addresses[hf] = value;
        addressEntries[numberOfAddresses++] = fn;
        emit AddressChanged(fn,value);
    }

    function setRegistryBool(string memory fn, bool value) external onlyPropertyAdmin {
        bytes32 hf = hash(fn);
        booleans[hf] = value;
        boolEntries[numberOfBooleans++] = fn;
        emit BooleanChanged(fn,value);
    }

    function setRegistryString(string memory fn, string memory value) external onlyPropertyAdmin {
        bytes32 hf = hash(fn);
        strings[hf] = value;
        stringEntries[numberOfStrings++] = fn;
        emit StringChanged(fn,value);
    }

    function setRegistryUINT(string memory fn, uint value) external onlyPropertyAdmin {
        bytes32 hf = hash(fn);
        uints[hf] = value;
        uintEntries[numberOfUINTs++] = fn;
        emit UintChanged(fn,value);
    }

    function getRegistryAddress(string memory key) external view returns (address) {
        return addresses[hash(key)];
    }

    function getRegistryBool(string memory key) external view returns (bool) {
        return booleans[hash(key)];
    }

    function getRegistryUINT(string memory key) external view returns (uint256) {
        return uints[hash(key)];
    }

    function getRegistryString(string memory key) external view returns (string memory) {
        return strings[hash(key)];
    }

}

File 15 of 52 : ICommunityList.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

interface ICommunityList {
    // struct community_entry {
    //     string      name;
    //     address     registry;
    //     uint32      id;
    // }
    // mapping(uint32 => community_entry)  public communities;   // community_id => record

    // function communities(uint32) external returns (struct community_entry memory);
    function communities(uint32) external view returns (string memory, address, uint32);
    function addCommunity(uint32, string memory, address community_registry) external;
}

File 16 of 52 : IRegistry.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

interface IRegistry {
    function setRegistryAddress(string memory fn, address value) external ;
    function setRegistryBool(string memory fn, bool value) external ;
    function setRegistryUINT(string memory key) external returns (uint256) ;
    function setRegistryString(string memory fn, string memory value) external ;
    function setAdmin(address user,bool status ) external;
    function setAppAdmin(address app, address user, bool state) external;

    function getRegistryAddress(string memory key) external view returns (address) ;
    function getRegistryBool(string memory key) external view returns (bool);
    function getRegistryUINT(string memory key) external view returns (uint256) ;
    function getRegistryString(string memory key) external view returns (string memory) ;
    function isAdmin(address user) external view returns (bool) ;
    function isAppAdmin(address app, address user) external view returns (bool);

    function numberOfAddresses() external view returns(uint256);
    function addressEntries(uint256) external view returns(string memory);
}

File 17 of 52 : UsesGalaxisRegistry.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.25;

import "./IRegistry.sol";

contract UsesGalaxisRegistry {

    IRegistry   immutable   public   galaxisRegistry;

    constructor(address _galaxisRegistry) {
        galaxisRegistry = IRegistry(_galaxisRegistry);
    }

}

File 18 of 52 : IVersionable.sol
//SPDX-License-Identifier: Unlicensed
pragma solidity 0.8.25;

/**
 * @title IVersionable
 * @dev Interface for versionable contracts.
 */
interface IVersionable {
    /**
     * @notice Get the current version of the contract.
     * @return The current version.
     */
    function version() external pure returns (uint256);
}

File 19 of 52 : IPaymentMatrix.sol
// SPDX-License-Identifier: UNLICENCED
pragma solidity 0.8.25;

interface IPaymentMatrix {
    function getDevIDAndAmountForTraitType(uint16 _traitType) external view returns(uint256 devId, uint256 amount);
    function getArtistIDAndAmountForCollection(uint32 _communityId, uint32 _collectionId) external view returns(uint256 artistId, uint256 amount);
}

File 20 of 52 : EnumerableSet.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

/**
 * @title Set implementation with enumeration functions
 * @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts (MIT license)
 */
library EnumerableSet {
    error EnumerableSet__IndexOutOfBounds();

    struct Set {
        bytes32[] _values;
        // 1-indexed to allow 0 to signify nonexistence
        mapping(bytes32 => uint256) _indexes;
    }

    struct Bytes32Set {
        Set _inner;
    }

    struct AddressSet {
        Set _inner;
    }

    struct UintSet {
        Set _inner;
    }

    function at(
        Bytes32Set storage set,
        uint256 index
    ) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    function at(
        AddressSet storage set,
        uint256 index
    ) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    function at(
        UintSet storage set,
        uint256 index
    ) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    function contains(
        Bytes32Set storage set,
        bytes32 value
    ) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    function contains(
        AddressSet storage set,
        address value
    ) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    function contains(
        UintSet storage set,
        uint256 value
    ) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    function indexOf(
        Bytes32Set storage set,
        bytes32 value
    ) internal view returns (uint256) {
        return _indexOf(set._inner, value);
    }

    function indexOf(
        AddressSet storage set,
        address value
    ) internal view returns (uint256) {
        return _indexOf(set._inner, bytes32(uint256(uint160(value))));
    }

    function indexOf(
        UintSet storage set,
        uint256 value
    ) internal view returns (uint256) {
        return _indexOf(set._inner, bytes32(value));
    }

    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    function add(
        Bytes32Set storage set,
        bytes32 value
    ) internal returns (bool) {
        return _add(set._inner, value);
    }

    function add(
        AddressSet storage set,
        address value
    ) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    function remove(
        Bytes32Set storage set,
        bytes32 value
    ) internal returns (bool) {
        return _remove(set._inner, value);
    }

    function remove(
        AddressSet storage set,
        address value
    ) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    function remove(
        UintSet storage set,
        uint256 value
    ) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    function toArray(
        Bytes32Set storage set
    ) internal view returns (bytes32[] memory) {
        return set._inner._values;
    }

    function toArray(
        AddressSet storage set
    ) internal view returns (address[] memory) {
        bytes32[] storage values = set._inner._values;
        address[] storage array;

        assembly {
            array.slot := values.slot
        }

        return array;
    }

    function toArray(
        UintSet storage set
    ) internal view returns (uint256[] memory) {
        bytes32[] storage values = set._inner._values;
        uint256[] storage array;

        assembly {
            array.slot := values.slot
        }

        return array;
    }

    function _at(
        Set storage set,
        uint256 index
    ) private view returns (bytes32) {
        if (index >= set._values.length)
            revert EnumerableSet__IndexOutOfBounds();
        return set._values[index];
    }

    function _contains(
        Set storage set,
        bytes32 value
    ) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    function _indexOf(
        Set storage set,
        bytes32 value
    ) private view returns (uint256) {
        unchecked {
            return set._indexes[value] - 1;
        }
    }

    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    function _add(
        Set storage set,
        bytes32 value
    ) private returns (bool status) {
        if (!_contains(set, value)) {
            set._values.push(value);
            set._indexes[value] = set._values.length;
            status = true;
        }
    }

    function _remove(
        Set storage set,
        bytes32 value
    ) private returns (bool status) {
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            unchecked {
                bytes32 last = set._values[set._values.length - 1];

                // move last value to now-vacant index

                set._values[valueIndex - 1] = last;
                set._indexes[last] = valueIndex;
            }
            // clear last index

            set._values.pop();
            delete set._indexes[value];

            status = true;
        }
    }
}

File 21 of 52 : ArrayFunctions.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;


library ArrayFunctions {

    function addressUintMap(uint256[] memory input, address user, function(address,uint) view returns (uint) f) internal view returns (uint256[] memory result) {
        result = new uint256[](input.length);
        for (uint pos = 0; pos < input.length; pos++) {
            result[pos] = f(user,input[pos]);
        }
    }

    function map(uint256[] memory input, function(uint) view returns (uint) f) internal view returns (uint256[] memory result) {
        result = new uint256[](input.length);
        for (uint pos = 0; pos < input.length; pos++) {
            result[pos] = f(input[pos]);
        }
    }

    function reduce(uint256[] memory input, function(uint,uint) view returns (uint) f) internal view returns (uint256 result) {
        result = input[0];
        for (uint pos = 1; pos < input.length; pos++) {
            result = f(result,input[pos]);
        }
    }
}

File 22 of 52 : ERC1155Base.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155 } from '../../interfaces/IERC1155.sol';
import { IERC1155Receiver } from '../../interfaces/IERC1155Receiver.sol';
import { IERC1155Base } from './IERC1155Base.sol';
import { ERC1155BaseInternal, ERC1155BaseStorage } from './ERC1155BaseInternal.sol';

/**
 * @title Base ERC1155 contract
 * @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts/ (MIT license)
 * @dev inheritor must either implement ERC165 supportsInterface or inherit ERC165Base
 */
abstract contract ERC1155Base is IERC1155Base, ERC1155BaseInternal {
    /**
     * @inheritdoc IERC1155
     */
    function balanceOf(
        address account,
        uint256 id
    ) public view virtual returns (uint256) {
        return _balanceOf(account, id);
    }

    /**
     * @inheritdoc IERC1155
     */
    function balanceOfBatch(
        address[] memory accounts,
        uint256[] memory ids
    ) public view virtual returns (uint256[] memory) {
        if (accounts.length != ids.length)
            revert ERC1155Base__ArrayLengthMismatch();

        mapping(uint256 => mapping(address => uint256))
            storage balances = ERC1155BaseStorage.layout().balances;

        uint256[] memory batchBalances = new uint256[](accounts.length);

        unchecked {
            for (uint256 i; i < accounts.length; i++) {
                if (accounts[i] == address(0))
                    revert ERC1155Base__BalanceQueryZeroAddress();
                batchBalances[i] = balances[ids[i]][accounts[i]];
            }
        }

        return batchBalances;
    }

    /**
     * @inheritdoc IERC1155
     */
    function isApprovedForAll(
        address account,
        address operator
    ) public view virtual returns (bool) {
        return ERC1155BaseStorage.layout().operatorApprovals[account][operator];
    }

    /**
     * @inheritdoc IERC1155
     */
    function setApprovalForAll(address operator, bool status) public virtual {
        if (msg.sender == operator) revert ERC1155Base__SelfApproval();
        ERC1155BaseStorage.layout().operatorApprovals[msg.sender][
            operator
        ] = status;
        emit ApprovalForAll(msg.sender, operator, status);
    }

    /**
     * @inheritdoc IERC1155
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public virtual {
        if (from != msg.sender && !isApprovedForAll(from, msg.sender))
            revert ERC1155Base__NotOwnerOrApproved();
        _safeTransfer(msg.sender, from, to, id, amount, data);
    }

    /**
     * @inheritdoc IERC1155
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public virtual {
        if (from != msg.sender && !isApprovedForAll(from, msg.sender))
            revert ERC1155Base__NotOwnerOrApproved();
        _safeTransferBatch(msg.sender, from, to, ids, amounts, data);
    }
}

File 23 of 52 : ERC1155BaseInternal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155Receiver } from '../../interfaces/IERC1155Receiver.sol';
import { AddressUtils } from '../../utils/AddressUtils.sol';
import { IERC1155BaseInternal } from './IERC1155BaseInternal.sol';
import { ERC1155BaseStorage } from './ERC1155BaseStorage.sol';

/**
 * @title Base ERC1155 internal functions
 * @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts/ (MIT license)
 */
abstract contract ERC1155BaseInternal is IERC1155BaseInternal {
    using AddressUtils for address;

    /**
     * @notice query the balance of given token held by given address
     * @param account address to query
     * @param id token to query
     * @return token balance
     */
    function _balanceOf(
        address account,
        uint256 id
    ) internal view virtual returns (uint256) {
        if (account == address(0))
            revert ERC1155Base__BalanceQueryZeroAddress();
        return ERC1155BaseStorage.layout().balances[id][account];
    }

    /**
     * @notice mint given quantity of tokens for given address
     * @dev ERC1155Receiver implementation is not checked
     * @param account beneficiary of minting
     * @param id token ID
     * @param amount quantity of tokens to mint
     * @param data data payload
     */
    function _mint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        if (account == address(0)) revert ERC1155Base__MintToZeroAddress();

        _beforeTokenTransfer(
            msg.sender,
            address(0),
            account,
            _asSingletonArray(id),
            _asSingletonArray(amount),
            data
        );

        ERC1155BaseStorage.layout().balances[id][account] += amount;

        emit TransferSingle(msg.sender, address(0), account, id, amount);
    }

    /**
     * @notice mint given quantity of tokens for given address
     * @param account beneficiary of minting
     * @param id token ID
     * @param amount quantity of tokens to mint
     * @param data data payload
     */
    function _safeMint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        _mint(account, id, amount, data);

        _doSafeTransferAcceptanceCheck(
            msg.sender,
            address(0),
            account,
            id,
            amount,
            data
        );
    }

    /**
     * @notice mint batch of tokens for given address
     * @dev ERC1155Receiver implementation is not checked
     * @param account beneficiary of minting
     * @param ids list of token IDs
     * @param amounts list of quantities of tokens to mint
     * @param data data payload
     */
    function _mintBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        if (account == address(0)) revert ERC1155Base__MintToZeroAddress();
        if (ids.length != amounts.length)
            revert ERC1155Base__ArrayLengthMismatch();

        _beforeTokenTransfer(
            msg.sender,
            address(0),
            account,
            ids,
            amounts,
            data
        );

        mapping(uint256 => mapping(address => uint256))
            storage balances = ERC1155BaseStorage.layout().balances;

        for (uint256 i; i < ids.length; ) {
            balances[ids[i]][account] += amounts[i];
            unchecked {
                i++;
            }
        }

        emit TransferBatch(msg.sender, address(0), account, ids, amounts);
    }

    /**
     * @notice mint batch of tokens for given address
     * @param account beneficiary of minting
     * @param ids list of token IDs
     * @param amounts list of quantities of tokens to mint
     * @param data data payload
     */
    function _safeMintBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        _mintBatch(account, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(
            msg.sender,
            address(0),
            account,
            ids,
            amounts,
            data
        );
    }

    /**
     * @notice burn given quantity of tokens held by given address
     * @param account holder of tokens to burn
     * @param id token ID
     * @param amount quantity of tokens to burn
     */
    function _burn(
        address account,
        uint256 id,
        uint256 amount
    ) internal virtual {
        if (account == address(0)) revert ERC1155Base__BurnFromZeroAddress();

        _beforeTokenTransfer(
            msg.sender,
            account,
            address(0),
            _asSingletonArray(id),
            _asSingletonArray(amount),
            ''
        );

        mapping(address => uint256) storage balances = ERC1155BaseStorage
            .layout()
            .balances[id];

        unchecked {
            if (amount > balances[account])
                revert ERC1155Base__BurnExceedsBalance();
            balances[account] -= amount;
        }

        emit TransferSingle(msg.sender, account, address(0), id, amount);
    }

    /**
     * @notice burn given batch of tokens held by given address
     * @param account holder of tokens to burn
     * @param ids token IDs
     * @param amounts quantities of tokens to burn
     */
    function _burnBatch(
        address account,
        uint256[] memory ids,
        uint256[] memory amounts
    ) internal virtual {
        if (account == address(0)) revert ERC1155Base__BurnFromZeroAddress();
        if (ids.length != amounts.length)
            revert ERC1155Base__ArrayLengthMismatch();

        _beforeTokenTransfer(msg.sender, account, address(0), ids, amounts, '');

        mapping(uint256 => mapping(address => uint256))
            storage balances = ERC1155BaseStorage.layout().balances;

        unchecked {
            for (uint256 i; i < ids.length; i++) {
                uint256 id = ids[i];
                if (amounts[i] > balances[id][account])
                    revert ERC1155Base__BurnExceedsBalance();
                balances[id][account] -= amounts[i];
            }
        }

        emit TransferBatch(msg.sender, account, address(0), ids, amounts);
    }

    /**
     * @notice transfer tokens between given addresses
     * @dev ERC1155Receiver implementation is not checked
     * @param operator executor of transfer
     * @param sender sender of tokens
     * @param recipient receiver of tokens
     * @param id token ID
     * @param amount quantity of tokens to transfer
     * @param data data payload
     */
    function _transfer(
        address operator,
        address sender,
        address recipient,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        if (recipient == address(0))
            revert ERC1155Base__TransferToZeroAddress();

        _beforeTokenTransfer(
            operator,
            sender,
            recipient,
            _asSingletonArray(id),
            _asSingletonArray(amount),
            data
        );

        mapping(uint256 => mapping(address => uint256))
            storage balances = ERC1155BaseStorage.layout().balances;

        unchecked {
            uint256 senderBalance = balances[id][sender];
            if (amount > senderBalance)
                revert ERC1155Base__TransferExceedsBalance();
            balances[id][sender] = senderBalance - amount;
        }

        balances[id][recipient] += amount;

        emit TransferSingle(operator, sender, recipient, id, amount);
    }

    /**
     * @notice transfer tokens between given addresses
     * @param operator executor of transfer
     * @param sender sender of tokens
     * @param recipient receiver of tokens
     * @param id token ID
     * @param amount quantity of tokens to transfer
     * @param data data payload
     */
    function _safeTransfer(
        address operator,
        address sender,
        address recipient,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) internal virtual {
        _transfer(operator, sender, recipient, id, amount, data);

        _doSafeTransferAcceptanceCheck(
            operator,
            sender,
            recipient,
            id,
            amount,
            data
        );
    }

    /**
     * @notice transfer batch of tokens between given addresses
     * @dev ERC1155Receiver implementation is not checked
     * @param operator executor of transfer
     * @param sender sender of tokens
     * @param recipient receiver of tokens
     * @param ids token IDs
     * @param amounts quantities of tokens to transfer
     * @param data data payload
     */
    function _transferBatch(
        address operator,
        address sender,
        address recipient,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        if (recipient == address(0))
            revert ERC1155Base__TransferToZeroAddress();
        if (ids.length != amounts.length)
            revert ERC1155Base__ArrayLengthMismatch();

        _beforeTokenTransfer(operator, sender, recipient, ids, amounts, data);

        mapping(uint256 => mapping(address => uint256))
            storage balances = ERC1155BaseStorage.layout().balances;

        for (uint256 i; i < ids.length; ) {
            uint256 token = ids[i];
            uint256 amount = amounts[i];

            unchecked {
                uint256 senderBalance = balances[token][sender];

                if (amount > senderBalance)
                    revert ERC1155Base__TransferExceedsBalance();

                balances[token][sender] = senderBalance - amount;

                i++;
            }

            // balance increase cannot be unchecked because ERC1155Base neither tracks nor validates a totalSupply
            balances[token][recipient] += amount;
        }

        emit TransferBatch(operator, sender, recipient, ids, amounts);
    }

    /**
     * @notice transfer batch of tokens between given addresses
     * @param operator executor of transfer
     * @param sender sender of tokens
     * @param recipient receiver of tokens
     * @param ids token IDs
     * @param amounts quantities of tokens to transfer
     * @param data data payload
     */
    function _safeTransferBatch(
        address operator,
        address sender,
        address recipient,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {
        _transferBatch(operator, sender, recipient, ids, amounts, data);

        _doSafeBatchTransferAcceptanceCheck(
            operator,
            sender,
            recipient,
            ids,
            amounts,
            data
        );
    }

    /**
     * @notice wrap given element in array of length 1
     * @param element element to wrap
     * @return singleton array
     */
    function _asSingletonArray(
        uint256 element
    ) private pure returns (uint256[] memory) {
        uint256[] memory array = new uint256[](1);
        array[0] = element;
        return array;
    }

    /**
     * @notice revert if applicable transfer recipient is not valid ERC1155Receiver
     * @param operator executor of transfer
     * @param from sender of tokens
     * @param to receiver of tokens
     * @param id token ID
     * @param amount quantity of tokens to transfer
     * @param data data payload
     */
    function _doSafeTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try
                IERC1155Receiver(to).onERC1155Received(
                    operator,
                    from,
                    id,
                    amount,
                    data
                )
            returns (bytes4 response) {
                if (response != IERC1155Receiver.onERC1155Received.selector)
                    revert ERC1155Base__ERC1155ReceiverRejected();
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert ERC1155Base__ERC1155ReceiverNotImplemented();
            }
        }
    }

    /**
     * @notice revert if applicable transfer recipient is not valid ERC1155Receiver
     * @param operator executor of transfer
     * @param from sender of tokens
     * @param to receiver of tokens
     * @param ids token IDs
     * @param amounts quantities of tokens to transfer
     * @param data data payload
     */
    function _doSafeBatchTransferAcceptanceCheck(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) private {
        if (to.isContract()) {
            try
                IERC1155Receiver(to).onERC1155BatchReceived(
                    operator,
                    from,
                    ids,
                    amounts,
                    data
                )
            returns (bytes4 response) {
                if (
                    response != IERC1155Receiver.onERC1155BatchReceived.selector
                ) revert ERC1155Base__ERC1155ReceiverRejected();
            } catch Error(string memory reason) {
                revert(reason);
            } catch {
                revert ERC1155Base__ERC1155ReceiverNotImplemented();
            }
        }
    }

    /**
     * @notice ERC1155 hook, called before all transfers including mint and burn
     * @dev function should be overridden and new implementation must call super
     * @dev called for both single and batch transfers
     * @param operator executor of transfer
     * @param from sender of tokens
     * @param to receiver of tokens
     * @param ids token IDs
     * @param amounts quantities of tokens to transfer
     * @param data data payload
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual {}
}

File 24 of 52 : ERC1155BaseStorage.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

library ERC1155BaseStorage {
    struct Layout {
        mapping(uint256 => mapping(address => uint256)) balances;
        mapping(address => mapping(address => bool)) operatorApprovals;
    }

    bytes32 internal constant STORAGE_SLOT =
        keccak256('solidstate.contracts.storage.ERC1155Base');

    function layout() internal pure returns (Layout storage l) {
        bytes32 slot = STORAGE_SLOT;
        assembly {
            l.slot := slot
        }
    }
}

File 25 of 52 : IERC1155Base.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155 } from '../../interfaces/IERC1155.sol';
import { IERC1155BaseInternal } from './IERC1155BaseInternal.sol';

/**
 * @title ERC1155 base interface
 */
interface IERC1155Base is IERC1155BaseInternal, IERC1155 {

}

File 26 of 52 : IERC1155BaseInternal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155Internal } from '../../interfaces/IERC1155Internal.sol';

/**
 * @title ERC1155 base interface
 */
interface IERC1155BaseInternal is IERC1155Internal {
    error ERC1155Base__ArrayLengthMismatch();
    error ERC1155Base__BalanceQueryZeroAddress();
    error ERC1155Base__NotOwnerOrApproved();
    error ERC1155Base__SelfApproval();
    error ERC1155Base__BurnExceedsBalance();
    error ERC1155Base__BurnFromZeroAddress();
    error ERC1155Base__ERC1155ReceiverRejected();
    error ERC1155Base__ERC1155ReceiverNotImplemented();
    error ERC1155Base__MintToZeroAddress();
    error ERC1155Base__TransferExceedsBalance();
    error ERC1155Base__TransferToZeroAddress();
}

File 27 of 52 : ERC1155Enumerable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { EnumerableSet } from '../../data/EnumerableSet.sol';
import { ERC1155BaseInternal } from '../base/ERC1155BaseInternal.sol';
import { IERC1155Enumerable } from './IERC1155Enumerable.sol';
import { ERC1155EnumerableInternal, ERC1155EnumerableStorage } from './ERC1155EnumerableInternal.sol';

/**
 * @title ERC1155 implementation including enumerable and aggregate functions
 */
abstract contract ERC1155Enumerable is
    IERC1155Enumerable,
    ERC1155EnumerableInternal
{
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.UintSet;

    /**
     * @inheritdoc IERC1155Enumerable
     */
    function totalSupply(uint256 id) public view virtual returns (uint256) {
        return _totalSupply(id);
    }

    /**
     * @inheritdoc IERC1155Enumerable
     */
    function totalHolders(uint256 id) public view virtual returns (uint256) {
        return _totalHolders(id);
    }

    /**
     * @inheritdoc IERC1155Enumerable
     */
    function accountsByToken(
        uint256 id
    ) public view virtual returns (address[] memory) {
        return _accountsByToken(id);
    }

    /**
     * @inheritdoc IERC1155Enumerable
     */
    function tokensByAccount(
        address account
    ) public view virtual returns (uint256[] memory) {
        return _tokensByAccount(account);
    }
}

File 28 of 52 : ERC1155EnumerableInternal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { EnumerableSet } from '../../data/EnumerableSet.sol';
import { ERC1155BaseInternal, ERC1155BaseStorage } from '../base/ERC1155BaseInternal.sol';
import { ERC1155EnumerableStorage } from './ERC1155EnumerableStorage.sol';

/**
 * @title ERC1155Enumerable internal functions
 */
abstract contract ERC1155EnumerableInternal is ERC1155BaseInternal {
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.UintSet;

    /**
     * @notice query total minted supply of given token
     * @param id token id to query
     * @return token supply
     */
    function _totalSupply(uint256 id) internal view virtual returns (uint256) {
        return ERC1155EnumerableStorage.layout().totalSupply[id];
    }

    /**
     * @notice query total number of holders for given token
     * @param id token id to query
     * @return quantity of holders
     */
    function _totalHolders(uint256 id) internal view virtual returns (uint256) {
        return ERC1155EnumerableStorage.layout().accountsByToken[id].length();
    }

    /**
     * @notice query holders of given token
     * @param id token id to query
     * @return list of holder addresses
     */
    function _accountsByToken(
        uint256 id
    ) internal view virtual returns (address[] memory) {
        return ERC1155EnumerableStorage
            .layout()
            .accountsByToken[id].toArray();

        // EnumerableSet.AddressSet storage accounts = ERC1155EnumerableStorage
        //     .layout()
        //     .accountsByToken[id];

        // address[] memory addresses = new address[](accounts.length());

        // unchecked {
        //     for (uint256 i; i < accounts.length(); i++) {
        //         addresses[i] = accounts.at(i);
        //     }
        // }

        // return addresses;
    }

    /**
     * @notice query tokens held by given address
     * @param account address to query
     * @return list of token ids
     */
    function _tokensByAccount(
        address account
    ) internal view virtual returns (uint256[] memory) {
        return ERC1155EnumerableStorage
            .layout()
            .tokensByAccount[account].toArray();

        // EnumerableSet.UintSet storage tokens = ERC1155EnumerableStorage
        //     .layout()
        //     .tokensByAccount[account];

        // uint256[] memory ids = new uint256[](tokens.length());

        // unchecked {
        //     for (uint256 i; i < tokens.length(); i++) {
        //         ids[i] = tokens.at(i);
        //     }
        // }

        // return ids;
    }

    /**
     * @notice ERC1155 hook: update aggregate values
     * @inheritdoc ERC1155BaseInternal
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);

        if (from != to) {
            ERC1155EnumerableStorage.Layout storage l = ERC1155EnumerableStorage
                .layout();
            mapping(uint256 => EnumerableSet.AddressSet)
                storage tokenAccounts = l.accountsByToken;
            EnumerableSet.UintSet storage fromTokens = l.tokensByAccount[from];
            EnumerableSet.UintSet storage toTokens = l.tokensByAccount[to];

            for (uint256 i; i < ids.length; ) {
                uint256 amount = amounts[i];

                if (amount > 0) {
                    uint256 id = ids[i];

                    if (from == address(0)) {
                        l.totalSupply[id] += amount;
                    } else if (_balanceOf(from, id) == amount) {
                        tokenAccounts[id].remove(from);
                        fromTokens.remove(id);
                    }

                    if (to == address(0)) {
                        l.totalSupply[id] -= amount;
                    } else if (_balanceOf(to, id) == 0) {
                        tokenAccounts[id].add(to);
                        toTokens.add(id);
                    }
                }

                unchecked {
                    i++;
                }
            }
        }
    }
}

File 29 of 52 : ERC1155EnumerableStorage.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { EnumerableSet } from '../../data/EnumerableSet.sol';

library ERC1155EnumerableStorage {
    struct Layout {
        mapping(uint256 => uint256) totalSupply;
        mapping(uint256 => EnumerableSet.AddressSet) accountsByToken;
        mapping(address => EnumerableSet.UintSet) tokensByAccount;
    }

    bytes32 internal constant STORAGE_SLOT =
        keccak256('solidstate.contracts.storage.ERC1155Enumerable');

    function layout() internal pure returns (Layout storage l) {
        bytes32 slot = STORAGE_SLOT;
        assembly {
            l.slot := slot
        }
    }
}

File 30 of 52 : IERC1155Enumerable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155BaseInternal } from '../base/IERC1155BaseInternal.sol';

/**
 * @title ERC1155 enumerable and aggregate function interface
 */
interface IERC1155Enumerable is IERC1155BaseInternal {
    /**
     * @notice query total minted supply of given token
     * @param id token id to query
     * @return token supply
     */
    function totalSupply(uint256 id) external view returns (uint256);

    /**
     * @notice query total number of holders for given token
     * @param id token id to query
     * @return quantity of holders
     */
    function totalHolders(uint256 id) external view returns (uint256);

    /**
     * @notice query holders of given token
     * @param id token id to query
     * @return list of holder addresses
     */
    function accountsByToken(
        uint256 id
    ) external view returns (address[] memory);

    /**
     * @notice query tokens held by given address
     * @param account address to query
     * @return list of token ids
     */
    function tokensByAccount(
        address account
    ) external view returns (uint256[] memory);
}

File 31 of 52 : ERC1155FullyEnumerable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import {IERC165} from '../interfaces/IERC165.sol';
import {IERC1155} from '../interfaces/IERC1155.sol';
import { ERC1155MetadataStorage } from './metadata/ERC1155Metadata.sol';


import { SolidStateERC1155 } from './SolidStateERC1155.sol';
import { EnumerableSet } from '../data/EnumerableSet.sol';
import { ArrayFunctions } from './ArrayFunctions.sol';

abstract contract ERC1155FullyEnumerable is SolidStateERC1155 {
    using EnumerableSet for EnumerableSet.AddressSet;
    using EnumerableSet for EnumerableSet.UintSet;
    using ArrayFunctions for uint256[];

    EnumerableSet.AddressSet accounts;
    EnumerableSet.UintSet tokenIdz;

    bool private erc1155FullInitialised;

    

    function _init(string memory _baseURI) internal {
        require(!erc1155FullInitialised, 'ERC1155FullyEnumerable: already initialised');
        _setSupportsInterface(type(IERC165).interfaceId, true);
        _setSupportsInterface(type(IERC1155).interfaceId, true);
        erc1155FullInitialised = true;
        ERC1155MetadataStorage.layout().baseURI = _baseURI;
    }

    function _setURI(string calldata _uri) internal {
        ERC1155MetadataStorage.layout().baseURI = _uri;
    }

    

    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) internal virtual override(SolidStateERC1155) {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
        if (to == address(0)) {
            // burning
            uint256[] memory bals = tokensByAccount(from);
            if (bals.length == 0) accounts.remove(from);
        } else {
            accounts.add(to);
        }

        for (uint j = 0; j < ids.length; j++) {
            uint256 id = ids[j];
            address[] memory addrs = accountsByToken(id);
            if (addrs.length == 0) {
                tokenIdz.remove(id);
            } else {
                tokenIdz.add(id);
            }
        }
    }

    // consider pagination here
    // maybe filters

    function numberOfTokenIds()external view returns (uint256) {
        return tokenIdz.length();
    }

    function tokenIds(uint256 start, uint256 count) external view returns (uint256[] memory ids) {
        uint len = tokenIdz.length();
        if (start >= len) return (new uint256[](0));
        if (start + count > len) {
            count = len - start;
        }
        ids = new uint256[](count);
        for (uint j = 0; j < count; j++) ids[j] = tokenIdz.at(start+j);
    }

    function tokenIds() external view returns (uint256[] memory ids) {
        return tokenIdz.toArray();
    }

    function tokenIdsAndBalances(address holder) external view returns (uint256[] memory _ids, uint256[] memory _balances) {
        _ids = _tokensByAccount(holder);
        _balances = _ids.addressUintMap(holder,balanceOf);
    }


    function numberOfHolders()external view returns (uint256) {
        return accounts.length();
    }

    function holders() external view returns (address[] memory holderz) {
        // console.log("holders()");
        return accounts.toArray();
    }

    function holders(uint256 start, uint256 count) external view returns (address[] memory holderz) {
        uint len = accounts.length();
        if (start >= len) return (new address[](0));
        if (start + count > len) {
            count = len - start;
        }
        holderz = new address[](count);
        for (uint j = 0; j < count; j++) holderz[j] = accounts.at(j+start);
    }

 
}

File 32 of 52 : ISolidStateERC1155.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155Base } from './base/IERC1155Base.sol';
import { IERC1155Enumerable } from './enumerable/IERC1155Enumerable.sol';
import { IERC1155Metadata } from './metadata/IERC1155Metadata.sol';

interface ISolidStateERC1155 is
    IERC1155Base,
    IERC1155Enumerable,
    IERC1155Metadata
{}

File 33 of 52 : ERC1155Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { UintUtils } from '../../utils/UintUtils.sol';
import { IERC1155Metadata } from './IERC1155Metadata.sol';
import { ERC1155MetadataInternal } from './ERC1155MetadataInternal.sol';
import { ERC1155MetadataStorage } from './ERC1155MetadataStorage.sol';

/**
 * @title ERC1155 metadata extensions
 */
abstract contract ERC1155Metadata is IERC1155Metadata, ERC1155MetadataInternal {
    using UintUtils for uint256;

    /**
     * @notice inheritdoc IERC1155Metadata
     */
    function uri(uint256 tokenId) public view virtual returns (string memory) {
        ERC1155MetadataStorage.Layout storage l = ERC1155MetadataStorage
            .layout();

        string memory tokenIdURI = l.tokenURIs[tokenId];
        string memory baseURI = l.baseURI;

        if (bytes(baseURI).length == 0) {
            return tokenIdURI;
        } else if (bytes(tokenIdURI).length > 0) {
            return string(abi.encodePacked(baseURI, tokenIdURI));
        } else {
            return string(abi.encodePacked(baseURI, tokenId.toString()));
        }
    }
}

File 34 of 52 : ERC1155MetadataInternal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155MetadataInternal } from './IERC1155MetadataInternal.sol';
import { ERC1155MetadataStorage } from './ERC1155MetadataStorage.sol';

/**
 * @title ERC1155Metadata internal functions
 */
abstract contract ERC1155MetadataInternal is IERC1155MetadataInternal {
    /**
     * @notice set base metadata URI
     * @dev base URI is a non-standard feature adapted from the ERC721 specification
     * @param baseURI base URI
     */
    function _setBaseURI(string memory baseURI) internal {
        ERC1155MetadataStorage.layout().baseURI = baseURI;
    }

    /**
     * @notice set per-token metadata URI
     * @param tokenId token whose metadata URI to set
     * @param tokenURI per-token URI
     */
    function _setTokenURI(uint256 tokenId, string memory tokenURI) internal {
        ERC1155MetadataStorage.layout().tokenURIs[tokenId] = tokenURI;
        emit URI(tokenURI, tokenId);
    }
}

File 35 of 52 : ERC1155MetadataStorage.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

/**
 * @title ERC1155 metadata extensions
 */
library ERC1155MetadataStorage {
    bytes32 internal constant STORAGE_SLOT =
        keccak256('solidstate.contracts.storage.ERC1155Metadata');

    struct Layout {
        string baseURI;
        mapping(uint256 => string) tokenURIs;
    }

    function layout() internal pure returns (Layout storage l) {
        bytes32 slot = STORAGE_SLOT;
        assembly {
            l.slot := slot
        }
    }
}

File 36 of 52 : IERC1155Metadata.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC1155MetadataInternal } from './IERC1155MetadataInternal.sol';

/**
 * @title ERC1155Metadata interface
 */
interface IERC1155Metadata is IERC1155MetadataInternal {
    /**
     * @notice get generated URI for given token
     * @return token URI
     */
    function uri(uint256 tokenId) external view returns (string memory);
}

File 37 of 52 : IERC1155MetadataInternal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

/**
 * @title Partial ERC1155Metadata interface needed by internal functions
 */
interface IERC1155MetadataInternal {
    event URI(string value, uint256 indexed tokenId);
}

File 38 of 52 : SolidStateERC1155.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { ERC165Base } from '../introspection/ERC165/base/ERC165Base.sol';
import { ERC1155Base, ERC1155BaseInternal } from './base/ERC1155Base.sol';
import { ERC1155Enumerable } from './enumerable/ERC1155Enumerable.sol';
import { ERC1155EnumerableInternal } from './enumerable/ERC1155EnumerableInternal.sol';
import { ERC1155Metadata } from './metadata/ERC1155Metadata.sol';
import { ISolidStateERC1155 } from './ISolidStateERC1155.sol';

/**
 * @title SolidState ERC1155 implementation
 */
abstract contract SolidStateERC1155 is
    ISolidStateERC1155,
    ERC1155Base,
    ERC1155Enumerable,
    ERC1155Metadata,
    ERC165Base
{
    /**
     * @inheritdoc ERC1155BaseInternal
     */
    function _beforeTokenTransfer(
        address operator,
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    )
        internal
        virtual
        override(ERC1155BaseInternal, ERC1155EnumerableInternal)
    {
        super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
    }
}

File 39 of 52 : IERC1155.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC165 } from './IERC165.sol';
import { IERC1155Internal } from './IERC1155Internal.sol';

/**
 * @title ERC1155 interface
 * @dev see https://eips.ethereum.org/EIPS/eip-1155
 */
interface IERC1155 is IERC1155Internal, IERC165 {
    /**
     * @notice query the balance of given token held by given address
     * @param account address to query
     * @param id token to query
     * @return token balance
     */
    function balanceOf(
        address account,
        uint256 id
    ) external view returns (uint256);

    /**
     * @notice query the balances of given tokens held by given addresses
     * @param accounts addresss to query
     * @param ids tokens to query
     * @return token balances
     */
    function balanceOfBatch(
        address[] calldata accounts,
        uint256[] calldata ids
    ) external view returns (uint256[] memory);

    /**
     * @notice query approval status of given operator with respect to given address
     * @param account address to query for approval granted
     * @param operator address to query for approval received
     * @return whether operator is approved to spend tokens held by account
     */
    function isApprovedForAll(
        address account,
        address operator
    ) external view returns (bool);

    /**
     * @notice grant approval to or revoke approval from given operator to spend held tokens
     * @param operator address whose approval status to update
     * @param status whether operator should be considered approved
     */
    function setApprovalForAll(address operator, bool status) external;

    /**
     * @notice transfer tokens between given addresses, checking for ERC1155Receiver implementation if applicable
     * @param from sender of tokens
     * @param to receiver of tokens
     * @param id token ID
     * @param amount quantity of tokens to transfer
     * @param data data payload
     */
    function safeTransferFrom(
        address from,
        address to,
        uint256 id,
        uint256 amount,
        bytes calldata data
    ) external;

    /**
     * @notice transfer batch of tokens between given addresses, checking for ERC1155Receiver implementation if applicable
     * @param from sender of tokens
     * @param to receiver of tokens
     * @param ids list of token IDs
     * @param amounts list of quantities of tokens to transfer
     * @param data data payload
     */
    function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] calldata ids,
        uint256[] calldata amounts,
        bytes calldata data
    ) external;
}

File 40 of 52 : IERC1155Internal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

/**
 * @title Partial ERC1155 interface needed by internal functions
 */
interface IERC1155Internal {
    event TransferSingle(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256 id,
        uint256 value
    );

    event TransferBatch(
        address indexed operator,
        address indexed from,
        address indexed to,
        uint256[] ids,
        uint256[] values
    );

    event ApprovalForAll(
        address indexed account,
        address indexed operator,
        bool approved
    );
}

File 41 of 52 : IERC1155Receiver.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC165 } from './IERC165.sol';

/**
 * @title ERC1155 transfer receiver interface
 */
interface IERC1155Receiver is IERC165 {
    /**
     * @notice validate receipt of ERC1155 transfer
     * @param operator executor of transfer
     * @param from sender of tokens
     * @param id token ID received
     * @param value quantity of tokens received
     * @param data data payload
     * @return function's own selector if transfer is accepted
     */
    function onERC1155Received(
        address operator,
        address from,
        uint256 id,
        uint256 value,
        bytes calldata data
    ) external returns (bytes4);

    /**
     * @notice validate receipt of ERC1155 batch transfer
     * @param operator executor of transfer
     * @param from sender of tokens
     * @param ids token IDs received
     * @param values quantities of tokens received
     * @param data data payload
     * @return function's own selector if transfer is accepted
     */
    function onERC1155BatchReceived(
        address operator,
        address from,
        uint256[] calldata ids,
        uint256[] calldata values,
        bytes calldata data
    ) external returns (bytes4);
}

File 42 of 52 : IERC165.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC165Internal } from './IERC165Internal.sol';

/**
 * @title ERC165 interface registration interface
 * @dev see https://eips.ethereum.org/EIPS/eip-165
 */
interface IERC165 is IERC165Internal {
    /**
     * @notice query whether contract has registered support for given interface
     * @param interfaceId interface id
     * @return bool whether interface is supported
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

File 43 of 52 : IERC165Internal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

/**
 * @title ERC165 interface registration interface
 */
interface IERC165Internal {

}

File 44 of 52 : ERC165Base.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC165 } from '../../../interfaces/IERC165.sol';
import { IERC165Base } from './IERC165Base.sol';
import { ERC165BaseInternal } from './ERC165BaseInternal.sol';
import { ERC165BaseStorage } from './ERC165BaseStorage.sol';

/**
 * @title ERC165 implementation
 */
abstract contract ERC165Base is IERC165Base, ERC165BaseInternal {
    /**
     * @inheritdoc IERC165
     */
    function supportsInterface(bytes4 interfaceId) public view returns (bool) {
        return _supportsInterface(interfaceId);
    }
}

File 45 of 52 : ERC165BaseInternal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { IERC165BaseInternal } from './IERC165BaseInternal.sol';
import { ERC165BaseStorage } from './ERC165BaseStorage.sol';

/**
 * @title ERC165 implementation
 */
abstract contract ERC165BaseInternal is IERC165BaseInternal {
    /**
     * @notice indicates whether an interface is already supported based on the interfaceId
     * @param interfaceId id of interface to check
     * @return bool indicating whether interface is supported
     */
    function _supportsInterface(
        bytes4 interfaceId
    ) internal view virtual returns (bool) {
        return ERC165BaseStorage.layout().supportedInterfaces[interfaceId];
    }

    /**
     * @notice sets status of interface support
     * @param interfaceId id of interface to set status for
     * @param status boolean indicating whether interface will be set as supported
     */
    function _setSupportsInterface(
        bytes4 interfaceId,
        bool status
    ) internal virtual {
        if (interfaceId == 0xffffffff) revert ERC165Base__InvalidInterfaceId();
        ERC165BaseStorage.layout().supportedInterfaces[interfaceId] = status;
    }
}

File 46 of 52 : ERC165BaseStorage.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

library ERC165BaseStorage {
    struct Layout {
        mapping(bytes4 => bool) supportedInterfaces;
    }

    bytes32 internal constant STORAGE_SLOT =
        keccak256('solidstate.contracts.storage.ERC165Base');

    function layout() internal pure returns (Layout storage l) {
        bytes32 slot = STORAGE_SLOT;
        assembly {
            l.slot := slot
        }
    }
}

File 47 of 52 : IERC165Base.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IERC165 } from '../../../interfaces/IERC165.sol';
import { IERC165BaseInternal } from './IERC165BaseInternal.sol';

interface IERC165Base is IERC165, IERC165BaseInternal {}

File 48 of 52 : IERC165BaseInternal.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import { IERC165Internal } from '../../../interfaces/IERC165Internal.sol';

interface IERC165BaseInternal is IERC165Internal {
    error ERC165Base__InvalidInterfaceId();
}

File 49 of 52 : AddressUtils.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

import { UintUtils } from './UintUtils.sol';

library AddressUtils {
    using UintUtils for uint256;

    error AddressUtils__InsufficientBalance();
    error AddressUtils__NotContract();
    error AddressUtils__SendValueFailed();

    function toString(address account) internal pure returns (string memory) {
        return uint256(uint160(account)).toHexString(20);
    }

    function isContract(address account) internal view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

    function sendValue(address payable account, uint256 amount) internal {
        (bool success, ) = account.call{ value: amount }('');
        if (!success) revert AddressUtils__SendValueFailed();
    }

    function functionCall(
        address target,
        bytes memory data
    ) internal returns (bytes memory) {
        return
            functionCall(target, data, 'AddressUtils: failed low-level call');
    }

    function functionCall(
        address target,
        bytes memory data,
        string memory error
    ) internal returns (bytes memory) {
        return _functionCallWithValue(target, data, 0, error);
    }

    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value
    ) internal returns (bytes memory) {
        return
            functionCallWithValue(
                target,
                data,
                value,
                'AddressUtils: failed low-level call with value'
            );
    }

    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory error
    ) internal returns (bytes memory) {
        if (value > address(this).balance)
            revert AddressUtils__InsufficientBalance();
        return _functionCallWithValue(target, data, value, error);
    }

    /**
     * @notice execute arbitrary external call with limited gas usage and amount of copied return data
     * @dev derived from https://github.com/nomad-xyz/ExcessivelySafeCall (MIT License)
     * @param target recipient of call
     * @param gasAmount gas allowance for call
     * @param value native token value to include in call
     * @param maxCopy maximum number of bytes to copy from return data
     * @param data encoded call data
     * @return success whether call is successful
     * @return returnData copied return data
     */
    function excessivelySafeCall(
        address target,
        uint256 gasAmount,
        uint256 value,
        uint16 maxCopy,
        bytes memory data
    ) internal returns (bool success, bytes memory returnData) {
        returnData = new bytes(maxCopy);

        assembly {
            // execute external call via assembly to avoid automatic copying of return data
            success := call(
                gasAmount,
                target,
                value,
                add(data, 0x20),
                mload(data),
                0,
                0
            )

            // determine whether to limit amount of data to copy
            let toCopy := returndatasize()

            if gt(toCopy, maxCopy) {
                toCopy := maxCopy
            }

            // store the length of the copied bytes
            mstore(returnData, toCopy)

            // copy the bytes from returndata[0:toCopy]
            returndatacopy(add(returnData, 0x20), 0, toCopy)
        }
    }

    function _functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory error
    ) private returns (bytes memory) {
        if (!isContract(target)) revert AddressUtils__NotContract();

        (bool success, bytes memory returnData) = target.call{ value: value }(
            data
        );

        if (success) {
            return returnData;
        } else if (returnData.length > 0) {
            assembly {
                let returnData_size := mload(returnData)
                revert(add(32, returnData), returnData_size)
            }
        } else {
            revert(error);
        }
    }
}

File 50 of 52 : UintUtils.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.8;

/**
 * @title utility functions for uint256 operations
 * @dev derived from https://github.com/OpenZeppelin/openzeppelin-contracts/ (MIT license)
 */
library UintUtils {
    error UintUtils__InsufficientHexLength();

    bytes16 private constant HEX_SYMBOLS = '0123456789abcdef';

    function add(uint256 a, int256 b) internal pure returns (uint256) {
        return b < 0 ? sub(a, -b) : a + uint256(b);
    }

    function sub(uint256 a, int256 b) internal pure returns (uint256) {
        return b < 0 ? add(a, -b) : a - uint256(b);
    }

    function toString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return '0';
        }

        uint256 temp = value;
        uint256 digits;

        while (temp != 0) {
            digits++;
            temp /= 10;
        }

        bytes memory buffer = new bytes(digits);

        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }

        return string(buffer);
    }

    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return '0x00';
        }

        uint256 length = 0;

        for (uint256 temp = value; temp != 0; temp >>= 8) {
            unchecked {
                length++;
            }
        }

        return toHexString(value, length);
    }

    function toHexString(
        uint256 value,
        uint256 length
    ) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = '0';
        buffer[1] = 'x';

        unchecked {
            for (uint256 i = 2 * length + 1; i > 1; --i) {
                buffer[i] = HEX_SYMBOLS[value & 0xf];
                value >>= 4;
            }
        }

        if (value != 0) revert UintUtils__InsufficientHexLength();

        return string(buffer);
    }
}

File 51 of 52 : GenericTrait.sol
// SPDX-License-Identifier: UNLICENCED
pragma solidity 0.8.25;

import "../../../@galaxis/registries/contracts/CommunityRegistry.sol";
import "../../../@galaxis/registries/contracts/UsesGalaxisRegistry.sol";

import "../../../PaymentMatrix/IPaymentMatrix.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";

interface IGTRegistry {
    function addressCanModifyTrait(address, uint16) external view returns (bool);
    function getTraitControllerAccessData(address) external view returns (uint8[] memory);
    function myCommunityRegistry() external view returns (CommunityRegistry);
    function tokenNumber() external view returns (uint32);
    function TOKEN_KEY() external view returns (string memory);
}

enum FieldTypes {
    NONE,
    STORED_BOOL,
    STORED_UINT_8,
    STORED_UINT_16,
    STORED_UINT_32,
    STORED_UINT_64,
    STORED_UINT_128,
    STORED_UINT_256,       
    STORED_BYTES_32,       // bytes32 fixed
    STORED_STRING,         // bytes array
    STORED_BYTES,          // bytes array
    STORED_ADDRESS,
    LOGIC_BOOL,
    LOGIC_UINT_8,
    LOGIC_UINT_32,
    LOGIC_UINT_64,
    LOGIC_UINT_128,
    LOGIC_UINT_256,
    LOGIC_BYTES_32,
    LOGIC_ADDRESS
}

struct traitProperty {
    bytes32     _name;
    FieldTypes  _type;
    bytes4      _selector;
    bytes       _default;
    bool        _limited;
    uint256     _min;
    uint256     _max;
    bool        _reset_on_owner_change;
}

struct traitInfo {
    uint16 _id;
    uint16 _type;
    address _registry;
    uint256 _baseVersion;
    uint256 _version;
    traitProperty[] _schema;
    uint8   _propertyCount;
    bytes32 _app;
    traitConfig _traitConfig; 
}

struct traitConfig {
    bool inverted;
}

enum BitType {
    NONE,
    EXISTS,
    INITIALIZED
}

enum TraitStatus {
    NONE,
    // NOT_INITIALIZED,
    ACTIVE,
    DORMANT,
    SPENT
}

enum MovementPermission {
    NONE,
    OPEN,
    LOCKED,
    SOULBOUND,
    SOULBURN
}

enum ModifierMode {
    NONE,
    ADD,
    SET
}


contract GenericTrait is UsesGalaxisRegistry  {

    uint16      public     traitId;
    IGTRegistry public     GTRegistry;
    event tokenTraitChangeEvent(uint32 indexed _tokenId);

    function baseVersion() public pure returns (uint256) {
        return 2024052201;
    }

    function version() public pure virtual returns (uint256) {
        return baseVersion();
    }
    
    function TRAIT_TYPE() public pure virtual returns (uint16) {
        return 0;   // Physical redemption
    }

    function APP() public pure virtual returns (bytes32) {
        return "generic-trait";   // Physical redemption
    }

    constructor(address _galaxisRegistry) UsesGalaxisRegistry(_galaxisRegistry) {
        
    }


    function tellEverything() external view returns(traitInfo memory) {
        return traitInfo(
            traitId,
            TRAIT_TYPE(),
            address(GTRegistry),
            baseVersion(),
            version(),
            getSchema(),
            propertyCount,
            APP(),
            thisTraitConfig
        );
    }

    // constructor(
    //     address _registry,
    //     uint16 _traitId,
    //     bytes[] memory _defaultPropValues
    // ) {
    //     traitId = _traitId;
    //     GTRegistry = IGTRegistry(_registry);
    //     for(uint8 i = 0; i < _defaultPropValues.length; i++) {
    //         defaultPropValues[i] = _defaultPropValues[i];
    //     }
    // }

    // cannot store as bytes unless we only allow simple types, no string / array 

    /*
        Set Properties
        Name	            type	defaults	description
        Expiration  date	date	-	        Trait can't be used after expiration date passes
        Counter	            int	    -	        Trait can only be used this many times
        Cooldown	        int	    -	        current date + cooldonw = Activation Date
        Activation Date	    date	-	        If set, trait can't be used before this date
        Modifier Lock	    bool	FALSE	    if True, Value Modifier Traits can't modify limiters
        Burn If Spent	    bool	FALSE	    If trait's status ever becomes "spent", it gets burned.
        Movement Permission	status	OPEN	    See "movement permission"
        Royalty ID	        ID	    -	        ID of the entity who is entitled to the Usage Royalty
        Royalty Amount	    int	    0	        Royalty amount in GLX


        Discount Trait Properties
        Name	        type	defaults	    Description
        Discount Type	status	PERCENTAGE	    It can be either PERCENTAGE or a fix GLX AMOUNT
        Discount Amount	int	    -	            Either 0-100 or a GLX amount
        Acceptor Type	status	MARKETPLACE	    Acceptor Type, can't be blank. Check Discounts for list.
        Max	            int	    -	            max value possible (value modifier can't go beyond)
        Modifier Lock	bool	FALSE	        If true, Value Modifier Traits have no effect


        Digital Redeemable Trait Properties
        Name	        Type	defaults	description
        Vault	        ID	    -	        The target vault of the redeemable. Can not be empty.
        Luck	        0-100	0	        If greater than zero, the Luck Process is invoked.
        Redeem Mode	    ID	    RR	        See "Redeem Modes" in the Vault page.
        Modifier Lock	bool	FALSE	    If True, Value Modifiers can't apply to this trait.


        Physical Redeemable Trait Properties
        name	    type	description
        item name	ID	    name of the item that can be redeemed


        Value Modifier Trait Properties
        name	    type	defaults	description
        Trait Type	ID	    -	        What type of trait to modify (Digital Redeemable, etc)
        Property	ID	    -	        What property of that trait to modify
        Mode	    ID	    ADD	        ADD or SET
        Value	    int	    -	        By how much

    */

    bool public initialized = false;
    traitConfig thisTraitConfig;

    mapping(uint8 => traitProperty) property;
    uint8 propertyCount = 0;
    mapping(bytes32 => uint8) propertyNameToId;
    mapping(uint8 => uint8) propertyStorageMap;

    //      propId  => tokenId => ( index => value )
    mapping(uint8 => mapping( uint32 => bytes ) ) storageMapArray;
    //      tokenId => data ( except bytes / string which go into storageMapArray )
    mapping(uint32 => bytes ) storageData;

    //      propId  => tokenId => ( index => value )
    mapping(uint8 => bytes ) storageMapArrayDEFAULT;
    //      tokenId => data ( except bytes / string which go into storageMapArrayDEFAULT )

    bytes tokenDataDEFAULT;
    mapping(uint8 => bytes ) defaultPropValues;

    // we need an efficient way to activate traits at mint or by using dropper
    // to achieve this we set 1 bit per tokenId
    // 

    mapping(uint32 => uint8 )    public existsData;
    mapping(uint32 => uint8 )    initializedData;

    // indexed props
    bool    public modifier_lock;
    uint8   public movement_permission;

    bytes32 constant constant_royalty_id_key = hex"726f79616c74795f696400000000000000000000000000000000000000000000";
    bytes32 constant constant_royalty_amount_key = hex"726f79616c74795f616d6f756e74000000000000000000000000000000000000";
    bytes32 constant constant_owner_stored_key = hex"6f776e65725f73746f7265640000000000000000000000000000000000000000";

    // constructor() {
    //     init();
    // }

    function isLogicFieldType(FieldTypes _type) internal pure returns (bool) {
        if(_type == FieldTypes.LOGIC_BOOL) {
            return true;
        }
        if(_type == FieldTypes.LOGIC_UINT_8) {
            return true;
        }
        if(_type == FieldTypes.LOGIC_UINT_32) {
            return true;
        }
        if(_type == FieldTypes.LOGIC_UINT_64) {
            return true;
        }
        if(_type == FieldTypes.LOGIC_UINT_128) {
            return true;
        }
        if(_type == FieldTypes.LOGIC_UINT_256) {
            return true;
        }
        if(_type == FieldTypes.LOGIC_BYTES_32) {
            return true;
        }
        if(_type == FieldTypes.LOGIC_ADDRESS) {
            return true;
        }
        return false;
    }

    function _addProperty(bytes32 _name, FieldTypes _type, bytes4 _selector) internal {
        uint8 thisId = propertyCount;

        if(propertyNameToId[_name] > 0) {
            // no duplicates
            revert();
        } else {
            propertyNameToId[_name]     = thisId;
            traitProperty storage prop = property[thisId];
            prop._name = _name;
            prop._type = _type;
            prop._selector = _selector;
            prop._default = defaultPropValues[thisId]; // _default;
            propertyCount++;
        }
    }

    function addStoredProperty(bytes32 _name, FieldTypes _type) internal {
        _addProperty(_name, _type, bytes4(0));
    }

    function addLogicProperty(bytes32 _name, FieldTypes _type, bytes4 _selector) internal {
        _addProperty(_name, _type, _selector);
    }

    function addPropertyLimits(bytes32 _name, uint256 _min, uint256 _max) internal {
        uint8 _id = propertyNameToId[_name];
        traitProperty storage thisProp = property[_id];
        require(thisProp._selector == bytes4(hex"00000000"), "Trait: Cannot set limits on Logic property");
        thisProp._limited = true;
        thisProp._min = _min;
        thisProp._max = _max;
    }

    function setPropertyResetOnOwnerChange(bytes32 _name) internal {
        uint8 _id = propertyNameToId[_name];
        traitProperty storage thisProp = property[_id];
        thisProp._reset_on_owner_change = true;
    }

    function _initStandardProps() internal {
        require(!initialized, "Trait: already initialized!");

        addLogicProperty( bytes32("exists"),              FieldTypes.LOGIC_BOOL,        bytes4(keccak256("hasTrait(uint32)")));
        addLogicProperty( bytes32("initialized"),         FieldTypes.LOGIC_BOOL,        bytes4(keccak256("isInitialized(uint32)")));

        // required for soulbound
        addStoredProperty(bytes32("owner_stored"),        FieldTypes.STORED_ADDRESS);
        addLogicProperty( bytes32("owner_current"),       FieldTypes.LOGIC_ADDRESS,     bytes4(keccak256("currentTokenOwnerAddress(uint32)")));


        // if true, Value Modifier Traits can't modify limiters
        addStoredProperty(bytes32("modifier_lock"),       FieldTypes.STORED_BOOL);
        addStoredProperty(bytes32("movement_permission"), FieldTypes.STORED_UINT_8);
        addStoredProperty(bytes32("activation"),          FieldTypes.STORED_UINT_256);
        addStoredProperty(bytes32("cooldown"),            FieldTypes.STORED_UINT_256);
        addStoredProperty(bytes32("expiration"),          FieldTypes.STORED_UINT_256);
        addStoredProperty(bytes32("counter"),             FieldTypes.STORED_UINT_8);

        addStoredProperty(bytes32("royalty_id"),          FieldTypes.STORED_UINT_256);
        addStoredProperty(bytes32("royalty_amount"),      FieldTypes.STORED_UINT_256);

        addLogicProperty( bytes32("status"),              FieldTypes.LOGIC_UINT_8,      bytes4(keccak256("status(uint32)")));



        // setPropertySoulbound()
            // owner_stored
            // if(_name == hex"6f776e65725f73746f7265640000000000000000000000000000000000000000") {
            //     prop._soulbound = true;
            // }


        // status change on owner_current change
        // if movement_permission == MovementPermission.SOULBOUND
        // on addTrait / setProperty / setData set owner_stored
        // 
        

        // prop reset on owner_stored
        // _reset_on_owner_change
        // addStoredProperty(bytes32("points"),              FieldTypes.STORED_UINT_256);
        // setPropertyResetOnOwnerChange(bytes32("points"));
        // addStoredProperty(bytes32("points"),              FieldTypes.STORED_UINT_256);

        // addPropertyLimits(bytes32("cooldown"),      0,      3600 * 24);
        // addPropertyLimits(bytes32("counter"),       0,      100);
    }

    function setup(
        address _registry,
        uint16 _traitId,
        traitConfig memory _traitConfig,
        bytes[] memory _defaultPropValues
    ) virtual public {
        require(!initialized, "Trait: already initialized!");
        GTRegistry = IGTRegistry(_registry);
        traitId = _traitId;
        thisTraitConfig = _traitConfig;
        for(uint8 i = 0; i < _defaultPropValues.length; i++) {
            defaultPropValues[i] = _defaultPropValues[i];
        }        
    }

    

    function init() virtual public {
        _initStandardProps();
        // custom props
        afterInit();
    }

    function getRoyaltiesForThisTraitType() internal view returns (uint256, uint256) {
        IPaymentMatrix PaymentMatrix = IPaymentMatrix(
            galaxisRegistry.getRegistryAddress("PAYMENT_MATRIX")
        ); 
        
        require(address(PaymentMatrix) != address(0), "Trait: PAYMENT_MATRIX address cannot be 0");

        // if(initialized){} 
        return PaymentMatrix.getDevIDAndAmountForTraitType(TRAIT_TYPE());
    }

    function afterInit() internal {

        // overwrite royalty_id / royalty_amount
        (uint256 royalty_id, uint256 royalty_amount) = getRoyaltiesForThisTraitType();
        for(uint8 _id = 0; _id < propertyCount; _id++) {
            traitProperty memory thisProp = property[_id];
            if(thisProp._name == constant_royalty_id_key || thisProp._name == constant_royalty_amount_key) {
                bytes memory value;
                if(thisProp._name == constant_royalty_id_key) {
                    value = abi.encode(royalty_id);
                } else if(thisProp._name == constant_royalty_amount_key) {
                    value = abi.encode(royalty_amount);
                }
                defaultPropValues[_id] = value;
                property[_id]._default = value;
            } 

            // reset default owner in case deployer wrote a different address here
            if(thisProp._name == constant_owner_stored_key ) {
                property[_id]._default = abi.encode(address(0));
            }
        }

        // index for cheaper internal logic
        modifier_lock = (uint256(bytes32(getProperty("modifier_lock", 0))) > 0 );
        movement_permission = abi.decode(getProperty("movement_permission", 0), (uint8));
        // set defaults
        tokenDataDEFAULT = getDefaultTokenDataOutput();

        initialized = true;
    }


    function getSchema() public view returns (traitProperty[] memory) {
        traitProperty[] memory myProps = new traitProperty[](propertyCount);
        for(uint8 i = 0; i < propertyCount; i++) {
            myProps[i] = property[i];
        }
        return myProps;
    }

    // function _getFieldTypeByteLenght(uint8 _id) public view returns (uint16) {
    //     traitProperty storage thisProp = property[_id];
    //     if(thisProp._type == FieldTypes.LOGIC_BOOL || thisProp._type == FieldTypes.STORED_BOOL) {
    //         return 1;
    //     }
    //     else if(thisProp._type == FieldTypes.STORED_UINT_8) {
    //         return 1;
    //     }
    //     else if(thisProp._type == FieldTypes.STORED_UINT_16) {
    //         return 2;
    //     }
    //     else if(thisProp._type == FieldTypes.STORED_UINT_32) {
    //         return 4;
    //     }
    //     else if(thisProp._type == FieldTypes.STORED_UINT_64) {
    //         return 8;
    //     }
    //     else if(thisProp._type == FieldTypes.STORED_UINT_128) {
    //         return 16;
    //     }
    //     else if(thisProp._type == FieldTypes.STORED_UINT_256) {
    //         return 32;
    //     }
    //     else if(thisProp._type == FieldTypes.STORED_STRING || thisProp._type == FieldTypes.STORED_BYTES) {
    //         // array length for strings / bytes limited to uint16.
    //         return 2;
    //     }

    //     revert("Trait: FieldType Not Implemented");
    // }

    function getOutputBufferLength(uint32 _tokenId) public view returns(uint16, uint16) {
        // abi.encode style 32 byte blocks
        // with memory pointer at location for complex types
        // pointer to length followed by records
        uint16 propCount = propertyCount;
        uint16 _length = 32 * propCount;
        uint16 complexDataOutputPtr = _length;
        bytes memory tokenData = bytes(storageData[_tokenId]);
        
        for(uint8 _id = 0; _id < propertyCount; _id++) {
            FieldTypes thisPropType = property[_id]._type;
            if(thisPropType == FieldTypes.STORED_STRING || thisPropType == FieldTypes.STORED_BYTES) {
                uint16 offset = uint16(_id) * 32;
                // console.log("getOutputBufferLength", _id, offset);
                bytes memory arrayLenB = new bytes(2);
                if(tokenData.length > 0) {
                    arrayLenB[0] = bytes1(tokenData[offset + 30]);
                    arrayLenB[1] = bytes1(tokenData[offset + 31]);
                    // each complex type adds another 32 for length 
                    // and data 32 * ceil(length/32)
                    _length+= 32 + 32 + ( 32 * ( uint16(bytes2(arrayLenB)) / 32 ) );

                } else {
                    arrayLenB[0] = 0;
                    arrayLenB[1] = 0;
                    _length+= 32;
                }
            }
        }
        return (_length, complexDataOutputPtr);
    }

    function getData(uint32[] memory _tokenIds) public view returns(bytes[] memory) {
        bytes[] memory outputs = new bytes[](_tokenIds.length);
        for(uint32 i = 0; i < _tokenIds.length; i++) {
            outputs[i] = getData(_tokenIds[i]);
        }
        return outputs;
    }

    function getDefaultTokenDataOutput() public view returns(bytes memory) {
        uint32 _tokenId = 0;
        ( uint16 _length, uint16 complexDataOutputPtr) = getOutputBufferLength(_tokenId);
        bytes memory outputBuffer = new bytes(_length);
        uint256 outputPtr;
        uint256 complexDataOutputRealPtr;
        uint256 _start = 0;

        assembly {
            // jump over length 32 byte block
            outputPtr := add(outputBuffer, 32)
            complexDataOutputRealPtr := add(outputPtr, complexDataOutputPtr)
        }

        for(uint8 _id = 0; _id < propertyCount; _id++) {
            _start+=32;

            FieldTypes thisPropType = property[_id]._type;
            if(thisPropType == FieldTypes.STORED_STRING || thisPropType == FieldTypes.STORED_BYTES) {
                bytes memory value = storageMapArrayDEFAULT[_id];
                assembly {
                    // let readptr := add(tokenData, _start)
                    // store location of data in place
                    mstore(outputPtr, complexDataOutputPtr)

                    complexDataOutputPtr := add(complexDataOutputPtr, 32)
                    let byteLength := mload(value)
                    let itemBlocks := div(byteLength, 32)
                    if lt(mul(itemBlocks, 32), byteLength ) {
                        itemBlocks := add(itemBlocks, 1)
                    }
                    // store array length
                    mstore(complexDataOutputRealPtr, byteLength)
                    complexDataOutputRealPtr:= add(complexDataOutputRealPtr, 32)
                    for { let n := 0 } lt(n, itemBlocks) { n := add(n, 1) } {
                        // store array 32 byte blocks
                        mstore(
                            complexDataOutputRealPtr, 
                            mload(
                                add(value, mul(add(n,1), 32) ) 
                            )
                        )
                        complexDataOutputRealPtr:= add(complexDataOutputRealPtr, 32)
                    }
                    complexDataOutputPtr := add(complexDataOutputPtr, mul(itemBlocks, 32))
                }

            }
            else {
                bytes32 value = bytes32(property[_id]._default);
                assembly {
                    // store empty value in place
                    mstore(outputPtr, value)
                }
            }

            assembly {
                outputPtr := add(outputPtr, 32)
            }
        }
        return outputBuffer;

    }

    function getData(uint32 _tokenId) public view returns(bytes memory) {
        uint16 _length = 0;
        uint16 complexDataOutputPtr;
        ( _length, complexDataOutputPtr) = getOutputBufferLength(_tokenId);
        bytes memory outputBuffer = new bytes(_length);
        bytes memory tokenData = storageData[_tokenId];

        if(!isInitialized(_tokenId)) {
            tokenData = tokenDataDEFAULT;
        }

        // 32 byte block contains bytes array size / length
        if(tokenData.length == 0) {
            // could simply return empty outputBuffer here..;
            tokenData = new bytes(
                uint16(propertyCount) * 32
            );
        }

        uint256 outputPtr;
        uint256 complexDataOutputRealPtr;
        uint256 _start = 0;

        assembly {
            // jump over length 32 byte block
            outputPtr := add(outputBuffer, 32)
            complexDataOutputRealPtr := add(outputPtr, complexDataOutputPtr)
        }

        for(uint8 _id = 0; _id < propertyCount; _id++) {
            _start+=32;

            FieldTypes thisPropType = property[_id]._type;
            if(thisPropType == FieldTypes.STORED_STRING || thisPropType == FieldTypes.STORED_BYTES) {
                bytes memory value = storageMapArray[_id][_tokenId];
                assembly {
                    // let readptr := add(tokenData, _start)
                    // store location of data in place
                    mstore(outputPtr, complexDataOutputPtr)

                    complexDataOutputPtr := add(complexDataOutputPtr, 32)
                    let byteLength := mload(value)
                    let itemBlocks := div(byteLength, 32)
                    if lt(mul(itemBlocks, 32), byteLength ) {
                        itemBlocks := add(itemBlocks, 1)
                    }
                    // store array length
                    mstore(complexDataOutputRealPtr, byteLength)
                    complexDataOutputRealPtr:= add(complexDataOutputRealPtr, 32)
                    for { let n := 0 } lt(n, itemBlocks) { n := add(n, 1) } {
                        // store array 32 byte blocks
                        mstore(
                            complexDataOutputRealPtr, 
                            mload(
                                add(value, mul(add(n,1), 32) ) 
                            )
                        )
                        complexDataOutputRealPtr:= add(complexDataOutputRealPtr, 32)
                    }
                    complexDataOutputPtr := add(complexDataOutputPtr, mul(itemBlocks, 32))
                }

            }
            else if(isLogicFieldType(thisPropType)) {

                callMethodAndCopyToOutputPointer(
                    property[_id]._selector, 
                    _tokenId,
                    outputPtr
                );

            } else {
                assembly {
                    // store value in place
                    mstore(outputPtr, mload(
                        add(tokenData, _start)
                    ))
                }
            }

            assembly {
                outputPtr := add(outputPtr, 32)
            }
        }
        return outputBuffer;
    }

    function callMethodAndCopyToOutputPointer(bytes4 _selector, uint32 _tokenId, uint256 outputPtr ) internal view {
        (bool success, bytes memory callResult) = address(this).staticcall(
            abi.encodeWithSelector(_selector, _tokenId)
        );
        require(success, "Trait: internal method call failed");
        // console.logBytes(callResult);
        assembly {
            // store value in place  // shift by 32 so we just get the value
            mstore(outputPtr, mload(add(callResult, 32)))
        }
    }

    /*
        should remove, gives too much power
    */
    function setData(uint32 _tokenId, bytes memory _bytesData) public onlyAllowed {
        _setData(_tokenId, _bytesData);
        
        //
        _updateCurrentOwnerInStorage(_tokenId);
    }

    function _setData(uint32 _tokenId, bytes memory _bytesData) internal {
        
        if(!hasTrait(_tokenId)) {
            // if the trait does not exist
            setTraitExistance(_tokenId, true);
        }

        if(!isInitialized(_tokenId)) {
            // if the trait is not initialized
            _tokenSetBit(_tokenId, BitType.INITIALIZED, true);
        }

        uint16 _length = uint16(propertyCount) * 32;
        if(_bytesData.length < _length) {
            revert("Trait: Message not long enough");
        }

        bytes memory newTokenData = new bytes(_length);
        uint256 newTokenDataPtr;
        uint256 readPtr;
        assembly {
            // jump over length 32 byte block
            newTokenDataPtr := add(newTokenData, 32)
            readPtr := add(_bytesData, 32)
        }

        for(uint8 _id = 0; _id < propertyCount; _id++) {
            FieldTypes thisPropType = property[_id]._type;
            bytes32 fieldValue;
            assembly {
                fieldValue:= mload(readPtr)
            }

            if(thisPropType == FieldTypes.STORED_STRING || thisPropType == FieldTypes.STORED_BYTES) {
                // read length from offset stored in fieldValue
                bytes32 byteLength;
                uint256 complexDataPtr;
                assembly {
                    complexDataPtr:= add(
                        add(_bytesData, 32),
                        fieldValue
                    )

                    byteLength:= mload(complexDataPtr)
                    // store length
                    mstore(newTokenDataPtr, byteLength)
                }

                bytes memory propValue = new bytes(uint256(byteLength));

                assembly {
                
                    let propValuePtr := add(propValue, 32)
                    let itemBlocks := div(byteLength, 32)
                    if lt(mul(itemBlocks, 32), byteLength ) {
                        itemBlocks := add(itemBlocks, 1)
                    }

                    // store array 32 byte blocks
                    for { let n := 0 } lt(n, itemBlocks) { n := add(n, 1) } {
                        complexDataPtr:= add(complexDataPtr, 32)
                        mstore(
                            propValuePtr, 
                            mload(complexDataPtr)
                        )                        
                        propValuePtr:= add(propValuePtr, 32)
                    }

                }
                storageMapArray[_id][_tokenId] = propValue;
            
            } else if(isLogicFieldType(thisPropType)) {
                // do nothing
            } else {
                // just store fieldValue in newTokenData
                assembly {
                    mstore(newTokenDataPtr, fieldValue)
                }
            }

            assembly {
                newTokenDataPtr := add(newTokenDataPtr, 32)
                readPtr := add(readPtr, 32)
            }
        }
        storageData[_tokenId] = newTokenData;
        emit tokenTraitChangeEvent(_tokenId);
    }

    // function getPropertyOutputBufferLength(uint8 _id, FieldTypes _thisPropType, uint32 _tokenId) public view returns(uint16) {
    //     uint16 _length = 32;
    //     bytes memory tokenData = bytes(storageData[_tokenId]);
    //     if(_thisPropType == FieldTypes.STORED_STRING || _thisPropType == FieldTypes.STORED_BYTES) {
    //         uint16 offset = _id * 32;
    //         bytes memory arrayLenB = new bytes(2);
    //         if(tokenData.length > 0) {
    //             arrayLenB[0] = bytes1(tokenData[offset + 30]);
    //             arrayLenB[1] = bytes1(tokenData[offset +31]);
    //             // each complex type adds another 32 for length 
    //             // and data 32 * ceil(length/32)
    //             _length+= 32 + 32 + ( 32 * ( uint16(bytes2(arrayLenB)) / 32 ) );
    //         } else {
    //             arrayLenB[0] = 0;
    //             arrayLenB[1] = 0;
    //         }
    //     }
        
    //     return _length;
    // }

    function getProperties(uint32 _tokenId, bytes32[] memory _names) public  view returns(bytes[] memory) {
        bytes[] memory outputs = new bytes[](_names.length);
        for(uint32 i = 0; i < _names.length; i++) {
            outputs[i] = getProperty(_names[i], _tokenId);
        }
        return outputs;
    }

    function getProperty(bytes32 _name, uint32 _tokenId) public view returns (bytes memory) {
        uint8 _id = propertyNameToId[_name];
        FieldTypes thisPropType = property[_id]._type;
        if(!isInitialized(_tokenId) && !isLogicFieldType(thisPropType)) {
            // if the trait has not been initialized, and is not a method return, we return default stored data
            return property[_id]._default;
        } else {
            return _getProperty(_id, _tokenId);
        }
    }

    function _getProperty(uint8 _id, uint32 _tokenId) internal view returns (bytes memory) {
        FieldTypes thisPropType = property[_id]._type;
        bytes memory output = new bytes(32);
        uint256 outputPtr;
        assembly {
            outputPtr := add(output, 32)
        }
        if(thisPropType == FieldTypes.STORED_STRING || thisPropType == FieldTypes.STORED_BYTES) {
            output = storageMapArray[_id][_tokenId];
        }
        else if(isLogicFieldType(thisPropType)) {
            callMethodAndCopyToOutputPointer(
                property[_id]._selector, 
                _tokenId,
                outputPtr
            );
        }
        else {
            bytes memory tokenData = bytes(storageData[_tokenId]);
            // first 32 is tokenData length
            uint256 _start = 32 + 32 * uint16(_id);
            assembly {
                outputPtr := add(output, 32)
                // store value in place
                mstore(outputPtr, mload(
                        add(tokenData, _start)
                    )
                )
            }
        }
        return output; 
    }

    // function canUpdateTo(bytes32 _name, bytes memory newValue) public view returns (bool) {
    //     return true;

    //     uint8 _id = propertyNameToId[_name];
    //     traitProperty memory thisProp = property[_id];
        
    //     thisProp._limited;

    //     if(modifier_lock) {
    //         // if()
    //         return false;
    //     }
    //     return false;
    //     // 
    // }

    function setProperties(uint32 _tokenId, bytes32[] memory _names, bytes[] memory inputs) public onlyAllowed {
        _updateCurrentOwnerInStorage(_tokenId);

        for(uint8 i = 0; i < _names.length; i++) {
            bytes32 name = _names[i];
            if(name == constant_owner_stored_key) {
                revert("Trait: dissalowed! Cannot set owner_stored value!");
            }
            _setProperty(name, _tokenId, inputs[i]);
        }
    }


    function setProperty(bytes32 _name, uint32 _tokenId, bytes memory input) public onlyAllowed {
        if(_name == constant_owner_stored_key) {
            revert("Trait: dissalowed! Cannot set owner_stored value!");
        }
        _updateCurrentOwnerInStorage(_tokenId);
        _setProperty(_name, _tokenId, input);
    }

    function _updateCurrentOwnerInStorage(uint32 _tokenId) internal {
        if(movement_permission == uint8(MovementPermission.SOULBOUND)) {
            // if default address 0 value, then do the update
            if(
                // decoded stored value
                abi.decode(getProperty(constant_owner_stored_key, _tokenId), (address)) 
                == address(0)
            ) {
                _setProperty(
                    constant_owner_stored_key,
                    _tokenId, 
                    // abi encodePacked left shifts everything, but ethers.js cannot decode that properly!
                    abi.encode(currentTokenOwnerAddress(_tokenId))
                );
            }
            // else do nothing
        } else {
            _setProperty(
                constant_owner_stored_key,
                _tokenId, 
                // abi encodePacked left shifts everything, but ethers.js cannot decode that properly!
                abi.encode(currentTokenOwnerAddress(_tokenId))
            );
        }

    }

    function _setProperty(bytes32 _name, uint32 _tokenId, bytes memory input) internal {
        // if(!canUpdateTo(_name, input)) {
        //     revert("Trait: Cannot update values because modifier lock is true");
        // }

        if(!hasTrait(_tokenId)) {
            // if the trait does not exist
            setTraitExistance(_tokenId, true);
        }

        if(!isInitialized(_tokenId)) {
            // if the trait is not initialized
            _tokenSetBit(_tokenId, BitType.INITIALIZED, true);
            _setData(_tokenId, tokenDataDEFAULT);
        }

        uint8 _id = propertyNameToId[_name];
        FieldTypes thisPropType = property[_id]._type;

        if(isLogicFieldType(thisPropType)) {
            revert("Trait: Cannot set logic value!");
        } else {

            uint16 _length = uint16(propertyCount) * 32;
            bytes memory tokenData = bytes(storageData[_tokenId]);
            if(tokenData.length == 0) {
                tokenData = new bytes(_length);
                // init default tokenData.. empty for now
            }

            uint256 valuePtr;
            if(thisPropType == FieldTypes.STORED_STRING || thisPropType == FieldTypes.STORED_BYTES) {
                assembly {
                    valuePtr := input
                }
                storageMapArray[_id][_tokenId] = input;

            } else {
                assembly {
                    // load from pointer location
                    valuePtr := add(input, 32)
                }
            }

            assembly {
                // store incomming length value into value slot
                mstore(
                    add(
                        add(tokenData, 32),
                        mul(_id, 32) 
                    ),
                    mload(valuePtr)
                )
            }
            storageData[_tokenId] = tokenData;
        }
        
        emit tokenTraitChangeEvent(_tokenId);
    }

    function getByteAndBit(uint32 _offset) public pure returns (uint32 _byte, uint8 _bit) {
        // find byte storig our bit
        _byte = uint32(_offset / 8);
        _bit = uint8(_offset - _byte * 8);
    }

    function hasTrait(uint32 _tokenId) public view returns (bool result) {
        bool _hasTrait = _tokenHasBit(_tokenId, BitType.EXISTS);
        if(thisTraitConfig.inverted) {
            return !_hasTrait;
        }
        return _hasTrait;
    }

    function isInitialized(uint32 _tokenId) public view returns (bool result) {
        return _tokenHasBit(_tokenId, BitType.INITIALIZED);
    }

    function _tokenHasBit(uint32 _tokenId, BitType _bitType) internal view returns (bool result) {
        uint8 bitType = uint8(_bitType);
        (uint32 byteNum, uint8 bitPos) = getByteAndBit(_tokenId);
        if(bitType == 1) {
            return existsData[byteNum] & (0x01 * 2**bitPos) != 0;
        } else if(bitType == 2) {
            return initializedData[byteNum] & (0x01 * 2**bitPos) != 0;
        }
    }

    function status(uint32 _tokenId) public view returns ( uint8 ) {
        TraitStatus statusValue = TraitStatus.NONE;
        if(hasTrait(_tokenId)) {
            uint256 activation  = uint256(bytes32(getProperty("activation", _tokenId)));
            uint256 expiration  = uint256(bytes32(getProperty("expiration", _tokenId)));
            uint256 counter     = uint256(bytes32(getProperty("counter",    _tokenId)));

            if(expiration == 0) {
                // expiration 0 means never
                expiration = block.timestamp + 3600;
            }

            if(counter > 0) {
                if(activation <= block.timestamp && block.timestamp <= expiration) {

                    // SOULBOUND Check
                    if(movement_permission == uint8(MovementPermission.SOULBOUND)) {

                        address storedOwnerValue = abi.decode(getProperty(constant_owner_stored_key, _tokenId), (address));
                        address currentOwnerValue = currentTokenOwnerAddress(_tokenId);
                        
                        if(storedOwnerValue == currentOwnerValue) {
                            statusValue = TraitStatus.ACTIVE;
                        } else {
                            statusValue = TraitStatus.DORMANT;
                        }

                    } else {
                        statusValue = TraitStatus.ACTIVE;
                    }

                } else {
                    statusValue = TraitStatus.DORMANT;
                }
            } else {
                statusValue = TraitStatus.SPENT;
            }
        }
        return uint8(statusValue);
    }

    // marks token as having the trait
    function addTrait(uint32[] memory _tokenIds) public onlyAllowed {
        for(uint16 _id = 0; _id < _tokenIds.length; _id++) {
            if(!hasTrait(_tokenIds[_id])) {
                // if trait is soulbound we have to initialize it.. 
                if(movement_permission == uint8(MovementPermission.SOULBOUND)) {
                    _updateCurrentOwnerInStorage(_tokenIds[_id]);     
                } else {
                    setTraitExistance(_tokenIds[_id], true);
                    emit tokenTraitChangeEvent(_tokenIds[_id]);
                }
            } else {
                revert("Trait: Token already has trait!");
            }
        }
    }

    function setTraitExistance(uint32 _tokenId, bool _value) internal {
        if(thisTraitConfig.inverted) {
            _value = !_value;
        }
        _tokenSetBit(_tokenId, BitType.EXISTS, _value);
    }

    // util, sets bit in item in map at position as true / false
    function _tokenSetBit(uint32 _tokenId, BitType _bitType, bool _value) internal {
        (uint32 byteNum, uint8 bitPos) = getByteAndBit(_tokenId);
        if(_bitType == BitType.EXISTS) {
            if(_value) {
                existsData[byteNum] = uint8(existsData[byteNum] | 2**bitPos);
            } else {
                existsData[byteNum] = uint8(existsData[byteNum] & ~(2**bitPos));
            }
        } else if(_bitType == BitType.INITIALIZED) {
            if(_value) {
                initializedData[byteNum] = uint8(initializedData[byteNum] | 2**bitPos);
            } else {
                initializedData[byteNum] = uint8(initializedData[byteNum] & ~(2**bitPos));
            }
        }
    }

    function _removeTrait(uint32 _tokenId) internal returns (bool) {
        require(hasTrait(_tokenId), "Trait: Token does not have trait!");

        delete storageData[_tokenId];
        for(uint8 _id = 0; _id < propertyCount; _id++) {
            FieldTypes thisPropType = property[_id]._type;
            if(thisPropType == FieldTypes.STORED_STRING || thisPropType == FieldTypes.STORED_BYTES) {
                delete storageMapArray[_id][_tokenId];
            }
        }

        setTraitExistance(_tokenId, false);
        _tokenSetBit(_tokenId, BitType.INITIALIZED, false);

        emit tokenTraitChangeEvent(_tokenId);
        return true;
    }

    function removeTrait(uint32[] memory _tokenIds) public onlyAllowed returns (bool) {
        for(uint8 i = 0; i < _tokenIds.length; i++) {
            _removeTrait(_tokenIds[i]);
        }
        return true;
    }

    function incrementCounter(uint32 _tokenId) public onlyAllowed {
        uint256 counter     = uint256(bytes32(getProperty("counter", _tokenId))) + 1;
        require(counter < 256, "GenericTrait: counter exceeds max (255)");
        setProperty("counter", _tokenId, abi.encodePacked(counter));
    }

    function decrementCounter(uint32 _tokenId) public onlyAllowed {
        uint256 counter     = uint256(bytes32(getProperty("counter", _tokenId)));
        require(counter > 0, "GenericTrait: attempt to decrement zero counter");
        uint256 cooldown    = uint256(bytes32(getProperty("cooldown", _tokenId)));
        setProperty("counter", _tokenId, abi.encodePacked(counter - 1));
        setProperty("activation", _tokenId, abi.encodePacked(block.timestamp + cooldown));
    }


    function currentTokenOwnerAddress(uint32 _tokenId) public view returns (address) {
        return IERC721(
            (GTRegistry.myCommunityRegistry()).getRegistryAddress(
                GTRegistry.TOKEN_KEY()
            )
        ).ownerOf(_tokenId);
    }

    modifier onlyAllowed() {
        require(
            GTRegistry.addressCanModifyTrait(msg.sender, traitId) ||
            galaxisRegistry.getRegistryAddress("ACTION_HUB") == msg.sender, "Trait: Not authorized.");
        _;
    }

}

File 52 of 52 : GTRegistry.sol
// SPDX-License-Identifier: UNLICENCED
pragma solidity 0.8.25;

import "../../@galaxis/registries/contracts/CommunityList.sol";
import "../../@galaxis/registries/contracts/UsesGalaxisRegistry.sol";
import "../../@galaxis/registries/contracts/CommunityRegistry.sol";
import "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract GTRegistry is UsesGalaxisRegistry {

    function version() public pure virtual returns (uint256) {
        return 2024040401;
    }

    bytes32                 public constant TRAIT_REGISTRY_ADMIN    = keccak256("TRAIT_REGISTRY_ADMIN");
    bytes32                 public constant TRAIT_DROP_ADMIN        = keccak256("TRAIT_DROP_ADMIN");
    bytes32                 public constant GLOBAL_TRAIT_DATA_ADMIN = keccak256("GLOBAL_TRAIT_DATA_ADMIN");

    CommunityRegistry       public          myCommunityRegistry;
    uint32                  public          tokenNumber;
    string                  public          TOKEN_KEY;
    bool                                    initialised;

    struct traitStruct {
        uint16  id;
        uint8   traitType;              
        
        // 0 normal (1bit), 1 range, 2 inverted range, >=3 with storageImplementer
        
        // internal 
        // - 0 for normal
        // - 1 for inverted
        // - 2 for inverted range
        // external 
        // - 3 Physical redeemables
        // - 4 Appointment
        // - 5 Autograph
        // 
        // - 100 uint8 values,
        // - 101 uint256 values
        // - 102 bytes32,
        // - 103 string
        // - 104 visual traits implementer

        uint256 start;                  // Range start for type 1/2 traits               
        uint256 end;                    // Range end for type 1/2 traits               
        bool    enabled;                // Frontend is responsible to hide disabled traits
        address storageImplementer;     // address of the smart contract that will implement the storage for the trait
        string  ipfsHash;               // IPFS address to store trait data (icon, etc.)
        string  name;
    }

    uint16 public traitCount;
    mapping(uint16 => traitStruct) public traits;


    // trait controller access designates sub contracts that can affect 1 or more traits
    mapping(uint16 => address ) public traitControllerById;
    mapping(address => uint16 ) public traitControllerByAddress;
    uint16 public traitControllerCount = 0;
    mapping(address => mapping(uint8 => uint8) ) public traitControllerAccess;
    mapping( uint8 => address ) public defaultTraitControllerAddressByType;

    /*
    *   Events
    */
    event traitControllerEvent(address _address);

    // Traits master data change
    event newTraitMasterEvent(uint16 indexed _id, string _name, address _address, uint8 _traitType, uint256 _start, uint256 _end);
    event updateTraitMasterEvent(uint16 indexed _id, string _name, address _address, uint8 _traitType, uint256 _start, uint256 _end);

    constructor (address _galaxisRegistry) UsesGalaxisRegistry(_galaxisRegistry) {
        initialised = true;                 // GOLDEN protection
    }

    function init(uint32  _communityId, uint32  _tokenNum) external {
        _init(_communityId, _tokenNum);
    }

    function _init(uint32  _communityId, uint32  _tokenNum) internal virtual {
        require(!initialised,"TraitRegistry: Already initialised");
        initialised = true;

        // Get the community_list contract
        CommunityList COMMUNITY_LIST = CommunityList(galaxisRegistry.getRegistryAddress("COMMUNITY_LIST"));
        // Get the community data
        (,address crAddr,) = COMMUNITY_LIST.communities(_communityId);
        myCommunityRegistry = CommunityRegistry(crAddr);
        tokenNumber = _tokenNum;
        TOKEN_KEY = string(abi.encodePacked("TOKEN_", Strings.toString(tokenNumber)));


        // Only the GOLDEN version can exist without valid community ID
        address GoldenECRegistryAddr = galaxisRegistry.getRegistryAddress("GOLDEN_TRAIT_REGISTRY");
        if( GoldenECRegistryAddr != address(this) ) {
            require(crAddr != address(0), "TraitRegistry: Invalid community ID");
        }
    }

    function getTrait(uint16 id) public view returns (traitStruct memory) {
        return traits[id];
    }

    function getTraits() public view returns (traitStruct[] memory) {
        traitStruct[] memory retval = new traitStruct[](traitCount);
        for(uint16 i = 0; i < traitCount; i++) {
            retval[i] = traits[i];
        }
        return retval;
    }

    function addTrait(
        traitStruct[] calldata _newTraits
    ) public onlyAllowed(TRAIT_REGISTRY_ADMIN) {

        for (uint8 i = 0; i < _newTraits.length; i++) {

            uint16 newTraitId = traitCount++;
            traitStruct storage newT = traits[newTraitId];
            newT.id =           newTraitId;
            newT.name =         _newTraits[i].name;
            newT.traitType =    _newTraits[i].traitType;
            newT.start =        _newTraits[i].start;
            newT.end =          _newTraits[i].end;
            newT.enabled =      _newTraits[i].enabled;
            newT.ipfsHash =     _newTraits[i].ipfsHash;
            newT.storageImplementer = _newTraits[i].storageImplementer;

            emit newTraitMasterEvent(newTraitId, newT.name, newT.storageImplementer, newT.traitType, newT.start, newT.end );
        }
    }

    function updateTrait(
        uint16 _index,
        string memory _name,
        address _storageImplementer,
        uint8   _traitType,
        uint256 _start,
        uint256 _end,
        bool    _enabled,
        string memory _ipfsHash
    ) public onlyAllowed(TRAIT_REGISTRY_ADMIN) {
        require(_storageImplementer != address(0),"TraitRegistry: Invalid StorageImplementer");
        traits[_index].name = _name;
        traits[_index].storageImplementer = _storageImplementer;
        traits[_index].ipfsHash = _ipfsHash;
        traits[_index].enabled = _enabled;
        traits[_index].traitType = _traitType;
        traits[_index].start = _start;
        traits[_index].end = _end;

        emit updateTraitMasterEvent(traits[_index].id, _name, _storageImplementer, _traitType, _start, _end);
    }

    function getTraitControllerAccessData(address _addr) public view returns (uint8[] memory) {
        uint16 _returnCount = getByteCountToStoreTraitData();
        uint8[] memory retValues = new uint8[](_returnCount);
        for(uint8 i = 0; i < _returnCount; i++) {
            retValues[i] = traitControllerAccess[_addr][i];
        }
        return retValues;
    }

    function getByteCountToStoreTraitData() internal view returns (uint16) {
        uint16 _returnCount = traitCount/8;
        if(_returnCount * 8 < traitCount) {
            _returnCount++;
        }
        return _returnCount;
    }

    function getByteAndBit(uint16 _offset) public pure returns (uint16 _byte, uint8 _bit)
    {
        // find byte storig our bit
        _byte = uint16(_offset / 8);
        _bit = uint8(_offset - _byte * 8);
    }

    function getImplementer(uint16 traitID) public view returns (address implementer)
    {
        return traits[traitID].storageImplementer;
    }


    /*
    *   Admin Stuff
    */

    function setDefaultTraitControllerType(address _addr, uint8 _traitType) external onlyAllowed(TRAIT_REGISTRY_ADMIN) {
        defaultTraitControllerAddressByType[_traitType] = _addr;
        emit traitControllerEvent(_addr);
    }

    function getDefaultTraitControllerByType(uint8 _traitType) external view returns (address) {
        return defaultTraitControllerAddressByType[_traitType];
    }

    /*
    *   Trait Controllers
    */

    function indexTraitController(address _addr) internal {
        if(traitControllerByAddress[_addr] == 0) {
            uint16 controllerId = ++traitControllerCount;
            traitControllerByAddress[_addr] = controllerId;
            traitControllerById[controllerId] = _addr;
        }
    }

    function setTraitControllerAccessData(address _addr, uint8[] calldata _data) public onlyAllowed(TRAIT_REGISTRY_ADMIN) {
        indexTraitController(_addr);
        for (uint8 i = 0; i < _data.length; i++) {
            traitControllerAccess[_addr][i] = _data[i];
        }
        emit traitControllerEvent(_addr);
    }

    function setTraitControllerAccess(address _addr, uint16 traitID, bool _value) public onlyAllowed(TRAIT_REGISTRY_ADMIN) {
        indexTraitController(_addr);
        if(_addr != address(0)) {
            (uint16 byteNum, uint8 bitPos) = getByteAndBit(traitID);
            if(_value) {
                traitControllerAccess[_addr][uint8(byteNum)] = uint8(traitControllerAccess[_addr][uint8(byteNum)] | 2**bitPos);
            } else {
                traitControllerAccess[_addr][uint8(byteNum)] = uint8(traitControllerAccess[_addr][uint8(byteNum)] & ~(2**bitPos));
            }
        }
        emit traitControllerEvent(_addr);
    }
 
    function addressCanModifyTrait(address _addr, uint16 traitID) public view returns (bool result) {
        (uint16 byteNum, uint8 bitPos) = getByteAndBit(traitID);
        return 
            traitControllerAccess[_addr][uint8(byteNum)] & (0x01 * 2**bitPos) != 0 ||
            hasRole(TRAIT_DROP_ADMIN, _addr) || 
            myCommunityRegistry.isUserCommunityAdmin(GLOBAL_TRAIT_DATA_ADMIN,_addr);
    }

    function addressCanModifyTraits(address _addr, uint16[] memory traitIDs) public view returns (bool result) {
        for(uint16 i = 0; i < traitIDs.length; i++) {
            if(!addressCanModifyTrait(_addr, traitIDs[i])) {
                return false;
            }
        }
        return true;
    }

    modifier onlyAllowed(bytes32 role) { 
        require(isAllowed(role, msg.sender), "TraitRegistry: Unauthorised");
        _;
    }

    function isAllowed(bytes32 role, address user) public view returns (bool) {
        return( hasRole(role, user));
    }

    function hasRole(bytes32 key, address user) public view returns (bool) {
        return myCommunityRegistry.hasRole(key, user);
    }

    modifier onlyTraitController(uint16 traitID) {
        require(
            addressCanModifyTrait(msg.sender, traitID),
            "TraitRegistry: Not Authorised"
        );
        _;
    }

}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_galaxisRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ERC1155Base__ArrayLengthMismatch","type":"error"},{"inputs":[],"name":"ERC1155Base__BalanceQueryZeroAddress","type":"error"},{"inputs":[],"name":"ERC1155Base__BurnExceedsBalance","type":"error"},{"inputs":[],"name":"ERC1155Base__BurnFromZeroAddress","type":"error"},{"inputs":[],"name":"ERC1155Base__ERC1155ReceiverNotImplemented","type":"error"},{"inputs":[],"name":"ERC1155Base__ERC1155ReceiverRejected","type":"error"},{"inputs":[],"name":"ERC1155Base__MintToZeroAddress","type":"error"},{"inputs":[],"name":"ERC1155Base__NotOwnerOrApproved","type":"error"},{"inputs":[],"name":"ERC1155Base__SelfApproval","type":"error"},{"inputs":[],"name":"ERC1155Base__TransferExceedsBalance","type":"error"},{"inputs":[],"name":"ERC1155Base__TransferToZeroAddress","type":"error"},{"inputs":[],"name":"ERC165Base__InvalidInterfaceId","type":"error"},{"inputs":[],"name":"EnumerableSet__IndexOutOfBounds","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"URI","type":"event"},{"inputs":[],"name":"UTILITY_TRAIT_COUPON_ADMIN","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"accountsByToken","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"},{"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"collectionIDs","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_tokenNumber","type":"uint32"},{"internalType":"uint16","name":"_traitID","type":"uint16"}],"name":"collectionTraitNumberIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_tokenNumber","type":"uint32"},{"internalType":"uint16","name":"_traitID","type":"uint16"},{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"length","type":"uint256"}],"name":"collectionTraitNumberIdsByPage","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_tokenNumber","type":"uint32"}],"name":"collectionTraitNumbers","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"communityId","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"configurationData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint16","name":"","type":"uint16"}],"name":"configurationMaxPointer","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"counterByPointer","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"galaxisRegistry","outputs":[{"internalType":"contract IRegistry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"tokenNum","type":"uint32"},{"internalType":"uint16","name":"traitNum","type":"uint16"},{"internalType":"uint256","name":"pointer","type":"uint256"}],"name":"getData","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"getInfo","outputs":[{"internalType":"uint32","name":"tokenNum","type":"uint32"},{"internalType":"uint16","name":"traitNum","type":"uint16"},{"internalType":"uint256","name":"pointer","type":"uint256"},{"internalType":"bytes","name":"_configurationData","type":"bytes"},{"components":[{"internalType":"bytes32","name":"_name","type":"bytes32"},{"internalType":"enum FieldTypes","name":"_type","type":"uint8"},{"internalType":"bytes4","name":"_selector","type":"bytes4"},{"internalType":"bytes","name":"_default","type":"bytes"},{"internalType":"bool","name":"_limited","type":"bool"},{"internalType":"uint256","name":"_min","type":"uint256"},{"internalType":"uint256","name":"_max","type":"uint256"},{"internalType":"bool","name":"_reset_on_owner_change","type":"bool"}],"internalType":"struct traitProperty[]","name":"traitProperties","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"holders","outputs":[{"internalType":"address[]","name":"holderz","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"count","type":"uint256"}],"name":"holders","outputs":[{"internalType":"address[]","name":"holderz","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_communityId","type":"uint32"},{"internalType":"string","name":"_uri","type":"string"}],"name":"init","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"tokenNumber","type":"uint32"},{"internalType":"uint16","name":"traitNumber","type":"uint16"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"makeId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint32","name":"_tokenNumber","type":"uint32"},{"internalType":"uint16","name":"_traitNumber","type":"uint16"},{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"uint256","name":"_numberToMint","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"_counter","type":"uint256"}],"name":"mint","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numberOfHolders","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"numberOfTokenIds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_tokenNumber","type":"uint32"},{"internalType":"uint16","name":"_traitID","type":"uint16"}],"name":"numberOfTraitNumberIds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_uri","type":"string"}],"name":"setURI","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenIds","outputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"count","type":"uint256"}],"name":"tokenIds","outputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"holder","type":"address"}],"name":"tokenIdsAndBalances","outputs":[{"internalType":"uint256[]","name":"_ids","type":"uint256[]"},{"internalType":"uint256[]","name":"_balances","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"tokenNumberQty","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"uint16","name":"","type":"uint16"}],"name":"tokenTraitQty","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"tokensByAccount","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalHolders","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"}]

60a060405234801561001057600080fd5b506040516141e73803806141e783398101604081905261002f916101da565b6001600160a01b03811660805260408051808201909152601b81527f474f4c44454e5f5554494c4954595f54524149545f434f55504f4e0000000000602082015261007990610091565b61008b6301193f3d60e61b6001610164565b5061036a565b60045460ff16156100fc5760405162461bcd60e51b815260206004820152602b60248201527f4552433131353546756c6c79456e756d657261626c653a20616c72656164792060448201526a1a5b9a5d1a585b1a5cd95960aa1b606482015260840160405180910390fd5b61010e6301ffc9a760e01b6001610164565b610120636cdb3d1360e11b6001610164565b6004805460ff19166001179055806101557f4281b61aefbe70b3d3f684b428efca5f33077bc240e76f2808f9177c307617f490565b9061016090826102ab565b5050565b6001600160e01b0319808316900361018f5760405163b0a19dd560e01b815260040160405180910390fd5b6001600160e01b03199190911660009081527ffc606c433378e3a7e0a6a531deac289b66caa1b4aa8554fd4ab2c6f1570f92d860205260409020805460ff1916911515919091179055565b6000602082840312156101ec57600080fd5b81516001600160a01b038116811461020357600080fd5b9392505050565b634e487b7160e01b600052604160045260246000fd5b600181811c9082168061023457607f821691505b60208210810361025457634e487b7160e01b600052602260045260246000fd5b50919050565b601f8211156102a6576000816000526020600020601f850160051c810160208610156102835750805b601f850160051c820191505b818110156102a25782815560010161028f565b5050505b505050565b81516001600160401b038111156102c4576102c461020a565b6102d8816102d28454610220565b8461025a565b602080601f83116001811461030d57600084156102f55750858301515b600019600386901b1c1916600185901b1785556102a2565b600085815260208120601f198616915b8281101561033c5788860151825594840194600190910190840161031d565b508582101561035a5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b608051613e466103a16000396000818161046b015281816107ee0152818161108e015281816113ba0152611b240152613e466000f3fe608060405234801561001057600080fd5b506004361061025d5760003560e01c8063714cff5611610146578063a22cb465116100c3578063dc47b3c111610087578063dc47b3c1146105d6578063e985e9c5146105de578063e9949c58146105f1578063eed8cc3514610604578063f242432a14610617578063f6d465891461062a57600080fd5b8063a22cb46514610577578063aed6176e1461058a578063b390c0ab1461059d578063bd85b039146105b0578063ca0425f2146105c357600080fd5b806383485eed1161010a57806383485eed146104d857806385bff2e7146104f8578063899dfbea1461050b57806395d89b41146105365780639ba12dfa1461055657600080fd5b8063714cff5614610456578063725639a01461045e5780637671114d146104665780637f50861a146104a55780638188f71c146104d057600080fd5b80631972793f116101df5780634860f5ce116101a35780634860f5ce146103e05780634e1273f4146103f35780635272e8821461040657806354fd4d50146104195780635b521461146104235780636dcfd8411461043657600080fd5b80631972793f1461036e5780631a3cd59a146103815780631a81397f146103a55780632eb2c2d6146103b857806343bb6eb8146103cb57600080fd5b806306fdde031161022657806306fdde03146102f35780630807c62d146103085780630e89341c1461032857806313ba55df1461033b57806315473de01461034e57600080fd5b8062fdd58e146102625780630199c7b21461028857806301ffc9a71461029057806302fe5305146102b357806305b2c810146102c8575b600080fd5b610275610270366004612d03565b61063d565b6040519081526020015b60405180910390f35b610275610652565b6102a361029e366004612d45565b610663565b604051901515815260200161027f565b6102c66102c1366004612daa565b6106a4565b005b6102756102d6366004612e14565b600660209081526000928352604080842090915290825290205481565b6102fb61076d565b60405161027f9190612e99565b610275610316366004612eac565b60076020526000908152604090205481565b6102fb610336366004612ec9565b6107ac565b610275610349366004612ec9565b61094c565b61036161035c366004612ee2565b610957565b60405161027f9190612f62565b61027561037c366004612e14565b610a6b565b61039461038f366004612ec9565b610a98565b60405161027f959493929190612f75565b6102fb6103b3366004613092565b610d0a565b6102c66103c636600461324c565b610db5565b610275600080516020613dd183398151915281565b6102fb6103ee366004613092565b610e07565b6103616104013660046132f9565b610ec9565b6102c66104143660046133c5565b611033565b6378a5a051610275565b6102c6610431366004613419565b61137b565b610449610444366004612ec9565b611658565b60405161027f91906134a4565b610361611663565b61036161166f565b61048d7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161027f565b6004546104bb9062010000900463ffffffff1681565b60405163ffffffff909116815260200161027f565b61044961167b565b6102756104e6366004612ec9565b600d6020526000908152604090205481565b6103616105063660046134f1565b611687565b610275610519366004612e14565b600860209081526000928352604080842090915290825290205481565b6040805180820190915260048152634755544360e01b60208201526102fb565b6105696105643660046134f1565b611692565b60405161027f92919061350e565b6102c661058536600461354a565b6116b4565b610449610598366004613583565b611768565b6102c66105ab366004613583565b611870565b6102756105be366004612ec9565b61187b565b6102756105d1366004613092565b6118ae565b6102756118c3565b6102a36105ec3660046135a5565b6118cf565b6103616105ff366004612e14565b61191c565b610361610612366004613583565b61194c565b6102c66106253660046135d3565b611a11565b610361610638366004612eac565b611a5c565b60006106498383611a7d565b90505b92915050565b600061065e6000611adb565b905090565b6001600160e01b0319811660009081527ffc606c433378e3a7e0a6a531deac289b66caa1b4aa8554fd4ab2c6f1570f92d8602052604081205460ff1661064c565b6004546106bc9062010000900463ffffffff16611ae5565b604051632474521560e21b8152600080516020613dd183398151915260048201523360248201526001600160a01b0391909116906391d1485490604401602060405180830381865afa158015610716573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073a9190613646565b61075f5760405162461bcd60e51b815260040161075690613663565b60405180910390fd5b6107698282611c1b565b5050565b6004546060906107889062010000900463ffffffff16611c47565b60405160200161079891906136aa565b604051602081830303815290604052905090565b604080518082018252601081526f54524149545f434f55504f4e5f55524960801b60208201529051631d2e660b60e21b81526060916000916001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916374b9982c916108229190600401612e99565b602060405180830381865afa15801561083f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108639190613703565b90506001600160a01b0381166108bb5760405162461bcd60e51b815260206004820152601860248201527f54524149545f434f55504f4e5f555249206e6f742073657400000000000000006044820152606401610756565b600480546040516376391ab760e11b8152309281019290925262010000900463ffffffff166024820152604481018490526001600160a01b0382169063ec72356e90606401600060405180830381865afa15801561091d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610945919081019061376f565b9392505050565b600061064c82611d47565b63ffffffff84166000908152600c6020908152604080832061ffff8716845290915281206060919061098890611adb565b90508061099584866137b9565b11156109a8576109a584826137cc565b92505b6000836001600160401b038111156109c2576109c26130d0565b6040519080825280602002602001820160405280156109eb578160200160208202803683370190505b50905060005b84811015610a60576000610a0582886137b9565b63ffffffff808b166000908152600c6020908152604080832061ffff8e1684529091529020919250610a3a91908390611d7d16565b838381518110610a4c57610a4c6137df565b6020908102919091010152506001016109f1565b509695505050505050565b63ffffffff82166000908152600c6020908152604080832061ffff85168452909152812061064990611adb565b63ffffffff601082901c16600081815260056020908152604080832061ffff8616808552908352818420603087901c8086529352922080546060918291610ade906137f5565b80601f0160208091040260200160405190810160405280929190818152602001828054610b0a906137f5565b8015610b575780601f10610b2c57610100808354040283529160200191610b57565b820191906000526020600020905b815481529060010190602001808311610b3a57829003601f168201915b505050505091506000610b6f8663ffffffff16611c47565b604051602001610b7f919061382f565b60405160208183030381529060405290506000610bad600460029054906101000a900463ffffffff16611ae5565b90506000816001600160a01b03166374b9982c846040518263ffffffff1660e01b8152600401610bdd9190612e99565b602060405180830381865afa158015610bfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1e9190613703565b6040516301db446960e01b815261ffff8916600482015290915081906000906001600160a01b038316906301db446990602401602060405180830381865afa158015610c6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c929190613703565b9050806001600160a01b0316636b122fe06040518163ffffffff1660e01b8152600401600060405180830381865afa158015610cd2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610cfa9190810190613880565b9550505050505091939590929450565b600560209081526000938452604080852082529284528284209052825290208054610d34906137f5565b80601f0160208091040260200160405190810160405280929190818152602001828054610d60906137f5565b8015610dad5780601f10610d8257610100808354040283529160200191610dad565b820191906000526020600020905b815481529060010190602001808311610d9057829003601f168201915b505050505081565b6001600160a01b0385163314801590610dd55750610dd385336118cf565b155b15610df2576040516212efed60e91b815260040160405180910390fd5b610e00338686868686611d89565b5050505050565b63ffffffff8316600090815260056020908152604080832061ffff8616845282528083208484529091529020805460609190610e42906137f5565b80601f0160208091040260200160405190810160405280929190818152602001828054610e6e906137f5565b8015610ebb5780601f10610e9057610100808354040283529160200191610ebb565b820191906000526020600020905b815481529060010190602001808311610e9e57829003601f168201915b505050505090509392505050565b60608151835114610eed57604051633e7e0b6d60e11b815260040160405180910390fd5b8251600080516020613df1833981519152906000906001600160401b03811115610f1957610f196130d0565b604051908082528060200260200182016040528015610f42578160200160208202803683370190505b50905060005b855181101561102a5760006001600160a01b0316868281518110610f6e57610f6e6137df565b60200260200101516001600160a01b031603610f9d5760405163db5d879760e01b815260040160405180910390fd5b826000868381518110610fb257610fb26137df565b602002602001015181526020019081526020016000206000878381518110610fdc57610fdc6137df565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054828281518110611017576110176137df565b6020908102919091010152600101610f48565b50949350505050565b6110456301193f3d60e61b6001611dad565b604080518082018252601b81527f474f4c44454e5f5554494c4954595f54524149545f434f55504f4e000000000060208201529051631d2e660b60e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916374b9982c916110c29190600401612e99565b602060405180830381865afa1580156110df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111039190613703565b6001600160a01b031630036111805760405162461bcd60e51b815260206004820152603a60248201527f5574696c6974795472616974436f75706f6e3a20476f6c64656e20636f6e747260448201527f616374732063616e6e6f7420626520696e697469616c697365640000000000006064820152608401610756565b600454610100900460ff16156111f15760405162461bcd60e51b815260206004820152603060248201527f5574696c6974795472616974436f75706f6e3a20636f6e747261637420616c7260448201526f1958591e481a5b9a5d1a585b1a5cd95960821b6064820152608401610756565b6004805461ff001916610100179055600061120b84611ae5565b60408051808201825260148152732aaa24a624aa2cafaa2920a4aa2fa1a7aaa827a760611b60208201529051631d2e660b60e21b81526001600160a01b0392909216916374b9982c9161126091600401612e99565b602060405180830381865afa15801561127d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a19190613703565b6001600160a01b03161461131d5760405162461bcd60e51b815260206004820152603a60248201527f5574696c6974795472616974436f75706f6e3a20636f6d6d756e69747920616c60448201527f72656164792068617320612054656c65706f727420546f6b656e0000000000006064820152608401610756565b6004805465ffffffff000019166201000063ffffffff861602179055604080516020601f8401819004810282018101909252828152611376918490849081908401838280828437600092019190915250611e2392505050565b505050565b60408051808201825260138152722a2920a4aa2fa1a7aaa827a72fa6a4a72a22a960691b60208201529051631d2e660b60e21b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916374b9982c916113ee9190600401612e99565b602060405180830381865afa15801561140b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061142f9190613703565b6001600160a01b0316336001600160a01b031614806114df57506004546114619062010000900463ffffffff16611ae5565b604051632474521560e21b8152600080516020613dd183398151915260048201523360248201526001600160a01b0391909116906391d1485490604401602060405180830381865afa1580156114bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114df9190613646565b8061157b57506004546114fd9062010000900463ffffffff16611ae5565b604051631092dd0160e11b8152600080516020613dd183398151915260048201523360248201526001600160a01b039190911690632125ba0290604401602060405180830381865afa158015611557573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061157b9190613646565b6115975760405162461bcd60e51b815260040161075690613663565b600082156116235763ffffffff8816600090815260066020908152604080832061ffff8b168452909152812080549091906115d1906139d4565b918290555063ffffffff8916600090815260056020908152604080832061ffff8c16845282528083208484529091529020909150611610848683613a35565b506000818152600d602052604090208290555b6000611630898984611eee565b905060606116408a8a848a611f19565b61164c88838984611fe9565b50505050505050505050565b606061064c826120c3565b606061065e60026120fc565b606061065e60096120fc565b606061065e6000612158565b606061064c826121bd565b60608061169e836121bd565b91506116ad828461063d612200565b9050915091565b6001600160a01b03821633036116dd57604051637b30a93360e11b815260040160405180910390fd5b3360008181527f1799cf914cb0cb442ca7c7ac709ee40d0cb89e87351dc08d517fbda27d50c68c602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b606060006117766000611adb565b90508084106117b45760005b6040519080825280602002602001820160405280156117ab578160200160208202803683370190505b5091505061064c565b806117bf84866137b9565b11156117d2576117cf84826137cc565b92505b826001600160401b038111156117ea576117ea6130d0565b604051908082528060200260200182016040528015611813578160200160208202803683370190505b50915060005b838110156118685761183661182e86836137b9565b600090611d7d565b838281518110611848576118486137df565b6001600160a01b0390921660209283029190910190910152600101611819565b505092915050565b6107693383836122a7565b60008181527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ea602052604081205461064c565b60006118bb848484611eee565b949350505050565b600061065e6002611adb565b6001600160a01b0391821660009081527f1799cf914cb0cb442ca7c7ac709ee40d0cb89e87351dc08d517fbda27d50c68c6020908152604080832093909416825291909152205460ff1690565b63ffffffff82166000908152600c6020908152604080832061ffff851684529091529020606090610649906120fc565b6060600061195a6002611adb565b905080841061196a576000611782565b8061197584866137b9565b11156119885761198584826137cc565b92505b826001600160401b038111156119a0576119a06130d0565b6040519080825280602002602001820160405280156119c9578160200160208202803683370190505b50915060005b83811015611868576119ec6119e482876137b9565b600290611d7d565b8382815181106119fe576119fe6137df565b60209081029190910101526001016119cf565b6001600160a01b0385163314801590611a315750611a2f85336118cf565b155b15611a4e576040516212efed60e91b815260040160405180910390fd5b610e003386868686866123a6565b63ffffffff81166000908152600b6020526040902060609061064c906120fc565b60006001600160a01b038316611aa65760405163db5d879760e01b815260040160405180910390fd5b600080516020613df18339815191526000928352602090815260408084206001600160a01b0395909516845293905250205490565b600061064c825490565b604080518082018252600e81526d10d3d353555392551657d31254d560921b60208201529051631d2e660b60e21b815260009182916001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916374b9982c91611b589190600401612e99565b602060405180830381865afa158015611b75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b999190613703565b60405163d0f4a53760e01b815263ffffffff851660048201529091506000906001600160a01b0383169063d0f4a53790602401600060405180830381865afa158015611be9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611c119190810190613af4565b5095945050505050565b7f4281b61aefbe70b3d3f684b428efca5f33077bc240e76f2808f9177c307617f4611376828483613a35565b606081600003611c6e5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611c985780611c82816139d4565b9150611c919050600a83613b6e565b9150611c72565b6000816001600160401b03811115611cb257611cb26130d0565b6040519080825280601f01601f191660200182016040528015611cdc576020820181803683370190505b5090505b84156118bb57611cf16001836137cc565b9150611cfe600a86613b82565b611d099060306137b9565b60f81b818381518110611d1e57611d1e6137df565b60200101906001600160f81b031916908160001a905350611d40600a86613b6e565b9450611ce0565b60008181527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424eb6020526040812061064c90611adb565b600061064983836123c2565b611d9786868686868661240e565b611da58686868686866125b7565b505050505050565b6001600160e01b03198083169003611dd85760405163b0a19dd560e01b815260040160405180910390fd5b6001600160e01b03199190911660009081527ffc606c433378e3a7e0a6a531deac289b66caa1b4aa8554fd4ab2c6f1570f92d860205260409020805460ff1916911515919091179055565b60045460ff1615611e8a5760405162461bcd60e51b815260206004820152602b60248201527f4552433131353546756c6c79456e756d657261626c653a20616c72656164792060448201526a1a5b9a5d1a585b1a5cd95960aa1b6064820152608401610756565b611e9c6301ffc9a760e01b6001611dad565b611eae636cdb3d1360e11b6001611dad565b6004805460ff1916600117905580611ee37f4281b61aefbe70b3d3f684b428efca5f33077bc240e76f2808f9177c307617f490565b906107699082613b96565b6000603082901b611f0f65ffffffff0000601087901b1661ffff86166137b9565b6118bb91906137b9565b611f2d600963ffffffff808716906126d016565b5063ffffffff8085166000908152600b60205260409020611f549161ffff8616906126d016565b5063ffffffff841660009081526007602052604081208054839290611f7a9084906137b9565b909155505063ffffffff8416600090815260086020908152604080832061ffff8716845290915281208054839290611fb39084906137b9565b909155505063ffffffff8085166000908152600c6020908152604080832061ffff881684529091529020610e009184906126d016565b6001600160a01b038416612010576040516301c8efbf60e11b815260040160405180910390fd5b61202f33600086612020876126dc565b612029876126dc565b86612727565b6000838152600080516020613df1833981519152602090815260408083206001600160a01b03881684529091528120805484929061206e9084906137b9565b909155505060408051848152602081018490526001600160a01b0386169160009133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291015b60405180910390a450505050565b60008181527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424eb6020526040902060609061064c90612158565b8054604080516020808402820181019092528281526060928492839291839183018282801561214a57602002820191906000526020600020905b815481526020019060010190808311612136575b505050505092505050919050565b8054604080516020808402820181019092528281526060928492839291839183018282801561214a57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161219257505050505092505050919050565b6001600160a01b03811660009081527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ec6020526040902060609061064c906120fc565b606083516001600160401b0381111561221b5761221b6130d0565b604051908082528060200260200182016040528015612244578160200160208202803683370190505b50905060005b845181101561229f5761227a84868381518110612269576122696137df565b60200260200101518563ffffffff16565b82828151811061228c5761228c6137df565b602090810291909101015260010161224a565b509392505050565b6001600160a01b0383166122ce5760405163baa75df760e01b815260040160405180910390fd5b6122fc338460006122de866126dc565b6122e7866126dc565b60405180602001604052806000815250612727565b6000828152600080516020613df1833981519152602090815260408083206001600160a01b0387168452918290529091205482111561234e57604051634190713d60e01b815260040160405180910390fd5b6001600160a01b03841660008181526020838152604080832080548790039055805187815291820186905291929133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291016120b5565b6123b48686868686866127e1565b611da58686868686866128f7565b815460009082106123e65760405163e637bf3b60e01b815260040160405180910390fd5b8260000182815481106123fb576123fb6137df565b9060005260206000200154905092915050565b6001600160a01b0384166124355760405163f5cadad560e01b815260040160405180910390fd5b815183511461245757604051633e7e0b6d60e11b815260040160405180910390fd5b612465868686868686612727565b600080516020613df183398151915260005b8451811015612556576000858281518110612494576124946137df565b6020026020010151905060008583815181106124b2576124b26137df565b602090810291909101810151600084815286835260408082206001600160a01b038e1683529093529190912054909150808211156125035760405163119ac6bb60e31b815260040160405180910390fd5b6000838152602086815260408083206001600160a01b038e811685529252808320938590039093558a1681529081208054600195909501948392906125499084906137b9565b9091555061247792505050565b50846001600160a01b0316866001600160a01b0316886001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb87876040516125a692919061350e565b60405180910390a450505050505050565b6001600160a01b0384163b15611da55760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906125fb9089908990889088908890600401613c55565b6020604051808303816000875af1925050508015612636575060408051601f3d908101601f1916820190925261263391810190613cb3565b60015b61269657612642613cd0565b806308c379a00361267b5750612656613cec565b80612661575061267d565b8060405162461bcd60e51b81526004016107569190612e99565b505b60405163380147a960e01b815260040160405180910390fd5b6001600160e01b0319811663bc197c8160e01b146126c757604051633744db2960e01b815260040160405180910390fd5b50505050505050565b600061064983836129b3565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110612716576127166137df565b602090810291909101015292915050565b6127358686868686866129f6565b6001600160a01b03841661276c57600061274e86611687565b9050805160000361276657612764600087612a04565b505b50612779565b612777600085612a19565b505b60005b83518110156126c7576000848281518110612799576127996137df565b6020026020010151905060006127ae82611658565b905080516000036127ca576127c4600283612a2e565b506127d7565b6127d56002836126d0565b505b505060010161277c565b6001600160a01b0384166128085760405163f5cadad560e01b815260040160405180910390fd5b612817868686612020876126dc565b6000838152600080516020613df1833981519152602081815260408084206001600160a01b038a16855290915290912054808411156128695760405163119ac6bb60e31b815260040160405180910390fd5b6000858152602083815260408083206001600160a01b038b811685529252808320938790039093558716815290812080548592906128a89084906137b9565b909155505060408051858152602081018590526001600160a01b038088169289821692918b16917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291016125a6565b6001600160a01b0384163b15611da55760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e619061293b9089908990889088908890600401613d75565b6020604051808303816000875af1925050508015612976575060408051601f3d908101601f1916820190925261297391810190613cb3565b60015b61298257612642613cd0565b6001600160e01b0319811663f23a6e6160e01b146126c757604051633744db2960e01b815260040160405180910390fd5b600081815260018301602052604081205461064c575081546001808201845560008481526020808220909301849055845493815293810190915260409092205590565b611da5868686868686612a3a565b6000610649836001600160a01b038416612c26565b6000610649836001600160a01b0384166129b3565b60006106498383612c26565b836001600160a01b0316856001600160a01b031614611da5576001600160a01b0385811660009081527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ec6020526040808220928716825281207fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ea927fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424eb929091905b8751811015612c19576000878281518110612af857612af86137df565b602002602001015190506000811115612c10576000898381518110612b1f57612b1f6137df565b6020026020010151905060006001600160a01b03168c6001600160a01b031603612b6c5760008181526020889052604081208054849290612b619084906137b9565b90915550612ba19050565b81612b778d83611a7d565b03612ba1576000818152602087905260409020612b94908d612a04565b50612b9f8582612a2e565b505b6001600160a01b038b16612bd85760008181526020889052604081208054849290612bcd9084906137cc565b90915550612c0e9050565b612be28b82611a7d565b600003612c0e576000818152602087905260409020612c01908c612a19565b50612c0c84826126d0565b505b505b50600101612adb565b5050505050505050505050565b60008181526001830160205260408120548015612ce457835460009085906000198101908110612c5857612c586137df565b9060005260206000200154905080856000016001840381548110612c7e57612c7e6137df565b6000918252602080832090910192909255918252600186019052604090208190558354849080612cb057612cb0613dba565b6001900381819060005260206000200160009055905583600101600084815260200190815260200160002060009055600191505b5092915050565b6001600160a01b0381168114612d0057600080fd5b50565b60008060408385031215612d1657600080fd5b8235612d2181612ceb565b946020939093013593505050565b6001600160e01b031981168114612d0057600080fd5b600060208284031215612d5757600080fd5b813561094581612d2f565b60008083601f840112612d7457600080fd5b5081356001600160401b03811115612d8b57600080fd5b602083019150836020828501011115612da357600080fd5b9250929050565b60008060208385031215612dbd57600080fd5b82356001600160401b03811115612dd357600080fd5b612ddf85828601612d62565b90969095509350505050565b63ffffffff81168114612d0057600080fd5b803561ffff81168114612e0f57600080fd5b919050565b60008060408385031215612e2757600080fd5b8235612e3281612deb565b9150612e4060208401612dfd565b90509250929050565b60005b83811015612e64578181015183820152602001612e4c565b50506000910152565b60008151808452612e85816020860160208601612e49565b601f01601f19169290920160200192915050565b6020815260006106496020830184612e6d565b600060208284031215612ebe57600080fd5b813561094581612deb565b600060208284031215612edb57600080fd5b5035919050565b60008060008060808587031215612ef857600080fd5b8435612f0381612deb565b9350612f1160208601612dfd565b93969395505050506040820135916060013590565b60008151808452602080850194506020840160005b83811015612f5757815187529582019590820190600101612f3b565b509495945050505050565b6020815260006106496020830184612f26565b600060a063ffffffff88168352602061ffff8816818501526040876040860152606060a06060870152612fab60a0870189612e6d565b608087820360808901528189518084528684019150868160051b850101878c016000805b8481101561307957601f198885030186528251610100815186528c8201516014811061300957634e487b7160e01b85526021600452602485fd5b868e0152818c01516001600160e01b0319168c8701528a8201518b870182905261303582880182612e6d565b915050888201516130498a88018215159052565b50818e0151868f015260c0808301519087015260e09182015115159190950152948a0194918a0191600101612fcf565b5050508099505050505050505050509695505050505050565b6000806000606084860312156130a757600080fd5b83356130b281612deb565b92506130c060208501612dfd565b9150604084013590509250925092565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561310b5761310b6130d0565b6040525050565b60405161010081016001600160401b0381118282101715613135576131356130d0565b60405290565b60006001600160401b03821115613154576131546130d0565b5060051b60200190565b600082601f83011261316f57600080fd5b8135602061317c8261313b565b60405161318982826130e6565b80915083815260208101915060208460051b8701019350868411156131ad57600080fd5b602086015b84811015610a6057803583529183019183016131b2565b60006001600160401b038211156131e2576131e26130d0565b50601f01601f191660200190565b600082601f83011261320157600080fd5b813561320c816131c9565b60405161321982826130e6565b82815285602084870101111561322e57600080fd5b82602086016020830137600092810160200192909252509392505050565b600080600080600060a0868803121561326457600080fd5b853561326f81612ceb565b9450602086013561327f81612ceb565b935060408601356001600160401b038082111561329b57600080fd5b6132a789838a0161315e565b945060608801359150808211156132bd57600080fd5b6132c989838a0161315e565b935060808801359150808211156132df57600080fd5b506132ec888289016131f0565b9150509295509295909350565b6000806040838503121561330c57600080fd5b82356001600160401b038082111561332357600080fd5b818501915085601f83011261333757600080fd5b813560206133448261313b565b60405161335182826130e6565b83815260059390931b850182019282810191508984111561337157600080fd5b948201945b8386101561339857853561338981612ceb565b82529482019490820190613376565b965050860135925050808211156133ae57600080fd5b506133bb8582860161315e565b9150509250929050565b6000806000604084860312156133da57600080fd5b83356133e581612deb565b925060208401356001600160401b0381111561340057600080fd5b61340c86828701612d62565b9497909650939450505050565b600080600080600080600060c0888a03121561343457600080fd5b873561343f81612deb565b965061344d60208901612dfd565b9550604088013561345d81612ceb565b94506060880135935060808801356001600160401b0381111561347f57600080fd5b61348b8a828b01612d62565b989b979a5095989497959660a090950135949350505050565b6020808252825182820181905260009190848201906040850190845b818110156134e55783516001600160a01b0316835292840192918401916001016134c0565b50909695505050505050565b60006020828403121561350357600080fd5b813561094581612ceb565b6040815260006135216040830185612f26565b82810360208401526135338185612f26565b95945050505050565b8015158114612d0057600080fd5b6000806040838503121561355d57600080fd5b823561356881612ceb565b915060208301356135788161353c565b809150509250929050565b6000806040838503121561359657600080fd5b50508035926020909101359150565b600080604083850312156135b857600080fd5b82356135c381612ceb565b9150602083013561357881612ceb565b600080600080600060a086880312156135eb57600080fd5b85356135f681612ceb565b9450602086013561360681612ceb565b9350604086013592506060860135915060808601356001600160401b0381111561362f57600080fd5b6132ec888289016131f0565b8051612e0f8161353c565b60006020828403121561365857600080fd5b81516109458161353c565b60208082526027908201527f5574696c6974795472616974436f75706f6e3a20756e617574686f72697365646040820152661036b4b73a32b960c91b606082015260800190565b7f47616c61786973205574696c69747920547261697420436f75706f6e20666f7281526a01031b7b6b6bab734ba3c960ad1b6020820152600082516136f681602b850160208701612e49565b91909101602b0192915050565b60006020828403121561371557600080fd5b815161094581612ceb565b600082601f83011261373157600080fd5b815161373c816131c9565b60405161374982826130e6565b82815285602084870101111561375e57600080fd5b613533836020830160208801612e49565b60006020828403121561378157600080fd5b81516001600160401b0381111561379757600080fd5b6118bb84828501613720565b634e487b7160e01b600052601160045260246000fd5b8082018082111561064c5761064c6137a3565b8181038181111561064c5761064c6137a3565b634e487b7160e01b600052603260045260246000fd5b600181811c9082168061380957607f821691505b60208210810361382957634e487b7160e01b600052602260045260246000fd5b50919050565b6e54524149545f52454749535452595f60881b81526000825161385981600f850160208701612e49565b91909101600f0192915050565b805160148110612e0f57600080fd5b8051612e0f81612d2f565b6000602080838503121561389357600080fd5b82516001600160401b03808211156138aa57600080fd5b818501915085601f8301126138be57600080fd5b81516138c98161313b565b6040516138d682826130e6565b82815260059290921b84018501918581019150888311156138f657600080fd5b8585015b838110156139c75780518581111561391157600080fd5b8601610100818c03601f190181131561392957600080fd5b613931613112565b89830151815261394360408401613866565b8a82015261395360608401613875565b60408201526080808401518981111561396c5760008081fd5b61397a8f8d83880101613720565b60608401525060a061398d81860161363b565b8284015260c0915081850151818401525060e080850151828401526139b384860161363b565b9083015250855250509186019186016138fa565b5098975050505050505050565b6000600182016139e6576139e66137a3565b5060010190565b601f821115611376576000816000526020600020601f850160051c81016020861015613a165750805b601f850160051c820191505b81811015611da557828155600101613a22565b6001600160401b03831115613a4c57613a4c6130d0565b613a6083613a5a83546137f5565b836139ed565b6000601f841160018114613a945760008515613a7c5750838201355b600019600387901b1c1916600186901b178355610e00565b600083815260209020601f19861690835b82811015613ac55786850135825560209485019460019092019101613aa5565b5086821015613ae25760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b600080600060608486031215613b0957600080fd5b83516001600160401b03811115613b1f57600080fd5b613b2b86828701613720565b9350506020840151613b3c81612ceb565b6040850151909250613b4d81612deb565b809150509250925092565b634e487b7160e01b600052601260045260246000fd5b600082613b7d57613b7d613b58565b500490565b600082613b9157613b91613b58565b500690565b81516001600160401b03811115613baf57613baf6130d0565b613bc381613bbd84546137f5565b846139ed565b602080601f831160018114613bf85760008415613be05750858301515b600019600386901b1c1916600185901b178555611da5565b600085815260208120601f198616915b82811015613c2757888601518255948401946001909101908401613c08565b5085821015613c455787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160a01b0386811682528516602082015260a060408201819052600090613c8190830186612f26565b8281036060840152613c938186612f26565b90508281036080840152613ca78185612e6d565b98975050505050505050565b600060208284031215613cc557600080fd5b815161094581612d2f565b600060033d1115613ce95760046000803e5060005160e01c5b90565b600060443d1015613cfa5790565b6040516003193d81016004833e81513d6001600160401b038160248401118184111715613d2957505050505090565b8285019150815181811115613d415750505050505090565b843d8701016020828501011115613d5b5750505050505090565b613d6a602082860101876130e6565b509095945050505050565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090613daf90830184612e6d565b979650505050505050565b634e487b7160e01b600052603160045260246000fdfe4d22f33240a09dddf495d4955c9f23af3488c8781d110f143c7072ad05e023821799cf914cb0cb442ca7c7ac709ee40d0cb89e87351dc08d517fbda27d50c68ba26469706673582212204cca6f6f0fcce9dc2741a8184da6eb40a930558d6bd53602ac230e7e97fd958c64736f6c63430008190033000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae2

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061025d5760003560e01c8063714cff5611610146578063a22cb465116100c3578063dc47b3c111610087578063dc47b3c1146105d6578063e985e9c5146105de578063e9949c58146105f1578063eed8cc3514610604578063f242432a14610617578063f6d465891461062a57600080fd5b8063a22cb46514610577578063aed6176e1461058a578063b390c0ab1461059d578063bd85b039146105b0578063ca0425f2146105c357600080fd5b806383485eed1161010a57806383485eed146104d857806385bff2e7146104f8578063899dfbea1461050b57806395d89b41146105365780639ba12dfa1461055657600080fd5b8063714cff5614610456578063725639a01461045e5780637671114d146104665780637f50861a146104a55780638188f71c146104d057600080fd5b80631972793f116101df5780634860f5ce116101a35780634860f5ce146103e05780634e1273f4146103f35780635272e8821461040657806354fd4d50146104195780635b521461146104235780636dcfd8411461043657600080fd5b80631972793f1461036e5780631a3cd59a146103815780631a81397f146103a55780632eb2c2d6146103b857806343bb6eb8146103cb57600080fd5b806306fdde031161022657806306fdde03146102f35780630807c62d146103085780630e89341c1461032857806313ba55df1461033b57806315473de01461034e57600080fd5b8062fdd58e146102625780630199c7b21461028857806301ffc9a71461029057806302fe5305146102b357806305b2c810146102c8575b600080fd5b610275610270366004612d03565b61063d565b6040519081526020015b60405180910390f35b610275610652565b6102a361029e366004612d45565b610663565b604051901515815260200161027f565b6102c66102c1366004612daa565b6106a4565b005b6102756102d6366004612e14565b600660209081526000928352604080842090915290825290205481565b6102fb61076d565b60405161027f9190612e99565b610275610316366004612eac565b60076020526000908152604090205481565b6102fb610336366004612ec9565b6107ac565b610275610349366004612ec9565b61094c565b61036161035c366004612ee2565b610957565b60405161027f9190612f62565b61027561037c366004612e14565b610a6b565b61039461038f366004612ec9565b610a98565b60405161027f959493929190612f75565b6102fb6103b3366004613092565b610d0a565b6102c66103c636600461324c565b610db5565b610275600080516020613dd183398151915281565b6102fb6103ee366004613092565b610e07565b6103616104013660046132f9565b610ec9565b6102c66104143660046133c5565b611033565b6378a5a051610275565b6102c6610431366004613419565b61137b565b610449610444366004612ec9565b611658565b60405161027f91906134a4565b610361611663565b61036161166f565b61048d7f000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae281565b6040516001600160a01b03909116815260200161027f565b6004546104bb9062010000900463ffffffff1681565b60405163ffffffff909116815260200161027f565b61044961167b565b6102756104e6366004612ec9565b600d6020526000908152604090205481565b6103616105063660046134f1565b611687565b610275610519366004612e14565b600860209081526000928352604080842090915290825290205481565b6040805180820190915260048152634755544360e01b60208201526102fb565b6105696105643660046134f1565b611692565b60405161027f92919061350e565b6102c661058536600461354a565b6116b4565b610449610598366004613583565b611768565b6102c66105ab366004613583565b611870565b6102756105be366004612ec9565b61187b565b6102756105d1366004613092565b6118ae565b6102756118c3565b6102a36105ec3660046135a5565b6118cf565b6103616105ff366004612e14565b61191c565b610361610612366004613583565b61194c565b6102c66106253660046135d3565b611a11565b610361610638366004612eac565b611a5c565b60006106498383611a7d565b90505b92915050565b600061065e6000611adb565b905090565b6001600160e01b0319811660009081527ffc606c433378e3a7e0a6a531deac289b66caa1b4aa8554fd4ab2c6f1570f92d8602052604081205460ff1661064c565b6004546106bc9062010000900463ffffffff16611ae5565b604051632474521560e21b8152600080516020613dd183398151915260048201523360248201526001600160a01b0391909116906391d1485490604401602060405180830381865afa158015610716573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061073a9190613646565b61075f5760405162461bcd60e51b815260040161075690613663565b60405180910390fd5b6107698282611c1b565b5050565b6004546060906107889062010000900463ffffffff16611c47565b60405160200161079891906136aa565b604051602081830303815290604052905090565b604080518082018252601081526f54524149545f434f55504f4e5f55524960801b60208201529051631d2e660b60e21b81526060916000916001600160a01b037f000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae216916374b9982c916108229190600401612e99565b602060405180830381865afa15801561083f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108639190613703565b90506001600160a01b0381166108bb5760405162461bcd60e51b815260206004820152601860248201527f54524149545f434f55504f4e5f555249206e6f742073657400000000000000006044820152606401610756565b600480546040516376391ab760e11b8152309281019290925262010000900463ffffffff166024820152604481018490526001600160a01b0382169063ec72356e90606401600060405180830381865afa15801561091d573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610945919081019061376f565b9392505050565b600061064c82611d47565b63ffffffff84166000908152600c6020908152604080832061ffff8716845290915281206060919061098890611adb565b90508061099584866137b9565b11156109a8576109a584826137cc565b92505b6000836001600160401b038111156109c2576109c26130d0565b6040519080825280602002602001820160405280156109eb578160200160208202803683370190505b50905060005b84811015610a60576000610a0582886137b9565b63ffffffff808b166000908152600c6020908152604080832061ffff8e1684529091529020919250610a3a91908390611d7d16565b838381518110610a4c57610a4c6137df565b6020908102919091010152506001016109f1565b509695505050505050565b63ffffffff82166000908152600c6020908152604080832061ffff85168452909152812061064990611adb565b63ffffffff601082901c16600081815260056020908152604080832061ffff8616808552908352818420603087901c8086529352922080546060918291610ade906137f5565b80601f0160208091040260200160405190810160405280929190818152602001828054610b0a906137f5565b8015610b575780601f10610b2c57610100808354040283529160200191610b57565b820191906000526020600020905b815481529060010190602001808311610b3a57829003601f168201915b505050505091506000610b6f8663ffffffff16611c47565b604051602001610b7f919061382f565b60405160208183030381529060405290506000610bad600460029054906101000a900463ffffffff16611ae5565b90506000816001600160a01b03166374b9982c846040518263ffffffff1660e01b8152600401610bdd9190612e99565b602060405180830381865afa158015610bfa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1e9190613703565b6040516301db446960e01b815261ffff8916600482015290915081906000906001600160a01b038316906301db446990602401602060405180830381865afa158015610c6e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c929190613703565b9050806001600160a01b0316636b122fe06040518163ffffffff1660e01b8152600401600060405180830381865afa158015610cd2573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610cfa9190810190613880565b9550505050505091939590929450565b600560209081526000938452604080852082529284528284209052825290208054610d34906137f5565b80601f0160208091040260200160405190810160405280929190818152602001828054610d60906137f5565b8015610dad5780601f10610d8257610100808354040283529160200191610dad565b820191906000526020600020905b815481529060010190602001808311610d9057829003601f168201915b505050505081565b6001600160a01b0385163314801590610dd55750610dd385336118cf565b155b15610df2576040516212efed60e91b815260040160405180910390fd5b610e00338686868686611d89565b5050505050565b63ffffffff8316600090815260056020908152604080832061ffff8616845282528083208484529091529020805460609190610e42906137f5565b80601f0160208091040260200160405190810160405280929190818152602001828054610e6e906137f5565b8015610ebb5780601f10610e9057610100808354040283529160200191610ebb565b820191906000526020600020905b815481529060010190602001808311610e9e57829003601f168201915b505050505090509392505050565b60608151835114610eed57604051633e7e0b6d60e11b815260040160405180910390fd5b8251600080516020613df1833981519152906000906001600160401b03811115610f1957610f196130d0565b604051908082528060200260200182016040528015610f42578160200160208202803683370190505b50905060005b855181101561102a5760006001600160a01b0316868281518110610f6e57610f6e6137df565b60200260200101516001600160a01b031603610f9d5760405163db5d879760e01b815260040160405180910390fd5b826000868381518110610fb257610fb26137df565b602002602001015181526020019081526020016000206000878381518110610fdc57610fdc6137df565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002054828281518110611017576110176137df565b6020908102919091010152600101610f48565b50949350505050565b6110456301193f3d60e61b6001611dad565b604080518082018252601b81527f474f4c44454e5f5554494c4954595f54524149545f434f55504f4e000000000060208201529051631d2e660b60e21b81526001600160a01b037f000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae216916374b9982c916110c29190600401612e99565b602060405180830381865afa1580156110df573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111039190613703565b6001600160a01b031630036111805760405162461bcd60e51b815260206004820152603a60248201527f5574696c6974795472616974436f75706f6e3a20476f6c64656e20636f6e747260448201527f616374732063616e6e6f7420626520696e697469616c697365640000000000006064820152608401610756565b600454610100900460ff16156111f15760405162461bcd60e51b815260206004820152603060248201527f5574696c6974795472616974436f75706f6e3a20636f6e747261637420616c7260448201526f1958591e481a5b9a5d1a585b1a5cd95960821b6064820152608401610756565b6004805461ff001916610100179055600061120b84611ae5565b60408051808201825260148152732aaa24a624aa2cafaa2920a4aa2fa1a7aaa827a760611b60208201529051631d2e660b60e21b81526001600160a01b0392909216916374b9982c9161126091600401612e99565b602060405180830381865afa15801561127d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a19190613703565b6001600160a01b03161461131d5760405162461bcd60e51b815260206004820152603a60248201527f5574696c6974795472616974436f75706f6e3a20636f6d6d756e69747920616c60448201527f72656164792068617320612054656c65706f727420546f6b656e0000000000006064820152608401610756565b6004805465ffffffff000019166201000063ffffffff861602179055604080516020601f8401819004810282018101909252828152611376918490849081908401838280828437600092019190915250611e2392505050565b505050565b60408051808201825260138152722a2920a4aa2fa1a7aaa827a72fa6a4a72a22a960691b60208201529051631d2e660b60e21b81526001600160a01b037f000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae216916374b9982c916113ee9190600401612e99565b602060405180830381865afa15801561140b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061142f9190613703565b6001600160a01b0316336001600160a01b031614806114df57506004546114619062010000900463ffffffff16611ae5565b604051632474521560e21b8152600080516020613dd183398151915260048201523360248201526001600160a01b0391909116906391d1485490604401602060405180830381865afa1580156114bb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114df9190613646565b8061157b57506004546114fd9062010000900463ffffffff16611ae5565b604051631092dd0160e11b8152600080516020613dd183398151915260048201523360248201526001600160a01b039190911690632125ba0290604401602060405180830381865afa158015611557573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061157b9190613646565b6115975760405162461bcd60e51b815260040161075690613663565b600082156116235763ffffffff8816600090815260066020908152604080832061ffff8b168452909152812080549091906115d1906139d4565b918290555063ffffffff8916600090815260056020908152604080832061ffff8c16845282528083208484529091529020909150611610848683613a35565b506000818152600d602052604090208290555b6000611630898984611eee565b905060606116408a8a848a611f19565b61164c88838984611fe9565b50505050505050505050565b606061064c826120c3565b606061065e60026120fc565b606061065e60096120fc565b606061065e6000612158565b606061064c826121bd565b60608061169e836121bd565b91506116ad828461063d612200565b9050915091565b6001600160a01b03821633036116dd57604051637b30a93360e11b815260040160405180910390fd5b3360008181527f1799cf914cb0cb442ca7c7ac709ee40d0cb89e87351dc08d517fbda27d50c68c602090815260408083206001600160a01b03871680855290835292819020805460ff191686151590811790915590519081529192917f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31910160405180910390a35050565b606060006117766000611adb565b90508084106117b45760005b6040519080825280602002602001820160405280156117ab578160200160208202803683370190505b5091505061064c565b806117bf84866137b9565b11156117d2576117cf84826137cc565b92505b826001600160401b038111156117ea576117ea6130d0565b604051908082528060200260200182016040528015611813578160200160208202803683370190505b50915060005b838110156118685761183661182e86836137b9565b600090611d7d565b838281518110611848576118486137df565b6001600160a01b0390921660209283029190910190910152600101611819565b505092915050565b6107693383836122a7565b60008181527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ea602052604081205461064c565b60006118bb848484611eee565b949350505050565b600061065e6002611adb565b6001600160a01b0391821660009081527f1799cf914cb0cb442ca7c7ac709ee40d0cb89e87351dc08d517fbda27d50c68c6020908152604080832093909416825291909152205460ff1690565b63ffffffff82166000908152600c6020908152604080832061ffff851684529091529020606090610649906120fc565b6060600061195a6002611adb565b905080841061196a576000611782565b8061197584866137b9565b11156119885761198584826137cc565b92505b826001600160401b038111156119a0576119a06130d0565b6040519080825280602002602001820160405280156119c9578160200160208202803683370190505b50915060005b83811015611868576119ec6119e482876137b9565b600290611d7d565b8382815181106119fe576119fe6137df565b60209081029190910101526001016119cf565b6001600160a01b0385163314801590611a315750611a2f85336118cf565b155b15611a4e576040516212efed60e91b815260040160405180910390fd5b610e003386868686866123a6565b63ffffffff81166000908152600b6020526040902060609061064c906120fc565b60006001600160a01b038316611aa65760405163db5d879760e01b815260040160405180910390fd5b600080516020613df18339815191526000928352602090815260408084206001600160a01b0395909516845293905250205490565b600061064c825490565b604080518082018252600e81526d10d3d353555392551657d31254d560921b60208201529051631d2e660b60e21b815260009182916001600160a01b037f000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae216916374b9982c91611b589190600401612e99565b602060405180830381865afa158015611b75573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b999190613703565b60405163d0f4a53760e01b815263ffffffff851660048201529091506000906001600160a01b0383169063d0f4a53790602401600060405180830381865afa158015611be9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052611c119190810190613af4565b5095945050505050565b7f4281b61aefbe70b3d3f684b428efca5f33077bc240e76f2808f9177c307617f4611376828483613a35565b606081600003611c6e5750506040805180820190915260018152600360fc1b602082015290565b8160005b8115611c985780611c82816139d4565b9150611c919050600a83613b6e565b9150611c72565b6000816001600160401b03811115611cb257611cb26130d0565b6040519080825280601f01601f191660200182016040528015611cdc576020820181803683370190505b5090505b84156118bb57611cf16001836137cc565b9150611cfe600a86613b82565b611d099060306137b9565b60f81b818381518110611d1e57611d1e6137df565b60200101906001600160f81b031916908160001a905350611d40600a86613b6e565b9450611ce0565b60008181527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424eb6020526040812061064c90611adb565b600061064983836123c2565b611d9786868686868661240e565b611da58686868686866125b7565b505050505050565b6001600160e01b03198083169003611dd85760405163b0a19dd560e01b815260040160405180910390fd5b6001600160e01b03199190911660009081527ffc606c433378e3a7e0a6a531deac289b66caa1b4aa8554fd4ab2c6f1570f92d860205260409020805460ff1916911515919091179055565b60045460ff1615611e8a5760405162461bcd60e51b815260206004820152602b60248201527f4552433131353546756c6c79456e756d657261626c653a20616c72656164792060448201526a1a5b9a5d1a585b1a5cd95960aa1b6064820152608401610756565b611e9c6301ffc9a760e01b6001611dad565b611eae636cdb3d1360e11b6001611dad565b6004805460ff1916600117905580611ee37f4281b61aefbe70b3d3f684b428efca5f33077bc240e76f2808f9177c307617f490565b906107699082613b96565b6000603082901b611f0f65ffffffff0000601087901b1661ffff86166137b9565b6118bb91906137b9565b611f2d600963ffffffff808716906126d016565b5063ffffffff8085166000908152600b60205260409020611f549161ffff8616906126d016565b5063ffffffff841660009081526007602052604081208054839290611f7a9084906137b9565b909155505063ffffffff8416600090815260086020908152604080832061ffff8716845290915281208054839290611fb39084906137b9565b909155505063ffffffff8085166000908152600c6020908152604080832061ffff881684529091529020610e009184906126d016565b6001600160a01b038416612010576040516301c8efbf60e11b815260040160405180910390fd5b61202f33600086612020876126dc565b612029876126dc565b86612727565b6000838152600080516020613df1833981519152602090815260408083206001600160a01b03881684529091528120805484929061206e9084906137b9565b909155505060408051848152602081018490526001600160a01b0386169160009133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291015b60405180910390a450505050565b60008181527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424eb6020526040902060609061064c90612158565b8054604080516020808402820181019092528281526060928492839291839183018282801561214a57602002820191906000526020600020905b815481526020019060010190808311612136575b505050505092505050919050565b8054604080516020808402820181019092528281526060928492839291839183018282801561214a57602002820191906000526020600020905b81546001600160a01b0316815260019091019060200180831161219257505050505092505050919050565b6001600160a01b03811660009081527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ec6020526040902060609061064c906120fc565b606083516001600160401b0381111561221b5761221b6130d0565b604051908082528060200260200182016040528015612244578160200160208202803683370190505b50905060005b845181101561229f5761227a84868381518110612269576122696137df565b60200260200101518563ffffffff16565b82828151811061228c5761228c6137df565b602090810291909101015260010161224a565b509392505050565b6001600160a01b0383166122ce5760405163baa75df760e01b815260040160405180910390fd5b6122fc338460006122de866126dc565b6122e7866126dc565b60405180602001604052806000815250612727565b6000828152600080516020613df1833981519152602090815260408083206001600160a01b0387168452918290529091205482111561234e57604051634190713d60e01b815260040160405180910390fd5b6001600160a01b03841660008181526020838152604080832080548790039055805187815291820186905291929133917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291016120b5565b6123b48686868686866127e1565b611da58686868686866128f7565b815460009082106123e65760405163e637bf3b60e01b815260040160405180910390fd5b8260000182815481106123fb576123fb6137df565b9060005260206000200154905092915050565b6001600160a01b0384166124355760405163f5cadad560e01b815260040160405180910390fd5b815183511461245757604051633e7e0b6d60e11b815260040160405180910390fd5b612465868686868686612727565b600080516020613df183398151915260005b8451811015612556576000858281518110612494576124946137df565b6020026020010151905060008583815181106124b2576124b26137df565b602090810291909101810151600084815286835260408082206001600160a01b038e1683529093529190912054909150808211156125035760405163119ac6bb60e31b815260040160405180910390fd5b6000838152602086815260408083206001600160a01b038e811685529252808320938590039093558a1681529081208054600195909501948392906125499084906137b9565b9091555061247792505050565b50846001600160a01b0316866001600160a01b0316886001600160a01b03167f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb87876040516125a692919061350e565b60405180910390a450505050505050565b6001600160a01b0384163b15611da55760405163bc197c8160e01b81526001600160a01b0385169063bc197c81906125fb9089908990889088908890600401613c55565b6020604051808303816000875af1925050508015612636575060408051601f3d908101601f1916820190925261263391810190613cb3565b60015b61269657612642613cd0565b806308c379a00361267b5750612656613cec565b80612661575061267d565b8060405162461bcd60e51b81526004016107569190612e99565b505b60405163380147a960e01b815260040160405180910390fd5b6001600160e01b0319811663bc197c8160e01b146126c757604051633744db2960e01b815260040160405180910390fd5b50505050505050565b600061064983836129b3565b60408051600180825281830190925260609160009190602080830190803683370190505090508281600081518110612716576127166137df565b602090810291909101015292915050565b6127358686868686866129f6565b6001600160a01b03841661276c57600061274e86611687565b9050805160000361276657612764600087612a04565b505b50612779565b612777600085612a19565b505b60005b83518110156126c7576000848281518110612799576127996137df565b6020026020010151905060006127ae82611658565b905080516000036127ca576127c4600283612a2e565b506127d7565b6127d56002836126d0565b505b505060010161277c565b6001600160a01b0384166128085760405163f5cadad560e01b815260040160405180910390fd5b612817868686612020876126dc565b6000838152600080516020613df1833981519152602081815260408084206001600160a01b038a16855290915290912054808411156128695760405163119ac6bb60e31b815260040160405180910390fd5b6000858152602083815260408083206001600160a01b038b811685529252808320938790039093558716815290812080548592906128a89084906137b9565b909155505060408051858152602081018590526001600160a01b038088169289821692918b16917fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6291016125a6565b6001600160a01b0384163b15611da55760405163f23a6e6160e01b81526001600160a01b0385169063f23a6e619061293b9089908990889088908890600401613d75565b6020604051808303816000875af1925050508015612976575060408051601f3d908101601f1916820190925261297391810190613cb3565b60015b61298257612642613cd0565b6001600160e01b0319811663f23a6e6160e01b146126c757604051633744db2960e01b815260040160405180910390fd5b600081815260018301602052604081205461064c575081546001808201845560008481526020808220909301849055845493815293810190915260409092205590565b611da5868686868686612a3a565b6000610649836001600160a01b038416612c26565b6000610649836001600160a01b0384166129b3565b60006106498383612c26565b836001600160a01b0316856001600160a01b031614611da5576001600160a01b0385811660009081527fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ec6020526040808220928716825281207fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424ea927fb31c2c74f86ca3ce94d901f5f5bbe66f7161eec2f7b5aa0b75a86371436424eb929091905b8751811015612c19576000878281518110612af857612af86137df565b602002602001015190506000811115612c10576000898381518110612b1f57612b1f6137df565b6020026020010151905060006001600160a01b03168c6001600160a01b031603612b6c5760008181526020889052604081208054849290612b619084906137b9565b90915550612ba19050565b81612b778d83611a7d565b03612ba1576000818152602087905260409020612b94908d612a04565b50612b9f8582612a2e565b505b6001600160a01b038b16612bd85760008181526020889052604081208054849290612bcd9084906137cc565b90915550612c0e9050565b612be28b82611a7d565b600003612c0e576000818152602087905260409020612c01908c612a19565b50612c0c84826126d0565b505b505b50600101612adb565b5050505050505050505050565b60008181526001830160205260408120548015612ce457835460009085906000198101908110612c5857612c586137df565b9060005260206000200154905080856000016001840381548110612c7e57612c7e6137df565b6000918252602080832090910192909255918252600186019052604090208190558354849080612cb057612cb0613dba565b6001900381819060005260206000200160009055905583600101600084815260200190815260200160002060009055600191505b5092915050565b6001600160a01b0381168114612d0057600080fd5b50565b60008060408385031215612d1657600080fd5b8235612d2181612ceb565b946020939093013593505050565b6001600160e01b031981168114612d0057600080fd5b600060208284031215612d5757600080fd5b813561094581612d2f565b60008083601f840112612d7457600080fd5b5081356001600160401b03811115612d8b57600080fd5b602083019150836020828501011115612da357600080fd5b9250929050565b60008060208385031215612dbd57600080fd5b82356001600160401b03811115612dd357600080fd5b612ddf85828601612d62565b90969095509350505050565b63ffffffff81168114612d0057600080fd5b803561ffff81168114612e0f57600080fd5b919050565b60008060408385031215612e2757600080fd5b8235612e3281612deb565b9150612e4060208401612dfd565b90509250929050565b60005b83811015612e64578181015183820152602001612e4c565b50506000910152565b60008151808452612e85816020860160208601612e49565b601f01601f19169290920160200192915050565b6020815260006106496020830184612e6d565b600060208284031215612ebe57600080fd5b813561094581612deb565b600060208284031215612edb57600080fd5b5035919050565b60008060008060808587031215612ef857600080fd5b8435612f0381612deb565b9350612f1160208601612dfd565b93969395505050506040820135916060013590565b60008151808452602080850194506020840160005b83811015612f5757815187529582019590820190600101612f3b565b509495945050505050565b6020815260006106496020830184612f26565b600060a063ffffffff88168352602061ffff8816818501526040876040860152606060a06060870152612fab60a0870189612e6d565b608087820360808901528189518084528684019150868160051b850101878c016000805b8481101561307957601f198885030186528251610100815186528c8201516014811061300957634e487b7160e01b85526021600452602485fd5b868e0152818c01516001600160e01b0319168c8701528a8201518b870182905261303582880182612e6d565b915050888201516130498a88018215159052565b50818e0151868f015260c0808301519087015260e09182015115159190950152948a0194918a0191600101612fcf565b5050508099505050505050505050509695505050505050565b6000806000606084860312156130a757600080fd5b83356130b281612deb565b92506130c060208501612dfd565b9150604084013590509250925092565b634e487b7160e01b600052604160045260246000fd5b601f8201601f191681016001600160401b038111828210171561310b5761310b6130d0565b6040525050565b60405161010081016001600160401b0381118282101715613135576131356130d0565b60405290565b60006001600160401b03821115613154576131546130d0565b5060051b60200190565b600082601f83011261316f57600080fd5b8135602061317c8261313b565b60405161318982826130e6565b80915083815260208101915060208460051b8701019350868411156131ad57600080fd5b602086015b84811015610a6057803583529183019183016131b2565b60006001600160401b038211156131e2576131e26130d0565b50601f01601f191660200190565b600082601f83011261320157600080fd5b813561320c816131c9565b60405161321982826130e6565b82815285602084870101111561322e57600080fd5b82602086016020830137600092810160200192909252509392505050565b600080600080600060a0868803121561326457600080fd5b853561326f81612ceb565b9450602086013561327f81612ceb565b935060408601356001600160401b038082111561329b57600080fd5b6132a789838a0161315e565b945060608801359150808211156132bd57600080fd5b6132c989838a0161315e565b935060808801359150808211156132df57600080fd5b506132ec888289016131f0565b9150509295509295909350565b6000806040838503121561330c57600080fd5b82356001600160401b038082111561332357600080fd5b818501915085601f83011261333757600080fd5b813560206133448261313b565b60405161335182826130e6565b83815260059390931b850182019282810191508984111561337157600080fd5b948201945b8386101561339857853561338981612ceb565b82529482019490820190613376565b965050860135925050808211156133ae57600080fd5b506133bb8582860161315e565b9150509250929050565b6000806000604084860312156133da57600080fd5b83356133e581612deb565b925060208401356001600160401b0381111561340057600080fd5b61340c86828701612d62565b9497909650939450505050565b600080600080600080600060c0888a03121561343457600080fd5b873561343f81612deb565b965061344d60208901612dfd565b9550604088013561345d81612ceb565b94506060880135935060808801356001600160401b0381111561347f57600080fd5b61348b8a828b01612d62565b989b979a5095989497959660a090950135949350505050565b6020808252825182820181905260009190848201906040850190845b818110156134e55783516001600160a01b0316835292840192918401916001016134c0565b50909695505050505050565b60006020828403121561350357600080fd5b813561094581612ceb565b6040815260006135216040830185612f26565b82810360208401526135338185612f26565b95945050505050565b8015158114612d0057600080fd5b6000806040838503121561355d57600080fd5b823561356881612ceb565b915060208301356135788161353c565b809150509250929050565b6000806040838503121561359657600080fd5b50508035926020909101359150565b600080604083850312156135b857600080fd5b82356135c381612ceb565b9150602083013561357881612ceb565b600080600080600060a086880312156135eb57600080fd5b85356135f681612ceb565b9450602086013561360681612ceb565b9350604086013592506060860135915060808601356001600160401b0381111561362f57600080fd5b6132ec888289016131f0565b8051612e0f8161353c565b60006020828403121561365857600080fd5b81516109458161353c565b60208082526027908201527f5574696c6974795472616974436f75706f6e3a20756e617574686f72697365646040820152661036b4b73a32b960c91b606082015260800190565b7f47616c61786973205574696c69747920547261697420436f75706f6e20666f7281526a01031b7b6b6bab734ba3c960ad1b6020820152600082516136f681602b850160208701612e49565b91909101602b0192915050565b60006020828403121561371557600080fd5b815161094581612ceb565b600082601f83011261373157600080fd5b815161373c816131c9565b60405161374982826130e6565b82815285602084870101111561375e57600080fd5b613533836020830160208801612e49565b60006020828403121561378157600080fd5b81516001600160401b0381111561379757600080fd5b6118bb84828501613720565b634e487b7160e01b600052601160045260246000fd5b8082018082111561064c5761064c6137a3565b8181038181111561064c5761064c6137a3565b634e487b7160e01b600052603260045260246000fd5b600181811c9082168061380957607f821691505b60208210810361382957634e487b7160e01b600052602260045260246000fd5b50919050565b6e54524149545f52454749535452595f60881b81526000825161385981600f850160208701612e49565b91909101600f0192915050565b805160148110612e0f57600080fd5b8051612e0f81612d2f565b6000602080838503121561389357600080fd5b82516001600160401b03808211156138aa57600080fd5b818501915085601f8301126138be57600080fd5b81516138c98161313b565b6040516138d682826130e6565b82815260059290921b84018501918581019150888311156138f657600080fd5b8585015b838110156139c75780518581111561391157600080fd5b8601610100818c03601f190181131561392957600080fd5b613931613112565b89830151815261394360408401613866565b8a82015261395360608401613875565b60408201526080808401518981111561396c5760008081fd5b61397a8f8d83880101613720565b60608401525060a061398d81860161363b565b8284015260c0915081850151818401525060e080850151828401526139b384860161363b565b9083015250855250509186019186016138fa565b5098975050505050505050565b6000600182016139e6576139e66137a3565b5060010190565b601f821115611376576000816000526020600020601f850160051c81016020861015613a165750805b601f850160051c820191505b81811015611da557828155600101613a22565b6001600160401b03831115613a4c57613a4c6130d0565b613a6083613a5a83546137f5565b836139ed565b6000601f841160018114613a945760008515613a7c5750838201355b600019600387901b1c1916600186901b178355610e00565b600083815260209020601f19861690835b82811015613ac55786850135825560209485019460019092019101613aa5565b5086821015613ae25760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b600080600060608486031215613b0957600080fd5b83516001600160401b03811115613b1f57600080fd5b613b2b86828701613720565b9350506020840151613b3c81612ceb565b6040850151909250613b4d81612deb565b809150509250925092565b634e487b7160e01b600052601260045260246000fd5b600082613b7d57613b7d613b58565b500490565b600082613b9157613b91613b58565b500690565b81516001600160401b03811115613baf57613baf6130d0565b613bc381613bbd84546137f5565b846139ed565b602080601f831160018114613bf85760008415613be05750858301515b600019600386901b1c1916600185901b178555611da5565b600085815260208120601f198616915b82811015613c2757888601518255948401946001909101908401613c08565b5085821015613c455787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b6001600160a01b0386811682528516602082015260a060408201819052600090613c8190830186612f26565b8281036060840152613c938186612f26565b90508281036080840152613ca78185612e6d565b98975050505050505050565b600060208284031215613cc557600080fd5b815161094581612d2f565b600060033d1115613ce95760046000803e5060005160e01c5b90565b600060443d1015613cfa5790565b6040516003193d81016004833e81513d6001600160401b038160248401118184111715613d2957505050505090565b8285019150815181811115613d415750505050505090565b843d8701016020828501011115613d5b5750505050505090565b613d6a602082860101876130e6565b509095945050505050565b6001600160a01b03868116825285166020820152604081018490526060810183905260a060808201819052600090613daf90830184612e6d565b979650505050505050565b634e487b7160e01b600052603160045260246000fdfe4d22f33240a09dddf495d4955c9f23af3488c8781d110f143c7072ad05e023821799cf914cb0cb442ca7c7ac709ee40d0cb89e87351dc08d517fbda27d50c68ba26469706673582212204cca6f6f0fcce9dc2741a8184da6eb40a930558d6bd53602ac230e7e97fd958c64736f6c63430008190033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae2

-----Decoded View---------------
Arg [0] : _galaxisRegistry (address): 0xdBD9608fBcA959828C1615d29AEb3dc872d40Ae2

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000dbd9608fbca959828c1615d29aeb3dc872d40ae2


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.