@etherisc/gif-next 0.0.2-f29e479-370 → 0.0.2-f2df3e2-873

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. package/README.md +6 -83
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +78 -89
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  5. package/artifacts/contracts/components/Distribution.sol/Distribution.json +139 -140
  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 +181 -112
  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 +527 -400
  26. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  27. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +175 -51
  28. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  29. package/artifacts/contracts/instance/Instance.sol/Instance.json +500 -612
  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 +253 -236
  34. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  35. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +305 -211
  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 -31
  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 +291 -100
  60. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  61. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +46 -22
  62. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  63. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +422 -252
  64. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  65. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +78 -14
  66. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  67. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +373 -87
  68. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +55 -7
  70. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +579 -123
  72. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +71 -47
  74. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +200 -46
  76. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +241 -188
  78. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +251 -58
  80. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +444 -25
  82. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +430 -76
  84. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +511 -14
  86. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +80 -14
  88. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +544 -153
  90. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +51 -27
  92. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  93. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +562 -52
  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 -52
  98. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  99. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +16 -12
  100. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  101. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +15 -2
  102. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  103. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +19 -0
  104. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  105. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +0 -24
  106. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  107. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.json +18 -0
  108. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  109. package/artifacts/contracts/registry/Registry.sol/Registry.json +31 -12
  110. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  111. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  112. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  113. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +18 -37
  114. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  115. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  116. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  117. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +23 -11
  118. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  119. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  120. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  121. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  122. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  123. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  124. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  125. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  126. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  127. package/artifacts/contracts/shared/IService.sol/IService.json +80 -14
  128. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  129. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  130. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  131. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  132. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  133. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  134. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  135. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  136. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +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 +87 -16
  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 +102 -27
  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 +185 -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/ClaimId.sol/ClaimIdLib.json +83 -4
  168. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  169. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.json +2 -2
  170. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  171. package/artifacts/contracts/types/Fee.sol/FeeLib.json +40 -9
  172. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  173. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  174. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  175. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +17 -4
  176. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  177. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  178. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  179. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  180. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  181. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  182. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.json +116 -7
  183. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  184. package/artifacts/contracts/types/Referral.sol/ReferralLib.json +23 -4
  185. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  186. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +2 -2
  187. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  188. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  189. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +4 -0
  190. package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
  191. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  192. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
  193. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  194. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +38 -7
  195. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  196. package/artifacts/contracts/types/UFixed.sol/MathLib.json +2 -2
  197. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  198. package/artifacts/contracts/types/UFixed.sol/UFixedLib.json +2 -2
  199. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  200. package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
  201. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  202. package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
  203. package/contracts/components/Component.sol +99 -87
  204. package/contracts/components/Distribution.sol +18 -21
  205. package/contracts/components/IComponent.sol +40 -18
  206. package/contracts/components/IDistributionComponent.sol +1 -22
  207. package/contracts/components/IPoolComponent.sol +73 -47
  208. package/contracts/components/IProductComponent.sol +3 -2
  209. package/contracts/components/Pool.sol +178 -130
  210. package/contracts/components/Product.sol +157 -71
  211. package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +13 -0
  212. package/contracts/instance/BundleManager.sol +10 -9
  213. package/contracts/instance/Cloneable.sol +7 -2
  214. package/contracts/instance/IInstance.sol +37 -27
  215. package/contracts/instance/IInstanceService.sol +18 -9
  216. package/contracts/instance/Instance.sol +117 -98
  217. package/contracts/instance/InstanceAccessManager.sol +388 -158
  218. package/contracts/instance/InstanceReader.sol +36 -12
  219. package/contracts/instance/InstanceService.sol +193 -191
  220. package/contracts/instance/ObjectManager.sol +6 -8
  221. package/contracts/instance/base/ComponentService.sol +17 -30
  222. package/contracts/instance/base/KeyValueStore.sol +13 -5
  223. package/contracts/instance/base/Lifecycle.sol +23 -6
  224. package/contracts/instance/module/IAccess.sol +21 -14
  225. package/contracts/instance/module/IBundle.sol +8 -5
  226. package/contracts/instance/module/IComponents.sol +41 -0
  227. package/contracts/instance/module/IDistribution.sol +2 -1
  228. package/contracts/instance/module/IPolicy.sol +37 -7
  229. package/contracts/instance/module/ISetup.sol +7 -22
  230. package/contracts/instance/service/ApplicationService.sol +137 -50
  231. package/contracts/instance/service/BundleService.sol +221 -83
  232. package/contracts/instance/service/ClaimService.sol +114 -26
  233. package/contracts/instance/service/DistributionService.sol +174 -118
  234. package/contracts/instance/service/IApplicationService.sol +9 -13
  235. package/contracts/instance/service/IBundleService.sol +68 -26
  236. package/contracts/instance/service/IClaimService.sol +46 -15
  237. package/contracts/instance/service/IDistributionService.sol +20 -4
  238. package/contracts/instance/service/IPolicyService.sol +69 -21
  239. package/contracts/instance/service/IPoolService.sol +82 -3
  240. package/contracts/instance/service/PolicyService.sol +297 -232
  241. package/contracts/instance/service/PoolService.sol +214 -20
  242. package/contracts/instance/service/ProductService.sol +31 -54
  243. package/contracts/registry/ChainNft.sol +8 -0
  244. package/contracts/registry/IRegistry.sol +2 -0
  245. package/contracts/registry/IRegistryService.sol +4 -3
  246. package/contracts/registry/ITransferInterceptor.sol +1 -0
  247. package/contracts/registry/Registry.sol +23 -20
  248. package/contracts/registry/RegistryService.sol +15 -16
  249. package/contracts/registry/ReleaseManager.sol +20 -18
  250. package/contracts/shared/IService.sol +4 -6
  251. package/contracts/shared/Registerable.sol +2 -2
  252. package/contracts/shared/Service.sol +21 -7
  253. package/contracts/shared/TokenHandler.sol +11 -5
  254. package/contracts/test/TestService.sol +1 -1
  255. package/contracts/types/Amount.sol +65 -0
  256. package/contracts/types/Blocknumber.sol +1 -0
  257. package/contracts/types/ClaimId.sol +25 -2
  258. package/contracts/types/Fee.sol +13 -5
  259. package/contracts/types/NftId.sol +8 -0
  260. package/contracts/types/ObjectType.sol +6 -5
  261. package/contracts/types/PayoutId.sol +33 -5
  262. package/contracts/types/Referral.sol +4 -0
  263. package/contracts/types/RoleId.sol +13 -6
  264. package/contracts/types/Seconds.sol +54 -0
  265. package/contracts/types/StateId.sol +7 -2
  266. package/contracts/types/Timestamp.sol +18 -13
  267. package/contracts/types/UFixed.sol +1 -0
  268. package/contracts/types/Version.sol +1 -0
  269. package/package.json +1 -1
@@ -22,18 +22,19 @@ import {TokenHandler} from "../../shared/TokenHandler.sol";
22
22
  import {IVersionable} from "../../shared/IVersionable.sol";
23
23
  import {Versionable} from "../../shared/Versionable.sol";
24
24
 
25
+ import {Amount, AmountLib} from "../../types/Amount.sol";
25
26
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
26
27
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
27
28
  import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
28
29
  import {ObjectType, INSTANCE, PRODUCT, POOL, APPLICATION, POLICY, CLAIM, BUNDLE} from "../../types/ObjectType.sol";
29
- import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
30
+ import {SUBMITTED, ACTIVE, KEEP_STATE, DECLINED, CONFIRMED, CLOSED} from "../../types/StateId.sol";
30
31
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
31
32
  import {Fee, FeeLib} from "../../types/Fee.sol";
32
33
  import {ReferralId} from "../../types/Referral.sol";
33
34
  import {RiskId} from "../../types/RiskId.sol";
34
35
  import {StateId} from "../../types/StateId.sol";
35
- import {ClaimId} from "../../types/ClaimId.sol";
36
- import {PayoutId} from "../../types/PayoutId.sol";
36
+ import {ClaimId, ClaimIdLib} from "../../types/ClaimId.sol";
37
+ import {PayoutId, PayoutIdLib} from "../../types/PayoutId.sol";
37
38
  import {Version, VersionLib} from "../../types/Version.sol";
38
39
 
39
40
  import {ComponentService} from "../base/ComponentService.sol";
@@ -50,6 +51,7 @@ contract ClaimService is
50
51
  IClaimService
51
52
  {
52
53
 
54
+ IPoolService internal _poolService;
53
55
 
54
56
  function _initialize(
55
57
  address owner,
@@ -64,77 +66,140 @@ contract ClaimService is
64
66
  address initialOwner;
65
67
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
66
68
 
67
- initializeService(registryAddress, owner);
69
+ initializeService(registryAddress, address(0), owner);
70
+
71
+ _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getVersion().toMajorPart()));
72
+
68
73
  registerInterface(type(IClaimService).interfaceId);
69
74
  }
70
75
 
71
76
 
72
- function getDomain() public pure override(IService, Service) returns(ObjectType) {
77
+ function getDomain() public pure override returns(ObjectType) {
73
78
  return CLAIM();
74
79
  }
75
80
 
76
81
 
77
- function createClaim(
82
+ function submit(
83
+ IInstance instance,
78
84
  NftId policyNftId,
79
- uint256 claimAmount,
85
+ ClaimId claimId,
86
+ Amount claimAmount,
80
87
  bytes memory claimData
81
88
  )
82
89
  external
83
90
  virtual
84
- returns (ClaimId)
91
+ // TODO add restricted and grant to policy service
85
92
  {
86
-
93
+ instance.createClaim(
94
+ policyNftId,
95
+ claimId,
96
+ IPolicy.ClaimInfo(
97
+ claimAmount,
98
+ AmountLib.zero(), // paidAmount
99
+ 0, // payoutsCount
100
+ 0, // openPayoutsCount
101
+ claimData,
102
+ TimestampLib.zero())); // closedAt
87
103
  }
88
104
 
89
105
 
90
- function confirmClaim(NftId policyNftId, ClaimId claimId, uint256 claimAmount)
106
+ function confirm(
107
+ IInstance instance,
108
+ InstanceReader instanceReader,
109
+ NftId policyNftId,
110
+ ClaimId claimId,
111
+ Amount confirmedAmount
112
+ )
91
113
  external
92
114
  virtual
93
- // solhint-disable-next-line no-empty-blocks
94
115
  {
95
-
116
+ IPolicy.ClaimInfo memory claimInfo = _verifyClaim(instanceReader, policyNftId, claimId, SUBMITTED());
117
+ claimInfo.claimAmount = confirmedAmount;
118
+ instance.updateClaim(policyNftId, claimId, claimInfo, CONFIRMED());
96
119
  }
97
120
 
98
-
99
- function declineClaim(NftId policyNftId, ClaimId claimId)
121
+ function decline(
122
+ IInstance instance,
123
+ InstanceReader instanceReader,
124
+ NftId policyNftId,
125
+ ClaimId claimId
126
+ )
100
127
  external
101
128
  virtual
102
- // solhint-disable-next-line no-empty-blocks
103
129
  {
104
-
130
+ IPolicy.ClaimInfo memory claimInfo = _verifyClaim(instanceReader, policyNftId, claimId, SUBMITTED());
131
+ claimInfo.closedAt = TimestampLib.blockTimestamp();
132
+ instance.updateClaim(policyNftId, claimId, claimInfo, DECLINED());
105
133
  }
106
134
 
107
135
 
108
- function closeClaim(NftId policyNftId, ClaimId claimId)
136
+ function close(
137
+ IInstance instance,
138
+ InstanceReader instanceReader,
139
+ NftId policyNftId,
140
+ ClaimId claimId
141
+ )
109
142
  external
110
143
  virtual
111
- // solhint-disable-next-line no-empty-blocks
112
144
  {
113
-
145
+ IPolicy.ClaimInfo memory claimInfo = _verifyClaim(instanceReader, policyNftId, claimId, CONFIRMED());
146
+
147
+ // check claim has no open payouts
148
+ if(claimInfo.openPayoutsCount > 0) {
149
+ revert ErrorClaimServiceClaimWithOpenPayouts(
150
+ policyNftId,
151
+ claimId,
152
+ claimInfo.openPayoutsCount);
153
+ }
154
+
155
+ // check claim paid amount matches with claim amount
156
+ if(claimInfo.paidAmount.toInt() < claimInfo.claimAmount.toInt()) {
157
+ revert ErrorClaimServiceClaimWithMissingPayouts(
158
+ policyNftId,
159
+ claimId,
160
+ claimInfo.claimAmount,
161
+ claimInfo.paidAmount);
162
+ }
163
+
164
+ claimInfo.closedAt = TimestampLib.blockTimestamp();
165
+ instance.updateClaim(policyNftId, claimId, claimInfo, CLOSED());
114
166
  }
115
167
 
116
168
 
117
169
  function createPayout(
170
+ IInstance instance,
118
171
  NftId policyNftId,
119
- ClaimId claimId,
120
- uint256 payoutAmount,
172
+ PayoutId payoutId,
173
+ Amount payoutAmount,
121
174
  bytes calldata payoutData
122
175
  )
123
176
  external
124
177
  virtual
125
- returns(PayoutId payoutId)
126
- // solhint-disable-next-line no-empty-blocks
178
+ // TODO add restricted and grant to policy service
127
179
  {
128
-
180
+ instance.createPayout(
181
+ policyNftId,
182
+ payoutId,
183
+ IPolicy.PayoutInfo(
184
+ payoutId.toClaimId(),
185
+ payoutAmount,
186
+ payoutData,
187
+ TimestampLib.zero()));
129
188
  }
130
189
 
131
190
 
132
- function payoutExecuted(
191
+ function processPayout(
192
+ IInstance instance,
193
+ InstanceReader instanceReader,
133
194
  NftId policyNftId,
134
195
  PayoutId payoutId
135
196
  )
136
197
  external
137
198
  virtual
199
+ returns (
200
+ Amount amount,
201
+ bool payoutIsClosingClaim
202
+ )
138
203
  // solhint-disable-next-line no-empty-blocks
139
204
  {
140
205
 
@@ -143,9 +208,32 @@ contract ClaimService is
143
208
 
144
209
  // internal functions
145
210
 
211
+ function _verifyClaim(
212
+ InstanceReader instanceReader,
213
+ NftId policyNftId,
214
+ ClaimId claimId,
215
+ StateId expectedState
216
+ )
217
+ internal
218
+ view
219
+ returns (
220
+ IPolicy.ClaimInfo memory claimInfo
221
+ )
222
+ {
223
+ // check claim is created state
224
+ StateId claimState = instanceReader.getClaimState(policyNftId, claimId);
225
+ if(claimState != expectedState) {
226
+ revert ErrorClaimServiceClaimNotInExpectedState(
227
+ policyNftId, claimId, expectedState, claimState);
228
+ }
229
+
230
+ // get claim info
231
+ claimInfo = instanceReader.getClaimInfo(policyNftId, claimId);
232
+ }
233
+
146
234
  function _getAndVerifyInstanceAndProduct() internal view returns (Product product) {
147
235
  IRegistry.ObjectInfo memory productInfo;
148
- (productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
236
+ (, productInfo,) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
149
237
  product = Product(productInfo.objectAddress);
150
238
  }
151
239
  }
@@ -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
12
  import {Fee, FeeLib} from "../../types/Fee.sol";
12
- import {DISTRIBUTION_OWNER_ROLE} from "../../types/RoleId.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";
@@ -41,6 +43,7 @@ contract DistributionService is
41
43
  using TimestampLib for Timestamp;
42
44
  using UFixedLib for UFixed;
43
45
  using FeeLib for Fee;
46
+ using ReferralLib for ReferralId;
44
47
 
45
48
  address internal _registryAddress;
46
49
 
@@ -57,11 +60,11 @@ contract DistributionService is
57
60
  (registryAddress, initialOwner) = abi.decode(data, (address, address));
58
61
  // TODO while DistributionService is not deployed in DistributionServiceManager constructor
59
62
  // owner is DistributionServiceManager deployer
60
- initializeService(registryAddress, owner);
63
+ initializeService(registryAddress, address(0), owner);
61
64
  registerInterface(type(IDistributionService).interfaceId);
62
65
  }
63
66
 
64
- function getDomain() public pure override(Service, IService) returns(ObjectType) {
67
+ function getDomain() public pure override returns(ObjectType) {
65
68
  return DISTRIBUTION();
66
69
  }
67
70
 
@@ -85,21 +88,42 @@ contract DistributionService is
85
88
  distributionNftId = distributionInfo.nftId;
86
89
 
87
90
  instance.createDistributionSetup(distributionNftId, distribution.getSetupInfo());
88
- getInstanceService().createGifTarget(instanceNftId, distributionAddress, distribution.getName());
89
- 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);
90
109
  }
91
110
 
92
111
  function setFees(
112
+ Fee memory minDistributionOwnerFee,
93
113
  Fee memory distributionFee
94
114
  )
95
115
  external
96
116
  override
97
117
  {
98
- (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());
99
123
  InstanceReader instanceReader = instance.getInstanceReader();
100
- NftId distributionNftId = info.nftId;
101
124
 
102
125
  ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
126
+ distSetupInfo.minDistributionOwnerFee = minDistributionOwnerFee;
103
127
  distSetupInfo.distributionFee = distributionFee;
104
128
 
105
129
  instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
@@ -119,36 +143,30 @@ contract DistributionService is
119
143
  external
120
144
  returns (DistributorType distributorType)
121
145
  {
122
- (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
146
+ (NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
123
147
 
124
148
  {
125
- if (commissionPercentage > maxDiscountPercentage) {
126
- revert ErrorIDistributionServiceCommissionTooHigh(commissionPercentage.toInt(), maxDiscountPercentage.toInt());
127
- }
128
-
129
149
  ISetup.DistributionSetupInfo memory setupInfo = instance.getInstanceReader().getDistributionSetupInfo(distributionNftId);
130
- if (maxDiscountPercentage > setupInfo.distributionFee.fractionalFee) {
131
- revert ErrorIDistributionServiceMaxDiscountTooHigh(maxDiscountPercentage.toInt(), setupInfo.distributionFee.fractionalFee.toInt());
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());
132
154
  }
133
155
  }
134
156
 
135
157
  distributorType = DistributorTypeLib.toDistributorType(distributionNftId, name);
136
- Key32 key32 = distributorType.toKey32();
137
-
138
- if(!instance.exists(key32)) {
139
- IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo(
140
- name,
141
- minDiscountPercentage,
142
- maxDiscountPercentage,
143
- commissionPercentage,
144
- maxReferralCount,
145
- maxReferralLifetime,
146
- allowSelfReferrals,
147
- allowRenewals,
148
- data);
149
-
150
- instance.createDistributorType(key32, info);
151
- }
158
+ IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo(
159
+ name,
160
+ minDiscountPercentage,
161
+ maxDiscountPercentage,
162
+ commissionPercentage,
163
+ maxReferralCount,
164
+ maxReferralLifetime,
165
+ allowSelfReferrals,
166
+ allowRenewals,
167
+ data);
168
+
169
+ instance.createDistributorType(distributorType, info);
152
170
  }
153
171
 
154
172
  function createDistributor(
@@ -157,7 +175,7 @@ contract DistributionService is
157
175
  bytes memory data
158
176
  ) external returns (NftId distributorNftId)
159
177
  {
160
- (, NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
178
+ (NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
161
179
 
162
180
  distributorNftId = getRegistryService().registerDistributor(
163
181
  IRegistry.ObjectInfo(
@@ -173,7 +191,9 @@ contract DistributionService is
173
191
  IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
174
192
  distributorType,
175
193
  true, // active
176
- data);
194
+ data,
195
+ 0,
196
+ 0);
177
197
 
178
198
  instance.createDistributor(distributorNftId, info);
179
199
  }
@@ -184,14 +204,12 @@ contract DistributionService is
184
204
  bytes memory data
185
205
  ) external virtual
186
206
  {
187
- (,, IInstance instance) = _getAndVerifyCallingDistribution();
188
-
189
- IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
190
- distributorType,
191
- true, // active
192
- data);
193
-
194
- instance.updateDistributor(distributorNftId, info, KEEP_STATE());
207
+ (, IInstance instance) = _getAndVerifyCallingDistribution();
208
+ InstanceReader instanceReader = instance.getInstanceReader();
209
+ IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
210
+ distributorInfo.distributorType = distributorType;
211
+ distributorInfo.data = data;
212
+ instance.updateDistributor(distributorNftId, distributorInfo, KEEP_STATE());
195
213
  }
196
214
 
197
215
 
@@ -207,7 +225,7 @@ contract DistributionService is
207
225
  virtual
208
226
  returns (ReferralId referralId)
209
227
  {
210
- (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
228
+ (NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
211
229
 
212
230
  if (bytes(code).length == 0) {
213
231
  revert ErrorIDistributionServiceInvalidReferral(code);
@@ -217,8 +235,8 @@ contract DistributionService is
217
235
  }
218
236
 
219
237
  InstanceReader instanceReader = instance.getInstanceReader();
220
- IDistribution.DistributorInfo memory distributorTypeInfo = instanceReader.getDistributorInfo(distributorNftId);
221
- DistributorType distributorType = distributorTypeInfo.distributorType;
238
+ IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
239
+ DistributorType distributorType = distributorInfo.distributorType;
222
240
  IDistribution.DistributorTypeInfo memory distributorTypeData = instanceReader.getDistributorTypeInfo(distributorType);
223
241
 
224
242
  if (distributorTypeData.maxReferralCount < maxReferrals) {
@@ -245,60 +263,129 @@ contract DistributionService is
245
263
  data
246
264
  );
247
265
 
248
- instance.createReferral(referralId.toKey32(), info);
266
+ instance.createReferral(referralId, info);
249
267
  return referralId;
250
268
  }
251
269
 
252
270
  function processSale(
271
+ NftId distributionNftId,
253
272
  ReferralId referralId,
254
- uint256 premiumAmount
273
+ IPolicy.Premium memory premium,
274
+ uint256 transferredDistributionFeeAmount
255
275
  )
256
276
  external
257
277
  virtual
258
278
  {
259
- // TODO: fetch referral
260
- // TODO: update referral usage numbers
261
- // TODO: update bookkeeping
262
- // TODO: calculate commission for distributor
263
- // TODO: calculate fee for distribution owner
264
- // TODO: updates sum of commission per distributor -> DistributorInfo
265
- // TODO: updates sum of fee per distribution owner
266
- revert("NOT_IMPLEMENTED_YET");
279
+ bool isReferral = ! referralId.eqz();
280
+ bool referralValid = referralIsValid(distributionNftId, referralId);
281
+
282
+ if (isReferral && ! referralValid) {
283
+ revert ErrorIDistributionServiceReferralInvalid(distributionNftId, referralId);
284
+ }
285
+
286
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
287
+ InstanceReader reader = instance.getInstanceReader();
288
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
289
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
290
+ ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
291
+
292
+ uint256 distributionOwnerFee = premium.distributionOwnerFeeFixAmount + premium.distributionOwnerFeeVarAmount;
293
+ uint256 commissionAmount = premium.commissionAmount;
294
+
295
+ if (transferredDistributionFeeAmount != distributionOwnerFee + commissionAmount) {
296
+ revert ErrorIDistributionServiceInvalidFeeTransferred(transferredDistributionFeeAmount, distributionOwnerFee + commissionAmount);
297
+ }
298
+
299
+
300
+ if (distributionOwnerFee > 0) {
301
+ setupInfo.sumDistributionOwnerFees += distributionOwnerFee;
302
+ instance.updateDistributionSetup(distributionNftId, setupInfo, KEEP_STATE());
303
+ }
304
+
305
+ if (isReferral) {
306
+ referralInfo.usedReferrals += 1;
307
+ instance.updateReferral(referralId, referralInfo, KEEP_STATE());
308
+
309
+ if (commissionAmount > 0) {
310
+ distributorInfo.sumCommisions += commissionAmount;
311
+ distributorInfo.numPoliciesSold += 1;
312
+ instance.updateDistributor(referralInfo.distributorNftId, distributorInfo, KEEP_STATE());
313
+ }
314
+ }
267
315
  }
268
316
 
269
317
  function calculateFeeAmount(
270
318
  NftId distributionNftId,
271
319
  ReferralId referralId,
272
- uint256 netPremiumAmount
320
+ IPolicy.Premium memory premium
273
321
  )
274
322
  external
275
323
  virtual
276
324
  view
277
- returns (uint256 feeAmount)
325
+ returns (IPolicy.Premium memory finalPremium)
278
326
  {
279
- (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
327
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
280
328
  InstanceReader reader = instance.getInstanceReader();
281
-
282
- // calculate fee based on the distribution components fee
329
+
330
+ // first calculate all fixed and variable fees for the distribution - this will defined the fullPremium
283
331
  ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
284
- Fee memory fee = setupInfo.distributionFee;
285
- (feeAmount,) = fee.calculateFee(netPremiumAmount);
286
-
287
- if (referralIsValid(distributionNftId, referralId)) {
288
- // (distributionFee(fixed + pct) - referralDiscount(pct)) ... discount <= distributionFee
289
- IDistribution.ReferralInfo memory info = reader.getReferralInfo(referralId);
290
- uint256 discountAmount = UFixedLib.toUFixed(netPremiumAmount).mul(info.discountPercentage).toInt();
291
- if (discountAmount > feeAmount) {
292
- feeAmount = 0;
293
- } else {
294
- feeAmount -= discountAmount;
295
- }
296
- }
297
- // else - just use distributionFee from component
332
+ Fee memory distributionFee = setupInfo.distributionFee;
333
+ Fee memory minDistributionOwnerFee = setupInfo.minDistributionOwnerFee;
334
+ uint256 distributionFeeVarAmount = (UFixedLib.toUFixed(premium.netPremiumAmount) * distributionFee.fractionalFee).toInt();
335
+ premium.distributionFeeVarAmount = distributionFeeVarAmount;
336
+ premium.fullPremiumAmount += distributionFeeVarAmount;
337
+
338
+ // if the referral is not valid, then the distribution owner gets everything
339
+ if (! referralIsValid(distributionNftId, referralId)) {
340
+ premium.distributionOwnerFeeFixAmount = premium.distributionFeeFixAmount;
341
+ premium.distributionOwnerFeeVarAmount = premium.distributionFeeVarAmount;
342
+ premium.premiumAmount = premium.fullPremiumAmount;
343
+ return premium;
344
+ }
345
+
346
+ // if the referral is valid, the the commission and discount are calculated based in the full premium
347
+ // the remaing amount goes to the distribution owner
348
+ {
349
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
350
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
351
+ IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
352
+
353
+ uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
354
+ premium.commissionAmount = commissionAmount;
355
+ premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
356
+ premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
357
+ premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
358
+ premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
359
+ }
360
+
361
+ // sanity check to validate the fee calculation
362
+ if (premium.distributionOwnerFeeFixAmount < minDistributionOwnerFee.fixedFee) {
363
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
364
+ premium.distributionFeeFixAmount,
365
+ premium.distributionFeeVarAmount,
366
+ premium.distributionOwnerFeeFixAmount,
367
+ premium.distributionOwnerFeeVarAmount,
368
+ premium.commissionAmount,
369
+ premium.discountAmount
370
+ );
371
+ }
372
+ if ((premium.distributionFeeVarAmount) != (premium.discountAmount + premium.distributionOwnerFeeVarAmount + premium.commissionAmount)) {
373
+ revert ErrorIDistributionServiceFeeCalculationMismatch(
374
+ premium.distributionFeeFixAmount,
375
+ premium.distributionFeeVarAmount,
376
+ premium.distributionOwnerFeeFixAmount,
377
+ premium.distributionOwnerFeeVarAmount,
378
+ premium.commissionAmount,
379
+ premium.discountAmount
380
+ );
381
+ }
382
+
383
+ return premium;
298
384
  }
299
385
 
386
+ // TODO: zero should return false
300
387
  function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
301
- (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
388
+ IInstance instance = _getInstanceForDistribution(distributionNftId);
302
389
  IDistribution.ReferralInfo memory info = instance.getInstanceReader().getReferralInfo(referralId);
303
390
 
304
391
  if (info.distributorNftId.eqz()) {
@@ -313,63 +400,32 @@ contract DistributionService is
313
400
  internal
314
401
  view
315
402
  returns(
316
- address distributionAddress,
317
403
  NftId distributionNftId,
318
404
  IInstance instance
319
405
  )
320
406
  {
321
- ObjectType objectType;
322
- (
323
- distributionAddress,
324
- distributionNftId,
325
- objectType,
326
- instance
327
- ) = _getAndVerifyCaller();
328
-
329
- if(objectType != DISTRIBUTION()) {
330
- revert ErrorIDistributionServiceCallerNotDistributor(msg.sender);
407
+ distributionNftId = getRegistry().getNftId(msg.sender);
408
+ if (distributionNftId.eqz()) {
409
+ revert ErrorDistributionServiceCallerNotRegistered(msg.sender);
331
410
  }
332
- }
333
411
 
334
- function _getAndVerifyDistribution(NftId distributionNftId)
335
- internal
336
- view
337
- returns(
338
- address distributionAddress,
339
- IInstance instance
340
- )
341
- {
342
412
  IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(distributionNftId);
343
- IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
344
- if (parentInfo.objectType != INSTANCE()) {
345
- revert ErrorIDistributionServiceParentNftIdNotInstance(distributionNftId, info.parentNftId);
413
+ if(info.objectType != DISTRIBUTION()) {
414
+ revert ErrorIDistributionServiceCallerNotDistributor(msg.sender);
346
415
  }
347
- instance = IInstance(parentInfo.objectAddress);
416
+
417
+ address instanceAddress = getRegistry().getObjectInfo(info.parentNftId).objectAddress;
418
+ instance = IInstance(instanceAddress);
348
419
  }
349
420
 
350
- function _getAndVerifyCaller()
421
+
422
+ function _getInstanceForDistribution(NftId distributionNftId)
351
423
  internal
352
424
  view
353
- returns(
354
- address objectAddress,
355
- NftId objectNftId,
356
- ObjectType objectType,
357
- IInstance instance
358
- )
425
+ returns(IInstance instance)
359
426
  {
360
- objectAddress = msg.sender;
361
- objectNftId = getRegistry().getNftId(objectAddress);
362
- if ( objectNftId.eqz()) {
363
- revert ErrorIServiceCallerUnknown(objectAddress);
364
- }
365
- IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(objectNftId);
366
- objectType = info.objectType;
367
-
368
- IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
369
- if (parentInfo.objectType != INSTANCE()) {
370
- revert ErrorIDistributionServiceParentNftIdNotInstance(objectNftId, info.parentNftId);
371
- }
372
- instance = IInstance(parentInfo.objectAddress);
427
+ NftId instanceNftId = getRegistry().getObjectInfo(distributionNftId).parentNftId;
428
+ address instanceAddress = getRegistry().getObjectInfo(instanceNftId).objectAddress;
429
+ return IInstance(instanceAddress);
373
430
  }
374
-
375
431
  }