@etherisc/gif-next 0.0.2-ed4dd55 → 0.0.2-f74fcad-685

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. package/README.md +33 -0
  2. package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
  3. package/artifacts/contracts/components/Component.sol/Component.json +35 -9
  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 +84 -8
  8. package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
  9. package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +34 -152
  10. package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
  11. package/artifacts/contracts/components/Pool.sol/Pool.json +146 -13
  12. package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
  13. package/artifacts/contracts/components/Product.sol/Product.json +148 -15
  14. package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
  15. package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
  16. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
  17. package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
  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 +714 -127
  44. package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
  45. package/artifacts/contracts/instance/Instance.sol/Instance.json +845 -129
  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 +31 -59
  53. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
  54. package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +103 -6
  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 +34 -8
  58. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
  59. package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +31 -59
  60. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
  61. package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +50 -3
  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 +44 -21
  72. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
  73. package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +44 -21
  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 +23 -43
  77. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
  78. package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +28 -35
  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 +21 -8
  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 +85 -14
  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 +8 -8
  107. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
  108. package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +20 -111
  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 +9 -9
  112. package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
  113. package/artifacts/contracts/registry/Registry.sol/Registry.json +66 -115
  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 +4 -0
  117. package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
  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 +85 -3
  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 +4 -0
  127. package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
  128. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
  129. package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +479 -0
  130. package/contracts/components/Component.sol +39 -24
  131. package/contracts/components/IPool.sol +9 -3
  132. package/contracts/components/IProduct.sol +11 -6
  133. package/contracts/components/Pool.sol +37 -14
  134. package/contracts/components/Product.sol +48 -24
  135. package/contracts/experiment/errors/Require.sol +38 -0
  136. package/contracts/experiment/errors/Revert.sol +44 -0
  137. package/contracts/experiment/inheritance/A.sol +8 -11
  138. package/contracts/experiment/inheritance/B.sol +10 -5
  139. package/contracts/experiment/inheritance/C.sol +11 -5
  140. package/contracts/experiment/inheritance/IA.sol +2 -7
  141. package/contracts/experiment/inheritance/IB.sol +3 -2
  142. package/contracts/experiment/inheritance/IC.sol +4 -3
  143. package/contracts/experiment/statemachine/Dummy.sol +27 -0
  144. package/contracts/experiment/statemachine/ISM.sol +25 -0
  145. package/contracts/experiment/statemachine/README.md +112 -0
  146. package/contracts/experiment/statemachine/SM.sol +57 -0
  147. package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
  148. package/contracts/experiment/types/TypeA.sol +14 -9
  149. package/contracts/experiment/types/TypeB.sol +14 -9
  150. package/contracts/instance/IInstance.sol +8 -3
  151. package/contracts/instance/Instance.sol +24 -15
  152. package/contracts/instance/access/Access.sol +63 -116
  153. package/contracts/instance/access/IAccess.sol +28 -48
  154. package/contracts/instance/component/ComponentModule.sol +162 -147
  155. package/contracts/instance/component/IComponent.sol +41 -61
  156. package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
  157. package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
  158. package/contracts/instance/policy/IPolicy.sol +19 -35
  159. package/contracts/instance/policy/PolicyModule.sol +52 -44
  160. package/contracts/instance/pool/IPoolModule.sol +9 -26
  161. package/contracts/instance/pool/PoolModule.sol +43 -45
  162. package/contracts/instance/product/IProductService.sol +10 -19
  163. package/contracts/instance/product/ProductService.sol +86 -55
  164. package/contracts/instance/treasury/ITreasury.sol +91 -0
  165. package/contracts/instance/treasury/TokenHandler.sol +24 -0
  166. package/contracts/instance/treasury/TreasuryModule.sol +168 -0
  167. package/contracts/mock/Dip.sol +26 -0
  168. package/contracts/mock/TestPool.sol +16 -0
  169. package/contracts/mock/TestProduct.sol +39 -0
  170. package/contracts/mock/Usdc.sol +26 -0
  171. package/contracts/registry/ChainNft.sol +23 -61
  172. package/contracts/registry/IChainNft.sol +10 -7
  173. package/contracts/registry/IRegistry.sol +40 -41
  174. package/contracts/registry/Registry.sol +73 -67
  175. package/contracts/types/Blocknumber.sol +118 -0
  176. package/contracts/types/ChainId.sol +24 -10
  177. package/contracts/types/Fee.sol +32 -0
  178. package/contracts/types/NftId.sol +36 -10
  179. package/contracts/types/ObjectType.sol +107 -0
  180. package/contracts/types/StateId.sol +91 -0
  181. package/contracts/types/Timestamp.sol +102 -0
  182. package/contracts/types/UFixed.sol +210 -0
  183. package/package.json +14 -5
@@ -4,7 +4,6 @@ pragma solidity ^0.8.19;
4
4
  import {IOwnable, IRegistryLinked} from "../../registry/IRegistry.sol";
5
5
 
6
6
  interface IAccess {
7
-
8
7
  struct RoleInfo {
9
8
  bytes32 id;
10
9
  string name;
@@ -13,71 +12,52 @@ interface IAccess {
13
12
  }
14
13
 
15
14
  interface IAccessCheckRole {
16
-
17
- function hasRole(bytes32 role, address member)
18
- external
19
- view
20
- returns(bool);
15
+ function hasRole(bytes32 role, address member) external view returns (bool);
21
16
  }
22
17
 
23
18
  interface IAccessComponentTypeRoles {
24
- function PRODUCT_OWNER_ROLE() external view returns(bytes32 role);
25
- function ORACLE_OWNER_ROLE() external view returns(bytes32 role);
26
- function POOL_OWNER_ROLE() external view returns(bytes32 role);
27
- }
19
+ function PRODUCT_OWNER_ROLE() external view returns (bytes32 role);
28
20
 
21
+ function ORACLE_OWNER_ROLE() external view returns (bytes32 role);
29
22
 
30
- interface IAccessModule is
23
+ function POOL_OWNER_ROLE() external view returns (bytes32 role);
24
+ }
25
+
26
+ interface IAccessModule is
31
27
  IOwnable,
32
28
  IRegistryLinked,
33
29
  IAccess,
34
30
  IAccessComponentTypeRoles,
35
31
  IAccessCheckRole
36
32
  {
33
+ function createRole(string memory roleName) external returns (bytes32 role);
37
34
 
38
- function createRole(string memory roleName)
39
- external
40
- returns(bytes32 role);
41
-
42
- function enableRole(bytes32 role)
43
- external;
35
+ function enableRole(bytes32 role) external;
44
36
 
45
- function disableRole(bytes32 role)
46
- external;
37
+ function disableRole(bytes32 role) external;
47
38
 
48
- function grantRole(bytes32 role, address member)
49
- external;
39
+ function grantRole(bytes32 role, address member) external;
50
40
 
51
- function revokeRole(bytes32 role, address member)
52
- external;
41
+ function revokeRole(bytes32 role, address member) external;
53
42
 
54
- function getRole(uint256 idx)
55
- external
56
- view
57
- returns(bytes32 role);
43
+ function getRole(uint256 idx) external view returns (bytes32 role);
58
44
 
59
- function getRoleInfo(bytes32 role)
60
- external
61
- view
62
- returns(RoleInfo memory info);
45
+ function getRoleInfo(
46
+ bytes32 role
47
+ ) external view returns (RoleInfo memory info);
63
48
 
64
- function getRoleForName(string memory roleName)
65
- external
66
- pure
67
- returns(bytes32 role);
49
+ function getRoleForName(
50
+ string memory roleName
51
+ ) external pure returns (bytes32 role);
68
52
 
69
- function getRoleCount()
70
- external
71
- view
72
- returns(uint256 roles);
53
+ function getRoleCount() external view returns (uint256 roles);
73
54
 
74
- function getRoleMemberCount(bytes32 role)
75
- external
76
- view
77
- returns(uint256 roleMembers);
55
+ function getRoleMemberCount(
56
+ bytes32 role
57
+ ) external view returns (uint256 roleMembers);
78
58
 
79
- function getRoleMember(bytes32 role, uint256 idx)
80
- external
81
- view
82
- returns(address roleMembers);
83
- }
59
+ function getRoleMember(
60
+ bytes32 role,
61
+ uint256 idx
62
+ ) external view returns (address roleMembers);
63
+ }
@@ -1,194 +1,207 @@
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";
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";
12
22
 
13
-
14
- abstract contract ComponentModule is
23
+ abstract contract ComponentModule is
15
24
  IRegistryLinked,
16
25
  IAccessComponentTypeRoles,
17
26
  IAccessCheckRole,
18
27
  IComponentModule
19
28
  {
29
+ using NftIdLib for NftId;
20
30
 
21
- mapping(uint256 nftId => ComponentInfo info) private _componentInfo;
22
- mapping(uint256 nftId => uint256 poolNftId) private _poolNftIdForProduct;
23
- mapping(address cAddress => uint256 id) private _idByAddress;
24
- uint256 [] private _ids;
31
+ mapping(NftId nftId => ComponentInfo info) private _componentInfo;
32
+ mapping(address cAddress => NftId nftId) private _nftIdByAddress;
33
+ NftId[] private _nftIds;
25
34
 
26
- mapping(uint256 cType => bytes32 role) private _componentOwnerRole;
35
+ mapping(ObjectType cType => bytes32 role) private _componentOwnerRole;
27
36
 
37
+ // TODO maybe move this to Instance contract as internal variable?
38
+ LifecycleModule private _lifecycleModule;
39
+ TreasuryModule private _treasuryModule;
40
+ IPoolModule private _poolModule;
28
41
  IComponentOwnerService private _componentOwnerService;
29
42
 
30
43
  modifier onlyComponentOwnerService() {
31
- require(address(_componentOwnerService) == msg.sender, "ERROR:CMP-001:NOT_OWNER_SERVICE");
44
+ require(
45
+ address(_componentOwnerService) == msg.sender,
46
+ "ERROR:CMP-001:NOT_OWNER_SERVICE"
47
+ );
32
48
  _;
33
49
  }
34
50
 
35
51
  constructor(address componentOwnerService) {
52
+ address componentAddress = address(this);
53
+ _lifecycleModule = LifecycleModule(componentAddress);
54
+ _treasuryModule = TreasuryModule(componentAddress);
55
+ _poolModule = IPoolModule(componentAddress);
36
56
  _componentOwnerService = ComponentOwnerService(componentOwnerService);
37
57
  }
38
58
 
39
- function registerComponent(IComponentContract component)
40
- external
41
- override
42
- onlyComponentOwnerService
43
- returns(uint256 nftId)
44
- {
45
- bytes32 typeRole = getRoleForType(component.getType());
59
+ function registerComponent(
60
+ IComponentContract component
61
+ ) external override onlyComponentOwnerService returns (NftId nftId) {
62
+ ObjectType objectType = component.getType();
63
+ bytes32 typeRole = getRoleForType(objectType);
46
64
  require(
47
65
  this.hasRole(typeRole, component.getInitialOwner()),
48
- "ERROR:CMP-004:TYPE_ROLE_MISSING");
49
-
66
+ "ERROR:CMP-004:TYPE_ROLE_MISSING"
67
+ );
68
+
50
69
  nftId = this.getRegistry().register(address(component));
70
+ IERC20Metadata token = component.getToken();
71
+ address wallet = component.getWallet();
51
72
 
73
+ // create component info
52
74
  _componentInfo[nftId] = ComponentInfo(
53
75
  nftId,
54
- CState.Active);
76
+ _lifecycleModule.getInitialState(objectType),
77
+ token
78
+ );
55
79
 
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
- uint256 poolNftId = product.getPoolNftId();
60
- require(poolNftId > 0, "ERROR:CMP-005:POOL_UNKNOWN");
61
- // add more validation (type, token, ...)
83
+ NftId poolNftId = product.getPoolNftId();
84
+ require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
85
+ // validate pool token and product token are same
86
+
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));
62
101
 
63
- _poolNftIdForProduct[nftId] = poolNftId;
102
+ // register with pool
103
+ _poolModule.registerPool(nftId);
64
104
 
65
- // add creation of productInfo
66
- }
67
- else if(component.getType() == this.getRegistry().POOL()) {
68
- IPoolModule poolModule = IPoolModule(address(this));
69
- poolModule.createPoolInfo(
105
+ // register with tresury
106
+ _treasuryModule.registerPool(
70
107
  nftId,
71
- address(component), // set pool as its wallet
72
- address(0) // don't deal with token yet
108
+ wallet,
109
+ pool.getStakingFee(),
110
+ pool.getPerformanceFee()
73
111
  );
74
112
  }
113
+ // TODO add distribution
75
114
 
76
- _idByAddress[address(component)] = nftId;
77
- _ids.push(nftId);
78
-
79
- // add logging
80
- }
115
+ _nftIdByAddress[address(component)] = nftId;
116
+ _nftIds.push(nftId);
81
117
 
82
- function getPoolNftId(uint256 productNftId)
83
- external
84
- view
85
- override
86
- returns(uint256 poolNftId)
87
- {
88
- poolNftId = _poolNftIdForProduct[productNftId];
118
+ // TODO add loggingx
89
119
  }
90
120
 
91
-
92
121
  function getComponentOwnerService()
93
122
  external
94
- override
95
123
  view
96
- returns(IComponentOwnerService)
124
+ override
125
+ returns (IComponentOwnerService)
97
126
  {
98
127
  return _componentOwnerService;
99
128
  }
100
129
 
101
- function setComponentInfo(ComponentInfo memory info)
102
- external
103
- onlyComponentOwnerService
104
- returns(uint256 nftId)
105
- {
106
- uint256 id = info.nftId;
130
+ function setComponentInfo(
131
+ ComponentInfo memory info
132
+ ) external onlyComponentOwnerService returns (NftId nftId) {
133
+ nftId = info.nftId;
107
134
  require(
108
- id > 0 && _componentInfo[id].nftId == id,
109
- "ERROR:CMP-005:COMPONENT_UNKNOWN");
110
-
111
- _componentInfo[id] = info;
135
+ nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
136
+ "ERROR:CMP-006:COMPONENT_UNKNOWN"
137
+ );
112
138
 
113
- // add logging
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
+ );
149
+ _componentInfo[nftId] = info;
114
150
  }
115
151
 
116
- function getComponentInfo(uint256 id)
117
- external
118
- override
119
- view
120
- returns(ComponentInfo memory)
121
- {
122
- return _componentInfo[id];
152
+ function getComponentInfo(
153
+ NftId nftId
154
+ ) external view override returns (ComponentInfo memory) {
155
+ return _componentInfo[nftId];
123
156
  }
124
157
 
125
- function getComponentOwner(uint256 id)
126
- external
127
- view
128
- returns(address owner)
129
- {
130
-
158
+ function getComponentId(
159
+ address componentAddress
160
+ ) external view returns (NftId componentNftId) {
161
+ return _nftIdByAddress[componentAddress];
131
162
  }
132
163
 
133
- function getComponentId(address componentAddress)
134
- external
135
- view
136
- returns(uint256 id)
137
- {
138
- return _idByAddress[componentAddress];
139
- }
140
-
141
-
142
- function getComponentId(uint256 idx)
143
- external
144
- override
145
- view
146
- returns(uint256 id)
147
- {
148
- return _ids[idx];
164
+ function getComponentId(
165
+ uint256 idx
166
+ ) external view override returns (NftId componentNftId) {
167
+ return _nftIds[idx];
149
168
  }
150
169
 
151
-
152
170
  function components()
153
171
  external
154
- override
155
172
  view
156
- returns(uint256 numberOfCompnents)
173
+ override
174
+ returns (uint256 numberOfCompnents)
157
175
  {
158
- return _ids.length;
176
+ return _nftIds.length;
159
177
  }
160
178
 
161
- function getRoleForType(uint256 cType)
162
- public
163
- view
164
- returns(bytes32 role)
165
- {
166
- if(cType == this.getRegistry().PRODUCT()) {
179
+ function getRoleForType(
180
+ ObjectType cType
181
+ ) public view returns (bytes32 role) {
182
+ if (cType == PRODUCT()) {
167
183
  return this.PRODUCT_OWNER_ROLE();
168
184
  }
169
- if(cType == this.getRegistry().POOL()) {
185
+ if (cType == POOL()) {
170
186
  return this.POOL_OWNER_ROLE();
171
187
  }
172
- if(cType == this.getRegistry().ORACLE()) {
188
+ if (cType == ORACLE()) {
173
189
  return this.ORACLE_OWNER_ROLE();
174
190
  }
175
-
176
191
  }
177
192
  }
178
193
 
179
-
180
194
  // this is actually the component owner service
181
195
  contract ComponentOwnerService is
182
196
  RegistryLinked,
183
197
  IComponent,
184
198
  IComponentOwnerService
185
199
  {
200
+ using NftIdLib for NftId;
186
201
 
187
202
  modifier onlyComponentOwner(IComponentContract component) {
188
- uint256 nftId = _registry.getNftId(address(component));
189
- require(
190
- nftId > 0,
191
- "ERROR:COS-001:COMPONENT_UNKNOWN");
203
+ NftId nftId = _registry.getNftId(address(component));
204
+ require(nftId.gtz(), "ERROR:COS-001:COMPONENT_UNKNOWN");
192
205
  require(
193
206
  msg.sender == _registry.getOwner(nftId),
194
207
  "ERROR:COS-002:NOT_OWNER"
@@ -196,64 +209,66 @@ contract ComponentOwnerService is
196
209
  _;
197
210
  }
198
211
 
199
- constructor(address registry)
200
- RegistryLinked(registry)
201
- { }
202
-
203
-
204
- // modifier onlyComponentOwnerRole(IComponentContract component) {
205
- // IInstance instance = component.getInstance();
206
- // // TODO add set/getComponentOwnerRole to IComonentModule
207
- // bytes32 typeRole = instance.getComponentTypeRole(component.getType());
208
- // require(
209
- // instance.hasRole(typeRole, msg.sender),
210
- // "ERROR:COS-003:COMPONENT_ROLE_MISSING"
211
- // );
212
- // _;
213
- // }
212
+ constructor(
213
+ address registry
214
+ ) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
215
+ {
214
216
 
217
+ }
215
218
 
216
- function register(IComponentContract component)
217
- external
218
- override
219
- returns(uint256 nftId)
220
- {
219
+ function register(
220
+ IComponentContract component
221
+ ) external override returns (NftId nftId) {
221
222
  require(
222
- msg.sender == component.getInitialOwner(),
223
- "ERROR:COS-003:NOT_OWNER");
223
+ msg.sender == component.getInitialOwner(),
224
+ "ERROR:COS-003:NOT_OWNER"
225
+ );
224
226
 
225
227
  IInstance instance = component.getInstance();
226
228
  nftId = instance.registerComponent(component);
227
229
  }
228
230
 
229
-
230
- function lock(IComponentContract component)
231
- external
232
- override
233
- onlyComponentOwner(component)
234
- {
231
+ function lock(
232
+ IComponentContract component
233
+ ) external override onlyComponentOwner(component) {
235
234
  IInstance instance = component.getInstance();
236
- ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
237
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
238
- // TODO add state change validation
235
+ ComponentInfo memory info = instance.getComponentInfo(
236
+ component.getNftId()
237
+ );
238
+ require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
239
239
 
240
- info.state = CState.Locked;
240
+ info.state = PAUSED();
241
+ // setComponentInfo checks for valid state changes
241
242
  instance.setComponentInfo(info);
242
243
  }
243
244
 
244
-
245
- function unlock(IComponentContract component)
246
- external
247
- override
248
- onlyComponentOwner(component)
249
- {
245
+ function unlock(
246
+ IComponentContract component
247
+ ) external override onlyComponentOwner(component) {
250
248
  IInstance instance = component.getInstance();
251
- ComponentInfo memory info = instance.getComponentInfo(component.getNftId());
252
- require(info.nftId > 0, "ERROR_COMPONENT_UNKNOWN");
253
- // TODO state change validation
249
+ ComponentInfo memory info = instance.getComponentInfo(
250
+ component.getNftId()
251
+ );
252
+ require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
254
253
 
255
- info.state = CState.Active;
254
+ info.state = ACTIVE();
255
+ // setComponentInfo checks for valid state changes
256
256
  instance.setComponentInfo(info);
257
257
  }
258
258
 
259
- }
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
+ }
274
+ }
@@ -1,94 +1,74 @@
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";
4
5
 
5
6
  import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
6
7
  import {IInstance} from "../IInstance.sol";
8
+ import {StateId} from "../../types/StateId.sol";
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
-
10
- // TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
11
- enum CState {
12
- Undefined,
13
- Active,
14
- Locked
15
- }
16
-
17
14
  // component dynamic info (static info kept in registry)
18
15
  struct ComponentInfo {
19
- uint256 nftId;
20
- CState state;
16
+ NftId nftId;
17
+ StateId state;
18
+ IERC20Metadata token;
21
19
  }
22
20
  }
23
21
 
24
-
25
22
  interface IInstanceLinked {
26
23
  // function setInstance(address instance) external;
27
- function getInstance() external view returns(IInstance instance);
24
+ function getInstance() external view returns (IInstance instance);
28
25
  }
29
26
 
27
+ interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {
28
+ function getToken() external view returns (IERC20Metadata token);
30
29
 
31
- interface IComponentContract is
32
- IRegisterable,
33
- IInstanceLinked,
34
- IComponent
35
- { }
36
-
30
+ function getWallet() external view returns (address walletAddress);
31
+ }
37
32
 
38
- interface IComponentOwnerService is IRegistryLinked{
33
+ interface IComponentOwnerService is IRegistryLinked {
34
+ function register(
35
+ IComponentContract component
36
+ ) external returns (NftId nftId);
39
37
 
40
- function register(IComponentContract component) external returns(uint256 id);
41
38
  function lock(IComponentContract component) external;
39
+
42
40
  function unlock(IComponentContract component) external;
41
+
42
+ function setProductFees(
43
+ IComponentContract product,
44
+ Fee memory policyFee,
45
+ Fee memory processingFee
46
+ ) external;
43
47
  }
44
48
 
49
+ interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
50
+ function registerComponent(
51
+ IComponentContract component
52
+ ) external returns (NftId nftId);
45
53
 
46
- interface IComponentModule is
47
- IOwnable,
48
- IRegistryLinked,
49
- IComponent
50
- {
54
+ function setComponentInfo(
55
+ ComponentInfo memory info
56
+ ) external returns (NftId componentNftId);
51
57
 
52
- function registerComponent(IComponentContract component)
53
- external
54
- returns(uint256 nftInfo);
58
+ function getComponentInfo(
59
+ NftId nftId
60
+ ) external view returns (ComponentInfo memory info);
55
61
 
56
- function setComponentInfo(ComponentInfo memory info)
57
- external
58
- returns(uint256 componentId);
62
+ function getComponentId(
63
+ address componentAddress
64
+ ) external view returns (NftId nftId);
59
65
 
60
- function getComponentInfo(uint256 id)
61
- external
62
- view
63
- returns(ComponentInfo memory info);
66
+ function getComponentId(uint256 idx) external view returns (NftId nftId);
64
67
 
65
- function getComponentOwner(uint256 id)
66
- external
67
- view
68
- returns(address owner);
69
-
70
- function getComponentId(address componentAddress)
71
- external
72
- view
73
- returns(uint256 id);
74
-
75
- function getComponentId(uint256 idx)
76
- external
77
- view
78
- returns(uint256 id);
79
-
80
- function getPoolNftId(uint256 productNftId)
81
- external
82
- view
83
- returns(uint256 poolNftId);
84
-
85
- function components()
86
- external
87
- view
88
- returns(uint256 numberOfCompnents);
68
+ function components() external view returns (uint256 numberOfCompnents);
89
69
 
90
70
  function getComponentOwnerService()
91
71
  external
92
72
  view
93
- returns(IComponentOwnerService);
94
- }
73
+ returns (IComponentOwnerService);
74
+ }