@etherisc/gif-next 0.0.2-3ae3aa8 → 0.0.2-3e0ffc8-142
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 +2 -1
- 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/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- 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/TypeB.sol/TypeBLib.dbg.json +1 -1
- 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/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/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- 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/UFixed.sol/UFixedMathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +2 -2
- package/contracts/components/Component.sol +25 -8
- package/contracts/components/IPool.sol +3 -1
- package/contracts/components/IProduct.sol +4 -2
- package/contracts/components/Pool.sol +27 -4
- package/contracts/components/Product.sol +30 -4
- 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/instance/IInstance.sol +5 -1
- package/contracts/instance/Instance.sol +11 -6
- package/contracts/instance/component/ComponentModule.sol +80 -39
- package/contracts/instance/component/IComponent.sol +15 -12
- package/contracts/instance/lifecycle/ILifecycle.sol +32 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +91 -0
- package/contracts/instance/policy/IPolicy.sol +9 -8
- package/contracts/instance/policy/PolicyModule.sol +28 -12
- package/contracts/instance/pool/IPoolModule.sol +4 -11
- package/contracts/instance/pool/PoolModule.sol +27 -18
- package/contracts/instance/product/IProductService.sol +1 -1
- package/contracts/instance/product/ProductService.sol +48 -42
- 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/IRegistry.sol +6 -17
- package/contracts/registry/Registry.sol +6 -38
- package/contracts/types/Fee.sol +30 -0
- package/contracts/types/ObjectType.sol +50 -0
- package/contracts/types/StateId.sol +46 -0
- package/contracts/types/UFixed.sol +1 -0
- package/package.json +4 -3
|
@@ -8,8 +8,9 @@ import {IRegistry} from "../../registry/IRegistry.sol";
|
|
|
8
8
|
import {IPolicyModule} from "../policy/IPolicy.sol";
|
|
9
9
|
import {RegistryLinked} from "../../registry/Registry.sol";
|
|
10
10
|
import {IProductService, IProductModule} from "./IProductService.sol";
|
|
11
|
-
import {
|
|
11
|
+
import {ITreasuryModule} from "../../instance/treasury/ITreasury.sol";
|
|
12
12
|
import {IPoolModule} from "../../instance/pool/IPoolModule.sol";
|
|
13
|
+
import {ObjectType, INSTANCE, PRODUCT} from "../../types/ObjectType.sol";
|
|
13
14
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
|
14
15
|
|
|
15
16
|
// TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
|
|
@@ -28,22 +29,12 @@ contract ProductService is RegistryLinked, IProductService {
|
|
|
28
29
|
// same as only registered product
|
|
29
30
|
NftId productNftId = _registry.getNftId(msg.sender);
|
|
30
31
|
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
|
31
|
-
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
require(
|
|
35
|
-
productInfo.objectType == _registry.PRODUCT(),
|
|
36
|
-
"ERROR_NOT_PRODUCT"
|
|
37
|
-
);
|
|
32
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
|
|
33
|
+
require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
|
|
38
34
|
|
|
39
|
-
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
|
40
|
-
productInfo.parentNftId
|
|
41
|
-
);
|
|
35
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
|
|
42
36
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
|
43
|
-
require(
|
|
44
|
-
instanceInfo.objectType == _registry.INSTANCE(),
|
|
45
|
-
"ERROR_NOT_INSTANCE"
|
|
46
|
-
);
|
|
37
|
+
require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
|
|
47
38
|
|
|
48
39
|
IPolicyModule policyModule = IPolicyModule(instanceInfo.objectAddress);
|
|
49
40
|
nftId = policyModule.createApplication(
|
|
@@ -58,45 +49,60 @@ contract ProductService is RegistryLinked, IProductService {
|
|
|
58
49
|
// add logging
|
|
59
50
|
}
|
|
60
51
|
|
|
61
|
-
function underwrite(NftId
|
|
52
|
+
function underwrite(NftId policyNftId) external override {
|
|
53
|
+
// validation
|
|
62
54
|
// same as only registered product
|
|
63
55
|
NftId productNftId = _registry.getNftId(msg.sender);
|
|
64
56
|
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
|
65
|
-
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
require(
|
|
69
|
-
productInfo.objectType == _registry.PRODUCT(),
|
|
70
|
-
"ERROR_NOT_PRODUCT"
|
|
71
|
-
);
|
|
57
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
|
|
58
|
+
require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
|
|
72
59
|
|
|
73
|
-
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(
|
|
74
|
-
productInfo.parentNftId
|
|
75
|
-
);
|
|
60
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
|
|
76
61
|
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
|
77
|
-
require(
|
|
78
|
-
instanceInfo.objectType == _registry.INSTANCE(),
|
|
79
|
-
"ERROR_NOT_INSTANCE"
|
|
80
|
-
);
|
|
62
|
+
require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
|
|
81
63
|
|
|
82
|
-
//
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
NftId poolNftId = componentModule.getPoolNftId(productNftId);
|
|
87
|
-
|
|
88
|
-
// lock capital (and update pool accounting)
|
|
89
|
-
IPoolModule poolModule = IPoolModule(instanceInfo.objectAddress);
|
|
90
|
-
poolModule.underwrite(poolNftId, nftId);
|
|
64
|
+
// underwrite policy
|
|
65
|
+
address instanceAddress = instanceInfo.objectAddress;
|
|
66
|
+
IPoolModule poolModule = IPoolModule(instanceAddress);
|
|
67
|
+
poolModule.underwrite(policyNftId, productNftId);
|
|
91
68
|
|
|
92
69
|
// activate policy
|
|
93
|
-
IPolicyModule policyModule = IPolicyModule(
|
|
94
|
-
policyModule.activate(
|
|
70
|
+
IPolicyModule policyModule = IPolicyModule(instanceAddress);
|
|
71
|
+
policyModule.activate(policyNftId);
|
|
95
72
|
|
|
96
73
|
// add logging
|
|
97
74
|
}
|
|
98
75
|
|
|
99
|
-
function
|
|
76
|
+
function collectPremium(NftId policyNftId)
|
|
77
|
+
external
|
|
78
|
+
override
|
|
79
|
+
{
|
|
80
|
+
// validation same as other functions, eg underwrite
|
|
81
|
+
// TODO unify validation into modifier and/or other suitable approaches
|
|
82
|
+
// same as only registered product
|
|
83
|
+
NftId productNftId = _registry.getNftId(msg.sender);
|
|
84
|
+
require(productNftId.gtz(), "ERROR_PRODUCT_UNKNOWN");
|
|
85
|
+
IRegistry.RegistryInfo memory productInfo = _registry.getInfo(productNftId);
|
|
86
|
+
require(productInfo.objectType == PRODUCT(), "ERROR_NOT_PRODUCT");
|
|
87
|
+
|
|
88
|
+
IRegistry.RegistryInfo memory instanceInfo = _registry.getInfo(productInfo.parentNftId);
|
|
89
|
+
require(instanceInfo.nftId.gtz(), "ERROR_INSTANCE_UNKNOWN");
|
|
90
|
+
require(instanceInfo.objectType == INSTANCE(), "ERROR_NOT_INSTANCE");
|
|
91
|
+
|
|
92
|
+
// process/collect premium: book keeping for policy
|
|
93
|
+
address instanceAddress = instanceInfo.objectAddress;
|
|
94
|
+
IPolicyModule policyModule = IPolicyModule(instanceAddress);
|
|
95
|
+
policyModule.processPremium(policyNftId);
|
|
96
|
+
|
|
97
|
+
// process/collect premium: actual token transfer
|
|
98
|
+
ITreasuryModule treasuryModule = ITreasuryModule(instanceAddress);
|
|
99
|
+
treasuryModule.processPremium(policyNftId, productNftId);
|
|
100
|
+
|
|
101
|
+
// TODO add logging
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function close(NftId policyNftId) external override {}
|
|
105
|
+
|
|
100
106
|
}
|
|
101
107
|
|
|
102
108
|
abstract contract ProductModule is IProductModule {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
|
|
6
|
+
contract TokenHandler {
|
|
7
|
+
|
|
8
|
+
// TODO use oz safeTransferFrom
|
|
9
|
+
|
|
10
|
+
IERC20 _token;
|
|
11
|
+
|
|
12
|
+
constructor(address token) {
|
|
13
|
+
_token = IERC20(token);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// TODO add logging
|
|
17
|
+
function transfer(
|
|
18
|
+
address from,
|
|
19
|
+
address to,
|
|
20
|
+
uint256 amount
|
|
21
|
+
)
|
|
22
|
+
external
|
|
23
|
+
// TODO add authz (only treasury)
|
|
24
|
+
{
|
|
25
|
+
_token.transferFrom(from, to, amount);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
|
+
|
|
6
|
+
import {NftId} from "../../types/NftId.sol";
|
|
7
|
+
import {Fee, feeIsZero} from "../../types/Fee.sol";
|
|
8
|
+
import {UFixed} from "../../types/UFixed.sol";
|
|
9
|
+
import {IProductComponent} from "../../components/IProduct.sol";
|
|
10
|
+
import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
|
|
11
|
+
import {TokenHandler} from "./TokenHandler.sol";
|
|
12
|
+
import {ITreasuryModule} from "./ITreasury.sol";
|
|
13
|
+
import {TokenHandler} from "./TokenHandler.sol";
|
|
14
|
+
|
|
15
|
+
abstract contract TreasuryModule is ITreasuryModule {
|
|
16
|
+
|
|
17
|
+
mapping(NftId productNftId => ProductSetup setup) private _productSetup;
|
|
18
|
+
mapping(NftId distributorNftId => DistributorSetup setup) private _distributorSetup;
|
|
19
|
+
mapping(NftId poolNftId => PoolSetup setup) private _poolSetup;
|
|
20
|
+
|
|
21
|
+
IPolicyModule private _policyModule;
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
_policyModule = IPolicyModule(address(this));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function registerProduct(
|
|
28
|
+
NftId productNftId,
|
|
29
|
+
NftId distributorNftId,
|
|
30
|
+
NftId poolNftId,
|
|
31
|
+
IERC20 token,
|
|
32
|
+
address wallet,
|
|
33
|
+
Fee memory policyFee,
|
|
34
|
+
Fee memory processingFee
|
|
35
|
+
)
|
|
36
|
+
external
|
|
37
|
+
override
|
|
38
|
+
// TODO add authz (only component module)
|
|
39
|
+
{
|
|
40
|
+
// TODO add validation
|
|
41
|
+
|
|
42
|
+
// deploy product specific handler contract
|
|
43
|
+
TokenHandler tokenHandler = new TokenHandler(address(token));
|
|
44
|
+
|
|
45
|
+
_productSetup[productNftId] = ProductSetup(
|
|
46
|
+
productNftId,
|
|
47
|
+
distributorNftId,
|
|
48
|
+
poolNftId,
|
|
49
|
+
token,
|
|
50
|
+
tokenHandler,
|
|
51
|
+
wallet,
|
|
52
|
+
policyFee,
|
|
53
|
+
processingFee
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// TODO add logging
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function registerPool(
|
|
60
|
+
NftId poolNftId,
|
|
61
|
+
address wallet,
|
|
62
|
+
Fee memory stakingFee,
|
|
63
|
+
Fee memory performanceFee
|
|
64
|
+
)
|
|
65
|
+
external
|
|
66
|
+
override
|
|
67
|
+
// TODO add authz (only component module)
|
|
68
|
+
{
|
|
69
|
+
// TODO add validation
|
|
70
|
+
|
|
71
|
+
_poolSetup[poolNftId] = PoolSetup(
|
|
72
|
+
poolNftId,
|
|
73
|
+
wallet,
|
|
74
|
+
stakingFee,
|
|
75
|
+
performanceFee
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// TODO add logging
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getTokenHandler(NftId productNftId)
|
|
82
|
+
external
|
|
83
|
+
view
|
|
84
|
+
override
|
|
85
|
+
returns(TokenHandler tokenHandler)
|
|
86
|
+
{
|
|
87
|
+
return _productSetup[productNftId].tokenHandler;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getProductSetup(NftId productNftId)
|
|
91
|
+
external
|
|
92
|
+
view
|
|
93
|
+
override
|
|
94
|
+
returns(ProductSetup memory setup)
|
|
95
|
+
{
|
|
96
|
+
return _productSetup[productNftId];
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getPoolSetup(NftId poolNftId)
|
|
100
|
+
external
|
|
101
|
+
view
|
|
102
|
+
override
|
|
103
|
+
returns(PoolSetup memory setup)
|
|
104
|
+
{
|
|
105
|
+
return _poolSetup[poolNftId];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
function processPremium(NftId policyNftId, NftId productNftId)
|
|
110
|
+
external
|
|
111
|
+
override
|
|
112
|
+
// TODO add authz (only product service)
|
|
113
|
+
{
|
|
114
|
+
IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(policyNftId);
|
|
115
|
+
require(policyInfo.nftId == policyNftId, "ERROR:TRS-020:POLICY_UNKNOWN");
|
|
116
|
+
|
|
117
|
+
ProductSetup memory product = _productSetup[productNftId];
|
|
118
|
+
|
|
119
|
+
TokenHandler tokenHandler = product.tokenHandler;
|
|
120
|
+
address policyOwner = this.getRegistry().getOwner(policyNftId);
|
|
121
|
+
address poolWallet = _poolSetup[product.poolNftId].wallet;
|
|
122
|
+
// TODO add validation
|
|
123
|
+
|
|
124
|
+
if(feeIsZero(product.policyFee)) {
|
|
125
|
+
tokenHandler.transfer(policyOwner, poolWallet, policyInfo.premiumAmount);
|
|
126
|
+
} else {
|
|
127
|
+
// TODO add fee handling
|
|
128
|
+
tokenHandler.transfer(policyOwner, poolWallet, policyInfo.premiumAmount);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
pragma solidity ^0.8.19;
|
|
3
3
|
|
|
4
4
|
import {NftId} from "../types/NftId.sol";
|
|
5
|
+
import {ObjectType} from "../types/ObjectType.sol";
|
|
5
6
|
|
|
6
7
|
interface IOwnable {
|
|
7
8
|
function getOwner() external view returns (address owner);
|
|
@@ -14,13 +15,14 @@ interface IRegistryLinked {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
interface IRegisterable is IOwnable, IRegistryLinked {
|
|
18
|
+
|
|
17
19
|
function register() external returns (NftId nftId);
|
|
18
20
|
|
|
19
21
|
function getNftId() external view returns (NftId nftId);
|
|
20
22
|
|
|
21
23
|
function getParentNftId() external view returns (NftId parentNftId);
|
|
22
24
|
|
|
23
|
-
function getType() external view returns (
|
|
25
|
+
function getType() external view returns (ObjectType objectType);
|
|
24
26
|
|
|
25
27
|
function getData() external view returns (bytes memory data);
|
|
26
28
|
|
|
@@ -32,33 +34,20 @@ interface IRegisterable is IOwnable, IRegistryLinked {
|
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
interface IRegistry {
|
|
37
|
+
|
|
35
38
|
struct RegistryInfo {
|
|
36
39
|
NftId nftId;
|
|
37
40
|
NftId parentNftId;
|
|
38
|
-
|
|
41
|
+
ObjectType objectType;
|
|
39
42
|
address objectAddress;
|
|
40
43
|
address initialOwner;
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
function TOKEN() external pure returns (uint256);
|
|
44
|
-
|
|
45
|
-
function INSTANCE() external pure returns (uint256);
|
|
46
|
-
|
|
47
|
-
function PRODUCT() external pure returns (uint256);
|
|
48
|
-
|
|
49
|
-
function ORACLE() external pure returns (uint256);
|
|
50
|
-
|
|
51
|
-
function POOL() external pure returns (uint256);
|
|
52
|
-
|
|
53
|
-
function POLICY() external pure returns (uint256);
|
|
54
|
-
|
|
55
|
-
function BUNDLE() external pure returns (uint256);
|
|
56
|
-
|
|
57
46
|
function register(address objectAddress) external returns (NftId nftId);
|
|
58
47
|
|
|
59
48
|
function registerObjectForInstance(
|
|
60
49
|
NftId parentNftid,
|
|
61
|
-
|
|
50
|
+
ObjectType objectType,
|
|
62
51
|
address initialOwner
|
|
63
52
|
) external returns (NftId nftId);
|
|
64
53
|
|
|
@@ -3,8 +3,8 @@ pragma solidity ^0.8.19;
|
|
|
3
3
|
|
|
4
4
|
import {IChainNft} from "./IChainNft.sol";
|
|
5
5
|
import {IRegistry, IRegistryLinked, IRegisterable} from "./IRegistry.sol";
|
|
6
|
-
import {NftId, toNftId} from "../types/NftId.sol";
|
|
7
|
-
import {
|
|
6
|
+
import {NftId, toNftId, NftIdLib} from "../types/NftId.sol";
|
|
7
|
+
import {ObjectType, INSTANCE, POLICY, BUNDLE} from "../types/ObjectType.sol";
|
|
8
8
|
|
|
9
9
|
contract RegistryLinked is IRegistryLinked {
|
|
10
10
|
IRegistry internal _registry;
|
|
@@ -55,6 +55,7 @@ abstract contract Registerable is RegistryLinked, IRegisterable {
|
|
|
55
55
|
|
|
56
56
|
contract Registry is IRegistry {
|
|
57
57
|
using NftIdLib for NftId;
|
|
58
|
+
|
|
58
59
|
string public constant EMPTY_URI = "";
|
|
59
60
|
|
|
60
61
|
mapping(NftId nftId => RegistryInfo info) private _info;
|
|
@@ -71,41 +72,8 @@ contract Registry is IRegistry {
|
|
|
71
72
|
_chainNft = IChainNft(chainNft);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
function
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function INSTANCE() public pure override returns (uint256) {
|
|
79
|
-
return 40;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function PRODUCT() public pure override returns (uint256) {
|
|
83
|
-
return 50;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function ORACLE() public pure override returns (uint256) {
|
|
87
|
-
return 60;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function POOL() public pure override returns (uint256) {
|
|
91
|
-
return 70;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function POLICY() public pure override returns (uint256) {
|
|
95
|
-
return 80;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function BUNDLE() public pure override returns (uint256) {
|
|
99
|
-
return 90;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function register(
|
|
103
|
-
address objectAddress
|
|
104
|
-
) external override returns (NftId nftId) {
|
|
105
|
-
require(
|
|
106
|
-
_nftIdByAddress[objectAddress].eqz(),
|
|
107
|
-
"ERROR:REG-002:ALREADY_REGISTERED"
|
|
108
|
-
);
|
|
75
|
+
function register(address objectAddress) external override returns(NftId nftId) {
|
|
76
|
+
require(_nftIdByAddress[objectAddress].eqz(), "ERROR:REG-002:ALREADY_REGISTERED");
|
|
109
77
|
|
|
110
78
|
IRegisterable registerable = IRegisterable(objectAddress);
|
|
111
79
|
require(
|
|
@@ -145,7 +113,7 @@ contract Registry is IRegistry {
|
|
|
145
113
|
|
|
146
114
|
function registerObjectForInstance(
|
|
147
115
|
NftId parentNftId,
|
|
148
|
-
|
|
116
|
+
ObjectType objectType,
|
|
149
117
|
address initialOwner
|
|
150
118
|
)
|
|
151
119
|
external
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
import {UFixed} from "./UFixed.sol";
|
|
5
|
+
|
|
6
|
+
struct Fee {
|
|
7
|
+
UFixed fractionalFee;
|
|
8
|
+
uint256 fixedFee;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// general pure free functions
|
|
12
|
+
/// @dev Converts the uint256 to a NftId.
|
|
13
|
+
function toFee(UFixed fractionalFee, uint256 fixedFee) pure returns (Fee memory fee) {
|
|
14
|
+
return Fee(fractionalFee, fixedFee);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/// @dev Return the NftId zero (0)
|
|
18
|
+
function zeroFee() pure returns (Fee memory fee) {
|
|
19
|
+
return Fee(UFixed.wrap(0), 0);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// pure free functions for operators
|
|
23
|
+
function feeIsSame(Fee memory a, Fee memory b) pure returns (bool isSame) {
|
|
24
|
+
return a.fixedFee == b.fixedFee && a.fractionalFee == b.fractionalFee;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function feeIsZero(Fee memory fee) pure returns(bool) {
|
|
29
|
+
return fee.fixedFee == 0 && UFixed.unwrap(fee.fractionalFee) == 0;
|
|
30
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
// uint96 allows for chain ids up to 13 digits
|
|
5
|
+
type ObjectType is uint8;
|
|
6
|
+
|
|
7
|
+
// type bindings
|
|
8
|
+
using {
|
|
9
|
+
eqObjectType as ==,
|
|
10
|
+
neObjectType as !=,
|
|
11
|
+
ObjectTypeLib.toInt
|
|
12
|
+
} for ObjectType global;
|
|
13
|
+
|
|
14
|
+
// general pure free functions
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
function PROTOCOL() pure returns(ObjectType) { return toObjectType(10); }
|
|
18
|
+
function CHAIN() pure returns(ObjectType) { return toObjectType(20); }
|
|
19
|
+
function REGISTRY() pure returns(ObjectType) { return toObjectType(30); }
|
|
20
|
+
function TOKEN() pure returns(ObjectType) { return toObjectType(40); }
|
|
21
|
+
function INSTANCE() pure returns(ObjectType) { return toObjectType(50); }
|
|
22
|
+
function PRODUCT() pure returns(ObjectType) { return toObjectType(60); }
|
|
23
|
+
function ORACLE() pure returns(ObjectType) { return toObjectType(70); }
|
|
24
|
+
function POOL() pure returns(ObjectType) { return toObjectType(80); }
|
|
25
|
+
function BUNDLE() pure returns(ObjectType) { return toObjectType(81); }
|
|
26
|
+
function POLICY() pure returns(ObjectType) { return toObjectType(90); }
|
|
27
|
+
function CLAIM() pure returns(ObjectType) { return toObjectType(91); }
|
|
28
|
+
function PAYOUT() pure returns(ObjectType) { return toObjectType(92); }
|
|
29
|
+
|
|
30
|
+
/// @dev Converts the uint8 to a ObjectType.
|
|
31
|
+
function toObjectType(uint256 objectType) pure returns(ObjectType) { return ObjectType.wrap(uint8(objectType)); }
|
|
32
|
+
|
|
33
|
+
/// @dev Return the ObjectType zero (0)
|
|
34
|
+
function zeroObjectType() pure returns(ObjectType) { return ObjectType.wrap(0); }
|
|
35
|
+
|
|
36
|
+
// pure free functions for operators
|
|
37
|
+
function eqObjectType(ObjectType a, ObjectType b) pure returns(bool isSame) { return ObjectType.unwrap(a) == ObjectType.unwrap(b); }
|
|
38
|
+
function neObjectType(ObjectType a, ObjectType b) pure returns(bool isDifferent) { return ObjectType.unwrap(a) != ObjectType.unwrap(b); }
|
|
39
|
+
|
|
40
|
+
// library functions that operate on user defined type
|
|
41
|
+
library ObjectTypeLib {
|
|
42
|
+
/// @dev Converts the NftId to a uint256.
|
|
43
|
+
function toInt(ObjectType objectType) public pure returns(uint96) { return uint96(ObjectType.unwrap(objectType)); }
|
|
44
|
+
/// @dev Returns true if the value is non-zero (> 0).
|
|
45
|
+
function gtz(ObjectType a) public pure returns(bool) { return ObjectType.unwrap(a) > 0; }
|
|
46
|
+
/// @dev Returns true if the value is zero (== 0).
|
|
47
|
+
function eqz(ObjectType a) public pure returns(bool) { return ObjectType.unwrap(a) == 0; }
|
|
48
|
+
/// @dev Returns true if the values are equal (==).
|
|
49
|
+
function eq(ObjectType a, ObjectType b) public pure returns(bool isSame) { return eqObjectType(a, b); }
|
|
50
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
pragma solidity ^0.8.19;
|
|
3
|
+
|
|
4
|
+
// uint96 allows for chain ids up to 13 digits
|
|
5
|
+
type StateId is uint8;
|
|
6
|
+
|
|
7
|
+
// type bindings
|
|
8
|
+
using {
|
|
9
|
+
eqStateId as ==,
|
|
10
|
+
neStateId as !=,
|
|
11
|
+
StateIdLib.toInt
|
|
12
|
+
} for StateId global;
|
|
13
|
+
|
|
14
|
+
// general pure free functions
|
|
15
|
+
function APPLIED() pure returns(StateId) { return toStateId(10); }
|
|
16
|
+
function REVOKED() pure returns(StateId) { return toStateId(20); }
|
|
17
|
+
function DECLINED() pure returns(StateId) { return toStateId(30); }
|
|
18
|
+
function CONFIRMED() pure returns(StateId) { return toStateId(40); }
|
|
19
|
+
function EXPECTED() pure returns(StateId) { return toStateId(50); }
|
|
20
|
+
function ACTIVE() pure returns(StateId) { return toStateId(100); }
|
|
21
|
+
function PAUSED() pure returns(StateId) { return toStateId(110); }
|
|
22
|
+
function CLOSED() pure returns(StateId) { return toStateId(200); }
|
|
23
|
+
function ARCHIVED() pure returns(StateId) { return toStateId(210); }
|
|
24
|
+
function PAID() pure returns(StateId) { return toStateId(220); }
|
|
25
|
+
|
|
26
|
+
/// @dev Converts the uint8 to a StateId.
|
|
27
|
+
function toStateId(uint256 id) pure returns(StateId) { return StateId.wrap(uint8(id)); }
|
|
28
|
+
|
|
29
|
+
/// @dev Return the StateId zero (0)
|
|
30
|
+
function zeroStateId() pure returns(StateId) { return StateId.wrap(0); }
|
|
31
|
+
|
|
32
|
+
// pure free functions for operators
|
|
33
|
+
function eqStateId(StateId a, StateId b) pure returns(bool isSame) { return StateId.unwrap(a) == StateId.unwrap(b); }
|
|
34
|
+
function neStateId(StateId a, StateId b) pure returns(bool isDifferent) { return StateId.unwrap(a) != StateId.unwrap(b); }
|
|
35
|
+
|
|
36
|
+
// library functions that operate on user defined type
|
|
37
|
+
library StateIdLib {
|
|
38
|
+
/// @dev Converts the NftId to a uint256.
|
|
39
|
+
function toInt(StateId stateId) public pure returns(uint96) { return uint96(StateId.unwrap(stateId)); }
|
|
40
|
+
/// @dev Returns true if the value is non-zero (> 0).
|
|
41
|
+
function gtz(StateId a) public pure returns(bool) { return StateId.unwrap(a) > 0; }
|
|
42
|
+
/// @dev Returns true if the value is zero (== 0).
|
|
43
|
+
function eqz(StateId a) public pure returns(bool) { return StateId.unwrap(a) == 0; }
|
|
44
|
+
/// @dev Returns true if the values are equal (==).
|
|
45
|
+
function eq(StateId a, StateId b) public pure returns(bool isSame) { return eqStateId(a, b); }
|
|
46
|
+
}
|
|
@@ -102,6 +102,7 @@ library UFixedMathLib {
|
|
|
102
102
|
return UFixed.wrap(a * MULTIPLIER);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
// TODO rename to toUFixed
|
|
105
106
|
/// @dev Converts the uint256 to a UFixed with given exponent.
|
|
106
107
|
function itof(uint256 a, int8 exp) public pure returns (UFixed) {
|
|
107
108
|
require(EXP + exp >= 0, "ERROR:FM-010:EXPONENT_TOO_SMALL");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etherisc/gif-next",
|
|
3
|
-
"version": "0.0.2-
|
|
3
|
+
"version": "0.0.2-3e0ffc8-142",
|
|
4
4
|
"description": "This is the repository for the next version of the Generic Insurance Framework (GIF) smart contracts. ",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"ptest": "hh test --parallel",
|
|
10
10
|
"test-with-gas": "REPORT_GAS=true hh test",
|
|
11
11
|
"coverage": "hh coverage",
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"styleFix": "prettier --write --plugin=prettier-plugin-solidity 'contracts/**/*.sol' 'test_forge/**/*.t.sol'",
|
|
13
|
+
"styleCheck": "prettier --check --plugin=prettier-plugin-solidity 'contracts/**/*.sol' 'test_forge/**/*.t.sol'",
|
|
14
|
+
"lint": "solhint 'contracts/**/*.sol' 'test_forge/**/*.t.sol'"
|
|
14
15
|
},
|
|
15
16
|
"repository": {
|
|
16
17
|
"type": "git",
|