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