@etherisc/gif-next 0.0.2-9b97b55 → 0.0.2-a0d749a
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 +24 -0
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- 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/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +2 -2
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +2 -2
- 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/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/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +2 -2
- 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/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +2 -2
- 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/IComponentModule.dbg.json +1 -1
- 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/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/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- 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/PoolModule.sol/PoolModule.dbg.json +1 -1
- 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/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 +2 -2
- 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/IRegistry.dbg.json +1 -1
- 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/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
- 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/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 +453 -0
- package/contracts/components/Component.sol +16 -18
- package/contracts/components/IPool.sol +3 -3
- package/contracts/components/IProduct.sol +3 -6
- package/contracts/components/Pool.sol +6 -13
- package/contracts/components/Product.sol +10 -21
- 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/types/TypeA.sol +14 -9
- package/contracts/experiment/types/TypeB.sol +14 -9
- package/contracts/instance/IInstance.sol +1 -3
- package/contracts/instance/Instance.sol +13 -13
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +63 -98
- package/contracts/instance/component/IComponent.sol +30 -52
- package/contracts/instance/policy/IPolicy.sol +9 -24
- package/contracts/instance/policy/PolicyModule.sol +19 -35
- package/contracts/instance/pool/IPoolModule.sol +7 -19
- package/contracts/instance/pool/PoolModule.sol +22 -35
- package/contracts/instance/product/IProductService.sol +5 -15
- package/contracts/instance/product/ProductService.sol +43 -39
- package/contracts/registry/ChainNft.sol +23 -61
- package/contracts/registry/IChainNft.sol +10 -7
- package/contracts/registry/IRegistry.sol +46 -36
- package/contracts/registry/Registry.sol +80 -53
- package/contracts/types/Blocknumber.sol +76 -18
- package/contracts/types/ChainId.sol +18 -10
- package/contracts/types/NftId.sol +29 -13
- package/contracts/types/Timestamp.sol +63 -16
- package/contracts/types/UFixed.sol +205 -0
- package/package.json +9 -4
@@ -1,13 +1,11 @@
|
|
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
|
interface IComponent {
|
10
|
-
|
11
9
|
// TODO decide if enum or uints with constants (as in IRegistry.PRODUCT())
|
12
10
|
enum CState {
|
13
11
|
Undefined,
|
@@ -22,74 +20,54 @@ interface IComponent {
|
|
22
20
|
}
|
23
21
|
}
|
24
22
|
|
25
|
-
|
26
23
|
interface IInstanceLinked {
|
27
24
|
// function setInstance(address instance) external;
|
28
|
-
function getInstance() external view returns(IInstance instance);
|
25
|
+
function getInstance() external view returns (IInstance instance);
|
29
26
|
}
|
30
27
|
|
28
|
+
interface IComponentContract is IRegisterable, IInstanceLinked, IComponent {}
|
31
29
|
|
32
|
-
interface
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
{ }
|
30
|
+
interface IComponentOwnerService is IRegistryLinked {
|
31
|
+
function register(
|
32
|
+
IComponentContract component
|
33
|
+
) external returns (NftId nftId);
|
37
34
|
|
38
|
-
|
39
|
-
interface IComponentOwnerService is IRegistryLinked{
|
40
|
-
|
41
|
-
function register(IComponentContract component) external returns(NftId nftId);
|
42
35
|
function lock(IComponentContract component) external;
|
36
|
+
|
43
37
|
function unlock(IComponentContract component) external;
|
44
38
|
}
|
45
39
|
|
40
|
+
interface IComponentModule is IOwnable, IRegistryLinked, IComponent {
|
41
|
+
function registerComponent(
|
42
|
+
IComponentContract component
|
43
|
+
) external returns (NftId nftId);
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
IComponent
|
51
|
-
{
|
45
|
+
function setComponentInfo(
|
46
|
+
ComponentInfo memory info
|
47
|
+
) external returns (NftId componentNftId);
|
52
48
|
|
53
|
-
function
|
54
|
-
|
55
|
-
|
49
|
+
function getComponentInfo(
|
50
|
+
NftId nftId
|
51
|
+
) external view returns (ComponentInfo memory info);
|
56
52
|
|
57
|
-
function
|
58
|
-
|
59
|
-
|
53
|
+
function getComponentOwner(
|
54
|
+
NftId nftId
|
55
|
+
) external view returns (address owner);
|
60
56
|
|
61
|
-
function
|
62
|
-
|
63
|
-
|
64
|
-
returns(ComponentInfo memory info);
|
57
|
+
function getComponentId(
|
58
|
+
address componentAddress
|
59
|
+
) external view returns (NftId nftId);
|
65
60
|
|
66
|
-
function
|
67
|
-
external
|
68
|
-
view
|
69
|
-
returns(address owner);
|
61
|
+
function getComponentId(uint256 idx) external view returns (NftId nftId);
|
70
62
|
|
71
|
-
function
|
72
|
-
|
73
|
-
|
74
|
-
returns(NftId nftId);
|
63
|
+
function getPoolNftId(
|
64
|
+
NftId productNftId
|
65
|
+
) external view returns (NftId poolNftId);
|
75
66
|
|
76
|
-
function
|
77
|
-
external
|
78
|
-
view
|
79
|
-
returns(NftId nftId);
|
80
|
-
|
81
|
-
function getPoolNftId(NftId productNftId)
|
82
|
-
external
|
83
|
-
view
|
84
|
-
returns(NftId poolNftId);
|
85
|
-
|
86
|
-
function components()
|
87
|
-
external
|
88
|
-
view
|
89
|
-
returns(uint256 numberOfCompnents);
|
67
|
+
function components() external view returns (uint256 numberOfCompnents);
|
90
68
|
|
91
69
|
function getComponentOwnerService()
|
92
70
|
external
|
93
71
|
view
|
94
|
-
returns(IComponentOwnerService);
|
95
|
-
}
|
72
|
+
returns (IComponentOwnerService);
|
73
|
+
}
|
@@ -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 {IOwnable, IRegistryLinked, IRegisterable, IRegistry} from "../../registry/IRegistry.sol";
|
6
5
|
import {IInstance} from "../IInstance.sol";
|
7
6
|
import {IProductService} from "../product/IProductService.sol";
|
@@ -9,7 +8,6 @@ import {NftId} from "../../types/NftId.sol";
|
|
9
8
|
|
10
9
|
// TODO check if there is value to introuce IContract and let IPolicy derive from IContract
|
11
10
|
interface IPolicy {
|
12
|
-
|
13
11
|
enum PolicyState {
|
14
12
|
Undefined,
|
15
13
|
Applied,
|
@@ -21,11 +19,9 @@ interface IPolicy {
|
|
21
19
|
struct PolicyInfo {
|
22
20
|
NftId nftId;
|
23
21
|
PolicyState state; // applied, withdrawn, rejected, active, closed
|
24
|
-
|
25
22
|
uint256 sumInsuredAmount;
|
26
23
|
uint256 premiumAmount;
|
27
24
|
uint256 lifetime; // activatedAt + lifetime >= expiredAt
|
28
|
-
|
29
25
|
uint256 createdAt;
|
30
26
|
uint256 activatedAt; // time of underwriting
|
31
27
|
uint256 expiredAt; // no new claims
|
@@ -33,12 +29,7 @@ interface IPolicy {
|
|
33
29
|
}
|
34
30
|
}
|
35
31
|
|
36
|
-
interface IPolicyModule is
|
37
|
-
IOwnable,
|
38
|
-
IRegistryLinked,
|
39
|
-
IPolicy
|
40
|
-
{
|
41
|
-
|
32
|
+
interface IPolicyModule is IOwnable, IRegistryLinked, IPolicy {
|
42
33
|
function createApplication(
|
43
34
|
IRegistry.RegistryInfo memory productInfo,
|
44
35
|
address applicationOwner,
|
@@ -46,21 +37,15 @@ interface IPolicyModule is
|
|
46
37
|
uint256 premiumAmount,
|
47
38
|
uint256 lifetime,
|
48
39
|
NftId bundleNftId
|
49
|
-
)
|
50
|
-
external
|
51
|
-
returns(NftId nftId);
|
52
|
-
|
53
|
-
function activate(NftId nftId)
|
54
|
-
external;
|
40
|
+
) external returns (NftId nftId);
|
55
41
|
|
56
|
-
function
|
57
|
-
external
|
58
|
-
view
|
59
|
-
returns(NftId bundleNft);
|
42
|
+
function activate(NftId nftId) external;
|
60
43
|
|
61
|
-
function
|
62
|
-
|
63
|
-
|
64
|
-
returns(PolicyInfo memory info);
|
44
|
+
function getBundleNftForPolicy(
|
45
|
+
NftId nftId
|
46
|
+
) external view returns (NftId bundleNft);
|
65
47
|
|
48
|
+
function getPolicyInfo(
|
49
|
+
NftId nftId
|
50
|
+
) external view returns (PolicyInfo memory info);
|
66
51
|
}
|
@@ -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 {IOwnable, IRegistryLinked, IRegisterable} from "../../registry/IRegistry.sol";
|
6
5
|
import {IRegistry, IRegistryLinked} from "../../registry/IRegistry.sol";
|
7
6
|
|
@@ -9,10 +8,7 @@ import {IProductService} from "../product/IProductService.sol";
|
|
9
8
|
import {IPolicy, IPolicyModule} from "./IPolicy.sol";
|
10
9
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
11
10
|
|
12
|
-
abstract contract PolicyModule is
|
13
|
-
IRegistryLinked,
|
14
|
-
IPolicyModule
|
15
|
-
{
|
11
|
+
abstract contract PolicyModule is IRegistryLinked, IPolicyModule {
|
16
12
|
using NftIdLib for NftId;
|
17
13
|
|
18
14
|
mapping(NftId nftId => PolicyInfo info) private _policyInfo;
|
@@ -22,7 +18,10 @@ abstract contract PolicyModule is
|
|
22
18
|
|
23
19
|
// TODO find a better place to avoid dupliation
|
24
20
|
modifier onlyProductService2() {
|
25
|
-
require(
|
21
|
+
require(
|
22
|
+
address(_productService) == msg.sender,
|
23
|
+
"ERROR:POL-001:NOT_PRODUCT_SERVICE"
|
24
|
+
);
|
26
25
|
_;
|
27
26
|
}
|
28
27
|
|
@@ -30,7 +29,6 @@ abstract contract PolicyModule is
|
|
30
29
|
_productService = IProductService(productService);
|
31
30
|
}
|
32
31
|
|
33
|
-
|
34
32
|
function createApplication(
|
35
33
|
IRegistry.RegistryInfo memory productInfo,
|
36
34
|
address applicationOwner,
|
@@ -38,22 +36,20 @@ abstract contract PolicyModule is
|
|
38
36
|
uint256 premiumAmount,
|
39
37
|
uint256 lifetime,
|
40
38
|
NftId bundleNftId
|
41
|
-
)
|
42
|
-
external
|
43
|
-
override
|
44
|
-
onlyProductService2
|
45
|
-
returns(NftId nftId)
|
46
|
-
{
|
39
|
+
) external override onlyProductService2 returns (NftId nftId) {
|
47
40
|
// TODO add parameter validation
|
48
|
-
if(bundleNftId.gtz()) {
|
49
|
-
IRegistry.RegistryInfo memory bundleInfo = this
|
41
|
+
if (bundleNftId.gtz()) {
|
42
|
+
IRegistry.RegistryInfo memory bundleInfo = this
|
43
|
+
.getRegistry()
|
44
|
+
.getInfo(bundleNftId);
|
50
45
|
// IRegistry.RegistryInfo memory poolInfo = this.getRegistry().getInfo(bundleInfo.parentNftId);
|
51
46
|
}
|
52
47
|
|
53
48
|
nftId = this.getRegistry().registerObjectForInstance(
|
54
49
|
productInfo.nftId,
|
55
50
|
this.getRegistry().POLICY(),
|
56
|
-
applicationOwner
|
51
|
+
applicationOwner
|
52
|
+
);
|
57
53
|
|
58
54
|
_policyInfo[nftId] = PolicyInfo(
|
59
55
|
nftId,
|
@@ -72,12 +68,7 @@ abstract contract PolicyModule is
|
|
72
68
|
// add logging
|
73
69
|
}
|
74
70
|
|
75
|
-
|
76
|
-
function activate(NftId nftId)
|
77
|
-
external
|
78
|
-
override
|
79
|
-
onlyProductService2
|
80
|
-
{
|
71
|
+
function activate(NftId nftId) external override onlyProductService2 {
|
81
72
|
PolicyInfo storage info = _policyInfo[nftId];
|
82
73
|
info.activatedAt = block.timestamp;
|
83
74
|
info.expiredAt = block.timestamp + info.lifetime;
|
@@ -86,22 +77,15 @@ abstract contract PolicyModule is
|
|
86
77
|
// add logging
|
87
78
|
}
|
88
79
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
external
|
93
|
-
view
|
94
|
-
returns(NftId bundleNft)
|
95
|
-
{
|
80
|
+
function getBundleNftForPolicy(
|
81
|
+
NftId nftId
|
82
|
+
) external view returns (NftId bundleNft) {
|
96
83
|
return _bundleForPolicy[nftId];
|
97
84
|
}
|
98
85
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
view
|
103
|
-
returns(PolicyInfo memory info)
|
104
|
-
{
|
86
|
+
function getPolicyInfo(
|
87
|
+
NftId nftId
|
88
|
+
) external view returns (PolicyInfo memory info) {
|
105
89
|
return _policyInfo[nftId];
|
106
90
|
}
|
107
91
|
}
|
@@ -5,7 +5,6 @@ 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
10
|
address wallet;
|
@@ -15,27 +14,16 @@ interface IPool {
|
|
15
14
|
}
|
16
15
|
}
|
17
16
|
|
18
|
-
interface IPoolModule is
|
19
|
-
|
20
|
-
IRegistryLinked,
|
21
|
-
IPool
|
22
|
-
{
|
23
|
-
|
24
|
-
function underwrite(
|
25
|
-
NftId poolNftId,
|
26
|
-
NftId policyNftId
|
27
|
-
)
|
28
|
-
external;
|
17
|
+
interface IPoolModule is IOwnable, IRegistryLinked, IPool {
|
18
|
+
function underwrite(NftId poolNftId, NftId policyNftId) external;
|
29
19
|
|
30
20
|
function createPoolInfo(
|
31
21
|
NftId nftId,
|
32
22
|
address wallet,
|
33
23
|
address token
|
34
|
-
)
|
35
|
-
external;
|
24
|
+
) external;
|
36
25
|
|
37
|
-
function getPoolInfo(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
}
|
26
|
+
function getPoolInfo(
|
27
|
+
NftId nftId
|
28
|
+
) external view returns (PoolInfo memory info);
|
29
|
+
}
|
@@ -7,19 +7,20 @@ import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
|
|
7
7
|
import {IPoolModule} from "./IPoolModule.sol";
|
8
8
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
9
9
|
|
10
|
-
abstract contract PoolModule is
|
11
|
-
IPoolModule
|
12
|
-
{
|
10
|
+
abstract contract PoolModule is IPoolModule {
|
13
11
|
using NftIdLib for NftId;
|
14
|
-
|
15
|
-
uint256 public constant INITIAL_CAPITAL = 10000*10**6;
|
12
|
+
|
13
|
+
uint256 public constant INITIAL_CAPITAL = 10000 * 10 ** 6;
|
16
14
|
|
17
15
|
mapping(NftId nftId => PoolInfo info) private _poolInfo;
|
18
16
|
|
19
17
|
IProductService private _productService;
|
20
18
|
|
21
19
|
modifier onlyProductService() {
|
22
|
-
require(
|
20
|
+
require(
|
21
|
+
address(_productService) == msg.sender,
|
22
|
+
"ERROR:POL-001:NOT_PRODUCT_SERVICE"
|
23
|
+
);
|
23
24
|
_;
|
24
25
|
}
|
25
26
|
|
@@ -31,13 +32,8 @@ abstract contract PoolModule is
|
|
31
32
|
NftId nftId,
|
32
33
|
address wallet,
|
33
34
|
address token
|
34
|
-
)
|
35
|
-
|
36
|
-
override
|
37
|
-
{
|
38
|
-
require(
|
39
|
-
_poolInfo[nftId].nftId.eqz(),
|
40
|
-
"ERROR:PL-001:ALREADY_CREATED");
|
35
|
+
) public override {
|
36
|
+
require(_poolInfo[nftId].nftId.eqz(), "ERROR:PL-001:ALREADY_CREATED");
|
41
37
|
|
42
38
|
_poolInfo[nftId] = PoolInfo(
|
43
39
|
nftId,
|
@@ -46,41 +42,32 @@ abstract contract PoolModule is
|
|
46
42
|
INITIAL_CAPITAL,
|
47
43
|
0 // locked capital
|
48
44
|
);
|
49
|
-
|
50
45
|
}
|
51
46
|
|
52
|
-
|
53
47
|
function underwrite(
|
54
48
|
NftId poolNftId,
|
55
49
|
NftId policyNftId
|
56
|
-
)
|
57
|
-
external
|
58
|
-
override
|
59
|
-
onlyProductService
|
60
|
-
{
|
50
|
+
) external override onlyProductService {
|
61
51
|
PoolInfo storage poolInfo = _poolInfo[poolNftId];
|
62
|
-
require(
|
63
|
-
poolInfo.nftId == poolNftId,
|
64
|
-
"ERROR:PL-002:POOL_UNKNOWN");
|
52
|
+
require(poolInfo.nftId == poolNftId, "ERROR:PL-002:POOL_UNKNOWN");
|
65
53
|
|
66
54
|
IPolicyModule policyModule = IPolicyModule(address(this));
|
67
|
-
IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(
|
55
|
+
IPolicy.PolicyInfo memory policyInfo = policyModule.getPolicyInfo(
|
56
|
+
policyNftId
|
57
|
+
);
|
68
58
|
|
69
59
|
require(
|
70
|
-
poolInfo.capital - poolInfo.lockedCapital >=
|
71
|
-
|
60
|
+
poolInfo.capital - poolInfo.lockedCapital >=
|
61
|
+
policyInfo.sumInsuredAmount,
|
62
|
+
"ERROR:PL-003:CAPACITY_TOO_LOW"
|
63
|
+
);
|
72
64
|
|
73
65
|
poolInfo.lockedCapital += policyInfo.sumInsuredAmount;
|
74
66
|
}
|
75
67
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
view
|
80
|
-
override
|
81
|
-
returns(PoolInfo memory info)
|
82
|
-
{
|
68
|
+
function getPoolInfo(
|
69
|
+
NftId nftId
|
70
|
+
) external view override returns (PoolInfo memory info) {
|
83
71
|
info = _poolInfo[nftId];
|
84
72
|
}
|
85
|
-
|
86
|
-
}
|
73
|
+
}
|
@@ -1,30 +1,24 @@
|
|
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;
|
@@ -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";
|
@@ -14,16 +13,10 @@ import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
|
|
14
13
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
15
14
|
|
16
15
|
// TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
|
17
|
-
contract ProductService is
|
18
|
-
RegistryLinked,
|
19
|
-
IProductService
|
20
|
-
{
|
16
|
+
contract ProductService is RegistryLinked, IProductService {
|
21
17
|
using NftIdLib for NftId;
|
22
|
-
|
23
|
-
constructor(address registry)
|
24
|
-
RegistryLinked(registry)
|
25
|
-
{ }
|
26
18
|
|
19
|
+
constructor(address registry) RegistryLinked(registry) {}
|
27
20
|
|
28
21
|
function createApplication(
|
29
22
|
address applicationOwner,
|
@@ -31,20 +24,26 @@ contract ProductService is
|
|
31
24
|
uint256 premiumAmount,
|
32
25
|
uint256 lifetime,
|
33
26
|
NftId bundleNftId
|
34
|
-
)
|
35
|
-
external
|
36
|
-
override
|
37
|
-
returns(NftId nftId)
|
38
|
-
{
|
27
|
+
) external override returns (NftId nftId) {
|
39
28
|
// same as only registered product
|
40
29
|
NftId productNftId = _registry.getNftId(msg.sender);
|
41
30
|
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
42
|
-
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
32
|
+
productNftId
|
33
|
+
);
|
34
|
+
require(
|
35
|
+
productInfo.objectType == _registry.PRODUCT(),
|
36
|
+
"ERROR_NOT_PRODUCT"
|
37
|
+
);
|
38
|
+
|
39
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
40
|
+
productInfo.parentNftId
|
41
|
+
);
|
46
42
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
47
|
-
require(
|
43
|
+
require(
|
44
|
+
instanceInfo.objectType == _registry.INSTANCE(),
|
45
|
+
"ERROR_NOT_INSTANCE"
|
46
|
+
);
|
48
47
|
|
49
48
|
IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
|
50
49
|
nftId = policyModule.createApplication(
|
@@ -53,34 +52,42 @@ contract ProductService is
|
|
53
52
|
sumInsuredAmount,
|
54
53
|
premiumAmount,
|
55
54
|
lifetime,
|
56
|
-
bundleNftId
|
55
|
+
bundleNftId
|
56
|
+
);
|
57
57
|
|
58
58
|
// add logging
|
59
59
|
}
|
60
60
|
|
61
|
-
function underwrite(NftId nftId)
|
62
|
-
external
|
63
|
-
override
|
64
|
-
{
|
61
|
+
function underwrite(NftId nftId) external override {
|
65
62
|
// same as only registered product
|
66
63
|
NftId productNftId = _registry.getNftId(msg.sender);
|
67
64
|
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
68
|
-
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
66
|
+
productNftId
|
67
|
+
);
|
68
|
+
require(
|
69
|
+
productInfo.objectType == _registry.PRODUCT(),
|
70
|
+
"ERROR_NOT_PRODUCT"
|
71
|
+
);
|
72
|
+
|
73
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
74
|
+
productInfo.parentNftId
|
75
|
+
);
|
72
76
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
73
|
-
require(
|
77
|
+
require(
|
78
|
+
instanceInfo.objectType == _registry.INSTANCE(),
|
79
|
+
"ERROR_NOT_INSTANCE"
|
80
|
+
);
|
74
81
|
|
75
82
|
// get responsible pool
|
76
|
-
IComponentModule componentModule = IComponentModule(
|
83
|
+
IComponentModule componentModule = IComponentModule(
|
84
|
+
instanceInfo.objectAddress
|
85
|
+
);
|
77
86
|
NftId poolNftId = componentModule.getPoolNftId(productNftId);
|
78
87
|
|
79
88
|
// lock capital (and update pool accounting)
|
80
89
|
IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
|
81
|
-
poolModule.underwrite(
|
82
|
-
poolNftId,
|
83
|
-
nftId);
|
90
|
+
poolModule.underwrite(poolNftId, nftId);
|
84
91
|
|
85
92
|
// activate policy
|
86
93
|
IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
|
@@ -92,17 +99,14 @@ contract ProductService is
|
|
92
99
|
function close(NftId nftId) external override {}
|
93
100
|
}
|
94
101
|
|
95
|
-
abstract contract ProductModule is
|
96
|
-
IProductModule
|
97
|
-
{
|
102
|
+
abstract contract ProductModule is IProductModule {
|
98
103
|
IProductService private _productService;
|
99
104
|
|
100
105
|
constructor(address productService) {
|
101
106
|
_productService = IProductService(productService);
|
102
107
|
}
|
103
108
|
|
104
|
-
function getProductService() external view returns(IProductService) {
|
109
|
+
function getProductService() external view returns (IProductService) {
|
105
110
|
return _productService;
|
106
111
|
}
|
107
|
-
|
108
|
-
}
|
112
|
+
}
|