@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.
Files changed (132) hide show
  1. package/contracts/ResilientOracle.sol +84 -55
  2. package/contracts/interfaces/FeedRegistryInterface.sol +4 -4
  3. package/contracts/interfaces/OracleInterface.sol +3 -1
  4. package/contracts/oracles/BinanceOracle.sol +46 -55
  5. package/contracts/oracles/BoundValidator.sol +22 -51
  6. package/contracts/oracles/ChainlinkOracle.sol +19 -59
  7. package/contracts/oracles/PythOracle.sol +27 -47
  8. package/contracts/oracles/TwapOracle.sol +36 -54
  9. package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +6 -6
  10. package/contracts/test/MockSimpleOracle.sol +14 -2
  11. package/dist/deploy/1-deploy-oracles.js +6 -6
  12. package/dist/deploy/1-deploy-oracles.js.map +1 -1
  13. package/package.json +2 -2
  14. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
  15. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
  16. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
  17. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
  18. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
  19. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
  20. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
  21. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
  22. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
  23. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
  24. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
  25. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
  26. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
  27. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
  28. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
  29. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
  30. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
  31. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
  32. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
  33. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
  34. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
  35. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
  36. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
  37. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
  38. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
  39. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
  40. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
  41. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
  42. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
  43. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
  44. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
  45. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
  46. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
  47. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
  48. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
  49. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
  50. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
  51. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
  52. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
  53. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
  54. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
  55. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
  56. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
  57. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
  58. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +0 -4
  59. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +0 -181
  60. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +0 -4
  61. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +0 -282
  62. package/artifacts/build-info/fc01a49cbd804e304740a46d676189d0.json +0 -1
  63. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
  64. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
  65. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
  66. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
  67. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
  68. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
  69. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
  70. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
  71. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
  72. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
  73. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
  74. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
  75. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
  76. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
  77. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
  78. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
  79. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
  80. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
  81. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
  82. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
  83. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
  84. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
  85. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
  86. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
  87. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
  88. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
  89. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
  90. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
  91. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
  92. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
  93. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
  94. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -342
  95. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
  96. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
  97. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
  98. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -462
  99. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
  100. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -445
  101. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
  102. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -663
  103. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
  104. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
  105. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
  106. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -144
  107. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
  108. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
  109. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
  110. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
  111. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
  112. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
  113. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +0 -4
  114. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +0 -364
  115. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
  116. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -328
  117. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
  118. package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
  119. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
  120. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
  121. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
  122. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
  123. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
  124. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
  125. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
  126. package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
  127. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
  128. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
  129. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
  130. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
  131. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
  132. 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
- (address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
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(vToken) {} catch {}
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 vToken vToken address
253
+ * @param asset asset address
240
254
  * @return tokenConfig Config for the vToken
241
255
  */
242
- function getTokenConfig(address vToken) external view returns (TokenConfig memory) {
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
- // Compare fallback and pivot if main oracle comparision fails with pivot
283
- // Return fallback price when fallback price is validated successfully with pivot oracle
284
- (uint256 fallbackPrice, bool validatedPivotFallback) = _getFallbackOraclePrice(vToken, pivotPrice);
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
- revert("invalid resilient oracle price");
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 vToken vToken address
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 vToken, OracleRole role) public view returns (address oracle, bool enabled) {
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 vToken
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 vToken vToken address
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. vToken decimals is 8 then price is returned as 10**18 * 10**(18-8) = 10**28 decimals
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 vToken,
381
+ address asset,
353
382
  uint256 pivotPrice,
354
383
  bool pivotEnabled
355
- ) private view returns (uint256, bool) {
356
- (address mainOracle, bool mainOracleEnabled) = getOracle(vToken, OracleRole.MAIN);
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).getUnderlyingPrice(vToken) returns (uint256 mainOraclePrice) {
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(vToken, mainOraclePrice, pivotPrice)
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 vToken vToken address
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 vToken, uint256 pivotPrice) private view returns (uint256, bool) {
388
- (address fallbackOracle, bool fallbackEnabled) = getOracle(vToken, OracleRole.FALLBACK);
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).getUnderlyingPrice(vToken) returns (uint256 fallbackOraclePrice) {
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(vToken, fallbackOraclePrice, pivotPrice)
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 latestRoundDataByName(
6
- string memory base,
7
- string memory quote
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 decimalsByName(string memory base, string memory quote) external view returns (uint8);
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 getUnderlyingPrice(address vToken) external view returns (uint256);
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 vBNB address
21
- /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
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 VAI address
25
- /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
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. Sets immutable variables.
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(address vBnbAddress, address vaiAddress) {
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(address _sidRegistryAddress, address _accessControlManager) external initializer {
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 Gets the price of a vToken from the binance oracle
71
- * @param vToken Address of the vToken
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 getUnderlyingPrice(address vToken) external view override returns (uint256) {
90
+ function getPrice(address asset) public view returns (uint256) {
75
91
  string memory symbol;
76
92
  uint256 decimals;
77
93
 
78
- // VBNB token doesn't have `underlying` method
79
- if (vToken == vBnb) {
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 underlyingToken = IERC20Metadata(VBep20Interface(vToken).underlying());
87
- symbol = underlyingToken.symbol();
88
- decimals = underlyingToken.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
- if (compare(symbol, "wBETH")) {
96
- symbol = "WBETH";
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.latestRoundDataByName(symbol, "USD");
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.decimalsByName(symbol, "USD");
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(address vBnbAddress, address vaiAddress) {
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
- * @dev This function returns the underlying asset of a vToken
139
- * @param vToken vToken address
140
- * @return asset underlying asset address
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(address vBnbAddress, address vaiAddress) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) {
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 Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
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 Chainlink price for the underlying asset of a given vToken
154
- * or the manually set price if it's been set
155
- * @dev The decimals of the underlying token are considered to ensure the returned price
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 _getUnderlyingPriceInternal(VBep20Interface vToken) private view returns (uint256 price) {
161
- address token;
116
+ function getPrice(address asset) public view returns (uint256) {
162
117
  uint256 decimals;
163
118
 
164
- // vBNB token doesn't have `underlying` method
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 = vToken.underlying();
173
- decimals = VBep20Interface(token).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;