@venusprotocol/oracle 1.6.11 → 1.6.12-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,26 +10,25 @@ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlle
|
|
|
10
10
|
/**
|
|
11
11
|
* @title ResilientOracle
|
|
12
12
|
* @author Venus
|
|
13
|
-
* @notice
|
|
13
|
+
* @notice The Resilient Oracle is the main contract that the protocol uses to fetch prices of assets.
|
|
14
14
|
*
|
|
15
|
-
* DeFi
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* DeFi protocols are vulnerable to price oracle failures including oracle manipulation and incorrectly
|
|
16
|
+
* reported prices. If only one oracle is used, this creates a single point of failure and opens a vector
|
|
17
|
+
* for attacking the protocol.
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* PancakeSwap as the on-chain price source.
|
|
19
|
+
* The Resilient Oracle uses multiple sources and fallback mechanisms to provide accurate prices and protect
|
|
20
|
+
* the protocol from oracle attacks. Currently it includes integrations with Chainlink, Pyth, Binance Oracle
|
|
21
|
+
* and TWAP (Time-Weighted Average Price) oracles. TWAP uses PancakeSwap as the on-chain price source.
|
|
23
22
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
23
|
+
* For every market (vToken) we configure the main, pivot and fallback oracles. The main oracle oracle is the
|
|
24
|
+
* most trustworthy price source, the pivot oracle is used as a loose sanity checker and the fallback oracle
|
|
25
|
+
* is used as a backup price source.
|
|
27
26
|
*
|
|
28
|
-
* To validate
|
|
29
|
-
*
|
|
30
|
-
* validated) and anchor price (price
|
|
31
|
-
* be invalidated.
|
|
32
|
-
*
|
|
27
|
+
* To validate prices returned from two oracles, we use an upper and lower bound ratio that is set for every
|
|
28
|
+
* market. The upper bound ratio represents the deviation between reported price (the price that’s being
|
|
29
|
+
* validated) and the anchor price (the price we are validating against) above which the reported price will
|
|
30
|
+
* be invalidated. The lower bound ratio presents the deviation between reported price and anchor price below
|
|
31
|
+
* which the reported price will be invalidated. So for oracle price to be considered valid the below statement
|
|
33
32
|
* should be true:
|
|
34
33
|
|
|
35
34
|
```
|
|
@@ -37,12 +36,12 @@ anchorRatio = anchorPrice/reporterPrice
|
|
|
37
36
|
isValid = anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio
|
|
38
37
|
```
|
|
39
38
|
|
|
40
|
-
*
|
|
41
|
-
* given market and Binance oracle is used as the fallback oracle. For some markets we may
|
|
42
|
-
* main oracle if the token price is not supported by Chainlink or Binance
|
|
39
|
+
* In most cases, Chainlink is used as the main oracle, TWAP or Pyth oracles are used as the pivot oracle depending
|
|
40
|
+
* on which supports the given market and Binance oracle is used as the fallback oracle. For some markets we may
|
|
41
|
+
* use Pyth or TWAP as the main oracle if the token price is not supported by Chainlink or Binance oracles.
|
|
43
42
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
43
|
+
* For a fetched price to be valid it must be positive and not stagnant. If the price is invalid then we consider the
|
|
44
|
+
* oracle to be stagnant and treat it like it's disabled.
|
|
46
45
|
*/
|
|
47
46
|
contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOracleInterface {
|
|
48
47
|
/**
|
|
@@ -8,8 +8,9 @@ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlle
|
|
|
8
8
|
/**
|
|
9
9
|
* @title BoundValidator
|
|
10
10
|
* @author Venus
|
|
11
|
-
* @notice
|
|
12
|
-
* and lower bound
|
|
11
|
+
* @notice The BoundValidator contract is used to validate prices fetched from two different sources.
|
|
12
|
+
* Each asset has an upper and lower bound ratio set in the config. In order for a price to be valid
|
|
13
|
+
* it must fall within this range of the validator price.
|
|
13
14
|
*/
|
|
14
15
|
contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
15
16
|
struct ValidateConfig {
|
|
@@ -9,7 +9,7 @@ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlle
|
|
|
9
9
|
/**
|
|
10
10
|
* @title ChainlinkOracle
|
|
11
11
|
* @author Venus
|
|
12
|
-
* @notice This oracle fetches
|
|
12
|
+
* @notice This oracle fetches prices of assets from the Chainlink oracle.
|
|
13
13
|
*/
|
|
14
14
|
contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
15
15
|
struct TokenConfig {
|