@venusprotocol/oracle 1.6.10 → 1.6.11-dev.11
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/LICENSE +11 -0
- package/README.md +140 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +2 -2
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +2 -2
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +2 -2
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +2 -2
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +2 -2
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +2 -2
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
- 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/{contracts/Governance/AccessControlled.sol/AccessControlled.json → @venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json} +3 -3
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +4 -0
- package/artifacts/{contracts/Governance/IAccessControlManager.sol/IAccessControlManager.json → @venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json} +2 -2
- package/artifacts/build-info/2f9bd32d7afaff51cf1627ed4903b445.json +1 -0
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +8 -8
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +2 -2
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +2 -2
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +2 -2
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +221 -3
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +5 -5
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +7 -13
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +11 -5
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +24 -37
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +3 -22
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +2 -2
- 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 +1 -1
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +15 -2
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +2 -2
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +2 -2
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +2 -2
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +2 -2
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +15 -2
- package/contracts/ResilientOracle.sol +45 -37
- package/contracts/interfaces/PythInterface.sol +4 -1
- package/contracts/oracles/BinanceOracle.sol +65 -24
- package/contracts/oracles/BoundValidator.sol +51 -54
- package/contracts/oracles/ChainlinkOracle.sol +54 -54
- package/contracts/oracles/PythOracle.sol +48 -47
- package/contracts/oracles/TwapOracle.sol +85 -83
- package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +1 -1
- package/contracts/oracles/mocks/MockBinanceOracle.sol +1 -7
- package/contracts/oracles/mocks/MockPythOracle.sol +1 -1
- package/contracts/oracles/mocks/MockTwapOracle.sol +1 -1
- package/contracts/test/AccessControlManager.sol +6 -0
- package/contracts/test/BEP20Harness.sol +4 -0
- package/contracts/test/MockPyth.sol +9 -2
- package/deployments/bscmainnet/.chainId +1 -0
- package/deployments/bscmainnet/BinanceOracle.json +571 -0
- package/deployments/bscmainnet/BinanceOracle_Implementation.json +629 -0
- package/deployments/bscmainnet/BinanceOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/BoundValidator.json +621 -0
- package/deployments/bscmainnet/BoundValidator_Implementation.json +706 -0
- package/deployments/bscmainnet/BoundValidator_Proxy.json +251 -0
- package/deployments/bscmainnet/ChainlinkOracle.json +691 -0
- package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +820 -0
- package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/DefaultProxyAdmin.json +257 -0
- package/deployments/bscmainnet/PythOracle.json +688 -0
- package/deployments/bscmainnet/PythOracle_Implementation.json +804 -0
- package/deployments/bscmainnet/PythOracle_Proxy.json +265 -0
- package/deployments/bscmainnet/ResilientOracle.json +841 -0
- package/deployments/bscmainnet/ResilientOracle_Implementation.json +1044 -0
- package/deployments/bscmainnet/ResilientOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/TwapOracle.json +887 -0
- package/deployments/bscmainnet/TwapOracle_Implementation.json +1111 -0
- package/deployments/bscmainnet/TwapOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
- package/deployments/bscmainnet/solcInputs/aae9f1601b873a5a4704ede73ede10cb.json +135 -0
- package/deployments/bsctestnet/BinanceOracle.json +273 -31
- package/deployments/bsctestnet/BinanceOracle_Implementation.json +398 -28
- package/deployments/bsctestnet/BinanceOracle_Proxy.json +52 -28
- package/deployments/bsctestnet/BoundValidator.json +40 -40
- package/deployments/bsctestnet/BoundValidator_Implementation.json +43 -51
- package/deployments/bsctestnet/BoundValidator_Proxy.json +35 -35
- package/deployments/bsctestnet/ChainlinkOracle.json +57 -49
- package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +46 -52
- package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +50 -36
- package/deployments/bsctestnet/DefaultProxyAdmin.json +18 -18
- package/deployments/bsctestnet/PythOracle.json +52 -45
- package/deployments/bsctestnet/PythOracle_Implementation.json +53 -47
- package/deployments/bsctestnet/PythOracle_Proxy.json +41 -40
- package/deployments/bsctestnet/ResilientOracle.json +51 -42
- package/deployments/bsctestnet/ResilientOracle_Implementation.json +65 -68
- package/deployments/bsctestnet/ResilientOracle_Proxy.json +48 -34
- package/deployments/bsctestnet/TwapOracle.json +70 -83
- package/deployments/bsctestnet/TwapOracle_Implementation.json +84 -97
- package/deployments/bsctestnet/TwapOracle_Proxy.json +46 -46
- package/deployments/bsctestnet/solcInputs/131f58942628e21632de19506977a910.json +120 -0
- package/deployments/bsctestnet/solcInputs/144b49e8aec3add79553ba273ea32d00.json +72 -0
- package/deployments/bsctestnet/solcInputs/503f2e4e766f3be923fadf8030a5470f.json +78 -0
- package/deployments/bsctestnet/solcInputs/b39d33092f7dd383ae3a042566194132.json +75 -0
- package/dist/deploy/1-deploy-oracles.d.ts +5 -0
- package/dist/deploy/1-deploy-oracles.d.ts.map +1 -0
- package/{deploy → dist/deploy}/1-deploy-oracles.js +66 -24
- package/dist/deploy/1-deploy-oracles.js.map +1 -0
- package/dist/deploy/2-configure-feeds.d.ts +15 -0
- package/dist/deploy/2-configure-feeds.d.ts.map +1 -0
- package/{deploy → dist/deploy}/2-configure-feeds.js +139 -16
- package/dist/deploy/2-configure-feeds.js.map +1 -0
- package/dist/hardhat.config.d.ts +13 -0
- package/dist/hardhat.config.d.ts.map +1 -0
- package/dist/hardhat.config.js +158 -0
- package/dist/hardhat.config.js.map +1 -0
- package/package.json +26 -19
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.json +0 -10
- package/artifacts/build-info/a47a69a8f108d3e7113faf89771988ff.json +0 -1
- package/artifacts/build-info/cc300b55b814df48229058e829c7c3c6.json +0 -1
- package/artifacts/build-info/de79b2637546f6f7d38c8f655549d9e2.json +0 -1
- package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
- package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
- package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.dbg.json +0 -4
- package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.dbg.json +0 -4
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +0 -4
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.json +0 -43
- package/contracts/Governance/AccessControlManager.sol +0 -99
- package/contracts/Governance/AccessControlled.sol +0 -75
- package/contracts/Governance/IAccessControlManager.sol +0 -22
- package/contracts/PriceOracle.sol +0 -16
- package/deploy/1-deploy-oracles.d.ts +0 -2
- package/deploy/1-deploy-oracles.d.ts.map +0 -1
- package/deploy/1-deploy-oracles.js.map +0 -1
- package/deploy/2-configure-feeds.d.ts +0 -2
- package/deploy/2-configure-feeds.d.ts.map +0 -1
- package/deploy/2-configure-feeds.js.map +0 -1
- package/deployments/bsctestnet/AccessControlManager.json +0 -563
- 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 "
|
|
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
|
|
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
|
-
|
|
45
|
-
|
|
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
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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_)
|
|
72
|
-
|
|
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
|
-
)
|
|
88
|
+
) external view override returns (bool) {
|
|
107
89
|
address asset = _getUnderlyingAsset(vToken);
|
|
108
90
|
|
|
109
|
-
|
|
110
|
-
|
|
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)
|
|
121
|
-
if (reportedPrice
|
|
122
|
-
|
|
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)
|
|
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/
|
|
7
|
-
import "
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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(
|
|
71
|
+
_checkAccessAllowed("setUnderlyingPrice(address,uint256)");
|
|
76
72
|
|
|
77
73
|
address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
|
|
78
|
-
|
|
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(
|
|
87
|
+
_checkAccessAllowed("setDirectPrice(address,uint256)");
|
|
91
88
|
|
|
89
|
+
uint256 previousPriceMantissa = prices[asset];
|
|
92
90
|
prices[asset] = price;
|
|
93
|
-
emit PricePosted(asset,
|
|
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
|
-
|
|
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;
|
|
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_)
|
|
116
|
-
|
|
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
|
-
|
|
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)
|
|
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 =
|
|
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
|
|
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
|
-
)
|
|
195
|
+
) private view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
|
|
196
196
|
TokenConfig memory tokenConfig = tokenConfigs[asset];
|
|
197
|
-
|
|
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 =
|
|
203
|
+
uint256 decimalDelta = 18 - feed.decimals();
|
|
204
204
|
|
|
205
205
|
(, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
|
|
206
|
-
|
|
206
|
+
if (answer <= 0) revert("chainlink price must be positive");
|
|
207
|
+
if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
|
|
207
208
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
209
|
+
uint256 deltaTime;
|
|
210
|
+
unchecked {
|
|
211
|
+
deltaTime = block.timestamp - updatedAt;
|
|
212
|
+
}
|
|
211
213
|
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
+
if (deltaTime > maxStalePeriod) revert("chainlink price expired");
|
|
214
215
|
|
|
215
|
-
|
|
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 "
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
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(
|
|
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(
|
|
108
|
-
|
|
109
|
-
|
|
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
|
|
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(
|
|
140
|
-
|
|
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 (
|
|
133
|
+
if (vToken == vBnb) {
|
|
147
134
|
asset = BNB_ADDR;
|
|
148
135
|
decimals = 18;
|
|
149
|
-
} else if (
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
160
|
+
return price * EXP_SCALE * (10 ** int256(priceInfo.expo).toUint256()) * (10 ** (18 - decimals));
|
|
174
161
|
} else {
|
|
175
|
-
return price
|
|
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
|
}
|