@etherisc/gif-next 0.0.2-ed4dd55 → 0.0.2-f619be3-760
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +49 -0
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +35 -9
- package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +84 -8
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +34 -152
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +146 -13
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +148 -15
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +714 -127
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +845 -129
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +31 -59
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +103 -6
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +34 -8
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +31 -59
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +50 -3
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +44 -21
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +44 -21
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +23 -43
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +28 -35
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +21 -8
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +85 -14
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
- package/artifacts/contracts/mock/Dip.sol/DIP.dbg.json +4 -0
- package/artifacts/contracts/mock/Dip.sol/DIP.json +338 -0
- package/artifacts/contracts/mock/TestPool.sol/TestPool.dbg.json +4 -0
- package/artifacts/contracts/mock/TestPool.sol/TestPool.json +294 -0
- package/artifacts/contracts/mock/TestProduct.sol/TestProduct.dbg.json +4 -0
- package/artifacts/contracts/mock/TestProduct.sol/TestProduct.json +384 -0
- package/artifacts/contracts/mock/Usdc.sol/USDC.dbg.json +4 -0
- package/artifacts/contracts/mock/Usdc.sol/USDC.json +338 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +8 -8
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +20 -111
- package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.json +9 -9
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +66 -115
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +85 -3
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +479 -0
- package/contracts/components/Component.sol +39 -24
- package/contracts/components/IPool.sol +9 -3
- package/contracts/components/IProduct.sol +11 -6
- package/contracts/components/Pool.sol +37 -14
- package/contracts/components/Product.sol +48 -24
- package/contracts/experiment/errors/Require.sol +38 -0
- package/contracts/experiment/errors/Revert.sol +44 -0
- package/contracts/experiment/inheritance/A.sol +8 -11
- package/contracts/experiment/inheritance/B.sol +10 -5
- package/contracts/experiment/inheritance/C.sol +11 -5
- package/contracts/experiment/inheritance/IA.sol +2 -7
- package/contracts/experiment/inheritance/IB.sol +3 -2
- package/contracts/experiment/inheritance/IC.sol +4 -3
- package/contracts/experiment/statemachine/Dummy.sol +27 -0
- package/contracts/experiment/statemachine/ISM.sol +25 -0
- package/contracts/experiment/statemachine/README.md +112 -0
- package/contracts/experiment/statemachine/SM.sol +57 -0
- package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
- package/contracts/experiment/types/TypeA.sol +14 -9
- package/contracts/experiment/types/TypeB.sol +14 -9
- package/contracts/instance/IInstance.sol +8 -3
- package/contracts/instance/Instance.sol +24 -15
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +162 -147
- package/contracts/instance/component/IComponent.sol +41 -61
- package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
- package/contracts/instance/policy/IPolicy.sol +19 -35
- package/contracts/instance/policy/PolicyModule.sol +52 -44
- package/contracts/instance/pool/IPoolModule.sol +9 -26
- package/contracts/instance/pool/PoolModule.sol +43 -45
- package/contracts/instance/product/IProductService.sol +10 -19
- package/contracts/instance/product/ProductService.sol +86 -55
- package/contracts/instance/treasury/ITreasury.sol +91 -0
- package/contracts/instance/treasury/TokenHandler.sol +24 -0
- package/contracts/instance/treasury/TreasuryModule.sol +168 -0
- package/contracts/mock/Dip.sol +26 -0
- package/contracts/mock/TestPool.sol +16 -0
- package/contracts/mock/TestProduct.sol +39 -0
- package/contracts/mock/Usdc.sol +26 -0
- package/contracts/registry/ChainNft.sol +23 -61
- package/contracts/registry/IChainNft.sol +10 -7
- package/contracts/registry/IRegistry.sol +40 -41
- package/contracts/registry/Registry.sol +73 -67
- package/contracts/types/Blocknumber.sol +118 -0
- package/contracts/types/ChainId.sol +24 -10
- package/contracts/types/Fee.sol +32 -0
- package/contracts/types/NftId.sol +36 -10
- package/contracts/types/ObjectType.sol +107 -0
- package/contracts/types/StateId.sol +91 -0
- package/contracts/types/Timestamp.sol +102 -0
- package/contracts/types/UFixed.sol +210 -0
- 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
|
-
|
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
|
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(
|
60
|
-
|
61
|
-
|
62
|
-
returns(RoleInfo memory info);
|
45
|
+
function getRoleInfo(
|
46
|
+
bytes32 role
|
47
|
+
) external view returns (RoleInfo memory info);
|
63
48
|
|
64
|
-
function getRoleForName(
|
65
|
-
|
66
|
-
|
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(
|
75
|
-
|
76
|
-
|
77
|
-
returns(uint256 roleMembers);
|
55
|
+
function getRoleMemberCount(
|
56
|
+
bytes32 role
|
57
|
+
) external view returns (uint256 roleMembers);
|
78
58
|
|
79
|
-
function getRoleMember(
|
80
|
-
|
81
|
-
|
82
|
-
|
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(
|
22
|
-
mapping(
|
23
|
-
|
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(
|
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(
|
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(
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
76
|
+
_lifecycleModule.getInitialState(objectType),
|
77
|
+
token
|
78
|
+
);
|
55
79
|
|
56
|
-
//
|
57
|
-
if(component.getType() ==
|
80
|
+
// component type specific registration actions
|
81
|
+
if (component.getType() == PRODUCT()) {
|
58
82
|
IProductComponent product = IProductComponent(address(component));
|
59
|
-
|
60
|
-
require(poolNftId
|
61
|
-
//
|
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
|
-
|
102
|
+
// register with pool
|
103
|
+
_poolModule.registerPool(nftId);
|
64
104
|
|
65
|
-
//
|
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
|
-
|
72
|
-
|
108
|
+
wallet,
|
109
|
+
pool.getStakingFee(),
|
110
|
+
pool.getPerformanceFee()
|
73
111
|
);
|
74
112
|
}
|
113
|
+
// TODO add distribution
|
75
114
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
// add logging
|
80
|
-
}
|
115
|
+
_nftIdByAddress[address(component)] = nftId;
|
116
|
+
_nftIds.push(nftId);
|
81
117
|
|
82
|
-
|
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
|
-
|
124
|
+
override
|
125
|
+
returns (IComponentOwnerService)
|
97
126
|
{
|
98
127
|
return _componentOwnerService;
|
99
128
|
}
|
100
129
|
|
101
|
-
function setComponentInfo(
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
|
109
|
-
"ERROR:CMP-
|
110
|
-
|
111
|
-
_componentInfo[id] = info;
|
135
|
+
nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
|
136
|
+
"ERROR:CMP-006:COMPONENT_UNKNOWN"
|
137
|
+
);
|
112
138
|
|
113
|
-
//
|
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(
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
126
|
-
|
127
|
-
|
128
|
-
|
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(
|
134
|
-
|
135
|
-
|
136
|
-
|
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
|
-
|
173
|
+
override
|
174
|
+
returns (uint256 numberOfCompnents)
|
157
175
|
{
|
158
|
-
return
|
176
|
+
return _nftIds.length;
|
159
177
|
}
|
160
178
|
|
161
|
-
function getRoleForType(
|
162
|
-
|
163
|
-
|
164
|
-
|
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 ==
|
185
|
+
if (cType == POOL()) {
|
170
186
|
return this.POOL_OWNER_ROLE();
|
171
187
|
}
|
172
|
-
if(cType ==
|
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
|
-
|
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(
|
200
|
-
|
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(
|
217
|
-
|
218
|
-
|
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
|
-
|
231
|
-
|
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(
|
237
|
-
|
238
|
-
|
235
|
+
ComponentInfo memory info = instance.getComponentInfo(
|
236
|
+
component.getNftId()
|
237
|
+
);
|
238
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
239
239
|
|
240
|
-
info.state =
|
240
|
+
info.state = PAUSED();
|
241
|
+
// setComponentInfo checks for valid state changes
|
241
242
|
instance.setComponentInfo(info);
|
242
243
|
}
|
243
244
|
|
244
|
-
|
245
|
-
|
246
|
-
|
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(
|
252
|
-
|
253
|
-
|
249
|
+
ComponentInfo memory info = instance.getComponentInfo(
|
250
|
+
component.getNftId()
|
251
|
+
);
|
252
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
254
253
|
|
255
|
-
info.state =
|
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
|
-
|
20
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
IComponent
|
50
|
-
{
|
54
|
+
function setComponentInfo(
|
55
|
+
ComponentInfo memory info
|
56
|
+
) external returns (NftId componentNftId);
|
51
57
|
|
52
|
-
function
|
53
|
-
|
54
|
-
|
58
|
+
function getComponentInfo(
|
59
|
+
NftId nftId
|
60
|
+
) external view returns (ComponentInfo memory info);
|
55
61
|
|
56
|
-
function
|
57
|
-
|
58
|
-
|
62
|
+
function getComponentId(
|
63
|
+
address componentAddress
|
64
|
+
) external view returns (NftId nftId);
|
59
65
|
|
60
|
-
function
|
61
|
-
external
|
62
|
-
view
|
63
|
-
returns(ComponentInfo memory info);
|
66
|
+
function getComponentId(uint256 idx) external view returns (NftId nftId);
|
64
67
|
|
65
|
-
function
|
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
|
+
}
|