@etherisc/gif-next 0.0.2-e1f23dc-329 → 0.0.2-e2d8c7d-942

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 (200) hide show
  1. package/README.md +63 -1
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +126 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +136 -10
  6. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +88 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +28 -2
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  12. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  13. package/artifacts/contracts/components/Pool.sol/Pool.json +168 -11
  14. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  15. package/artifacts/contracts/components/Product.sol/Product.json +144 -8
  16. package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  34. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  35. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  36. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  37. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  38. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +4 -0
  39. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +788 -0
  40. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +4 -0
  41. package/artifacts/contracts/instance/{AccessManagedSimple.sol/AccessManagedSimple.json → Cloneable.sol/Cloneable.json} +86 -2
  42. package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  44. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +69 -0
  45. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
  46. package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +448 -0
  47. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  48. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +17 -1
  49. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  50. package/artifacts/contracts/instance/Instance.sol/Instance.json +156 -139
  51. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  52. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +55 -32
  53. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +4 -0
  54. package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +763 -0
  55. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  56. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +55 -40
  57. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  58. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +243 -95
  59. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  60. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +82 -30
  61. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  62. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +285 -0
  63. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.json +0 -19
  65. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  66. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  68. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  69. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  73. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +4 -0
  78. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +923 -0
  79. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +4 -0
  80. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +440 -0
  81. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  82. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +2 -2
  83. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +16 -48
  85. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +8 -24
  87. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +4 -0
  88. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +669 -0
  89. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +4 -0
  92. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +664 -0
  93. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +9 -158
  95. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +9 -212
  97. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +4 -0
  98. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +984 -0
  99. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +464 -0
  101. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  102. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +20 -228
  103. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  104. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +10 -30
  105. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  106. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +20 -346
  107. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  108. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +10 -62
  109. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  110. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  111. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  112. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  113. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  114. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  115. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  116. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  117. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  118. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  119. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  120. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  121. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  122. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  124. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  125. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  126. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  127. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  128. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  130. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  131. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  132. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  133. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  134. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  135. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  136. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  137. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  138. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  139. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  140. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  141. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  142. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  143. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  144. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  145. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  147. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  148. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  149. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  150. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  151. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  154. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  156. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  157. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  163. package/contracts/components/BaseComponent.sol +49 -8
  164. package/contracts/components/Distribution.sol +5 -1
  165. package/contracts/components/IBaseComponent.sol +6 -0
  166. package/contracts/components/IPoolComponent.sol +5 -1
  167. package/contracts/components/Pool.sol +39 -10
  168. package/contracts/components/Product.sol +15 -7
  169. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
  170. package/contracts/instance/BundleManager.sol +129 -0
  171. package/contracts/instance/Cloneable.sol +46 -0
  172. package/contracts/instance/IInstance.sol +6 -0
  173. package/contracts/instance/IInstanceBase.sol +26 -0
  174. package/contracts/instance/IInstanceService.sol +7 -3
  175. package/contracts/instance/Instance.sol +36 -15
  176. package/contracts/instance/InstanceAccessManager.sol +6 -6
  177. package/contracts/instance/InstanceBase.sol +41 -0
  178. package/contracts/instance/InstanceService.sol +171 -70
  179. package/contracts/instance/ObjectManager.sol +101 -0
  180. package/contracts/instance/base/ComponentServiceBase.sol +15 -77
  181. package/contracts/instance/module/ISetup.sol +3 -1
  182. package/contracts/instance/service/BundleService.sol +260 -0
  183. package/contracts/instance/service/BundleServiceManager.sol +54 -0
  184. package/contracts/instance/service/DistributionService.sol +38 -8
  185. package/contracts/instance/service/IBundleService.sol +45 -0
  186. package/contracts/instance/service/IPolicyService.sol +87 -0
  187. package/contracts/instance/service/IPoolService.sol +4 -25
  188. package/contracts/instance/service/IProductService.sol +3 -70
  189. package/contracts/instance/service/PolicyService.sol +508 -0
  190. package/contracts/instance/service/PolicyServiceManager.sol +54 -0
  191. package/contracts/instance/service/PoolService.sol +41 -118
  192. package/contracts/instance/service/ProductService.sol +50 -441
  193. package/contracts/types/NftIdSet.sol +26 -24
  194. package/contracts/types/RoleId.sol +2 -0
  195. package/package.json +1 -1
  196. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  197. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  198. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
  199. package/contracts/instance/AccessManagedSimple.sol +0 -115
  200. package/contracts/instance/AccessManagerSimple.sol +0 -692
@@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
5
  import {IProductComponent} from "../../components/IProductComponent.sol";
6
6
  import {Product} from "../../components/Product.sol";
7
+ import {IBaseComponent} from "../../components/IBaseComponent.sol";
7
8
  import {IPoolComponent} from "../../components/IPoolComponent.sol";
8
9
  import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
9
10
  import {IInstance} from "../IInstance.sol";
@@ -30,6 +31,7 @@ import {ReferralId} from "../../types/Referral.sol";
30
31
  import {RiskId} from "../../types/RiskId.sol";
31
32
  import {StateId} from "../../types/StateId.sol";
32
33
  import {Version, VersionLib} from "../../types/Version.sol";
34
+ import {RoleId, PRODUCT_OWNER_ROLE} from "../../types/RoleId.sol";
33
35
 
34
36
  import {IService} from "../../shared/IService.sol";
35
37
  import {Service} from "../../shared/Service.sol";
@@ -47,7 +49,6 @@ contract ProductService is ComponentServiceBase, IProductService {
47
49
 
48
50
  string public constant NAME = "ProductService";
49
51
 
50
- address internal _registryAddress;
51
52
  IPoolService internal _poolService;
52
53
 
53
54
  event LogProductServiceSender(address sender);
@@ -60,14 +61,14 @@ contract ProductService is ComponentServiceBase, IProductService {
60
61
  initializer
61
62
  virtual override
62
63
  {
63
- address initialOwner = address(0);
64
- (_registryAddress, initialOwner) = abi.decode(data, (address, address));
64
+ address registryAddress;
65
+ address initialOwner;
66
+ (registryAddress, initialOwner) = abi.decode(data, (address, address));
65
67
 
66
- _initializeService(_registryAddress, owner);
68
+ _initializeService(registryAddress, owner);
67
69
 
68
70
  _poolService = IPoolService(_registry.getServiceAddress(POOL_SERVICE_NAME, getMajorVersion()));
69
71
 
70
- _registerInterface(type(IService).interfaceId);
71
72
  _registerInterface(type(IProductService).interfaceId);
72
73
  }
73
74
 
@@ -76,12 +77,40 @@ contract ProductService is ComponentServiceBase, IProductService {
76
77
  return NAME;
77
78
  }
78
79
 
79
- function _finalizeComponentRegistration(NftId componentNftId, bytes memory initialObjData, IInstance instance) internal override {
80
- ISetup.ProductSetupInfo memory initialSetup = abi.decode(
81
- initialObjData,
80
+ function register(address productAddress)
81
+ external
82
+ returns(NftId productNftId)
83
+ {
84
+ address productOwner = msg.sender;
85
+ IBaseComponent product = IBaseComponent(productAddress);
86
+
87
+ IRegistry.ObjectInfo memory info;
88
+ bytes memory data;
89
+ (info, data) = getRegistryService().registerProduct(product, productOwner);
90
+
91
+ IInstance instance = _getInstance(info);
92
+ bool hasRole = getInstanceService().hasRole(
93
+ productOwner,
94
+ PRODUCT_OWNER_ROLE(),
95
+ address(instance));
96
+
97
+ if(!hasRole) {
98
+ revert ExpectedRoleMissing(PRODUCT_OWNER_ROLE(), productOwner);
99
+ }
100
+
101
+ productNftId = info.nftId;
102
+ ISetup.ProductSetupInfo memory initialSetup = _decodeAndVerifyProductSetup(data);
103
+ instance.createProductSetup(productNftId, initialSetup);
104
+ }
105
+
106
+ function _decodeAndVerifyProductSetup(bytes memory data) internal returns(ISetup.ProductSetupInfo memory setup)
107
+ {
108
+ setup = abi.decode(
109
+ data,
82
110
  (ISetup.ProductSetupInfo)
83
111
  );
84
- instance.createProductSetup(componentNftId, initialSetup);
112
+
113
+ // TODO add checks if applicable
85
114
  }
86
115
 
87
116
  function setFees(
@@ -89,13 +118,18 @@ contract ProductService is ComponentServiceBase, IProductService {
89
118
  Fee memory processingFee
90
119
  )
91
120
  external
92
- override
93
121
  {
94
- (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
122
+ // TODO check args
123
+
124
+ (
125
+ IRegistry.ObjectInfo memory productInfo,
126
+ IInstance instance
127
+ ) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
128
+
95
129
  InstanceReader instanceReader = instance.getInstanceReader();
96
130
  NftId productNftId = productInfo.nftId;
97
-
98
131
  ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
132
+
99
133
  productSetupInfo.productFee = productFee;
100
134
  productSetupInfo.processingFee = processingFee;
101
135
 
@@ -106,7 +140,10 @@ contract ProductService is ComponentServiceBase, IProductService {
106
140
  RiskId riskId,
107
141
  bytes memory data
108
142
  ) external override {
109
- (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
143
+ (
144
+ IRegistry.ObjectInfo memory productInfo,
145
+ IInstance instance
146
+ ) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
110
147
  NftId productNftId = productInfo.nftId;
111
148
  IRisk.RiskInfo memory riskInfo = IRisk.RiskInfo(productNftId, data);
112
149
  instance.createRisk(
@@ -133,432 +170,4 @@ contract ProductService is ComponentServiceBase, IProductService {
133
170
  (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
134
171
  instance.updateRiskState(riskId, state);
135
172
  }
136
-
137
- function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
138
- IRegistry.ObjectInfo memory productInfo;
139
- (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
140
- product = Product(productInfo.objectAddress);
141
- }
142
-
143
- function calculatePremium(
144
- RiskId riskId,
145
- uint256 sumInsuredAmount,
146
- uint256 lifetime,
147
- bytes memory applicationData,
148
- NftId bundleNftId,
149
- ReferralId referralId
150
- )
151
- public
152
- view
153
- override
154
- returns (
155
- uint256 premiumAmount,
156
- uint256 productFeeAmount,
157
- uint256 poolFeeAmount,
158
- uint256 bundleFeeAmount,
159
- uint256 distributionFeeAmount
160
- )
161
- {
162
- Product product = _getAndVerifyInstanceAndProduct();
163
- uint256 netPremiumAmount = product.calculateNetPremium(
164
- sumInsuredAmount,
165
- riskId,
166
- lifetime,
167
- applicationData
168
- );
169
-
170
- (
171
- productFeeAmount,
172
- poolFeeAmount,
173
- bundleFeeAmount,
174
- distributionFeeAmount
175
- ) = _calculateFeeAmounts(
176
- netPremiumAmount,
177
- product,
178
- bundleNftId,
179
- referralId
180
- );
181
-
182
- premiumAmount = netPremiumAmount + productFeeAmount;
183
- premiumAmount += poolFeeAmount + bundleFeeAmount;
184
- premiumAmount += distributionFeeAmount;
185
- }
186
-
187
- function _calculateFeeAmounts(
188
- uint256 netPremiumAmount,
189
- Product product,
190
- NftId bundleNftId,
191
- ReferralId referralId
192
- )
193
- internal
194
- view
195
- returns (
196
- uint256 productFeeAmount,
197
- uint256 poolFeeAmount,
198
- uint256 bundleFeeAmount,
199
- uint256 distributionFeeAmount
200
- )
201
- {
202
- InstanceReader instanceReader;
203
- {
204
- IInstance instance = product.getInstance();
205
- instanceReader = instance.getInstanceReader();
206
- }
207
-
208
- NftId poolNftId = product.getPoolNftId();
209
- IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
210
- require(bundleInfo.poolNftId == poolNftId,"ERROR:PRS-035:BUNDLE_POOL_MISMATCH");
211
-
212
- {
213
- ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(product.getProductNftId());
214
- (productFeeAmount,) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
215
- }
216
- {
217
- ISetup.PoolSetupInfo memory poolSetupInfo = instanceReader.getPoolSetupInfo(poolNftId);
218
- (poolFeeAmount,) = FeeLib.calculateFee(poolSetupInfo.poolFee, netPremiumAmount);
219
- }
220
- {
221
- NftId distributionNftId = product.getDistributionNftId();
222
- ISetup.DistributionSetupInfo memory distributionSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
223
- (distributionFeeAmount,) = FeeLib.calculateFee(distributionSetupInfo.distributionFee, netPremiumAmount);
224
- }
225
-
226
- (bundleFeeAmount,) = FeeLib.calculateFee(bundleInfo.fee, netPremiumAmount);
227
- }
228
-
229
-
230
- function createApplication(
231
- address applicationOwner,
232
- RiskId riskId,
233
- uint256 sumInsuredAmount,
234
- uint256 lifetime,
235
- bytes memory applicationData,
236
- NftId bundleNftId,
237
- ReferralId referralId
238
- ) external override returns (NftId policyNftId) {
239
- (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
240
- // TODO add validations (see create bundle in pool service)
241
-
242
- policyNftId = getRegistryService().registerPolicy(
243
- IRegistry.ObjectInfo(
244
- zeroNftId(),
245
- productInfo.nftId,
246
- POLICY(),
247
- false, // intercepting property for policies is defined on product
248
- address(0),
249
- applicationOwner,
250
- ""
251
- )
252
- );
253
-
254
- (uint256 premiumAmount,,,,) = calculatePremium(
255
- riskId,
256
- sumInsuredAmount,
257
- lifetime,
258
- applicationData,
259
- bundleNftId,
260
- referralId
261
- );
262
-
263
- IPolicy.PolicyInfo memory policyInfo = IPolicy.PolicyInfo(
264
- productInfo.nftId,
265
- bundleNftId,
266
- referralId,
267
- riskId,
268
- sumInsuredAmount,
269
- premiumAmount,
270
- 0,
271
- lifetime,
272
- applicationData,
273
- "",
274
- 0,
275
- 0,
276
- 0,
277
- zeroTimestamp(),
278
- zeroTimestamp(),
279
- zeroTimestamp()
280
- );
281
-
282
- instance.createPolicy(policyNftId, policyInfo);
283
- instance.updatePolicyState(policyNftId, APPLIED());
284
-
285
- // TODO add logging
286
- }
287
-
288
- function _getAndVerifyUnderwritingSetup(
289
- IInstance instance,
290
- InstanceReader instanceReader,
291
- IPolicy.PolicyInfo memory policyInfo,
292
- ISetup.ProductSetupInfo memory productSetupInfo
293
- )
294
- internal
295
- view
296
- returns (
297
- NftId bundleNftId,
298
- IBundle.BundleInfo memory bundleInfo,
299
- uint256 collateralAmount
300
- )
301
- {
302
- // check match between policy and bundle (via pool)
303
- bundleNftId = policyInfo.bundleNftId;
304
- bundleInfo = instanceReader.getBundleInfo(bundleNftId);
305
- require(bundleInfo.poolNftId == productSetupInfo.poolNftId, "POLICY_BUNDLE_MISMATCH");
306
-
307
- // calculate required collateral
308
- NftId poolNftId = productSetupInfo.poolNftId;
309
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
310
-
311
- // obtain remaining return values
312
- collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
313
- }
314
-
315
- function _lockCollateralInBundle(
316
- IInstance instance,
317
- NftId bundleNftId,
318
- IBundle.BundleInfo memory bundleInfo,
319
- NftId policyNftId,
320
- uint256 collateralAmount
321
- )
322
- internal
323
- returns (IBundle.BundleInfo memory)
324
- {
325
- bundleInfo.lockedAmount += collateralAmount;
326
- // FIXME: this
327
- // instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
328
- return bundleInfo;
329
- }
330
-
331
- function _underwriteByPool(
332
- NftId poolNftId,
333
- NftId policyNftId,
334
- IPolicy.PolicyInfo memory policyInfo,
335
- bytes memory bundleFilter,
336
- uint256 collateralAmount
337
- )
338
- internal
339
- {
340
- address poolAddress = getRegistry().getObjectInfo(poolNftId).objectAddress;
341
- IPoolComponent pool = IPoolComponent(poolAddress);
342
- pool.underwrite(
343
- policyNftId,
344
- policyInfo.applicationData,
345
- bundleFilter,
346
- collateralAmount);
347
- }
348
-
349
-
350
- function revoke(
351
- NftId policyNftId
352
- )
353
- external
354
- override
355
- {
356
- require(false, "ERROR:PRS-234:NOT_YET_IMPLEMENTED");
357
- }
358
-
359
-
360
- function underwrite(
361
- NftId policyNftId,
362
- bool requirePremiumPayment,
363
- Timestamp activateAt
364
- )
365
- external
366
- override
367
- {
368
- // check caller is registered product
369
- (
370
- IRegistry.ObjectInfo memory productInfo,
371
- IInstance instance
372
- ) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
373
- InstanceReader instanceReader = instance.getInstanceReader();
374
-
375
- // check match between policy and calling product
376
- NftId productNftId = productInfo.nftId;
377
- // FIXME: this
378
- IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
379
- require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
380
- require(instanceReader.getPolicyState(policyNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
381
-
382
- NftId bundleNftId;
383
- IBundle.BundleInfo memory bundleInfo;
384
- uint256 collateralAmount;
385
- ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
386
-
387
- (
388
- bundleNftId,
389
- bundleInfo,
390
- collateralAmount
391
- ) = _getAndVerifyUnderwritingSetup(
392
- instance,
393
- instanceReader,
394
- policyInfo,
395
- productSetupInfo
396
- );
397
-
398
- // lock bundle collateral
399
- bundleInfo = _lockCollateralInBundle(
400
- instance,
401
- bundleNftId,
402
- bundleInfo,
403
- policyNftId,
404
- collateralAmount);
405
-
406
- // optional activation of policy
407
- if(activateAt > zeroTimestamp()) {
408
- policyInfo.activatedAt = activateAt;
409
- policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
410
- }
411
-
412
- // optional collection of premium
413
- if(requirePremiumPayment) {
414
- uint256 netPremiumAmount = _processPremiumByTreasury(
415
- instance,
416
- productInfo.nftId,
417
- policyNftId,
418
- policyInfo.premiumAmount);
419
-
420
- policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
421
- bundleInfo.balanceAmount += netPremiumAmount;
422
- }
423
-
424
- instance.updatePolicy(policyNftId, policyInfo, UNDERWRITTEN());
425
- _poolService.updateBundle(productInfo.parentNftId, bundleNftId, bundleInfo, KEEP_STATE());
426
-
427
- // involve pool if necessary
428
- {
429
- NftId poolNftId = bundleInfo.poolNftId;
430
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
431
-
432
- // FIXME: use poolInfo.isVerifying ???
433
- if(poolInfo.isIntercepting) {
434
- _underwriteByPool(
435
- poolNftId,
436
- policyNftId,
437
- policyInfo,
438
- bundleInfo.filter,
439
- collateralAmount
440
- );
441
- }
442
- }
443
-
444
- // TODO add logging
445
- }
446
-
447
- function calculateRequiredCollateral(UFixed collateralizationLevel, uint256 sumInsuredAmount) public pure override returns(uint256 collateralAmount) {
448
- UFixed sumInsuredUFixed = UFixedLib.toUFixed(sumInsuredAmount);
449
- UFixed collateralUFixed = collateralizationLevel * sumInsuredUFixed;
450
- return collateralUFixed.toInt();
451
- }
452
-
453
- function collectPremium(NftId policyNftId, Timestamp activateAt) external override {
454
- // check caller is registered product
455
- (IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
456
-
457
- // perform actual token transfers
458
- // FIXME: this
459
- // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
460
- // ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(productInfo.nftId);
461
-
462
- // uint256 premiumAmount = policyInfo.premiumAmount;
463
- // _processPremiumByTreasury(instance, productInfo.nftId, treasuryInfo, policyNftId, premiumAmount);
464
-
465
- // // policy level book keeping for premium paid
466
- // policyInfo.premiumPaidAmount += premiumAmount;
467
-
468
- // // optional activation of policy
469
- // if(activateAt > zeroTimestamp()) {
470
- // require(
471
- // policyInfo.activatedAt.eqz(),
472
- // "ERROR:PRS-030:ALREADY_ACTIVATED");
473
-
474
- // policyInfo.activatedAt = activateAt;
475
- // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
476
-
477
- // instance.updatePolicyState(policyNftId, ACTIVE());
478
- // }
479
-
480
- // instance.setPolicyInfo(policyNftId, policyInfo);
481
-
482
- // TODO add logging
483
- }
484
-
485
- // FIXME: this
486
- function activate(NftId policyNftId, Timestamp activateAt) external override {
487
- // check caller is registered product
488
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
489
-
490
- // IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
491
-
492
- // require(
493
- // policyInfo.activatedAt.eqz(),
494
- // "ERROR:PRS-020:ALREADY_ACTIVATED");
495
-
496
- // policyInfo.activatedAt = activateAt;
497
- // policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
498
-
499
- // instance.setPolicyInfo(policyNftId, policyInfo);
500
- // instance.updatePolicyState(policyNftId, ACTIVE());
501
-
502
- // TODO add logging
503
- }
504
-
505
- function close(
506
- NftId policyNftId
507
- ) external override // solhint-disable-next-line no-empty-blocks
508
- {
509
-
510
- }
511
-
512
- function _getPoolNftId(
513
- IInstance instance,
514
- NftId productNftId
515
- )
516
- internal
517
- view
518
- returns (NftId poolNftid)
519
- {
520
- // FIXME: this
521
- // return instance.getTreasuryInfo(productNftId).poolNftId;
522
- }
523
-
524
-
525
- function _processPremiumByTreasury(
526
- IInstance instance,
527
- NftId productNftId,
528
- NftId policyNftId,
529
- uint256 premiumAmount
530
- )
531
- internal
532
- returns (uint256 netPremiumAmount)
533
- {
534
- // process token transfer(s)
535
- if(premiumAmount > 0) {
536
- // FIXME: this
537
- // TokenHandler tokenHandler = instance.getTokenHandler(productNftId);
538
- // address policyOwner = getRegistry().ownerOf(policyNftId);
539
- // address poolWallet = instance.getComponentWallet(treasuryInfo.poolNftId);
540
- // netPremiumAmount = premiumAmount;
541
- // Fee memory productFee = treasuryInfo.productFee;
542
-
543
- // if (FeeLib.feeIsZero(productFee)) {
544
- // tokenHandler.transfer(
545
- // policyOwner,
546
- // poolWallet,
547
- // premiumAmount
548
- // );
549
- // } else {
550
- // (uint256 feeAmount, uint256 netAmount) = instance.calculateFeeAmount(
551
- // premiumAmount,
552
- // productFee
553
- // );
554
-
555
- // address productWallet = instance.getComponentWallet(productNftId);
556
- // tokenHandler.transfer(policyOwner, productWallet, feeAmount);
557
- // tokenHandler.transfer(policyOwner, poolWallet, netAmount);
558
- // netPremiumAmount = netAmount;
559
- // }
560
- }
561
-
562
- // TODO add logging
563
- }
564
173
  }
@@ -11,35 +11,37 @@ library LibNftIdSet {
11
11
  mapping(NftId nftid => uint256 index) at;
12
12
  }
13
13
 
14
- function add(Set storage set, NftId nftId) external returns(bool added) {
15
- if (set.at[nftId] == 0) {
16
- set.ids.push(nftId);
17
- set.at[nftId] = set.ids.length;
18
- return true;
19
- } else {
20
- return false;
14
+ error ErrorNftIdSetAlreadyAdded(NftId nftId);
15
+ error ErrorNftIdSetNotInSet(NftId nftId);
16
+
17
+
18
+ function add(Set storage set, NftId nftId) external {
19
+ if (set.at[nftId] > 0) {
20
+ revert ErrorNftIdSetAlreadyAdded(nftId);
21
21
  }
22
+
23
+ set.ids.push(nftId);
24
+ set.at[nftId] = set.ids.length;
22
25
  }
23
26
 
24
- function remove(Set storage set, NftId nftId) external returns(bool removed) {
27
+ function remove(Set storage set, NftId nftId) external {
25
28
  uint256 nftIdIndex = set.at[nftId];
26
29
 
27
- if (nftIdIndex > 0) {
28
- uint256 toDeleteIndex = nftIdIndex - 1;
29
- uint256 lastIndex = set.ids.length - 1;
30
-
31
- if (lastIndex != toDeleteIndex) {
32
- NftId lastId = set.ids[lastIndex];
33
- set.ids[toDeleteIndex] = lastId;
34
- set.at[lastId] = nftIdIndex; // Replace lastValue's index to valueIndex
35
- }
36
-
37
- set.ids.pop();
38
- delete set.at[nftId];
39
- return true;
40
- } else {
41
- return false;
30
+ if (nftIdIndex == 0) {
31
+ revert ErrorNftIdSetNotInSet(nftId);
42
32
  }
33
+
34
+ uint256 toDeleteIndex = nftIdIndex - 1;
35
+ uint256 lastIndex = set.ids.length - 1;
36
+
37
+ if (lastIndex != toDeleteIndex) {
38
+ NftId lastId = set.ids[lastIndex];
39
+ set.ids[toDeleteIndex] = lastId;
40
+ set.at[lastId] = nftIdIndex; // Replace lastValue's index to valueIndex
41
+ }
42
+
43
+ set.ids.pop();
44
+ delete set.at[nftId];
43
45
  }
44
46
 
45
47
  function isEmpty(Set storage set) external view returns(bool empty) {
@@ -50,7 +52,7 @@ library LibNftIdSet {
50
52
  return set.at[nftId] > 0;
51
53
  }
52
54
 
53
- function getLength(Set storage set) external view returns(uint256 length) {
55
+ function size(Set storage set) external view returns(uint256 length) {
54
56
  return set.ids.length;
55
57
  }
56
58
 
@@ -39,6 +39,8 @@ function PRODUCT_REGISTRAR_ROLE() pure returns (RoleId) { return RoleIdLib.toRol
39
39
  function DISTRIBUTION_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(10000); }
40
40
  function POOL_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(10100); }
41
41
  function PRODUCT_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(10200); }
42
+ function POLICY_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(10300); }
43
+ function BUNDLE_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(10400); }
42
44
 
43
45
  function INSTANCE_SERVICE_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(11000); }
44
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etherisc/gif-next",
3
- "version": "0.0.2-e1f23dc-329",
3
+ "version": "0.0.2-e2d8c7d-942",
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": {
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/975c16748e8c205fdb3397ef4efe6b12.json"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/975c16748e8c205fdb3397ef4efe6b12.json"
4
- }