@etherisc/gif-next 0.0.2-ebbe63d → 0.0.2-ed4dd55

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. package/README.md +95 -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 +195 -0
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
  13. package/artifacts/contracts/components/Product.sol/Product.json +213 -0
  14. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +4 -0
  15. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
  16. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
  18. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
  19. package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
  20. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
  21. package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
  22. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
  23. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
  27. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
  28. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
  30. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
  32. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
  34. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
  35. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +892 -0
  36. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
  37. package/artifacts/contracts/instance/Instance.sol/Instance.json +1009 -0
  38. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +4 -0
  39. package/artifacts/contracts/instance/access/Access.sol/AccessModule.json +400 -0
  40. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +4 -0
  41. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.json +10 -0
  42. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +4 -0
  43. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.json +35 -0
  44. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +4 -0
  45. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.json +50 -0
  46. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +4 -0
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.json +336 -0
  48. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +4 -0
  49. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +327 -0
  50. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +4 -0
  51. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +105 -0
  52. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +4 -0
  53. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.json +10 -0
  54. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +4 -0
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +179 -0
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +4 -0
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +245 -0
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +4 -0
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +94 -0
  60. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +4 -0
  61. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.json +24 -0
  62. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +4 -0
  63. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.json +10 -0
  64. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +4 -0
  65. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +231 -0
  66. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +4 -0
  67. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +231 -0
  68. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +4 -0
  69. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.json +10 -0
  70. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +4 -0
  71. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +149 -0
  72. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +4 -0
  73. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +162 -0
  74. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +4 -0
  75. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.json +75 -0
  76. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +4 -0
  77. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +114 -0
  78. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +4 -0
  79. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.json +75 -0
  80. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +4 -0
  81. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +125 -0
  82. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
  83. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
  84. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
  85. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
  86. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +4 -0
  87. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.json +24 -0
  88. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +4 -0
  89. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +166 -0
  90. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
  91. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +279 -0
  92. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +4 -0
  93. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.json +49 -0
  94. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +4 -0
  95. package/artifacts/contracts/registry/Registry.sol/Registerable.json +166 -0
  96. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
  97. package/artifacts/contracts/registry/Registry.sol/Registry.json +305 -0
  98. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +4 -0
  99. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +60 -0
  100. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +4 -0
  101. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  102. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  103. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +10 -0
  104. package/contracts/components/Component.sol +62 -0
  105. package/contracts/components/IPool.sol +9 -0
  106. package/contracts/components/IProduct.sol +11 -0
  107. package/contracts/components/Pool.sol +29 -0
  108. package/contracts/components/Product.sol +65 -0
  109. package/contracts/experiment/inheritance/A.sol +56 -0
  110. package/contracts/experiment/inheritance/B.sol +23 -0
  111. package/contracts/experiment/inheritance/C.sol +28 -0
  112. package/contracts/experiment/inheritance/IA.sol +18 -0
  113. package/contracts/experiment/inheritance/IB.sol +9 -0
  114. package/contracts/experiment/inheritance/IC.sol +11 -0
  115. package/contracts/experiment/types/TypeA.sol +42 -0
  116. package/contracts/experiment/types/TypeB.sol +24 -0
  117. package/contracts/instance/IInstance.sol +20 -0
  118. package/contracts/instance/Instance.sol +63 -0
  119. package/contracts/instance/access/Access.sol +218 -0
  120. package/contracts/instance/access/IAccess.sol +83 -0
  121. package/contracts/instance/component/ComponentModule.sol +259 -0
  122. package/contracts/instance/component/IComponent.sol +94 -0
  123. package/contracts/instance/policy/IPolicy.sol +66 -0
  124. package/contracts/instance/policy/PolicyModule.sol +106 -0
  125. package/contracts/instance/pool/IPoolModule.sol +40 -0
  126. package/contracts/instance/pool/PoolModule.sol +83 -0
  127. package/contracts/instance/product/IProductService.sol +45 -0
  128. package/contracts/instance/product/ProductService.sol +105 -0
  129. package/contracts/registry/ChainNft.sol +173 -0
  130. package/contracts/registry/IChainNft.sol +18 -0
  131. package/contracts/registry/IRegistry.sol +68 -0
  132. package/contracts/registry/Registry.sol +176 -0
  133. package/contracts/types/ChainId.sol +24 -0
  134. package/contracts/types/NftId.sol +25 -0
  135. package/package.json +7 -6
  136. package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
  137. package/artifacts/contracts/Dip.sol/DIP.json +0 -338
  138. package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
  139. package/artifacts/contracts/Lock.sol/Lock.json +0 -74
  140. package/contracts/Dip.sol +0 -26
  141. package/contracts/Lock.sol +0 -34
@@ -0,0 +1,105 @@
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
+
15
+ // TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
16
+ contract ProductService is
17
+ RegistryLinked,
18
+ IProductService
19
+ {
20
+ constructor(address registry)
21
+ RegistryLinked(registry)
22
+ { }
23
+
24
+
25
+ function createApplication(
26
+ address applicationOwner,
27
+ uint256 sumInsuredAmount,
28
+ uint256 premiumAmount,
29
+ uint256 lifetime,
30
+ uint256 bundleNftId
31
+ )
32
+ external
33
+ override
34
+ returns(uint256 nftId)
35
+ {
36
+ // same as only registered product
37
+ uint256 productNftId = _registry.getNftId(msg.sender);
38
+ require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
39
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
40
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
41
+
42
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
43
+ require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
44
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
45
+
46
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
47
+ nftId = policyModule.createApplication(
48
+ productInfo,
49
+ applicationOwner,
50
+ sumInsuredAmount,
51
+ premiumAmount,
52
+ lifetime,
53
+ bundleNftId);
54
+
55
+ // add logging
56
+ }
57
+
58
+ function underwrite(uint256 nftId)
59
+ external
60
+ override
61
+ {
62
+ // same as only registered product
63
+ uint256 productNftId = _registry.getNftId(msg.sender);
64
+ require(productNftId > 0, "ERROR_PRODUCT_UNKNOWN");
65
+ IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
66
+ require(productInfo.objectType == _registry.PRODUCT(), "ERROR_NOT_PRODUCT");
67
+
68
+ IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
69
+ require(instanceInfo.nftId > 0, "ERROR_INSTANCE_UNKNOWN");
70
+ require(instanceInfo.objectType == _registry.INSTANCE(), "ERROR_NOT_INSTANCE");
71
+
72
+ // get responsible pool
73
+ IComponentModule componentModule = IComponentModule(instanceInfo.objectAddress);
74
+ uint256 poolNftId = componentModule.getPoolNftId(productNftId);
75
+
76
+ // lock capital (and update pool accounting)
77
+ IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
78
+ poolModule.underwrite(
79
+ poolNftId,
80
+ nftId);
81
+
82
+ // activate policy
83
+ IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
84
+ policyModule.activate(nftId);
85
+
86
+ // add logging
87
+ }
88
+
89
+ function close(uint256 nftId) external override {}
90
+ }
91
+
92
+ abstract contract ProductModule is
93
+ IProductModule
94
+ {
95
+ IProductService private _productService;
96
+
97
+ constructor(address productService) {
98
+ _productService = IProductService(productService);
99
+ }
100
+
101
+ function getProductService() external view returns(IProductService) {
102
+ return _productService;
103
+ }
104
+
105
+ }
@@ -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,68 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ interface IOwnable {
5
+ function getOwner() external view returns(address owner);
6
+ }
7
+
8
+ interface IRegistryLinked {
9
+
10
+ event LogDebug(uint256 idx, address module, string comment);
11
+
12
+ function getRegistry() external view returns(IRegistry registry);
13
+ }
14
+
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
+ }
31
+
32
+
33
+ interface IRegistry {
34
+
35
+ struct RegistryInfo {
36
+ uint256 nftId;
37
+ uint256 parentNftId;
38
+ uint256 objectType;
39
+ address objectAddress;
40
+ address initialOwner;
41
+ }
42
+
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);
50
+
51
+ function register(address objectAddress) external returns(uint256 nftId);
52
+ function registerObjectForInstance(
53
+ uint256 parentNftid,
54
+ uint256 objectType,
55
+ address initialOwner
56
+ )
57
+ external returns(uint256 nftId);
58
+
59
+ function getObjectCount() external view returns(uint256);
60
+
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);
64
+
65
+ function isRegistered(address objectAddress) external view returns(bool);
66
+
67
+ function getNftAddress() external view returns(address nft);
68
+ }
@@ -0,0 +1,176 @@
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
+
7
+ contract RegistryLinked is IRegistryLinked {
8
+
9
+ IRegistry internal _registry;
10
+
11
+ constructor(address registry) {
12
+ _registry = IRegistry(registry);
13
+ }
14
+
15
+ function getRegistry() external view override returns(IRegistry registry) {
16
+ return _registry;
17
+ }
18
+
19
+ }
20
+
21
+
22
+ abstract contract Registerable is
23
+ RegistryLinked,
24
+ IRegisterable
25
+ {
26
+
27
+ address private _initialOwner;
28
+
29
+ constructor(address registry)
30
+ RegistryLinked(registry)
31
+ {
32
+ _initialOwner = msg.sender;
33
+ }
34
+
35
+ // getType, getData and register need to be implemented by concrete contract
36
+
37
+ function isRegisterable() external pure override returns(bool) {
38
+ return true;
39
+ }
40
+
41
+ function getInitialOwner() public view override returns(address deployer) {
42
+ return _initialOwner;
43
+ }
44
+
45
+ function isRegistered() public view override returns(bool) {
46
+ return _registry.getNftId(address(this)) > 0;
47
+ }
48
+
49
+ function getNftId() public view override returns(uint256 id) {
50
+ return _registry.getNftId(address(this));
51
+ }
52
+
53
+ function getOwner() public view override returns(address owner) {
54
+ uint256 id = _registry.getNftId(address(this));
55
+ owner = _registry.getOwner(id);
56
+ return owner != address(0) ? owner : _initialOwner;
57
+ }
58
+
59
+ }
60
+
61
+ contract Registry is IRegistry {
62
+
63
+ string public constant EMPTY_URI = "";
64
+
65
+ mapping(uint256 id => RegistryInfo info) private _info;
66
+ mapping(uint256 id => address owner) private _owner;
67
+ mapping(address object => uint256 id) private _idByAddress;
68
+
69
+ IChainNft private _chainNft;
70
+
71
+ function initialize(address chainNft) external {
72
+ require(address(_chainNft) == address(0), "ERROR:REG-001:ALREADY_INITIALIZED");
73
+ _chainNft = IChainNft(chainNft);
74
+ }
75
+
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-001:ALREADY_REGISTERED");
86
+
87
+ IRegisterable registerable = IRegisterable(objectAddress);
88
+ require(registerable.isRegisterable(), "ERROR:REG-002:NOT_REGISTERABLE");
89
+
90
+ // 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-003:PARENT_NOT_FOUND");
94
+ // check validity of parent relation, valid relations are
95
+ // policy -> product, bundle -> pool, product -> instance, pool -> instance
96
+ }
97
+
98
+ nftId = _chainNft.mint(
99
+ registerable.getInitialOwner(),
100
+ EMPTY_URI);
101
+
102
+ RegistryInfo memory info = RegistryInfo(
103
+ nftId,
104
+ registerable.getParentNftId(),
105
+ registerable.getType(),
106
+ objectAddress,
107
+ registerable.getInitialOwner()
108
+ );
109
+
110
+ _info[nftId] = info;
111
+ _idByAddress[objectAddress] = nftId;
112
+
113
+ // add logging
114
+ }
115
+
116
+
117
+ function registerObjectForInstance(
118
+ uint256 parentNftId,
119
+ uint256 objectType,
120
+ address initialOwner
121
+ )
122
+ external
123
+ override
124
+ // TODO add onlyRegisteredInstance
125
+ returns(uint256 nftId)
126
+ {
127
+ // TODO add more validation
128
+ require(
129
+ objectType == POLICY() || objectType == BUNDLE(),
130
+ "ERROR:REG-005:TYPE_INVALID");
131
+
132
+ nftId = _chainNft.mint(
133
+ initialOwner,
134
+ EMPTY_URI);
135
+
136
+ RegistryInfo memory info = RegistryInfo(
137
+ nftId,
138
+ parentNftId,
139
+ objectType,
140
+ address(0),
141
+ initialOwner
142
+ );
143
+
144
+ _info[nftId] = info;
145
+
146
+ // add logging
147
+ }
148
+
149
+
150
+ function getObjectCount() external view override returns(uint256) {
151
+ return _chainNft.totalSupply();
152
+ }
153
+
154
+
155
+ function getNftId(address object) external view override returns(uint256 id) {
156
+ return _idByAddress[object];
157
+ }
158
+
159
+
160
+ function isRegistered(address object) external view override returns(bool) {
161
+ return _idByAddress[object] > 0;
162
+ }
163
+
164
+
165
+ function getInfo(uint256 nftId) external view override returns(RegistryInfo memory info) {
166
+ return _info[nftId];
167
+ }
168
+
169
+ function getOwner(uint256 nftId) external view override returns(address) {
170
+ return _chainNft.ownerOf(nftId);
171
+ }
172
+
173
+ function getNftAddress() external view override returns(address nft) {
174
+ return address(_chainNft);
175
+ }
176
+ }
@@ -0,0 +1,24 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // bytes5 (uint40) allows for chain ids up to 13 digits
5
+ type ChainId is bytes5;
6
+
7
+ // type bindings
8
+ using {
9
+ eqChainId as ==,
10
+ neChainId as !=,
11
+ ChainIdLib.toInt
12
+ } for ChainId global;
13
+
14
+ // general pure free functions
15
+ function toChainId(uint256 chainId) pure returns(ChainId) { return ChainId.wrap(bytes5(uint40(chainId))); }
16
+
17
+ // pure free functions for operators
18
+ function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) { return ChainId.unwrap(a) == ChainId.unwrap(b); }
19
+ function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) { return ChainId.unwrap(a) != ChainId.unwrap(b); }
20
+
21
+ // library functions that operate on user defined type
22
+ library ChainIdLib {
23
+ function toInt(ChainId chainId) internal pure returns(uint256) { return uint256(uint40(ChainId.unwrap(chainId))); }
24
+ }
@@ -0,0 +1,25 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ // uint96 allows for chain ids up to 13 digits
5
+ type NftId is uint96;
6
+
7
+ // type bindings
8
+ using {
9
+ eqNftId as ==,
10
+ neNftId as !=,
11
+ NftIdLib.toInt
12
+ } for NftId global;
13
+
14
+ // general pure free functions
15
+ function toNftId(uint256 id) pure returns(NftId) { return NftId.wrap(uint96(id)); }
16
+ function gtz(NftId a) pure returns(bool) { return NftId.unwrap(a) > 0; }
17
+
18
+ // pure free functions for operators
19
+ function eqNftId(NftId a, NftId b) pure returns(bool isSame) { return NftId.unwrap(a) == NftId.unwrap(b); }
20
+ function neNftId(NftId a, NftId b) pure returns(bool isDifferent) { return NftId.unwrap(a) != NftId.unwrap(b); }
21
+
22
+ // library functions that operate on user defined type
23
+ library NftIdLib {
24
+ function toInt(NftId nftId) internal pure returns(uint256) { return uint256(NftId.unwrap(nftId)); }
25
+ }
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@etherisc/gif-next",
3
- "version": "0.0.2-ebbe63d",
3
+ "version": "0.0.2-ed4dd55",
4
4
  "description": "This is the repository for the next version of the Generic Insurance Framework (GIF) smart contracts. ",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "build": "hardhat compile",
8
- "test": "hardhat test",
9
- "ptest": "hardhat test --parallel",
10
- "test-with-gas": "REPORT_GAS=true hardhat test",
11
- "coverage": "hardhat coverage"
7
+ "build": "hh compile",
8
+ "test": "hh test",
9
+ "ptest": "hh test --parallel",
10
+ "test-with-gas": "REPORT_GAS=true hh test",
11
+ "coverage": "hh coverage"
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
@@ -27,6 +27,7 @@
27
27
  "devDependencies": {
28
28
  "@nomicfoundation/hardhat-foundry": "^1.0.3",
29
29
  "@nomicfoundation/hardhat-toolbox": "^3.0.0",
30
+ "dotenv": "^16.3.1",
30
31
  "hardhat": "^2.17.1"
31
32
  },
32
33
  "dependencies": {
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../build-info/d6ddc31c8d0f29d05ebcf7dbd3184aca.json"
4
- }