@venusprotocol/oracle 1.6.9 → 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 +140 -17
  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
@@ -3,22 +3,22 @@ pragma solidity 0.8.13;
3
3
 
4
4
  import "../interfaces/VBep20Interface.sol";
5
5
  import "../interfaces/OracleInterface.sol";
6
- import "../Governance/AccessControlled.sol";
7
-
8
- struct ValidateConfig {
9
- /// @notice asset address
10
- address asset;
11
- /// @notice Upper bound of deviation between reported price and anchor price,
12
- /// beyond which the reported price will be invalidated
13
- uint256 upperBoundRatio;
14
- /// @notice Lower bound of deviation between reported price and anchor price,
15
- /// below which the reported price will be invalidated
16
- uint256 lowerBoundRatio;
17
- }
6
+ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
18
7
 
19
8
  // BoundValidator provides some common functions and can be used
20
9
  // to wrap up other contracts to form pivot oracles
21
- contract BoundValidator is AccessControlled, BoundValidatorInterface {
10
+ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
11
+ struct ValidateConfig {
12
+ /// @notice asset address
13
+ address asset;
14
+ /// @notice Upper bound of deviation between reported price and anchor price,
15
+ /// beyond which the reported price will be invalidated
16
+ uint256 upperBoundRatio;
17
+ /// @notice Lower bound of deviation between reported price and anchor price,
18
+ /// below which the reported price will be invalidated
19
+ uint256 lowerBoundRatio;
20
+ }
21
+
22
22
  /// @notice validation configs by asset
23
23
  mapping(address => ValidateConfig) public validateConfigs;
24
24
 
@@ -41,8 +41,8 @@ contract BoundValidator is AccessControlled, BoundValidatorInterface {
41
41
  /// @param vaiAddress The address of the VAI
42
42
  /// @custom:oz-upgrades-unsafe-allow constructor
43
43
  constructor(address vBnbAddress, address vaiAddress) {
44
- require(vBnbAddress != address(0), "can't be a zero address");
45
- require(vaiAddress != address(0), "can't be a zero address");
44
+ if (vBnbAddress == address(0)) revert("vBNB can't be zero address");
45
+ if (vaiAddress == address(0)) revert("VAI can't be zero address");
46
46
  vBnb = vBnbAddress;
47
47
  vai = vaiAddress;
48
48
  _disableInitializers();
@@ -55,12 +55,14 @@ contract BoundValidator is AccessControlled, BoundValidatorInterface {
55
55
  * @custom:error Zero length error is thrown if length of the config array is 0
56
56
  * @custom:event Emits ValidateConfigAdded for each validation config that is successfully set
57
57
  */
58
- function setValidateConfigs(ValidateConfig[] memory configs) external virtual {
59
- _checkAccessAllowed("setValidateConfigs(ValidateConfig[])");
60
-
61
- require(configs.length > 0, "invalid validate config length");
62
- for (uint256 i; i < configs.length; ++i) {
58
+ function setValidateConfigs(ValidateConfig[] memory configs) external {
59
+ uint256 length = configs.length;
60
+ if (length == 0) revert("invalid validate config length");
61
+ for (uint256 i; i < length; ) {
63
62
  setValidateConfig(configs[i]);
63
+ unchecked {
64
+ ++i;
65
+ }
64
66
  }
65
67
  }
66
68
 
@@ -68,28 +70,8 @@ contract BoundValidator is AccessControlled, BoundValidatorInterface {
68
70
  * @notice Initializes the owner of the contract
69
71
  * @param accessControlManager_ Address of the access control manager contract
70
72
  */
71
- function initialize(address accessControlManager_) public initializer {
72
- __Ownable2Step_init();
73
- __AccessControlled_init_unchained(accessControlManager_);
74
- }
75
-
76
- /**
77
- * @notice Add a single validation config
78
- * @param config Validation config struct
79
- * @custom:access Only Governance
80
- * @custom:error Null address error is thrown if asset address is null
81
- * @custom:error Range error thrown if bound ratio is not positive
82
- * @custom:error Range error thrown if lower bound is greater than upper bound
83
- * @custom:event Emits ValidateConfigAdded when a validation config is successfully set
84
- */
85
- function setValidateConfig(ValidateConfig memory config) public virtual {
86
- _checkAccessAllowed("setValidateConfig(ValidateConfig)");
87
-
88
- require(config.asset != address(0), "asset can't be zero address");
89
- require(config.upperBoundRatio > 0 && config.lowerBoundRatio > 0, "bound must be positive");
90
- require(config.upperBoundRatio > config.lowerBoundRatio, "upper bound must be higher than lowner bound");
91
- validateConfigs[config.asset] = config;
92
- emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
73
+ function initialize(address accessControlManager_) external initializer {
74
+ __AccessControlled_init(accessControlManager_);
93
75
  }
94
76
 
95
77
  /**
@@ -103,23 +85,43 @@ contract BoundValidator is AccessControlled, BoundValidatorInterface {
103
85
  address vToken,
104
86
  uint256 reportedPrice,
105
87
  uint256 anchorPrice
106
- ) public view virtual override returns (bool) {
88
+ ) external view override returns (bool) {
107
89
  address asset = _getUnderlyingAsset(vToken);
108
90
 
109
- require(validateConfigs[asset].upperBoundRatio != 0, "validation config not exist");
110
- require(anchorPrice != 0, "anchor price is not valid");
91
+ if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
92
+ if (anchorPrice == 0) revert("anchor price is not valid");
111
93
  return _isWithinAnchor(asset, reportedPrice, anchorPrice);
112
94
  }
113
95
 
96
+ /**
97
+ * @notice Add a single validation config
98
+ * @param config Validation config struct
99
+ * @custom:access Only Governance
100
+ * @custom:error Null address error is thrown if asset address is null
101
+ * @custom:error Range error thrown if bound ratio is not positive
102
+ * @custom:error Range error thrown if lower bound is greater than or equal to upper bound
103
+ * @custom:event Emits ValidateConfigAdded when a validation config is successfully set
104
+ */
105
+ function setValidateConfig(ValidateConfig memory config) public {
106
+ _checkAccessAllowed("setValidateConfig(ValidateConfig)");
107
+
108
+ if (config.asset == address(0)) revert("asset can't be zero address");
109
+ if (config.upperBoundRatio == 0 || config.lowerBoundRatio == 0) revert("bound must be positive");
110
+ if (config.upperBoundRatio <= config.lowerBoundRatio) revert("upper bound must be higher than lowner bound");
111
+ validateConfigs[config.asset] = config;
112
+ emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
113
+ }
114
+
114
115
  /**
115
116
  * @notice Test whether the reported price is within the valid bounds
116
117
  * @param asset Asset address
117
118
  * @param reportedPrice The price to be tested
118
119
  * @param anchorPrice The reported price must be within the the valid bounds of this price
119
120
  */
120
- function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) internal view returns (bool) {
121
- if (reportedPrice > 0) {
122
- uint256 anchorRatio = (anchorPrice * 100e16) / reportedPrice;
121
+ function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) private view returns (bool) {
122
+ if (reportedPrice != 0) {
123
+ // we need to multiply anchorPrice by 1e18 to make the ratio 18 decimals
124
+ uint256 anchorRatio = (anchorPrice * 1e18) / reportedPrice;
123
125
  uint256 upperBoundAnchorRatio = validateConfigs[asset].upperBoundRatio;
124
126
  uint256 lowerBoundAnchorRatio = validateConfigs[asset].lowerBoundRatio;
125
127
  return anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio;
@@ -132,7 +134,7 @@ contract BoundValidator is AccessControlled, BoundValidatorInterface {
132
134
  * @param vToken vToken address
133
135
  * @return asset underlying asset address
134
136
  */
135
- function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
137
+ function _getUnderlyingAsset(address vToken) private view returns (address asset) {
136
138
  if (address(vToken) == vBnb) {
137
139
  asset = BNB_ADDR;
138
140
  } else if (address(vToken) == vai) {
@@ -141,9 +143,4 @@ contract BoundValidator is AccessControlled, BoundValidatorInterface {
141
143
  asset = VBep20Interface(vToken).underlying();
142
144
  }
143
145
  }
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
146
  }
@@ -3,20 +3,21 @@ pragma solidity 0.8.13;
3
3
 
4
4
  import "../interfaces/VBep20Interface.sol";
5
5
  import "../interfaces/OracleInterface.sol";
6
- import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";
7
- import "../Governance/AccessControlled.sol";
8
-
9
- struct TokenConfig {
10
- /// @notice Underlying token address, which can't be a null address and can be used to check if a token is supported
11
- /// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
12
- address asset;
13
- /// @notice Chainlink feed address
14
- address feed;
15
- /// @notice Price expiration period of this asset
16
- uint256 maxStalePeriod;
17
- }
6
+ import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
7
+ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
8
+
9
+ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
10
+ struct TokenConfig {
11
+ /// @notice Underlying token address, which can't be a null address
12
+ /// @notice Used to check if a token is supported
13
+ /// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
14
+ address asset;
15
+ /// @notice Chainlink feed address
16
+ address feed;
17
+ /// @notice Price expiration period of this asset
18
+ uint256 maxStalePeriod;
19
+ }
18
20
 
19
- contract ChainlinkOracle is AccessControlled, OracleInterface {
20
21
  /// @notice vBNB address
21
22
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
22
23
  address public immutable vBnb;
@@ -35,18 +36,13 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
35
36
  mapping(address => TokenConfig) public tokenConfigs;
36
37
 
37
38
  /// @notice Emit when a price is manually set
38
- event PricePosted(
39
- address asset,
40
- uint256 previousPriceMantissa,
41
- uint256 requestedPriceMantissa,
42
- uint256 newPriceMantissa
43
- );
39
+ event PricePosted(address indexed asset, uint256 previousPriceMantissa, uint256 newPriceMantissa);
44
40
 
45
41
  /// @notice Emit when a token config is added
46
- event TokenConfigAdded(address asset, address feed, uint256 maxStalePeriod);
42
+ event TokenConfigAdded(address indexed asset, address feed, uint256 maxStalePeriod);
47
43
 
48
44
  modifier notNullAddress(address someone) {
49
- require(someone != address(0), "can't be zero address");
45
+ if (someone == address(0)) revert("can't be zero address");
50
46
  _;
51
47
  }
52
48
 
@@ -72,11 +68,12 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
72
68
  VBep20Interface vToken,
73
69
  uint256 underlyingPriceMantissa
74
70
  ) external notNullAddress(address(vToken)) {
75
- _checkAccessAllowed("setUnderlyingPrice(VBep20Interface,uint256)");
71
+ _checkAccessAllowed("setUnderlyingPrice(address,uint256)");
76
72
 
77
73
  address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
78
- emit PricePosted(asset, prices[asset], underlyingPriceMantissa, underlyingPriceMantissa);
74
+ uint256 previousPriceMantissa = prices[asset];
79
75
  prices[asset] = underlyingPriceMantissa;
76
+ emit PricePosted(asset, previousPriceMantissa, prices[asset]);
80
77
  }
81
78
 
82
79
  /**
@@ -87,10 +84,11 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
87
84
  * @custom:event Emits PricePosted event on succesfully setup of underlying price
88
85
  */
89
86
  function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) {
90
- _checkAccessAllowed("setDirectPrice(asset,price)");
87
+ _checkAccessAllowed("setDirectPrice(address,uint256)");
91
88
 
89
+ uint256 previousPriceMantissa = prices[asset];
92
90
  prices[asset] = price;
93
- emit PricePosted(asset, prices[asset], price, price);
91
+ emit PricePosted(asset, previousPriceMantissa, price);
94
92
  }
95
93
 
96
94
  /**
@@ -100,11 +98,13 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
100
98
  * @custom:error Zero length error thrown, if length of the array in parameter is 0
101
99
  */
102
100
  function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
103
- _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
104
- require(tokenConfigs_.length > 0, "length can't be 0");
101
+ if (tokenConfigs_.length == 0) revert("length can't be 0");
105
102
  uint256 numTokenConfigs = tokenConfigs_.length;
106
- for (uint256 i; i < numTokenConfigs; ++i) {
103
+ for (uint256 i; i < numTokenConfigs; ) {
107
104
  setTokenConfig(tokenConfigs_[i]);
105
+ unchecked {
106
+ ++i;
107
+ }
108
108
  }
109
109
  }
110
110
 
@@ -112,8 +112,17 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
112
112
  * @notice Initializes the owner of the contract
113
113
  * @param accessControlManager_ Address of the access control manager contract
114
114
  */
115
- function initialize(address accessControlManager_) public initializer {
116
- __AccessControlled_init_unchained(accessControlManager_);
115
+ function initialize(address accessControlManager_) external initializer {
116
+ __AccessControlled_init(accessControlManager_);
117
+ }
118
+
119
+ /**
120
+ * @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
121
+ * @param vToken vToken address
122
+ * @return price Underlying price in USD
123
+ */
124
+ function getUnderlyingPrice(address vToken) external view override returns (uint256) {
125
+ return _getUnderlyingPriceInternal(VBep20Interface(vToken));
117
126
  }
118
127
 
119
128
  /**
@@ -130,20 +139,11 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
130
139
  ) public notNullAddress(tokenConfig.asset) notNullAddress(tokenConfig.feed) {
131
140
  _checkAccessAllowed("setTokenConfig(TokenConfig)");
132
141
 
133
- require(tokenConfig.maxStalePeriod > 0, "stale period can't be zero");
142
+ if (tokenConfig.maxStalePeriod == 0) revert("stale period can't be zero");
134
143
  tokenConfigs[tokenConfig.asset] = tokenConfig;
135
144
  emit TokenConfigAdded(tokenConfig.asset, tokenConfig.feed, tokenConfig.maxStalePeriod);
136
145
  }
137
146
 
138
- /**
139
- * @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
140
- * @param vToken vToken address
141
- * @return price Underlying price in USD
142
- */
143
- function getUnderlyingPrice(address vToken) public view override returns (uint256) {
144
- return _getUnderlyingPriceInternal(VBep20Interface(vToken));
145
- }
146
-
147
147
  /**
148
148
  * @notice Gets the Chainlink price for the underlying asset of a given vToken
149
149
  * or the manually set price if it's been set
@@ -152,7 +152,7 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
152
152
  * @param vToken vToken address
153
153
  * @return price Underlying price in USD
154
154
  */
155
- function _getUnderlyingPriceInternal(VBep20Interface vToken) internal view returns (uint256 price) {
155
+ function _getUnderlyingPriceInternal(VBep20Interface vToken) private view returns (uint256 price) {
156
156
  address token;
157
157
  uint256 decimals;
158
158
 
@@ -175,12 +175,12 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
175
175
  price = _getChainlinkPrice(token);
176
176
  }
177
177
 
178
- uint256 decimalDelta = uint256(18) - uint256(decimals);
178
+ uint256 decimalDelta = 18 - uint256(decimals);
179
179
  return price * (10 ** decimalDelta);
180
180
  }
181
181
 
182
182
  /**
183
- * @notice Get the Chainlink price for the underlying asset of a given vToken, revert if token config doesn't exit
183
+ * @notice Get the Chainlink price for the underlying asset of a given vToken, revert if token config doesn't exist
184
184
  * @dev The precision of the price feed is used to ensure the returned price has 18 decimals of precision
185
185
  * @param asset Underlying asset address
186
186
  * @return price Underlying price in USD, with 18 decimals of precision
@@ -192,27 +192,27 @@ contract ChainlinkOracle is AccessControlled, OracleInterface {
192
192
  */
193
193
  function _getChainlinkPrice(
194
194
  address asset
195
- ) internal view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
195
+ ) private view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
196
196
  TokenConfig memory tokenConfig = tokenConfigs[asset];
197
- AggregatorV2V3Interface feed = AggregatorV2V3Interface(tokenConfig.feed);
197
+ AggregatorV3Interface feed = AggregatorV3Interface(tokenConfig.feed);
198
198
 
199
199
  // note: maxStalePeriod cannot be 0
200
200
  uint256 maxStalePeriod = tokenConfig.maxStalePeriod;
201
201
 
202
202
  // Chainlink USD-denominated feeds store answers at 8 decimals, mostly
203
- uint256 decimalDelta = uint256(18) - feed.decimals();
203
+ uint256 decimalDelta = 18 - feed.decimals();
204
204
 
205
205
  (, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
206
- require(answer > 0, "chainlink price must be positive");
206
+ if (answer <= 0) revert("chainlink price must be positive");
207
+ if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
207
208
 
208
- require(block.timestamp >= updatedAt, "updatedAt exceeds block time");
209
- uint256 deltaTime = block.timestamp - updatedAt;
210
- require(deltaTime <= maxStalePeriod, "chainlink price expired");
209
+ uint256 deltaTime;
210
+ unchecked {
211
+ deltaTime = block.timestamp - updatedAt;
212
+ }
211
213
 
212
- return uint256(answer) * (10 ** decimalDelta);
213
- }
214
+ if (deltaTime > maxStalePeriod) revert("chainlink price expired");
214
215
 
215
- function _compareStrings(string memory a, string memory b) internal pure returns (bool) {
216
- return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
216
+ return uint256(answer) * (10 ** decimalDelta);
217
217
  }
218
218
  }
@@ -1,33 +1,30 @@
1
1
  // SPDX-License-Identifier: BSD-3-Clause
2
2
  pragma solidity 0.8.13;
3
3
 
4
- import "@openzeppelin/contracts/utils/math/SafeMath.sol";
5
4
  import "@openzeppelin/contracts/utils/math/SafeCast.sol";
6
5
  import "@openzeppelin/contracts/utils/math/SignedMath.sol";
7
6
  import "../interfaces/PythInterface.sol";
8
7
  import "../interfaces/OracleInterface.sol";
9
8
  import "../interfaces/VBep20Interface.sol";
10
- import "../Governance/AccessControlled.sol";
11
-
12
- struct TokenConfig {
13
- bytes32 pythId;
14
- address asset;
15
- uint64 maxStalePeriod;
16
- }
9
+ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
17
10
 
18
11
  /**
19
12
  * PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores the
20
13
  * updated prices from external sources
21
14
  */
22
- contract PythOracle is AccessControlled, OracleInterface {
23
- using SafeMath for uint256;
24
-
15
+ contract PythOracle is AccessControlledV8, OracleInterface {
25
16
  // To calculate 10 ** n(which is a signed type)
26
17
  using SignedMath for int256;
27
18
 
28
19
  // To cast int64/int8 types from Pyth to unsigned types
29
20
  using SafeCast for int256;
30
21
 
22
+ struct TokenConfig {
23
+ bytes32 pythId;
24
+ address asset;
25
+ uint64 maxStalePeriod;
26
+ }
27
+
31
28
  /// @notice Exponent scale (decimal precision) of prices
32
29
  uint256 public constant EXP_SCALE = 1e18;
33
30
 
@@ -49,13 +46,13 @@ contract PythOracle is AccessControlled, OracleInterface {
49
46
  mapping(address => TokenConfig) public tokenConfigs;
50
47
 
51
48
  /// @notice Emit when setting a new pyth oracle address
52
- event PythOracleSet(address indexed newPythOracle);
49
+ event PythOracleSet(address indexed oldPythOracle, address indexed newPythOracle);
53
50
 
54
51
  /// @notice Emit when a token config is added
55
52
  event TokenConfigAdded(address indexed vToken, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
56
53
 
57
54
  modifier notNullAddress(address someone) {
58
- require(someone != address(0), "can't be zero address");
55
+ if (someone == address(0)) revert("can't be zero address");
59
56
  _;
60
57
  }
61
58
 
@@ -76,11 +73,13 @@ contract PythOracle is AccessControlled, OracleInterface {
76
73
  * @custom:error Zero length error is thrown if length of the array in parameter is 0
77
74
  */
78
75
  function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
79
- _checkAccessAllowed("setTokenConfigs(TokenConfig[])");
80
- require(tokenConfigs_.length != 0, "length can't be 0");
76
+ if (tokenConfigs_.length == 0) revert("length can't be 0");
81
77
  uint256 numTokenConfigs = tokenConfigs_.length;
82
- for (uint256 i; i < numTokenConfigs; ++i) {
78
+ for (uint256 i; i < numTokenConfigs; ) {
83
79
  setTokenConfig(tokenConfigs_[i]);
80
+ unchecked {
81
+ ++i;
82
+ }
84
83
  }
85
84
  }
86
85
 
@@ -94,9 +93,10 @@ contract PythOracle is AccessControlled, OracleInterface {
94
93
  function setUnderlyingPythOracle(
95
94
  IPyth underlyingPythOracle_
96
95
  ) external notNullAddress(address(underlyingPythOracle_)) {
97
- _checkAccessAllowed("setUnderlyingPythOracle(IPyth)");
96
+ _checkAccessAllowed("setUnderlyingPythOracle(address)");
97
+ IPyth oldUnderlyingPythOracle = underlyingPythOracle;
98
98
  underlyingPythOracle = underlyingPythOracle_;
99
- emit PythOracleSet(address(underlyingPythOracle_));
99
+ emit PythOracleSet(address(oldUnderlyingPythOracle), address(underlyingPythOracle_));
100
100
  }
101
101
 
102
102
  /**
@@ -104,49 +104,36 @@ contract PythOracle is AccessControlled, OracleInterface {
104
104
  * @param underlyingPythOracle_ Address of the Pyth oracle
105
105
  * @param accessControlManager_ Address of the access control manager contract
106
106
  */
107
- function initialize(address underlyingPythOracle_, address accessControlManager_) public initializer {
108
- __Ownable2Step_init();
109
- __AccessControlled_init_unchained(accessControlManager_);
107
+ function initialize(
108
+ address underlyingPythOracle_,
109
+ address accessControlManager_
110
+ ) external initializer notNullAddress(underlyingPythOracle_) {
111
+ __AccessControlled_init(accessControlManager_);
110
112
 
111
- require(underlyingPythOracle_ != address(0), "pyth oracle cannot be zero address");
112
113
  underlyingPythOracle = IPyth(underlyingPythOracle_);
113
- emit PythOracleSet(underlyingPythOracle_);
114
- }
115
-
116
- /**
117
- * @notice Set single token config. `maxStalePeriod` cannot be 0 and `vToken` can be a null address
118
- * @param tokenConfig Token config struct
119
- * @custom:access Only Governance
120
- * @custom:error Range error is thrown if max stale period is zero
121
- * @custom:error NotNullAddress error is thrown if asset address is null
122
- */
123
- function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
124
- _checkAccessAllowed("setTokenConfig(TokenConfig)");
125
- require(tokenConfig.maxStalePeriod != 0, "max stale period cannot be 0");
126
- tokenConfigs[tokenConfig.asset] = tokenConfig;
127
- emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
114
+ emit PythOracleSet(address(0), underlyingPythOracle_);
128
115
  }
129
116
 
130
117
  /**
131
118
  * @notice Get price of underlying asset of the input vToken, under the hood this function
132
119
  * get price from Pyth contract, the prices of which are updated externally
133
120
  * @param vToken vToken address
134
- * @return price Underlying price with a precision of 10 decimals
121
+ * @return price Underlying price with a precision of 18 decimals
135
122
  * @custom:error Zero address error thrown if underlyingPythOracle address is null
136
123
  * @custom:error Zero address error thrown if asset address is null
137
124
  * @custom:error Range error thrown if price of Pyth oracle is not greater than zero
138
125
  */
139
- function getUnderlyingPrice(address vToken) public view override returns (uint256) {
140
- require(address(underlyingPythOracle) != address(0), "Pyth oracle is zero address");
141
-
126
+ function getUnderlyingPrice(
127
+ address vToken
128
+ ) external view override notNullAddress(address(underlyingPythOracle)) returns (uint256) {
142
129
  address asset;
143
130
  uint256 decimals;
144
131
 
145
132
  // VBNB token doesn't have `underlying` method
146
- if (address(vToken) == vBnb) {
133
+ if (vToken == vBnb) {
147
134
  asset = BNB_ADDR;
148
135
  decimals = 18;
149
- } else if (address(vToken) == vai) {
136
+ } else if (vToken == vai) {
150
137
  asset = vai;
151
138
  decimals = 18;
152
139
  } else {
@@ -155,7 +142,7 @@ contract PythOracle is AccessControlled, OracleInterface {
155
142
  }
156
143
 
157
144
  TokenConfig storage tokenConfig = tokenConfigs[asset];
158
- require(tokenConfig.asset != address(0), "asset doesn't exist");
145
+ if (tokenConfig.asset == address(0)) revert("asset doesn't exist");
159
146
 
160
147
  // if the price is expired after it's compared against `maxStalePeriod`, the following call will revert
161
148
  PythStructs.Price memory priceInfo = underlyingPythOracle.getPriceNoOlderThan(
@@ -165,14 +152,28 @@ contract PythOracle is AccessControlled, OracleInterface {
165
152
 
166
153
  uint256 price = int256(priceInfo.price).toUint256();
167
154
 
168
- require(price > 0, "Pyth oracle price must be positive");
155
+ if (price == 0) revert("invalid pyth oracle price");
169
156
 
170
157
  // the price returned from Pyth is price ** 10^expo, which is the real dollar price of the assets
171
158
  // we need to multiply it by 1e18 to make the price 18 decimals
172
159
  if (priceInfo.expo > 0) {
173
- return price.mul(EXP_SCALE).mul(10 ** int256(priceInfo.expo).toUint256()) * (10 ** (18 - decimals));
160
+ return price * EXP_SCALE * (10 ** int256(priceInfo.expo).toUint256()) * (10 ** (18 - decimals));
174
161
  } else {
175
- return price.mul(EXP_SCALE).div(10 ** int256(-priceInfo.expo).toUint256()) * (10 ** (18 - decimals));
162
+ return ((price * EXP_SCALE) / (10 ** int256(-priceInfo.expo).toUint256())) * (10 ** (18 - decimals));
176
163
  }
177
164
  }
165
+
166
+ /**
167
+ * @notice Set single token config. `maxStalePeriod` cannot be 0 and `vToken` can be a null address
168
+ * @param tokenConfig Token config struct
169
+ * @custom:access Only Governance
170
+ * @custom:error Range error is thrown if max stale period is zero
171
+ * @custom:error NotNullAddress error is thrown if asset address is null
172
+ */
173
+ function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
174
+ _checkAccessAllowed("setTokenConfig(TokenConfig)");
175
+ if (tokenConfig.maxStalePeriod == 0) revert("max stale period cannot be 0");
176
+ tokenConfigs[tokenConfig.asset] = tokenConfig;
177
+ emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
178
+ }
178
179
  }