@venusprotocol/oracle 1.5.1 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/build-info/1d7bedd9b14544f287811332b9a539d7.json +1 -0
- package/artifacts/build-info/f6af69795174616b8b4a6373f9f1c538.json +1 -0
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +2 -2
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +2 -2
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +2 -2
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +2 -2
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +3 -3
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +2 -2
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +2 -2
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +2 -2
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +2 -2
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +2 -2
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +2 -2
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +2 -2
- package/contracts/PriceOracle.sol +2 -2
- package/contracts/ResilientOracle.sol +127 -114
- package/contracts/libraries/PancakeLibrary.sol +8 -8
- package/contracts/oracles/BinanceOracle.sol +4 -4
- package/contracts/oracles/BoundValidator.sol +31 -29
- package/contracts/oracles/ChainlinkOracle.sol +85 -83
- package/contracts/oracles/PythOracle.sol +41 -41
- package/contracts/oracles/TwapOracle.sol +67 -67
- package/contracts/oracles/mocks/MockBinanceOracle.sol +4 -4
- package/contracts/oracles/mocks/MockChainlinkOracle.sol +4 -4
- package/contracts/oracles/mocks/MockPythOracle.sol +4 -4
- package/contracts/oracles/mocks/MockTwapOracle.sol +4 -4
- package/contracts/test/MockPyth.sol +13 -13
- package/contracts/test/MockSimpleOracle.sol +8 -8
- package/contracts/test/MockV3Aggregator.sol +18 -18
- package/contracts/test/PancakePairHarness.sol +10 -10
- package/deploy/1-deploy-oracles.d.ts +1 -3
- package/deploy/1-deploy-oracles.d.ts.map +1 -1
- package/deploy/1-deploy-oracles.js +2 -1
- package/deploy/1-deploy-oracles.js.map +1 -1
- package/deploy/2-configure-feeds.d.ts +1 -3
- package/deploy/2-configure-feeds.d.ts.map +1 -1
- package/deploy/2-configure-feeds.js +101 -87
- package/deploy/2-configure-feeds.js.map +1 -1
- package/deployments/bsctestnet/BinanceOracle.json +42 -29
- package/deployments/bsctestnet/BinanceOracle_Implementation.json +96 -23
- package/deployments/bsctestnet/BinanceOracle_Proxy.json +28 -28
- package/deployments/bsctestnet/BoundValidator.json +65 -39
- package/deployments/bsctestnet/BoundValidator_Implementation.json +113 -35
- package/deployments/bsctestnet/BoundValidator_Proxy.json +37 -37
- package/deployments/bsctestnet/ChainlinkOracle.json +64 -38
- package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +122 -41
- package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +37 -37
- package/deployments/bsctestnet/DefaultProxyAdmin.json +15 -15
- package/deployments/bsctestnet/PythOracle.json +71 -45
- package/deployments/bsctestnet/PythOracle_Implementation.json +128 -44
- package/deployments/bsctestnet/PythOracle_Proxy.json +44 -44
- package/deployments/bsctestnet/ResilientOracle.json +67 -54
- package/deployments/bsctestnet/ResilientOracle_Implementation.json +161 -63
- package/deployments/bsctestnet/ResilientOracle_Proxy.json +39 -39
- package/deployments/bsctestnet/TwapOracle.json +74 -71
- package/deployments/bsctestnet/TwapOracle_Implementation.json +163 -93
- package/deployments/bsctestnet/TwapOracle_Proxy.json +37 -41
- package/deployments/bsctestnet/solcInputs/6153c675ce838eebb6442d63350712be.json +144 -0
- package/package.json +4 -2
- package/artifacts/build-info/4f6308532d612c9477fab05b03e221e5.json +0 -1
- package/deployments/bsctestnet/solcInputs/09bc2981019c6dcce653b90bac585fe0.json +0 -81
- package/deployments/bsctestnet/solcInputs/5dedb37ab8105f1f71e53a3f865859c5.json +0 -57
- package/deployments/bsctestnet/solcInputs/bb71c6049f6b7b21a6581f40daf802bc.json +0 -138
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
"contractName": "UQ112x112",
|
|
4
4
|
"sourceName": "contracts/test/PancakePairHarness.sol",
|
|
5
5
|
"abi": [],
|
|
6
|
-
"bytecode": "
|
|
7
|
-
"deployedBytecode": "
|
|
6
|
+
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122065dd1aba8b49cec425c48656322d3b21fbfb833a258afc914ec218340bb70b9464736f6c634300080d0033",
|
|
7
|
+
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122065dd1aba8b49cec425c48656322d3b21fbfb833a258afc914ec218340bb70b9464736f6c634300080d0033",
|
|
8
8
|
"linkReferences": {},
|
|
9
9
|
"deployedLinkReferences": {}
|
|
10
10
|
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
pragma solidity 0.8.13;
|
|
5
5
|
|
|
6
6
|
abstract contract PriceOracle {
|
|
7
|
+
function updatePrice(address vToken) external virtual;
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* @notice Get the underlying price of a vToken asset
|
|
9
11
|
* @param vToken The vToken address to get the underlying price of
|
|
@@ -11,6 +13,4 @@ abstract contract PriceOracle {
|
|
|
11
13
|
* Zero means the price is unavailable.
|
|
12
14
|
*/
|
|
13
15
|
function getUnderlyingPrice(address vToken) external view virtual returns (uint256);
|
|
14
|
-
|
|
15
|
-
function updatePrice(address vToken) external virtual;
|
|
16
16
|
}
|
|
@@ -8,21 +8,10 @@ import "./interfaces/VBep20Interface.sol";
|
|
|
8
8
|
import "./interfaces/OracleInterface.sol";
|
|
9
9
|
|
|
10
10
|
contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOracleInterface {
|
|
11
|
-
uint256 public constant INVALID_PRICE = 0;
|
|
12
|
-
|
|
13
|
-
/// @notice vBNB address
|
|
14
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
15
|
-
address public immutable vBnb;
|
|
16
|
-
|
|
17
|
-
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
18
|
-
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
19
|
-
|
|
20
|
-
BoundValidatorInterface public boundValidator;
|
|
21
|
-
|
|
22
11
|
/**
|
|
23
|
-
* @dev
|
|
12
|
+
* @dev Oracle roles:
|
|
24
13
|
* **main**: The most trustworthy price source
|
|
25
|
-
* **pivot**:
|
|
14
|
+
* **pivot**: Price oracle used as a loose sanity checker
|
|
26
15
|
* **fallback**: The backup source when main oracle price is invalidated
|
|
27
16
|
*/
|
|
28
17
|
enum OracleRole {
|
|
@@ -34,14 +23,26 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
34
23
|
struct TokenConfig {
|
|
35
24
|
/// @notice asset address
|
|
36
25
|
address asset;
|
|
37
|
-
/// @notice `oracles` stores the oracles in the order
|
|
38
|
-
///
|
|
26
|
+
/// @notice `oracles` stores the oracles based on their role in the following order:
|
|
27
|
+
/// [main, pivot, fallback],
|
|
28
|
+
/// It can be indexed with the corresponding enum OracleRole value
|
|
39
29
|
address[3] oracles;
|
|
40
|
-
/// @notice `enableFlagsForOracles` stores the
|
|
30
|
+
/// @notice `enableFlagsForOracles` stores the enabled state
|
|
41
31
|
/// for each oracle in the same order as `oracles`
|
|
42
32
|
bool[3] enableFlagsForOracles;
|
|
43
33
|
}
|
|
44
34
|
|
|
35
|
+
uint256 public constant INVALID_PRICE = 0;
|
|
36
|
+
|
|
37
|
+
/// @notice vBNB address
|
|
38
|
+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
39
|
+
address public immutable vBnb;
|
|
40
|
+
|
|
41
|
+
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
42
|
+
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
43
|
+
|
|
44
|
+
BoundValidatorInterface public boundValidator;
|
|
45
|
+
|
|
45
46
|
mapping(address => TokenConfig) private tokenConfigs;
|
|
46
47
|
|
|
47
48
|
event TokenConfigAdded(
|
|
@@ -50,17 +51,24 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
50
51
|
address indexed pivotOracle,
|
|
51
52
|
address fallbackOracle
|
|
52
53
|
);
|
|
54
|
+
|
|
55
|
+
/// Event emitted when an oracle is set
|
|
53
56
|
event OracleSet(address indexed asset, address indexed oracle, uint256 indexed role);
|
|
57
|
+
|
|
58
|
+
/// Event emitted when an oracle is enabled or disabled
|
|
54
59
|
event OracleEnabled(address indexed asset, uint256 indexed role, bool indexed enable);
|
|
55
60
|
|
|
61
|
+
/**
|
|
62
|
+
* @notice Checks whether an address is null or not
|
|
63
|
+
*/
|
|
56
64
|
modifier notNullAddress(address someone) {
|
|
57
65
|
require(someone != address(0), "can't be zero address");
|
|
58
66
|
_;
|
|
59
67
|
}
|
|
60
68
|
|
|
61
69
|
/**
|
|
62
|
-
* @notice
|
|
63
|
-
* @dev vToken can't be
|
|
70
|
+
* @notice Checks whether token config exists by checking whether vToken is null address
|
|
71
|
+
* @dev vToken can't be null, so it's suitable to be used to check the validity of the config
|
|
64
72
|
* @param asset asset address
|
|
65
73
|
*/
|
|
66
74
|
modifier checkTokenConfigExistance(address asset) {
|
|
@@ -69,7 +77,7 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
72
|
-
/// @param vBnbAddress The address of the
|
|
80
|
+
/// @param vBnbAddress The address of the vBNB
|
|
73
81
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
74
82
|
constructor(address vBnbAddress) notNullAddress(vBnbAddress) {
|
|
75
83
|
vBnb = vBnbAddress;
|
|
@@ -77,59 +85,26 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
77
85
|
}
|
|
78
86
|
|
|
79
87
|
/**
|
|
80
|
-
* @notice
|
|
81
|
-
* @
|
|
82
|
-
*/
|
|
83
|
-
function initialize(BoundValidatorInterface _boundValidator) public initializer {
|
|
84
|
-
require(address(_boundValidator) != address(0), "invalid bound validator address");
|
|
85
|
-
boundValidator = _boundValidator;
|
|
86
|
-
|
|
87
|
-
__Ownable_init();
|
|
88
|
-
__Pausable_init();
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* @notice Pause oracle
|
|
88
|
+
* @notice Pauses oracle
|
|
89
|
+
* @custom:access Only Governance
|
|
93
90
|
*/
|
|
94
91
|
function pause() external onlyOwner {
|
|
95
92
|
_pause();
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
/**
|
|
99
|
-
* @notice
|
|
96
|
+
* @notice Unpauses oracle
|
|
97
|
+
* @custom:access Only Governance
|
|
100
98
|
*/
|
|
101
99
|
function unpause() external onlyOwner {
|
|
102
100
|
_unpause();
|
|
103
101
|
}
|
|
104
102
|
|
|
105
103
|
/**
|
|
106
|
-
* @
|
|
107
|
-
* @param
|
|
108
|
-
* @return tokenConfig config of the vToken
|
|
109
|
-
*/
|
|
110
|
-
function getTokenConfig(address vToken) external view returns (TokenConfig memory) {
|
|
111
|
-
address asset = address(vToken) == vBnb ? BNB_ADDR : VBep20Interface(vToken).underlying();
|
|
112
|
-
return tokenConfigs[asset];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* @notice Get oracle & enabling status by vToken address
|
|
117
|
-
* @param vToken vtoken address
|
|
118
|
-
* @param role oracle role
|
|
119
|
-
* @return oracle oracle address based on role
|
|
120
|
-
* @return enabled enabled flag of the oracle based on token config
|
|
121
|
-
*/
|
|
122
|
-
function getOracle(address vToken, OracleRole role) public view returns (address oracle, bool enabled) {
|
|
123
|
-
address asset = address(vToken) == vBnb ? BNB_ADDR : VBep20Interface(vToken).underlying();
|
|
124
|
-
oracle = tokenConfigs[asset].oracles[uint256(role)];
|
|
125
|
-
enabled = tokenConfigs[asset].enableFlagsForOracles[uint256(role)];
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* @notice Batch set token configs
|
|
130
|
-
* @param tokenConfigs_ token config array
|
|
104
|
+
* @notice Batch sets token configs
|
|
105
|
+
* @param tokenConfigs_ Token config array
|
|
131
106
|
* @custom:access Only Governance
|
|
132
|
-
* @custom:error
|
|
107
|
+
* @custom:error Throws a length error if the lenght of the token configs array is 0
|
|
133
108
|
*/
|
|
134
109
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
|
|
135
110
|
require(tokenConfigs_.length != 0, "length can't be 0");
|
|
@@ -140,34 +115,15 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
140
115
|
}
|
|
141
116
|
|
|
142
117
|
/**
|
|
143
|
-
* @notice
|
|
144
|
-
* @
|
|
145
|
-
* @
|
|
146
|
-
* @
|
|
147
|
-
* @
|
|
148
|
-
* @custom:event Emits TokenConfigAdded event when vToken config are set by governnace
|
|
149
|
-
*/
|
|
150
|
-
function setTokenConfig(
|
|
151
|
-
TokenConfig memory tokenConfig
|
|
152
|
-
) public onlyOwner notNullAddress(tokenConfig.asset) notNullAddress(tokenConfig.oracles[uint256(OracleRole.MAIN)]) {
|
|
153
|
-
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
154
|
-
emit TokenConfigAdded(
|
|
155
|
-
tokenConfig.asset,
|
|
156
|
-
tokenConfig.oracles[uint256(OracleRole.MAIN)],
|
|
157
|
-
tokenConfig.oracles[uint256(OracleRole.PIVOT)],
|
|
158
|
-
tokenConfig.oracles[uint256(OracleRole.FALLBACK)]
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @notice Set oracle of any type for the input vToken, input vToken **must** exist
|
|
164
|
-
* @param asset asset address
|
|
165
|
-
* @param oracle oracle address
|
|
166
|
-
* @param role oracle role
|
|
118
|
+
* @notice Sets oracle for a given vToken and role.
|
|
119
|
+
* @dev Supplied vToken **must** exist and main oracle may not be null
|
|
120
|
+
* @param asset Asset address
|
|
121
|
+
* @param oracle Oracle address
|
|
122
|
+
* @param role Oracle role
|
|
167
123
|
* @custom:access Only Governance
|
|
168
|
-
* @custom:error
|
|
169
|
-
* @custom:error NotNullAddress error thrown if asset address is
|
|
170
|
-
* @custom:error TokenConfigExistance error thrown if token config is not set
|
|
124
|
+
* @custom:error Null address error if main-role oracle address is null
|
|
125
|
+
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
126
|
+
* @custom:error TokenConfigExistance error is thrown if token config is not set
|
|
171
127
|
* @custom:event Emits OracleSet event with asset address, oracle address and role of the oracle for the asset
|
|
172
128
|
*/
|
|
173
129
|
function setOracle(
|
|
@@ -181,13 +137,13 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
181
137
|
}
|
|
182
138
|
|
|
183
139
|
/**
|
|
184
|
-
* @notice
|
|
185
|
-
* @param asset
|
|
186
|
-
* @param role
|
|
187
|
-
* @param enable
|
|
140
|
+
* @notice Enables/ disables oracle for the input vToken, input vToken **must** exist
|
|
141
|
+
* @param asset Asset address
|
|
142
|
+
* @param role Oracle role
|
|
143
|
+
* @param enable Enabled boolean of the oracle
|
|
188
144
|
* @custom:access Only Governance
|
|
189
|
-
* @custom:error NotNullAddress error thrown if asset address is
|
|
190
|
-
* @custom:error TokenConfigExistance error thrown if token config is not set
|
|
145
|
+
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
146
|
+
* @custom:error TokenConfigExistance error is thrown if token config is not set
|
|
191
147
|
*/
|
|
192
148
|
function enableOracle(
|
|
193
149
|
address asset,
|
|
@@ -199,8 +155,8 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
199
155
|
}
|
|
200
156
|
|
|
201
157
|
/**
|
|
202
|
-
* @notice
|
|
203
|
-
* @dev This function should be called
|
|
158
|
+
* @notice Updates the pivot oracle price. Currently using TWAP
|
|
159
|
+
* @dev This function should always be called before calling getUnderlyingPrice
|
|
204
160
|
* @param vToken vToken address
|
|
205
161
|
*/
|
|
206
162
|
function updatePrice(address vToken) external override {
|
|
@@ -212,15 +168,26 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
212
168
|
}
|
|
213
169
|
|
|
214
170
|
/**
|
|
215
|
-
* @
|
|
216
|
-
* - check the global pausing status
|
|
217
|
-
* - check price from main oracle against pivot oracle
|
|
218
|
-
* - check price from fallback oracle against pivot oracle or main oracle if fails
|
|
171
|
+
* @dev Gets token config by vToken address
|
|
219
172
|
* @param vToken vToken address
|
|
220
|
-
* @return
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
173
|
+
* @return tokenConfig Config for the vToken
|
|
174
|
+
*/
|
|
175
|
+
function getTokenConfig(address vToken) external view returns (TokenConfig memory) {
|
|
176
|
+
address asset = address(vToken) == vBnb ? BNB_ADDR : VBep20Interface(vToken).underlying();
|
|
177
|
+
return tokenConfigs[asset];
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* @notice Gets price of the underlying asset for a given vToken. Validation flow:
|
|
182
|
+
* - Check if the oracle is paused globally
|
|
183
|
+
* - Validate price from main oracle against pivot oracle
|
|
184
|
+
* - Validate price from fallback oracle against pivot oracle or main oracle if the first validation failed
|
|
185
|
+
* In the case that the pivot oracle is not available but main price is available and validation is successful,
|
|
186
|
+
* main oracle price is returned.
|
|
187
|
+
* @param vToken vToken address
|
|
188
|
+
* @return price USD price in scaled decimal places.
|
|
189
|
+
* @custom:error Paused error is thrown when resilent oracle is paused
|
|
190
|
+
* @custom:error Invalid resilient oracle price error is thrown if fetched prices from oracle is invalid
|
|
224
191
|
*/
|
|
225
192
|
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
226
193
|
require(!paused(), "resilient oracle is paused");
|
|
@@ -262,19 +229,65 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
262
229
|
}
|
|
263
230
|
|
|
264
231
|
/**
|
|
265
|
-
* @notice
|
|
232
|
+
* @notice Initializes the contract admin and sets the BoundValidator contract address
|
|
233
|
+
* @param _boundValidator Address of the bound validator contract
|
|
234
|
+
*/
|
|
235
|
+
function initialize(BoundValidatorInterface _boundValidator) public initializer {
|
|
236
|
+
require(address(_boundValidator) != address(0), "invalid bound validator address");
|
|
237
|
+
boundValidator = _boundValidator;
|
|
238
|
+
|
|
239
|
+
__Ownable_init();
|
|
240
|
+
__Pausable_init();
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @notice Sets/resets single token configs.
|
|
245
|
+
* @dev main oracle **must not** be a null address
|
|
246
|
+
* @param tokenConfig Token config struct
|
|
247
|
+
* @custom:access Only Governance
|
|
248
|
+
* @custom:error NotNullAddress is thrown if asset address is null
|
|
249
|
+
* @custom:error NotNullAddress is thrown if main-role oracle address for asset is null
|
|
250
|
+
* @custom:event Emits TokenConfigAdded event when vToken config is set successfully by governnace
|
|
251
|
+
*/
|
|
252
|
+
function setTokenConfig(
|
|
253
|
+
TokenConfig memory tokenConfig
|
|
254
|
+
) public onlyOwner notNullAddress(tokenConfig.asset) notNullAddress(tokenConfig.oracles[uint256(OracleRole.MAIN)]) {
|
|
255
|
+
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
256
|
+
emit TokenConfigAdded(
|
|
257
|
+
tokenConfig.asset,
|
|
258
|
+
tokenConfig.oracles[uint256(OracleRole.MAIN)],
|
|
259
|
+
tokenConfig.oracles[uint256(OracleRole.PIVOT)],
|
|
260
|
+
tokenConfig.oracles[uint256(OracleRole.FALLBACK)]
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @notice Gets oracle and enabled status by vToken address
|
|
266
|
+
* @param vToken vToken address
|
|
267
|
+
* @param role Oracle role
|
|
268
|
+
* @return oracle Oracle address based on role
|
|
269
|
+
* @return enabled Enabled flag of the oracle based on token config
|
|
270
|
+
*/
|
|
271
|
+
function getOracle(address vToken, OracleRole role) public view returns (address oracle, bool enabled) {
|
|
272
|
+
address asset = address(vToken) == vBnb ? BNB_ADDR : VBep20Interface(vToken).underlying();
|
|
273
|
+
oracle = tokenConfigs[asset].oracles[uint256(role)];
|
|
274
|
+
enabled = tokenConfigs[asset].enableFlagsForOracles[uint256(role)];
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @notice Gets underlying asset price for the provided vToken
|
|
266
279
|
* @dev This function won't revert when price is 0, because the fallback oracle may still be
|
|
267
280
|
* able to fetch a correct price
|
|
268
281
|
* @param vToken vToken address
|
|
269
|
-
* @param pivotPrice
|
|
270
|
-
* @param pivotEnabled
|
|
282
|
+
* @param pivotPrice Pivot oracle price
|
|
283
|
+
* @param pivotEnabled If pivot oracle is not empty and enabled
|
|
271
284
|
* @return price USD price in scaled decimals
|
|
272
285
|
* e.g. vToken decimals is 8 then price is returned as 10**18 * 10**(18-8) = 10**28 decimals
|
|
273
286
|
* @return pivotValidated Boolean representing if the validation of main oracle price
|
|
274
|
-
* and pivot oracle price
|
|
275
|
-
* @custom:error Invalid price error thrown if main oracle fails to fetch price of underlying asset
|
|
276
|
-
* @custom:error Invalid price error thrown if main oracle is not enabled or main oracle
|
|
277
|
-
* address is
|
|
287
|
+
* and pivot oracle price were successful
|
|
288
|
+
* @custom:error Invalid price error is thrown if main oracle fails to fetch price of underlying asset
|
|
289
|
+
* @custom:error Invalid price error is thrown if main oracle is not enabled or main oracle
|
|
290
|
+
* address is null
|
|
278
291
|
*/
|
|
279
292
|
function _getMainOraclePrice(
|
|
280
293
|
address vToken,
|
|
@@ -303,14 +316,14 @@ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOr
|
|
|
303
316
|
}
|
|
304
317
|
|
|
305
318
|
/**
|
|
306
|
-
* @
|
|
319
|
+
* @dev This function won't revert when the price is 0 because getUnderlyingPrice checks if price is > 0
|
|
307
320
|
* @param vToken vToken address
|
|
308
321
|
* @return price USD price in 18 decimals
|
|
309
322
|
* @return pivotValidated Boolean representing if the validation of fallback oracle price
|
|
310
|
-
* and pivot oracle price
|
|
311
|
-
* @custom:error Invalid price error thrown if fallback oracle fails to fetch price of underlying asset
|
|
312
|
-
* @custom:error Invalid price error thrown if fallback oracle is not enabled or fallback oracle
|
|
313
|
-
* address is
|
|
323
|
+
* and pivot oracle price were successfull
|
|
324
|
+
* @custom:error Invalid price error is thrown if fallback oracle fails to fetch price of underlying asset
|
|
325
|
+
* @custom:error Invalid price error is thrown if fallback oracle is not enabled or fallback oracle
|
|
326
|
+
* address is null
|
|
314
327
|
*/
|
|
315
328
|
function _getFallbackOraclePrice(address vToken, uint256 pivotPrice) internal view returns (uint256, bool) {
|
|
316
329
|
(address fallbackOracle, bool fallbackEnabled) = getOracle(vToken, OracleRole.FALLBACK);
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
2
|
pragma solidity 0.8.13;
|
|
3
3
|
|
|
4
|
+
interface IPancakePair {
|
|
5
|
+
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
|
|
6
|
+
|
|
7
|
+
function price0CumulativeLast() external view returns (uint256);
|
|
8
|
+
|
|
9
|
+
function price1CumulativeLast() external view returns (uint256);
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
library FixedPoint {
|
|
5
13
|
// range: [0, 2**112 - 1]
|
|
6
14
|
// resolution: 1 / 2**112
|
|
@@ -58,11 +66,3 @@ library PancakeOracleLibrary {
|
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
interface IPancakePair {
|
|
63
|
-
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
|
|
64
|
-
|
|
65
|
-
function price0CumulativeLast() external view returns (uint256);
|
|
66
|
-
|
|
67
|
-
function price1CumulativeLast() external view returns (uint256);
|
|
68
|
-
}
|
|
@@ -14,7 +14,7 @@ contract BinanceOracle is Initializable {
|
|
|
14
14
|
address public immutable vBnb;
|
|
15
15
|
|
|
16
16
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
17
|
-
/// @param vBnbAddress The address of the
|
|
17
|
+
/// @param vBnbAddress The address of the vBNB
|
|
18
18
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
19
19
|
constructor(address vBnbAddress) {
|
|
20
20
|
require(vBnbAddress != address(0), "can't be zero address");
|
|
@@ -23,7 +23,7 @@ contract BinanceOracle is Initializable {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
|
-
* @notice Sets the contracts required to fetch
|
|
26
|
+
* @notice Sets the contracts required to fetch prices
|
|
27
27
|
* @param feed Address of binance oracle feed registry.
|
|
28
28
|
*/
|
|
29
29
|
function initialize(FeedRegistryInterface feed) public initializer {
|
|
@@ -31,9 +31,9 @@ contract BinanceOracle is Initializable {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* @notice Gets the price of vToken from binance oracle
|
|
34
|
+
* @notice Gets the price of a vToken from the binance oracle
|
|
35
35
|
* @param vToken Address of the vToken
|
|
36
|
-
* @return
|
|
36
|
+
* @return Price in USD
|
|
37
37
|
*/
|
|
38
38
|
function getUnderlyingPrice(VBep20Interface vToken) public view returns (uint256) {
|
|
39
39
|
string memory symbol;
|
|
@@ -8,10 +8,10 @@ import "../interfaces/OracleInterface.sol";
|
|
|
8
8
|
struct ValidateConfig {
|
|
9
9
|
/// @notice asset address
|
|
10
10
|
address asset;
|
|
11
|
-
/// @notice
|
|
11
|
+
/// @notice Upper bound of deviation between reported price and anchor price,
|
|
12
12
|
/// beyond which the reported price will be invalidated
|
|
13
13
|
uint256 upperBoundRatio;
|
|
14
|
-
/// @notice
|
|
14
|
+
/// @notice Lower bound of deviation between reported price and anchor price,
|
|
15
15
|
/// below which the reported price will be invalidated
|
|
16
16
|
uint256 lowerBoundRatio;
|
|
17
17
|
}
|
|
@@ -29,30 +29,24 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
29
29
|
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
30
30
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
31
31
|
|
|
32
|
-
/// @notice Emit this event when new
|
|
32
|
+
/// @notice Emit this event when new validation configs are added
|
|
33
33
|
event ValidateConfigAdded(address indexed asset, uint256 indexed upperBound, uint256 indexed lowerBound);
|
|
34
34
|
|
|
35
35
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
36
|
-
/// @param vBnbAddress The address of the
|
|
36
|
+
/// @param vBnbAddress The address of the vBNB
|
|
37
37
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
38
38
|
constructor(address vBnbAddress) {
|
|
39
|
-
require(vBnbAddress != address(0), "can't be zero address");
|
|
39
|
+
require(vBnbAddress != address(0), "can't be a zero address");
|
|
40
40
|
vBnb = vBnbAddress;
|
|
41
41
|
_disableInitializers();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* @notice Initializes the owner of the contract
|
|
46
|
-
*/
|
|
47
|
-
function initialize() public initializer {
|
|
48
|
-
__Ownable_init();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
44
|
/**
|
|
52
45
|
* @notice Add multiple validation configs at the same time
|
|
53
|
-
* @param configs
|
|
46
|
+
* @param configs Array of validation configs
|
|
54
47
|
* @custom:access Only Governance
|
|
55
|
-
* @custom:error Zero length error thrown
|
|
48
|
+
* @custom:error Zero length error is thrown if length of the config array is 0
|
|
49
|
+
* @custom:event Emits ValidateConfigAdded for each validation config that is successfully set
|
|
56
50
|
*/
|
|
57
51
|
function setValidateConfigs(ValidateConfig[] memory configs) external virtual onlyOwner {
|
|
58
52
|
require(configs.length > 0, "invalid validate config length");
|
|
@@ -62,13 +56,20 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
/**
|
|
65
|
-
* @notice
|
|
66
|
-
|
|
59
|
+
* @notice Initializes the owner of the contract
|
|
60
|
+
*/
|
|
61
|
+
function initialize() public initializer {
|
|
62
|
+
__Ownable_init();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @notice Add a single validation config
|
|
67
|
+
* @param config Validation config struct
|
|
67
68
|
* @custom:access Only Governance
|
|
68
|
-
* @custom:error
|
|
69
|
+
* @custom:error Null address error is thrown if asset address is null
|
|
69
70
|
* @custom:error Range error thrown if bound ratio is not positive
|
|
70
71
|
* @custom:error Range error thrown if lower bound is greater than upper bound
|
|
71
|
-
* @custom:event Emits ValidateConfigAdded
|
|
72
|
+
* @custom:event Emits ValidateConfigAdded when a validation config is successfully set
|
|
72
73
|
*/
|
|
73
74
|
function setValidateConfig(ValidateConfig memory config) public virtual onlyOwner {
|
|
74
75
|
require(config.asset != address(0), "asset can't be zero address");
|
|
@@ -81,31 +82,31 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
81
82
|
/**
|
|
82
83
|
* @notice Test reported asset price against anchor price
|
|
83
84
|
* @param vToken vToken address
|
|
84
|
-
* @param
|
|
85
|
+
* @param reportedPrice The price to be tested
|
|
85
86
|
* @custom:error Missing error thrown if asset config is not set
|
|
86
|
-
* @custom:error Price error
|
|
87
|
+
* @custom:error Price error thrown if anchor price is not valid
|
|
87
88
|
*/
|
|
88
89
|
function validatePriceWithAnchorPrice(
|
|
89
90
|
address vToken,
|
|
90
|
-
uint256
|
|
91
|
+
uint256 reportedPrice,
|
|
91
92
|
uint256 anchorPrice
|
|
92
93
|
) public view virtual override returns (bool) {
|
|
93
94
|
address asset = vToken == vBnb ? BNB_ADDR : VBep20Interface(vToken).underlying();
|
|
94
95
|
|
|
95
96
|
require(validateConfigs[asset].upperBoundRatio != 0, "validation config not exist");
|
|
96
97
|
require(anchorPrice != 0, "anchor price is not valid");
|
|
97
|
-
return _isWithinAnchor(asset,
|
|
98
|
+
return _isWithinAnchor(asset, reportedPrice, anchorPrice);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
* @notice Test whether the reported price is within the
|
|
102
|
-
* @param asset
|
|
103
|
-
* @param
|
|
104
|
-
* @param anchorPrice
|
|
102
|
+
* @notice Test whether the reported price is within the valid bounds
|
|
103
|
+
* @param asset Asset address
|
|
104
|
+
* @param reportedPrice The price to be tested
|
|
105
|
+
* @param anchorPrice The reported price must be within the the valid bounds of this price
|
|
105
106
|
*/
|
|
106
|
-
function _isWithinAnchor(address asset, uint256
|
|
107
|
-
if (
|
|
108
|
-
uint256 anchorRatio = (anchorPrice * 100e16) /
|
|
107
|
+
function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) internal view returns (bool) {
|
|
108
|
+
if (reportedPrice > 0) {
|
|
109
|
+
uint256 anchorRatio = (anchorPrice * 100e16) / reportedPrice;
|
|
109
110
|
uint256 upperBoundAnchorRatio = validateConfigs[asset].upperBoundRatio;
|
|
110
111
|
uint256 lowerBoundAnchorRatio = validateConfigs[asset].lowerBoundRatio;
|
|
111
112
|
return anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio;
|
|
@@ -115,5 +116,6 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
115
116
|
|
|
116
117
|
// BoundValidator is to get inherited, so it's a good practice to add some storage gaps like
|
|
117
118
|
// OpenZepplin proposed in their contracts: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
119
|
+
// solhint-disable-next-line
|
|
118
120
|
uint256[49] private __gap;
|
|
119
121
|
}
|