@etherisc/gif-next 0.0.2-e6a90b9 → 0.0.2-eb1b869-461

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. package/README.md +33 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +35 -9
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
  5. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +84 -8
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +34 -152
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +146 -13
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +148 -15
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
  32. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
  34. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
  36. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
  38. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  39. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  40. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  41. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  42. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +714 -127
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +845 -129
  46. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  48. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  49. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  50. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  51. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  52. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +31 -59
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +103 -6
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +34 -8
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +31 -59
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +50 -3
  62. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  63. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  64. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
  65. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
  66. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
  67. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
  68. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
  69. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  70. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  71. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +44 -21
  72. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +44 -21
  74. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  75. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  76. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +23 -43
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  78. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +28 -35
  79. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  80. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +21 -8
  82. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  83. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +85 -14
  85. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
  86. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
  87. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
  88. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
  89. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  90. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
  91. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
  92. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
  93. package/artifacts/contracts/mock/Dip.sol/DIP.dbg.json +4 -0
  94. package/artifacts/contracts/mock/Dip.sol/DIP.json +338 -0
  95. package/artifacts/contracts/mock/TestPool.sol/TestPool.dbg.json +4 -0
  96. package/artifacts/contracts/mock/TestPool.sol/TestPool.json +294 -0
  97. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.dbg.json +4 -0
  98. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.json +384 -0
  99. package/artifacts/contracts/mock/Usdc.sol/USDC.dbg.json +4 -0
  100. package/artifacts/contracts/mock/Usdc.sol/USDC.json +338 -0
  101. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  102. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  103. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  104. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  105. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  106. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +8 -8
  107. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  108. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +20 -111
  109. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  110. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  111. package/artifacts/contracts/registry/Registry.sol/Registerable.json +9 -9
  112. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/Registry.sol/Registry.json +66 -115
  114. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  115. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  116. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
  117. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  118. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  119. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  120. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  121. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +85 -3
  122. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  123. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  124. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  125. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  126. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
  127. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  128. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  129. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +479 -0
  130. package/contracts/components/Component.sol +39 -24
  131. package/contracts/components/IPool.sol +9 -3
  132. package/contracts/components/IProduct.sol +11 -6
  133. package/contracts/components/Pool.sol +37 -14
  134. package/contracts/components/Product.sol +48 -24
  135. package/contracts/experiment/errors/Require.sol +10 -5
  136. package/contracts/experiment/errors/Revert.sol +13 -8
  137. package/contracts/experiment/inheritance/A.sol +8 -11
  138. package/contracts/experiment/inheritance/B.sol +10 -5
  139. package/contracts/experiment/inheritance/C.sol +11 -5
  140. package/contracts/experiment/inheritance/IA.sol +2 -7
  141. package/contracts/experiment/inheritance/IB.sol +3 -2
  142. package/contracts/experiment/inheritance/IC.sol +4 -3
  143. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  144. package/contracts/experiment/statemachine/ISM.sol +25 -0
  145. package/contracts/experiment/statemachine/README.md +112 -0
  146. package/contracts/experiment/statemachine/SM.sol +57 -0
  147. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  148. package/contracts/experiment/types/TypeA.sol +14 -9
  149. package/contracts/experiment/types/TypeB.sol +14 -9
  150. package/contracts/instance/IInstance.sol +8 -3
  151. package/contracts/instance/Instance.sol +24 -15
  152. package/contracts/instance/access/Access.sol +63 -116
  153. package/contracts/instance/access/IAccess.sol +28 -48
  154. package/contracts/instance/component/ComponentModule.sol +163 -135
  155. package/contracts/instance/component/IComponent.sol +41 -61
  156. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  157. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  158. package/contracts/instance/policy/IPolicy.sol +19 -35
  159. package/contracts/instance/policy/PolicyModule.sol +52 -44
  160. package/contracts/instance/pool/IPoolModule.sol +9 -26
  161. package/contracts/instance/pool/PoolModule.sol +43 -45
  162. package/contracts/instance/product/IProductService.sol +10 -19
  163. package/contracts/instance/product/ProductService.sol +86 -55
  164. package/contracts/instance/treasury/ITreasury.sol +91 -0
  165. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  166. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  167. package/contracts/mock/Dip.sol +26 -0
  168. package/contracts/mock/TestPool.sol +16 -0
  169. package/contracts/mock/TestProduct.sol +39 -0
  170. package/contracts/mock/Usdc.sol +26 -0
  171. package/contracts/registry/ChainNft.sol +23 -61
  172. package/contracts/registry/IChainNft.sol +10 -7
  173. package/contracts/registry/IRegistry.sol +40 -41
  174. package/contracts/registry/Registry.sol +73 -67
  175. package/contracts/types/Blocknumber.sol +118 -0
  176. package/contracts/types/ChainId.sol +24 -10
  177. package/contracts/types/Fee.sol +32 -0
  178. package/contracts/types/NftId.sol +36 -10
  179. package/contracts/types/ObjectType.sol +107 -0
  180. package/contracts/types/StateId.sol +91 -0
  181. package/contracts/types/Timestamp.sol +102 -0
  182. package/contracts/types/UFixed.sol +210 -0
  183. package/package.json +14 -5
@@ -4,10 +4,7 @@ pragma solidity ^0.8.19;
4
4
  import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
5
5
  import {IChainNft} from "./IChainNft.sol";
6
6
 
7
- contract ChainNft is
8
- ERC721Enumerable,
9
- IChainNft
10
- {
7
+ contract ChainNft is ERC721Enumerable, IChainNft {
11
8
  string public constant NAME = "Dezentralized Insurance Protocol Registry";
12
9
  string public constant SYMBOL = "DIPR";
13
10
 
@@ -18,22 +15,18 @@ contract ChainNft is
18
15
  address private _registry;
19
16
 
20
17
  // only used for _getNextTokenId
21
- uint256 internal _chainIdInt;
18
+ uint256 internal _chainIdInt;
22
19
  uint256 internal _chainIdDigits;
23
20
  uint256 internal _chainIdMultiplier;
24
21
  uint256 internal _idNext;
25
22
  uint256 internal _totalMinted;
26
23
 
27
-
28
24
  modifier onlyRegistry() {
29
25
  require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
30
26
  _;
31
27
  }
32
28
 
33
-
34
- constructor(address registry)
35
- ERC721(NAME, SYMBOL)
36
- {
29
+ constructor(address registry) ERC721(NAME, SYMBOL) {
37
30
  require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
38
31
 
39
32
  _registry = registry;
@@ -43,88 +36,59 @@ contract ChainNft is
43
36
  _chainIdMultiplier = 10 ** _chainIdDigits;
44
37
 
45
38
  // on mainnet/goerli start /1 (reserved for protocol nft) on other chains with 2
46
- if(block.chainid == 1 || block.chainid == 5) {
39
+ if (block.chainid == 1 || block.chainid == 5) {
47
40
  _idNext = 1;
48
41
  } else {
49
42
  _idNext = 2;
50
43
  }
51
44
  }
52
45
 
53
-
54
46
  function mint(
55
47
  address to,
56
48
  string memory uri
57
- )
58
- external
59
- override
60
- onlyRegistry
61
- returns(uint256 tokenId)
62
- {
49
+ ) external override onlyRegistry returns (uint256 tokenId) {
63
50
  tokenId = _getNextTokenId();
64
51
  _totalMinted++;
65
52
 
66
53
  _safeMint(to, tokenId);
67
54
 
68
- if(bytes(uri).length > 0) {
55
+ if (bytes(uri).length > 0) {
69
56
  _uri[tokenId] = uri;
70
57
  }
71
58
  }
72
59
 
73
-
74
- function burn(uint256 tokenId)
75
- external
76
- override
77
- onlyRegistry
78
- {
60
+ function burn(uint256 tokenId) external override onlyRegistry {
79
61
  _requireMinted(tokenId);
80
62
  _burn(tokenId);
81
63
  delete _uri[tokenId];
82
64
  }
83
65
 
84
-
85
- function setURI(uint256 tokenId, string memory uri)
86
- external
87
- override
88
- onlyRegistry
89
- {
66
+ function setURI(
67
+ uint256 tokenId,
68
+ string memory uri
69
+ ) external override onlyRegistry {
90
70
  require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
91
71
 
92
72
  _requireMinted(tokenId);
93
73
  _uri[tokenId] = uri;
94
74
  }
95
75
 
96
-
97
- function exists(uint256 tokenId)
98
- external
99
- view
100
- override
101
- returns(bool)
102
- {
76
+ function exists(uint256 tokenId) external view override returns (bool) {
103
77
  return _exists(tokenId);
104
78
  }
105
79
 
106
-
107
- function tokenURI(uint256 tokenId)
108
- public
109
- view
110
- override
111
- returns(string memory)
112
- {
80
+ function tokenURI(
81
+ uint256 tokenId
82
+ ) public view override returns (string memory) {
113
83
  _requireMinted(tokenId);
114
84
  return _uri[tokenId];
115
85
  }
116
86
 
117
-
118
- function getRegistryAddress()
119
- external
120
- view
121
- override
122
- returns(address)
123
- {
87
+ function getRegistryAddress() external view override returns (address) {
124
88
  return _registry;
125
89
  }
126
90
 
127
- function totalMinted() external override view returns(uint256) {
91
+ function totalMinted() external view override returns (uint256) {
128
92
  return _totalMinted;
129
93
  }
130
94
 
@@ -153,17 +117,15 @@ contract ChainNft is
153
117
  // (42 * 10 ** 10 + 9876543210) * 100 + 10
154
118
  // (index * 10 ** digits + chainid) * 100 + digits (1 < digits < 100)
155
119
 
156
- function _getNextTokenId() private returns(uint256 id) {
157
- id = (_idNext * _chainIdMultiplier + _chainIdInt) * 100 + _chainIdDigits;
120
+ function _getNextTokenId() private returns (uint256 id) {
121
+ id =
122
+ (_idNext * _chainIdMultiplier + _chainIdInt) *
123
+ 100 +
124
+ _chainIdDigits;
158
125
  _idNext++;
159
126
  }
160
127
 
161
-
162
- function _countDigits(uint256 num)
163
- private
164
- pure
165
- returns (uint256 count)
166
- {
128
+ function _countDigits(uint256 num) private pure returns (uint256 count) {
167
129
  count = 0;
168
130
  while (num != 0) {
169
131
  count++;
@@ -3,16 +3,19 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
5
5
 
6
- interface IChainNft is
7
- IERC721Enumerable
8
- {
6
+ interface IChainNft is IERC721Enumerable {
7
+ function mint(
8
+ address to,
9
+ string memory uri
10
+ ) external returns (uint256 tokenId);
9
11
 
10
- function mint(address to, string memory uri) external returns(uint256 tokenId);
11
12
  function burn(uint256 tokenId) external;
13
+
12
14
  function setURI(uint256 tokenId, string memory uri) external;
13
15
 
14
- function exists(uint256 tokenId) external view returns(bool);
15
- function totalMinted() external view returns(uint256);
16
+ function exists(uint256 tokenId) external view returns (bool);
17
+
18
+ function totalMinted() external view returns (uint256);
16
19
 
17
- function getRegistryAddress() external view returns(address registry);
20
+ function getRegistryAddress() external view returns (address registry);
18
21
  }
@@ -1,68 +1,67 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {NftId} from "../types/NftId.sol";
5
+ import {ObjectType} from "../types/ObjectType.sol";
6
+
4
7
  interface IOwnable {
5
- function getOwner() external view returns(address owner);
8
+ function getOwner() external view returns (address owner);
6
9
  }
7
10
 
8
11
  interface IRegistryLinked {
9
-
10
12
  event LogDebug(uint256 idx, address module, string comment);
11
13
 
12
- function getRegistry() external view returns(IRegistry registry);
14
+ function getRegistry() external view returns (IRegistry registry);
13
15
  }
14
16
 
15
- interface IRegisterable is
16
- IOwnable,
17
- IRegistryLinked
18
- {
19
-
20
- function register() external returns(uint256 nftId);
21
-
22
- function getNftId() external view returns(uint256 nftId);
23
- function getParentNftId() external view returns(uint256 parentNftId);
24
- function getType() external view returns(uint256 objectType);
25
- function getData() external view returns(bytes memory data);
26
- function isRegisterable() external pure returns(bool);
27
- function getInitialOwner() external view returns(address initialOwner);
28
-
29
- function isRegistered() external view returns(bool);
30
- }
17
+ interface IRegisterable is IOwnable, IRegistryLinked {
18
+ function register() external returns (NftId nftId);
31
19
 
20
+ function getNftId() external view returns (NftId nftId);
32
21
 
33
- interface IRegistry {
22
+ function getParentNftId() external view returns (NftId parentNftId);
23
+
24
+ function getType() external view returns (ObjectType objectType);
25
+
26
+ function getData() external view returns (bytes memory data);
27
+
28
+ function isRegisterable() external pure returns (bool);
34
29
 
30
+ function getInitialOwner() external view returns (address initialOwner);
31
+
32
+ function isRegistered() external view returns (bool);
33
+ }
34
+
35
+ interface IRegistry {
35
36
  struct RegistryInfo {
36
- uint256 nftId;
37
- uint256 parentNftId;
38
- uint256 objectType;
37
+ NftId nftId;
38
+ NftId parentNftId;
39
+ ObjectType objectType;
39
40
  address objectAddress;
40
41
  address initialOwner;
41
42
  }
42
43
 
43
- function TOKEN() external pure returns(uint256);
44
- function INSTANCE() external pure returns(uint256);
45
- function PRODUCT() external pure returns(uint256);
46
- function ORACLE() external pure returns(uint256);
47
- function POOL() external pure returns(uint256);
48
- function POLICY() external pure returns(uint256);
49
- function BUNDLE() external pure returns(uint256);
44
+ function register(address objectAddress) external returns (NftId nftId);
50
45
 
51
- function register(address objectAddress) external returns(uint256 nftId);
52
46
  function registerObjectForInstance(
53
- uint256 parentNftid,
54
- uint256 objectType,
47
+ NftId parentNftid,
48
+ ObjectType objectType,
55
49
  address initialOwner
56
- )
57
- external returns(uint256 nftId);
50
+ ) external returns (NftId nftId);
51
+
52
+ function getObjectCount() external view returns (uint256);
53
+
54
+ function getNftId(
55
+ address objectAddress
56
+ ) external view returns (NftId nftId);
58
57
 
59
- function getObjectCount() external view returns(uint256);
58
+ function getInfo(
59
+ NftId nftId
60
+ ) external view returns (RegistryInfo memory info);
60
61
 
61
- function getNftId(address objectAddress) external view returns(uint256 nftId);
62
- function getInfo(uint256 nftId) external view returns(RegistryInfo memory info);
63
- function getOwner(uint256 nftId) external view returns(address ownerAddress);
62
+ function getOwner(NftId nftId) external view returns (address ownerAddress);
64
63
 
65
- function isRegistered(address objectAddress) external view returns(bool);
64
+ function isRegistered(address objectAddress) external view returns (bool);
66
65
 
67
- function getNftAddress() external view returns(address nft);
66
+ function getNftAddress() external view returns (address nft);
68
67
  }
@@ -3,102 +3,105 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {IChainNft} from "./IChainNft.sol";
5
5
  import {IRegistry, IRegistryLinked, IRegisterable} from "./IRegistry.sol";
6
+ import {NftId, toNftId, NftIdLib} from "../types/NftId.sol";
7
+ import {ObjectType, INSTANCE, POLICY, BUNDLE} from "../types/ObjectType.sol";
6
8
 
7
9
  contract RegistryLinked is IRegistryLinked {
8
-
9
10
  IRegistry internal _registry;
10
-
11
+
11
12
  constructor(address registry) {
12
13
  _registry = IRegistry(registry);
13
14
  }
14
15
 
15
- function getRegistry() external view override returns(IRegistry registry) {
16
+ function getRegistry() external view override returns (IRegistry registry) {
16
17
  return _registry;
17
18
  }
18
-
19
19
  }
20
20
 
21
-
22
- abstract contract Registerable is
23
- RegistryLinked,
24
- IRegisterable
25
- {
21
+ abstract contract Registerable is RegistryLinked, IRegisterable {
22
+ using NftIdLib for NftId;
26
23
 
27
24
  address private _initialOwner;
28
-
29
- constructor(address registry)
30
- RegistryLinked(registry)
31
- {
25
+
26
+ constructor(address registry) RegistryLinked(registry) {
32
27
  _initialOwner = msg.sender;
33
28
  }
34
29
 
35
30
  // getType, getData and register need to be implemented by concrete contract
36
31
 
37
- function isRegisterable() external pure override returns(bool) {
32
+ function isRegisterable() external pure override returns (bool) {
38
33
  return true;
39
34
  }
40
35
 
41
- function getInitialOwner() public view override returns(address deployer) {
36
+ function getInitialOwner() public view override returns (address deployer) {
42
37
  return _initialOwner;
43
38
  }
44
39
 
45
- function isRegistered() public view override returns(bool) {
46
- return _registry.getNftId(address(this)) > 0;
40
+ function isRegistered() public view override returns (bool) {
41
+ NftId nftId = _registry.getNftId(address(this));
42
+ return nftId.gtz();
47
43
  }
48
44
 
49
- function getNftId() public view override returns(uint256 id) {
45
+ function getNftId() public view override returns (NftId nftId) {
50
46
  return _registry.getNftId(address(this));
51
47
  }
52
48
 
53
- function getOwner() public view override returns(address owner) {
54
- uint256 id = _registry.getNftId(address(this));
49
+ function getOwner() public view override returns (address owner) {
50
+ NftId id = _registry.getNftId(address(this));
55
51
  owner = _registry.getOwner(id);
56
52
  return owner != address(0) ? owner : _initialOwner;
57
53
  }
58
-
59
54
  }
60
55
 
61
56
  contract Registry is IRegistry {
57
+ using NftIdLib for NftId;
62
58
 
63
59
  string public constant EMPTY_URI = "";
64
60
 
65
- mapping(uint256 id => RegistryInfo info) private _info;
66
- mapping(uint256 id => address owner) private _owner;
67
- mapping(address object => uint256 id) private _idByAddress;
61
+ mapping(NftId nftId => RegistryInfo info) private _info;
62
+ mapping(NftId nftId => address owner) private _owner;
63
+ mapping(address object => NftId nftId) private _nftIdByAddress;
68
64
 
69
65
  IChainNft private _chainNft;
70
66
 
71
67
  function initialize(address chainNft) external {
72
- require(address(_chainNft) == address(0), "ERROR:REG-001:ALREADY_INITIALIZED");
68
+ require(
69
+ address(_chainNft) == address(0),
70
+ "ERROR:REG-001:ALREADY_INITIALIZED"
71
+ );
73
72
  _chainNft = IChainNft(chainNft);
74
73
  }
75
74
 
76
- function TOKEN() public pure override returns(uint256) { return 30; }
77
- function INSTANCE() public pure override returns(uint256) { return 40; }
78
- function PRODUCT() public pure override returns(uint256) { return 50; }
79
- function ORACLE() public pure override returns(uint256) { return 60; }
80
- function POOL() public pure override returns(uint256) { return 70; }
81
- function POLICY() public pure override returns(uint256) { return 80; }
82
- function BUNDLE() public pure override returns(uint256) { return 90; }
83
-
84
- function register(address objectAddress) external override returns(uint256 nftId) {
85
- require(_idByAddress[objectAddress] == 0, "ERROR:REG-002:ALREADY_REGISTERED");
75
+ function register(
76
+ address objectAddress
77
+ ) external override returns (NftId nftId) {
78
+ require(
79
+ _nftIdByAddress[objectAddress].eqz(),
80
+ "ERROR:REG-002:ALREADY_REGISTERED"
81
+ );
86
82
 
87
83
  IRegisterable registerable = IRegisterable(objectAddress);
88
- require(registerable.isRegisterable(), "ERROR:REG-003:NOT_REGISTERABLE");
84
+ require(
85
+ registerable.isRegisterable(),
86
+ "ERROR:REG-003:NOT_REGISTERABLE"
87
+ );
89
88
 
90
89
  // check parent exists (for objects not instances)
91
- if(registerable.getType() != INSTANCE()) {
92
- RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
93
- require(parentInfo.nftId > 0, "ERROR:REG-004:PARENT_NOT_FOUND");
90
+ if (registerable.getType() != INSTANCE()) {
91
+ RegistryInfo memory parentInfo = _info[
92
+ registerable.getParentNftId()
93
+ ];
94
+ require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
94
95
  // check validity of parent relation, valid relations are
95
96
  // policy -> product, bundle -> pool, product -> instance, pool -> instance
96
97
  }
97
98
 
98
- nftId = _chainNft.mint(
99
- registerable.getInitialOwner(),
100
- EMPTY_URI);
101
-
99
+ uint256 mintedTokenId = _chainNft.mint(
100
+ registerable.getInitialOwner(),
101
+ EMPTY_URI
102
+ );
103
+ nftId = toNftId(mintedTokenId);
104
+
102
105
  RegistryInfo memory info = RegistryInfo(
103
106
  nftId,
104
107
  registerable.getParentNftId(),
@@ -108,30 +111,31 @@ contract Registry is IRegistry {
108
111
  );
109
112
 
110
113
  _info[nftId] = info;
111
- _idByAddress[objectAddress] = nftId;
114
+ _nftIdByAddress[objectAddress] = nftId;
112
115
 
113
116
  // add logging
114
117
  }
115
118
 
116
-
117
119
  function registerObjectForInstance(
118
- uint256 parentNftId,
119
- uint256 objectType,
120
+ NftId parentNftId,
121
+ ObjectType objectType,
120
122
  address initialOwner
121
123
  )
122
- external
124
+ external
123
125
  override
124
- // TODO add onlyRegisteredInstance
125
- returns(uint256 nftId)
126
+ returns (
127
+ // TODO add onlyRegisteredInstance
128
+ NftId nftId
129
+ )
126
130
  {
127
131
  // TODO add more validation
128
132
  require(
129
133
  objectType == POLICY() || objectType == BUNDLE(),
130
- "ERROR:REG-005:TYPE_INVALID");
134
+ "ERROR:REG-005:TYPE_INVALID"
135
+ );
131
136
 
132
- nftId = _chainNft.mint(
133
- initialOwner,
134
- EMPTY_URI);
137
+ uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
138
+ nftId = toNftId(mintedTokenId);
135
139
 
136
140
  RegistryInfo memory info = RegistryInfo(
137
141
  nftId,
@@ -146,31 +150,33 @@ contract Registry is IRegistry {
146
150
  // add logging
147
151
  }
148
152
 
149
-
150
- function getObjectCount() external view override returns(uint256) {
153
+ function getObjectCount() external view override returns (uint256) {
151
154
  return _chainNft.totalSupply();
152
155
  }
153
156
 
154
-
155
- function getNftId(address object) external view override returns(uint256 id) {
156
- return _idByAddress[object];
157
+ function getNftId(
158
+ address object
159
+ ) external view override returns (NftId id) {
160
+ return _nftIdByAddress[object];
157
161
  }
158
162
 
159
-
160
- function isRegistered(address object) external view override returns(bool) {
161
- return _idByAddress[object] > 0;
163
+ function isRegistered(
164
+ address object
165
+ ) external view override returns (bool) {
166
+ return _nftIdByAddress[object].gtz();
162
167
  }
163
168
 
164
-
165
- function getInfo(uint256 nftId) external view override returns(RegistryInfo memory info) {
169
+ function getInfo(
170
+ NftId nftId
171
+ ) external view override returns (RegistryInfo memory info) {
166
172
  return _info[nftId];
167
173
  }
168
174
 
169
- function getOwner(uint256 nftId) external view override returns(address) {
170
- return _chainNft.ownerOf(nftId);
175
+ function getOwner(NftId nftId) external view override returns (address) {
176
+ return _chainNft.ownerOf(nftId.toInt());
171
177
  }
172
178
 
173
- function getNftAddress() external view override returns(address nft) {
179
+ function getNftAddress() external view override returns (address nft) {
174
180
  return address(_chainNft);
175
181
  }
176
182
  }
@@ -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
+ }