-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathPriceOracleSentinel.sol
97 lines (83 loc) · 3.41 KB
/
PriceOracleSentinel.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
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.10;
import {Errors} from '../protocol/libraries/helpers/Errors.sol';
import {IPoolAddressesProvider} from '../interfaces/IPoolAddressesProvider.sol';
import {IPriceOracleSentinel} from '../interfaces/IPriceOracleSentinel.sol';
import {ISequencerOracle} from '../interfaces/ISequencerOracle.sol';
import {IACLManager} from '../interfaces/IACLManager.sol';
/**
* @title PriceOracleSentinel
* @author Aave
* @notice It validates if operations are allowed depending on the PriceOracle health.
* @dev Once the PriceOracle gets up after an outage/downtime, users can make their positions healthy during a grace
* period. So the PriceOracle is considered completely up once its up and the grace period passed.
*/
contract PriceOracleSentinel is IPriceOracleSentinel {
/**
* @dev Only pool admin can call functions marked by this modifier.
*/
modifier onlyPoolAdmin() {
IACLManager aclManager = IACLManager(ADDRESSES_PROVIDER.getACLManager());
require(aclManager.isPoolAdmin(msg.sender), Errors.CALLER_NOT_POOL_ADMIN);
_;
}
/**
* @dev Only risk or pool admin can call functions marked by this modifier.
*/
modifier onlyRiskOrPoolAdmins() {
IACLManager aclManager = IACLManager(ADDRESSES_PROVIDER.getACLManager());
require(
aclManager.isRiskAdmin(msg.sender) || aclManager.isPoolAdmin(msg.sender),
Errors.CALLER_NOT_RISK_OR_POOL_ADMIN
);
_;
}
IPoolAddressesProvider public immutable override ADDRESSES_PROVIDER;
ISequencerOracle internal _sequencerOracle;
uint256 internal _gracePeriod;
/**
* @dev Constructor
* @param provider The address of the PoolAddressesProvider
* @param oracle The address of the SequencerOracle
* @param gracePeriod The duration of the grace period in seconds
*/
constructor(IPoolAddressesProvider provider, ISequencerOracle oracle, uint256 gracePeriod) {
ADDRESSES_PROVIDER = provider;
_sequencerOracle = oracle;
_gracePeriod = gracePeriod;
}
/// @inheritdoc IPriceOracleSentinel
function isBorrowAllowed() external view override returns (bool) {
return _isUpAndGracePeriodPassed();
}
/// @inheritdoc IPriceOracleSentinel
function isLiquidationAllowed() external view override returns (bool) {
return _isUpAndGracePeriodPassed();
}
/**
* @notice Checks the sequencer oracle is healthy: is up and grace period passed.
* @return True if the SequencerOracle is up and the grace period passed, false otherwise
*/
function _isUpAndGracePeriodPassed() internal view returns (bool) {
(, int256 answer, uint256 startedAt, , ) = _sequencerOracle.latestRoundData();
return answer == 0 && block.timestamp - startedAt > _gracePeriod;
}
/// @inheritdoc IPriceOracleSentinel
function setSequencerOracle(address newSequencerOracle) external onlyPoolAdmin {
_sequencerOracle = ISequencerOracle(newSequencerOracle);
emit SequencerOracleUpdated(newSequencerOracle);
}
/// @inheritdoc IPriceOracleSentinel
function setGracePeriod(uint256 newGracePeriod) external onlyRiskOrPoolAdmins {
_gracePeriod = newGracePeriod;
emit GracePeriodUpdated(newGracePeriod);
}
/// @inheritdoc IPriceOracleSentinel
function getSequencerOracle() external view returns (address) {
return address(_sequencerOracle);
}
/// @inheritdoc IPriceOracleSentinel
function getGracePeriod() external view returns (uint256) {
return _gracePeriod;
}
}