@venusprotocol/oracle 1.6.12-dev.2 → 1.6.12-dev.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +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/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/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/SafeCast.sol/SafeCast.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
- 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/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +1 -1
- package/artifacts/build-info/{fc01a49cbd804e304740a46d676189d0.json → e6185827013b85f715ee874203b21fc8.json} +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +36 -4
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +10 -10
- 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/OracleInterface.json +2 -2
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +19 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +2 -2
- 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/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/IPancakePair.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +49 -42
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +4 -54
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +5 -60
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +6 -43
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +18 -41
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +16 -16
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
- 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/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +1 -1
- 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/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +32 -3
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +21 -2
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
- package/contracts/ResilientOracle.sol +100 -70
- package/contracts/interfaces/FeedRegistryInterface.sol +4 -4
- package/contracts/interfaces/OracleInterface.sol +3 -1
- package/contracts/oracles/BinanceOracle.sol +53 -61
- package/contracts/oracles/BoundValidator.sol +22 -51
- package/contracts/oracles/ChainlinkOracle.sol +25 -65
- package/contracts/oracles/PythOracle.sol +28 -48
- package/contracts/oracles/TwapOracle.sol +39 -57
- package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +6 -6
- package/contracts/test/MockSimpleOracle.sol +14 -2
- package/dist/deploy/1-deploy-oracles.js +6 -6
- package/dist/deploy/1-deploy-oracles.js.map +1 -1
- package/package.json +2 -2
|
@@ -8,6 +8,7 @@ import "../interfaces/FeedRegistryInterface.sol";
|
|
|
8
8
|
import "../interfaces/PublicResolverInterface.sol";
|
|
9
9
|
import "../interfaces/OracleInterface.sol";
|
|
10
10
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
11
|
+
import "../interfaces/OracleInterface.sol";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* @title BinanceOracle
|
|
@@ -17,28 +18,31 @@ import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlle
|
|
|
17
18
|
contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
18
19
|
address public sidRegistryAddress;
|
|
19
20
|
|
|
20
|
-
/// @notice
|
|
21
|
-
|
|
22
|
-
address public immutable vBnb;
|
|
21
|
+
/// @notice Set this as asset address for BNB. This is the underlying address for vBNB
|
|
22
|
+
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
23
23
|
|
|
24
|
-
/// @notice
|
|
25
|
-
|
|
26
|
-
address public immutable vai;
|
|
24
|
+
/// @notice Quote address for USD
|
|
25
|
+
address public constant USD_ADDR = 0x0000000000000000000000000000000000000348;
|
|
27
26
|
|
|
28
27
|
/// @notice Max stale period configuration for assets
|
|
29
28
|
mapping(string => uint256) public maxStalePeriod;
|
|
30
29
|
|
|
30
|
+
/// @notice Address of WBNB contract
|
|
31
|
+
address public WBNB;
|
|
32
|
+
|
|
31
33
|
event MaxStalePeriodAdded(string indexed asset, uint256 maxStalePeriod);
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @notice Checks whether an address is null or not
|
|
37
|
+
*/
|
|
38
|
+
modifier notNullAddress(address someone) {
|
|
39
|
+
if (someone == address(0)) revert("can't be zero address");
|
|
40
|
+
_;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// @notice Constructor for the implementation contract.
|
|
36
44
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
37
|
-
constructor(
|
|
38
|
-
if (vBnbAddress == address(0)) revert("vBNB can't be zero address");
|
|
39
|
-
if (vaiAddress == address(0)) revert("VAI can't be zero address");
|
|
40
|
-
vBnb = vBnbAddress;
|
|
41
|
-
vai = vaiAddress;
|
|
45
|
+
constructor() {
|
|
42
46
|
_disableInitializers();
|
|
43
47
|
}
|
|
44
48
|
|
|
@@ -60,45 +64,58 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
|
60
64
|
* @notice Sets the contracts required to fetch prices
|
|
61
65
|
* @param _sidRegistryAddress Address of SID registry
|
|
62
66
|
* @param _accessControlManager Address of the access control manager contract
|
|
67
|
+
* @param _WBNB Address of the wBNB contract
|
|
63
68
|
*/
|
|
64
|
-
function initialize(
|
|
69
|
+
function initialize(
|
|
70
|
+
address _sidRegistryAddress,
|
|
71
|
+
address _accessControlManager,
|
|
72
|
+
address _WBNB
|
|
73
|
+
) external reinitializer(2) notNullAddress(_sidRegistryAddress) notNullAddress(_WBNB) {
|
|
65
74
|
sidRegistryAddress = _sidRegistryAddress;
|
|
75
|
+
WBNB = _WBNB;
|
|
66
76
|
__AccessControlled_init(_accessControlManager);
|
|
67
77
|
}
|
|
68
78
|
|
|
69
79
|
/**
|
|
70
|
-
* @notice
|
|
71
|
-
* @
|
|
80
|
+
* @notice Uses Space ID to fetch the feed registry address
|
|
81
|
+
* @return feedRegistryAddress Address of binance oracle feed registry.
|
|
82
|
+
*/
|
|
83
|
+
function getFeedRegistryAddress() public view returns (address) {
|
|
84
|
+
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
|
|
85
|
+
|
|
86
|
+
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
87
|
+
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
88
|
+
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
89
|
+
|
|
90
|
+
return publicResolver.addr(nodeHash);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @notice Gets the price of a asset from the binance oracle
|
|
95
|
+
* @param asset Address of the asset
|
|
72
96
|
* @return Price in USD
|
|
73
97
|
*/
|
|
74
|
-
function
|
|
98
|
+
function getPrice(address asset) public view returns (uint256) {
|
|
75
99
|
string memory symbol;
|
|
76
100
|
uint256 decimals;
|
|
77
101
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
symbol = "BNB";
|
|
81
|
-
decimals = 18;
|
|
82
|
-
} else if (vToken == vai) {
|
|
83
|
-
symbol = "VAI";
|
|
102
|
+
if (asset == BNB_ADDR) {
|
|
103
|
+
symbol = "WBNB";
|
|
84
104
|
decimals = 18;
|
|
105
|
+
asset = WBNB;
|
|
85
106
|
} else {
|
|
86
|
-
IERC20Metadata
|
|
87
|
-
symbol =
|
|
88
|
-
decimals =
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (compare(symbol, "WBNB")) {
|
|
92
|
-
symbol = "BNB";
|
|
107
|
+
IERC20Metadata token = IERC20Metadata(asset);
|
|
108
|
+
symbol = token.symbol();
|
|
109
|
+
decimals = token.decimals();
|
|
93
110
|
}
|
|
94
111
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
112
|
+
return _getPrice(asset, symbol, decimals);
|
|
113
|
+
}
|
|
98
114
|
|
|
115
|
+
function _getPrice(address asset, string memory symbol, uint256 decimals) internal view returns (uint256) {
|
|
99
116
|
FeedRegistryInterface feedRegistry = FeedRegistryInterface(getFeedRegistryAddress());
|
|
100
117
|
|
|
101
|
-
(, int256 answer, , uint256 updatedAt, ) = feedRegistry.
|
|
118
|
+
(, int256 answer, , uint256 updatedAt, ) = feedRegistry.latestRoundData(asset, USD_ADDR);
|
|
102
119
|
if (answer <= 0) revert("invalid binance oracle price");
|
|
103
120
|
if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
|
|
104
121
|
|
|
@@ -106,34 +123,9 @@ contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
|
106
123
|
unchecked {
|
|
107
124
|
deltaTime = block.timestamp - updatedAt;
|
|
108
125
|
}
|
|
109
|
-
|
|
110
126
|
if (deltaTime > maxStalePeriod[symbol]) revert("binance oracle price expired");
|
|
111
127
|
|
|
112
|
-
uint256 decimalDelta = feedRegistry.
|
|
128
|
+
uint256 decimalDelta = feedRegistry.decimals(asset, USD_ADDR);
|
|
113
129
|
return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
|
|
114
130
|
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @notice Uses Space ID to fetch the feed registry address
|
|
118
|
-
* @return feedRegistryAddress Address of binance oracle feed registry.
|
|
119
|
-
*/
|
|
120
|
-
function getFeedRegistryAddress() public view returns (address) {
|
|
121
|
-
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
|
|
122
|
-
|
|
123
|
-
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
124
|
-
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
125
|
-
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
126
|
-
|
|
127
|
-
return publicResolver.addr(nodeHash);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* @notice Used to compare if two strings are equal or not
|
|
132
|
-
* @param str1 The first string
|
|
133
|
-
* @param str2 The second string
|
|
134
|
-
* @return equal Returns true if both are equal or else false.
|
|
135
|
-
*/
|
|
136
|
-
function compare(string memory str1, string memory str2) private pure returns (bool) {
|
|
137
|
-
return keccak256(bytes(str1)) == keccak256(bytes(str2));
|
|
138
|
-
}
|
|
139
131
|
}
|
|
@@ -27,29 +27,12 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
27
27
|
/// @notice validation configs by asset
|
|
28
28
|
mapping(address => ValidateConfig) public validateConfigs;
|
|
29
29
|
|
|
30
|
-
/// @notice vBNB address
|
|
31
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
32
|
-
address public immutable vBnb;
|
|
33
|
-
|
|
34
|
-
/// @notice VAI address
|
|
35
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
36
|
-
address public immutable vai;
|
|
37
|
-
|
|
38
|
-
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
39
|
-
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
40
|
-
|
|
41
30
|
/// @notice Emit this event when new validation configs are added
|
|
42
31
|
event ValidateConfigAdded(address indexed asset, uint256 indexed upperBound, uint256 indexed lowerBound);
|
|
43
32
|
|
|
44
33
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
45
|
-
/// @param vBnbAddress The address of the vBNB
|
|
46
|
-
/// @param vaiAddress The address of the VAI
|
|
47
34
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
48
|
-
constructor(
|
|
49
|
-
if (vBnbAddress == address(0)) revert("vBNB can't be zero address");
|
|
50
|
-
if (vaiAddress == address(0)) revert("VAI can't be zero address");
|
|
51
|
-
vBnb = vBnbAddress;
|
|
52
|
-
vai = vaiAddress;
|
|
35
|
+
constructor() {
|
|
53
36
|
_disableInitializers();
|
|
54
37
|
}
|
|
55
38
|
|
|
@@ -79,25 +62,6 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
79
62
|
__AccessControlled_init(accessControlManager_);
|
|
80
63
|
}
|
|
81
64
|
|
|
82
|
-
/**
|
|
83
|
-
* @notice Test reported asset price against anchor price
|
|
84
|
-
* @param vToken vToken address
|
|
85
|
-
* @param reportedPrice The price to be tested
|
|
86
|
-
* @custom:error Missing error thrown if asset config is not set
|
|
87
|
-
* @custom:error Price error thrown if anchor price is not valid
|
|
88
|
-
*/
|
|
89
|
-
function validatePriceWithAnchorPrice(
|
|
90
|
-
address vToken,
|
|
91
|
-
uint256 reportedPrice,
|
|
92
|
-
uint256 anchorPrice
|
|
93
|
-
) external view override returns (bool) {
|
|
94
|
-
address asset = _getUnderlyingAsset(vToken);
|
|
95
|
-
|
|
96
|
-
if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
|
|
97
|
-
if (anchorPrice == 0) revert("anchor price is not valid");
|
|
98
|
-
return _isWithinAnchor(asset, reportedPrice, anchorPrice);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
65
|
/**
|
|
102
66
|
* @notice Add a single validation config
|
|
103
67
|
* @param config Validation config struct
|
|
@@ -117,6 +81,23 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
117
81
|
emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
|
|
118
82
|
}
|
|
119
83
|
|
|
84
|
+
/**
|
|
85
|
+
* @notice Test reported asset price against anchor price
|
|
86
|
+
* @param asset asset address
|
|
87
|
+
* @param reportedPrice The price to be tested
|
|
88
|
+
* @custom:error Missing error thrown if asset config is not set
|
|
89
|
+
* @custom:error Price error thrown if anchor price is not valid
|
|
90
|
+
*/
|
|
91
|
+
function validatePriceWithAnchorPrice(
|
|
92
|
+
address asset,
|
|
93
|
+
uint256 reportedPrice,
|
|
94
|
+
uint256 anchorPrice
|
|
95
|
+
) public view virtual override returns (bool) {
|
|
96
|
+
if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
|
|
97
|
+
if (anchorPrice == 0) revert("anchor price is not valid");
|
|
98
|
+
return _isWithinAnchor(asset, reportedPrice, anchorPrice);
|
|
99
|
+
}
|
|
100
|
+
|
|
120
101
|
/**
|
|
121
102
|
* @notice Test whether the reported price is within the valid bounds
|
|
122
103
|
* @param asset Asset address
|
|
@@ -134,18 +115,8 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
134
115
|
return false;
|
|
135
116
|
}
|
|
136
117
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*/
|
|
142
|
-
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
|
|
143
|
-
if (address(vToken) == vBnb) {
|
|
144
|
-
asset = BNB_ADDR;
|
|
145
|
-
} else if (address(vToken) == vai) {
|
|
146
|
-
asset = vai;
|
|
147
|
-
} else {
|
|
148
|
-
asset = VBep20Interface(vToken).underlying();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
118
|
+
// BoundValidator is to get inherited, so it's a good practice to add some storage gaps like
|
|
119
|
+
// OpenZepplin proposed in their contracts: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
120
|
+
// solhint-disable-next-line
|
|
121
|
+
uint256[49] private __gap;
|
|
151
122
|
}
|
|
@@ -23,14 +23,6 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
23
23
|
uint256 maxStalePeriod;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
/// @notice vBNB address
|
|
27
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
28
|
-
address public immutable vBnb;
|
|
29
|
-
|
|
30
|
-
/// @notice VAI address
|
|
31
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
32
|
-
address public immutable vai;
|
|
33
|
-
|
|
34
26
|
/// @notice Set this as asset address for BNB. This is the underlying address for vBNB
|
|
35
27
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
36
28
|
|
|
@@ -51,42 +43,18 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
51
43
|
_;
|
|
52
44
|
}
|
|
53
45
|
|
|
54
|
-
/// @notice Constructor for the implementation contract.
|
|
55
|
-
/// @param vBnbAddress The address of the vBNB
|
|
56
|
-
/// @param vaiAddress The address of the VAI
|
|
46
|
+
/// @notice Constructor for the implementation contract.
|
|
57
47
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
58
|
-
constructor(
|
|
59
|
-
vBnb = vBnbAddress;
|
|
60
|
-
vai = vaiAddress;
|
|
48
|
+
constructor() {
|
|
61
49
|
_disableInitializers();
|
|
62
50
|
}
|
|
63
51
|
|
|
64
|
-
/**
|
|
65
|
-
* @notice Set the forced prices of the underlying token of input vToken
|
|
66
|
-
* @param vToken vToken address
|
|
67
|
-
* @param underlyingPriceMantissa price in 18 decimals
|
|
68
|
-
* @custom:access Only Governance
|
|
69
|
-
* @custom:error NotNullAddress thrown if address of vToken is null
|
|
70
|
-
* @custom:event Emits PricePosted event on succesfully setup of underlying price
|
|
71
|
-
*/
|
|
72
|
-
function setUnderlyingPrice(
|
|
73
|
-
VBep20Interface vToken,
|
|
74
|
-
uint256 underlyingPriceMantissa
|
|
75
|
-
) external notNullAddress(address(vToken)) {
|
|
76
|
-
_checkAccessAllowed("setUnderlyingPrice(address,uint256)");
|
|
77
|
-
|
|
78
|
-
address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
|
|
79
|
-
uint256 previousPriceMantissa = prices[asset];
|
|
80
|
-
prices[asset] = underlyingPriceMantissa;
|
|
81
|
-
emit PricePosted(asset, previousPriceMantissa, prices[asset]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
52
|
/**
|
|
85
53
|
* @notice Manually set the price of a given asset
|
|
86
54
|
* @param asset Asset address
|
|
87
|
-
* @param price
|
|
55
|
+
* @param price Asset price in 18 decimals
|
|
88
56
|
* @custom:access Only Governance
|
|
89
|
-
* @custom:event Emits PricePosted event on succesfully setup of
|
|
57
|
+
* @custom:event Emits PricePosted event on succesfully setup of asset price
|
|
90
58
|
*/
|
|
91
59
|
function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) {
|
|
92
60
|
_checkAccessAllowed("setDirectPrice(address,uint256)");
|
|
@@ -122,16 +90,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
122
90
|
}
|
|
123
91
|
|
|
124
92
|
/**
|
|
125
|
-
* @notice
|
|
126
|
-
* @param vToken vToken address
|
|
127
|
-
* @return price Underlying price in USD
|
|
128
|
-
*/
|
|
129
|
-
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
130
|
-
return _getUnderlyingPriceInternal(VBep20Interface(vToken));
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* @notice Add single token config. vToken & feed cannot be null addresses and maxStalePeriod must be positive
|
|
93
|
+
* @notice Add single token config. asset & feed cannot be null addresses and maxStalePeriod must be positive
|
|
135
94
|
* @param tokenConfig Token config struct
|
|
136
95
|
* @custom:access Only Governance
|
|
137
96
|
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
@@ -150,29 +109,30 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
150
109
|
}
|
|
151
110
|
|
|
152
111
|
/**
|
|
153
|
-
* @notice Gets the
|
|
154
|
-
*
|
|
155
|
-
* @
|
|
156
|
-
* has 18 decimals of precision
|
|
157
|
-
* @param vToken vToken address
|
|
158
|
-
* @return price Underlying price in USD
|
|
112
|
+
* @notice Gets the price of a asset from the chainlink oracle
|
|
113
|
+
* @param asset Address of the asset
|
|
114
|
+
* @return Price in USD from Chainlink or a manually set price for the asset
|
|
159
115
|
*/
|
|
160
|
-
function
|
|
161
|
-
address token;
|
|
116
|
+
function getPrice(address asset) public view returns (uint256) {
|
|
162
117
|
uint256 decimals;
|
|
163
118
|
|
|
164
|
-
|
|
165
|
-
if (address(vToken) == vBnb) {
|
|
166
|
-
token = BNB_ADDR;
|
|
167
|
-
decimals = 18;
|
|
168
|
-
} else if (address(vToken) == vai) {
|
|
169
|
-
token = vai;
|
|
119
|
+
if (asset == BNB_ADDR) {
|
|
170
120
|
decimals = 18;
|
|
171
121
|
} else {
|
|
172
|
-
token =
|
|
173
|
-
decimals =
|
|
122
|
+
IERC20Metadata token = IERC20Metadata(asset);
|
|
123
|
+
decimals = token.decimals();
|
|
174
124
|
}
|
|
175
125
|
|
|
126
|
+
return _getPriceInternal(asset, decimals);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @notice Gets the Chainlink price for a given asset
|
|
131
|
+
* @param token address of the asset
|
|
132
|
+
* @param decimals decimals of the asset
|
|
133
|
+
* @return price Asset price in USD or a manually set price of the asset
|
|
134
|
+
*/
|
|
135
|
+
function _getPriceInternal(address token, uint256 decimals) internal view returns (uint256 price) {
|
|
176
136
|
uint256 tokenPrice = prices[token];
|
|
177
137
|
if (tokenPrice != 0) {
|
|
178
138
|
price = tokenPrice;
|
|
@@ -185,10 +145,10 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
185
145
|
}
|
|
186
146
|
|
|
187
147
|
/**
|
|
188
|
-
* @notice Get the Chainlink price for
|
|
148
|
+
* @notice Get the Chainlink price for an asset, revert if token config doesn't exist
|
|
189
149
|
* @dev The precision of the price feed is used to ensure the returned price has 18 decimals of precision
|
|
190
|
-
* @param asset
|
|
191
|
-
* @return price
|
|
150
|
+
* @param asset Address of the asset
|
|
151
|
+
* @return price Price in USD, with 18 decimals of precision
|
|
192
152
|
* @custom:error NotNullAddress error is thrown if the asset address is null
|
|
193
153
|
* @custom:error Price error is thrown if the Chainlink price of asset is not greater than zero
|
|
194
154
|
* @custom:error Timing error is thrown if current timestamp is less than the last updatedAt timestamp
|
|
@@ -30,14 +30,6 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
30
30
|
/// @notice Exponent scale (decimal precision) of prices
|
|
31
31
|
uint256 public constant EXP_SCALE = 1e18;
|
|
32
32
|
|
|
33
|
-
/// @notice vBNB address
|
|
34
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
35
|
-
address public immutable vBnb;
|
|
36
|
-
|
|
37
|
-
/// @notice VAI address
|
|
38
|
-
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
39
|
-
address public immutable vai;
|
|
40
|
-
|
|
41
33
|
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
42
34
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
43
35
|
|
|
@@ -51,20 +43,16 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
51
43
|
event PythOracleSet(address indexed oldPythOracle, address indexed newPythOracle);
|
|
52
44
|
|
|
53
45
|
/// @notice Emit when a token config is added
|
|
54
|
-
event TokenConfigAdded(address indexed
|
|
46
|
+
event TokenConfigAdded(address indexed asset, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
|
|
55
47
|
|
|
56
48
|
modifier notNullAddress(address someone) {
|
|
57
49
|
if (someone == address(0)) revert("can't be zero address");
|
|
58
50
|
_;
|
|
59
51
|
}
|
|
60
52
|
|
|
61
|
-
/// @notice Constructor for the implementation contract.
|
|
62
|
-
/// @param vBnbAddress The address of the vBNB
|
|
63
|
-
/// @param vaiAddress The address of the VAI
|
|
53
|
+
/// @notice Constructor for the implementation contract.
|
|
64
54
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
65
|
-
constructor(
|
|
66
|
-
vBnb = vBnbAddress;
|
|
67
|
-
vai = vaiAddress;
|
|
55
|
+
constructor() {
|
|
68
56
|
_disableInitializers();
|
|
69
57
|
}
|
|
70
58
|
|
|
@@ -117,32 +105,38 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
117
105
|
}
|
|
118
106
|
|
|
119
107
|
/**
|
|
120
|
-
* @notice
|
|
121
|
-
*
|
|
122
|
-
* @
|
|
123
|
-
* @
|
|
124
|
-
* @custom:error
|
|
125
|
-
* @custom:error Zero address error thrown if asset address is null
|
|
126
|
-
* @custom:error Range error thrown if price of Pyth oracle is not greater than zero
|
|
108
|
+
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `asset` cannot be a null address
|
|
109
|
+
* @param tokenConfig Token config struct
|
|
110
|
+
* @custom:access Only Governance
|
|
111
|
+
* @custom:error Range error is thrown if max stale period is zero
|
|
112
|
+
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
127
113
|
*/
|
|
128
|
-
function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
114
|
+
function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
|
|
115
|
+
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
116
|
+
if (tokenConfig.maxStalePeriod == 0) revert("max stale period cannot be 0");
|
|
117
|
+
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
118
|
+
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @notice Gets the price of a asset from the pyth oracle
|
|
123
|
+
* @param asset Address of the asset
|
|
124
|
+
* @return Price in USD
|
|
125
|
+
*/
|
|
126
|
+
function getPrice(address asset) public view returns (uint256) {
|
|
132
127
|
uint256 decimals;
|
|
133
128
|
|
|
134
|
-
|
|
135
|
-
if (vToken == vBnb) {
|
|
136
|
-
asset = BNB_ADDR;
|
|
137
|
-
decimals = 18;
|
|
138
|
-
} else if (vToken == vai) {
|
|
139
|
-
asset = vai;
|
|
129
|
+
if (asset == BNB_ADDR) {
|
|
140
130
|
decimals = 18;
|
|
141
131
|
} else {
|
|
142
|
-
|
|
143
|
-
decimals =
|
|
132
|
+
IERC20Metadata token = IERC20Metadata(asset);
|
|
133
|
+
decimals = token.decimals();
|
|
144
134
|
}
|
|
145
135
|
|
|
136
|
+
return _getPriceInternal(asset, decimals);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function _getPriceInternal(address asset, uint256 decimals) internal view returns (uint256) {
|
|
146
140
|
TokenConfig storage tokenConfig = tokenConfigs[asset];
|
|
147
141
|
if (tokenConfig.asset == address(0)) revert("asset doesn't exist");
|
|
148
142
|
|
|
@@ -164,18 +158,4 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
164
158
|
return ((price * EXP_SCALE) / (10 ** int256(-priceInfo.expo).toUint256())) * (10 ** (18 - decimals));
|
|
165
159
|
}
|
|
166
160
|
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `vToken` can be a null address
|
|
170
|
-
* @param tokenConfig Token config struct
|
|
171
|
-
* @custom:access Only Governance
|
|
172
|
-
* @custom:error Range error is thrown if max stale period is zero
|
|
173
|
-
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
174
|
-
*/
|
|
175
|
-
function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
|
|
176
|
-
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
177
|
-
if (tokenConfig.maxStalePeriod == 0) revert("max stale period cannot be 0");
|
|
178
|
-
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
179
|
-
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
180
|
-
}
|
|
181
161
|
}
|