@venusprotocol/oracle 1.4.0 → 1.5.0
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/{contracts → @chainlink/contracts/src/v0.8}/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +2 -2
- 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/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/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/SafeMath.sol/SafeMath.dbg.json +1 -1
- 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/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/build-info/96c10bfc915caedc90a237abc802c96d.json +1 -0
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +1 -1
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.json +0 -13
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +33 -9
- 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/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/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +4 -17
- 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 +26 -2
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +39 -2
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +39 -2
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +39 -2
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +53 -30
- 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 +2 -2
- 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/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +2 -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 +3 -3
- 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 +2 -2
- package/contracts/PriceOracle.sol +4 -4
- package/contracts/ResilientOracle.sol +140 -92
- package/contracts/interfaces/FeedRegistryInterface.sol +7 -10
- package/contracts/interfaces/OracleInterface.sol +2 -3
- package/contracts/interfaces/PythInterface.sol +10 -13
- package/contracts/interfaces/VBep20Interface.sol +4 -4
- package/contracts/libraries/PancakeLibrary.sol +7 -20
- package/contracts/oracles/BinanceOracle.sol +37 -6
- package/contracts/oracles/BoundValidator.sol +33 -11
- package/contracts/oracles/ChainlinkOracle.sol +78 -44
- package/contracts/oracles/PythOracle.sol +51 -17
- package/contracts/oracles/TwapOracle.sol +113 -67
- package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +7 -10
- package/contracts/oracles/mocks/MockBinanceOracle.sol +1 -1
- package/contracts/oracles/mocks/MockChainlinkOracle.sol +3 -2
- package/contracts/oracles/mocks/MockPythOracle.sol +3 -2
- package/contracts/oracles/mocks/MockTwapOracle.sol +1 -1
- package/contracts/test/BEP20Harness.sol +3 -8
- package/contracts/test/MockPyth.sol +2 -2
- package/contracts/test/MockSimpleOracle.sol +2 -2
- package/contracts/test/MockV3Aggregator.sol +9 -24
- package/contracts/test/PancakePairHarness.sol +7 -20
- package/contracts/test/VBEP20Harness.sol +2 -3
- package/deploy/2-configure-feeds.d.ts.map +1 -1
- package/deploy/2-configure-feeds.js +63 -28
- package/deploy/2-configure-feeds.js.map +1 -1
- package/package.json +10 -5
- package/artifacts/build-info/2fde13baf96aae3a4a0595eaa19cc540.json +0 -1
- package/artifacts/build-info/442613ba0e31d357bb61ad07d3e9ccb5.json +0 -1
- package/artifacts/build-info/4d2af5803ee95a57ec9aace7ed32201c.json +0 -1
- package/artifacts/build-info/99d7aae43e9eacb55ec69b3cd6d3a70b.json +0 -1
- package/artifacts/build-info/e79aa95060bbee82bc36063535db4019.json +0 -1
- package/artifacts/contracts/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/BEP20Interface.sol/BEP20Interface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/BEP20Interface.sol/BEP20Interface.json +0 -246
- package/contracts/interfaces/AggregatorV2V3Interface.sol +0 -60
- package/contracts/interfaces/BEP20Interface.sol +0 -97
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
pragma solidity
|
|
3
|
-
pragma experimental ABIEncoderV2;
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
pragma solidity 0.8.13;
|
|
4
3
|
|
|
5
4
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
6
|
-
import "../interfaces/BEP20Interface.sol";
|
|
7
5
|
import "../interfaces/VBep20Interface.sol";
|
|
8
6
|
import "../interfaces/OracleInterface.sol";
|
|
9
7
|
|
|
@@ -24,9 +22,28 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
24
22
|
/// @notice validation configs by asset
|
|
25
23
|
mapping(address => ValidateConfig) public validateConfigs;
|
|
26
24
|
|
|
25
|
+
/// @notice vBNB address
|
|
26
|
+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
27
|
+
address public immutable vBnb;
|
|
28
|
+
|
|
29
|
+
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
30
|
+
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
31
|
+
|
|
27
32
|
/// @notice Emit this event when new validate configs are added
|
|
28
33
|
event ValidateConfigAdded(address indexed asset, uint256 indexed upperBound, uint256 indexed lowerBound);
|
|
29
34
|
|
|
35
|
+
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
36
|
+
/// @param vBnbAddress The address of the VBNB
|
|
37
|
+
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
38
|
+
constructor(address vBnbAddress) {
|
|
39
|
+
require(vBnbAddress != address(0), "can't be zero address");
|
|
40
|
+
vBnb = vBnbAddress;
|
|
41
|
+
_disableInitializers();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @notice Initializes the owner of the contract
|
|
46
|
+
*/
|
|
30
47
|
function initialize() public initializer {
|
|
31
48
|
__Ownable_init();
|
|
32
49
|
}
|
|
@@ -34,10 +51,12 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
34
51
|
/**
|
|
35
52
|
* @notice Add multiple validation configs at the same time
|
|
36
53
|
* @param configs config array
|
|
54
|
+
* @custom:access Only Governance
|
|
55
|
+
* @custom:error Zero length error thrown, if length of the array in parameter is 0
|
|
37
56
|
*/
|
|
38
57
|
function setValidateConfigs(ValidateConfig[] memory configs) external virtual onlyOwner {
|
|
39
58
|
require(configs.length > 0, "invalid validate config length");
|
|
40
|
-
for (
|
|
59
|
+
for (uint256 i; i < configs.length; ++i) {
|
|
41
60
|
setValidateConfig(configs[i]);
|
|
42
61
|
}
|
|
43
62
|
}
|
|
@@ -45,6 +64,11 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
45
64
|
/**
|
|
46
65
|
* @notice Add single validation config
|
|
47
66
|
* @param config config struct
|
|
67
|
+
* @custom:access Only Governance
|
|
68
|
+
* @custom:error Zero address error thrown if asset address is zero
|
|
69
|
+
* @custom:error Range error thrown if bound ratio is not positive
|
|
70
|
+
* @custom:error Range error thrown if lower bound is greater than upper bound
|
|
71
|
+
* @custom:event Emits ValidateConfigAdded if succesfully config are set
|
|
48
72
|
*/
|
|
49
73
|
function setValidateConfig(ValidateConfig memory config) public virtual onlyOwner {
|
|
50
74
|
require(config.asset != address(0), "asset can't be zero address");
|
|
@@ -58,13 +82,15 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
58
82
|
* @notice Test reported asset price against anchor price
|
|
59
83
|
* @param vToken vToken address
|
|
60
84
|
* @param reporterPrice the price to be tested
|
|
85
|
+
* @custom:error Missing error thrown if asset config is not set
|
|
86
|
+
* @custom:error Price error thrwon if anchor price is not valid
|
|
61
87
|
*/
|
|
62
88
|
function validatePriceWithAnchorPrice(
|
|
63
89
|
address vToken,
|
|
64
90
|
uint256 reporterPrice,
|
|
65
91
|
uint256 anchorPrice
|
|
66
92
|
) public view virtual override returns (bool) {
|
|
67
|
-
address asset = VBep20Interface(vToken).underlying();
|
|
93
|
+
address asset = vToken == vBnb ? BNB_ADDR : VBep20Interface(vToken).underlying();
|
|
68
94
|
|
|
69
95
|
require(validateConfigs[asset].upperBoundRatio != 0, "validation config not exist");
|
|
70
96
|
require(anchorPrice != 0, "anchor price is not valid");
|
|
@@ -77,11 +103,7 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
77
103
|
* @param reporterPrice the price to be tested
|
|
78
104
|
* @param anchorPrice anchor price as testing anchor
|
|
79
105
|
*/
|
|
80
|
-
function _isWithinAnchor(
|
|
81
|
-
address asset,
|
|
82
|
-
uint256 reporterPrice,
|
|
83
|
-
uint256 anchorPrice
|
|
84
|
-
) internal view returns (bool) {
|
|
106
|
+
function _isWithinAnchor(address asset, uint256 reporterPrice, uint256 anchorPrice) internal view returns (bool) {
|
|
85
107
|
if (reporterPrice > 0) {
|
|
86
108
|
uint256 anchorRatio = (anchorPrice * 100e16) / reporterPrice;
|
|
87
109
|
uint256 upperBoundAnchorRatio = validateConfigs[asset].upperBoundRatio;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
pragma solidity
|
|
3
|
-
pragma experimental ABIEncoderV2;
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
pragma solidity 0.8.13;
|
|
4
3
|
|
|
5
4
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
6
5
|
import "../interfaces/VBep20Interface.sol";
|
|
7
|
-
import "../interfaces/AggregatorV2V3Interface.sol";
|
|
8
6
|
import "../interfaces/OracleInterface.sol";
|
|
7
|
+
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";
|
|
9
8
|
|
|
10
9
|
struct TokenConfig {
|
|
11
10
|
/// @notice underlying token address, which can't be zero address and can be used for existance check
|
|
11
|
+
/// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
|
|
12
12
|
address asset;
|
|
13
13
|
/// @notice chainlink feed address
|
|
14
14
|
address feed;
|
|
@@ -20,8 +20,14 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
20
20
|
/// @notice VAI token is considered $1 constantly in oracle for now
|
|
21
21
|
uint256 public constant VAI_VALUE = 1e18;
|
|
22
22
|
|
|
23
|
-
/// @notice
|
|
24
|
-
///
|
|
23
|
+
/// @notice vBNB address
|
|
24
|
+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
25
|
+
address public immutable vBnb;
|
|
26
|
+
|
|
27
|
+
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
28
|
+
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
29
|
+
|
|
30
|
+
/// @notice Enables us to force set the prices to certain values in some urgent conditions
|
|
25
31
|
mapping(address => uint256) public prices;
|
|
26
32
|
|
|
27
33
|
/// @notice token config by assets
|
|
@@ -43,6 +49,15 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
43
49
|
_;
|
|
44
50
|
}
|
|
45
51
|
|
|
52
|
+
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
53
|
+
/// @param vBnbAddress The address of the VBNB
|
|
54
|
+
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
55
|
+
constructor(address vBnbAddress) notNullAddress(vBnbAddress) {
|
|
56
|
+
vBnb = vBnbAddress;
|
|
57
|
+
_disableInitializers();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// @notice Initializes the owner of the contract
|
|
46
61
|
function initialize() public initializer {
|
|
47
62
|
__Ownable_init();
|
|
48
63
|
}
|
|
@@ -50,18 +65,13 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
50
65
|
/**
|
|
51
66
|
* @notice Get the Chainlink price of underlying asset of input vToken, revert when vToken is zero address
|
|
52
67
|
* @param vToken vToken address
|
|
53
|
-
* @return price in USD
|
|
68
|
+
* @return price in USD
|
|
54
69
|
*/
|
|
55
70
|
function getUnderlyingPrice(address vToken) public view override returns (uint256) {
|
|
56
|
-
string memory symbol = VBep20Interface(vToken).symbol();
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (_compareStrings(symbol, "vBNB")) {
|
|
60
|
-
return _getChainlinkPrice(vToken);
|
|
61
|
-
// VAI price is constantly 1 at the moment, but not guarantee in the future
|
|
62
|
-
} else if (_compareStrings(symbol, "VAI")) {
|
|
71
|
+
string memory symbol = address(vToken) != vBnb ? VBep20Interface(vToken).symbol() : "BNB";
|
|
72
|
+
|
|
73
|
+
if (_compareStrings(symbol, "VAI")) {
|
|
63
74
|
return VAI_VALUE;
|
|
64
|
-
// @TODO: This is some history code, keep it here in case of messing up
|
|
65
75
|
} else {
|
|
66
76
|
return _getUnderlyingPriceInternal(VBep20Interface(vToken));
|
|
67
77
|
}
|
|
@@ -71,36 +81,47 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
71
81
|
* @notice Get the Chainlink price of underlying asset of input vToken or cached price when it's been set
|
|
72
82
|
* @dev The decimals of underlying tokens is considered to ensure the returned prices are in 18 decimals
|
|
73
83
|
* @param vToken vToken address
|
|
74
|
-
* @return price in USD
|
|
84
|
+
* @return price in USD
|
|
75
85
|
*/
|
|
76
86
|
function _getUnderlyingPriceInternal(VBep20Interface vToken) internal view returns (uint256 price) {
|
|
77
|
-
|
|
87
|
+
address token;
|
|
88
|
+
uint256 decimals;
|
|
78
89
|
|
|
79
|
-
|
|
80
|
-
|
|
90
|
+
// VBNB token doesn't have `underlying` method
|
|
91
|
+
if (address(vToken) == vBnb) {
|
|
92
|
+
token = BNB_ADDR;
|
|
93
|
+
decimals = 18;
|
|
81
94
|
} else {
|
|
82
|
-
|
|
95
|
+
token = vToken.underlying();
|
|
96
|
+
decimals = VBep20Interface(token).decimals();
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
uint256
|
|
86
|
-
|
|
99
|
+
uint256 tokenPrice = prices[token];
|
|
100
|
+
if (tokenPrice != 0) {
|
|
101
|
+
price = tokenPrice;
|
|
102
|
+
} else {
|
|
103
|
+
price = _getChainlinkPrice(token);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
uint256 decimalDelta = uint256(18) - uint256(decimals);
|
|
107
|
+
return price * (10 ** decimalDelta);
|
|
87
108
|
}
|
|
88
109
|
|
|
89
110
|
/**
|
|
90
111
|
* @notice Get the Chainlink price of underlying asset of input vToken, revert if token config doesn't exit
|
|
91
112
|
* @dev The decimals of feeds are considered
|
|
92
|
-
* @param
|
|
113
|
+
* @param asset underlying asset address
|
|
93
114
|
* @return price in USD, with 18 decimals
|
|
115
|
+
* @custom:error NotNullAddress error thrown if asset address is zero
|
|
116
|
+
* @custom:error Price error if chain link price of asset is not greater than zero
|
|
117
|
+
* @custom:error Timing error if current timestamp is less than last updated at timestamp
|
|
118
|
+
* @custom:error Timing error if time difference between current time and last update time
|
|
119
|
+
* is greater than maxStalePeriod
|
|
94
120
|
*/
|
|
95
|
-
function _getChainlinkPrice(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
returns (uint256)
|
|
100
|
-
{
|
|
101
|
-
address asset = VBep20Interface(vToken).underlying();
|
|
102
|
-
|
|
103
|
-
TokenConfig storage tokenConfig = tokenConfigs[asset];
|
|
121
|
+
function _getChainlinkPrice(
|
|
122
|
+
address asset
|
|
123
|
+
) internal view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
|
|
124
|
+
TokenConfig memory tokenConfig = tokenConfigs[asset];
|
|
104
125
|
AggregatorV2V3Interface feed = AggregatorV2V3Interface(tokenConfig.feed);
|
|
105
126
|
|
|
106
127
|
// note: maxStalePeriod cannot be 0
|
|
@@ -112,20 +133,26 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
112
133
|
(, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
|
|
113
134
|
require(answer > 0, "chainlink price must be positive");
|
|
114
135
|
|
|
115
|
-
require(block.timestamp
|
|
136
|
+
require(block.timestamp >= updatedAt, "updatedAt exceeds block time");
|
|
116
137
|
uint256 deltaTime = block.timestamp - updatedAt;
|
|
117
138
|
require(deltaTime <= maxStalePeriod, "chainlink price expired");
|
|
118
139
|
|
|
119
|
-
return uint256(answer) * (10**decimalDelta);
|
|
140
|
+
return uint256(answer) * (10 ** decimalDelta);
|
|
120
141
|
}
|
|
121
142
|
|
|
122
143
|
/**
|
|
123
144
|
* @notice Set the forced prices of the underlying token of input vToken
|
|
124
145
|
* @param vToken vToken address
|
|
125
146
|
* @param underlyingPriceMantissa price in 18 decimals
|
|
147
|
+
* @custom:access Only Governance
|
|
148
|
+
* @custom:error NotNullAddress thrown if address of vToken is zero
|
|
149
|
+
* @custom:event Emits PricePosted event on succesfully setup of underlying price
|
|
126
150
|
*/
|
|
127
|
-
function setUnderlyingPrice(
|
|
128
|
-
|
|
151
|
+
function setUnderlyingPrice(
|
|
152
|
+
VBep20Interface vToken,
|
|
153
|
+
uint256 underlyingPriceMantissa
|
|
154
|
+
) external notNullAddress(address(vToken)) onlyOwner {
|
|
155
|
+
address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
|
|
129
156
|
emit PricePosted(asset, prices[asset], underlyingPriceMantissa, underlyingPriceMantissa);
|
|
130
157
|
prices[asset] = underlyingPriceMantissa;
|
|
131
158
|
}
|
|
@@ -134,8 +161,10 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
134
161
|
* @notice Set the forced prices of the input token
|
|
135
162
|
* @param asset asset address
|
|
136
163
|
* @param price price in 18 decimals
|
|
164
|
+
* @custom:access Only GOvernance
|
|
165
|
+
* @custom:event Emits PricePosted event on succesfully setup of underlying price
|
|
137
166
|
*/
|
|
138
|
-
function setDirectPrice(address asset, uint256 price) external onlyOwner {
|
|
167
|
+
function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) onlyOwner {
|
|
139
168
|
emit PricePosted(asset, prices[asset], price, price);
|
|
140
169
|
prices[asset] = price;
|
|
141
170
|
}
|
|
@@ -143,10 +172,13 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
143
172
|
/**
|
|
144
173
|
* @notice Add multiple token configs at the same time
|
|
145
174
|
* @param tokenConfigs_ config array
|
|
175
|
+
* @custom:access Only Governance
|
|
176
|
+
* @custom:error Zero length error thrown, if length of the array in parameter is 0
|
|
146
177
|
*/
|
|
147
178
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
|
|
148
179
|
require(tokenConfigs_.length > 0, "length can't be 0");
|
|
149
|
-
|
|
180
|
+
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
181
|
+
for (uint256 i; i < numTokenConfigs; ++i) {
|
|
150
182
|
setTokenConfig(tokenConfigs_[i]);
|
|
151
183
|
}
|
|
152
184
|
}
|
|
@@ -154,13 +186,15 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
154
186
|
/**
|
|
155
187
|
* @notice Add single token config, vToken & feed cannot be zero address, and maxStalePeriod must be positive
|
|
156
188
|
* @param tokenConfig token config struct
|
|
189
|
+
* @custom:access Only Governance
|
|
190
|
+
* @custom:error NotNullAddress error thrown if asset address is zero
|
|
191
|
+
* @custom:error NotNullAddress error thrown if token feed address is zero
|
|
192
|
+
* @custom:error Range error if maxStale period of token is not greater than zero
|
|
193
|
+
* @custom:event Emits TokenConfigAdded event on succesfully setting up token config
|
|
157
194
|
*/
|
|
158
|
-
function setTokenConfig(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
notNullAddress(tokenConfig.asset)
|
|
162
|
-
notNullAddress(tokenConfig.feed)
|
|
163
|
-
{
|
|
195
|
+
function setTokenConfig(
|
|
196
|
+
TokenConfig memory tokenConfig
|
|
197
|
+
) public onlyOwner notNullAddress(tokenConfig.asset) notNullAddress(tokenConfig.feed) {
|
|
164
198
|
require(tokenConfig.maxStalePeriod > 0, "stale period can't be zero");
|
|
165
199
|
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
166
200
|
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.feed, tokenConfig.maxStalePeriod);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
2
|
-
pragma solidity
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
pragma solidity 0.8.13;
|
|
3
3
|
|
|
4
4
|
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
|
5
5
|
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
|
|
@@ -7,7 +7,6 @@ import "@openzeppelin/contracts/utils/math/SignedMath.sol";
|
|
|
7
7
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
8
8
|
import "../interfaces/PythInterface.sol";
|
|
9
9
|
import "../interfaces/OracleInterface.sol";
|
|
10
|
-
import "../interfaces/BEP20Interface.sol";
|
|
11
10
|
import "../interfaces/VBep20Interface.sol";
|
|
12
11
|
|
|
13
12
|
struct TokenConfig {
|
|
@@ -32,6 +31,13 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
32
31
|
/// @notice price decimals
|
|
33
32
|
uint256 public constant EXP_SCALE = 1e18;
|
|
34
33
|
|
|
34
|
+
/// @notice vBNB address
|
|
35
|
+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
36
|
+
address public immutable vBnb;
|
|
37
|
+
|
|
38
|
+
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
39
|
+
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
40
|
+
|
|
35
41
|
/// @notice the actual pyth oracle address fetch & store the prices
|
|
36
42
|
IPyth public underlyingPythOracle;
|
|
37
43
|
|
|
@@ -49,6 +55,18 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
49
55
|
_;
|
|
50
56
|
}
|
|
51
57
|
|
|
58
|
+
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
59
|
+
/// @param vBnbAddress The address of the VBNB
|
|
60
|
+
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
61
|
+
constructor(address vBnbAddress) notNullAddress(vBnbAddress) {
|
|
62
|
+
vBnb = vBnbAddress;
|
|
63
|
+
_disableInitializers();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @notice Initializes the owner of the contract and sets required contracts
|
|
68
|
+
* @param underlyingPythOracle_ Address of the pyth oracle
|
|
69
|
+
*/
|
|
52
70
|
function initialize(address underlyingPythOracle_) public initializer {
|
|
53
71
|
__Ownable_init();
|
|
54
72
|
require(underlyingPythOracle_ != address(0), "pyth oracle cannot be zero address");
|
|
@@ -59,10 +77,13 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
59
77
|
/**
|
|
60
78
|
* @notice Batch set token configs
|
|
61
79
|
* @param tokenConfigs_ token config array
|
|
80
|
+
* @custom:access Only Governance
|
|
81
|
+
* @custom:error Zero length error thrown, if length of the array in parameter is 0
|
|
62
82
|
*/
|
|
63
83
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
|
|
64
84
|
require(tokenConfigs_.length != 0, "length can't be 0");
|
|
65
|
-
|
|
85
|
+
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
86
|
+
for (uint256 i; i < numTokenConfigs; ++i) {
|
|
66
87
|
setTokenConfig(tokenConfigs_[i]);
|
|
67
88
|
}
|
|
68
89
|
}
|
|
@@ -70,6 +91,9 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
70
91
|
/**
|
|
71
92
|
* @notice Set single token config, `maxStalePeriod` cannot be 0 and `vToken` can be zero address
|
|
72
93
|
* @param tokenConfig token config struct
|
|
94
|
+
* @custom:access Only Governance
|
|
95
|
+
* @custom:error Range error thrown if max stale period is zero
|
|
96
|
+
* @custom:error NotNullAddress error thrown if asset address is zero
|
|
73
97
|
*/
|
|
74
98
|
function setTokenConfig(TokenConfig memory tokenConfig) public onlyOwner notNullAddress(tokenConfig.asset) {
|
|
75
99
|
require(tokenConfig.maxStalePeriod != 0, "max stale period cannot be 0");
|
|
@@ -80,12 +104,13 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
80
104
|
/**
|
|
81
105
|
* @notice set the underlying pyth oracle contract address
|
|
82
106
|
* @param underlyingPythOracle_ pyth oracle contract address
|
|
107
|
+
* @custom:access Only Governance
|
|
108
|
+
* @custom:error NotNullAddress error thrown if underlyingPythOracle_ address is zero
|
|
109
|
+
* @custom:event Emits PythOracleSet event with address of Pyth oracle.
|
|
83
110
|
*/
|
|
84
|
-
function setUnderlyingPythOracle(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
notNullAddress(address(underlyingPythOracle_))
|
|
88
|
-
{
|
|
111
|
+
function setUnderlyingPythOracle(
|
|
112
|
+
IPyth underlyingPythOracle_
|
|
113
|
+
) external onlyOwner notNullAddress(address(underlyingPythOracle_)) {
|
|
89
114
|
underlyingPythOracle = underlyingPythOracle_;
|
|
90
115
|
emit PythOracleSet(address(underlyingPythOracle_));
|
|
91
116
|
}
|
|
@@ -95,11 +120,25 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
95
120
|
* get price from Pyth contract, the prices of which are updated externally
|
|
96
121
|
* @param vToken vToken address
|
|
97
122
|
* @return price in 10 decimals
|
|
123
|
+
* @custom:error Zero address error thrown if underlyingPythOracle address is zero
|
|
124
|
+
* @custom:error Zero address error thrown if asset address is zero
|
|
125
|
+
* @custom:error Range error thrown if price of pythoracle is not greater than zero
|
|
98
126
|
*/
|
|
99
127
|
function getUnderlyingPrice(address vToken) public view override returns (uint256) {
|
|
100
128
|
require(address(underlyingPythOracle) != address(0), "Pyth oracle is zero address");
|
|
101
129
|
|
|
102
|
-
address asset
|
|
130
|
+
address asset;
|
|
131
|
+
uint256 decimals;
|
|
132
|
+
|
|
133
|
+
// VBNB token doesn't have `underlying` method
|
|
134
|
+
if (address(vToken) == vBnb) {
|
|
135
|
+
asset = BNB_ADDR;
|
|
136
|
+
decimals = 18;
|
|
137
|
+
} else {
|
|
138
|
+
asset = VBep20Interface(vToken).underlying();
|
|
139
|
+
decimals = VBep20Interface(asset).decimals();
|
|
140
|
+
}
|
|
141
|
+
|
|
103
142
|
TokenConfig storage tokenConfig = tokenConfigs[asset];
|
|
104
143
|
require(tokenConfig.asset != address(0), "asset doesn't exist");
|
|
105
144
|
|
|
@@ -115,15 +154,10 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
115
154
|
|
|
116
155
|
// the price returned from Pyth is price ** 10^expo, which is the real dollar price of the assets
|
|
117
156
|
// we need to multiply it by 1e18 to make the price 18 decimals
|
|
118
|
-
BEP20Interface underlyingToken = BEP20Interface(asset);
|
|
119
157
|
if (priceInfo.expo > 0) {
|
|
120
|
-
return
|
|
121
|
-
price.mul(EXP_SCALE).mul(10**int256(priceInfo.expo).toUint256()) *
|
|
122
|
-
(10**(18 - underlyingToken.decimals()));
|
|
158
|
+
return price.mul(EXP_SCALE).mul(10 ** int256(priceInfo.expo).toUint256()) * (10 ** (18 - decimals));
|
|
123
159
|
} else {
|
|
124
|
-
return
|
|
125
|
-
price.mul(EXP_SCALE).div(10**int256(-priceInfo.expo).toUint256()) *
|
|
126
|
-
(10**(18 - underlyingToken.decimals()));
|
|
160
|
+
return price.mul(EXP_SCALE).div(10 ** int256(-priceInfo.expo).toUint256()) * (10 ** (18 - decimals));
|
|
127
161
|
}
|
|
128
162
|
}
|
|
129
163
|
}
|