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

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -5,46 +5,95 @@ import {Fee} from "../types/Fee.sol";
5
5
  import {IComponent} from "./IComponent.sol";
6
6
  import {ISetup} from "../instance/module/ISetup.sol";
7
7
  import {NftId} from "../types/NftId.sol";
8
+ import {RoleId} from "../types/RoleId.sol";
9
+ import {Seconds} from "../types/Seconds.sol";
8
10
  import {UFixed} from "../types/UFixed.sol";
9
11
 
10
12
  /// @dev pool components hold and manage the collateral to cover active policies
11
13
  /// pools come in different flavors
12
14
  interface IPoolComponent is IComponent {
13
15
 
14
- event LogUnderwrittenByPool(NftId policyNftId, uint256 collateralizationAmount, address pool);
16
+ error ErrorPoolNotBundleOwner(NftId bundleNftId, address caller);
17
+ error ErrorPoolNotPoolService(address caller);
15
18
 
16
- error ErrorPoolNotPoolService(address service);
19
+ error ErrorPoolApplicationBundleMismatch(NftId applicationNftId);
20
+ error ErrorPoolBundleOwnerRoleAlreadySet();
17
21
 
18
- function getSetupInfo() external view returns (ISetup.PoolSetupInfo memory setupInfo);
22
+ event LogPoolVerifiedByPool(address pool, NftId applicationNftId, uint256 collateralizationAmount);
23
+ event LogPoolBundleMaxCapitalAmountUpdated(uint256 previousMaxCapitalAmount, uint256 currentMaxCapitalAmount);
24
+ event LogPoolBundleOwnerRoleSet(RoleId bundleOwnerRole);
19
25
 
20
- function setFees(
21
- Fee memory poolFee,
22
- Fee memory stakingFee,
23
- Fee memory performanceFee
24
- ) external;
26
+ /// @dev increases the staked tokens by the specified amount
27
+ /// only the bundle owner may stake tokens
28
+ /// bundle MUST be in active or locked state
29
+ function stake(NftId bundleNftId, uint256 amount) external;
30
+
31
+ /// @dev decreases the staked tokens by the specified amount
32
+ /// only the bundle owner may unstake tokens from the bundle
33
+ /// bundle MUST be in active, locked or closed state
34
+ function unstake(NftId bundleNftId, uint256 amount) external;
35
+
36
+ /// @dev extends the bundle lifetime of the bundle by the specified time
37
+ /// only the bundle owner may extend the bundle's lifetime
38
+ /// bundle MUST be in active or locked state
39
+ function extend(NftId bundleNftId, Seconds lifetimeExtension) external;
40
+
41
+ /// @dev locks the specified bundle
42
+ /// a bundle to be locked MUST be in active state
43
+ /// locked bundles may not be used to underwrite any new policy
44
+ function lockBundle(NftId bundleNftId) external;
45
+
46
+ /// @dev unlocks the specified bundle
47
+ /// a bundle to be unlocked MUST be in locked state
48
+ function unlockBundle(NftId bundleNftId) external;
25
49
 
26
- /// @dev sets an additional bundle fee, this fee is added on top of the poolFee and deducted from the premium amounts.
50
+ /// @dev close the specified bundle
51
+ /// a bundle to be closed MUST be in active or locked state
52
+ /// to close a bundle all all linked policies MUST be in closed state as well
53
+ /// closing a bundle finalizes the bundle bookkeeping including overall profit calculation
54
+ /// once a bundle is closed this action cannot be reversed
55
+ function close(NftId bundleNftId) external;
56
+
57
+ /// @dev sets the fee for the specified bundle
58
+ /// the fee is added on top of the poolFee and deducted from the premium amounts
27
59
  /// via these fees individual bundler owner may earn income per policy in the context of peer to peer pools
28
60
  function setBundleFee(
29
61
  NftId bundleNftId,
30
62
  Fee memory fee
31
63
  ) external;
32
64
 
65
+ /// @dev sets the maximum overall capital amound held by this pool
66
+ /// function may only be called by pool owner
67
+ function setMaxCapitalAmount(uint256 maxCapitalAmount) external;
68
+
69
+ /// @dev sets the required role to create/own bundles
70
+ /// may only be called once after setting up a pool
71
+ /// may only be called by pool owner
72
+ function setBundleOwnerRole(RoleId bundleOwnerRole) external;
73
+
74
+ /// @dev update pool fees to the specified values
75
+ /// pool fees: are deducted from the premium amount and goes to the pool owner
76
+ /// staking fees: are deducted from the staked tokens by a bundle owner and goes to the pool owner
77
+ /// performance fees: when a bundle is closed a bundle specific profit is calculated
78
+ /// the performance fee is deducted from this profit and goes to the pool owner
79
+ function setFees(
80
+ Fee memory poolFee,
81
+ Fee memory stakingFee,
82
+ Fee memory performanceFee
83
+ ) external;
84
+
33
85
  /// @dev this is a callback function that is called by the product service when underwriting a policy.
34
86
  /// the pool has the option to check the details and object to underwriting by reverting.
35
87
  /// the function is only called for "active" pools that ask to be involved/notified
36
88
  /// by product related state changes.
37
89
  function verifyApplication(
38
90
  NftId applicationNftId,
39
- bytes memory policyData,
91
+ bytes memory applicationData,
92
+ NftId bundleNftId,
40
93
  bytes memory bundleFilter,
41
94
  uint256 collateralizationAmount
42
95
  ) external;
43
96
 
44
- function lockBundle(NftId bundleNftId) external;
45
-
46
- function unlockBundle(NftId bundleNftId) external;
47
-
48
97
  /// @dev defines the multiplier to calculate the required collateral to cover a given sum insured amount
49
98
  /// default implementation returns 100%
50
99
  function getCollateralizationLevel() external view returns (UFixed collateralizationLevel);
@@ -54,12 +103,6 @@ interface IPoolComponent is IComponent {
54
103
  /// default implementation returns 100%
55
104
  function getRetentionLevel() external view returns (UFixed retentionLevel);
56
105
 
57
- /// @dev declares if pool intercept transfers of bundle nft ids
58
- /// - yes: pool may block transfer of bundle ownership or simply updates some bookkeeping related to bundle ownership. callback function is nftTransferFrom
59
- /// - no: pool is not involved in transfer of bundle ownership
60
- /// default implementation returns false (no)
61
- function isInterceptingBundleTransfers() external view returns (bool);
62
-
63
106
  /// @dev declares if pool relies on external management of collateral (yes/no):
64
107
  /// - yes: underwriting of new policies does not require an actual token balance, instead it is assumed that the pool owner will manage funds externally and inject enough tokens to allow process confirmed payouts
65
108
  /// - no: the pool smart contract ensures that the necessary capacity of the pool prior to underwriting.
@@ -72,16 +115,37 @@ interface IPoolComponent is IComponent {
72
115
  /// default implementation returnsfalse (no)
73
116
  function isVerifyingApplications() external view returns (bool);
74
117
 
75
- /// @dev returns true iff the policy application data in policyData matches
76
- /// with the bundle filter criteria encoded in bundleFilter
118
+ /// @dev returns the maximum overall capital amound held by this pool
119
+ function getMaxCapitalAmount() external view returns (uint256 maxCapitalAmount);
120
+
121
+ /// @dev declares if pool intercept transfers of bundle nft ids
122
+ /// - yes: pool may block transfer of bundle ownership or simply updates some bookkeeping related to bundle ownership. callback function is nftTransferFrom
123
+ /// - no: pool is not involved in transfer of bundle ownership
124
+ /// default implementation returns false (no)
125
+ function isInterceptingBundleTransfers() external view returns (bool);
126
+
127
+ /// @dev returns the required role for bundle owners
128
+ /// default emplementation returns PUBLIC_ROLE
129
+ /// the PUBLIC_ROLE role implies that no specific roole is required for bundle owners
130
+ function getBundleOwnerRole() external view returns (RoleId bundleOwnerRole);
131
+
132
+ /// @dev returns true iff the application matches with the bundle
77
133
  /// this is a callback function that is only called if a pool declares itself as a verifying pool
78
134
  /// default implementation returns true
79
- function policyMatchesBundle(
80
- bytes memory policyData,
81
- bytes memory bundleFilter
135
+ function applicationMatchesBundle(
136
+ NftId applicationNftId,
137
+ bytes memory applicationData,
138
+ NftId bundleNftId,
139
+ bytes memory bundleFilter,
140
+ uint256 collateralizationAmount
82
141
  )
83
142
  external
84
143
  view
85
144
  returns (bool isMatching);
86
145
 
146
+ /// @dev returns setup infos for this pool
147
+ /// when registered with an instance the setup info is obtained from the data stored in the instance
148
+ /// when not registered the function returns the initial setup info
149
+ function getSetupInfo() external view returns (ISetup.PoolSetupInfo memory setupInfo);
150
+
87
151
  }
@@ -7,6 +7,7 @@ import {ISetup} from "../instance/module/ISetup.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
 
11
12
  interface IProductComponent is IComponent {
12
13
 
@@ -20,7 +21,7 @@ interface IProductComponent is IComponent {
20
21
  function calculatePremium(
21
22
  uint256 sumInsuredAmount,
22
23
  RiskId riskId,
23
- uint256 lifetime,
24
+ Seconds lifetime,
24
25
  bytes memory applicationData,
25
26
  NftId bundleNftId,
26
27
  ReferralId referralId
@@ -29,7 +30,7 @@ interface IProductComponent is IComponent {
29
30
  function calculateNetPremium(
30
31
  uint256 sumInsuredAmount,
31
32
  RiskId riskId,
32
- uint256 lifetime,
33
+ Seconds lifetime,
33
34
  bytes memory applicationData
34
35
  ) external view returns (uint256 netPremiumAmount);
35
36
 
@@ -1,19 +1,19 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.20;
3
3
 
4
- import {POOL} from "../types/ObjectType.sol";
5
- import {IPoolService} from "../instance/service/IPoolService.sol";
6
- import {IBundleService} from "../instance/service/IBundleService.sol";
7
- import {NftId, NftIdLib} from "../types/NftId.sol";
4
+ import {Component} from "./Component.sol";
8
5
  import {Fee, FeeLib} from "../types/Fee.sol";
9
- import {UFixed} from "../types/UFixed.sol";
6
+ import {IBundleService} from "../instance/service/IBundleService.sol";
7
+ import {InstanceReader} from "../instance/InstanceReader.sol";
10
8
  import {IPoolComponent} from "./IPoolComponent.sol";
11
- import {Component} from "./Component.sol";
12
- import {TokenHandler} from "../shared/TokenHandler.sol";
13
- import {ISetup} from "../instance/module/ISetup.sol";
14
-
9
+ import {IPoolService} from "../instance/service/IPoolService.sol";
15
10
  import {ISetup} from "../instance/module/ISetup.sol";
16
- import {InstanceReader} from "../instance/InstanceReader.sol";
11
+ import {NftId, NftIdLib} from "../types/NftId.sol";
12
+ import {POOL} from "../types/ObjectType.sol";
13
+ import {RoleId, PUBLIC_ROLE} from "../types/RoleId.sol";
14
+ import {Seconds} from "../types/Seconds.sol";
15
+ import {TokenHandler} from "../shared/TokenHandler.sol";
16
+ import {UFixed} from "../types/UFixed.sol";
17
17
 
18
18
 
19
19
  abstract contract Pool is
@@ -26,11 +26,14 @@ abstract contract Pool is
26
26
  struct PoolStorage {
27
27
  UFixed _collateralizationLevel;
28
28
  UFixed _retentionLevel;
29
-
29
+ uint256 _maxCapitalAmount;
30
+
30
31
  bool _isExternallyManaged;
31
- bool _isInterceptingBundleTransfers;
32
32
  bool _isVerifyingApplications;
33
33
 
34
+ RoleId _bundleOwnerRole;
35
+ bool _isInterceptingBundleTransfers;
36
+
34
37
  Fee _initialPoolFee;
35
38
  Fee _initialStakingFee;
36
39
  Fee _initialPerformanceFee;
@@ -42,6 +45,15 @@ abstract contract Pool is
42
45
  IBundleService _bundleService;
43
46
  }
44
47
 
48
+
49
+ modifier onlyBundleOwner(NftId bundleNftId) {
50
+ if(msg.sender != getRegistry().ownerOf(bundleNftId)) {
51
+ revert ErrorPoolNotBundleOwner(bundleNftId, msg.sender);
52
+ }
53
+ _;
54
+ }
55
+
56
+
45
57
  modifier onlyPoolService() {
46
58
  if(msg.sender != address(_getPoolStorage()._poolService)) {
47
59
  revert ErrorPoolNotPoolService(msg.sender);
@@ -54,7 +66,6 @@ abstract contract Pool is
54
66
  address registry,
55
67
  NftId instanceNftId,
56
68
  string memory name,
57
- // TODO refactor into tokenNftId
58
69
  address token,
59
70
  bool isInterceptingNftTransfers,
60
71
  bool isExternallyManaging,
@@ -62,19 +73,21 @@ abstract contract Pool is
62
73
  UFixed collateralizationLevel,
63
74
  UFixed retentionLevel,
64
75
  address initialOwner,
65
- bytes memory data
76
+ bytes memory registryData // writeonly data that will saved in the object info record of the registry
66
77
  )
67
78
  public
68
79
  virtual
69
80
  onlyInitializing()
70
81
  {
71
- initializeComponent(registry, instanceNftId, name, token, POOL(), isInterceptingNftTransfers, initialOwner, data);
82
+ initializeComponent(registry, instanceNftId, name, token, POOL(), isInterceptingNftTransfers, initialOwner, registryData);
72
83
 
73
84
  PoolStorage storage $ = _getPoolStorage();
74
85
  // TODO add validation
75
86
  $._tokenHandler = new TokenHandler(token);
87
+ $._maxCapitalAmount = type(uint256).max;
76
88
  $._isExternallyManaged = isExternallyManaging;
77
89
  $._isVerifyingApplications = isVerifying;
90
+ $._bundleOwnerRole = PUBLIC_ROLE();
78
91
  $._collateralizationLevel = collateralizationLevel;
79
92
  $._retentionLevel = retentionLevel;
80
93
  $._initialPoolFee = FeeLib.zeroFee();
@@ -86,66 +99,121 @@ abstract contract Pool is
86
99
  registerInterface(type(IPoolComponent).interfaceId);
87
100
  }
88
101
 
89
- /**
90
- * @dev see {IPool.verifyApplication}.
91
- * Default implementation that only writes a {LogUnderwrittenByPool} entry.
92
- */
93
- function verifyApplication(
94
- NftId applicationNftId,
95
- bytes memory applicationData,
96
- bytes memory bundleFilter,
97
- uint256 collateralizationAmount
102
+
103
+ function stake(
104
+ NftId bundleNftId,
105
+ uint256 amount
98
106
  )
99
- external
107
+ public
108
+ virtual
100
109
  restricted()
101
- virtual override
110
+ onlyBundleOwner(bundleNftId)
102
111
  {
103
- require(
104
- policyMatchesBundle(applicationData, bundleFilter),
105
- "ERROR:POL-020:POLICY_BUNDLE_MISMATCH"
106
- );
107
-
108
- emit LogUnderwrittenByPool(applicationNftId, collateralizationAmount, address(this));
112
+ // TODO add implementation
109
113
  }
110
114
 
111
115
 
112
- function isInterceptingBundleTransfers() external view override returns (bool) {
113
- return isNftInterceptor();
116
+ function unstake(
117
+ NftId bundleNftId,
118
+ uint256 amount
119
+ )
120
+ public
121
+ virtual
122
+ restricted()
123
+ onlyBundleOwner(bundleNftId)
124
+ {
125
+ // TODO add implementation
114
126
  }
115
127
 
116
128
 
117
- function isExternallyManaged() external view override returns (bool) {
118
- return _getPoolStorage()._isExternallyManaged;
129
+ function extend(
130
+ NftId bundleNftId,
131
+ Seconds lifetimeExtension
132
+ )
133
+ public
134
+ virtual
135
+ restricted()
136
+ onlyBundleOwner(bundleNftId)
137
+ {
138
+ // TODO add implementation
119
139
  }
120
140
 
121
141
 
122
- function getRetentionLevel() external view override returns (UFixed retentionLevel) {
123
- return _getPoolStorage()._retentionLevel;
142
+ function lockBundle(NftId bundleNftId)
143
+ public
144
+ virtual
145
+ restricted()
146
+ onlyBundleOwner(bundleNftId)
147
+ {
148
+ _getPoolStorage()._bundleService.lockBundle(bundleNftId);
124
149
  }
125
150
 
126
151
 
127
- function getCollateralizationLevel() external view override returns (UFixed collateralizationLevel) {
128
- return _getPoolStorage()._collateralizationLevel;
152
+ function unlockBundle(NftId bundleNftId)
153
+ public
154
+ virtual
155
+ restricted()
156
+ onlyBundleOwner(bundleNftId)
157
+ {
158
+ _getPoolStorage()._bundleService.unlockBundle(bundleNftId);
129
159
  }
130
160
 
131
161
 
132
- function isVerifyingApplications() external view override returns (bool isConfirmingApplication) {
133
- return _getPoolStorage()._isVerifyingApplications;
162
+ function close(NftId bundleNftId)
163
+ public
164
+ virtual
165
+ restricted()
166
+ onlyBundleOwner(bundleNftId)
167
+ {
168
+ // TODO add implementation
134
169
  }
135
170
 
136
171
 
137
- /// @dev see {IPoolComponent.policyMatchesBundle}.
138
- /// Default implementation always returns true
139
- function policyMatchesBundle(
140
- bytes memory, // policyData
141
- bytes memory // bundleFilter
172
+ function setBundleFee(
173
+ NftId bundleNftId,
174
+ Fee memory fee
142
175
  )
143
176
  public
144
- pure
145
- virtual override
146
- returns (bool isMatching)
177
+ virtual
178
+ restricted()
179
+ onlyBundleOwner(bundleNftId)
147
180
  {
148
- return true;
181
+ _getPoolStorage()._bundleService.setBundleFee(bundleNftId, fee);
182
+ }
183
+
184
+
185
+ function setMaxCapitalAmount(uint256 maxCapitalAmount)
186
+ public
187
+ virtual
188
+ restricted()
189
+ onlyOwner()
190
+ {
191
+ // TODO refactor to use pool service
192
+ // _getPoolStorage()._poolService.setMaxCapitalAmount(...);
193
+
194
+ uint256 previousMaxCapitalAmount = _getPoolStorage()._maxCapitalAmount;
195
+ _getPoolStorage()._maxCapitalAmount = maxCapitalAmount;
196
+
197
+ emit LogPoolBundleMaxCapitalAmountUpdated(previousMaxCapitalAmount, maxCapitalAmount);
198
+ }
199
+
200
+
201
+ function setBundleOwnerRole(RoleId bundleOwnerRole)
202
+ public
203
+ virtual
204
+ restricted()
205
+ onlyOwner()
206
+ {
207
+ // TODO refactor to use pool service
208
+ // _getPoolStorage()._poolService.setBundleOwnerRole(...);
209
+
210
+ if(_getPoolStorage()._bundleOwnerRole != PUBLIC_ROLE()) {
211
+ revert ErrorPoolBundleOwnerRoleAlreadySet();
212
+ }
213
+
214
+ _getPoolStorage()._bundleOwnerRole = bundleOwnerRole;
215
+
216
+ emit LogPoolBundleOwnerRoleSet(bundleOwnerRole);
149
217
  }
150
218
 
151
219
 
@@ -154,45 +222,97 @@ abstract contract Pool is
154
222
  Fee memory stakingFee,
155
223
  Fee memory performanceFee
156
224
  )
157
- external
158
- onlyOwner
225
+ public
226
+ virtual
159
227
  restricted()
160
- override
228
+ onlyOwner()
161
229
  {
162
230
  _getPoolStorage()._poolService.setFees(poolFee, stakingFee, performanceFee);
163
231
  }
164
232
 
165
- function setBundleFee(
233
+
234
+ /// @dev see {IPool.verifyApplication}
235
+ function verifyApplication(
236
+ NftId applicationNftId,
237
+ bytes memory applicationData,
166
238
  NftId bundleNftId,
167
- Fee memory fee
239
+ bytes memory bundleFilter,
240
+ uint256 collateralizationAmount
168
241
  )
169
- external
170
- override
171
- // TODO add onlyBundleOwner
242
+ public
243
+ virtual
244
+ restricted()
172
245
  {
173
- _getPoolStorage()._bundleService.setBundleFee(bundleNftId, fee);
246
+ // validate application data against bundle filter
247
+ if(!applicationMatchesBundle(
248
+ applicationNftId,
249
+ applicationData,
250
+ bundleNftId,
251
+ bundleFilter,
252
+ collateralizationAmount)
253
+ )
254
+ {
255
+ revert ErrorPoolApplicationBundleMismatch(applicationNftId);
256
+ }
257
+
258
+ emit LogPoolVerifiedByPool(address(this), applicationNftId, collateralizationAmount);
174
259
  }
175
260
 
176
- function lockBundle(
177
- NftId bundleNftId
178
- )
179
- external
180
- override
181
- // TODO add onlyBundleOwner
182
- {
183
- _getPoolStorage()._bundleService.lockBundle(bundleNftId);
261
+
262
+ function getCollateralizationLevel() public view virtual returns (UFixed collateralizationLevel) {
263
+ return _getPoolStorage()._collateralizationLevel;
264
+ }
265
+
266
+
267
+ function getRetentionLevel() public view virtual returns (UFixed retentionLevel) {
268
+ return _getPoolStorage()._retentionLevel;
269
+ }
270
+
271
+
272
+ function isExternallyManaged() public view virtual returns (bool) {
273
+ return _getPoolStorage()._isExternallyManaged;
274
+ }
275
+
276
+
277
+ function isVerifyingApplications() public view virtual returns (bool isConfirmingApplication) {
278
+ return _getPoolStorage()._isVerifyingApplications;
279
+ }
280
+
281
+
282
+ function getMaxCapitalAmount() public view virtual returns (uint256 maxCapitalAmount) {
283
+ return _getPoolStorage()._maxCapitalAmount;
284
+ }
285
+
286
+
287
+ function isInterceptingBundleTransfers() public view virtual returns (bool) {
288
+ return isNftInterceptor();
289
+ }
290
+
291
+
292
+ function getBundleOwnerRole() public view returns (RoleId bundleOwnerRole) {
293
+ return _getPoolStorage()._bundleOwnerRole;
184
294
  }
185
295
 
186
- function unlockBundle(
187
- NftId bundleNftId
296
+
297
+ /// @dev see {IPoolComponent.applicationMatchesBundle}
298
+ /// Override this function to implement any custom application verification
299
+ /// Default implementation always returns true
300
+ function applicationMatchesBundle(
301
+ NftId applicationNftId,
302
+ bytes memory applicationData,
303
+ NftId bundleNftId,
304
+ bytes memory bundleFilter,
305
+ uint256 collateralizationAmount
188
306
  )
189
- external
190
- override
191
- // TODO add onlyBundleOwner
307
+ public
308
+ view
309
+ virtual override
310
+ returns (bool isMatching)
192
311
  {
193
- _getPoolStorage()._bundleService.unlockBundle(bundleNftId);
312
+ return true;
194
313
  }
195
314
 
315
+
196
316
  function getSetupInfo() public view returns (ISetup.PoolSetupInfo memory setupInfo) {
197
317
  InstanceReader reader = getInstance().getInstanceReader();
198
318
  setupInfo = reader.getPoolSetupInfo(getNftId());
@@ -203,30 +323,13 @@ abstract contract Pool is
203
323
  }
204
324
  }
205
325
 
206
- function _getInitialSetupInfo() internal view returns (ISetup.PoolSetupInfo memory) {
207
- PoolStorage storage $ = _getPoolStorage();
208
- return ISetup.PoolSetupInfo(
209
- getProductNftId(),
210
- $._tokenHandler,
211
- isNftInterceptor(),
212
- $._isExternallyManaged,
213
- $._isVerifyingApplications,
214
- $._collateralizationLevel,
215
- $._retentionLevel,
216
- $._initialPoolFee,
217
- $._initialStakingFee,
218
- $._initialPerformanceFee,
219
- getWallet()
220
- );
221
- }
222
-
223
326
  // Internals
224
327
 
225
328
  function _createBundle(
226
329
  address bundleOwner,
227
330
  Fee memory fee,
228
331
  uint256 amount,
229
- uint256 lifetime,
332
+ Seconds lifetime,
230
333
  bytes memory filter
231
334
  )
232
335
  internal
@@ -242,10 +345,31 @@ abstract contract Pool is
242
345
  // TODO add logging
243
346
  }
244
347
 
348
+ // TODO remove function once this is no longer used to produce contract locations on the fly ...
245
349
  function getContractLocation(bytes memory name) external pure returns (bytes32 hash) {
246
350
  return keccak256(abi.encode(uint256(keccak256(name)) - 1)) & ~bytes32(uint256(0xff));
247
351
  }
248
352
 
353
+
354
+ function _getInitialSetupInfo() internal view returns (ISetup.PoolSetupInfo memory) {
355
+ PoolStorage storage $ = _getPoolStorage();
356
+ return ISetup.PoolSetupInfo(
357
+ getProductNftId(),
358
+ $._tokenHandler,
359
+ $._maxCapitalAmount,
360
+ isNftInterceptor(),
361
+ $._isExternallyManaged,
362
+ $._isVerifyingApplications,
363
+ $._collateralizationLevel,
364
+ $._retentionLevel,
365
+ $._initialPoolFee,
366
+ $._initialStakingFee,
367
+ $._initialPerformanceFee,
368
+ getWallet()
369
+ );
370
+ }
371
+
372
+
249
373
  function _getPoolStorage() private pure returns (PoolStorage storage $) {
250
374
  assembly {
251
375
  $.slot := POOL_STORAGE_LOCATION_V1