@etherisc/gif-next 0.0.2-c4efd5e → 0.0.2-c630f3f-038

Sign up to get free protection for your applications and to get access to all the features.
Files changed (165) hide show
  1. package/README.md +10 -2
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +28 -2
  4. package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
  5. package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
  6. package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
  7. package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +78 -2
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +32 -150
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +121 -6
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +121 -6
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
  18. package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
  19. package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
  20. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
  21. package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
  22. package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
  23. package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
  24. package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
  25. package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
  26. package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
  27. package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
  28. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +4 -0
  29. package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
  30. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
  31. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
  32. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
  33. package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
  34. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
  35. package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
  36. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
  37. package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
  38. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
  39. package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
  40. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
  41. package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
  42. package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
  43. package/artifacts/contracts/instance/IInstance.sol/IInstance.json +686 -99
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +757 -99
  46. package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
  47. package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
  48. package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
  49. package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
  50. package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
  51. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
  52. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +14 -42
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +65 -10
  55. package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
  56. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
  57. package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +28 -2
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +12 -40
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +47 -0
  62. package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
  63. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
  64. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
  65. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
  66. package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
  67. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
  68. package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
  69. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
  70. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
  71. package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +26 -3
  72. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +26 -3
  74. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
  75. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
  76. package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +15 -35
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  78. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +22 -29
  79. package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
  80. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
  81. package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +13 -0
  82. package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
  83. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
  84. package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +41 -12
  85. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
  86. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
  87. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
  88. package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
  89. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
  90. package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
  91. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
  92. package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
  93. package/artifacts/contracts/mock/Dip.sol/DIP.dbg.json +4 -0
  94. package/artifacts/contracts/mock/Dip.sol/DIP.json +338 -0
  95. package/artifacts/contracts/mock/TestPool.sol/TestPool.dbg.json +4 -0
  96. package/artifacts/contracts/mock/TestPool.sol/TestPool.json +294 -0
  97. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.dbg.json +4 -0
  98. package/artifacts/contracts/mock/TestProduct.sol/TestProduct.json +384 -0
  99. package/artifacts/contracts/mock/Usdc.sol/USDC.dbg.json +4 -0
  100. package/artifacts/contracts/mock/Usdc.sol/USDC.json +338 -0
  101. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
  102. package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
  103. package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
  104. package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
  105. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
  106. package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +2 -2
  107. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  108. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +4 -95
  109. package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
  110. package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
  111. package/artifacts/contracts/registry/Registry.sol/Registerable.json +2 -2
  112. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/Registry.sol/Registry.json +14 -105
  114. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
  115. package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
  116. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
  117. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
  118. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
  119. package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
  120. package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
  121. package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
  122. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
  123. package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
  124. package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
  125. package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
  126. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
  127. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
  128. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
  129. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +37 -11
  130. package/contracts/components/Component.sol +24 -7
  131. package/contracts/components/IPool.sol +6 -0
  132. package/contracts/components/IProduct.sol +9 -2
  133. package/contracts/components/Pool.sol +34 -4
  134. package/contracts/components/Product.sol +38 -4
  135. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  136. package/contracts/experiment/statemachine/ISM.sol +25 -0
  137. package/contracts/experiment/statemachine/README.md +112 -0
  138. package/contracts/experiment/statemachine/SM.sol +57 -0
  139. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  140. package/contracts/instance/IInstance.sol +9 -2
  141. package/contracts/instance/Instance.sol +13 -5
  142. package/contracts/instance/component/ComponentModule.sol +99 -38
  143. package/contracts/instance/component/IComponent.sol +18 -17
  144. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  145. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  146. package/contracts/instance/policy/IPolicy.sol +8 -9
  147. package/contracts/instance/policy/PolicyModule.sol +32 -9
  148. package/contracts/instance/pool/IPoolModule.sol +2 -8
  149. package/contracts/instance/pool/PoolModule.sol +24 -16
  150. package/contracts/instance/product/IProductService.sol +1 -1
  151. package/contracts/instance/product/ProductService.sol +54 -30
  152. package/contracts/instance/treasury/ITreasury.sol +91 -0
  153. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  154. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  155. package/contracts/mock/Dip.sol +26 -0
  156. package/contracts/mock/TestPool.sol +16 -0
  157. package/contracts/mock/TestProduct.sol +39 -0
  158. package/contracts/mock/Usdc.sol +26 -0
  159. package/contracts/registry/IRegistry.sol +4 -17
  160. package/contracts/registry/Registry.sol +4 -31
  161. package/contracts/types/Fee.sol +32 -0
  162. package/contracts/types/ObjectType.sol +107 -0
  163. package/contracts/types/StateId.sol +91 -0
  164. package/contracts/types/UFixed.sol +19 -14
  165. package/package.json +10 -6
@@ -0,0 +1,112 @@
1
+ # State Machines
2
+
3
+ Most GIF objects have a life cycle defined by a state machine.
4
+
5
+ For each object type the set of possible states is defined together with its initial state and the set of valid state transitions.
6
+
7
+ ## Object Types without States
8
+
9
+ * Protocol
10
+ * Chains
11
+ * Registries (both chain and main registry)
12
+
13
+ ## Object Types with States
14
+
15
+ * Tokens
16
+ * Instances
17
+ * Products
18
+ * Oracles
19
+ * Pools
20
+ * Bundles
21
+ * Policies
22
+ * Claim (non-NFT)
23
+ * Payout (non-NFT)
24
+
25
+ ### Simple State Machine
26
+
27
+ Valid states
28
+
29
+ * Active (initial state)
30
+ * Paused
31
+ * Archived (final state)
32
+
33
+ Valid state transitions:
34
+
35
+ * Active -> Paused
36
+ * Paused -> Active
37
+ * Paused -> Archived
38
+
39
+
40
+ Candidate object types for simple state machine
41
+
42
+ * Token
43
+ * Instance
44
+ * Product
45
+ * Oracle
46
+ * Pool
47
+
48
+ To discuss:
49
+
50
+ * Archived is final state
51
+ * What mechanism should exist to revert an unintended transition to 'Archived' state. Should there be such a mechanism?
52
+ * What mechanism should exist when the NFT of such an object is burned prematurely. Should there be such a mechanism
53
+
54
+ ### Bundle State Machine
55
+
56
+ Valid states
57
+
58
+ * Active (initial state)
59
+ * Paused
60
+ * Expired (implicit state)
61
+ * Closed (final state)
62
+
63
+ Expired is not an explicit state.
64
+ A bundle is expired for block.timestamp >= expiredAt
65
+
66
+ ### Policy State Machine
67
+
68
+ Valid states
69
+
70
+ * Applied (initial state)
71
+ * Revoked (final state)
72
+ * Declined (final state)
73
+ * Active
74
+ * Expired (implicit state)
75
+ * Closed (final state)
76
+
77
+ Expired is not an explicit state.
78
+ A policy is expired for block.timestamp >= expiredAt
79
+
80
+ To discuss:
81
+
82
+ * Should 'Closed' be less explicit using a closedAt state variable?
83
+ * Or even more lighweight? ie. block.timestamp >= expiredAt and no open claims
84
+
85
+ Valid state transitions:
86
+
87
+ * Applied -> Revoked
88
+ * Applied -> Declined
89
+ * Applied -> Active
90
+ * Active -> Closed (needs to be expired)
91
+
92
+ ### Claim State Machine
93
+
94
+ Valid states
95
+ * Applied (initial state)
96
+ * Confirmed
97
+ * Declined (final state)
98
+ * Closed (final state)
99
+
100
+ Valid state transitions:
101
+ * Applied -> Confirmed
102
+ * Applied -> Declined
103
+ * Confirmed -> Closed
104
+
105
+ ### Payout State Machine
106
+
107
+ Valid states
108
+ * Expected
109
+ * PaidOut
110
+
111
+ Valid state transitions:
112
+ * Expected -> PaidOut
@@ -0,0 +1,57 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {StateId, toStateId, zeroStateId} from "../../types/StateId.sol";
5
+ import {ISM} from "./ISM.sol";
6
+
7
+ contract SM is ISM {
8
+ mapping(StateId currentState => mapping(StateId newState => bool isValid))
9
+ private _isValidTransition;
10
+
11
+ StateId internal _state;
12
+
13
+ function setInitialState(StateId initialStateId) internal {
14
+ if (initialStateId == zeroStateId()) {
15
+ revert ErrorInitialStateUndefined();
16
+ }
17
+
18
+ _state = initialStateId;
19
+ }
20
+
21
+ function addTransition(
22
+ StateId currentStateId,
23
+ StateId nextStateId
24
+ ) internal {
25
+ if (currentStateId == zeroStateId()) {
26
+ revert ErrorStartStateUndefined();
27
+ }
28
+
29
+ if (nextStateId == zeroStateId()) {
30
+ revert ErrorNextStateUndefined();
31
+ }
32
+
33
+ _isValidTransition[currentStateId][nextStateId] = true;
34
+ }
35
+
36
+ function changeToState(StateId newStateId) external override {
37
+ if (!_isValidTransition[_state][newStateId]) {
38
+ revert ErrorStateChangeInvalid(_state, newStateId);
39
+ }
40
+
41
+ StateId stateOld = _state;
42
+ _state = newStateId;
43
+
44
+ emit LogStateChanged(stateOld, _state);
45
+ }
46
+
47
+ function isValidTransition(
48
+ StateId currentStateId,
49
+ StateId newStateId
50
+ ) external view override returns (bool isValid) {
51
+ return _isValidTransition[currentStateId][newStateId];
52
+ }
53
+
54
+ function getState() external view override returns (StateId state) {
55
+ return _state;
56
+ }
57
+ }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {StateId, toStateId} from "../../types/StateId.sol";
5
+ import {SM} from "./SM.sol";
6
+
7
+ contract SimpleStateMachine is SM {
8
+ uint8 public constant STATE_ACTIVE = 10;
9
+ uint8 public constant STATE_PAUSED = 20;
10
+ uint8 public constant STATE_ARCHIVED = 30;
11
+
12
+ constructor() {
13
+ addTransition(ACTIVE(), PAUSED());
14
+ addTransition(PAUSED(), ACTIVE());
15
+ addTransition(PAUSED(), ARCHIVED());
16
+
17
+ setInitialState(ACTIVE());
18
+ }
19
+
20
+ function ACTIVE() public pure returns (StateId stateId) {
21
+ return toStateId(STATE_ACTIVE);
22
+ }
23
+
24
+ function PAUSED() public pure returns (StateId stateId) {
25
+ return toStateId(STATE_PAUSED);
26
+ }
27
+
28
+ function ARCHIVED() public pure returns (StateId stateId) {
29
+ return toStateId(STATE_ARCHIVED);
30
+ }
31
+ }
@@ -3,16 +3,23 @@ pragma solidity ^0.8.19;
3
3
 
4
4
  import {IRegisterable} from "../registry/IRegistry.sol";
5
5
  import {IAccessModule} from "./access/IAccess.sol";
6
+ import {ILifecycleModule} from "./lifecycle/ILifecycle.sol";
6
7
  import {IComponentModule} from "./component/IComponent.sol";
7
8
  import {IProductModule} from "./product/IProductService.sol";
8
9
  import {IPolicyModule} from "./policy/IPolicy.sol";
9
10
  import {IPoolModule} from "./pool/IPoolModule.sol";
11
+ import {ITreasuryModule} from "./treasury/ITreasury.sol";
10
12
 
13
+ // solhint-disable-next-line no-empty-blocks
11
14
  interface IInstance is
12
15
  IRegisterable,
13
16
  IAccessModule,
17
+ ILifecycleModule,
14
18
  IPolicyModule,
15
19
  IPoolModule,
16
20
  IComponentModule,
17
- IProductModule
18
- {}
21
+ IProductModule,
22
+ ITreasuryModule
23
+ {
24
+
25
+ }
@@ -5,21 +5,26 @@ import {Registerable} from "../registry/Registry.sol";
5
5
  import {IRegistry} from "../registry/IRegistry.sol";
6
6
 
7
7
  import {IAccessModule, AccessModule} from "./access/Access.sol";
8
+ import {LifecycleModule} from "./lifecycle/LifecycleModule.sol";
8
9
  import {ComponentModule} from "./component/ComponentModule.sol";
9
10
  import {ProductModule} from "./product/ProductService.sol";
10
11
  import {PolicyModule} from "./policy/PolicyModule.sol";
11
12
  import {PoolModule} from "./pool/PoolModule.sol";
13
+ import {TreasuryModule} from "./treasury/TreasuryModule.sol";
12
14
 
13
15
  import {IInstance} from "./IInstance.sol";
16
+ import {ObjectType, INSTANCE} from "../types/ObjectType.sol";
14
17
  import {NftId, toNftId} from "../types/NftId.sol";
15
18
 
16
19
  contract Instance is
17
20
  Registerable,
18
21
  AccessModule,
22
+ LifecycleModule,
19
23
  ComponentModule,
20
24
  PolicyModule,
21
25
  PoolModule,
22
26
  ProductModule,
27
+ TreasuryModule,
23
28
  IInstance
24
29
  {
25
30
  constructor(
@@ -33,7 +38,10 @@ contract Instance is
33
38
  PolicyModule(productService)
34
39
  ProductModule(productService)
35
40
  PoolModule(productService)
36
- {}
41
+ // solhint-disable-next-line no-empty-blocks
42
+ {
43
+
44
+ }
37
45
 
38
46
  // from registerable
39
47
  function register() external override returns (NftId nftId) {
@@ -45,7 +53,7 @@ contract Instance is
45
53
  }
46
54
 
47
55
  // from registerable
48
- function getParentNftId() public view override returns (NftId) {
56
+ function getParentNftId() public pure override returns (NftId) {
49
57
  // TODO add self registry and exchange 0 for_registry.getNftId();
50
58
  // define parent tree for all registerables
51
59
  // eg 0 <- chain(mainnet) <- global registry <- chain registry <- instance <- component <- policy/bundle
@@ -53,12 +61,12 @@ contract Instance is
53
61
  }
54
62
 
55
63
  // from registerable
56
- function getType() external view override returns (uint256 objectType) {
57
- return _registry.INSTANCE();
64
+ function getType() external pure override returns (ObjectType objectType) {
65
+ return INSTANCE();
58
66
  }
59
67
 
60
68
  // from registerable
61
- function getData() external view override returns (bytes memory data) {
69
+ function getData() external pure override returns (bytes memory data) {
62
70
  return bytes(abi.encode(0));
63
71
  }
64
72
  }
@@ -1,15 +1,24 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+
4
6
  import {RegistryLinked} from "../../registry/Registry.sol";
5
7
  import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
6
8
  import {IAccessComponentTypeRoles, IAccessCheckRole} from "../access/IAccess.sol";
7
9
  import {IInstance} from "../IInstance.sol";
8
10
 
11
+ import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
12
+ import {ITreasuryModule} from "../treasury/ITreasury.sol";
13
+ import {TreasuryModule} from "../treasury/TreasuryModule.sol";
9
14
  import {IComponent, IComponentContract, IComponentModule, IComponentOwnerService} from "./IComponent.sol";
10
15
  import {IProductComponent} from "../../components/IProduct.sol";
16
+ import {IPoolComponent} from "../../components/IPool.sol";
11
17
  import {IPoolModule} from "../pool/IPoolModule.sol";
12
- import {NftId, NftIdLib} from "../../types/NftId.sol";
18
+ import {ObjectType, PRODUCT, ORACLE, POOL} from "../../types/ObjectType.sol";
19
+ import {StateId, ACTIVE, PAUSED} from "../../types/StateId.sol";
20
+ import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
21
+ import {Fee, zeroFee} from "../../types/Fee.sol";
13
22
 
14
23
  abstract contract ComponentModule is
15
24
  IRegistryLinked,
@@ -20,12 +29,15 @@ abstract contract ComponentModule is
20
29
  using NftIdLib for NftId;
21
30
 
22
31
  mapping(NftId nftId => ComponentInfo info) private _componentInfo;
23
- mapping(NftId nftId => NftId poolNftId) private _poolNftIdForProduct;
24
32
  mapping(address cAddress => NftId nftId) private _nftIdByAddress;
25
33
  NftId[] private _nftIds;
26
34
 
27
- mapping(uint256 cType => bytes32 role) private _componentOwnerRole;
35
+ mapping(ObjectType cType => bytes32 role) private _componentOwnerRole;
28
36
 
37
+ // TODO maybe move this to Instance contract as internal variable?
38
+ LifecycleModule private _lifecycleModule;
39
+ TreasuryModule private _treasuryModule;
40
+ IPoolModule private _poolModule;
29
41
  IComponentOwnerService private _componentOwnerService;
30
42
 
31
43
  modifier onlyComponentOwnerService() {
@@ -37,51 +49,73 @@ abstract contract ComponentModule is
37
49
  }
38
50
 
39
51
  constructor(address componentOwnerService) {
52
+ address componentAddress = address(this);
53
+ _lifecycleModule = LifecycleModule(componentAddress);
54
+ _treasuryModule = TreasuryModule(componentAddress);
55
+ _poolModule = IPoolModule(componentAddress);
40
56
  _componentOwnerService = ComponentOwnerService(componentOwnerService);
41
57
  }
42
58
 
43
59
  function registerComponent(
44
60
  IComponentContract component
45
61
  ) external override onlyComponentOwnerService returns (NftId nftId) {
46
- bytes32 typeRole = getRoleForType(component.getType());
62
+ ObjectType objectType = component.getType();
63
+ bytes32 typeRole = getRoleForType(objectType);
47
64
  require(
48
65
  this.hasRole(typeRole, component.getInitialOwner()),
49
66
  "ERROR:CMP-004:TYPE_ROLE_MISSING"
50
67
  );
51
68
 
52
69
  nftId = this.getRegistry().register(address(component));
70
+ IERC20Metadata token = component.getToken();
71
+ address wallet = component.getWallet();
72
+
73
+ // create component info
74
+ _componentInfo[nftId] = ComponentInfo(
75
+ nftId,
76
+ _lifecycleModule.getInitialState(objectType),
77
+ token
78
+ );
53
79
 
54
- _componentInfo[nftId] = ComponentInfo(nftId, CState.Active);
55
-
56
- // special case product -> persist product - pool assignment
57
- if (component.getType() == this.getRegistry().PRODUCT()) {
80
+ // component type specific registration actions
81
+ if (component.getType() == PRODUCT()) {
58
82
  IProductComponent product = IProductComponent(address(component));
59
83
  NftId poolNftId = product.getPoolNftId();
60
84
  require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
61
- // add more validation (type, token, ...)
85
+ // validate pool token and product token are same
62
86
 
63
- _poolNftIdForProduct[nftId] = poolNftId;
87
+ // register with tresury
88
+ // implement and add validation
89
+ NftId distributorNftId = zeroNftId();
90
+ _treasuryModule.registerProduct(
91
+ nftId,
92
+ distributorNftId,
93
+ poolNftId,
94
+ token,
95
+ wallet,
96
+ product.getPolicyFee(),
97
+ product.getProcessingFee()
98
+ );
99
+ } else if (component.getType() == POOL()) {
100
+ IPoolComponent pool = IPoolComponent(address(component));
64
101
 
65
- // add creation of productInfo
66
- } else if (component.getType() == this.getRegistry().POOL()) {
67
- IPoolModule poolModule = IPoolModule(address(this));
68
- poolModule.createPoolInfo(
102
+ // register with pool
103
+ _poolModule.registerPool(nftId);
104
+
105
+ // register with tresury
106
+ _treasuryModule.registerPool(
69
107
  nftId,
70
- address(component), // set pool as its wallet
71
- address(0) // don't deal with token yet
108
+ wallet,
109
+ pool.getStakingFee(),
110
+ pool.getPerformanceFee()
72
111
  );
73
112
  }
113
+ // TODO add distribution
74
114
 
75
115
  _nftIdByAddress[address(component)] = nftId;
76
116
  _nftIds.push(nftId);
77
117
 
78
- // add logging
79
- }
80
-
81
- function getPoolNftId(
82
- NftId productNftId
83
- ) external view override returns (NftId poolNftId) {
84
- poolNftId = _poolNftIdForProduct[productNftId];
118
+ // TODO add loggingx
85
119
  }
86
120
 
87
121
  function getComponentOwnerService()
@@ -102,9 +136,17 @@ abstract contract ComponentModule is
102
136
  "ERROR:CMP-006:COMPONENT_UNKNOWN"
103
137
  );
104
138
 
139
+ // TODO decide if state changes should have explicit functions and not
140
+ // just a generic setXYZInfo and implicit state transitions
141
+ // when in doubt go for the explicit approach ...
142
+ ObjectType objectType = this.getRegistry().getInfo(nftId).objectType;
143
+ _lifecycleModule.checkAndLogTransition(
144
+ nftId,
145
+ objectType,
146
+ _componentInfo[nftId].state,
147
+ info.state
148
+ );
105
149
  _componentInfo[nftId] = info;
106
-
107
- // add logging
108
150
  }
109
151
 
110
152
  function getComponentInfo(
@@ -113,10 +155,6 @@ abstract contract ComponentModule is
113
155
  return _componentInfo[nftId];
114
156
  }
115
157
 
116
- function getComponentOwner(
117
- NftId nftId
118
- ) external view returns (address owner) {}
119
-
120
158
  function getComponentId(
121
159
  address componentAddress
122
160
  ) external view returns (NftId componentNftId) {
@@ -138,14 +176,16 @@ abstract contract ComponentModule is
138
176
  return _nftIds.length;
139
177
  }
140
178
 
141
- function getRoleForType(uint256 cType) public view returns (bytes32 role) {
142
- if (cType == this.getRegistry().PRODUCT()) {
179
+ function getRoleForType(
180
+ ObjectType cType
181
+ ) public view returns (bytes32 role) {
182
+ if (cType == PRODUCT()) {
143
183
  return this.PRODUCT_OWNER_ROLE();
144
184
  }
145
- if (cType == this.getRegistry().POOL()) {
185
+ if (cType == POOL()) {
146
186
  return this.POOL_OWNER_ROLE();
147
187
  }
148
- if (cType == this.getRegistry().ORACLE()) {
188
+ if (cType == ORACLE()) {
149
189
  return this.ORACLE_OWNER_ROLE();
150
190
  }
151
191
  }
@@ -169,7 +209,12 @@ contract ComponentOwnerService is
169
209
  _;
170
210
  }
171
211
 
172
- constructor(address registry) RegistryLinked(registry) {}
212
+ constructor(
213
+ address registry
214
+ ) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
215
+ {
216
+
217
+ }
173
218
 
174
219
  function register(
175
220
  IComponentContract component
@@ -191,9 +236,9 @@ contract ComponentOwnerService is
191
236
  component.getNftId()
192
237
  );
193
238
  require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
194
- // TODO add state change validation
195
239
 
196
- info.state = CState.Locked;
240
+ info.state = PAUSED();
241
+ // setComponentInfo checks for valid state changes
197
242
  instance.setComponentInfo(info);
198
243
  }
199
244
 
@@ -205,9 +250,25 @@ contract ComponentOwnerService is
205
250
  component.getNftId()
206
251
  );
207
252
  require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
208
- // TODO state change validation
209
253
 
210
- info.state = CState.Active;
254
+ info.state = ACTIVE();
255
+ // setComponentInfo checks for valid state changes
211
256
  instance.setComponentInfo(info);
212
257
  }
258
+
259
+ function setProductFees(
260
+ IComponentContract product,
261
+ Fee memory policyFee,
262
+ Fee memory processingFee
263
+ ) external override onlyComponentOwner(product) {
264
+ require(product.getType() == PRODUCT(), "ERROR_NOT_PRODUCT");
265
+
266
+ address instanceAddress = address(product.getInstance());
267
+ ITreasuryModule treasuryModule = ITreasuryModule(instanceAddress);
268
+ treasuryModule.setProductFees(
269
+ product.getNftId(),
270
+ policyFee,
271
+ processingFee
272
+ );
273
+ }
213
274
  }
@@ -1,22 +1,21 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  pragma solidity ^0.8.19;
3
3
 
4
+ import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
+
4
6
  import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
5
7
  import {IInstance} from "../IInstance.sol";
8
+ import {StateId} from "../../types/StateId.sol";
6
9
  import {NftId} from "../../types/NftId.sol";
10
+ import {Fee} from "../../types/Fee.sol";
11
+ import {UFixed} from "../../types/UFixed.sol";
7
12
 
8
13
  interface IComponent {
9
- // TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
10
- enum CState {
11
- Undefined,
12
- Active,
13
- Locked
14
- }
15
-
16
14
  // component dynamic info (static info kept in registry)
17
15
  struct ComponentInfo {
18
16
  NftId nftId;
19
- CState state;
17
+ StateId state;
18
+ IERC20Metadata token;
20
19
  }
21
20
  }
22
21
 
@@ -25,7 +24,11 @@ interface IInstanceLinked {
25
24
  function getInstance() external view returns (IInstance instance);
26
25
  }
27
26
 
28
- interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {}
27
+ interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {
28
+ function getToken() external view returns (IERC20Metadata token);
29
+
30
+ function getWallet() external view returns (address walletAddress);
31
+ }
29
32
 
30
33
  interface IComponentOwnerService is IRegistryLinked {
31
34
  function register(
@@ -35,6 +38,12 @@ interface IComponentOwnerService is IRegistryLinked {
35
38
  function lock(IComponentContract component) external;
36
39
 
37
40
  function unlock(IComponentContract component) external;
41
+
42
+ function setProductFees(
43
+ IComponentContract product,
44
+ Fee memory policyFee,
45
+ Fee memory processingFee
46
+ ) external;
38
47
  }
39
48
 
40
49
  interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
@@ -50,20 +59,12 @@ interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
50
59
  NftId nftId
51
60
  ) external view returns (ComponentInfo memory info);
52
61
 
53
- function getComponentOwner(
54
- NftId nftId
55
- ) external view returns (address owner);
56
-
57
62
  function getComponentId(
58
63
  address componentAddress
59
64
  ) external view returns (NftId nftId);
60
65
 
61
66
  function getComponentId(uint256 idx) external view returns (NftId nftId);
62
67
 
63
- function getPoolNftId(
64
- NftId productNftId
65
- ) external view returns (NftId poolNftId);
66
-
67
68
  function components() external view returns (uint256 numberOfCompnents);
68
69
 
69
70
  function getComponentOwnerService()
@@ -0,0 +1,47 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.19;
3
+
4
+ import {ObjectType} from "../../types/ObjectType.sol";
5
+ import {StateId, toStateId, zeroStateId} from "../../types/StateId.sol";
6
+ import {NftId} from "../../types/NftId.sol";
7
+
8
+ interface ILifecycle {
9
+ event LogComponentStateChanged(
10
+ NftId nftId,
11
+ ObjectType objectType,
12
+ StateId fromStateId,
13
+ StateId toStateId
14
+ );
15
+ event LogBundleStateChanged(
16
+ NftId nftId,
17
+ StateId fromStateId,
18
+ StateId toStateId
19
+ );
20
+ event LogPolicyStateChanged(
21
+ NftId nftId,
22
+ StateId fromStateId,
23
+ StateId toStateId
24
+ );
25
+ // event LogClaimStateChanged(NftId nftId, ClaimId claimId, StateId fromStateId, StateId toStateId);
26
+ // event LogPayoutStateChanged(NftId nftId, ClaimId claimId, PayoutId payoutId, StateId fromStateId, StateId toStateId);
27
+
28
+ error ErrorNoLifecycle(NftId nftId, ObjectType objectType);
29
+ error ErrorInvalidStateTransition(
30
+ NftId nftId,
31
+ ObjectType objectType,
32
+ StateId fromStateId,
33
+ StateId toStateId
34
+ );
35
+ }
36
+
37
+ interface ILifecycleModule is ILifecycle {
38
+ function getInitialState(
39
+ ObjectType objectType
40
+ ) external view returns (StateId);
41
+
42
+ function isValidTransition(
43
+ ObjectType objectType,
44
+ StateId fromId,
45
+ StateId toId
46
+ ) external view returns (bool);
47
+ }