@etherisc/gif-next 0.0.2-a66c9a8-623 → 0.0.2-a6ea1b1-244

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 (271) hide show
  1. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.dbg.json +1 -1
  2. package/artifacts/contracts/authorization/AccessAdmin.sol/AccessAdmin.json +2 -2
  3. package/artifacts/contracts/authorization/AccessManagerCloneable.sol/AccessManagerCloneable.dbg.json +1 -1
  4. package/artifacts/contracts/authorization/Authorization.sol/Authorization.dbg.json +1 -1
  5. package/artifacts/contracts/authorization/Authorization.sol/Authorization.json +2 -2
  6. package/artifacts/contracts/authorization/IAccess.sol/IAccess.dbg.json +1 -1
  7. package/artifacts/contracts/authorization/IAccessAdmin.sol/IAccessAdmin.dbg.json +1 -1
  8. package/artifacts/contracts/authorization/IAuthorization.sol/IAuthorization.dbg.json +1 -1
  9. package/artifacts/contracts/authorization/IModuleAuthorization.sol/IModuleAuthorization.dbg.json +1 -1
  10. package/artifacts/contracts/authorization/IServiceAuthorization.sol/IServiceAuthorization.dbg.json +1 -1
  11. package/artifacts/contracts/authorization/ModuleAuthorization.sol/ModuleAuthorization.dbg.json +1 -1
  12. package/artifacts/contracts/authorization/ModuleAuthorization.sol/ModuleAuthorization.json +2 -2
  13. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.dbg.json +1 -1
  14. package/artifacts/contracts/authorization/ServiceAuthorization.sol/ServiceAuthorization.json +2 -2
  15. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.dbg.json +1 -1
  16. package/artifacts/contracts/distribution/BasicDistribution.sol/BasicDistribution.json +50 -26
  17. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.dbg.json +1 -1
  18. package/artifacts/contracts/distribution/BasicDistributionAuthorization.sol/BasicDistributionAuthorization.json +16 -16
  19. package/artifacts/contracts/distribution/Distribution.sol/Distribution.dbg.json +1 -1
  20. package/artifacts/contracts/distribution/Distribution.sol/Distribution.json +24 -0
  21. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.dbg.json +1 -1
  22. package/artifacts/contracts/distribution/DistributionService.sol/DistributionService.json +237 -74
  23. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  24. package/artifacts/contracts/distribution/DistributionServiceManager.sol/DistributionServiceManager.json +66 -38
  25. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  26. package/artifacts/contracts/distribution/IDistributionComponent.sol/IDistributionComponent.json +24 -0
  27. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  28. package/artifacts/contracts/distribution/IDistributionService.sol/IDistributionService.json +102 -0
  29. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.dbg.json +1 -1
  30. package/artifacts/contracts/instance/BundleSet.sol/BundleSet.json +2 -2
  31. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  32. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  33. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  34. package/artifacts/contracts/instance/Instance.sol/Instance.json +2 -2
  35. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.dbg.json +1 -1
  36. package/artifacts/contracts/instance/InstanceAdmin.sol/InstanceAdmin.json +2 -2
  37. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.dbg.json +1 -1
  38. package/artifacts/contracts/instance/InstanceAuthorizationV3.sol/InstanceAuthorizationV3.json +2 -2
  39. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  40. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +56 -66
  41. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  42. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +2 -2
  43. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  44. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +2 -2
  45. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.dbg.json +1 -1
  46. package/artifacts/contracts/instance/InstanceStore.sol/InstanceStore.json +74 -94
  47. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.dbg.json +1 -1
  48. package/artifacts/contracts/instance/base/BalanceStore.sol/BalanceStore.json +2 -2
  49. package/artifacts/contracts/instance/base/Cloneable.sol/Cloneable.dbg.json +1 -1
  50. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.dbg.json +1 -1
  51. package/artifacts/contracts/instance/base/ObjectCounter.sol/ObjectCounter.json +2 -2
  52. package/artifacts/contracts/instance/base/ObjectLifecycle.sol/ObjectLifecycle.dbg.json +1 -1
  53. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.dbg.json +1 -1
  54. package/artifacts/contracts/instance/base/ObjectSet.sol/ObjectSet.json +2 -2
  55. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/IComponents.sol/IComponents.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  59. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  60. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  61. package/artifacts/contracts/mock/Dip.sol/Dip.dbg.json +1 -1
  62. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.dbg.json +1 -1
  63. package/artifacts/contracts/oracle/BasicOracle.sol/BasicOracle.json +27 -16
  64. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.dbg.json +1 -1
  65. package/artifacts/contracts/oracle/BasicOracleAuthorization.sol/BasicOracleAuthorization.json +2 -2
  66. package/artifacts/contracts/oracle/IOracle.sol/IOracle.dbg.json +1 -1
  67. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.dbg.json +1 -1
  68. package/artifacts/contracts/oracle/IOracleComponent.sol/IOracleComponent.json +11 -0
  69. package/artifacts/contracts/oracle/IOracleService.sol/IOracleService.dbg.json +1 -1
  70. package/artifacts/contracts/oracle/Oracle.sol/Oracle.dbg.json +1 -1
  71. package/artifacts/contracts/oracle/Oracle.sol/Oracle.json +11 -0
  72. package/artifacts/contracts/oracle/OracleService.sol/OracleService.dbg.json +1 -1
  73. package/artifacts/contracts/oracle/OracleService.sol/OracleService.json +2 -2
  74. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.dbg.json +1 -1
  75. package/artifacts/contracts/oracle/OracleServiceManager.sol/OracleServiceManager.json +2 -2
  76. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.dbg.json +1 -1
  77. package/artifacts/contracts/pool/BasicPool.sol/BasicPool.json +31 -6
  78. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.dbg.json +1 -1
  79. package/artifacts/contracts/pool/BasicPoolAuthorization.sol/BasicPoolAuthorization.json +16 -16
  80. package/artifacts/contracts/pool/BundleService.sol/BundleService.dbg.json +1 -1
  81. package/artifacts/contracts/pool/BundleService.sol/BundleService.json +444 -44
  82. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  83. package/artifacts/contracts/pool/BundleServiceManager.sol/BundleServiceManager.json +111 -23
  84. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.dbg.json +1 -1
  85. package/artifacts/contracts/pool/IBundleService.sol/IBundleService.json +224 -0
  86. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  87. package/artifacts/contracts/pool/IPoolComponent.sol/IPoolComponent.json +24 -5
  88. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.dbg.json +1 -1
  89. package/artifacts/contracts/pool/IPoolService.sol/IPoolService.json +189 -0
  90. package/artifacts/contracts/pool/Pool.sol/Pool.dbg.json +1 -1
  91. package/artifacts/contracts/pool/Pool.sol/Pool.json +24 -5
  92. package/artifacts/contracts/pool/PoolService.sol/PoolService.dbg.json +1 -1
  93. package/artifacts/contracts/pool/PoolService.sol/PoolService.json +289 -36
  94. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  95. package/artifacts/contracts/pool/PoolServiceManager.sol/PoolServiceManager.json +51 -19
  96. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  97. package/artifacts/contracts/product/ApplicationService.sol/ApplicationService.json +2 -2
  98. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/product/ApplicationServiceManager.sol/ApplicationServiceManager.json +2 -2
  100. package/artifacts/contracts/product/BasicProduct.sol/BasicProduct.dbg.json +1 -1
  101. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.dbg.json +1 -1
  102. package/artifacts/contracts/product/BasicProductAuthorization.sol/BasicProductAuthorization.json +2 -2
  103. package/artifacts/contracts/product/ClaimService.sol/ClaimService.dbg.json +1 -1
  104. package/artifacts/contracts/product/ClaimService.sol/ClaimService.json +2 -2
  105. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  106. package/artifacts/contracts/product/ClaimServiceManager.sol/ClaimServiceManager.json +2 -2
  107. package/artifacts/contracts/product/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  108. package/artifacts/contracts/product/IClaimService.sol/IClaimService.dbg.json +1 -1
  109. package/artifacts/contracts/product/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  110. package/artifacts/contracts/product/IPricingService.sol/IPricingService.dbg.json +1 -1
  111. package/artifacts/contracts/product/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  112. package/artifacts/contracts/product/IProductService.sol/IProductService.dbg.json +1 -1
  113. package/artifacts/contracts/product/PolicyService.sol/PolicyService.dbg.json +1 -1
  114. package/artifacts/contracts/product/PolicyService.sol/PolicyService.json +2 -2
  115. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  116. package/artifacts/contracts/product/PolicyServiceManager.sol/PolicyServiceManager.json +2 -2
  117. package/artifacts/contracts/product/PricingService.sol/PricingService.dbg.json +1 -1
  118. package/artifacts/contracts/product/PricingService.sol/PricingService.json +7 -2
  119. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.dbg.json +1 -1
  120. package/artifacts/contracts/product/PricingServiceManager.sol/PricingServiceManager.json +2 -2
  121. package/artifacts/contracts/product/Product.sol/Product.dbg.json +1 -1
  122. package/artifacts/contracts/product/ProductService.sol/ProductService.dbg.json +1 -1
  123. package/artifacts/contracts/product/ProductService.sol/ProductService.json +2 -2
  124. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  125. package/artifacts/contracts/product/ProductServiceManager.sol/ProductServiceManager.json +2 -2
  126. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  127. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  128. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  129. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  130. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  131. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  132. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.dbg.json +1 -1
  133. package/artifacts/contracts/registry/RegistryAdmin.sol/RegistryAdmin.json +2 -2
  134. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  135. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
  136. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  137. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
  138. package/artifacts/contracts/registry/ReleaseLifecycle.sol/ReleaseLifecycle.dbg.json +1 -1
  139. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.dbg.json +1 -1
  140. package/artifacts/contracts/registry/ReleaseRegistry.sol/ReleaseRegistry.json +2 -2
  141. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.dbg.json +1 -1
  142. package/artifacts/contracts/registry/ServiceAuthorizationV3.sol/ServiceAuthorizationV3.json +2 -2
  143. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  144. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  145. package/artifacts/contracts/shared/Component.sol/Component.dbg.json +1 -1
  146. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.dbg.json +1 -1
  147. package/artifacts/contracts/shared/ComponentService.sol/ComponentService.json +132 -76
  148. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.dbg.json +1 -1
  149. package/artifacts/contracts/shared/ComponentServiceManager.sol/ComponentServiceManager.json +39 -39
  150. package/artifacts/contracts/shared/ComponentVerifyingService.sol/ComponentVerifyingService.dbg.json +1 -1
  151. package/artifacts/contracts/shared/IComponent.sol/IComponent.dbg.json +1 -1
  152. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.dbg.json +1 -1
  153. package/artifacts/contracts/shared/IComponentService.sol/IComponentService.json +56 -0
  154. package/artifacts/contracts/shared/IInstanceLinkedComponent.sol/IInstanceLinkedComponent.dbg.json +1 -1
  155. package/artifacts/contracts/shared/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  156. package/artifacts/contracts/shared/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  157. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  158. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  159. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  160. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  161. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  162. package/artifacts/contracts/shared/InitializableCustom.sol/InitializableCustom.dbg.json +1 -1
  163. package/artifacts/contracts/shared/InitializableERC165.sol/InitializableERC165.dbg.json +4 -0
  164. package/artifacts/contracts/shared/{ERC165.sol/ERC165.json → InitializableERC165.sol/InitializableERC165.json} +4 -4
  165. package/artifacts/contracts/shared/InstanceLinkedComponent.sol/InstanceLinkedComponent.dbg.json +1 -1
  166. package/artifacts/contracts/shared/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  167. package/artifacts/contracts/shared/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  168. package/artifacts/contracts/shared/NftIdSet.sol/NftIdSet.dbg.json +1 -1
  169. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  170. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  171. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  172. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  173. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  174. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
  175. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  176. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  177. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  178. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  179. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.json +2 -2
  180. package/artifacts/contracts/staking/IStaking.sol/IStaking.dbg.json +1 -1
  181. package/artifacts/contracts/staking/IStakingService.sol/IStakingService.dbg.json +1 -1
  182. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.dbg.json +1 -1
  183. package/artifacts/contracts/staking/StakeManagerLib.sol/StakeManagerLib.json +12 -2
  184. package/artifacts/contracts/staking/Staking.sol/Staking.dbg.json +1 -1
  185. package/artifacts/contracts/staking/Staking.sol/Staking.json +2 -2
  186. package/artifacts/contracts/staking/StakingLifecycle.sol/StakingLifecycle.dbg.json +1 -1
  187. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.dbg.json +1 -1
  188. package/artifacts/contracts/staking/StakingManager.sol/StakingManager.json +2 -2
  189. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.dbg.json +1 -1
  190. package/artifacts/contracts/staking/StakingReader.sol/StakingReader.json +2 -2
  191. package/artifacts/contracts/staking/StakingService.sol/StakingService.dbg.json +1 -1
  192. package/artifacts/contracts/staking/StakingService.sol/StakingService.json +2 -2
  193. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.dbg.json +1 -1
  194. package/artifacts/contracts/staking/StakingServiceManager.sol/StakingServiceManager.json +2 -2
  195. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.dbg.json +1 -1
  196. package/artifacts/contracts/staking/StakingStore.sol/StakingStore.json +17 -12
  197. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.dbg.json +1 -1
  198. package/artifacts/contracts/staking/TargetManagerLib.sol/TargetManagerLib.json +7 -2
  199. package/artifacts/contracts/type/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  200. package/artifacts/contracts/type/Amount.sol/AmountLib.dbg.json +1 -1
  201. package/artifacts/contracts/type/Amount.sol/AmountLib.json +37 -8
  202. package/artifacts/contracts/type/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  203. package/artifacts/contracts/type/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  204. package/artifacts/contracts/type/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  205. package/artifacts/contracts/type/Fee.sol/FeeLib.dbg.json +1 -1
  206. package/artifacts/contracts/type/Fee.sol/FeeLib.json +7 -2
  207. package/artifacts/contracts/type/Key32.sol/Key32Lib.dbg.json +1 -1
  208. package/artifacts/contracts/type/NftId.sol/NftIdLib.dbg.json +1 -1
  209. package/artifacts/contracts/type/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  210. package/artifacts/contracts/type/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  211. package/artifacts/contracts/type/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  212. package/artifacts/contracts/type/Referral.sol/ReferralLib.dbg.json +1 -1
  213. package/artifacts/contracts/type/Referral.sol/ReferralLib.json +2 -2
  214. package/artifacts/contracts/type/RequestId.sol/RequestIdLib.dbg.json +1 -1
  215. package/artifacts/contracts/type/RiskId.sol/RiskIdLib.dbg.json +1 -1
  216. package/artifacts/contracts/type/RoleId.sol/RoleIdLib.dbg.json +1 -1
  217. package/artifacts/contracts/type/Seconds.sol/SecondsLib.dbg.json +1 -1
  218. package/artifacts/contracts/type/Seconds.sol/SecondsLib.json +26 -2
  219. package/artifacts/contracts/type/Selector.sol/SelectorLib.dbg.json +1 -1
  220. package/artifacts/contracts/type/Selector.sol/SelectorSetLib.dbg.json +1 -1
  221. package/artifacts/contracts/type/StateId.sol/StateIdLib.dbg.json +1 -1
  222. package/artifacts/contracts/type/String.sol/StrLib.dbg.json +1 -1
  223. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.dbg.json +1 -1
  224. package/artifacts/contracts/type/Timestamp.sol/TimestampLib.json +2 -2
  225. package/artifacts/contracts/type/UFixed.sol/MathLib.dbg.json +1 -1
  226. package/artifacts/contracts/type/UFixed.sol/MathLib.json +9 -3
  227. package/artifacts/contracts/type/UFixed.sol/UFixedLib.dbg.json +1 -1
  228. package/artifacts/contracts/type/UFixed.sol/UFixedLib.json +39 -2
  229. package/artifacts/contracts/type/Version.sol/VersionLib.dbg.json +1 -1
  230. package/artifacts/contracts/type/Version.sol/VersionPartLib.dbg.json +1 -1
  231. package/artifacts/contracts/upgradeability/IVersionable.sol/IVersionable.dbg.json +1 -1
  232. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  233. package/artifacts/contracts/upgradeability/ProxyManager.sol/ProxyManager.json +2 -2
  234. package/artifacts/contracts/upgradeability/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  235. package/artifacts/contracts/upgradeability/Versionable.sol/Versionable.dbg.json +1 -1
  236. package/contracts/distribution/BasicDistribution.sol +4 -15
  237. package/contracts/distribution/BasicDistributionAuthorization.sol +2 -1
  238. package/contracts/distribution/Distribution.sol +21 -10
  239. package/contracts/distribution/DistributionService.sol +59 -10
  240. package/contracts/distribution/IDistributionComponent.sol +6 -1
  241. package/contracts/distribution/IDistributionService.sol +12 -0
  242. package/contracts/instance/InstanceStore.sol +2 -1
  243. package/contracts/instance/module/IBundle.sol +1 -1
  244. package/contracts/instance/module/IComponents.sol +0 -1
  245. package/contracts/instance/module/IDistribution.sol +0 -1
  246. package/contracts/oracle/IOracleComponent.sol +2 -1
  247. package/contracts/oracle/Oracle.sol +15 -6
  248. package/contracts/pool/BasicPool.sol +3 -1
  249. package/contracts/pool/BasicPoolAuthorization.sol +6 -0
  250. package/contracts/pool/BundleService.sol +159 -5
  251. package/contracts/pool/IBundleService.sol +30 -3
  252. package/contracts/pool/IPoolComponent.sol +7 -0
  253. package/contracts/pool/IPoolService.sol +12 -4
  254. package/contracts/pool/Pool.sol +24 -4
  255. package/contracts/pool/PoolService.sol +132 -6
  256. package/contracts/product/ClaimService.sol +2 -1
  257. package/contracts/product/PolicyService.sol +1 -0
  258. package/contracts/registry/ReleaseRegistry.sol +0 -2
  259. package/contracts/shared/Component.sol +6 -0
  260. package/contracts/shared/ComponentService.sol +32 -3
  261. package/contracts/shared/IComponentService.sol +5 -9
  262. package/contracts/shared/{ERC165.sol → InitializableERC165.sol} +1 -1
  263. package/contracts/shared/NftOwnable.sol +2 -2
  264. package/contracts/shared/PolicyHolder.sol +2 -5
  265. package/contracts/staking/Staking.sol +3 -1
  266. package/contracts/type/Amount.sol +12 -5
  267. package/contracts/type/Referral.sol +1 -0
  268. package/contracts/type/Seconds.sol +13 -1
  269. package/contracts/type/UFixed.sol +29 -10
  270. package/package.json +1 -1
  271. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +0 -4
@@ -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;
@@ -115,7 +117,7 @@ contract BundleService is
115
117
  poolNftId,
116
118
  bundleFee,
117
119
  filter,
118
- lifetime,
120
+ TimestampLib.blockTimestamp(),
119
121
  TimestampLib.blockTimestamp().addSeconds(lifetime),
120
122
  zeroTimestamp()));
121
123
 
@@ -231,6 +233,103 @@ 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
+ // TODO: restricted() (once #462 is done)
245
+ {
246
+ IBundle.BundleInfo memory bundleInfo = instance.getInstanceReader().getBundleInfo(bundleNftId);
247
+ StateId bundleState = instance.getInstanceReader().getMetadata(bundleNftId.toKey32(BUNDLE())).state;
248
+
249
+ if(bundleState != ACTIVE() || bundleInfo.expiredAt < TimestampLib.blockTimestamp() || bundleInfo.closedAt.gtz()) {
250
+ revert ErrorBundleServiceBundleNotOpen(bundleNftId, bundleState, bundleInfo.expiredAt);
251
+ }
252
+
253
+ _componentService.increaseBundleBalance(
254
+ instance.getInstanceStore(),
255
+ bundleNftId,
256
+ amount,
257
+ AmountLib.zero());
258
+ }
259
+
260
+ /// @inheritdoc IBundleService
261
+ function unstake(
262
+ IInstance instance,
263
+ NftId bundleNftId,
264
+ Amount amount
265
+ )
266
+ external
267
+ virtual
268
+ // TODO: restricted() (once #462 is done)
269
+ returns (Amount unstakedAmount)
270
+ {
271
+ InstanceStore instanceStore = instance.getInstanceStore();
272
+ (
273
+ Amount balanceAmount,
274
+ Amount lockedAmount,
275
+ Amount feeAmount
276
+ ) = instanceStore.getAmounts(bundleNftId);
277
+
278
+ Amount unstakedAmount = amount;
279
+ Amount availableAmount = balanceAmount - (lockedAmount + feeAmount);
280
+
281
+ // if amount is max, then unstake all available
282
+ if (amount.gte(AmountLib.max())) {
283
+ unstakedAmount = availableAmount;
284
+ }
285
+
286
+ // ensure unstaked amount does not exceed available amount
287
+ if (unstakedAmount > availableAmount) {
288
+ revert ErrorBundleServiceUnstakeAmountExceedsLimit(amount, availableAmount);
289
+ }
290
+
291
+ _componentService.decreaseBundleBalance(
292
+ instanceStore,
293
+ bundleNftId,
294
+ unstakedAmount,
295
+ AmountLib.zero());
296
+
297
+ return unstakedAmount;
298
+ }
299
+
300
+ /// @inheritdoc IBundleService
301
+ function extend(NftId bundleNftId, Seconds lifetimeExtension)
302
+ external
303
+ virtual
304
+ // TODO: restricted() (once #462 is done)
305
+ returns (Timestamp extendedExpiredAt)
306
+ {
307
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
308
+ IBundle.BundleInfo memory bundleInfo = instance.getInstanceReader().getBundleInfo(bundleNftId);
309
+ StateId bundleState = instance.getInstanceReader().getMetadata(bundleNftId.toKey32(BUNDLE())).state;
310
+
311
+ // ensure bundle belongs to the pool
312
+ if (bundleInfo.poolNftId != poolNftId) {
313
+ revert ErrorBundleServiceBundlePoolMismatch(bundleNftId, bundleInfo.poolNftId, poolNftId);
314
+ }
315
+
316
+ // ensure bundle is active and not yet expired
317
+ if(bundleState != ACTIVE() || bundleInfo.expiredAt < TimestampLib.blockTimestamp()) {
318
+ revert ErrorBundleServiceBundleNotOpen(bundleNftId, bundleState, bundleInfo.expiredAt);
319
+ }
320
+
321
+ if (lifetimeExtension.eqz()) {
322
+ revert ErrorBundleServiceExtensionLifetimeIsZero();
323
+ }
324
+
325
+ bundleInfo.expiredAt = bundleInfo.expiredAt.addSeconds(lifetimeExtension);
326
+ instance.getInstanceStore().updateBundle(bundleNftId, bundleInfo, KEEP_STATE());
327
+
328
+ emit LogBundleServiceBundleExtended(bundleNftId, lifetimeExtension, bundleInfo.expiredAt);
329
+
330
+ return bundleInfo.expiredAt;
331
+ }
332
+
234
333
 
235
334
  function releaseCollateral(
236
335
  IInstance instance,
@@ -262,6 +361,61 @@ contract BundleService is
262
361
  instance.getBundleSet().unlinkPolicy(policyNftId);
263
362
  }
264
363
 
364
+ /// @inheritdoc IBundleService
365
+ function withdrawBundleFees(NftId bundleNftId, Amount amount)
366
+ public
367
+ virtual
368
+ // TODO: restricted() (once #462 is done)
369
+ returns (Amount withdrawnAmount)
370
+ {
371
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
372
+ InstanceReader reader = instance.getInstanceReader();
373
+
374
+ IComponents.ComponentInfo memory poolInfo = reader.getComponentInfo(poolNftId);
375
+ address poolWallet = poolInfo.wallet;
376
+
377
+ IBundle.BundleInfo memory bundleInfo = reader.getBundleInfo(bundleNftId);
378
+
379
+ // determine withdrawn amount
380
+ withdrawnAmount = amount;
381
+ if (withdrawnAmount.gte(AmountLib.max())) {
382
+ withdrawnAmount = reader.getFeeAmount(bundleNftId);
383
+ } else {
384
+ if (withdrawnAmount.gt(reader.getFeeAmount(bundleNftId))) {
385
+ revert ErrorBundleServiceFeesWithdrawAmountExceedsLimit(withdrawnAmount, reader.getFeeAmount(bundleNftId));
386
+ }
387
+ }
388
+
389
+ if (withdrawnAmount.eqz()) {
390
+ revert ErrorBundleServiceFeesWithdrawAmountIsZero();
391
+ }
392
+
393
+ // check allowance
394
+ IERC20Metadata token = IERC20Metadata(poolInfo.token);
395
+ uint256 tokenAllowance = token.allowance(poolWallet, address(poolInfo.tokenHandler));
396
+ if (tokenAllowance < withdrawnAmount.toInt()) {
397
+ revert ErrorBundleServiceWalletAllowanceTooSmall(poolWallet, address(poolInfo.tokenHandler), tokenAllowance, withdrawnAmount.toInt());
398
+ }
399
+
400
+ // decrease fee counters by withdrawnAmount
401
+ {
402
+ InstanceStore store = instance.getInstanceStore();
403
+ // decrease fee amount of the bundle
404
+ _componentService.decreaseBundleBalance(store, bundleNftId, AmountLib.zero(), withdrawnAmount);
405
+ // decrease pool balance
406
+ _componentService.decreasePoolBalance(store, poolNftId, withdrawnAmount, AmountLib.zero());
407
+ }
408
+
409
+ // transfer amount to bundle owner
410
+ {
411
+ address owner = getRegistry().ownerOf(bundleNftId);
412
+ // TODO: centralize token handling (issue #471)
413
+ poolInfo.tokenHandler.transfer(poolWallet, owner, withdrawnAmount);
414
+
415
+ emit LogBundleServiceFeesWithdrawn(bundleNftId, owner, address(token), withdrawnAmount);
416
+ }
417
+ }
418
+
265
419
  /// @dev links policy to bundle
266
420
  function _linkPolicy(IInstance instance, NftId policyNftId)
267
421
  internal
@@ -26,6 +26,17 @@ interface IBundleService is IService {
26
26
 
27
27
  error ErrorBundleServicePolicyNotCloseable(NftId policyNftId);
28
28
 
29
+ error ErrorBundleServiceFeesWithdrawAmountExceedsLimit(Amount amount, Amount limit);
30
+ error ErrorBundleServiceFeesWithdrawAmountIsZero();
31
+ error ErrorBundleServiceWalletAllowanceTooSmall(address wallet, address tokenHandler, uint256 allowance, uint256 amount);
32
+
33
+ error ErrorBundleServiceUnstakeAmountExceedsLimit(Amount amount, Amount limit);
34
+
35
+ error ErrorBundleServiceExtensionLifetimeIsZero();
36
+
37
+ event LogBundleServiceFeesWithdrawn(NftId bundleNftId, address recipient, address tokenAddress, Amount amount);
38
+ event LogBundleServiceBundleExtended(NftId bundleNftId, Seconds lifetimeExtension, Timestamp extendedExpiredAt);
39
+
29
40
  /// @dev create a new bundle for the specified attributes
30
41
  /// may only be called by pool service
31
42
  function create(
@@ -42,10 +53,19 @@ interface IBundleService is IService {
42
53
 
43
54
 
44
55
  /// @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);
56
+ /// may only be called by the pool service
57
+ function stake(IInstance instance, NftId bundleNftId, Amount amount) external;
47
58
 
48
- // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
59
+ /// @dev decrease bundle stakes by the specified amount
60
+ /// may only be called by the pool service
61
+ /// @param instance the instance relevant for the bundle
62
+ /// @param bundleNftId the bundle nft id
63
+ /// @param amount the amount to unstake (set to AmountLib.max() to unstake all available stakes)
64
+ /// @return unstakedAmount the effective unstaked amount
65
+ function unstake(IInstance instance, NftId bundleNftId, Amount amount) external returns (Amount unstakedAmount);
66
+
67
+ /// @dev extend the lifetime of the bundle by the specified time in seconds
68
+ function extend(NftId bundleNftId, Seconds lifetimeExtension) external returns (Timestamp extendedExpiredAt);
49
69
 
50
70
  /// @dev locks the specified bundle, locked bundles are not available to collateralize new policies
51
71
  /// only active bundles may be locked
@@ -103,4 +123,11 @@ interface IBundleService is IService {
103
123
  IInstance instance,
104
124
  NftId policyNftId
105
125
  ) external;
126
+
127
+ /// @dev Withdraw bundle feeds for the given bundle
128
+ /// @param bundleNftId the bundle Nft Id
129
+ /// @param amount the amount to withdraw. If set to AMOUNT_MAX, the full commission available is withdrawn
130
+ /// @return withdrawnAmount the effective withdrawn amount
131
+ function withdrawBundleFees(NftId bundleNftId, Amount amount) external returns (Amount withdrawnAmount);
132
+
106
133
  }
@@ -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,15 @@ 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
+ event LogPoolServiceBundleUnstaked(NftId instanceNftId, NftId poolNftId, NftId bundleNftId, Amount amount);
28
+
26
29
  error ErrorPoolServiceBundleOwnerRoleAlreadySet(NftId poolNftId);
27
30
  error ErrorPoolServiceInvalidTransferAmount(Amount expectedAmount, Amount actualAmount);
31
+ error ErrorPoolServiceBundlePoolMismatch(NftId bundleNftId, NftId poolNftId);
32
+ error ErrorPoolServiceMaxCapitalAmountExceeded(NftId poolNftId, Amount maxCapitalAmount, Amount capitalAmount, Amount amountToBeAdded);
33
+ error ErrorPoolServiceWalletAllowanceTooSmall(address wallet, address spender, uint256 allowance, uint256 amount);
34
+ error ErrorPoolServiceAmountIsZero();
28
35
 
29
36
  /// @dev defines the required role for bundle owners for the calling pool
30
37
  /// default implementation returns PUBLIC ROLE
@@ -85,7 +92,8 @@ interface IPoolService is IService {
85
92
 
86
93
  /// @dev create a new bundle for the provided parameters
87
94
  /// staking fees will be deducted by the pool service from the staking amount
88
- /// may only be called by registered and unlocked pool components
95
+ /// may only be called by registered and unlocked pool components.
96
+ /// The pool balance is equal to the pool fees plus the capital of all bundles.
89
97
  function createBundle(
90
98
  address owner, // initial bundle owner
91
99
  Fee memory fee, // fees deducted from premium that go to bundle owner
@@ -95,6 +103,7 @@ interface IPoolService is IService {
95
103
  )
96
104
  external
97
105
  returns(NftId bundleNftId); // the nft id of the newly created bundle
106
+ // TODO: return netAmount
98
107
 
99
108
 
100
109
  /// @dev closes the specified bundle
@@ -111,13 +120,12 @@ interface IPoolService is IService {
111
120
  /// @dev increase stakes for bundle
112
121
  /// staking fees will be deducted by the pool service from the staking amount
113
122
  /// may only be called by registered and unlocked pool components
114
- // function stake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
115
-
123
+ function stake(NftId bundleNftId, Amount amount) external returns(Amount netAmount);
116
124
 
117
125
  /// @dev decrease stakes for bundle
118
126
  /// performance fees will be deducted by the pool service from the staking amount
119
127
  /// may only be called by registered and unlocked pool components
120
- // function unstake(NftId bundleNftId, uint256 amount) external returns(uint256 netAmount);
128
+ function unstake(NftId bundleNftId, Amount amount) external returns(Amount netAmount);
121
129
 
122
130
 
123
131
  /// @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
@@ -102,7 +114,6 @@ abstract contract Pool is
102
114
  returns (IComponents.PoolInfo memory poolInfo)
103
115
  {
104
116
  return IComponents.PoolInfo(
105
- NftIdLib.zero(), // will be set when GIF registers the related product
106
117
  PUBLIC_ROLE(), // bundleOwnerRole
107
118
  AmountLib.max(), // maxCapitalAmount,
108
119
  isNftInterceptor(), // isInterceptingBundleTransfers
@@ -161,8 +172,9 @@ abstract contract Pool is
161
172
  )
162
173
  internal
163
174
  virtual
175
+ returns(Amount netAmount)
164
176
  {
165
- // TODO add implementation
177
+ _getPoolStorage()._poolService.stake(bundleNftId, amount);
166
178
  }
167
179
 
168
180
 
@@ -174,8 +186,9 @@ abstract contract Pool is
174
186
  )
175
187
  internal
176
188
  virtual
189
+ returns(Amount netAmount)
177
190
  {
178
- // TODO add implementation
191
+ return _getPoolStorage()._poolService.unstake(bundleNftId, amount);
179
192
  }
180
193
 
181
194
 
@@ -187,8 +200,9 @@ abstract contract Pool is
187
200
  )
188
201
  internal
189
202
  virtual
203
+ returns (Timestamp extendedExpiredAt)
190
204
  {
191
- // TODO add implementation
205
+ return _getPoolStorage()._bundleService.extend(bundleNftId, lifetimeExtension);
192
206
  }
193
207
 
194
208
 
@@ -302,6 +316,12 @@ abstract contract Pool is
302
316
  return keccak256(abi.encode(uint256(keccak256(name)) - 1)) & ~bytes32(uint256(0xff));
303
317
  }
304
318
 
319
+ function _withdrawBundleFees(NftId bundleNftId, Amount amount)
320
+ internal
321
+ returns (Amount withdrawnAmount)
322
+ {
323
+ return _getPoolStorage()._bundleService.withdrawBundleFees(bundleNftId, amount);
324
+ }
305
325
 
306
326
  function _getPoolStorage() private pure returns (PoolStorage storage $) {
307
327
  assembly {
@@ -1,6 +1,9 @@
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
+
6
+ import {IBundle} from "../instance/module/IBundle.sol";
4
7
  import {IBundleService} from "./IBundleService.sol";
5
8
  import {IComponents} from "../instance/module/IComponents.sol";
6
9
  import {IComponentService} from "../shared/IComponentService.sol";
@@ -32,9 +35,6 @@ contract PoolService is
32
35
  ComponentVerifyingService,
33
36
  IPoolService
34
37
  {
35
- using NftIdLib for NftId;
36
- using AmountLib for Amount;
37
-
38
38
  IBundleService internal _bundleService;
39
39
  IComponentService internal _componentService;
40
40
  IInstanceService private _instanceService;
@@ -130,6 +130,7 @@ contract PoolService is
130
130
  // TODO add logging
131
131
  }
132
132
 
133
+ /// @inheritdoc IPoolService
133
134
  function createBundle(
134
135
  address bundleOwner, // initial bundle owner
135
136
  Fee memory fee, // fees deducted from premium that go to bundle owner
@@ -151,6 +152,8 @@ contract PoolService is
151
152
  _getStakingFee(instanceReader, poolNftId),
152
153
  stakingAmount);
153
154
 
155
+ // TODO: staking amount must be be > maxCapitalAmount
156
+
154
157
  bundleNftId = _bundleService.create(
155
158
  instance,
156
159
  poolNftId,
@@ -164,7 +167,7 @@ contract PoolService is
164
167
  _componentService.increasePoolBalance(
165
168
  instance.getInstanceStore(),
166
169
  poolNftId,
167
- stakingAmount,
170
+ stakingNetAmount,
168
171
  stakingFeeAmount);
169
172
 
170
173
  // pool bookkeeping and collect tokens from bundle owner
@@ -183,8 +186,8 @@ contract PoolService is
183
186
  view
184
187
  returns (Fee memory stakingFee)
185
188
  {
186
- NftId productNftId = instanceReader.getPoolInfo(poolNftId).productNftId;
187
- return instanceReader.getPoolInfo(productNftId).stakingFee;
189
+ NftId productNftId = instanceReader.getComponentInfo(poolNftId).productNftId;
190
+ return instanceReader.getProductInfo(productNftId).stakingFee;
188
191
  }
189
192
 
190
193
  function closeBundle(NftId bundleNftId)
@@ -203,6 +206,121 @@ contract PoolService is
203
206
  emit LogPoolServiceBundleClosed(instance.getNftId(), poolNftId, bundleNftId);
204
207
  }
205
208
 
209
+ /// @inheritdoc IPoolService
210
+ function stake(NftId bundleNftId, Amount amount)
211
+ external
212
+ virtual
213
+ // TODO: restricted() (once #462 is done)
214
+ returns(Amount netAmount)
215
+ {
216
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
217
+ InstanceReader instanceReader = instance.getInstanceReader();
218
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
219
+ IComponents.PoolInfo memory poolInfo = instanceReader.getPoolInfo(poolNftId);
220
+
221
+ if (bundleInfo.poolNftId != poolNftId) {
222
+ revert ErrorPoolServiceBundlePoolMismatch(bundleNftId, poolNftId);
223
+ }
224
+
225
+ Amount currentPoolBalance = instanceReader.getBalanceAmount(poolNftId);
226
+ if (amount + currentPoolBalance > poolInfo.maxCapitalAmount) {
227
+ revert ErrorPoolServiceMaxCapitalAmountExceeded(poolNftId, poolInfo.maxCapitalAmount, currentPoolBalance, amount);
228
+ }
229
+
230
+ // calculate fees
231
+ (
232
+ Amount feeAmount,
233
+ Amount netAmount
234
+ ) = FeeLib.calculateFee(
235
+ _getStakingFee(instanceReader, poolNftId),
236
+ amount);
237
+
238
+ // do all the bookkeeping
239
+ _componentService.increasePoolBalance(
240
+ instance.getInstanceStore(),
241
+ poolNftId,
242
+ netAmount,
243
+ feeAmount);
244
+
245
+ _bundleService.stake(instance, bundleNftId, netAmount);
246
+
247
+ // collect tokens from bundle owner
248
+ address bundleOwner = getRegistry().ownerOf(bundleNftId);
249
+ _collectStakingAmount(
250
+ instanceReader,
251
+ poolNftId,
252
+ bundleOwner,
253
+ amount);
254
+
255
+ emit LogPoolServiceBundleStaked(instance.getNftId(), poolNftId, bundleNftId, amount, netAmount);
256
+ }
257
+
258
+ /// @inheritdoc IPoolService
259
+ function unstake(NftId bundleNftId, Amount amount)
260
+ external
261
+ virtual
262
+ // TODO: restricted() (once #462 is done)
263
+ returns(Amount netAmount)
264
+ {
265
+ (NftId poolNftId,, IInstance instance) = _getAndVerifyActiveComponent(POOL());
266
+ InstanceReader instanceReader = instance.getInstanceReader();
267
+ InstanceStore instanceStore = instance.getInstanceStore();
268
+ IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
269
+
270
+ if (bundleInfo.poolNftId != poolNftId) {
271
+ revert ErrorPoolServiceBundlePoolMismatch(bundleNftId, poolNftId);
272
+ }
273
+
274
+ if (amount.eqz()) {
275
+ revert ErrorPoolServiceAmountIsZero();
276
+ }
277
+
278
+ // call bundle service for bookkeeping and additional checks
279
+ Amount unstakedAmount = _bundleService.unstake(instance, bundleNftId, amount);
280
+
281
+ // Important: from now on work only with unstakedAmount as it is the only reliable amount.
282
+ // if amount was max, this was set to the available amount
283
+
284
+ // TODO: handle performance fees (issue #477)
285
+
286
+ // update pool bookkeeping - performance fees stay in the pool, but as fees
287
+ _componentService.decreasePoolBalance(
288
+ instanceStore,
289
+ poolNftId,
290
+ unstakedAmount,
291
+ AmountLib.zero());
292
+
293
+ IComponents.ComponentInfo memory poolComponentInfo = instanceReader.getComponentInfo(poolNftId);
294
+ address poolWallet = poolComponentInfo.wallet;
295
+
296
+ // check allowance
297
+ {
298
+ IERC20Metadata token = IERC20Metadata(poolComponentInfo.token);
299
+ uint256 tokenAllowance = token.allowance(poolWallet, address(poolComponentInfo.tokenHandler));
300
+ if (tokenAllowance < unstakedAmount.toInt()) {
301
+ revert ErrorPoolServiceWalletAllowanceTooSmall(poolWallet, address(poolComponentInfo.tokenHandler), tokenAllowance, amount.toInt());
302
+ }
303
+ }
304
+
305
+ // transfer amount to bundle owner
306
+ address owner = getRegistry().ownerOf(bundleNftId);
307
+ // TODO: centralize token handling (issue #471)
308
+ poolComponentInfo.tokenHandler.transfer(poolWallet, owner, unstakedAmount);
309
+
310
+ emit LogPoolServiceBundleUnstaked(instance.getNftId(), poolNftId, bundleNftId, unstakedAmount);
311
+
312
+ return unstakedAmount;
313
+ }
314
+
315
+ function _getPerformanceFee(InstanceReader instanceReader, NftId poolNftId)
316
+ internal
317
+ virtual
318
+ view
319
+ returns (Fee memory performanceFee)
320
+ {
321
+ NftId productNftId = instanceReader.getComponentInfo(poolNftId).productNftId;
322
+ return instanceReader.getPoolInfo(productNftId).performanceFee;
323
+ }
206
324
 
207
325
  function processSale(
208
326
  NftId bundleNftId,
@@ -423,10 +541,18 @@ contract PoolService is
423
541
  address poolWallet = componentInfo.wallet;
424
542
 
425
543
  if(amount.gtz()) {
544
+ uint256 allowance = IERC20Metadata(componentInfo.token).allowance(bundleOwner, address(tokenHandler));
545
+ if (allowance < amount.toInt()) {
546
+ revert ErrorPoolServiceWalletAllowanceTooSmall(bundleOwner, address(tokenHandler), allowance, amount.toInt());
547
+ }
548
+
549
+ // TODO: centralize token handling (issue #471)
426
550
  tokenHandler.transfer(
427
551
  bundleOwner,
428
552
  poolWallet,
429
553
  amount);
554
+ } else {
555
+ revert ErrorPoolServiceAmountIsZero();
430
556
  }
431
557
  }
432
558
 
@@ -336,7 +336,8 @@ contract ClaimService is
336
336
  // TODO transfer processing fees to product wallet
337
337
  // TODO inform product to update fee book keeping
338
338
  }
339
-
339
+
340
+ // TODO: centralize token handling (issue #471)
340
341
  poolInfo.tokenHandler.transfer(
341
342
  poolInfo.wallet,
342
343
  beneficiary,
@@ -427,6 +427,7 @@ contract PolicyService is
427
427
  bundleNftId,
428
428
  premium);
429
429
 
430
+ // TODO: centralize token handling (issue #471)
430
431
  // transfer premium amounts to target wallets
431
432
  tokenHandler.transfer(policyHolder, productWallet, premium.productFeeAmount);
432
433
  tokenHandler.transfer(policyHolder, distributionWallet, premium.distributionFeeAndCommissionAmount);
@@ -32,8 +32,6 @@ import {Registry} from "./Registry.sol";
32
32
  import {TokenRegistry} from "./TokenRegistry.sol";
33
33
  import {ReleaseLifecycle} from "./ReleaseLifecycle.sol";
34
34
 
35
- // TODO rename to something that does not end with 'Manager'
36
- // everywhere else *Manager points to an upgradeable contract
37
35
  contract ReleaseRegistry is
38
36
  AccessManaged,
39
37
  ReleaseLifecycle,
@@ -39,6 +39,12 @@ abstract contract Component is
39
39
  _;
40
40
  }
41
41
 
42
+ modifier onlyNftOwner(NftId nftId) {
43
+ if(msg.sender != getRegistry().ownerOf(nftId)) {
44
+ revert ErrorNftOwnableNotOwner(msg.sender);
45
+ }
46
+ _;
47
+ }
42
48
 
43
49
  function _getComponentStorage() private pure returns (ComponentStorage storage $) {
44
50
  assembly {