@etherisc/gif-next 0.0.2-f8e07c7-917 → 0.0.2-f981ede-436

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.dbg.json +1 -1
  2. package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.dbg.json +1 -1
  3. package/artifacts/contracts/authorization/Authorization.sol/Authorization.dbg.json +1 -1
  4. package/artifacts/contracts/authorization/IAccess.sol/IAccess.dbg.json +1 -1
  5. package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.dbg.json +1 -1
  6. package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.dbg.json +1 -1
  7. package/artifacts/contracts/authorization/IModuleAuthorization.sol/IModuleAuthorization.dbg.json +1 -1
  8. package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.dbg.json +1 -1
  9. package/artifacts/contracts/authorization/ModuleAuthorization.sol/ModuleAuthorization.dbg.json +1 -1
  10. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.dbg.json +1 -1
  11. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.dbg.json +1 -1
  12. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.json +50 -26
  13. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.dbg.json +1 -1
  14. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.json +16 -16
  15. package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
  16. package/artifacts/contracts/distribution/Distribution.sol/Distribution.json +24 -0
  17. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
  18. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +237 -74
  19. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  20. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +66 -38
  21. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  22. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.json +24 -0
  23. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  24. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.json +102 -0
  25. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.dbg.json +1 -1
  26. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.json +2 -2
  27. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  28. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  29. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  30. package/artifacts/contracts/instance/Instance.sol/Instance.json +2 -2
  31. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.dbg.json +1 -1
  32. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.json +2 -2
  33. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.dbg.json +1 -1
  34. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.json +2 -2
  35. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  36. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +54 -59
  37. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  38. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +2 -2
  39. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  40. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +2 -2
  41. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
  42. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +66 -76
  43. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.dbg.json +1 -1
  44. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.json +2 -2
  45. package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.json +2 -2
  48. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.dbg.json +1 -1
  49. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.dbg.json +1 -1
  50. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.json +2 -2
  51. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  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/mock/Dip.sol/Dip.dbg.json +1 -1
  58. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.dbg.json +1 -1
  59. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.json +2 -2
  60. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.dbg.json +1 -1
  61. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.json +2 -2
  62. package/artifacts/contracts/oracle/IOracle.sol/IOracle.dbg.json +1 -1
  63. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.dbg.json +1 -1
  64. package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.dbg.json +1 -1
  65. package/artifacts/contracts/oracle/Oracle.sol/Oracle.dbg.json +1 -1
  66. package/artifacts/contracts/oracle/OracleService.sol/OracleService.dbg.json +1 -1
  67. package/artifacts/contracts/oracle/OracleService.sol/OracleService.json +2 -2
  68. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.dbg.json +1 -1
  69. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.json +2 -2
  70. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.dbg.json +1 -1
  71. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.json +24 -0
  72. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.dbg.json +1 -1
  73. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.json +16 -16
  74. package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
  75. package/artifacts/contracts/pool/BundleService.sol/BundleService.json +312 -44
  76. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  77. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +63 -23
  78. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
  79. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.json +188 -0
  80. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  81. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.json +24 -0
  82. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
  83. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.json +101 -0
  84. package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
  85. package/artifacts/contracts/pool/Pool.sol/Pool.json +24 -0
  86. package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
  87. package/artifacts/contracts/pool/PoolService.sol/PoolService.json +177 -36
  88. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  89. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +39 -19
  90. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  91. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +2 -2
  92. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  93. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +2 -2
  94. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.dbg.json +1 -1
  95. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.dbg.json +1 -1
  96. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.json +2 -2
  97. package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
  98. package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +2 -2
  99. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  100. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +2 -2
  101. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  102. package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
  103. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  104. package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
  105. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  106. package/artifacts/contracts/product/IProductService.sol/IProductService.dbg.json +1 -1
  107. package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
  108. package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +2 -2
  109. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  110. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +2 -2
  111. package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
  112. package/artifacts/contracts/product/PricingService.sol/PricingService.json +7 -2
  113. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
  114. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +2 -2
  115. package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
  116. package/artifacts/contracts/product/ProductService.sol/ProductService.dbg.json +1 -1
  117. package/artifacts/contracts/product/ProductService.sol/ProductService.json +2 -2
  118. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  119. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.json +2 -2
  120. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  121. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  122. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  123. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  124. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  125. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  126. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.dbg.json +1 -1
  127. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.json +2 -2
  128. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  129. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  130. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  131. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  132. package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.dbg.json +1 -1
  133. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.dbg.json +1 -1
  134. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.json +2 -2
  135. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.dbg.json +1 -1
  136. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.json +2 -2
  137. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  138. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  139. package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
  140. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
  141. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +132 -76
  142. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
  143. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +39 -39
  144. package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.dbg.json +1 -1
  145. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  146. package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
  147. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.dbg.json +1 -1
  148. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.json +56 -0
  149. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.dbg.json +1 -1
  150. package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  151. package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  152. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  153. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  154. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  155. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  156. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  157. package/artifacts/contracts/shared/InitializableCustom.sol/InitializableCustom.dbg.json +1 -1
  158. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.dbg.json +1 -1
  159. package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  160. package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  161. package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.dbg.json +1 -1
  162. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  163. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  164. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  165. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  166. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  167. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  168. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  169. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  170. package/artifacts/contracts/staking/IStaking.sol/IStaking.dbg.json +1 -1
  171. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
  172. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.dbg.json +1 -1
  173. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.json +12 -2
  174. package/artifacts/contracts/staking/Staking.sol/Staking.dbg.json +1 -1
  175. package/artifacts/contracts/staking/Staking.sol/Staking.json +2 -2
  176. package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.dbg.json +1 -1
  177. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.dbg.json +1 -1
  178. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.json +2 -2
  179. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.dbg.json +1 -1
  180. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.json +2 -2
  181. package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
  182. package/artifacts/contracts/staking/StakingService.sol/StakingService.json +2 -2
  183. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +1 -1
  184. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +2 -2
  185. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.dbg.json +1 -1
  186. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.json +17 -12
  187. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.dbg.json +1 -1
  188. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.json +7 -2
  189. package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  190. package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
  191. package/artifacts/contracts/type/Amount.sol/AmountLib.json +37 -8
  192. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  193. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  194. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  195. package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
  196. package/artifacts/contracts/type/Fee.sol/FeeLib.json +7 -2
  197. package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
  198. package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
  199. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  200. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  201. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  202. package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
  203. package/artifacts/contracts/type/Referral.sol/ReferralLib.json +2 -2
  204. package/artifacts/contracts/type/RequestId.sol/RequestIdLib.dbg.json +1 -1
  205. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
  206. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
  207. package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
  208. package/artifacts/contracts/type/Selector.sol/SelectorLib.dbg.json +1 -1
  209. package/artifacts/contracts/type/Selector.sol/SelectorSetLib.dbg.json +1 -1
  210. package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
  211. package/artifacts/contracts/type/String.sol/StrLib.dbg.json +1 -1
  212. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
  213. package/artifacts/contracts/type/UFixed.sol/MathLib.dbg.json +1 -1
  214. package/artifacts/contracts/type/UFixed.sol/MathLib.json +9 -3
  215. package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
  216. package/artifacts/contracts/type/UFixed.sol/UFixedLib.json +39 -2
  217. package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
  218. package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
  219. package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.dbg.json +1 -1
  220. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  221. package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  222. package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.dbg.json +1 -1
  223. package/contracts/distribution/BasicDistributionAuthorization.sol +2 -1
  224. package/contracts/distribution/Distribution.sol +18 -1
  225. package/contracts/distribution/DistributionService.sol +59 -10
  226. package/contracts/distribution/IDistributionComponent.sol +6 -1
  227. package/contracts/distribution/IDistributionService.sol +12 -0
  228. package/contracts/instance/InstanceStore.sol +2 -1
  229. package/contracts/instance/module/IBundle.sol +1 -0
  230. package/contracts/instance/module/IDistribution.sol +0 -1
  231. package/contracts/pool/BasicPoolAuthorization.sol +3 -0
  232. package/contracts/pool/BundleService.sol +125 -4
  233. package/contracts/pool/IBundleService.sol +24 -3
  234. package/contracts/pool/IPoolComponent.sol +7 -0
  235. package/contracts/pool/IPoolService.sol +5 -3
  236. package/contracts/pool/Pool.sol +24 -3
  237. package/contracts/pool/PoolService.sol +103 -3
  238. package/contracts/product/ClaimService.sol +2 -1
  239. package/contracts/product/PolicyService.sol +1 -0
  240. package/contracts/shared/Component.sol +6 -0
  241. package/contracts/shared/ComponentService.sol +32 -3
  242. package/contracts/shared/IComponentService.sol +5 -9
  243. package/contracts/staking/Staking.sol +3 -1
  244. package/contracts/type/Amount.sol +12 -5
  245. package/contracts/type/Referral.sol +1 -0
  246. package/contracts/type/UFixed.sol +29 -10
  247. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+
4
6
  import {IRegistry} from "../registry/IRegistry.sol";
5
7
  import {IInstance} from "../instance/IInstance.sol";
6
8
  import {IComponentService} from "../shared/IComponentService.sol";
@@ -29,12 +31,6 @@ contract DistributionService is
29
31
  ComponentVerifyingService,
30
32
  IDistributionService
31
33
  {
32
- using NftIdLib for NftId;
33
- using TimestampLib for Timestamp;
34
- using UFixedLib for UFixed;
35
- using FeeLib for Fee;
36
- using ReferralLib for ReferralId;
37
-
38
34
  IComponentService private _componentService;
39
35
  IInstanceService private _instanceService;
40
36
  IRegistryService private _registryService;
@@ -138,7 +134,6 @@ contract DistributionService is
138
134
  distributorType,
139
135
  true, // active
140
136
  data,
141
- AmountLib.zero(),
142
137
  0);
143
138
 
144
139
  instance.getInstanceStore().createDistributor(distributorNftId, info);
@@ -243,19 +238,73 @@ contract DistributionService is
243
238
  referralInfo.usedReferrals += 1;
244
239
  store.updateReferral(referralId, referralInfo, KEEP_STATE());
245
240
 
241
+ _componentService.increaseDistributorBalance(store, referralInfo.distributorNftId, AmountLib.zero(), commissionAmount);
242
+
246
243
  // update book keeping for distributor info
247
244
  IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
248
- // TODO refactor sum of commission amount into a fee balance for distributors
249
- distributorInfo.commissionAmount = distributorInfo.commissionAmount + commissionAmount;
250
245
  distributorInfo.numPoliciesSold += 1;
251
246
  store.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
252
247
  } else {
253
-
254
248
  // increase distribution balance by distribution owner fee
255
249
  _componentService.increaseDistributionBalance(store, distributionNftId, AmountLib.zero(), distributionOwnerFee);
256
250
  }
257
251
  }
258
252
 
253
+ /// @inheritdoc IDistributionService
254
+ function withdrawCommission(NftId distributorNftId, Amount amount)
255
+ public
256
+ virtual
257
+ // TODO: restricted() (once #462 is done)
258
+ returns (Amount withdrawnAmount)
259
+ {
260
+ (NftId distributionNftId,, IInstance instance) = _getAndVerifyActiveComponent(DISTRIBUTION());
261
+ InstanceReader reader = instance.getInstanceReader();
262
+
263
+ IComponents.ComponentInfo memory distributionInfo = reader.getComponentInfo(distributionNftId);
264
+ address distributionWallet = distributionInfo.wallet;
265
+
266
+ Amount commissionAmount = reader.getFeeAmount(distributorNftId);
267
+
268
+ // determine withdrawn amount
269
+ withdrawnAmount = amount;
270
+ if (withdrawnAmount.gte(AmountLib.max())) {
271
+ withdrawnAmount = commissionAmount;
272
+ } else {
273
+ if (withdrawnAmount.gt(commissionAmount)) {
274
+ revert ErrorDistributionServiceCommissionWithdrawAmountExceedsLimit(withdrawnAmount, commissionAmount);
275
+ }
276
+ }
277
+
278
+ if (withdrawnAmount.eqz()) {
279
+ revert ErrorDistributionServiceCommissionWithdrawAmountIsZero();
280
+ }
281
+
282
+ // check allowance
283
+ IERC20Metadata token = IERC20Metadata(distributionInfo.token);
284
+ uint256 tokenAllowance = token.allowance(distributionWallet, address(distributionInfo.tokenHandler));
285
+ if (tokenAllowance < withdrawnAmount.toInt()) {
286
+ revert ErrorDistributionServiceWalletAllowanceTooSmall(distributionWallet, address(distributionInfo.tokenHandler), tokenAllowance, withdrawnAmount.toInt());
287
+ }
288
+
289
+ // decrease fee counters by withdrawnAmount and update distributor info
290
+ {
291
+ InstanceStore store = instance.getInstanceStore();
292
+ // decrease fee counter for distribution balance
293
+ _componentService.decreaseDistributionBalance(store, distributionNftId, withdrawnAmount, AmountLib.zero());
294
+ // decrease fee counter for distributor fee
295
+ _componentService.decreaseDistributorBalance(store, distributorNftId, AmountLib.zero(), withdrawnAmount);
296
+ }
297
+
298
+ // transfer amount to distributor
299
+ {
300
+ address distributor = getRegistry().ownerOf(distributorNftId);
301
+ // TODO: centralize token handling (issue #471)
302
+ distributionInfo.tokenHandler.transfer(distributionWallet, distributor, withdrawnAmount);
303
+
304
+ emit LogDistributionServiceCommissionWithdrawn(distributorNftId, distributor, address(token), withdrawnAmount);
305
+ }
306
+ }
307
+
259
308
  function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
260
309
  if (distributionNftId.eqz() || referralId.eqz()) {
261
310
  return false;
@@ -43,5 +43,10 @@ interface IDistributionComponent is IInstanceLinkedComponent {
43
43
 
44
44
  /// @dev Returns true to ensure component is called when transferring distributor Nft Ids.
45
45
  function isVerifying() external view returns (bool verifying);
46
-
46
+
47
+ /// @dev Withdraw commission for the distributor
48
+ /// @param distributorNftId the distributor Nft Id
49
+ /// @param amount the amount to withdraw. If set to AMOUNT_MAX, the full commission available is withdrawn
50
+ /// @return withdrawnAmount the effective withdrawn amount
51
+ function withdrawCommission(NftId distributorNftId, Amount amount) external returns (Amount withdrawnAmount);
47
52
  }
@@ -27,12 +27,18 @@ interface IDistributionService is IService {
27
27
  error ErrorIDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
28
28
  error ErrorIDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
29
29
 
30
+ error ErrorDistributionServiceCommissionWithdrawAmountExceedsLimit(Amount amount, Amount limit);
31
+ error ErrorDistributionServiceCommissionWithdrawAmountIsZero();
32
+ error ErrorDistributionServiceWalletAllowanceTooSmall(address wallet, address tokenHandler, uint256 allowance, uint256 amount);
33
+
30
34
  error ErrorDistributionServiceVariableFeesTooHight(uint256 maxDiscountPercentage, uint256 limit);
31
35
  error ErrorDistributionServiceMaxDiscountTooHigh(uint256 maxDiscountPercentage, uint256 limit);
32
36
 
33
37
  error ErrorIDistributionServiceReferralInvalid(NftId distributionNftId, ReferralId referralId);
34
38
  error ErrorDistributionServiceInvalidFeeTransferred(Amount transferredDistributionFeeAmount, Amount expectedDistributionFeeAmount);
35
39
 
40
+ event LogDistributionServiceCommissionWithdrawn(NftId distributorNftId, address recipient, address tokenAddress, Amount amount);
41
+
36
42
  function createDistributorType(
37
43
  string memory name,
38
44
  UFixed minDiscountPercentage,
@@ -82,4 +88,10 @@ interface IDistributionService is IService {
82
88
  NftId distributorNftId,
83
89
  ReferralId referralId
84
90
  ) external view returns (bool isValid);
91
+
92
+ /// @dev Withdraw commission for the distributor
93
+ /// @param distributorNftId the distributor Nft Id
94
+ /// @param amount the amount to withdraw. If set to AMOUNT_MAX, the full commission available is withdrawn
95
+ /// @return withdrawnAmount the effective withdrawn amount
96
+ function withdrawCommission(NftId distributorNftId, Amount amount) external returns (Amount withdrawnAmount);
85
97
  }
@@ -7,7 +7,7 @@ import {Amount} from "../type/Amount.sol";
7
7
  import {Key32} from "../type/Key32.sol";
8
8
  import {NftId} from "../type/NftId.sol";
9
9
  import {ClaimId} from "../type/ClaimId.sol";
10
- import {ObjectType, BUNDLE, POLICY, POOL, PRODUCT, COMPONENT, DISTRIBUTOR, DISTRIBUTOR_TYPE} from "../type/ObjectType.sol";
10
+ import {ObjectType, BUNDLE, POLICY, POOL, PRODUCT, COMPONENT, DISTRIBUTOR} from "../type/ObjectType.sol";
11
11
  import {RequestId} from "../type/RequestId.sol";
12
12
  import {RiskId} from "../type/RiskId.sol";
13
13
  import {StateId} from "../type/StateId.sol";
@@ -116,6 +116,7 @@ contract InstanceStore is
116
116
 
117
117
  //--- Distributor -------------------------------------------------------//
118
118
  function createDistributor(NftId distributorNftId, IDistribution.DistributorInfo memory info) external restricted() {
119
+ _registerBalanceTarget(distributorNftId);
119
120
  _create(_toNftKey32(distributorNftId, DISTRIBUTOR()), abi.encode(info));
120
121
  }
121
122
 
@@ -13,6 +13,7 @@ interface IBundle {
13
13
  NftId poolNftId;
14
14
  Fee fee; // bundle fee on net premium amounts
15
15
  bytes filter; // required conditions for applications to be considered for collateralization by this bundle
16
+ // TODO: is lifetime **AND** expiredAt necessary?
16
17
  Seconds lifetime; // lifetime of bundle after creation
17
18
  Timestamp expiredAt; // no new policies starting with this timestamp
18
19
  Timestamp closedAt; // no open policies, locked amount = 0
@@ -25,7 +25,6 @@ interface IDistribution {
25
25
  DistributorType distributorType;
26
26
  bool active;
27
27
  bytes data;
28
- Amount commissionAmount;
29
28
  uint32 numPoliciesSold;
30
29
  }
31
30
 
@@ -5,6 +5,7 @@ import {Authorization} from "../authorization/Authorization.sol";
5
5
  import {BasicPool} from "./BasicPool.sol";
6
6
  import {IAccess} from "../authorization/IAccess.sol";
7
7
  import {IInstanceLinkedComponent} from "../shared/IInstanceLinkedComponent.sol";
8
+ import {IPoolComponent} from "./IPoolComponent.sol";
8
9
  import {POOL} from "../type/ObjectType.sol";
9
10
  import {PUBLIC_ROLE} from "../../contracts/type/RoleId.sol";
10
11
  import {RoleId} from "../type/RoleId.sol";
@@ -47,6 +48,8 @@ contract BasicPoolAuthorization
47
48
  _authorize(functions, BasicPool.setFees.selector, "setFees");
48
49
 
49
50
  _authorize(functions, IInstanceLinkedComponent.withdrawFees.selector, "withdrawFees");
51
+
52
+ _authorize(functions, IPoolComponent.withdrawBundleFees.selector, "withdrawBundleFees");
50
53
  }
51
54
  }
52
55
 
@@ -1,8 +1,11 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+
4
6
  import {IBundle} from "../instance/module/IBundle.sol";
5
7
  import {IBundleService} from "./IBundleService.sol";
8
+ import {IComponents} from "../instance/module/IComponents.sol";
6
9
  import {IComponentService} from "../shared/IComponentService.sol";
7
10
  import {IRegistry} from "../registry/IRegistry.sol";
8
11
  import {IRegistryService} from "../registry/IRegistryService.sol";
@@ -13,13 +16,13 @@ import {IPolicy} from "../instance/module/IPolicy.sol";
13
16
  import {Amount, AmountLib} from "../type/Amount.sol";
14
17
  import {BundleSet} from "../instance/BundleSet.sol";
15
18
  import {ComponentVerifyingService} from "../shared/ComponentVerifyingService.sol";
16
- import {Fee} from "../type/Fee.sol";
19
+ import {Fee, FeeLib} from "../type/Fee.sol";
17
20
  import {InstanceReader} from "../instance/InstanceReader.sol";
18
21
  import {NftId, NftIdLib} from "../type/NftId.sol";
19
22
  import {ObjectType, COMPONENT, POOL, BUNDLE, REGISTRY} from "../type/ObjectType.sol";
20
23
  import {StateId, ACTIVE, PAUSED, CLOSED, KEEP_STATE} from "../type/StateId.sol";
21
24
  import {Seconds} from "../type/Seconds.sol";
22
- import {TimestampLib, zeroTimestamp} from "../type/Timestamp.sol";
25
+ import {Timestamp, TimestampLib, zeroTimestamp} from "../type/Timestamp.sol";
23
26
 
24
27
  string constant BUNDLE_SERVICE_NAME = "BundleService";
25
28
 
@@ -27,8 +30,7 @@ contract BundleService is
27
30
  ComponentVerifyingService,
28
31
  IBundleService
29
32
  {
30
- using NftIdLib for NftId;
31
-
33
+
32
34
  string public constant NAME = "BundleService";
33
35
 
34
36
  address private _registryAddress;
@@ -231,6 +233,70 @@ contract BundleService is
231
233
  bundleManager.lock(bundleNftId);
232
234
  }
233
235
 
236
+ /// @inheritdoc IBundleService
237
+ function stake(
238
+ IInstance instance,
239
+ NftId bundleNftId,
240
+ Amount amount
241
+ )
242
+ external
243
+ virtual
244
+ restricted()
245
+ {
246
+ // TODO: check not locked
247
+ // TODO: check not expired
248
+ // TODO: check not closed
249
+
250
+ _componentService.increaseBundleBalance(
251
+ instance.getInstanceStore(),
252
+ bundleNftId,
253
+ amount,
254
+ AmountLib.zero());
255
+ }
256
+
257
+ /// @inheritdoc IBundleService
258
+ function unstake(
259
+ IInstance instance,
260
+ NftId bundleNftId,
261
+ Amount amount
262
+ )
263
+ external
264
+ virtual
265
+ restricted()
266
+ {
267
+ InstanceStore instanceStore = instance.getInstanceStore();
268
+ (
269
+ Amount balanceAmount,
270
+ Amount lockedAmount,
271
+ Amount feeAmount
272
+ ) = instanceStore.getAmounts(bundleNftId);
273
+
274
+ // TODO: should the available amount include the fees or not?
275
+ Amount availableAmount = balanceAmount - (lockedAmount + feeAmount);
276
+
277
+ if (availableAmount < amount) {
278
+ revert ErrorBundleServiceStakeAmountExceedsLimit(amount, availableAmount);
279
+ }
280
+
281
+ _componentService.decreaseBundleBalance(
282
+ instanceStore,
283
+ bundleNftId,
284
+ amount,
285
+ // TODO: if above includes fees, how to split this?
286
+ AmountLib.zero());
287
+ }
288
+
289
+ function extend(NftId bundleNftId, Seconds lifetimeExtension)
290
+ external
291
+ virtual
292
+ restricted
293
+ returns (Timestamp extendedExpiredAt)
294
+ {
295
+ // TODO: implement lifetime extension
296
+ // TODO: bundle must be active or locked, not expired or closed
297
+ revert("Not implemented yet");
298
+ }
299
+
234
300
 
235
301
  function releaseCollateral(
236
302
  IInstance instance,
@@ -262,6 +328,61 @@ contract BundleService is
262
328
  instance.getBundleSet().unlinkPolicy(policyNftId);
263
329
  }
264
330
 
331
+ /// @inheritdoc IBundleService
332
+ function withdrawBundleFees(NftId bundleNftId, Amount amount)
333
+ public
334
+ virtual
335
+ // TODO: restricted() (once #462 is done)
336
+ returns (Amount withdrawnAmount)
337
+ {
338
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
339
+ InstanceReader reader = instance.getInstanceReader();
340
+
341
+ IComponents.ComponentInfo memory poolInfo = reader.getComponentInfo(poolNftId);
342
+ address poolWallet = poolInfo.wallet;
343
+
344
+ IBundle.BundleInfo memory bundleInfo = reader.getBundleInfo(bundleNftId);
345
+
346
+ // determine withdrawn amount
347
+ withdrawnAmount = amount;
348
+ if (withdrawnAmount.gte(AmountLib.max())) {
349
+ withdrawnAmount = reader.getFeeAmount(bundleNftId);
350
+ } else {
351
+ if (withdrawnAmount.gt(reader.getFeeAmount(bundleNftId))) {
352
+ revert ErrorBundleServiceFeesWithdrawAmountExceedsLimit(withdrawnAmount, reader.getFeeAmount(bundleNftId));
353
+ }
354
+ }
355
+
356
+ if (withdrawnAmount.eqz()) {
357
+ revert ErrorBundleServiceFeesWithdrawAmountIsZero();
358
+ }
359
+
360
+ // check allowance
361
+ IERC20Metadata token = IERC20Metadata(poolInfo.token);
362
+ uint256 tokenAllowance = token.allowance(poolWallet, address(poolInfo.tokenHandler));
363
+ if (tokenAllowance < withdrawnAmount.toInt()) {
364
+ revert ErrorBundleServiceWalletAllowanceTooSmall(poolWallet, address(poolInfo.tokenHandler), tokenAllowance, withdrawnAmount.toInt());
365
+ }
366
+
367
+ // decrease fee counters by withdrawnAmount
368
+ {
369
+ InstanceStore store = instance.getInstanceStore();
370
+ // decrease fee amount of the bundle
371
+ _componentService.decreaseBundleBalance(store, bundleNftId, AmountLib.zero(), withdrawnAmount);
372
+ // decrease pool balance
373
+ _componentService.decreasePoolBalance(store, poolNftId, withdrawnAmount, AmountLib.zero());
374
+ }
375
+
376
+ // transfer amount to bundle owner
377
+ {
378
+ address owner = getRegistry().ownerOf(bundleNftId);
379
+ // TODO: centralize token handling (issue #471)
380
+ poolInfo.tokenHandler.transfer(poolWallet, owner, withdrawnAmount);
381
+
382
+ emit LogBundleServiceFeesWithdrawn(bundleNftId, owner, address(token), withdrawnAmount);
383
+ }
384
+ }
385
+
265
386
  /// @dev links policy to bundle
266
387
  function _linkPolicy(IInstance instance, NftId policyNftId)
267
388
  internal
@@ -26,6 +26,15 @@ interface IBundleService is IService {
26
26
 
27
27
  error ErrorBundleServicePolicyNotCloseable(NftId policyNftId);
28
28
 
29
+ // error ErrorBundleServiceBundleNotActive(NftId distributorNftId);
30
+ error ErrorBundleServiceFeesWithdrawAmountExceedsLimit(Amount amount, Amount limit);
31
+ error ErrorBundleServiceFeesWithdrawAmountIsZero();
32
+ error ErrorBundleServiceWalletAllowanceTooSmall(address wallet, address tokenHandler, uint256 allowance, uint256 amount);
33
+
34
+ error ErrorBundleServiceStakeAmountExceedsLimit(Amount amount, Amount limit);
35
+
36
+ event LogBundleServiceFeesWithdrawn(NftId bundleNftId, address recipient, address tokenAddress, Amount amount);
37
+
29
38
  /// @dev create a new bundle for the specified attributes
30
39
  /// may only be called by pool service
31
40
  function create(
@@ -42,10 +51,15 @@ interface IBundleService is IService {
42
51
 
43
52
 
44
53
  /// @dev increase bundle stakes by the specified amount
45
- /// may only be called by the bundle owner
46
- // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
54
+ /// may only be called by the pool service
55
+ function stake(IInstance instance, NftId bundleNftId, Amount amount) external;
47
56
 
48
- // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
57
+ /// @dev decrease bundle stakes by the specified amount
58
+ /// may only be called by the pool service
59
+ function unstake(IInstance instance, NftId bundleNftId, Amount amount) external;
60
+
61
+ /// @dev extend the lifetime of the bundle by the specified time in seconds
62
+ function extend(NftId bundleNftId, Seconds lifetimeExtension) external returns (Timestamp extendedExpiredAt);
49
63
 
50
64
  /// @dev locks the specified bundle, locked bundles are not available to collateralize new policies
51
65
  /// only active bundles may be locked
@@ -103,4 +117,11 @@ interface IBundleService is IService {
103
117
  IInstance instance,
104
118
  NftId policyNftId
105
119
  ) external;
120
+
121
+ /// @dev Withdraw bundle feeds for the given bundle
122
+ /// @param bundleNftId the bundle Nft Id
123
+ /// @param amount the amount to withdraw. If set to AMOUNT_MAX, the full commission available is withdrawn
124
+ /// @return withdrawnAmount the effective withdrawn amount
125
+ function withdrawBundleFees(NftId bundleNftId, Amount amount) external returns (Amount withdrawnAmount);
126
+
106
127
  }
@@ -46,6 +46,13 @@ interface IPoolComponent is IInstanceLinkedComponent {
46
46
  view
47
47
  returns (bool isMatching);
48
48
 
49
+ /// @dev Withdraw bundle feeds for the given bundle
50
+ /// @param bundleNftId the bundle Nft Id
51
+ /// @param amount the amount to withdraw. If set to AMOUNT_MAX, the full commission available is withdrawn
52
+ /// @return withdrawnAmount the effective withdrawn amount
53
+ function withdrawBundleFees(NftId bundleNftId, Amount amount) external returns (Amount withdrawnAmount);
54
+
49
55
  /// @dev returns initial pool specific infos for this pool
50
56
  function getInitialPoolInfo() external view returns (IComponents.PoolInfo memory info);
57
+
51
58
  }
@@ -23,8 +23,11 @@ interface IPoolService is IService {
23
23
  event LogPoolServiceBundleCreated(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
24
24
  event LogPoolServiceBundleClosed(NftId instanceNftId, NftId poolNftId, NftId bundleNftId);
25
25
 
26
+ event LogPoolServiceBundleStaked(NftId instanceNftId, NftId poolNftId, NftId bundleNftId, Amount amount, Amount netAmount);
27
+
26
28
  error ErrorPoolServiceBundleOwnerRoleAlreadySet(NftId poolNftId);
27
29
  error ErrorPoolServiceInvalidTransferAmount(Amount expectedAmount, Amount actualAmount);
30
+ error ErrorPoolServiceBundlePoolMismatch(NftId bundleNftId, NftId poolNftId);
28
31
 
29
32
  /// @dev defines the required role for bundle owners for the calling pool
30
33
  /// default implementation returns PUBLIC ROLE
@@ -111,13 +114,12 @@ interface IPoolService is IService {
111
114
  /// @dev increase stakes for bundle
112
115
  /// staking fees will be deducted by the pool service from the staking amount
113
116
  /// may only be called by registered and unlocked pool components
114
- // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
115
-
117
+ function stake(NftId bundleNftId, Amount amount) external returns(Amount netAmount);
116
118
 
117
119
  /// @dev decrease stakes for bundle
118
120
  /// performance fees will be deducted by the pool service from the staking amount
119
121
  /// may only be called by registered and unlocked pool components
120
- // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
122
+ function unstake(NftId bundleNftId, Amount amount) external returns(Amount netAmount);
121
123
 
122
124
 
123
125
  /// @dev calulate required collateral for the provided parameters
@@ -14,6 +14,7 @@ import {Fee, FeeLib} from "../type/Fee.sol";
14
14
  import {NftId, NftIdLib} from "../type/NftId.sol";
15
15
  import {RoleId, PUBLIC_ROLE} from "../type/RoleId.sol";
16
16
  import {Seconds} from "../type/Seconds.sol";
17
+ import {Timestamp} from "../type/Timestamp.sol";
17
18
  import {TokenHandler} from "../shared/TokenHandler.sol";
18
19
  import {UFixed, UFixedLib} from "../type/UFixed.sol";
19
20
 
@@ -94,6 +95,17 @@ abstract contract Pool is
94
95
  _approveTokenHandler(type(uint256).max);
95
96
  }
96
97
 
98
+ /// @inheritdoc IPoolComponent
99
+ function withdrawBundleFees(NftId bundleNftId, Amount amount)
100
+ external
101
+ virtual
102
+ restricted()
103
+ onlyBundleOwner(bundleNftId)
104
+ returns (Amount withdrawnAmount)
105
+ {
106
+ return _withdrawBundleFees(bundleNftId, amount);
107
+ }
108
+
97
109
 
98
110
  function getInitialPoolInfo()
99
111
  public
@@ -161,8 +173,9 @@ abstract contract Pool is
161
173
  )
162
174
  internal
163
175
  virtual
176
+ returns(Amount netAmount)
164
177
  {
165
- // TODO add implementation
178
+ _getPoolStorage()._poolService.stake(bundleNftId, amount);
166
179
  }
167
180
 
168
181
 
@@ -174,8 +187,9 @@ abstract contract Pool is
174
187
  )
175
188
  internal
176
189
  virtual
190
+ returns(Amount netAmount)
177
191
  {
178
- // TODO add implementation
192
+ return _getPoolStorage()._poolService.unstake(bundleNftId, amount);
179
193
  }
180
194
 
181
195
 
@@ -187,8 +201,9 @@ abstract contract Pool is
187
201
  )
188
202
  internal
189
203
  virtual
204
+ returns (Timestamp extendedExpiredAt)
190
205
  {
191
- // TODO add implementation
206
+ return _getPoolStorage()._bundleService.extend(bundleNftId, lifetimeExtension);
192
207
  }
193
208
 
194
209
 
@@ -302,6 +317,12 @@ abstract contract Pool is
302
317
  return keccak256(abi.encode(uint256(keccak256(name)) - 1)) & ~bytes32(uint256(0xff));
303
318
  }
304
319
 
320
+ function _withdrawBundleFees(NftId bundleNftId, Amount amount)
321
+ internal
322
+ returns (Amount withdrawnAmount)
323
+ {
324
+ return _getPoolStorage()._bundleService.withdrawBundleFees(bundleNftId, amount);
325
+ }
305
326
 
306
327
  function _getPoolStorage() private pure returns (PoolStorage storage $) {
307
328
  assembly {
@@ -1,6 +1,7 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
+ import {IBundle} from "../instance/module/IBundle.sol";
4
5
  import {IBundleService} from "./IBundleService.sol";
5
6
  import {IComponents} from "../instance/module/IComponents.sol";
6
7
  import {IComponentService} from "../shared/IComponentService.sol";
@@ -32,9 +33,6 @@ contract PoolService is
32
33
  ComponentVerifyingService,
33
34
  IPoolService
34
35
  {
35
- using NftIdLib for NftId;
36
- using AmountLib for Amount;
37
-
38
36
  IBundleService internal _bundleService;
39
37
  IComponentService internal _componentService;
40
38
  IInstanceService private _instanceService;
@@ -151,6 +149,8 @@ contract PoolService is
151
149
  _getStakingFee(instanceReader, poolNftId),
152
150
  stakingAmount);
153
151
 
152
+ // TODO: staking amount must be be > maxCapitalAmount
153
+
154
154
  bundleNftId = _bundleService.create(
155
155
  instance,
156
156
  poolNftId,
@@ -203,6 +203,105 @@ contract PoolService is
203
203
  emit LogPoolServiceBundleClosed(instance.getNftId(), poolNftId, bundleNftId);
204
204
  }
205
205
 
206
+ /// @inheritdoc IPoolService
207
+ function stake(NftId bundleNftId, Amount amount)
208
+ external
209
+ virtual
210
+ restricted()
211
+ returns(Amount netAmount)
212
+ {
213
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
214
+ InstanceReader instanceReader = instance.getInstanceReader();
215
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
216
+
217
+ if (bundleInfo.poolNftId != poolNftId) {
218
+ revert ErrorPoolServiceBundlePoolMismatch(bundleNftId, poolNftId);
219
+ }
220
+
221
+ // TODO: ensure that poolBalance + amount <= maxCapitalAmount
222
+
223
+ // calculate fees
224
+ (
225
+ Amount feeAmount,
226
+ Amount netAmount
227
+ ) = FeeLib.calculateFee(
228
+ _getStakingFee(instanceReader, poolNftId),
229
+ amount);
230
+
231
+ // do all the bookkeeping
232
+ _componentService.increasePoolBalance(
233
+ instance.getInstanceStore(),
234
+ poolNftId,
235
+ amount,
236
+ feeAmount);
237
+
238
+ _bundleService.stake(instance, bundleNftId, netAmount);
239
+
240
+ // collect tokens from bundle owner
241
+ address bundleOwner = getRegistry().ownerOf(bundleNftId);
242
+ _collectStakingAmount(
243
+ instanceReader,
244
+ poolNftId,
245
+ bundleOwner,
246
+ amount);
247
+
248
+ emit LogPoolServiceBundleStaked(instance.getNftId(), poolNftId, bundleNftId, amount, netAmount);
249
+ }
250
+
251
+ /// @inheritdoc IPoolService
252
+ function unstake(NftId bundleNftId, Amount amount)
253
+ external
254
+ virtual
255
+ restricted()
256
+ returns(Amount netAmount)
257
+ {
258
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
259
+ InstanceReader instanceReader = instance.getInstanceReader();
260
+ InstanceStore instanceStore = instance.getInstanceStore();
261
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
262
+
263
+ if (bundleInfo.poolNftId != poolNftId) {
264
+ revert ErrorPoolServiceBundlePoolMismatch(bundleNftId, poolNftId);
265
+ }
266
+
267
+ // call bundle service for bookkeeping and additional checks
268
+ _bundleService.unstake(instance, bundleNftId, amount);
269
+
270
+ // FIXME: performance fee is only calculated on the earnings
271
+ (
272
+ Amount performanceFeeAmount,
273
+ Amount netAmount
274
+ ) = FeeLib.calculateFee(
275
+ _getPerformanceFee(instanceReader, poolNftId),
276
+ amount);
277
+
278
+ // update pool bookkeeping - performance fees stay in the pool, but as fees
279
+ _componentService.decreasePoolBalance(
280
+ instanceStore,
281
+ poolNftId,
282
+ amount,
283
+ AmountLib.zero());
284
+
285
+ _componentService.increasePoolBalance(
286
+ instanceStore,
287
+ poolNftId,
288
+ AmountLib.zero(),
289
+ performanceFeeAmount);
290
+
291
+ // TODO: transfer net amount to bundle owner (allowance)
292
+
293
+ // TODO: log event
294
+ }
295
+
296
+ function _getPerformanceFee(InstanceReader instanceReader, NftId poolNftId)
297
+ internal
298
+ virtual
299
+ view
300
+ returns (Fee memory performanceFee)
301
+ {
302
+ NftId productNftId = instanceReader.getPoolInfo(poolNftId).productNftId;
303
+ return instanceReader.getPoolInfo(productNftId).performanceFee;
304
+ }
206
305
 
207
306
  function processSale(
208
307
  NftId bundleNftId,
@@ -423,6 +522,7 @@ contract PoolService is
423
522
  address poolWallet = componentInfo.wallet;
424
523
 
425
524
  if(amount.gtz()) {
525
+ // TODO: centralize token handling (issue #471)
426
526
  tokenHandler.transfer(
427
527
  bundleOwner,
428
528
  poolWallet,