@etherisc/gif-next 0.0.2-7631288 → 0.0.2-886fd8b

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 (147) 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/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 +1009 -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 +105 -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 +125 -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 +305 -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/ChainId.sol/ChainIdLib.dbg.json +4 -0
  105. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
  106. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
  107. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +10 -0
  108. package/contracts/components/Component.sol +62 -0
  109. package/contracts/components/IPool.sol +9 -0
  110. package/contracts/components/IProduct.sol +12 -0
  111. package/contracts/components/Pool.sol +29 -0
  112. package/contracts/components/Product.sol +66 -0
  113. package/contracts/experiment/errors/Require.sol +33 -0
  114. package/contracts/experiment/errors/Revert.sol +39 -0
  115. package/contracts/experiment/inheritance/A.sol +56 -0
  116. package/contracts/experiment/inheritance/B.sol +23 -0
  117. package/contracts/experiment/inheritance/C.sol +28 -0
  118. package/contracts/experiment/inheritance/IA.sol +18 -0
  119. package/contracts/experiment/inheritance/IB.sol +9 -0
  120. package/contracts/experiment/inheritance/IC.sol +11 -0
  121. package/contracts/experiment/types/TypeA.sol +42 -0
  122. package/contracts/experiment/types/TypeB.sol +24 -0
  123. package/contracts/instance/IInstance.sol +20 -0
  124. package/contracts/instance/Instance.sol +64 -0
  125. package/contracts/instance/access/Access.sol +218 -0
  126. package/contracts/instance/access/IAccess.sol +83 -0
  127. package/contracts/instance/component/ComponentModule.sol +246 -0
  128. package/contracts/instance/component/IComponent.sol +95 -0
  129. package/contracts/instance/policy/IPolicy.sol +66 -0
  130. package/contracts/instance/policy/PolicyModule.sol +106 -0
  131. package/contracts/instance/pool/IPoolModule.sol +41 -0
  132. package/contracts/instance/pool/PoolModule.sol +84 -0
  133. package/contracts/instance/product/IProductService.sol +46 -0
  134. package/contracts/instance/product/ProductService.sol +106 -0
  135. package/contracts/registry/ChainNft.sol +173 -0
  136. package/contracts/registry/IChainNft.sol +18 -0
  137. package/contracts/registry/IRegistry.sol +70 -0
  138. package/contracts/registry/Registry.sol +181 -0
  139. package/contracts/types/ChainId.sol +24 -0
  140. package/contracts/types/NftId.sol +26 -0
  141. package/package.json +7 -6
  142. package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
  143. package/artifacts/contracts/Dip.sol/DIP.json +0 -338
  144. package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
  145. package/artifacts/contracts/Lock.sol/Lock.json +0 -74
  146. package/contracts/Dip.sol +0 -26
  147. package/contracts/Lock.sol +0 -34
@@ -0,0 +1,246 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {RegistryLinked} from "../../registry/Registry.sol";
5
+ import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
6
+ import {IAccessComponentTypeRoles, IAccessCheckRole} from "../access/IAccess.sol";
7
+ import {IInstance} from "../IInstance.sol";
8
+
9
+ import {IComponent, IComponentContract, IComponentModule, IComponentOwnerService} from "./IComponent.sol";
10
+ import {IProductComponent} from "../../components/IProduct.sol";
11
+ import {IPoolModule} from "../pool/IPoolModule.sol";
12
+ import {NftId, gtz, eqNftId} from "../../types/NftId.sol";
13
+
14
+ abstract contract ComponentModule is
15
+ IRegistryLinked,
16
+ IAccessComponentTypeRoles,
17
+ IAccessCheckRole,
18
+ IComponentModule
19
+ {
20
+
21
+ mapping(NftId nftId => ComponentInfo info) private _componentInfo;
22
+ mapping(NftId nftId => NftId poolNftId) private _poolNftIdForProduct;
23
+ mapping(address cAddress => NftId nftId) private _nftIdByAddress;
24
+ NftId[] private _nftIds;
25
+
26
+ mapping(uint256 cType => bytes32 role) private _componentOwnerRole;
27
+
28
+ IComponentOwnerService private _componentOwnerService;
29
+
30
+ modifier onlyComponentOwnerService() {
31
+ require(address(_componentOwnerService) == msg.sender, "ERROR:CMP-001:NOT_OWNER_SERVICE");
32
+ _;
33
+ }
34
+
35
+ constructor(address componentOwnerService) {
36
+ _componentOwnerService = ComponentOwnerService(componentOwnerService);
37
+ }
38
+
39
+ function registerComponent(IComponentContract component)
40
+ external
41
+ override
42
+ onlyComponentOwnerService
43
+ returns(NftId nftId)
44
+ {
45
+ bytes32 typeRole = getRoleForType(component.getType());
46
+ require(
47
+ this.hasRole(typeRole, component.getInitialOwner()),
48
+ "ERROR:CMP-004:TYPE_ROLE_MISSING");
49
+
50
+ nftId = this.getRegistry().register(address(component));
51
+
52
+ _componentInfo[nftId] = ComponentInfo(
53
+ nftId,
54
+ CState.Active);
55
+
56
+ // special case product -> persist product - pool assignment
57
+ if(component.getType() == this.getRegistry().PRODUCT()) {
58
+ IProductComponent product = IProductComponent(address(component));
59
+ NftId poolNftId = product.getPoolNftId();
60
+ require(gtz(poolNftId), "ERROR:CMP-005:POOL_UNKNOWN");
61
+ // add more validation (type, token, ...)
62
+
63
+ _poolNftIdForProduct[nftId] = poolNftId;
64
+
65
+ // add creation of productInfo
66
+ }
67
+ else if(component.getType() == this.getRegistry().POOL()) {
68
+ IPoolModule poolModule = IPoolModule(address(this));
69
+ poolModule.createPoolInfo(
70
+ nftId,
71
+ address(component), // set pool as its wallet
72
+ address(0) // don't deal with token yet
73
+ );
74
+ }
75
+
76
+ _nftIdByAddress[address(component)] = nftId;
77
+ _nftIds.push(nftId);
78
+
79
+ // add logging
80
+ }
81
+
82
+ function getPoolNftId(NftId productNftId)
83
+ external
84
+ view
85
+ override
86
+ returns(NftId poolNftId)
87
+ {
88
+ poolNftId = _poolNftIdForProduct[productNftId];
89
+ }
90
+
91
+
92
+ function getComponentOwnerService()
93
+ external
94
+ override
95
+ view
96
+ returns(IComponentOwnerService)
97
+ {
98
+ return _componentOwnerService;
99
+ }
100
+
101
+ function setComponentInfo(ComponentInfo memory info)
102
+ external
103
+ onlyComponentOwnerService
104
+ returns(NftId nftId)
105
+ {
106
+ nftId = info.nftId;
107
+ require(
108
+ gtz(nftId) && eqNftId(_componentInfo[nftId].nftId, nftId),
109
+ "ERROR:CMP-006:COMPONENT_UNKNOWN");
110
+
111
+ _componentInfo[nftId] = info;
112
+
113
+ // add logging
114
+ }
115
+
116
+ function getComponentInfo(NftId nftId)
117
+ external
118
+ override
119
+ view
120
+ returns(ComponentInfo memory)
121
+ {
122
+ return _componentInfo[nftId];
123
+ }
124
+
125
+ function getComponentOwner(NftId nftId)
126
+ external
127
+ view
128
+ returns(address owner)
129
+ {
130
+
131
+ }
132
+
133
+ function getComponentId(address componentAddress)
134
+ external
135
+ view
136
+ returns(NftId componentNftId)
137
+ {
138
+ return _nftIdByAddress[componentAddress];
139
+ }
140
+
141
+
142
+ function getComponentId(uint256 idx)
143
+ external
144
+ override
145
+ view
146
+ returns(NftId componentNftId)
147
+ {
148
+ return _nftIds[idx];
149
+ }
150
+
151
+
152
+ function components()
153
+ external
154
+ override
155
+ view
156
+ returns(uint256 numberOfCompnents)
157
+ {
158
+ return _nftIds.length;
159
+ }
160
+
161
+ function getRoleForType(uint256 cType)
162
+ public
163
+ view
164
+ returns(bytes32 role)
165
+ {
166
+ if(cType == this.getRegistry().PRODUCT()) {
167
+ return this.PRODUCT_OWNER_ROLE();
168
+ }
169
+ if(cType == this.getRegistry().POOL()) {
170
+ return this.POOL_OWNER_ROLE();
171
+ }
172
+ if(cType == this.getRegistry().ORACLE()) {
173
+ return this.ORACLE_OWNER_ROLE();
174
+ }
175
+
176
+ }
177
+ }
178
+
179
+
180
+ // this is actually the component owner service
181
+ contract ComponentOwnerService is
182
+ RegistryLinked,
183
+ IComponent,
184
+ IComponentOwnerService
185
+ {
186
+
187
+ modifier onlyComponentOwner(IComponentContract component) {
188
+ NftId nftId = _registry.getNftId(address(component));
189
+ require(
190
+ gtz(nftId),
191
+ "ERROR:COS-001:COMPONENT_UNKNOWN");
192
+ require(
193
+ msg.sender == _registry.getOwner(nftId),
194
+ "ERROR:COS-002:NOT_OWNER"
195
+ );
196
+ _;
197
+ }
198
+
199
+ constructor(address registry)
200
+ RegistryLinked(registry)
201
+ { }
202
+
203
+ function register(IComponentContract component)
204
+ external
205
+ override
206
+ returns(NftId nftId)
207
+ {
208
+ require(
209
+ msg.sender == component.getInitialOwner(),
210
+ "ERROR:COS-003:NOT_OWNER");
211
+
212
+ IInstance instance = component.getInstance();
213
+ nftId = instance.registerComponent(component);
214
+ }
215
+
216
+
217
+ function lock(IComponentContract component)
218
+ external
219
+ override
220
+ onlyComponentOwner(component)
221
+ {
222
+ IInstance instance = component.getInstance();
223
+ ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
224
+ require(gtz(info.nftId), "ERROR_COMPONENT_UNKNOWN");
225
+ // TODO add state change validation
226
+
227
+ info.state = CState.Locked;
228
+ instance.setComponentInfo(info);
229
+ }
230
+
231
+
232
+ function unlock(IComponentContract component)
233
+ external
234
+ override
235
+ onlyComponentOwner(component)
236
+ {
237
+ IInstance instance = component.getInstance();
238
+ ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
239
+ require(gtz(info.nftId), "ERROR_COMPONENT_UNKNOWN");
240
+ // TODO state change validation
241
+
242
+ info.state = CState.Active;
243
+ instance.setComponentInfo(info);
244
+ }
245
+
246
+ }
@@ -0,0 +1,95 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
+ import {IInstance} from "../IInstance.sol";
7
+ import {NftId} from "../../types/NftId.sol";
8
+
9
+ interface IComponent {
10
+
11
+ // TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
12
+ enum CState {
13
+ Undefined,
14
+ Active,
15
+ Locked
16
+ }
17
+
18
+ // component dynamic info (static info kept in registry)
19
+ struct ComponentInfo {
20
+ NftId nftId;
21
+ CState state;
22
+ }
23
+ }
24
+
25
+
26
+ interface IInstanceLinked {
27
+ // function setInstance(address instance) external;
28
+ function getInstance() external view returns(IInstance instance);
29
+ }
30
+
31
+
32
+ interface IComponentContract is
33
+ IRegisterable,
34
+ IInstanceLinked,
35
+ IComponent
36
+ { }
37
+
38
+
39
+ interface IComponentOwnerService is IRegistryLinked{
40
+
41
+ function register(IComponentContract component) external returns(NftId nftId);
42
+ function lock(IComponentContract component) external;
43
+ function unlock(IComponentContract component) external;
44
+ }
45
+
46
+
47
+ interface IComponentModule is
48
+ IOwnable,
49
+ IRegistryLinked,
50
+ IComponent
51
+ {
52
+
53
+ function registerComponent(IComponentContract component)
54
+ external
55
+ returns(NftId nftId);
56
+
57
+ function setComponentInfo(ComponentInfo memory info)
58
+ external
59
+ returns(NftId componentNftId);
60
+
61
+ function getComponentInfo(NftId nftId)
62
+ external
63
+ view
64
+ returns(ComponentInfo memory info);
65
+
66
+ function getComponentOwner(NftId nftId)
67
+ external
68
+ view
69
+ returns(address owner);
70
+
71
+ function getComponentId(address componentAddress)
72
+ external
73
+ view
74
+ returns(NftId nftId);
75
+
76
+ function getComponentId(uint256 idx)
77
+ external
78
+ view
79
+ returns(NftId nftId);
80
+
81
+ function getPoolNftId(NftId productNftId)
82
+ external
83
+ view
84
+ returns(NftId poolNftId);
85
+
86
+ function components()
87
+ external
88
+ view
89
+ returns(uint256 numberOfCompnents);
90
+
91
+ function getComponentOwnerService()
92
+ external
93
+ view
94
+ returns(IComponentOwnerService);
95
+ }
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
6
+ import {IInstance} from "../IInstance.sol";
7
+ import {IProductService} from "../product/IProductService.sol";
8
+ import {NftId} from "../../types/NftId.sol";
9
+
10
+ // TODO check if there is value to introuce IContract and let IPolicy derive from IContract
11
+ interface IPolicy {
12
+
13
+ enum PolicyState {
14
+ Undefined,
15
+ Applied,
16
+ Rejected,
17
+ Active,
18
+ Closed
19
+ }
20
+
21
+ struct PolicyInfo {
22
+ NftId nftId;
23
+ PolicyState state; // applied, withdrawn, rejected, active, closed
24
+
25
+ uint256 sumInsuredAmount;
26
+ uint256 premiumAmount;
27
+ uint256 lifetime; // activatedAt + lifetime >= expiredAt
28
+
29
+ uint256 createdAt;
30
+ uint256 activatedAt; // time of underwriting
31
+ uint256 expiredAt; // no new claims
32
+ uint256 closedAt; // no locked capital
33
+ }
34
+ }
35
+
36
+ interface IPolicyModule is
37
+ IOwnable,
38
+ IRegistryLinked,
39
+ IPolicy
40
+ {
41
+
42
+ function createApplication(
43
+ IRegistry.RegistryInfo memory productInfo,
44
+ address applicationOwner,
45
+ uint256 sumInsuredAmount,
46
+ uint256 premiumAmount,
47
+ uint256 lifetime,
48
+ NftId bundleNftId
49
+ )
50
+ external
51
+ returns(NftId nftId);
52
+
53
+ function activate(NftId nftId)
54
+ external;
55
+
56
+ function getBundleNftForPolicy(NftId nftId)
57
+ external
58
+ view
59
+ returns(NftId bundleNft);
60
+
61
+ function getPolicyInfo(NftId nftId)
62
+ external
63
+ view
64
+ returns(PolicyInfo memory info);
65
+
66
+ }
@@ -0,0 +1,106 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ // import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
+ import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
7
+
8
+ import {IProductService} from "../product/IProductService.sol";
9
+ import {IPolicy, IPolicyModule} from "./IPolicy.sol";
10
+ import {NftId, gtz} from "../../types/NftId.sol";
11
+
12
+ abstract contract PolicyModule is
13
+ IRegistryLinked,
14
+ IPolicyModule
15
+ {
16
+
17
+ mapping(NftId nftId => PolicyInfo info) private _policyInfo;
18
+ mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
19
+
20
+ IProductService private _productService;
21
+
22
+ // TODO find a better place to avoid dupliation
23
+ modifier onlyProductService2() {
24
+ require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
25
+ _;
26
+ }
27
+
28
+ constructor(address productService) {
29
+ _productService = IProductService(productService);
30
+ }
31
+
32
+
33
+ function createApplication(
34
+ IRegistry.RegistryInfo memory productInfo,
35
+ address applicationOwner,
36
+ uint256 sumInsuredAmount,
37
+ uint256 premiumAmount,
38
+ uint256 lifetime,
39
+ NftId bundleNftId
40
+ )
41
+ external
42
+ override
43
+ onlyProductService2
44
+ returns(NftId nftId)
45
+ {
46
+ // TODO add parameter validation
47
+ if(gtz(bundleNftId)) {
48
+ IRegistry.RegistryInfo memory bundleInfo = this.getRegistry().getInfo(bundleNftId);
49
+ IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
50
+ }
51
+
52
+ nftId = this.getRegistry().registerObjectForInstance(
53
+ productInfo.nftId,
54
+ this.getRegistry().POLICY(),
55
+ applicationOwner);
56
+
57
+ _policyInfo[nftId] = PolicyInfo(
58
+ nftId,
59
+ PolicyState.Applied,
60
+ sumInsuredAmount,
61
+ premiumAmount,
62
+ lifetime,
63
+ block.timestamp,
64
+ 0, // activatedAt
65
+ 0, // expiredAt
66
+ 0 // closedAt
67
+ );
68
+
69
+ _bundleForPolicy[nftId] = bundleNftId;
70
+
71
+ // add logging
72
+ }
73
+
74
+
75
+ function activate(NftId nftId)
76
+ external
77
+ override
78
+ onlyProductService2
79
+ {
80
+ PolicyInfo storage info = _policyInfo[nftId];
81
+ info.activatedAt = block.timestamp;
82
+ info.expiredAt = block.timestamp + info.lifetime;
83
+ info.state = PolicyState.Active;
84
+
85
+ // add logging
86
+ }
87
+
88
+
89
+
90
+ function getBundleNftForPolicy(NftId nftId)
91
+ external
92
+ view
93
+ returns(NftId bundleNft)
94
+ {
95
+ return _bundleForPolicy[nftId];
96
+ }
97
+
98
+
99
+ function getPolicyInfo(NftId nftId)
100
+ external
101
+ view
102
+ returns(PolicyInfo memory info)
103
+ {
104
+ return _policyInfo[nftId];
105
+ }
106
+ }
@@ -0,0 +1,41 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
5
+ import {NftId} from "../../types/NftId.sol";
6
+
7
+ interface IPool {
8
+
9
+ struct PoolInfo {
10
+ NftId nftId;
11
+ address wallet;
12
+ address token;
13
+ uint256 capital;
14
+ uint256 lockedCapital;
15
+ }
16
+ }
17
+
18
+ interface IPoolModule is
19
+ IOwnable,
20
+ IRegistryLinked,
21
+ IPool
22
+ {
23
+
24
+ function underwrite(
25
+ NftId poolNftId,
26
+ NftId policyNftId
27
+ )
28
+ external;
29
+
30
+ function createPoolInfo(
31
+ NftId nftId,
32
+ address wallet,
33
+ address token
34
+ )
35
+ external;
36
+
37
+ function getPoolInfo(NftId nftId)
38
+ external
39
+ view
40
+ returns(PoolInfo memory info);
41
+ }
@@ -0,0 +1,84 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
5
+ import {IProductService} from "../product/IProductService.sol";
6
+ import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
7
+ import {IPoolModule} from "./IPoolModule.sol";
8
+ import {NftId, eqz} from "../../types/NftId.sol";
9
+
10
+ abstract contract PoolModule is
11
+ IPoolModule
12
+ {
13
+ uint256 public constant INITIAL_CAPITAL = 10000*10**6;
14
+
15
+ mapping(NftId nftId => PoolInfo info) private _poolInfo;
16
+
17
+ IProductService private _productService;
18
+
19
+ modifier onlyProductService() {
20
+ require(address(_productService) == msg.sender, "ERROR:POL-001:NOT_PRODUCT_SERVICE");
21
+ _;
22
+ }
23
+
24
+ constructor(address productService) {
25
+ _productService = IProductService(productService);
26
+ }
27
+
28
+ function createPoolInfo(
29
+ NftId nftId,
30
+ address wallet,
31
+ address token
32
+ )
33
+ public
34
+ override
35
+ {
36
+ require(
37
+ eqz(_poolInfo[nftId].nftId),
38
+ "ERROR:PL-001:ALREADY_CREATED");
39
+
40
+ _poolInfo[nftId] = PoolInfo(
41
+ nftId,
42
+ wallet,
43
+ token,
44
+ INITIAL_CAPITAL,
45
+ 0 // locked capital
46
+ );
47
+
48
+ }
49
+
50
+
51
+ function underwrite(
52
+ NftId poolNftId,
53
+ NftId policyNftId
54
+ )
55
+ external
56
+ override
57
+ onlyProductService
58
+ {
59
+ PoolInfo storage poolInfo = _poolInfo[poolNftId];
60
+ require(
61
+ poolInfo.nftId == poolNftId,
62
+ "ERROR:PL-002:POOL_UNKNOWN");
63
+
64
+ IPolicyModule policyModule = IPolicyModule(address(this));
65
+ IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(policyNftId);
66
+
67
+ require(
68
+ poolInfo.capital - poolInfo.lockedCapital >= policyInfo.sumInsuredAmount,
69
+ "ERROR:PL-003:CAPACITY_TOO_LOW");
70
+
71
+ poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
72
+ }
73
+
74
+
75
+ function getPoolInfo(NftId nftId)
76
+ external
77
+ view
78
+ override
79
+ returns(PoolInfo memory info)
80
+ {
81
+ info = _poolInfo[nftId];
82
+ }
83
+
84
+ }
@@ -0,0 +1,46 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+
5
+ import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
+ import {IInstance} from "../IInstance.sol";
7
+ import {NftId} from "../../types/NftId.sol";
8
+
9
+
10
+ // TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
11
+ interface IProductService is
12
+ IRegistryLinked
13
+ {
14
+
15
+ function createApplication(
16
+ address applicationOwner,
17
+ uint256 sumInsuredAmount,
18
+ uint256 premiumAmount,
19
+ uint256 lifetime,
20
+ NftId bundleNftId
21
+ )
22
+ external
23
+ returns(NftId nftId);
24
+
25
+ // function revoke(unit256 nftId) external;
26
+
27
+ function underwrite(NftId nftId) external;
28
+ // function decline(uint256 nftId) external;
29
+ // function expire(uint256 nftId) external;
30
+ function close(NftId nftId) external;
31
+
32
+ // function collectPremium(uint256 nftId, uint256 premiumAmount) external;
33
+
34
+ // function createClaim(uint256 nftId, uint256 claimAmount) external;
35
+ // function confirmClaim(uint256 nftId, uint256 claimId, uint256 claimAmount) external;
36
+ // function declineClaim(uint256 nftId, uint256 claimId) external;
37
+ // function closeClaim(uint256 nftId, uint256 claimId) external;
38
+ }
39
+
40
+
41
+ interface IProductModule is
42
+ IOwnable,
43
+ IRegistryLinked
44
+ {
45
+ function getProductService() external view returns(IProductService);
46
+ }