@venusprotocol/oracle 1.6.11-dev.9 → 1.6.11
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/README.md +33 -10
- 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 +6 -1
- package/deployments/bscmainnet/BinanceOracle.json +45 -45
- package/deployments/bscmainnet/BinanceOracle_Implementation.json +34 -34
- package/deployments/bscmainnet/BinanceOracle_Proxy.json +43 -43
- package/deployments/bscmainnet/BoundValidator.json +46 -46
- package/deployments/bscmainnet/BoundValidator_Implementation.json +44 -52
- package/deployments/bscmainnet/BoundValidator_Proxy.json +43 -43
- package/deployments/bscmainnet/ChainlinkOracle.json +46 -52
- package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +45 -51
- package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +43 -43
- package/deployments/bscmainnet/DefaultProxyAdmin.json +15 -15
- package/deployments/bscmainnet/PythOracle.json +61 -54
- package/deployments/bscmainnet/PythOracle_Implementation.json +54 -48
- package/deployments/bscmainnet/PythOracle_Proxy.json +52 -51
- package/deployments/bscmainnet/ResilientOracle.json +47 -52
- package/deployments/bscmainnet/ResilientOracle_Implementation.json +62 -65
- package/deployments/bscmainnet/ResilientOracle_Proxy.json +45 -45
- package/deployments/bscmainnet/TwapOracle.json +67 -67
- package/deployments/bscmainnet/TwapOracle_Implementation.json +83 -83
- package/deployments/bscmainnet/TwapOracle_Proxy.json +44 -44
- package/deployments/bscmainnet/solcInputs/{3c9df0f4b407c3d8079629dd6ddb913e.json → aae9f1601b873a5a4704ede73ede10cb.json} +9 -54
- package/deployments/bsctestnet/BinanceOracle.json +35 -35
- package/deployments/bsctestnet/BinanceOracle_Implementation.json +31 -31
- package/deployments/bsctestnet/BinanceOracle_Proxy.json +33 -33
- package/deployments/bsctestnet/BoundValidator.json +36 -36
- package/deployments/bsctestnet/BoundValidator_Implementation.json +44 -52
- package/deployments/bsctestnet/BoundValidator_Proxy.json +33 -33
- package/deployments/bsctestnet/ChainlinkOracle.json +36 -42
- package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +42 -48
- package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +33 -33
- package/deployments/bsctestnet/DefaultProxyAdmin.json +11 -11
- package/deployments/bsctestnet/PythOracle.json +48 -41
- package/deployments/bsctestnet/PythOracle_Implementation.json +51 -45
- package/deployments/bsctestnet/PythOracle_Proxy.json +39 -38
- package/deployments/bsctestnet/ResilientOracle.json +36 -41
- package/deployments/bsctestnet/ResilientOracle_Implementation.json +63 -66
- package/deployments/bsctestnet/ResilientOracle_Proxy.json +34 -34
- package/deployments/bsctestnet/TwapOracle.json +56 -56
- package/deployments/bsctestnet/TwapOracle_Implementation.json +81 -81
- package/deployments/bsctestnet/TwapOracle_Proxy.json +33 -33
- package/deployments/bsctestnet/solcInputs/{f35da22a430a956ee338e720b5898e3d.json → 131f58942628e21632de19506977a910.json} +7 -13
- package/deployments/bsctestnet/solcInputs/{4769dd98af512bf3b6b6504ad0c3bd74.json → 144b49e8aec3add79553ba273ea32d00.json} +4 -10
- package/deployments/bsctestnet/solcInputs/503f2e4e766f3be923fadf8030a5470f.json +78 -0
- package/deployments/bsctestnet/solcInputs/b39d33092f7dd383ae3a042566194132.json +75 -0
- package/package.json +1 -1
- 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/0137d0ff3ae413641739f9f6322cc2b3.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
package/README.md
CHANGED
|
@@ -1,14 +1,37 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Resilient Price Feeds
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Resilient Price Feeds is a set of smart contracts that uses multiple oracles and a price validation algorithm to fetch asset prices for the [Venus Protocol](https://app.venus.io).
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
DeFi protocols are vulnerable to incorrectly reported prices which can lead to lost money. A price oracle can be manipulated,fail, or suffer other attacks depending on the type of price oracle. It creates a single point of failure, opening attack vectors to the protocol if not mitigated.
|
|
6
|
+
|
|
7
|
+
The Resilient Price Feeds uses multiple oracle sources and fallback mechanisms to return accurate prices and protect from oracle failures. Currently, it includes integrations with Chainlink, Pyth, Binance Oracle and TWAP (Time-Weighted Average Price) oracles. TWAP uses PancakeSwap as the on-chain price source.
|
|
8
|
+
|
|
9
|
+
## Details
|
|
10
|
+
|
|
11
|
+
The Resilient Price Feeds configures a main, pivot and fallback oracle for every asset. The main oracle is the most trustworthy price source, the pivot oracle is used as a loose sanity checker and the fallback oracle is used as a backup price source.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
Oracle prices are validated using an **upper** and **lower** bound ratio, which is set for every market. The **upper bound ratio** represents the **deviation** between the **reported price** (price from oracle that’s being validated) and anchor price (price from oracle we are validating against) beyond which the reported price will be invalidated. The **lower bound ratio** presents the **deviation** between **reported price and anchor price** below which the reported price will be invalidated. For an oracle price to be considered valid the below statement should be true:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
anchorRatio = anchorPrice/reporterPrice
|
|
19
|
+
isValid = anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The default configuration uses Chainlink as the main oracle, TWAP or Pyth oracle as pivot oracle depending on which supports the given market and Binance oracle as the fallback oracle. For some markets we may use Pyth as the main oracle if the token price is not supported by Chainlink or Binance oracles.
|
|
23
|
+
|
|
24
|
+
When fetching an oracle price, for the price to be valid it must be positive and not stagnant. If the price is invalid or stagnant it is ignored and a fallback oracle is used.
|
|
25
|
+
|
|
26
|
+
# Development
|
|
27
|
+
|
|
28
|
+
## Prerequisites
|
|
6
29
|
|
|
7
30
|
- NodeJS - 14.x
|
|
8
31
|
|
|
9
32
|
- Solc - v0.8.13 (https://github.com/ethereum/solidity/releases/tag/v0.8.13)
|
|
10
33
|
|
|
11
|
-
|
|
34
|
+
## Installing
|
|
12
35
|
|
|
13
36
|
```
|
|
14
37
|
|
|
@@ -16,7 +39,7 @@ yarn install
|
|
|
16
39
|
|
|
17
40
|
```
|
|
18
41
|
|
|
19
|
-
|
|
42
|
+
## Linting and code formatting
|
|
20
43
|
|
|
21
44
|
Linting is done using eslint for typescript and solhint for solidity. Prettier is used to format solidity and typescript files.
|
|
22
45
|
|
|
@@ -39,7 +62,7 @@ To pretty all files run:
|
|
|
39
62
|
$ yarn prettier
|
|
40
63
|
```
|
|
41
64
|
|
|
42
|
-
|
|
65
|
+
## Run Tests
|
|
43
66
|
|
|
44
67
|
```
|
|
45
68
|
|
|
@@ -53,7 +76,7 @@ npx hardhat test
|
|
|
53
76
|
|
|
54
77
|
Releases are automatically managed using semantic-release and commit messages.
|
|
55
78
|
|
|
56
|
-
|
|
79
|
+
## Deployment
|
|
57
80
|
|
|
58
81
|
```
|
|
59
82
|
|
|
@@ -68,13 +91,13 @@ npx hardhat deploy
|
|
|
68
91
|
- In the deployment scripts you have added `tags` for example: - `func.tags = ["MockTokens"];`
|
|
69
92
|
- Once this is done, adding `--tags "<tag_name>,<tag_name>..."` to the deployment command will execute only the scripts containing the tags.
|
|
70
93
|
|
|
71
|
-
|
|
94
|
+
## Verify Contracts
|
|
72
95
|
|
|
73
96
|
```
|
|
74
97
|
npx hardhat etherscan-verify --network <network-name>
|
|
75
98
|
```
|
|
76
99
|
|
|
77
|
-
|
|
100
|
+
## Hardhat Commands
|
|
78
101
|
|
|
79
102
|
```
|
|
80
103
|
|
|
@@ -110,7 +133,7 @@ npx solhint 'contracts/**/*.sol' --fix
|
|
|
110
133
|
|
|
111
134
|
```
|
|
112
135
|
|
|
113
|
-
|
|
136
|
+
## Documentation
|
|
114
137
|
|
|
115
138
|
Documentation is autogenerated using [solidity-docgen](https://github.com/OpenZeppelin/solidity-docgen).
|
|
116
139
|
|
|
@@ -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
|
|
|
@@ -18,7 +23,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
18
23
|
struct TokenConfig {
|
|
19
24
|
/// @notice Asset address, which can't be zero address and can be used for existance check
|
|
20
25
|
address asset;
|
|
21
|
-
/// @notice Decimals of underlying asset
|
|
26
|
+
/// @notice Decimals of underlying asset represented as 1e{decimals}
|
|
22
27
|
uint256 baseUnit;
|
|
23
28
|
/// @notice The address of Pancake pair
|
|
24
29
|
address pancakePool;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"address": "
|
|
2
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
3
3
|
"abi": [
|
|
4
4
|
{
|
|
5
5
|
"anonymous": false,
|
|
@@ -257,7 +257,7 @@
|
|
|
257
257
|
{
|
|
258
258
|
"inputs": [
|
|
259
259
|
{
|
|
260
|
-
"internalType": "
|
|
260
|
+
"internalType": "address",
|
|
261
261
|
"name": "vToken",
|
|
262
262
|
"type": "address"
|
|
263
263
|
}
|
|
@@ -448,83 +448,83 @@
|
|
|
448
448
|
"type": "constructor"
|
|
449
449
|
}
|
|
450
450
|
],
|
|
451
|
-
"transactionHash": "
|
|
451
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
452
452
|
"receipt": {
|
|
453
453
|
"to": null,
|
|
454
454
|
"from": "0xa05f990d647287e4E84715b813BC000aEA970467",
|
|
455
|
-
"contractAddress": "
|
|
456
|
-
"transactionIndex":
|
|
455
|
+
"contractAddress": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
456
|
+
"transactionIndex": 109,
|
|
457
457
|
"gasUsed": "718007",
|
|
458
|
-
"logsBloom": "
|
|
459
|
-
"blockHash": "
|
|
460
|
-
"transactionHash": "
|
|
458
|
+
"logsBloom": "0x00000000000000000000000000100000400000000000020000800000000000000000000000000000000000000200000000000000000000000000000000008000000000000000000000008000000002000001000000000100000000000000000000000000020000000000000000000800000000800000002000000000000000400000000000000000000000000000000000000000000080000000000000800000000000000000000000000000000400000000000000808000000000000000000000000020000000000000000000040000000000000402000000000000000020000000000000000000000000000000000000000800400000000000000000000000",
|
|
459
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b",
|
|
460
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
461
461
|
"logs": [
|
|
462
462
|
{
|
|
463
|
-
"transactionIndex":
|
|
464
|
-
"blockNumber":
|
|
465
|
-
"transactionHash": "
|
|
466
|
-
"address": "
|
|
463
|
+
"transactionIndex": 109,
|
|
464
|
+
"blockNumber": 28525842,
|
|
465
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
466
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
467
467
|
"topics": [
|
|
468
468
|
"0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b",
|
|
469
|
-
"
|
|
469
|
+
"0x00000000000000000000000073760d55bf10cf9d265a126d349bdd5f64326c0e"
|
|
470
470
|
],
|
|
471
471
|
"data": "0x",
|
|
472
|
-
"logIndex":
|
|
473
|
-
"blockHash": "
|
|
472
|
+
"logIndex": 279,
|
|
473
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
474
474
|
},
|
|
475
475
|
{
|
|
476
|
-
"transactionIndex":
|
|
477
|
-
"blockNumber":
|
|
478
|
-
"transactionHash": "
|
|
479
|
-
"address": "
|
|
476
|
+
"transactionIndex": 109,
|
|
477
|
+
"blockNumber": 28525842,
|
|
478
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
479
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
480
480
|
"topics": [
|
|
481
481
|
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
|
|
482
482
|
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
483
483
|
"0x000000000000000000000000a05f990d647287e4e84715b813bc000aea970467"
|
|
484
484
|
],
|
|
485
485
|
"data": "0x",
|
|
486
|
-
"logIndex":
|
|
487
|
-
"blockHash": "
|
|
486
|
+
"logIndex": 280,
|
|
487
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
488
488
|
},
|
|
489
489
|
{
|
|
490
|
-
"transactionIndex":
|
|
491
|
-
"blockNumber":
|
|
492
|
-
"transactionHash": "
|
|
493
|
-
"address": "
|
|
490
|
+
"transactionIndex": 109,
|
|
491
|
+
"blockNumber": 28525842,
|
|
492
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
493
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
494
494
|
"topics": ["0x66fd58e82f7b31a2a5c30e0888f3093efe4e111b00cd2b0c31fe014601293aa0"],
|
|
495
495
|
"data": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000004788629abc6cfca10f9f969efdeaa1cf70c23555",
|
|
496
|
-
"logIndex":
|
|
497
|
-
"blockHash": "
|
|
496
|
+
"logIndex": 281,
|
|
497
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
498
498
|
},
|
|
499
499
|
{
|
|
500
|
-
"transactionIndex":
|
|
501
|
-
"blockNumber":
|
|
502
|
-
"transactionHash": "
|
|
503
|
-
"address": "
|
|
500
|
+
"transactionIndex": 109,
|
|
501
|
+
"blockNumber": 28525842,
|
|
502
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
503
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
504
504
|
"topics": ["0x7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498"],
|
|
505
505
|
"data": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
506
|
-
"logIndex":
|
|
507
|
-
"blockHash": "
|
|
506
|
+
"logIndex": 282,
|
|
507
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
508
508
|
},
|
|
509
509
|
{
|
|
510
|
-
"transactionIndex":
|
|
511
|
-
"blockNumber":
|
|
512
|
-
"transactionHash": "
|
|
513
|
-
"address": "
|
|
510
|
+
"transactionIndex": 109,
|
|
511
|
+
"blockNumber": 28525842,
|
|
512
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
513
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
514
514
|
"topics": ["0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f"],
|
|
515
|
-
"data": "
|
|
516
|
-
"logIndex":
|
|
517
|
-
"blockHash": "
|
|
515
|
+
"data": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000001bb765b741a5f3c2a338369dab539385534e3343",
|
|
516
|
+
"logIndex": 283,
|
|
517
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
518
518
|
}
|
|
519
519
|
],
|
|
520
|
-
"blockNumber":
|
|
521
|
-
"cumulativeGasUsed": "
|
|
520
|
+
"blockNumber": 28525842,
|
|
521
|
+
"cumulativeGasUsed": "11886540",
|
|
522
522
|
"status": 1,
|
|
523
523
|
"byzantium": true
|
|
524
524
|
},
|
|
525
525
|
"args": [
|
|
526
|
-
"
|
|
527
|
-
"
|
|
526
|
+
"0x73760D55bF10cf9D265A126D349bdd5f64326c0e",
|
|
527
|
+
"0x1BB765b741A5f3C2A338369DAb539385534E3343",
|
|
528
528
|
"0x485cc95500000000000000000000000008ced32a7f3eec915ba84415e9c07a72869779560000000000000000000000004788629abc6cfca10f9f969efdeaa1cf70c23555"
|
|
529
529
|
],
|
|
530
530
|
"numDeployments": 1,
|
|
@@ -536,7 +536,7 @@
|
|
|
536
536
|
"methodName": "initialize",
|
|
537
537
|
"args": ["0x08CEd32a7f3eeC915Ba84415e9C07a7286977956", "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555"]
|
|
538
538
|
},
|
|
539
|
-
"implementation": "
|
|
539
|
+
"implementation": "0x73760D55bF10cf9D265A126D349bdd5f64326c0e",
|
|
540
540
|
"devdoc": {
|
|
541
541
|
"details": "This contract implements a proxy that is upgradeable by an admin. To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector clashing], which can potentially be used in an attack, this contract uses the https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two things that go hand in hand: 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if that call matches one of the admin functions exposed by the proxy itself. 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the implementation. If the admin tries to call a function on the implementation it will fail with an error that says \"admin cannot fallback to proxy target\". These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due to sudden errors when trying to call a function from the proxy implementation. Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.",
|
|
542
542
|
"kind": "dev",
|