@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.
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
- package/artifacts/build-info/{2f9bd32d7afaff51cf1627ed4903b445.json → 48e79bdb82402d34b922e34b8aa88141.json} +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +2 -2
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +2 -2
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +2 -2
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +2 -2
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +2 -2
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +1 -1
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
- package/contracts/ResilientOracle.sol +37 -0
- package/contracts/oracles/BinanceOracle.sol +5 -0
- package/contracts/oracles/BoundValidator.sol +6 -2
- package/contracts/oracles/ChainlinkOracle.sol +5 -0
- package/contracts/oracles/PythOracle.sol +4 -2
- package/contracts/oracles/TwapOracle.sol +5 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
9
|
-
|
|
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
|
|
13
|
-
*
|
|
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
|
|