@venusprotocol/oracle 1.6.12-dev.3 → 1.6.12-dev.4
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.
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +4 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +138 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +4 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +249 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +4 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +122 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +215 -0
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +183 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +297 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +194 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +233 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +10 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +115 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +76 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +24 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +63 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +10 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +24 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +4 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +369 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +4 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +181 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +4 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +282 -0
- package/artifacts/build-info/e6185827013b85f715ee874203b21fc8.json +1 -0
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +4 -0
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +649 -0
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +79 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +40 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +30 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +62 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +49 -0
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +30 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +545 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +446 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +10 -0
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +30 -0
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +246 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +4 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +10 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +4 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +60 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +4 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +10 -0
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +349 -0
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +4 -0
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +342 -0
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +407 -0
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +408 -0
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +640 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +116 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +144 -0
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +144 -0
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +163 -0
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +163 -0
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +4 -0
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +364 -0
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +4 -0
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +328 -0
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +4 -0
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +684 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +4 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +124 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +4 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +91 -0
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +4 -0
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +306 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +4 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +10 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +4 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +158 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +4 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +10 -0
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +4 -0
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +346 -0
- package/contracts/ResilientOracle.sol +19 -18
- package/contracts/oracles/BinanceOracle.sol +15 -14
- package/contracts/oracles/ChainlinkOracle.sol +9 -9
- package/contracts/oracles/PythOracle.sol +3 -3
- package/contracts/oracles/TwapOracle.sol +5 -5
- package/package.json +1 -1
|
@@ -20,9 +20,9 @@ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlle
|
|
|
20
20
|
* the protocol from oracle attacks. Currently it includes integrations with Chainlink, Pyth, Binance Oracle
|
|
21
21
|
* and TWAP (Time-Weighted Average Price) oracles. TWAP uses PancakeSwap as the on-chain price source.
|
|
22
22
|
*
|
|
23
|
-
* For every market (vToken) we configure the main, pivot and fallback oracles. The
|
|
24
|
-
*
|
|
25
|
-
* is used as a backup price source.
|
|
23
|
+
* For every market (vToken) we configure the main, pivot and fallback oracles. The oracles are configured per
|
|
24
|
+
* vToken's underlying asset address. The main oracle oracle is the most trustworthy price source, the pivot
|
|
25
|
+
* oracle is used as a loose sanity checker and the fallback oracle is used as a backup price source.
|
|
26
26
|
*
|
|
27
27
|
* To validate prices returned from two oracles, we use an upper and lower bound ratio that is set for every
|
|
28
28
|
* market. The upper bound ratio represents the deviation between reported price (the price that’s being
|
|
@@ -109,8 +109,8 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
|
-
* @notice Checks whether token config exists by checking whether
|
|
113
|
-
* @dev
|
|
112
|
+
* @notice Checks whether token config exists by checking whether asset is null address
|
|
113
|
+
* @dev address can't be null, so it's suitable to be used to check the validity of the config
|
|
114
114
|
* @param asset asset address
|
|
115
115
|
*/
|
|
116
116
|
modifier checkTokenConfigExistence(address asset) {
|
|
@@ -180,8 +180,8 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* @notice Sets oracle for a given
|
|
184
|
-
* @dev Supplied
|
|
183
|
+
* @notice Sets oracle for a given asset and role.
|
|
184
|
+
* @dev Supplied asset **must** exist and main oracle may not be null
|
|
185
185
|
* @param asset Asset address
|
|
186
186
|
* @param oracle Oracle address
|
|
187
187
|
* @param role Oracle role
|
|
@@ -203,7 +203,8 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
/**
|
|
206
|
-
* @notice Enables/ disables oracle for the input
|
|
206
|
+
* @notice Enables/ disables oracle for the input asset. Token config for the input asset **must** exist
|
|
207
|
+
* @dev Configuration for the asset **must** already exist and the asset cannot be 0 address
|
|
207
208
|
* @param asset Asset address
|
|
208
209
|
* @param role Oracle role
|
|
209
210
|
* @param enable Enabled boolean of the oracle
|
|
@@ -237,7 +238,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
237
238
|
|
|
238
239
|
/**
|
|
239
240
|
* @notice Updates the pivot oracle price. Currently using TWAP
|
|
240
|
-
* @dev This function should always be called before calling
|
|
241
|
+
* @dev This function should always be called before calling getPrice
|
|
241
242
|
* @param asset asset address
|
|
242
243
|
*/
|
|
243
244
|
function updateAssetPrice(address asset) external {
|
|
@@ -249,9 +250,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
/**
|
|
252
|
-
* @dev Gets token config by
|
|
253
|
+
* @dev Gets token config by asset address
|
|
253
254
|
* @param asset asset address
|
|
254
|
-
* @return tokenConfig Config for the
|
|
255
|
+
* @return tokenConfig Config for the asset
|
|
255
256
|
*/
|
|
256
257
|
function getTokenConfig(address asset) external view returns (TokenConfig memory) {
|
|
257
258
|
return tokenConfigs[asset];
|
|
@@ -296,7 +297,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
296
297
|
* @custom:access Only Governance
|
|
297
298
|
* @custom:error NotNullAddress is thrown if asset address is null
|
|
298
299
|
* @custom:error NotNullAddress is thrown if main-role oracle address for asset is null
|
|
299
|
-
* @custom:event Emits TokenConfigAdded event when
|
|
300
|
+
* @custom:event Emits TokenConfigAdded event when the asset config is set successfully by the authorized account
|
|
300
301
|
*/
|
|
301
302
|
function setTokenConfig(
|
|
302
303
|
TokenConfig memory tokenConfig
|
|
@@ -313,7 +314,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
313
314
|
}
|
|
314
315
|
|
|
315
316
|
/**
|
|
316
|
-
* @notice Gets oracle and enabled status by
|
|
317
|
+
* @notice Gets oracle and enabled status by asset address
|
|
317
318
|
* @param asset asset address
|
|
318
319
|
* @param role Oracle role
|
|
319
320
|
* @return oracle Oracle address based on role
|
|
@@ -354,7 +355,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
354
355
|
if (
|
|
355
356
|
mainPrice != INVALID_PRICE &&
|
|
356
357
|
fallbackPrice != INVALID_PRICE &&
|
|
357
|
-
boundValidator.validatePriceWithAnchorPrice(asset,
|
|
358
|
+
boundValidator.validatePriceWithAnchorPrice(asset, mainPrice, fallbackPrice)
|
|
358
359
|
) {
|
|
359
360
|
return mainPrice;
|
|
360
361
|
}
|
|
@@ -363,7 +364,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
363
364
|
}
|
|
364
365
|
|
|
365
366
|
/**
|
|
366
|
-
* @notice Gets
|
|
367
|
+
* @notice Gets a price for the provided asset
|
|
367
368
|
* @dev This function won't revert when price is 0, because the fallback oracle may still be
|
|
368
369
|
* able to fetch a correct price
|
|
369
370
|
* @param asset asset address
|
|
@@ -373,7 +374,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
373
374
|
* e.g. asset decimals is 8 then price is returned as 10**18 * 10**(18-8) = 10**28 decimals
|
|
374
375
|
* @return pivotValidated Boolean representing if the validation of main oracle price
|
|
375
376
|
* and pivot oracle price were successful
|
|
376
|
-
* @custom:error Invalid price error is thrown if main oracle fails to fetch price of
|
|
377
|
+
* @custom:error Invalid price error is thrown if main oracle fails to fetch price of the asset
|
|
377
378
|
* @custom:error Invalid price error is thrown if main oracle is not enabled or main oracle
|
|
378
379
|
* address is null
|
|
379
380
|
*/
|
|
@@ -404,12 +405,12 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
404
405
|
}
|
|
405
406
|
|
|
406
407
|
/**
|
|
407
|
-
* @dev This function won't revert when the price is 0 because
|
|
408
|
+
* @dev This function won't revert when the price is 0 because getPrice checks if price is > 0
|
|
408
409
|
* @param asset asset address
|
|
409
410
|
* @return price USD price in 18 decimals
|
|
410
411
|
* @return pivotValidated Boolean representing if the validation of fallback oracle price
|
|
411
412
|
* and pivot oracle price were successfull
|
|
412
|
-
* @custom:error Invalid price error is thrown if fallback oracle fails to fetch price of
|
|
413
|
+
* @custom:error Invalid price error is thrown if fallback oracle fails to fetch price of the asset
|
|
413
414
|
* @custom:error Invalid price error is thrown if fallback oracle is not enabled or fallback oracle
|
|
414
415
|
* address is null
|
|
415
416
|
*/
|
|
@@ -32,6 +32,14 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
|
32
32
|
|
|
33
33
|
event MaxStalePeriodAdded(string indexed asset, uint256 maxStalePeriod);
|
|
34
34
|
|
|
35
|
+
/**
|
|
36
|
+
* @notice Checks whether an address is null or not
|
|
37
|
+
*/
|
|
38
|
+
modifier notNullAddress(address someone) {
|
|
39
|
+
if (someone == address(0)) revert("can't be zero address");
|
|
40
|
+
_;
|
|
41
|
+
}
|
|
42
|
+
|
|
35
43
|
/// @notice Constructor for the implementation contract.
|
|
36
44
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
37
45
|
constructor() {
|
|
@@ -56,13 +64,13 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
|
56
64
|
* @notice Sets the contracts required to fetch prices
|
|
57
65
|
* @param _sidRegistryAddress Address of SID registry
|
|
58
66
|
* @param _accessControlManager Address of the access control manager contract
|
|
59
|
-
* @param _WBNB Address of the
|
|
67
|
+
* @param _WBNB Address of the wBNB contract
|
|
60
68
|
*/
|
|
61
69
|
function initialize(
|
|
62
70
|
address _sidRegistryAddress,
|
|
63
71
|
address _accessControlManager,
|
|
64
72
|
address _WBNB
|
|
65
|
-
) external reinitializer(2) {
|
|
73
|
+
) external reinitializer(2) notNullAddress(_sidRegistryAddress) notNullAddress(_WBNB) {
|
|
66
74
|
sidRegistryAddress = _sidRegistryAddress;
|
|
67
75
|
WBNB = _WBNB;
|
|
68
76
|
__AccessControlled_init(_accessControlManager);
|
|
@@ -84,7 +92,7 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
|
84
92
|
|
|
85
93
|
/**
|
|
86
94
|
* @notice Gets the price of a asset from the binance oracle
|
|
87
|
-
* @param asset Address of the
|
|
95
|
+
* @param asset Address of the asset
|
|
88
96
|
* @return Price in USD
|
|
89
97
|
*/
|
|
90
98
|
function getPrice(address asset) public view returns (uint256) {
|
|
@@ -111,20 +119,13 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
|
111
119
|
if (answer <= 0) revert("invalid binance oracle price");
|
|
112
120
|
if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
|
|
113
121
|
|
|
114
|
-
uint256 deltaTime
|
|
122
|
+
uint256 deltaTime;
|
|
123
|
+
unchecked {
|
|
124
|
+
deltaTime = block.timestamp - updatedAt;
|
|
125
|
+
}
|
|
115
126
|
if (deltaTime > maxStalePeriod[symbol]) revert("binance oracle price expired");
|
|
116
127
|
|
|
117
128
|
uint256 decimalDelta = feedRegistry.decimals(asset, USD_ADDR);
|
|
118
129
|
return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
|
|
119
130
|
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @notice Used to compare if two strings are equal or not
|
|
123
|
-
* @param str1 The first string
|
|
124
|
-
* @param str2 The second string
|
|
125
|
-
* @return equal Returns true if both are equal or else false.
|
|
126
|
-
*/
|
|
127
|
-
function compare(string memory str1, string memory str2) private pure returns (bool) {
|
|
128
|
-
return keccak256(bytes(str1)) == keccak256(bytes(str2));
|
|
129
|
-
}
|
|
130
131
|
}
|
|
@@ -43,7 +43,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
43
43
|
_;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/// @notice Constructor for the implementation contract.
|
|
46
|
+
/// @notice Constructor for the implementation contract.
|
|
47
47
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
48
48
|
constructor() {
|
|
49
49
|
_disableInitializers();
|
|
@@ -52,9 +52,9 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
52
52
|
/**
|
|
53
53
|
* @notice Manually set the price of a given asset
|
|
54
54
|
* @param asset Asset address
|
|
55
|
-
* @param price
|
|
55
|
+
* @param price Asset price in 18 decimals
|
|
56
56
|
* @custom:access Only Governance
|
|
57
|
-
* @custom:event Emits PricePosted event on succesfully setup of
|
|
57
|
+
* @custom:event Emits PricePosted event on succesfully setup of asset price
|
|
58
58
|
*/
|
|
59
59
|
function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) {
|
|
60
60
|
_checkAccessAllowed("setDirectPrice(address,uint256)");
|
|
@@ -110,8 +110,8 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* @notice Gets the price of a asset from the chainlink oracle
|
|
113
|
-
* @param asset Address of the
|
|
114
|
-
* @return Price in USD
|
|
113
|
+
* @param asset Address of the asset
|
|
114
|
+
* @return Price in USD from Chainlink or a manually set price for the asset
|
|
115
115
|
*/
|
|
116
116
|
function getPrice(address asset) public view returns (uint256) {
|
|
117
117
|
uint256 decimals;
|
|
@@ -130,7 +130,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
130
130
|
* @notice Gets the Chainlink price for a given asset
|
|
131
131
|
* @param token address of the asset
|
|
132
132
|
* @param decimals decimals of the asset
|
|
133
|
-
* @return price
|
|
133
|
+
* @return price Asset price in USD or a manually set price of the asset
|
|
134
134
|
*/
|
|
135
135
|
function _getPriceInternal(address token, uint256 decimals) internal view returns (uint256 price) {
|
|
136
136
|
uint256 tokenPrice = prices[token];
|
|
@@ -145,10 +145,10 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
* @notice Get the Chainlink price for
|
|
148
|
+
* @notice Get the Chainlink price for an asset, revert if token config doesn't exist
|
|
149
149
|
* @dev The precision of the price feed is used to ensure the returned price has 18 decimals of precision
|
|
150
|
-
* @param asset
|
|
151
|
-
* @return price
|
|
150
|
+
* @param asset Address of the asset
|
|
151
|
+
* @return price Price in USD, with 18 decimals of precision
|
|
152
152
|
* @custom:error NotNullAddress error is thrown if the asset address is null
|
|
153
153
|
* @custom:error Price error is thrown if the Chainlink price of asset is not greater than zero
|
|
154
154
|
* @custom:error Timing error is thrown if current timestamp is less than the last updatedAt timestamp
|
|
@@ -43,7 +43,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
43
43
|
event PythOracleSet(address indexed oldPythOracle, address indexed newPythOracle);
|
|
44
44
|
|
|
45
45
|
/// @notice Emit when a token config is added
|
|
46
|
-
event TokenConfigAdded(address indexed
|
|
46
|
+
event TokenConfigAdded(address indexed asset, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
|
|
47
47
|
|
|
48
48
|
modifier notNullAddress(address someone) {
|
|
49
49
|
if (someone == address(0)) revert("can't be zero address");
|
|
@@ -105,7 +105,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `
|
|
108
|
+
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `asset` cannot be a null address
|
|
109
109
|
* @param tokenConfig Token config struct
|
|
110
110
|
* @custom:access Only Governance
|
|
111
111
|
* @custom:error Range error is thrown if max stale period is zero
|
|
@@ -120,7 +120,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
120
120
|
|
|
121
121
|
/**
|
|
122
122
|
* @notice Gets the price of a asset from the pyth oracle
|
|
123
|
-
* @param asset Address of the
|
|
123
|
+
* @param asset Address of the asset
|
|
124
124
|
* @return Price in USD
|
|
125
125
|
*/
|
|
126
126
|
function getPrice(address asset) public view returns (uint256) {
|
|
@@ -23,7 +23,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
23
23
|
struct TokenConfig {
|
|
24
24
|
/// @notice Asset address, which can't be zero address and can be used for existance check
|
|
25
25
|
address asset;
|
|
26
|
-
/// @notice Decimals of
|
|
26
|
+
/// @notice Decimals of asset represented as 1e{decimals}
|
|
27
27
|
uint256 baseUnit;
|
|
28
28
|
/// @notice The address of Pancake pair
|
|
29
29
|
address pancakePool;
|
|
@@ -112,9 +112,9 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
|
-
* @notice Get the
|
|
115
|
+
* @notice Get the TWAP price for the given asset
|
|
116
116
|
* @param asset asset address
|
|
117
|
-
* @return price
|
|
117
|
+
* @return price asset price in USD
|
|
118
118
|
* @custom:error Missing error is thrown if the token config does not exist
|
|
119
119
|
* @custom:error Range error is thrown if TWAP price is not greater than zero
|
|
120
120
|
*/
|
|
@@ -168,7 +168,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
168
168
|
|
|
169
169
|
/**
|
|
170
170
|
* @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
171
|
-
* @return anchorPrice anchor price of the
|
|
171
|
+
* @return anchorPrice anchor price of the asset
|
|
172
172
|
* @custom:error Missing error is thrown if token config does not exist
|
|
173
173
|
*/
|
|
174
174
|
function updateTwap(address asset) public returns (uint256) {
|
|
@@ -200,7 +200,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* @notice Fetches the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
203
|
-
* @return price
|
|
203
|
+
* @return price Asset price in USD, with 18 decimals
|
|
204
204
|
* @custom:error Timing error is thrown if current time is not greater than old observation timestamp
|
|
205
205
|
* @custom:error Zero price error is thrown if token is BNB based and price is zero
|
|
206
206
|
* @custom:error Zero price error is thrown if fetched anchorPriceMantissa is zero
|