@etherisc/gif-next 0.0.2-bdcb44f-543 → 0.0.2-be8b3db-650

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  2. package/artifacts/contracts/components/Component.sol/Component.json +40 -0
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +41 -19
  5. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.json +40 -0
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +41 -19
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +57 -150
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +40 -0
  13. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  14. package/artifacts/contracts/components/Pool.sol/Pool.json +76 -189
  15. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  16. package/artifacts/contracts/components/Product.sol/Product.json +40 -0
  17. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  18. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +30 -11
  19. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  20. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  21. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +32 -174
  22. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  23. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  24. package/artifacts/contracts/instance/Instance.sol/Instance.json +103 -238
  25. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  26. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  27. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  28. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +73 -144
  29. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  30. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +32 -32
  31. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  32. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +17 -17
  33. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  34. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
  35. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  36. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  37. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  38. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  39. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +40 -10
  40. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +36 -11
  42. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  43. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  44. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +4 -0
  45. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.json +10 -0
  46. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  47. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  48. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  49. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  50. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  51. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  52. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +14 -14
  53. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  54. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +8 -8
  55. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  56. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +132 -135
  57. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  58. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +12 -12
  59. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  60. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +2 -2
  61. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  62. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +2 -2
  63. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  64. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +234 -63
  65. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  66. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +40 -32
  67. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  68. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +89 -92
  70. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  72. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +156 -1
  73. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  74. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +21 -0
  75. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  76. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +81 -0
  77. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  78. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +31 -10
  80. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +6 -6
  82. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +105 -16
  84. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +13 -9
  86. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +2 -2
  88. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +2 -2
  90. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  91. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +15 -2
  92. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  93. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  94. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  95. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  96. package/artifacts/contracts/registry/Registry.sol/Registry.json +4 -4
  97. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  98. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  99. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  100. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +12 -12
  101. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  102. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  103. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  104. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +3 -3
  105. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  106. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  107. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  108. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  109. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  110. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  111. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  112. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  113. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  114. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  115. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  116. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  117. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  118. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  119. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  120. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  121. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  122. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  123. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  124. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  125. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  126. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  127. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  128. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  129. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  130. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  131. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  132. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  133. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  134. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  135. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  136. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  137. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  138. package/artifacts/contracts/test/TestService.sol/TestService.json +2 -2
  139. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  140. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  141. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  142. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  143. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  144. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  145. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  146. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  147. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
  148. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  149. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  151. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  152. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  153. package/artifacts/contracts/types/Fee.sol/FeeLib.json +2 -2
  154. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  155. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  156. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +17 -4
  158. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  159. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  160. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  163. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +23 -4
  166. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  168. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  170. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  173. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  174. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
  175. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  176. package/artifacts/contracts/types/UFixed.sol/MathLib.json +2 -2
  177. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  178. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +2 -2
  179. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  180. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  181. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  182. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  183. package/contracts/components/Component.sol +20 -0
  184. package/contracts/components/Distribution.sol +0 -13
  185. package/contracts/components/IComponent.sol +6 -0
  186. package/contracts/components/IDistributionComponent.sol +0 -8
  187. package/contracts/components/IPoolComponent.sol +5 -43
  188. package/contracts/components/Pool.sol +38 -117
  189. package/contracts/components/Product.sol +4 -0
  190. package/contracts/instance/BundleManager.sol +6 -4
  191. package/contracts/instance/IInstance.sol +3 -2
  192. package/contracts/instance/IInstanceService.sol +2 -1
  193. package/contracts/instance/Instance.sol +8 -4
  194. package/contracts/instance/InstanceReader.sol +4 -3
  195. package/contracts/instance/InstanceService.sol +5 -6
  196. package/contracts/instance/base/KeyValueStore.sol +5 -2
  197. package/contracts/instance/base/Lifecycle.sol +11 -2
  198. package/contracts/instance/module/IComponents.sol +35 -0
  199. package/contracts/instance/module/ISetup.sol +4 -17
  200. package/contracts/instance/service/ApplicationService.sol +6 -5
  201. package/contracts/instance/service/BundleService.sol +72 -35
  202. package/contracts/instance/service/DistributionService.sol +75 -19
  203. package/contracts/instance/service/IBundleService.sol +16 -9
  204. package/contracts/instance/service/IDistributionService.sol +13 -1
  205. package/contracts/instance/service/IPolicyService.sol +2 -0
  206. package/contracts/instance/service/IPoolService.sol +17 -2
  207. package/contracts/instance/service/PolicyService.sol +46 -45
  208. package/contracts/instance/service/PoolService.sol +72 -18
  209. package/contracts/registry/ChainNft.sol +4 -0
  210. package/contracts/registry/Registry.sol +10 -12
  211. package/contracts/shared/TokenHandler.sol +11 -5
  212. package/contracts/types/Blocknumber.sol +1 -0
  213. package/contracts/types/Fee.sol +1 -0
  214. package/contracts/types/NftId.sol +8 -0
  215. package/contracts/types/ObjectType.sol +1 -0
  216. package/contracts/types/Referral.sol +4 -0
  217. package/contracts/types/StateId.sol +1 -0
  218. package/contracts/types/Timestamp.sol +1 -0
  219. package/contracts/types/UFixed.sol +1 -0
  220. package/contracts/types/Version.sol +1 -0
  221. package/package.json +1 -1
@@ -1,22 +1,23 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- import {Pool} from "../../components/Pool.sol";
4
+ import {IBundle} from "../../instance/module/IBundle.sol";
5
+ import {IComponents} from "../module/IComponents.sol";
5
6
  import {IRegistry} from "../../registry/IRegistry.sol";
6
7
  import {IInstance} from "../../instance/IInstance.sol";
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
10
  import {IPolicy} from "../module/IPolicy.sol";
11
11
 
12
12
  import {IVersionable} from "../../shared/IVersionable.sol";
13
13
  import {INftOwnable} from "../../shared/INftOwnable.sol";
14
-
15
14
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
16
15
  import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
17
16
  import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
17
+ import {Pool} from "../../components/Pool.sol";
18
+
18
19
  import {Fee, FeeLib} from "../../types/Fee.sol";
19
- import {KEEP_STATE, StateId} from "../../types/StateId.sol";
20
+ import {StateId, ACTIVE, PAUSED, CLOSED, KEEP_STATE} from "../../types/StateId.sol";
20
21
  import {Seconds} from "../../types/Seconds.sol";
21
22
  import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
22
23
  import {Version, VersionLib} from "../../types/Version.sol";
@@ -64,7 +65,7 @@ contract BundleService is
64
65
  return BUNDLE();
65
66
  }
66
67
 
67
- function createBundle(
68
+ function create(
68
69
  address owner,
69
70
  Fee memory fee,
70
71
  uint256 stakingAmount,
@@ -119,7 +120,7 @@ contract BundleService is
119
120
  // TODO add logging
120
121
  }
121
122
 
122
- function setBundleFee(
123
+ function setFee(
123
124
  NftId bundleNftId,
124
125
  Fee memory fee
125
126
  )
@@ -139,30 +140,6 @@ contract BundleService is
139
140
  instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
140
141
  }
141
142
 
142
- function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state)
143
- external
144
- onlyService
145
- {
146
- IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
147
- IInstance instance = IInstance(instanceInfo.objectAddress);
148
- instance.updateBundle(bundleNftId, bundleInfo, state);
149
- }
150
-
151
- function lockBundle(NftId bundleNftId)
152
- external
153
- {
154
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
155
- BundleManager bundleManager = instance.getBundleManager();
156
- bundleManager.lock(bundleNftId);
157
- }
158
-
159
- function unlockBundle(NftId bundleNftId)
160
- external
161
- {
162
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
163
- BundleManager bundleManager = instance.getBundleManager();
164
- bundleManager.unlock(bundleNftId);
165
- }
166
143
 
167
144
  function lockCollateral(
168
145
  IInstance instance,
@@ -191,6 +168,64 @@ contract BundleService is
191
168
  linkPolicy(instance, policyNftId);
192
169
  }
193
170
 
171
+
172
+ function lock(NftId bundleNftId)
173
+ external
174
+ virtual
175
+ {
176
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
177
+
178
+ // udpate bundle state
179
+ instance.updateBundleState(bundleNftId, PAUSED());
180
+
181
+ // update set of active bundles
182
+ BundleManager bundleManager = instance.getBundleManager();
183
+ bundleManager.lock(bundleNftId);
184
+
185
+ emit LogBundleServiceBundleLocked(bundleNftId);
186
+ }
187
+
188
+
189
+ function unlock(NftId bundleNftId)
190
+ external
191
+ virtual
192
+ {
193
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
194
+
195
+ // udpate bundle state
196
+ instance.updateBundleState(bundleNftId, ACTIVE());
197
+
198
+ // update set of active bundles
199
+ BundleManager bundleManager = instance.getBundleManager();
200
+ bundleManager.unlock(bundleNftId);
201
+
202
+ emit LogBundleServiceBundleActivated(bundleNftId);
203
+ }
204
+
205
+
206
+ function close(NftId bundleNftId)
207
+ external
208
+ virtual
209
+ {
210
+ (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
211
+
212
+ // udpate bundle state
213
+ instance.updateBundleState(bundleNftId, CLOSED());
214
+
215
+ // ensure no open policies attached to bundle
216
+ BundleManager bundleManager = instance.getBundleManager();
217
+ uint256 openPolicies = bundleManager.activePolicies(bundleNftId);
218
+ if(openPolicies > 0) {
219
+ revert ErrorBundleServiceBundleWithOpenPolicies(bundleNftId, openPolicies);
220
+ }
221
+
222
+ // update set of active bundles
223
+ bundleManager.lock(bundleNftId);
224
+
225
+ emit LogBundleServiceBundleClosed(bundleNftId);
226
+ }
227
+
228
+
194
229
  function increaseBalance(IInstance instance,
195
230
  NftId bundleNftId,
196
231
  uint256 amount
@@ -235,7 +270,7 @@ contract BundleService is
235
270
 
236
271
  // ensure policy has not yet been activated
237
272
  if (policyInfo.activatedAt.gtz()) {
238
- revert BundleManager.ErrorBundleManagerErrorPolicyAlreadyActivated(policyNftId);
273
+ revert BundleManager.ErrorBundleManagerPolicyAlreadyActivated(policyNftId);
239
274
  }
240
275
 
241
276
  BundleManager bundleManager = instance.getBundleManager();
@@ -278,18 +313,20 @@ contract BundleService is
278
313
  {
279
314
  // process token transfer(s)
280
315
  if(stakingAmount > 0) {
281
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
282
- TokenHandler tokenHandler = poolInfo.tokenHandler;
316
+ IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
317
+ IComponents.PoolInfo memory poolInfo = abi.decode(
318
+ componentInfo.data, (IComponents.PoolInfo));
319
+
320
+ TokenHandler tokenHandler = componentInfo.tokenHandler;
283
321
  address bundleOwner = getRegistry().ownerOf(bundleNftId);
284
322
  Fee memory stakingFee = poolInfo.stakingFee;
285
323
 
286
324
  tokenHandler.transfer(
287
325
  bundleOwner,
288
- poolInfo.wallet,
326
+ componentInfo.wallet,
289
327
  stakingAmount
290
328
  );
291
329
 
292
-
293
330
  if (! FeeLib.feeIsZero(stakingFee)) {
294
331
  (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
295
332
  // TODO: track staking fees in pool's state (issue #177)
@@ -42,6 +42,7 @@ contract DistributionService is
42
42
  using TimestampLib for Timestamp;
43
43
  using UFixedLib for UFixed;
44
44
  using FeeLib for Fee;
45
+ using ReferralLib for ReferralId;
45
46
 
46
47
  address internal _registryAddress;
47
48
 
@@ -255,20 +256,50 @@ contract DistributionService is
255
256
  }
256
257
 
257
258
  function processSale(
259
+ NftId distributionNftId,
258
260
  ReferralId referralId,
259
- uint256 premiumAmount
261
+ IPolicy.Premium memory premium,
262
+ uint256 transferredDistributionFeeAmount
260
263
  )
261
264
  external
262
265
  virtual
263
266
  {
264
- // TODO: fetch referral
265
- // TODO: update referral usage numbers
266
- // TODO: update bookkeeping
267
- // TODO: calculate commission for distributor
268
- // TODO: calculate fee for distribution owner
269
- // TODO: updates sum of commission per distributor -> DistributorInfo
270
- // TODO: updates sum of fee per distribution owner
271
- revert("NOT_IMPLEMENTED_YET");
267
+ bool isReferral = ! referralId.eqz();
268
+ bool referralValid = referralIsValid(distributionNftId, referralId);
269
+
270
+ if (isReferral && ! referralValid) {
271
+ revert ErrorIDistributionServiceReferralInvalid(distributionNftId, referralId);
272
+ }
273
+
274
+ (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
275
+ InstanceReader reader = instance.getInstanceReader();
276
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
277
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
278
+ ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
279
+
280
+ uint256 distributionOwnerFee = premium.distributionOwnerFeeFixAmount + premium.distributionOwnerFeeVarAmount;
281
+ uint256 commissionAmount = premium.commissionAmount;
282
+
283
+ if (transferredDistributionFeeAmount != distributionOwnerFee + commissionAmount) {
284
+ revert ErrorIDistributionServiceInvalidFeeTransferred(transferredDistributionFeeAmount, distributionOwnerFee + commissionAmount);
285
+ }
286
+
287
+
288
+ if (distributionOwnerFee > 0) {
289
+ setupInfo.sumDistributionOwnerFees += distributionOwnerFee;
290
+ instance.updateDistributionSetup(distributionNftId, setupInfo, KEEP_STATE());
291
+ }
292
+
293
+ if (isReferral) {
294
+ referralInfo.usedReferrals += 1;
295
+ instance.updateReferral(referralId.toKey32(), referralInfo, KEEP_STATE());
296
+
297
+ if (commissionAmount > 0) {
298
+ distributorInfo.sumCommisions += commissionAmount;
299
+ distributorInfo.numPoliciesSold += 1;
300
+ instance.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
301
+ }
302
+ }
272
303
  }
273
304
 
274
305
  function calculateFeeAmount(
@@ -302,20 +333,45 @@ contract DistributionService is
302
333
 
303
334
  // if the referral is valid, the the commission and discount are calculated based in the full premium
304
335
  // the remaing amount goes to the distribution owner
305
- IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
306
- IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
307
- IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
308
-
309
- uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
310
- premium.commissionAmount = commissionAmount;
311
- premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
312
- premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
313
- premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
314
- premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
336
+ {
337
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
338
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
339
+ IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
340
+
341
+ uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
342
+ premium.commissionAmount = commissionAmount;
343
+ premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
344
+ premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
345
+ premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
346
+ premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
347
+ }
348
+
349
+ // sanity check to validate the fee calculation
350
+ if (premium.distributionOwnerFeeFixAmount < minDistributionOwnerFee.fixedFee) {
351
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
352
+ premium.distributionFeeFixAmount,
353
+ premium.distributionFeeVarAmount,
354
+ premium.distributionOwnerFeeFixAmount,
355
+ premium.distributionOwnerFeeVarAmount,
356
+ premium.commissionAmount,
357
+ premium.discountAmount
358
+ );
359
+ }
360
+ if ((premium.distributionFeeVarAmount) != (premium.discountAmount + premium.distributionOwnerFeeVarAmount + premium.commissionAmount)) {
361
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
362
+ premium.distributionFeeFixAmount,
363
+ premium.distributionFeeVarAmount,
364
+ premium.distributionOwnerFeeFixAmount,
365
+ premium.distributionOwnerFeeVarAmount,
366
+ premium.commissionAmount,
367
+ premium.discountAmount
368
+ );
369
+ }
315
370
 
316
371
  return premium;
317
372
  }
318
373
 
374
+ // TODO: zero should return false
319
375
  function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
320
376
  (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
321
377
  IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);
@@ -10,9 +10,16 @@ import {Seconds} from "../../types/Seconds.sol";
10
10
  import {StateId} from "../../types/StateId.sol";
11
11
 
12
12
  interface IBundleService is IService {
13
- error ErrorIBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
14
13
 
15
- function createBundle(
14
+ event LogBundleServiceBundleActivated(NftId bundleNftId);
15
+ event LogBundleServiceBundleLocked(NftId bundleNftId);
16
+ event LogBundleServiceBundleClosed(NftId bundleNftId);
17
+
18
+ error ErrorBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
19
+ error ErrorBundleServiceBundleNotOpen(NftId bundleNftId, StateId state);
20
+ error ErrorBundleServiceBundleWithOpenPolicies(NftId bundleNftId, uint256 openPoliciesCount);
21
+
22
+ function create(
16
23
  address owner,
17
24
  Fee memory fee,
18
25
  uint256 amount,
@@ -20,12 +27,12 @@ interface IBundleService is IService {
20
27
  bytes calldata filter
21
28
  ) external returns(NftId bundleNftId);
22
29
 
23
- function setBundleFee(
30
+
31
+ function setFee(
24
32
  NftId bundleNftId,
25
33
  Fee memory fee
26
34
  ) external;
27
35
 
28
- function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) external;
29
36
 
30
37
  function lockCollateral(
31
38
  IInstance instanceNftId,
@@ -43,13 +50,13 @@ interface IBundleService is IService {
43
50
 
44
51
  function closePolicy(IInstance instance, NftId policyNftId, NftId bundleNftId, uint256 collateralAmount) external;
45
52
 
46
- // function fundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
53
+ // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
47
54
 
48
- // function defundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
55
+ // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
49
56
 
50
- function lockBundle(NftId bundleNftId) external;
57
+ function lock(NftId bundleNftId) external;
51
58
 
52
- function unlockBundle(NftId bundleNftId) external;
59
+ function unlock(NftId bundleNftId) external;
53
60
 
54
- // function closeBundle(NftId bundleNftId) external;
61
+ function close(NftId bundleNftId) external;
55
62
  }
@@ -24,6 +24,16 @@ interface IDistributionService is IService {
24
24
  error ErrorIDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
25
25
  error ErrorIDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
26
26
  error ErrorIDistributionServiceMaxDiscountTooHigh(uint256 maxDiscountPercentage, uint256 limit);
27
+ error ErrorIDistributionServiceFeeCalculationMismatch(
28
+ uint256 distributionFeeFixAmount,
29
+ uint256 distributionFeeVarAmount,
30
+ uint256 distributionOwnerFeeFixAmount,
31
+ uint256 distributionOwnerFeeVarAmount,
32
+ uint256 commissionAmount,
33
+ uint256 discountAmount
34
+ );
35
+ error ErrorIDistributionServiceReferralInvalid(NftId distributionNftId, ReferralId referralId);
36
+ error ErrorIDistributionServiceInvalidFeeTransferred(uint256 transferredDistributionFeeAmount, uint256 expectedDistributionFeeAmount);
27
37
 
28
38
  function setFees(
29
39
  Fee memory minDistributionOwnerFee,
@@ -69,8 +79,10 @@ interface IDistributionService is IService {
69
79
 
70
80
  /// @dev callback from product service when selling a policy for a specific referralId
71
81
  function processSale(
82
+ NftId distributionNftId,
72
83
  ReferralId referralId,
73
- uint256 premiumAmount
84
+ IPolicy.Premium memory premium,
85
+ uint256 transferredDistributionFeeAmount
74
86
  ) external;
75
87
 
76
88
  function calculateFeeAmount(
@@ -24,6 +24,8 @@ interface IPolicyService is IService {
24
24
  error ErrorIPolicyServiceOpenClaims(NftId policyNftId, uint16 openClaimsCount);
25
25
  error ErrorIPolicyServicePolicyHasNotExpired(NftId policyNftId, Timestamp expiredAt);
26
26
 
27
+ error ErrorIPolicyServicePremiumMismatch(NftId policyNftId, uint256 premiumAmount, uint256 recalculatedPremiumAmount);
28
+
27
29
  /// @dev declines an application represented by {policyNftId}
28
30
  /// an application can only be declined in applied state
29
31
  /// only the related product may decline an application
@@ -1,17 +1,32 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- import {NftId} from "../../types/NftId.sol";
5
4
  import {Fee} from "../../types/Fee.sol";
6
- import {StateId} from "../../types/StateId.sol";
5
+ import {NftId} from "../../types/NftId.sol";
7
6
  import {IService} from "../../shared/IService.sol";
8
7
  import {IBundle} from "../module/IBundle.sol";
9
8
  import {IInstance} from "../../instance/IInstance.sol";
9
+ import {RoleId} from "../../types/RoleId.sol";
10
+ import {StateId} from "../../types/StateId.sol";
10
11
 
11
12
  interface IPoolService is IService {
12
13
 
14
+ event LogPoolServiceMaxCapitalAmountUpdated(NftId poolNftId, uint256 previousMaxCapitalAmount, uint256 currentMaxCapitalAmount);
15
+ event LogPoolServiceBundleOwnerRoleSet(NftId poolNftId, RoleId bundleOwnerRole);
16
+
17
+ error ErrorPoolServiceBundleOwnerRoleAlreadySet(NftId poolNftId);
18
+
19
+ /// @dev registers a new pool with the registry service
13
20
  function register(address poolAddress) external returns(NftId);
14
21
 
22
+ /// @dev defines the required role for bundle owners for the calling pool
23
+ /// default implementation returns PUBLIC ROLE
24
+ function setBundleOwnerRole(RoleId bundleOwnerRole) external;
25
+
26
+ /// @dev sets the max capital amount for the calling pool
27
+ function setMaxCapitalAmount(uint256 maxCapitalAmount) external;
28
+
29
+ /// @dev set pool sepecific fees
15
30
  function setFees(
16
31
  Fee memory poolFee,
17
32
  Fee memory stakingFee,
@@ -2,45 +2,34 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {IRegistry} from "../../registry/IRegistry.sol";
5
- import {IProductComponent} from "../../components/IProductComponent.sol";
6
5
  import {Product} from "../../components/Product.sol";
7
- import {IPoolComponent} from "../../components/IPoolComponent.sol";
6
+ import {IComponents} from "../module/IComponents.sol";
8
7
  import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
9
8
  import {IInstance} from "../IInstance.sol";
10
9
  import {IPolicy} from "../module/IPolicy.sol";
10
+ import {IPoolComponent} from "../../components/IPoolComponent.sol";
11
11
  import {IRisk} from "../module/IRisk.sol";
12
12
  import {IBundle} from "../module/IBundle.sol";
13
- import {IProductService} from "./IProductService.sol";
14
- import {ITreasury} from "../module/ITreasury.sol";
15
13
  import {ISetup} from "../module/ISetup.sol";
16
14
 
17
15
  import {TokenHandler} from "../../shared/TokenHandler.sol";
18
16
 
19
- import {IVersionable} from "../../shared/IVersionable.sol";
20
- import {Versionable} from "../../shared/Versionable.sol";
21
-
22
- import {Seconds} from "../../types/Seconds.sol";
23
17
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
24
18
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
25
- import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
26
- import {ObjectType, APPLICATION, INSTANCE, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
19
+ import {ObjectType, APPLICATION, DISTRIBUTION, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
27
20
  import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
28
- import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
29
- import {Fee, FeeLib} from "../../types/Fee.sol";
30
- import {ReferralId} from "../../types/Referral.sol";
31
- import {RiskId} from "../../types/RiskId.sol";
21
+ import {NftId, NftIdLib} from "../../types/NftId.sol";
32
22
  import {StateId} from "../../types/StateId.sol";
33
- import {Version, VersionLib} from "../../types/Version.sol";
34
- //import {RoleId, PRODUCT_OWNER_ROLE} from "../../types/RoleId.sol";
35
23
 
36
- import {IService} from "../../shared/IService.sol";
37
- import {Service} from "../../shared/Service.sol";
38
24
  import {ComponentService} from "../base/ComponentService.sol";
39
25
  import {IApplicationService} from "./IApplicationService.sol";
40
- import {IPolicyService} from "./IPolicyService.sol";
26
+ import {IBundleService} from "./IBundleService.sol";
27
+ import {IDistributionService} from "./IDistributionService.sol";
41
28
  import {InstanceReader} from "../InstanceReader.sol";
29
+ import {IPolicyService} from "./IPolicyService.sol";
42
30
  import {IPoolService} from "./IPoolService.sol";
43
- import {IBundleService} from "./IBundleService.sol";
31
+ import {IService} from "../../shared/IService.sol";
32
+ import {Service} from "../../shared/Service.sol";
44
33
 
45
34
 
46
35
  contract PolicyService is
@@ -53,6 +42,7 @@ contract PolicyService is
53
42
  IPoolService internal _poolService;
54
43
  IBundleService internal _bundleService;
55
44
  IApplicationService internal _applicationService;
45
+ IDistributionService internal _distributionService;
56
46
 
57
47
  event LogProductServiceSender(address sender);
58
48
 
@@ -73,6 +63,7 @@ contract PolicyService is
73
63
  _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getMajorVersion()));
74
64
  _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getMajorVersion()));
75
65
  _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), getMajorVersion()));
66
+ _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), getMajorVersion()));
76
67
 
77
68
  registerInterface(type(IPolicyService).interfaceId);
78
69
  }
@@ -111,7 +102,9 @@ contract PolicyService is
111
102
  require(bundleInfo.poolNftId == poolNftId, "POLICY_BUNDLE_MISMATCH");
112
103
 
113
104
  // calculate required collateral
114
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
105
+ IComponents.ComponentInfo memory componentInfo = instanceReader.getComponentInfo(poolNftId);
106
+ IComponents.PoolInfo memory poolInfo = abi.decode(
107
+ componentInfo.data, (IComponents.PoolInfo));
115
108
 
116
109
  // obtain remaining return values
117
110
  // TODO required collateral amount should be calculated by pool service, not policy service
@@ -184,7 +177,6 @@ contract PolicyService is
184
177
  if(requirePremiumPayment) {
185
178
  netPremiumAmount = _processPremiumByTreasury(
186
179
  instance,
187
- productNftId,
188
180
  applicationNftId,
189
181
  policyInfo.premiumAmount);
190
182
 
@@ -212,7 +204,12 @@ contract PolicyService is
212
204
  instance.updatePolicy(applicationNftId, policyInfo, newPolicyState);
213
205
 
214
206
  // also verify/confirm application by pool if necessary
215
- if(instanceReader.getPoolSetupInfo(poolNftId).isVerifyingApplications) {
207
+ if(abi.decode(
208
+ instanceReader.getComponentInfo(poolNftId).data,
209
+ (IComponents.PoolInfo)
210
+ ).isVerifyingApplications
211
+ )
212
+ {
216
213
  IPoolComponent pool = IPoolComponent(
217
214
  getRegistry().getObjectInfo(poolNftId).objectAddress);
218
215
 
@@ -248,7 +245,6 @@ contract PolicyService is
248
245
 
249
246
  uint256 netPremiumAmount = _processPremiumByTreasury(
250
247
  instance,
251
- productInfo.nftId,
252
248
  policyNftId,
253
249
  unpaidPremiumAmount);
254
250
 
@@ -352,7 +348,6 @@ contract PolicyService is
352
348
 
353
349
  function _processPremiumByTreasury(
354
350
  IInstance instance,
355
- NftId productNftId,
356
351
  NftId policyNftId,
357
352
  uint256 premiumAmount
358
353
  )
@@ -361,12 +356,12 @@ contract PolicyService is
361
356
  {
362
357
  // process token transfer(s)
363
358
  if(premiumAmount > 0) {
359
+ NftId productNftId = getRegistry().getObjectInfo(policyNftId).parentNftId;
364
360
  ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
365
361
  IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
366
362
  TokenHandler tokenHandler = productSetupInfo.tokenHandler;
367
363
  address policyOwner = getRegistry().ownerOf(policyNftId);
368
- ISetup.PoolSetupInfo memory poolSetupInfo = instance.getInstanceReader().getPoolSetupInfo(productSetupInfo.poolNftId);
369
- address poolWallet = poolSetupInfo.wallet;
364
+ address poolWallet = instance.getInstanceReader().getComponentInfo(productSetupInfo.poolNftId).wallet;
370
365
  IPolicy.Premium memory premium = _applicationService.calculatePremium(
371
366
  productNftId,
372
367
  policyInfo.riskId,
@@ -377,24 +372,30 @@ contract PolicyService is
377
372
  policyInfo.referralId
378
373
  );
379
374
 
380
- // if (FeeLib.feeIsZero(premium.productFeeAmount)) {
381
- // tokenHandler.transfer(
382
- // policyOwner,
383
- // poolWallet,
384
- // premiumAmount
385
- // );
386
- // } else {
387
- address productWallet = productSetupInfo.wallet;
388
- if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premium.premiumAmount) {
389
- revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premium.premiumAmount);
390
- }
391
- tokenHandler.transfer(policyOwner, productWallet, premium.productFeeFixAmount + premium.productFeeVarAmount);
392
- tokenHandler.transfer(policyOwner, poolWallet, premium.netPremiumAmount);
393
- netPremiumAmount = premium.netPremiumAmount;
394
- // TODO: also move distribution tokens to distribution wallet and call `Distribution.processSale` to update distribution balances
395
- // }
396
- // TODO: move pool/bundle related tokens too
397
-
375
+ if (premium.premiumAmount != premiumAmount) {
376
+ revert ErrorIPolicyServicePremiumMismatch(policyNftId, premiumAmount, premium.premiumAmount);
377
+ }
378
+
379
+ // move product fee to product wallet
380
+ address productWallet = productSetupInfo.wallet;
381
+ if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premium.premiumAmount) {
382
+ revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premium.premiumAmount);
383
+ }
384
+ tokenHandler.transfer(policyOwner, productWallet, premium.productFeeFixAmount + premium.productFeeVarAmount);
385
+
386
+ // move distribution fee to distribution wallet
387
+ ISetup.DistributionSetupInfo memory distributionSetupInfo = instance.getInstanceReader().getDistributionSetupInfo(productSetupInfo.distributionNftId);
388
+ address distributionWallet = distributionSetupInfo.wallet;
389
+ uint256 distributionFeeAmountToTransfer = premium.distributionFeeFixAmount + premium.distributionFeeVarAmount - premium.discountAmount;
390
+ tokenHandler.transfer(policyOwner, distributionWallet, distributionFeeAmountToTransfer);
391
+ _distributionService.processSale(productSetupInfo.distributionNftId, policyInfo.referralId, premium, distributionFeeAmountToTransfer);
392
+
393
+ // move netpremium to pool wallet
394
+ tokenHandler.transfer(policyOwner, poolWallet, premium.netPremiumAmount);
395
+
396
+ // TODO: move pool related tokens too
397
+ // TODO: move bundle related tokens too
398
+ netPremiumAmount = premium.netPremiumAmount;
398
399
  }
399
400
 
400
401
  // TODO: add logging