@etherisc/gif-next 0.0.2-fc8b370-882 → 0.0.2-fe34d97-357
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +36 -0
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProductComponent.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 +72 -4
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +46 -3
- 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 +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
- 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 +540 -401
- package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +640 -469
- package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.json +18 -0
- package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +49 -0
- package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +1 -1
- package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.json +18 -0
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +41 -23
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +4 -4
- package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.json +17 -48
- package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.json +18 -49
- package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.json +2 -2
- package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensation.dbg.json +1 -1
- package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensationModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.json +36 -88
- package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.json +36 -88
- package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.json +65 -38
- package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.json +65 -38
- package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.json +0 -5
- package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.json +0 -5
- package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +1 -1
- package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.json +123 -1
- package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +145 -5
- package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +166 -168
- package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.json +2 -2
- package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +167 -169
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +21 -21
- package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +71 -0
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +6 -6
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +97 -26
- 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/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.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/shared/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
- package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +1 -1
- package/artifacts/contracts/test/TestPool.sol/TestPool.json +72 -4
- package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +1 -1
- package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +90 -4
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.json +2 -2
- package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
- package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
- 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/Fee.sol/FeeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
- package/artifacts/contracts/types/Key32.sol/Key32Lib.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/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
- package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
- package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/RiskId.sol/RiskIdLib.json +86 -0
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
- 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/Version.sol/VersionLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
- package/contracts/components/BaseComponent.sol +7 -1
- package/contracts/components/Pool.sol +20 -3
- package/contracts/components/Product.sol +69 -5
- package/contracts/instance/IInstance.sol +3 -4
- package/contracts/instance/Instance.sol +7 -4
- package/contracts/instance/base/IInstanceBase.sol +5 -0
- package/contracts/instance/base/IKeyValueStore.sol +4 -3
- package/contracts/instance/base/InstanceBase.sol +6 -2
- package/contracts/instance/base/KeyValueStore.sol +12 -7
- package/contracts/instance/base/Lifecycle.sol +15 -10
- package/contracts/instance/base/ModuleBase.sol +18 -17
- package/contracts/instance/module/bundle/BundleModule.sol +10 -11
- package/contracts/instance/module/bundle/IBundle.sol +4 -11
- package/contracts/instance/module/compensation/CompensationModule.sol +11 -2
- package/contracts/instance/module/component/ComponentModule.sol +39 -53
- package/contracts/instance/module/component/IComponent.sol +6 -30
- package/contracts/instance/module/policy/IPolicy.sol +11 -9
- package/contracts/instance/module/policy/PolicyModule.sol +35 -19
- package/contracts/instance/module/pool/IPoolModule.sol +0 -1
- package/contracts/instance/module/pool/PoolModule.sol +12 -9
- package/contracts/instance/module/risk/IRisk.sol +19 -2
- package/contracts/instance/module/risk/RiskModule.sol +64 -2
- package/contracts/instance/module/treasury/ITreasury.sol +35 -42
- package/contracts/instance/module/treasury/TreasuryModule.sol +96 -77
- package/contracts/instance/service/ComponentOwnerService.sol +19 -34
- package/contracts/instance/service/IProductService.sol +21 -1
- package/contracts/instance/service/PoolService.sol +10 -4
- package/contracts/instance/service/ProductService.sol +120 -68
- package/contracts/registry/Registry.sol +2 -2
- package/contracts/test/TestPool.sol +4 -2
- package/contracts/test/TestProduct.sol +25 -3
- package/contracts/types/ObjectType.sol +20 -8
- package/contracts/types/RiskId.sol +43 -0
- package/package.json +1 -1
@@ -6,6 +6,7 @@ import {IPoolComponent} from "../../components/IPoolComponent.sol";
|
|
6
6
|
import {IInstance} from "../../instance/IInstance.sol";
|
7
7
|
import {IPolicy, IPolicyModule} from "../module/policy/IPolicy.sol";
|
8
8
|
import {IPool} from "../module/pool/IPoolModule.sol";
|
9
|
+
import {IRisk} from "../module/risk/IRisk.sol";
|
9
10
|
import {IBundle} from "../module/bundle/IBundle.sol";
|
10
11
|
import {IProductService} from "./IProductService.sol";
|
11
12
|
import {ITreasury, ITreasuryModule, TokenHandler} from "../../instance/module/treasury/ITreasury.sol";
|
@@ -15,11 +16,13 @@ import {Versionable} from "../../shared/Versionable.sol";
|
|
15
16
|
|
16
17
|
import {Timestamp, zeroTimestamp} from "../../types/Timestamp.sol";
|
17
18
|
import {UFixed, UFixedMathLib} from "../../types/UFixed.sol";
|
19
|
+
import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
|
18
20
|
import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol";
|
19
21
|
import {APPLIED, UNDERWRITTEN, ACTIVE} from "../../types/StateId.sol";
|
20
22
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
21
|
-
import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
|
22
23
|
import {Fee, FeeLib} from "../../types/Fee.sol";
|
24
|
+
import {RiskId} from "../../types/RiskId.sol";
|
25
|
+
import {StateId} from "../../types/StateId.sol";
|
23
26
|
import {Version, VersionLib} from "../../types/Version.sol";
|
24
27
|
|
25
28
|
import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
|
@@ -62,11 +65,51 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
62
65
|
override
|
63
66
|
{
|
64
67
|
(IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
|
65
|
-
|
68
|
+
NftId productNftId = productInfo.nftId;
|
69
|
+
ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(productNftId);
|
70
|
+
treasuryInfo.policyFee = policyFee;
|
71
|
+
treasuryInfo.processingFee = processingFee;
|
72
|
+
instance.setTreasuryInfo(productNftId, treasuryInfo);
|
73
|
+
}
|
74
|
+
|
75
|
+
function createRisk(
|
76
|
+
RiskId riskId,
|
77
|
+
bytes memory data
|
78
|
+
) external override {
|
79
|
+
(IRegistry.ObjectInfo memory productInfo, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
|
80
|
+
NftId productNftId = productInfo.nftId;
|
81
|
+
instance.createRisk(
|
82
|
+
riskId,
|
83
|
+
productNftId,
|
84
|
+
data
|
85
|
+
);
|
86
|
+
}
|
87
|
+
|
88
|
+
function setRiskInfo(
|
89
|
+
RiskId riskId,
|
90
|
+
IRisk.RiskInfo memory info
|
91
|
+
) external {
|
92
|
+
(, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
|
93
|
+
instance.setRiskInfo(
|
94
|
+
riskId,
|
95
|
+
info
|
96
|
+
);
|
97
|
+
}
|
98
|
+
|
99
|
+
function updateRiskState(
|
100
|
+
RiskId riskId,
|
101
|
+
StateId state
|
102
|
+
) external {
|
103
|
+
(, IInstance instance) = _getAndVerifyComponentInfoAndInstance(PRODUCT());
|
104
|
+
instance.updateRiskState(
|
105
|
+
riskId,
|
106
|
+
state
|
107
|
+
);
|
66
108
|
}
|
67
109
|
|
68
110
|
function createApplication(
|
69
111
|
address applicationOwner,
|
112
|
+
RiskId riskId,
|
70
113
|
uint256 sumInsuredAmount,
|
71
114
|
uint256 premiumAmount,
|
72
115
|
uint256 lifetime,
|
@@ -83,9 +126,10 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
83
126
|
""
|
84
127
|
);
|
85
128
|
|
86
|
-
instance.
|
87
|
-
productNftId,
|
129
|
+
instance.createPolicyInfo(
|
88
130
|
policyNftId,
|
131
|
+
productNftId,
|
132
|
+
riskId,
|
89
133
|
sumInsuredAmount,
|
90
134
|
premiumAmount,
|
91
135
|
lifetime,
|
@@ -102,30 +146,29 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
102
146
|
internal
|
103
147
|
view
|
104
148
|
returns (
|
105
|
-
ITreasury.
|
149
|
+
ITreasury.TreasuryInfo memory treasuryInfo,
|
150
|
+
NftId bundleNftId,
|
106
151
|
IBundle.BundleInfo memory bundleInfo,
|
107
|
-
uint256 collateralAmount
|
108
|
-
bool poolIsVerifying,
|
109
|
-
bytes memory bundleFilter
|
152
|
+
uint256 collateralAmount
|
110
153
|
)
|
111
154
|
{
|
112
155
|
// check match between policy and bundle (via pool)
|
113
|
-
|
114
|
-
|
115
|
-
|
156
|
+
treasuryInfo = instance.getTreasuryInfo(policyInfo.productNftId);
|
157
|
+
bundleNftId = policyInfo.bundleNftId;
|
158
|
+
bundleInfo = instance.getBundleInfo(bundleNftId);
|
159
|
+
require(bundleInfo.poolNftId == treasuryInfo.poolNftId, "POLICY_BUNDLE_MISMATCH");
|
116
160
|
|
117
161
|
// calculate required collateral
|
118
|
-
NftId poolNftId =
|
162
|
+
NftId poolNftId = treasuryInfo.poolNftId;
|
119
163
|
IPool.PoolInfo memory poolInfo = instance.getPoolInfo(poolNftId);
|
120
164
|
|
121
165
|
// obtain remaining return values
|
122
|
-
poolIsVerifying = poolInfo.isVerifying;
|
123
166
|
collateralAmount = calculateRequiredCollateral(poolInfo.collateralizationLevel, policyInfo.sumInsuredAmount);
|
124
|
-
bundleFilter = bundleInfo.filter;
|
125
167
|
}
|
126
168
|
|
127
169
|
function _lockCollateralInBundle(
|
128
170
|
IInstance instance,
|
171
|
+
NftId bundleNftId,
|
129
172
|
IBundle.BundleInfo memory bundleInfo,
|
130
173
|
NftId policyNftId,
|
131
174
|
uint256 collateralAmount
|
@@ -134,23 +177,24 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
134
177
|
returns (IBundle.BundleInfo memory)
|
135
178
|
{
|
136
179
|
bundleInfo.lockedAmount += collateralAmount;
|
137
|
-
instance.collateralizePolicy(
|
180
|
+
instance.collateralizePolicy(bundleNftId, policyNftId, collateralAmount);
|
138
181
|
return bundleInfo;
|
139
182
|
}
|
140
183
|
|
141
184
|
function _underwriteByPool(
|
142
|
-
ITreasury.
|
185
|
+
ITreasury.TreasuryInfo memory treasuryInfo,
|
186
|
+
NftId policyNftId,
|
143
187
|
IPolicy.PolicyInfo memory policyInfo,
|
144
188
|
bytes memory bundleFilter,
|
145
189
|
uint256 collateralAmount
|
146
190
|
)
|
147
191
|
internal
|
148
192
|
{
|
149
|
-
address poolAddress = _registry.getObjectInfo(
|
193
|
+
address poolAddress = _registry.getObjectInfo(treasuryInfo.poolNftId).objectAddress;
|
150
194
|
IPoolComponent pool = IPoolComponent(poolAddress);
|
151
195
|
pool.underwrite(
|
152
|
-
|
153
|
-
policyInfo.
|
196
|
+
policyNftId,
|
197
|
+
policyInfo.applicationData,
|
154
198
|
bundleFilter,
|
155
199
|
collateralAmount);
|
156
200
|
}
|
@@ -174,14 +218,18 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
174
218
|
NftId productNftId = productInfo.nftId;
|
175
219
|
IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
|
176
220
|
require(policyInfo.productNftId == productNftId, "POLICY_PRODUCT_MISMATCH");
|
177
|
-
require(
|
221
|
+
require(instance.getPolicyState(policyNftId) == APPLIED(), "ERROR:PRS-021:STATE_NOT_APPLIED");
|
222
|
+
|
223
|
+
ITreasury.TreasuryInfo memory treasuryInfo;
|
224
|
+
NftId bundleNftId;
|
225
|
+
IBundle.BundleInfo memory bundleInfo;
|
226
|
+
uint256 collateralAmount;
|
178
227
|
|
179
228
|
(
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
bytes memory bundleFilter
|
229
|
+
treasuryInfo,
|
230
|
+
bundleNftId,
|
231
|
+
bundleInfo,
|
232
|
+
collateralAmount
|
185
233
|
) = _getAndVerifyUnderwritingSetup(
|
186
234
|
instance,
|
187
235
|
policyInfo
|
@@ -190,15 +238,28 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
190
238
|
// lock bundle collateral
|
191
239
|
bundleInfo = _lockCollateralInBundle(
|
192
240
|
instance,
|
241
|
+
bundleNftId,
|
193
242
|
bundleInfo,
|
194
243
|
policyNftId,
|
195
244
|
collateralAmount);
|
196
245
|
|
197
|
-
//
|
246
|
+
// set policy state to underwritten
|
247
|
+
instance.updatePolicyState(policyNftId, UNDERWRITTEN());
|
248
|
+
|
249
|
+
// optional activation of policy
|
250
|
+
if(activateAt > zeroTimestamp()) {
|
251
|
+
policyInfo.activatedAt = activateAt;
|
252
|
+
policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
|
253
|
+
|
254
|
+
instance.updatePolicyState(policyNftId, ACTIVE());
|
255
|
+
}
|
256
|
+
|
257
|
+
// optional collection of premium
|
198
258
|
if(requirePremiumPayment) {
|
199
259
|
uint256 netPremiumAmount = _processPremiumByTreasury(
|
200
260
|
instance,
|
201
|
-
|
261
|
+
productInfo.nftId,
|
262
|
+
treasuryInfo,
|
202
263
|
policyNftId,
|
203
264
|
policyInfo.premiumAmount);
|
204
265
|
|
@@ -206,31 +267,23 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
206
267
|
bundleInfo.balanceAmount += netPremiumAmount;
|
207
268
|
}
|
208
269
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
// integrate pool component
|
227
|
-
if(poolIsVerifying) {
|
228
|
-
_underwriteByPool(
|
229
|
-
productSetup,
|
230
|
-
policyInfo,
|
231
|
-
bundleFilter,
|
232
|
-
collateralAmount
|
233
|
-
);
|
270
|
+
instance.setPolicyInfo(policyNftId, policyInfo);
|
271
|
+
instance.setBundleInfo(bundleNftId, bundleInfo);
|
272
|
+
|
273
|
+
// involve pool if necessary
|
274
|
+
{
|
275
|
+
NftId poolNftId = treasuryInfo.poolNftId;
|
276
|
+
IPool.PoolInfo memory poolInfo = instance.getPoolInfo(poolNftId);
|
277
|
+
|
278
|
+
if(poolInfo.isVerifying) {
|
279
|
+
_underwriteByPool(
|
280
|
+
treasuryInfo,
|
281
|
+
policyNftId,
|
282
|
+
policyInfo,
|
283
|
+
bundleInfo.filter,
|
284
|
+
collateralAmount
|
285
|
+
);
|
286
|
+
}
|
234
287
|
}
|
235
288
|
|
236
289
|
// TODO add logging
|
@@ -248,14 +301,13 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
248
301
|
|
249
302
|
// perform actual token transfers
|
250
303
|
IPolicy.PolicyInfo memory policyInfo = instance.getPolicyInfo(policyNftId);
|
251
|
-
ITreasury.
|
304
|
+
ITreasury.TreasuryInfo memory treasuryInfo = instance.getTreasuryInfo(productInfo.nftId);
|
252
305
|
|
253
306
|
uint256 premiumAmount = policyInfo.premiumAmount;
|
254
|
-
_processPremiumByTreasury(instance,
|
307
|
+
_processPremiumByTreasury(instance, productInfo.nftId, treasuryInfo, policyNftId, premiumAmount);
|
255
308
|
|
256
309
|
// policy level book keeping for premium paid
|
257
310
|
policyInfo.premiumPaidAmount += premiumAmount;
|
258
|
-
policyInfo.updatedIn = blockNumber();
|
259
311
|
|
260
312
|
// optional activation of policy
|
261
313
|
if(activateAt > zeroTimestamp()) {
|
@@ -266,11 +318,10 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
266
318
|
policyInfo.activatedAt = activateAt;
|
267
319
|
policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
|
268
320
|
|
269
|
-
|
270
|
-
policyInfo.state = ACTIVE();
|
321
|
+
instance.updatePolicyState(policyNftId, ACTIVE());
|
271
322
|
}
|
272
323
|
|
273
|
-
instance.setPolicyInfo(policyInfo);
|
324
|
+
instance.setPolicyInfo(policyNftId, policyInfo);
|
274
325
|
|
275
326
|
// TODO add logging
|
276
327
|
}
|
@@ -288,10 +339,8 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
288
339
|
policyInfo.activatedAt = activateAt;
|
289
340
|
policyInfo.expiredAt = activateAt.addSeconds(policyInfo.lifetime);
|
290
341
|
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
instance.setPolicyInfo(policyInfo);
|
342
|
+
instance.setPolicyInfo(policyNftId, policyInfo);
|
343
|
+
instance.updatePolicyState(policyNftId, ACTIVE());
|
295
344
|
|
296
345
|
// TODO add logging
|
297
346
|
}
|
@@ -311,12 +360,14 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
311
360
|
view
|
312
361
|
returns (NftId poolNftid)
|
313
362
|
{
|
314
|
-
return instance.
|
363
|
+
return instance.getTreasuryInfo(productNftId).poolNftId;
|
315
364
|
}
|
316
365
|
|
366
|
+
|
317
367
|
function _processPremiumByTreasury(
|
318
368
|
IInstance instance,
|
319
|
-
|
369
|
+
NftId productNftId,
|
370
|
+
ITreasury.TreasuryInfo memory treasuryInfo,
|
320
371
|
NftId policyNftId,
|
321
372
|
uint256 premiumAmount
|
322
373
|
)
|
@@ -325,11 +376,11 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
325
376
|
{
|
326
377
|
// process token transfer(s)
|
327
378
|
if(premiumAmount > 0) {
|
328
|
-
TokenHandler tokenHandler = instance.getTokenHandler(
|
379
|
+
TokenHandler tokenHandler = instance.getTokenHandler(productNftId);
|
329
380
|
address policyOwner = _registry.getOwner(policyNftId);
|
330
|
-
address poolWallet = instance.
|
381
|
+
address poolWallet = instance.getComponentWallet(treasuryInfo.poolNftId);
|
331
382
|
netPremiumAmount = premiumAmount;
|
332
|
-
Fee memory policyFee =
|
383
|
+
Fee memory policyFee = treasuryInfo.policyFee;
|
333
384
|
|
334
385
|
if (FeeLib.feeIsZero(policyFee)) {
|
335
386
|
tokenHandler.transfer(
|
@@ -343,7 +394,8 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
343
394
|
policyFee
|
344
395
|
);
|
345
396
|
|
346
|
-
|
397
|
+
address productWallet = instance.getComponentWallet(productNftId);
|
398
|
+
tokenHandler.transfer(policyOwner, productWallet, feeAmount);
|
347
399
|
tokenHandler.transfer(policyOwner, poolWallet, netAmount);
|
348
400
|
netPremiumAmount = netAmount;
|
349
401
|
}
|
@@ -9,7 +9,7 @@ import {ChainNft} from "./ChainNft.sol";
|
|
9
9
|
import {IRegistry} from "./IRegistry.sol";
|
10
10
|
import {NftId, toNftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
|
11
11
|
import {VersionPart} from "../types/Version.sol";
|
12
|
-
import {ObjectType, PROTOCOL, REGISTRY, TOKEN, SERVICE, INSTANCE, STAKE, PRODUCT,
|
12
|
+
import {ObjectType, PROTOCOL, REGISTRY, TOKEN, SERVICE, INSTANCE, STAKE, PRODUCT, COMPENSATION, ORACLE, POOL, POLICY, BUNDLE} from "../types/ObjectType.sol";
|
13
13
|
|
14
14
|
// TODO make registry upgradable
|
15
15
|
contract Registry is
|
@@ -293,7 +293,7 @@ contract Registry is
|
|
293
293
|
|
294
294
|
// instance as parent
|
295
295
|
_isValidParentType[PRODUCT()][INSTANCE()] = true;
|
296
|
-
_isValidParentType[
|
296
|
+
_isValidParentType[COMPENSATION()][INSTANCE()] = true;
|
297
297
|
_isValidParentType[ORACLE()][INSTANCE()] = true;
|
298
298
|
_isValidParentType[POOL()][INSTANCE()] = true;
|
299
299
|
|
@@ -14,9 +14,11 @@ contract TestPool is Pool {
|
|
14
14
|
NftId instanceNftid,
|
15
15
|
address token,
|
16
16
|
bool isVerifying,
|
17
|
-
UFixed collateralizationLevel
|
17
|
+
UFixed collateralizationLevel,
|
18
|
+
Fee memory stakingFee,
|
19
|
+
Fee memory performanceFee
|
18
20
|
)
|
19
|
-
Pool(registry, instanceNftid, token, isVerifying, collateralizationLevel)
|
21
|
+
Pool(registry, instanceNftid, token, isVerifying, collateralizationLevel, stakingFee, performanceFee)
|
20
22
|
// solhint-disable-next-line no-empty-blocks
|
21
23
|
{}
|
22
24
|
}
|
@@ -3,6 +3,7 @@ pragma solidity ^0.8.19;
|
|
3
3
|
|
4
4
|
import {Product} from "../../contracts/components/Product.sol";
|
5
5
|
import {NftId, toNftId} from "../../contracts/types/NftId.sol";
|
6
|
+
import {RiskId} from "../../contracts/types/RiskId.sol";
|
6
7
|
import {Timestamp, blockTimestamp} from "../../contracts/types/Timestamp.sol";
|
7
8
|
import {Fee} from "../../contracts/types/Fee.sol";
|
8
9
|
|
@@ -10,10 +11,25 @@ contract TestProduct is Product {
|
|
10
11
|
|
11
12
|
event LogTestProductSender(address sender);
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
string public constant DEFAULT_RISK_NAME = "DEFAULT_RISK";
|
15
|
+
bool private defaultRiskCreated;
|
16
|
+
|
17
|
+
constructor(
|
18
|
+
address registry,
|
19
|
+
NftId instanceNftid,
|
20
|
+
address token,
|
21
|
+
address pool,
|
22
|
+
Fee memory policyFee,
|
23
|
+
Fee memory processingFee
|
24
|
+
)
|
25
|
+
Product(registry, instanceNftid, token, pool, policyFee, processingFee)
|
15
26
|
// solhint-disable-next-line no-empty-blocks
|
16
|
-
{
|
27
|
+
{
|
28
|
+
}
|
29
|
+
|
30
|
+
function getDefaultRiskId() public pure returns (RiskId) {
|
31
|
+
return _toRiskId(DEFAULT_RISK_NAME);
|
32
|
+
}
|
17
33
|
|
18
34
|
function applyForPolicy(
|
19
35
|
uint256 sumInsuredAmount,
|
@@ -24,8 +40,14 @@ contract TestProduct is Product {
|
|
24
40
|
external
|
25
41
|
returns(NftId nftId)
|
26
42
|
{
|
43
|
+
if (!defaultRiskCreated) {
|
44
|
+
_createRisk(getDefaultRiskId() , "");
|
45
|
+
defaultRiskCreated = true;
|
46
|
+
}
|
47
|
+
|
27
48
|
nftId = _createApplication(
|
28
49
|
msg.sender, // policy holder
|
50
|
+
getDefaultRiskId(),
|
29
51
|
sumInsuredAmount,
|
30
52
|
premiumAmount,
|
31
53
|
lifetime,
|
@@ -37,36 +37,48 @@ function STAKE() pure returns (ObjectType) {
|
|
37
37
|
return toObjectType(60);
|
38
38
|
}
|
39
39
|
|
40
|
-
function
|
40
|
+
function COMPONENT() pure returns (ObjectType) {
|
41
41
|
return toObjectType(100);
|
42
42
|
}
|
43
43
|
|
44
|
-
function
|
44
|
+
function TREASURY() pure returns (ObjectType) {
|
45
|
+
return toObjectType(101);
|
46
|
+
}
|
47
|
+
|
48
|
+
function PRODUCT() pure returns (ObjectType) {
|
45
49
|
return toObjectType(110);
|
46
50
|
}
|
47
51
|
|
48
|
-
function
|
52
|
+
function COMPENSATION() pure returns (ObjectType) {
|
49
53
|
return toObjectType(120);
|
50
54
|
}
|
51
55
|
|
52
|
-
function
|
56
|
+
function ORACLE() pure returns (ObjectType) {
|
53
57
|
return toObjectType(130);
|
54
58
|
}
|
55
59
|
|
56
|
-
function
|
60
|
+
function POOL() pure returns (ObjectType) {
|
61
|
+
return toObjectType(140);
|
62
|
+
}
|
63
|
+
|
64
|
+
function RISK() pure returns (ObjectType) {
|
57
65
|
return toObjectType(200);
|
58
66
|
}
|
59
67
|
|
60
|
-
function
|
68
|
+
function POLICY() pure returns (ObjectType) {
|
61
69
|
return toObjectType(210);
|
62
70
|
}
|
63
71
|
|
72
|
+
function BUNDLE() pure returns (ObjectType) {
|
73
|
+
return toObjectType(220);
|
74
|
+
}
|
75
|
+
|
64
76
|
function CLAIM() pure returns (ObjectType) {
|
65
|
-
return toObjectType(
|
77
|
+
return toObjectType(211);
|
66
78
|
}
|
67
79
|
|
68
80
|
function PAYOUT() pure returns (ObjectType) {
|
69
|
-
return toObjectType(
|
81
|
+
return toObjectType(212);
|
70
82
|
}
|
71
83
|
|
72
84
|
/// @dev Converts the uint8 to a ObjectType.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {Key32, KeyId, Key32Lib} from "./Key32.sol";
|
5
|
+
import {RISK} from "./ObjectType.sol";
|
6
|
+
|
7
|
+
type RiskId is bytes8;
|
8
|
+
|
9
|
+
// type bindings
|
10
|
+
using {
|
11
|
+
eqRiskId as ==,
|
12
|
+
neRiskId as !=,
|
13
|
+
RiskIdLib.toKey32
|
14
|
+
} for RiskId global;
|
15
|
+
|
16
|
+
// general pure free functions
|
17
|
+
|
18
|
+
// @dev Returns true iff risk ids a and b are identical
|
19
|
+
function eqRiskId(RiskId a, RiskId b) pure returns (bool isSame) {
|
20
|
+
return RiskId.unwrap(a) == RiskId.unwrap(b);
|
21
|
+
}
|
22
|
+
|
23
|
+
// @dev Returns true iff risk ids a and b are different
|
24
|
+
function neRiskId(RiskId a, RiskId b) pure returns (bool isDifferent) {
|
25
|
+
return RiskId.unwrap(a) != RiskId.unwrap(b);
|
26
|
+
}
|
27
|
+
|
28
|
+
library RiskIdLib {
|
29
|
+
// @dev Converts a role string into a role id.
|
30
|
+
function toRiskId(string memory risk) public pure returns (RiskId) {
|
31
|
+
return RiskId.wrap(bytes8(keccak256(abi.encode(risk))));
|
32
|
+
}
|
33
|
+
|
34
|
+
/// @dev Returns the key32 value for the specified nft id and object type.
|
35
|
+
function toKey32(RiskId id) public pure returns (Key32 key) {
|
36
|
+
return Key32Lib.toKey32(RISK(), toKeyId(id));
|
37
|
+
}
|
38
|
+
|
39
|
+
/// @dev Returns the key id value for the specified nft id
|
40
|
+
function toKeyId(RiskId id) public pure returns (KeyId keyId) {
|
41
|
+
return KeyId.wrap(bytes31(RiskId.unwrap(id)));
|
42
|
+
}
|
43
|
+
}
|
package/package.json
CHANGED