@etherisc/gif-next 0.0.2-c4efd5e → 0.0.2-c630f3f-038
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +10 -2
- 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/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 +686 -99
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +757 -99
- 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 -42
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +65 -10
- 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 -40
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +47 -0
- 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 +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 +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/Blocknumber.sol/BlocknumberLib.json +2 -2
- 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 +2 -2
- 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/Timestamp.sol/TimestampLib.json +2 -2
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +37 -11
- package/contracts/components/Component.sol +24 -7
- package/contracts/components/IPool.sol +6 -0
- package/contracts/components/IProduct.sol +9 -2
- package/contracts/components/Pool.sol +34 -4
- package/contracts/components/Product.sol +38 -4
- 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/instance/IInstance.sol +9 -2
- package/contracts/instance/Instance.sol +13 -5
- package/contracts/instance/component/ComponentModule.sol +99 -38
- package/contracts/instance/component/IComponent.sol +18 -17
- package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
- package/contracts/instance/policy/IPolicy.sol +8 -9
- package/contracts/instance/policy/PolicyModule.sol +32 -9
- package/contracts/instance/pool/IPoolModule.sol +2 -8
- package/contracts/instance/pool/PoolModule.sol +24 -16
- package/contracts/instance/product/IProductService.sol +1 -1
- package/contracts/instance/product/ProductService.sol +54 -30
- 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/IRegistry.sol +4 -17
- package/contracts/registry/Registry.sol +4 -31
- package/contracts/types/Fee.sol +32 -0
- package/contracts/types/ObjectType.sol +107 -0
- package/contracts/types/StateId.sol +91 -0
- package/contracts/types/UFixed.sol +19 -14
- package/package.json +10 -6
@@ -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
|
+
}
|
@@ -5,24 +5,20 @@ 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
|
-
|
19
12
|
struct PolicyInfo {
|
20
13
|
NftId nftId;
|
21
|
-
|
14
|
+
StateId state; // applied, withdrawn, rejected, active, closed
|
15
|
+
// TODO add beneficiary address
|
22
16
|
uint256 sumInsuredAmount;
|
23
17
|
uint256 premiumAmount;
|
18
|
+
uint256 premiumPaidAmount;
|
24
19
|
uint256 lifetime; // activatedAt + lifetime >= expiredAt
|
25
20
|
uint256 createdAt;
|
21
|
+
uint256 updatedAt;
|
26
22
|
uint256 activatedAt; // time of underwriting
|
27
23
|
uint256 expiredAt; // no new claims
|
28
24
|
uint256 closedAt; // no locked capital
|
@@ -39,6 +35,9 @@ interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
|
|
39
35
|
NftId bundleNftId
|
40
36
|
) external returns (NftId nftId);
|
41
37
|
|
38
|
+
// process full premium
|
39
|
+
function processPremium(NftId nftId) external;
|
40
|
+
|
42
41
|
function activate(NftId nftId) external;
|
43
42
|
|
44
43
|
function getBundleNftForPolicy(
|
@@ -4,16 +4,22 @@ 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
|
|
14
|
+
import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
|
15
|
+
|
11
16
|
abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
12
17
|
using NftIdLib for NftId;
|
13
18
|
|
14
19
|
mapping(NftId nftId => PolicyInfo info) private _policyInfo;
|
15
20
|
mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
|
16
21
|
|
22
|
+
LifecycleModule private _lifecycleModule;
|
17
23
|
IProductService private _productService;
|
18
24
|
|
19
25
|
// TODO find a better place to avoid dupliation
|
@@ -26,6 +32,7 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
|
26
32
|
}
|
27
33
|
|
28
34
|
constructor(address productService) {
|
35
|
+
_lifecycleModule = LifecycleModule(address(this));
|
29
36
|
_productService = IProductService(productService);
|
30
37
|
}
|
31
38
|
|
@@ -39,25 +46,29 @@ abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
|
39
46
|
) external override onlyProductService2 returns (NftId nftId) {
|
40
47
|
// TODO add parameter validation
|
41
48
|
if (bundleNftId.gtz()) {
|
42
|
-
IRegistry.RegistryInfo memory bundleInfo = this
|
43
|
-
|
44
|
-
|
49
|
+
// IRegistry.RegistryInfo memory bundleInfo = this
|
50
|
+
// .getRegistry()
|
51
|
+
// .getInfo(bundleNftId);
|
45
52
|
// IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
|
46
53
|
}
|
47
54
|
|
48
55
|
nftId = this.getRegistry().registerObjectForInstance(
|
49
56
|
productInfo.nftId,
|
50
|
-
|
57
|
+
POLICY(),
|
51
58
|
applicationOwner
|
52
59
|
);
|
53
60
|
|
54
61
|
_policyInfo[nftId] = PolicyInfo(
|
55
62
|
nftId,
|
56
|
-
|
63
|
+
_lifecycleModule.getInitialState(POLICY()),
|
57
64
|
sumInsuredAmount,
|
58
65
|
premiumAmount,
|
66
|
+
0, // premium paid amount
|
59
67
|
lifetime,
|
60
|
-
|
68
|
+
// solhint-disable-next-line not-rely-on-time
|
69
|
+
block.timestamp, // createdAt
|
70
|
+
// solhint-disable-next-line not-rely-on-time
|
71
|
+
block.timestamp, // updatedAt
|
61
72
|
0, // activatedAt
|
62
73
|
0, // expiredAt
|
63
74
|
0 // closedAt
|
@@ -68,13 +79,25 @@ 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
|
+
// solhint-disable-next-line not-rely-on-time
|
86
|
+
info.updatedAt = block.timestamp;
|
87
|
+
}
|
88
|
+
|
71
89
|
function activate(NftId nftId) external override onlyProductService2 {
|
72
90
|
PolicyInfo storage info = _policyInfo[nftId];
|
91
|
+
// solhint-disable-next-line not-rely-on-time
|
73
92
|
info.activatedAt = block.timestamp;
|
93
|
+
// solhint-disable-next-line not-rely-on-time
|
74
94
|
info.expiredAt = block.timestamp + info.lifetime;
|
75
|
-
info.state =
|
76
|
-
|
77
|
-
|
95
|
+
info.state = _lifecycleModule.checkAndLogTransition(
|
96
|
+
nftId,
|
97
|
+
POLICY(),
|
98
|
+
info.state,
|
99
|
+
ACTIVE()
|
100
|
+
);
|
78
101
|
}
|
79
102
|
|
80
103
|
function getBundleNftForPolicy(
|
@@ -7,21 +7,15 @@ 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
|
16
|
+
function underwrite(NftId policyNftId, NftId productNftId) external;
|
19
17
|
|
20
|
-
function
|
21
|
-
NftId nftId,
|
22
|
-
address wallet,
|
23
|
-
address token
|
24
|
-
) external;
|
18
|
+
function registerPool(NftId nftId) external;
|
25
19
|
|
26
20
|
function getPoolInfo(
|
27
21
|
NftId nftId
|
@@ -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,45 @@ 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
|
-
NftId nftId,
|
33
|
-
address wallet,
|
34
|
-
address token
|
35
|
-
) public override {
|
37
|
+
function registerPool(NftId nftId) public override {
|
36
38
|
require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
|
37
39
|
|
38
40
|
_poolInfo[nftId] = PoolInfo(
|
39
41
|
nftId,
|
40
|
-
wallet,
|
41
|
-
token,
|
42
42
|
INITIAL_CAPITAL,
|
43
|
-
|
43
|
+
INITIAL_LOCKED_CAPITAL
|
44
44
|
);
|
45
45
|
}
|
46
46
|
|
47
47
|
function underwrite(
|
48
|
-
NftId
|
49
|
-
NftId
|
48
|
+
NftId policyNftId,
|
49
|
+
NftId productNftId
|
50
50
|
) external override onlyProductService {
|
51
|
-
|
52
|
-
require(poolInfo.nftId == poolNftId, "ERROR:PL-002:POOL_UNKNOWN");
|
53
|
-
|
54
|
-
IPolicyModule policyModule = IPolicyModule(address(this));
|
55
|
-
IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(
|
51
|
+
IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(
|
56
52
|
policyNftId
|
57
53
|
);
|
54
|
+
require(policyInfo.nftId == policyNftId, "ERROR:PL-002:POLICY_UNKNOWN");
|
55
|
+
|
56
|
+
ITreasuryModule.ProductSetup memory product = _treasuryModule
|
57
|
+
.getProductSetup(productNftId);
|
58
|
+
require(
|
59
|
+
product.productNftId == productNftId,
|
60
|
+
"ERROR:PL-003:PRODUCT_SETUP_MISSING"
|
61
|
+
);
|
62
|
+
|
63
|
+
NftId poolNftId = product.poolNftId;
|
64
|
+
PoolInfo storage poolInfo = _poolInfo[poolNftId];
|
65
|
+
require(poolInfo.nftId == poolNftId, "ERROR:PL-004:POOL_UNKNOWN");
|
58
66
|
|
59
67
|
require(
|
60
68
|
poolInfo.capital - poolInfo.lockedCapital >=
|
61
69
|
policyInfo.sumInsuredAmount,
|
62
|
-
"ERROR:PL-
|
70
|
+
"ERROR:PL-005:CAPACITY_TOO_LOW"
|
63
71
|
);
|
64
72
|
|
65
73
|
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;
|
@@ -8,15 +8,21 @@ import {IRegistry} from "../../registry/IRegistry.sol";
|
|
8
8
|
import {IPolicyModule} from "../policy/IPolicy.sol";
|
9
9
|
import {RegistryLinked} from "../../registry/Registry.sol";
|
10
10
|
import {IProductService, IProductModule} from "./IProductService.sol";
|
11
|
-
import {
|
11
|
+
import {ITreasuryModule} from "../../instance/treasury/ITreasury.sol";
|
12
12
|
import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
|
13
|
+
import {ObjectType, INSTANCE, PRODUCT} from "../../types/ObjectType.sol";
|
13
14
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
14
15
|
|
15
16
|
// TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
|
16
17
|
contract ProductService is RegistryLinked, IProductService {
|
17
18
|
using NftIdLib for NftId;
|
18
19
|
|
19
|
-
constructor(
|
20
|
+
constructor(
|
21
|
+
address registry
|
22
|
+
) RegistryLinked(registry) // solhint-disable-next-line no-empty-blocks
|
23
|
+
{
|
24
|
+
|
25
|
+
}
|
20
26
|
|
21
27
|
function createApplication(
|
22
28
|
address applicationOwner,
|
@@ -31,19 +37,13 @@ contract ProductService is RegistryLinked, IProductService {
|
|
31
37
|
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
32
38
|
productNftId
|
33
39
|
);
|
34
|
-
require(
|
35
|
-
productInfo.objectType == _registry.PRODUCT(),
|
36
|
-
"ERROR_NOT_PRODUCT"
|
37
|
-
);
|
40
|
+
require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
|
38
41
|
|
39
42
|
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
40
43
|
productInfo.parentNftId
|
41
44
|
);
|
42
45
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
43
|
-
require(
|
44
|
-
instanceInfo.objectType == _registry.INSTANCE(),
|
45
|
-
"ERROR_NOT_INSTANCE"
|
46
|
-
);
|
46
|
+
require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
|
47
47
|
|
48
48
|
IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
|
49
49
|
nftId = policyModule.createApplication(
|
@@ -58,45 +58,69 @@ contract ProductService is RegistryLinked, IProductService {
|
|
58
58
|
// add logging
|
59
59
|
}
|
60
60
|
|
61
|
-
function underwrite(NftId
|
61
|
+
function underwrite(NftId policyNftId) external override {
|
62
|
+
// validation
|
62
63
|
// same as only registered product
|
63
64
|
NftId productNftId = _registry.getNftId(msg.sender);
|
64
65
|
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
65
66
|
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
66
67
|
productNftId
|
67
68
|
);
|
68
|
-
require(
|
69
|
-
productInfo.objectType == _registry.PRODUCT(),
|
70
|
-
"ERROR_NOT_PRODUCT"
|
71
|
-
);
|
69
|
+
require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
|
72
70
|
|
73
71
|
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
74
72
|
productInfo.parentNftId
|
75
73
|
);
|
76
74
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
77
|
-
require(
|
78
|
-
|
79
|
-
|
75
|
+
require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
|
76
|
+
|
77
|
+
// underwrite policy
|
78
|
+
address instanceAddress = instanceInfo.objectAddress;
|
79
|
+
IPoolModule poolModule = IPoolModule(instanceAddress);
|
80
|
+
poolModule.underwrite(policyNftId, productNftId);
|
81
|
+
|
82
|
+
// activate policy
|
83
|
+
IPolicyModule policyModule = IPolicyModule(instanceAddress);
|
84
|
+
policyModule.activate(policyNftId);
|
85
|
+
|
86
|
+
// add logging
|
87
|
+
}
|
88
|
+
|
89
|
+
function collectPremium(NftId policyNftId) external override {
|
90
|
+
// validation same as other functions, eg underwrite
|
91
|
+
// TODO unify validation into modifier and/or other suitable approaches
|
92
|
+
// same as only registered product
|
93
|
+
NftId productNftId = _registry.getNftId(msg.sender);
|
94
|
+
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
95
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
96
|
+
productNftId
|
80
97
|
);
|
98
|
+
require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
|
81
99
|
|
82
|
-
|
83
|
-
|
84
|
-
instanceInfo.objectAddress
|
100
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
101
|
+
productInfo.parentNftId
|
85
102
|
);
|
86
|
-
|
103
|
+
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
104
|
+
require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
|
87
105
|
|
88
|
-
//
|
89
|
-
|
90
|
-
|
106
|
+
// process/collect premium: book keeping for policy
|
107
|
+
address instanceAddress = instanceInfo.objectAddress;
|
108
|
+
IPolicyModule policyModule = IPolicyModule(instanceAddress);
|
109
|
+
policyModule.processPremium(policyNftId);
|
91
110
|
|
92
|
-
//
|
93
|
-
|
94
|
-
|
111
|
+
// process/collect premium: actual token transfer
|
112
|
+
ITreasuryModule treasuryModule = ITreasuryModule(instanceAddress);
|
113
|
+
treasuryModule.processPremium(policyNftId, productNftId);
|
95
114
|
|
96
|
-
// add logging
|
115
|
+
// TODO add logging
|
97
116
|
}
|
98
117
|
|
99
|
-
function close(
|
118
|
+
function close(
|
119
|
+
NftId policyNftId
|
120
|
+
) external override // solhint-disable-next-line no-empty-blocks
|
121
|
+
{
|
122
|
+
|
123
|
+
}
|
100
124
|
}
|
101
125
|
|
102
126
|
abstract contract ProductModule is IProductModule {
|
@@ -0,0 +1,91 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
5
|
+
|
6
|
+
import {IRegistryLinked} from "../../registry/IRegistry.sol";
|
7
|
+
|
8
|
+
import {NftId} from "../../types/NftId.sol";
|
9
|
+
import {UFixed} from "../../types/UFixed.sol";
|
10
|
+
import {Fee} from "../../types/Fee.sol";
|
11
|
+
|
12
|
+
import {TokenHandler} from "./TokenHandler.sol";
|
13
|
+
|
14
|
+
interface ITreasury {
|
15
|
+
// TODO add events
|
16
|
+
// TODO add errors
|
17
|
+
}
|
18
|
+
|
19
|
+
interface ITreasuryModule is IRegistryLinked, ITreasury {
|
20
|
+
struct ProductSetup {
|
21
|
+
NftId productNftId;
|
22
|
+
NftId distributorNftId;
|
23
|
+
NftId poolNftId;
|
24
|
+
IERC20 token;
|
25
|
+
TokenHandler tokenHandler;
|
26
|
+
address wallet;
|
27
|
+
Fee policyFee;
|
28
|
+
Fee processingFee;
|
29
|
+
}
|
30
|
+
|
31
|
+
struct DistributorSetup {
|
32
|
+
NftId distributorNftId;
|
33
|
+
address wallet;
|
34
|
+
Fee commissionFees;
|
35
|
+
}
|
36
|
+
|
37
|
+
struct PoolSetup {
|
38
|
+
NftId poolNftId;
|
39
|
+
address wallet;
|
40
|
+
Fee stakingFee;
|
41
|
+
Fee performanceFee;
|
42
|
+
}
|
43
|
+
|
44
|
+
function registerProduct(
|
45
|
+
NftId productNftId,
|
46
|
+
NftId distributorNftId,
|
47
|
+
NftId poolNftId,
|
48
|
+
IERC20 token,
|
49
|
+
address wallet,
|
50
|
+
Fee memory policyFee,
|
51
|
+
Fee memory processingFee
|
52
|
+
) external;
|
53
|
+
|
54
|
+
function setProductFees(
|
55
|
+
NftId productNftId,
|
56
|
+
Fee memory policyFee,
|
57
|
+
Fee memory processingFee
|
58
|
+
) external;
|
59
|
+
|
60
|
+
function registerPool(
|
61
|
+
NftId poolNftId,
|
62
|
+
address wallet,
|
63
|
+
Fee memory stakingFee,
|
64
|
+
Fee memory performanceFee
|
65
|
+
) external;
|
66
|
+
|
67
|
+
function setPoolFees(
|
68
|
+
NftId poolNftId,
|
69
|
+
Fee memory stakingFee,
|
70
|
+
Fee memory performanceFee
|
71
|
+
) external;
|
72
|
+
|
73
|
+
function processPremium(NftId policyNftId, NftId productNftId) external;
|
74
|
+
|
75
|
+
function getTokenHandler(
|
76
|
+
NftId productNftId
|
77
|
+
) external view returns (TokenHandler tokenHandler);
|
78
|
+
|
79
|
+
function getProductSetup(
|
80
|
+
NftId productNftId
|
81
|
+
) external view returns (ProductSetup memory setup);
|
82
|
+
|
83
|
+
function getPoolSetup(
|
84
|
+
NftId poolNftId
|
85
|
+
) external view returns (PoolSetup memory setup);
|
86
|
+
|
87
|
+
function calculateFeeAmount(
|
88
|
+
uint256 amount,
|
89
|
+
Fee memory fee
|
90
|
+
) external pure returns (uint256 feeAmount, uint256 netAmount);
|
91
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
5
|
+
|
6
|
+
contract TokenHandler {
|
7
|
+
// TODO use oz safeTransferFrom
|
8
|
+
|
9
|
+
IERC20 _token;
|
10
|
+
|
11
|
+
constructor(address token) {
|
12
|
+
_token = IERC20(token);
|
13
|
+
}
|
14
|
+
|
15
|
+
// TODO add logging
|
16
|
+
function transfer(
|
17
|
+
address from,
|
18
|
+
address to,
|
19
|
+
uint256 amount
|
20
|
+
) external // TODO add authz (only treasury)
|
21
|
+
{
|
22
|
+
_token.transferFrom(from, to, amount);
|
23
|
+
}
|
24
|
+
}
|