@etherisc/gif-next 0.0.2-b9b3e89 → 0.0.2-e6a90b9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
 - package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
 - package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
 - package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
 - package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
 - package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
 - package/artifacts/contracts/components/Pool.sol/Pool.json +2 -2
 - package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
 - package/artifacts/contracts/components/Product.sol/Product.json +2 -2
 - package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
 - package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
 - package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
 - package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
 - package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
 - package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
 - package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
 - package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
 - package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
 - package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
 - package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
 - package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
 - package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
 - package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
 - package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
 - package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
 - package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
 - package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
 - package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
 - package/artifacts/contracts/instance/Instance.sol/Instance.json +2 -2
 - package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
 - package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
 - package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
 - package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
 - package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +2 -2
 - package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
 - package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
 - package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
 - package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
 - package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
 - package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
 - package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
 - package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
 - package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
 - package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +2 -2
 - package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
 - package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
 - package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
 - package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
 - package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
 - package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
 - package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
 - package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +26 -18
 - package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
 - package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
 - package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
 - package/artifacts/contracts/registry/Registry.sol/Registry.json +43 -27
 - package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
 - package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
 - package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
 - package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
 - package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
 - package/artifacts/contracts/types/NftId.sol/NftIdLib.json +10 -0
 - package/contracts/experiment/errors/Require.sol +33 -0
 - package/contracts/experiment/errors/Revert.sol +39 -0
 - package/contracts/experiment/inheritance/A.sol +56 -0
 - package/contracts/experiment/inheritance/B.sol +23 -0
 - package/contracts/experiment/inheritance/C.sol +28 -0
 - package/contracts/experiment/inheritance/IA.sol +18 -0
 - package/contracts/experiment/inheritance/IB.sol +9 -0
 - package/contracts/experiment/inheritance/IC.sol +11 -0
 - package/contracts/experiment/types/TypeA.sol +42 -0
 - package/contracts/experiment/types/TypeB.sol +24 -0
 - package/contracts/instance/IInstance.sol +3 -3
 - package/contracts/instance/component/ComponentModule.sol +1 -14
 - package/contracts/registry/ChainNft.sol +173 -0
 - package/contracts/registry/IChainNft.sol +18 -0
 - package/contracts/registry/IRegistry.sol +3 -1
 - package/contracts/registry/Registry.sol +24 -45
 - package/contracts/types/ChainId.sol +24 -0
 - package/contracts/types/NftId.sol +25 -0
 - package/package.json +1 -1
 
| 
         @@ -0,0 +1,173 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
      
 2 
     | 
    
         
            +
            pragma solidity ^0.8.19;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
         
     | 
| 
      
 5 
     | 
    
         
            +
            import {IChainNft} from "./IChainNft.sol";
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            contract ChainNft is
         
     | 
| 
      
 8 
     | 
    
         
            +
                ERC721Enumerable,
         
     | 
| 
      
 9 
     | 
    
         
            +
                IChainNft
         
     | 
| 
      
 10 
     | 
    
         
            +
            {
         
     | 
| 
      
 11 
     | 
    
         
            +
                string public constant NAME = "Dezentralized Insurance Protocol Registry";
         
     | 
| 
      
 12 
     | 
    
         
            +
                string public constant SYMBOL = "DIPR";
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                // remember token uri
         
     | 
| 
      
 15 
     | 
    
         
            +
                mapping(uint256 tokenId => string uri) private _uri;
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                // remember registry
         
     | 
| 
      
 18 
     | 
    
         
            +
                address private _registry;
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                // only used for _getNextTokenId
         
     | 
| 
      
 21 
     | 
    
         
            +
                uint256 internal _chainIdInt; 
         
     | 
| 
      
 22 
     | 
    
         
            +
                uint256 internal _chainIdDigits;
         
     | 
| 
      
 23 
     | 
    
         
            +
                uint256 internal _chainIdMultiplier;
         
     | 
| 
      
 24 
     | 
    
         
            +
                uint256 internal _idNext;
         
     | 
| 
      
 25 
     | 
    
         
            +
                uint256 internal _totalMinted;
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                modifier onlyRegistry() {
         
     | 
| 
      
 29 
     | 
    
         
            +
                    require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
         
     | 
| 
      
 30 
     | 
    
         
            +
                    _;
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                constructor(address registry)
         
     | 
| 
      
 35 
     | 
    
         
            +
                    ERC721(NAME, SYMBOL)
         
     | 
| 
      
 36 
     | 
    
         
            +
                {
         
     | 
| 
      
 37 
     | 
    
         
            +
                    require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    _registry = registry;
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                    _chainIdInt = block.chainid;
         
     | 
| 
      
 42 
     | 
    
         
            +
                    _chainIdDigits = _countDigits(_chainIdInt);
         
     | 
| 
      
 43 
     | 
    
         
            +
                    _chainIdMultiplier = 10 ** _chainIdDigits;
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                    // on mainnet/goerli start /1 (reserved for protocol nft) on other chains with 2
         
     | 
| 
      
 46 
     | 
    
         
            +
                    if(block.chainid == 1 || block.chainid == 5) {
         
     | 
| 
      
 47 
     | 
    
         
            +
                        _idNext = 1;
         
     | 
| 
      
 48 
     | 
    
         
            +
                    } else {
         
     | 
| 
      
 49 
     | 
    
         
            +
                        _idNext = 2;
         
     | 
| 
      
 50 
     | 
    
         
            +
                    }
         
     | 
| 
      
 51 
     | 
    
         
            +
                }
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                function mint(
         
     | 
| 
      
 55 
     | 
    
         
            +
                    address to,
         
     | 
| 
      
 56 
     | 
    
         
            +
                    string memory uri
         
     | 
| 
      
 57 
     | 
    
         
            +
                )
         
     | 
| 
      
 58 
     | 
    
         
            +
                    external
         
     | 
| 
      
 59 
     | 
    
         
            +
                    override
         
     | 
| 
      
 60 
     | 
    
         
            +
                    onlyRegistry
         
     | 
| 
      
 61 
     | 
    
         
            +
                    returns(uint256 tokenId)
         
     | 
| 
      
 62 
     | 
    
         
            +
                {
         
     | 
| 
      
 63 
     | 
    
         
            +
                    tokenId = _getNextTokenId();
         
     | 
| 
      
 64 
     | 
    
         
            +
                    _totalMinted++;
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                    _safeMint(to, tokenId);
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                    if(bytes(uri).length > 0) {
         
     | 
| 
      
 69 
     | 
    
         
            +
                        _uri[tokenId] = uri;
         
     | 
| 
      
 70 
     | 
    
         
            +
                    }
         
     | 
| 
      
 71 
     | 
    
         
            +
                }
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
                function burn(uint256 tokenId)
         
     | 
| 
      
 75 
     | 
    
         
            +
                    external
         
     | 
| 
      
 76 
     | 
    
         
            +
                    override
         
     | 
| 
      
 77 
     | 
    
         
            +
                    onlyRegistry
         
     | 
| 
      
 78 
     | 
    
         
            +
                {
         
     | 
| 
      
 79 
     | 
    
         
            +
                    _requireMinted(tokenId);
         
     | 
| 
      
 80 
     | 
    
         
            +
                    _burn(tokenId);
         
     | 
| 
      
 81 
     | 
    
         
            +
                    delete _uri[tokenId];
         
     | 
| 
      
 82 
     | 
    
         
            +
                }
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                function setURI(uint256 tokenId, string memory uri)
         
     | 
| 
      
 86 
     | 
    
         
            +
                    external
         
     | 
| 
      
 87 
     | 
    
         
            +
                    override
         
     | 
| 
      
 88 
     | 
    
         
            +
                    onlyRegistry
         
     | 
| 
      
 89 
     | 
    
         
            +
                {
         
     | 
| 
      
 90 
     | 
    
         
            +
                    require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                    _requireMinted(tokenId);
         
     | 
| 
      
 93 
     | 
    
         
            +
                    _uri[tokenId] = uri;
         
     | 
| 
      
 94 
     | 
    
         
            +
                }
         
     | 
| 
      
 95 
     | 
    
         
            +
             
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                function exists(uint256 tokenId)
         
     | 
| 
      
 98 
     | 
    
         
            +
                    external
         
     | 
| 
      
 99 
     | 
    
         
            +
                    view
         
     | 
| 
      
 100 
     | 
    
         
            +
                    override
         
     | 
| 
      
 101 
     | 
    
         
            +
                    returns(bool)
         
     | 
| 
      
 102 
     | 
    
         
            +
                {
         
     | 
| 
      
 103 
     | 
    
         
            +
                    return _exists(tokenId);
         
     | 
| 
      
 104 
     | 
    
         
            +
                }
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                function tokenURI(uint256 tokenId)
         
     | 
| 
      
 108 
     | 
    
         
            +
                    public
         
     | 
| 
      
 109 
     | 
    
         
            +
                    view
         
     | 
| 
      
 110 
     | 
    
         
            +
                    override 
         
     | 
| 
      
 111 
     | 
    
         
            +
                    returns(string memory)
         
     | 
| 
      
 112 
     | 
    
         
            +
                {
         
     | 
| 
      
 113 
     | 
    
         
            +
                    _requireMinted(tokenId);
         
     | 
| 
      
 114 
     | 
    
         
            +
                    return _uri[tokenId];
         
     | 
| 
      
 115 
     | 
    
         
            +
                }
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
                function getRegistryAddress()
         
     | 
| 
      
 119 
     | 
    
         
            +
                    external
         
     | 
| 
      
 120 
     | 
    
         
            +
                    view
         
     | 
| 
      
 121 
     | 
    
         
            +
                    override
         
     | 
| 
      
 122 
     | 
    
         
            +
                    returns(address)
         
     | 
| 
      
 123 
     | 
    
         
            +
                {
         
     | 
| 
      
 124 
     | 
    
         
            +
                    return _registry;
         
     | 
| 
      
 125 
     | 
    
         
            +
                }
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                function totalMinted() external override view returns(uint256) {
         
     | 
| 
      
 128 
     | 
    
         
            +
                    return _totalMinted;
         
     | 
| 
      
 129 
     | 
    
         
            +
                }
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
                // requirement: each chain registry produces token ids that
         
     | 
| 
      
 132 
     | 
    
         
            +
                // are guaranteed to not collide with any token id genereated
         
     | 
| 
      
 133 
     | 
    
         
            +
                // on a different chain
         
     | 
| 
      
 134 
     | 
    
         
            +
                //
         
     | 
| 
      
 135 
     | 
    
         
            +
                // format concat(counter,chainid,2 digits for len-of-chain-id)
         
     | 
| 
      
 136 
     | 
    
         
            +
                // restriction chainid up to 99 digits
         
     | 
| 
      
 137 
     | 
    
         
            +
                // decode: from right to left:
         
     | 
| 
      
 138 
     | 
    
         
            +
                // - 2 right most digits encode length of chainid
         
     | 
| 
      
 139 
     | 
    
         
            +
                // - move number of digits to left as determined above (-> chainid)
         
     | 
| 
      
 140 
     | 
    
         
            +
                // - the reminder to the left is the counter
         
     | 
| 
      
 141 
     | 
    
         
            +
                // examples
         
     | 
| 
      
 142 
     | 
    
         
            +
                // 1101
         
     | 
| 
      
 143 
     | 
    
         
            +
                // ^^ ^
         
     | 
| 
      
 144 
     | 
    
         
            +
                // || +- 1-digit chain id
         
     | 
| 
      
 145 
     | 
    
         
            +
                // |+-- chain id = 1 (mainnet)
         
     | 
| 
      
 146 
     | 
    
         
            +
                // +-- 1st token id on mainnet
         
     | 
| 
      
 147 
     | 
    
         
            +
                // (1 * 10 ** 1 + 1) * 100 + 1
         
     | 
| 
      
 148 
     | 
    
         
            +
                // 42987654321010
         
     | 
| 
      
 149 
     | 
    
         
            +
                // ^ ^          ^
         
     | 
| 
      
 150 
     | 
    
         
            +
                // | |          +- 10-digit chain id
         
     | 
| 
      
 151 
     | 
    
         
            +
                // | +-- chain id = 9876543210 (hypothetical chainid)
         
     | 
| 
      
 152 
     | 
    
         
            +
                // +-- 42nd token id on this chain
         
     | 
| 
      
 153 
     | 
    
         
            +
                // (42 * 10 ** 10 + 9876543210) * 100 + 10
         
     | 
| 
      
 154 
     | 
    
         
            +
                // (index * 10 ** digits + chainid) * 100 + digits (1 < digits < 100)
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                function _getNextTokenId() private returns(uint256 id) {
         
     | 
| 
      
 157 
     | 
    
         
            +
                    id = (_idNext * _chainIdMultiplier + _chainIdInt) * 100 + _chainIdDigits;
         
     | 
| 
      
 158 
     | 
    
         
            +
                    _idNext++;
         
     | 
| 
      
 159 
     | 
    
         
            +
                }
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                function _countDigits(uint256 num)
         
     | 
| 
      
 163 
     | 
    
         
            +
                    private 
         
     | 
| 
      
 164 
     | 
    
         
            +
                    pure 
         
     | 
| 
      
 165 
     | 
    
         
            +
                    returns (uint256 count)
         
     | 
| 
      
 166 
     | 
    
         
            +
                {
         
     | 
| 
      
 167 
     | 
    
         
            +
                    count = 0;
         
     | 
| 
      
 168 
     | 
    
         
            +
                    while (num != 0) {
         
     | 
| 
      
 169 
     | 
    
         
            +
                        count++;
         
     | 
| 
      
 170 
     | 
    
         
            +
                        num /= 10;
         
     | 
| 
      
 171 
     | 
    
         
            +
                    }
         
     | 
| 
      
 172 
     | 
    
         
            +
                }
         
     | 
| 
      
 173 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
      
 2 
     | 
    
         
            +
            pragma solidity ^0.8.19;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            interface IChainNft is 
         
     | 
| 
      
 7 
     | 
    
         
            +
                IERC721Enumerable 
         
     | 
| 
      
 8 
     | 
    
         
            +
            {
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                function mint(address to, string memory uri) external returns(uint256 tokenId);
         
     | 
| 
      
 11 
     | 
    
         
            +
                function burn(uint256 tokenId) external;
         
     | 
| 
      
 12 
     | 
    
         
            +
                function setURI(uint256 tokenId, string memory uri) external;
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                function exists(uint256 tokenId) external view returns(bool);
         
     | 
| 
      
 15 
     | 
    
         
            +
                function totalMinted() external view returns(uint256);
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                function getRegistryAddress() external view returns(address registry);
         
     | 
| 
      
 18 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -56,11 +56,13 @@ interface IRegistry { 
     | 
|
| 
       56 
56 
     | 
    
         
             
                )
         
     | 
| 
       57 
57 
     | 
    
         
             
                    external returns(uint256 nftId);
         
     | 
| 
       58 
58 
     | 
    
         | 
| 
       59 
     | 
    
         
            -
                function  
     | 
| 
      
 59 
     | 
    
         
            +
                function getObjectCount() external view returns(uint256);
         
     | 
| 
       60 
60 
     | 
    
         | 
| 
       61 
61 
     | 
    
         
             
                function getNftId(address objectAddress) external view returns(uint256 nftId);
         
     | 
| 
       62 
62 
     | 
    
         
             
                function getInfo(uint256 nftId) external view returns(RegistryInfo memory info);
         
     | 
| 
       63 
63 
     | 
    
         
             
                function getOwner(uint256 nftId) external view returns(address ownerAddress);
         
     | 
| 
       64 
64 
     | 
    
         | 
| 
       65 
65 
     | 
    
         
             
                function isRegistered(address objectAddress) external view returns(bool);
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                function getNftAddress() external view returns(address nft);
         
     | 
| 
       66 
68 
     | 
    
         
             
            }
         
     | 
| 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
       2 
2 
     | 
    
         
             
            pragma solidity ^0.8.19;
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
      
 4 
     | 
    
         
            +
            import {IChainNft} from "./IChainNft.sol";
         
     | 
| 
       4 
5 
     | 
    
         
             
            import {IRegistry, IRegistryLinked, IRegisterable} from "./IRegistry.sol";
         
     | 
| 
       5 
6 
     | 
    
         | 
| 
       6 
7 
     | 
    
         
             
            contract RegistryLinked is IRegistryLinked {
         
     | 
| 
         @@ -11,11 +12,6 @@ contract RegistryLinked is IRegistryLinked { 
     | 
|
| 
       11 
12 
     | 
    
         
             
                    _registry = IRegistry(registry);
         
     | 
| 
       12 
13 
     | 
    
         
             
                }
         
     | 
| 
       13 
14 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                // function setRegistry(address registry) public override {
         
     | 
| 
       15 
     | 
    
         
            -
                //     require(address(_registry) == address(0), "ERROR:RGL-001:REGISTRY_ALREADY_SET");
         
     | 
| 
       16 
     | 
    
         
            -
                //     _registry = IRegistry(registry);
         
     | 
| 
       17 
     | 
    
         
            -
                // }
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
15 
     | 
    
         
             
                function getRegistry() external view override returns(IRegistry registry) {
         
     | 
| 
       20 
16 
     | 
    
         
             
                    return _registry;
         
     | 
| 
       21 
17 
     | 
    
         
             
                }
         
     | 
| 
         @@ -62,24 +58,19 @@ abstract contract Registerable is 
     | 
|
| 
       62 
58 
     | 
    
         | 
| 
       63 
59 
     | 
    
         
             
            }
         
     | 
| 
       64 
60 
     | 
    
         | 
| 
       65 
     | 
    
         
            -
                // struct RegistryInfo {
         
     | 
| 
       66 
     | 
    
         
            -
                //     bytes32 id;
         
     | 
| 
       67 
     | 
    
         
            -
                //     uint256 objectType;
         
     | 
| 
       68 
     | 
    
         
            -
                //     address objectAddress;
         
     | 
| 
       69 
     | 
    
         
            -
                //     address initialOwner;
         
     | 
| 
       70 
     | 
    
         
            -
                // }
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
61 
     | 
    
         
             
            contract Registry is IRegistry {
         
     | 
| 
       73 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
                string public constant EMPTY_URI = "";
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       74 
65 
     | 
    
         
             
                mapping(uint256 id => RegistryInfo info) private _info;
         
     | 
| 
       75 
66 
     | 
    
         
             
                mapping(uint256 id => address owner) private _owner;
         
     | 
| 
       76 
67 
     | 
    
         
             
                mapping(address object => uint256 id) private _idByAddress;
         
     | 
| 
       77 
     | 
    
         
            -
                uint256 [] private _ids;
         
     | 
| 
       78 
     | 
    
         
            -
                uint256 private _idNext;
         
     | 
| 
       79 
68 
     | 
    
         | 
| 
      
 69 
     | 
    
         
            +
                IChainNft private _chainNft;
         
     | 
| 
       80 
70 
     | 
    
         | 
| 
       81 
     | 
    
         
            -
                 
     | 
| 
       82 
     | 
    
         
            -
                     
     | 
| 
      
 71 
     | 
    
         
            +
                function initialize(address chainNft) external {
         
     | 
| 
      
 72 
     | 
    
         
            +
                    require(address(_chainNft) == address(0), "ERROR:REG-001:ALREADY_INITIALIZED");
         
     | 
| 
      
 73 
     | 
    
         
            +
                    _chainNft = IChainNft(chainNft);
         
     | 
| 
       83 
74 
     | 
    
         
             
                }
         
     | 
| 
       84 
75 
     | 
    
         | 
| 
       85 
76 
     | 
    
         
             
                function TOKEN() public pure override returns(uint256) { return 30; }
         
     | 
| 
         @@ -91,20 +82,22 @@ contract Registry is IRegistry { 
     | 
|
| 
       91 
82 
     | 
    
         
             
                function BUNDLE() public pure override returns(uint256) { return 90; }
         
     | 
| 
       92 
83 
     | 
    
         | 
| 
       93 
84 
     | 
    
         
             
                function register(address objectAddress) external override returns(uint256 nftId) {
         
     | 
| 
       94 
     | 
    
         
            -
                    require(_idByAddress[objectAddress] == 0, "ERROR:REG- 
     | 
| 
      
 85 
     | 
    
         
            +
                    require(_idByAddress[objectAddress] == 0, "ERROR:REG-002:ALREADY_REGISTERED");
         
     | 
| 
       95 
86 
     | 
    
         | 
| 
       96 
87 
     | 
    
         
             
                    IRegisterable registerable = IRegisterable(objectAddress);
         
     | 
| 
       97 
     | 
    
         
            -
                    require(registerable.isRegisterable(), "ERROR:REG- 
     | 
| 
      
 88 
     | 
    
         
            +
                    require(registerable.isRegisterable(), "ERROR:REG-003:NOT_REGISTERABLE");
         
     | 
| 
       98 
89 
     | 
    
         | 
| 
       99 
90 
     | 
    
         
             
                    // check parent exists (for objects not instances)
         
     | 
| 
       100 
91 
     | 
    
         
             
                    if(registerable.getType() != INSTANCE()) {
         
     | 
| 
       101 
92 
     | 
    
         
             
                        RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
         
     | 
| 
       102 
     | 
    
         
            -
                        require(parentInfo.nftId > 0, "ERROR:REG- 
     | 
| 
      
 93 
     | 
    
         
            +
                        require(parentInfo.nftId > 0, "ERROR:REG-004:PARENT_NOT_FOUND");
         
     | 
| 
       103 
94 
     | 
    
         
             
                        // check validity of parent relation, valid relations are
         
     | 
| 
       104 
95 
     | 
    
         
             
                        // policy -> product, bundle -> pool, product -> instance, pool -> instance
         
     | 
| 
       105 
96 
     | 
    
         
             
                    }
         
     | 
| 
       106 
97 
     | 
    
         | 
| 
       107 
     | 
    
         
            -
                    nftId =  
     | 
| 
      
 98 
     | 
    
         
            +
                    nftId = _chainNft.mint(
         
     | 
| 
      
 99 
     | 
    
         
            +
                        registerable.getInitialOwner(), 
         
     | 
| 
      
 100 
     | 
    
         
            +
                        EMPTY_URI);
         
     | 
| 
       108 
101 
     | 
    
         | 
| 
       109 
102 
     | 
    
         
             
                    RegistryInfo memory info = RegistryInfo(
         
     | 
| 
       110 
103 
     | 
    
         
             
                        nftId,
         
     | 
| 
         @@ -136,7 +129,9 @@ contract Registry is IRegistry { 
     | 
|
| 
       136 
129 
     | 
    
         
             
                        objectType == POLICY() || objectType == BUNDLE(),
         
     | 
| 
       137 
130 
     | 
    
         
             
                        "ERROR:REG-005:TYPE_INVALID");
         
     | 
| 
       138 
131 
     | 
    
         | 
| 
       139 
     | 
    
         
            -
                    nftId =  
     | 
| 
      
 132 
     | 
    
         
            +
                    nftId = _chainNft.mint(
         
     | 
| 
      
 133 
     | 
    
         
            +
                        initialOwner,
         
     | 
| 
      
 134 
     | 
    
         
            +
                        EMPTY_URI);
         
     | 
| 
       140 
135 
     | 
    
         | 
| 
       141 
136 
     | 
    
         
             
                    RegistryInfo memory info = RegistryInfo(
         
     | 
| 
       142 
137 
     | 
    
         
             
                        nftId,
         
     | 
| 
         @@ -152,16 +147,8 @@ contract Registry is IRegistry { 
     | 
|
| 
       152 
147 
     | 
    
         
             
                }
         
     | 
| 
       153 
148 
     | 
    
         | 
| 
       154 
149 
     | 
    
         | 
| 
       155 
     | 
    
         
            -
                function  
     | 
| 
       156 
     | 
    
         
            -
                     
     | 
| 
       157 
     | 
    
         
            -
                    _owner[id] = newOwner;
         
     | 
| 
       158 
     | 
    
         
            -
             
     | 
| 
       159 
     | 
    
         
            -
                    // TODO logging
         
     | 
| 
       160 
     | 
    
         
            -
                }
         
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
             
     | 
| 
       163 
     | 
    
         
            -
                function getObjectCount() external view returns(uint256) {
         
     | 
| 
       164 
     | 
    
         
            -
                    return _ids.length;
         
     | 
| 
      
 150 
     | 
    
         
            +
                function getObjectCount() external view override returns(uint256) {
         
     | 
| 
      
 151 
     | 
    
         
            +
                    return _chainNft.totalSupply();
         
     | 
| 
       165 
152 
     | 
    
         
             
                }
         
     | 
| 
       166 
153 
     | 
    
         | 
| 
       167 
154 
     | 
    
         | 
| 
         @@ -175,23 +162,15 @@ contract Registry is IRegistry { 
     | 
|
| 
       175 
162 
     | 
    
         
             
                }
         
     | 
| 
       176 
163 
     | 
    
         | 
| 
       177 
164 
     | 
    
         | 
| 
       178 
     | 
    
         
            -
                function getInfo(uint256  
     | 
| 
       179 
     | 
    
         
            -
                    return _info[ 
     | 
| 
      
 165 
     | 
    
         
            +
                function getInfo(uint256 nftId) external view override returns(RegistryInfo memory info) {
         
     | 
| 
      
 166 
     | 
    
         
            +
                    return _info[nftId];
         
     | 
| 
       180 
167 
     | 
    
         
             
                }
         
     | 
| 
       181 
168 
     | 
    
         | 
| 
       182 
     | 
    
         
            -
                function getOwner(uint256  
     | 
| 
       183 
     | 
    
         
            -
                    return  
     | 
| 
      
 169 
     | 
    
         
            +
                function getOwner(uint256 nftId) external view override returns(address) {
         
     | 
| 
      
 170 
     | 
    
         
            +
                    return _chainNft.ownerOf(nftId);
         
     | 
| 
       184 
171 
     | 
    
         
             
                }
         
     | 
| 
       185 
172 
     | 
    
         | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
                    internal
         
     | 
| 
       189 
     | 
    
         
            -
                    returns(uint256 id)
         
     | 
| 
       190 
     | 
    
         
            -
                {
         
     | 
| 
       191 
     | 
    
         
            -
                    _idNext++;
         
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
                    id = _idNext;
         
     | 
| 
       194 
     | 
    
         
            -
                    _owner[id] = initialOwner;
         
     | 
| 
       195 
     | 
    
         
            -
                    _ids.push(id);
         
     | 
| 
      
 173 
     | 
    
         
            +
                function getNftAddress() external view override returns(address nft) {
         
     | 
| 
      
 174 
     | 
    
         
            +
                    return address(_chainNft);
         
     | 
| 
       196 
175 
     | 
    
         
             
                }
         
     | 
| 
       197 
176 
     | 
    
         
             
            }
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
      
 2 
     | 
    
         
            +
            pragma solidity ^0.8.19;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            // bytes5 (uint40) allows for chain ids up to 13 digits
         
     | 
| 
      
 5 
     | 
    
         
            +
            type ChainId is bytes5;
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            // type bindings
         
     | 
| 
      
 8 
     | 
    
         
            +
            using {
         
     | 
| 
      
 9 
     | 
    
         
            +
                eqChainId as ==,
         
     | 
| 
      
 10 
     | 
    
         
            +
                neChainId as !=,
         
     | 
| 
      
 11 
     | 
    
         
            +
                ChainIdLib.toInt
         
     | 
| 
      
 12 
     | 
    
         
            +
            } for ChainId global;
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            // general pure free functions
         
     | 
| 
      
 15 
     | 
    
         
            +
            function toChainId(uint256 chainId) pure returns(ChainId) { return ChainId.wrap(bytes5(uint40(chainId))); }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            // pure free functions for operators
         
     | 
| 
      
 18 
     | 
    
         
            +
            function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) { return ChainId.unwrap(a) == ChainId.unwrap(b); }
         
     | 
| 
      
 19 
     | 
    
         
            +
            function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) { return ChainId.unwrap(a) != ChainId.unwrap(b); }
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            // library functions that operate on user defined type
         
     | 
| 
      
 22 
     | 
    
         
            +
            library ChainIdLib {
         
     | 
| 
      
 23 
     | 
    
         
            +
                function toInt(ChainId chainId) internal pure returns(uint256) { return uint256(uint40(ChainId.unwrap(chainId))); }
         
     | 
| 
      
 24 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            // SPDX-License-Identifier: Apache-2.0
         
     | 
| 
      
 2 
     | 
    
         
            +
            pragma solidity ^0.8.19;
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            // uint96 allows for chain ids up to 13 digits
         
     | 
| 
      
 5 
     | 
    
         
            +
            type NftId is uint96;
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            // type bindings
         
     | 
| 
      
 8 
     | 
    
         
            +
            using {
         
     | 
| 
      
 9 
     | 
    
         
            +
                eqNftId as ==,
         
     | 
| 
      
 10 
     | 
    
         
            +
                neNftId as !=,
         
     | 
| 
      
 11 
     | 
    
         
            +
                NftIdLib.toInt
         
     | 
| 
      
 12 
     | 
    
         
            +
            } for NftId global;
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            // general pure free functions
         
     | 
| 
      
 15 
     | 
    
         
            +
            function toNftId(uint256 id) pure returns(NftId) { return NftId.wrap(uint96(id)); }
         
     | 
| 
      
 16 
     | 
    
         
            +
            function gtz(NftId a) pure returns(bool) { return NftId.unwrap(a) > 0; }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            // pure free functions for operators
         
     | 
| 
      
 19 
     | 
    
         
            +
            function eqNftId(NftId a, NftId b) pure returns(bool isSame) { return NftId.unwrap(a) == NftId.unwrap(b); }
         
     | 
| 
      
 20 
     | 
    
         
            +
            function neNftId(NftId a, NftId b) pure returns(bool isDifferent) { return NftId.unwrap(a) != NftId.unwrap(b); }
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
            // library functions that operate on user defined type
         
     | 
| 
      
 23 
     | 
    
         
            +
            library NftIdLib {
         
     | 
| 
      
 24 
     | 
    
         
            +
                function toInt(NftId nftId) internal pure returns(uint256) { return uint256(NftId.unwrap(nftId)); }
         
     | 
| 
      
 25 
     | 
    
         
            +
            }
         
     | 
    
        package/package.json
    CHANGED