@etherisc/gif-next 0.0.2-f29e479-370 → 0.0.2-f30e0eb-805

Sign up to get free protection for your applications and to get access to all the features.
Files changed (250) hide show
  1. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  2. package/artifacts/contracts/components/Component.sol/Component.json +68 -89
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +113 -140
  5. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.json +65 -73
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +91 -122
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +256 -189
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +69 -145
  13. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  14. package/artifacts/contracts/components/Pool.sol/Pool.json +279 -245
  15. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  16. package/artifacts/contracts/components/Product.sol/Product.json +73 -162
  17. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  18. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  19. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  20. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +64 -50
  21. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  22. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +5 -0
  23. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  24. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +171 -308
  25. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  26. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +98 -40
  27. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  28. package/artifacts/contracts/instance/Instance.sol/Instance.json +260 -379
  29. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  30. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +448 -121
  31. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  32. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +120 -227
  33. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  34. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +148 -161
  35. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  36. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +31 -23
  37. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  38. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +8 -13
  39. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  40. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +1 -1
  41. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  42. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  44. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +40 -10
  45. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +36 -11
  47. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  48. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +54 -71
  49. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  50. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +4 -0
  51. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.json +10 -0
  52. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  53. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  57. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  58. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +161 -62
  59. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  60. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +33 -25
  61. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  62. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +137 -140
  63. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  64. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +12 -12
  65. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  66. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +3 -3
  67. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  68. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +2 -2
  69. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +505 -91
  71. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  72. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +78 -42
  73. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  74. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +110 -27
  75. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  76. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +93 -96
  77. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  78. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +350 -8
  80. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +21 -64
  82. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +81 -0
  84. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +58 -157
  87. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  88. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +19 -47
  89. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +114 -17
  91. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +17 -9
  93. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +7 -7
  95. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +4 -4
  97. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  98. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +15 -2
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +19 -0
  101. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  102. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  103. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +18 -0
  104. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  105. package/artifacts/contracts/registry/Registry.sol/Registry.json +31 -12
  106. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  107. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  108. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  109. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +5 -5
  110. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  111. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +3 -3
  112. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  113. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +7 -7
  114. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  115. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  116. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  117. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  118. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  119. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  120. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  121. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  122. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  124. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  125. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  126. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  127. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  128. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  129. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  130. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  131. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +3 -3
  132. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  133. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  134. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  135. package/artifacts/contracts/shared/Service.sol/Service.json +1 -1
  136. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  137. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  138. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  139. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  140. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  141. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  142. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  143. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  144. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +3 -3
  145. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +6 -6
  147. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  148. package/artifacts/contracts/test/TestService.sol/TestService.json +3 -3
  149. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  150. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  151. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  152. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  153. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  154. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  155. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  156. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
  158. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  162. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/Fee.sol/FeeLib.json +2 -2
  164. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  165. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  166. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +17 -4
  168. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  169. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  170. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  172. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  173. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  174. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  175. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +23 -4
  176. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  177. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  178. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  179. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  180. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +4 -0
  181. package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
  182. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  183. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  184. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  185. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +25 -7
  186. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  187. package/artifacts/contracts/types/UFixed.sol/MathLib.json +2 -2
  188. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  189. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +2 -2
  190. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  192. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  193. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  194. package/contracts/components/Component.sol +95 -85
  195. package/contracts/components/Distribution.sol +12 -19
  196. package/contracts/components/IComponent.sol +37 -17
  197. package/contracts/components/IDistributionComponent.sol +1 -22
  198. package/contracts/components/IPoolComponent.sol +73 -47
  199. package/contracts/components/IProductComponent.sol +3 -2
  200. package/contracts/components/Pool.sol +171 -126
  201. package/contracts/components/Product.sol +26 -18
  202. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +13 -0
  203. package/contracts/instance/BundleManager.sol +7 -5
  204. package/contracts/instance/Cloneable.sol +7 -2
  205. package/contracts/instance/IInstance.sol +16 -10
  206. package/contracts/instance/IInstanceService.sol +18 -5
  207. package/contracts/instance/Instance.sol +45 -9
  208. package/contracts/instance/InstanceAccessManager.sol +382 -157
  209. package/contracts/instance/InstanceReader.sol +7 -10
  210. package/contracts/instance/InstanceService.sol +174 -155
  211. package/contracts/instance/ObjectManager.sol +6 -8
  212. package/contracts/instance/base/ComponentService.sol +5 -5
  213. package/contracts/instance/base/KeyValueStore.sol +5 -2
  214. package/contracts/instance/base/Lifecycle.sol +11 -2
  215. package/contracts/instance/module/IAccess.sol +20 -13
  216. package/contracts/instance/module/IBundle.sol +2 -1
  217. package/contracts/instance/module/IComponents.sol +35 -0
  218. package/contracts/instance/module/IDistribution.sol +2 -1
  219. package/contracts/instance/module/IPolicy.sol +26 -1
  220. package/contracts/instance/module/ISetup.sol +7 -22
  221. package/contracts/instance/service/ApplicationService.sol +123 -41
  222. package/contracts/instance/service/BundleService.sol +76 -38
  223. package/contracts/instance/service/DistributionService.sol +139 -47
  224. package/contracts/instance/service/IApplicationService.sol +7 -7
  225. package/contracts/instance/service/IBundleService.sol +19 -11
  226. package/contracts/instance/service/IDistributionService.sol +19 -4
  227. package/contracts/instance/service/IPolicyService.sol +3 -20
  228. package/contracts/instance/service/IPoolService.sol +17 -2
  229. package/contracts/instance/service/PolicyService.sol +59 -132
  230. package/contracts/instance/service/PoolService.sol +128 -17
  231. package/contracts/instance/service/ProductService.sol +10 -2
  232. package/contracts/registry/ChainNft.sol +8 -0
  233. package/contracts/registry/IRegistry.sol +2 -0
  234. package/contracts/registry/ITransferInterceptor.sol +1 -0
  235. package/contracts/registry/Registry.sol +23 -20
  236. package/contracts/registry/RegistryService.sol +5 -5
  237. package/contracts/shared/Registerable.sol +2 -2
  238. package/contracts/shared/TokenHandler.sol +11 -5
  239. package/contracts/types/Blocknumber.sol +1 -0
  240. package/contracts/types/Fee.sol +1 -0
  241. package/contracts/types/NftId.sol +8 -0
  242. package/contracts/types/ObjectType.sol +1 -0
  243. package/contracts/types/Referral.sol +4 -0
  244. package/contracts/types/RoleId.sol +13 -6
  245. package/contracts/types/Seconds.sol +54 -0
  246. package/contracts/types/StateId.sol +1 -0
  247. package/contracts/types/Timestamp.sol +13 -13
  248. package/contracts/types/UFixed.sol +1 -0
  249. package/contracts/types/Version.sol +1 -0
  250. package/package.json +1 -1
@@ -1,25 +1,27 @@
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
- import {Versionable} from "../../shared/Versionable.sol";
14
13
  import {INftOwnable} from "../../shared/INftOwnable.sol";
15
-
16
14
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
17
15
  import {ObjectType, POOL, BUNDLE} from "../../types/ObjectType.sol";
18
16
  import {POOL_OWNER_ROLE, RoleId} from "../../types/RoleId.sol";
17
+ import {Pool} from "../../components/Pool.sol";
18
+
19
19
  import {Fee, FeeLib} from "../../types/Fee.sol";
20
- import {Version, VersionLib} from "../../types/Version.sol";
21
- import {KEEP_STATE, StateId} from "../../types/StateId.sol";
20
+ import {StateId, ACTIVE, PAUSED, CLOSED, KEEP_STATE} from "../../types/StateId.sol";
21
+ import {Seconds} from "../../types/Seconds.sol";
22
22
  import {TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
23
+ import {Version, VersionLib} from "../../types/Version.sol";
24
+ import {Versionable} from "../../shared/Versionable.sol";
23
25
 
24
26
  import {IService} from "../../shared/IService.sol";
25
27
  import {Service} from "../../shared/Service.sol";
@@ -63,11 +65,11 @@ contract BundleService is
63
65
  return BUNDLE();
64
66
  }
65
67
 
66
- function createBundle(
68
+ function create(
67
69
  address owner,
68
70
  Fee memory fee,
69
71
  uint256 stakingAmount,
70
- uint256 lifetime,
72
+ Seconds lifetime,
71
73
  bytes calldata filter
72
74
  )
73
75
  external
@@ -118,7 +120,7 @@ contract BundleService is
118
120
  // TODO add logging
119
121
  }
120
122
 
121
- function setBundleFee(
123
+ function setFee(
122
124
  NftId bundleNftId,
123
125
  Fee memory fee
124
126
  )
@@ -138,30 +140,6 @@ contract BundleService is
138
140
  instance.updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
139
141
  }
140
142
 
141
- function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state)
142
- external
143
- onlyService
144
- {
145
- IRegistry.ObjectInfo memory instanceInfo = getRegistry().getObjectInfo(instanceNftId);
146
- IInstance instance = IInstance(instanceInfo.objectAddress);
147
- instance.updateBundle(bundleNftId, bundleInfo, state);
148
- }
149
-
150
- function lockBundle(NftId bundleNftId)
151
- external
152
- {
153
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
154
- BundleManager bundleManager = instance.getBundleManager();
155
- bundleManager.lock(bundleNftId);
156
- }
157
-
158
- function unlockBundle(NftId bundleNftId)
159
- external
160
- {
161
- (, IInstance instance) = _getAndVerifyComponentInfoAndInstance(POOL());
162
- BundleManager bundleManager = instance.getBundleManager();
163
- bundleManager.unlock(bundleNftId);
164
- }
165
143
 
166
144
  function lockCollateral(
167
145
  IInstance instance,
@@ -190,6 +168,64 @@ contract BundleService is
190
168
  linkPolicy(instance, policyNftId);
191
169
  }
192
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
+
193
229
  function increaseBalance(IInstance instance,
194
230
  NftId bundleNftId,
195
231
  uint256 amount
@@ -234,7 +270,7 @@ contract BundleService is
234
270
 
235
271
  // ensure policy has not yet been activated
236
272
  if (policyInfo.activatedAt.gtz()) {
237
- revert BundleManager.ErrorBundleManagerErrorPolicyAlreadyActivated(policyNftId);
273
+ revert BundleManager.ErrorBundleManagerPolicyAlreadyActivated(policyNftId);
238
274
  }
239
275
 
240
276
  BundleManager bundleManager = instance.getBundleManager();
@@ -277,18 +313,20 @@ contract BundleService is
277
313
  {
278
314
  // process token transfer(s)
279
315
  if(stakingAmount > 0) {
280
- ISetup.PoolSetupInfo memory poolInfo = instanceReader.getPoolSetupInfo(poolNftId);
281
- 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;
282
321
  address bundleOwner = getRegistry().ownerOf(bundleNftId);
283
322
  Fee memory stakingFee = poolInfo.stakingFee;
284
323
 
285
324
  tokenHandler.transfer(
286
325
  bundleOwner,
287
- poolInfo.wallet,
326
+ componentInfo.wallet,
288
327
  stakingAmount
289
328
  );
290
329
 
291
-
292
330
  if (! FeeLib.feeIsZero(stakingFee)) {
293
331
  (uint256 stakingFeeAmount, uint256 netAmount) = FeeLib.calculateFee(stakingFee, stakingAmount);
294
332
  // TODO: track staking fees in pool's state (issue #177)
@@ -6,13 +6,15 @@ import {IInstance} from "../../instance/IInstance.sol";
6
6
  import {InstanceAccessManager} from "../InstanceAccessManager.sol";
7
7
  import {InstanceReader} from "../../instance/InstanceReader.sol";
8
8
  import {ISetup} from "../../instance/module/ISetup.sol";
9
+ import {IPolicy} from "../module/IPolicy.sol";
9
10
 
10
11
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
11
12
  import {Fee, FeeLib} from "../../types/Fee.sol";
12
- import {DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
13
+ import {PRODUCT_SERVICE_ROLE, DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
13
14
  import {KEEP_STATE} from "../../types/StateId.sol";
14
15
  import {ObjectType, DISTRIBUTION, INSTANCE, DISTRIBUTION, DISTRIBUTOR} from "../../types/ObjectType.sol";
15
16
  import {Version, VersionLib} from "../../types/Version.sol";
17
+ import {RoleId} from "../../types/RoleId.sol";
16
18
 
17
19
  import {IVersionable} from "../../shared/IVersionable.sol";
18
20
  import {Versionable} from "../../shared/Versionable.sol";
@@ -41,6 +43,7 @@ contract DistributionService is
41
43
  using TimestampLib for Timestamp;
42
44
  using UFixedLib for UFixed;
43
45
  using FeeLib for Fee;
46
+ using ReferralLib for ReferralId;
44
47
 
45
48
  address internal _registryAddress;
46
49
 
@@ -85,21 +88,43 @@ contract DistributionService is
85
88
  distributionNftId = distributionInfo.nftId;
86
89
 
87
90
  instance.createDistributionSetup(distributionNftId, distribution.getSetupInfo());
88
- getInstanceService().createGifTarget(instanceNftId, distributionAddress, distribution.getName());
89
- getInstanceService().grantDistributionDefaultPermissions(instanceNftId, distributionAddress, distribution.getName());
91
+ // TODO move to distribution?
92
+ bytes4[][] memory selectors = new bytes4[][](2);
93
+ selectors[0] = new bytes4[](1);
94
+ selectors[1] = new bytes4[](2);
95
+
96
+ selectors[0][0] = IDistributionComponent.setFees.selector;
97
+ selectors[1][0] = IDistributionComponent.processRenewal.selector;
98
+
99
+ RoleId[] memory roles = new RoleId[](2);
100
+ roles[0] = DISTRIBUTION_OWNER_ROLE();
101
+ roles[1] = PRODUCT_SERVICE_ROLE();
102
+
103
+ getInstanceService().createGifTarget(
104
+ instanceNftId,
105
+ distributionAddress,
106
+ distribution.getName(),
107
+ selectors,
108
+ roles);
90
109
  }
91
110
 
92
111
  function setFees(
112
+ Fee memory minDistributionOwnerFee,
93
113
  Fee memory distributionFee
94
114
  )
95
115
  external
96
116
  override
97
117
  {
118
+ if (minDistributionOwnerFee.fractionalFee > distributionFee.fractionalFee) {
119
+ revert ErrorIDistributionServiceMinFeeTooHigh(minDistributionOwnerFee.fractionalFee.toInt(), distributionFee.fractionalFee.toInt());
120
+ }
121
+
98
122
  (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
99
123
  InstanceReader instanceReader = instance.getInstanceReader();
100
124
  NftId distributionNftId = info.nftId;
101
125
 
102
126
  ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
127
+ distSetupInfo.minDistributionOwnerFee = minDistributionOwnerFee;
103
128
  distSetupInfo.distributionFee = distributionFee;
104
129
 
105
130
  instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
@@ -122,13 +147,11 @@ contract DistributionService is
122
147
  (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
123
148
 
124
149
  {
125
- if (commissionPercentage > maxDiscountPercentage) {
126
- revert ErrorIDistributionServiceCommissionTooHigh(commissionPercentage.toInt(), maxDiscountPercentage.toInt());
127
- }
128
-
129
150
  ISetup.DistributionSetupInfo memory setupInfo = instance.getInstanceReader().getDistributionSetupInfo(distributionNftId);
130
- if (maxDiscountPercentage > setupInfo.distributionFee.fractionalFee) {
131
- revert ErrorIDistributionServiceMaxDiscountTooHigh(maxDiscountPercentage.toInt(), setupInfo.distributionFee.fractionalFee.toInt());
151
+ UFixed variableFeesPartsTotal = setupInfo.minDistributionOwnerFee.fractionalFee.add(commissionPercentage);
152
+ UFixed maxDiscountPercentageLimit = setupInfo.distributionFee.fractionalFee.sub(variableFeesPartsTotal);
153
+ if (maxDiscountPercentage.gt(maxDiscountPercentageLimit)) {
154
+ revert ErrorIDistributionServiceMaxDiscountTooHigh(maxDiscountPercentage.toInt(), maxDiscountPercentageLimit.toInt());
132
155
  }
133
156
  }
134
157
 
@@ -173,7 +196,9 @@ contract DistributionService is
173
196
  IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
174
197
  distributorType,
175
198
  true, // active
176
- data);
199
+ data,
200
+ 0,
201
+ 0);
177
202
 
178
203
  instance.createDistributor(distributorNftId, info);
179
204
  }
@@ -185,13 +210,11 @@ contract DistributionService is
185
210
  ) external virtual
186
211
  {
187
212
  (,, IInstance instance) = _getAndVerifyCallingDistribution();
188
-
189
- IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
190
- distributorType,
191
- true, // active
192
- data);
193
-
194
- instance.updateDistributor(distributorNftId, info, KEEP_STATE());
213
+ InstanceReader instanceReader = instance.getInstanceReader();
214
+ IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
215
+ distributorInfo.distributorType = distributorType;
216
+ distributorInfo.data = data;
217
+ instance.updateDistributor(distributorNftId, distributorInfo, KEEP_STATE());
195
218
  }
196
219
 
197
220
 
@@ -217,8 +240,8 @@ contract DistributionService is
217
240
  }
218
241
 
219
242
  InstanceReader instanceReader = instance.getInstanceReader();
220
- IDistribution.DistributorInfo memory distributorTypeInfo = instanceReader.getDistributorInfo(distributorNftId);
221
- DistributorType distributorType = distributorTypeInfo.distributorType;
243
+ IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
244
+ DistributorType distributorType = distributorInfo.distributorType;
222
245
  IDistribution.DistributorTypeInfo memory distributorTypeData = instanceReader.getDistributorTypeInfo(distributorType);
223
246
 
224
247
  if (distributorTypeData.maxReferralCount < maxReferrals) {
@@ -250,53 +273,122 @@ contract DistributionService is
250
273
  }
251
274
 
252
275
  function processSale(
276
+ NftId distributionNftId,
253
277
  ReferralId referralId,
254
- uint256 premiumAmount
278
+ IPolicy.Premium memory premium,
279
+ uint256 transferredDistributionFeeAmount
255
280
  )
256
281
  external
257
282
  virtual
258
283
  {
259
- // TODO: fetch referral
260
- // TODO: update referral usage numbers
261
- // TODO: update bookkeeping
262
- // TODO: calculate commission for distributor
263
- // TODO: calculate fee for distribution owner
264
- // TODO: updates sum of commission per distributor -> DistributorInfo
265
- // TODO: updates sum of fee per distribution owner
266
- revert("NOT_IMPLEMENTED_YET");
284
+ bool isReferral = ! referralId.eqz();
285
+ bool referralValid = referralIsValid(distributionNftId, referralId);
286
+
287
+ if (isReferral && ! referralValid) {
288
+ revert ErrorIDistributionServiceReferralInvalid(distributionNftId, referralId);
289
+ }
290
+
291
+ (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
292
+ InstanceReader reader = instance.getInstanceReader();
293
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
294
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
295
+ ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
296
+
297
+ uint256 distributionOwnerFee = premium.distributionOwnerFeeFixAmount + premium.distributionOwnerFeeVarAmount;
298
+ uint256 commissionAmount = premium.commissionAmount;
299
+
300
+ if (transferredDistributionFeeAmount != distributionOwnerFee + commissionAmount) {
301
+ revert ErrorIDistributionServiceInvalidFeeTransferred(transferredDistributionFeeAmount, distributionOwnerFee + commissionAmount);
302
+ }
303
+
304
+
305
+ if (distributionOwnerFee > 0) {
306
+ setupInfo.sumDistributionOwnerFees += distributionOwnerFee;
307
+ instance.updateDistributionSetup(distributionNftId, setupInfo, KEEP_STATE());
308
+ }
309
+
310
+ if (isReferral) {
311
+ referralInfo.usedReferrals += 1;
312
+ instance.updateReferral(referralId.toKey32(), referralInfo, KEEP_STATE());
313
+
314
+ if (commissionAmount > 0) {
315
+ distributorInfo.sumCommisions += commissionAmount;
316
+ distributorInfo.numPoliciesSold += 1;
317
+ instance.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
318
+ }
319
+ }
267
320
  }
268
321
 
269
322
  function calculateFeeAmount(
270
323
  NftId distributionNftId,
271
324
  ReferralId referralId,
272
- uint256 netPremiumAmount
325
+ IPolicy.Premium memory premium
273
326
  )
274
327
  external
275
328
  virtual
276
329
  view
277
- returns (uint256 feeAmount)
330
+ returns (IPolicy.Premium memory finalPremium)
278
331
  {
279
- (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
332
+ (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
280
333
  InstanceReader reader = instance.getInstanceReader();
281
-
282
- // calculate fee based on the distribution components fee
334
+
335
+ // first calculate all fixed and variable fees for the distribution - this will defined the fullPremium
283
336
  ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
284
- Fee memory fee = setupInfo.distributionFee;
285
- (feeAmount,) = fee.calculateFee(netPremiumAmount);
286
-
287
- if (referralIsValid(distributionNftId, referralId)) {
288
- // (distributionFee(fixed + pct) - referralDiscount(pct)) ... discount <= distributionFee
289
- IDistribution.ReferralInfo memory info = reader.getReferralInfo(referralId);
290
- uint256 discountAmount = UFixedLib.toUFixed(netPremiumAmount).mul(info.discountPercentage).toInt();
291
- if (discountAmount > feeAmount) {
292
- feeAmount = 0;
293
- } else {
294
- feeAmount -= discountAmount;
295
- }
296
- }
297
- // else - just use distributionFee from component
337
+ Fee memory distributionFee = setupInfo.distributionFee;
338
+ Fee memory minDistributionOwnerFee = setupInfo.minDistributionOwnerFee;
339
+ uint256 distributionFeeVarAmount = (UFixedLib.toUFixed(premium.netPremiumAmount) * distributionFee.fractionalFee).toInt();
340
+ premium.distributionFeeVarAmount = distributionFeeVarAmount;
341
+ premium.fullPremiumAmount += distributionFeeVarAmount;
342
+
343
+ // if the referral is not valid, then the distribution owner gets everything
344
+ if (! referralIsValid(distributionNftId, referralId)) {
345
+ premium.distributionOwnerFeeFixAmount = premium.distributionFeeFixAmount;
346
+ premium.distributionOwnerFeeVarAmount = premium.distributionFeeVarAmount;
347
+ premium.premiumAmount = premium.fullPremiumAmount;
348
+ return premium;
349
+ }
350
+
351
+ // if the referral is valid, the the commission and discount are calculated based in the full premium
352
+ // the remaing amount goes to the distribution owner
353
+ {
354
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
355
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
356
+ IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
357
+
358
+ uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
359
+ premium.commissionAmount = commissionAmount;
360
+ premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
361
+ premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
362
+ premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
363
+ premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
364
+ }
365
+
366
+ // sanity check to validate the fee calculation
367
+ if (premium.distributionOwnerFeeFixAmount < minDistributionOwnerFee.fixedFee) {
368
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
369
+ premium.distributionFeeFixAmount,
370
+ premium.distributionFeeVarAmount,
371
+ premium.distributionOwnerFeeFixAmount,
372
+ premium.distributionOwnerFeeVarAmount,
373
+ premium.commissionAmount,
374
+ premium.discountAmount
375
+ );
376
+ }
377
+ if ((premium.distributionFeeVarAmount) != (premium.discountAmount + premium.distributionOwnerFeeVarAmount + premium.commissionAmount)) {
378
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
379
+ premium.distributionFeeFixAmount,
380
+ premium.distributionFeeVarAmount,
381
+ premium.distributionOwnerFeeFixAmount,
382
+ premium.distributionOwnerFeeVarAmount,
383
+ premium.commissionAmount,
384
+ premium.discountAmount
385
+ );
386
+ }
387
+
388
+ return premium;
298
389
  }
299
390
 
391
+ // TODO: zero should return false
300
392
  function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
301
393
  (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
302
394
  IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);
@@ -1,12 +1,14 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IPolicy} from "../module/IPolicy.sol";
4
5
  import {IRisk} from "../module/IRisk.sol";
5
6
  import {IService} from "../../shared/IService.sol";
6
7
 
7
8
  import {NftId} from "../../types/NftId.sol";
8
9
  import {ReferralId} from "../../types/Referral.sol";
9
10
  import {RiskId} from "../../types/RiskId.sol";
11
+ import {Seconds} from "../../types/Seconds.sol";
10
12
  import {StateId} from "../../types/StateId.sol";
11
13
  import {Timestamp} from "../../types/Timestamp.sol";
12
14
  import {UFixed} from "../../types/UFixed.sol";
@@ -17,6 +19,7 @@ import {Fee} from "../../types/Fee.sol";
17
19
  interface IApplicationService is IService {
18
20
 
19
21
  error IApplicationServicePolicyNotApplied(NftId applicationNftId);
22
+ error IApplicationServiceBundlePoolMismatch(NftId bundleNftId, NftId bundlePoolNftId, NftId poolNftId);
20
23
 
21
24
  /// @dev creates a new application based on the specified attributes
22
25
  /// may only be called by a product component
@@ -24,7 +27,7 @@ interface IApplicationService is IService {
24
27
  address applicationOwner,
25
28
  RiskId riskId,
26
29
  uint256 sumInsuredAmount,
27
- uint256 lifetime,
30
+ Seconds lifetime,
28
31
  NftId bundleNftId,
29
32
  ReferralId referralId,
30
33
  bytes memory applicationData
@@ -63,9 +66,10 @@ interface IApplicationService is IService {
63
66
  /// @dev calculates the premium amount for the specified attributes
64
67
  /// also returns the various fee components involved with creating a policy
65
68
  function calculatePremium(
69
+ NftId productNftId,
66
70
  RiskId riskId,
67
71
  uint256 sumInsuredAmount,
68
- uint256 lifetime,
72
+ Seconds lifetime,
69
73
  bytes memory applicationData,
70
74
  NftId bundleNftId,
71
75
  ReferralId referralId
@@ -73,10 +77,6 @@ interface IApplicationService is IService {
73
77
  external
74
78
  view
75
79
  returns (
76
- uint256 premiumAmount,
77
- uint256 distributionFeeAmount,
78
- uint256 productFeeAmount,
79
- uint256 poolFeeAmount,
80
- uint256 bundleFeeAmount
80
+ IPolicy.Premium memory premium
81
81
  );
82
82
  }
@@ -3,28 +3,36 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {NftId} from "../../types/NftId.sol";
5
5
  import {Fee} from "../../types/Fee.sol";
6
- import {StateId} from "../../types/StateId.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 {Seconds} from "../../types/Seconds.sol";
10
+ import {StateId} from "../../types/StateId.sol";
10
11
 
11
12
  interface IBundleService is IService {
12
- error ErrorIBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
13
13
 
14
- 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(
15
23
  address owner,
16
24
  Fee memory fee,
17
25
  uint256 amount,
18
- uint256 lifetime,
26
+ Seconds lifetime,
19
27
  bytes calldata filter
20
28
  ) external returns(NftId bundleNftId);
21
29
 
22
- function setBundleFee(
30
+
31
+ function setFee(
23
32
  NftId bundleNftId,
24
33
  Fee memory fee
25
34
  ) external;
26
35
 
27
- function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) external;
28
36
 
29
37
  function lockCollateral(
30
38
  IInstance instanceNftId,
@@ -42,13 +50,13 @@ interface IBundleService is IService {
42
50
 
43
51
  function closePolicy(IInstance instance, NftId policyNftId, NftId bundleNftId, uint256 collateralAmount) external;
44
52
 
45
- // function fundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
53
+ // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
46
54
 
47
- // function defundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
55
+ // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
48
56
 
49
- function lockBundle(NftId bundleNftId) external;
57
+ function lock(NftId bundleNftId) external;
50
58
 
51
- function unlockBundle(NftId bundleNftId) external;
59
+ function unlock(NftId bundleNftId) external;
52
60
 
53
- // function closeBundle(NftId bundleNftId) external;
61
+ function close(NftId bundleNftId) external;
54
62
  }
@@ -3,6 +3,7 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {NftId} from "../../types/NftId.sol";
5
5
  import {Fee} from "../../types/Fee.sol";
6
+ import {IPolicy} from "../module/IPolicy.sol";
6
7
  import {IService} from "../../shared/IService.sol";
7
8
  import {UFixed} from "../../types/UFixed.sol";
8
9
  import {DistributorType} from "../../types/DistributorType.sol";
@@ -21,9 +22,21 @@ interface IDistributionService is IService {
21
22
  error ErrorIDistributionServiceInvalidReferral(string code);
22
23
  error ErrorIDistributionServiceExpirationInvalid(Timestamp expiryAt);
23
24
  error ErrorIDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
24
- error ErrorIDistributionServiceMaxDiscountTooHigh(uint256 maxDiscountPercentage, uint256 maxMaxDiscountPercentage);
25
+ error ErrorIDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
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);
25
37
 
26
38
  function setFees(
39
+ Fee memory minDistributionOwnerFee,
27
40
  Fee memory distributionFee
28
41
  ) external;
29
42
 
@@ -66,15 +79,17 @@ interface IDistributionService is IService {
66
79
 
67
80
  /// @dev callback from product service when selling a policy for a specific referralId
68
81
  function processSale(
82
+ NftId distributionNftId,
69
83
  ReferralId referralId,
70
- uint256 premiumAmount
84
+ IPolicy.Premium memory premium,
85
+ uint256 transferredDistributionFeeAmount
71
86
  ) external;
72
87
 
73
88
  function calculateFeeAmount(
74
89
  NftId distributionNftId,
75
90
  ReferralId referralId,
76
- uint256 netPremiumAmount
77
- ) external view returns (uint256 feeAmount);
91
+ IPolicy.Premium memory premium
92
+ ) external view returns (IPolicy.Premium memory finalPremium);
78
93
 
79
94
  function referralIsValid(
80
95
  NftId distributorNftId,