@venusprotocol/oracle 1.5.0 → 1.6.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 +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/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
- 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/SafeMath.sol/SafeMath.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.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/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
- package/artifacts/build-info/1d7bedd9b14544f287811332b9a539d7.json +1 -0
- package/artifacts/build-info/{96c10bfc915caedc90a237abc802c96d.json → 57da5d39a9f98618d0dcf1f6d4ff6b0d.json} +1 -1
- package/artifacts/build-info/f6af69795174616b8b4a6373f9f1c538.json +1 -0
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +2 -2
- 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/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 +2 -2
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +3 -3
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +2 -2
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +2 -2
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
- 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/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/contracts/PriceOracle.sol +2 -2
- package/contracts/ResilientOracle.sol +127 -114
- package/contracts/libraries/PancakeLibrary.sol +8 -8
- package/contracts/oracles/BinanceOracle.sol +4 -4
- package/contracts/oracles/BoundValidator.sol +31 -29
- package/contracts/oracles/ChainlinkOracle.sol +85 -83
- package/contracts/oracles/PythOracle.sol +41 -41
- package/contracts/oracles/TwapOracle.sol +67 -67
- package/contracts/oracles/mocks/MockBinanceOracle.sol +4 -4
- package/contracts/oracles/mocks/MockChainlinkOracle.sol +4 -4
- package/contracts/oracles/mocks/MockPythOracle.sol +4 -4
- package/contracts/oracles/mocks/MockTwapOracle.sol +4 -4
- package/contracts/test/MockPyth.sol +13 -13
- package/contracts/test/MockSimpleOracle.sol +8 -8
- package/contracts/test/MockV3Aggregator.sol +18 -18
- package/contracts/test/PancakePairHarness.sol +10 -10
- package/deploy/1-deploy-oracles.d.ts +1 -3
- package/deploy/1-deploy-oracles.d.ts.map +1 -1
- package/deploy/1-deploy-oracles.js +13 -3
- package/deploy/1-deploy-oracles.js.map +1 -1
- package/deploy/2-configure-feeds.d.ts +1 -3
- package/deploy/2-configure-feeds.d.ts.map +1 -1
- package/deploy/2-configure-feeds.js +101 -87
- package/deploy/2-configure-feeds.js.map +1 -1
- package/deployments/bsctestnet/BinanceOracle.json +42 -29
- package/deployments/bsctestnet/BinanceOracle_Implementation.json +96 -23
- package/deployments/bsctestnet/BinanceOracle_Proxy.json +28 -28
- package/deployments/bsctestnet/BoundValidator.json +65 -39
- package/deployments/bsctestnet/BoundValidator_Implementation.json +113 -35
- package/deployments/bsctestnet/BoundValidator_Proxy.json +37 -37
- package/deployments/bsctestnet/ChainlinkOracle.json +64 -38
- package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +122 -41
- package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +37 -37
- package/deployments/bsctestnet/DefaultProxyAdmin.json +15 -15
- package/deployments/bsctestnet/PythOracle.json +71 -45
- package/deployments/bsctestnet/PythOracle_Implementation.json +128 -44
- package/deployments/bsctestnet/PythOracle_Proxy.json +44 -44
- package/deployments/bsctestnet/ResilientOracle.json +67 -54
- package/deployments/bsctestnet/ResilientOracle_Implementation.json +161 -63
- package/deployments/bsctestnet/ResilientOracle_Proxy.json +39 -39
- package/deployments/bsctestnet/TwapOracle.json +74 -71
- package/deployments/bsctestnet/TwapOracle_Implementation.json +163 -93
- package/deployments/bsctestnet/TwapOracle_Proxy.json +37 -41
- package/deployments/bsctestnet/solcInputs/6153c675ce838eebb6442d63350712be.json +144 -0
- package/package.json +4 -2
- package/deployments/bsctestnet/solcInputs/09bc2981019c6dcce653b90bac585fe0.json +0 -81
- package/deployments/bsctestnet/solcInputs/5dedb37ab8105f1f71e53a3f865859c5.json +0 -57
- package/deployments/bsctestnet/solcInputs/bb71c6049f6b7b21a6581f40daf802bc.json +0 -138
|
@@ -8,10 +8,10 @@ import "../interfaces/OracleInterface.sol";
|
|
|
8
8
|
struct ValidateConfig {
|
|
9
9
|
/// @notice asset address
|
|
10
10
|
address asset;
|
|
11
|
-
/// @notice
|
|
11
|
+
/// @notice Upper bound of deviation between reported price and anchor price,
|
|
12
12
|
/// beyond which the reported price will be invalidated
|
|
13
13
|
uint256 upperBoundRatio;
|
|
14
|
-
/// @notice
|
|
14
|
+
/// @notice Lower bound of deviation between reported price and anchor price,
|
|
15
15
|
/// below which the reported price will be invalidated
|
|
16
16
|
uint256 lowerBoundRatio;
|
|
17
17
|
}
|
|
@@ -29,30 +29,24 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
29
29
|
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
30
30
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
31
31
|
|
|
32
|
-
/// @notice Emit this event when new
|
|
32
|
+
/// @notice Emit this event when new validation configs are added
|
|
33
33
|
event ValidateConfigAdded(address indexed asset, uint256 indexed upperBound, uint256 indexed lowerBound);
|
|
34
34
|
|
|
35
35
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
36
|
-
/// @param vBnbAddress The address of the
|
|
36
|
+
/// @param vBnbAddress The address of the vBNB
|
|
37
37
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
38
38
|
constructor(address vBnbAddress) {
|
|
39
|
-
require(vBnbAddress != address(0), "can't be zero address");
|
|
39
|
+
require(vBnbAddress != address(0), "can't be a zero address");
|
|
40
40
|
vBnb = vBnbAddress;
|
|
41
41
|
_disableInitializers();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
/**
|
|
45
|
-
* @notice Initializes the owner of the contract
|
|
46
|
-
*/
|
|
47
|
-
function initialize() public initializer {
|
|
48
|
-
__Ownable_init();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
44
|
/**
|
|
52
45
|
* @notice Add multiple validation configs at the same time
|
|
53
|
-
* @param configs
|
|
46
|
+
* @param configs Array of validation configs
|
|
54
47
|
* @custom:access Only Governance
|
|
55
|
-
* @custom:error Zero length error thrown
|
|
48
|
+
* @custom:error Zero length error is thrown if length of the config array is 0
|
|
49
|
+
* @custom:event Emits ValidateConfigAdded for each validation config that is successfully set
|
|
56
50
|
*/
|
|
57
51
|
function setValidateConfigs(ValidateConfig[] memory configs) external virtual onlyOwner {
|
|
58
52
|
require(configs.length > 0, "invalid validate config length");
|
|
@@ -62,13 +56,20 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
62
56
|
}
|
|
63
57
|
|
|
64
58
|
/**
|
|
65
|
-
* @notice
|
|
66
|
-
|
|
59
|
+
* @notice Initializes the owner of the contract
|
|
60
|
+
*/
|
|
61
|
+
function initialize() public initializer {
|
|
62
|
+
__Ownable_init();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @notice Add a single validation config
|
|
67
|
+
* @param config Validation config struct
|
|
67
68
|
* @custom:access Only Governance
|
|
68
|
-
* @custom:error
|
|
69
|
+
* @custom:error Null address error is thrown if asset address is null
|
|
69
70
|
* @custom:error Range error thrown if bound ratio is not positive
|
|
70
71
|
* @custom:error Range error thrown if lower bound is greater than upper bound
|
|
71
|
-
* @custom:event Emits ValidateConfigAdded
|
|
72
|
+
* @custom:event Emits ValidateConfigAdded when a validation config is successfully set
|
|
72
73
|
*/
|
|
73
74
|
function setValidateConfig(ValidateConfig memory config) public virtual onlyOwner {
|
|
74
75
|
require(config.asset != address(0), "asset can't be zero address");
|
|
@@ -81,31 +82,31 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
81
82
|
/**
|
|
82
83
|
* @notice Test reported asset price against anchor price
|
|
83
84
|
* @param vToken vToken address
|
|
84
|
-
* @param
|
|
85
|
+
* @param reportedPrice The price to be tested
|
|
85
86
|
* @custom:error Missing error thrown if asset config is not set
|
|
86
|
-
* @custom:error Price error
|
|
87
|
+
* @custom:error Price error thrown if anchor price is not valid
|
|
87
88
|
*/
|
|
88
89
|
function validatePriceWithAnchorPrice(
|
|
89
90
|
address vToken,
|
|
90
|
-
uint256
|
|
91
|
+
uint256 reportedPrice,
|
|
91
92
|
uint256 anchorPrice
|
|
92
93
|
) public view virtual override returns (bool) {
|
|
93
94
|
address asset = vToken == vBnb ? BNB_ADDR : VBep20Interface(vToken).underlying();
|
|
94
95
|
|
|
95
96
|
require(validateConfigs[asset].upperBoundRatio != 0, "validation config not exist");
|
|
96
97
|
require(anchorPrice != 0, "anchor price is not valid");
|
|
97
|
-
return _isWithinAnchor(asset,
|
|
98
|
+
return _isWithinAnchor(asset, reportedPrice, anchorPrice);
|
|
98
99
|
}
|
|
99
100
|
|
|
100
101
|
/**
|
|
101
|
-
* @notice Test whether the reported price is within the
|
|
102
|
-
* @param asset
|
|
103
|
-
* @param
|
|
104
|
-
* @param anchorPrice
|
|
102
|
+
* @notice Test whether the reported price is within the valid bounds
|
|
103
|
+
* @param asset Asset address
|
|
104
|
+
* @param reportedPrice The price to be tested
|
|
105
|
+
* @param anchorPrice The reported price must be within the the valid bounds of this price
|
|
105
106
|
*/
|
|
106
|
-
function _isWithinAnchor(address asset, uint256
|
|
107
|
-
if (
|
|
108
|
-
uint256 anchorRatio = (anchorPrice * 100e16) /
|
|
107
|
+
function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) internal view returns (bool) {
|
|
108
|
+
if (reportedPrice > 0) {
|
|
109
|
+
uint256 anchorRatio = (anchorPrice * 100e16) / reportedPrice;
|
|
109
110
|
uint256 upperBoundAnchorRatio = validateConfigs[asset].upperBoundRatio;
|
|
110
111
|
uint256 lowerBoundAnchorRatio = validateConfigs[asset].lowerBoundRatio;
|
|
111
112
|
return anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio;
|
|
@@ -115,5 +116,6 @@ contract BoundValidator is OwnableUpgradeable, BoundValidatorInterface {
|
|
|
115
116
|
|
|
116
117
|
// BoundValidator is to get inherited, so it's a good practice to add some storage gaps like
|
|
117
118
|
// OpenZepplin proposed in their contracts: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
119
|
+
// solhint-disable-next-line
|
|
118
120
|
uint256[49] private __gap;
|
|
119
121
|
}
|
|
@@ -7,12 +7,12 @@ import "../interfaces/OracleInterface.sol";
|
|
|
7
7
|
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol";
|
|
8
8
|
|
|
9
9
|
struct TokenConfig {
|
|
10
|
-
/// @notice
|
|
10
|
+
/// @notice Underlying token address, which can't be a null address and can be used to check if a token is supported
|
|
11
11
|
/// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
|
|
12
12
|
address asset;
|
|
13
|
-
/// @notice
|
|
13
|
+
/// @notice Chainlink feed address
|
|
14
14
|
address feed;
|
|
15
|
-
/// @notice expiration period of this asset
|
|
15
|
+
/// @notice Price expiration period of this asset
|
|
16
16
|
uint256 maxStalePeriod;
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -24,16 +24,16 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
24
24
|
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
25
25
|
address public immutable vBnb;
|
|
26
26
|
|
|
27
|
-
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
27
|
+
/// @notice Set this as asset address for BNB. This is the underlying address for vBNB
|
|
28
28
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
29
29
|
|
|
30
|
-
/// @notice
|
|
30
|
+
/// @notice Manually set an override price, useful under extenuating conditions such as price feed failure
|
|
31
31
|
mapping(address => uint256) public prices;
|
|
32
32
|
|
|
33
|
-
/// @notice
|
|
33
|
+
/// @notice Token config by assets
|
|
34
34
|
mapping(address => TokenConfig) public tokenConfigs;
|
|
35
35
|
|
|
36
|
-
/// @notice
|
|
36
|
+
/// @notice Emit when a price is manually set
|
|
37
37
|
event PricePosted(
|
|
38
38
|
address asset,
|
|
39
39
|
uint256 previousPriceMantissa,
|
|
@@ -41,7 +41,7 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
41
41
|
uint256 newPriceMantissa
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
/// @notice
|
|
44
|
+
/// @notice Emit when a token config is added
|
|
45
45
|
event TokenConfigAdded(address asset, address feed, uint256 maxStalePeriod);
|
|
46
46
|
|
|
47
47
|
modifier notNullAddress(address someone) {
|
|
@@ -50,22 +50,82 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
53
|
-
/// @param vBnbAddress The address of the
|
|
53
|
+
/// @param vBnbAddress The address of the vBNB
|
|
54
54
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
55
55
|
constructor(address vBnbAddress) notNullAddress(vBnbAddress) {
|
|
56
56
|
vBnb = vBnbAddress;
|
|
57
57
|
_disableInitializers();
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* @notice Set the forced prices of the underlying token of input vToken
|
|
62
|
+
* @param vToken vToken address
|
|
63
|
+
* @param underlyingPriceMantissa price in 18 decimals
|
|
64
|
+
* @custom:access Only Governance
|
|
65
|
+
* @custom:error NotNullAddress thrown if address of vToken is null
|
|
66
|
+
* @custom:event Emits PricePosted event on succesfully setup of underlying price
|
|
67
|
+
*/
|
|
68
|
+
function setUnderlyingPrice(
|
|
69
|
+
VBep20Interface vToken,
|
|
70
|
+
uint256 underlyingPriceMantissa
|
|
71
|
+
) external notNullAddress(address(vToken)) onlyOwner {
|
|
72
|
+
address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
|
|
73
|
+
emit PricePosted(asset, prices[asset], underlyingPriceMantissa, underlyingPriceMantissa);
|
|
74
|
+
prices[asset] = underlyingPriceMantissa;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @notice Manually set the price of a given asset
|
|
79
|
+
* @param asset Asset address
|
|
80
|
+
* @param price Underlying price in 18 decimals
|
|
81
|
+
* @custom:access Only Governance
|
|
82
|
+
* @custom:event Emits PricePosted event on succesfully setup of underlying price
|
|
83
|
+
*/
|
|
84
|
+
function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) onlyOwner {
|
|
85
|
+
emit PricePosted(asset, prices[asset], price, price);
|
|
86
|
+
prices[asset] = price;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @notice Add multiple token configs at the same time
|
|
91
|
+
* @param tokenConfigs_ config array
|
|
92
|
+
* @custom:access Only Governance
|
|
93
|
+
* @custom:error Zero length error thrown, if length of the array in parameter is 0
|
|
94
|
+
*/
|
|
95
|
+
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
|
|
96
|
+
require(tokenConfigs_.length > 0, "length can't be 0");
|
|
97
|
+
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
98
|
+
for (uint256 i; i < numTokenConfigs; ++i) {
|
|
99
|
+
setTokenConfig(tokenConfigs_[i]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
60
103
|
/// @notice Initializes the owner of the contract
|
|
61
104
|
function initialize() public initializer {
|
|
62
105
|
__Ownable_init();
|
|
63
106
|
}
|
|
64
107
|
|
|
65
108
|
/**
|
|
66
|
-
* @notice
|
|
109
|
+
* @notice Add single token config. vToken & feed cannot be null addresses and maxStalePeriod must be positive
|
|
110
|
+
* @param tokenConfig Token config struct
|
|
111
|
+
* @custom:access Only Governance
|
|
112
|
+
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
113
|
+
* @custom:error NotNullAddress error is thrown if token feed address is null
|
|
114
|
+
* @custom:error Range error is thrown if maxStale period of token is not greater than zero
|
|
115
|
+
* @custom:event Emits TokenConfigAdded event on succesfully setting of the token config
|
|
116
|
+
*/
|
|
117
|
+
function setTokenConfig(
|
|
118
|
+
TokenConfig memory tokenConfig
|
|
119
|
+
) public onlyOwner notNullAddress(tokenConfig.asset) notNullAddress(tokenConfig.feed) {
|
|
120
|
+
require(tokenConfig.maxStalePeriod > 0, "stale period can't be zero");
|
|
121
|
+
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
122
|
+
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.feed, tokenConfig.maxStalePeriod);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
|
|
67
127
|
* @param vToken vToken address
|
|
68
|
-
* @return price in USD
|
|
128
|
+
* @return price Underlying price in USD
|
|
69
129
|
*/
|
|
70
130
|
function getUnderlyingPrice(address vToken) public view override returns (uint256) {
|
|
71
131
|
string memory symbol = address(vToken) != vBnb ? VBep20Interface(vToken).symbol() : "BNB";
|
|
@@ -78,16 +138,18 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
78
138
|
}
|
|
79
139
|
|
|
80
140
|
/**
|
|
81
|
-
* @notice
|
|
82
|
-
*
|
|
141
|
+
* @notice Gets the Chainlink price for the underlying asset of a given vToken
|
|
142
|
+
* or the manually set price if it's been set
|
|
143
|
+
* @dev The decimals of the underlying token are considered to ensure the returned price
|
|
144
|
+
* has 18 decimals of precision
|
|
83
145
|
* @param vToken vToken address
|
|
84
|
-
* @return price in USD
|
|
146
|
+
* @return price Underlying price in USD
|
|
85
147
|
*/
|
|
86
148
|
function _getUnderlyingPriceInternal(VBep20Interface vToken) internal view returns (uint256 price) {
|
|
87
149
|
address token;
|
|
88
150
|
uint256 decimals;
|
|
89
151
|
|
|
90
|
-
//
|
|
152
|
+
// vBNB token doesn't have `underlying` method
|
|
91
153
|
if (address(vToken) == vBnb) {
|
|
92
154
|
token = BNB_ADDR;
|
|
93
155
|
decimals = 18;
|
|
@@ -108,14 +170,14 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
108
170
|
}
|
|
109
171
|
|
|
110
172
|
/**
|
|
111
|
-
* @notice Get the Chainlink price
|
|
112
|
-
* @dev The
|
|
113
|
-
* @param asset
|
|
114
|
-
* @return price in USD, with 18 decimals
|
|
115
|
-
* @custom:error NotNullAddress error thrown if asset address is
|
|
116
|
-
* @custom:error Price error if
|
|
117
|
-
* @custom:error Timing error if current timestamp is less than last
|
|
118
|
-
* @custom:error Timing error if time difference between current time and last
|
|
173
|
+
* @notice Get the Chainlink price for the underlying asset of a given vToken, revert if token config doesn't exit
|
|
174
|
+
* @dev The precision of the price feed is used to ensure the returned price has 18 decimals of precision
|
|
175
|
+
* @param asset Underlying asset address
|
|
176
|
+
* @return price Underlying price in USD, with 18 decimals of precision
|
|
177
|
+
* @custom:error NotNullAddress error is thrown if the asset address is null
|
|
178
|
+
* @custom:error Price error is thrown if the Chainlink price of asset is not greater than zero
|
|
179
|
+
* @custom:error Timing error is thrown if current timestamp is less than the last updatedAt timestamp
|
|
180
|
+
* @custom:error Timing error is thrown if time difference between current time and last updated time
|
|
119
181
|
* is greater than maxStalePeriod
|
|
120
182
|
*/
|
|
121
183
|
function _getChainlinkPrice(
|
|
@@ -140,66 +202,6 @@ contract ChainlinkOracle is OwnableUpgradeable, OracleInterface {
|
|
|
140
202
|
return uint256(answer) * (10 ** decimalDelta);
|
|
141
203
|
}
|
|
142
204
|
|
|
143
|
-
/**
|
|
144
|
-
* @notice Set the forced prices of the underlying token of input vToken
|
|
145
|
-
* @param vToken vToken address
|
|
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
|
|
150
|
-
*/
|
|
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());
|
|
156
|
-
emit PricePosted(asset, prices[asset], underlyingPriceMantissa, underlyingPriceMantissa);
|
|
157
|
-
prices[asset] = underlyingPriceMantissa;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* @notice Set the forced prices of the input token
|
|
162
|
-
* @param asset asset address
|
|
163
|
-
* @param price price in 18 decimals
|
|
164
|
-
* @custom:access Only GOvernance
|
|
165
|
-
* @custom:event Emits PricePosted event on succesfully setup of underlying price
|
|
166
|
-
*/
|
|
167
|
-
function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) onlyOwner {
|
|
168
|
-
emit PricePosted(asset, prices[asset], price, price);
|
|
169
|
-
prices[asset] = price;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* @notice Add multiple token configs at the same time
|
|
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
|
|
177
|
-
*/
|
|
178
|
-
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
|
|
179
|
-
require(tokenConfigs_.length > 0, "length can't be 0");
|
|
180
|
-
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
181
|
-
for (uint256 i; i < numTokenConfigs; ++i) {
|
|
182
|
-
setTokenConfig(tokenConfigs_[i]);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* @notice Add single token config, vToken & feed cannot be zero address, and maxStalePeriod must be positive
|
|
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
|
|
194
|
-
*/
|
|
195
|
-
function setTokenConfig(
|
|
196
|
-
TokenConfig memory tokenConfig
|
|
197
|
-
) public onlyOwner notNullAddress(tokenConfig.asset) notNullAddress(tokenConfig.feed) {
|
|
198
|
-
require(tokenConfig.maxStalePeriod > 0, "stale period can't be zero");
|
|
199
|
-
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
200
|
-
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.feed, tokenConfig.maxStalePeriod);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
205
|
function _compareStrings(string memory a, string memory b) internal pure returns (bool) {
|
|
204
206
|
return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
|
|
205
207
|
}
|
|
@@ -16,7 +16,7 @@ struct TokenConfig {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* PythOracle contract reads prices from actual Pyth oracle contract which accepts
|
|
19
|
+
* PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores the
|
|
20
20
|
* updated prices from external sources
|
|
21
21
|
*/
|
|
22
22
|
contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
@@ -28,7 +28,7 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
28
28
|
// To cast int64/int8 types from Pyth to unsigned types
|
|
29
29
|
using SafeCast for int256;
|
|
30
30
|
|
|
31
|
-
/// @notice
|
|
31
|
+
/// @notice Exponent scale (decimal precision) of prices
|
|
32
32
|
uint256 public constant EXP_SCALE = 1e18;
|
|
33
33
|
|
|
34
34
|
/// @notice vBNB address
|
|
@@ -38,47 +38,36 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
38
38
|
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
39
39
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
40
40
|
|
|
41
|
-
/// @notice
|
|
41
|
+
/// @notice The actual pyth oracle address fetch & store the prices
|
|
42
42
|
IPyth public underlyingPythOracle;
|
|
43
43
|
|
|
44
|
-
/// @notice
|
|
44
|
+
/// @notice Token configs by asset address
|
|
45
|
+
mapping(address => TokenConfig) public tokenConfigs;
|
|
46
|
+
|
|
47
|
+
/// @notice Emit when setting a new pyth oracle address
|
|
45
48
|
event PythOracleSet(address indexed newPythOracle);
|
|
46
49
|
|
|
47
|
-
/// @notice
|
|
50
|
+
/// @notice Emit when a token config is added
|
|
48
51
|
event TokenConfigAdded(address indexed vToken, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
|
|
49
52
|
|
|
50
|
-
/// @notice token configs by asset address
|
|
51
|
-
mapping(address => TokenConfig) public tokenConfigs;
|
|
52
|
-
|
|
53
53
|
modifier notNullAddress(address someone) {
|
|
54
54
|
require(someone != address(0), "can't be zero address");
|
|
55
55
|
_;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
59
|
-
/// @param vBnbAddress The address of the
|
|
59
|
+
/// @param vBnbAddress The address of the vBNB
|
|
60
60
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
61
61
|
constructor(address vBnbAddress) notNullAddress(vBnbAddress) {
|
|
62
62
|
vBnb = vBnbAddress;
|
|
63
63
|
_disableInitializers();
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
/**
|
|
67
|
-
* @notice Initializes the owner of the contract and sets required contracts
|
|
68
|
-
* @param underlyingPythOracle_ Address of the pyth oracle
|
|
69
|
-
*/
|
|
70
|
-
function initialize(address underlyingPythOracle_) public initializer {
|
|
71
|
-
__Ownable_init();
|
|
72
|
-
require(underlyingPythOracle_ != address(0), "pyth oracle cannot be zero address");
|
|
73
|
-
underlyingPythOracle = IPyth(underlyingPythOracle_);
|
|
74
|
-
emit PythOracleSet(underlyingPythOracle_);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
66
|
/**
|
|
78
67
|
* @notice Batch set token configs
|
|
79
|
-
* @param tokenConfigs_
|
|
68
|
+
* @param tokenConfigs_ Token config array
|
|
80
69
|
* @custom:access Only Governance
|
|
81
|
-
* @custom:error Zero length error thrown
|
|
70
|
+
* @custom:error Zero length error is thrown if length of the array in parameter is 0
|
|
82
71
|
*/
|
|
83
72
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
|
|
84
73
|
require(tokenConfigs_.length != 0, "length can't be 0");
|
|
@@ -89,21 +78,8 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
89
78
|
}
|
|
90
79
|
|
|
91
80
|
/**
|
|
92
|
-
* @notice Set
|
|
93
|
-
* @param
|
|
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
|
|
97
|
-
*/
|
|
98
|
-
function setTokenConfig(TokenConfig memory tokenConfig) public onlyOwner notNullAddress(tokenConfig.asset) {
|
|
99
|
-
require(tokenConfig.maxStalePeriod != 0, "max stale period cannot be 0");
|
|
100
|
-
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
101
|
-
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @notice set the underlying pyth oracle contract address
|
|
106
|
-
* @param underlyingPythOracle_ pyth oracle contract address
|
|
81
|
+
* @notice Set the underlying Pyth oracle contract address
|
|
82
|
+
* @param underlyingPythOracle_ Pyth oracle contract address
|
|
107
83
|
* @custom:access Only Governance
|
|
108
84
|
* @custom:error NotNullAddress error thrown if underlyingPythOracle_ address is zero
|
|
109
85
|
* @custom:event Emits PythOracleSet event with address of Pyth oracle.
|
|
@@ -115,14 +91,38 @@ contract PythOracle is OwnableUpgradeable, OracleInterface {
|
|
|
115
91
|
emit PythOracleSet(address(underlyingPythOracle_));
|
|
116
92
|
}
|
|
117
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @notice Initializes the owner of the contract and sets required contracts
|
|
96
|
+
* @param underlyingPythOracle_ Address of the Pyth oracle
|
|
97
|
+
*/
|
|
98
|
+
function initialize(address underlyingPythOracle_) public initializer {
|
|
99
|
+
__Ownable_init();
|
|
100
|
+
require(underlyingPythOracle_ != address(0), "pyth oracle cannot be zero address");
|
|
101
|
+
underlyingPythOracle = IPyth(underlyingPythOracle_);
|
|
102
|
+
emit PythOracleSet(underlyingPythOracle_);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `vToken` can be a null address
|
|
107
|
+
* @param tokenConfig Token config struct
|
|
108
|
+
* @custom:access Only Governance
|
|
109
|
+
* @custom:error Range error is thrown if max stale period is zero
|
|
110
|
+
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
111
|
+
*/
|
|
112
|
+
function setTokenConfig(TokenConfig memory tokenConfig) public onlyOwner notNullAddress(tokenConfig.asset) {
|
|
113
|
+
require(tokenConfig.maxStalePeriod != 0, "max stale period cannot be 0");
|
|
114
|
+
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
115
|
+
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
118
|
/**
|
|
119
119
|
* @notice Get price of underlying asset of the input vToken, under the hood this function
|
|
120
120
|
* get price from Pyth contract, the prices of which are updated externally
|
|
121
121
|
* @param vToken vToken address
|
|
122
|
-
* @return price
|
|
123
|
-
* @custom:error Zero address error thrown if underlyingPythOracle address is
|
|
124
|
-
* @custom:error Zero address error thrown if asset address is
|
|
125
|
-
* @custom:error Range error thrown if price of
|
|
122
|
+
* @return price Underlying price with a precision of 10 decimals
|
|
123
|
+
* @custom:error Zero address error thrown if underlyingPythOracle address is null
|
|
124
|
+
* @custom:error Zero address error thrown if asset address is null
|
|
125
|
+
* @custom:error Range error thrown if price of Pyth oracle is not greater than zero
|
|
126
126
|
*/
|
|
127
127
|
function getUnderlyingPrice(address vToken) public view override returns (uint256) {
|
|
128
128
|
require(address(underlyingPythOracle) != address(0), "Pyth oracle is zero address");
|