@etherisc/gif-next 0.0.2-93de5de-423 → 0.0.2-94237b7-984

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