@etherisc/gif-next 0.0.2-d3ee0cc-268 → 0.0.2-d408403-475

Sign up to get free protection for your applications and to get access to all the features.
Files changed (217) hide show
  1. package/README.md +38 -11
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +4 -0
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +405 -0
  5. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +4 -0
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +340 -0
  8. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +131 -0
  10. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +109 -18
  12. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  13. package/artifacts/contracts/components/Pool.sol/Pool.json +194 -3
  14. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  15. package/artifacts/contracts/components/Product.sol/Product.json +160 -21
  16. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  22. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  28. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  29. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  30. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  31. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  32. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  33. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  34. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  35. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +592 -451
  36. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +1 -1
  37. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  38. package/artifacts/contracts/instance/Instance.sol/Instance.json +735 -506
  39. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  40. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +50 -0
  42. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +49 -0
  44. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +1 -1
  46. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.json +50 -0
  48. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  49. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +41 -23
  50. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  51. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +4 -4
  52. package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +1 -1
  53. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +1 -1
  56. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +1 -1
  58. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +55 -54
  59. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +1 -1
  60. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +1 -1
  61. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +56 -55
  62. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  63. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.json +22 -93
  64. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +1 -1
  65. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  66. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.json +22 -93
  67. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.dbg.json +4 -0
  68. package/artifacts/contracts/instance/module/distribution/DistributionModule.sol/DistributionModule.json +10 -0
  69. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistribution.dbg.json +4 -0
  70. package/artifacts/contracts/instance/module/{compensation/ICompensation.sol/ICompensation.json → distribution/IDistribution.sol/IDistribution.json} +2 -2
  71. package/artifacts/contracts/instance/module/distribution/IDistribution.sol/IDistributionModule.dbg.json +4 -0
  72. package/artifacts/contracts/instance/module/{compensation/ICompensation.sol/ICompensationModule.json → distribution/IDistribution.sol/IDistributionModule.json} +2 -2
  73. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  75. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.json +61 -38
  76. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  77. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.json +61 -38
  78. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  79. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  80. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.json +0 -5
  81. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  82. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.json +0 -5
  83. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +1 -1
  84. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +1 -1
  85. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.json +104 -1
  86. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +1 -1
  87. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +126 -5
  88. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
  89. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
  90. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +209 -231
  91. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  92. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +2 -2
  93. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
  94. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +209 -231
  95. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +55 -15
  97. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +4 -0
  98. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +420 -0
  99. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  100. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +4 -0
  101. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +325 -0
  102. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  103. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +64 -0
  104. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  105. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +160 -7
  106. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  107. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +84 -12
  108. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  109. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +216 -31
  110. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  111. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  112. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  114. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  115. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  116. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  117. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +1 -1
  118. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  119. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  120. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  121. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  122. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.dbg.json +4 -0
  123. package/artifacts/contracts/test/TestDistribution.sol/TestDistribution.json +405 -0
  124. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  125. package/artifacts/contracts/test/TestFee.sol/TestFee.json +2 -2
  126. package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +1 -1
  127. package/artifacts/contracts/test/TestPool.sol/TestPool.json +194 -3
  128. package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +1 -1
  129. package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +209 -27
  130. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  131. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  132. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  133. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +38 -4
  134. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  135. package/artifacts/contracts/test/TestService.sol/TestService.json +2 -2
  136. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  137. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  138. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  139. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  140. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  141. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  143. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  144. package/artifacts/contracts/types/Fee.sol/FeeLib.json +50 -11
  145. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  146. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  147. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  148. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  149. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  150. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  151. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  153. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.dbg.json +4 -0
  154. package/artifacts/contracts/types/ReferralId.sol/ReferralIdLib.json +99 -0
  155. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  156. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  157. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +4 -0
  158. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +30 -0
  159. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  160. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  161. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
  162. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  164. package/contracts/components/BaseComponent.sol +7 -1
  165. package/contracts/components/Distribution.sol +132 -0
  166. package/contracts/components/IDistributionComponent.sol +48 -0
  167. package/contracts/components/IPoolComponent.sol +14 -0
  168. package/contracts/components/IProductComponent.sol +24 -5
  169. package/contracts/components/Pool.sol +64 -3
  170. package/contracts/components/Product.sol +123 -13
  171. package/contracts/instance/IInstance.sol +7 -6
  172. package/contracts/instance/Instance.sol +12 -6
  173. package/contracts/instance/base/IInstanceBase.sol +8 -0
  174. package/contracts/instance/base/IKeyValueStore.sol +4 -3
  175. package/contracts/instance/base/InstanceBase.sol +13 -2
  176. package/contracts/instance/base/KeyValueStore.sol +12 -7
  177. package/contracts/instance/base/Lifecycle.sol +15 -10
  178. package/contracts/instance/base/ModuleBase.sol +22 -17
  179. package/contracts/instance/module/access/Access.sol +6 -6
  180. package/contracts/instance/module/bundle/BundleModule.sol +10 -12
  181. package/contracts/instance/module/bundle/IBundle.sol +6 -11
  182. package/contracts/instance/module/component/ComponentModule.sol +29 -54
  183. package/contracts/instance/module/component/IComponent.sol +5 -30
  184. package/contracts/instance/module/distribution/DistributionModule.sol +17 -0
  185. package/contracts/instance/module/distribution/IDistribution.sol +10 -0
  186. package/contracts/instance/module/policy/IPolicy.sol +12 -9
  187. package/contracts/instance/module/policy/PolicyModule.sol +35 -20
  188. package/contracts/instance/module/pool/IPoolModule.sol +0 -1
  189. package/contracts/instance/module/pool/PoolModule.sol +12 -9
  190. package/contracts/instance/module/risk/IRisk.sol +18 -2
  191. package/contracts/instance/module/risk/RiskModule.sol +56 -2
  192. package/contracts/instance/module/treasury/ITreasury.sol +29 -50
  193. package/contracts/instance/module/treasury/TreasuryModule.sol +71 -85
  194. package/contracts/instance/service/ComponentOwnerService.sol +29 -42
  195. package/contracts/instance/service/DistributionService.sol +59 -0
  196. package/contracts/instance/service/IDistributionService.sol +12 -0
  197. package/contracts/instance/service/IPoolService.sol +7 -0
  198. package/contracts/instance/service/IProductService.sol +56 -7
  199. package/contracts/instance/service/PoolService.sol +30 -4
  200. package/contracts/instance/service/ProductService.sol +230 -75
  201. package/contracts/registry/Registry.sol +3 -2
  202. package/contracts/test/TestDistribution.sol +21 -0
  203. package/contracts/test/TestPool.sol +5 -2
  204. package/contracts/test/TestProduct.sol +35 -7
  205. package/contracts/test/TestRoleId.sol +2 -2
  206. package/contracts/types/Fee.sol +8 -3
  207. package/contracts/types/ObjectType.sol +24 -8
  208. package/contracts/types/ReferralId.sol +48 -0
  209. package/contracts/types/RiskId.sol +43 -0
  210. package/contracts/types/RoleId.sol +12 -10
  211. package/package.json +1 -1
  212. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.dbg.json +0 -4
  213. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.json +0 -10
  214. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensation.dbg.json +0 -4
  215. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensationModule.dbg.json +0 -4
  216. package/contracts/instance/module/compensation/CompensationModule.sol +0 -8
  217. package/contracts/instance/module/compensation/ICompensation.sol +0 -10
@@ -0,0 +1,132 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {ObjectType, DISTRIBUTION} from "../types/ObjectType.sol";
5
+ import {IDistributionService} from "../instance/service/IDistributionService.sol";
6
+ import {IProductService} from "../instance/service/IProductService.sol";
7
+ import {NftId} from "../types/NftId.sol";
8
+ import {ReferralId} from "../types/ReferralId.sol";
9
+ import {Fee, FeeLib} from "../types/Fee.sol";
10
+ import {BaseComponent} from "./BaseComponent.sol";
11
+ import {IDistributionComponent} from "./IDistributionComponent.sol";
12
+
13
+ contract Distribution is
14
+ BaseComponent,
15
+ IDistributionComponent
16
+ {
17
+
18
+ Fee internal _initialDistributionFee;
19
+ bool internal _isVerifying;
20
+
21
+ IDistributionService private _distributionService;
22
+ IProductService private _productService;
23
+
24
+ modifier onlyProductService() {
25
+ require(
26
+ msg.sender == address(_productService),
27
+ "ERROR:POL-002:NOT_PRODUCT_SERVICE");
28
+ _;
29
+ }
30
+
31
+ constructor(
32
+ address registry,
33
+ NftId instanceNftId,
34
+ // TODO refactor into tokenNftId
35
+ address token,
36
+ bool verifying,
37
+ Fee memory distributionFee
38
+ )
39
+ BaseComponent(registry, instanceNftId, token)
40
+ {
41
+ _isVerifying = verifying;
42
+ _initialDistributionFee = distributionFee;
43
+
44
+ _distributionService = _instance.getDistributionService();
45
+ _productService = _instance.getProductService();
46
+ }
47
+
48
+
49
+ function setFees(
50
+ Fee memory distributionFee
51
+ )
52
+ external
53
+ override
54
+ {
55
+ _distributionService.setFees(distributionFee);
56
+ }
57
+
58
+ function calculateFeeAmount(
59
+ ReferralId referralId,
60
+ uint256 netPremiumAmount
61
+ )
62
+ external
63
+ view
64
+ virtual override
65
+ returns (uint256 feeAmount)
66
+ {
67
+ Fee memory fee = getDistributionFee();
68
+ (feeAmount,) = FeeLib.calculateFee(fee, netPremiumAmount);
69
+ }
70
+
71
+
72
+ function calculateRenewalFeeAmount(
73
+ ReferralId referralId,
74
+ uint256 netPremiumAmount
75
+ )
76
+ external
77
+ view
78
+ virtual override
79
+ returns (uint256 feeAmount)
80
+ {
81
+ // default is no fees
82
+ return 0 * netPremiumAmount;
83
+ }
84
+
85
+ function processSale(
86
+ ReferralId referralId,
87
+ uint256 feeAmount
88
+ )
89
+ external
90
+ onlyProductService
91
+ virtual override
92
+ {
93
+ // default is no action
94
+ }
95
+
96
+ function processRenewal(
97
+ ReferralId referralId,
98
+ uint256 feeAmount
99
+ )
100
+ external
101
+ onlyProductService
102
+ virtual override
103
+ {
104
+ // default is no action
105
+ }
106
+
107
+ function referralIsValid(ReferralId referralId) external view returns (bool isValid) {
108
+ // default is invalid
109
+ return false;
110
+ }
111
+
112
+ /// @dev default distribution fee, ie when not using any valid referralId
113
+ function getDistributionFee() public view returns (Fee memory distributionFee) {
114
+ NftId productNftId = _instance.getProductNftId(getNftId());
115
+ if (_instance.hasTreasuryInfo(productNftId)) {
116
+ return _instance.getTreasuryInfo(productNftId).distributionFee;
117
+ } else {
118
+ return _initialDistributionFee;
119
+ }
120
+ }
121
+
122
+
123
+ /// @dev returns true iff the component needs to be called when selling/renewing policis
124
+ function isVerifying() external view returns (bool verifying) {
125
+ return _isVerifying;
126
+ }
127
+
128
+ // from registerable
129
+ function getType() public pure override returns (ObjectType) {
130
+ return DISTRIBUTION();
131
+ }
132
+ }
@@ -0,0 +1,48 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {Fee} from "../types/Fee.sol";
5
+ import {NftId} from "../types/NftId.sol";
6
+ import {ReferralId} from "../types/ReferralId.sol";
7
+
8
+ import {IBaseComponent} from "./IBaseComponent.sol";
9
+
10
+ interface IDistributionComponent is IBaseComponent {
11
+
12
+ function setFees(
13
+ Fee memory distributionFee
14
+ ) external;
15
+
16
+ function calculateFeeAmount(
17
+ ReferralId referralId,
18
+ uint256 netPremiumAmount
19
+ ) external view returns (uint256 feeAmount);
20
+
21
+ function calculateRenewalFeeAmount(
22
+ ReferralId referralId,
23
+ uint256 netPremiumAmount
24
+ ) external view returns (uint256 feeAmount);
25
+
26
+ /// @dev callback from product service when selling a policy for a specific referralId
27
+ /// the used referral id and the collected fee are provided as parameters
28
+ /// the component implementation can then process this information accordingly
29
+ function processSale(
30
+ ReferralId referralId,
31
+ uint256 feeAmount
32
+ ) external;
33
+
34
+ /// @dev callback from product service when a policy is renews for a specific referralId
35
+ function processRenewal(
36
+ ReferralId referralId,
37
+ uint256 feeAmount
38
+ ) external;
39
+
40
+ /// @dev returns true iff the referral id is valid
41
+ function referralIsValid(ReferralId referralId) external view returns (bool isValid);
42
+
43
+ /// @dev default distribution fee, ie when not using any valid referralId
44
+ function getDistributionFee() external view returns (Fee memory distributionFee);
45
+
46
+ /// @dev returns true iff the component needs to be called when selling/renewing policis
47
+ function isVerifying() external view returns (bool verifying);
48
+ }
@@ -10,15 +10,27 @@ interface IPoolComponent is IBaseComponent {
10
10
 
11
11
  event LogUnderwrittenByPool(NftId policyNftId, uint256 collateralizationAmount, address pool);
12
12
 
13
+ function setFees(
14
+ Fee memory poolFee,
15
+ Fee memory stakingFee,
16
+ Fee memory performanceFee
17
+ ) external;
18
+
13
19
  /**
14
20
  * @dev creates a new bundle for this pool.
15
21
  */
16
22
  function createBundle(
23
+ Fee memory fee,
17
24
  uint256 initialAmount,
18
25
  uint256 lifetime,
19
26
  bytes memory filter
20
27
  ) external returns(NftId bundleNftId);
21
28
 
29
+ function setBundleFee(
30
+ NftId policyNftId,
31
+ Fee memory fee
32
+ ) external;
33
+
22
34
  /**
23
35
  * @dev this is a callback function that is called by the product service when underwriting a policy.
24
36
  * the pool has the option to check the details and object to underwriting by reverting.
@@ -48,6 +60,8 @@ interface IPoolComponent is IBaseComponent {
48
60
 
49
61
  function getCollateralizationLevel() external view returns (UFixed collateralizationLevel);
50
62
 
63
+ function getPoolFee() external view returns (Fee memory poolFee);
64
+
51
65
  function getStakingFee() external view returns (Fee memory stakingFee);
52
66
 
53
67
  function getPerformanceFee()
@@ -1,19 +1,38 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- import {NftId} from "../types/NftId.sol";
5
4
  import {Fee} from "../types/Fee.sol";
5
+ import {NftId} from "../types/NftId.sol";
6
+ import {ReferralId} from "../types/ReferralId.sol";
7
+ import {RiskId} from "../types/RiskId.sol";
8
+
6
9
  import {IBaseComponent} from "./IBaseComponent.sol";
7
10
 
8
11
  interface IProductComponent is IBaseComponent {
9
12
  function setFees(
10
- Fee memory policyFee,
13
+ Fee memory productFee,
11
14
  Fee memory processingFee
12
15
  ) external;
13
16
 
14
- function getPoolNftId() external view returns (NftId poolNftId);
15
-
16
- function getPolicyFee() external view returns (Fee memory policyFee);
17
+ function calculatePremium(
18
+ uint256 sumInsuredAmount,
19
+ RiskId riskId,
20
+ uint256 lifetime,
21
+ bytes memory applicationData,
22
+ ReferralId referralId,
23
+ NftId bundleNftId
24
+ ) external view returns (uint256 premiumAmount);
17
25
 
26
+ function calculateNetPremium(
27
+ uint256 sumInsuredAmount,
28
+ RiskId riskId,
29
+ uint256 lifetime,
30
+ bytes memory applicationData
31
+ ) external view returns (uint256 netPremiumAmount);
32
+
33
+ function getProductFee() external view returns (Fee memory productFee);
18
34
  function getProcessingFee() external view returns (Fee memory processingFee);
35
+
36
+ function getPoolNftId() external view returns (NftId poolNftId);
37
+ function getDistributionNftId() external view returns (NftId distributionNftId);
19
38
  }
@@ -15,6 +15,10 @@ contract Pool is BaseComponent, IPoolComponent {
15
15
  bool internal _isVerifying;
16
16
  UFixed internal _collateralizationLevel;
17
17
 
18
+ Fee internal _initialPoolFee;
19
+ Fee internal _initialStakingFee;
20
+ Fee internal _initialPerformanceFee;
21
+
18
22
  // may be used to interact with instance by derived contracts
19
23
  IPoolService internal _poolService;
20
24
 
@@ -41,19 +45,38 @@ contract Pool is BaseComponent, IPoolComponent {
41
45
  // TODO refactor into tokenNftId
42
46
  address token,
43
47
  bool verifying,
44
- UFixed collateralizationLevel
48
+ UFixed collateralizationLevel,
49
+ Fee memory poolFee,
50
+ Fee memory stakingFee,
51
+ Fee memory performanceFee
45
52
  )
46
53
  BaseComponent(registry, instanceNftId, token)
47
54
  {
48
55
  _isVerifying = verifying;
49
56
  // TODO add validation
50
57
  _collateralizationLevel = collateralizationLevel;
58
+ _initialPoolFee = poolFee;
59
+ _initialStakingFee = stakingFee;
60
+ _initialPerformanceFee = performanceFee;
51
61
 
52
62
  _poolService = _instance.getPoolService();
53
63
  _productService = _instance.getProductService();
54
64
  }
55
65
 
66
+ function setFees(
67
+ Fee memory poolFee,
68
+ Fee memory stakingFee,
69
+ Fee memory performanceFee
70
+ )
71
+ external
72
+ onlyOwner
73
+ override
74
+ {
75
+ _poolService.setFees(poolFee, stakingFee, performanceFee);
76
+ }
77
+
56
78
  function createBundle(
79
+ Fee memory fee,
57
80
  uint256 initialAmount,
58
81
  uint256 lifetime,
59
82
  bytes memory filter
@@ -65,6 +88,7 @@ contract Pool is BaseComponent, IPoolComponent {
65
88
  address owner = msg.sender;
66
89
  bundleNftId = _poolService.createBundle(
67
90
  owner,
91
+ fee,
68
92
  initialAmount,
69
93
  lifetime,
70
94
  filter
@@ -73,6 +97,17 @@ contract Pool is BaseComponent, IPoolComponent {
73
97
  // TODO add logging
74
98
  }
75
99
 
100
+ function setBundleFee(
101
+ NftId bundleNftId,
102
+ Fee memory fee
103
+ )
104
+ external
105
+ override
106
+ // TODO add onlyBundleOwner
107
+ {
108
+ _poolService.setBundleFee(bundleNftId, fee);
109
+ }
110
+
76
111
  /**
77
112
  * @dev see {IPool.underwrite}.
78
113
  * Default implementation that only writes a {LogUnderwrittenByPool} entry.
@@ -133,6 +168,7 @@ contract Pool is BaseComponent, IPoolComponent {
133
168
 
134
169
  function _createBundle(
135
170
  address bundleOwner,
171
+ Fee memory fee,
136
172
  uint256 amount,
137
173
  uint256 lifetime,
138
174
  bytes calldata filter
@@ -142,6 +178,7 @@ contract Pool is BaseComponent, IPoolComponent {
142
178
  {
143
179
  bundleNftId = _poolService.createBundle(
144
180
  bundleOwner,
181
+ fee,
145
182
  amount,
146
183
  lifetime,
147
184
  filter
@@ -149,13 +186,32 @@ contract Pool is BaseComponent, IPoolComponent {
149
186
  }
150
187
 
151
188
  // from pool component
189
+ function getPoolFee()
190
+ external
191
+ view
192
+ override
193
+ returns (Fee memory poolFee)
194
+ {
195
+ NftId productNftId = _instance.getProductNftId(getNftId());
196
+ if (_instance.hasTreasuryInfo(productNftId)) {
197
+ return _instance.getTreasuryInfo(productNftId).poolFee;
198
+ } else {
199
+ return _initialPoolFee;
200
+ }
201
+ }
202
+
152
203
  function getStakingFee()
153
204
  external
154
205
  view
155
206
  override
156
207
  returns (Fee memory stakingFee)
157
208
  {
158
- return _instance.getPoolSetup(getNftId()).stakingFee;
209
+ NftId productNftId = _instance.getProductNftId(getNftId());
210
+ if (_instance.hasTreasuryInfo(productNftId)) {
211
+ return _instance.getTreasuryInfo(productNftId).stakingFee;
212
+ } else {
213
+ return _initialStakingFee;
214
+ }
159
215
  }
160
216
 
161
217
  function getPerformanceFee()
@@ -164,7 +220,12 @@ contract Pool is BaseComponent, IPoolComponent {
164
220
  override
165
221
  returns (Fee memory performanceFee)
166
222
  {
167
- return _instance.getPoolSetup(getNftId()).performanceFee;
223
+ NftId productNftId = _instance.getProductNftId(getNftId());
224
+ if (_instance.hasTreasuryInfo(productNftId)) {
225
+ return _instance.getTreasuryInfo(productNftId).performanceFee;
226
+ } else {
227
+ return _initialPerformanceFee;
228
+ }
168
229
  }
169
230
 
170
231
  // from registerable
@@ -1,42 +1,138 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IRisk} from "../instance/module/risk/IRisk.sol";
5
+ import {ITreasury} from "../instance/module/treasury/ITreasury.sol";
4
6
  import {IProductService} from "../instance/service/IProductService.sol";
5
7
  import {IProductComponent} from "./IProductComponent.sol";
6
8
  import {NftId} from "../types/NftId.sol";
7
9
  import {ObjectType, PRODUCT} from "../types/ObjectType.sol";
10
+ import {ReferralId} from "../types/ReferralId.sol";
11
+ import {RiskId, RiskIdLib} from "../types/RiskId.sol";
12
+ import {StateId} from "../types/StateId.sol";
8
13
  import {Timestamp} from "../types/Timestamp.sol";
9
14
  import {Fee} from "../types/Fee.sol";
10
15
  import {BaseComponent} from "./BaseComponent.sol";
11
16
 
12
17
  contract Product is BaseComponent, IProductComponent {
13
- IProductService private _productService;
14
- address private _pool;
18
+ IProductService internal _productService;
19
+ address internal _pool;
20
+ address internal _distribution;
21
+ Fee internal _initialProductFee;
22
+ Fee internal _initialProcessingFee;
15
23
 
16
24
  constructor(
17
25
  address registry,
18
26
  NftId instanceNftid,
19
27
  address token,
20
- address pool
28
+ address pool,
29
+ address distribution,
30
+ Fee memory productFee,
31
+ Fee memory processingFee
21
32
  ) BaseComponent(registry, instanceNftid, token) {
22
33
  // TODO add validation
23
34
  _productService = _instance.getProductService();
24
35
  _pool = pool;
36
+ _distribution = distribution;
37
+ _initialProductFee = productFee;
38
+ _initialProcessingFee = processingFee;
39
+ }
40
+
41
+
42
+ function calculatePremium(
43
+ uint256 sumInsuredAmount,
44
+ RiskId riskId,
45
+ uint256 lifetime,
46
+ bytes memory applicationData,
47
+ ReferralId referralId,
48
+ NftId bundleNftId
49
+ )
50
+ external
51
+ view
52
+ override
53
+ returns (uint256 premiumAmount)
54
+ {
55
+ (premiumAmount,,,,) = _productService.calculatePremium(
56
+ riskId,
57
+ sumInsuredAmount,
58
+ lifetime,
59
+ applicationData,
60
+ bundleNftId,
61
+ referralId
62
+ );
63
+ }
64
+
65
+
66
+ function calculateNetPremium(
67
+ uint256 sumInsuredAmount,
68
+ RiskId riskId,
69
+ uint256 lifetime,
70
+ bytes memory applicationData
71
+ )
72
+ external
73
+ view
74
+ override
75
+ returns (uint256 netPremiumAmount)
76
+ {
77
+ // default 10% of sum insured
78
+ return sumInsuredAmount / 10;
79
+ }
80
+
81
+ function _toRiskId(string memory riskName) internal pure returns (RiskId riskId) {
82
+ return RiskIdLib.toRiskId(riskName);
83
+ }
84
+
85
+ function _createRisk(
86
+ RiskId id,
87
+ bytes memory data
88
+ ) internal {
89
+ _productService.createRisk(
90
+ id,
91
+ data
92
+ );
93
+ }
94
+
95
+ function _setRiskInfo(
96
+ RiskId id,
97
+ IRisk.RiskInfo memory info
98
+ ) internal {
99
+ _productService.setRiskInfo(
100
+ id,
101
+ info
102
+ );
103
+ }
104
+
105
+ function _updateRiskState(
106
+ RiskId id,
107
+ StateId state
108
+ ) internal {
109
+ _productService.updateRiskState(
110
+ id,
111
+ state
112
+ );
113
+ }
114
+
115
+ function _getRiskInfo(RiskId id) internal view returns (IRisk.RiskInfo memory info) {
116
+ return _instance.getRiskInfo(id);
25
117
  }
26
118
 
27
119
  function _createApplication(
28
120
  address applicationOwner,
121
+ RiskId riskId,
29
122
  uint256 sumInsuredAmount,
30
- uint256 premiumAmount,
31
123
  uint256 lifetime,
32
- NftId bundleNftId
124
+ bytes memory applicationData,
125
+ NftId bundleNftId,
126
+ ReferralId referralId
33
127
  ) internal returns (NftId nftId) {
34
128
  nftId = _productService.createApplication(
35
129
  applicationOwner,
130
+ riskId,
36
131
  sumInsuredAmount,
37
- premiumAmount,
38
132
  lifetime,
39
- bundleNftId
133
+ applicationData,
134
+ bundleNftId,
135
+ referralId
40
136
  );
41
137
  }
42
138
 
@@ -79,26 +175,35 @@ contract Product is BaseComponent, IProductComponent {
79
175
  return _registry.getNftId(_pool);
80
176
  }
81
177
 
178
+ function getDistributionNftId() external view override returns (NftId distributionNftId) {
179
+ return _registry.getNftId(_distribution);
180
+ }
181
+
82
182
  // from product component
83
183
  function setFees(
84
- Fee memory policyFee,
184
+ Fee memory productFee,
85
185
  Fee memory processingFee
86
186
  )
87
187
  external
88
188
  onlyOwner
89
189
  override
90
190
  {
91
- _productService.setFees(policyFee, processingFee);
191
+ _productService.setFees(productFee, processingFee);
92
192
  }
93
193
 
94
194
 
95
- function getPolicyFee()
195
+ function getProductFee()
96
196
  external
97
197
  view
98
198
  override
99
- returns (Fee memory policyFee)
199
+ returns (Fee memory productFee)
100
200
  {
101
- return _instance.getProductSetup(getNftId()).policyFee;
201
+ NftId productNftId = getNftId();
202
+ if (_instance.hasTreasuryInfo(productNftId)) {
203
+ return _instance.getTreasuryInfo(productNftId).productFee;
204
+ } else {
205
+ return _initialProductFee;
206
+ }
102
207
  }
103
208
 
104
209
  function getProcessingFee()
@@ -107,7 +212,12 @@ contract Product is BaseComponent, IProductComponent {
107
212
  override
108
213
  returns (Fee memory processingFee)
109
214
  {
110
- return _instance.getProductSetup(getNftId()).processingFee;
215
+ NftId productNftId = getNftId();
216
+ if (_instance.hasTreasuryInfo(productNftId)) {
217
+ return _instance.getTreasuryInfo(productNftId).processingFee;
218
+ } else {
219
+ return _initialProcessingFee;
220
+ }
111
221
  }
112
222
 
113
223
  // from registerable
@@ -10,7 +10,7 @@ import {RoleId} from "../types/RoleId.sol";
10
10
 
11
11
  import {IAccessModule} from "./module/access/IAccess.sol";
12
12
  import {IBundleModule} from "./module/bundle/IBundle.sol";
13
- import {ICompensationModule} from "./module/compensation/ICompensation.sol";
13
+ import {IDistributionModule} from "./module/distribution/IDistribution.sol";
14
14
  import {IComponentModule} from "./module/component/IComponent.sol";
15
15
  import {IPolicyModule} from "./module/policy/IPolicy.sol";
16
16
  import {IPoolModule} from "./module/pool/IPoolModule.sol";
@@ -21,6 +21,7 @@ import {IKeyValueStore} from "./base/IKeyValueStore.sol";
21
21
  import {IRegistry, IRegistryLinked} from "../registry/IRegistryLinked.sol";
22
22
 
23
23
  import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
24
+ import {IDistributionService} from "./service/IDistributionService.sol";
24
25
  import {IProductService} from "./service/IProductService.sol";
25
26
  import {IPoolService} from "./service/IPoolService.sol";
26
27
  import {IInstanceBase} from "./base/IInstanceBase.sol";
@@ -33,19 +34,19 @@ interface IInstance is
33
34
  IAccessModule,
34
35
  IPolicyModule,
35
36
  IPoolModule,
37
+ IRiskModule,
36
38
  IBundleModule,
37
39
  IComponentModule,
38
40
  ITreasuryModule,
39
- ICompensationModule,
41
+ IDistributionModule,
40
42
  IInstanceBase
41
43
  {
42
- function getRegistry() external view override (IBundleModule, IComponentModule, IPolicyModule, IRegisterable) returns (IRegistry registry);
44
+ function getRegistry() external view override (IPolicyModule, IRegisterable) returns (IRegistry registry);
43
45
  function getOwner() external view override (IOwnable, IAccessModule) returns(address owner);
44
46
 
45
- function hasRole(RoleId role, address member) external view override (IAccessModule, IComponentModule) returns (bool hasRole);
46
-
47
- function getKeyValueStore() external view override (IBundleModule, IInstanceBase) returns (IKeyValueStore keyValueStore);
47
+ function getKeyValueStore() external view override (IInstanceBase) returns (IKeyValueStore keyValueStore);
48
48
  function getComponentOwnerService() external view override (IInstanceBase, IComponentModule) returns(IComponentOwnerService);
49
+ function getDistributionService() external view override returns(IDistributionService);
49
50
  function getProductService() external view override (IInstanceBase, IBundleModule, IPolicyModule) returns(IProductService);
50
51
  function getPoolService() external view override (IInstanceBase, IBundleModule, IPoolModule) returns(IPoolService);
51
52