@etherisc/gif-next 0.0.2-e6a90b9 → 0.0.2-e6ad61d-739
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -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 +1 -1
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
- 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/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 +10 -5
- package/contracts/experiment/errors/Revert.sol +13 -8
- 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 +163 -135
- 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/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 +13 -5
@@ -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-006:COMPONENT_UNKNOWN"
|
110
|
-
|
111
|
-
_componentInfo[id] = info;
|
112
|
-
|
113
|
-
// add logging
|
114
|
-
}
|
135
|
+
nftId.gtz() && _componentInfo[nftId].nftId.eq(nftId),
|
136
|
+
"ERROR:CMP-006:COMPONENT_UNKNOWN"
|
137
|
+
);
|
115
138
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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;
|
123
150
|
}
|
124
151
|
|
125
|
-
function
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
{
|
130
|
-
|
152
|
+
function getComponentInfo(
|
153
|
+
NftId nftId
|
154
|
+
) external view override returns (ComponentInfo memory) {
|
155
|
+
return _componentInfo[nftId];
|
131
156
|
}
|
132
157
|
|
133
|
-
function getComponentId(
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
{
|
138
|
-
return _idByAddress[componentAddress];
|
158
|
+
function getComponentId(
|
159
|
+
address componentAddress
|
160
|
+
) external view returns (NftId componentNftId) {
|
161
|
+
return _nftIdByAddress[componentAddress];
|
139
162
|
}
|
140
163
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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,51 +209,66 @@ contract ComponentOwnerService is
|
|
196
209
|
_;
|
197
210
|
}
|
198
211
|
|
199
|
-
constructor(
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
function register(IComponentContract component)
|
204
|
-
external
|
205
|
-
override
|
206
|
-
returns(uint256 nftId)
|
212
|
+
constructor(
|
213
|
+
address registry
|
214
|
+
) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
|
207
215
|
{
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
function register(
|
220
|
+
IComponentContract component
|
221
|
+
) external override returns (NftId nftId) {
|
208
222
|
require(
|
209
|
-
msg.sender == component.getInitialOwner(),
|
210
|
-
"ERROR:COS-003:NOT_OWNER"
|
223
|
+
msg.sender == component.getInitialOwner(),
|
224
|
+
"ERROR:COS-003:NOT_OWNER"
|
225
|
+
);
|
211
226
|
|
212
227
|
IInstance instance = component.getInstance();
|
213
228
|
nftId = instance.registerComponent(component);
|
214
229
|
}
|
215
230
|
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
override
|
220
|
-
onlyComponentOwner(component)
|
221
|
-
{
|
231
|
+
function lock(
|
232
|
+
IComponentContract component
|
233
|
+
) external override onlyComponentOwner(component) {
|
222
234
|
IInstance instance = component.getInstance();
|
223
|
-
ComponentInfo memory info = instance.getComponentInfo(
|
224
|
-
|
225
|
-
|
235
|
+
ComponentInfo memory info = instance.getComponentInfo(
|
236
|
+
component.getNftId()
|
237
|
+
);
|
238
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
226
239
|
|
227
|
-
info.state =
|
240
|
+
info.state = PAUSED();
|
241
|
+
// setComponentInfo checks for valid state changes
|
228
242
|
instance.setComponentInfo(info);
|
229
243
|
}
|
230
244
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
override
|
235
|
-
onlyComponentOwner(component)
|
236
|
-
{
|
245
|
+
function unlock(
|
246
|
+
IComponentContract component
|
247
|
+
) external override onlyComponentOwner(component) {
|
237
248
|
IInstance instance = component.getInstance();
|
238
|
-
ComponentInfo memory info = instance.getComponentInfo(
|
239
|
-
|
240
|
-
|
249
|
+
ComponentInfo memory info = instance.getComponentInfo(
|
250
|
+
component.getNftId()
|
251
|
+
);
|
252
|
+
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
241
253
|
|
242
|
-
info.state =
|
254
|
+
info.state = ACTIVE();
|
255
|
+
// setComponentInfo checks for valid state changes
|
243
256
|
instance.setComponentInfo(info);
|
244
257
|
}
|
245
258
|
|
246
|
-
|
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
|
+
}
|
@@ -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
|
+
}
|
@@ -0,0 +1,88 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {NftId} from "../../types/NftId.sol";
|
5
|
+
import {ObjectType, PRODUCT, ORACLE, POOL, BUNDLE, POLICY} from "../../types/ObjectType.sol";
|
6
|
+
import {StateId, ACTIVE, PAUSED, ARCHIVED, CLOSED, APPLIED, REVOKED, DECLINED} from "../../types/StateId.sol";
|
7
|
+
import {ILifecycleModule} from "./ILifecycle.sol";
|
8
|
+
|
9
|
+
contract LifecycleModule is ILifecycleModule {
|
10
|
+
mapping(ObjectType objectType => StateId initialState)
|
11
|
+
private _initialState;
|
12
|
+
|
13
|
+
mapping(ObjectType objectType => mapping(StateId stateFrom => mapping(StateId stateTo => bool isValid)))
|
14
|
+
private _isValidTransition;
|
15
|
+
|
16
|
+
constructor() {
|
17
|
+
_setupComponentLifecycle(PRODUCT());
|
18
|
+
_setupComponentLifecycle(ORACLE());
|
19
|
+
_setupComponentLifecycle(POOL());
|
20
|
+
|
21
|
+
_setupBundleLifecycle();
|
22
|
+
_setupPolicyLifecycle();
|
23
|
+
}
|
24
|
+
|
25
|
+
function checkAndLogTransition(
|
26
|
+
NftId nftId,
|
27
|
+
ObjectType objectType,
|
28
|
+
StateId fromId,
|
29
|
+
StateId toId
|
30
|
+
) public returns (StateId) // add only currentcontract? would that work?
|
31
|
+
{
|
32
|
+
if (!_isValidTransition[objectType][fromId][toId]) {
|
33
|
+
revert ErrorInvalidStateTransition(nftId, objectType, fromId, toId);
|
34
|
+
}
|
35
|
+
|
36
|
+
if (objectType == POLICY()) {
|
37
|
+
emit LogPolicyStateChanged(nftId, fromId, toId);
|
38
|
+
} else if (objectType == BUNDLE()) {
|
39
|
+
emit LogBundleStateChanged(nftId, fromId, toId);
|
40
|
+
} else if (
|
41
|
+
objectType == PRODUCT() ||
|
42
|
+
objectType == ORACLE() ||
|
43
|
+
objectType == POOL()
|
44
|
+
) {
|
45
|
+
emit LogComponentStateChanged(nftId, objectType, fromId, toId);
|
46
|
+
} else {
|
47
|
+
revert ErrorNoLifecycle(nftId, objectType);
|
48
|
+
}
|
49
|
+
|
50
|
+
return toId;
|
51
|
+
}
|
52
|
+
|
53
|
+
function getInitialState(
|
54
|
+
ObjectType objectType
|
55
|
+
) public view returns (StateId) {
|
56
|
+
return _initialState[objectType];
|
57
|
+
}
|
58
|
+
|
59
|
+
function isValidTransition(
|
60
|
+
ObjectType objectType,
|
61
|
+
StateId fromId,
|
62
|
+
StateId toId
|
63
|
+
) public view returns (bool) {
|
64
|
+
return _isValidTransition[objectType][fromId][toId];
|
65
|
+
}
|
66
|
+
|
67
|
+
function _setupComponentLifecycle(ObjectType objectType) internal {
|
68
|
+
_initialState[objectType] = ACTIVE();
|
69
|
+
_isValidTransition[objectType][ACTIVE()][PAUSED()] = true;
|
70
|
+
_isValidTransition[objectType][PAUSED()][ACTIVE()] = true;
|
71
|
+
_isValidTransition[objectType][PAUSED()][ARCHIVED()] = true;
|
72
|
+
}
|
73
|
+
|
74
|
+
function _setupBundleLifecycle() internal {
|
75
|
+
_initialState[BUNDLE()] = ACTIVE();
|
76
|
+
_isValidTransition[BUNDLE()][ACTIVE()][PAUSED()] = true;
|
77
|
+
_isValidTransition[BUNDLE()][PAUSED()][ACTIVE()] = true;
|
78
|
+
_isValidTransition[BUNDLE()][PAUSED()][CLOSED()] = true;
|
79
|
+
}
|
80
|
+
|
81
|
+
function _setupPolicyLifecycle() internal {
|
82
|
+
_initialState[POLICY()] = APPLIED();
|
83
|
+
_isValidTransition[POLICY()][APPLIED()][REVOKED()] = true;
|
84
|
+
_isValidTransition[POLICY()][APPLIED()][DECLINED()] = true;
|
85
|
+
_isValidTransition[POLICY()][APPLIED()][ACTIVE()] = true;
|
86
|
+
_isValidTransition[POLICY()][ACTIVE()][CLOSED()] = true;
|
87
|
+
}
|
88
|
+
}
|