@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
@@ -5,31 +5,31 @@ import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
5
5
  import "../libraries/PancakeLibrary.sol";
6
6
  import "../interfaces/OracleInterface.sol";
7
7
  import "../interfaces/VBep20Interface.sol";
8
- import "../Governance/AccessControlled.sol";
8
+ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
9
9
 
10
- struct Observation {
11
- uint256 timestamp;
12
- uint256 acc;
13
- }
10
+ contract TwapOracle is AccessControlledV8, TwapInterface {
11
+ using FixedPoint for *;
14
12
 
15
- struct TokenConfig {
16
- /// @notice Asset address, which can't be zero address and can be used for existance check
17
- address asset;
18
- /// @notice Decimals of underlying asset
19
- uint256 baseUnit;
20
- /// @notice The address of Pancake pair
21
- address pancakePool;
22
- /// @notice Whether the token is paired with WBNB
23
- bool isBnbBased;
24
- /// @notice A flag identifies whether the Pancake pair is reversed
25
- /// e.g. XVS-WBNB is not reversed, while WBNB-XVS is.
26
- bool isReversedPool;
27
- /// @notice The minimum window in seconds required between TWAP updates
28
- uint256 anchorPeriod;
29
- }
13
+ struct Observation {
14
+ uint256 timestamp;
15
+ uint256 acc;
16
+ }
30
17
 
31
- contract TwapOracle is AccessControlled, TwapInterface {
32
- using FixedPoint for *;
18
+ struct TokenConfig {
19
+ /// @notice Asset address, which can't be zero address and can be used for existance check
20
+ address asset;
21
+ /// @notice Decimals of underlying asset represented as 1e{decimals}
22
+ uint256 baseUnit;
23
+ /// @notice The address of Pancake pair
24
+ address pancakePool;
25
+ /// @notice Whether the token is paired with WBNB
26
+ bool isBnbBased;
27
+ /// @notice A flag identifies whether the Pancake pair is reversed
28
+ /// e.g. XVS-WBNB is reversed, while WBNB-XVS is not.
29
+ bool isReversedPool;
30
+ /// @notice The minimum window in seconds required between TWAP updates
31
+ uint256 anchorPeriod;
32
+ }
33
33
 
34
34
  /// @notice WBNB address
35
35
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
@@ -44,10 +44,8 @@ contract TwapOracle is AccessControlled, TwapInterface {
44
44
  address public immutable vai;
45
45
 
46
46
  /// @notice the base unit of WBNB and BUSD, which are the paired tokens for all assets
47
- uint256 public constant bnbBaseUnit = 1e18;
48
- uint256 public constant busdBaseUnit = 1e18;
49
-
50
- uint256 public constant expScale = 1e18;
47
+ uint256 public constant BNB_BASE_UNIT = 1e18;
48
+ uint256 public constant BUSD_BASE_UNIT = 1e18;
51
49
 
52
50
  /// @notice Configs by token
53
51
  mapping(address => TokenConfig) public tokenConfigs;
@@ -77,7 +75,7 @@ contract TwapOracle is AccessControlled, TwapInterface {
77
75
  event TokenConfigAdded(address indexed asset, address indexed pancakePool, uint256 indexed anchorPeriod);
78
76
 
79
77
  modifier notNullAddress(address someone) {
80
- require(someone != address(0), "can't be zero address");
78
+ if (someone == address(0)) revert("can't be zero address");
81
79
  _;
82
80
  }
83
81
 
@@ -102,13 +100,40 @@ contract TwapOracle is AccessControlled, TwapInterface {
102
100
  * @param configs Config array
103
101
  * @custom:error Zero length error thrown, if length of the config array is 0
104
102
  */
105
- function setTokenConfigs(TokenConfig[] memory configs) external onlyOwner {
106
- _checkAccessAllowed("setTokenConfigsTokenConfig[])");
107
- require(configs.length > 0, "length can't be 0");
103
+ function setTokenConfigs(TokenConfig[] memory configs) external {
104
+ if (configs.length == 0) revert("length can't be 0");
108
105
  uint256 numTokenConfigs = configs.length;
109
- for (uint256 i; i < numTokenConfigs; ++i) {
106
+ for (uint256 i; i < numTokenConfigs; ) {
110
107
  setTokenConfig(configs[i]);
108
+ unchecked {
109
+ ++i;
110
+ }
111
+ }
112
+ }
113
+
114
+ /**
115
+ * @notice Initializes the owner of the contract
116
+ * @param accessControlManager_ Address of the access control manager contract
117
+ */
118
+ function initialize(address accessControlManager_) external initializer {
119
+ __AccessControlled_init(accessControlManager_);
120
+ }
121
+
122
+ /**
123
+ * @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
124
+ * @return anchorPrice anchor price of the underlying asset of the vToken
125
+ * @custom:error Missing error is thrown if token config does not exist
126
+ */
127
+ function updateTwap(address vToken) external returns (uint256) {
128
+ address asset = _getUnderlyingAsset(vToken);
129
+
130
+ if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
131
+ // Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
132
+ if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
133
+ if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
134
+ _updateTwapInternal(tokenConfigs[WBNB]);
111
135
  }
136
+ return _updateTwapInternal(tokenConfigs[asset]);
112
137
  }
113
138
 
114
139
  /**
@@ -121,23 +146,14 @@ contract TwapOracle is AccessControlled, TwapInterface {
121
146
  function getUnderlyingPrice(address vToken) external view override returns (uint256) {
122
147
  address asset = _getUnderlyingAsset(vToken);
123
148
 
124
- require(tokenConfigs[asset].asset != address(0), "asset not exist");
149
+ if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
125
150
  uint256 price = prices[asset];
126
151
 
127
152
  // if price is 0, it means the price hasn't been updated yet and it's meaningless, revert
128
- require(price > 0, "TWAP price must be positive");
153
+ if (price == 0) revert("TWAP price must be positive");
129
154
  return (price * (10 ** (18 - IERC20Metadata(asset).decimals())));
130
155
  }
131
156
 
132
- /**
133
- * @notice Initializes the owner of the contract
134
- * @param accessControlManager_ Address of the access control manager contract
135
- */
136
- function initialize(address accessControlManager_) public initializer {
137
- __Ownable2Step_init();
138
- __AccessControlled_init_unchained(accessControlManager_);
139
- }
140
-
141
157
  /**
142
158
  * @notice Adds a single token config
143
159
  * @param config token config struct
@@ -155,12 +171,9 @@ contract TwapOracle is AccessControlled, TwapInterface {
155
171
  ) public notNullAddress(config.asset) notNullAddress(config.pancakePool) {
156
172
  _checkAccessAllowed("setTokenConfig(TokenConfig)");
157
173
 
158
- require(config.anchorPeriod > 0, "anchor period must be positive");
159
- require(config.baseUnit > 0, "base unit must be positive");
160
- require(
161
- config.baseUnit == 10 ** IERC20Metadata(config.asset).decimals(),
162
- "base unit decimals must be same as asset decimals"
163
- );
174
+ if (config.anchorPeriod == 0) revert("anchor period must be positive");
175
+ if (config.baseUnit != 10 ** IERC20Metadata(config.asset).decimals())
176
+ revert("base unit decimals must be same as asset decimals");
164
177
 
165
178
  uint256 cumulativePrice = currentCumulativePrice(config);
166
179
 
@@ -170,23 +183,6 @@ contract TwapOracle is AccessControlled, TwapInterface {
170
183
  emit TokenConfigAdded(config.asset, config.pancakePool, config.anchorPeriod);
171
184
  }
172
185
 
173
- /**
174
- * @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
175
- * @return anchorPrice anchor price of the underlying asset of the vToken
176
- * @custom:error Missing error is thrown if token config does not exist
177
- */
178
- function updateTwap(address vToken) public returns (uint256) {
179
- address asset = _getUnderlyingAsset(vToken);
180
-
181
- require(tokenConfigs[asset].asset != address(0), "asset not exist");
182
- // Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
183
- if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
184
- require(tokenConfigs[WBNB].asset != address(0), "WBNB not exist");
185
- _updateTwapInternal(tokenConfigs[WBNB]);
186
- }
187
- return _updateTwapInternal(tokenConfigs[asset]);
188
- }
189
-
190
186
  /**
191
187
  * @notice Fetches the current token/WBNB and token/BUSD price accumulator from PancakeSwap.
192
188
  * @return cumulative price of target token regardless of pair order
@@ -209,16 +205,22 @@ contract TwapOracle is AccessControlled, TwapInterface {
209
205
  * @custom:event Emits AnchorPriceUpdated event on successful update of observation with assset address,
210
206
  * AnchorPrice, old observation timestamp and current timestamp
211
207
  */
212
- function _updateTwapInternal(TokenConfig memory config) internal virtual returns (uint256) {
208
+ function _updateTwapInternal(TokenConfig memory config) private returns (uint256) {
213
209
  // pokeWindowValues already handled reversed pool cases,
214
210
  // priceAverage will always be Token/BNB or Token/BUSD *twap** price.
215
211
  (uint256 nowCumulativePrice, uint256 oldCumulativePrice, uint256 oldTimestamp) = pokeWindowValues(config);
216
212
 
213
+ if (block.timestamp == oldTimestamp) return prices[config.asset];
214
+
217
215
  // This should be impossible, but better safe than sorry
218
- require(block.timestamp > oldTimestamp, "now must come after before");
219
- uint256 timeElapsed = block.timestamp - oldTimestamp;
216
+ if (block.timestamp < oldTimestamp) revert("now must come after before");
217
+
218
+ uint256 timeElapsed;
219
+ unchecked {
220
+ timeElapsed = block.timestamp - oldTimestamp;
221
+ }
220
222
 
221
- // Calculate Pancakge *twap**
223
+ // Calculate Pancake *twap**
222
224
  FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112(
223
225
  uint224((nowCumulativePrice - oldCumulativePrice) / timeElapsed)
224
226
  );
@@ -226,18 +228,18 @@ contract TwapOracle is AccessControlled, TwapInterface {
226
228
  uint256 priceAverageMantissa = priceAverage.decode112with18();
227
229
 
228
230
  // To cancel the decimals in cumulative price, we need to mulitply the average price with
229
- // tokenBaseUnit / (wbnbBaseUnit or busdBaseUnit, which is 1e18)
230
- uint256 pairedTokenBaseUnit = config.isBnbBased ? bnbBaseUnit : busdBaseUnit;
231
+ // tokenBaseUnit / (BNB_BASE_UNIT or BUSD_BASE_UNIT, which is 1e18)
232
+ uint256 pairedTokenBaseUnit = config.isBnbBased ? BNB_BASE_UNIT : BUSD_BASE_UNIT;
231
233
  uint256 anchorPriceMantissa = (priceAverageMantissa * config.baseUnit) / pairedTokenBaseUnit;
232
234
 
233
235
  // if this token is paired with BNB, convert its price to USD
234
236
  if (config.isBnbBased) {
235
237
  uint256 bnbPrice = prices[WBNB];
236
- require(bnbPrice != 0, "bnb price is invalid");
237
- anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / bnbBaseUnit;
238
+ if (bnbPrice == 0) revert("bnb price is invalid");
239
+ anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / BNB_BASE_UNIT;
238
240
  }
239
241
 
240
- require(anchorPriceMantissa != 0, "twap price cannot be 0");
242
+ if (anchorPriceMantissa == 0) revert("twap price cannot be 0");
241
243
 
242
244
  emit AnchorPriceUpdated(config.asset, anchorPriceMantissa, oldTimestamp, block.timestamp);
243
245
 
@@ -258,18 +260,14 @@ contract TwapOracle is AccessControlled, TwapInterface {
258
260
  */
259
261
  function pokeWindowValues(
260
262
  TokenConfig memory config
261
- ) internal returns (uint256, uint256 startCumulativePrice, uint256 startCumulativeTimestamp) {
263
+ ) private returns (uint256, uint256 startCumulativePrice, uint256 startCumulativeTimestamp) {
262
264
  uint256 cumulativePrice = currentCumulativePrice(config);
263
265
  uint256 currentTimestamp = block.timestamp;
264
266
  uint256 windowStartTimestamp = currentTimestamp - config.anchorPeriod;
265
267
  Observation[] memory storedObservations = observations[config.asset];
266
268
 
267
269
  uint256 storedObservationsLength = storedObservations.length;
268
- for (
269
- uint256 windowStartIndex = windowStart[config.asset];
270
- windowStartIndex < storedObservationsLength;
271
- ++windowStartIndex
272
- ) {
270
+ for (uint256 windowStartIndex = windowStart[config.asset]; windowStartIndex < storedObservationsLength; ) {
273
271
  if (
274
272
  (storedObservations[windowStartIndex].timestamp >= windowStartTimestamp) ||
275
273
  (windowStartIndex == storedObservationsLength - 1)
@@ -281,6 +279,10 @@ contract TwapOracle is AccessControlled, TwapInterface {
281
279
  } else {
282
280
  delete observations[config.asset][windowStartIndex];
283
281
  }
282
+
283
+ unchecked {
284
+ ++windowStartIndex;
285
+ }
284
286
  }
285
287
 
286
288
  observations[config.asset].push(Observation(currentTimestamp, cumulativePrice));
@@ -299,10 +301,10 @@ contract TwapOracle is AccessControlled, TwapInterface {
299
301
  * @param vToken vToken address
300
302
  * @return asset underlying asset address
301
303
  */
302
- function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
303
- if (address(vToken) == vBnb) {
304
+ function _getUnderlyingAsset(address vToken) private view returns (address asset) {
305
+ if (vToken == vBnb) {
304
306
  asset = WBNB;
305
- } else if (address(vToken) == vai) {
307
+ } else if (vToken == vai) {
306
308
  asset = vai;
307
309
  } else {
308
310
  asset = VBep20Interface(vToken).underlying();
@@ -20,7 +20,7 @@ contract MockBinanceFeedRegistry is FeedRegistryInterface {
20
20
  returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
21
21
  {
22
22
  quote;
23
- return (0, int256(assetPrices[base]), 0, 0, 0);
23
+ return (0, int256(assetPrices[base]), 0, block.timestamp - 10, 0);
24
24
  }
25
25
 
26
26
  function decimalsByName(string memory base, string memory quote) external view override returns (uint8) {
@@ -3,23 +3,17 @@ pragma solidity 0.8.13;
3
3
 
4
4
  import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
5
5
  import "../../interfaces/VBep20Interface.sol";
6
- import "../../interfaces/FeedRegistryInterface.sol";
7
6
 
8
7
  contract MockBinanceOracle is OwnableUpgradeable {
9
8
  mapping(address => uint256) public assetPrices;
10
9
 
11
- FeedRegistryInterface public feedRegistry;
12
-
13
10
  constructor() {}
14
11
 
15
12
  function setPrice(address asset, uint256 price) external {
16
13
  assetPrices[asset] = price;
17
14
  }
18
15
 
19
- function initialize(FeedRegistryInterface feed) public initializer {
20
- __Ownable_init();
21
- feedRegistry = feed;
22
- }
16
+ function initialize() public initializer {}
23
17
 
24
18
  function getUnderlyingPrice(address vToken) public view returns (uint256) {
25
19
  address token = VBep20Interface(vToken).underlying();
@@ -20,7 +20,7 @@ contract MockPythOracle is OwnableUpgradeable {
20
20
 
21
21
  function initialize(address underlyingPythOracle_) public initializer {
22
22
  __Ownable_init();
23
- require(underlyingPythOracle_ != address(0), "pyth oracle cannot be zero address");
23
+ if (underlyingPythOracle_ == address(0)) revert("pyth oracle cannot be zero address");
24
24
  underlyingPythOracle = IPyth(underlyingPythOracle_);
25
25
  }
26
26
 
@@ -19,7 +19,7 @@ contract MockTwapOracle is OwnableUpgradeable {
19
19
 
20
20
  function initialize(address vBNB_) public initializer {
21
21
  __Ownable_init();
22
- require(vBNB_ != address(0), "vBNB can't be zero address");
22
+ if (vBNB_ == address(0)) revert("vBNB can't be zero address");
23
23
  vBNB = vBNB_;
24
24
  }
25
25
 
@@ -0,0 +1,6 @@
1
+ // SPDX-License-Identifier: BSD-3-Clause
2
+ pragma solidity 0.8.13;
3
+ import "@openzeppelin/contracts/access/AccessControl.sol";
4
+ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol";
5
+
6
+ contract AccessControlManagerScenario is AccessControlManager {}
@@ -10,6 +10,10 @@ contract BEP20Harness is ERC20 {
10
10
  decimalsInternal = decimals_;
11
11
  }
12
12
 
13
+ function faucet(uint256 amount) external {
14
+ _mint(msg.sender, amount);
15
+ }
16
+
13
17
  function decimals() public view virtual override returns (uint8) {
14
18
  return decimalsInternal;
15
19
  }
@@ -18,8 +18,11 @@ contract MockPyth is AbstractPyth {
18
18
  // simply update price feeds
19
19
  function updatePriceFeedsHarness(PythStructs.PriceFeed[] calldata feeds) external {
20
20
  require(feeds.length > 0, "feeds length must > 0");
21
- for (uint256 i = 0; i < feeds.length; ++i) {
21
+ for (uint256 i = 0; i < feeds.length; ) {
22
22
  priceFeeds[feeds[i].id] = feeds[i];
23
+ unchecked {
24
+ ++i;
25
+ }
23
26
  }
24
27
  }
25
28
 
@@ -41,7 +44,7 @@ contract MockPyth is AbstractPyth {
41
44
  // We set it to 1.
42
45
  uint16 chainId = 1;
43
46
 
44
- for (uint256 i = 0; i < updateData.length; i++) {
47
+ for (uint256 i = 0; i < updateData.length; ) {
45
48
  PythStructs.PriceFeed memory priceFeed = abi.decode(updateData[i], (PythStructs.PriceFeed));
46
49
 
47
50
  bool fresh = false;
@@ -64,6 +67,10 @@ contract MockPyth is AbstractPyth {
64
67
  priceFeed.price.price,
65
68
  priceFeed.price.conf
66
69
  );
70
+
71
+ unchecked {
72
+ i++;
73
+ }
67
74
  }
68
75
 
69
76
  // In the real contract, the input of this function contains multiple batches that each contain multiple prices.
@@ -0,0 +1 @@
1
+ 56