-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathFinalization.sol
More file actions
96 lines (85 loc) · 3.81 KB
/
Finalization.sol
File metadata and controls
96 lines (85 loc) · 3.81 KB
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
// Neptune Mutual Protocol (https://neptunemutual.com)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import "../../Recoverable.sol";
import "../../../interfaces/IFinalization.sol";
/**
* @title Finalization Contract
* @dev This contract allows governance agents "finalize"
* a resolved cover product after the claim period.
*
* When a cover product is finalized, it resets back to normal
* state where tokenholders can again supply liquidity
* and purchase policies.
*/
abstract contract Finalization is Recoverable, IFinalization {
using GovernanceUtilV1 for IStore;
using StoreKeyUtil for IStore;
using ValidationLibV1 for IStore;
using RoutineInvokerLibV1 for IStore;
/**
* @dev Finalizes a cover pool or a product contract.
* Once finalized, the cover resets back to the normal state.
*
* @custom:note Please note the following:
*
* An incident can be finalized:
*
* - by a governance agent
* - if it was reported and resolved
* - after claim period
* - after reassurance fund is capitalized back to the liquidity pool
*
* @param coverKey Enter the cover key you want to finalize
* @param productKey Enter the product key you want to finalize
* @param incidentDate Enter the date of this incident reporting
*
*/
function finalize(
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) external override nonReentrant {
require(incidentDate > 0, "Please specify incident date");
s.mustNotBePaused();
AccessControlLibV1.mustBeGovernanceAgent(s);
s.mustBeSupportedProductOrEmpty(coverKey, productKey);
s.mustBeValidIncidentDate(coverKey, productKey, incidentDate);
s.mustBeClaimingOrDisputed(coverKey, productKey);
s.mustBeAfterResolutionDeadline(coverKey, productKey);
s.mustBeAfterClaimExpiry(coverKey, productKey);
// The reassurance capital (if available) needs to be transferred before this cover can be finalized.
uint256 transferable = s.getReassuranceTransferrableInternal(coverKey, productKey, incidentDate);
require(transferable == 0, "Pool must be capitalized");
_finalize(coverKey, productKey, incidentDate);
}
/**
*
* @custom:warning Warning:
*
* Since this product's incident status is needed after finalization,
* do not invoke `setStatusInternal` or attempt to reset it to normal.
*
*/
function _finalize(
bytes32 coverKey,
bytes32 productKey,
uint256 incidentDate
) internal {
s.setBoolByKey(GovernanceUtilV1.getHasFinalizedKeyInternal(coverKey, productKey, incidentDate), true);
// Deleting latest incident date resets this product
s.deleteUintByKeys(ProtoUtilV1.NS_GOVERNANCE_REPORTING_INCIDENT_DATE, coverKey, productKey);
s.deleteUintByKeys(ProtoUtilV1.NS_GOVERNANCE_RESOLUTION_TS, coverKey, productKey);
s.deleteUintByKeys(ProtoUtilV1.NS_CLAIM_BEGIN_TS, coverKey, productKey);
s.deleteUintByKeys(ProtoUtilV1.NS_CLAIM_EXPIRY_TS, coverKey, productKey);
s.deleteAddressByKeys(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_YES, coverKey, productKey);
s.deleteAddressByKeys(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_NO, coverKey, productKey);
s.deleteUintByKeys(ProtoUtilV1.NS_RESOLUTION_DEADLINE, coverKey, productKey);
s.deleteBoolByKey(GovernanceUtilV1.getHasDisputeKeyInternal(coverKey, productKey));
// @warning: do not uncomment these lines as these vales are required to enable unstaking any time after finalization
// s.deleteAddressByKey(keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_YES, coverKey, productKey, incidentDate)));
// s.deleteAddressByKey(keccak256(abi.encodePacked(ProtoUtilV1.NS_GOVERNANCE_REPORTING_WITNESS_NO, coverKey, productKey, incidentDate)));
s.updateStateAndLiquidityInternal(coverKey);
emit Finalized(coverKey, productKey, msg.sender, incidentDate);
}
}