@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
@@ -22,18 +22,19 @@ import {TokenHandler} from "../../shared/TokenHandler.sol";
22
22
  import {IVersionable} from "../../shared/IVersionable.sol";
23
23
  import {Versionable} from "../../shared/Versionable.sol";
24
24
 
25
+ import {Amount, AmountLib} from "../../types/Amount.sol";
25
26
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
26
27
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
27
28
  import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
28
29
  import {ObjectType, INSTANCE, PRODUCT, POOL, APPLICATION, POLICY, CLAIM, BUNDLE} from "../../types/ObjectType.sol";
29
- import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
30
+ import {SUBMITTED, ACTIVE, KEEP_STATE, DECLINED, CONFIRMED, CLOSED} from "../../types/StateId.sol";
30
31
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
31
32
  import {Fee, FeeLib} from "../../types/Fee.sol";
32
33
  import {ReferralId} from "../../types/Referral.sol";
33
34
  import {RiskId} from "../../types/RiskId.sol";
34
35
  import {StateId} from "../../types/StateId.sol";
35
- import {ClaimId} from "../../types/ClaimId.sol";
36
- import {PayoutId} from "../../types/PayoutId.sol";
36
+ import {ClaimId, ClaimIdLib} from "../../types/ClaimId.sol";
37
+ import {PayoutId, PayoutIdLib} from "../../types/PayoutId.sol";
37
38
  import {Version, VersionLib} from "../../types/Version.sol";
38
39
 
39
40
  import {ComponentService} from "../base/ComponentService.sol";
@@ -50,6 +51,7 @@ contract ClaimService is
50
51
  IClaimService
51
52
  {
52
53
 
54
+ IPoolService internal _poolService;
53
55
 
54
56
  function _initialize(
55
57
  address owner,
@@ -65,6 +67,9 @@ contract ClaimService is
65
67
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
66
68
 
67
69
  initializeService(registryAddress, address(0), owner);
70
+
71
+ _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getVersion().toMajorPart()));
72
+
68
73
  registerInterface(type(IClaimService).interfaceId);
69
74
  }
70
75
 
@@ -74,67 +79,127 @@ contract ClaimService is
74
79
  }
75
80
 
76
81
 
77
- function createClaim(
82
+ function submit(
83
+ IInstance instance,
78
84
  NftId policyNftId,
79
- uint256 claimAmount,
85
+ ClaimId claimId,
86
+ Amount claimAmount,
80
87
  bytes memory claimData
81
88
  )
82
89
  external
83
90
  virtual
84
- returns (ClaimId)
91
+ // TODO add restricted and grant to policy service
85
92
  {
86
-
93
+ instance.createClaim(
94
+ policyNftId,
95
+ claimId,
96
+ IPolicy.ClaimInfo(
97
+ claimAmount,
98
+ AmountLib.zero(), // paidAmount
99
+ 0, // payoutsCount
100
+ 0, // openPayoutsCount
101
+ claimData,
102
+ TimestampLib.zero())); // closedAt
87
103
  }
88
104
 
89
105
 
90
- function confirmClaim(NftId policyNftId, ClaimId claimId, uint256 claimAmount)
106
+ function confirm(
107
+ IInstance instance,
108
+ InstanceReader instanceReader,
109
+ NftId policyNftId,
110
+ ClaimId claimId,
111
+ Amount confirmedAmount
112
+ )
91
113
  external
92
114
  virtual
93
- // solhint-disable-next-line no-empty-blocks
94
115
  {
95
-
116
+ IPolicy.ClaimInfo memory claimInfo = _verifyClaim(instanceReader, policyNftId, claimId, SUBMITTED());
117
+ claimInfo.claimAmount = confirmedAmount;
118
+ instance.updateClaim(policyNftId, claimId, claimInfo, CONFIRMED());
96
119
  }
97
120
 
98
-
99
- function declineClaim(NftId policyNftId, ClaimId claimId)
121
+ function decline(
122
+ IInstance instance,
123
+ InstanceReader instanceReader,
124
+ NftId policyNftId,
125
+ ClaimId claimId
126
+ )
100
127
  external
101
128
  virtual
102
- // solhint-disable-next-line no-empty-blocks
103
129
  {
104
-
130
+ IPolicy.ClaimInfo memory claimInfo = _verifyClaim(instanceReader, policyNftId, claimId, SUBMITTED());
131
+ claimInfo.closedAt = TimestampLib.blockTimestamp();
132
+ instance.updateClaim(policyNftId, claimId, claimInfo, DECLINED());
105
133
  }
106
134
 
107
135
 
108
- function closeClaim(NftId policyNftId, ClaimId claimId)
136
+ function close(
137
+ IInstance instance,
138
+ InstanceReader instanceReader,
139
+ NftId policyNftId,
140
+ ClaimId claimId
141
+ )
109
142
  external
110
143
  virtual
111
- // solhint-disable-next-line no-empty-blocks
112
144
  {
113
-
145
+ IPolicy.ClaimInfo memory claimInfo = _verifyClaim(instanceReader, policyNftId, claimId, CONFIRMED());
146
+
147
+ // check claim has no open payouts
148
+ if(claimInfo.openPayoutsCount > 0) {
149
+ revert ErrorClaimServiceClaimWithOpenPayouts(
150
+ policyNftId,
151
+ claimId,
152
+ claimInfo.openPayoutsCount);
153
+ }
154
+
155
+ // check claim paid amount matches with claim amount
156
+ if(claimInfo.paidAmount.toInt() < claimInfo.claimAmount.toInt()) {
157
+ revert ErrorClaimServiceClaimWithMissingPayouts(
158
+ policyNftId,
159
+ claimId,
160
+ claimInfo.claimAmount,
161
+ claimInfo.paidAmount);
162
+ }
163
+
164
+ claimInfo.closedAt = TimestampLib.blockTimestamp();
165
+ instance.updateClaim(policyNftId, claimId, claimInfo, CLOSED());
114
166
  }
115
167
 
116
168
 
117
169
  function createPayout(
170
+ IInstance instance,
118
171
  NftId policyNftId,
119
- ClaimId claimId,
120
- uint256 payoutAmount,
172
+ PayoutId payoutId,
173
+ Amount payoutAmount,
121
174
  bytes calldata payoutData
122
175
  )
123
176
  external
124
177
  virtual
125
- returns(PayoutId payoutId)
126
- // solhint-disable-next-line no-empty-blocks
178
+ // TODO add restricted and grant to policy service
127
179
  {
128
-
180
+ instance.createPayout(
181
+ policyNftId,
182
+ payoutId,
183
+ IPolicy.PayoutInfo(
184
+ payoutId.toClaimId(),
185
+ payoutAmount,
186
+ payoutData,
187
+ TimestampLib.zero()));
129
188
  }
130
189
 
131
190
 
132
- function payoutExecuted(
191
+ function processPayout(
192
+ IInstance instance,
193
+ InstanceReader instanceReader,
133
194
  NftId policyNftId,
134
195
  PayoutId payoutId
135
196
  )
136
197
  external
137
198
  virtual
199
+ returns (
200
+ Amount amount,
201
+ bool payoutIsClosingClaim
202
+ )
138
203
  // solhint-disable-next-line no-empty-blocks
139
204
  {
140
205
 
@@ -143,6 +208,29 @@ contract ClaimService is
143
208
 
144
209
  // internal functions
145
210
 
211
+ function _verifyClaim(
212
+ InstanceReader instanceReader,
213
+ NftId policyNftId,
214
+ ClaimId claimId,
215
+ StateId expectedState
216
+ )
217
+ internal
218
+ view
219
+ returns (
220
+ IPolicy.ClaimInfo memory claimInfo
221
+ )
222
+ {
223
+ // check claim is created state
224
+ StateId claimState = instanceReader.getClaimState(policyNftId, claimId);
225
+ if(claimState != expectedState) {
226
+ revert ErrorClaimServiceClaimNotInExpectedState(
227
+ policyNftId, claimId, expectedState, claimState);
228
+ }
229
+
230
+ // get claim info
231
+ claimInfo = instanceReader.getClaimInfo(policyNftId, claimId);
232
+ }
233
+
146
234
  function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
147
235
  IRegistry.ObjectInfo memory productInfo;
148
236
  (, productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
@@ -155,22 +155,18 @@ contract DistributionService is
155
155
  }
156
156
 
157
157
  distributorType = DistributorTypeLib.toDistributorType(distributionNftId, name);
158
- Key32 key32 = distributorType.toKey32();
159
-
160
- if(!instance.exists(key32)) {
161
- IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo(
162
- name,
163
- minDiscountPercentage,
164
- maxDiscountPercentage,
165
- commissionPercentage,
166
- maxReferralCount,
167
- maxReferralLifetime,
168
- allowSelfReferrals,
169
- allowRenewals,
170
- data);
171
-
172
- instance.createDistributorType(key32, info);
173
- }
158
+ IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo(
159
+ name,
160
+ minDiscountPercentage,
161
+ maxDiscountPercentage,
162
+ commissionPercentage,
163
+ maxReferralCount,
164
+ maxReferralLifetime,
165
+ allowSelfReferrals,
166
+ allowRenewals,
167
+ data);
168
+
169
+ instance.createDistributorType(distributorType, info);
174
170
  }
175
171
 
176
172
  function createDistributor(
@@ -267,7 +263,7 @@ contract DistributionService is
267
263
  data
268
264
  );
269
265
 
270
- instance.createReferral(referralId.toKey32(), info);
266
+ instance.createReferral(referralId, info);
271
267
  return referralId;
272
268
  }
273
269
 
@@ -308,7 +304,7 @@ contract DistributionService is
308
304
 
309
305
  if (isReferral) {
310
306
  referralInfo.usedReferrals += 1;
311
- instance.updateReferral(referralId.toKey32(), referralInfo, KEEP_STATE());
307
+ instance.updateReferral(referralId, referralInfo, KEEP_STATE());
312
308
 
313
309
  if (commissionAmount > 0) {
314
310
  distributorInfo.sumCommisions += commissionAmount;
@@ -2,24 +2,20 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {IPolicy} from "../module/IPolicy.sol";
5
- import {IRisk} from "../module/IRisk.sol";
6
5
  import {IService} from "../../shared/IService.sol";
7
6
 
8
7
  import {NftId} from "../../types/NftId.sol";
8
+ import {ObjectType} from "../../types/ObjectType.sol";
9
9
  import {ReferralId} from "../../types/Referral.sol";
10
10
  import {RiskId} from "../../types/RiskId.sol";
11
11
  import {Seconds} from "../../types/Seconds.sol";
12
- import {StateId} from "../../types/StateId.sol";
13
- import {Timestamp} from "../../types/Timestamp.sol";
14
- import {UFixed} from "../../types/UFixed.sol";
15
- import {Fee} from "../../types/Fee.sol";
16
12
 
17
13
  /// @dev gif service responsible for creating applications
18
14
  /// only product components may call transaction functions
19
15
  interface IApplicationService is IService {
20
16
 
21
- error IApplicationServicePolicyNotApplied(NftId applicationNftId);
22
- error IApplicationServiceBundlePoolMismatch(NftId bundleNftId, NftId bundlePoolNftId, NftId poolNftId);
17
+ error ErrorApplicationServiceNotProduct(NftId callerNftId, ObjectType callerType);
18
+ error ErrorApplicationServiceBundlePoolMismatch(NftId bundleNftId, NftId bundlePoolNftId, NftId poolNftId);
23
19
 
24
20
  /// @dev creates a new application based on the specified attributes
25
21
  /// may only be called by a product component
@@ -21,6 +21,9 @@ interface IBundleService is IService {
21
21
  error ErrorBundleServiceCapacityInsufficient(NftId bundleNftId, uint capacityAmount, uint collateralAmount);
22
22
  error ErrorBundleServiceBundleWithOpenPolicies(NftId bundleNftId, uint256 openPoliciesCount);
23
23
 
24
+ error ErrorBundleServiceBundleUnknown(NftId bundleNftId);
25
+ error ErrorBundleServiceBundlePoolMismatch(NftId expectedPoolNftId, NftId bundlePoolNftId);
26
+
24
27
  /// @dev create a new bundle for the specified attributes
25
28
  /// may only be called by pool service
26
29
  function create(
@@ -1,14 +1,14 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- import {IRisk} from "../module/IRisk.sol";
4
+ import {IInstance} from "../IInstance.sol";
5
+ import {InstanceReader} from "../InstanceReader.sol";
5
6
  import {IService} from "../../shared/IService.sol";
6
7
 
8
+ import {Amount} from "../../types/Amount.sol";
7
9
  import {ClaimId} from "../../types/ClaimId.sol";
8
10
  import {PayoutId} from "../../types/PayoutId.sol";
9
11
  import {NftId} from "../../types/NftId.sol";
10
- import {ReferralId} from "../../types/Referral.sol";
11
- import {RiskId} from "../../types/RiskId.sol";
12
12
  import {StateId} from "../../types/StateId.sol";
13
13
  import {Timestamp} from "../../types/Timestamp.sol";
14
14
  import {UFixed} from "../../types/UFixed.sol";
@@ -20,42 +20,73 @@ interface IClaimService is
20
20
  IService
21
21
  {
22
22
 
23
+ error ErrorClaimServiceClaimWithOpenPayouts(NftId policyNftId, ClaimId claimId, uint8 openPayouts);
24
+ error ErrorClaimServiceClaimWithMissingPayouts(NftId policyNftId, ClaimId claimId, Amount claimAmount, Amount paidAmount);
25
+ error ErrorClaimServiceClaimNotInExpectedState(NftId policyNftId, ClaimId claimId, StateId expectedState, StateId actualState);
26
+
23
27
  /// @dev create a new claim for the specified policy
24
28
  /// function can only be called by product, policy needs to match with calling product
25
- function createClaim(
29
+ function submit(
30
+ IInstance instance,
26
31
  NftId policyNftId,
27
- uint256 claimAmount,
32
+ ClaimId claimId,
33
+ Amount claimAmount,
28
34
  bytes memory claimData
29
- ) external returns (ClaimId);
35
+ ) external;
30
36
 
31
37
  /// @dev confirms the specified claim and fixes the final claim amount
32
38
  /// function can only be called by product, policy needs to match with calling product
33
- function confirmClaim(NftId policyNftId, ClaimId claimId, uint256 claimAmount) external;
39
+ function confirm(
40
+ IInstance instance,
41
+ InstanceReader instanceReader,
42
+ NftId policyNftId,
43
+ ClaimId claimId,
44
+ Amount claimAmount
45
+ ) external;
34
46
 
35
47
  /// @dev declares the claim as invalid, no payout(s) will be made
36
48
  /// function can only be called by product, policy needs to match with calling product
37
- function declineClaim(NftId policyNftId, ClaimId claimId) external;
49
+ function decline(
50
+ IInstance instance,
51
+ InstanceReader instanceReader,
52
+ NftId policyNftId,
53
+ ClaimId claimId
54
+ ) external;
38
55
 
39
56
  /// @dev closes the claim
40
57
  /// a claim may only be closed once all existing payouts have been executed and the sum of the paid out amounts has reached the claim amount
41
58
  /// function can only be called by product, policy needs to match with calling product
42
- function closeClaim(NftId policyNftId, ClaimId claimId) external;
59
+ function close(
60
+ IInstance instance,
61
+ InstanceReader instanceReader,
62
+ NftId policyNftId,
63
+ ClaimId claimId
64
+ ) external;
43
65
 
44
- /// @dev create a new payout for the specified policy and claim
66
+ /// @dev create a new payout for the specified policy
67
+ /// payoutId may be constructed using PayoutIdLib(claimId, payoutNo)
45
68
  /// function can only be called by product, policy needs to match with calling product
46
69
  function createPayout(
70
+ IInstance instance,
47
71
  NftId policyNftId,
48
- ClaimId claimId,
49
- uint256 payoutAmount,
72
+ PayoutId payoutId,
73
+ Amount payoutAmount,
50
74
  bytes calldata payoutData
51
- ) external returns (PayoutId payoutId);
75
+ ) external;
52
76
 
53
77
  /// @dev callback function to confirm transfer of payout token to beneficiary
54
78
  /// allows claim service to update claims/payout book keeping
55
79
  /// only pool service can confirm executed payout
56
- function payoutExecuted(
80
+ function processPayout(
81
+ IInstance instance,
82
+ InstanceReader instanceReader,
57
83
  NftId policyNftId,
58
84
  PayoutId payoutId
59
- ) external;
85
+ )
86
+ external
87
+ returns (
88
+ Amount amount,
89
+ bool payoutIsClosingClaim
90
+ );
60
91
 
61
92
  }
@@ -4,7 +4,10 @@ pragma solidity ^0.8.19;
4
4
  import {IRisk} from "../module/IRisk.sol";
5
5
  import {IService} from "../../shared/IService.sol";
6
6
 
7
+ import {Amount} from "../../types/Amount.sol";
8
+ import {ClaimId} from "../../types/ClaimId.sol";
7
9
  import {NftId} from "../../types/NftId.sol";
10
+ import {PayoutId} from "../../types/PayoutId.sol";
8
11
  import {ReferralId} from "../../types/Referral.sol";
9
12
  import {RiskId} from "../../types/RiskId.sol";
10
13
  import {Seconds} from "../../types/Seconds.sol";
@@ -14,7 +17,19 @@ import {UFixed} from "../../types/UFixed.sol";
14
17
  import {Fee} from "../../types/Fee.sol";
15
18
 
16
19
  interface IPolicyService is IService {
17
-
20
+
21
+ event LogPolicyServiceClaimSubmitted(NftId policyNftId, ClaimId claimId, Amount claimAmount);
22
+ event LogPolicyServiceClaimConfirmed(NftId policyNftId, ClaimId claimId, Amount confirmedAmount);
23
+ event LogPolicyServiceClaimDeclined(NftId policyNftId, ClaimId claimId);
24
+ event LogPolicyServiceClaimClosed(NftId policyNftId, ClaimId claimId);
25
+
26
+ event LogPolicyServicePayoutCreated(NftId policyNftId, PayoutId payoutId, Amount amount);
27
+ event LogPolicyServicePayoutProcessed(NftId policyNftId, PayoutId payoutId, Amount amount);
28
+
29
+ error ErrorPolicyServicePolicyProductMismatch(NftId policyNftId, NftId expectedProduct, NftId actualProduct);
30
+ error ErrorPolicyServicePolicyNotOpen(NftId policyNftId);
31
+ error ErrorPolicyServiceClaimExceedsSumInsured(NftId policyNftId, Amount sumInsured, Amount payoutsIncludingClaimAmount);
32
+
18
33
  error ErrorIPolicyServiceInsufficientAllowance(address customer, address tokenHandlerAddress, uint256 amount);
19
34
  error ErrorIPolicyServicePremiumAlreadyPaid(NftId policyNftId, uint256 premiumPaidAmount);
20
35
  error ErrorIPolicyServicePolicyNotActivated(NftId policyNftId);
@@ -24,22 +39,22 @@ interface IPolicyService is IService {
24
39
  error ErrorIPolicyServiceOpenClaims(NftId policyNftId, uint16 openClaimsCount);
25
40
  error ErrorIPolicyServicePolicyHasNotExpired(NftId policyNftId, Timestamp expiredAt);
26
41
 
27
- error ErrorIPolicyServicePremiumMismatch(NftId policyNftId, uint256 premiumAmount, uint256 recalculatedPremiumAmount);
42
+ error ErrorIPolicyServicePremiumMismatch(NftId policyNftId, uint256 expectedPremiumAmount, uint256 recalculatedPremiumAmount);
28
43
 
29
44
  /// @dev declines an application represented by {policyNftId}
30
45
  /// an application can only be declined in applied state
31
46
  /// only the related product may decline an application
32
47
  function decline(NftId policyNftId) external;
33
48
 
34
- /// @dev underwrites the policy represented by {policyNftId}
49
+ /// @dev collateralizes the policy represented by {policyNftId}
35
50
  /// sets the policy state to underwritten
36
51
  /// may set the policy state to activated and set the activation date
37
52
  /// optionally collects premiums and activates the policy.
38
53
  /// - premium payment is only attempted if requirePremiumPayment is set to true
39
54
  /// - activation is only done if activateAt is a non-zero timestamp
40
55
  /// an application can only be underwritten in applied state
41
- /// only the related product may underwrite an application
42
- function underwrite(
56
+ /// only the related product may collateralize an application
57
+ function collateralize(
43
58
  NftId policyNftId,
44
59
  bool requirePremiumPayment,
45
60
  Timestamp activateAt
@@ -63,6 +78,56 @@ interface IPolicyService is IService {
63
78
  /// this function can only be called by a product. the policy needs to match with the calling product
64
79
  function close(NftId policyNftId) external;
65
80
 
81
+ /// @dev create a new claim for the specified policy
82
+ /// returns the id of the newly created claim
83
+ /// function can only be called by product, policy needs to match with calling product
84
+ function submitClaim(
85
+ NftId policyNftId,
86
+ Amount claimAmount,
87
+ bytes memory claimData
88
+ ) external returns (ClaimId claimId);
89
+
90
+ /// @dev declines the specified claim
91
+ /// function can only be called by product, policy needs to match with calling product
92
+ function declineClaim(
93
+ NftId policyNftId,
94
+ ClaimId claimId) external;
95
+
96
+ /// @dev confirms the specified claim and specifies the payout amount
97
+ /// function can only be called by product, policy needs to match with calling product
98
+ function confirmClaim(
99
+ NftId policyNftId,
100
+ ClaimId claimId,
101
+ Amount confirmedAmount
102
+ ) external;
103
+
104
+ /// @dev closes the specified claim
105
+ /// function can only be called by product, policy needs to match with calling product
106
+ function closeClaim(
107
+ NftId policyNftId,
108
+ ClaimId claimId
109
+ ) external;
110
+
111
+ /// @dev creates a new payout for the specified claim
112
+ /// returns the id of the newly created payout, this id is unique for the specified policy
113
+ /// function can only be called by product, policy needs to match with calling product
114
+ function createPayout(
115
+ NftId policyNftId,
116
+ ClaimId claimId,
117
+ Amount amount,
118
+ bytes memory data
119
+ )
120
+ external
121
+ returns (PayoutId payoutId);
122
+
123
+ /// @dev processes the specified payout
124
+ /// this includes moving the payout token to the beneficiary (default: policy holder)
125
+ /// function can only be called by product, policy needs to match with calling product
126
+ function processPayout(
127
+ NftId policyNftId,
128
+ PayoutId payoutId
129
+ ) external;
130
+
66
131
  // TODO move function to pool service
67
132
  function calculateRequiredCollateral(
68
133
  UFixed collateralizationLevel,