@venusprotocol/oracle 1.6.11-dev.9 → 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.
Files changed (170) hide show
  1. package/README.md +33 -10
  2. package/contracts/ResilientOracle.sol +36 -0
  3. package/contracts/oracles/BinanceOracle.sol +5 -0
  4. package/contracts/oracles/BoundValidator.sol +7 -2
  5. package/contracts/oracles/ChainlinkOracle.sol +5 -0
  6. package/contracts/oracles/PythOracle.sol +4 -2
  7. package/contracts/oracles/TwapOracle.sol +6 -1
  8. package/deployments/bscmainnet/BinanceOracle.json +45 -45
  9. package/deployments/bscmainnet/BinanceOracle_Implementation.json +34 -34
  10. package/deployments/bscmainnet/BinanceOracle_Proxy.json +43 -43
  11. package/deployments/bscmainnet/BoundValidator.json +46 -46
  12. package/deployments/bscmainnet/BoundValidator_Implementation.json +44 -52
  13. package/deployments/bscmainnet/BoundValidator_Proxy.json +43 -43
  14. package/deployments/bscmainnet/ChainlinkOracle.json +46 -52
  15. package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +45 -51
  16. package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +43 -43
  17. package/deployments/bscmainnet/DefaultProxyAdmin.json +15 -15
  18. package/deployments/bscmainnet/PythOracle.json +61 -54
  19. package/deployments/bscmainnet/PythOracle_Implementation.json +54 -48
  20. package/deployments/bscmainnet/PythOracle_Proxy.json +52 -51
  21. package/deployments/bscmainnet/ResilientOracle.json +47 -52
  22. package/deployments/bscmainnet/ResilientOracle_Implementation.json +62 -65
  23. package/deployments/bscmainnet/ResilientOracle_Proxy.json +45 -45
  24. package/deployments/bscmainnet/TwapOracle.json +67 -67
  25. package/deployments/bscmainnet/TwapOracle_Implementation.json +83 -83
  26. package/deployments/bscmainnet/TwapOracle_Proxy.json +44 -44
  27. package/deployments/bscmainnet/solcInputs/{3c9df0f4b407c3d8079629dd6ddb913e.json → aae9f1601b873a5a4704ede73ede10cb.json} +9 -54
  28. package/deployments/bsctestnet/BinanceOracle.json +35 -35
  29. package/deployments/bsctestnet/BinanceOracle_Implementation.json +31 -31
  30. package/deployments/bsctestnet/BinanceOracle_Proxy.json +33 -33
  31. package/deployments/bsctestnet/BoundValidator.json +36 -36
  32. package/deployments/bsctestnet/BoundValidator_Implementation.json +44 -52
  33. package/deployments/bsctestnet/BoundValidator_Proxy.json +33 -33
  34. package/deployments/bsctestnet/ChainlinkOracle.json +36 -42
  35. package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +42 -48
  36. package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +33 -33
  37. package/deployments/bsctestnet/DefaultProxyAdmin.json +11 -11
  38. package/deployments/bsctestnet/PythOracle.json +48 -41
  39. package/deployments/bsctestnet/PythOracle_Implementation.json +51 -45
  40. package/deployments/bsctestnet/PythOracle_Proxy.json +39 -38
  41. package/deployments/bsctestnet/ResilientOracle.json +36 -41
  42. package/deployments/bsctestnet/ResilientOracle_Implementation.json +63 -66
  43. package/deployments/bsctestnet/ResilientOracle_Proxy.json +34 -34
  44. package/deployments/bsctestnet/TwapOracle.json +56 -56
  45. package/deployments/bsctestnet/TwapOracle_Implementation.json +81 -81
  46. package/deployments/bsctestnet/TwapOracle_Proxy.json +33 -33
  47. package/deployments/bsctestnet/solcInputs/{f35da22a430a956ee338e720b5898e3d.json → 131f58942628e21632de19506977a910.json} +7 -13
  48. package/deployments/bsctestnet/solcInputs/{4769dd98af512bf3b6b6504ad0c3bd74.json → 144b49e8aec3add79553ba273ea32d00.json} +4 -10
  49. package/deployments/bsctestnet/solcInputs/503f2e4e766f3be923fadf8030a5470f.json +78 -0
  50. package/deployments/bsctestnet/solcInputs/b39d33092f7dd383ae3a042566194132.json +75 -0
  51. package/package.json +1 -1
  52. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
  53. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
  54. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
  55. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
  56. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
  57. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
  58. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
  59. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
  60. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
  61. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
  62. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
  63. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
  64. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
  65. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
  66. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
  67. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
  68. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
  69. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
  70. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
  71. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
  72. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
  73. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
  74. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
  75. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
  76. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
  77. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
  78. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
  79. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
  80. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
  81. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
  82. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
  83. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
  84. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
  85. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
  86. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
  87. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
  88. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
  89. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
  90. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
  91. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
  92. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
  93. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
  94. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
  95. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
  96. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +0 -4
  97. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +0 -181
  98. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +0 -4
  99. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +0 -282
  100. package/artifacts/build-info/0137d0ff3ae413641739f9f6322cc2b3.json +0 -1
  101. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
  102. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
  103. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
  104. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
  105. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
  106. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
  107. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
  108. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
  109. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
  110. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
  111. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
  112. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
  113. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
  114. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
  115. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
  116. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
  117. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
  118. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
  119. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
  120. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
  121. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
  122. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
  123. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
  124. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
  125. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
  126. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
  127. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
  128. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
  129. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
  130. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
  131. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
  132. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -342
  133. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
  134. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
  135. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
  136. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -462
  137. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
  138. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -445
  139. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
  140. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -663
  141. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
  142. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
  143. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
  144. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -144
  145. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
  146. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
  147. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
  148. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
  149. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
  150. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
  151. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +0 -4
  152. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +0 -364
  153. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
  154. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -328
  155. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
  156. package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
  157. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
  158. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
  159. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
  160. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
  161. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
  162. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
  163. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
  164. package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
  165. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
  166. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
  167. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
  168. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
  169. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
  170. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +0 -346
package/README.md CHANGED
@@ -1,14 +1,37 @@
1
- # Venus Oracle
1
+ # Resilient Price Feeds
2
2
 
3
- ## Usage
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
- ### Prerequisites
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
+ ![Resilient Price Feeds](./marketing-assets/oracles.png)
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
- ### Installing
34
+ ## Installing
12
35
 
13
36
  ```
14
37
 
@@ -16,7 +39,7 @@ yarn install
16
39
 
17
40
  ```
18
41
 
19
- ### Linting and code formatting
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
- ### Run Tests
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
- ### Deployment
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
- ### Verify Contracts
94
+ ## Verify Contracts
72
95
 
73
96
  ```
74
97
  npx hardhat etherscan-verify --network <network-name>
75
98
  ```
76
99
 
77
- ### Hardhat Commands
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
- ### Documentation
136
+ ## Documentation
114
137
 
115
138
  Documentation is autogenerated using [solidity-docgen](https://github.com/OpenZeppelin/solidity-docgen).
116
139
 
@@ -7,6 +7,42 @@ 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 The Resilient Oracle is the main contract that the protocol uses to fetch prices of assets.
14
+ *
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
+ *
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.
22
+ *
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.
26
+ *
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
32
+ * should be true:
33
+
34
+ ```
35
+ anchorRatio = anchorPrice/reporterPrice
36
+ isValid = anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio
37
+ ```
38
+
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.
42
+ *
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.
45
+ */
10
46
  contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOracleInterface {
11
47
  /**
12
48
  * @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,13 @@ 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 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.
14
+ */
10
15
  contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
11
16
  struct ValidateConfig {
12
17
  /// @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 prices of assets from the Chainlink oracle.
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
 
@@ -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 respresented as 1e{decimals}
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": "0x9663A87f5CDbb0792C0E73572c9AFcE2EE6d1f9d",
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": "contract VBep20Interface",
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": "0xa937ce2ca93a665aae7837624da5208bf7830d261b44d9def1b4d98e6539b8d6",
451
+ "transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
452
452
  "receipt": {
453
453
  "to": null,
454
454
  "from": "0xa05f990d647287e4E84715b813BC000aEA970467",
455
- "contractAddress": "0x9663A87f5CDbb0792C0E73572c9AFcE2EE6d1f9d",
456
- "transactionIndex": 116,
455
+ "contractAddress": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
456
+ "transactionIndex": 109,
457
457
  "gasUsed": "718007",
458
- "logsBloom": "0x00000000000000000000000000000000400000000000000000800000000000000000000000000000000000000000004000000000000000000000000000008000000000000000000000008000000002000001000000000100000000000000000000000000020000000000000000000800000000800000000000000000002000400000000000080000000000000000000000000000000080000000000000800000000000000000000000000000000400000000000000808000000000000000000000000020000000000000000000040000000000200400000000000000000020000000000080000000000000800000000000000800000000000000000000000000",
459
- "blockHash": "0x87aadf24ae3ea41870bb81c2307980e693ba63e5f1eee1e24cea6dda148ace2d",
460
- "transactionHash": "0xa937ce2ca93a665aae7837624da5208bf7830d261b44d9def1b4d98e6539b8d6",
458
+ "logsBloom": "0x00000000000000000000000000100000400000000000020000800000000000000000000000000000000000000200000000000000000000000000000000008000000000000000000000008000000002000001000000000100000000000000000000000000020000000000000000000800000000800000002000000000000000400000000000000000000000000000000000000000000080000000000000800000000000000000000000000000000400000000000000808000000000000000000000000020000000000000000000040000000000000402000000000000000020000000000000000000000000000000000000000800400000000000000000000000",
459
+ "blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b",
460
+ "transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
461
461
  "logs": [
462
462
  {
463
- "transactionIndex": 116,
464
- "blockNumber": 27541120,
465
- "transactionHash": "0xa937ce2ca93a665aae7837624da5208bf7830d261b44d9def1b4d98e6539b8d6",
466
- "address": "0x9663A87f5CDbb0792C0E73572c9AFcE2EE6d1f9d",
463
+ "transactionIndex": 109,
464
+ "blockNumber": 28525842,
465
+ "transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
466
+ "address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
467
467
  "topics": [
468
468
  "0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b",
469
- "0x000000000000000000000000442fbeadf8da4f334a3eba0796d19e45ab25d6a0"
469
+ "0x00000000000000000000000073760d55bf10cf9d265a126d349bdd5f64326c0e"
470
470
  ],
471
471
  "data": "0x",
472
- "logIndex": 350,
473
- "blockHash": "0x87aadf24ae3ea41870bb81c2307980e693ba63e5f1eee1e24cea6dda148ace2d"
472
+ "logIndex": 279,
473
+ "blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
474
474
  },
475
475
  {
476
- "transactionIndex": 116,
477
- "blockNumber": 27541120,
478
- "transactionHash": "0xa937ce2ca93a665aae7837624da5208bf7830d261b44d9def1b4d98e6539b8d6",
479
- "address": "0x9663A87f5CDbb0792C0E73572c9AFcE2EE6d1f9d",
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": 351,
487
- "blockHash": "0x87aadf24ae3ea41870bb81c2307980e693ba63e5f1eee1e24cea6dda148ace2d"
486
+ "logIndex": 280,
487
+ "blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
488
488
  },
489
489
  {
490
- "transactionIndex": 116,
491
- "blockNumber": 27541120,
492
- "transactionHash": "0xa937ce2ca93a665aae7837624da5208bf7830d261b44d9def1b4d98e6539b8d6",
493
- "address": "0x9663A87f5CDbb0792C0E73572c9AFcE2EE6d1f9d",
490
+ "transactionIndex": 109,
491
+ "blockNumber": 28525842,
492
+ "transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
493
+ "address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
494
494
  "topics": ["0x66fd58e82f7b31a2a5c30e0888f3093efe4e111b00cd2b0c31fe014601293aa0"],
495
495
  "data": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000004788629abc6cfca10f9f969efdeaa1cf70c23555",
496
- "logIndex": 352,
497
- "blockHash": "0x87aadf24ae3ea41870bb81c2307980e693ba63e5f1eee1e24cea6dda148ace2d"
496
+ "logIndex": 281,
497
+ "blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
498
498
  },
499
499
  {
500
- "transactionIndex": 116,
501
- "blockNumber": 27541120,
502
- "transactionHash": "0xa937ce2ca93a665aae7837624da5208bf7830d261b44d9def1b4d98e6539b8d6",
503
- "address": "0x9663A87f5CDbb0792C0E73572c9AFcE2EE6d1f9d",
500
+ "transactionIndex": 109,
501
+ "blockNumber": 28525842,
502
+ "transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
503
+ "address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
504
504
  "topics": ["0x7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498"],
505
505
  "data": "0x0000000000000000000000000000000000000000000000000000000000000001",
506
- "logIndex": 353,
507
- "blockHash": "0x87aadf24ae3ea41870bb81c2307980e693ba63e5f1eee1e24cea6dda148ace2d"
506
+ "logIndex": 282,
507
+ "blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
508
508
  },
509
509
  {
510
- "transactionIndex": 116,
511
- "blockNumber": 27541120,
512
- "transactionHash": "0xa937ce2ca93a665aae7837624da5208bf7830d261b44d9def1b4d98e6539b8d6",
513
- "address": "0x9663A87f5CDbb0792C0E73572c9AFcE2EE6d1f9d",
510
+ "transactionIndex": 109,
511
+ "blockNumber": 28525842,
512
+ "transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
513
+ "address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
514
514
  "topics": ["0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f"],
515
- "data": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000adb35da0690a6dff4c9dac1638372272d2d0f91e",
516
- "logIndex": 354,
517
- "blockHash": "0x87aadf24ae3ea41870bb81c2307980e693ba63e5f1eee1e24cea6dda148ace2d"
515
+ "data": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000001bb765b741a5f3c2a338369dab539385534e3343",
516
+ "logIndex": 283,
517
+ "blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
518
518
  }
519
519
  ],
520
- "blockNumber": 27541120,
521
- "cumulativeGasUsed": "14315159",
520
+ "blockNumber": 28525842,
521
+ "cumulativeGasUsed": "11886540",
522
522
  "status": 1,
523
523
  "byzantium": true
524
524
  },
525
525
  "args": [
526
- "0x442fBeadF8DA4f334a3EbA0796d19E45aB25D6A0",
527
- "0xAdb35Da0690a6dFF4C9dAc1638372272D2d0f91E",
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": "0x442fBeadF8DA4f334a3EbA0796d19E45aB25D6A0",
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",