@venusprotocol/oracle 1.6.10 → 1.6.11-dev.10

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 (209) hide show
  1. package/LICENSE +11 -0
  2. package/README.md +117 -0
  3. package/contracts/ResilientOracle.sol +45 -37
  4. package/contracts/interfaces/PythInterface.sol +4 -1
  5. package/contracts/oracles/BinanceOracle.sol +65 -24
  6. package/contracts/oracles/BoundValidator.sol +51 -54
  7. package/contracts/oracles/ChainlinkOracle.sol +54 -54
  8. package/contracts/oracles/PythOracle.sol +48 -47
  9. package/contracts/oracles/TwapOracle.sol +85 -83
  10. package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +1 -1
  11. package/contracts/oracles/mocks/MockBinanceOracle.sol +1 -7
  12. package/contracts/oracles/mocks/MockPythOracle.sol +1 -1
  13. package/contracts/oracles/mocks/MockTwapOracle.sol +1 -1
  14. package/contracts/test/AccessControlManager.sol +6 -0
  15. package/contracts/test/BEP20Harness.sol +4 -0
  16. package/contracts/test/MockPyth.sol +9 -2
  17. package/deployments/bscmainnet/.chainId +1 -0
  18. package/deployments/bscmainnet/BinanceOracle.json +571 -0
  19. package/deployments/bscmainnet/BinanceOracle_Implementation.json +629 -0
  20. package/deployments/bscmainnet/BinanceOracle_Proxy.json +251 -0
  21. package/deployments/bscmainnet/BoundValidator.json +621 -0
  22. package/deployments/bscmainnet/BoundValidator_Implementation.json +706 -0
  23. package/deployments/bscmainnet/BoundValidator_Proxy.json +251 -0
  24. package/deployments/bscmainnet/ChainlinkOracle.json +691 -0
  25. package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +820 -0
  26. package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +251 -0
  27. package/deployments/bscmainnet/DefaultProxyAdmin.json +257 -0
  28. package/deployments/bscmainnet/PythOracle.json +688 -0
  29. package/deployments/bscmainnet/PythOracle_Implementation.json +804 -0
  30. package/deployments/bscmainnet/PythOracle_Proxy.json +265 -0
  31. package/deployments/bscmainnet/ResilientOracle.json +841 -0
  32. package/deployments/bscmainnet/ResilientOracle_Implementation.json +1044 -0
  33. package/deployments/bscmainnet/ResilientOracle_Proxy.json +251 -0
  34. package/deployments/bscmainnet/TwapOracle.json +887 -0
  35. package/deployments/bscmainnet/TwapOracle_Implementation.json +1111 -0
  36. package/deployments/bscmainnet/TwapOracle_Proxy.json +251 -0
  37. package/deployments/bscmainnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
  38. package/deployments/bscmainnet/solcInputs/aae9f1601b873a5a4704ede73ede10cb.json +135 -0
  39. package/deployments/bsctestnet/BinanceOracle.json +273 -31
  40. package/deployments/bsctestnet/BinanceOracle_Implementation.json +398 -28
  41. package/deployments/bsctestnet/BinanceOracle_Proxy.json +52 -28
  42. package/deployments/bsctestnet/BoundValidator.json +40 -40
  43. package/deployments/bsctestnet/BoundValidator_Implementation.json +43 -51
  44. package/deployments/bsctestnet/BoundValidator_Proxy.json +35 -35
  45. package/deployments/bsctestnet/ChainlinkOracle.json +57 -49
  46. package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +46 -52
  47. package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +50 -36
  48. package/deployments/bsctestnet/DefaultProxyAdmin.json +18 -18
  49. package/deployments/bsctestnet/PythOracle.json +52 -45
  50. package/deployments/bsctestnet/PythOracle_Implementation.json +53 -47
  51. package/deployments/bsctestnet/PythOracle_Proxy.json +41 -40
  52. package/deployments/bsctestnet/ResilientOracle.json +51 -42
  53. package/deployments/bsctestnet/ResilientOracle_Implementation.json +65 -68
  54. package/deployments/bsctestnet/ResilientOracle_Proxy.json +48 -34
  55. package/deployments/bsctestnet/TwapOracle.json +70 -83
  56. package/deployments/bsctestnet/TwapOracle_Implementation.json +84 -97
  57. package/deployments/bsctestnet/TwapOracle_Proxy.json +46 -46
  58. package/deployments/bsctestnet/solcInputs/131f58942628e21632de19506977a910.json +120 -0
  59. package/deployments/bsctestnet/solcInputs/144b49e8aec3add79553ba273ea32d00.json +72 -0
  60. package/deployments/bsctestnet/solcInputs/503f2e4e766f3be923fadf8030a5470f.json +78 -0
  61. package/deployments/bsctestnet/solcInputs/b39d33092f7dd383ae3a042566194132.json +75 -0
  62. package/dist/deploy/1-deploy-oracles.d.ts +5 -0
  63. package/dist/deploy/1-deploy-oracles.d.ts.map +1 -0
  64. package/{deploy → dist/deploy}/1-deploy-oracles.js +66 -24
  65. package/dist/deploy/1-deploy-oracles.js.map +1 -0
  66. package/dist/deploy/2-configure-feeds.d.ts +15 -0
  67. package/dist/deploy/2-configure-feeds.d.ts.map +1 -0
  68. package/{deploy → dist/deploy}/2-configure-feeds.js +139 -16
  69. package/dist/deploy/2-configure-feeds.js.map +1 -0
  70. package/dist/hardhat.config.d.ts +13 -0
  71. package/dist/hardhat.config.d.ts.map +1 -0
  72. package/dist/hardhat.config.js +158 -0
  73. package/dist/hardhat.config.js.map +1 -0
  74. package/package.json +26 -19
  75. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
  76. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
  77. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
  78. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
  79. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
  80. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
  81. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
  82. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
  83. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
  84. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
  85. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
  86. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
  87. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
  88. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
  89. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
  90. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
  91. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
  92. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
  93. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
  94. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
  95. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
  96. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
  97. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
  98. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
  99. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
  100. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
  101. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
  102. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
  103. package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +0 -4
  104. package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.json +0 -10
  105. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
  106. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
  107. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
  108. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
  109. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
  110. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
  111. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
  112. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
  113. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
  114. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
  115. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
  116. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
  117. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
  118. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
  119. package/artifacts/build-info/a47a69a8f108d3e7113faf89771988ff.json +0 -1
  120. package/artifacts/build-info/cc300b55b814df48229058e829c7c3c6.json +0 -1
  121. package/artifacts/build-info/de79b2637546f6f7d38c8f655549d9e2.json +0 -1
  122. package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
  123. package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
  124. package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.dbg.json +0 -4
  125. package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.json +0 -181
  126. package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.dbg.json +0 -4
  127. package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.json +0 -282
  128. package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +0 -4
  129. package/artifacts/contracts/PriceOracle.sol/PriceOracle.json +0 -43
  130. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
  131. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
  132. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
  133. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
  134. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
  135. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
  136. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
  137. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
  138. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
  139. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
  140. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
  141. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
  142. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
  143. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
  144. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
  145. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
  146. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
  147. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
  148. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
  149. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
  150. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
  151. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
  152. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
  153. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
  154. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
  155. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
  156. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
  157. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
  158. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
  159. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
  160. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
  161. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -124
  162. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
  163. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
  164. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
  165. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -468
  166. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
  167. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -439
  168. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
  169. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -676
  170. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
  171. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
  172. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
  173. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -163
  174. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
  175. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
  176. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
  177. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
  178. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
  179. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
  180. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
  181. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -315
  182. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
  183. package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
  184. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
  185. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
  186. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
  187. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
  188. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
  189. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
  190. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
  191. package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
  192. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
  193. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
  194. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
  195. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
  196. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
  197. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +0 -333
  198. package/contracts/Governance/AccessControlManager.sol +0 -99
  199. package/contracts/Governance/AccessControlled.sol +0 -75
  200. package/contracts/Governance/IAccessControlManager.sol +0 -22
  201. package/contracts/PriceOracle.sol +0 -16
  202. package/deploy/1-deploy-oracles.d.ts +0 -2
  203. package/deploy/1-deploy-oracles.d.ts.map +0 -1
  204. package/deploy/1-deploy-oracles.js.map +0 -1
  205. package/deploy/2-configure-feeds.d.ts +0 -2
  206. package/deploy/2-configure-feeds.d.ts.map +0 -1
  207. package/deploy/2-configure-feeds.js.map +0 -1
  208. package/deployments/bsctestnet/AccessControlManager.json +0 -563
  209. package/deployments/bsctestnet/solcInputs/30f2cb3e89e183b8669f05bddf9426d9.json +0 -183
package/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2022 Venus Protocol.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Venus Oracle
2
+
3
+ ## Usage
4
+
5
+ ### Prerequisites
6
+
7
+ - NodeJS - 14.x
8
+
9
+ - Solc - v0.8.13 (https://github.com/ethereum/solidity/releases/tag/v0.8.13)
10
+
11
+ ### Installing
12
+
13
+ ```
14
+
15
+ yarn install
16
+
17
+ ```
18
+
19
+ ### Linting and code formatting
20
+
21
+ Linting is done using eslint for typescript and solhint for solidity. Prettier is used to format solidity and typescript files.
22
+
23
+ To check linting and formatting on all files run:
24
+
25
+ ```sh
26
+ $ yarn lint
27
+ ```
28
+
29
+ Linting command can be run with the fix flag to fix eligible errors automatically
30
+
31
+ ```sh
32
+ $ yarn lint:sol --fix
33
+ $ yarn lint:ts --fix
34
+ ```
35
+
36
+ To pretty all files run:
37
+
38
+ ```sh
39
+ $ yarn prettier
40
+ ```
41
+
42
+ ### Run Tests
43
+
44
+ ```
45
+
46
+ npx hardhat test
47
+
48
+ ```
49
+
50
+ - To run fork tests add FORK_MAINNET=true PRIVATE_KEY and QUICK_NODE_KEY in the .env file.
51
+
52
+ ## Releases and Versioning
53
+
54
+ Releases are automatically managed using semantic-release and commit messages.
55
+
56
+ ### Deployment
57
+
58
+ ```
59
+
60
+ npx hardhat deploy
61
+
62
+ ```
63
+
64
+ - This command will execute all the deployment scripts in `./deploy` directory
65
+ - The default network will be `hardhat`
66
+ - Deployment to another network: - Make sure the desired network is configured in `hardhat.config.ts` - Add `PRIVATE_KEY` variable in `.env` file - Execute deploy command by adding `--network <network_name>` in the deploy command above - E.g. `npx hardhat deploy --network bsctestnet`
67
+ - Execution of single or custom set of scripts is possible, if:
68
+ - In the deployment scripts you have added `tags` for example: - `func.tags = ["MockTokens"];`
69
+ - Once this is done, adding `--tags "<tag_name>,<tag_name>..."` to the deployment command will execute only the scripts containing the tags.
70
+
71
+ ### Verify Contracts
72
+
73
+ ```
74
+ npx hardhat etherscan-verify --network <network-name>
75
+ ```
76
+
77
+ ### Hardhat Commands
78
+
79
+ ```
80
+
81
+ npx hardhat accounts
82
+
83
+ npx hardhat compile
84
+
85
+ npx hardhat clean
86
+
87
+ npx hardhat test
88
+
89
+ npx hardhat node
90
+
91
+ npx hardhat help
92
+
93
+ REPORT_GAS=true npx hardhat test
94
+
95
+ npx hardhat coverage
96
+
97
+ TS_NODE_FILES=true npx ts-node scripts/deploy.ts
98
+
99
+ npx eslint '**/*.{js,ts}'
100
+
101
+ npx eslint '**/*.{js,ts}' --fix
102
+
103
+ npx prettier '**/*.{json,sol,md}' --check
104
+
105
+ npx prettier '**/*.{json,sol,md}' --write
106
+
107
+ npx solhint 'contracts/**/*.sol'
108
+
109
+ npx solhint 'contracts/**/*.sol' --fix
110
+
111
+ ```
112
+
113
+ ### Documentation
114
+
115
+ Documentation is autogenerated using [solidity-docgen](https://github.com/OpenZeppelin/solidity-docgen).
116
+
117
+ They can be generated by running `yarn docgen`
@@ -2,13 +2,12 @@
2
2
  // SPDX-FileCopyrightText: 2022 Venus
3
3
  pragma solidity 0.8.13;
4
4
 
5
- import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
6
5
  import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
7
6
  import "./interfaces/VBep20Interface.sol";
8
7
  import "./interfaces/OracleInterface.sol";
9
- import "./Governance/AccessControlled.sol";
8
+ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
10
9
 
11
- contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOracleInterface {
10
+ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOracleInterface {
12
11
  /**
13
12
  * @dev Oracle roles:
14
13
  * **main**: The most trustworthy price source
@@ -46,7 +45,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
46
45
  /// @notice Set this as asset address for BNB. This is the underlying for vBNB
47
46
  address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
48
47
 
49
- BoundValidatorInterface public boundValidator;
48
+ /// @notice Bound validator contract address
49
+ /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
50
+ BoundValidatorInterface public immutable boundValidator;
50
51
 
51
52
  mapping(address => TokenConfig) private tokenConfigs;
52
53
 
@@ -67,7 +68,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
67
68
  * @notice Checks whether an address is null or not
68
69
  */
69
70
  modifier notNullAddress(address someone) {
70
- require(someone != address(0), "can't be zero address");
71
+ if (someone == address(0)) revert("can't be zero address");
71
72
  _;
72
73
  }
73
74
 
@@ -76,21 +77,37 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
76
77
  * @dev vToken can't be null, so it's suitable to be used to check the validity of the config
77
78
  * @param asset asset address
78
79
  */
79
- modifier checkTokenConfigExistance(address asset) {
80
- require(tokenConfigs[asset].asset != address(0), "token config must exist");
80
+ modifier checkTokenConfigExistence(address asset) {
81
+ if (tokenConfigs[asset].asset == address(0)) revert("token config must exist");
81
82
  _;
82
83
  }
83
84
 
84
85
  /// @notice Constructor for the implementation contract. Sets immutable variables.
85
86
  /// @param vBnbAddress The address of the vBNB
86
87
  /// @param vaiAddress The address of the VAI
88
+ /// @param _boundValidator Address of the bound validator contract
87
89
  /// @custom:oz-upgrades-unsafe-allow constructor
88
- constructor(address vBnbAddress, address vaiAddress) notNullAddress(vBnbAddress) {
90
+ constructor(
91
+ address vBnbAddress,
92
+ address vaiAddress,
93
+ BoundValidatorInterface _boundValidator
94
+ ) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) notNullAddress(address(_boundValidator)) {
89
95
  vBnb = vBnbAddress;
90
96
  vai = vaiAddress;
97
+ boundValidator = _boundValidator;
98
+
91
99
  _disableInitializers();
92
100
  }
93
101
 
102
+ /**
103
+ * @notice Initializes the contract admin and sets the BoundValidator contract address
104
+ * @param accessControlManager_ Address of the access control manager contract
105
+ */
106
+ function initialize(address accessControlManager_) external initializer {
107
+ __AccessControlled_init(accessControlManager_);
108
+ __Pausable_init();
109
+ }
110
+
94
111
  /**
95
112
  * @notice Pauses oracle
96
113
  * @custom:access Only Governance
@@ -113,14 +130,16 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
113
130
  * @notice Batch sets token configs
114
131
  * @param tokenConfigs_ Token config array
115
132
  * @custom:access Only Governance
116
- * @custom:error Throws a length error if the lenght of the token configs array is 0
133
+ * @custom:error Throws a length error if the length of the token configs array is 0
117
134
  */
118
135
  function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
119
- _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
120
- require(tokenConfigs_.length != 0, "length can't be 0");
136
+ if (tokenConfigs_.length == 0) revert("length can't be 0");
121
137
  uint256 numTokenConfigs = tokenConfigs_.length;
122
- for (uint256 i; i < numTokenConfigs; ++i) {
138
+ for (uint256 i; i < numTokenConfigs; ) {
123
139
  setTokenConfig(tokenConfigs_[i]);
140
+ unchecked {
141
+ ++i;
142
+ }
124
143
  }
125
144
  }
126
145
 
@@ -140,9 +159,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
140
159
  address asset,
141
160
  address oracle,
142
161
  OracleRole role
143
- ) external notNullAddress(asset) checkTokenConfigExistance(asset) {
144
- _checkAccessAllowed("setOracle(address,address,OracleRole)");
145
- require(!(oracle == address(0) && role == OracleRole.MAIN), "can't set zero address to main oracle");
162
+ ) external notNullAddress(asset) checkTokenConfigExistence(asset) {
163
+ _checkAccessAllowed("setOracle(address,address,uint8)");
164
+ if (oracle == address(0) && role == OracleRole.MAIN) revert("can't set zero address to main oracle");
146
165
  tokenConfigs[asset].oracles[uint256(role)] = oracle;
147
166
  emit OracleSet(asset, oracle, uint256(role));
148
167
  }
@@ -160,21 +179,21 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
160
179
  address asset,
161
180
  OracleRole role,
162
181
  bool enable
163
- ) external notNullAddress(asset) checkTokenConfigExistance(asset) {
164
- _checkAccessAllowed("enableOracle(address,OracleRole,address)");
182
+ ) external notNullAddress(asset) checkTokenConfigExistence(asset) {
183
+ _checkAccessAllowed("enableOracle(address,uint8,bool)");
165
184
  tokenConfigs[asset].enableFlagsForOracles[uint256(role)] = enable;
166
185
  emit OracleEnabled(asset, uint256(role), enable);
167
186
  }
168
187
 
169
188
  /**
170
- * @notice Updates the pivot oracle price. Currently using TWAP
189
+ * @notice Updates the TWAP pivot oracle price.
171
190
  * @dev This function should always be called before calling getUnderlyingPrice
172
191
  * @param vToken vToken address
173
192
  */
174
193
  function updatePrice(address vToken) external override {
175
194
  (address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
176
195
  if (pivotOracle != address(0) && pivotOracleEnabled) {
177
- //if **pivot** oracle is PythOrcle it will revert so we need to catch the revert
196
+ //if pivot oracle is not TwapOracle it will revert so we need to catch the revert
178
197
  try TwapInterface(pivotOracle).updateTwap(vToken) {} catch {}
179
198
  }
180
199
  }
@@ -193,7 +212,8 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
193
212
  * @notice Gets price of the underlying asset for a given vToken. Validation flow:
194
213
  * - Check if the oracle is paused globally
195
214
  * - Validate price from main oracle against pivot oracle
196
- * - Validate price from fallback oracle against pivot oracle or main oracle if the first validation failed
215
+ * - Validate price from fallback oracle against pivot oracle if the first validation failed
216
+ * - Validate price from main oracle against fallback oracle if the second validation failed
197
217
  * In the case that the pivot oracle is not available but main price is available and validation is successful,
198
218
  * main oracle price is returned.
199
219
  * @param vToken vToken address
@@ -202,7 +222,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
202
222
  * @custom:error Invalid resilient oracle price error is thrown if fetched prices from oracle is invalid
203
223
  */
204
224
  function getUnderlyingPrice(address vToken) external view override returns (uint256) {
205
- require(!paused(), "resilient oracle is paused");
225
+ if (paused()) revert("resilient oracle is paused");
206
226
  uint256 pivotPrice = INVALID_PRICE;
207
227
 
208
228
  // Get pivot oracle price, Invalid price if not available or error
@@ -232,7 +252,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
232
252
  if (
233
253
  mainPrice != INVALID_PRICE &&
234
254
  fallbackPrice != INVALID_PRICE &&
235
- boundValidator.validatePriceWithAnchorPrice(vToken, fallbackPrice, mainPrice)
255
+ boundValidator.validatePriceWithAnchorPrice(vToken, mainPrice, fallbackPrice)
236
256
  ) {
237
257
  return mainPrice;
238
258
  }
@@ -240,18 +260,6 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
240
260
  revert("invalid resilient oracle price");
241
261
  }
242
262
 
243
- /**
244
- * @notice Initializes the contract admin and sets the BoundValidator contract address
245
- * @param _boundValidator Address of the bound validator contract
246
- * @param accessControlManager_ Address of the access control manager contract
247
- */
248
- function initialize(BoundValidatorInterface _boundValidator, address accessControlManager_) public initializer {
249
- require(address(_boundValidator) != address(0), "invalid bound validator address");
250
- boundValidator = _boundValidator;
251
-
252
- __AccessControlled_init_unchained(accessControlManager_);
253
- }
254
-
255
263
  /**
256
264
  * @notice Sets/resets single token configs.
257
265
  * @dev main oracle **must not** be a null address
@@ -308,7 +316,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
308
316
  address vToken,
309
317
  uint256 pivotPrice,
310
318
  bool pivotEnabled
311
- ) internal view returns (uint256, bool) {
319
+ ) private view returns (uint256, bool) {
312
320
  (address mainOracle, bool mainOracleEnabled) = getOracle(vToken, OracleRole.MAIN);
313
321
  if (mainOracleEnabled && mainOracle != address(0)) {
314
322
  try OracleInterface(mainOracle).getUnderlyingPrice(vToken) returns (uint256 mainOraclePrice) {
@@ -340,7 +348,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
340
348
  * @custom:error Invalid price error is thrown if fallback oracle is not enabled or fallback oracle
341
349
  * address is null
342
350
  */
343
- function _getFallbackOraclePrice(address vToken, uint256 pivotPrice) internal view returns (uint256, bool) {
351
+ function _getFallbackOraclePrice(address vToken, uint256 pivotPrice) private view returns (uint256, bool) {
344
352
  (address fallbackOracle, bool fallbackEnabled) = getOracle(vToken, OracleRole.FALLBACK);
345
353
  if (fallbackEnabled && fallbackOracle != address(0)) {
346
354
  try OracleInterface(fallbackOracle).getUnderlyingPrice(vToken) returns (uint256 fallbackOraclePrice) {
@@ -364,7 +372,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlled, ResilientOrac
364
372
  * @param vToken vToken address
365
373
  * @return asset underlying asset address
366
374
  */
367
- function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
375
+ function _getUnderlyingAsset(address vToken) private view returns (address asset) {
368
376
  if (address(vToken) == vBnb) {
369
377
  asset = BNB_ADDR;
370
378
  } else if (address(vToken) == vai) {
@@ -235,11 +235,14 @@ abstract contract AbstractPyth is IPyth {
235
235
  require(priceIds.length == publishTimes.length, "priceIds and publishTimes arrays should have same length");
236
236
 
237
237
  bool updateNeeded = false;
238
- for (uint256 i = 0; i < priceIds.length; i++) {
238
+ for (uint256 i = 0; i < priceIds.length; ) {
239
239
  if (!priceFeedExists(priceIds[i]) || queryPriceFeed(priceIds[i]).price.publishTime < publishTimes[i]) {
240
240
  updateNeeded = true;
241
241
  break;
242
242
  }
243
+ unchecked {
244
+ i++;
245
+ }
243
246
  }
244
247
 
245
248
  require(updateNeeded, "no prices in the submitted batch have fresh prices, so this update will have no effect");
@@ -1,14 +1,15 @@
1
1
  // SPDX-License-Identifier: BSD-3-Clause
2
2
  pragma solidity 0.8.13;
3
3
 
4
- import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
5
4
  import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
6
5
  import "../interfaces/VBep20Interface.sol";
7
6
  import "../interfaces/SIDRegistryInterface.sol";
8
7
  import "../interfaces/FeedRegistryInterface.sol";
9
8
  import "../interfaces/PublicResolverInterface.sol";
9
+ import "../interfaces/OracleInterface.sol";
10
+ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
10
11
 
11
- contract BinanceOracle is Initializable {
12
+ contract BinanceOracle is AccessControlledV8, OracleInterface {
12
13
  address public sidRegistryAddress;
13
14
 
14
15
  /// @notice vBNB address
@@ -19,38 +20,45 @@ contract BinanceOracle is Initializable {
19
20
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
20
21
  address public immutable vai;
21
22
 
23
+ /// @notice Max stale period configuration for assets
24
+ mapping(string => uint256) public maxStalePeriod;
25
+
26
+ event MaxStalePeriodAdded(string indexed asset, uint256 maxStalePeriod);
27
+
22
28
  /// @notice Constructor for the implementation contract. Sets immutable variables.
23
29
  /// @param vBnbAddress The address of the vBNB
24
30
  /// @param vaiAddress The address of the VAI
25
31
  /// @custom:oz-upgrades-unsafe-allow constructor
26
32
  constructor(address vBnbAddress, address vaiAddress) {
27
- require(vBnbAddress != address(0), "vBNB can't be zero address");
28
- require(vaiAddress != address(0), "VAI can't be zero address");
33
+ if (vBnbAddress == address(0)) revert("vBNB can't be zero address");
34
+ if (vaiAddress == address(0)) revert("VAI can't be zero address");
29
35
  vBnb = vBnbAddress;
30
36
  vai = vaiAddress;
31
37
  _disableInitializers();
32
38
  }
33
39
 
34
40
  /**
35
- * @notice Sets the contracts required to fetch prices
36
- * @param _sidRegistryAddress Address of SID registry
41
+ * @notice Used to set the max stale period of an asset
42
+ * @param symbol The symbol of the asset
43
+ * @param _maxStalePeriod The max stake period
37
44
  */
38
- function initialize(address _sidRegistryAddress) public initializer {
39
- sidRegistryAddress = _sidRegistryAddress;
45
+ function setMaxStalePeriod(string memory symbol, uint256 _maxStalePeriod) external {
46
+ _checkAccessAllowed("setMaxStalePeriod(string,uint256)");
47
+ if (_maxStalePeriod == 0) revert("stale period can't be zero");
48
+ if (bytes(symbol).length == 0) revert("symbol cannot be empty");
49
+
50
+ maxStalePeriod[symbol] = _maxStalePeriod;
51
+ emit MaxStalePeriodAdded(symbol, _maxStalePeriod);
40
52
  }
41
53
 
42
54
  /**
43
- * @notice Uses Space ID to fetch the feed registry address
44
- * @return feedRegistryAddress Address of binance oracle feed registry.
55
+ * @notice Sets the contracts required to fetch prices
56
+ * @param _sidRegistryAddress Address of SID registry
57
+ * @param _accessControlManager Address of the access control manager contract
45
58
  */
46
- function getFeedRegistryAddress() public view returns (address) {
47
- bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
48
-
49
- SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
50
- address publicResolverAddress = sidRegistry.resolver(nodeHash);
51
- PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
52
-
53
- return publicResolver.addr(nodeHash);
59
+ function initialize(address _sidRegistryAddress, address _accessControlManager) external initializer {
60
+ sidRegistryAddress = _sidRegistryAddress;
61
+ __AccessControlled_init(_accessControlManager);
54
62
  }
55
63
 
56
64
  /**
@@ -58,32 +66,65 @@ contract BinanceOracle is Initializable {
58
66
  * @param vToken Address of the vToken
59
67
  * @return Price in USD
60
68
  */
61
- function getUnderlyingPrice(VBep20Interface vToken) public view returns (uint256) {
69
+ function getUnderlyingPrice(address vToken) external view override returns (uint256) {
62
70
  string memory symbol;
63
71
  uint256 decimals;
64
72
 
65
73
  // VBNB token doesn't have `underlying` method
66
- if (address(vToken) == vBnb) {
74
+ if (vToken == vBnb) {
67
75
  symbol = "BNB";
68
76
  decimals = 18;
69
- } else if (address(vToken) == vai) {
77
+ } else if (vToken == vai) {
70
78
  symbol = "VAI";
71
79
  decimals = 18;
72
80
  } else {
73
- IERC20Metadata underlyingToken = IERC20Metadata(vToken.underlying());
81
+ IERC20Metadata underlyingToken = IERC20Metadata(VBep20Interface(vToken).underlying());
74
82
  symbol = underlyingToken.symbol();
75
83
  decimals = underlyingToken.decimals();
76
84
  }
77
85
 
78
- if (keccak256(bytes(symbol)) == keccak256(bytes("WBNB"))) {
86
+ if (compare(symbol, "WBNB")) {
79
87
  symbol = "BNB";
80
88
  }
81
89
 
82
90
  FeedRegistryInterface feedRegistry = FeedRegistryInterface(getFeedRegistryAddress());
83
91
 
84
- (, int256 answer, , , ) = feedRegistry.latestRoundDataByName(symbol, "USD");
92
+ (, int256 answer, , uint256 updatedAt, ) = feedRegistry.latestRoundDataByName(symbol, "USD");
93
+ if (answer <= 0) revert("invalid binance oracle price");
94
+ if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
95
+
96
+ uint256 deltaTime;
97
+ unchecked {
98
+ deltaTime = block.timestamp - updatedAt;
99
+ }
100
+
101
+ if (deltaTime > maxStalePeriod[symbol]) revert("binance oracle price expired");
85
102
 
86
103
  uint256 decimalDelta = feedRegistry.decimalsByName(symbol, "USD");
87
104
  return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
88
105
  }
106
+
107
+ /**
108
+ * @notice Uses Space ID to fetch the feed registry address
109
+ * @return feedRegistryAddress Address of binance oracle feed registry.
110
+ */
111
+ function getFeedRegistryAddress() public view returns (address) {
112
+ bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
113
+
114
+ SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
115
+ address publicResolverAddress = sidRegistry.resolver(nodeHash);
116
+ PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
117
+
118
+ return publicResolver.addr(nodeHash);
119
+ }
120
+
121
+ /**
122
+ * @notice Used to compare if two strings are equal or not
123
+ * @param str1 The first string
124
+ * @param str2 The second string
125
+ * @return equal Returns true if both are equal or else false.
126
+ */
127
+ function compare(string memory str1, string memory str2) private pure returns (bool) {
128
+ return keccak256(bytes(str1)) == keccak256(bytes(str2));
129
+ }
89
130
  }