@venusprotocol/oracle 1.6.11-dev.11 → 1.6.11-dev.12

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 (75) hide show
  1. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +1 -1
  2. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
  3. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +1 -1
  4. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +1 -1
  5. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
  6. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
  7. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
  8. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
  9. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
  10. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +1 -1
  11. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +1 -1
  12. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +1 -1
  13. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +1 -1
  14. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
  15. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
  16. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
  17. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
  18. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
  19. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
  20. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
  21. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
  22. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +1 -1
  23. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
  24. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
  25. package/artifacts/build-info/{2f9bd32d7afaff51cf1627ed4903b445.json → 48e79bdb82402d34b922e34b8aa88141.json} +1 -1
  26. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
  27. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +2 -2
  28. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
  29. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
  30. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
  31. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
  32. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
  33. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +1 -1
  34. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +1 -1
  35. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
  36. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
  37. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +1 -1
  38. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
  39. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
  40. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
  41. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
  42. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
  43. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +2 -2
  44. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
  45. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +2 -2
  46. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
  47. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +2 -2
  48. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
  49. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +2 -2
  50. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
  51. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +2 -2
  52. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
  53. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
  54. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
  55. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
  56. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
  57. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
  58. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
  59. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +1 -1
  60. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
  61. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
  62. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
  63. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
  64. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
  65. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
  66. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
  67. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
  68. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
  69. package/contracts/ResilientOracle.sol +37 -0
  70. package/contracts/oracles/BinanceOracle.sol +5 -0
  71. package/contracts/oracles/BoundValidator.sol +6 -2
  72. package/contracts/oracles/ChainlinkOracle.sol +5 -0
  73. package/contracts/oracles/PythOracle.sol +4 -2
  74. package/contracts/oracles/TwapOracle.sol +5 -0
  75. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../build-info/2f9bd32d7afaff51cf1627ed4903b445.json"
3
+ "buildInfo": "../../../build-info/48e79bdb82402d34b922e34b8aa88141.json"
4
4
  }
@@ -7,6 +7,43 @@ import "./interfaces/VBep20Interface.sol";
7
7
  import "./interfaces/OracleInterface.sol";
8
8
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
9
9
 
10
+ /**
11
+ * @title ResilientOracle
12
+ * @author Venus
13
+ * @notice Resillient oracle is the price oracle that the protocol interacts with for fetching price of assets.
14
+ *
15
+ * DeFi Protocols are usually vulnerable to price oracles reporting incorrect prices. There are various ways in which
16
+ * oracle prices can be manipulated depending on the type of price oracle used which can create a single point of
17
+ * failure and opens several ways for attacking the protocol.
18
+ *
19
+ * Keeping this in mind, we have designed a resilient oracle which uses multiple oracle sources to validate prices
20
+ * and fallback mechanisms to provide accurate prices and protect from oracle attacks. Currently it includes
21
+ * integrations with Chainlink, Pyth, Binance Oracle and TWAP (Time-Weighted Average Price) oracles. TWAP uses
22
+ * PancakeSwap as the on-chain price source.
23
+ *
24
+ * The way the Resilient Oracle works is for every market (vToken) we configure the main, pivot and fallback oracles.
25
+ * The main oracle oracle is the most trustworthy price source, the pivot oracle is is used as a loose sanity
26
+ * checker and the fallback oracle is used as a backup price source.
27
+ *
28
+ * To validate the price between two oracles we set an **upper** and **lower** bound ratio for every market. The
29
+ * **upper bound ratio** represents the **deviation** between **reported prices** (price from oracle that’s being
30
+ * validated) and anchor price (price from oracle we are validating against) beyond which the reported price will
31
+ * be invalidated. And the **lower bound ratio** presents the **deviation** between **reported price and anchor price**
32
+ * below which the reported price will be invalidated. So for oracle price to be considered valid the below statement
33
+ * should be true:
34
+
35
+ ```
36
+ anchorRatio = anchorPrice/reporterPrice
37
+ isValid = anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio
38
+ ```
39
+
40
+ * We usually use Chainlink as the main oracle, TWAP or Pyth oracle as pivot oracle depending on which supports the
41
+ * given market and Binance oracle is used as the fallback oracle. For some markets we may use Pyth or TWAP as the
42
+ * main oracle if the token price is not supported by Chainlink or Binance oracle.
43
+ *
44
+ * When fetching an oracle price, for the price to be valid it must be positive and not stagnant. If the price is
45
+ * invalid then we consider the oracle to be stagnant and treat it like it's disabled.
46
+ */
10
47
  contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOracleInterface {
11
48
  /**
12
49
  * @dev Oracle roles:
@@ -9,6 +9,11 @@ import "../interfaces/PublicResolverInterface.sol";
9
9
  import "../interfaces/OracleInterface.sol";
10
10
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
11
11
 
12
+ /**
13
+ * @title BinanceOracle
14
+ * @author Venus
15
+ * @notice This oracle fetches price of assets from Binance.
16
+ */
12
17
  contract BinanceOracle is AccessControlledV8, OracleInterface {
13
18
  address public sidRegistryAddress;
14
19
 
@@ -5,8 +5,12 @@ import "../interfaces/VBep20Interface.sol";
5
5
  import "../interfaces/OracleInterface.sol";
6
6
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
7
7
 
8
- // BoundValidator provides some common functions and can be used
9
- // to wrap up other contracts to form pivot oracles
8
+ /**
9
+ * @title BoundValidator
10
+ * @author Venus
11
+ * @notice This contracts is used to validate prices from two different sources. We need to set upper
12
+ * and lower bound ratios config for each vToken in this contract.
13
+ */
10
14
  contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
11
15
  struct ValidateConfig {
12
16
  /// @notice asset address
@@ -6,6 +6,11 @@ import "../interfaces/OracleInterface.sol";
6
6
  import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
7
7
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
8
8
 
9
+ /**
10
+ * @title ChainlinkOracle
11
+ * @author Venus
12
+ * @notice This oracle fetches price of assets from Chainlink.
13
+ */
9
14
  contract ChainlinkOracle is AccessControlledV8, OracleInterface {
10
15
  struct TokenConfig {
11
16
  /// @notice Underlying token address, which can't be a null address
@@ -9,8 +9,10 @@ import "../interfaces/VBep20Interface.sol";
9
9
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
10
10
 
11
11
  /**
12
- * PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores the
13
- * updated prices from external sources
12
+ * @title PythOracle
13
+ * @author Venus
14
+ * @notice PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores
15
+ * the updated prices from external sources
14
16
  */
15
17
  contract PythOracle is AccessControlledV8, OracleInterface {
16
18
  // To calculate 10 ** n(which is a signed type)
@@ -7,6 +7,11 @@ import "../interfaces/OracleInterface.sol";
7
7
  import "../interfaces/VBep20Interface.sol";
8
8
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
9
9
 
10
+ /**
11
+ * @title TwapOracle
12
+ * @author Venus
13
+ * @notice This oracle fetches price of assets from PancakeSwap.
14
+ */
10
15
  contract TwapOracle is AccessControlledV8, TwapInterface {
11
16
  using FixedPoint for *;
12
17
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@venusprotocol/oracle",
3
3
  "description": "Venus Protocol Price Oracle",
4
- "version": "1.6.11-dev.11",
4
+ "version": "1.6.11-dev.12",
5
5
  "author": "",
6
6
  "engines": {
7
7
  "node": ">=14.x.x"