@etherisc/gif-next 0.0.2-fc8b370-882 → 0.0.2-fe34d97-357

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. package/README.md +36 -0
  2. package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
  3. package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
  4. package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
  5. package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
  6. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  7. package/artifacts/contracts/components/Pool.sol/Pool.json +72 -4
  8. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  9. package/artifacts/contracts/components/Product.sol/Product.json +46 -3
  10. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  11. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  12. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  13. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  14. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  15. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  16. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  18. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  20. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
  22. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  28. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  29. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +540 -401
  30. package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +1 -1
  31. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  32. package/artifacts/contracts/instance/Instance.sol/Instance.json +640 -469
  33. package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
  34. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
  35. package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +18 -0
  36. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
  37. package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +49 -0
  38. package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
  39. package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +1 -1
  40. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +1 -1
  41. package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.json +18 -0
  42. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
  43. package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +41 -23
  44. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
  45. package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +4 -4
  46. package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +1 -1
  47. package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +1 -1
  48. package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +1 -1
  49. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +1 -1
  50. package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  51. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +1 -1
  52. package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +17 -48
  53. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +1 -1
  54. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +1 -1
  55. package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +18 -49
  56. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.dbg.json +1 -1
  57. package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.json +2 -2
  58. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensation.dbg.json +1 -1
  59. package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensationModule.dbg.json +1 -1
  60. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  61. package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.json +36 -88
  62. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +1 -1
  63. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  64. package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.json +36 -88
  65. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  66. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  67. package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.json +65 -38
  68. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  69. package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.json +65 -38
  70. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  71. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  72. package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.json +0 -5
  73. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  74. package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.json +0 -5
  75. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +1 -1
  76. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +1 -1
  77. package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.json +123 -1
  78. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +1 -1
  79. package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +145 -5
  80. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
  81. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
  82. package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +166 -168
  83. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
  84. package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +2 -2
  85. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
  86. package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +167 -169
  87. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
  88. package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +21 -21
  89. package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
  90. package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
  91. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
  92. package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +71 -0
  93. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
  94. package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +6 -6
  95. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
  96. package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +97 -26
  97. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  98. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  99. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  100. package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
  101. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  102. package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
  103. package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
  104. package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +1 -1
  105. package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
  106. package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
  107. package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
  108. package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
  109. package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
  110. package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +1 -1
  111. package/artifacts/contracts/test/TestPool.sol/TestPool.json +72 -4
  112. package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +1 -1
  113. package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +90 -4
  114. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
  115. package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
  116. package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
  117. package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
  118. package/artifacts/contracts/test/TestService.sol/TestService.json +2 -2
  119. package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
  120. package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
  121. package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
  122. package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
  123. package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
  124. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  125. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  126. package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
  127. package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
  128. package/artifacts/contracts/types/Key32.sol/Key32Lib.json +2 -2
  129. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  130. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  131. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
  132. package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
  133. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
  134. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
  135. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
  136. package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
  137. package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
  138. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
  139. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  140. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
  141. package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
  142. package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
  143. package/contracts/components/BaseComponent.sol +7 -1
  144. package/contracts/components/Pool.sol +20 -3
  145. package/contracts/components/Product.sol +69 -5
  146. package/contracts/instance/IInstance.sol +3 -4
  147. package/contracts/instance/Instance.sol +7 -4
  148. package/contracts/instance/base/IInstanceBase.sol +5 -0
  149. package/contracts/instance/base/IKeyValueStore.sol +4 -3
  150. package/contracts/instance/base/InstanceBase.sol +6 -2
  151. package/contracts/instance/base/KeyValueStore.sol +12 -7
  152. package/contracts/instance/base/Lifecycle.sol +15 -10
  153. package/contracts/instance/base/ModuleBase.sol +18 -17
  154. package/contracts/instance/module/bundle/BundleModule.sol +10 -11
  155. package/contracts/instance/module/bundle/IBundle.sol +4 -11
  156. package/contracts/instance/module/compensation/CompensationModule.sol +11 -2
  157. package/contracts/instance/module/component/ComponentModule.sol +39 -53
  158. package/contracts/instance/module/component/IComponent.sol +6 -30
  159. package/contracts/instance/module/policy/IPolicy.sol +11 -9
  160. package/contracts/instance/module/policy/PolicyModule.sol +35 -19
  161. package/contracts/instance/module/pool/IPoolModule.sol +0 -1
  162. package/contracts/instance/module/pool/PoolModule.sol +12 -9
  163. package/contracts/instance/module/risk/IRisk.sol +19 -2
  164. package/contracts/instance/module/risk/RiskModule.sol +64 -2
  165. package/contracts/instance/module/treasury/ITreasury.sol +35 -42
  166. package/contracts/instance/module/treasury/TreasuryModule.sol +96 -77
  167. package/contracts/instance/service/ComponentOwnerService.sol +19 -34
  168. package/contracts/instance/service/IProductService.sol +21 -1
  169. package/contracts/instance/service/PoolService.sol +10 -4
  170. package/contracts/instance/service/ProductService.sol +120 -68
  171. package/contracts/registry/Registry.sol +2 -2
  172. package/contracts/test/TestPool.sol +4 -2
  173. package/contracts/test/TestProduct.sol +25 -3
  174. package/contracts/types/ObjectType.sol +20 -8
  175. package/contracts/types/RiskId.sol +43 -0
  176. package/package.json +1 -1
@@ -55,7 +55,7 @@ abstract contract BundleModule is
55
55
  }
56
56
 
57
57
  function initializeBundleModule(IKeyValueStore keyValueStore) internal {
58
- _initialize(keyValueStore, BUNDLE());
58
+ _initialize(keyValueStore);
59
59
  }
60
60
 
61
61
  function createBundleInfo(
@@ -69,8 +69,7 @@ abstract contract BundleModule is
69
69
  onlyBundlePoolService
70
70
  override
71
71
  {
72
- BundleInfo memory bundleInfo = BundleInfo(
73
- bundleNftId,
72
+ BundleInfo memory info = BundleInfo(
74
73
  poolNftId,
75
74
  filter,
76
75
  amount, // capital
@@ -80,15 +79,15 @@ abstract contract BundleModule is
80
79
  zeroTimestamp() // closedAt
81
80
  );
82
81
 
83
- _create(bundleNftId, abi.encode(bundleInfo));
82
+ _create(BUNDLE(), bundleNftId, abi.encode(info));
84
83
  }
85
84
 
86
- function setBundleInfo(BundleInfo memory bundleInfo)
85
+ function setBundleInfo(NftId bundleNftId, BundleInfo memory info)
87
86
  external
88
87
  override
89
88
  onlyPoolOrProductService
90
89
  {
91
- _updateData(bundleInfo.nftId, abi.encode(bundleInfo));
90
+ _updateData(BUNDLE(), bundleNftId, abi.encode(info));
92
91
  }
93
92
 
94
93
  function updateBundleState(NftId bundleNftId, StateId state)
@@ -96,7 +95,7 @@ abstract contract BundleModule is
96
95
  override
97
96
  onlyBundlePoolService
98
97
  {
99
- _updateState(bundleNftId, state);
98
+ _updateState(BUNDLE(), bundleNftId, state);
100
99
  }
101
100
 
102
101
  function collateralizePolicy(
@@ -127,10 +126,10 @@ abstract contract BundleModule is
127
126
  }
128
127
 
129
128
  function getBundleInfo(NftId bundleNftId) external view override returns(BundleInfo memory bundleInfo) {
130
- return abi.decode(_getData(bundleNftId), (BundleInfo));
129
+ return abi.decode(_getData(BUNDLE(), bundleNftId), (BundleInfo));
131
130
  }
132
131
 
133
- function toBundleKey32(NftId bundleNftId) external view override returns (Key32 key32) {
134
- return _toKey32(bundleNftId);
135
- }
132
+ function getBundleState(NftId bundleNftId) external view override returns(StateId state) {
133
+ return _getState(BUNDLE(), bundleNftId);
134
+ }
136
135
  }
@@ -16,7 +16,6 @@ import {IPoolService} from "../../service/IPoolService.sol";
16
16
  interface IBundle {
17
17
 
18
18
  struct BundleInfo {
19
- NftId nftId;
20
19
  NftId poolNftId;
21
20
  bytes filter; // required conditions for applications to be considered for collateralization by this bundle
22
21
  uint256 capitalAmount; // net investment capital amount (<= balance)
@@ -37,20 +36,14 @@ interface IBundleModule is IBundle {
37
36
  bytes calldata filter
38
37
  ) external;
39
38
 
40
- function setBundleInfo(BundleInfo memory bundleInfo) external;
41
- function updateBundleState(NftId bundleNftId, StateId state) external;
39
+ function setBundleInfo(NftId nftId, BundleInfo memory bundleInfo) external;
40
+ function updateBundleState(NftId nftId, StateId state) external;
42
41
 
43
42
  function collateralizePolicy(NftId bundleNftId, NftId policyNftId, uint256 amount) external;
44
43
  function releasePolicy(NftId bundleNftId, NftId policyNftId) external returns(uint256 collateralAmount);
45
44
 
46
- function getBundleInfo(NftId bundleNftId) external view returns(BundleInfo memory bundleInfo);
47
- function toBundleKey32(NftId bundleNftId) external view returns (Key32 key32);
48
-
49
- // repeat registry linked signature
50
- function getRegistry() external view returns (IRegistry registry);
51
-
52
- // repeat instance base signature
53
- function getKeyValueStore() external view returns (IKeyValueStore keyValueStore);
45
+ function getBundleInfo(NftId nftId) external view returns(BundleInfo memory bundleInfo);
46
+ function getBundleState(NftId nftId) external view returns(StateId state);
54
47
 
55
48
  // repeat service linked signatures to avoid linearization issues
56
49
  function getProductService() external returns(IProductService);
@@ -2,7 +2,16 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {ICompensationModule} from "./ICompensation.sol";
5
+ import {IKeyValueStore} from "../../base/IKeyValueStore.sol";
6
+ import {ModuleBase} from "../../base/ModuleBase.sol";
7
+
8
+ contract CompensationModule is
9
+ ModuleBase,
10
+ ICompensationModule
11
+ {
12
+
13
+ function initializeCompensationModule(IKeyValueStore keyValueStore) internal {
14
+ _initialize(keyValueStore);
15
+ }
5
16
 
6
- contract CompensationModule is ICompensationModule {
7
-
8
17
  }
@@ -2,27 +2,21 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+ import {IKeyValueStore} from "../../base/IKeyValueStore.sol";
6
+ import {IComponentModule} from "./IComponent.sol";
5
7
 
6
- import {IRegistry} from "../../../registry/IRegistry.sol";
7
- import {IInstance} from "../../IInstance.sol";
8
+ import {NftId} from "../../../types/NftId.sol";
9
+ import {ObjectType, COMPONENT} from "../../../types/ObjectType.sol";
10
+ import {StateId} from "../../../types/StateId.sol";
11
+ import {ModuleBase} from "../../base/ModuleBase.sol";
8
12
 
9
- import {IComponent, IComponentModule} from "./IComponent.sol";
10
- import {IComponentOwnerService} from "../../service/IComponentOwnerService.sol";
11
- import {ObjectType, PRODUCT, ORACLE, POOL} from "../../../types/ObjectType.sol";
12
- import {StateId, ACTIVE, PAUSED} from "../../../types/StateId.sol";
13
- import {NftId, NftIdLib, zeroNftId} from "../../../types/NftId.sol";
14
- import {Fee} from "../../../types/Fee.sol";
15
-
16
- abstract contract ComponentModule is
13
+ abstract contract ComponentModule is
14
+ ModuleBase,
17
15
  IComponentModule
18
16
  {
19
- using NftIdLib for NftId;
20
17
 
21
- mapping(NftId nftId => ComponentInfo info) private _componentInfo;
22
18
  NftId[] private _nftIds;
23
19
 
24
- mapping(ObjectType cType => bytes32 role) private _componentOwnerRole;
25
-
26
20
  modifier onlyComponentOwnerService() {
27
21
  require(
28
22
  msg.sender == address(this.getComponentOwnerService()),
@@ -31,45 +25,43 @@ abstract contract ComponentModule is
31
25
  _;
32
26
  }
33
27
 
28
+ function initializeComponentModule(IKeyValueStore keyValueStore) internal {
29
+ _initialize(keyValueStore);
30
+ }
31
+
34
32
  function registerComponent(
35
33
  NftId nftId,
36
- ObjectType objectType,
37
- IERC20Metadata token
38
- ) external override onlyComponentOwnerService {
39
-
40
- // create component info
41
- _componentInfo[nftId] = ComponentInfo(
42
- nftId,
43
- // _lifecycleModule.getInitialState(objectType),
44
- ACTIVE(),
45
- token
46
- );
47
-
34
+ IERC20Metadata token,
35
+ address wallet
36
+ )
37
+ external
38
+ onlyComponentOwnerService
39
+ override
40
+ {
41
+ ComponentInfo memory info = ComponentInfo(token, wallet);
48
42
  _nftIds.push(nftId);
43
+ _create(COMPONENT(), nftId, abi.encode(info));
44
+ }
49
45
 
50
- // TODO add logging
46
+ function getComponentState(
47
+ NftId nftId
48
+ )
49
+ external
50
+ view
51
+ override
52
+ returns (StateId state)
53
+ {
54
+ return _getState(COMPONENT(), nftId);
51
55
  }
52
56
 
53
- function setComponentInfo(
54
- ComponentInfo memory info
55
- ) external onlyComponentOwnerService returns (NftId nftId) {
56
- nftId = info.nftId;
57
- require(
58
- nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
59
- "ERROR:CMP-006:COMPONENT_UNKNOWN"
60
- );
57
+ function getComponentToken(NftId nftId) external view override returns(IERC20Metadata token) {
58
+ ComponentInfo memory info = abi.decode(_getData(COMPONENT(), nftId), (ComponentInfo));
59
+ return info.token;
60
+ }
61
61
 
62
- // TODO decide if state changes should have explicit functions and not
63
- // just a generic setXYZInfo and implicit state transitions
64
- // when in doubt go for the explicit approach ...
65
- // ObjectType objectType = this.getRegistry().getObjectInfo(nftId).objectType;
66
- // _lifecycleModule.checkAndLogTransition(
67
- // nftId,
68
- // objectType,
69
- // _componentInfo[nftId].state,
70
- // info.state
71
- // );
72
- _componentInfo[nftId] = info;
62
+ function getComponentWallet(NftId nftId) external view override returns (address wallet) {
63
+ ComponentInfo memory info = abi.decode(_getData(COMPONENT(), nftId), (ComponentInfo));
64
+ return info.wallet;
73
65
  }
74
66
 
75
67
  function getComponentCount()
@@ -86,10 +78,4 @@ abstract contract ComponentModule is
86
78
  ) external view override returns (NftId componentNftId) {
87
79
  return _nftIds[idx];
88
80
  }
89
-
90
- function getComponentInfo(
91
- NftId nftId
92
- ) external view override returns (ComponentInfo memory) {
93
- return _componentInfo[nftId];
94
- }
95
- }
81
+ }
@@ -2,52 +2,28 @@
2
2
  pragma solidity ^0.8.19;
3
3
 
4
4
  import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+ import {IComponentOwnerService} from "../../service/IComponentOwnerService.sol";
5
6
 
6
-
7
- import {IRegistry} from "../../../registry/IRegistry.sol";
8
- import {IInstance} from "../../IInstance.sol";
9
7
  import {StateId} from "../../../types/StateId.sol";
10
8
  import {NftId} from "../../../types/NftId.sol";
11
- import {ObjectType} from "../../../types/ObjectType.sol";
12
- import {RoleId} from "../../../types/RoleId.sol";
13
- import {Fee} from "../../../types/Fee.sol";
14
- import {UFixed} from "../../../types/UFixed.sol";
15
-
16
- import {IComponentOwnerService} from "../../service/IComponentOwnerService.sol";
17
- // import {IComponentBase} from "../../../components/IComponentBase.sol";
18
9
 
19
10
  interface IComponent {
20
- // component dynamic info (static info kept in registry)
21
11
  struct ComponentInfo {
22
- NftId nftId;
23
- StateId state;
24
12
  IERC20Metadata token;
13
+ address wallet;
25
14
  }
26
15
  }
27
16
 
28
17
  interface IComponentModule is IComponent {
29
- function getRegistry() external view returns (IRegistry registry);
30
18
 
31
- function registerComponent(
32
- NftId nftId,
33
- ObjectType objectType,
34
- IERC20Metadata token
35
- ) external;
36
-
37
- function setComponentInfo(
38
- ComponentInfo memory info
39
- ) external returns (NftId componentNftId);
40
-
41
- function getComponentInfo(
42
- NftId nftId
43
- ) external view returns (ComponentInfo memory info);
19
+ function registerComponent(NftId nftId, IERC20Metadata token, address wallet) external;
20
+ function getComponentState(NftId nftId) external view returns (StateId state);
21
+ function getComponentToken(NftId nftId) external view returns (IERC20Metadata token);
22
+ function getComponentWallet(NftId nftId) external view returns (address wallet);
44
23
 
45
24
  function getComponentCount() external view returns (uint256 numberOfCompnents);
46
-
47
25
  function getComponentId(uint256 idx) external view returns (NftId nftId);
48
26
 
49
27
  // repeat service linked signaturea to avoid linearization issues
50
28
  function getComponentOwnerService() external view returns(IComponentOwnerService);
51
-
52
- function hasRole(RoleId role, address member) external view returns (bool);
53
29
  }
@@ -5,42 +5,42 @@ import {IRegistry} from "../../../registry/IRegistry.sol";
5
5
  import {IInstance} from "../../IInstance.sol";
6
6
  import {IProductService} from "../../service/IProductService.sol";
7
7
  import {NftId} from "../../../types/NftId.sol";
8
+ import {RiskId} from "../../../types/RiskId.sol";
8
9
  import {StateId} from "../../../types/StateId.sol";
9
10
  import {Timestamp} from "../../../types/Timestamp.sol";
10
- import {Blocknumber} from "../../../types/Blocknumber.sol";
11
11
 
12
12
  // TODO check if there is value to introuce IContract and let IPolicy derive from IContract
13
13
  interface IPolicy {
14
14
  struct PolicyInfo {
15
- NftId nftId;
16
15
  NftId productNftId;
17
16
  NftId bundleNftId;
18
17
  address beneficiary;
19
- StateId state; // applied, withdrawn, rejected, active, closed
18
+ RiskId riskId;
20
19
  uint256 sumInsuredAmount;
21
20
  uint256 premiumAmount;
22
21
  uint256 premiumPaidAmount;
23
22
  uint256 lifetime;
24
- bytes data;
25
- Timestamp createdAt;
23
+ bytes applicationData;
24
+ bytes policyData;
26
25
  Timestamp activatedAt; // time of underwriting
27
26
  Timestamp expiredAt; // no new claims (activatedAt + lifetime)
28
27
  Timestamp closedAt; // no locked capital
29
- Blocknumber updatedIn; // write log entries in a way to support backtracking of all state changes
30
28
  }
31
29
  }
32
30
 
33
31
  interface IPolicyModule is IPolicy {
34
- function createApplication(
35
- NftId productNftId,
32
+ function createPolicyInfo(
36
33
  NftId policyNftId,
34
+ NftId productNftId,
35
+ RiskId riskId,
37
36
  uint256 sumInsuredAmount,
38
37
  uint256 premiumAmount,
39
38
  uint256 lifetime,
40
39
  NftId bundleNftId
41
40
  ) external;
42
41
 
43
- function setPolicyInfo(PolicyInfo memory policyInfo) external;
42
+ function setPolicyInfo(NftId policyNftId, PolicyInfo memory info) external;
43
+ function updatePolicyState(NftId nftId, StateId state) external;
44
44
 
45
45
  // function underwrite(NftId nftId) external;
46
46
 
@@ -52,6 +52,8 @@ interface IPolicyModule is IPolicy {
52
52
  NftId nftId
53
53
  ) external view returns (PolicyInfo memory info);
54
54
 
55
+ function getPolicyState(NftId nftId) external view returns (StateId state);
56
+
55
57
  // repeat registry linked signature
56
58
  function getRegistry() external view returns (IRegistry registry);
57
59
 
@@ -6,15 +6,18 @@ import {IRegistry} from "../../../registry/IRegistry.sol";
6
6
  import {IProductService} from "../../service/IProductService.sol";
7
7
  import {IPolicy, IPolicyModule} from "./IPolicy.sol";
8
8
  import {ObjectType, POLICY} from "../../../types/ObjectType.sol";
9
- import {APPLIED, ACTIVE, UNDERWRITTEN} from "../../../types/StateId.sol";
10
9
  import {NftId, NftIdLib} from "../../../types/NftId.sol";
10
+ import {RiskId} from "../../../types/RiskId.sol";
11
+ import {StateId} from "../../../types/StateId.sol";
11
12
  import {Timestamp, blockTimestamp, zeroTimestamp} from "../../../types/Timestamp.sol";
12
- import {Blocknumber, blockNumber} from "../../../types/Blocknumber.sol";
13
13
 
14
- abstract contract PolicyModule is IPolicyModule {
15
- using NftIdLib for NftId;
14
+ import {IKeyValueStore} from "../../base/IKeyValueStore.sol";
15
+ import {ModuleBase} from "../../base/ModuleBase.sol";
16
16
 
17
- mapping(NftId nftId => PolicyInfo info) private _policyInfo;
17
+ abstract contract PolicyModule is
18
+ ModuleBase,
19
+ IPolicyModule
20
+ {
18
21
 
19
22
  // TODO find a better place to avoid dupliation
20
23
  modifier onlyProductService2() {
@@ -25,9 +28,14 @@ abstract contract PolicyModule is IPolicyModule {
25
28
  _;
26
29
  }
27
30
 
28
- function createApplication(
29
- NftId productNftId,
31
+ function initializePolicyModule(IKeyValueStore keyValueStore) internal {
32
+ _initialize(keyValueStore);
33
+ }
34
+
35
+ function createPolicyInfo(
30
36
  NftId policyNftId,
37
+ NftId productNftId,
38
+ RiskId riskId,
31
39
  uint256 sumInsuredAmount,
32
40
  uint256 premiumAmount,
33
41
  uint256 lifetime,
@@ -37,40 +45,48 @@ abstract contract PolicyModule is IPolicyModule {
37
45
  onlyProductService2
38
46
  override
39
47
  {
40
- _policyInfo[policyNftId] = PolicyInfo(
41
- policyNftId,
48
+ PolicyInfo memory info = PolicyInfo(
42
49
  productNftId,
43
50
  bundleNftId,
44
51
  address(0), // beneficiary = policy nft holder
45
- // _lifecycleModule.getInitialState(POLICY()),
46
- APPLIED(),
52
+ riskId,
47
53
  sumInsuredAmount,
48
54
  premiumAmount,
49
55
  0, // premium paid amount
50
56
  lifetime,
51
- "", // data
52
- blockTimestamp(), // createdAt
57
+ "", // applicationData
58
+ "", // policyData
53
59
  zeroTimestamp(), // activatedAt
54
60
  zeroTimestamp(), // expiredAt
55
- zeroTimestamp(), // closedAt
56
- blockNumber() // updatedIn
61
+ zeroTimestamp() // closedAt
57
62
  );
58
63
 
59
- // TODO add logging
64
+ _create(POLICY(), policyNftId, abi.encode(info));
60
65
  }
61
66
 
62
- function setPolicyInfo(PolicyInfo memory policyInfo)
67
+ function setPolicyInfo(NftId policyNftId, PolicyInfo memory info)
63
68
  external
64
69
  override
65
70
  onlyProductService2
66
71
  {
67
- _policyInfo[policyInfo.nftId] = policyInfo;
72
+ _updateData(POLICY(), policyNftId, abi.encode(info));
73
+ }
74
+
75
+ function updatePolicyState(NftId bundleNftId, StateId state)
76
+ external
77
+ override
78
+ onlyProductService2
79
+ {
80
+ _updateState(POLICY(), bundleNftId, state);
68
81
  }
69
82
 
70
83
  function getPolicyInfo(
71
84
  NftId nftId
72
85
  ) external view returns (PolicyInfo memory info) {
73
- return _policyInfo[nftId];
86
+ return abi.decode(_getData(POLICY(), nftId), (PolicyInfo));
74
87
  }
75
88
 
89
+ function getPolicyState(NftId nftId) external view override returns(StateId state) {
90
+ return _getState(POLICY(), nftId);
91
+ }
76
92
  }
@@ -9,7 +9,6 @@ import {IPoolService} from "../../service/IPoolService.sol";
9
9
 
10
10
  interface IPool {
11
11
  struct PoolInfo {
12
- NftId nftId;
13
12
  bool isVerifying;
14
13
  UFixed collateralizationLevel;
15
14
  }
@@ -8,18 +8,22 @@ import {IPolicy, IPolicyModule} from "../../module/policy/IPolicy.sol";
8
8
  import {ITreasuryModule} from "../../module/treasury/ITreasury.sol";
9
9
 
10
10
  import {NftId} from "../../../types/NftId.sol";
11
+ import {POOL} from "../../../types/ObjectType.sol";
11
12
  import {LibNftIdSet} from "../../../types/NftIdSet.sol";
12
13
  import {StateId, APPLIED} from "../../../types/StateId.sol";
13
14
  import {UFixed} from "../../../types/UFixed.sol";
14
15
 
16
+ import {IKeyValueStore} from "../../base/IKeyValueStore.sol";
15
17
  import {IPoolModule} from "./IPoolModule.sol";
18
+ import {ModuleBase} from "../../base/ModuleBase.sol";
16
19
 
17
20
  abstract contract PoolModule is
21
+ ModuleBase,
18
22
  IPoolModule
19
23
  {
20
24
  using LibNftIdSet for LibNftIdSet.Set;
21
25
 
22
- mapping(NftId poolNftId => PoolInfo info) private _poolInfo;
26
+ // mapping(NftId poolNftId => PoolInfo info) private _poolInfo;
23
27
  mapping(NftId poolNftId => LibNftIdSet.Set bundles) private _bundlesForPool;
24
28
 
25
29
  modifier poolServiceCallingPool() {
@@ -30,6 +34,10 @@ abstract contract PoolModule is
30
34
  _;
31
35
  }
32
36
 
37
+ function initializePoolModule(IKeyValueStore keyValueStore) internal {
38
+ _initialize(keyValueStore);
39
+ }
40
+
33
41
  function registerPool(
34
42
  NftId nftId,
35
43
  bool isVerifying,
@@ -38,17 +46,12 @@ abstract contract PoolModule is
38
46
  public
39
47
  override
40
48
  {
41
- require(
42
- _poolInfo[nftId].nftId.eqz(),
43
- "ERROR:PL-010:ALREADY_CREATED");
44
-
45
- _poolInfo[nftId] = PoolInfo(
46
- nftId,
49
+ PoolInfo memory info = PoolInfo(
47
50
  isVerifying,
48
51
  collateralizationRate
49
52
  );
50
53
 
51
- // TODO add logging
54
+ _create(POOL(), nftId, abi.encode(info));
52
55
  }
53
56
 
54
57
  function addBundleToPool(
@@ -71,7 +74,7 @@ abstract contract PoolModule is
71
74
  function getPoolInfo(
72
75
  NftId nftId
73
76
  ) external view override returns (PoolInfo memory info) {
74
- info = _poolInfo[nftId];
77
+ return abi.decode(_getData(POOL(), nftId), (PoolInfo));
75
78
  }
76
79
 
77
80
 
@@ -1,10 +1,27 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
- interface IRisk {
4
+ import {NftId} from "../../../types/NftId.sol";
5
+ import {RiskId} from "../../../types/RiskId.sol";
6
+ import {StateId} from "../../../types/StateId.sol";
5
7
 
8
+ interface IRisk {
9
+ struct RiskInfo {
10
+ NftId productNftId;
11
+ bytes data;
12
+ }
6
13
  }
7
14
 
8
15
  interface IRiskModule is IRisk {
9
-
16
+ function createRisk(
17
+ RiskId riskId,
18
+ NftId productNftId,
19
+ bytes memory data
20
+ ) external;
21
+
22
+ function setRiskInfo(RiskId riskId, RiskInfo memory info) external;
23
+ function updateRiskState(RiskId riskId, StateId state) external;
24
+
25
+ function getRiskInfo(RiskId riskId) external view returns (RiskInfo memory info);
26
+ function getRiskState(RiskId riskId) external view returns (StateId state);
10
27
  }
@@ -1,8 +1,70 @@
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
+ import {RISK} from "../../../types/ObjectType.sol";
6
+ import {RiskId} from "../../../types/RiskId.sol";
7
+ import {StateId} from "../../../types/StateId.sol";
8
+
9
+ import {IKeyValueStore} from "../../base/IKeyValueStore.sol";
4
10
  import {IRiskModule} from "./IRisk.sol";
11
+ import {ModuleBase} from "../../base/ModuleBase.sol";
12
+
13
+ contract RiskModule is
14
+ ModuleBase,
15
+ IRiskModule
16
+ {
17
+ function initializeRiskModule(IKeyValueStore keyValueStore) internal {
18
+ _initialize(keyValueStore);
19
+ }
20
+
21
+ function createRisk(
22
+ RiskId riskId,
23
+ NftId productNftId,
24
+ bytes memory data
25
+ ) external override {
26
+ RiskInfo memory info = RiskInfo(
27
+ productNftId,
28
+ data
29
+ );
30
+
31
+ _create(RISK(), riskId.toKey32(), abi.encode(info));
32
+ }
33
+
34
+ function setRiskInfo(
35
+ RiskId riskId,
36
+ RiskInfo memory info
37
+ )
38
+ external
39
+ override
40
+ {
41
+
42
+ }
43
+
44
+ function updateRiskState(
45
+ RiskId riskId,
46
+ StateId state
47
+ )
48
+ external
49
+ override
50
+ {
51
+
52
+ }
53
+
54
+ function getRiskInfo(RiskId riskId)
55
+ external
56
+ view
57
+ override
58
+ returns (RiskInfo memory info)
59
+ {
60
+
61
+ }
62
+
63
+ function getRiskState(RiskId riskId)
64
+ external
65
+ view
66
+ returns (StateId state)
67
+ {
5
68
 
6
- contract RiskModule is IRiskModule {
7
-
69
+ }
8
70
  }