@etherisc/gif-next 0.0.2-9141c0d → 0.0.2-a0d749a

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.
Files changed (156) hide show
  1. package/README.md +119 -1
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
  3. package/artifacts/contracts/components/Component.sol/Component.json +179 -0
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +4 -0
  5. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +35 -0
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +4 -0
  7. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +179 -0
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +4 -0
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +192 -0
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +213 -0
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  13. package/artifacts/contracts/components/Product.sol/Product.json +231 -0
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  25. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  27. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
  28. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
  30. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
  32. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  36. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  38. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
  39. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +892 -0
  40. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
  41. package/artifacts/contracts/instance/Instance.sol/Instance.json +1067 -0
  42. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +4 -0
  43. package/artifacts/contracts/instance/access/Access.sol/AccessModule.json +400 -0
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +4 -0
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.json +10 -0
  46. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +4 -0
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.json +35 -0
  48. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +4 -0
  49. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.json +50 -0
  50. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +4 -0
  51. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.json +336 -0
  52. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +4 -0
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +327 -0
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +4 -0
  55. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +147 -0
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +4 -0
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.json +10 -0
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +4 -0
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +179 -0
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +4 -0
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +245 -0
  62. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +4 -0
  63. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +94 -0
  64. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +4 -0
  65. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.json +24 -0
  66. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +4 -0
  67. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.json +10 -0
  68. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +4 -0
  69. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +231 -0
  70. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +4 -0
  71. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +231 -0
  72. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +4 -0
  73. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.json +10 -0
  74. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +4 -0
  75. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +149 -0
  76. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +4 -0
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +162 -0
  78. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +4 -0
  79. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.json +75 -0
  80. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +4 -0
  81. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +114 -0
  82. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +4 -0
  83. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.json +75 -0
  84. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +4 -0
  85. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +167 -0
  86. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  87. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  88. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  89. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  90. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +4 -0
  91. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.json +24 -0
  92. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +4 -0
  93. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +166 -0
  94. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
  95. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +279 -0
  96. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +4 -0
  97. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.json +49 -0
  98. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +4 -0
  99. package/artifacts/contracts/registry/Registry.sol/Registerable.json +166 -0
  100. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
  101. package/artifacts/contracts/registry/Registry.sol/Registry.json +347 -0
  102. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +4 -0
  103. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +60 -0
  104. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  105. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  106. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  107. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  108. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  109. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
  110. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  111. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  112. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  113. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
  114. package/contracts/components/Component.sol +60 -0
  115. package/contracts/components/IPool.sol +9 -0
  116. package/contracts/components/IProduct.sol +9 -0
  117. package/contracts/components/Pool.sol +22 -0
  118. package/contracts/components/Product.sol +55 -0
  119. package/contracts/experiment/errors/Require.sol +38 -0
  120. package/contracts/experiment/errors/Revert.sol +44 -0
  121. package/contracts/experiment/inheritance/A.sol +53 -0
  122. package/contracts/experiment/inheritance/B.sol +28 -0
  123. package/contracts/experiment/inheritance/C.sol +34 -0
  124. package/contracts/experiment/inheritance/IA.sol +13 -0
  125. package/contracts/experiment/inheritance/IB.sol +10 -0
  126. package/contracts/experiment/inheritance/IC.sol +12 -0
  127. package/contracts/experiment/types/TypeA.sol +47 -0
  128. package/contracts/experiment/types/TypeB.sol +29 -0
  129. package/contracts/instance/IInstance.sol +18 -0
  130. package/contracts/instance/Instance.sol +64 -0
  131. package/contracts/instance/access/Access.sol +165 -0
  132. package/contracts/instance/access/IAccess.sol +63 -0
  133. package/contracts/instance/component/ComponentModule.sol +213 -0
  134. package/contracts/instance/component/IComponent.sol +73 -0
  135. package/contracts/instance/policy/IPolicy.sol +51 -0
  136. package/contracts/instance/policy/PolicyModule.sol +91 -0
  137. package/contracts/instance/pool/IPoolModule.sol +29 -0
  138. package/contracts/instance/pool/PoolModule.sol +73 -0
  139. package/contracts/instance/product/IProductService.sol +36 -0
  140. package/contracts/instance/product/ProductService.sol +112 -0
  141. package/contracts/registry/ChainNft.sol +135 -0
  142. package/contracts/registry/IChainNft.sol +21 -0
  143. package/contracts/registry/IRegistry.sol +80 -0
  144. package/contracts/registry/Registry.sol +209 -0
  145. package/contracts/types/Blocknumber.sol +118 -0
  146. package/contracts/types/ChainId.sol +38 -0
  147. package/contracts/types/NftId.sol +51 -0
  148. package/contracts/types/Timestamp.sol +102 -0
  149. package/contracts/types/UFixed.sol +205 -0
  150. package/package.json +14 -8
  151. package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
  152. package/artifacts/contracts/Dip.sol/DIP.json +0 -338
  153. package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
  154. package/artifacts/contracts/Lock.sol/Lock.json +0 -74
  155. package/contracts/Dip.sol +0 -26
  156. package/contracts/Lock.sol +0 -34
@@ -0,0 +1,135 @@
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 ERC721Enumerable, IChainNft {
8
+ string public constant NAME = "Dezentralized Insurance Protocol Registry";
9
+ string public constant SYMBOL = "DIPR";
10
+
11
+ // remember token uri
12
+ mapping(uint256 tokenId => string uri) private _uri;
13
+
14
+ // remember registry
15
+ address private _registry;
16
+
17
+ // only used for _getNextTokenId
18
+ uint256 internal _chainIdInt;
19
+ uint256 internal _chainIdDigits;
20
+ uint256 internal _chainIdMultiplier;
21
+ uint256 internal _idNext;
22
+ uint256 internal _totalMinted;
23
+
24
+ modifier onlyRegistry() {
25
+ require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
26
+ _;
27
+ }
28
+
29
+ constructor(address registry) ERC721(NAME, SYMBOL) {
30
+ require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
31
+
32
+ _registry = registry;
33
+
34
+ _chainIdInt = block.chainid;
35
+ _chainIdDigits = _countDigits(_chainIdInt);
36
+ _chainIdMultiplier = 10 ** _chainIdDigits;
37
+
38
+ // on mainnet/goerli start /1 (reserved for protocol nft) on other chains with 2
39
+ if (block.chainid == 1 || block.chainid == 5) {
40
+ _idNext = 1;
41
+ } else {
42
+ _idNext = 2;
43
+ }
44
+ }
45
+
46
+ function mint(
47
+ address to,
48
+ string memory uri
49
+ ) external override onlyRegistry returns (uint256 tokenId) {
50
+ tokenId = _getNextTokenId();
51
+ _totalMinted++;
52
+
53
+ _safeMint(to, tokenId);
54
+
55
+ if (bytes(uri).length > 0) {
56
+ _uri[tokenId] = uri;
57
+ }
58
+ }
59
+
60
+ function burn(uint256 tokenId) external override onlyRegistry {
61
+ _requireMinted(tokenId);
62
+ _burn(tokenId);
63
+ delete _uri[tokenId];
64
+ }
65
+
66
+ function setURI(
67
+ uint256 tokenId,
68
+ string memory uri
69
+ ) external override onlyRegistry {
70
+ require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
71
+
72
+ _requireMinted(tokenId);
73
+ _uri[tokenId] = uri;
74
+ }
75
+
76
+ function exists(uint256 tokenId) external view override returns (bool) {
77
+ return _exists(tokenId);
78
+ }
79
+
80
+ function tokenURI(
81
+ uint256 tokenId
82
+ ) public view override returns (string memory) {
83
+ _requireMinted(tokenId);
84
+ return _uri[tokenId];
85
+ }
86
+
87
+ function getRegistryAddress() external view override returns (address) {
88
+ return _registry;
89
+ }
90
+
91
+ function totalMinted() external view override returns (uint256) {
92
+ return _totalMinted;
93
+ }
94
+
95
+ // requirement: each chain registry produces token ids that
96
+ // are guaranteed to not collide with any token id genereated
97
+ // on a different chain
98
+ //
99
+ // format concat(counter,chainid,2 digits for len-of-chain-id)
100
+ // restriction chainid up to 99 digits
101
+ // decode: from right to left:
102
+ // - 2 right most digits encode length of chainid
103
+ // - move number of digits to left as determined above (-> chainid)
104
+ // - the reminder to the left is the counter
105
+ // examples
106
+ // 1101
107
+ // ^^ ^
108
+ // || +- 1-digit chain id
109
+ // |+-- chain id = 1 (mainnet)
110
+ // +-- 1st token id on mainnet
111
+ // (1 * 10 ** 1 + 1) * 100 + 1
112
+ // 42987654321010
113
+ // ^ ^ ^
114
+ // | | +- 10-digit chain id
115
+ // | +-- chain id = 9876543210 (hypothetical chainid)
116
+ // +-- 42nd token id on this chain
117
+ // (42 * 10 ** 10 + 9876543210) * 100 + 10
118
+ // (index * 10 ** digits + chainid) * 100 + digits (1 < digits < 100)
119
+
120
+ function _getNextTokenId() private returns (uint256 id) {
121
+ id =
122
+ (_idNext * _chainIdMultiplier + _chainIdInt) *
123
+ 100 +
124
+ _chainIdDigits;
125
+ _idNext++;
126
+ }
127
+
128
+ function _countDigits(uint256 num) private pure returns (uint256 count) {
129
+ count = 0;
130
+ while (num != 0) {
131
+ count++;
132
+ num /= 10;
133
+ }
134
+ }
135
+ }
@@ -0,0 +1,21 @@
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 IERC721Enumerable {
7
+ function mint(
8
+ address to,
9
+ string memory uri
10
+ ) external returns (uint256 tokenId);
11
+
12
+ function burn(uint256 tokenId) external;
13
+
14
+ function setURI(uint256 tokenId, string memory uri) external;
15
+
16
+ function exists(uint256 tokenId) external view returns (bool);
17
+
18
+ function totalMinted() external view returns (uint256);
19
+
20
+ function getRegistryAddress() external view returns (address registry);
21
+ }
@@ -0,0 +1,80 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {NftId} from "../types/NftId.sol";
5
+
6
+ interface IOwnable {
7
+ function getOwner() external view returns (address owner);
8
+ }
9
+
10
+ interface IRegistryLinked {
11
+ event LogDebug(uint256 idx, address module, string comment);
12
+
13
+ function getRegistry() external view returns (IRegistry registry);
14
+ }
15
+
16
+ interface IRegisterable is IOwnable, IRegistryLinked {
17
+ function register() external returns (NftId nftId);
18
+
19
+ function getNftId() external view returns (NftId nftId);
20
+
21
+ function getParentNftId() external view returns (NftId parentNftId);
22
+
23
+ function getType() external view returns (uint256 objectType);
24
+
25
+ function getData() external view returns (bytes memory data);
26
+
27
+ function isRegisterable() external pure returns (bool);
28
+
29
+ function getInitialOwner() external view returns (address initialOwner);
30
+
31
+ function isRegistered() external view returns (bool);
32
+ }
33
+
34
+ interface IRegistry {
35
+ struct RegistryInfo {
36
+ NftId nftId;
37
+ NftId parentNftId;
38
+ uint256 objectType;
39
+ address objectAddress;
40
+ address initialOwner;
41
+ }
42
+
43
+ function TOKEN() external pure returns (uint256);
44
+
45
+ function INSTANCE() external pure returns (uint256);
46
+
47
+ function PRODUCT() external pure returns (uint256);
48
+
49
+ function ORACLE() external pure returns (uint256);
50
+
51
+ function POOL() external pure returns (uint256);
52
+
53
+ function POLICY() external pure returns (uint256);
54
+
55
+ function BUNDLE() external pure returns (uint256);
56
+
57
+ function register(address objectAddress) external returns (NftId nftId);
58
+
59
+ function registerObjectForInstance(
60
+ NftId parentNftid,
61
+ uint256 objectType,
62
+ address initialOwner
63
+ ) external returns (NftId nftId);
64
+
65
+ function getObjectCount() external view returns (uint256);
66
+
67
+ function getNftId(
68
+ address objectAddress
69
+ ) external view returns (NftId nftId);
70
+
71
+ function getInfo(
72
+ NftId nftId
73
+ ) external view returns (RegistryInfo memory info);
74
+
75
+ function getOwner(NftId nftId) external view returns (address ownerAddress);
76
+
77
+ function isRegistered(address objectAddress) external view returns (bool);
78
+
79
+ function getNftAddress() external view returns (address nft);
80
+ }
@@ -0,0 +1,209 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IChainNft} from "./IChainNft.sol";
5
+ import {IRegistry, IRegistryLinked, IRegisterable} from "./IRegistry.sol";
6
+ import {NftId, toNftId} from "../types/NftId.sol";
7
+ import {NftIdLib} from "../types/NftId.sol";
8
+
9
+ contract RegistryLinked is IRegistryLinked {
10
+ IRegistry internal _registry;
11
+
12
+ constructor(address registry) {
13
+ _registry = IRegistry(registry);
14
+ }
15
+
16
+ function getRegistry() external view override returns (IRegistry registry) {
17
+ return _registry;
18
+ }
19
+ }
20
+
21
+ abstract contract Registerable is RegistryLinked, IRegisterable {
22
+ using NftIdLib for NftId;
23
+
24
+ address private _initialOwner;
25
+
26
+ constructor(address registry) RegistryLinked(registry) {
27
+ _initialOwner = msg.sender;
28
+ }
29
+
30
+ // getType, getData and register need to be implemented by concrete contract
31
+
32
+ function isRegisterable() external pure override returns (bool) {
33
+ return true;
34
+ }
35
+
36
+ function getInitialOwner() public view override returns (address deployer) {
37
+ return _initialOwner;
38
+ }
39
+
40
+ function isRegistered() public view override returns (bool) {
41
+ NftId nftId = _registry.getNftId(address(this));
42
+ return nftId.gtz();
43
+ }
44
+
45
+ function getNftId() public view override returns (NftId nftId) {
46
+ return _registry.getNftId(address(this));
47
+ }
48
+
49
+ function getOwner() public view override returns (address owner) {
50
+ NftId id = _registry.getNftId(address(this));
51
+ owner = _registry.getOwner(id);
52
+ return owner != address(0) ? owner : _initialOwner;
53
+ }
54
+ }
55
+
56
+ contract Registry is IRegistry {
57
+ using NftIdLib for NftId;
58
+ string public constant EMPTY_URI = "";
59
+
60
+ mapping(NftId nftId => RegistryInfo info) private _info;
61
+ mapping(NftId nftId => address owner) private _owner;
62
+ mapping(address object => NftId nftId) private _nftIdByAddress;
63
+
64
+ IChainNft private _chainNft;
65
+
66
+ function initialize(address chainNft) external {
67
+ require(
68
+ address(_chainNft) == address(0),
69
+ "ERROR:REG-001:ALREADY_INITIALIZED"
70
+ );
71
+ _chainNft = IChainNft(chainNft);
72
+ }
73
+
74
+ function TOKEN() public pure override returns (uint256) {
75
+ return 30;
76
+ }
77
+
78
+ function INSTANCE() public pure override returns (uint256) {
79
+ return 40;
80
+ }
81
+
82
+ function PRODUCT() public pure override returns (uint256) {
83
+ return 50;
84
+ }
85
+
86
+ function ORACLE() public pure override returns (uint256) {
87
+ return 60;
88
+ }
89
+
90
+ function POOL() public pure override returns (uint256) {
91
+ return 70;
92
+ }
93
+
94
+ function POLICY() public pure override returns (uint256) {
95
+ return 80;
96
+ }
97
+
98
+ function BUNDLE() public pure override returns (uint256) {
99
+ return 90;
100
+ }
101
+
102
+ function register(
103
+ address objectAddress
104
+ ) external override returns (NftId nftId) {
105
+ require(
106
+ _nftIdByAddress[objectAddress].eqz(),
107
+ "ERROR:REG-002:ALREADY_REGISTERED"
108
+ );
109
+
110
+ IRegisterable registerable = IRegisterable(objectAddress);
111
+ require(
112
+ registerable.isRegisterable(),
113
+ "ERROR:REG-003:NOT_REGISTERABLE"
114
+ );
115
+
116
+ // check parent exists (for objects not instances)
117
+ if (registerable.getType() != INSTANCE()) {
118
+ RegistryInfo memory parentInfo = _info[
119
+ registerable.getParentNftId()
120
+ ];
121
+ require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
122
+ // check validity of parent relation, valid relations are
123
+ // policy -> product, bundle -> pool, product -> instance, pool -> instance
124
+ }
125
+
126
+ uint256 mintedTokenId = _chainNft.mint(
127
+ registerable.getInitialOwner(),
128
+ EMPTY_URI
129
+ );
130
+ nftId = toNftId(mintedTokenId);
131
+
132
+ RegistryInfo memory info = RegistryInfo(
133
+ nftId,
134
+ registerable.getParentNftId(),
135
+ registerable.getType(),
136
+ objectAddress,
137
+ registerable.getInitialOwner()
138
+ );
139
+
140
+ _info[nftId] = info;
141
+ _nftIdByAddress[objectAddress] = nftId;
142
+
143
+ // add logging
144
+ }
145
+
146
+ function registerObjectForInstance(
147
+ NftId parentNftId,
148
+ uint256 objectType,
149
+ address initialOwner
150
+ )
151
+ external
152
+ override
153
+ returns (
154
+ // TODO add onlyRegisteredInstance
155
+ NftId nftId
156
+ )
157
+ {
158
+ // TODO add more validation
159
+ require(
160
+ objectType == POLICY() || objectType == BUNDLE(),
161
+ "ERROR:REG-005:TYPE_INVALID"
162
+ );
163
+
164
+ uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
165
+ nftId = toNftId(mintedTokenId);
166
+
167
+ RegistryInfo memory info = RegistryInfo(
168
+ nftId,
169
+ parentNftId,
170
+ objectType,
171
+ address(0),
172
+ initialOwner
173
+ );
174
+
175
+ _info[nftId] = info;
176
+
177
+ // add logging
178
+ }
179
+
180
+ function getObjectCount() external view override returns (uint256) {
181
+ return _chainNft.totalSupply();
182
+ }
183
+
184
+ function getNftId(
185
+ address object
186
+ ) external view override returns (NftId id) {
187
+ return _nftIdByAddress[object];
188
+ }
189
+
190
+ function isRegistered(
191
+ address object
192
+ ) external view override returns (bool) {
193
+ return _nftIdByAddress[object].gtz();
194
+ }
195
+
196
+ function getInfo(
197
+ NftId nftId
198
+ ) external view override returns (RegistryInfo memory info) {
199
+ return _info[nftId];
200
+ }
201
+
202
+ function getOwner(NftId nftId) external view override returns (address) {
203
+ return _chainNft.ownerOf(nftId.toInt());
204
+ }
205
+
206
+ function getNftAddress() external view override returns (address nft) {
207
+ return address(_chainNft);
208
+ }
209
+ }
@@ -0,0 +1,118 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ type Blocknumber is uint32;
5
+
6
+ using {
7
+ gtBlocknumber as >,
8
+ gteBlocknumber as >=,
9
+ ltBlocknumber as <,
10
+ lteBlocknumber as <=,
11
+ eqBlocknumber as ==,
12
+ neBlocknumber as !=,
13
+ BlocknumberLib.toInt
14
+ } for Blocknumber global;
15
+
16
+ /// @dev return true if Blocknumber a is greater than Blocknumber b
17
+ function gtBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
18
+ return Blocknumber.unwrap(a) > Blocknumber.unwrap(b);
19
+ }
20
+
21
+ /// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
22
+ function gteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
23
+ return Blocknumber.unwrap(a) >= Blocknumber.unwrap(b);
24
+ }
25
+
26
+ /// @dev return true if Blocknumber a is less than Blocknumber b
27
+ function ltBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
28
+ return Blocknumber.unwrap(a) < Blocknumber.unwrap(b);
29
+ }
30
+
31
+ /// @dev return true if Blocknumber a is less than or equal to Blocknumber b
32
+ function lteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
33
+ return Blocknumber.unwrap(a) <= Blocknumber.unwrap(b);
34
+ }
35
+
36
+ /// @dev return true if Blocknumber a is equal to Blocknumber b
37
+ function eqBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
38
+ return Blocknumber.unwrap(a) == Blocknumber.unwrap(b);
39
+ }
40
+
41
+ /// @dev return true if Blocknumber a is not equal to Blocknumber b
42
+ function neBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
43
+ return Blocknumber.unwrap(a) != Blocknumber.unwrap(b);
44
+ }
45
+
46
+ /// @dev Converts the uint256 to a Blocknumber.
47
+ function toBlocknumber(uint256 blocknum) pure returns (Blocknumber) {
48
+ return Blocknumber.wrap(uint32(blocknum));
49
+ }
50
+
51
+ function blockBlocknumber() view returns (Blocknumber) {
52
+ return toBlocknumber(block.number);
53
+ }
54
+
55
+ /// @dev Return the Blocknumber zero (0)
56
+ function zeroBlocknumber() pure returns (Blocknumber) {
57
+ return toBlocknumber(0);
58
+ }
59
+
60
+ /// @dev Return the current block number
61
+ function blockNumber() view returns (Blocknumber) {
62
+ return toBlocknumber(block.number);
63
+ }
64
+
65
+ library BlocknumberLib {
66
+ /// @dev return true if Blocknumber a is greater than Blocknumber b
67
+ function gt(
68
+ Blocknumber a,
69
+ Blocknumber b
70
+ ) public pure returns (bool isAfter) {
71
+ return gtBlocknumber(a, b);
72
+ }
73
+
74
+ /// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
75
+ function gte(
76
+ Blocknumber a,
77
+ Blocknumber b
78
+ ) public pure returns (bool isAfterOrSame) {
79
+ return gteBlocknumber(a, b);
80
+ }
81
+
82
+ /// @dev return true if Blocknumber a is less than Blocknumber b
83
+ function lt(
84
+ Blocknumber a,
85
+ Blocknumber b
86
+ ) public pure returns (bool isBefore) {
87
+ return ltBlocknumber(a, b);
88
+ }
89
+
90
+ /// @dev return true if Blocknumber a is less than or equal to Blocknumber b
91
+ function lte(
92
+ Blocknumber a,
93
+ Blocknumber b
94
+ ) public pure returns (bool isBeforeOrSame) {
95
+ return lteBlocknumber(a, b);
96
+ }
97
+
98
+ /// @dev return true if Blocknumber a is equal to Blocknumber b
99
+ function eq(
100
+ Blocknumber a,
101
+ Blocknumber b
102
+ ) public pure returns (bool isSame) {
103
+ return eqBlocknumber(a, b);
104
+ }
105
+
106
+ /// @dev return true if Blocknumber a is not equal to Blocknumber b
107
+ function ne(
108
+ Blocknumber a,
109
+ Blocknumber b
110
+ ) public pure returns (bool isDifferent) {
111
+ return neBlocknumber(a, b);
112
+ }
113
+
114
+ /// @dev converts the Blocknumber to a uint256
115
+ function toInt(Blocknumber blocknumber) public pure returns (uint256) {
116
+ return uint256(uint32(Blocknumber.unwrap(blocknumber)));
117
+ }
118
+ }
@@ -0,0 +1,38 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ /// @dev bytes5 (uint40) allows for chain ids up to 13 digits
5
+ type ChainId is bytes5;
6
+
7
+ // type bindings
8
+ using {eqChainId as ==, neChainId as !=, ChainIdLib.toInt} for ChainId global;
9
+
10
+ // general pure free functions
11
+ /// @dev Converts the uint256 to a ChainId.
12
+ function toChainId(uint256 chainId) pure returns (ChainId) {
13
+ return ChainId.wrap(bytes5(uint40(chainId)));
14
+ }
15
+
16
+ /// @dev Return the ChainId for the chain the contract is deployed to
17
+ function thisChainId() view returns (ChainId) {
18
+ return toChainId(block.chainid);
19
+ }
20
+
21
+ // pure free functions for operators
22
+ /// @dev Returns true if the values are equal (==).
23
+ function eqChainId(ChainId a, ChainId b) pure returns (bool isSame) {
24
+ return ChainId.unwrap(a) == ChainId.unwrap(b);
25
+ }
26
+
27
+ /// @dev Returns true if the values are not equal (!=).
28
+ function neChainId(ChainId a, ChainId b) pure returns (bool isDifferent) {
29
+ return ChainId.unwrap(a) != ChainId.unwrap(b);
30
+ }
31
+
32
+ // library functions that operate on user defined type
33
+ library ChainIdLib {
34
+ /// @dev Converts the ChainId to a uint256.
35
+ function toInt(ChainId chainId) internal pure returns (uint256) {
36
+ return uint256(uint40(ChainId.unwrap(chainId)));
37
+ }
38
+ }
@@ -0,0 +1,51 @@
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 {eqNftId as ==, neNftId as !=, NftIdLib.toInt} for NftId global;
9
+
10
+ // general pure free functions
11
+ /// @dev Converts the uint256 to a NftId.
12
+ function toNftId(uint256 id) pure returns (NftId) {
13
+ return NftId.wrap(uint96(id));
14
+ }
15
+
16
+ /// @dev Return the NftId zero (0)
17
+ function zeroNftId() pure returns (NftId) {
18
+ return NftId.wrap(0);
19
+ }
20
+
21
+ // pure free functions for operators
22
+ function eqNftId(NftId a, NftId b) pure returns (bool isSame) {
23
+ return NftId.unwrap(a) == NftId.unwrap(b);
24
+ }
25
+
26
+ function neNftId(NftId a, NftId b) pure returns (bool isDifferent) {
27
+ return NftId.unwrap(a) != NftId.unwrap(b);
28
+ }
29
+
30
+ // library functions that operate on user defined type
31
+ library NftIdLib {
32
+ /// @dev Converts the NftId to a uint256.
33
+ function toInt(NftId nftId) public pure returns (uint96) {
34
+ return uint96(NftId.unwrap(nftId));
35
+ }
36
+
37
+ /// @dev Returns true if the value is non-zero (> 0).
38
+ function gtz(NftId a) public pure returns (bool) {
39
+ return NftId.unwrap(a) > 0;
40
+ }
41
+
42
+ /// @dev Returns true if the value is zero (== 0).
43
+ function eqz(NftId a) public pure returns (bool) {
44
+ return NftId.unwrap(a) == 0;
45
+ }
46
+
47
+ /// @dev Returns true if the values are equal (==).
48
+ function eq(NftId a, NftId b) public pure returns (bool isSame) {
49
+ return eqNftId(a, b);
50
+ }
51
+ }