@etherisc/gif-next 0.0.2-da0f894-204 → 0.0.2-db1e1e4-828

Sign up to get free protection for your applications and to get access to all the features.
Files changed (258) 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 +68 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +64 -14
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IComponent.sol/IComponent.json +158 -0
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +150 -10
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +184 -149
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  13. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +158 -0
  14. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  15. package/artifacts/contracts/components/Pool.sol/Pool.json +114 -189
  16. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  17. package/artifacts/contracts/components/Product.sol/Product.json +68 -0
  18. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
  19. package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
  20. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  21. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +64 -50
  22. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  23. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.json +5 -0
  24. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  25. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +127 -182
  26. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  27. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +175 -51
  28. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  29. package/artifacts/contracts/instance/Instance.sol/Instance.json +215 -252
  30. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  31. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +472 -126
  32. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +102 -168
  34. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  35. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +304 -171
  36. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  37. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +71 -23
  38. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  39. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +8 -13
  40. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +85 -30
  42. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  44. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +40 -10
  46. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +36 -11
  48. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  49. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.json +56 -73
  50. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +4 -0
  52. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.json +10 -0
  53. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  58. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  59. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +145 -53
  60. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  61. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +21 -13
  62. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  63. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +384 -249
  64. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  65. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +74 -14
  66. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  67. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +104 -41
  68. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +11 -7
  70. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +356 -111
  72. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +57 -45
  74. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +101 -14
  76. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +212 -186
  78. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +80 -14
  80. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +250 -18
  82. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +106 -19
  84. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +511 -14
  86. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +80 -14
  88. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +152 -60
  90. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +27 -19
  92. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +561 -51
  94. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  95. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +24 -12
  96. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  97. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +114 -51
  98. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +16 -12
  100. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  101. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +15 -2
  102. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  103. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +19 -0
  104. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  105. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +0 -24
  106. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  107. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +18 -0
  108. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  109. package/artifacts/contracts/registry/Registry.sol/Registry.json +31 -12
  110. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  111. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  112. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  113. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +17 -36
  114. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  115. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  116. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  117. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +23 -11
  118. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  119. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  120. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  121. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  122. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  124. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  125. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  126. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IService.sol/IService.json +80 -14
  128. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  131. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  132. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  133. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  134. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  135. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  136. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  137. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  138. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  139. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  140. package/artifacts/contracts/shared/Service.sol/Service.json +86 -15
  141. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  142. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  143. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  144. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
  145. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  146. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  147. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  148. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  149. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  150. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  151. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +6 -6
  152. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  153. package/artifacts/contracts/test/TestService.sol/TestService.json +101 -26
  154. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  155. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  156. package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
  157. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  158. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
  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/Blocknumber.sol/BlocknumberLib.json +2 -2
  165. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  169. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  170. package/artifacts/contracts/types/Fee.sol/FeeLib.json +40 -9
  171. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  172. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  173. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  174. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +17 -4
  175. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  176. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  177. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  178. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  179. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  180. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  181. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  182. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +23 -4
  183. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  184. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  185. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  186. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  187. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +1 -1
  188. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  189. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  190. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  191. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
  192. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  193. package/artifacts/contracts/types/UFixed.sol/MathLib.json +2 -2
  194. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  195. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +2 -2
  196. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  197. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  198. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  199. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  200. package/contracts/components/Component.sol +42 -10
  201. package/contracts/components/Distribution.sol +0 -13
  202. package/contracts/components/IComponent.sol +9 -1
  203. package/contracts/components/IDistributionComponent.sol +0 -8
  204. package/contracts/components/IPoolComponent.sol +5 -43
  205. package/contracts/components/Pool.sol +47 -122
  206. package/contracts/components/Product.sol +4 -0
  207. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +13 -0
  208. package/contracts/instance/BundleManager.sol +6 -4
  209. package/contracts/instance/Cloneable.sol +7 -2
  210. package/contracts/instance/IInstance.sol +16 -10
  211. package/contracts/instance/IInstanceService.sol +18 -5
  212. package/contracts/instance/Instance.sol +46 -9
  213. package/contracts/instance/InstanceAccessManager.sol +388 -158
  214. package/contracts/instance/InstanceReader.sol +8 -10
  215. package/contracts/instance/InstanceService.sol +184 -179
  216. package/contracts/instance/ObjectManager.sol +6 -8
  217. package/contracts/instance/base/ComponentService.sol +17 -30
  218. package/contracts/instance/base/KeyValueStore.sol +13 -5
  219. package/contracts/instance/base/Lifecycle.sol +11 -2
  220. package/contracts/instance/module/IAccess.sol +21 -14
  221. package/contracts/instance/module/IBundle.sol +6 -4
  222. package/contracts/instance/module/IComponents.sol +41 -0
  223. package/contracts/instance/module/ISetup.sol +4 -17
  224. package/contracts/instance/service/ApplicationService.sol +22 -18
  225. package/contracts/instance/service/BundleService.sol +209 -77
  226. package/contracts/instance/service/ClaimService.sol +3 -3
  227. package/contracts/instance/service/DistributionService.sol +118 -77
  228. package/contracts/instance/service/IApplicationService.sol +1 -0
  229. package/contracts/instance/service/IBundleService.sol +63 -25
  230. package/contracts/instance/service/IDistributionService.sol +14 -1
  231. package/contracts/instance/service/IPolicyService.sol +2 -0
  232. package/contracts/instance/service/IPoolService.sol +82 -3
  233. package/contracts/instance/service/PolicyService.sol +96 -138
  234. package/contracts/instance/service/PoolService.sol +214 -20
  235. package/contracts/instance/service/ProductService.sol +30 -53
  236. package/contracts/registry/ChainNft.sol +8 -0
  237. package/contracts/registry/IRegistry.sol +2 -0
  238. package/contracts/registry/IRegistryService.sol +4 -3
  239. package/contracts/registry/ITransferInterceptor.sol +1 -0
  240. package/contracts/registry/Registry.sol +23 -20
  241. package/contracts/registry/RegistryService.sol +10 -11
  242. package/contracts/registry/ReleaseManager.sol +20 -18
  243. package/contracts/shared/IService.sol +4 -6
  244. package/contracts/shared/Service.sol +21 -7
  245. package/contracts/shared/TokenHandler.sol +11 -5
  246. package/contracts/test/TestService.sol +1 -1
  247. package/contracts/types/Amount.sol +60 -0
  248. package/contracts/types/Blocknumber.sol +1 -0
  249. package/contracts/types/Fee.sol +13 -5
  250. package/contracts/types/NftId.sol +8 -0
  251. package/contracts/types/ObjectType.sol +1 -0
  252. package/contracts/types/Referral.sol +4 -0
  253. package/contracts/types/RoleId.sol +6 -4
  254. package/contracts/types/StateId.sol +1 -0
  255. package/contracts/types/Timestamp.sol +1 -0
  256. package/contracts/types/UFixed.sol +1 -0
  257. package/contracts/types/Version.sol +1 -0
  258. package/package.json +1 -1
@@ -10,10 +10,11 @@ import {IPolicy} from "../module/IPolicy.sol";
10
10
 
11
11
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
12
12
  import {Fee, FeeLib} from "../../types/Fee.sol";
13
- import {DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
13
+ import {PRODUCT_SERVICE_ROLE, DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.sol";
14
14
  import {KEEP_STATE} from "../../types/StateId.sol";
15
15
  import {ObjectType, DISTRIBUTION, INSTANCE, DISTRIBUTION, DISTRIBUTOR} from "../../types/ObjectType.sol";
16
16
  import {Version, VersionLib} from "../../types/Version.sol";
17
+ import {RoleId} from "../../types/RoleId.sol";
17
18
 
18
19
  import {IVersionable} from "../../shared/IVersionable.sol";
19
20
  import {Versionable} from "../../shared/Versionable.sol";
@@ -42,6 +43,7 @@ contract DistributionService is
42
43
  using TimestampLib for Timestamp;
43
44
  using UFixedLib for UFixed;
44
45
  using FeeLib for Fee;
46
+ using ReferralLib for ReferralId;
45
47
 
46
48
  address internal _registryAddress;
47
49
 
@@ -58,11 +60,11 @@ contract DistributionService is
58
60
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
59
61
  // TODO while DistributionService is not deployed in DistributionServiceManager constructor
60
62
  // owner is DistributionServiceManager deployer
61
- initializeService(registryAddress, owner);
63
+ initializeService(registryAddress, address(0), owner);
62
64
  registerInterface(type(IDistributionService).interfaceId);
63
65
  }
64
66
 
65
- function getDomain() public pure override(Service, IService) returns(ObjectType) {
67
+ function getDomain() public pure override returns(ObjectType) {
66
68
  return DISTRIBUTION();
67
69
  }
68
70
 
@@ -86,8 +88,24 @@ contract DistributionService is
86
88
  distributionNftId = distributionInfo.nftId;
87
89
 
88
90
  instance.createDistributionSetup(distributionNftId, distribution.getSetupInfo());
89
- getInstanceService().createGifTarget(instanceNftId, distributionAddress, distribution.getName());
90
- 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);
91
109
  }
92
110
 
93
111
  function setFees(
@@ -101,9 +119,8 @@ contract DistributionService is
101
119
  revert ErrorIDistributionServiceMinFeeTooHigh(minDistributionOwnerFee.fractionalFee.toInt(), distributionFee.fractionalFee.toInt());
102
120
  }
103
121
 
104
- (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
122
+ (NftId distributionNftId, IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
105
123
  InstanceReader instanceReader = instance.getInstanceReader();
106
- NftId distributionNftId = info.nftId;
107
124
 
108
125
  ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
109
126
  distSetupInfo.minDistributionOwnerFee = minDistributionOwnerFee;
@@ -126,7 +143,7 @@ contract DistributionService is
126
143
  external
127
144
  returns (DistributorType distributorType)
128
145
  {
129
- (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
146
+ (NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
130
147
 
131
148
  {
132
149
  ISetup.DistributionSetupInfo memory setupInfo = instance.getInstanceReader().getDistributionSetupInfo(distributionNftId);
@@ -162,7 +179,7 @@ contract DistributionService is
162
179
  bytes memory data
163
180
  ) external returns (NftId distributorNftId)
164
181
  {
165
- (, NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
182
+ (NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
166
183
 
167
184
  distributorNftId = getRegistryService().registerDistributor(
168
185
  IRegistry.ObjectInfo(
@@ -191,7 +208,7 @@ contract DistributionService is
191
208
  bytes memory data
192
209
  ) external virtual
193
210
  {
194
- (,, IInstance instance) = _getAndVerifyCallingDistribution();
211
+ (, IInstance instance) = _getAndVerifyCallingDistribution();
195
212
  InstanceReader instanceReader = instance.getInstanceReader();
196
213
  IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
197
214
  distributorInfo.distributorType = distributorType;
@@ -212,7 +229,7 @@ contract DistributionService is
212
229
  virtual
213
230
  returns (ReferralId referralId)
214
231
  {
215
- (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
232
+ (NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
216
233
 
217
234
  if (bytes(code).length == 0) {
218
235
  revert ErrorIDistributionServiceInvalidReferral(code);
@@ -255,20 +272,50 @@ contract DistributionService is
255
272
  }
256
273
 
257
274
  function processSale(
275
+ NftId distributionNftId,
258
276
  ReferralId referralId,
259
- uint256 premiumAmount
277
+ IPolicy.Premium memory premium,
278
+ uint256 transferredDistributionFeeAmount
260
279
  )
261
280
  external
262
281
  virtual
263
282
  {
264
- // TODO: fetch referral
265
- // TODO: update referral usage numbers
266
- // TODO: update bookkeeping
267
- // TODO: calculate commission for distributor
268
- // TODO: calculate fee for distribution owner
269
- // TODO: updates sum of commission per distributor -> DistributorInfo
270
- // TODO: updates sum of fee per distribution owner
271
- revert("NOT_IMPLEMENTED_YET");
283
+ bool isReferral = ! referralId.eqz();
284
+ bool referralValid = referralIsValid(distributionNftId, referralId);
285
+
286
+ if (isReferral && ! referralValid) {
287
+ revert ErrorIDistributionServiceReferralInvalid(distributionNftId, referralId);
288
+ }
289
+
290
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
291
+ InstanceReader reader = instance.getInstanceReader();
292
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
293
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
294
+ ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
295
+
296
+ uint256 distributionOwnerFee = premium.distributionOwnerFeeFixAmount + premium.distributionOwnerFeeVarAmount;
297
+ uint256 commissionAmount = premium.commissionAmount;
298
+
299
+ if (transferredDistributionFeeAmount != distributionOwnerFee + commissionAmount) {
300
+ revert ErrorIDistributionServiceInvalidFeeTransferred(transferredDistributionFeeAmount, distributionOwnerFee + commissionAmount);
301
+ }
302
+
303
+
304
+ if (distributionOwnerFee > 0) {
305
+ setupInfo.sumDistributionOwnerFees += distributionOwnerFee;
306
+ instance.updateDistributionSetup(distributionNftId, setupInfo, KEEP_STATE());
307
+ }
308
+
309
+ if (isReferral) {
310
+ referralInfo.usedReferrals += 1;
311
+ instance.updateReferral(referralId.toKey32(), referralInfo, KEEP_STATE());
312
+
313
+ if (commissionAmount > 0) {
314
+ distributorInfo.sumCommisions += commissionAmount;
315
+ distributorInfo.numPoliciesSold += 1;
316
+ instance.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
317
+ }
318
+ }
272
319
  }
273
320
 
274
321
  function calculateFeeAmount(
@@ -281,7 +328,7 @@ contract DistributionService is
281
328
  view
282
329
  returns (IPolicy.Premium memory finalPremium)
283
330
  {
284
- (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
331
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
285
332
  InstanceReader reader = instance.getInstanceReader();
286
333
 
287
334
  // first calculate all fixed and variable fees for the distribution - this will defined the fullPremium
@@ -302,22 +349,47 @@ contract DistributionService is
302
349
 
303
350
  // if the referral is valid, the the commission and discount are calculated based in the full premium
304
351
  // the remaing amount goes to the distribution owner
305
- IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
306
- IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
307
- IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
308
-
309
- uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
310
- premium.commissionAmount = commissionAmount;
311
- premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
312
- premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
313
- premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
314
- premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
352
+ {
353
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
354
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
355
+ IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
356
+
357
+ uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
358
+ premium.commissionAmount = commissionAmount;
359
+ premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
360
+ premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
361
+ premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
362
+ premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
363
+ }
364
+
365
+ // sanity check to validate the fee calculation
366
+ if (premium.distributionOwnerFeeFixAmount < minDistributionOwnerFee.fixedFee) {
367
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
368
+ premium.distributionFeeFixAmount,
369
+ premium.distributionFeeVarAmount,
370
+ premium.distributionOwnerFeeFixAmount,
371
+ premium.distributionOwnerFeeVarAmount,
372
+ premium.commissionAmount,
373
+ premium.discountAmount
374
+ );
375
+ }
376
+ if ((premium.distributionFeeVarAmount) != (premium.discountAmount + premium.distributionOwnerFeeVarAmount + premium.commissionAmount)) {
377
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
378
+ premium.distributionFeeFixAmount,
379
+ premium.distributionFeeVarAmount,
380
+ premium.distributionOwnerFeeFixAmount,
381
+ premium.distributionOwnerFeeVarAmount,
382
+ premium.commissionAmount,
383
+ premium.discountAmount
384
+ );
385
+ }
315
386
 
316
387
  return premium;
317
388
  }
318
389
 
390
+ // TODO: zero should return false
319
391
  function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
320
- (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
392
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
321
393
  IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);
322
394
 
323
395
  if (info.distributorNftId.eqz()) {
@@ -332,63 +404,32 @@ contract DistributionService is
332
404
  internal
333
405
  view
334
406
  returns(
335
- address distributionAddress,
336
407
  NftId distributionNftId,
337
408
  IInstance instance
338
409
  )
339
410
  {
340
- ObjectType objectType;
341
- (
342
- distributionAddress,
343
- distributionNftId,
344
- objectType,
345
- instance
346
- ) = _getAndVerifyCaller();
347
-
348
- if(objectType != DISTRIBUTION()) {
349
- revert ErrorIDistributionServiceCallerNotDistributor(msg.sender);
411
+ distributionNftId = getRegistry().getNftId(msg.sender);
412
+ if (distributionNftId.eqz()) {
413
+ revert ErrorDistributionServiceCallerNotRegistered(msg.sender);
350
414
  }
351
- }
352
415
 
353
- function _getAndVerifyDistribution(NftId distributionNftId)
354
- internal
355
- view
356
- returns(
357
- address distributionAddress,
358
- IInstance instance
359
- )
360
- {
361
416
  IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(distributionNftId);
362
- IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
363
- if (parentInfo.objectType != INSTANCE()) {
364
- revert ErrorIDistributionServiceParentNftIdNotInstance(distributionNftId, info.parentNftId);
417
+ if(info.objectType != DISTRIBUTION()) {
418
+ revert ErrorIDistributionServiceCallerNotDistributor(msg.sender);
365
419
  }
366
- instance = IInstance(parentInfo.objectAddress);
420
+
421
+ address instanceAddress = getRegistry().getObjectInfo(info.parentNftId).objectAddress;
422
+ instance = IInstance(instanceAddress);
367
423
  }
368
424
 
369
- function _getAndVerifyCaller()
425
+
426
+ function _getInstanceForDistribution(NftId distributionNftId)
370
427
  internal
371
428
  view
372
- returns(
373
- address objectAddress,
374
- NftId objectNftId,
375
- ObjectType objectType,
376
- IInstance instance
377
- )
429
+ returns(IInstance instance)
378
430
  {
379
- objectAddress = msg.sender;
380
- objectNftId = getRegistry().getNftId(objectAddress);
381
- if ( objectNftId.eqz()) {
382
- revert ErrorIServiceCallerUnknown(objectAddress);
383
- }
384
- IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(objectNftId);
385
- objectType = info.objectType;
386
-
387
- IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
388
- if (parentInfo.objectType != INSTANCE()) {
389
- revert ErrorIDistributionServiceParentNftIdNotInstance(objectNftId, info.parentNftId);
390
- }
391
- instance = IInstance(parentInfo.objectAddress);
431
+ NftId instanceNftId = getRegistry().getObjectInfo(distributionNftId).parentNftId;
432
+ address instanceAddress = getRegistry().getObjectInfo(instanceNftId).objectAddress;
433
+ return IInstance(instanceAddress);
392
434
  }
393
-
394
435
  }
@@ -19,6 +19,7 @@ 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);
22
23
 
23
24
  /// @dev creates a new application based on the specified attributes
24
25
  /// may only be called by a product component
@@ -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,48 +9,85 @@ 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
- error ErrorIBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
14
15
 
15
- function createBundle(
16
- address owner,
17
- Fee memory fee,
18
- uint256 amount,
19
- Seconds lifetime,
20
- bytes calldata filter
21
- ) external returns(NftId bundleNftId);
16
+ event LogBundleServiceBundleActivated(NftId bundleNftId);
17
+ event LogBundleServiceBundleLocked(NftId bundleNftId);
22
18
 
23
- function setBundleFee(
19
+ error ErrorBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
20
+ error ErrorBundleServiceBundleNotOpen(NftId bundleNftId, StateId state, Timestamp expiredAt);
21
+ error ErrorBundleServiceCapacityInsufficient(NftId bundleNftId, uint capacityAmount, uint collateralAmount);
22
+ error ErrorBundleServiceBundleWithOpenPolicies(NftId bundleNftId, uint256 openPoliciesCount);
23
+
24
+ /// @dev create a new bundle for the specified attributes
25
+ /// may only be called by pool service
26
+ function create(
27
+ IInstance instance, // instance relevant for bundle
28
+ NftId poolNftId, // the pool the bundle will be linked to
29
+ address owner, // initial bundle owner
30
+ Fee memory fee, // fees deducted from premium that go to bundle owner
31
+ Amount stakingAmount, // staking amount - staking fees result in initial bundle capital
32
+ Seconds lifetime, // initial duration for which new policies are covered
33
+ bytes calldata filter // optional use case specific criteria that define if a policy may be covered by this bundle
34
+ )
35
+ external
36
+ returns(NftId bundleNftId); // the nft id of the newly created bundle
37
+
38
+ /// @dev locks the specified bundle, locked bundles are not available to collateralize new policies
39
+ /// only active bundles may be locked
40
+ /// may only be called by registered and unlocked pool components
41
+ function lock(NftId bundleNftId) external;
42
+
43
+ /// @dev activates the specified bundle
44
+ /// only locked bundles may be unlocked
45
+ /// may only be called by registered and unlocked pool components
46
+ function unlock(NftId bundleNftId) external;
47
+
48
+ /// @dev closes the specified bundle
49
+ /// only open bundles (active or locked) may be closed
50
+ /// to close a bundle it may not have any non-closed polices attached to it
51
+ /// may only be called by registered and unlocked pool components
52
+ function close(
53
+ IInstance instance,
54
+ NftId bundleNftId
55
+ ) external;
56
+
57
+ /// @dev set bundle fee to provided value
58
+ /// may only be called by registered and unlocked pool components
59
+ function setFee(
24
60
  NftId bundleNftId,
25
61
  Fee memory fee
26
62
  ) external;
27
63
 
28
- function updateBundle(NftId instanceNftId, NftId bundleNftId, IBundle.BundleInfo memory bundleInfo, StateId state) external;
29
64
 
65
+ /// @dev locks the specified collateral in the bundle
66
+ /// the locked collateral is added to the bundle locked capital
67
+ /// the bundles' fees are updated with the fees for this premium
68
+ /// the premium (minus bundle fee) is added to the bundle capital
69
+ /// may only be called by pool service
30
70
  function lockCollateral(
31
71
  IInstance instanceNftId,
32
72
  NftId policyNftId,
33
73
  NftId bundleNftId,
34
74
  uint256 collateralAmount,
35
- uint256 netPremium
36
- )
37
- external
38
- returns (
39
- IBundle.BundleInfo memory bundleInfo
40
- );
41
-
42
- function increaseBalance(IInstance instance, NftId bundleNftId, uint256 amount) external;
43
-
44
- function closePolicy(IInstance instance, NftId policyNftId, NftId bundleNftId, uint256 collateralAmount) external;
75
+ uint256 premium // premium amount after pool fee
76
+ ) external;
45
77
 
46
- // function fundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
47
78
 
48
- // function defundBundle(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
79
+ /// @dev releases the specified collateral in the bundle
80
+ /// may only be called by pool service
81
+ function releaseCollateral(
82
+ IInstance instance,
83
+ NftId policyNftId,
84
+ NftId bundleNftId,
85
+ uint256 collateralAmount
86
+ ) external;
49
87
 
50
- function lockBundle(NftId bundleNftId) external;
88
+ function increaseBalance(IInstance instance, NftId bundleNftId, uint256 amount) external;
51
89
 
52
- function unlockBundle(NftId bundleNftId) external;
90
+ // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
53
91
 
54
- // function closeBundle(NftId bundleNftId) external;
92
+ // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
55
93
  }
@@ -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,6 +25,16 @@ 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);
28
+ error ErrorIDistributionServiceFeeCalculationMismatch(
29
+ uint256 distributionFeeFixAmount,
30
+ uint256 distributionFeeVarAmount,
31
+ uint256 distributionOwnerFeeFixAmount,
32
+ uint256 distributionOwnerFeeVarAmount,
33
+ uint256 commissionAmount,
34
+ uint256 discountAmount
35
+ );
36
+ error ErrorIDistributionServiceReferralInvalid(NftId distributionNftId, ReferralId referralId);
37
+ error ErrorIDistributionServiceInvalidFeeTransferred(uint256 transferredDistributionFeeAmount, uint256 expectedDistributionFeeAmount);
27
38
 
28
39
  function setFees(
29
40
  Fee memory minDistributionOwnerFee,
@@ -69,8 +80,10 @@ interface IDistributionService is IService {
69
80
 
70
81
  /// @dev callback from product service when selling a policy for a specific referralId
71
82
  function processSale(
83
+ NftId distributionNftId,
72
84
  ReferralId referralId,
73
- uint256 premiumAmount
85
+ IPolicy.Premium memory premium,
86
+ uint256 transferredDistributionFeeAmount
74
87
  ) external;
75
88
 
76
89
  function calculateFeeAmount(
@@ -24,6 +24,8 @@ interface IPolicyService is IService {
24
24
  error ErrorIPolicyServiceOpenClaims(NftId policyNftId, uint16 openClaimsCount);
25
25
  error ErrorIPolicyServicePolicyHasNotExpired(NftId policyNftId, Timestamp expiredAt);
26
26
 
27
+ error ErrorIPolicyServicePremiumMismatch(NftId policyNftId, uint256 premiumAmount, uint256 recalculatedPremiumAmount);
28
+
27
29
  /// @dev declines an application represented by {policyNftId}
28
30
  /// an application can only be declined in applied state
29
31
  /// only the related product may decline an application
@@ -1,20 +1,99 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- import {NftId} from "../../types/NftId.sol";
4
+ import {Amount} from "../../types/Amount.sol";
5
5
  import {Fee} from "../../types/Fee.sol";
6
- import {StateId} from "../../types/StateId.sol";
7
- import {IService} from "../../shared/IService.sol";
6
+ import {NftId} from "../../types/NftId.sol";
8
7
  import {IBundle} from "../module/IBundle.sol";
9
8
  import {IInstance} from "../../instance/IInstance.sol";
9
+ import {IPolicy} from "../module/IPolicy.sol";
10
+ import {IService} from "../../shared/IService.sol";
11
+ import {RoleId} from "../../types/RoleId.sol";
12
+ import {Seconds} from "../../types/Seconds.sol";
13
+ import {StateId} from "../../types/StateId.sol";
10
14
 
11
15
  interface IPoolService is IService {
12
16
 
17
+ event LogPoolServiceMaxCapitalAmountUpdated(NftId poolNftId, uint256 previousMaxCapitalAmount, uint256 currentMaxCapitalAmount);
18
+ event LogPoolServiceBundleOwnerRoleSet(NftId poolNftId, RoleId bundleOwnerRole);
19
+
20
+ event LogPoolServiceBundleCreated(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
21
+ event LogPoolServiceBundleClosed(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
22
+
23
+ error ErrorPoolServiceBundleOwnerRoleAlreadySet(NftId poolNftId);
24
+ error ErrorPoolServiceBundlePoolMismatch(NftId bundlePoolNftId, NftId productPoolNftId);
25
+
26
+ /// @dev registers a new pool with the registry service
13
27
  function register(address poolAddress) external returns(NftId);
14
28
 
29
+ /// @dev defines the required role for bundle owners for the calling pool
30
+ /// default implementation returns PUBLIC ROLE
31
+ function setBundleOwnerRole(RoleId bundleOwnerRole) external;
32
+
33
+ /// @dev sets the max capital amount for the calling pool
34
+ function setMaxCapitalAmount(uint256 maxCapitalAmount) external;
35
+
36
+ /// @dev set pool sepecific fees
15
37
  function setFees(
16
38
  Fee memory poolFee,
17
39
  Fee memory stakingFee,
18
40
  Fee memory performanceFee
19
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);
20
99
  }