@etherisc/gif-next 0.0.2-3ae3aa8 → 0.0.2-3e0ffc8-142
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 +2 -1
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +28 -2
- 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 +78 -2
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +32 -150
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +121 -6
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +121 -6
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- 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/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +518 -47
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +584 -66
- 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 +14 -23
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +8 -8
- 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 +28 -2
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +12 -21
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- 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 +26 -3
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +26 -3
- 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 +15 -35
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +22 -29
- 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 +13 -0
- 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 +41 -12
- 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 +355 -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 +355 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- 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 +2 -2
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +4 -95
- 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 +2 -2
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +14 -105
- 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 +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- 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 +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +2 -2
- package/contracts/components/Component.sol +25 -8
- package/contracts/components/IPool.sol +3 -1
- package/contracts/components/IProduct.sol +4 -2
- package/contracts/components/Pool.sol +27 -4
- package/contracts/components/Product.sol +30 -4
- package/contracts/experiment/statemachine/Dummy.sol +33 -0
- package/contracts/experiment/statemachine/ISM.sol +20 -0
- package/contracts/experiment/statemachine/README.md +112 -0
- package/contracts/experiment/statemachine/SM.sol +54 -0
- package/contracts/experiment/statemachine/SimpleStateMachine.sol +24 -0
- package/contracts/instance/IInstance.sol +5 -1
- package/contracts/instance/Instance.sol +11 -6
- package/contracts/instance/component/ComponentModule.sol +80 -39
- package/contracts/instance/component/IComponent.sol +15 -12
- package/contracts/instance/lifecycle/ILifecycle.sol +32 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +91 -0
- package/contracts/instance/policy/IPolicy.sol +9 -8
- package/contracts/instance/policy/PolicyModule.sol +28 -12
- package/contracts/instance/pool/IPoolModule.sol +4 -11
- package/contracts/instance/pool/PoolModule.sol +27 -18
- package/contracts/instance/product/IProductService.sol +1 -1
- package/contracts/instance/product/ProductService.sol +48 -42
- package/contracts/instance/treasury/ITreasury.sol +73 -0
- package/contracts/instance/treasury/TokenHandler.sol +27 -0
- package/contracts/instance/treasury/TreasuryModule.sol +131 -0
- package/contracts/registry/IRegistry.sol +6 -17
- package/contracts/registry/Registry.sol +6 -38
- package/contracts/types/Fee.sol +30 -0
- package/contracts/types/ObjectType.sol +50 -0
- package/contracts/types/StateId.sol +46 -0
- package/contracts/types/UFixed.sol +1 -0
- package/package.json +4 -3
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.19;
|
|
3
3
|
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.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 {TreasuryModule} from "../treasury/TreasuryModule.sol";
|
|
9
13
|
import {IComponent, IComponentContract, IComponentModule, IComponentOwnerService} from "./IComponent.sol";
|
|
10
14
|
import {IProductComponent} from "../../components/IProduct.sol";
|
|
15
|
+
import {IPoolComponent} from "../../components/IPool.sol";
|
|
11
16
|
import {IPoolModule} from "../pool/IPoolModule.sol";
|
|
12
|
-
import {
|
|
17
|
+
import {ObjectType, PRODUCT, ORACLE, POOL} from "../../types/ObjectType.sol";
|
|
18
|
+
import {StateId, ACTIVE, PAUSED} from "../../types/StateId.sol";
|
|
19
|
+
import {NftId, NftIdLib, zeroNftId} from "../../types/NftId.sol";
|
|
20
|
+
import {Fee, zeroFee} from "../../types/Fee.sol";
|
|
13
21
|
|
|
14
22
|
abstract contract ComponentModule is
|
|
15
23
|
IRegistryLinked,
|
|
@@ -20,12 +28,15 @@ abstract contract ComponentModule is
|
|
|
20
28
|
using NftIdLib for NftId;
|
|
21
29
|
|
|
22
30
|
mapping(NftId nftId => ComponentInfo info) private _componentInfo;
|
|
23
|
-
mapping(NftId nftId => NftId poolNftId) private _poolNftIdForProduct;
|
|
24
31
|
mapping(address cAddress => NftId nftId) private _nftIdByAddress;
|
|
25
32
|
NftId[] private _nftIds;
|
|
26
33
|
|
|
27
|
-
mapping(
|
|
34
|
+
mapping(ObjectType cType => bytes32 role) private _componentOwnerRole;
|
|
28
35
|
|
|
36
|
+
// TODO maybe move this to Instance contract as internal variable?
|
|
37
|
+
LifecycleModule private _lifecycleModule;
|
|
38
|
+
TreasuryModule private _treasuryModule;
|
|
39
|
+
IPoolModule private _poolModule;
|
|
29
40
|
IComponentOwnerService private _componentOwnerService;
|
|
30
41
|
|
|
31
42
|
modifier onlyComponentOwnerService() {
|
|
@@ -37,51 +48,74 @@ abstract contract ComponentModule is
|
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
constructor(address componentOwnerService) {
|
|
51
|
+
address componentAddress = address(this);
|
|
52
|
+
_lifecycleModule = LifecycleModule(componentAddress);
|
|
53
|
+
_treasuryModule = TreasuryModule(componentAddress);
|
|
54
|
+
_poolModule = IPoolModule(componentAddress);
|
|
40
55
|
_componentOwnerService = ComponentOwnerService(componentOwnerService);
|
|
41
56
|
}
|
|
42
57
|
|
|
43
|
-
function registerComponent(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
function registerComponent(IComponentContract component)
|
|
59
|
+
external
|
|
60
|
+
override
|
|
61
|
+
onlyComponentOwnerService
|
|
62
|
+
returns(NftId nftId)
|
|
63
|
+
{
|
|
64
|
+
ObjectType objectType = component.getType();
|
|
65
|
+
bytes32 typeRole = getRoleForType(objectType);
|
|
47
66
|
require(
|
|
48
67
|
this.hasRole(typeRole, component.getInitialOwner()),
|
|
49
68
|
"ERROR:CMP-004:TYPE_ROLE_MISSING"
|
|
50
69
|
);
|
|
51
70
|
|
|
52
71
|
nftId = this.getRegistry().register(address(component));
|
|
72
|
+
IERC20 token = component.getToken();
|
|
73
|
+
address wallet = component.getWallet();
|
|
53
74
|
|
|
54
|
-
|
|
75
|
+
// create component info
|
|
76
|
+
_componentInfo[nftId] = ComponentInfo(
|
|
77
|
+
nftId,
|
|
78
|
+
_lifecycleModule.getInitialState(objectType),
|
|
79
|
+
token);
|
|
55
80
|
|
|
56
|
-
//
|
|
57
|
-
if
|
|
81
|
+
// component type specific registration actions
|
|
82
|
+
if(component.getType() == PRODUCT()) {
|
|
58
83
|
IProductComponent product = IProductComponent(address(component));
|
|
59
84
|
NftId poolNftId = product.getPoolNftId();
|
|
60
85
|
require(poolNftId.gtz(), "ERROR:CMP-005:POOL_UNKNOWN");
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
// validate pool token and product token are same
|
|
87
|
+
|
|
88
|
+
// register with tresury
|
|
89
|
+
// implement and add validation
|
|
90
|
+
NftId distributorNftId = zeroNftId();
|
|
91
|
+
_treasuryModule.registerProduct(
|
|
92
|
+
nftId,
|
|
93
|
+
distributorNftId,
|
|
94
|
+
poolNftId,
|
|
95
|
+
token,
|
|
96
|
+
wallet,
|
|
97
|
+
product.getPolicyFee(),
|
|
98
|
+
product.getProcessingFee());
|
|
99
|
+
}
|
|
100
|
+
else if(component.getType() == POOL()) {
|
|
101
|
+
IPoolComponent pool = IPoolComponent(address(component));
|
|
102
|
+
|
|
103
|
+
// register with pool
|
|
104
|
+
_poolModule.registerPool(nftId);
|
|
105
|
+
|
|
106
|
+
// register with tresury
|
|
107
|
+
_treasuryModule.registerPool(
|
|
108
|
+
nftId,
|
|
109
|
+
wallet,
|
|
110
|
+
pool.getStakingFee(),
|
|
111
|
+
pool.getPerformanceFee());
|
|
73
112
|
}
|
|
113
|
+
// TODO add distribution
|
|
74
114
|
|
|
75
115
|
_nftIdByAddress[address(component)] = nftId;
|
|
76
116
|
_nftIds.push(nftId);
|
|
77
117
|
|
|
78
|
-
// add
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function getPoolNftId(
|
|
82
|
-
NftId productNftId
|
|
83
|
-
) external view override returns (NftId poolNftId) {
|
|
84
|
-
poolNftId = _poolNftIdForProduct[productNftId];
|
|
118
|
+
// TODO add loggingx
|
|
85
119
|
}
|
|
86
120
|
|
|
87
121
|
function getComponentOwnerService()
|
|
@@ -102,9 +136,12 @@ abstract contract ComponentModule is
|
|
|
102
136
|
"ERROR:CMP-006:COMPONENT_UNKNOWN"
|
|
103
137
|
);
|
|
104
138
|
|
|
139
|
+
// TODO decide if state changes should have explicit functions and not
|
|
140
|
+
// just a generic setXYZInfo and implicit state transitions
|
|
141
|
+
// when in doubt go for the explicit approach ...
|
|
142
|
+
ObjectType objectType = this.getRegistry().getInfo(nftId).objectType;
|
|
143
|
+
_lifecycleModule.checkAndLogTransition(nftId, objectType, _componentInfo[nftId].state, info.state);
|
|
105
144
|
_componentInfo[nftId] = info;
|
|
106
|
-
|
|
107
|
-
// add logging
|
|
108
145
|
}
|
|
109
146
|
|
|
110
147
|
function getComponentInfo(
|
|
@@ -138,14 +175,18 @@ abstract contract ComponentModule is
|
|
|
138
175
|
return _nftIds.length;
|
|
139
176
|
}
|
|
140
177
|
|
|
141
|
-
function getRoleForType(
|
|
142
|
-
|
|
178
|
+
function getRoleForType(ObjectType cType)
|
|
179
|
+
public
|
|
180
|
+
view
|
|
181
|
+
returns(bytes32 role)
|
|
182
|
+
{
|
|
183
|
+
if(cType == PRODUCT()) {
|
|
143
184
|
return this.PRODUCT_OWNER_ROLE();
|
|
144
185
|
}
|
|
145
|
-
if
|
|
186
|
+
if(cType == POOL()) {
|
|
146
187
|
return this.POOL_OWNER_ROLE();
|
|
147
188
|
}
|
|
148
|
-
if
|
|
189
|
+
if(cType == ORACLE()) {
|
|
149
190
|
return this.ORACLE_OWNER_ROLE();
|
|
150
191
|
}
|
|
151
192
|
}
|
|
@@ -191,9 +232,9 @@ contract ComponentOwnerService is
|
|
|
191
232
|
component.getNftId()
|
|
192
233
|
);
|
|
193
234
|
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
|
194
|
-
// TODO add state change validation
|
|
195
235
|
|
|
196
|
-
info.state =
|
|
236
|
+
info.state = PAUSED();
|
|
237
|
+
// setComponentInfo checks for valid state changes
|
|
197
238
|
instance.setComponentInfo(info);
|
|
198
239
|
}
|
|
199
240
|
|
|
@@ -205,9 +246,9 @@ contract ComponentOwnerService is
|
|
|
205
246
|
component.getNftId()
|
|
206
247
|
);
|
|
207
248
|
require(info.nftId.gtz(), "ERROR_COMPONENT_UNKNOWN");
|
|
208
|
-
// TODO state change validation
|
|
209
249
|
|
|
210
|
-
info.state =
|
|
250
|
+
info.state = ACTIVE();
|
|
251
|
+
// setComponentInfo checks for valid state changes
|
|
211
252
|
instance.setComponentInfo(info);
|
|
212
253
|
}
|
|
213
254
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity ^0.8.19;
|
|
3
3
|
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
|
|
4
6
|
import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
|
5
7
|
import {IInstance} from "../IInstance.sol";
|
|
8
|
+
import {StateId} from "../../types/StateId.sol";
|
|
6
9
|
import {NftId} from "../../types/NftId.sol";
|
|
10
|
+
import {Fee} from "../../types/Fee.sol";
|
|
11
|
+
import {UFixed} from "../../types/UFixed.sol";
|
|
7
12
|
|
|
8
13
|
interface IComponent {
|
|
9
|
-
// TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
|
|
10
|
-
enum CState {
|
|
11
|
-
Undefined,
|
|
12
|
-
Active,
|
|
13
|
-
Locked
|
|
14
|
-
}
|
|
15
14
|
|
|
16
15
|
// component dynamic info (static info kept in registry)
|
|
17
16
|
struct ComponentInfo {
|
|
18
17
|
NftId nftId;
|
|
19
|
-
|
|
18
|
+
StateId state;
|
|
19
|
+
IERC20 token;
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -25,7 +25,14 @@ interface IInstanceLinked {
|
|
|
25
25
|
function getInstance() external view returns (IInstance instance);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
interface IComponentContract is
|
|
28
|
+
interface IComponentContract is
|
|
29
|
+
IRegisterable,
|
|
30
|
+
IInstanceLinked,
|
|
31
|
+
IComponent
|
|
32
|
+
{
|
|
33
|
+
function getToken() external view returns(IERC20 token);
|
|
34
|
+
function getWallet() external view returns(address walletAddress);
|
|
35
|
+
}
|
|
29
36
|
|
|
30
37
|
interface IComponentOwnerService is IRegistryLinked {
|
|
31
38
|
function register(
|
|
@@ -60,10 +67,6 @@ interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
|
|
|
60
67
|
|
|
61
68
|
function getComponentId(uint256 idx) external view returns (NftId nftId);
|
|
62
69
|
|
|
63
|
-
function getPoolNftId(
|
|
64
|
-
NftId productNftId
|
|
65
|
-
) external view returns (NftId poolNftId);
|
|
66
|
-
|
|
67
70
|
function components() external view returns (uint256 numberOfCompnents);
|
|
68
71
|
|
|
69
72
|
function getComponentOwnerService()
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
|
|
10
|
+
event LogComponentStateChanged(NftId nftId, ObjectType objectType, StateId fromStateId, StateId toStateId);
|
|
11
|
+
event LogBundleStateChanged(NftId nftId, StateId fromStateId, StateId toStateId);
|
|
12
|
+
event LogPolicyStateChanged(NftId nftId, StateId fromStateId, StateId toStateId);
|
|
13
|
+
// event LogClaimStateChanged(NftId nftId, ClaimId claimId, StateId fromStateId, StateId toStateId);
|
|
14
|
+
// event LogPayoutStateChanged(NftId nftId, ClaimId claimId, PayoutId payoutId, StateId fromStateId, StateId toStateId);
|
|
15
|
+
|
|
16
|
+
error ErrorNoLifecycle(NftId nftId, ObjectType objectType);
|
|
17
|
+
error ErrorInvalidStateTransition(NftId nftId, ObjectType objectType, StateId fromStateId, StateId toStateId);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ILifecycleModule is ILifecycle {
|
|
21
|
+
|
|
22
|
+
function getInitialState(ObjectType objectType)
|
|
23
|
+
external
|
|
24
|
+
view
|
|
25
|
+
returns(StateId);
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function isValidTransition(ObjectType objectType, StateId fromId, StateId toId)
|
|
29
|
+
external
|
|
30
|
+
view
|
|
31
|
+
returns(bool);
|
|
32
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
|
|
11
|
+
mapping(ObjectType objectType => StateId initialState) private _initialState;
|
|
12
|
+
|
|
13
|
+
mapping(ObjectType objectType =>
|
|
14
|
+
mapping(StateId stateFrom =>
|
|
15
|
+
mapping(StateId stateTo => bool isValid))) private _isValidTransition;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
constructor() {
|
|
19
|
+
_setupComponentLifecycle(PRODUCT());
|
|
20
|
+
_setupComponentLifecycle(ORACLE());
|
|
21
|
+
_setupComponentLifecycle(POOL());
|
|
22
|
+
|
|
23
|
+
_setupBundleLifecycle();
|
|
24
|
+
_setupPolicyLifecycle();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function checkAndLogTransition(NftId nftId, ObjectType objectType, StateId fromId, StateId toId)
|
|
29
|
+
public
|
|
30
|
+
returns(StateId)
|
|
31
|
+
// add only currentcontract? would that work?
|
|
32
|
+
{
|
|
33
|
+
if(!_isValidTransition[objectType][fromId][toId]) {
|
|
34
|
+
revert ErrorInvalidStateTransition(nftId, objectType, fromId, toId);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if(objectType == POLICY()) {
|
|
38
|
+
emit LogPolicyStateChanged(nftId, fromId, toId);
|
|
39
|
+
} else if(objectType == BUNDLE()) {
|
|
40
|
+
emit LogBundleStateChanged(nftId, fromId, toId);
|
|
41
|
+
} else if(objectType == PRODUCT() || objectType == ORACLE() || objectType == POOL()) {
|
|
42
|
+
emit LogComponentStateChanged(nftId, objectType, fromId, toId);
|
|
43
|
+
} else {
|
|
44
|
+
revert ErrorNoLifecycle(nftId, objectType);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return toId;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getInitialState(ObjectType objectType)
|
|
51
|
+
public
|
|
52
|
+
view
|
|
53
|
+
returns(StateId)
|
|
54
|
+
{
|
|
55
|
+
return _initialState[objectType];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function isValidTransition(ObjectType objectType, StateId fromId, StateId toId)
|
|
60
|
+
public
|
|
61
|
+
view
|
|
62
|
+
returns(bool)
|
|
63
|
+
{
|
|
64
|
+
return _isValidTransition[objectType][fromId][toId];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function _setupComponentLifecycle(ObjectType objectType) internal {
|
|
69
|
+
_initialState[objectType] = ACTIVE();
|
|
70
|
+
_isValidTransition[objectType][ACTIVE()][PAUSED()] = true;
|
|
71
|
+
_isValidTransition[objectType][PAUSED()][ACTIVE()] = true;
|
|
72
|
+
_isValidTransition[objectType][PAUSED()][ARCHIVED()] = true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
function _setupBundleLifecycle() internal {
|
|
77
|
+
_initialState[BUNDLE()] = ACTIVE();
|
|
78
|
+
_isValidTransition[BUNDLE()][ACTIVE()][PAUSED()] = true;
|
|
79
|
+
_isValidTransition[BUNDLE()][PAUSED()][ACTIVE()] = true;
|
|
80
|
+
_isValidTransition[BUNDLE()][PAUSED()][CLOSED()] = true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
function _setupPolicyLifecycle() internal {
|
|
85
|
+
_initialState[POLICY()] = APPLIED();
|
|
86
|
+
_isValidTransition[POLICY()][APPLIED()][REVOKED()] = true;
|
|
87
|
+
_isValidTransition[POLICY()][APPLIED()][DECLINED()] = true;
|
|
88
|
+
_isValidTransition[POLICY()][APPLIED()][ACTIVE()] = true;
|
|
89
|
+
_isValidTransition[POLICY()][ACTIVE()][CLOSED()] = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -5,24 +5,21 @@ import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registr
|
|
|
5
5
|
import {IInstance} from "../IInstance.sol";
|
|
6
6
|
import {IProductService} from "../product/IProductService.sol";
|
|
7
7
|
import {NftId} from "../../types/NftId.sol";
|
|
8
|
+
import {StateId} from "../../types/StateId.sol";
|
|
8
9
|
|
|
9
10
|
// TODO check if there is value to introuce IContract and let IPolicy derive from IContract
|
|
10
11
|
interface IPolicy {
|
|
11
|
-
enum PolicyState {
|
|
12
|
-
Undefined,
|
|
13
|
-
Applied,
|
|
14
|
-
Rejected,
|
|
15
|
-
Active,
|
|
16
|
-
Closed
|
|
17
|
-
}
|
|
18
12
|
|
|
19
13
|
struct PolicyInfo {
|
|
20
14
|
NftId nftId;
|
|
21
|
-
|
|
15
|
+
StateId state; // applied, withdrawn, rejected, active, closed
|
|
16
|
+
// TODO add beneficiary address
|
|
22
17
|
uint256 sumInsuredAmount;
|
|
23
18
|
uint256 premiumAmount;
|
|
19
|
+
uint256 premiumPaidAmount;
|
|
24
20
|
uint256 lifetime; // activatedAt + lifetime >= expiredAt
|
|
25
21
|
uint256 createdAt;
|
|
22
|
+
uint256 updatedAt;
|
|
26
23
|
uint256 activatedAt; // time of underwriting
|
|
27
24
|
uint256 expiredAt; // no new claims
|
|
28
25
|
uint256 closedAt; // no locked capital
|
|
@@ -30,6 +27,7 @@ interface IPolicy {
|
|
|
30
27
|
}
|
|
31
28
|
|
|
32
29
|
interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
|
|
30
|
+
|
|
33
31
|
function createApplication(
|
|
34
32
|
IRegistry.RegistryInfo memory productInfo,
|
|
35
33
|
address applicationOwner,
|
|
@@ -39,6 +37,9 @@ interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
|
|
|
39
37
|
NftId bundleNftId
|
|
40
38
|
) external returns (NftId nftId);
|
|
41
39
|
|
|
40
|
+
// process full premium
|
|
41
|
+
function processPremium(NftId nftId) external;
|
|
42
|
+
|
|
42
43
|
function activate(NftId nftId) external;
|
|
43
44
|
|
|
44
45
|
function getBundleNftForPolicy(
|
|
@@ -4,16 +4,25 @@ pragma solidity ^0.8.19;
|
|
|
4
4
|
// import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
|
5
5
|
import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
|
|
6
6
|
|
|
7
|
+
import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
|
|
7
8
|
import {IProductService} from "../product/IProductService.sol";
|
|
8
9
|
import {IPolicy, IPolicyModule} from "./IPolicy.sol";
|
|
10
|
+
import {ObjectType, POLICY} from "../../types/ObjectType.sol";
|
|
11
|
+
import {ACTIVE} from "../../types/StateId.sol";
|
|
9
12
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
|
10
13
|
|
|
11
|
-
|
|
14
|
+
import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
|
|
15
|
+
|
|
16
|
+
abstract contract PolicyModule is
|
|
17
|
+
IRegistryLinked,
|
|
18
|
+
IPolicyModule
|
|
19
|
+
{
|
|
12
20
|
using NftIdLib for NftId;
|
|
13
21
|
|
|
14
22
|
mapping(NftId nftId => PolicyInfo info) private _policyInfo;
|
|
15
23
|
mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
|
|
16
24
|
|
|
25
|
+
LifecycleModule private _lifecycleModule;
|
|
17
26
|
IProductService private _productService;
|
|
18
27
|
|
|
19
28
|
// TODO find a better place to avoid dupliation
|
|
@@ -26,6 +35,7 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
constructor(address productService) {
|
|
38
|
+
_lifecycleModule = LifecycleModule(address(this));
|
|
29
39
|
_productService = IProductService(productService);
|
|
30
40
|
}
|
|
31
41
|
|
|
@@ -39,25 +49,26 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
|
|
39
49
|
) external override onlyProductService2 returns (NftId nftId) {
|
|
40
50
|
// TODO add parameter validation
|
|
41
51
|
if (bundleNftId.gtz()) {
|
|
42
|
-
IRegistry.RegistryInfo memory bundleInfo = this
|
|
43
|
-
|
|
44
|
-
|
|
52
|
+
// IRegistry.RegistryInfo memory bundleInfo = this
|
|
53
|
+
// .getRegistry()
|
|
54
|
+
// .getInfo(bundleNftId);
|
|
45
55
|
// IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
|
|
46
56
|
}
|
|
47
57
|
|
|
48
58
|
nftId = this.getRegistry().registerObjectForInstance(
|
|
49
59
|
productInfo.nftId,
|
|
50
|
-
|
|
51
|
-
applicationOwner
|
|
52
|
-
);
|
|
60
|
+
POLICY(),
|
|
61
|
+
applicationOwner);
|
|
53
62
|
|
|
54
63
|
_policyInfo[nftId] = PolicyInfo(
|
|
55
64
|
nftId,
|
|
56
|
-
|
|
65
|
+
_lifecycleModule.getInitialState(POLICY()),
|
|
57
66
|
sumInsuredAmount,
|
|
58
67
|
premiumAmount,
|
|
68
|
+
0, // premium paid amount
|
|
59
69
|
lifetime,
|
|
60
|
-
block.timestamp,
|
|
70
|
+
block.timestamp, // createdAt
|
|
71
|
+
block.timestamp, // updatedAt
|
|
61
72
|
0, // activatedAt
|
|
62
73
|
0, // expiredAt
|
|
63
74
|
0 // closedAt
|
|
@@ -68,13 +79,18 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
|
|
68
79
|
// add logging
|
|
69
80
|
}
|
|
70
81
|
|
|
82
|
+
function processPremium(NftId nftId) external override onlyProductService2 {
|
|
83
|
+
PolicyInfo storage info = _policyInfo[nftId];
|
|
84
|
+
info.premiumPaidAmount = info.premiumAmount;
|
|
85
|
+
info.updatedAt = block.timestamp;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
71
89
|
function activate(NftId nftId) external override onlyProductService2 {
|
|
72
90
|
PolicyInfo storage info = _policyInfo[nftId];
|
|
73
91
|
info.activatedAt = block.timestamp;
|
|
74
92
|
info.expiredAt = block.timestamp + info.lifetime;
|
|
75
|
-
info.state =
|
|
76
|
-
|
|
77
|
-
// add logging
|
|
93
|
+
info.state = _lifecycleModule.checkAndLogTransition(nftId, POLICY(), info.state, ACTIVE());
|
|
78
94
|
}
|
|
79
95
|
|
|
80
96
|
function getBundleNftForPolicy(
|
|
@@ -7,23 +7,16 @@ import {NftId} from "../../types/NftId.sol";
|
|
|
7
7
|
interface IPool {
|
|
8
8
|
struct PoolInfo {
|
|
9
9
|
NftId nftId;
|
|
10
|
-
address wallet;
|
|
11
|
-
address token;
|
|
12
10
|
uint256 capital;
|
|
13
11
|
uint256 lockedCapital;
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
interface IPoolModule is IOwnable, IRegistryLinked, IPool {
|
|
18
|
-
function underwrite(NftId poolNftId, NftId policyNftId) external;
|
|
19
16
|
|
|
20
|
-
function
|
|
21
|
-
NftId nftId,
|
|
22
|
-
address wallet,
|
|
23
|
-
address token
|
|
24
|
-
) external;
|
|
17
|
+
function underwrite(NftId policyNftId, NftId productNftId) external;
|
|
25
18
|
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
-
) external view returns (PoolInfo memory info);
|
|
19
|
+
function registerPool(NftId nftId) external;
|
|
20
|
+
|
|
21
|
+
function getPoolInfo(NftId nftId) external view returns (PoolInfo memory info);
|
|
29
22
|
}
|
|
@@ -4,6 +4,7 @@ pragma solidity ^0.8.19;
|
|
|
4
4
|
import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
|
|
5
5
|
import {IProductService} from "../product/IProductService.sol";
|
|
6
6
|
import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
|
|
7
|
+
import {ITreasuryModule} from "../treasury/ITreasury.sol";
|
|
7
8
|
import {IPoolModule} from "./IPoolModule.sol";
|
|
8
9
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
|
9
10
|
|
|
@@ -11,9 +12,12 @@ abstract contract PoolModule is IPoolModule {
|
|
|
11
12
|
using NftIdLib for NftId;
|
|
12
13
|
|
|
13
14
|
uint256 public constant INITIAL_CAPITAL = 10000 * 10 ** 6;
|
|
15
|
+
uint256 public constant INITIAL_LOCKED_CAPITAL = 0;
|
|
14
16
|
|
|
15
17
|
mapping(NftId nftId => PoolInfo info) private _poolInfo;
|
|
16
18
|
|
|
19
|
+
IPolicyModule private _policyModule;
|
|
20
|
+
ITreasuryModule private _treasuryModule;
|
|
17
21
|
IProductService private _productService;
|
|
18
22
|
|
|
19
23
|
modifier onlyProductService() {
|
|
@@ -25,41 +29,46 @@ abstract contract PoolModule is IPoolModule {
|
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
constructor(address productService) {
|
|
32
|
+
_policyModule = IPolicyModule(address(this));
|
|
33
|
+
_treasuryModule = ITreasuryModule(address(this));
|
|
28
34
|
_productService = IProductService(productService);
|
|
29
35
|
}
|
|
30
36
|
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
) public override {
|
|
37
|
+
function registerPool(NftId nftId)
|
|
38
|
+
public
|
|
39
|
+
override
|
|
40
|
+
{
|
|
36
41
|
require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
|
|
37
42
|
|
|
38
43
|
_poolInfo[nftId] = PoolInfo(
|
|
39
44
|
nftId,
|
|
40
|
-
wallet,
|
|
41
|
-
token,
|
|
42
45
|
INITIAL_CAPITAL,
|
|
43
|
-
|
|
46
|
+
INITIAL_LOCKED_CAPITAL
|
|
44
47
|
);
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
function underwrite(
|
|
48
|
-
NftId
|
|
49
|
-
NftId
|
|
50
|
-
)
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
NftId policyNftId,
|
|
52
|
+
NftId productNftId
|
|
53
|
+
)
|
|
54
|
+
external
|
|
55
|
+
override
|
|
56
|
+
onlyProductService
|
|
57
|
+
{
|
|
58
|
+
IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(policyNftId);
|
|
59
|
+
require(policyInfo.nftId == policyNftId, "ERROR:PL-002:POLICY_UNKNOWN");
|
|
53
60
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
ITreasuryModule.ProductSetup memory product = _treasuryModule.getProductSetup(productNftId);
|
|
62
|
+
require(product.productNftId == productNftId, "ERROR:PL-003:PRODUCT_SETUP_MISSING");
|
|
63
|
+
|
|
64
|
+
NftId poolNftId = product.poolNftId;
|
|
65
|
+
PoolInfo storage poolInfo = _poolInfo[poolNftId];
|
|
66
|
+
require(poolInfo.nftId == poolNftId, "ERROR:PL-004:POOL_UNKNOWN");
|
|
58
67
|
|
|
59
68
|
require(
|
|
60
69
|
poolInfo.capital - poolInfo.lockedCapital >=
|
|
61
70
|
policyInfo.sumInsuredAmount,
|
|
62
|
-
"ERROR:PL-
|
|
71
|
+
"ERROR:PL-005:CAPACITY_TOO_LOW"
|
|
63
72
|
);
|
|
64
73
|
|
|
65
74
|
poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
|
|
@@ -23,7 +23,7 @@ interface IProductService is IRegistryLinked {
|
|
|
23
23
|
// function expire(uint256 nftId) external;
|
|
24
24
|
function close(NftId nftId) external;
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
function collectPremium(NftId nftId) external;
|
|
27
27
|
|
|
28
28
|
// function createClaim(uint256 nftId, uint256 claimAmount) external;
|
|
29
29
|
// function confirmClaim(uint256 nftId, uint256 claimId, uint256 claimAmount) external;
|