@venusprotocol/oracle 1.6.11-dev.3 → 1.6.11-dev.5

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 (128) hide show
  1. package/contracts/ResilientOracle.sol +13 -10
  2. package/contracts/interfaces/PythInterface.sol +4 -1
  3. package/contracts/oracles/BinanceOracle.sol +13 -8
  4. package/contracts/oracles/BoundValidator.sol +4 -8
  5. package/contracts/oracles/ChainlinkOracle.sol +16 -8
  6. package/contracts/oracles/PythOracle.sol +15 -11
  7. package/contracts/oracles/TwapOracle.sol +13 -9
  8. package/contracts/test/MockPyth.sol +9 -2
  9. package/package.json +1 -1
  10. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
  11. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
  12. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
  13. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
  14. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
  15. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
  16. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
  17. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
  18. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
  19. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
  20. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
  21. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
  22. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
  23. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
  24. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
  25. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
  26. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
  27. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
  28. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
  29. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
  30. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
  31. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
  32. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
  33. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
  34. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
  35. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
  36. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
  37. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
  38. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
  39. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
  40. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
  41. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
  42. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
  43. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
  44. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
  45. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
  46. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
  47. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
  48. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
  49. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
  50. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
  51. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
  52. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
  53. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
  54. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +0 -4
  55. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +0 -181
  56. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +0 -4
  57. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +0 -282
  58. package/artifacts/build-info/669ba4532c64b244397816b0f72e9870.json +0 -1
  59. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
  60. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
  61. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
  62. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
  63. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
  64. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
  65. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
  66. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
  67. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
  68. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
  69. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
  70. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
  71. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
  72. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
  73. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
  74. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
  75. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
  76. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
  77. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
  78. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
  79. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
  80. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
  81. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
  82. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
  83. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
  84. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
  85. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
  86. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
  87. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
  88. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
  89. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
  90. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -342
  91. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
  92. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
  93. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
  94. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -468
  95. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
  96. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -439
  97. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
  98. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -663
  99. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
  100. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
  101. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
  102. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -144
  103. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
  104. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
  105. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
  106. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
  107. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
  108. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
  109. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +0 -4
  110. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +0 -364
  111. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
  112. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -315
  113. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
  114. package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
  115. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
  116. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
  117. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
  118. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
  119. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
  120. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
  121. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
  122. package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
  123. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
  124. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
  125. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
  126. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
  127. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
  128. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +0 -333
@@ -84,7 +84,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
84
84
  /// @param vBnbAddress The address of the vBNB
85
85
  /// @param vaiAddress The address of the VAI
86
86
  /// @custom:oz-upgrades-unsafe-allow constructor
87
- constructor(address vBnbAddress, address vaiAddress) notNullAddress(vBnbAddress) {
87
+ constructor(address vBnbAddress, address vaiAddress) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) {
88
88
  vBnb = vBnbAddress;
89
89
  vai = vaiAddress;
90
90
  _disableInitializers();
@@ -112,14 +112,16 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
112
112
  * @notice Batch sets token configs
113
113
  * @param tokenConfigs_ Token config array
114
114
  * @custom:access Only Governance
115
- * @custom:error Throws a length error if the lenght of the token configs array is 0
115
+ * @custom:error Throws a length error if the length of the token configs array is 0
116
116
  */
117
117
  function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
118
- _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
119
118
  if (tokenConfigs_.length == 0) revert("length can't be 0");
120
119
  uint256 numTokenConfigs = tokenConfigs_.length;
121
- for (uint256 i; i < numTokenConfigs; ++i) {
120
+ for (uint256 i; i < numTokenConfigs; ) {
122
121
  setTokenConfig(tokenConfigs_[i]);
122
+ unchecked {
123
+ ++i;
124
+ }
123
125
  }
124
126
  }
125
127
 
@@ -140,7 +142,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
140
142
  address oracle,
141
143
  OracleRole role
142
144
  ) external notNullAddress(asset) checkTokenConfigExistence(asset) {
143
- _checkAccessAllowed("setOracle(address,address,OracleRole)");
145
+ _checkAccessAllowed("setOracle(address,address,uint8)");
144
146
  if (oracle == address(0) && role == OracleRole.MAIN) revert("can't set zero address to main oracle");
145
147
  tokenConfigs[asset].oracles[uint256(role)] = oracle;
146
148
  emit OracleSet(asset, oracle, uint256(role));
@@ -160,20 +162,20 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
160
162
  OracleRole role,
161
163
  bool enable
162
164
  ) external notNullAddress(asset) checkTokenConfigExistence(asset) {
163
- _checkAccessAllowed("enableOracle(address,OracleRole,bool)");
165
+ _checkAccessAllowed("enableOracle(address,uint8,bool)");
164
166
  tokenConfigs[asset].enableFlagsForOracles[uint256(role)] = enable;
165
167
  emit OracleEnabled(asset, uint256(role), enable);
166
168
  }
167
169
 
168
170
  /**
169
- * @notice Updates the pivot oracle price. Currently using TWAP
171
+ * @notice Updates the TWAP pivot oracle price.
170
172
  * @dev This function should always be called before calling getUnderlyingPrice
171
173
  * @param vToken vToken address
172
174
  */
173
175
  function updatePrice(address vToken) external override {
174
176
  (address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
175
177
  if (pivotOracle != address(0) && pivotOracleEnabled) {
176
- //if **pivot** oracle is PythOrcle it will revert so we need to catch the revert
178
+ //if pivot oracle is not TwapOracle it will revert so we need to catch the revert
177
179
  try TwapInterface(pivotOracle).updateTwap(vToken) {} catch {}
178
180
  }
179
181
  }
@@ -192,7 +194,8 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
192
194
  * @notice Gets price of the underlying asset for a given vToken. Validation flow:
193
195
  * - Check if the oracle is paused globally
194
196
  * - Validate price from main oracle against pivot oracle
195
- * - Validate price from fallback oracle against pivot oracle or main oracle if the first validation failed
197
+ * - Validate price from fallback oracle against pivot oracle if the first validation failed
198
+ * - Validate price from main oracle against fallback oracle if the second validation failed
196
199
  * In the case that the pivot oracle is not available but main price is available and validation is successful,
197
200
  * main oracle price is returned.
198
201
  * @param vToken vToken address
@@ -231,7 +234,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
231
234
  if (
232
235
  mainPrice != INVALID_PRICE &&
233
236
  fallbackPrice != INVALID_PRICE &&
234
- boundValidator.validatePriceWithAnchorPrice(vToken, fallbackPrice, mainPrice)
237
+ boundValidator.validatePriceWithAnchorPrice(vToken, mainPrice, fallbackPrice)
235
238
  ) {
236
239
  return mainPrice;
237
240
  }
@@ -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");
@@ -6,9 +6,10 @@ import "../interfaces/VBep20Interface.sol";
6
6
  import "../interfaces/SIDRegistryInterface.sol";
7
7
  import "../interfaces/FeedRegistryInterface.sol";
8
8
  import "../interfaces/PublicResolverInterface.sol";
9
+ import "../interfaces/OracleInterface.sol";
9
10
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
10
11
 
11
- contract BinanceOracle is AccessControlledV8 {
12
+ contract BinanceOracle is AccessControlledV8, OracleInterface {
12
13
  address public sidRegistryAddress;
13
14
 
14
15
  /// @notice vBNB address
@@ -44,7 +45,7 @@ contract BinanceOracle is AccessControlledV8 {
44
45
  function setMaxStalePeriod(string memory symbol, uint256 _maxStalePeriod) external {
45
46
  _checkAccessAllowed("setMaxStalePeriod(string,uint256)");
46
47
  if (_maxStalePeriod == 0) revert("stale period can't be zero");
47
- if (compare(symbol, "")) revert("symbol cannot be empty");
48
+ if (bytes(symbol).length == 0) revert("symbol cannot be empty");
48
49
 
49
50
  maxStalePeriod[symbol] = _maxStalePeriod;
50
51
  emit MaxStalePeriodAdded(symbol, _maxStalePeriod);
@@ -79,19 +80,19 @@ contract BinanceOracle is AccessControlledV8 {
79
80
  * @param vToken Address of the vToken
80
81
  * @return Price in USD
81
82
  */
82
- function getUnderlyingPrice(VBep20Interface vToken) public view returns (uint256) {
83
+ function getUnderlyingPrice(address vToken) public view override returns (uint256) {
83
84
  string memory symbol;
84
85
  uint256 decimals;
85
86
 
86
87
  // VBNB token doesn't have `underlying` method
87
- if (address(vToken) == vBnb) {
88
+ if (vToken == vBnb) {
88
89
  symbol = "BNB";
89
90
  decimals = 18;
90
- } else if (address(vToken) == vai) {
91
+ } else if (vToken == vai) {
91
92
  symbol = "VAI";
92
93
  decimals = 18;
93
94
  } else {
94
- IERC20Metadata underlyingToken = IERC20Metadata(vToken.underlying());
95
+ IERC20Metadata underlyingToken = IERC20Metadata(VBep20Interface(vToken).underlying());
95
96
  symbol = underlyingToken.symbol();
96
97
  decimals = underlyingToken.decimals();
97
98
  }
@@ -106,7 +107,11 @@ contract BinanceOracle is AccessControlledV8 {
106
107
  if (answer <= 0) revert("invalid binance oracle price");
107
108
  if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
108
109
 
109
- uint256 deltaTime = block.timestamp - updatedAt;
110
+ uint256 deltaTime;
111
+ unchecked {
112
+ deltaTime = block.timestamp - updatedAt;
113
+ }
114
+
110
115
  if (deltaTime > maxStalePeriod[symbol]) revert("binance oracle price expired");
111
116
 
112
117
  uint256 decimalDelta = feedRegistry.decimalsByName(symbol, "USD");
@@ -120,6 +125,6 @@ contract BinanceOracle is AccessControlledV8 {
120
125
  * @return equal Returns true if both are equal or else false.
121
126
  */
122
127
  function compare(string memory str1, string memory str2) internal pure returns (bool) {
123
- return keccak256(abi.encodePacked(str1)) == keccak256(abi.encodePacked(str2));
128
+ return keccak256(bytes(str1)) == keccak256(bytes(str2));
124
129
  }
125
130
  }
@@ -56,12 +56,13 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
56
56
  * @custom:event Emits ValidateConfigAdded for each validation config that is successfully set
57
57
  */
58
58
  function setValidateConfigs(ValidateConfig[] memory configs) external virtual {
59
- _checkAccessAllowed("setValidateConfigs(ValidateConfig[])");
60
-
61
59
  uint256 length = configs.length;
62
60
  if (length == 0) revert("invalid validate config length");
63
- for (uint256 i; i < length; ++i) {
61
+ for (uint256 i; i < length; ) {
64
62
  setValidateConfig(configs[i]);
63
+ unchecked {
64
+ ++i;
65
+ }
65
66
  }
66
67
  }
67
68
 
@@ -141,9 +142,4 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
141
142
  asset = VBep20Interface(vToken).underlying();
142
143
  }
143
144
  }
144
-
145
- // BoundValidator is to get inherited, so it's a good practice to add some storage gaps like
146
- // OpenZepplin proposed in their contracts: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
147
- // solhint-disable-next-line
148
- uint256[49] private __gap;
149
145
  }
@@ -72,11 +72,12 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
72
72
  VBep20Interface vToken,
73
73
  uint256 underlyingPriceMantissa
74
74
  ) external notNullAddress(address(vToken)) {
75
- _checkAccessAllowed("setUnderlyingPrice(VBep20Interface,uint256)");
75
+ _checkAccessAllowed("setUnderlyingPrice(address,uint256)");
76
76
 
77
77
  address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
78
- emit PricePosted(asset, prices[asset], underlyingPriceMantissa, underlyingPriceMantissa);
78
+ uint256 previousPriceMantissa = prices[asset];
79
79
  prices[asset] = underlyingPriceMantissa;
80
+ emit PricePosted(asset, previousPriceMantissa, prices[asset], prices[asset]);
80
81
  }
81
82
 
82
83
  /**
@@ -89,8 +90,9 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
89
90
  function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) {
90
91
  _checkAccessAllowed("setDirectPrice(address,uint256)");
91
92
 
93
+ uint256 previousPriceMantissa = prices[asset];
92
94
  prices[asset] = price;
93
- emit PricePosted(asset, prices[asset], price, price);
95
+ emit PricePosted(asset, previousPriceMantissa, price, price);
94
96
  }
95
97
 
96
98
  /**
@@ -100,11 +102,13 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
100
102
  * @custom:error Zero length error thrown, if length of the array in parameter is 0
101
103
  */
102
104
  function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
103
- _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
104
105
  if (tokenConfigs_.length == 0) revert("length can't be 0");
105
106
  uint256 numTokenConfigs = tokenConfigs_.length;
106
- for (uint256 i; i < numTokenConfigs; ++i) {
107
+ for (uint256 i; i < numTokenConfigs; ) {
107
108
  setTokenConfig(tokenConfigs_[i]);
109
+ unchecked {
110
+ ++i;
111
+ }
108
112
  }
109
113
  }
110
114
 
@@ -180,7 +184,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
180
184
  }
181
185
 
182
186
  /**
183
- * @notice Get the Chainlink price for the underlying asset of a given vToken, revert if token config doesn't exit
187
+ * @notice Get the Chainlink price for the underlying asset of a given vToken, revert if token config doesn't exist
184
188
  * @dev The precision of the price feed is used to ensure the returned price has 18 decimals of precision
185
189
  * @param asset Underlying asset address
186
190
  * @return price Underlying price in USD, with 18 decimals of precision
@@ -203,10 +207,14 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
203
207
  uint256 decimalDelta = uint256(18) - feed.decimals();
204
208
 
205
209
  (, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
206
- if (answer == 0) revert("chainlink price must be positive");
210
+ if (answer <= 0) revert("chainlink price must be positive");
207
211
  if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
208
212
 
209
- uint256 deltaTime = block.timestamp - updatedAt;
213
+ uint256 deltaTime;
214
+ unchecked {
215
+ deltaTime = block.timestamp - updatedAt;
216
+ }
217
+
210
218
  if (deltaTime > maxStalePeriod) revert("chainlink price expired");
211
219
 
212
220
  return uint256(answer) * (10 ** decimalDelta);
@@ -73,11 +73,13 @@ contract PythOracle is AccessControlledV8, OracleInterface {
73
73
  * @custom:error Zero length error is thrown if length of the array in parameter is 0
74
74
  */
75
75
  function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
76
- _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
77
76
  if (tokenConfigs_.length == 0) revert("length can't be 0");
78
77
  uint256 numTokenConfigs = tokenConfigs_.length;
79
- for (uint256 i; i < numTokenConfigs; ++i) {
78
+ for (uint256 i; i < numTokenConfigs; ) {
80
79
  setTokenConfig(tokenConfigs_[i]);
80
+ unchecked {
81
+ ++i;
82
+ }
81
83
  }
82
84
  }
83
85
 
@@ -91,7 +93,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
91
93
  function setUnderlyingPythOracle(
92
94
  IPyth underlyingPythOracle_
93
95
  ) external notNullAddress(address(underlyingPythOracle_)) {
94
- _checkAccessAllowed("setUnderlyingPythOracle(IPyth)");
96
+ _checkAccessAllowed("setUnderlyingPythOracle(address)");
95
97
  underlyingPythOracle = underlyingPythOracle_;
96
98
  emit PythOracleSet(address(underlyingPythOracle_));
97
99
  }
@@ -101,10 +103,12 @@ contract PythOracle is AccessControlledV8, OracleInterface {
101
103
  * @param underlyingPythOracle_ Address of the Pyth oracle
102
104
  * @param accessControlManager_ Address of the access control manager contract
103
105
  */
104
- function initialize(address underlyingPythOracle_, address accessControlManager_) public initializer {
106
+ function initialize(
107
+ address underlyingPythOracle_,
108
+ address accessControlManager_
109
+ ) public initializer notNullAddress(underlyingPythOracle_) {
105
110
  __AccessControlled_init(accessControlManager_);
106
111
 
107
- if (underlyingPythOracle_ == address(0)) revert("pyth oracle cannot be zero address");
108
112
  underlyingPythOracle = IPyth(underlyingPythOracle_);
109
113
  emit PythOracleSet(underlyingPythOracle_);
110
114
  }
@@ -127,22 +131,22 @@ contract PythOracle is AccessControlledV8, OracleInterface {
127
131
  * @notice Get price of underlying asset of the input vToken, under the hood this function
128
132
  * get price from Pyth contract, the prices of which are updated externally
129
133
  * @param vToken vToken address
130
- * @return price Underlying price with a precision of 10 decimals
134
+ * @return price Underlying price with a precision of 18 decimals
131
135
  * @custom:error Zero address error thrown if underlyingPythOracle address is null
132
136
  * @custom:error Zero address error thrown if asset address is null
133
137
  * @custom:error Range error thrown if price of Pyth oracle is not greater than zero
134
138
  */
135
- function getUnderlyingPrice(address vToken) public view override returns (uint256) {
136
- if (address(underlyingPythOracle) == address(0)) revert("Pyth oracle is zero address");
137
-
139
+ function getUnderlyingPrice(
140
+ address vToken
141
+ ) public view override notNullAddress(address(underlyingPythOracle)) returns (uint256) {
138
142
  address asset;
139
143
  uint256 decimals;
140
144
 
141
145
  // VBNB token doesn't have `underlying` method
142
- if (address(vToken) == vBnb) {
146
+ if (vToken == vBnb) {
143
147
  asset = BNB_ADDR;
144
148
  decimals = 18;
145
- } else if (address(vToken) == vai) {
149
+ } else if (vToken == vai) {
146
150
  asset = vai;
147
151
  decimals = 18;
148
152
  } else {
@@ -101,11 +101,13 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
101
101
  * @custom:error Zero length error thrown, if length of the config array is 0
102
102
  */
103
103
  function setTokenConfigs(TokenConfig[] memory configs) external {
104
- _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
105
104
  if (configs.length == 0) revert("length can't be 0");
106
105
  uint256 numTokenConfigs = configs.length;
107
- for (uint256 i; i < numTokenConfigs; ++i) {
106
+ for (uint256 i; i < numTokenConfigs; ) {
108
107
  setTokenConfig(configs[i]);
108
+ unchecked {
109
+ ++i;
110
+ }
109
111
  }
110
112
  }
111
113
 
@@ -153,7 +155,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
153
155
  _checkAccessAllowed("setTokenConfig(TokenConfig)");
154
156
 
155
157
  if (config.anchorPeriod == 0) revert("anchor period must be positive");
156
- if (config.baseUnit == 0) revert("base unit must be positive");
157
158
  if (config.baseUnit != 10 ** IERC20Metadata(config.asset).decimals())
158
159
  revert("base unit decimals must be same as asset decimals");
159
160
 
@@ -214,7 +215,10 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
214
215
  // This should be impossible, but better safe than sorry
215
216
  if (block.timestamp < oldTimestamp) revert("now must come after before");
216
217
 
217
- uint256 timeElapsed = block.timestamp - oldTimestamp;
218
+ uint256 timeElapsed;
219
+ unchecked {
220
+ timeElapsed = block.timestamp - oldTimestamp;
221
+ }
218
222
 
219
223
  // Calculate Pancake *twap**
220
224
  FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112(
@@ -263,11 +267,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
263
267
  Observation[] memory storedObservations = observations[config.asset];
264
268
 
265
269
  uint256 storedObservationsLength = storedObservations.length;
266
- for (
267
- uint256 windowStartIndex = windowStart[config.asset];
268
- windowStartIndex < storedObservationsLength;
269
- ++windowStartIndex
270
- ) {
270
+ for (uint256 windowStartIndex = windowStart[config.asset]; windowStartIndex < storedObservationsLength; ) {
271
271
  if (
272
272
  (storedObservations[windowStartIndex].timestamp >= windowStartTimestamp) ||
273
273
  (windowStartIndex == storedObservationsLength - 1)
@@ -279,6 +279,10 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
279
279
  } else {
280
280
  delete observations[config.asset][windowStartIndex];
281
281
  }
282
+
283
+ unchecked {
284
+ ++windowStartIndex;
285
+ }
282
286
  }
283
287
 
284
288
  observations[config.asset].push(Observation(currentTimestamp, cumulativePrice));
@@ -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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@venusprotocol/oracle",
3
3
  "description": "Venus Protocol Price Oracle",
4
- "version": "1.6.11-dev.3",
4
+ "version": "1.6.11-dev.5",
5
5
  "author": "",
6
6
  "engines": {
7
7
  "node": ">=14.x.x"
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../../../../build-info/669ba4532c64b244397816b0f72e9870.json"
4
- }
@@ -1,138 +0,0 @@
1
- {
2
- "_format": "hh-sol-artifact-1",
3
- "contractName": "AggregatorInterface",
4
- "sourceName": "@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol",
5
- "abi": [
6
- {
7
- "anonymous": false,
8
- "inputs": [
9
- {
10
- "indexed": true,
11
- "internalType": "int256",
12
- "name": "current",
13
- "type": "int256"
14
- },
15
- {
16
- "indexed": true,
17
- "internalType": "uint256",
18
- "name": "roundId",
19
- "type": "uint256"
20
- },
21
- {
22
- "indexed": false,
23
- "internalType": "uint256",
24
- "name": "updatedAt",
25
- "type": "uint256"
26
- }
27
- ],
28
- "name": "AnswerUpdated",
29
- "type": "event"
30
- },
31
- {
32
- "anonymous": false,
33
- "inputs": [
34
- {
35
- "indexed": true,
36
- "internalType": "uint256",
37
- "name": "roundId",
38
- "type": "uint256"
39
- },
40
- {
41
- "indexed": true,
42
- "internalType": "address",
43
- "name": "startedBy",
44
- "type": "address"
45
- },
46
- {
47
- "indexed": false,
48
- "internalType": "uint256",
49
- "name": "startedAt",
50
- "type": "uint256"
51
- }
52
- ],
53
- "name": "NewRound",
54
- "type": "event"
55
- },
56
- {
57
- "inputs": [
58
- {
59
- "internalType": "uint256",
60
- "name": "roundId",
61
- "type": "uint256"
62
- }
63
- ],
64
- "name": "getAnswer",
65
- "outputs": [
66
- {
67
- "internalType": "int256",
68
- "name": "",
69
- "type": "int256"
70
- }
71
- ],
72
- "stateMutability": "view",
73
- "type": "function"
74
- },
75
- {
76
- "inputs": [
77
- {
78
- "internalType": "uint256",
79
- "name": "roundId",
80
- "type": "uint256"
81
- }
82
- ],
83
- "name": "getTimestamp",
84
- "outputs": [
85
- {
86
- "internalType": "uint256",
87
- "name": "",
88
- "type": "uint256"
89
- }
90
- ],
91
- "stateMutability": "view",
92
- "type": "function"
93
- },
94
- {
95
- "inputs": [],
96
- "name": "latestAnswer",
97
- "outputs": [
98
- {
99
- "internalType": "int256",
100
- "name": "",
101
- "type": "int256"
102
- }
103
- ],
104
- "stateMutability": "view",
105
- "type": "function"
106
- },
107
- {
108
- "inputs": [],
109
- "name": "latestRound",
110
- "outputs": [
111
- {
112
- "internalType": "uint256",
113
- "name": "",
114
- "type": "uint256"
115
- }
116
- ],
117
- "stateMutability": "view",
118
- "type": "function"
119
- },
120
- {
121
- "inputs": [],
122
- "name": "latestTimestamp",
123
- "outputs": [
124
- {
125
- "internalType": "uint256",
126
- "name": "",
127
- "type": "uint256"
128
- }
129
- ],
130
- "stateMutability": "view",
131
- "type": "function"
132
- }
133
- ],
134
- "bytecode": "0x",
135
- "deployedBytecode": "0x",
136
- "linkReferences": {},
137
- "deployedLinkReferences": {}
138
- }
@@ -1,4 +0,0 @@
1
- {
2
- "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../../../../build-info/669ba4532c64b244397816b0f72e9870.json"
4
- }