@venusprotocol/oracle 1.6.11-dev.7 → 1.6.11-dev.9

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 (102) hide show
  1. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +1 -1
  2. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
  3. package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +1 -1
  4. package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +1 -1
  5. package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
  6. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
  7. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
  8. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
  9. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
  10. package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +1 -1
  11. package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +1 -1
  12. package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +1 -1
  13. package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +1 -1
  14. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
  15. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
  16. package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
  17. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
  18. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
  19. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
  20. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
  21. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
  22. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +1 -1
  23. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
  24. package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
  25. package/artifacts/build-info/{0fa2b75b56480052b72f8190a534e534.json → 0137d0ff3ae413641739f9f6322cc2b3.json} +1 -1
  26. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
  27. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +7 -7
  28. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
  29. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
  30. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
  31. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
  32. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
  33. package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +1 -1
  34. package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +1 -1
  35. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
  36. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
  37. package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +1 -1
  38. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
  39. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
  40. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
  41. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
  42. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
  43. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +2 -2
  44. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
  45. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +4 -4
  46. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
  47. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +4 -10
  48. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
  49. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +10 -4
  50. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
  51. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +24 -24
  52. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
  53. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
  54. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
  55. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
  56. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
  57. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
  58. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
  59. package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +1 -1
  60. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
  61. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
  62. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
  63. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
  64. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
  65. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
  66. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
  67. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
  68. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
  69. package/contracts/ResilientOracle.sol +23 -18
  70. package/contracts/oracles/BinanceOracle.sol +17 -17
  71. package/contracts/oracles/BoundValidator.sol +37 -36
  72. package/contracts/oracles/ChainlinkOracle.sol +30 -34
  73. package/contracts/oracles/PythOracle.sol +26 -25
  74. package/contracts/oracles/TwapOracle.sol +56 -56
  75. package/deployments/bscmainnet/BinanceOracle.json +278 -36
  76. package/deployments/bscmainnet/BinanceOracle_Implementation.json +398 -28
  77. package/deployments/bscmainnet/BinanceOracle_Proxy.json +58 -34
  78. package/deployments/bscmainnet/BoundValidator.json +48 -48
  79. package/deployments/bscmainnet/BoundValidator_Implementation.json +36 -36
  80. package/deployments/bscmainnet/BoundValidator_Proxy.json +46 -46
  81. package/deployments/bscmainnet/ChainlinkOracle.json +55 -41
  82. package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +36 -36
  83. package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +53 -39
  84. package/deployments/bscmainnet/DefaultProxyAdmin.json +16 -16
  85. package/deployments/bscmainnet/PythOracle.json +54 -54
  86. package/deployments/bscmainnet/PythOracle_Implementation.json +38 -38
  87. package/deployments/bscmainnet/PythOracle_Proxy.json +52 -52
  88. package/deployments/bscmainnet/ResilientOracle.json +57 -43
  89. package/deployments/bscmainnet/ResilientOracle_Implementation.json +38 -38
  90. package/deployments/bscmainnet/ResilientOracle_Proxy.json +54 -40
  91. package/deployments/bscmainnet/TwapOracle.json +48 -61
  92. package/deployments/bscmainnet/TwapOracle_Implementation.json +49 -62
  93. package/deployments/bscmainnet/TwapOracle_Proxy.json +46 -46
  94. package/deployments/bscmainnet/solcInputs/3c9df0f4b407c3d8079629dd6ddb913e.json +180 -0
  95. package/dist/deploy/1-deploy-oracles.js +2 -2
  96. package/dist/deploy/1-deploy-oracles.js.map +1 -1
  97. package/dist/hardhat.config.d.ts.map +1 -1
  98. package/dist/hardhat.config.js +20 -4
  99. package/dist/hardhat.config.js.map +1 -1
  100. package/package.json +1 -1
  101. package/deployments/bscmainnet/solcInputs/68ea814c0d6925581f2bda5deba8ce4a.json +0 -60
  102. package/deployments/bscmainnet/solcInputs/8658c669dade0e9ab80874eab3bf3468.json +0 -117
@@ -56,31 +56,17 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
56
56
  * @param _sidRegistryAddress Address of SID registry
57
57
  * @param _accessControlManager Address of the access control manager contract
58
58
  */
59
- function initialize(address _sidRegistryAddress, address _accessControlManager) public initializer {
59
+ function initialize(address _sidRegistryAddress, address _accessControlManager) external initializer {
60
60
  sidRegistryAddress = _sidRegistryAddress;
61
61
  __AccessControlled_init(_accessControlManager);
62
62
  }
63
63
 
64
- /**
65
- * @notice Uses Space ID to fetch the feed registry address
66
- * @return feedRegistryAddress Address of binance oracle feed registry.
67
- */
68
- function getFeedRegistryAddress() public view returns (address) {
69
- bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
70
-
71
- SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
72
- address publicResolverAddress = sidRegistry.resolver(nodeHash);
73
- PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
74
-
75
- return publicResolver.addr(nodeHash);
76
- }
77
-
78
64
  /**
79
65
  * @notice Gets the price of a vToken from the binance oracle
80
66
  * @param vToken Address of the vToken
81
67
  * @return Price in USD
82
68
  */
83
- function getUnderlyingPrice(address vToken) public view override returns (uint256) {
69
+ function getUnderlyingPrice(address vToken) external view override returns (uint256) {
84
70
  string memory symbol;
85
71
  uint256 decimals;
86
72
 
@@ -118,13 +104,27 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
118
104
  return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
119
105
  }
120
106
 
107
+ /**
108
+ * @notice Uses Space ID to fetch the feed registry address
109
+ * @return feedRegistryAddress Address of binance oracle feed registry.
110
+ */
111
+ function getFeedRegistryAddress() public view returns (address) {
112
+ bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
113
+
114
+ SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
115
+ address publicResolverAddress = sidRegistry.resolver(nodeHash);
116
+ PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
117
+
118
+ return publicResolver.addr(nodeHash);
119
+ }
120
+
121
121
  /**
122
122
  * @notice Used to compare if two strings are equal or not
123
123
  * @param str1 The first string
124
124
  * @param str2 The second string
125
125
  * @return equal Returns true if both are equal or else false.
126
126
  */
127
- function compare(string memory str1, string memory str2) internal pure returns (bool) {
127
+ function compare(string memory str1, string memory str2) private pure returns (bool) {
128
128
  return keccak256(bytes(str1)) == keccak256(bytes(str2));
129
129
  }
130
130
  }
@@ -5,20 +5,20 @@ import "../interfaces/VBep20Interface.sol";
5
5
  import "../interfaces/OracleInterface.sol";
6
6
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
7
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
- }
18
-
19
8
  // BoundValidator provides some common functions and can be used
20
9
  // to wrap up other contracts to form pivot oracles
21
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
 
@@ -55,7 +55,7 @@ contract BoundValidator is AccessControlledV8, 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 {
58
+ function setValidateConfigs(ValidateConfig[] memory configs) external {
59
59
  uint256 length = configs.length;
60
60
  if (length == 0) revert("invalid validate config length");
61
61
  for (uint256 i; i < length; ) {
@@ -70,29 +70,10 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
70
70
  * @notice Initializes the owner of the contract
71
71
  * @param accessControlManager_ Address of the access control manager contract
72
72
  */
73
- function initialize(address accessControlManager_) public initializer {
73
+ function initialize(address accessControlManager_) external initializer {
74
74
  __AccessControlled_init(accessControlManager_);
75
75
  }
76
76
 
77
- /**
78
- * @notice Add a single validation config
79
- * @param config Validation config struct
80
- * @custom:access Only Governance
81
- * @custom:error Null address error is thrown if asset address is null
82
- * @custom:error Range error thrown if bound ratio is not positive
83
- * @custom:error Range error thrown if lower bound is greater than upper bound
84
- * @custom:event Emits ValidateConfigAdded when a validation config is successfully set
85
- */
86
- function setValidateConfig(ValidateConfig memory config) public virtual {
87
- _checkAccessAllowed("setValidateConfig(ValidateConfig)");
88
-
89
- if (config.asset == address(0)) revert("asset can't be zero address");
90
- if (config.upperBoundRatio == 0 || config.lowerBoundRatio == 0) revert("bound must be positive");
91
- if (config.upperBoundRatio <= config.lowerBoundRatio) revert("upper bound must be higher than lowner bound");
92
- validateConfigs[config.asset] = config;
93
- emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
94
- }
95
-
96
77
  /**
97
78
  * @notice Test reported asset price against anchor price
98
79
  * @param vToken vToken address
@@ -104,7 +85,7 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
104
85
  address vToken,
105
86
  uint256 reportedPrice,
106
87
  uint256 anchorPrice
107
- ) public view virtual override returns (bool) {
88
+ ) external view override returns (bool) {
108
89
  address asset = _getUnderlyingAsset(vToken);
109
90
 
110
91
  if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
@@ -112,15 +93,35 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
112
93
  return _isWithinAnchor(asset, reportedPrice, anchorPrice);
113
94
  }
114
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
+
115
115
  /**
116
116
  * @notice Test whether the reported price is within the valid bounds
117
117
  * @param asset Asset address
118
118
  * @param reportedPrice The price to be tested
119
119
  * @param anchorPrice The reported price must be within the the valid bounds of this price
120
120
  */
121
- function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) internal view returns (bool) {
121
+ function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) private view returns (bool) {
122
122
  if (reportedPrice != 0) {
123
- uint256 anchorRatio = (anchorPrice * 100e16) / reportedPrice;
123
+ // we need to multiply anchorPrice by 1e18 to make the ratio 18 decimals
124
+ uint256 anchorRatio = (anchorPrice * 1e18) / reportedPrice;
124
125
  uint256 upperBoundAnchorRatio = validateConfigs[asset].upperBoundRatio;
125
126
  uint256 lowerBoundAnchorRatio = validateConfigs[asset].lowerBoundRatio;
126
127
  return anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio;
@@ -133,7 +134,7 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
133
134
  * @param vToken vToken address
134
135
  * @return asset underlying asset address
135
136
  */
136
- function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
137
+ function _getUnderlyingAsset(address vToken) private view returns (address asset) {
137
138
  if (address(vToken) == vBnb) {
138
139
  asset = BNB_ADDR;
139
140
  } else if (address(vToken) == vai) {
@@ -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";
6
+ import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
7
7
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
8
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
- }
18
-
19
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
+ }
20
+
20
21
  /// @notice vBNB address
21
22
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
22
23
  address public immutable vBnb;
@@ -35,12 +36,7 @@ contract ChainlinkOracle is AccessControlledV8, 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 indexed 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
42
  event TokenConfigAdded(address indexed asset, address feed, uint256 maxStalePeriod);
@@ -77,7 +73,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
77
73
  address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
78
74
  uint256 previousPriceMantissa = prices[asset];
79
75
  prices[asset] = underlyingPriceMantissa;
80
- emit PricePosted(asset, previousPriceMantissa, prices[asset], prices[asset]);
76
+ emit PricePosted(asset, previousPriceMantissa, prices[asset]);
81
77
  }
82
78
 
83
79
  /**
@@ -92,7 +88,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
92
88
 
93
89
  uint256 previousPriceMantissa = prices[asset];
94
90
  prices[asset] = price;
95
- emit PricePosted(asset, previousPriceMantissa, price, price);
91
+ emit PricePosted(asset, previousPriceMantissa, price);
96
92
  }
97
93
 
98
94
  /**
@@ -116,10 +112,19 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
116
112
  * @notice Initializes the owner of the contract
117
113
  * @param accessControlManager_ Address of the access control manager contract
118
114
  */
119
- function initialize(address accessControlManager_) public initializer {
115
+ function initialize(address accessControlManager_) external initializer {
120
116
  __AccessControlled_init(accessControlManager_);
121
117
  }
122
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));
126
+ }
127
+
123
128
  /**
124
129
  * @notice Add single token config. vToken & feed cannot be null addresses and maxStalePeriod must be positive
125
130
  * @param tokenConfig Token config struct
@@ -139,15 +144,6 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
139
144
  emit TokenConfigAdded(tokenConfig.asset, tokenConfig.feed, tokenConfig.maxStalePeriod);
140
145
  }
141
146
 
142
- /**
143
- * @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
144
- * @param vToken vToken address
145
- * @return price Underlying price in USD
146
- */
147
- function getUnderlyingPrice(address vToken) public view override returns (uint256) {
148
- return _getUnderlyingPriceInternal(VBep20Interface(vToken));
149
- }
150
-
151
147
  /**
152
148
  * @notice Gets the Chainlink price for the underlying asset of a given vToken
153
149
  * or the manually set price if it's been set
@@ -156,7 +152,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
156
152
  * @param vToken vToken address
157
153
  * @return price Underlying price in USD
158
154
  */
159
- function _getUnderlyingPriceInternal(VBep20Interface vToken) internal view returns (uint256 price) {
155
+ function _getUnderlyingPriceInternal(VBep20Interface vToken) private view returns (uint256 price) {
160
156
  address token;
161
157
  uint256 decimals;
162
158
 
@@ -179,7 +175,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
179
175
  price = _getChainlinkPrice(token);
180
176
  }
181
177
 
182
- uint256 decimalDelta = uint256(18) - uint256(decimals);
178
+ uint256 decimalDelta = 18 - uint256(decimals);
183
179
  return price * (10 ** decimalDelta);
184
180
  }
185
181
 
@@ -196,15 +192,15 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
196
192
  */
197
193
  function _getChainlinkPrice(
198
194
  address asset
199
- ) internal view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
195
+ ) private view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
200
196
  TokenConfig memory tokenConfig = tokenConfigs[asset];
201
- AggregatorV2V3Interface feed = AggregatorV2V3Interface(tokenConfig.feed);
197
+ AggregatorV3Interface feed = AggregatorV3Interface(tokenConfig.feed);
202
198
 
203
199
  // note: maxStalePeriod cannot be 0
204
200
  uint256 maxStalePeriod = tokenConfig.maxStalePeriod;
205
201
 
206
202
  // Chainlink USD-denominated feeds store answers at 8 decimals, mostly
207
- uint256 decimalDelta = uint256(18) - feed.decimals();
203
+ uint256 decimalDelta = 18 - feed.decimals();
208
204
 
209
205
  (, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
210
206
  if (answer <= 0) revert("chainlink price must be positive");
@@ -8,12 +8,6 @@ import "../interfaces/OracleInterface.sol";
8
8
  import "../interfaces/VBep20Interface.sol";
9
9
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
10
10
 
11
- struct TokenConfig {
12
- bytes32 pythId;
13
- address asset;
14
- uint64 maxStalePeriod;
15
- }
16
-
17
11
  /**
18
12
  * PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores the
19
13
  * updated prices from external sources
@@ -25,6 +19,12 @@ contract PythOracle is AccessControlledV8, OracleInterface {
25
19
  // To cast int64/int8 types from Pyth to unsigned types
26
20
  using SafeCast for int256;
27
21
 
22
+ struct TokenConfig {
23
+ bytes32 pythId;
24
+ address asset;
25
+ uint64 maxStalePeriod;
26
+ }
27
+
28
28
  /// @notice Exponent scale (decimal precision) of prices
29
29
  uint256 public constant EXP_SCALE = 1e18;
30
30
 
@@ -46,7 +46,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
46
46
  mapping(address => TokenConfig) public tokenConfigs;
47
47
 
48
48
  /// @notice Emit when setting a new pyth oracle address
49
- event PythOracleSet(address indexed newPythOracle);
49
+ event PythOracleSet(address indexed oldPythOracle, address indexed newPythOracle);
50
50
 
51
51
  /// @notice Emit when a token config is added
52
52
  event TokenConfigAdded(address indexed vToken, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
@@ -94,8 +94,9 @@ contract PythOracle is AccessControlledV8, OracleInterface {
94
94
  IPyth underlyingPythOracle_
95
95
  ) external notNullAddress(address(underlyingPythOracle_)) {
96
96
  _checkAccessAllowed("setUnderlyingPythOracle(address)");
97
+ IPyth oldUnderlyingPythOracle = underlyingPythOracle;
97
98
  underlyingPythOracle = underlyingPythOracle_;
98
- emit PythOracleSet(address(underlyingPythOracle_));
99
+ emit PythOracleSet(address(oldUnderlyingPythOracle), address(underlyingPythOracle_));
99
100
  }
100
101
 
101
102
  /**
@@ -106,25 +107,11 @@ contract PythOracle is AccessControlledV8, OracleInterface {
106
107
  function initialize(
107
108
  address underlyingPythOracle_,
108
109
  address accessControlManager_
109
- ) public initializer notNullAddress(underlyingPythOracle_) {
110
+ ) external initializer notNullAddress(underlyingPythOracle_) {
110
111
  __AccessControlled_init(accessControlManager_);
111
112
 
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
- if (tokenConfig.maxStalePeriod == 0) revert("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
  /**
@@ -138,7 +125,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
138
125
  */
139
126
  function getUnderlyingPrice(
140
127
  address vToken
141
- ) public view override notNullAddress(address(underlyingPythOracle)) returns (uint256) {
128
+ ) external view override notNullAddress(address(underlyingPythOracle)) returns (uint256) {
142
129
  address asset;
143
130
  uint256 decimals;
144
131
 
@@ -175,4 +162,18 @@ contract PythOracle is AccessControlledV8, OracleInterface {
175
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
  }
@@ -7,30 +7,30 @@ import "../interfaces/OracleInterface.sol";
7
7
  import "../interfaces/VBep20Interface.sol";
8
8
  import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
9
9
 
10
- struct Observation {
11
- uint256 timestamp;
12
- uint256 acc;
13
- }
14
-
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
- }
30
-
31
10
  contract TwapOracle is AccessControlledV8, TwapInterface {
32
11
  using FixedPoint for *;
33
12
 
13
+ struct Observation {
14
+ uint256 timestamp;
15
+ uint256 acc;
16
+ }
17
+
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 respresented 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
+
34
34
  /// @notice WBNB address
35
35
  /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
36
36
  address public immutable WBNB;
@@ -44,8 +44,8 @@ contract TwapOracle is AccessControlledV8, 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;
47
+ uint256 public constant BNB_BASE_UNIT = 1e18;
48
+ uint256 public constant BUSD_BASE_UNIT = 1e18;
49
49
 
50
50
  /// @notice Configs by token
51
51
  mapping(address => TokenConfig) public tokenConfigs;
@@ -111,6 +111,31 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
111
111
  }
112
112
  }
113
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]);
135
+ }
136
+ return _updateTwapInternal(tokenConfigs[asset]);
137
+ }
138
+
114
139
  /**
115
140
  * @notice Get the underlying TWAP price for the given vToken
116
141
  * @param vToken vToken address
@@ -129,14 +154,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
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
- __AccessControlled_init(accessControlManager_);
138
- }
139
-
140
157
  /**
141
158
  * @notice Adds a single token config
142
159
  * @param config token config struct
@@ -166,23 +183,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
166
183
  emit TokenConfigAdded(config.asset, config.pancakePool, config.anchorPeriod);
167
184
  }
168
185
 
169
- /**
170
- * @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
171
- * @return anchorPrice anchor price of the underlying asset of the vToken
172
- * @custom:error Missing error is thrown if token config does not exist
173
- */
174
- function updateTwap(address vToken) public returns (uint256) {
175
- address asset = _getUnderlyingAsset(vToken);
176
-
177
- if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
178
- // Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
179
- if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
180
- if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
181
- _updateTwapInternal(tokenConfigs[WBNB]);
182
- }
183
- return _updateTwapInternal(tokenConfigs[asset]);
184
- }
185
-
186
186
  /**
187
187
  * @notice Fetches the current token/WBNB and token/BUSD price accumulator from PancakeSwap.
188
188
  * @return cumulative price of target token regardless of pair order
@@ -205,7 +205,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
205
205
  * @custom:event Emits AnchorPriceUpdated event on successful update of observation with assset address,
206
206
  * AnchorPrice, old observation timestamp and current timestamp
207
207
  */
208
- function _updateTwapInternal(TokenConfig memory config) internal virtual returns (uint256) {
208
+ function _updateTwapInternal(TokenConfig memory config) private returns (uint256) {
209
209
  // pokeWindowValues already handled reversed pool cases,
210
210
  // priceAverage will always be Token/BNB or Token/BUSD *twap** price.
211
211
  (uint256 nowCumulativePrice, uint256 oldCumulativePrice, uint256 oldTimestamp) = pokeWindowValues(config);
@@ -228,15 +228,15 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
228
228
  uint256 priceAverageMantissa = priceAverage.decode112with18();
229
229
 
230
230
  // To cancel the decimals in cumulative price, we need to mulitply the average price with
231
- // tokenBaseUnit / (wbnbBaseUnit or busdBaseUnit, which is 1e18)
232
- 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;
233
233
  uint256 anchorPriceMantissa = (priceAverageMantissa * config.baseUnit) / pairedTokenBaseUnit;
234
234
 
235
235
  // if this token is paired with BNB, convert its price to USD
236
236
  if (config.isBnbBased) {
237
237
  uint256 bnbPrice = prices[WBNB];
238
238
  if (bnbPrice == 0) revert("bnb price is invalid");
239
- anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / bnbBaseUnit;
239
+ anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / BNB_BASE_UNIT;
240
240
  }
241
241
 
242
242
  if (anchorPriceMantissa == 0) revert("twap price cannot be 0");
@@ -260,7 +260,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
260
260
  */
261
261
  function pokeWindowValues(
262
262
  TokenConfig memory config
263
- ) internal returns (uint256, uint256 startCumulativePrice, uint256 startCumulativeTimestamp) {
263
+ ) private returns (uint256, uint256 startCumulativePrice, uint256 startCumulativeTimestamp) {
264
264
  uint256 cumulativePrice = currentCumulativePrice(config);
265
265
  uint256 currentTimestamp = block.timestamp;
266
266
  uint256 windowStartTimestamp = currentTimestamp - config.anchorPeriod;
@@ -301,10 +301,10 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
301
301
  * @param vToken vToken address
302
302
  * @return asset underlying asset address
303
303
  */
304
- function _getUnderlyingAsset(address vToken) internal view returns (address asset) {
305
- if (address(vToken) == vBnb) {
304
+ function _getUnderlyingAsset(address vToken) private view returns (address asset) {
305
+ if (vToken == vBnb) {
306
306
  asset = WBNB;
307
- } else if (address(vToken) == vai) {
307
+ } else if (vToken == vai) {
308
308
  asset = vai;
309
309
  } else {
310
310
  asset = VBep20Interface(vToken).underlying();