@venusprotocol/oracle 1.6.12-dev.2 → 1.6.12-dev.3
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/contracts/ResilientOracle.sol +84 -55
- package/contracts/interfaces/FeedRegistryInterface.sol +4 -4
- package/contracts/interfaces/OracleInterface.sol +3 -1
- package/contracts/oracles/BinanceOracle.sol +46 -55
- package/contracts/oracles/BoundValidator.sol +22 -51
- package/contracts/oracles/ChainlinkOracle.sol +19 -59
- package/contracts/oracles/PythOracle.sol +27 -47
- package/contracts/oracles/TwapOracle.sol +36 -54
- package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +6 -6
- package/contracts/test/MockSimpleOracle.sol +14 -2
- package/dist/deploy/1-deploy-oracles.js +6 -6
- package/dist/deploy/1-deploy-oracles.js.map +1 -1
- package/package.json +2 -2
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +0 -4
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +0 -181
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +0 -4
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +0 -282
- package/artifacts/build-info/fc01a49cbd804e304740a46d676189d0.json +0 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -342
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -462
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -445
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -663
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -144
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +0 -4
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +0 -364
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -328
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +0 -346
|
@@ -227,20 +227,33 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
227
227
|
* @param vToken vToken address
|
|
228
228
|
*/
|
|
229
229
|
function updatePrice(address vToken) external override {
|
|
230
|
-
|
|
230
|
+
address asset = _getUnderlyingAsset(vToken);
|
|
231
|
+
(address pivotOracle, bool pivotOracleEnabled) = getOracle(asset, OracleRole.PIVOT);
|
|
232
|
+
if (pivotOracle != address(0) && pivotOracleEnabled) {
|
|
233
|
+
//if pivot oracle is not TwapOracle it will revert so we need to catch the revert
|
|
234
|
+
try TwapInterface(pivotOracle).updateTwap(asset) {} catch {}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* @notice Updates the pivot oracle price. Currently using TWAP
|
|
240
|
+
* @dev This function should always be called before calling getUnderlyingPrice
|
|
241
|
+
* @param asset asset address
|
|
242
|
+
*/
|
|
243
|
+
function updateAssetPrice(address asset) external {
|
|
244
|
+
(address pivotOracle, bool pivotOracleEnabled) = getOracle(asset, OracleRole.PIVOT);
|
|
231
245
|
if (pivotOracle != address(0) && pivotOracleEnabled) {
|
|
232
246
|
//if pivot oracle is not TwapOracle it will revert so we need to catch the revert
|
|
233
|
-
try TwapInterface(pivotOracle).updateTwap(
|
|
247
|
+
try TwapInterface(pivotOracle).updateTwap(asset) {} catch {}
|
|
234
248
|
}
|
|
235
249
|
}
|
|
236
250
|
|
|
237
251
|
/**
|
|
238
252
|
* @dev Gets token config by vToken address
|
|
239
|
-
* @param
|
|
253
|
+
* @param asset asset address
|
|
240
254
|
* @return tokenConfig Config for the vToken
|
|
241
255
|
*/
|
|
242
|
-
function getTokenConfig(address
|
|
243
|
-
address asset = _getUnderlyingAsset(vToken);
|
|
256
|
+
function getTokenConfig(address asset) external view returns (TokenConfig memory) {
|
|
244
257
|
return tokenConfigs[asset];
|
|
245
258
|
}
|
|
246
259
|
|
|
@@ -259,41 +272,21 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
259
272
|
*/
|
|
260
273
|
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
261
274
|
if (paused()) revert("resilient oracle is paused");
|
|
262
|
-
uint256 pivotPrice = INVALID_PRICE;
|
|
263
|
-
|
|
264
|
-
// Get pivot oracle price, Invalid price if not available or error
|
|
265
|
-
(address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
|
|
266
|
-
if (pivotOracleEnabled && pivotOracle != address(0)) {
|
|
267
|
-
try OracleInterface(pivotOracle).getUnderlyingPrice(vToken) returns (uint256 pricePivot) {
|
|
268
|
-
pivotPrice = pricePivot;
|
|
269
|
-
} catch {}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// Compare main price and pivot price, return main price and if validation was successful
|
|
273
|
-
// note: In case pivot oracle is not available but main price is available and
|
|
274
|
-
// validation is successful, the main oracle price is returned.
|
|
275
|
-
(uint256 mainPrice, bool validatedPivotMain) = _getMainOraclePrice(
|
|
276
|
-
vToken,
|
|
277
|
-
pivotPrice,
|
|
278
|
-
pivotOracleEnabled && pivotOracle != address(0)
|
|
279
|
-
);
|
|
280
|
-
if (mainPrice != INVALID_PRICE && validatedPivotMain) return mainPrice;
|
|
281
275
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (fallbackPrice != INVALID_PRICE && validatedPivotFallback) return fallbackPrice;
|
|
286
|
-
|
|
287
|
-
// Lastly compare main price and fallback price
|
|
288
|
-
if (
|
|
289
|
-
mainPrice != INVALID_PRICE &&
|
|
290
|
-
fallbackPrice != INVALID_PRICE &&
|
|
291
|
-
boundValidator.validatePriceWithAnchorPrice(vToken, mainPrice, fallbackPrice)
|
|
292
|
-
) {
|
|
293
|
-
return mainPrice;
|
|
294
|
-
}
|
|
276
|
+
address asset = _getUnderlyingAsset(vToken);
|
|
277
|
+
return _getPrice(asset);
|
|
278
|
+
}
|
|
295
279
|
|
|
296
|
-
|
|
280
|
+
/**
|
|
281
|
+
* @notice Gets price of the asset
|
|
282
|
+
* @param asset asset address
|
|
283
|
+
* @return price USD price in scaled decimal places.
|
|
284
|
+
* @custom:error Paused error is thrown when resilent oracle is paused
|
|
285
|
+
* @custom:error Invalid resilient oracle price error is thrown if fetched prices from oracle is invalid
|
|
286
|
+
*/
|
|
287
|
+
function getPrice(address asset) external view override returns (uint256) {
|
|
288
|
+
if (paused()) revert("resilient oracle is paused");
|
|
289
|
+
return _getPrice(asset);
|
|
297
290
|
}
|
|
298
291
|
|
|
299
292
|
/**
|
|
@@ -321,27 +314,63 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
321
314
|
|
|
322
315
|
/**
|
|
323
316
|
* @notice Gets oracle and enabled status by vToken address
|
|
324
|
-
* @param
|
|
317
|
+
* @param asset asset address
|
|
325
318
|
* @param role Oracle role
|
|
326
319
|
* @return oracle Oracle address based on role
|
|
327
320
|
* @return enabled Enabled flag of the oracle based on token config
|
|
328
321
|
*/
|
|
329
|
-
function getOracle(address
|
|
330
|
-
address asset = _getUnderlyingAsset(vToken);
|
|
331
|
-
|
|
322
|
+
function getOracle(address asset, OracleRole role) public view returns (address oracle, bool enabled) {
|
|
332
323
|
oracle = tokenConfigs[asset].oracles[uint256(role)];
|
|
333
324
|
enabled = tokenConfigs[asset].enableFlagsForOracles[uint256(role)];
|
|
334
325
|
}
|
|
335
326
|
|
|
327
|
+
function _getPrice(address asset) internal view returns (uint256) {
|
|
328
|
+
uint256 pivotPrice = INVALID_PRICE;
|
|
329
|
+
|
|
330
|
+
// Get pivot oracle price, Invalid price if not available or error
|
|
331
|
+
(address pivotOracle, bool pivotOracleEnabled) = getOracle(asset, OracleRole.PIVOT);
|
|
332
|
+
if (pivotOracleEnabled && pivotOracle != address(0)) {
|
|
333
|
+
try OracleInterface(pivotOracle).getPrice(asset) returns (uint256 pricePivot) {
|
|
334
|
+
pivotPrice = pricePivot;
|
|
335
|
+
} catch {}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Compare main price and pivot price, return main price and if validation was successful
|
|
339
|
+
// note: In case pivot oracle is not available but main price is available and
|
|
340
|
+
// validation is successful, the main oracle price is returned.
|
|
341
|
+
(uint256 mainPrice, bool validatedPivotMain) = _getMainOraclePrice(
|
|
342
|
+
asset,
|
|
343
|
+
pivotPrice,
|
|
344
|
+
pivotOracleEnabled && pivotOracle != address(0)
|
|
345
|
+
);
|
|
346
|
+
if (mainPrice != INVALID_PRICE && validatedPivotMain) return mainPrice;
|
|
347
|
+
|
|
348
|
+
// Compare fallback and pivot if main oracle comparision fails with pivot
|
|
349
|
+
// Return fallback price when fallback price is validated successfully with pivot oracle
|
|
350
|
+
(uint256 fallbackPrice, bool validatedPivotFallback) = _getFallbackOraclePrice(asset, pivotPrice);
|
|
351
|
+
if (fallbackPrice != INVALID_PRICE && validatedPivotFallback) return fallbackPrice;
|
|
352
|
+
|
|
353
|
+
// Lastly compare main price and fallback price
|
|
354
|
+
if (
|
|
355
|
+
mainPrice != INVALID_PRICE &&
|
|
356
|
+
fallbackPrice != INVALID_PRICE &&
|
|
357
|
+
boundValidator.validatePriceWithAnchorPrice(asset, fallbackPrice, mainPrice)
|
|
358
|
+
) {
|
|
359
|
+
return mainPrice;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
revert("invalid resilient oracle price");
|
|
363
|
+
}
|
|
364
|
+
|
|
336
365
|
/**
|
|
337
|
-
* @notice Gets underlying asset price for the provided
|
|
366
|
+
* @notice Gets underlying asset price for the provided asset
|
|
338
367
|
* @dev This function won't revert when price is 0, because the fallback oracle may still be
|
|
339
368
|
* able to fetch a correct price
|
|
340
|
-
* @param
|
|
369
|
+
* @param asset asset address
|
|
341
370
|
* @param pivotPrice Pivot oracle price
|
|
342
371
|
* @param pivotEnabled If pivot oracle is not empty and enabled
|
|
343
372
|
* @return price USD price in scaled decimals
|
|
344
|
-
* e.g.
|
|
373
|
+
* e.g. asset decimals is 8 then price is returned as 10**18 * 10**(18-8) = 10**28 decimals
|
|
345
374
|
* @return pivotValidated Boolean representing if the validation of main oracle price
|
|
346
375
|
* and pivot oracle price were successful
|
|
347
376
|
* @custom:error Invalid price error is thrown if main oracle fails to fetch price of underlying asset
|
|
@@ -349,13 +378,13 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
349
378
|
* address is null
|
|
350
379
|
*/
|
|
351
380
|
function _getMainOraclePrice(
|
|
352
|
-
address
|
|
381
|
+
address asset,
|
|
353
382
|
uint256 pivotPrice,
|
|
354
383
|
bool pivotEnabled
|
|
355
|
-
)
|
|
356
|
-
(address mainOracle, bool mainOracleEnabled) = getOracle(
|
|
384
|
+
) internal view returns (uint256, bool) {
|
|
385
|
+
(address mainOracle, bool mainOracleEnabled) = getOracle(asset, OracleRole.MAIN);
|
|
357
386
|
if (mainOracleEnabled && mainOracle != address(0)) {
|
|
358
|
-
try OracleInterface(mainOracle).
|
|
387
|
+
try OracleInterface(mainOracle).getPrice(asset) returns (uint256 mainOraclePrice) {
|
|
359
388
|
if (!pivotEnabled) {
|
|
360
389
|
return (mainOraclePrice, true);
|
|
361
390
|
}
|
|
@@ -364,7 +393,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
364
393
|
}
|
|
365
394
|
return (
|
|
366
395
|
mainOraclePrice,
|
|
367
|
-
boundValidator.validatePriceWithAnchorPrice(
|
|
396
|
+
boundValidator.validatePriceWithAnchorPrice(asset, mainOraclePrice, pivotPrice)
|
|
368
397
|
);
|
|
369
398
|
} catch {
|
|
370
399
|
return (INVALID_PRICE, false);
|
|
@@ -376,7 +405,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
376
405
|
|
|
377
406
|
/**
|
|
378
407
|
* @dev This function won't revert when the price is 0 because getUnderlyingPrice checks if price is > 0
|
|
379
|
-
* @param
|
|
408
|
+
* @param asset asset address
|
|
380
409
|
* @return price USD price in 18 decimals
|
|
381
410
|
* @return pivotValidated Boolean representing if the validation of fallback oracle price
|
|
382
411
|
* and pivot oracle price were successfull
|
|
@@ -384,16 +413,16 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
384
413
|
* @custom:error Invalid price error is thrown if fallback oracle is not enabled or fallback oracle
|
|
385
414
|
* address is null
|
|
386
415
|
*/
|
|
387
|
-
function _getFallbackOraclePrice(address
|
|
388
|
-
(address fallbackOracle, bool fallbackEnabled) = getOracle(
|
|
416
|
+
function _getFallbackOraclePrice(address asset, uint256 pivotPrice) private view returns (uint256, bool) {
|
|
417
|
+
(address fallbackOracle, bool fallbackEnabled) = getOracle(asset, OracleRole.FALLBACK);
|
|
389
418
|
if (fallbackEnabled && fallbackOracle != address(0)) {
|
|
390
|
-
try OracleInterface(fallbackOracle).
|
|
419
|
+
try OracleInterface(fallbackOracle).getPrice(asset) returns (uint256 fallbackOraclePrice) {
|
|
391
420
|
if (pivotPrice == INVALID_PRICE) {
|
|
392
421
|
return (fallbackOraclePrice, false);
|
|
393
422
|
}
|
|
394
423
|
return (
|
|
395
424
|
fallbackOraclePrice,
|
|
396
|
-
boundValidator.validatePriceWithAnchorPrice(
|
|
425
|
+
boundValidator.validatePriceWithAnchorPrice(asset, fallbackOraclePrice, pivotPrice)
|
|
397
426
|
);
|
|
398
427
|
} catch {
|
|
399
428
|
return (INVALID_PRICE, false);
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
pragma solidity 0.8.13;
|
|
3
3
|
|
|
4
4
|
interface FeedRegistryInterface {
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function latestRoundData(
|
|
6
|
+
address base,
|
|
7
|
+
address quote
|
|
8
8
|
)
|
|
9
9
|
external
|
|
10
10
|
view
|
|
11
11
|
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
|
|
12
12
|
|
|
13
|
-
function
|
|
13
|
+
function decimals(address base, address quote) external view returns (uint8);
|
|
14
14
|
}
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
pragma solidity 0.8.13;
|
|
3
3
|
|
|
4
4
|
interface OracleInterface {
|
|
5
|
-
function
|
|
5
|
+
function getPrice(address asset) external view returns (uint256);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
interface ResilientOracleInterface is OracleInterface {
|
|
9
9
|
function updatePrice(address vToken) external;
|
|
10
|
+
|
|
11
|
+
function getUnderlyingPrice(address vToken) external view returns (uint256);
|
|
10
12
|
}
|
|
11
13
|
|
|
12
14
|
interface TwapInterface is OracleInterface {
|
|
@@ -8,6 +8,7 @@ import "../interfaces/FeedRegistryInterface.sol";
|
|
|
8
8
|
import "../interfaces/PublicResolverInterface.sol";
|
|
9
9
|
import "../interfaces/OracleInterface.sol";
|
|
10
10
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
11
|
+
import "../interfaces/OracleInterface.sol";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @title BinanceOracle
|
|
@@ -17,28 +18,23 @@ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlle
|
|
|
17
18
|
contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
18
19
|
address public sidRegistryAddress;
|
|
19
20
|
|
|
20
|
-
/// @notice
|
|
21
|
-
|
|
22
|
-
address public immutable vBnb;
|
|
21
|
+
/// @notice Set this as asset address for BNB. This is the underlying address for vBNB
|
|
22
|
+
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
23
23
|
|
|
24
|
-
/// @notice
|
|
25
|
-
|
|
26
|
-
address public immutable vai;
|
|
24
|
+
/// @notice Quote address for USD
|
|
25
|
+
address public constant USD_ADDR = 0x0000000000000000000000000000000000000348;
|
|
27
26
|
|
|
28
27
|
/// @notice Max stale period configuration for assets
|
|
29
28
|
mapping(string => uint256) public maxStalePeriod;
|
|
30
29
|
|
|
30
|
+
/// @notice Address of WBNB contract
|
|
31
|
+
address public WBNB;
|
|
32
|
+
|
|
31
33
|
event MaxStalePeriodAdded(string indexed asset, uint256 maxStalePeriod);
|
|
32
34
|
|
|
33
|
-
/// @notice Constructor for the implementation contract.
|
|
34
|
-
/// @param vBnbAddress The address of the vBNB
|
|
35
|
-
/// @param vaiAddress The address of the VAI
|
|
35
|
+
/// @notice Constructor for the implementation contract.
|
|
36
36
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
37
|
-
constructor(
|
|
38
|
-
if (vBnbAddress == address(0)) revert("vBNB can't be zero address");
|
|
39
|
-
if (vaiAddress == address(0)) revert("VAI can't be zero address");
|
|
40
|
-
vBnb = vBnbAddress;
|
|
41
|
-
vai = vaiAddress;
|
|
37
|
+
constructor() {
|
|
42
38
|
_disableInitializers();
|
|
43
39
|
}
|
|
44
40
|
|
|
@@ -60,73 +56,68 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
|
60
56
|
* @notice Sets the contracts required to fetch prices
|
|
61
57
|
* @param _sidRegistryAddress Address of SID registry
|
|
62
58
|
* @param _accessControlManager Address of the access control manager contract
|
|
59
|
+
* @param _WBNB Address of the access control manager contract
|
|
63
60
|
*/
|
|
64
|
-
function initialize(
|
|
61
|
+
function initialize(
|
|
62
|
+
address _sidRegistryAddress,
|
|
63
|
+
address _accessControlManager,
|
|
64
|
+
address _WBNB
|
|
65
|
+
) external reinitializer(2) {
|
|
65
66
|
sidRegistryAddress = _sidRegistryAddress;
|
|
67
|
+
WBNB = _WBNB;
|
|
66
68
|
__AccessControlled_init(_accessControlManager);
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
/**
|
|
70
|
-
* @notice
|
|
71
|
-
* @
|
|
72
|
+
* @notice Uses Space ID to fetch the feed registry address
|
|
73
|
+
* @return feedRegistryAddress Address of binance oracle feed registry.
|
|
74
|
+
*/
|
|
75
|
+
function getFeedRegistryAddress() public view returns (address) {
|
|
76
|
+
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
|
|
77
|
+
|
|
78
|
+
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
79
|
+
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
80
|
+
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
81
|
+
|
|
82
|
+
return publicResolver.addr(nodeHash);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @notice Gets the price of a asset from the binance oracle
|
|
87
|
+
* @param asset Address of the address
|
|
72
88
|
* @return Price in USD
|
|
73
89
|
*/
|
|
74
|
-
function
|
|
90
|
+
function getPrice(address asset) public view returns (uint256) {
|
|
75
91
|
string memory symbol;
|
|
76
92
|
uint256 decimals;
|
|
77
93
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
symbol = "BNB";
|
|
81
|
-
decimals = 18;
|
|
82
|
-
} else if (vToken == vai) {
|
|
83
|
-
symbol = "VAI";
|
|
94
|
+
if (asset == BNB_ADDR) {
|
|
95
|
+
symbol = "WBNB";
|
|
84
96
|
decimals = 18;
|
|
97
|
+
asset = WBNB;
|
|
85
98
|
} else {
|
|
86
|
-
IERC20Metadata
|
|
87
|
-
symbol =
|
|
88
|
-
decimals =
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (compare(symbol, "WBNB")) {
|
|
92
|
-
symbol = "BNB";
|
|
99
|
+
IERC20Metadata token = IERC20Metadata(asset);
|
|
100
|
+
symbol = token.symbol();
|
|
101
|
+
decimals = token.decimals();
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
104
|
+
return _getPrice(asset, symbol, decimals);
|
|
105
|
+
}
|
|
98
106
|
|
|
107
|
+
function _getPrice(address asset, string memory symbol, uint256 decimals) internal view returns (uint256) {
|
|
99
108
|
FeedRegistryInterface feedRegistry = FeedRegistryInterface(getFeedRegistryAddress());
|
|
100
109
|
|
|
101
|
-
(, int256 answer, , uint256 updatedAt, ) = feedRegistry.
|
|
110
|
+
(, int256 answer, , uint256 updatedAt, ) = feedRegistry.latestRoundData(asset, USD_ADDR);
|
|
102
111
|
if (answer <= 0) revert("invalid binance oracle price");
|
|
103
112
|
if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
|
|
104
113
|
|
|
105
|
-
uint256 deltaTime;
|
|
106
|
-
unchecked {
|
|
107
|
-
deltaTime = block.timestamp - updatedAt;
|
|
108
|
-
}
|
|
109
|
-
|
|
114
|
+
uint256 deltaTime = block.timestamp - updatedAt;
|
|
110
115
|
if (deltaTime > maxStalePeriod[symbol]) revert("binance oracle price expired");
|
|
111
116
|
|
|
112
|
-
uint256 decimalDelta = feedRegistry.
|
|
117
|
+
uint256 decimalDelta = feedRegistry.decimals(asset, USD_ADDR);
|
|
113
118
|
return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
|
|
114
119
|
}
|
|
115
120
|
|
|
116
|
-
/**
|
|
117
|
-
* @notice Uses Space ID to fetch the feed registry address
|
|
118
|
-
* @return feedRegistryAddress Address of binance oracle feed registry.
|
|
119
|
-
*/
|
|
120
|
-
function getFeedRegistryAddress() public view returns (address) {
|
|
121
|
-
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
|
|
122
|
-
|
|
123
|
-
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
124
|
-
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
125
|
-
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
126
|
-
|
|
127
|
-
return publicResolver.addr(nodeHash);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
121
|
/**
|
|
131
122
|
* @notice Used to compare if two strings are equal or not
|
|
132
123
|
* @param str1 The first string
|
|
@@ -27,29 +27,12 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
27
27
|
/// @notice validation configs by asset
|
|
28
28
|
mapping(address => ValidateConfig) public validateConfigs;
|
|
29
29
|
|
|
30
|
-
/// @notice vBNB address
|
|
31
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
32
|
-
address public immutable vBnb;
|
|
33
|
-
|
|
34
|
-
/// @notice VAI address
|
|
35
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
36
|
-
address public immutable vai;
|
|
37
|
-
|
|
38
|
-
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
39
|
-
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
40
|
-
|
|
41
30
|
/// @notice Emit this event when new validation configs are added
|
|
42
31
|
event ValidateConfigAdded(address indexed asset, uint256 indexed upperBound, uint256 indexed lowerBound);
|
|
43
32
|
|
|
44
33
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
45
|
-
/// @param vBnbAddress The address of the vBNB
|
|
46
|
-
/// @param vaiAddress The address of the VAI
|
|
47
34
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
48
|
-
constructor(
|
|
49
|
-
if (vBnbAddress == address(0)) revert("vBNB can't be zero address");
|
|
50
|
-
if (vaiAddress == address(0)) revert("VAI can't be zero address");
|
|
51
|
-
vBnb = vBnbAddress;
|
|
52
|
-
vai = vaiAddress;
|
|
35
|
+
constructor() {
|
|
53
36
|
_disableInitializers();
|
|
54
37
|
}
|
|
55
38
|
|
|
@@ -79,25 +62,6 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
79
62
|
__AccessControlled_init(accessControlManager_);
|
|
80
63
|
}
|
|
81
64
|
|
|
82
|
-
/**
|
|
83
|
-
* @notice Test reported asset price against anchor price
|
|
84
|
-
* @param vToken vToken address
|
|
85
|
-
* @param reportedPrice The price to be tested
|
|
86
|
-
* @custom:error Missing error thrown if asset config is not set
|
|
87
|
-
* @custom:error Price error thrown if anchor price is not valid
|
|
88
|
-
*/
|
|
89
|
-
function validatePriceWithAnchorPrice(
|
|
90
|
-
address vToken,
|
|
91
|
-
uint256 reportedPrice,
|
|
92
|
-
uint256 anchorPrice
|
|
93
|
-
) external view override returns (bool) {
|
|
94
|
-
address asset = _getUnderlyingAsset(vToken);
|
|
95
|
-
|
|
96
|
-
if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
|
|
97
|
-
if (anchorPrice == 0) revert("anchor price is not valid");
|
|
98
|
-
return _isWithinAnchor(asset, reportedPrice, anchorPrice);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
65
|
/**
|
|
102
66
|
* @notice Add a single validation config
|
|
103
67
|
* @param config Validation config struct
|
|
@@ -117,6 +81,23 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
117
81
|
emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
|
|
118
82
|
}
|
|
119
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @notice Test reported asset price against anchor price
|
|
86
|
+
* @param asset asset address
|
|
87
|
+
* @param reportedPrice The price to be tested
|
|
88
|
+
* @custom:error Missing error thrown if asset config is not set
|
|
89
|
+
* @custom:error Price error thrown if anchor price is not valid
|
|
90
|
+
*/
|
|
91
|
+
function validatePriceWithAnchorPrice(
|
|
92
|
+
address asset,
|
|
93
|
+
uint256 reportedPrice,
|
|
94
|
+
uint256 anchorPrice
|
|
95
|
+
) public view virtual override returns (bool) {
|
|
96
|
+
if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
|
|
97
|
+
if (anchorPrice == 0) revert("anchor price is not valid");
|
|
98
|
+
return _isWithinAnchor(asset, reportedPrice, anchorPrice);
|
|
99
|
+
}
|
|
100
|
+
|
|
120
101
|
/**
|
|
121
102
|
* @notice Test whether the reported price is within the valid bounds
|
|
122
103
|
* @param asset Asset address
|
|
@@ -134,18 +115,8 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
134
115
|
return false;
|
|
135
116
|
}
|
|
136
117
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*/
|
|
142
|
-
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
|
|
143
|
-
if (address(vToken) == vBnb) {
|
|
144
|
-
asset = BNB_ADDR;
|
|
145
|
-
} else if (address(vToken) == vai) {
|
|
146
|
-
asset = vai;
|
|
147
|
-
} else {
|
|
148
|
-
asset = VBep20Interface(vToken).underlying();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
118
|
+
// BoundValidator is to get inherited, so it's a good practice to add some storage gaps like
|
|
119
|
+
// OpenZepplin proposed in their contracts: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
120
|
+
// solhint-disable-next-line
|
|
121
|
+
uint256[49] private __gap;
|
|
151
122
|
}
|
|
@@ -23,14 +23,6 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
23
23
|
uint256 maxStalePeriod;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/// @notice vBNB address
|
|
27
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
28
|
-
address public immutable vBnb;
|
|
29
|
-
|
|
30
|
-
/// @notice VAI address
|
|
31
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
32
|
-
address public immutable vai;
|
|
33
|
-
|
|
34
26
|
/// @notice Set this as asset address for BNB. This is the underlying address for vBNB
|
|
35
27
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
36
28
|
|
|
@@ -52,35 +44,11 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
52
44
|
}
|
|
53
45
|
|
|
54
46
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
55
|
-
/// @param vBnbAddress The address of the vBNB
|
|
56
|
-
/// @param vaiAddress The address of the VAI
|
|
57
47
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
58
|
-
constructor(
|
|
59
|
-
vBnb = vBnbAddress;
|
|
60
|
-
vai = vaiAddress;
|
|
48
|
+
constructor() {
|
|
61
49
|
_disableInitializers();
|
|
62
50
|
}
|
|
63
51
|
|
|
64
|
-
/**
|
|
65
|
-
* @notice Set the forced prices of the underlying token of input vToken
|
|
66
|
-
* @param vToken vToken address
|
|
67
|
-
* @param underlyingPriceMantissa price in 18 decimals
|
|
68
|
-
* @custom:access Only Governance
|
|
69
|
-
* @custom:error NotNullAddress thrown if address of vToken is null
|
|
70
|
-
* @custom:event Emits PricePosted event on succesfully setup of underlying price
|
|
71
|
-
*/
|
|
72
|
-
function setUnderlyingPrice(
|
|
73
|
-
VBep20Interface vToken,
|
|
74
|
-
uint256 underlyingPriceMantissa
|
|
75
|
-
) external notNullAddress(address(vToken)) {
|
|
76
|
-
_checkAccessAllowed("setUnderlyingPrice(address,uint256)");
|
|
77
|
-
|
|
78
|
-
address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
|
|
79
|
-
uint256 previousPriceMantissa = prices[asset];
|
|
80
|
-
prices[asset] = underlyingPriceMantissa;
|
|
81
|
-
emit PricePosted(asset, previousPriceMantissa, prices[asset]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
52
|
/**
|
|
85
53
|
* @notice Manually set the price of a given asset
|
|
86
54
|
* @param asset Asset address
|
|
@@ -122,16 +90,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
122
90
|
}
|
|
123
91
|
|
|
124
92
|
/**
|
|
125
|
-
* @notice
|
|
126
|
-
* @param vToken vToken address
|
|
127
|
-
* @return price Underlying price in USD
|
|
128
|
-
*/
|
|
129
|
-
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
130
|
-
return _getUnderlyingPriceInternal(VBep20Interface(vToken));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @notice Add single token config. vToken & feed cannot be null addresses and maxStalePeriod must be positive
|
|
93
|
+
* @notice Add single token config. asset & feed cannot be null addresses and maxStalePeriod must be positive
|
|
135
94
|
* @param tokenConfig Token config struct
|
|
136
95
|
* @custom:access Only Governance
|
|
137
96
|
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
@@ -150,29 +109,30 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
150
109
|
}
|
|
151
110
|
|
|
152
111
|
/**
|
|
153
|
-
* @notice Gets the
|
|
154
|
-
*
|
|
155
|
-
* @
|
|
156
|
-
* has 18 decimals of precision
|
|
157
|
-
* @param vToken vToken address
|
|
158
|
-
* @return price Underlying price in USD
|
|
112
|
+
* @notice Gets the price of a asset from the chainlink oracle
|
|
113
|
+
* @param asset Address of the address
|
|
114
|
+
* @return Price in USD
|
|
159
115
|
*/
|
|
160
|
-
function
|
|
161
|
-
address token;
|
|
116
|
+
function getPrice(address asset) public view returns (uint256) {
|
|
162
117
|
uint256 decimals;
|
|
163
118
|
|
|
164
|
-
|
|
165
|
-
if (address(vToken) == vBnb) {
|
|
166
|
-
token = BNB_ADDR;
|
|
167
|
-
decimals = 18;
|
|
168
|
-
} else if (address(vToken) == vai) {
|
|
169
|
-
token = vai;
|
|
119
|
+
if (asset == BNB_ADDR) {
|
|
170
120
|
decimals = 18;
|
|
171
121
|
} else {
|
|
172
|
-
token =
|
|
173
|
-
decimals =
|
|
122
|
+
IERC20Metadata token = IERC20Metadata(asset);
|
|
123
|
+
decimals = token.decimals();
|
|
174
124
|
}
|
|
175
125
|
|
|
126
|
+
return _getPriceInternal(asset, decimals);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @notice Gets the Chainlink price for a given asset
|
|
131
|
+
* @param token address of the asset
|
|
132
|
+
* @param decimals decimals of the asset
|
|
133
|
+
* @return price Underlying price in USD
|
|
134
|
+
*/
|
|
135
|
+
function _getPriceInternal(address token, uint256 decimals) internal view returns (uint256 price) {
|
|
176
136
|
uint256 tokenPrice = prices[token];
|
|
177
137
|
if (tokenPrice != 0) {
|
|
178
138
|
price = tokenPrice;
|