@venusprotocol/oracle 1.0.0-dev.1 → 1.0.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/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +249 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +4 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +122 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +215 -0
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +183 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +297 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +194 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +233 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +30 -0
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +10 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +10 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +115 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +76 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +24 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +63 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +10 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +4 -0
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +24 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +4 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +369 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +4 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +181 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +4 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +282 -0
- package/artifacts/build-info/0137d0ff3ae413641739f9f6322cc2b3.json +1 -0
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +4 -0
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +617 -0
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +79 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +40 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +30 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +43 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +49 -0
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +30 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +545 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +446 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +4 -0
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +10 -0
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +30 -0
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +4 -0
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +246 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +4 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +10 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +4 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +60 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +4 -0
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +10 -0
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +342 -0
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +4 -0
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +392 -0
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +462 -0
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +445 -0
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +663 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +116 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +144 -0
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +144 -0
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +163 -0
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +4 -0
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +163 -0
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +4 -0
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +364 -0
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +4 -0
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +328 -0
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +4 -0
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +684 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +4 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +95 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +4 -0
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +72 -0
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +4 -0
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +306 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +4 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +10 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +4 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +158 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +4 -0
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +10 -0
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +4 -0
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +346 -0
- package/contracts/ResilientOracle.sol +35 -27
- package/contracts/interfaces/PythInterface.sol +4 -1
- package/contracts/oracles/BinanceOracle.sol +29 -24
- package/contracts/oracles/BoundValidator.sol +41 -44
- package/contracts/oracles/ChainlinkOracle.sol +44 -40
- package/contracts/oracles/PythOracle.sol +39 -34
- package/contracts/oracles/TwapOracle.sol +69 -65
- package/contracts/test/BEP20Harness.sol +4 -0
- package/contracts/test/MockPyth.sol +9 -2
- package/deployments/bscmainnet/BinanceOracle.json +279 -37
- package/deployments/bscmainnet/BinanceOracle_Implementation.json +399 -29
- package/deployments/bscmainnet/BinanceOracle_Proxy.json +58 -34
- package/deployments/bscmainnet/BoundValidator.json +50 -50
- package/deployments/bscmainnet/BoundValidator_Implementation.json +47 -55
- package/deployments/bscmainnet/BoundValidator_Proxy.json +46 -46
- package/deployments/bscmainnet/ChainlinkOracle.json +57 -49
- package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +48 -54
- package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +53 -39
- package/deployments/bscmainnet/DefaultProxyAdmin.json +16 -16
- package/deployments/bscmainnet/PythOracle.json +64 -57
- package/deployments/bscmainnet/PythOracle_Implementation.json +57 -51
- package/deployments/bscmainnet/PythOracle_Proxy.json +54 -53
- package/deployments/bscmainnet/ResilientOracle.json +57 -48
- package/deployments/bscmainnet/ResilientOracle_Implementation.json +67 -70
- package/deployments/bscmainnet/ResilientOracle_Proxy.json +54 -40
- package/deployments/bscmainnet/TwapOracle.json +69 -82
- package/deployments/bscmainnet/TwapOracle_Implementation.json +85 -98
- package/deployments/bscmainnet/TwapOracle_Proxy.json +46 -46
- package/deployments/bscmainnet/solcInputs/{8658c669dade0e9ab80874eab3bf3468.json → aae9f1601b873a5a4704ede73ede10cb.json} +37 -19
- package/deployments/bsctestnet/BinanceOracle.json +35 -35
- package/deployments/bsctestnet/BinanceOracle_Implementation.json +31 -31
- package/deployments/bsctestnet/BinanceOracle_Proxy.json +33 -33
- package/deployments/bsctestnet/BoundValidator.json +36 -36
- package/deployments/bsctestnet/BoundValidator_Implementation.json +44 -52
- package/deployments/bsctestnet/BoundValidator_Proxy.json +33 -33
- package/deployments/bsctestnet/ChainlinkOracle.json +36 -42
- package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +42 -48
- package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +33 -33
- package/deployments/bsctestnet/DefaultProxyAdmin.json +11 -11
- package/deployments/bsctestnet/PythOracle.json +48 -41
- package/deployments/bsctestnet/PythOracle_Implementation.json +51 -45
- package/deployments/bsctestnet/PythOracle_Proxy.json +39 -38
- package/deployments/bsctestnet/ResilientOracle.json +36 -41
- package/deployments/bsctestnet/ResilientOracle_Implementation.json +63 -66
- package/deployments/bsctestnet/ResilientOracle_Proxy.json +34 -34
- package/deployments/bsctestnet/TwapOracle.json +56 -56
- package/deployments/bsctestnet/TwapOracle_Implementation.json +81 -81
- package/deployments/bsctestnet/TwapOracle_Proxy.json +33 -33
- package/deployments/bsctestnet/solcInputs/{f35da22a430a956ee338e720b5898e3d.json → 131f58942628e21632de19506977a910.json} +7 -13
- package/deployments/bsctestnet/solcInputs/{4769dd98af512bf3b6b6504ad0c3bd74.json → 144b49e8aec3add79553ba273ea32d00.json} +4 -10
- package/deployments/bsctestnet/solcInputs/503f2e4e766f3be923fadf8030a5470f.json +78 -0
- package/deployments/bsctestnet/solcInputs/b39d33092f7dd383ae3a042566194132.json +75 -0
- package/dist/deploy/1-deploy-oracles.d.ts +5 -0
- package/dist/deploy/1-deploy-oracles.d.ts.map +1 -0
- package/dist/deploy/1-deploy-oracles.js +186 -0
- package/dist/deploy/1-deploy-oracles.js.map +1 -0
- package/dist/deploy/2-configure-feeds.d.ts +15 -0
- package/dist/deploy/2-configure-feeds.d.ts.map +1 -0
- package/dist/deploy/2-configure-feeds.js +300 -0
- package/dist/deploy/2-configure-feeds.js.map +1 -0
- package/dist/hardhat.config.d.ts +13 -0
- package/dist/hardhat.config.d.ts.map +1 -0
- package/dist/hardhat.config.js +158 -0
- package/dist/hardhat.config.js.map +1 -0
- package/package.json +2 -15
- package/deploy/1-deploy-oracles.ts +0 -195
- package/deploy/2-configure-feeds.ts +0 -324
- package/deployments/bscmainnet/solcInputs/68ea814c0d6925581f2bda5deba8ce4a.json +0 -60
|
@@ -45,7 +45,9 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
45
45
|
/// @notice Set this as asset address for BNB. This is the underlying for vBNB
|
|
46
46
|
address public constant BNB_ADDR = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB;
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
/// @notice Bound validator contract address
|
|
49
|
+
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
50
|
+
BoundValidatorInterface public immutable boundValidator;
|
|
49
51
|
|
|
50
52
|
mapping(address => TokenConfig) private tokenConfigs;
|
|
51
53
|
|
|
@@ -83,13 +85,29 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
83
85
|
/// @notice Constructor for the implementation contract. Sets immutable variables.
|
|
84
86
|
/// @param vBnbAddress The address of the vBNB
|
|
85
87
|
/// @param vaiAddress The address of the VAI
|
|
88
|
+
/// @param _boundValidator Address of the bound validator contract
|
|
86
89
|
/// @custom:oz-upgrades-unsafe-allow constructor
|
|
87
|
-
constructor(
|
|
90
|
+
constructor(
|
|
91
|
+
address vBnbAddress,
|
|
92
|
+
address vaiAddress,
|
|
93
|
+
BoundValidatorInterface _boundValidator
|
|
94
|
+
) notNullAddress(vBnbAddress) notNullAddress(vaiAddress) notNullAddress(address(_boundValidator)) {
|
|
88
95
|
vBnb = vBnbAddress;
|
|
89
96
|
vai = vaiAddress;
|
|
97
|
+
boundValidator = _boundValidator;
|
|
98
|
+
|
|
90
99
|
_disableInitializers();
|
|
91
100
|
}
|
|
92
101
|
|
|
102
|
+
/**
|
|
103
|
+
* @notice Initializes the contract admin and sets the BoundValidator contract address
|
|
104
|
+
* @param accessControlManager_ Address of the access control manager contract
|
|
105
|
+
*/
|
|
106
|
+
function initialize(address accessControlManager_) external initializer {
|
|
107
|
+
__AccessControlled_init(accessControlManager_);
|
|
108
|
+
__Pausable_init();
|
|
109
|
+
}
|
|
110
|
+
|
|
93
111
|
/**
|
|
94
112
|
* @notice Pauses oracle
|
|
95
113
|
* @custom:access Only Governance
|
|
@@ -112,14 +130,16 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
112
130
|
* @notice Batch sets token configs
|
|
113
131
|
* @param tokenConfigs_ Token config array
|
|
114
132
|
* @custom:access Only Governance
|
|
115
|
-
* @custom:error Throws a length error if the
|
|
133
|
+
* @custom:error Throws a length error if the length of the token configs array is 0
|
|
116
134
|
*/
|
|
117
135
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
|
|
118
|
-
_checkAccessAllowed("setTokenConfigs(TokenConfig[])");
|
|
119
136
|
if (tokenConfigs_.length == 0) revert("length can't be 0");
|
|
120
137
|
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
121
|
-
for (uint256 i; i < numTokenConfigs;
|
|
138
|
+
for (uint256 i; i < numTokenConfigs; ) {
|
|
122
139
|
setTokenConfig(tokenConfigs_[i]);
|
|
140
|
+
unchecked {
|
|
141
|
+
++i;
|
|
142
|
+
}
|
|
123
143
|
}
|
|
124
144
|
}
|
|
125
145
|
|
|
@@ -140,7 +160,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
140
160
|
address oracle,
|
|
141
161
|
OracleRole role
|
|
142
162
|
) external notNullAddress(asset) checkTokenConfigExistence(asset) {
|
|
143
|
-
_checkAccessAllowed("setOracle(address,address,
|
|
163
|
+
_checkAccessAllowed("setOracle(address,address,uint8)");
|
|
144
164
|
if (oracle == address(0) && role == OracleRole.MAIN) revert("can't set zero address to main oracle");
|
|
145
165
|
tokenConfigs[asset].oracles[uint256(role)] = oracle;
|
|
146
166
|
emit OracleSet(asset, oracle, uint256(role));
|
|
@@ -160,20 +180,20 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
160
180
|
OracleRole role,
|
|
161
181
|
bool enable
|
|
162
182
|
) external notNullAddress(asset) checkTokenConfigExistence(asset) {
|
|
163
|
-
_checkAccessAllowed("enableOracle(address,
|
|
183
|
+
_checkAccessAllowed("enableOracle(address,uint8,bool)");
|
|
164
184
|
tokenConfigs[asset].enableFlagsForOracles[uint256(role)] = enable;
|
|
165
185
|
emit OracleEnabled(asset, uint256(role), enable);
|
|
166
186
|
}
|
|
167
187
|
|
|
168
188
|
/**
|
|
169
|
-
* @notice Updates the pivot oracle price.
|
|
189
|
+
* @notice Updates the TWAP pivot oracle price.
|
|
170
190
|
* @dev This function should always be called before calling getUnderlyingPrice
|
|
171
191
|
* @param vToken vToken address
|
|
172
192
|
*/
|
|
173
193
|
function updatePrice(address vToken) external override {
|
|
174
194
|
(address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
|
|
175
195
|
if (pivotOracle != address(0) && pivotOracleEnabled) {
|
|
176
|
-
//if
|
|
196
|
+
//if pivot oracle is not TwapOracle it will revert so we need to catch the revert
|
|
177
197
|
try TwapInterface(pivotOracle).updateTwap(vToken) {} catch {}
|
|
178
198
|
}
|
|
179
199
|
}
|
|
@@ -192,7 +212,8 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
192
212
|
* @notice Gets price of the underlying asset for a given vToken. Validation flow:
|
|
193
213
|
* - Check if the oracle is paused globally
|
|
194
214
|
* - Validate price from main oracle against pivot oracle
|
|
195
|
-
* - Validate price from fallback oracle against pivot oracle
|
|
215
|
+
* - Validate price from fallback oracle against pivot oracle if the first validation failed
|
|
216
|
+
* - Validate price from main oracle against fallback oracle if the second validation failed
|
|
196
217
|
* In the case that the pivot oracle is not available but main price is available and validation is successful,
|
|
197
218
|
* main oracle price is returned.
|
|
198
219
|
* @param vToken vToken address
|
|
@@ -231,7 +252,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
231
252
|
if (
|
|
232
253
|
mainPrice != INVALID_PRICE &&
|
|
233
254
|
fallbackPrice != INVALID_PRICE &&
|
|
234
|
-
boundValidator.validatePriceWithAnchorPrice(vToken,
|
|
255
|
+
boundValidator.validatePriceWithAnchorPrice(vToken, mainPrice, fallbackPrice)
|
|
235
256
|
) {
|
|
236
257
|
return mainPrice;
|
|
237
258
|
}
|
|
@@ -239,19 +260,6 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
239
260
|
revert("invalid resilient oracle price");
|
|
240
261
|
}
|
|
241
262
|
|
|
242
|
-
/**
|
|
243
|
-
* @notice Initializes the contract admin and sets the BoundValidator contract address
|
|
244
|
-
* @param _boundValidator Address of the bound validator contract
|
|
245
|
-
* @param accessControlManager_ Address of the access control manager contract
|
|
246
|
-
*/
|
|
247
|
-
function initialize(BoundValidatorInterface _boundValidator, address accessControlManager_) public initializer {
|
|
248
|
-
if (address(_boundValidator) == address(0)) revert("invalid bound validator address");
|
|
249
|
-
boundValidator = _boundValidator;
|
|
250
|
-
|
|
251
|
-
__AccessControlled_init(accessControlManager_);
|
|
252
|
-
__Pausable_init();
|
|
253
|
-
}
|
|
254
|
-
|
|
255
263
|
/**
|
|
256
264
|
* @notice Sets/resets single token configs.
|
|
257
265
|
* @dev main oracle **must not** be a null address
|
|
@@ -308,7 +316,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
308
316
|
address vToken,
|
|
309
317
|
uint256 pivotPrice,
|
|
310
318
|
bool pivotEnabled
|
|
311
|
-
)
|
|
319
|
+
) private view returns (uint256, bool) {
|
|
312
320
|
(address mainOracle, bool mainOracleEnabled) = getOracle(vToken, OracleRole.MAIN);
|
|
313
321
|
if (mainOracleEnabled && mainOracle != address(0)) {
|
|
314
322
|
try OracleInterface(mainOracle).getUnderlyingPrice(vToken) returns (uint256 mainOraclePrice) {
|
|
@@ -340,7 +348,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
340
348
|
* @custom:error Invalid price error is thrown if fallback oracle is not enabled or fallback oracle
|
|
341
349
|
* address is null
|
|
342
350
|
*/
|
|
343
|
-
function _getFallbackOraclePrice(address vToken, uint256 pivotPrice)
|
|
351
|
+
function _getFallbackOraclePrice(address vToken, uint256 pivotPrice) private view returns (uint256, bool) {
|
|
344
352
|
(address fallbackOracle, bool fallbackEnabled) = getOracle(vToken, OracleRole.FALLBACK);
|
|
345
353
|
if (fallbackEnabled && fallbackOracle != address(0)) {
|
|
346
354
|
try OracleInterface(fallbackOracle).getUnderlyingPrice(vToken) returns (uint256 fallbackOraclePrice) {
|
|
@@ -364,7 +372,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
|
|
|
364
372
|
* @param vToken vToken address
|
|
365
373
|
* @return asset underlying asset address
|
|
366
374
|
*/
|
|
367
|
-
function _getUnderlyingAsset(address vToken)
|
|
375
|
+
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
|
|
368
376
|
if (address(vToken) == vBnb) {
|
|
369
377
|
asset = BNB_ADDR;
|
|
370
378
|
} else if (address(vToken) == vai) {
|
|
@@ -235,11 +235,14 @@ abstract contract AbstractPyth is IPyth {
|
|
|
235
235
|
require(priceIds.length == publishTimes.length, "priceIds and publishTimes arrays should have same length");
|
|
236
236
|
|
|
237
237
|
bool updateNeeded = false;
|
|
238
|
-
for (uint256 i = 0; i < priceIds.length;
|
|
238
|
+
for (uint256 i = 0; i < priceIds.length; ) {
|
|
239
239
|
if (!priceFeedExists(priceIds[i]) || queryPriceFeed(priceIds[i]).price.publishTime < publishTimes[i]) {
|
|
240
240
|
updateNeeded = true;
|
|
241
241
|
break;
|
|
242
242
|
}
|
|
243
|
+
unchecked {
|
|
244
|
+
i++;
|
|
245
|
+
}
|
|
243
246
|
}
|
|
244
247
|
|
|
245
248
|
require(updateNeeded, "no prices in the submitted batch have fresh prices, so this update will have no effect");
|
|
@@ -6,9 +6,10 @@ import "../interfaces/VBep20Interface.sol";
|
|
|
6
6
|
import "../interfaces/SIDRegistryInterface.sol";
|
|
7
7
|
import "../interfaces/FeedRegistryInterface.sol";
|
|
8
8
|
import "../interfaces/PublicResolverInterface.sol";
|
|
9
|
+
import "../interfaces/OracleInterface.sol";
|
|
9
10
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
10
11
|
|
|
11
|
-
contract BinanceOracle is AccessControlledV8 {
|
|
12
|
+
contract BinanceOracle is AccessControlledV8, OracleInterface {
|
|
12
13
|
address public sidRegistryAddress;
|
|
13
14
|
|
|
14
15
|
/// @notice vBNB address
|
|
@@ -44,7 +45,7 @@ contract BinanceOracle is AccessControlledV8 {
|
|
|
44
45
|
function setMaxStalePeriod(string memory symbol, uint256 _maxStalePeriod) external {
|
|
45
46
|
_checkAccessAllowed("setMaxStalePeriod(string,uint256)");
|
|
46
47
|
if (_maxStalePeriod == 0) revert("stale period can't be zero");
|
|
47
|
-
if (
|
|
48
|
+
if (bytes(symbol).length == 0) revert("symbol cannot be empty");
|
|
48
49
|
|
|
49
50
|
maxStalePeriod[symbol] = _maxStalePeriod;
|
|
50
51
|
emit MaxStalePeriodAdded(symbol, _maxStalePeriod);
|
|
@@ -55,43 +56,29 @@ contract BinanceOracle is AccessControlledV8 {
|
|
|
55
56
|
* @param _sidRegistryAddress Address of SID registry
|
|
56
57
|
* @param _accessControlManager Address of the access control manager contract
|
|
57
58
|
*/
|
|
58
|
-
function initialize(address _sidRegistryAddress, address _accessControlManager)
|
|
59
|
+
function initialize(address _sidRegistryAddress, address _accessControlManager) external initializer {
|
|
59
60
|
sidRegistryAddress = _sidRegistryAddress;
|
|
60
61
|
__AccessControlled_init(_accessControlManager);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
/**
|
|
64
|
-
* @notice Uses Space ID to fetch the feed registry address
|
|
65
|
-
* @return feedRegistryAddress Address of binance oracle feed registry.
|
|
66
|
-
*/
|
|
67
|
-
function getFeedRegistryAddress() public view returns (address) {
|
|
68
|
-
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
|
|
69
|
-
|
|
70
|
-
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
71
|
-
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
72
|
-
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
73
|
-
|
|
74
|
-
return publicResolver.addr(nodeHash);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
64
|
/**
|
|
78
65
|
* @notice Gets the price of a vToken from the binance oracle
|
|
79
66
|
* @param vToken Address of the vToken
|
|
80
67
|
* @return Price in USD
|
|
81
68
|
*/
|
|
82
|
-
function getUnderlyingPrice(
|
|
69
|
+
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
83
70
|
string memory symbol;
|
|
84
71
|
uint256 decimals;
|
|
85
72
|
|
|
86
73
|
// VBNB token doesn't have `underlying` method
|
|
87
|
-
if (
|
|
74
|
+
if (vToken == vBnb) {
|
|
88
75
|
symbol = "BNB";
|
|
89
76
|
decimals = 18;
|
|
90
|
-
} else if (
|
|
77
|
+
} else if (vToken == vai) {
|
|
91
78
|
symbol = "VAI";
|
|
92
79
|
decimals = 18;
|
|
93
80
|
} else {
|
|
94
|
-
IERC20Metadata underlyingToken = IERC20Metadata(vToken.underlying());
|
|
81
|
+
IERC20Metadata underlyingToken = IERC20Metadata(VBep20Interface(vToken).underlying());
|
|
95
82
|
symbol = underlyingToken.symbol();
|
|
96
83
|
decimals = underlyingToken.decimals();
|
|
97
84
|
}
|
|
@@ -106,20 +93,38 @@ contract BinanceOracle is AccessControlledV8 {
|
|
|
106
93
|
if (answer <= 0) revert("invalid binance oracle price");
|
|
107
94
|
if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
|
|
108
95
|
|
|
109
|
-
uint256 deltaTime
|
|
96
|
+
uint256 deltaTime;
|
|
97
|
+
unchecked {
|
|
98
|
+
deltaTime = block.timestamp - updatedAt;
|
|
99
|
+
}
|
|
100
|
+
|
|
110
101
|
if (deltaTime > maxStalePeriod[symbol]) revert("binance oracle price expired");
|
|
111
102
|
|
|
112
103
|
uint256 decimalDelta = feedRegistry.decimalsByName(symbol, "USD");
|
|
113
104
|
return (uint256(answer) * (10 ** (18 - decimalDelta))) * (10 ** (18 - decimals));
|
|
114
105
|
}
|
|
115
106
|
|
|
107
|
+
/**
|
|
108
|
+
* @notice Uses Space ID to fetch the feed registry address
|
|
109
|
+
* @return feedRegistryAddress Address of binance oracle feed registry.
|
|
110
|
+
*/
|
|
111
|
+
function getFeedRegistryAddress() public view returns (address) {
|
|
112
|
+
bytes32 nodeHash = 0x94fe3821e0768eb35012484db4df61890f9a6ca5bfa984ef8ff717e73139faff;
|
|
113
|
+
|
|
114
|
+
SIDRegistryInterface sidRegistry = SIDRegistryInterface(sidRegistryAddress);
|
|
115
|
+
address publicResolverAddress = sidRegistry.resolver(nodeHash);
|
|
116
|
+
PublicResolverInterface publicResolver = PublicResolverInterface(publicResolverAddress);
|
|
117
|
+
|
|
118
|
+
return publicResolver.addr(nodeHash);
|
|
119
|
+
}
|
|
120
|
+
|
|
116
121
|
/**
|
|
117
122
|
* @notice Used to compare if two strings are equal or not
|
|
118
123
|
* @param str1 The first string
|
|
119
124
|
* @param str2 The second string
|
|
120
125
|
* @return equal Returns true if both are equal or else false.
|
|
121
126
|
*/
|
|
122
|
-
function compare(string memory str1, string memory str2)
|
|
123
|
-
return keccak256(
|
|
127
|
+
function compare(string memory str1, string memory str2) private pure returns (bool) {
|
|
128
|
+
return keccak256(bytes(str1)) == keccak256(bytes(str2));
|
|
124
129
|
}
|
|
125
130
|
}
|
|
@@ -5,20 +5,20 @@ import "../interfaces/VBep20Interface.sol";
|
|
|
5
5
|
import "../interfaces/OracleInterface.sol";
|
|
6
6
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
7
7
|
|
|
8
|
-
struct ValidateConfig {
|
|
9
|
-
/// @notice asset address
|
|
10
|
-
address asset;
|
|
11
|
-
/// @notice Upper bound of deviation between reported price and anchor price,
|
|
12
|
-
/// beyond which the reported price will be invalidated
|
|
13
|
-
uint256 upperBoundRatio;
|
|
14
|
-
/// @notice Lower bound of deviation between reported price and anchor price,
|
|
15
|
-
/// below which the reported price will be invalidated
|
|
16
|
-
uint256 lowerBoundRatio;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
8
|
// BoundValidator provides some common functions and can be used
|
|
20
9
|
// to wrap up other contracts to form pivot oracles
|
|
21
10
|
contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
11
|
+
struct ValidateConfig {
|
|
12
|
+
/// @notice asset address
|
|
13
|
+
address asset;
|
|
14
|
+
/// @notice Upper bound of deviation between reported price and anchor price,
|
|
15
|
+
/// beyond which the reported price will be invalidated
|
|
16
|
+
uint256 upperBoundRatio;
|
|
17
|
+
/// @notice Lower bound of deviation between reported price and anchor price,
|
|
18
|
+
/// below which the reported price will be invalidated
|
|
19
|
+
uint256 lowerBoundRatio;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
22
|
/// @notice validation configs by asset
|
|
23
23
|
mapping(address => ValidateConfig) public validateConfigs;
|
|
24
24
|
|
|
@@ -55,13 +55,14 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
55
55
|
* @custom:error Zero length error is thrown if length of the config array is 0
|
|
56
56
|
* @custom:event Emits ValidateConfigAdded for each validation config that is successfully set
|
|
57
57
|
*/
|
|
58
|
-
function setValidateConfigs(ValidateConfig[] memory configs) external
|
|
59
|
-
_checkAccessAllowed("setValidateConfigs(ValidateConfig[])");
|
|
60
|
-
|
|
58
|
+
function setValidateConfigs(ValidateConfig[] memory configs) external {
|
|
61
59
|
uint256 length = configs.length;
|
|
62
60
|
if (length == 0) revert("invalid validate config length");
|
|
63
|
-
for (uint256 i; i < length;
|
|
61
|
+
for (uint256 i; i < length; ) {
|
|
64
62
|
setValidateConfig(configs[i]);
|
|
63
|
+
unchecked {
|
|
64
|
+
++i;
|
|
65
|
+
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -69,29 +70,10 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
69
70
|
* @notice Initializes the owner of the contract
|
|
70
71
|
* @param accessControlManager_ Address of the access control manager contract
|
|
71
72
|
*/
|
|
72
|
-
function initialize(address accessControlManager_)
|
|
73
|
+
function initialize(address accessControlManager_) external initializer {
|
|
73
74
|
__AccessControlled_init(accessControlManager_);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
/**
|
|
77
|
-
* @notice Add a single validation config
|
|
78
|
-
* @param config Validation config struct
|
|
79
|
-
* @custom:access Only Governance
|
|
80
|
-
* @custom:error Null address error is thrown if asset address is null
|
|
81
|
-
* @custom:error Range error thrown if bound ratio is not positive
|
|
82
|
-
* @custom:error Range error thrown if lower bound is greater than upper bound
|
|
83
|
-
* @custom:event Emits ValidateConfigAdded when a validation config is successfully set
|
|
84
|
-
*/
|
|
85
|
-
function setValidateConfig(ValidateConfig memory config) public virtual {
|
|
86
|
-
_checkAccessAllowed("setValidateConfig(ValidateConfig)");
|
|
87
|
-
|
|
88
|
-
if (config.asset == address(0)) revert("asset can't be zero address");
|
|
89
|
-
if (config.upperBoundRatio == 0 || config.lowerBoundRatio == 0) revert("bound must be positive");
|
|
90
|
-
if (config.upperBoundRatio <= config.lowerBoundRatio) revert("upper bound must be higher than lowner bound");
|
|
91
|
-
validateConfigs[config.asset] = config;
|
|
92
|
-
emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
77
|
/**
|
|
96
78
|
* @notice Test reported asset price against anchor price
|
|
97
79
|
* @param vToken vToken address
|
|
@@ -103,7 +85,7 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
103
85
|
address vToken,
|
|
104
86
|
uint256 reportedPrice,
|
|
105
87
|
uint256 anchorPrice
|
|
106
|
-
)
|
|
88
|
+
) external view override returns (bool) {
|
|
107
89
|
address asset = _getUnderlyingAsset(vToken);
|
|
108
90
|
|
|
109
91
|
if (validateConfigs[asset].upperBoundRatio == 0) revert("validation config not exist");
|
|
@@ -111,15 +93,35 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
111
93
|
return _isWithinAnchor(asset, reportedPrice, anchorPrice);
|
|
112
94
|
}
|
|
113
95
|
|
|
96
|
+
/**
|
|
97
|
+
* @notice Add a single validation config
|
|
98
|
+
* @param config Validation config struct
|
|
99
|
+
* @custom:access Only Governance
|
|
100
|
+
* @custom:error Null address error is thrown if asset address is null
|
|
101
|
+
* @custom:error Range error thrown if bound ratio is not positive
|
|
102
|
+
* @custom:error Range error thrown if lower bound is greater than or equal to upper bound
|
|
103
|
+
* @custom:event Emits ValidateConfigAdded when a validation config is successfully set
|
|
104
|
+
*/
|
|
105
|
+
function setValidateConfig(ValidateConfig memory config) public {
|
|
106
|
+
_checkAccessAllowed("setValidateConfig(ValidateConfig)");
|
|
107
|
+
|
|
108
|
+
if (config.asset == address(0)) revert("asset can't be zero address");
|
|
109
|
+
if (config.upperBoundRatio == 0 || config.lowerBoundRatio == 0) revert("bound must be positive");
|
|
110
|
+
if (config.upperBoundRatio <= config.lowerBoundRatio) revert("upper bound must be higher than lowner bound");
|
|
111
|
+
validateConfigs[config.asset] = config;
|
|
112
|
+
emit ValidateConfigAdded(config.asset, config.upperBoundRatio, config.lowerBoundRatio);
|
|
113
|
+
}
|
|
114
|
+
|
|
114
115
|
/**
|
|
115
116
|
* @notice Test whether the reported price is within the valid bounds
|
|
116
117
|
* @param asset Asset address
|
|
117
118
|
* @param reportedPrice The price to be tested
|
|
118
119
|
* @param anchorPrice The reported price must be within the the valid bounds of this price
|
|
119
120
|
*/
|
|
120
|
-
function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice)
|
|
121
|
+
function _isWithinAnchor(address asset, uint256 reportedPrice, uint256 anchorPrice) private view returns (bool) {
|
|
121
122
|
if (reportedPrice != 0) {
|
|
122
|
-
|
|
123
|
+
// we need to multiply anchorPrice by 1e18 to make the ratio 18 decimals
|
|
124
|
+
uint256 anchorRatio = (anchorPrice * 1e18) / reportedPrice;
|
|
123
125
|
uint256 upperBoundAnchorRatio = validateConfigs[asset].upperBoundRatio;
|
|
124
126
|
uint256 lowerBoundAnchorRatio = validateConfigs[asset].lowerBoundRatio;
|
|
125
127
|
return anchorRatio <= upperBoundAnchorRatio && anchorRatio >= lowerBoundAnchorRatio;
|
|
@@ -132,7 +134,7 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
132
134
|
* @param vToken vToken address
|
|
133
135
|
* @return asset underlying asset address
|
|
134
136
|
*/
|
|
135
|
-
function _getUnderlyingAsset(address vToken)
|
|
137
|
+
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
|
|
136
138
|
if (address(vToken) == vBnb) {
|
|
137
139
|
asset = BNB_ADDR;
|
|
138
140
|
} else if (address(vToken) == vai) {
|
|
@@ -141,9 +143,4 @@ contract BoundValidator is AccessControlledV8, BoundValidatorInterface {
|
|
|
141
143
|
asset = VBep20Interface(vToken).underlying();
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
|
-
|
|
145
|
-
// BoundValidator is to get inherited, so it's a good practice to add some storage gaps like
|
|
146
|
-
// OpenZepplin proposed in their contracts: https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
|
|
147
|
-
// solhint-disable-next-line
|
|
148
|
-
uint256[49] private __gap;
|
|
149
146
|
}
|
|
@@ -3,20 +3,21 @@ pragma solidity 0.8.13;
|
|
|
3
3
|
|
|
4
4
|
import "../interfaces/VBep20Interface.sol";
|
|
5
5
|
import "../interfaces/OracleInterface.sol";
|
|
6
|
-
import "@chainlink/contracts/src/v0.8/interfaces/
|
|
6
|
+
import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
|
|
7
7
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
8
8
|
|
|
9
|
-
struct TokenConfig {
|
|
10
|
-
/// @notice Underlying token address, which can't be a null address and can be used to check if a token is supported
|
|
11
|
-
/// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
|
|
12
|
-
address asset;
|
|
13
|
-
/// @notice Chainlink feed address
|
|
14
|
-
address feed;
|
|
15
|
-
/// @notice Price expiration period of this asset
|
|
16
|
-
uint256 maxStalePeriod;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
9
|
contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
10
|
+
struct TokenConfig {
|
|
11
|
+
/// @notice Underlying token address, which can't be a null address
|
|
12
|
+
/// @notice Used to check if a token is supported
|
|
13
|
+
/// @notice 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB for BNB
|
|
14
|
+
address asset;
|
|
15
|
+
/// @notice Chainlink feed address
|
|
16
|
+
address feed;
|
|
17
|
+
/// @notice Price expiration period of this asset
|
|
18
|
+
uint256 maxStalePeriod;
|
|
19
|
+
}
|
|
20
|
+
|
|
20
21
|
/// @notice vBNB address
|
|
21
22
|
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
22
23
|
address public immutable vBnb;
|
|
@@ -35,12 +36,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
35
36
|
mapping(address => TokenConfig) public tokenConfigs;
|
|
36
37
|
|
|
37
38
|
/// @notice Emit when a price is manually set
|
|
38
|
-
event PricePosted(
|
|
39
|
-
address indexed asset,
|
|
40
|
-
uint256 previousPriceMantissa,
|
|
41
|
-
uint256 requestedPriceMantissa,
|
|
42
|
-
uint256 newPriceMantissa
|
|
43
|
-
);
|
|
39
|
+
event PricePosted(address indexed asset, uint256 previousPriceMantissa, uint256 newPriceMantissa);
|
|
44
40
|
|
|
45
41
|
/// @notice Emit when a token config is added
|
|
46
42
|
event TokenConfigAdded(address indexed asset, address feed, uint256 maxStalePeriod);
|
|
@@ -72,11 +68,12 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
72
68
|
VBep20Interface vToken,
|
|
73
69
|
uint256 underlyingPriceMantissa
|
|
74
70
|
) external notNullAddress(address(vToken)) {
|
|
75
|
-
_checkAccessAllowed("setUnderlyingPrice(
|
|
71
|
+
_checkAccessAllowed("setUnderlyingPrice(address,uint256)");
|
|
76
72
|
|
|
77
73
|
address asset = address(vToken) == vBnb ? BNB_ADDR : address(vToken.underlying());
|
|
78
|
-
|
|
74
|
+
uint256 previousPriceMantissa = prices[asset];
|
|
79
75
|
prices[asset] = underlyingPriceMantissa;
|
|
76
|
+
emit PricePosted(asset, previousPriceMantissa, prices[asset]);
|
|
80
77
|
}
|
|
81
78
|
|
|
82
79
|
/**
|
|
@@ -89,8 +86,9 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
89
86
|
function setDirectPrice(address asset, uint256 price) external notNullAddress(asset) {
|
|
90
87
|
_checkAccessAllowed("setDirectPrice(address,uint256)");
|
|
91
88
|
|
|
89
|
+
uint256 previousPriceMantissa = prices[asset];
|
|
92
90
|
prices[asset] = price;
|
|
93
|
-
emit PricePosted(asset,
|
|
91
|
+
emit PricePosted(asset, previousPriceMantissa, price);
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
/**
|
|
@@ -100,11 +98,13 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
100
98
|
* @custom:error Zero length error thrown, if length of the array in parameter is 0
|
|
101
99
|
*/
|
|
102
100
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
|
|
103
|
-
_checkAccessAllowed("setTokenConfigs(TokenConfig[])");
|
|
104
101
|
if (tokenConfigs_.length == 0) revert("length can't be 0");
|
|
105
102
|
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
106
|
-
for (uint256 i; i < numTokenConfigs;
|
|
103
|
+
for (uint256 i; i < numTokenConfigs; ) {
|
|
107
104
|
setTokenConfig(tokenConfigs_[i]);
|
|
105
|
+
unchecked {
|
|
106
|
+
++i;
|
|
107
|
+
}
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
|
|
@@ -112,10 +112,19 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
112
112
|
* @notice Initializes the owner of the contract
|
|
113
113
|
* @param accessControlManager_ Address of the access control manager contract
|
|
114
114
|
*/
|
|
115
|
-
function initialize(address accessControlManager_)
|
|
115
|
+
function initialize(address accessControlManager_) external initializer {
|
|
116
116
|
__AccessControlled_init(accessControlManager_);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
|
|
121
|
+
* @param vToken vToken address
|
|
122
|
+
* @return price Underlying price in USD
|
|
123
|
+
*/
|
|
124
|
+
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
125
|
+
return _getUnderlyingPriceInternal(VBep20Interface(vToken));
|
|
126
|
+
}
|
|
127
|
+
|
|
119
128
|
/**
|
|
120
129
|
* @notice Add single token config. vToken & feed cannot be null addresses and maxStalePeriod must be positive
|
|
121
130
|
* @param tokenConfig Token config struct
|
|
@@ -135,15 +144,6 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
135
144
|
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.feed, tokenConfig.maxStalePeriod);
|
|
136
145
|
}
|
|
137
146
|
|
|
138
|
-
/**
|
|
139
|
-
* @notice Gets the Chainlink price for the underlying asset of a given vToken, revert when vToken is a null address
|
|
140
|
-
* @param vToken vToken address
|
|
141
|
-
* @return price Underlying price in USD
|
|
142
|
-
*/
|
|
143
|
-
function getUnderlyingPrice(address vToken) public view override returns (uint256) {
|
|
144
|
-
return _getUnderlyingPriceInternal(VBep20Interface(vToken));
|
|
145
|
-
}
|
|
146
|
-
|
|
147
147
|
/**
|
|
148
148
|
* @notice Gets the Chainlink price for the underlying asset of a given vToken
|
|
149
149
|
* or the manually set price if it's been set
|
|
@@ -152,7 +152,7 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
152
152
|
* @param vToken vToken address
|
|
153
153
|
* @return price Underlying price in USD
|
|
154
154
|
*/
|
|
155
|
-
function _getUnderlyingPriceInternal(VBep20Interface vToken)
|
|
155
|
+
function _getUnderlyingPriceInternal(VBep20Interface vToken) private view returns (uint256 price) {
|
|
156
156
|
address token;
|
|
157
157
|
uint256 decimals;
|
|
158
158
|
|
|
@@ -175,12 +175,12 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
175
175
|
price = _getChainlinkPrice(token);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
uint256 decimalDelta =
|
|
178
|
+
uint256 decimalDelta = 18 - uint256(decimals);
|
|
179
179
|
return price * (10 ** decimalDelta);
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
* @notice Get the Chainlink price for the underlying asset of a given vToken, revert if token config doesn't
|
|
183
|
+
* @notice Get the Chainlink price for the underlying asset of a given vToken, revert if token config doesn't exist
|
|
184
184
|
* @dev The precision of the price feed is used to ensure the returned price has 18 decimals of precision
|
|
185
185
|
* @param asset Underlying asset address
|
|
186
186
|
* @return price Underlying price in USD, with 18 decimals of precision
|
|
@@ -192,21 +192,25 @@ contract ChainlinkOracle is AccessControlledV8, OracleInterface {
|
|
|
192
192
|
*/
|
|
193
193
|
function _getChainlinkPrice(
|
|
194
194
|
address asset
|
|
195
|
-
)
|
|
195
|
+
) private view notNullAddress(tokenConfigs[asset].asset) returns (uint256) {
|
|
196
196
|
TokenConfig memory tokenConfig = tokenConfigs[asset];
|
|
197
|
-
|
|
197
|
+
AggregatorV3Interface feed = AggregatorV3Interface(tokenConfig.feed);
|
|
198
198
|
|
|
199
199
|
// note: maxStalePeriod cannot be 0
|
|
200
200
|
uint256 maxStalePeriod = tokenConfig.maxStalePeriod;
|
|
201
201
|
|
|
202
202
|
// Chainlink USD-denominated feeds store answers at 8 decimals, mostly
|
|
203
|
-
uint256 decimalDelta =
|
|
203
|
+
uint256 decimalDelta = 18 - feed.decimals();
|
|
204
204
|
|
|
205
205
|
(, int256 answer, , uint256 updatedAt, ) = feed.latestRoundData();
|
|
206
|
-
if (answer
|
|
206
|
+
if (answer <= 0) revert("chainlink price must be positive");
|
|
207
207
|
if (block.timestamp < updatedAt) revert("updatedAt exceeds block time");
|
|
208
208
|
|
|
209
|
-
uint256 deltaTime
|
|
209
|
+
uint256 deltaTime;
|
|
210
|
+
unchecked {
|
|
211
|
+
deltaTime = block.timestamp - updatedAt;
|
|
212
|
+
}
|
|
213
|
+
|
|
210
214
|
if (deltaTime > maxStalePeriod) revert("chainlink price expired");
|
|
211
215
|
|
|
212
216
|
return uint256(answer) * (10 ** decimalDelta);
|