@etherisc/gif-next 0.0.2-f9905e1 → 0.0.2-f99f1d2-109
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 +4 -0
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +714 -127
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +845 -129
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +31 -59
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +103 -6
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +34 -8
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +31 -59
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +50 -3
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +44 -21
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +44 -21
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +23 -43
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +28 -35
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +21 -8
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +85 -14
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +4 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
- 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 +45 -128
- 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 +95 -128
- 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 +4 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
- 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 +453 -0
- package/contracts/components/Component.sol +39 -24
- package/contracts/components/IPool.sol +9 -3
- package/contracts/components/IProduct.sol +11 -6
- package/contracts/components/Pool.sol +37 -14
- package/contracts/components/Product.sol +48 -24
- package/contracts/experiment/errors/Require.sol +38 -0
- package/contracts/experiment/errors/Revert.sol +44 -0
- package/contracts/experiment/inheritance/A.sol +8 -11
- package/contracts/experiment/inheritance/B.sol +10 -5
- package/contracts/experiment/inheritance/C.sol +11 -5
- package/contracts/experiment/inheritance/IA.sol +2 -7
- package/contracts/experiment/inheritance/IB.sol +3 -2
- package/contracts/experiment/inheritance/IC.sol +4 -3
- package/contracts/experiment/statemachine/Dummy.sol +27 -0
- package/contracts/experiment/statemachine/ISM.sol +25 -0
- package/contracts/experiment/statemachine/README.md +112 -0
- package/contracts/experiment/statemachine/SM.sol +57 -0
- package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
- package/contracts/experiment/types/TypeA.sol +14 -9
- package/contracts/experiment/types/TypeB.sol +14 -9
- package/contracts/instance/IInstance.sol +9 -4
- package/contracts/instance/Instance.sol +24 -15
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +162 -147
- package/contracts/instance/component/IComponent.sol +41 -61
- package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
- package/contracts/instance/policy/IPolicy.sol +19 -35
- package/contracts/instance/policy/PolicyModule.sol +52 -44
- package/contracts/instance/pool/IPoolModule.sol +9 -26
- package/contracts/instance/pool/PoolModule.sol +43 -45
- package/contracts/instance/product/IProductService.sol +10 -19
- package/contracts/instance/product/ProductService.sol +86 -55
- package/contracts/instance/treasury/ITreasury.sol +91 -0
- package/contracts/instance/treasury/TokenHandler.sol +24 -0
- package/contracts/instance/treasury/TreasuryModule.sol +168 -0
- package/contracts/registry/ChainNft.sol +135 -0
- package/contracts/registry/IChainNft.sol +21 -0
- package/contracts/registry/IRegistry.sol +41 -40
- package/contracts/registry/Registry.sol +82 -97
- 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 +51 -0
- 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 +206 -0
- package/package.json +13 -5
@@ -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
|
+
}
|
@@ -1,66 +1,50 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
5
4
|
import {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
|
6
5
|
import {IInstance} from "../IInstance.sol";
|
7
|
-
|
8
6
|
import {IProductService} from "../product/IProductService.sol";
|
7
|
+
import {NftId} from "../../types/NftId.sol";
|
8
|
+
import {StateId} from "../../types/StateId.sol";
|
9
9
|
|
10
10
|
// TODO check if there is value to introuce IContract and let IPolicy derive from IContract
|
11
11
|
interface IPolicy {
|
12
|
-
|
13
|
-
enum PolicyState {
|
14
|
-
Undefined,
|
15
|
-
Applied,
|
16
|
-
Rejected,
|
17
|
-
Active,
|
18
|
-
Closed
|
19
|
-
}
|
20
|
-
|
21
12
|
struct PolicyInfo {
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
NftId nftId;
|
14
|
+
StateId state; // applied, withdrawn, rejected, active, closed
|
15
|
+
// TODO add beneficiary address
|
25
16
|
uint256 sumInsuredAmount;
|
26
17
|
uint256 premiumAmount;
|
18
|
+
uint256 premiumPaidAmount;
|
27
19
|
uint256 lifetime; // activatedAt + lifetime >= expiredAt
|
28
|
-
|
29
20
|
uint256 createdAt;
|
21
|
+
uint256 updatedAt;
|
30
22
|
uint256 activatedAt; // time of underwriting
|
31
23
|
uint256 expiredAt; // no new claims
|
32
24
|
uint256 closedAt; // no locked capital
|
33
25
|
}
|
34
26
|
}
|
35
27
|
|
36
|
-
interface IPolicyModule is
|
37
|
-
IOwnable,
|
38
|
-
IRegistryLinked,
|
39
|
-
IPolicy
|
40
|
-
{
|
41
|
-
|
28
|
+
interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
|
42
29
|
function createApplication(
|
43
30
|
IRegistry.RegistryInfo memory productInfo,
|
44
31
|
address applicationOwner,
|
45
32
|
uint256 sumInsuredAmount,
|
46
33
|
uint256 premiumAmount,
|
47
34
|
uint256 lifetime,
|
48
|
-
|
49
|
-
)
|
50
|
-
external
|
51
|
-
returns(uint256 nftId);
|
35
|
+
NftId bundleNftId
|
36
|
+
) external returns (NftId nftId);
|
52
37
|
|
53
|
-
|
54
|
-
|
38
|
+
// process full premium
|
39
|
+
function processPremium(NftId nftId) external;
|
55
40
|
|
56
|
-
function
|
57
|
-
external
|
58
|
-
view
|
59
|
-
returns(uint256 bundleNft);
|
41
|
+
function activate(NftId nftId) external;
|
60
42
|
|
61
|
-
function
|
62
|
-
|
63
|
-
|
64
|
-
returns(PolicyInfo memory info);
|
43
|
+
function getBundleNftForPolicy(
|
44
|
+
NftId nftId
|
45
|
+
) external view returns (NftId bundleNft);
|
65
46
|
|
47
|
+
function getPolicyInfo(
|
48
|
+
NftId nftId
|
49
|
+
) external view returns (PolicyInfo memory info);
|
66
50
|
}
|
@@ -1,66 +1,74 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
5
4
|
// import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
6
5
|
import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
|
7
6
|
|
7
|
+
import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
|
8
8
|
import {IProductService} from "../product/IProductService.sol";
|
9
9
|
import {IPolicy, IPolicyModule} from "./IPolicy.sol";
|
10
|
+
import {ObjectType, POLICY} from "../../types/ObjectType.sol";
|
11
|
+
import {ACTIVE} from "../../types/StateId.sol";
|
12
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
10
13
|
|
14
|
+
import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
|
11
15
|
|
12
|
-
abstract contract PolicyModule is
|
13
|
-
|
14
|
-
IPolicyModule
|
15
|
-
{
|
16
|
+
abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
17
|
+
using NftIdLib for NftId;
|
16
18
|
|
17
|
-
mapping(
|
18
|
-
mapping(
|
19
|
+
mapping(NftId nftId => PolicyInfo info) private _policyInfo;
|
20
|
+
mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
|
19
21
|
|
22
|
+
LifecycleModule private _lifecycleModule;
|
20
23
|
IProductService private _productService;
|
21
24
|
|
22
25
|
// TODO find a better place to avoid dupliation
|
23
26
|
modifier onlyProductService2() {
|
24
|
-
require(
|
27
|
+
require(
|
28
|
+
address(_productService) == msg.sender,
|
29
|
+
"ERROR:POL-001:NOT_PRODUCT_SERVICE"
|
30
|
+
);
|
25
31
|
_;
|
26
32
|
}
|
27
33
|
|
28
34
|
constructor(address productService) {
|
35
|
+
_lifecycleModule = LifecycleModule(address(this));
|
29
36
|
_productService = IProductService(productService);
|
30
37
|
}
|
31
38
|
|
32
|
-
|
33
39
|
function createApplication(
|
34
40
|
IRegistry.RegistryInfo memory productInfo,
|
35
41
|
address applicationOwner,
|
36
42
|
uint256 sumInsuredAmount,
|
37
43
|
uint256 premiumAmount,
|
38
44
|
uint256 lifetime,
|
39
|
-
|
40
|
-
)
|
41
|
-
external
|
42
|
-
override
|
43
|
-
onlyProductService2
|
44
|
-
returns(uint256 nftId)
|
45
|
-
{
|
45
|
+
NftId bundleNftId
|
46
|
+
) external override onlyProductService2 returns (NftId nftId) {
|
46
47
|
// TODO add parameter validation
|
47
|
-
if(bundleNftId
|
48
|
-
IRegistry.RegistryInfo memory bundleInfo = this
|
49
|
-
|
48
|
+
if (bundleNftId.gtz()) {
|
49
|
+
// IRegistry.RegistryInfo memory bundleInfo = this
|
50
|
+
// .getRegistry()
|
51
|
+
// .getInfo(bundleNftId);
|
52
|
+
// IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
|
50
53
|
}
|
51
54
|
|
52
55
|
nftId = this.getRegistry().registerObjectForInstance(
|
53
56
|
productInfo.nftId,
|
54
|
-
|
55
|
-
applicationOwner
|
57
|
+
POLICY(),
|
58
|
+
applicationOwner
|
59
|
+
);
|
56
60
|
|
57
61
|
_policyInfo[nftId] = PolicyInfo(
|
58
62
|
nftId,
|
59
|
-
|
63
|
+
_lifecycleModule.getInitialState(POLICY()),
|
60
64
|
sumInsuredAmount,
|
61
65
|
premiumAmount,
|
66
|
+
0, // premium paid amount
|
62
67
|
lifetime,
|
63
|
-
|
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
|
64
72
|
0, // activatedAt
|
65
73
|
0, // expiredAt
|
66
74
|
0 // closedAt
|
@@ -71,36 +79,36 @@ abstract contract PolicyModule is
|
|
71
79
|
// add logging
|
72
80
|
}
|
73
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
|
+
}
|
74
88
|
|
75
|
-
function activate(
|
76
|
-
external
|
77
|
-
override
|
78
|
-
onlyProductService2
|
79
|
-
{
|
89
|
+
function activate(NftId nftId) external override onlyProductService2 {
|
80
90
|
PolicyInfo storage info = _policyInfo[nftId];
|
91
|
+
// solhint-disable-next-line not-rely-on-time
|
81
92
|
info.activatedAt = block.timestamp;
|
93
|
+
// solhint-disable-next-line not-rely-on-time
|
82
94
|
info.expiredAt = block.timestamp + info.lifetime;
|
83
|
-
info.state =
|
84
|
-
|
85
|
-
|
95
|
+
info.state = _lifecycleModule.checkAndLogTransition(
|
96
|
+
nftId,
|
97
|
+
POLICY(),
|
98
|
+
info.state,
|
99
|
+
ACTIVE()
|
100
|
+
);
|
86
101
|
}
|
87
102
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
external
|
92
|
-
view
|
93
|
-
returns(uint256 bundleNft)
|
94
|
-
{
|
103
|
+
function getBundleNftForPolicy(
|
104
|
+
NftId nftId
|
105
|
+
) external view returns (NftId bundleNft) {
|
95
106
|
return _bundleForPolicy[nftId];
|
96
107
|
}
|
97
108
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
view
|
102
|
-
returns(PolicyInfo memory info)
|
103
|
-
{
|
109
|
+
function getPolicyInfo(
|
110
|
+
NftId nftId
|
111
|
+
) external view returns (PolicyInfo memory info) {
|
104
112
|
return _policyInfo[nftId];
|
105
113
|
}
|
106
114
|
}
|
@@ -2,39 +2,22 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
|
5
|
+
import {NftId} from "../../types/NftId.sol";
|
5
6
|
|
6
7
|
interface IPool {
|
7
|
-
|
8
8
|
struct PoolInfo {
|
9
|
-
|
10
|
-
address wallet;
|
11
|
-
address token;
|
9
|
+
NftId nftId;
|
12
10
|
uint256 capital;
|
13
11
|
uint256 lockedCapital;
|
14
12
|
}
|
15
13
|
}
|
16
14
|
|
17
|
-
interface IPoolModule is
|
18
|
-
|
19
|
-
IRegistryLinked,
|
20
|
-
IPool
|
21
|
-
{
|
22
|
-
|
23
|
-
function underwrite(
|
24
|
-
uint256 poolNftId,
|
25
|
-
uint256 policyNftId
|
26
|
-
)
|
27
|
-
external;
|
15
|
+
interface IPoolModule is IOwnable, IRegistryLinked, IPool {
|
16
|
+
function underwrite(NftId policyNftId, NftId productNftId) external;
|
28
17
|
|
29
|
-
function
|
30
|
-
uint256 nftId,
|
31
|
-
address wallet,
|
32
|
-
address token
|
33
|
-
)
|
34
|
-
external;
|
18
|
+
function registerPool(NftId nftId) external;
|
35
19
|
|
36
|
-
function getPoolInfo(
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
}
|
20
|
+
function getPoolInfo(
|
21
|
+
NftId nftId
|
22
|
+
) external view returns (PoolInfo memory info);
|
23
|
+
}
|
@@ -4,80 +4,78 @@ 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";
|
9
|
+
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
8
10
|
|
9
|
-
abstract contract PoolModule is
|
10
|
-
|
11
|
-
{
|
12
|
-
uint256 public constant INITIAL_CAPITAL = 10000*10**6;
|
11
|
+
abstract contract PoolModule is IPoolModule {
|
12
|
+
using NftIdLib for NftId;
|
13
13
|
|
14
|
-
|
14
|
+
uint256 public constant INITIAL_CAPITAL = 10000 * 10 ** 6;
|
15
|
+
uint256 public constant INITIAL_LOCKED_CAPITAL = 0;
|
15
16
|
|
17
|
+
mapping(NftId nftId => PoolInfo info) private _poolInfo;
|
18
|
+
|
19
|
+
IPolicyModule private _policyModule;
|
20
|
+
ITreasuryModule private _treasuryModule;
|
16
21
|
IProductService private _productService;
|
17
22
|
|
18
23
|
modifier onlyProductService() {
|
19
|
-
require(
|
24
|
+
require(
|
25
|
+
address(_productService) == msg.sender,
|
26
|
+
"ERROR:POL-001:NOT_PRODUCT_SERVICE"
|
27
|
+
);
|
20
28
|
_;
|
21
29
|
}
|
22
30
|
|
23
31
|
constructor(address productService) {
|
32
|
+
_policyModule = IPolicyModule(address(this));
|
33
|
+
_treasuryModule = ITreasuryModule(address(this));
|
24
34
|
_productService = IProductService(productService);
|
25
35
|
}
|
26
36
|
|
27
|
-
function
|
28
|
-
|
29
|
-
address wallet,
|
30
|
-
address token
|
31
|
-
)
|
32
|
-
public
|
33
|
-
override
|
34
|
-
{
|
35
|
-
require(
|
36
|
-
_poolInfo[nftId].nftId == 0,
|
37
|
-
"ERROR:PL-001:ALREADY_CREATED");
|
37
|
+
function registerPool(NftId nftId) public override {
|
38
|
+
require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
|
38
39
|
|
39
40
|
_poolInfo[nftId] = PoolInfo(
|
40
41
|
nftId,
|
41
|
-
wallet,
|
42
|
-
token,
|
43
42
|
INITIAL_CAPITAL,
|
44
|
-
|
43
|
+
INITIAL_LOCKED_CAPITAL
|
45
44
|
);
|
46
|
-
|
47
45
|
}
|
48
46
|
|
49
|
-
|
50
47
|
function underwrite(
|
51
|
-
|
52
|
-
|
53
|
-
)
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
48
|
+
NftId policyNftId,
|
49
|
+
NftId productNftId
|
50
|
+
) external override onlyProductService {
|
51
|
+
IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(
|
52
|
+
policyNftId
|
53
|
+
);
|
54
|
+
require(policyInfo.nftId == policyNftId, "ERROR:PL-002:POLICY_UNKNOWN");
|
55
|
+
|
56
|
+
ITreasuryModule.ProductSetup memory product = _treasuryModule
|
57
|
+
.getProductSetup(productNftId);
|
59
58
|
require(
|
60
|
-
|
61
|
-
"ERROR:PL-
|
59
|
+
product.productNftId == productNftId,
|
60
|
+
"ERROR:PL-003:PRODUCT_SETUP_MISSING"
|
61
|
+
);
|
62
62
|
|
63
|
-
|
64
|
-
|
63
|
+
NftId poolNftId = product.poolNftId;
|
64
|
+
PoolInfo storage poolInfo = _poolInfo[poolNftId];
|
65
|
+
require(poolInfo.nftId == poolNftId, "ERROR:PL-004:POOL_UNKNOWN");
|
65
66
|
|
66
67
|
require(
|
67
|
-
poolInfo.capital - poolInfo.lockedCapital >=
|
68
|
-
|
68
|
+
poolInfo.capital - poolInfo.lockedCapital >=
|
69
|
+
policyInfo.sumInsuredAmount,
|
70
|
+
"ERROR:PL-005:CAPACITY_TOO_LOW"
|
71
|
+
);
|
69
72
|
|
70
73
|
poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
|
71
74
|
}
|
72
75
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
view
|
77
|
-
override
|
78
|
-
returns(PoolInfo memory info)
|
79
|
-
{
|
76
|
+
function getPoolInfo(
|
77
|
+
NftId nftId
|
78
|
+
) external view override returns (PoolInfo memory info) {
|
80
79
|
info = _poolInfo[nftId];
|
81
80
|
}
|
82
|
-
|
83
|
-
}
|
81
|
+
}
|
@@ -1,34 +1,29 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
5
4
|
import {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
6
5
|
import {IInstance} from "../IInstance.sol";
|
7
|
-
|
6
|
+
import {NftId} from "../../types/NftId.sol";
|
8
7
|
|
9
8
|
// TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
|
10
|
-
interface IProductService is
|
11
|
-
IRegistryLinked
|
12
|
-
{
|
13
|
-
|
9
|
+
interface IProductService is IRegistryLinked {
|
14
10
|
function createApplication(
|
15
11
|
address applicationOwner,
|
16
12
|
uint256 sumInsuredAmount,
|
17
13
|
uint256 premiumAmount,
|
18
14
|
uint256 lifetime,
|
19
|
-
|
20
|
-
)
|
21
|
-
external
|
22
|
-
returns(uint256 nftId);
|
15
|
+
NftId bundleNftId
|
16
|
+
) external returns (NftId nftId);
|
23
17
|
|
24
18
|
// function revoke(unit256 nftId) external;
|
25
19
|
|
26
|
-
function underwrite(
|
20
|
+
function underwrite(NftId nftId) external;
|
21
|
+
|
27
22
|
// function decline(uint256 nftId) external;
|
28
23
|
// function expire(uint256 nftId) external;
|
29
|
-
function close(
|
24
|
+
function close(NftId nftId) external;
|
30
25
|
|
31
|
-
|
26
|
+
function collectPremium(NftId nftId) external;
|
32
27
|
|
33
28
|
// function createClaim(uint256 nftId, uint256 claimAmount) external;
|
34
29
|
// function confirmClaim(uint256 nftId, uint256 claimId, uint256 claimAmount) external;
|
@@ -36,10 +31,6 @@ interface IProductService is
|
|
36
31
|
// function closeClaim(uint256 nftId, uint256 claimId) external;
|
37
32
|
}
|
38
33
|
|
39
|
-
|
40
|
-
|
41
|
-
IOwnable,
|
42
|
-
IRegistryLinked
|
43
|
-
{
|
44
|
-
function getProductService() external view returns(IProductService);
|
34
|
+
interface IProductModule is IOwnable, IRegistryLinked {
|
35
|
+
function getProductService() external view returns (IProductService);
|
45
36
|
}
|