@etherisc/gif-next 0.0.2-db1e1e4-828 → 0.0.2-db81915-875

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  2. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.json +16 -0
  4. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  5. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  9. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  10. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +1 -1
  11. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  12. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
  13. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  14. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  15. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +346 -102
  16. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  17. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  18. package/artifacts/contracts/instance/Instance.sol/Instance.json +276 -289
  19. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  20. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  21. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  22. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +154 -40
  23. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  24. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +62 -101
  25. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  26. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +32 -32
  27. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  28. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
  29. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  30. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  31. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  32. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  33. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +8 -8
  34. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  35. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +6 -6
  36. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  37. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  38. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  39. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  40. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  41. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  42. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  43. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  44. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  45. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +71 -50
  46. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  47. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +18 -10
  48. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  49. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +79 -44
  50. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  51. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +27 -23
  52. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  53. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +284 -61
  54. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  55. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +52 -8
  56. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  57. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +42 -66
  58. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  59. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +22 -34
  60. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +37 -32
  62. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  63. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +27 -0
  64. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  65. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +173 -46
  66. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  67. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  68. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +353 -22
  69. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +4 -4
  71. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  72. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +481 -62
  74. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +65 -21
  76. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +12 -12
  78. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +5 -5
  80. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +2 -2
  82. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +2 -2
  84. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  85. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  86. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  87. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  88. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  89. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  90. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  91. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  92. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  93. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  94. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  95. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  96. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  97. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +2 -2
  98. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  99. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  100. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  101. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  102. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  103. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  104. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  105. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  106. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  107. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  109. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  110. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  111. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  112. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  113. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  114. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  115. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  116. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  117. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  118. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  119. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  120. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  121. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  122. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  123. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  124. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  125. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  126. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  127. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  128. package/artifacts/contracts/test/TestService.sol/TestService.json +2 -2
  129. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  130. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  131. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  132. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  133. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  134. package/artifacts/contracts/types/Amount.sol/AmountLib.dbg.json +1 -1
  135. package/artifacts/contracts/types/Amount.sol/AmountLib.json +28 -4
  136. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  137. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  138. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.json +83 -4
  140. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  141. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  142. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  144. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  145. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  147. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  148. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  149. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  151. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  152. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.json +116 -7
  154. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +2 -2
  156. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  158. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  160. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  163. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +17 -4
  165. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  169. package/contracts/components/Distribution.sol +6 -2
  170. package/contracts/components/IPoolComponent.sol +1 -1
  171. package/contracts/components/Pool.sol +3 -4
  172. package/contracts/components/Product.sol +137 -59
  173. package/contracts/instance/BundleManager.sol +3 -4
  174. package/contracts/instance/IInstance.sol +25 -21
  175. package/contracts/instance/IInstanceService.sol +0 -4
  176. package/contracts/instance/Instance.sol +85 -103
  177. package/contracts/instance/InstanceReader.sol +30 -4
  178. package/contracts/instance/InstanceService.sol +11 -28
  179. package/contracts/instance/base/Lifecycle.sol +12 -4
  180. package/contracts/instance/module/IPolicy.sol +11 -6
  181. package/contracts/instance/service/ApplicationService.sol +10 -5
  182. package/contracts/instance/service/BundleService.sol +8 -3
  183. package/contracts/instance/service/ClaimService.sol +111 -23
  184. package/contracts/instance/service/DistributionService.sol +14 -18
  185. package/contracts/instance/service/IApplicationService.sol +3 -7
  186. package/contracts/instance/service/IBundleService.sol +3 -0
  187. package/contracts/instance/service/IClaimService.sol +46 -15
  188. package/contracts/instance/service/IPolicyService.sol +70 -5
  189. package/contracts/instance/service/PolicyService.sol +219 -40
  190. package/contracts/instance/service/ProductService.sol +1 -1
  191. package/contracts/types/Amount.sol +5 -0
  192. package/contracts/types/ClaimId.sol +25 -2
  193. package/contracts/types/ObjectType.sol +5 -5
  194. package/contracts/types/PayoutId.sol +33 -5
  195. package/contracts/types/StateId.sol +6 -2
  196. package/contracts/types/Timestamp.sol +5 -0
  197. package/package.json +1 -1
@@ -14,17 +14,21 @@ import {ISetup} from "../module/ISetup.sol";
14
14
 
15
15
  import {TokenHandler} from "../../shared/TokenHandler.sol";
16
16
 
17
+ import {Amount, AmountLib} from "../../types/Amount.sol";
18
+ import {ClaimId, ClaimIdLib} from "../../types/ClaimId.sol";
17
19
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
18
20
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
19
- import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
20
- import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
21
+ import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE, CLAIM} from "../../types/ObjectType.sol";
22
+ import {APPLIED, COLLATERALIZED, ACTIVE, KEEP_STATE, CLOSED, DECLINED, CONFIRMED} from "../../types/StateId.sol";
21
23
  import {NftId, NftIdLib} from "../../types/NftId.sol";
24
+ import {PayoutId, PayoutIdLib} from "../../types/PayoutId.sol";
22
25
  import {StateId} from "../../types/StateId.sol";
23
26
  import {VersionPart} from "../../types/Version.sol";
24
27
 
25
28
  import {ComponentService} from "../base/ComponentService.sol";
26
29
  import {IApplicationService} from "./IApplicationService.sol";
27
30
  import {IBundleService} from "./IBundleService.sol";
31
+ import {IClaimService} from "./IClaimService.sol";
28
32
  import {IDistributionService} from "./IDistributionService.sol";
29
33
  import {InstanceReader} from "../InstanceReader.sol";
30
34
  import {IPolicyService} from "./IPolicyService.sol";
@@ -40,10 +44,11 @@ contract PolicyService is
40
44
  using NftIdLib for NftId;
41
45
  using TimestampLib for Timestamp;
42
46
 
43
- IPoolService internal _poolService;
44
- IBundleService internal _bundleService;
45
47
  IApplicationService internal _applicationService;
48
+ IBundleService internal _bundleService;
49
+ IClaimService internal _claimService;
46
50
  IDistributionService internal _distributionService;
51
+ IPoolService internal _poolService;
47
52
 
48
53
  event LogProductServiceSender(address sender);
49
54
 
@@ -64,6 +69,7 @@ contract PolicyService is
64
69
  VersionPart majorVersion = getVersion().toMajorPart();
65
70
  _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), majorVersion));
66
71
  _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), majorVersion));
72
+ _claimService = IClaimService(getRegistry().getServiceAddress(CLAIM(), majorVersion));
67
73
  _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), majorVersion));
68
74
  _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion));
69
75
 
@@ -82,32 +88,6 @@ contract PolicyService is
82
88
  product = Product(productInfo.objectAddress);
83
89
  }
84
90
 
85
- // function _getAndVerifyUnderwritingSetup(
86
- // IInstance instance,
87
- // InstanceReader instanceReader,
88
- // IPolicy.PolicyInfo memory policyInfo,
89
- // ISetup.ProductSetupInfo memory productSetupInfo
90
- // )
91
- // internal
92
- // view
93
- // returns (
94
- // NftId poolNftId,
95
- // IComponents.PoolInfo memory poolInfo,
96
- // NftId bundleNftId,
97
- // IBundle.BundleInfo memory bundleInfo
98
- // )
99
- // {
100
- // // check match between policy and bundle (via pool)
101
- // poolNftId = productSetupInfo.poolNftId;
102
- // bundleNftId = policyInfo.bundleNftId;
103
- // bundleInfo = instanceReader.getBundleInfo(bundleNftId);
104
- // require(bundleInfo.poolNftId == poolNftId, "BUNDLE_POOL_MISMATCH");
105
-
106
- // // calculate required collateral
107
- // IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
108
- // poolInfo = abi.decode(componentInfo.data, (IComponents.PoolInfo));
109
- // }
110
-
111
91
 
112
92
  function decline(
113
93
  NftId policyNftId
@@ -120,7 +100,7 @@ contract PolicyService is
120
100
 
121
101
 
122
102
  /// @dev underwites application which includes the locking of the required collateral from the pool.
123
- function underwrite(
103
+ function collateralize(
124
104
  NftId applicationNftId, // = policyNftId
125
105
  bool requirePremiumPayment,
126
106
  Timestamp activateAt
@@ -139,7 +119,7 @@ contract PolicyService is
139
119
  // check policy is in state applied
140
120
  require(instanceReader.getPolicyState(applicationNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
141
121
 
142
- StateId newPolicyState = UNDERWRITTEN();
122
+ StateId newPolicyState = COLLATERALIZED();
143
123
 
144
124
  // optional activation of policy
145
125
  if(activateAt > zeroTimestamp()) {
@@ -269,6 +249,7 @@ contract PolicyService is
269
249
  revert ErrorIPolicyServicePolicyAlreadyClosed(policyNftId);
270
250
  }
271
251
 
252
+ // TODO consider to allow for underpaid premiums (with the effects of reducing max payouts accordingly)
272
253
  if (policyInfo.premiumAmount != policyInfo.premiumPaidAmount) {
273
254
  revert ErrorIPolicyServicePremiumNotFullyPaid(policyNftId, policyInfo.premiumAmount, policyInfo.premiumPaidAmount);
274
255
  }
@@ -277,10 +258,6 @@ contract PolicyService is
277
258
  revert ErrorIPolicyServiceOpenClaims(policyNftId, policyInfo.openClaimsCount);
278
259
  }
279
260
 
280
- if (TimestampLib.blockTimestamp().lte(policyInfo.expiredAt) && (policyInfo.payoutAmount < policyInfo.sumInsuredAmount)) {
281
- revert ErrorIPolicyServicePolicyHasNotExpired(policyNftId, policyInfo.expiredAt);
282
- }
283
-
284
261
  policyInfo.closedAt = TimestampLib.blockTimestamp();
285
262
 
286
263
  _poolService.releaseCollateral(
@@ -291,6 +268,205 @@ contract PolicyService is
291
268
  instance.updatePolicy(policyNftId, policyInfo, CLOSED());
292
269
  }
293
270
 
271
+ function submitClaim(
272
+ NftId policyNftId,
273
+ Amount claimAmount,
274
+ bytes memory claimData
275
+ )
276
+ external
277
+ virtual
278
+ returns (ClaimId claimId)
279
+ {
280
+ (
281
+ IInstance instance,
282
+ InstanceReader instanceReader,
283
+ IPolicy.PolicyInfo memory policyInfo
284
+ ) = _verifyCallerWithPolicy(policyNftId);
285
+
286
+ // check policy is in its active period
287
+ if(policyInfo.activatedAt.eqz() || TimestampLib.blockTimestamp() >= policyInfo.expiredAt) {
288
+ revert ErrorPolicyServicePolicyNotOpen(policyNftId);
289
+ }
290
+
291
+ // check policy including this claim is still within sum insured
292
+ if(policyInfo.payoutAmount.toInt() + claimAmount.toInt() > policyInfo.sumInsuredAmount) {
293
+ revert ErrorPolicyServiceClaimExceedsSumInsured(
294
+ policyNftId,
295
+ AmountLib.toAmount(policyInfo.sumInsuredAmount),
296
+ AmountLib.toAmount(policyInfo.payoutAmount.toInt() + claimAmount.toInt()));
297
+ }
298
+
299
+ // create new claim
300
+ claimId = ClaimIdLib.toClaimId(policyInfo.claimsCount + 1);
301
+ _claimService.submit(instance, policyNftId, claimId, claimAmount, claimData);
302
+
303
+ // update and save policy info with instance
304
+ policyInfo.claimsCount += 1;
305
+ policyInfo.openClaimsCount += 1;
306
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
307
+
308
+ emit LogPolicyServiceClaimSubmitted(policyNftId, claimId, claimAmount);
309
+ }
310
+
311
+ function confirmClaim(
312
+ NftId policyNftId,
313
+ ClaimId claimId,
314
+ Amount confirmedAmount
315
+ )
316
+ external
317
+ {
318
+ (
319
+ IInstance instance,
320
+ InstanceReader instanceReader,
321
+ IPolicy.PolicyInfo memory policyInfo
322
+ ) = _verifyCallerWithPolicy(policyNftId);
323
+
324
+ // check/update claim info
325
+ _claimService.confirm(instance, instanceReader, policyNftId, claimId, confirmedAmount);
326
+
327
+ // update and save policy info with instance
328
+ instance.updatePolicy(policyNftId, policyInfo, CONFIRMED());
329
+
330
+ emit LogPolicyServiceClaimConfirmed(policyNftId, claimId, confirmedAmount);
331
+ }
332
+
333
+ function declineClaim(
334
+ NftId policyNftId,
335
+ ClaimId claimId
336
+ )
337
+ external
338
+ {
339
+ (
340
+ IInstance instance,
341
+ InstanceReader instanceReader,
342
+ IPolicy.PolicyInfo memory policyInfo
343
+ ) = _verifyCallerWithPolicy(policyNftId);
344
+
345
+ // check/update claim info
346
+ _claimService.decline(instance, instanceReader, policyNftId, claimId);
347
+
348
+ // update and save policy info with instance
349
+ policyInfo.openClaimsCount -= 1;
350
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
351
+
352
+ emit LogPolicyServiceClaimDeclined(policyNftId, claimId);
353
+ }
354
+
355
+ function closeClaim(
356
+ NftId policyNftId,
357
+ ClaimId claimId
358
+ )
359
+ external
360
+ {
361
+ (
362
+ IInstance instance,
363
+ InstanceReader instanceReader,
364
+ IPolicy.PolicyInfo memory policyInfo
365
+ ) = _verifyCallerWithPolicy(policyNftId);
366
+
367
+ // check/update claim info
368
+ _claimService.close(instance, instanceReader, policyNftId, claimId);
369
+
370
+ // update and save policy info with instance
371
+ policyInfo.openClaimsCount -= 1;
372
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
373
+
374
+ emit LogPolicyServiceClaimClosed(policyNftId, claimId);
375
+ }
376
+
377
+ function createPayout(
378
+ NftId policyNftId,
379
+ ClaimId claimId,
380
+ Amount amount,
381
+ bytes memory data
382
+ )
383
+ external
384
+ returns (PayoutId payoutId)
385
+ {
386
+ (
387
+ IInstance instance,
388
+ InstanceReader instanceReader,
389
+ IPolicy.PolicyInfo memory policyInfo
390
+ ) = _verifyCallerWithPolicy(policyNftId);
391
+
392
+ IPolicy.ClaimInfo memory claimInfo = instanceReader.getClaimInfo(policyNftId, claimId);
393
+ StateId claimState = instanceReader.getClaimState(policyNftId, claimId);
394
+
395
+ // TODO add checks
396
+ // claim needs to be open
397
+ // claim.paidAmount + amount <= claim.claimAmount
398
+
399
+ // check/update claim info
400
+ uint8 claimNo = claimInfo.payoutsCount + 1;
401
+ payoutId = PayoutIdLib.toPayoutId(claimId, claimNo);
402
+ _claimService.createPayout(
403
+ instance,
404
+ policyNftId,
405
+ payoutId,
406
+ amount,
407
+ data);
408
+
409
+ // update and save policy info with instance
410
+ policyInfo.payoutAmount.add(amount);
411
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
412
+
413
+ emit LogPolicyServicePayoutCreated(policyNftId, payoutId, amount);
414
+ }
415
+
416
+ function processPayout(
417
+ NftId policyNftId,
418
+ PayoutId payoutId
419
+ )
420
+ external
421
+ {
422
+ (
423
+ IInstance instance,
424
+ InstanceReader instanceReader,
425
+ IPolicy.PolicyInfo memory policyInfo
426
+ ) = _verifyCallerWithPolicy(policyNftId);
427
+
428
+ // check/update claim info
429
+ (
430
+ Amount amount,
431
+ bool payoutIsClosingClaim
432
+ ) = _claimService.processPayout(
433
+ instance,
434
+ instanceReader,
435
+ policyNftId,
436
+ payoutId);
437
+
438
+ // update policy info if affected by processed payout
439
+ if(payoutIsClosingClaim) {
440
+ policyInfo.openClaimsCount -= 1;
441
+ instance.updatePolicy(policyNftId, policyInfo, KEEP_STATE());
442
+ }
443
+
444
+ emit LogPolicyServicePayoutProcessed(policyNftId, payoutId, amount);
445
+ }
446
+
447
+ function _verifyCallerWithPolicy(
448
+ NftId policyNftId
449
+ )
450
+ internal
451
+ returns (
452
+ IInstance instance,
453
+ InstanceReader instanceReader,
454
+ IPolicy.PolicyInfo memory policyInfo
455
+ )
456
+ {
457
+ NftId productNftId;
458
+ (productNftId,, instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
459
+ instanceReader = instance.getInstanceReader();
460
+
461
+ // check caller(product) policy match
462
+ policyInfo = instanceReader.getPolicyInfo(policyNftId);
463
+ if(policyInfo.productNftId != productNftId) {
464
+ revert ErrorPolicyServicePolicyProductMismatch(policyNftId,
465
+ policyInfo.productNftId,
466
+ productNftId);
467
+ }
468
+ }
469
+
294
470
  function _getPoolNftId(
295
471
  IInstance instance,
296
472
  NftId productNftId
@@ -308,13 +484,13 @@ contract PolicyService is
308
484
  function _processPremiumByTreasury(
309
485
  IInstance instance,
310
486
  NftId policyNftId,
311
- uint256 premiumAmount
487
+ uint256 premiumExpectedAmount
312
488
  )
313
489
  internal
314
490
  returns (uint256 netPremiumAmount)
315
491
  {
316
492
  // process token transfer(s)
317
- if(premiumAmount > 0) {
493
+ if(premiumExpectedAmount > 0) {
318
494
  NftId productNftId = getRegistry().getObjectInfo(policyNftId).parentNftId;
319
495
  ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
320
496
  IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
@@ -331,8 +507,11 @@ contract PolicyService is
331
507
  policyInfo.referralId
332
508
  );
333
509
 
334
- if (premium.premiumAmount != premiumAmount) {
335
- revert ErrorIPolicyServicePremiumMismatch(policyNftId, premiumAmount, premium.premiumAmount);
510
+ if (premium.premiumAmount != premiumExpectedAmount) {
511
+ revert ErrorIPolicyServicePremiumMismatch(
512
+ policyNftId,
513
+ premiumExpectedAmount,
514
+ premium.premiumAmount);
336
515
  }
337
516
 
338
517
  // move product fee to product wallet
@@ -24,7 +24,7 @@ import {Timestamp, zeroTimestamp} from "../../types/Timestamp.sol";
24
24
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
25
25
  import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
26
26
  import {ObjectType, PRODUCT, POOL, POLICY} from "../../types/ObjectType.sol";
27
- import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE} from "../../types/StateId.sol";
27
+ import {APPLIED, ACTIVE, KEEP_STATE} from "../../types/StateId.sol";
28
28
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
29
29
  import {Fee, FeeLib} from "../../types/Fee.sol";
30
30
  import {ReferralId} from "../../types/Referral.sol";
@@ -9,6 +9,7 @@ using {
9
9
  AmountLib.eqz,
10
10
  AmountLib.gtz,
11
11
  AmountLib.toInt,
12
+ AmountLib.add,
12
13
  AmountLib.toUFixed
13
14
  } for Amount global;
14
15
 
@@ -45,6 +46,10 @@ library AmountLib {
45
46
  return Amount.unwrap(amount) > 0;
46
47
  }
47
48
 
49
+ function add(Amount a1, Amount a2) public pure returns (Amount) {
50
+ return Amount.wrap(Amount.unwrap(a1) + Amount.unwrap(a2));
51
+ }
52
+
48
53
  function toInt(Amount amount) public pure returns (uint256) {
49
54
  return uint256(uint96(Amount.unwrap(amount)));
50
55
  }
@@ -4,13 +4,18 @@ pragma solidity ^0.8.20;
4
4
  // uint16 allows for 65'535 claims per policy
5
5
  type ClaimId is uint16;
6
6
 
7
+ import {CLAIM} from "./ObjectType.sol";
8
+ import {Key32, KeyId, Key32Lib} from "./Key32.sol";
9
+ import {NftId} from "./NftId.sol";
10
+
7
11
  // type bindings
8
12
  using {
9
13
  eqClaimId as ==,
10
14
  neClaimId as !=,
11
15
  ClaimIdLib.eqz,
12
16
  ClaimIdLib.gtz,
13
- ClaimIdLib.toInt
17
+ ClaimIdLib.toInt,
18
+ ClaimIdLib.toKey32
14
19
  } for ClaimId global;
15
20
 
16
21
 
@@ -25,10 +30,14 @@ function neClaimId(ClaimId a, ClaimId b) pure returns (bool isDifferent) {
25
30
 
26
31
  // library functions that operate on user defined type
27
32
  library ClaimIdLib {
28
- /// @dev Converts the ClaimId to a uint.
33
+ /// @dev claim id min value (0), use only for non-initialized values
29
34
  function zero() public pure returns (ClaimId) {
30
35
  return ClaimId.wrap(0);
31
36
  }
37
+ /// @dev claim id max value (2**16-1), use only for non-initialized values
38
+ function max() public pure returns (ClaimId) {
39
+ return ClaimId.wrap(type(uint16).max);
40
+ }
32
41
 
33
42
  /// @dev Converts an uint into a ClaimId.
34
43
  function toClaimId(uint256 a) public pure returns (ClaimId) {
@@ -40,6 +49,20 @@ library ClaimIdLib {
40
49
  return uint16(ClaimId.unwrap(a));
41
50
  }
42
51
 
52
+ /// @dev Converts the ClaimId and NftId to a Key32.
53
+ function toKey32(ClaimId claimId, NftId policyNftId) public pure returns (Key32) {
54
+ return Key32Lib.toKey32(CLAIM(), toKeyId(claimId, policyNftId));
55
+ }
56
+
57
+ /// @dev Converts the ClaimId and NftId to a Key32.
58
+ function toKeyId(ClaimId claimId, NftId policyNftId) public pure returns (KeyId) {
59
+ return KeyId.wrap(
60
+ bytes31(
61
+ bytes14(
62
+ uint112(
63
+ NftId.unwrap(policyNftId) << 16 + ClaimId.unwrap(claimId)))));
64
+ }
65
+
43
66
  /// @dev Returns true if the value is non-zero (> 0).
44
67
  function gtz(ClaimId a) public pure returns (bool) {
45
68
  return ClaimId.unwrap(a) > 0;
@@ -86,6 +86,10 @@ function POOL() pure returns (ObjectType) {
86
86
  return toObjectType(140);
87
87
  }
88
88
 
89
+ function BUNDLE() pure returns (ObjectType) {
90
+ return toObjectType(220);
91
+ }
92
+
89
93
  function RISK() pure returns (ObjectType) {
90
94
  return toObjectType(200);
91
95
  }
@@ -102,12 +106,8 @@ function CLAIM() pure returns (ObjectType) {
102
106
  return toObjectType(212);
103
107
  }
104
108
 
105
- function BUNDLE() pure returns (ObjectType) {
106
- return toObjectType(220);
107
- }
108
-
109
109
  function PAYOUT() pure returns (ObjectType) {
110
- return toObjectType(212);
110
+ return toObjectType(213);
111
111
  }
112
112
 
113
113
  /// @dev Converts the uint8 to a ObjectType.
@@ -4,13 +4,21 @@ pragma solidity ^0.8.20;
4
4
  // uint24 allows for 65'535 claims with 255 payouts each per policy
5
5
  type PayoutId is uint24;
6
6
 
7
+ import {ClaimId} from "./ClaimId.sol";
8
+ import {PAYOUT} from "./ObjectType.sol";
9
+ import {Key32, KeyId, Key32Lib} from "./Key32.sol";
10
+ import {NftId} from "./NftId.sol";
11
+
7
12
  // type bindings
8
13
  using {
9
14
  eqPayoutId as ==,
10
15
  nePayoutId as !=,
11
16
  PayoutIdLib.eqz,
12
17
  PayoutIdLib.gtz,
13
- PayoutIdLib.toInt
18
+ PayoutIdLib.toInt,
19
+ PayoutIdLib.toClaimId,
20
+ PayoutIdLib.toPayoutNo,
21
+ PayoutIdLib.toKey32
14
22
  } for PayoutId global;
15
23
 
16
24
 
@@ -23,8 +31,6 @@ function nePayoutId(PayoutId a, PayoutId b) pure returns (bool isDifferent) {
23
31
  return PayoutId.unwrap(a) != PayoutId.unwrap(b);
24
32
  }
25
33
 
26
- // TODO come up with a way to code claim id into payout id
27
- // eg payoutId.getClaimId(), payoutId.getPayoutNo()
28
34
  // library functions that operate on user defined type
29
35
  library PayoutIdLib {
30
36
  /// @dev Converts the PayoutId to a uint.
@@ -33,8 +39,16 @@ library PayoutIdLib {
33
39
  }
34
40
 
35
41
  /// @dev Converts an uint into a PayoutId.
36
- function toPayoutId(uint256 a) public pure returns (PayoutId) {
37
- return PayoutId.wrap(uint24(a));
42
+ function toPayoutId(ClaimId claimId, uint8 payoutNo) public pure returns (PayoutId) {
43
+ return PayoutId.wrap((ClaimId.unwrap(claimId) << 8) + payoutNo);
44
+ }
45
+
46
+ function toClaimId(PayoutId payoutId) public pure returns (ClaimId) {
47
+ return ClaimId.wrap(uint16(PayoutId.unwrap(payoutId) >> 8));
48
+ }
49
+
50
+ function toPayoutNo(PayoutId payoutId) public pure returns (uint8) {
51
+ return uint8(PayoutId.unwrap(payoutId) & 255);
38
52
  }
39
53
 
40
54
  /// @dev Converts the PayoutId to a uint.
@@ -51,4 +65,18 @@ library PayoutIdLib {
51
65
  function eqz(PayoutId a) public pure returns (bool) {
52
66
  return PayoutId.unwrap(a) == 0;
53
67
  }
68
+
69
+ /// @dev Converts the PayoutId and NftId to a Key32.
70
+ function toKey32(PayoutId payoutId, NftId policyNftId) public pure returns (Key32) {
71
+ return Key32Lib.toKey32(PAYOUT(), toKeyId(payoutId, policyNftId));
72
+ }
73
+
74
+ /// @dev Converts the PayoutId and NftId to a Key32.
75
+ function toKeyId(PayoutId payoutId, NftId policyNftId) public pure returns (KeyId) {
76
+ return KeyId.wrap(
77
+ bytes31(
78
+ bytes15(
79
+ uint120(
80
+ (NftId.unwrap(policyNftId) << 24) + PayoutId.unwrap(payoutId)))));
81
+ }
54
82
  }
@@ -26,14 +26,18 @@ function DECLINED() pure returns (StateId) {
26
26
  return toStateId(30);
27
27
  }
28
28
 
29
- function UNDERWRITTEN() pure returns (StateId) {
29
+ function COLLATERALIZED() pure returns (StateId) {
30
30
  return toStateId(40);
31
31
  }
32
32
 
33
- function CONFIRMED() pure returns (StateId) {
33
+ function SUBMITTED() pure returns (StateId) {
34
34
  return toStateId(50);
35
35
  }
36
36
 
37
+ function CONFIRMED() pure returns (StateId) {
38
+ return toStateId(51);
39
+ }
40
+
37
41
  function EXPECTED() pure returns (StateId) {
38
42
  return toStateId(60);
39
43
  }
@@ -60,6 +60,11 @@ function zeroTimestamp() pure returns (Timestamp) {
60
60
  }
61
61
 
62
62
  library TimestampLib {
63
+
64
+ function zero() public pure returns (Timestamp) {
65
+ return toTimestamp(0);
66
+ }
67
+
63
68
  function blockTimestamp() public view returns (Timestamp) {
64
69
  return Timestamp.wrap(uint40(block.timestamp));
65
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etherisc/gif-next",
3
- "version": "0.0.2-db1e1e4-828",
3
+ "version": "0.0.2-db81915-875",
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": {