@etherisc/gif-next 0.0.2-ac5f18b → 0.0.2-aeb86f4

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 +70 -0
  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 +62 -0
  115. package/contracts/components/IPool.sol +9 -0
  116. package/contracts/components/IProduct.sol +12 -0
  117. package/contracts/components/Pool.sol +29 -0
  118. package/contracts/components/Product.sol +66 -0
  119. package/contracts/experiment/errors/Require.sol +33 -0
  120. package/contracts/experiment/errors/Revert.sol +39 -0
  121. package/contracts/experiment/inheritance/A.sol +56 -0
  122. package/contracts/experiment/inheritance/B.sol +23 -0
  123. package/contracts/experiment/inheritance/C.sol +28 -0
  124. package/contracts/experiment/inheritance/IA.sol +18 -0
  125. package/contracts/experiment/inheritance/IB.sol +9 -0
  126. package/contracts/experiment/inheritance/IC.sol +11 -0
  127. package/contracts/experiment/types/TypeA.sol +42 -0
  128. package/contracts/experiment/types/TypeB.sol +24 -0
  129. package/contracts/instance/IInstance.sol +20 -0
  130. package/contracts/instance/Instance.sol +64 -0
  131. package/contracts/instance/access/Access.sol +218 -0
  132. package/contracts/instance/access/IAccess.sol +83 -0
  133. package/contracts/instance/component/ComponentModule.sol +248 -0
  134. package/contracts/instance/component/IComponent.sol +95 -0
  135. package/contracts/instance/policy/IPolicy.sol +66 -0
  136. package/contracts/instance/policy/PolicyModule.sol +107 -0
  137. package/contracts/instance/pool/IPoolModule.sol +41 -0
  138. package/contracts/instance/pool/PoolModule.sol +86 -0
  139. package/contracts/instance/product/IProductService.sol +46 -0
  140. package/contracts/instance/product/ProductService.sol +108 -0
  141. package/contracts/registry/ChainNft.sol +173 -0
  142. package/contracts/registry/IChainNft.sol +18 -0
  143. package/contracts/registry/IRegistry.sol +70 -0
  144. package/contracts/registry/Registry.sol +182 -0
  145. package/contracts/types/Blocknumber.sol +60 -0
  146. package/contracts/types/ChainId.sol +30 -0
  147. package/contracts/types/NftId.sol +35 -0
  148. package/contracts/types/Timestamp.sol +55 -0
  149. package/contracts/types/UFixed.sol +211 -0
  150. package/package.json +6 -6
  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,108 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ // import {IProduct} from "../../components/IProduct.sol";
6
+ // import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
7
+ // import {IInstance} from "../IInstance.sol";
8
+ import {IRegistry} from "../../registry/IRegistry.sol";
9
+ import {IPolicyModule} from "../policy/IPolicy.sol";
10
+ import {RegistryLinked} from "../../registry/Registry.sol";
11
+ import {IProductService, IProductModule} from "./IProductService.sol";
12
+ import {IComponentModule} from "../../instance/component/IComponent.sol";
13
+ import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
14
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
15
+
16
+ // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
17
+ contract ProductService is
18
+ RegistryLinked,
19
+ IProductService
20
+ {
21
+ using NftIdLib for NftId;
22
+
23
+ constructor(address registry)
24
+ RegistryLinked(registry)
25
+ { }
26
+
27
+
28
+ function createApplication(
29
+ address applicationOwner,
30
+ uint256 sumInsuredAmount,
31
+ uint256 premiumAmount,
32
+ uint256 lifetime,
33
+ NftId bundleNftId
34
+ )
35
+ external
36
+ override
37
+ returns(NftId nftId)
38
+ {
39
+ // same as only registered product
40
+ NftId productNftId = _registry.getNftId(msg.sender);
41
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
42
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
43
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
44
+
45
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
46
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
47
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
48
+
49
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
50
+ nftId = policyModule.createApplication(
51
+ productInfo,
52
+ applicationOwner,
53
+ sumInsuredAmount,
54
+ premiumAmount,
55
+ lifetime,
56
+ bundleNftId);
57
+
58
+ // add logging
59
+ }
60
+
61
+ function underwrite(NftId nftId)
62
+ external
63
+ override
64
+ {
65
+ // same as only registered product
66
+ NftId productNftId = _registry.getNftId(msg.sender);
67
+ require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
68
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
69
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
70
+
71
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
72
+ require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
73
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
74
+
75
+ // get responsible pool
76
+ IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
77
+ NftId poolNftId = componentModule.getPoolNftId(productNftId);
78
+
79
+ // lock capital (and update pool accounting)
80
+ IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
81
+ poolModule.underwrite(
82
+ poolNftId,
83
+ nftId);
84
+
85
+ // activate policy
86
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
87
+ policyModule.activate(nftId);
88
+
89
+ // add logging
90
+ }
91
+
92
+ function close(NftId nftId) external override {}
93
+ }
94
+
95
+ abstract contract ProductModule is
96
+ IProductModule
97
+ {
98
+ IProductService private _productService;
99
+
100
+ constructor(address productService) {
101
+ _productService = IProductService(productService);
102
+ }
103
+
104
+ function getProductService() external view returns(IProductService) {
105
+ return _productService;
106
+ }
107
+
108
+ }
@@ -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
+ }
@@ -0,0 +1,70 @@
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
+
12
+ event LogDebug(uint256 idx, address module, string comment);
13
+
14
+ function getRegistry() external view returns(IRegistry registry);
15
+ }
16
+
17
+ interface IRegisterable is
18
+ IOwnable,
19
+ IRegistryLinked
20
+ {
21
+
22
+ function register() external returns(NftId nftId);
23
+
24
+ function getNftId() external view returns(NftId nftId);
25
+ function getParentNftId() external view returns(NftId parentNftId);
26
+ function getType() external view returns(uint256 objectType);
27
+ function getData() external view returns(bytes memory data);
28
+ function isRegisterable() external pure returns(bool);
29
+ function getInitialOwner() external view returns(address initialOwner);
30
+
31
+ function isRegistered() external view returns(bool);
32
+ }
33
+
34
+
35
+ interface IRegistry {
36
+
37
+ struct RegistryInfo {
38
+ NftId nftId;
39
+ NftId parentNftId;
40
+ uint256 objectType;
41
+ address objectAddress;
42
+ address initialOwner;
43
+ }
44
+
45
+ function TOKEN() external pure returns(uint256);
46
+ function INSTANCE() external pure returns(uint256);
47
+ function PRODUCT() external pure returns(uint256);
48
+ function ORACLE() external pure returns(uint256);
49
+ function POOL() external pure returns(uint256);
50
+ function POLICY() external pure returns(uint256);
51
+ function BUNDLE() external pure returns(uint256);
52
+
53
+ function register(address objectAddress) external returns(NftId nftId);
54
+ function registerObjectForInstance(
55
+ NftId parentNftid,
56
+ uint256 objectType,
57
+ address initialOwner
58
+ )
59
+ external returns(NftId nftId);
60
+
61
+ function getObjectCount() external view returns(uint256);
62
+
63
+ function getNftId(address objectAddress) external view returns(NftId nftId);
64
+ function getInfo(NftId nftId) external view returns(RegistryInfo memory info);
65
+ function getOwner(NftId nftId) external view returns(address ownerAddress);
66
+
67
+ function isRegistered(address objectAddress) external view returns(bool);
68
+
69
+ function getNftAddress() external view returns(address nft);
70
+ }
@@ -0,0 +1,182 @@
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
+
11
+ IRegistry internal _registry;
12
+
13
+ constructor(address registry) {
14
+ _registry = IRegistry(registry);
15
+ }
16
+
17
+ function getRegistry() external view override returns(IRegistry registry) {
18
+ return _registry;
19
+ }
20
+
21
+ }
22
+
23
+
24
+ abstract contract Registerable is
25
+ RegistryLinked,
26
+ IRegisterable
27
+ {
28
+ using NftIdLib for NftId;
29
+
30
+ address private _initialOwner;
31
+
32
+ constructor(address registry)
33
+ RegistryLinked(registry)
34
+ {
35
+ _initialOwner = msg.sender;
36
+ }
37
+
38
+ // getType, getData and register need to be implemented by concrete contract
39
+
40
+ function isRegisterable() external pure override returns(bool) {
41
+ return true;
42
+ }
43
+
44
+ function getInitialOwner() public view override returns(address deployer) {
45
+ return _initialOwner;
46
+ }
47
+
48
+ function isRegistered() public view override returns(bool) {
49
+ NftId nftId = _registry.getNftId(address(this));
50
+ return nftId.gtz();
51
+ }
52
+
53
+ function getNftId() public view override returns(NftId nftId) {
54
+ return _registry.getNftId(address(this));
55
+ }
56
+
57
+ function getOwner() public view override returns(address owner) {
58
+ NftId id = _registry.getNftId(address(this));
59
+ owner = _registry.getOwner(id);
60
+ return owner != address(0) ? owner : _initialOwner;
61
+ }
62
+
63
+ }
64
+
65
+ contract Registry is IRegistry {
66
+ using NftIdLib for NftId;
67
+ string public constant EMPTY_URI = "";
68
+
69
+ mapping(NftId nftId => RegistryInfo info) private _info;
70
+ mapping(NftId nftId => address owner) private _owner;
71
+ mapping(address object => NftId nftId) private _nftIdByAddress;
72
+
73
+ IChainNft private _chainNft;
74
+
75
+ function initialize(address chainNft) external {
76
+ require(address(_chainNft) == address(0), "ERROR:REG-001:ALREADY_INITIALIZED");
77
+ _chainNft = IChainNft(chainNft);
78
+ }
79
+
80
+ function TOKEN() public pure override returns(uint256) { return 30; }
81
+ function INSTANCE() public pure override returns(uint256) { return 40; }
82
+ function PRODUCT() public pure override returns(uint256) { return 50; }
83
+ function ORACLE() public pure override returns(uint256) { return 60; }
84
+ function POOL() public pure override returns(uint256) { return 70; }
85
+ function POLICY() public pure override returns(uint256) { return 80; }
86
+ function BUNDLE() public pure override returns(uint256) { return 90; }
87
+
88
+ function register(address objectAddress) external override returns(NftId nftId) {
89
+ require(_nftIdByAddress[objectAddress].eqz(), "ERROR:REG-002:ALREADY_REGISTERED");
90
+
91
+ IRegisterable registerable = IRegisterable(objectAddress);
92
+ require(registerable.isRegisterable(), "ERROR:REG-003:NOT_REGISTERABLE");
93
+
94
+ // check parent exists (for objects not instances)
95
+ if(registerable.getType() != INSTANCE()) {
96
+ RegistryInfo memory parentInfo = _info[registerable.getParentNftId()];
97
+ require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
98
+ // check validity of parent relation, valid relations are
99
+ // policy -> product, bundle -> pool, product -> instance, pool -> instance
100
+ }
101
+
102
+ uint256 mintedTokenId = _chainNft.mint(
103
+ registerable.getInitialOwner(),
104
+ EMPTY_URI);
105
+ nftId = toNftId(mintedTokenId);
106
+
107
+ RegistryInfo memory info = RegistryInfo(
108
+ nftId,
109
+ registerable.getParentNftId(),
110
+ registerable.getType(),
111
+ objectAddress,
112
+ registerable.getInitialOwner()
113
+ );
114
+
115
+ _info[nftId] = info;
116
+ _nftIdByAddress[objectAddress] = nftId;
117
+
118
+ // add logging
119
+ }
120
+
121
+
122
+ function registerObjectForInstance(
123
+ NftId parentNftId,
124
+ uint256 objectType,
125
+ address initialOwner
126
+ )
127
+ external
128
+ override
129
+ // TODO add onlyRegisteredInstance
130
+ returns(NftId nftId)
131
+ {
132
+ // TODO add more validation
133
+ require(
134
+ objectType == POLICY() || objectType == BUNDLE(),
135
+ "ERROR:REG-005:TYPE_INVALID");
136
+
137
+ uint256 mintedTokenId = _chainNft.mint(
138
+ initialOwner,
139
+ EMPTY_URI);
140
+ nftId = toNftId(mintedTokenId);
141
+
142
+ RegistryInfo memory info = RegistryInfo(
143
+ nftId,
144
+ parentNftId,
145
+ objectType,
146
+ address(0),
147
+ initialOwner
148
+ );
149
+
150
+ _info[nftId] = info;
151
+
152
+ // add logging
153
+ }
154
+
155
+
156
+ function getObjectCount() external view override returns(uint256) {
157
+ return _chainNft.totalSupply();
158
+ }
159
+
160
+
161
+ function getNftId(address object) external view override returns(NftId id) {
162
+ return _nftIdByAddress[object];
163
+ }
164
+
165
+
166
+ function isRegistered(address object) external view override returns(bool) {
167
+ return _nftIdByAddress[object].gtz();
168
+ }
169
+
170
+
171
+ function getInfo(NftId nftId) external view override returns(RegistryInfo memory info) {
172
+ return _info[nftId];
173
+ }
174
+
175
+ function getOwner(NftId nftId) external view override returns(address) {
176
+ return _chainNft.ownerOf(nftId.toInt());
177
+ }
178
+
179
+ function getNftAddress() external view override returns(address nft) {
180
+ return address(_chainNft);
181
+ }
182
+ }
@@ -0,0 +1,60 @@
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) { return Blocknumber.unwrap(a) > Blocknumber.unwrap(b); }
18
+ /// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
19
+ function gteBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) >= Blocknumber.unwrap(b); }
20
+
21
+ /// @dev return true if Blocknumber a is less than Blocknumber b
22
+ function ltBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) < Blocknumber.unwrap(b); }
23
+ /// @dev return true if Blocknumber a is less than or equal to Blocknumber b
24
+ function lteBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) <= Blocknumber.unwrap(b); }
25
+
26
+ /// @dev return true if Blocknumber a is equal to Blocknumber b
27
+ function eqBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) == Blocknumber.unwrap(b); }
28
+ /// @dev return true if Blocknumber a is not equal to Blocknumber b
29
+ function neBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) { return Blocknumber.unwrap(a) != Blocknumber.unwrap(b); }
30
+
31
+ /// @dev Converts the uint256 to a Blocknumber.
32
+ function toBlocknumber(uint256 blocknum) pure returns(Blocknumber) { return Blocknumber.wrap(uint32(blocknum)); }
33
+
34
+ function blockBlocknumber() view returns(Blocknumber) { return toBlocknumber(block.number); }
35
+
36
+ /// @dev Return the Blocknumber zero (0)
37
+ function zeroBlocknumber() pure returns(Blocknumber) { return toBlocknumber(0); }
38
+
39
+ /// @dev Return the current block number
40
+ function blockNumber() view returns(Blocknumber) { return toBlocknumber(block.number); }
41
+
42
+ library BlocknumberLib {
43
+ /// @dev return true if Blocknumber a is greater than Blocknumber b
44
+ function gt(Blocknumber a, Blocknumber b) public pure returns(bool isAfter) { return gtBlocknumber(a, b); }
45
+ /// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
46
+ function gte(Blocknumber a, Blocknumber b) public pure returns(bool isAfterOrSame) { return gteBlocknumber(a, b); }
47
+
48
+ /// @dev return true if Blocknumber a is less than Blocknumber b
49
+ function lt(Blocknumber a, Blocknumber b) public pure returns(bool isBefore) { return ltBlocknumber(a, b); }
50
+ /// @dev return true if Blocknumber a is less than or equal to Blocknumber b
51
+ function lte(Blocknumber a, Blocknumber b) public pure returns(bool isBeforeOrSame) { return lteBlocknumber(a, b); }
52
+
53
+ /// @dev return true if Blocknumber a is equal to Blocknumber b
54
+ function eq(Blocknumber a, Blocknumber b) public pure returns(bool isSame) { return eqBlocknumber(a, b); }
55
+ /// @dev return true if Blocknumber a is not equal to Blocknumber b
56
+ function ne(Blocknumber a, Blocknumber b) public pure returns(bool isDifferent) { return neBlocknumber(a, b); }
57
+
58
+ /// @dev converts the Blocknumber to a uint256
59
+ function toInt(Blocknumber blocknumber) public pure returns(uint256) { return uint256(uint32(Blocknumber.unwrap(blocknumber))); }
60
+ }
@@ -0,0 +1,30 @@
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 {
9
+ eqChainId as ==,
10
+ neChainId as !=,
11
+ ChainIdLib.toInt
12
+ } for ChainId global;
13
+
14
+ // general pure free functions
15
+ /// @dev Converts the uint256 to a ChainId.
16
+ function toChainId(uint256 chainId) pure returns(ChainId) { return ChainId.wrap(bytes5(uint40(chainId))); }
17
+ /// @dev Return the ChainId for the chain the contract is deployed to
18
+ function thisChainId() view returns(ChainId) { return toChainId(block.chainid); }
19
+
20
+ // pure free functions for operators
21
+ /// @dev Returns true if the values are equal (==).
22
+ function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) { return ChainId.unwrap(a) == ChainId.unwrap(b); }
23
+ /// @dev Returns true if the values are not equal (!=).
24
+ function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) { return ChainId.unwrap(a) != ChainId.unwrap(b); }
25
+
26
+ // library functions that operate on user defined type
27
+ library ChainIdLib {
28
+ /// @dev Converts the ChainId to a uint256.
29
+ function toInt(ChainId chainId) internal pure returns(uint256) { return uint256(uint40(ChainId.unwrap(chainId))); }
30
+ }
@@ -0,0 +1,35 @@
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
+ /// @dev Converts the uint256 to a NftId.
16
+ function toNftId(uint256 id) pure returns(NftId) { return NftId.wrap(uint96(id)); }
17
+
18
+ /// @dev Return the NftId zero (0)
19
+ function zeroNftId() pure returns(NftId) { return NftId.wrap(0); }
20
+
21
+ // pure free functions for operators
22
+ function eqNftId(NftId a, NftId b) pure returns(bool isSame) { return NftId.unwrap(a) == NftId.unwrap(b); }
23
+ function neNftId(NftId a, NftId b) pure returns(bool isDifferent) { return NftId.unwrap(a) != NftId.unwrap(b); }
24
+
25
+ // library functions that operate on user defined type
26
+ library NftIdLib {
27
+ /// @dev Converts the NftId to a uint256.
28
+ function toInt(NftId nftId) public pure returns(uint96) { return uint96(NftId.unwrap(nftId)); }
29
+ /// @dev Returns true if the value is non-zero (> 0).
30
+ function gtz(NftId a) public pure returns(bool) { return NftId.unwrap(a) > 0; }
31
+ /// @dev Returns true if the value is zero (== 0).
32
+ function eqz(NftId a) public pure returns(bool) { return NftId.unwrap(a) == 0; }
33
+ /// @dev Returns true if the values are equal (==).
34
+ function eq(NftId a, NftId b) public pure returns(bool isSame) { return eqNftId(a, b); }
35
+ }