@etherisc/gif-next 0.0.2-9b97b55 → 0.0.2-a04040f-684
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 +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 +4 -0
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +479 -0
- package/contracts/components/Component.sol +38 -23
- package/contracts/components/IPool.sol +9 -3
- package/contracts/components/IProduct.sol +10 -6
- package/contracts/components/Pool.sol +37 -14
- package/contracts/components/Product.sol +46 -23
- package/contracts/experiment/errors/Require.sol +10 -5
- package/contracts/experiment/errors/Revert.sol +13 -8
- package/contracts/experiment/inheritance/A.sol +8 -11
- package/contracts/experiment/inheritance/B.sol +10 -5
- package/contracts/experiment/inheritance/C.sol +11 -5
- package/contracts/experiment/inheritance/IA.sol +2 -7
- package/contracts/experiment/inheritance/IB.sol +3 -2
- package/contracts/experiment/inheritance/IC.sol +4 -3
- package/contracts/experiment/statemachine/Dummy.sol +27 -0
- package/contracts/experiment/statemachine/ISM.sol +25 -0
- package/contracts/experiment/statemachine/README.md +112 -0
- package/contracts/experiment/statemachine/SM.sol +57 -0
- package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
- package/contracts/experiment/types/TypeA.sol +14 -9
- package/contracts/experiment/types/TypeB.sol +14 -9
- package/contracts/instance/IInstance.sol +8 -3
- package/contracts/instance/Instance.sol +22 -14
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +144 -118
- package/contracts/instance/component/IComponent.sol +39 -60
- package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
- package/contracts/instance/policy/IPolicy.sol +16 -32
- package/contracts/instance/policy/PolicyModule.sol +47 -40
- package/contracts/instance/pool/IPoolModule.sol +7 -25
- package/contracts/instance/pool/PoolModule.sol +40 -45
- package/contracts/instance/product/IProductService.sol +6 -16
- package/contracts/instance/product/ProductService.sol +76 -48
- package/contracts/instance/treasury/ITreasury.sol +91 -0
- package/contracts/instance/treasury/TokenHandler.sol +24 -0
- package/contracts/instance/treasury/TreasuryModule.sol +168 -0
- package/contracts/mock/Dip.sol +26 -0
- package/contracts/mock/TestPool.sol +16 -0
- package/contracts/mock/TestProduct.sol +39 -0
- package/contracts/mock/Usdc.sol +26 -0
- package/contracts/registry/ChainNft.sol +23 -61
- package/contracts/registry/IChainNft.sol +10 -7
- package/contracts/registry/IRegistry.sol +35 -38
- package/contracts/registry/Registry.sol +57 -57
- package/contracts/types/Blocknumber.sol +76 -18
- package/contracts/types/ChainId.sol +18 -10
- package/contracts/types/Fee.sol +32 -0
- package/contracts/types/NftId.sol +29 -13
- package/contracts/types/ObjectType.sol +107 -0
- package/contracts/types/StateId.sol +91 -0
- package/contracts/types/Timestamp.sol +63 -16
- package/contracts/types/UFixed.sol +210 -0
- package/package.json +14 -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,44 +1,31 @@
|
|
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
6
|
import {IProductService} from "../product/IProductService.sol";
|
8
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
13
|
NftId nftId;
|
23
|
-
|
24
|
-
|
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,
|
@@ -46,21 +33,18 @@ interface IPolicyModule is
|
|
46
33
|
uint256 premiumAmount,
|
47
34
|
uint256 lifetime,
|
48
35
|
NftId bundleNftId
|
49
|
-
)
|
50
|
-
external
|
51
|
-
returns(NftId nftId);
|
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(NftId 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,36 +1,41 @@
|
|
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";
|
10
12
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
{
|
14
|
+
import {LifecycleModule} from "../lifecycle/LifecycleModule.sol";
|
15
|
+
|
16
|
+
abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
16
17
|
using NftIdLib for NftId;
|
17
18
|
|
18
19
|
mapping(NftId nftId => PolicyInfo info) private _policyInfo;
|
19
20
|
mapping(NftId nftId => NftId bundleNftId) private _bundleForPolicy;
|
20
21
|
|
22
|
+
LifecycleModule private _lifecycleModule;
|
21
23
|
IProductService private _productService;
|
22
24
|
|
23
25
|
// TODO find a better place to avoid dupliation
|
24
26
|
modifier onlyProductService2() {
|
25
|
-
require(
|
27
|
+
require(
|
28
|
+
address(_productService) == msg.sender,
|
29
|
+
"ERROR:POL-001:NOT_PRODUCT_SERVICE"
|
30
|
+
);
|
26
31
|
_;
|
27
32
|
}
|
28
33
|
|
29
34
|
constructor(address productService) {
|
35
|
+
_lifecycleModule = LifecycleModule(address(this));
|
30
36
|
_productService = IProductService(productService);
|
31
37
|
}
|
32
38
|
|
33
|
-
|
34
39
|
function createApplication(
|
35
40
|
IRegistry.RegistryInfo memory productInfo,
|
36
41
|
address applicationOwner,
|
@@ -38,30 +43,32 @@ abstract contract PolicyModule is
|
|
38
43
|
uint256 premiumAmount,
|
39
44
|
uint256 lifetime,
|
40
45
|
NftId bundleNftId
|
41
|
-
)
|
42
|
-
external
|
43
|
-
override
|
44
|
-
onlyProductService2
|
45
|
-
returns(NftId nftId)
|
46
|
-
{
|
46
|
+
) external override onlyProductService2 returns (NftId nftId) {
|
47
47
|
// TODO add parameter validation
|
48
|
-
if(bundleNftId.gtz()) {
|
49
|
-
IRegistry.RegistryInfo memory bundleInfo = this
|
48
|
+
if (bundleNftId.gtz()) {
|
49
|
+
// IRegistry.RegistryInfo memory bundleInfo = this
|
50
|
+
// .getRegistry()
|
51
|
+
// .getInfo(bundleNftId);
|
50
52
|
// IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
|
51
53
|
}
|
52
54
|
|
53
55
|
nftId = this.getRegistry().registerObjectForInstance(
|
54
56
|
productInfo.nftId,
|
55
|
-
|
56
|
-
applicationOwner
|
57
|
+
POLICY(),
|
58
|
+
applicationOwner
|
59
|
+
);
|
57
60
|
|
58
61
|
_policyInfo[nftId] = PolicyInfo(
|
59
62
|
nftId,
|
60
|
-
|
63
|
+
_lifecycleModule.getInitialState(POLICY()),
|
61
64
|
sumInsuredAmount,
|
62
65
|
premiumAmount,
|
66
|
+
0, // premium paid amount
|
63
67
|
lifetime,
|
64
|
-
|
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
|
65
72
|
0, // activatedAt
|
66
73
|
0, // expiredAt
|
67
74
|
0 // closedAt
|
@@ -72,36 +79,36 @@ abstract contract PolicyModule is
|
|
72
79
|
// add logging
|
73
80
|
}
|
74
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
|
+
}
|
75
88
|
|
76
|
-
function activate(NftId nftId)
|
77
|
-
external
|
78
|
-
override
|
79
|
-
onlyProductService2
|
80
|
-
{
|
89
|
+
function activate(NftId nftId) external override onlyProductService2 {
|
81
90
|
PolicyInfo storage info = _policyInfo[nftId];
|
91
|
+
// solhint-disable-next-line not-rely-on-time
|
82
92
|
info.activatedAt = block.timestamp;
|
93
|
+
// solhint-disable-next-line not-rely-on-time
|
83
94
|
info.expiredAt = block.timestamp + info.lifetime;
|
84
|
-
info.state =
|
85
|
-
|
86
|
-
|
95
|
+
info.state = _lifecycleModule.checkAndLogTransition(
|
96
|
+
nftId,
|
97
|
+
POLICY(),
|
98
|
+
info.state,
|
99
|
+
ACTIVE()
|
100
|
+
);
|
87
101
|
}
|
88
102
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
external
|
93
|
-
view
|
94
|
-
returns(NftId bundleNft)
|
95
|
-
{
|
103
|
+
function getBundleNftForPolicy(
|
104
|
+
NftId nftId
|
105
|
+
) external view returns (NftId bundleNft) {
|
96
106
|
return _bundleForPolicy[nftId];
|
97
107
|
}
|
98
108
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
view
|
103
|
-
returns(PolicyInfo memory info)
|
104
|
-
{
|
109
|
+
function getPolicyInfo(
|
110
|
+
NftId nftId
|
111
|
+
) external view returns (PolicyInfo memory info) {
|
105
112
|
return _policyInfo[nftId];
|
106
113
|
}
|
107
114
|
}
|
@@ -5,37 +5,19 @@ import {IOwnable, IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol
|
|
5
5
|
import {NftId} from "../../types/NftId.sol";
|
6
6
|
|
7
7
|
interface IPool {
|
8
|
-
|
9
8
|
struct PoolInfo {
|
10
9
|
NftId nftId;
|
11
|
-
address wallet;
|
12
|
-
address token;
|
13
10
|
uint256 capital;
|
14
11
|
uint256 lockedCapital;
|
15
12
|
}
|
16
13
|
}
|
17
14
|
|
18
|
-
interface IPoolModule is
|
19
|
-
|
20
|
-
IRegistryLinked,
|
21
|
-
IPool
|
22
|
-
{
|
23
|
-
|
24
|
-
function underwrite(
|
25
|
-
NftId poolNftId,
|
26
|
-
NftId policyNftId
|
27
|
-
)
|
28
|
-
external;
|
15
|
+
interface IPoolModule is IOwnable, IRegistryLinked, IPool {
|
16
|
+
function underwrite(NftId policyNftId, NftId productNftId) external;
|
29
17
|
|
30
|
-
function
|
31
|
-
NftId nftId,
|
32
|
-
address wallet,
|
33
|
-
address token
|
34
|
-
)
|
35
|
-
external;
|
18
|
+
function registerPool(NftId nftId) external;
|
36
19
|
|
37
|
-
function getPoolInfo(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
20
|
+
function getPoolInfo(
|
21
|
+
NftId nftId
|
22
|
+
) external view returns (PoolInfo memory info);
|
23
|
+
}
|
@@ -4,83 +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";
|
8
9
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
9
10
|
|
10
|
-
abstract contract PoolModule is
|
11
|
-
IPoolModule
|
12
|
-
{
|
11
|
+
abstract contract PoolModule is IPoolModule {
|
13
12
|
using NftIdLib for NftId;
|
14
|
-
|
15
|
-
uint256 public constant INITIAL_CAPITAL = 10000*10**6;
|
13
|
+
|
14
|
+
uint256 public constant INITIAL_CAPITAL = 10000 * 10 ** 6;
|
15
|
+
uint256 public constant INITIAL_LOCKED_CAPITAL = 0;
|
16
16
|
|
17
17
|
mapping(NftId nftId => PoolInfo info) private _poolInfo;
|
18
18
|
|
19
|
+
IPolicyModule private _policyModule;
|
20
|
+
ITreasuryModule private _treasuryModule;
|
19
21
|
IProductService private _productService;
|
20
22
|
|
21
23
|
modifier onlyProductService() {
|
22
|
-
require(
|
24
|
+
require(
|
25
|
+
address(_productService) == msg.sender,
|
26
|
+
"ERROR:POL-001:NOT_PRODUCT_SERVICE"
|
27
|
+
);
|
23
28
|
_;
|
24
29
|
}
|
25
30
|
|
26
31
|
constructor(address productService) {
|
32
|
+
_policyModule = IPolicyModule(address(this));
|
33
|
+
_treasuryModule = ITreasuryModule(address(this));
|
27
34
|
_productService = IProductService(productService);
|
28
35
|
}
|
29
36
|
|
30
|
-
function
|
31
|
-
|
32
|
-
address wallet,
|
33
|
-
address token
|
34
|
-
)
|
35
|
-
public
|
36
|
-
override
|
37
|
-
{
|
38
|
-
require(
|
39
|
-
_poolInfo[nftId].nftId.eqz(),
|
40
|
-
"ERROR:PL-001:ALREADY_CREATED");
|
37
|
+
function registerPool(NftId nftId) public override {
|
38
|
+
require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
|
41
39
|
|
42
40
|
_poolInfo[nftId] = PoolInfo(
|
43
41
|
nftId,
|
44
|
-
wallet,
|
45
|
-
token,
|
46
42
|
INITIAL_CAPITAL,
|
47
|
-
|
43
|
+
INITIAL_LOCKED_CAPITAL
|
48
44
|
);
|
49
|
-
|
50
45
|
}
|
51
46
|
|
52
|
-
|
53
47
|
function underwrite(
|
54
|
-
NftId
|
55
|
-
NftId
|
56
|
-
)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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);
|
62
58
|
require(
|
63
|
-
|
64
|
-
"ERROR:PL-
|
59
|
+
product.productNftId == productNftId,
|
60
|
+
"ERROR:PL-003:PRODUCT_SETUP_MISSING"
|
61
|
+
);
|
65
62
|
|
66
|
-
|
67
|
-
|
63
|
+
NftId poolNftId = product.poolNftId;
|
64
|
+
PoolInfo storage poolInfo = _poolInfo[poolNftId];
|
65
|
+
require(poolInfo.nftId == poolNftId, "ERROR:PL-004:POOL_UNKNOWN");
|
68
66
|
|
69
67
|
require(
|
70
|
-
poolInfo.capital - poolInfo.lockedCapital >=
|
71
|
-
|
68
|
+
poolInfo.capital - poolInfo.lockedCapital >=
|
69
|
+
policyInfo.sumInsuredAmount,
|
70
|
+
"ERROR:PL-005:CAPACITY_TOO_LOW"
|
71
|
+
);
|
72
72
|
|
73
73
|
poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
|
74
74
|
}
|
75
75
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
view
|
80
|
-
override
|
81
|
-
returns(PoolInfo memory info)
|
82
|
-
{
|
76
|
+
function getPoolInfo(
|
77
|
+
NftId nftId
|
78
|
+
) external view override returns (PoolInfo memory info) {
|
83
79
|
info = _poolInfo[nftId];
|
84
80
|
}
|
85
|
-
|
86
|
-
}
|
81
|
+
}
|
@@ -1,35 +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
|
-
|
10
8
|
// TODO or name this IProtectionService to have Product be something more generic (loan, savings account, ...)
|
11
|
-
interface IProductService is
|
12
|
-
IRegistryLinked
|
13
|
-
{
|
14
|
-
|
9
|
+
interface IProductService is IRegistryLinked {
|
15
10
|
function createApplication(
|
16
11
|
address applicationOwner,
|
17
12
|
uint256 sumInsuredAmount,
|
18
13
|
uint256 premiumAmount,
|
19
14
|
uint256 lifetime,
|
20
15
|
NftId bundleNftId
|
21
|
-
)
|
22
|
-
external
|
23
|
-
returns(NftId nftId);
|
16
|
+
) external returns (NftId nftId);
|
24
17
|
|
25
18
|
// function revoke(unit256 nftId) external;
|
26
19
|
|
27
20
|
function underwrite(NftId nftId) external;
|
21
|
+
|
28
22
|
// function decline(uint256 nftId) external;
|
29
23
|
// function expire(uint256 nftId) external;
|
30
24
|
function close(NftId nftId) external;
|
31
25
|
|
32
|
-
|
26
|
+
function collectPremium(NftId nftId) external;
|
33
27
|
|
34
28
|
// function createClaim(uint256 nftId, uint256 claimAmount) external;
|
35
29
|
// function confirmClaim(uint256 nftId, uint256 claimId, uint256 claimAmount) external;
|
@@ -37,10 +31,6 @@ interface IProductService is
|
|
37
31
|
// function closeClaim(uint256 nftId, uint256 claimId) external;
|
38
32
|
}
|
39
33
|
|
40
|
-
|
41
|
-
|
42
|
-
IOwnable,
|
43
|
-
IRegistryLinked
|
44
|
-
{
|
45
|
-
function getProductService() external view returns(IProductService);
|
34
|
+
interface IProductModule is IOwnable, IRegistryLinked {
|
35
|
+
function getProductService() external view returns (IProductService);
|
46
36
|
}
|