forked from neptune-mutual-blue/protocol
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PolicyAdmin.sol
126 lines (109 loc) · 3.89 KB
/
PolicyAdmin.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
// Neptune Mutual Protocol (https://neptunemutual.com)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "../../interfaces/IStore.sol";
import "../../interfaces/IPolicyAdmin.sol";
import "../../libraries/PolicyHelperV1.sol";
import "../../libraries/StoreKeyUtil.sol";
import "../../libraries/ProtoUtilV1.sol";
import "../Recoverable.sol";
/**
* @title Policy Admin Contract
* @dev The policy admin contract enables the owner (governance)
* to set the policy rate and fee info.
*/
contract PolicyAdmin is IPolicyAdmin, Recoverable {
using ProtoUtilV1 for bytes;
using PolicyHelperV1 for IStore;
using ProtoUtilV1 for IStore;
using ValidationLibV1 for IStore;
using CoverUtilV1 for IStore;
using StoreKeyUtil for IStore;
using NTransferUtilV2 for IERC20;
using RoutineInvokerLibV1 for IStore;
/**
* @dev Constructs this contract
* @param store Provide the store contract instance
*/
constructor(IStore store) Recoverable(store) {} // solhint-disable-line
/**
* @dev Sets policy rates for the given cover key. This feature is only accessible by cover manager.
* @param floor The lowest cover fee rate for this cover
* @param ceiling The highest cover fee rate for this cover
*/
function setPolicyRatesByKey(
bytes32 coverKey,
uint256 floor,
uint256 ceiling
) external override nonReentrant {
s.mustNotBePaused();
AccessControlLibV1.mustBeCoverManager(s);
require(floor > 0, "Please specify floor");
require(ceiling > floor, "Invalid ceiling");
if (coverKey > 0) {
s.mustBeValidCoverKey(coverKey);
s.setUintByKeys(ProtoUtilV1.NS_COVER_POLICY_RATE_FLOOR, coverKey, floor);
s.setUintByKeys(ProtoUtilV1.NS_COVER_POLICY_RATE_CEILING, coverKey, ceiling);
} else {
s.setUintByKey(ProtoUtilV1.NS_COVER_POLICY_RATE_FLOOR, floor);
s.setUintByKey(ProtoUtilV1.NS_COVER_POLICY_RATE_CEILING, ceiling);
}
s.updateStateAndLiquidity(coverKey);
emit CoverPolicyRateSet(coverKey, floor, ceiling);
}
/**
* @dev The coverage of a policy begins at the EOD timestamp
* of the policy purchase date plus the coverage lag.
*
* Coverage lag is a specified time period that can be set globally
* or on a per-cover basis to delay the start of coverage.
*
* This allows us to defend against time-based opportunistic attacks,
* which occur when an attacker purchases coverage after
* an incident has occurred but before the incident has been reported.
*/
function setCoverageLag(bytes32 coverKey, uint256 window) external override {
require(window >= 1 days, "Enter at least 1 day");
s.mustNotBePaused();
AccessControlLibV1.mustBeCoverManager(s);
if (coverKey > 0) {
s.mustBeValidCoverKey(coverKey);
s.setUintByKeys(ProtoUtilV1.NS_COVERAGE_LAG, coverKey, window);
emit CoverageLagSet(coverKey, window);
return;
}
s.setUintByKey(ProtoUtilV1.NS_COVERAGE_LAG, window);
emit CoverageLagSet(coverKey, window);
}
/**
* @dev Gets the cover policy rates for the given cover key
*
* Warning: this function does not validate the cover key supplied.
*
*/
function getPolicyRates(bytes32 coverKey) external view override returns (uint256 floor, uint256 ceiling) {
return s.getPolicyRatesInternal(coverKey);
}
/**
* @dev Gets the policy lag for the given cover key
*
* Warning: this function does not validate the cover key supplied.
*
*/
function getCoverageLag(bytes32 coverKey) external view override returns (uint256) {
return s.getCoverageLagInternal(coverKey);
}
/**
* @dev Version number of this contract
*/
function version() external pure override returns (bytes32) {
return "v0.1";
}
/**
* @dev Name of this contract
*/
function getName() external pure override returns (bytes32) {
return ProtoUtilV1.CNAME_POLICY_ADMIN;
}
}