-
Notifications
You must be signed in to change notification settings - Fork 35
/
CoverUtilV1.sol
714 lines (635 loc) · 23.3 KB
/
CoverUtilV1.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
// Neptune Mutual Protocol (https://neptunemutual.com)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "../dependencies/BokkyPooBahsDateTimeLibrary.sol";
import "../interfaces/IStore.sol";
import "../interfaces/ICxToken.sol";
import "../interfaces/IERC20Detailed.sol";
import "./StrategyLibV1.sol";
library CoverUtilV1 {
using ProtoUtilV1 for IStore;
using StoreKeyUtil for IStore;
using StrategyLibV1 for IStore;
uint256 public constant REASSURANCE_WEIGHT_FALLBACK_VALUE = 8000;
uint256 public constant COVER_LAG_FALLBACK_VALUE = 1 days;
enum ProductStatus {
Normal,
Stopped,
IncidentHappened,
FalseReporting,
Claimable
}
/**
* @dev Returns the given cover's owner.
*
* Warning: this function does not validate the cover key supplied.
*
* @param s Specify store instance
* @param coverKey Enter cover key
*
*/
function getCoverOwnerInternal(IStore s, bytes32 coverKey) external view returns (address) {
return s.getAddressByKeys(ProtoUtilV1.NS_COVER_OWNER, coverKey);
}
/**
* @dev Returns cover creation fee information.
* @param s Specify store instance
*
* @return fee Returns the amount of NPM tokens you need to pay to create a new cover
* @return minCoverCreationStake Returns the amount of NPM tokens you need to stake to create a new cover
* @return minStakeToAddLiquidity Returns the amount of NPM tokens you need to stake to add liquidity
*
*/
function getCoverCreationFeeInfoInternal(IStore s)
external
view
returns (
uint256 fee,
uint256 minCoverCreationStake,
uint256 minStakeToAddLiquidity
)
{
fee = s.getUintByKey(ProtoUtilV1.NS_COVER_CREATION_FEE);
minCoverCreationStake = getMinCoverCreationStakeInternal(s);
minStakeToAddLiquidity = getMinStakeToAddLiquidityInternal(s);
}
/**
* @dev Returns minimum NPM stake to create a new cover.
* @param s Specify store instance
*/
function getMinCoverCreationStakeInternal(IStore s) public view returns (uint256) {
return s.getUintByKey(ProtoUtilV1.NS_COVER_CREATION_MIN_STAKE);
}
/**
* @dev Returns a cover's creation date
*
* Warning: this function does not validate the cover key supplied.
*
* @param s Specify store instance
* @param coverKey Enter cover key
*
*/
function getCoverCreationDateInternal(IStore s, bytes32 coverKey) external view returns (uint256) {
return s.getUintByKeys(ProtoUtilV1.NS_COVER_CREATION_DATE, coverKey);
}
/**
* @dev Returns minimum NPM stake to add liquidity.
* @param s Specify store instance
*/
function getMinStakeToAddLiquidityInternal(IStore s) public view returns (uint256) {
return s.getUintByKey(ProtoUtilV1.NS_COVER_LIQUIDITY_MIN_STAKE);
}
/**
* @dev Gets claim period/duration of the given cover.
*
* Warning: this function does not validate the cover key supplied.
*
* @param s Specify store instance
* @param coverKey Enter cover key
*
*/
function getClaimPeriodInternal(IStore s, bytes32 coverKey) external view returns (uint256) {
uint256 fromKey = s.getUintByKeys(ProtoUtilV1.NS_CLAIM_PERIOD, coverKey);
uint256 fallbackValue = s.getUintByKey(ProtoUtilV1.NS_CLAIM_PERIOD);
return fromKey > 0 ? fromKey : fallbackValue;
}
/**
* @dev Returns a summary of the given cover pool.
*
* Warning: this function does not validate the cover key supplied.
*
*/
function getCoverPoolSummaryInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey
) external view returns (IPolicy.CoverPoolSummaryType memory summary) {
uint256 precision = s.getStablecoinPrecisionInternal();
summary.totalAmountInPool = s.getStablecoinOwnedByVaultInternal(coverKey); // precision: stablecoin
summary.totalCommitment = getActiveLiquidityUnderProtectionInternal(s, coverKey, productKey, precision); // <-- adjusted precision
summary.reassuranceAmount = getReassuranceAmountInternal(s, coverKey); // precision: stablecoin
summary.reassurancePoolWeight = getReassuranceWeightInternal(s, coverKey);
summary.productCount = s.countBytes32ArrayByKeys(ProtoUtilV1.NS_COVER_PRODUCT, coverKey);
summary.leverage = s.getUintByKeys(ProtoUtilV1.NS_COVER_LEVERAGE_FACTOR, coverKey);
summary.productCapitalEfficiency = s.getUintByKeys(ProtoUtilV1.NS_COVER_PRODUCT_EFFICIENCY, coverKey, productKey);
}
/**
* @dev Gets the reassurance weight of a given cover key.
*
* Warning: this function does not validate the cover key supplied.
*
* @param s Provide store instance
* @param coverKey Enter the cover for which you want to obtain the reassurance weight for.
*
* @return If reassurance weight value wasn't set for the specified cover pool,
* the global value will be returned.
*
* If global value, too, isn't available, a fallback value of `REASSURANCE_WEIGHT_FALLBACK_VALUE`
* is returned.
*
*/
function getReassuranceWeightInternal(IStore s, bytes32 coverKey) public view returns (uint256) {
uint256 setForTheCoverPool = s.getUintByKey(getReassuranceWeightKeyInternal(coverKey));
if (setForTheCoverPool > 0) {
return setForTheCoverPool;
}
// Globally set value: not set for any specific cover
uint256 setGlobally = s.getUintByKey(getReassuranceWeightKeyInternal(0));
if (setGlobally > 0) {
return setGlobally;
}
return REASSURANCE_WEIGHT_FALLBACK_VALUE;
}
/**
* @dev Gets the reassurance amount of the specified cover contract
*
* Warning: this function does not validate the cover key supplied.
*
* @param coverKey Enter the cover key
*
*/
function getReassuranceAmountInternal(IStore s, bytes32 coverKey) public view returns (uint256) {
return s.getUintByKey(getReassuranceKeyInternal(coverKey));
}
/**
* @dev Returns reassurance rate of the specified cover key.
* When a cover is finalized after claims payout, a portion
* of the reassurance fund (if available) is transferred to the cover liquidity pool.
*
* If the reassurance rate is 25%, either 25% of the reassurance pool
* or 25% of the suffered loss is transferred prior to finalization, whichever is less.
*
* Warning: this function does not validate the cover key supplied.
*
* @param s Specify store
* @param coverKey Enter cover key
*
*/
function getReassuranceRateInternal(IStore s, bytes32 coverKey) external view returns (uint256) {
uint256 rate = s.getUintByKey(getReassuranceRateKeyInternal(coverKey));
if (rate > 0) {
return rate;
}
// Default: 25%
return 2500;
}
/**
* @dev Hash key of the reassurance for the given cover.
*
* Warning: this function does not validate the cover key supplied.
*
* @param coverKey Enter cover key
*
*/
function getReassuranceKeyInternal(bytes32 coverKey) public pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_REASSURANCE, coverKey));
}
/**
* @dev Hash key of the reassurance rate for the given cover.
*
* Warning: this function does not validate the cover key supplied.
*
* @param coverKey Enter cover key
*
*/
function getReassuranceRateKeyInternal(bytes32 coverKey) public pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_REASSURANCE_RATE, coverKey));
}
/**
* @dev Hash key of the reassurance weight for the given cover.
*
* Warning: this function does not validate the cover key supplied.
*
* @param coverKey Enter cover key
*
*/
function getReassuranceWeightKeyInternal(bytes32 coverKey) public pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_REASSURANCE_WEIGHT, coverKey));
}
/**
* @dev Indicates whether the specified cover and all associated products are "normal".
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @return Returns false if any associated product isn't normal.
*
*/
function isCoverNormalInternal(IStore s, bytes32 coverKey) external view returns (bool) {
uint256 incidentDate;
bool supportsProducts = supportsProductsInternal(s, coverKey);
if (supportsProducts == false) {
incidentDate = getActiveIncidentDateInternal(s, coverKey, ProtoUtilV1.PRODUCT_KEY_INTENTIONALLY_EMPTY);
return getProductStatusOfInternal(s, coverKey, ProtoUtilV1.PRODUCT_KEY_INTENTIONALLY_EMPTY, incidentDate) == ProductStatus.Normal;
}
bytes32[] memory products = _getProducts(s, coverKey);
for (uint256 i = 0; i < products.length; i++) {
incidentDate = getActiveIncidentDateInternal(s, coverKey, products[i]);
bool isNormal = getProductStatusOfInternal(s, coverKey, products[i], incidentDate) == ProductStatus.Normal;
if (!isNormal) {
return false;
}
}
return true;
}
/**
* @dev Gets product status of the given cover product.
*
*
* 0 - normal
* 1 - stopped, can not purchase covers or add liquidity
* 2 - reporting, incident happened
* 3 - reporting, false reporting
* 4 - claimable, claims accepted for payout
*
* Warning: this function does not validate the cover and product key supplied.
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param productKey Enter product key
*
*/
function getProductStatusInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey
) public view returns (ProductStatus) {
uint256 incidentDate = getActiveIncidentDateInternal(s, coverKey, productKey);
return getProductStatusOfInternal(s, coverKey, productKey, incidentDate);
}
/**
* @dev Returns current status a given cover product as `ProductStatus`.
*
* Warning: this function does not validate the cover and product key supplied.
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param productKey Enter product key
*
*/
function getProductStatusOfInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) public view returns (ProductStatus) {
uint256 value = s.getUintByKey(getProductStatusOfKeyInternal(coverKey, productKey, incidentDate));
return ProductStatus(value);
}
/**
* @dev Hash key of the product status of (the given cover, product, and incident date)
* for historical significance. This must not be reset during finalization.
*
* Warning: this function does not validate the input arguments.
*
* @param coverKey Enter cover key
* @param productKey Enter product key
* @param incidentDate Enter incident date
*
*/
function getProductStatusOfKeyInternal(
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_STATUS, coverKey, productKey, incidentDate));
}
/**
* @dev Hash key of the stakes (collectively added by liquidity providers) of the given cover.
*
* Warning: this function does not validate the cover key supplied.
*
* @param coverKey Enter cover key
*
*/
function getCoverLiquidityStakeKeyInternal(bytes32 coverKey) external pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_LIQUIDITY_STAKE, coverKey));
}
/**
* @dev Hash key of the last stablecoin deposit of the given cover.
* There must be a couple of block heights as an offset
* before withdrawal can be performed (even during a withdrawal window).
*
* Warning: this function does not validate the cover key supplied.
*
* @param coverKey Enter cover key
*
*/
function getLastDepositHeightKeyInternal(bytes32 coverKey) external pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_VAULT_DEPOSIT_HEIGHTS, coverKey));
}
/**
* @dev Hash key of the individual stake (added by an LP) for the given cover and account.
*
* Warning: this function does not validate the input arguments.
*
* @param coverKey Enter cover key
* @param account Enter the account to obtain the hash key
*
*/
function getCoverLiquidityStakeIndividualKeyInternal(bytes32 coverKey, address account) external pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_LIQUIDITY_STAKE, coverKey, account));
}
/**
* @dev Hash key of the blacklisted accounts for the given cover.
* Blacklisted accounts are forbidden to receive claims payout.
*
* Warning: this function does not validate the input arguments.
*
* @param coverKey Enter cover key
* @param productKey Enter product key
* @param incidentDate Enter the trigger incident date
*
*/
function getBlacklistKeyInternal(
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) external pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_CLAIM_BLACKLIST, coverKey, productKey, incidentDate));
}
/**
* @dev Returns the total liquidity committed/under active protection.
* If the cover is a diversified pool, returns sum total of all products' commitments.
*
* Simply put, commitments are the "totalSupply" of cxTokens that haven't yet expired.
* Note that cxTokens can be precise to 18 decimal places.
* If the protocol's stablecoin has a different precision,
* you must tell this function explicitly when you call it.
*
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param precision Specify the protocol stablecoin precision.
*
*/
function getTotalLiquidityUnderProtectionInternal(
IStore s,
bytes32 coverKey,
uint256 precision
) external view returns (uint256 total) {
bool supportsProducts = supportsProductsInternal(s, coverKey);
if (supportsProducts == false) {
return getActiveLiquidityUnderProtectionInternal(s, coverKey, ProtoUtilV1.PRODUCT_KEY_INTENTIONALLY_EMPTY, precision);
}
bytes32[] memory products = _getProducts(s, coverKey);
for (uint256 i = 0; i < products.length; i++) {
total += getActiveLiquidityUnderProtectionInternal(s, coverKey, products[i], precision);
}
}
function _getProducts(IStore s, bytes32 coverKey) private view returns (bytes32[] memory products) {
return s.getBytes32ArrayByKeys(ProtoUtilV1.NS_COVER_PRODUCT, coverKey);
}
/**
* @dev Returns the total liquidity committed/under active protection.
* If the cover is a diversified pool, you must a provide product key.
*
* Simply put, commitments are the "totalSupply" of cxTokens that haven't yet expired.
* Note that cxTokens are precise to 18 decimal places.
* If the protocol's stablecoin has a different precision,
* you must tell this function explicitly when you call it.
*
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param productKey Enter product key
* @param adjustPrecision Specify the protocol stablecoin precision.
*
*/
function getActiveLiquidityUnderProtectionInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey,
uint256 adjustPrecision
) public view returns (uint256 total) {
(uint256 current, uint256 expiryDate) = _getCurrentCommitment(s, coverKey, productKey);
uint256 future = _getFutureCommitments(s, coverKey, productKey, expiryDate);
total = current + future;
// @caution:
// Adjusting precision results in truncation and data loss.
//
// Can also open a can of worms if the protocol stablecoin
// address needs to be updated in the future.
total = (total * adjustPrecision) / ProtoUtilV1.CXTOKEN_PRECISION;
}
/**
* @dev Gets current commitment of a given cover product.
*
* <br /> <br />
*
* If there is no incident, should return zero.
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param productKey Enter product key
*
* @return amount The current commitment amount.
* @return expiryDate The time at which the commitment `amount` expires.
*
*/
function _getCurrentCommitment(
IStore s,
bytes32 coverKey,
bytes32 productKey
) private view returns (uint256 amount, uint256 expiryDate) {
uint256 incidentDateIfAny = getActiveIncidentDateInternal(s, coverKey, productKey);
// There isn't any incident for this cover
// and therefore no need to pay
if (incidentDateIfAny == 0) {
return (0, 0);
}
expiryDate = _getMonthEndDate(incidentDateIfAny);
ICxToken cxToken = ICxToken(getCxTokenByExpiryDateInternal(s, coverKey, productKey, expiryDate));
if (address(cxToken) != address(0)) {
amount = cxToken.totalSupply();
}
}
/**
* @dev Gets future commitment of a given cover product.
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param productKey Enter product key
* @param excludedExpiryDate Enter expiry date (from current commitment) to exclude
*
* @return sum The total commitment amount.
*
*/
function _getFutureCommitments(
IStore s,
bytes32 coverKey,
bytes32 productKey,
uint256 excludedExpiryDate
) private view returns (uint256 sum) {
for (uint256 i = 0; i <= ProtoUtilV1.MAX_POLICY_DURATION; i++) {
uint256 expiryDate = _getNextMonthEndDate(block.timestamp, i); // solhint-disable-line
if (expiryDate == excludedExpiryDate || expiryDate <= block.timestamp) {
// solhint-disable-previous-line
continue;
}
ICxToken cxToken = ICxToken(getCxTokenByExpiryDateInternal(s, coverKey, productKey, expiryDate));
if (address(cxToken) != address(0)) {
sum += cxToken.totalSupply();
}
}
}
/**
* @dev Sets the current status of a given cover
*
* 0 - normal
* 1 - stopped, can not purchase covers or add liquidity
* 2 - reporting, incident happened
* 3 - reporting, false reporting
* 4 - claimable, claims accepted for payout
*
*/
function setStatusInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate,
ProductStatus status
) external {
s.setUintByKey(getProductStatusOfKeyInternal(coverKey, productKey, incidentDate), uint256(status));
}
/**
* @dev Gets the expiry date based on cover duration
* @param today Enter the current timestamp
* @param coverDuration Enter the number of months to cover. Accepted values: 1-3.
*/
function getExpiryDateInternal(uint256 today, uint256 coverDuration) external pure returns (uint256) {
// Get the day of the month
(, , uint256 day) = BokkyPooBahsDateTimeLibrary.timestampToDate(today);
// Cover duration of 1 month means current month
// unless today is the 25th calendar day or later
uint256 monthToAdd = coverDuration - 1;
if (day >= 25) {
// Add one month
monthToAdd += 1;
}
return _getNextMonthEndDate(today, monthToAdd);
}
// function _getPreviousMonthEndDate(uint256 date, uint256 monthsToSubtract) private pure returns (uint256) {
// uint256 pastDate = BokkyPooBahsDateTimeLibrary.subMonths(date, monthsToSubtract);
// return _getMonthEndDate(pastDate);
// }
function _getNextMonthEndDate(uint256 date, uint256 monthsToAdd) private pure returns (uint256) {
uint256 futureDate = BokkyPooBahsDateTimeLibrary.addMonths(date, monthsToAdd);
return _getMonthEndDate(futureDate);
}
function _getMonthEndDate(uint256 date) private pure returns (uint256) {
// Get the year and month from the date
(uint256 year, uint256 month, ) = BokkyPooBahsDateTimeLibrary.timestampToDate(date);
// Count the total number of days of that month and year
uint256 daysInMonth = BokkyPooBahsDateTimeLibrary._getDaysInMonth(year, month);
// Get the month end date
return BokkyPooBahsDateTimeLibrary.timestampFromDateTime(year, month, daysInMonth, 23, 59, 59);
}
/**
* @dev Returns the given cover product's cxToken by its expiry date (if available).
*
* Warning: this function does not validate the input arguments.
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param productKey Enter product key
* @param expiryDate Enter cxToken's expiry date
*
*/
function getCxTokenByExpiryDateInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey,
uint256 expiryDate
) public view returns (address cxToken) {
bytes32 k = keccak256(abi.encodePacked(ProtoUtilV1.NS_COVER_CXTOKEN, coverKey, productKey, expiryDate));
cxToken = s.getAddress(k);
}
function checkIfProductRequiresWhitelistInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey
) external view returns (bool) {
return s.getBoolByKeys(ProtoUtilV1.NS_COVER_REQUIRES_WHITELIST, coverKey, productKey);
}
function checkIfRequiresWhitelistInternal(IStore s, bytes32 coverKey) external view returns (bool) {
return s.getBoolByKeys(ProtoUtilV1.NS_COVER_REQUIRES_WHITELIST, coverKey);
}
function supportsProductsInternal(IStore s, bytes32 coverKey) public view returns (bool) {
return s.getBoolByKeys(ProtoUtilV1.NS_COVER_SUPPORTS_PRODUCTS, coverKey);
}
function isValidProductInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey
) external view returns (bool) {
return s.getBoolByKeys(ProtoUtilV1.NS_COVER_PRODUCT, coverKey, productKey);
}
function isActiveProductInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey
) external view returns (bool) {
return s.getUintByKeys(ProtoUtilV1.NS_COVER_PRODUCT, coverKey, productKey) == 1;
}
function disablePolicyInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey,
bool status
) external {
bytes32 key = getPolicyDisabledKeyInternal(coverKey, productKey);
s.setBoolByKey(key, status);
}
function isPolicyDisabledInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey
) external view returns (bool) {
bytes32 key = getPolicyDisabledKeyInternal(coverKey, productKey);
return s.getBoolByKey(key);
}
/**
* @dev Hash key of the "disabled policy flag" for the given cover product.
*
* Warning: this function does not validate the cover and product key supplied.
*
* @param coverKey Enter cover key
* @param productKey Enter product key
*
*/
function getPolicyDisabledKeyInternal(bytes32 coverKey, bytes32 productKey) public pure returns (bytes32) {
return keccak256(abi.encodePacked(ProtoUtilV1.NS_POLICY_DISABLED, coverKey, productKey));
}
/**
* @dev Gets the latest and "active" incident date of a cover product.
* Note that after "resolve" is invoked, incident date is reset.
*
* Warning: this function does not validate the cover and product key supplied.
*
* @param s Specify store instance
* @param coverKey Enter cover key
* @param productKey Enter product key
*/
function getActiveIncidentDateInternal(
IStore s,
bytes32 coverKey,
bytes32 productKey
) public view returns (uint256) {
return s.getUintByKeys(ProtoUtilV1.NS_GOVERNANCE_REPORTING_INCIDENT_DATE, coverKey, productKey);
}
function getCoverageLagInternal(IStore s, bytes32 coverKey) internal view returns (uint256) {
uint256 custom = s.getUintByKeys(ProtoUtilV1.NS_COVERAGE_LAG, coverKey);
// Custom means set for this exact cover
if (custom > 0) {
return custom;
}
// Global means set for all covers (without specifying a cover key)
uint256 global = s.getUintByKey(ProtoUtilV1.NS_COVERAGE_LAG);
if (global > 0) {
return global;
}
// Fallback means the default option
return COVER_LAG_FALLBACK_VALUE;
}
}