@etherisc/gif-next 0.0.2-eb98db7-932 → 0.0.2-ebf1a6b-485

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 (197) hide show
  1. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  2. package/artifacts/contracts/components/Component.sol/Component.json +10 -89
  3. package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
  4. package/artifacts/contracts/components/Distribution.sol/Distribution.json +67 -134
  5. package/artifacts/contracts/components/IComponent.sol/IComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/IComponent.sol/IComponent.json +7 -73
  7. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
  8. package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.json +46 -117
  9. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  10. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.json +238 -96
  11. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  12. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.json +11 -145
  13. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  14. package/artifacts/contracts/components/Pool.sol/Pool.json +241 -112
  15. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  16. package/artifacts/contracts/components/Product.sol/Product.json +15 -162
  17. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
  18. package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +2 -2
  19. package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
  20. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  21. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +84 -146
  22. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
  23. package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +11 -0
  24. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  25. package/artifacts/contracts/instance/Instance.sol/Instance.json +149 -211
  26. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
  27. package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +2 -2
  28. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
  29. package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +79 -110
  30. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
  31. package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +44 -33
  32. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
  33. package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +17 -17
  34. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
  35. package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +2 -2
  36. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.dbg.json +1 -1
  37. package/artifacts/contracts/instance/base/ComponentService.sol/ComponentService.json +12 -1
  38. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  39. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  40. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +2 -2
  42. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  43. package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
  44. package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
  45. package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
  46. package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
  47. package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
  48. package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
  49. package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
  50. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.dbg.json +1 -1
  51. package/artifacts/contracts/instance/service/ApplicationService.sol/ApplicationService.json +172 -62
  52. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.dbg.json +1 -1
  53. package/artifacts/contracts/instance/service/ApplicationServiceManager.sol/ApplicationServiceManager.json +33 -25
  54. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.dbg.json +1 -1
  55. package/artifacts/contracts/instance/service/BundleService.sol/BundleService.json +34 -23
  56. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.dbg.json +1 -1
  57. package/artifacts/contracts/instance/service/BundleServiceManager.sol/BundleServiceManager.json +9 -9
  58. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.dbg.json +1 -1
  59. package/artifacts/contracts/instance/service/ClaimService.sol/ClaimService.json +14 -3
  60. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.dbg.json +1 -1
  61. package/artifacts/contracts/instance/service/ClaimServiceManager.sol/ClaimServiceManager.json +2 -2
  62. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.dbg.json +1 -1
  63. package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +535 -69
  64. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
  65. package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.json +96 -32
  66. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.dbg.json +1 -1
  67. package/artifacts/contracts/instance/service/IApplicationService.sol/IApplicationService.json +121 -27
  68. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.dbg.json +1 -1
  69. package/artifacts/contracts/instance/service/IBundleService.sol/IBundleService.json +17 -6
  70. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.dbg.json +1 -1
  71. package/artifacts/contracts/instance/service/IClaimService.sol/IClaimService.json +11 -0
  72. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
  73. package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.json +344 -6
  74. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.dbg.json +1 -1
  75. package/artifacts/contracts/instance/service/IPolicyService.sol/IPolicyService.json +11 -64
  76. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  77. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +11 -0
  78. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  79. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +11 -0
  80. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/service/PolicyService.sol/PolicyService.json +48 -157
  82. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.dbg.json +1 -1
  83. package/artifacts/contracts/instance/service/PolicyServiceManager.sol/PolicyServiceManager.json +19 -47
  84. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  85. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +22 -11
  86. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
  87. package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +6 -6
  88. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  89. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +14 -3
  90. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +2 -2
  92. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  93. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  94. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
  95. package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.json +11 -0
  96. package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
  97. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  98. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  99. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.dbg.json +1 -1
  100. package/artifacts/contracts/registry/RegistryAccessManager.sol/RegistryAccessManager.json +2 -2
  101. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
  102. package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +24 -13
  103. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
  104. package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +7 -7
  105. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.dbg.json +1 -1
  106. package/artifacts/contracts/registry/ReleaseManager.sol/ReleaseManager.json +2 -2
  107. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
  108. package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.json +2 -2
  109. package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
  110. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  111. package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
  112. package/artifacts/contracts/shared/IPolicyHolder.sol/IPolicyHolder.dbg.json +1 -1
  113. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  114. package/artifacts/contracts/shared/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  115. package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
  116. package/artifacts/contracts/shared/IService.sol/IService.json +11 -0
  117. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  118. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
  119. package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
  120. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.dbg.json +1 -1
  121. package/artifacts/contracts/shared/PolicyHolder.sol/PolicyHolder.json +2 -2
  122. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
  123. package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
  124. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  125. package/artifacts/contracts/shared/Registerable.sol/Registerable.json +3 -3
  126. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.dbg.json +1 -1
  127. package/artifacts/contracts/shared/RegistryLinked.sol/RegistryLinked.json +2 -2
  128. package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
  129. package/artifacts/contracts/shared/Service.sol/Service.json +12 -1
  130. package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  131. package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
  132. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  133. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  134. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  135. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +3 -3
  136. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  137. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.json +2 -2
  138. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  139. package/artifacts/contracts/test/TestService.sol/TestService.json +14 -3
  140. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  141. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  142. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  143. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  144. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  145. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  146. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  147. package/artifacts/contracts/types/ClaimId.sol/ClaimIdLib.dbg.json +1 -1
  148. package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
  149. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  150. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  151. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  152. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  153. package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
  154. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  155. package/artifacts/contracts/types/PayoutId.sol/PayoutIdLib.dbg.json +1 -1
  156. package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
  157. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
  158. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  159. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +2 -2
  160. package/artifacts/contracts/types/Seconds.sol/SecondsLib.dbg.json +4 -0
  161. package/artifacts/contracts/types/Seconds.sol/SecondsLib.json +124 -0
  162. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  163. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  164. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +25 -7
  165. package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
  166. package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
  167. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  168. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  169. package/contracts/components/Component.sol +68 -88
  170. package/contracts/components/Distribution.sol +12 -6
  171. package/contracts/components/IComponent.sol +31 -17
  172. package/contracts/components/IDistributionComponent.sol +1 -14
  173. package/contracts/components/IPoolComponent.sol +89 -25
  174. package/contracts/components/IProductComponent.sol +3 -2
  175. package/contracts/components/Pool.sol +216 -92
  176. package/contracts/components/Product.sol +24 -20
  177. package/contracts/instance/BundleManager.sol +1 -1
  178. package/contracts/instance/InstanceService.sol +15 -1
  179. package/contracts/instance/module/IBundle.sol +2 -1
  180. package/contracts/instance/module/IDistribution.sol +2 -1
  181. package/contracts/instance/module/IPolicy.sol +26 -1
  182. package/contracts/instance/module/ISetup.sol +5 -7
  183. package/contracts/instance/service/ApplicationService.sol +121 -40
  184. package/contracts/instance/service/BundleService.sol +4 -3
  185. package/contracts/instance/service/DistributionService.sol +91 -43
  186. package/contracts/instance/service/IApplicationService.sol +7 -7
  187. package/contracts/instance/service/IBundleService.sol +3 -2
  188. package/contracts/instance/service/IDistributionService.sol +15 -2
  189. package/contracts/instance/service/IPolicyService.sol +1 -20
  190. package/contracts/instance/service/PolicyService.sol +31 -105
  191. package/contracts/registry/RegistryService.sol +5 -5
  192. package/contracts/shared/IService.sol +2 -0
  193. package/contracts/shared/Registerable.sol +2 -2
  194. package/contracts/types/RoleId.sol +7 -2
  195. package/contracts/types/Seconds.sol +54 -0
  196. package/contracts/types/Timestamp.sol +12 -13
  197. package/package.json +1 -1
@@ -6,6 +6,7 @@ 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";
@@ -90,16 +91,22 @@ contract DistributionService is
90
91
  }
91
92
 
92
93
  function setFees(
94
+ Fee memory minDistributionOwnerFee,
93
95
  Fee memory distributionFee
94
96
  )
95
97
  external
96
98
  override
97
99
  {
100
+ if (minDistributionOwnerFee.fractionalFee > distributionFee.fractionalFee) {
101
+ revert ErrorIDistributionServiceMinFeeTooHigh(minDistributionOwnerFee.fractionalFee.toInt(), distributionFee.fractionalFee.toInt());
102
+ }
103
+
98
104
  (IRegistry.ObjectInfo memory info , IInstance instance) = _getAndVerifyComponentInfoAndInstance(DISTRIBUTION());
99
105
  InstanceReader instanceReader = instance.getInstanceReader();
100
106
  NftId distributionNftId = info.nftId;
101
107
 
102
108
  ISetup.DistributionSetupInfo memory distSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
109
+ distSetupInfo.minDistributionOwnerFee = minDistributionOwnerFee;
103
110
  distSetupInfo.distributionFee = distributionFee;
104
111
 
105
112
  instance.updateDistributionSetup(distributionNftId, distSetupInfo, KEEP_STATE());
@@ -120,12 +127,19 @@ contract DistributionService is
120
127
  returns (DistributorType distributorType)
121
128
  {
122
129
  (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
130
+
131
+ {
132
+ ISetup.DistributionSetupInfo memory setupInfo = instance.getInstanceReader().getDistributionSetupInfo(distributionNftId);
133
+ UFixed variableFeesPartsTotal = setupInfo.minDistributionOwnerFee.fractionalFee.add(commissionPercentage);
134
+ UFixed maxDiscountPercentageLimit = setupInfo.distributionFee.fractionalFee.sub(variableFeesPartsTotal);
135
+ if (maxDiscountPercentage.gt(maxDiscountPercentageLimit)) {
136
+ revert ErrorIDistributionServiceMaxDiscountTooHigh(maxDiscountPercentage.toInt(), maxDiscountPercentageLimit.toInt());
137
+ }
138
+ }
139
+
123
140
  distributorType = DistributorTypeLib.toDistributorType(distributionNftId, name);
124
141
  Key32 key32 = distributorType.toKey32();
125
142
 
126
- // FIXME: commission <= maxDiscountPercentage
127
- // FIXME: maxDiscountPercentage <= distributionFee
128
-
129
143
  if(!instance.exists(key32)) {
130
144
  IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo(
131
145
  name,
@@ -164,7 +178,9 @@ contract DistributionService is
164
178
  IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
165
179
  distributorType,
166
180
  true, // active
167
- data);
181
+ data,
182
+ 0,
183
+ 0);
168
184
 
169
185
  instance.createDistributor(distributorNftId, info);
170
186
  }
@@ -176,13 +192,11 @@ contract DistributionService is
176
192
  ) external virtual
177
193
  {
178
194
  (,, IInstance instance) = _getAndVerifyCallingDistribution();
179
-
180
- IDistribution.DistributorInfo memory info = IDistribution.DistributorInfo(
181
- distributorType,
182
- true, // active
183
- data);
184
-
185
- instance.updateDistributor(distributorNftId, info, KEEP_STATE());
195
+ InstanceReader instanceReader = instance.getInstanceReader();
196
+ IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
197
+ distributorInfo.distributorType = distributorType;
198
+ distributorInfo.data = data;
199
+ instance.updateDistributor(distributorNftId, distributorInfo, KEEP_STATE());
186
200
  }
187
201
 
188
202
 
@@ -199,19 +213,31 @@ contract DistributionService is
199
213
  returns (ReferralId referralId)
200
214
  {
201
215
  (,NftId distributionNftId, IInstance instance) = _getAndVerifyCallingDistribution();
202
- require(bytes(code).length > 0, "ERROR:DSV-030:CODE_INVALID");
203
- require(expiryAt > zeroTimestamp(), "ERROR:DSV-031:EXPIRY_AT_ZERO");
216
+
217
+ if (bytes(code).length == 0) {
218
+ revert ErrorIDistributionServiceInvalidReferral(code);
219
+ }
220
+ if (expiryAt.eqz()) {
221
+ revert ErrorIDistributionServiceExpirationInvalid(expiryAt);
222
+ }
204
223
 
205
224
  InstanceReader instanceReader = instance.getInstanceReader();
206
- IDistribution.DistributorInfo memory distributorTypeInfo = instanceReader.getDistributorInfo(distributorNftId);
207
- DistributorType distributorType = distributorTypeInfo.distributorType;
225
+ IDistribution.DistributorInfo memory distributorInfo = instanceReader.getDistributorInfo(distributorNftId);
226
+ DistributorType distributorType = distributorInfo.distributorType;
208
227
  IDistribution.DistributorTypeInfo memory distributorTypeData = instanceReader.getDistributorTypeInfo(distributorType);
209
228
 
210
- // FIXME: no require
211
- require(distributorTypeData.maxReferralCount >= maxReferrals, "ERROR:DSV-032:MAX_REFERRALS_EXCEEDED");
212
- require(distributorTypeData.minDiscountPercentage <= discountPercentage, "ERROR:DSV-033:DISCOUNT_TOO_LOW");
213
- require(distributorTypeData.maxDiscountPercentage >= discountPercentage, "ERROR:DSV-034:DISCOUNT_TOO_HIGH");
214
- require(expiryAt.toInt() - TimestampLib.blockTimestamp().toInt() <= distributorTypeData.maxReferralLifetime, "ERROR:DSV-035:EXPIRY_TOO_LONG");
229
+ if (distributorTypeData.maxReferralCount < maxReferrals) {
230
+ revert ErrorIDistributionServiceMaxReferralsExceeded(distributorTypeData.maxReferralCount);
231
+ }
232
+ if (distributorTypeData.minDiscountPercentage > discountPercentage) {
233
+ revert ErrorIDistributionServiceDiscountTooLow(distributorTypeData.minDiscountPercentage.toInt(), discountPercentage.toInt());
234
+ }
235
+ if (distributorTypeData.maxDiscountPercentage < discountPercentage) {
236
+ revert ErrorIDistributionServiceDiscountTooHigh(distributorTypeData.maxDiscountPercentage.toInt(), discountPercentage.toInt());
237
+ }
238
+ if (expiryAt.toInt() - TimestampLib.blockTimestamp().toInt() > distributorTypeData.maxReferralLifetime) {
239
+ revert ErrorIDistributionServiceExpiryTooLong(distributorTypeData.maxReferralLifetime, expiryAt.toInt());
240
+ }
215
241
 
216
242
  referralId = ReferralLib.toReferralId(distributionNftId, code);
217
243
  IDistribution.ReferralInfo memory info = IDistribution.ReferralInfo(
@@ -248,32 +274,46 @@ contract DistributionService is
248
274
  function calculateFeeAmount(
249
275
  NftId distributionNftId,
250
276
  ReferralId referralId,
251
- uint256 netPremiumAmount
277
+ IPolicy.Premium memory premium
252
278
  )
253
279
  external
254
280
  virtual
255
281
  view
256
- returns (uint256 feeAmount)
282
+ returns (IPolicy.Premium memory finalPremium)
257
283
  {
258
- (address distributionAddress, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
284
+ (, IInstance instance) = _getAndVerifyDistribution(distributionNftId);
259
285
  InstanceReader reader = instance.getInstanceReader();
260
-
261
- // calculate fee based on the distribution components fee
286
+
287
+ // first calculate all fixed and variable fees for the distribution - this will defined the fullPremium
262
288
  ISetup.DistributionSetupInfo memory setupInfo = reader.getDistributionSetupInfo(distributionNftId);
263
- Fee memory fee = setupInfo.distributionFee;
264
- (feeAmount,) = fee.calculateFee(netPremiumAmount);
265
-
266
- if (referralIsValid(distributionNftId, referralId)) {
267
- // (distributionFee(fixed + pct) - referralDiscount(pct)) ... discount <= distributionFee
268
- IDistribution.ReferralInfo memory info = reader.getReferralInfo(referralId);
269
- uint256 discountAmount = UFixedLib.toUFixed(netPremiumAmount).mul(info.discountPercentage).toInt();
270
- if (discountAmount > feeAmount) {
271
- feeAmount = 0;
272
- } else {
273
- feeAmount -= discountAmount;
274
- }
275
- }
276
- // else - just use distributionFee from component
289
+ Fee memory distributionFee = setupInfo.distributionFee;
290
+ Fee memory minDistributionOwnerFee = setupInfo.minDistributionOwnerFee;
291
+ uint256 distributionFeeVarAmount = (UFixedLib.toUFixed(premium.netPremiumAmount) * distributionFee.fractionalFee).toInt();
292
+ premium.distributionFeeVarAmount = distributionFeeVarAmount;
293
+ premium.fullPremiumAmount += distributionFeeVarAmount;
294
+
295
+ // if the referral is not valid, then the distribution owner gets everything
296
+ if (! referralIsValid(distributionNftId, referralId)) {
297
+ premium.distributionOwnerFeeFixAmount = premium.distributionFeeFixAmount;
298
+ premium.distributionOwnerFeeVarAmount = premium.distributionFeeVarAmount;
299
+ premium.premiumAmount = premium.fullPremiumAmount;
300
+ return premium;
301
+ }
302
+
303
+ // if the referral is valid, the the commission and discount are calculated based in the full premium
304
+ // the remaing amount goes to the distribution owner
305
+ IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId);
306
+ IDistribution.DistributorInfo memory distributorInfo = reader.getDistributorInfo(referralInfo.distributorNftId);
307
+ IDistribution.DistributorTypeInfo memory distributorTypeInfo = reader.getDistributorTypeInfo(distributorInfo.distributorType);
308
+
309
+ uint256 commissionAmount = UFixedLib.toUFixed(premium.netPremiumAmount).mul(distributorTypeInfo.commissionPercentage).toInt();
310
+ premium.commissionAmount = commissionAmount;
311
+ premium.discountAmount = UFixedLib.toUFixed(premium.fullPremiumAmount).mul(referralInfo.discountPercentage).toInt();
312
+ premium.distributionOwnerFeeFixAmount = minDistributionOwnerFee.fixedFee;
313
+ premium.distributionOwnerFeeVarAmount = distributionFeeVarAmount - commissionAmount - premium.discountAmount;
314
+ premium.premiumAmount = premium.fullPremiumAmount - premium.discountAmount;
315
+
316
+ return premium;
277
317
  }
278
318
 
279
319
  function referralIsValid(NftId distributionNftId, ReferralId referralId) public view returns (bool isValid) {
@@ -305,7 +345,9 @@ contract DistributionService is
305
345
  instance
306
346
  ) = _getAndVerifyCaller();
307
347
 
308
- require(objectType == DISTRIBUTION(), "ERROR:PRS-031:CALLER_NOT_DISTRUBUTION");
348
+ if(objectType != DISTRIBUTION()) {
349
+ revert ErrorIDistributionServiceCallerNotDistributor(msg.sender);
350
+ }
309
351
  }
310
352
 
311
353
  function _getAndVerifyDistribution(NftId distributionNftId)
@@ -318,7 +360,9 @@ contract DistributionService is
318
360
  {
319
361
  IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(distributionNftId);
320
362
  IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
321
- require(parentInfo.objectType == INSTANCE(), "ERROR:SRV-031:PARENT_NOT_INSTANCE");
363
+ if (parentInfo.objectType != INSTANCE()) {
364
+ revert ErrorIDistributionServiceParentNftIdNotInstance(distributionNftId, info.parentNftId);
365
+ }
322
366
  instance = IInstance(parentInfo.objectAddress);
323
367
  }
324
368
 
@@ -334,12 +378,16 @@ contract DistributionService is
334
378
  {
335
379
  objectAddress = msg.sender;
336
380
  objectNftId = getRegistry().getNftId(objectAddress);
337
- require(objectNftId.gtz(), "ERROR:SRV-030:CALLER_UNKNOWN");
381
+ if ( objectNftId.eqz()) {
382
+ revert ErrorIServiceCallerUnknown(objectAddress);
383
+ }
338
384
  IRegistry.ObjectInfo memory info = getRegistry().getObjectInfo(objectNftId);
339
385
  objectType = info.objectType;
340
386
 
341
387
  IRegistry.ObjectInfo memory parentInfo = getRegistry().getObjectInfo(info.parentNftId);
342
- require(parentInfo.objectType == INSTANCE(), "ERROR:SRV-031:PARENT_NOT_INSTANCE");
388
+ if (parentInfo.objectType != INSTANCE()) {
389
+ revert ErrorIDistributionServiceParentNftIdNotInstance(objectNftId, info.parentNftId);
390
+ }
343
391
  instance = IInstance(parentInfo.objectAddress);
344
392
  }
345
393
 
@@ -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
  }
@@ -3,10 +3,11 @@ 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 {StateId} from "../../types/StateId.sol";
7
6
  import {IService} from "../../shared/IService.sol";
8
7
  import {IBundle} from "../module/IBundle.sol";
9
8
  import {IInstance} from "../../instance/IInstance.sol";
9
+ import {Seconds} from "../../types/Seconds.sol";
10
+ import {StateId} from "../../types/StateId.sol";
10
11
 
11
12
  interface IBundleService is IService {
12
13
  error ErrorIBundleServiceInsufficientAllowance(address bundleOwner, address tokenHandlerAddress, uint256 amount);
@@ -15,7 +16,7 @@ interface IBundleService is IService {
15
16
  address owner,
16
17
  Fee memory fee,
17
18
  uint256 amount,
18
- uint256 lifetime,
19
+ Seconds lifetime,
19
20
  bytes calldata filter
20
21
  ) external returns(NftId bundleNftId);
21
22
 
@@ -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,9 +12,21 @@ import {Timestamp} from "../../types/Timestamp.sol";
11
12
 
12
13
 
13
14
  interface IDistributionService is IService {
15
+ error ErrorIDistributionServiceParentNftIdNotInstance(NftId nftId, NftId parentNftId);
16
+ error ErrorIDistributionServiceCallerNotDistributor(address caller);
14
17
  error ErrorIDistributionServiceInvalidReferralId(ReferralId referralId);
18
+ error ErrorIDistributionServiceMaxReferralsExceeded(uint256 maxReferrals);
19
+ error ErrorIDistributionServiceDiscountTooLow(uint256 minDiscountPercentage, uint256 discountPercentage);
20
+ error ErrorIDistributionServiceDiscountTooHigh(uint256 maxDiscountPercentage, uint256 discountPercentage);
21
+ error ErrorIDistributionServiceExpiryTooLong(uint256 maxReferralLifetime, uint256 expiryAt);
22
+ error ErrorIDistributionServiceInvalidReferral(string code);
23
+ error ErrorIDistributionServiceExpirationInvalid(Timestamp expiryAt);
24
+ error ErrorIDistributionServiceCommissionTooHigh(uint256 commissionPercentage, uint256 maxCommissionPercentage);
25
+ error ErrorIDistributionServiceMinFeeTooHigh(uint256 minFee, uint256 limit);
26
+ error ErrorIDistributionServiceMaxDiscountTooHigh(uint256 maxDiscountPercentage, uint256 limit);
15
27
 
16
28
  function setFees(
29
+ Fee memory minDistributionOwnerFee,
17
30
  Fee memory distributionFee
18
31
  ) external;
19
32
 
@@ -63,8 +76,8 @@ interface IDistributionService is IService {
63
76
  function calculateFeeAmount(
64
77
  NftId distributionNftId,
65
78
  ReferralId referralId,
66
- uint256 netPremiumAmount
67
- ) external view returns (uint256 feeAmount);
79
+ IPolicy.Premium memory premium
80
+ ) external view returns (IPolicy.Premium memory finalPremium);
68
81
 
69
82
  function referralIsValid(
70
83
  NftId distributorNftId,
@@ -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";
@@ -60,26 +61,6 @@ interface IPolicyService is IService {
60
61
  /// this function can only be called by a product. the policy needs to match with the calling product
61
62
  function close(NftId policyNftId) external;
62
63
 
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
64
  // TODO move function to pool service
84
65
  function calculateRequiredCollateral(
85
66
  UFixed collateralizationLevel,
@@ -19,10 +19,11 @@ import {TokenHandler} from "../../shared/TokenHandler.sol";
19
19
  import {IVersionable} from "../../shared/IVersionable.sol";
20
20
  import {Versionable} from "../../shared/Versionable.sol";
21
21
 
22
+ import {Seconds} from "../../types/Seconds.sol";
22
23
  import {Timestamp, TimestampLib, zeroTimestamp} from "../../types/Timestamp.sol";
23
24
  import {UFixed, UFixedLib} from "../../types/UFixed.sol";
24
25
  import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
25
- import {ObjectType, INSTANCE, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
26
+ import {ObjectType, APPLICATION, INSTANCE, PRODUCT, POOL, POLICY, BUNDLE} from "../../types/ObjectType.sol";
26
27
  import {APPLIED, UNDERWRITTEN, ACTIVE, KEEP_STATE, CLOSED} from "../../types/StateId.sol";
27
28
  import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
28
29
  import {Fee, FeeLib} from "../../types/Fee.sol";
@@ -35,6 +36,7 @@ import {Version, VersionLib} from "../../types/Version.sol";
35
36
  import {IService} from "../../shared/IService.sol";
36
37
  import {Service} from "../../shared/Service.sol";
37
38
  import {ComponentService} from "../base/ComponentService.sol";
39
+ import {IApplicationService} from "./IApplicationService.sol";
38
40
  import {IPolicyService} from "./IPolicyService.sol";
39
41
  import {InstanceReader} from "../InstanceReader.sol";
40
42
  import {IPoolService} from "./IPoolService.sol";
@@ -50,6 +52,7 @@ contract PolicyService is
50
52
 
51
53
  IPoolService internal _poolService;
52
54
  IBundleService internal _bundleService;
55
+ IApplicationService internal _applicationService;
53
56
 
54
57
  event LogProductServiceSender(address sender);
55
58
 
@@ -69,6 +72,7 @@ contract PolicyService is
69
72
 
70
73
  _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getMajorVersion()));
71
74
  _bundleService = IBundleService(getRegistry().getServiceAddress(BUNDLE(), getMajorVersion()));
75
+ _applicationService = IApplicationService(getRegistry().getServiceAddress(APPLICATION(), getMajorVersion()));
72
76
 
73
77
  registerInterface(type(IPolicyService).interfaceId);
74
78
  }
@@ -85,94 +89,6 @@ contract PolicyService is
85
89
  product = Product(productInfo.objectAddress);
86
90
  }
87
91
 
88
- // TODO: no access restrictions
89
- function calculatePremium(
90
- RiskId riskId,
91
- uint256 sumInsuredAmount,
92
- uint256 lifetime,
93
- bytes memory applicationData,
94
- NftId bundleNftId,
95
- ReferralId referralId
96
- )
97
- public
98
- view
99
- virtual override
100
- returns (
101
- uint256 premiumAmount,
102
- uint256 productFeeAmount,
103
- uint256 poolFeeAmount,
104
- uint256 bundleFeeAmount,
105
- uint256 distributionFeeAmount
106
- )
107
- {
108
- Product product = _getAndVerifyInstanceAndProduct();
109
- uint256 netPremiumAmount = product.calculateNetPremium(
110
- sumInsuredAmount,
111
- riskId,
112
- lifetime,
113
- applicationData
114
- );
115
-
116
- (
117
- productFeeAmount,
118
- poolFeeAmount,
119
- bundleFeeAmount,
120
- distributionFeeAmount
121
- ) = _calculateFeeAmounts(
122
- netPremiumAmount,
123
- product,
124
- bundleNftId,
125
- referralId
126
- );
127
-
128
- premiumAmount = netPremiumAmount + productFeeAmount;
129
- premiumAmount += poolFeeAmount + bundleFeeAmount;
130
- premiumAmount += distributionFeeAmount;
131
- }
132
-
133
- function _calculateFeeAmounts(
134
- uint256 netPremiumAmount,
135
- Product product,
136
- NftId bundleNftId,
137
- ReferralId referralId
138
- )
139
- internal
140
- view
141
- returns (
142
- uint256 productFeeAmount,
143
- uint256 poolFeeAmount,
144
- uint256 bundleFeeAmount,
145
- uint256 distributionFeeAmount
146
- )
147
- {
148
- InstanceReader instanceReader;
149
- {
150
- IInstance instance = product.getInstance();
151
- instanceReader = instance.getInstanceReader();
152
- }
153
-
154
- NftId poolNftId = product.getPoolNftId();
155
- IBundle.BundleInfo memory bundleInfo = instanceReader.getBundleInfo(bundleNftId);
156
- require(bundleInfo.poolNftId == poolNftId,"ERROR:PRS-035:BUNDLE_POOL_MISMATCH");
157
-
158
- {
159
- ISetup.ProductSetupInfo memory productSetupInfo = instanceReader.getProductSetupInfo(product.getProductNftId());
160
- (productFeeAmount,) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
161
- }
162
- {
163
- ISetup.PoolSetupInfo memory poolSetupInfo = instanceReader.getPoolSetupInfo(poolNftId);
164
- (poolFeeAmount,) = FeeLib.calculateFee(poolSetupInfo.poolFee, netPremiumAmount);
165
- }
166
- {
167
- NftId distributionNftId = product.getDistributionNftId();
168
- ISetup.DistributionSetupInfo memory distributionSetupInfo = instanceReader.getDistributionSetupInfo(distributionNftId);
169
- // FIXME: call distributionService.calculateFeeAmount
170
- (distributionFeeAmount,) = FeeLib.calculateFee(distributionSetupInfo.distributionFee, netPremiumAmount);
171
- }
172
-
173
- (bundleFeeAmount,) = FeeLib.calculateFee(bundleInfo.fee, netPremiumAmount);
174
- }
175
-
176
92
  function _getAndVerifyUnderwritingSetup(
177
93
  IInstance instance,
178
94
  InstanceReader instanceReader,
@@ -303,6 +219,7 @@ contract PolicyService is
303
219
  pool.verifyApplication(
304
220
  applicationNftId,
305
221
  policyInfo.applicationData,
222
+ bundleNftId,
306
223
  bundleInfo.filter,
307
224
  collateralAmount);
308
225
  }
@@ -445,30 +362,39 @@ contract PolicyService is
445
362
  // process token transfer(s)
446
363
  if(premiumAmount > 0) {
447
364
  ISetup.ProductSetupInfo memory productSetupInfo = instance.getInstanceReader().getProductSetupInfo(productNftId);
365
+ IPolicy.PolicyInfo memory policyInfo = instance.getInstanceReader().getPolicyInfo(policyNftId);
448
366
  TokenHandler tokenHandler = productSetupInfo.tokenHandler;
449
367
  address policyOwner = getRegistry().ownerOf(policyNftId);
450
368
  ISetup.PoolSetupInfo memory poolSetupInfo = instance.getInstanceReader().getPoolSetupInfo(productSetupInfo.poolNftId);
451
369
  address poolWallet = poolSetupInfo.wallet;
452
- netPremiumAmount = premiumAmount;
453
- Fee memory productFee = productSetupInfo.productFee;
454
-
455
- if (FeeLib.feeIsZero(productFee)) {
456
- tokenHandler.transfer(
457
- policyOwner,
458
- poolWallet,
459
- premiumAmount
370
+ IPolicy.Premium memory premium = _applicationService.calculatePremium(
371
+ productNftId,
372
+ policyInfo.riskId,
373
+ policyInfo.sumInsuredAmount,
374
+ policyInfo.lifetime,
375
+ policyInfo.applicationData,
376
+ policyInfo.bundleNftId,
377
+ policyInfo.referralId
460
378
  );
461
- } else {
462
- (uint256 productFeeAmount, uint256 netAmount) = FeeLib.calculateFee(productSetupInfo.productFee, netPremiumAmount);
379
+
380
+ // if (FeeLib.feeIsZero(premium.productFeeAmount)) {
381
+ // tokenHandler.transfer(
382
+ // policyOwner,
383
+ // poolWallet,
384
+ // premiumAmount
385
+ // );
386
+ // } else {
463
387
  address productWallet = productSetupInfo.wallet;
464
- if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premiumAmount) {
465
- revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premiumAmount);
388
+ if (tokenHandler.getToken().allowance(policyOwner, address(tokenHandler)) < premium.premiumAmount) {
389
+ revert ErrorIPolicyServiceInsufficientAllowance(policyOwner, address(tokenHandler), premium.premiumAmount);
466
390
  }
467
- tokenHandler.transfer(policyOwner, productWallet, productFeeAmount);
468
- tokenHandler.transfer(policyOwner, poolWallet, netAmount);
469
- netPremiumAmount = netAmount;
391
+ tokenHandler.transfer(policyOwner, productWallet, premium.productFeeFixAmount + premium.productFeeVarAmount);
392
+ tokenHandler.transfer(policyOwner, poolWallet, premium.netPremiumAmount);
393
+ netPremiumAmount = premium.netPremiumAmount;
470
394
  // TODO: also move distribution tokens to distribution wallet and call `Distribution.processSale` to update distribution balances
471
- }
395
+ // }
396
+ // TODO: move pool/bundle related tokens too
397
+
472
398
  }
473
399
 
474
400
  // TODO: add logging
@@ -184,12 +184,12 @@ contract RegistryService is
184
184
  /*config[-1].serviceDomain = STAKE();
185
185
  config[-1].selector = RegistryService.registerStake.selector;*/
186
186
 
187
- config[0].serviceDomain = APPLICATION();
188
- config[0].selectors = new bytes4[](1);
189
- config[0].selectors[0] = RegistryService.registerPolicy.selector;
187
+ config[0].serviceDomain = POLICY();
188
+ config[0].selectors = new bytes4[](0);
190
189
 
191
- config[1].serviceDomain = POLICY();
192
- config[1].selectors = new bytes4[](0);
190
+ config[1].serviceDomain = APPLICATION();
191
+ config[1].selectors = new bytes4[](1);
192
+ config[1].selectors[0] = RegistryService.registerPolicy.selector;
193
193
 
194
194
  config[2].serviceDomain = CLAIM();
195
195
  config[2].selectors = new bytes4[](0);
@@ -11,6 +11,8 @@ interface IService is
11
11
  IRegisterable,
12
12
  IVersionable
13
13
  {
14
+ error ErrorIServiceCallerUnknown(address caller);
15
+
14
16
  function getDomain() external pure returns(ObjectType serviceDomain);
15
17
  function getMajorVersion() external view returns(VersionPart majorVersion);
16
18
  }
@@ -37,7 +37,7 @@ contract Registerable is
37
37
  ObjectType objectType,
38
38
  bool isInterceptor,
39
39
  address initialOwner,
40
- bytes memory data
40
+ bytes memory registryData // writeonly data that will saved in the object info record of the registry
41
41
  )
42
42
  public
43
43
  virtual
@@ -51,7 +51,7 @@ contract Registerable is
51
51
  $._parentNftId = parentNftId;
52
52
  $._objectType = objectType;
53
53
  $._isInterceptor = isInterceptor;
54
- $._data = data;
54
+ $._data = registryData;
55
55
  }
56
56
 
57
57
 
@@ -16,14 +16,19 @@ using {
16
16
  RoleIdLib.toKey32
17
17
  } for RoleId global;
18
18
 
19
+
20
+ /// @dev role id needs to match with oz AccessManager.ADMIN_ROLE
21
+ function ADMIN_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(type(uint64).min); }
22
+
23
+ /// @dev role id needs to match with oz AccessManager.PUBLIC_ROLE
24
+ function PUBLIC_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(type(uint64).max); }
25
+
19
26
  // general pure free functions
20
27
  function DISTRIBUTION_OWNER_ROLE_NAME() pure returns (string memory) { return "DistributionOwnerRole"; }
21
28
  function ORACLE_OWNER_ROLE_NAME() pure returns (string memory) { return "OracleOwnerRole"; }
22
29
  function POOL_OWNER_ROLE_NAME() pure returns (string memory) { return "PoolOwnerRole"; }
23
30
  function PRODUCT_OWNER_ROLE_NAME() pure returns (string memory) { return "ProductOwnerRole"; }
24
31
 
25
- function ADMIN_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(0); }
26
-
27
32
  function DISTRIBUTION_OWNER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(100); }
28
33
  function ORACLE_OWNER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(200); }
29
34
  function POOL_OWNER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId(300); }