@etherisc/gif-next 0.0.2-f034782-101 → 0.0.2-f080b71-868

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. package/README.md +6 -83
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +10 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +10 -0
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IComponent.sol/IComponent.json +100 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +100 -0
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +110 -0
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +100 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +20 -0
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +10 -0
  18. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +1 -1
  19. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  20. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
  21. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  22. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  23. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +214 -1988
  24. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  25. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +101 -14
  26. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  27. package/artifacts/contracts/instance/Instance.sol/Instance.json +379 -2729
  28. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  29. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +95 -58
  30. package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.dbg.json +4 -0
  31. package/artifacts/contracts/instance/InstanceAuthorizationsLib.sol/InstanceAuthorizationsLib.json +124 -0
  32. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +45 -25
  34. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  35. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +157 -126
  36. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  37. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +30 -58
  38. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +4 -0
  39. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +2677 -0
  40. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  41. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
  42. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +108 -21
  44. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +2 -2
  48. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  49. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +2 -2
  50. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +6 -6
  52. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  53. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  59. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  60. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +119 -227
  61. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  62. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +11 -35
  63. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  64. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +330 -147
  65. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  66. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +70 -14
  67. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  68. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +127 -32
  69. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  70. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +11 -7
  71. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  72. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +193 -386
  73. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  74. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +38 -74
  75. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  76. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +68 -149
  77. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  78. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +163 -113
  79. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  80. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +80 -14
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  82. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +89 -231
  83. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +132 -24
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  86. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +430 -14
  87. package/artifacts/contracts/instance/service/IPricingService.sol/IPricingService.dbg.json +4 -0
  88. package/artifacts/contracts/instance/service/IPricingService.sol/IPricingService.json +518 -0
  89. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +80 -14
  91. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +210 -65
  93. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +27 -19
  95. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +493 -48
  97. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  98. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +18 -14
  99. package/artifacts/contracts/instance/service/PricingService.sol/PricingService.dbg.json +4 -0
  100. package/artifacts/contracts/instance/service/PricingService.sol/PricingService.json +988 -0
  101. package/artifacts/contracts/instance/service/PricingServiceManager.sol/PricingServiceManager.dbg.json +4 -0
  102. package/artifacts/contracts/instance/service/PricingServiceManager.sol/PricingServiceManager.json +689 -0
  103. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  104. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +139 -44
  105. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  106. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +16 -12
  107. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  108. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  109. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  110. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +0 -24
  111. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  112. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  114. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  115. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  116. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  117. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +17 -36
  118. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  119. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  120. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  121. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +23 -11
  122. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  123. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  124. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  125. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  126. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  128. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  130. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  131. package/artifacts/contracts/shared/IService.sol/IService.json +80 -14
  132. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  133. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  134. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  135. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  136. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  137. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  138. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  139. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  140. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  141. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  142. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  143. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  144. package/artifacts/contracts/shared/Service.sol/Service.json +86 -15
  145. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  146. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  147. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  148. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  149. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  150. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  151. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  152. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  153. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  154. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  155. package/artifacts/contracts/test/TestService.sol/TestService.json +101 -26
  156. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  157. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  159. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  160. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  161. package/artifacts/contracts/types/Amount.sol/AmountLib.dbg.json +4 -0
  162. package/artifacts/contracts/types/Amount.sol/AmountLib.json +161 -0
  163. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  165. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  168. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/Fee.sol/FeeLib.json +40 -9
  170. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  171. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  172. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  173. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  174. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  175. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  176. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  177. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  178. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  179. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  180. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +2 -2
  182. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  183. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  184. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  185. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  186. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +1 -1
  187. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  188. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  189. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  190. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  192. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  193. package/contracts/components/Component.sol +4 -2
  194. package/contracts/components/IComponent.sol +3 -1
  195. package/contracts/components/Pool.sol +8 -4
  196. package/contracts/components/Product.sol +8 -5
  197. package/contracts/instance/IInstance.sol +16 -54
  198. package/contracts/instance/IInstanceService.sol +14 -2
  199. package/contracts/instance/Instance.sol +88 -188
  200. package/contracts/instance/InstanceAccessManager.sol +41 -23
  201. package/contracts/instance/InstanceAuthorizationsLib.sol +299 -0
  202. package/contracts/instance/InstanceReader.sol +15 -6
  203. package/contracts/instance/InstanceService.sol +59 -234
  204. package/contracts/instance/InstanceStore.sol +219 -0
  205. package/contracts/instance/base/ComponentService.sol +51 -38
  206. package/contracts/instance/base/KeyValueStore.sol +8 -3
  207. package/contracts/instance/module/IAccess.sol +2 -2
  208. package/contracts/instance/module/IBundle.sol +6 -4
  209. package/contracts/instance/module/IComponents.sol +6 -0
  210. package/contracts/instance/service/ApplicationService.sol +35 -202
  211. package/contracts/instance/service/BundleService.sol +165 -70
  212. package/contracts/instance/service/ClaimService.sol +2 -8
  213. package/contracts/instance/service/DistributionService.sol +30 -151
  214. package/contracts/instance/service/IApplicationService.sol +0 -18
  215. package/contracts/instance/service/IBundleService.sol +54 -22
  216. package/contracts/instance/service/IDistributionService.sol +1 -14
  217. package/contracts/instance/service/IPolicyService.sol +2 -0
  218. package/contracts/instance/service/IPoolService.sol +65 -1
  219. package/contracts/instance/service/IPricingService.sol +36 -0
  220. package/contracts/instance/service/PolicyService.sol +88 -115
  221. package/contracts/instance/service/PoolService.sol +136 -53
  222. package/contracts/instance/service/PricingService.sol +275 -0
  223. package/contracts/instance/service/PricingServiceManager.sol +51 -0
  224. package/contracts/instance/service/ProductService.sol +25 -56
  225. package/contracts/registry/IRegistryService.sol +4 -3
  226. package/contracts/registry/RegistryService.sol +25 -22
  227. package/contracts/registry/ReleaseManager.sol +20 -18
  228. package/contracts/shared/IService.sol +4 -6
  229. package/contracts/shared/Service.sol +21 -7
  230. package/contracts/test/TestService.sol +1 -1
  231. package/contracts/types/Amount.sol +60 -0
  232. package/contracts/types/Fee.sol +12 -5
  233. package/contracts/types/ObjectType.sol +4 -0
  234. package/package.json +1 -1
@@ -12,7 +12,7 @@ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
12
12
  import {Fee, FeeLib} from "../../types/Fee.sol";
13
13
  import {PRODUCT_SERVICE_ROLE, DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
14
14
  import {KEEP_STATE} from "../../types/StateId.sol";
15
- import {ObjectType, DISTRIBUTION, INSTANCE, DISTRIBUTION, DISTRIBUTOR} from "../../types/ObjectType.sol";
15
+ import {ObjectType, DISTRIBUTION, INSTANCE, DISTRIBUTION, DISTRIBUTOR, PRICE} from "../../types/ObjectType.sol";
16
16
  import {Version, VersionLib} from "../../types/Version.sol";
17
17
  import {RoleId} from "../../types/RoleId.sol";
18
18
 
@@ -26,6 +26,7 @@ import {InstanceService} from "../InstanceService.sol";
26
26
  import {IComponent} from "../../components/IComponent.sol";
27
27
  import {IDistributionComponent} from "../../components/IDistributionComponent.sol";
28
28
  import {IDistributionService} from "./IDistributionService.sol";
29
+ import {IPricingService} from "./IPricingService.sol";
29
30
 
30
31
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
31
32
  import {DistributorType, DistributorTypeLib} from "../../types/DistributorType.sol";
@@ -33,6 +34,7 @@ import {ReferralId, ReferralStatus, ReferralLib} from "../../types/Referral.sol"
33
34
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
34
35
  import {Key32} from "../../types/Key32.sol";
35
36
  import {IDistribution} from "../module/IDistribution.sol";
37
+ import {InstanceStore} from "../InstanceStore.sol";
36
38
 
37
39
 
38
40
  contract DistributionService is
@@ -60,11 +62,11 @@ contract DistributionService is
60
62
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
61
63
  // TODO while DistributionService is not deployed in DistributionServiceManager constructor
62
64
  // owner is DistributionServiceManager deployer
63
- initializeService(registryAddress, owner);
65
+ initializeService(registryAddress, address(0), owner);
64
66
  registerInterface(type(IDistributionService).interfaceId);
65
67
  }
66
68
 
67
- function getDomain() public pure override(Service, IService) returns(ObjectType) {
69
+ function getDomain() public pure override returns(ObjectType) {
68
70
  return DISTRIBUTION();
69
71
  }
70
72
 
@@ -87,7 +89,7 @@ contract DistributionService is
87
89
  distribution.linkToRegisteredNftId();
88
90
  distributionNftId = distributionInfo.nftId;
89
91
 
90
- instance.createDistributionSetup(distributionNftId, distribution.getSetupInfo());
92
+ instance.getInstanceStore().createDistributionSetup(distributionNftId, distribution.getSetupInfo());
91
93
  // TODO move to distribution?
92
94
  bytes4[][] memory selectors = new bytes4[][](2);
93
95
  selectors[0] = new bytes4[](1);
@@ -119,15 +121,14 @@ contract DistributionService is
119
121
  revert ErrorIDistributionServiceMinFeeTooHigh(minDistributionOwnerFee.fractionalFee.toInt(), distributionFee.fractionalFee.toInt());
120
122
  }
121
123
 
122
- (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
124
+ (NftId distributionNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(DISTRIBUTION());
123
125
  InstanceReader instanceReader = instance.getInstanceReader();
124
- NftId distributionNftId = info.nftId;
125
126
 
126
127
  ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
127
128
  distSetupInfo.minDistributionOwnerFee = minDistributionOwnerFee;
128
129
  distSetupInfo.distributionFee = distributionFee;
129
130
 
130
- instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
131
+ instance.getInstanceStore().updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
131
132
  }
132
133
 
133
134
  function createDistributorType(
@@ -144,7 +145,7 @@ contract DistributionService is
144
145
  external
145
146
  returns (DistributorType distributorType)
146
147
  {
147
- (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
148
+ (NftId distributionNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(DISTRIBUTION());
148
149
 
149
150
  {
150
151
  ISetup.DistributionSetupInfo memory setupInfo = instance.getInstanceReader().getDistributionSetupInfo(distributionNftId);
@@ -154,11 +155,11 @@ contract DistributionService is
154
155
  revert ErrorIDistributionServiceMaxDiscountTooHigh(maxDiscountPercentage.toInt(), maxDiscountPercentageLimit.toInt());
155
156
  }
156
157
  }
157
-
158
+
158
159
  distributorType = DistributorTypeLib.toDistributorType(distributionNftId, name);
159
160
  Key32 key32 = distributorType.toKey32();
160
161
 
161
- if(!instance.exists(key32)) {
162
+ if(!instance.getInstanceStore().exists(key32)) {
162
163
  IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo(
163
164
  name,
164
165
  minDiscountPercentage,
@@ -170,7 +171,7 @@ contract DistributionService is
170
171
  allowRenewals,
171
172
  data);
172
173
 
173
- instance.createDistributorType(key32, info);
174
+ instance.getInstanceStore().createDistributorType(key32, info);
174
175
  }
175
176
  }
176
177
 
@@ -180,7 +181,7 @@ contract DistributionService is
180
181
  bytes memory data
181
182
  ) external returns (NftId distributorNftId)
182
183
  {
183
- (, NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
184
+ (NftId distributionNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(DISTRIBUTION());
184
185
 
185
186
  distributorNftId = getRegistryService().registerDistributor(
186
187
  IRegistry.ObjectInfo(
@@ -200,7 +201,7 @@ contract DistributionService is
200
201
  0,
201
202
  0);
202
203
 
203
- instance.createDistributor(distributorNftId, info);
204
+ instance.getInstanceStore().createDistributor(distributorNftId, info);
204
205
  }
205
206
 
206
207
  function updateDistributorType(
@@ -209,12 +210,12 @@ contract DistributionService is
209
210
  bytes memory data
210
211
  ) external virtual
211
212
  {
212
- (,, IInstance instance) = _getAndVerifyCallingDistribution();
213
+ (,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(DISTRIBUTION());
213
214
  InstanceReader instanceReader = instance.getInstanceReader();
214
215
  IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
215
216
  distributorInfo.distributorType = distributorType;
216
217
  distributorInfo.data = data;
217
- instance.updateDistributor(distributorNftId, distributorInfo, KEEP_STATE());
218
+ instance.getInstanceStore().updateDistributor(distributorNftId, distributorInfo, KEEP_STATE());
218
219
  }
219
220
 
220
221
 
@@ -230,7 +231,7 @@ contract DistributionService is
230
231
  virtual
231
232
  returns (ReferralId referralId)
232
233
  {
233
- (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
234
+ (NftId distributionNftId,, IInstance instance) = _getAndVerifyCallingComponentAndInstance(DISTRIBUTION());
234
235
 
235
236
  if (bytes(code).length == 0) {
236
237
  revert ErrorIDistributionServiceInvalidReferral(code);
@@ -268,12 +269,12 @@ contract DistributionService is
268
269
  data
269
270
  );
270
271
 
271
- instance.createReferral(referralId.toKey32(), info);
272
+ instance.getInstanceStore().createReferral(referralId.toKey32(), info);
272
273
  return referralId;
273
274
  }
274
275
 
275
276
  function processSale(
276
- NftId distributionNftId,
277
+ NftId distributionNftId, // assume always of distribution type
277
278
  ReferralId referralId,
278
279
  IPolicy.Premium memory premium,
279
280
  uint256 transferredDistributionFeeAmount
@@ -288,8 +289,9 @@ contract DistributionService is
288
289
  revert ErrorIDistributionServiceReferralInvalid(distributionNftId, referralId);
289
290
  }
290
291
 
291
- (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
292
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
292
293
  InstanceReader reader = instance.getInstanceReader();
294
+ InstanceStore store = instance.getInstanceStore();
293
295
  IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
294
296
  IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
295
297
  ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
@@ -304,93 +306,24 @@ contract DistributionService is
304
306
 
305
307
  if (distributionOwnerFee > 0) {
306
308
  setupInfo.sumDistributionOwnerFees += distributionOwnerFee;
307
- instance.updateDistributionSetup(distributionNftId, setupInfo, KEEP_STATE());
309
+ store.updateDistributionSetup(distributionNftId, setupInfo, KEEP_STATE());
308
310
  }
309
311
 
310
312
  if (isReferral) {
311
313
  referralInfo.usedReferrals += 1;
312
- instance.updateReferral(referralId.toKey32(), referralInfo, KEEP_STATE());
314
+ store.updateReferral(referralId.toKey32(), referralInfo, KEEP_STATE());
313
315
 
314
316
  if (commissionAmount > 0) {
315
317
  distributorInfo.sumCommisions += commissionAmount;
316
318
  distributorInfo.numPoliciesSold += 1;
317
- instance.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
319
+ store.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
318
320
  }
319
321
  }
320
322
  }
321
323
 
322
- function calculateFeeAmount(
323
- NftId distributionNftId,
324
- ReferralId referralId,
325
- IPolicy.Premium memory premium
326
- )
327
- external
328
- virtual
329
- view
330
- returns (IPolicy.Premium memory finalPremium)
331
- {
332
- (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
333
- InstanceReader reader = instance.getInstanceReader();
334
-
335
- // first calculate all fixed and variable fees for the distribution - this will defined the fullPremium
336
- ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
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;
389
- }
390
-
391
324
  // TODO: zero should return false
392
325
  function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
393
- (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
326
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
394
327
  IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);
395
328
 
396
329
  if (info.distributorNftId.eqz()) {
@@ -401,67 +334,13 @@ contract DistributionService is
401
334
  isValid = isValid && info.usedReferrals < info.maxReferrals;
402
335
  }
403
336
 
404
- function _getAndVerifyCallingDistribution()
337
+ function _getInstanceForDistribution(NftId distributionNftId)
405
338
  internal
406
339
  view
407
- returns(
408
- address distributionAddress,
409
- NftId distributionNftId,
410
- IInstance instance
411
- )
340
+ returns(IInstance instance)
412
341
  {
413
- ObjectType objectType;
414
- (
415
- distributionAddress,
416
- distributionNftId,
417
- objectType,
418
- instance
419
- ) = _getAndVerifyCaller();
420
-
421
- if(objectType != DISTRIBUTION()) {
422
- revert ErrorIDistributionServiceCallerNotDistributor(msg.sender);
423
- }
424
- }
425
-
426
- function _getAndVerifyDistribution(NftId distributionNftId)
427
- internal
428
- view
429
- returns(
430
- address distributionAddress,
431
- IInstance instance
432
- )
433
- {
434
- IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(distributionNftId);
435
- IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
436
- if (parentInfo.objectType != INSTANCE()) {
437
- revert ErrorIDistributionServiceParentNftIdNotInstance(distributionNftId, info.parentNftId);
438
- }
439
- instance = IInstance(parentInfo.objectAddress);
342
+ NftId instanceNftId = getRegistry().getObjectInfo(distributionNftId).parentNftId;
343
+ address instanceAddress = getRegistry().getObjectInfo(instanceNftId).objectAddress;
344
+ return IInstance(instanceAddress);
440
345
  }
441
-
442
- function _getAndVerifyCaller()
443
- internal
444
- view
445
- returns(
446
- address objectAddress,
447
- NftId objectNftId,
448
- ObjectType objectType,
449
- IInstance instance
450
- )
451
- {
452
- objectAddress = msg.sender;
453
- objectNftId = getRegistry().getNftId(objectAddress);
454
- if ( objectNftId.eqz()) {
455
- revert ErrorIServiceCallerUnknown(objectAddress);
456
- }
457
- IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(objectNftId);
458
- objectType = info.objectType;
459
-
460
- IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
461
- if (parentInfo.objectType != INSTANCE()) {
462
- revert ErrorIDistributionServiceParentNftIdNotInstance(objectNftId, info.parentNftId);
463
- }
464
- instance = IInstance(parentInfo.objectAddress);
465
- }
466
-
467
346
  }
@@ -19,7 +19,6 @@ import {Fee} from "../../types/Fee.sol";
19
19
  interface IApplicationService is IService {
20
20
 
21
21
  error IApplicationServicePolicyNotApplied(NftId applicationNftId);
22
- error IApplicationServiceBundlePoolMismatch(NftId bundleNftId, NftId bundlePoolNftId, NftId poolNftId);
23
22
 
24
23
  /// @dev creates a new application based on the specified attributes
25
24
  /// may only be called by a product component
@@ -62,21 +61,4 @@ interface IApplicationService is IService {
62
61
  /// an application can only be revoked in applied state
63
62
  /// only the application holder may revoke an application
64
63
  function revoke(NftId policyNftId) external;
65
-
66
- /// @dev calculates the premium amount for the specified attributes
67
- /// also returns the various fee components involved with creating a policy
68
- function calculatePremium(
69
- NftId productNftId,
70
- RiskId riskId,
71
- uint256 sumInsuredAmount,
72
- Seconds lifetime,
73
- bytes memory applicationData,
74
- NftId bundleNftId,
75
- ReferralId referralId
76
- )
77
- external
78
- view
79
- returns (
80
- IPolicy.Premium memory premium
81
- );
82
64
  }
@@ -1,6 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {Amount} from "../../types/Amount.sol";
4
5
  import {NftId} from "../../types/NftId.sol";
5
6
  import {Fee} from "../../types/Fee.sol";
6
7
  import {IService} from "../../shared/IService.sol";
@@ -8,55 +9,86 @@ import {IBundle} from "../module/IBundle.sol";
8
9
  import {IInstance} from "../../instance/IInstance.sol";
9
10
  import {Seconds} from "../../types/Seconds.sol";
10
11
  import {StateId} from "../../types/StateId.sol";
12
+ import {Timestamp} from "../../types/Timestamp.sol";
11
13
 
12
14
  interface IBundleService is IService {
13
15
 
14
16
  event LogBundleServiceBundleActivated(NftId bundleNftId);
15
17
  event LogBundleServiceBundleLocked(NftId bundleNftId);
16
- event LogBundleServiceBundleClosed(NftId bundleNftId);
17
18
 
19
+ error ErrorBundleServiceBundlePoolMismatch(NftId bundleNftId, NftId bundlePoolNftId, NftId poolNftId);
18
20
  error ErrorBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
19
- error ErrorBundleServiceBundleNotOpen(NftId bundleNftId, StateId state);
21
+ error ErrorBundleServiceBundleNotOpen(NftId bundleNftId, StateId state, Timestamp expiredAt);
22
+ error ErrorBundleServiceCapacityInsufficient(NftId bundleNftId, uint capacityAmount, uint collateralAmount);
20
23
  error ErrorBundleServiceBundleWithOpenPolicies(NftId bundleNftId, uint256 openPoliciesCount);
21
24
 
25
+ /// @dev create a new bundle for the specified attributes
26
+ /// may only be called by pool service
22
27
  function create(
23
- address owner,
24
- Fee memory fee,
25
- uint256 amount,
26
- Seconds lifetime,
27
- bytes calldata filter
28
- ) external returns(NftId bundleNftId);
28
+ IInstance instance, // instance relevant for bundle
29
+ NftId poolNftId, // the pool the bundle will be linked to
30
+ address owner, // initial bundle owner
31
+ Fee memory fee, // fees deducted from premium that go to bundle owner
32
+ Amount stakingAmount, // staking amount - staking fees result in initial bundle capital
33
+ Seconds lifetime, // initial duration for which new policies are covered
34
+ bytes calldata filter // optional use case specific criteria that define if a policy may be covered by this bundle
35
+ )
36
+ external
37
+ returns(NftId bundleNftId); // the nft id of the newly created bundle
38
+
39
+ /// @dev locks the specified bundle, locked bundles are not available to collateralize new policies
40
+ /// only active bundles may be locked
41
+ /// may only be called by registered and unlocked pool components
42
+ function lock(NftId bundleNftId) external;
43
+
44
+ /// @dev activates the specified bundle
45
+ /// only locked bundles may be unlocked
46
+ /// may only be called by registered and unlocked pool components
47
+ function unlock(NftId bundleNftId) external;
29
48
 
49
+ /// @dev closes the specified bundle
50
+ /// only open bundles (active or locked) may be closed
51
+ /// to close a bundle it may not have any non-closed polices attached to it
52
+ /// may only be called by registered and unlocked pool components
53
+ function close(
54
+ IInstance instance,
55
+ NftId bundleNftId
56
+ ) external;
30
57
 
58
+ /// @dev set bundle fee to provided value
59
+ /// may only be called by registered and unlocked pool components
31
60
  function setFee(
32
61
  NftId bundleNftId,
33
62
  Fee memory fee
34
63
  ) external;
35
64
 
36
65
 
66
+ /// @dev locks the specified collateral in the bundle
67
+ /// the locked collateral is added to the bundle locked capital
68
+ /// the bundles' fees are updated with the fees for this premium
69
+ /// the premium (minus bundle fee) is added to the bundle capital
70
+ /// may only be called by pool service
37
71
  function lockCollateral(
38
72
  IInstance instanceNftId,
39
73
  NftId policyNftId,
40
74
  NftId bundleNftId,
41
75
  uint256 collateralAmount,
42
- uint256 netPremium
43
- )
44
- external
45
- returns (
46
- IBundle.BundleInfo memory bundleInfo
47
- );
76
+ uint256 premium // premium amount after pool fee
77
+ ) external;
48
78
 
49
- function increaseBalance(IInstance instance, NftId bundleNftId, uint256 amount) external;
50
79
 
51
- function closePolicy(IInstance instance, NftId policyNftId, NftId bundleNftId, uint256 collateralAmount) external;
80
+ /// @dev releases the specified collateral in the bundle
81
+ /// may only be called by pool service
82
+ function releaseCollateral(
83
+ IInstance instance,
84
+ NftId policyNftId,
85
+ NftId bundleNftId,
86
+ uint256 collateralAmount
87
+ ) external;
88
+
89
+ function increaseBalance(IInstance instance, NftId bundleNftId, uint256 amount) external;
52
90
 
53
91
  // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
54
92
 
55
93
  // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
56
-
57
- function lock(NftId bundleNftId) external;
58
-
59
- function unlock(NftId bundleNftId) external;
60
-
61
- function close(NftId bundleNftId) external;
62
94
  }
@@ -12,6 +12,7 @@ import {Timestamp} from "../../types/Timestamp.sol";
12
12
 
13
13
 
14
14
  interface IDistributionService is IService {
15
+ error ErrorDistributionServiceCallerNotRegistered(address caller);
15
16
  error ErrorIDistributionServiceParentNftIdNotInstance(NftId nftId, NftId parentNftId);
16
17
  error ErrorIDistributionServiceCallerNotDistributor(address caller);
17
18
  error ErrorIDistributionServiceInvalidReferralId(ReferralId referralId);
@@ -24,14 +25,6 @@ interface IDistributionService is IService {
24
25
  error ErrorIDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
25
26
  error ErrorIDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
26
27
  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
28
  error ErrorIDistributionServiceReferralInvalid(NftId distributionNftId, ReferralId referralId);
36
29
  error ErrorIDistributionServiceInvalidFeeTransferred(uint256 transferredDistributionFeeAmount, uint256 expectedDistributionFeeAmount);
37
30
 
@@ -85,12 +78,6 @@ interface IDistributionService is IService {
85
78
  uint256 transferredDistributionFeeAmount
86
79
  ) external;
87
80
 
88
- function calculateFeeAmount(
89
- NftId distributionNftId,
90
- ReferralId referralId,
91
- IPolicy.Premium memory premium
92
- ) external view returns (IPolicy.Premium memory finalPremium);
93
-
94
81
  function referralIsValid(
95
82
  NftId distributorNftId,
96
83
  ReferralId referralId
@@ -25,6 +25,8 @@ interface IPolicyService is IService {
25
25
  error ErrorIPolicyServicePolicyHasNotExpired(NftId policyNftId, Timestamp expiredAt);
26
26
 
27
27
  error ErrorIPolicyServicePremiumMismatch(NftId policyNftId, uint256 premiumAmount, uint256 recalculatedPremiumAmount);
28
+ error ErrorIPolicyServicePolicyProductMismatch(NftId policyNftId, NftId policyProductNftId, NftId productNftId);
29
+ error ErrorIPolicyServicePolicyStateInvalid(NftId policyNftId, StateId expectedState, StateId foundState);
28
30
 
29
31
  /// @dev declines an application represented by {policyNftId}
30
32
  /// an application can only be declined in applied state
@@ -1,12 +1,15 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {Amount} from "../../types/Amount.sol";
4
5
  import {Fee} from "../../types/Fee.sol";
5
6
  import {NftId} from "../../types/NftId.sol";
6
- import {IService} from "../../shared/IService.sol";
7
7
  import {IBundle} from "../module/IBundle.sol";
8
8
  import {IInstance} from "../../instance/IInstance.sol";
9
+ import {IPolicy} from "../module/IPolicy.sol";
10
+ import {IService} from "../../shared/IService.sol";
9
11
  import {RoleId} from "../../types/RoleId.sol";
12
+ import {Seconds} from "../../types/Seconds.sol";
10
13
  import {StateId} from "../../types/StateId.sol";
11
14
 
12
15
  interface IPoolService is IService {
@@ -14,7 +17,11 @@ interface IPoolService is IService {
14
17
  event LogPoolServiceMaxCapitalAmountUpdated(NftId poolNftId, uint256 previousMaxCapitalAmount, uint256 currentMaxCapitalAmount);
15
18
  event LogPoolServiceBundleOwnerRoleSet(NftId poolNftId, RoleId bundleOwnerRole);
16
19
 
20
+ event LogPoolServiceBundleCreated(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
21
+ event LogPoolServiceBundleClosed(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
22
+
17
23
  error ErrorPoolServiceBundleOwnerRoleAlreadySet(NftId poolNftId);
24
+ error ErrorPoolServiceBundlePoolMismatch(NftId bundlePoolNftId, NftId productPoolNftId);
18
25
 
19
26
  /// @dev registers a new pool with the registry service
20
27
  function register(address poolAddress) external returns(NftId);
@@ -32,4 +39,61 @@ interface IPoolService is IService {
32
39
  Fee memory stakingFee,
33
40
  Fee memory performanceFee
34
41
  ) external;
42
+
43
+
44
+ /// @dev locks required collateral to cover the specified application (and turn it into a policy)
45
+ /// - retention level == 1: the full collateral amount will be locked by the specified bundle
46
+ /// - retention level < 1: a part of the coverage is provided by the specified bundle, the rest by the pool component
47
+ /// in which case the pool component might hold a re-insurance policy
48
+ /// may only be called by the policy service for unlocked pool components
49
+ function lockCollateral(
50
+ IInstance instance,
51
+ NftId productNftId,
52
+ NftId applicationNftId,
53
+ IPolicy.PolicyInfo memory applicationInfo,
54
+ uint256 premiumAmount
55
+ ) external;
56
+
57
+
58
+ /// @dev releases the remaining collateral linked to the specified policy
59
+ /// may only be called by the policy service for unlocked pool components
60
+ function releaseCollateral(
61
+ IInstance instance,
62
+ NftId policyNftId,
63
+ IPolicy.PolicyInfo memory policyInfo
64
+ ) external;
65
+
66
+
67
+ /// @dev create a new bundle for the provided parameters
68
+ /// staking fees will be deducted by the pool service from the staking amount
69
+ /// may only be called by registered and unlocked pool components
70
+ function createBundle(
71
+ address owner, // initial bundle owner
72
+ Fee memory fee, // fees deducted from premium that go to bundle owner
73
+ Amount stakingAmount, // staking amount - staking fees result in initial bundle capital
74
+ Seconds lifetime, // initial duration for which new policies are covered
75
+ bytes calldata filter // optional use case specific criteria that define if a policy may be covered by this bundle
76
+ )
77
+ external
78
+ returns(NftId bundleNftId); // the nft id of the newly created bundle
79
+
80
+
81
+ /// @dev closes the specified bundle
82
+ /// only open bundles (active or locked) may be closed
83
+ /// to close a bundle it may not have any non-closed polices attached to it
84
+ /// bundle fees and remaining capital (after deduction of the performance fee) will be transferred to the bundle owner
85
+ /// may only be called by registered and unlocked pool components
86
+ function closeBundle(NftId bundleNftId) external;
87
+
88
+
89
+ /// @dev increase stakes for bundle
90
+ /// staking fees will be deducted by the pool service from the staking amount
91
+ /// may only be called by registered and unlocked pool components
92
+ // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
93
+
94
+
95
+ /// @dev decrease stakes for bundle
96
+ /// performance fees will be deducted by the pool service from the staking amount
97
+ /// may only be called by registered and unlocked pool components
98
+ // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
35
99
  }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {Seconds} from "../../types/Seconds.sol";
5
+ import {NftId} from "../../types/NftId.sol";
6
+ import {ReferralId} from "../../types/Referral.sol";
7
+ import {RiskId} from "../../types/RiskId.sol";
8
+
9
+ import {IService} from "./IApplicationService.sol";
10
+ import {IPolicy} from "../module/IPolicy.sol";
11
+
12
+ interface IPricingService is IService
13
+ {
14
+ error ErrorIPricingServiceBundlePoolMismatch(NftId bundleNftId, NftId bundlePoolNftId, NftId poolNftId);
15
+ error ErrorIPricingServiceFeeCalculationMismatch(
16
+ uint256 distributionFeeFixAmount,
17
+ uint256 distributionFeeVarAmount,
18
+ uint256 distributionOwnerFeeFixAmount,
19
+ uint256 distributionOwnerFeeVarAmount,
20
+ uint256 commissionAmount,
21
+ uint256 discountAmount
22
+ );
23
+
24
+ function calculatePremium(
25
+ NftId productNftId,
26
+ NftId bundleNftId,
27
+ RiskId riskId,
28
+ ReferralId referralId,
29
+ uint256 sumInsuredAmount,
30
+ Seconds lifetime,
31
+ bytes memory applicationData
32
+ )
33
+ external
34
+ view
35
+ returns (IPolicy.Premium memory premium);
36
+ }