@etherisc/gif-next 0.0.2-d64ea51-772 → 0.0.2-d6f24e1-490

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) 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 +139 -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 +775 -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 +33 -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 +6 -1
  49. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  50. package/artifacts/contracts/instance/Instance.sol/Instance.json +131 -85
  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 +38 -28
  57. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  58. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +99 -60
  59. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  60. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +34 -30
  61. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +4 -0
  62. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +272 -0
  63. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  64. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  65. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  66. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  67. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  68. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  70. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  73. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  76. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +2 -2
  78. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +2 -2
  80. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +2 -2
  82. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +80 -0
  86. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  88. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +151 -28
  89. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +31 -15
  91. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +34 -34
  93. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +18 -18
  95. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  96. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  97. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  98. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  99. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  101. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  102. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  103. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  104. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  105. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  106. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  107. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  109. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  110. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  111. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  112. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  113. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  114. package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
  115. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  116. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  117. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  118. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  119. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  120. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  121. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  122. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  123. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  124. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  125. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  126. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  127. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  128. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  129. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  130. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  131. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  132. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  133. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  134. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  135. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +26 -3
  136. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  137. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  138. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  140. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  141. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  144. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  145. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  147. package/contracts/components/BaseComponent.sol +49 -8
  148. package/contracts/components/IBaseComponent.sol +6 -0
  149. package/contracts/components/IPoolComponent.sol +5 -1
  150. package/contracts/components/Pool.sol +27 -6
  151. package/contracts/components/Product.sol +1 -0
  152. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
  153. package/contracts/instance/BundleManager.sol +129 -0
  154. package/contracts/instance/Cloneable.sol +46 -0
  155. package/contracts/instance/IInstance.sol +2 -0
  156. package/contracts/instance/IInstanceBase.sol +26 -0
  157. package/contracts/instance/IInstanceService.sol +5 -3
  158. package/contracts/instance/Instance.sol +25 -10
  159. package/contracts/instance/InstanceAccessManager.sol +6 -6
  160. package/contracts/instance/InstanceBase.sol +41 -0
  161. package/contracts/instance/InstanceService.sol +49 -14
  162. package/contracts/instance/ObjectManager.sol +95 -0
  163. package/contracts/instance/module/ISetup.sol +2 -1
  164. package/contracts/instance/service/IPoolService.sol +12 -2
  165. package/contracts/instance/service/PoolService.sol +100 -14
  166. package/contracts/instance/service/ProductService.sol +18 -11
  167. package/contracts/types/NftIdSet.sol +26 -24
  168. package/package.json +1 -1
  169. package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
  170. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
  171. package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
  172. package/contracts/instance/AccessManagedSimple.sol +0 -115
  173. package/contracts/instance/AccessManagerSimple.sol +0 -692
@@ -7,6 +7,7 @@ import {IInstance} from "../../instance/IInstance.sol";
7
7
  import {IBundle} from "../../instance/module/IBundle.sol";
8
8
  import {TokenHandler} from "../../instance/module/ITreasury.sol";
9
9
  import {ISetup} from "../module/ISetup.sol";
10
+ import {IPolicy} from "../module/IPolicy.sol";
10
11
 
11
12
  import {IVersionable} from "../../shared/IVersionable.sol";
12
13
  import {Versionable} from "../../shared/Versionable.sol";
@@ -18,17 +19,17 @@ import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
18
19
  import {Fee, FeeLib} from "../../types/Fee.sol";
19
20
  import {Version, VersionLib} from "../../types/Version.sol";
20
21
  import {KEEP_STATE, StateId} from "../../types/StateId.sol";
21
- import {zeroTimestamp} from "../../types/Timestamp.sol";
22
+ import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
22
23
 
23
24
  import {IService} from "../../shared/IService.sol";
24
25
  import {Service} from "../../shared/Service.sol";
26
+ import {BundleManager} from "../BundleManager.sol";
25
27
  import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
26
28
  import {IPoolService} from "./IPoolService.sol";
27
29
  import {IRegistryService} from "../../registry/IRegistryService.sol";
28
30
  import {InstanceService} from "../InstanceService.sol";
29
31
  import {InstanceReader} from "../InstanceReader.sol";
30
32
 
31
-
32
33
  string constant POOL_SERVICE_NAME = "PoolService";
33
34
 
34
35
  contract PoolService is
@@ -134,15 +135,14 @@ contract PoolService is
134
135
  // create bundle info in instance
135
136
  instance.createBundle(bundleNftId, bundleInfo);
136
137
 
137
- // TODO add bundle to pool in instance
138
+ BundleManager bundleManager = instance.getBundleManager();
139
+ bundleManager.add(bundleNftId);
138
140
 
139
- // TODO collect capital
140
- // _processStakingByTreasury(
141
- // instanceReader,
142
- // zeroNftId(),
143
- // poolNftId,
144
- // bundleNftId,
145
- // stakingAmount);
141
+ _processStakingByTreasury(
142
+ instanceReader,
143
+ poolNftId,
144
+ bundleNftId,
145
+ stakingAmount);
146
146
 
147
147
  // TODO add logging
148
148
  }
@@ -176,9 +176,88 @@ contract PoolService is
176
176
  instance.updateBundle(bundleNftId, bundleInfo, state);
177
177
  }
178
178
 
179
+ function lockBundle(NftId bundleNftId)
180
+ external
181
+ {
182
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
183
+ BundleManager bundleManager = instance.getBundleManager();
184
+ bundleManager.lock(bundleNftId);
185
+ }
186
+
187
+ function unlockBundle(NftId bundleNftId)
188
+ external
189
+ {
190
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
191
+ BundleManager bundleManager = instance.getBundleManager();
192
+ bundleManager.unlock(bundleNftId);
193
+ }
194
+
195
+ function underwritePolicy(IInstance instance,
196
+ NftId policyNftId,
197
+ NftId bundleNftId,
198
+ uint256 collateralAmount,
199
+ uint256 netPremiumAmount
200
+ )
201
+ external
202
+ onlyService
203
+ {
204
+ InstanceReader instanceReader = instance.getInstanceReader();
205
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
206
+
207
+ // lock collateral
208
+ bundleInfo.lockedAmount += collateralAmount;
209
+ bundleInfo.balanceAmount += netPremiumAmount;
210
+
211
+ instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
212
+
213
+ linkPolicy(instance, policyNftId);
214
+ }
215
+
216
+ /// @dev links policy to bundle
217
+ function linkPolicy(IInstance instance, NftId policyNftId)
218
+ internal
219
+ onlyService
220
+ {
221
+ InstanceReader instanceReader = instance.getInstanceReader();
222
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
223
+
224
+ // ensure policy has not yet been activated
225
+ if (policyInfo.activatedAt.gtz()) {
226
+ revert BundleManager.ErrorBundleManagerErrorPolicyAlreadyActivated(policyNftId);
227
+ }
228
+
229
+ BundleManager bundleManager = instance.getBundleManager();
230
+ bundleManager.linkPolicy(policyNftId);
231
+ }
232
+
233
+ /// @dev unlinks policy from bundle
234
+ function unlinkPolicy(IInstance instance, NftId policyNftId)
235
+ internal
236
+ onlyService
237
+ {
238
+ InstanceReader instanceReader = instance.getInstanceReader();
239
+ IPolicy.PolicyInfo memory policyInfo = instanceReader.getPolicyInfo(policyNftId);
240
+
241
+ // ensure policy has no open claims
242
+ if (policyInfo.openClaimsCount > 0) {
243
+ revert BundleManager.ErrorBundleManagerPolicyWithOpenClaims(
244
+ policyNftId,
245
+ policyInfo.openClaimsCount);
246
+ }
247
+
248
+ // ensure policy is closeable
249
+ if (policyInfo.expiredAt < TimestampLib.blockTimestamp()
250
+ || policyInfo.payoutAmount < policyInfo.sumInsuredAmount)
251
+ {
252
+ revert BundleManager.ErrorBundleManagerPolicyNotCloseable(policyNftId);
253
+ }
254
+
255
+ BundleManager bundleManager = instance.getBundleManager();
256
+ bundleManager.unlinkPolicy(policyNftId);
257
+ }
258
+
179
259
  function _processStakingByTreasury(
180
260
  InstanceReader instanceReader,
181
- NftId productNftId,
182
261
  NftId poolNftId,
183
262
  NftId bundleNftId,
184
263
  uint256 stakingAmount
@@ -187,15 +266,22 @@ contract PoolService is
187
266
  {
188
267
  // process token transfer(s)
189
268
  if(stakingAmount > 0) {
190
- TokenHandler tokenHandler = TokenHandler(instanceReader.getTokenHandler(productNftId));
191
- address bundleOwner = getRegistry().ownerOf(bundleNftId);
192
269
  ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
193
-
270
+ TokenHandler tokenHandler = poolInfo.tokenHandler;
271
+ address bundleOwner = getRegistry().ownerOf(bundleNftId);
272
+ Fee memory stakingFee = poolInfo.stakingFee;
273
+
194
274
  tokenHandler.transfer(
195
275
  bundleOwner,
196
276
  poolInfo.wallet,
197
277
  stakingAmount
198
278
  );
279
+
280
+
281
+ if (! FeeLib.feeIsZero(stakingFee)) {
282
+ (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
283
+ // TODO: track staking fees in pool's state (issue #177)
284
+ }
199
285
  }
200
286
  }
201
287
  }
@@ -323,8 +323,7 @@ contract ProductService is ComponentServiceBase, IProductService {
323
323
  returns (IBundle.BundleInfo memory)
324
324
  {
325
325
  bundleInfo.lockedAmount += collateralAmount;
326
- // FIXME: this
327
- // instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
326
+ // TODO: track policy associated to bundle in bundlemanager (tbd) and how much is locked for it
328
327
  return bundleInfo;
329
328
  }
330
329
 
@@ -381,9 +380,11 @@ contract ProductService is ComponentServiceBase, IProductService {
381
380
  NftId bundleNftId;
382
381
  IBundle.BundleInfo memory bundleInfo;
383
382
  uint256 collateralAmount;
383
+ uint256 netPremiumAmount = 0; // > 0 if immediate premium payment
384
384
  {
385
385
  ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(productNftId);
386
-
386
+ IBundle.BundleInfo memory bundleInfo;
387
+
387
388
  (
388
389
  bundleNftId,
389
390
  bundleInfo,
@@ -396,6 +397,15 @@ contract ProductService is ComponentServiceBase, IProductService {
396
397
  );
397
398
  }
398
399
 
400
+
401
+ // lock bundle collateral
402
+ bundleInfo = _lockCollateralInBundle(
403
+ instance,
404
+ bundleNftId,
405
+ bundleInfo,
406
+ policyNftId,
407
+ collateralAmount);
408
+
399
409
  // lock bundle collateral
400
410
  bundleInfo = _lockCollateralInBundle(
401
411
  instance,
@@ -414,28 +424,25 @@ contract ProductService is ComponentServiceBase, IProductService {
414
424
 
415
425
  // optional collection of premium
416
426
  if(requirePremiumPayment) {
417
- uint256 netPremiumAmount = _processPremiumByTreasury(
427
+ netPremiumAmount = _processPremiumByTreasury(
418
428
  instance,
419
429
  productInfo.nftId,
420
430
  policyNftId,
421
431
  policyInfo.premiumAmount);
422
432
 
423
433
  policyInfo.premiumPaidAmount += policyInfo.premiumAmount;
424
- bundleInfo.balanceAmount += netPremiumAmount;
425
434
  }
426
435
 
436
+ _poolService.underwritePolicy(instance, policyNftId, bundleNftId, collateralAmount, netPremiumAmount);
427
437
  instance.updatePolicy(policyNftId, policyInfo, newPolicyState);
428
- _poolService.updateBundle(productInfo.parentNftId, bundleNftId, bundleInfo, KEEP_STATE());
429
438
 
430
439
  // involve pool if necessary
431
440
  {
432
- NftId poolNftId = bundleInfo.poolNftId;
433
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
441
+ ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(bundleInfo.poolNftId);
434
442
 
435
- // FIXME: use poolInfo.isVerifying ???
436
- if(poolInfo.isIntercepting) {
443
+ if(poolInfo.isConfirmingApplication) {
437
444
  _underwriteByPool(
438
- poolNftId,
445
+ bundleInfo.poolNftId,
439
446
  policyNftId,
440
447
  policyInfo,
441
448
  bundleInfo.filter,
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etherisc/gif-next",
3
- "version": "0.0.2-d64ea51-772",
3
+ "version": "0.0.2-d6f24e1-490",
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/6e730571a8919f24f85e81e92f606870.json"
4
- }
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/6e730571a8919f24f85e81e92f606870.json"
4
- }