@venusprotocol/oracle 1.6.9 → 1.6.11-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +11 -0
- package/README.md +117 -0
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +2 -2
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +2 -2
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +2 -2
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +2 -2
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +2 -2
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +2 -2
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +4 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +369 -0
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +4 -0
- package/artifacts/{contracts/Governance/AccessControlled.sol/AccessControlled.json → @venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json} +3 -3
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +4 -0
- package/artifacts/{contracts/Governance/IAccessControlManager.sol/IAccessControlManager.json → @venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json} +2 -2
- package/artifacts/build-info/669ba4532c64b244397816b0f72e9870.json +1 -0
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +3 -3
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +2 -2
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +1 -1
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +2 -2
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +2 -2
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +220 -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 +5 -5
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +3 -3
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +3 -16
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +3 -22
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +2 -2
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +4 -0
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +364 -0
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +2 -2
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +2 -2
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +2 -2
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +2 -2
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +2 -2
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +2 -2
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +2 -2
- package/contracts/ResilientOracle.sol +14 -14
- package/contracts/oracles/BinanceOracle.sol +43 -7
- package/contracts/oracles/BoundValidator.sol +14 -14
- package/contracts/oracles/ChainlinkOracle.sol +12 -16
- package/contracts/oracles/PythOracle.sol +12 -16
- package/contracts/oracles/TwapOracle.sol +22 -24
- package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +1 -1
- package/contracts/oracles/mocks/MockBinanceOracle.sol +1 -7
- package/contracts/oracles/mocks/MockPythOracle.sol +1 -1
- package/contracts/oracles/mocks/MockTwapOracle.sol +1 -1
- package/contracts/test/AccessControlManager.sol +6 -0
- package/deploy/1-deploy-oracles.ts +195 -0
- package/deploy/2-configure-feeds.ts +324 -0
- package/deployments/bscmainnet/.chainId +1 -0
- package/deployments/bscmainnet/BinanceOracle.json +329 -0
- package/deployments/bscmainnet/BinanceOracle_Implementation.json +259 -0
- package/deployments/bscmainnet/BinanceOracle_Proxy.json +227 -0
- package/deployments/bscmainnet/BoundValidator.json +621 -0
- package/deployments/bscmainnet/BoundValidator_Implementation.json +714 -0
- package/deployments/bscmainnet/BoundValidator_Proxy.json +251 -0
- package/deployments/bscmainnet/ChainlinkOracle.json +683 -0
- package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +826 -0
- package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +237 -0
- package/deployments/bscmainnet/DefaultProxyAdmin.json +257 -0
- package/deployments/bscmainnet/PythOracle.json +681 -0
- package/deployments/bscmainnet/PythOracle_Implementation.json +798 -0
- package/deployments/bscmainnet/PythOracle_Proxy.json +264 -0
- package/deployments/bscmainnet/ResilientOracle.json +832 -0
- package/deployments/bscmainnet/ResilientOracle_Implementation.json +1047 -0
- package/deployments/bscmainnet/ResilientOracle_Proxy.json +237 -0
- package/deployments/bscmainnet/TwapOracle.json +900 -0
- package/deployments/bscmainnet/TwapOracle_Implementation.json +1124 -0
- package/deployments/bscmainnet/TwapOracle_Proxy.json +251 -0
- package/deployments/bscmainnet/solcInputs/0e89febeebc7444140de8e67c9067d2c.json +78 -0
- package/deployments/bscmainnet/solcInputs/68ea814c0d6925581f2bda5deba8ce4a.json +60 -0
- package/deployments/{bsctestnet/solcInputs/30f2cb3e89e183b8669f05bddf9426d9.json → bscmainnet/solcInputs/8658c669dade0e9ab80874eab3bf3468.json} +6 -72
- package/deployments/bsctestnet/BinanceOracle.json +272 -30
- package/deployments/bsctestnet/BinanceOracle_Implementation.json +397 -27
- package/deployments/bsctestnet/BinanceOracle_Proxy.json +52 -28
- package/deployments/bsctestnet/BoundValidator.json +38 -38
- package/deployments/bsctestnet/BoundValidator_Implementation.json +35 -35
- package/deployments/bsctestnet/BoundValidator_Proxy.json +35 -35
- package/deployments/bsctestnet/ChainlinkOracle.json +55 -41
- package/deployments/bsctestnet/ChainlinkOracle_Implementation.json +34 -34
- package/deployments/bsctestnet/ChainlinkOracle_Proxy.json +50 -36
- package/deployments/bsctestnet/DefaultProxyAdmin.json +18 -18
- package/deployments/bsctestnet/PythOracle.json +42 -42
- package/deployments/bsctestnet/PythOracle_Implementation.json +34 -34
- package/deployments/bsctestnet/PythOracle_Proxy.json +39 -39
- package/deployments/bsctestnet/ResilientOracle.json +51 -37
- package/deployments/bsctestnet/ResilientOracle_Implementation.json +34 -34
- package/deployments/bsctestnet/ResilientOracle_Proxy.json +48 -34
- package/deployments/bsctestnet/TwapOracle.json +49 -62
- package/deployments/bsctestnet/TwapOracle_Implementation.json +47 -60
- package/deployments/bsctestnet/TwapOracle_Proxy.json +46 -46
- package/deployments/bsctestnet/solcInputs/4769dd98af512bf3b6b6504ad0c3bd74.json +78 -0
- package/deployments/bsctestnet/solcInputs/f35da22a430a956ee338e720b5898e3d.json +126 -0
- package/package.json +34 -14
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.json +0 -10
- package/artifacts/build-info/a47a69a8f108d3e7113faf89771988ff.json +0 -1
- package/artifacts/build-info/cc300b55b814df48229058e829c7c3c6.json +0 -1
- package/artifacts/build-info/de79b2637546f6f7d38c8f655549d9e2.json +0 -1
- package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
- package/artifacts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
- package/artifacts/contracts/Governance/AccessControlled.sol/AccessControlled.dbg.json +0 -4
- package/artifacts/contracts/Governance/IAccessControlManager.sol/IAccessControlManager.dbg.json +0 -4
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +0 -4
- package/artifacts/contracts/PriceOracle.sol/PriceOracle.json +0 -43
- package/contracts/Governance/AccessControlManager.sol +0 -99
- package/contracts/Governance/AccessControlled.sol +0 -75
- package/contracts/Governance/IAccessControlManager.sol +0 -22
- package/contracts/PriceOracle.sol +0 -16
- package/deploy/1-deploy-oracles.d.ts +0 -2
- package/deploy/1-deploy-oracles.d.ts.map +0 -1
- package/deploy/1-deploy-oracles.js +0 -144
- package/deploy/1-deploy-oracles.js.map +0 -1
- package/deploy/2-configure-feeds.d.ts +0 -2
- package/deploy/2-configure-feeds.d.ts.map +0 -1
- package/deploy/2-configure-feeds.js +0 -177
- package/deploy/2-configure-feeds.js.map +0 -1
- package/deployments/bsctestnet/AccessControlManager.json +0 -563
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
2
|
pragma solidity 0.8.13;
|
|
3
3
|
|
|
4
|
-
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
|
5
4
|
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
|
|
6
5
|
import "@openzeppelin/contracts/utils/math/SignedMath.sol";
|
|
7
6
|
import "../interfaces/PythInterface.sol";
|
|
8
7
|
import "../interfaces/OracleInterface.sol";
|
|
9
8
|
import "../interfaces/VBep20Interface.sol";
|
|
10
|
-
import "
|
|
9
|
+
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
11
10
|
|
|
12
11
|
struct TokenConfig {
|
|
13
12
|
bytes32 pythId;
|
|
@@ -19,9 +18,7 @@ struct TokenConfig {
|
|
|
19
18
|
* PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores the
|
|
20
19
|
* updated prices from external sources
|
|
21
20
|
*/
|
|
22
|
-
contract PythOracle is
|
|
23
|
-
using SafeMath for uint256;
|
|
24
|
-
|
|
21
|
+
contract PythOracle is AccessControlledV8, OracleInterface {
|
|
25
22
|
// To calculate 10 ** n(which is a signed type)
|
|
26
23
|
using SignedMath for int256;
|
|
27
24
|
|
|
@@ -55,7 +52,7 @@ contract PythOracle is AccessControlled, OracleInterface {
|
|
|
55
52
|
event TokenConfigAdded(address indexed vToken, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
|
|
56
53
|
|
|
57
54
|
modifier notNullAddress(address someone) {
|
|
58
|
-
|
|
55
|
+
if (someone == address(0)) revert("can't be zero address");
|
|
59
56
|
_;
|
|
60
57
|
}
|
|
61
58
|
|
|
@@ -77,7 +74,7 @@ contract PythOracle is AccessControlled, OracleInterface {
|
|
|
77
74
|
*/
|
|
78
75
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
|
|
79
76
|
_checkAccessAllowed("setTokenConfigs(TokenConfig[])");
|
|
80
|
-
|
|
77
|
+
if (tokenConfigs_.length == 0) revert("length can't be 0");
|
|
81
78
|
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
82
79
|
for (uint256 i; i < numTokenConfigs; ++i) {
|
|
83
80
|
setTokenConfig(tokenConfigs_[i]);
|
|
@@ -105,10 +102,9 @@ contract PythOracle is AccessControlled, OracleInterface {
|
|
|
105
102
|
* @param accessControlManager_ Address of the access control manager contract
|
|
106
103
|
*/
|
|
107
104
|
function initialize(address underlyingPythOracle_, address accessControlManager_) public initializer {
|
|
108
|
-
|
|
109
|
-
__AccessControlled_init_unchained(accessControlManager_);
|
|
105
|
+
__AccessControlled_init(accessControlManager_);
|
|
110
106
|
|
|
111
|
-
|
|
107
|
+
if (underlyingPythOracle_ == address(0)) revert("pyth oracle cannot be zero address");
|
|
112
108
|
underlyingPythOracle = IPyth(underlyingPythOracle_);
|
|
113
109
|
emit PythOracleSet(underlyingPythOracle_);
|
|
114
110
|
}
|
|
@@ -122,7 +118,7 @@ contract PythOracle is AccessControlled, OracleInterface {
|
|
|
122
118
|
*/
|
|
123
119
|
function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
|
|
124
120
|
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
125
|
-
|
|
121
|
+
if (tokenConfig.maxStalePeriod == 0) revert("max stale period cannot be 0");
|
|
126
122
|
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
127
123
|
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
128
124
|
}
|
|
@@ -137,7 +133,7 @@ contract PythOracle is AccessControlled, OracleInterface {
|
|
|
137
133
|
* @custom:error Range error thrown if price of Pyth oracle is not greater than zero
|
|
138
134
|
*/
|
|
139
135
|
function getUnderlyingPrice(address vToken) public view override returns (uint256) {
|
|
140
|
-
|
|
136
|
+
if (address(underlyingPythOracle) == address(0)) revert("Pyth oracle is zero address");
|
|
141
137
|
|
|
142
138
|
address asset;
|
|
143
139
|
uint256 decimals;
|
|
@@ -155,7 +151,7 @@ contract PythOracle is AccessControlled, OracleInterface {
|
|
|
155
151
|
}
|
|
156
152
|
|
|
157
153
|
TokenConfig storage tokenConfig = tokenConfigs[asset];
|
|
158
|
-
|
|
154
|
+
if (tokenConfig.asset == address(0)) revert("asset doesn't exist");
|
|
159
155
|
|
|
160
156
|
// if the price is expired after it's compared against `maxStalePeriod`, the following call will revert
|
|
161
157
|
PythStructs.Price memory priceInfo = underlyingPythOracle.getPriceNoOlderThan(
|
|
@@ -165,14 +161,14 @@ contract PythOracle is AccessControlled, OracleInterface {
|
|
|
165
161
|
|
|
166
162
|
uint256 price = int256(priceInfo.price).toUint256();
|
|
167
163
|
|
|
168
|
-
|
|
164
|
+
if (price == 0) revert("invalid pyth oracle price");
|
|
169
165
|
|
|
170
166
|
// the price returned from Pyth is price ** 10^expo, which is the real dollar price of the assets
|
|
171
167
|
// we need to multiply it by 1e18 to make the price 18 decimals
|
|
172
168
|
if (priceInfo.expo > 0) {
|
|
173
|
-
return price
|
|
169
|
+
return price * EXP_SCALE * (10 ** int256(priceInfo.expo).toUint256()) * (10 ** (18 - decimals));
|
|
174
170
|
} else {
|
|
175
|
-
return price
|
|
171
|
+
return ((price * EXP_SCALE) / (10 ** int256(-priceInfo.expo).toUint256())) * (10 ** (18 - decimals));
|
|
176
172
|
}
|
|
177
173
|
}
|
|
178
174
|
}
|
|
@@ -5,7 +5,7 @@ import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
|
|
5
5
|
import "../libraries/PancakeLibrary.sol";
|
|
6
6
|
import "../interfaces/OracleInterface.sol";
|
|
7
7
|
import "../interfaces/VBep20Interface.sol";
|
|
8
|
-
import "
|
|
8
|
+
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
9
9
|
|
|
10
10
|
struct Observation {
|
|
11
11
|
uint256 timestamp;
|
|
@@ -28,7 +28,7 @@ struct TokenConfig {
|
|
|
28
28
|
uint256 anchorPeriod;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
contract TwapOracle is
|
|
31
|
+
contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
32
32
|
using FixedPoint for *;
|
|
33
33
|
|
|
34
34
|
/// @notice WBNB address
|
|
@@ -47,8 +47,6 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
47
47
|
uint256 public constant bnbBaseUnit = 1e18;
|
|
48
48
|
uint256 public constant busdBaseUnit = 1e18;
|
|
49
49
|
|
|
50
|
-
uint256 public constant expScale = 1e18;
|
|
51
|
-
|
|
52
50
|
/// @notice Configs by token
|
|
53
51
|
mapping(address => TokenConfig) public tokenConfigs;
|
|
54
52
|
|
|
@@ -77,7 +75,7 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
77
75
|
event TokenConfigAdded(address indexed asset, address indexed pancakePool, uint256 indexed anchorPeriod);
|
|
78
76
|
|
|
79
77
|
modifier notNullAddress(address someone) {
|
|
80
|
-
|
|
78
|
+
if (someone == address(0)) revert("can't be zero address");
|
|
81
79
|
_;
|
|
82
80
|
}
|
|
83
81
|
|
|
@@ -102,9 +100,9 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
102
100
|
* @param configs Config array
|
|
103
101
|
* @custom:error Zero length error thrown, if length of the config array is 0
|
|
104
102
|
*/
|
|
105
|
-
function setTokenConfigs(TokenConfig[] memory configs) external
|
|
106
|
-
_checkAccessAllowed("
|
|
107
|
-
|
|
103
|
+
function setTokenConfigs(TokenConfig[] memory configs) external {
|
|
104
|
+
_checkAccessAllowed("setTokenConfigs(TokenConfig[])");
|
|
105
|
+
if (configs.length == 0) revert("length can't be 0");
|
|
108
106
|
uint256 numTokenConfigs = configs.length;
|
|
109
107
|
for (uint256 i; i < numTokenConfigs; ++i) {
|
|
110
108
|
setTokenConfig(configs[i]);
|
|
@@ -121,11 +119,11 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
121
119
|
function getUnderlyingPrice(address vToken) external view override returns (uint256) {
|
|
122
120
|
address asset = _getUnderlyingAsset(vToken);
|
|
123
121
|
|
|
124
|
-
|
|
122
|
+
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
125
123
|
uint256 price = prices[asset];
|
|
126
124
|
|
|
127
125
|
// if price is 0, it means the price hasn't been updated yet and it's meaningless, revert
|
|
128
|
-
|
|
126
|
+
if (price == 0) revert("TWAP price must be positive");
|
|
129
127
|
return (price * (10 ** (18 - IERC20Metadata(asset).decimals())));
|
|
130
128
|
}
|
|
131
129
|
|
|
@@ -134,8 +132,7 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
134
132
|
* @param accessControlManager_ Address of the access control manager contract
|
|
135
133
|
*/
|
|
136
134
|
function initialize(address accessControlManager_) public initializer {
|
|
137
|
-
|
|
138
|
-
__AccessControlled_init_unchained(accessControlManager_);
|
|
135
|
+
__AccessControlled_init(accessControlManager_);
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
/**
|
|
@@ -155,12 +152,10 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
155
152
|
) public notNullAddress(config.asset) notNullAddress(config.pancakePool) {
|
|
156
153
|
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
157
154
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
"base unit decimals must be same as asset decimals"
|
|
163
|
-
);
|
|
155
|
+
if (config.anchorPeriod == 0) revert("anchor period must be positive");
|
|
156
|
+
if (config.baseUnit == 0) revert("base unit must be positive");
|
|
157
|
+
if (config.baseUnit != 10 ** IERC20Metadata(config.asset).decimals())
|
|
158
|
+
revert("base unit decimals must be same as asset decimals");
|
|
164
159
|
|
|
165
160
|
uint256 cumulativePrice = currentCumulativePrice(config);
|
|
166
161
|
|
|
@@ -178,10 +173,10 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
178
173
|
function updateTwap(address vToken) public returns (uint256) {
|
|
179
174
|
address asset = _getUnderlyingAsset(vToken);
|
|
180
175
|
|
|
181
|
-
|
|
176
|
+
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
182
177
|
// Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
|
|
183
178
|
if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
|
|
184
|
-
|
|
179
|
+
if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
|
|
185
180
|
_updateTwapInternal(tokenConfigs[WBNB]);
|
|
186
181
|
}
|
|
187
182
|
return _updateTwapInternal(tokenConfigs[asset]);
|
|
@@ -214,11 +209,14 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
214
209
|
// priceAverage will always be Token/BNB or Token/BUSD *twap** price.
|
|
215
210
|
(uint256 nowCumulativePrice, uint256 oldCumulativePrice, uint256 oldTimestamp) = pokeWindowValues(config);
|
|
216
211
|
|
|
212
|
+
if (block.timestamp == oldTimestamp) return prices[config.asset];
|
|
213
|
+
|
|
217
214
|
// This should be impossible, but better safe than sorry
|
|
218
|
-
|
|
215
|
+
if (block.timestamp < oldTimestamp) revert("now must come after before");
|
|
216
|
+
|
|
219
217
|
uint256 timeElapsed = block.timestamp - oldTimestamp;
|
|
220
218
|
|
|
221
|
-
// Calculate
|
|
219
|
+
// Calculate Pancake *twap**
|
|
222
220
|
FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112(
|
|
223
221
|
uint224((nowCumulativePrice - oldCumulativePrice) / timeElapsed)
|
|
224
222
|
);
|
|
@@ -233,11 +231,11 @@ contract TwapOracle is AccessControlled, TwapInterface {
|
|
|
233
231
|
// if this token is paired with BNB, convert its price to USD
|
|
234
232
|
if (config.isBnbBased) {
|
|
235
233
|
uint256 bnbPrice = prices[WBNB];
|
|
236
|
-
|
|
234
|
+
if (bnbPrice == 0) revert("bnb price is invalid");
|
|
237
235
|
anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / bnbBaseUnit;
|
|
238
236
|
}
|
|
239
237
|
|
|
240
|
-
|
|
238
|
+
if (anchorPriceMantissa == 0) revert("twap price cannot be 0");
|
|
241
239
|
|
|
242
240
|
emit AnchorPriceUpdated(config.asset, anchorPriceMantissa, oldTimestamp, block.timestamp);
|
|
243
241
|
|
|
@@ -20,7 +20,7 @@ contract MockBinanceFeedRegistry is FeedRegistryInterface {
|
|
|
20
20
|
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)
|
|
21
21
|
{
|
|
22
22
|
quote;
|
|
23
|
-
return (0, int256(assetPrices[base]), 0,
|
|
23
|
+
return (0, int256(assetPrices[base]), 0, block.timestamp - 10, 0);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function decimalsByName(string memory base, string memory quote) external view override returns (uint8) {
|
|
@@ -3,23 +3,17 @@ pragma solidity 0.8.13;
|
|
|
3
3
|
|
|
4
4
|
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
5
5
|
import "../../interfaces/VBep20Interface.sol";
|
|
6
|
-
import "../../interfaces/FeedRegistryInterface.sol";
|
|
7
6
|
|
|
8
7
|
contract MockBinanceOracle is OwnableUpgradeable {
|
|
9
8
|
mapping(address => uint256) public assetPrices;
|
|
10
9
|
|
|
11
|
-
FeedRegistryInterface public feedRegistry;
|
|
12
|
-
|
|
13
10
|
constructor() {}
|
|
14
11
|
|
|
15
12
|
function setPrice(address asset, uint256 price) external {
|
|
16
13
|
assetPrices[asset] = price;
|
|
17
14
|
}
|
|
18
15
|
|
|
19
|
-
function initialize(
|
|
20
|
-
__Ownable_init();
|
|
21
|
-
feedRegistry = feed;
|
|
22
|
-
}
|
|
16
|
+
function initialize() public initializer {}
|
|
23
17
|
|
|
24
18
|
function getUnderlyingPrice(address vToken) public view returns (uint256) {
|
|
25
19
|
address token = VBep20Interface(vToken).underlying();
|
|
@@ -20,7 +20,7 @@ contract MockPythOracle is OwnableUpgradeable {
|
|
|
20
20
|
|
|
21
21
|
function initialize(address underlyingPythOracle_) public initializer {
|
|
22
22
|
__Ownable_init();
|
|
23
|
-
|
|
23
|
+
if (underlyingPythOracle_ == address(0)) revert("pyth oracle cannot be zero address");
|
|
24
24
|
underlyingPythOracle = IPyth(underlyingPythOracle_);
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -19,7 +19,7 @@ contract MockTwapOracle is OwnableUpgradeable {
|
|
|
19
19
|
|
|
20
20
|
function initialize(address vBNB_) public initializer {
|
|
21
21
|
__Ownable_init();
|
|
22
|
-
|
|
22
|
+
if (vBNB_ == address(0)) revert("vBNB can't be zero address");
|
|
23
23
|
vBNB = vBNB_;
|
|
24
24
|
}
|
|
25
25
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
pragma solidity 0.8.13;
|
|
3
|
+
import "@openzeppelin/contracts/access/AccessControl.sol";
|
|
4
|
+
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol";
|
|
5
|
+
|
|
6
|
+
contract AccessControlManagerScenario is AccessControlManager {}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import mainnetDeployments from "@venusprotocol/venus-protocol/networks/mainnet.json";
|
|
2
|
+
import testnetDeployments from "@venusprotocol/venus-protocol/networks/testnet.json";
|
|
3
|
+
import hre from "hardhat";
|
|
4
|
+
import { DeployFunction } from "hardhat-deploy/dist/types";
|
|
5
|
+
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
|
6
|
+
|
|
7
|
+
const ADDRESSES = {
|
|
8
|
+
bsctestnet: {
|
|
9
|
+
vBNBAddress: testnetDeployments.Contracts.vBNB,
|
|
10
|
+
WBNBAddress: "0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd",
|
|
11
|
+
VAIAddress: testnetDeployments.Contracts.VAI,
|
|
12
|
+
pythOracleAddress: "0xd7308b14BF4008e7C7196eC35610B1427C5702EA",
|
|
13
|
+
sidRegistryAddress: "0xfFB52185b56603e0fd71De9de4F6f902f05EEA23",
|
|
14
|
+
acm: "0x45f8a08F534f34A97187626E05d4b6648Eeaa9AA",
|
|
15
|
+
timelock: testnetDeployments.Contracts.Timelock,
|
|
16
|
+
},
|
|
17
|
+
bscmainnet: {
|
|
18
|
+
vBNBAddress: mainnetDeployments.Contracts.vBNB,
|
|
19
|
+
WBNBAddress: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
|
|
20
|
+
VAIAddress: mainnetDeployments.Contracts.VAI,
|
|
21
|
+
pythOracleAddress: "0x4D7E825f80bDf85e913E0DD2A2D54927e9dE1594",
|
|
22
|
+
sidRegistryAddress: "0x08CEd32a7f3eeC915Ba84415e9C07a7286977956",
|
|
23
|
+
acm: "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555",
|
|
24
|
+
timelock: mainnetDeployments.Contracts.Timelock,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const func: DeployFunction = async function ({ getNamedAccounts, deployments, network }: HardhatRuntimeEnvironment) {
|
|
29
|
+
const { deploy } = deployments;
|
|
30
|
+
const { deployer } = await getNamedAccounts();
|
|
31
|
+
|
|
32
|
+
const networkName = network.name === "bscmainnet" ? "bscmainnet" : "bsctestnet";
|
|
33
|
+
|
|
34
|
+
const { vBNBAddress } = ADDRESSES[networkName];
|
|
35
|
+
const { VAIAddress } = ADDRESSES[networkName];
|
|
36
|
+
const { WBNBAddress } = ADDRESSES[networkName];
|
|
37
|
+
|
|
38
|
+
let accessControlManager;
|
|
39
|
+
if (!network.live) {
|
|
40
|
+
await deploy("AccessControlManagerScenario", {
|
|
41
|
+
from: deployer,
|
|
42
|
+
args: [],
|
|
43
|
+
log: true,
|
|
44
|
+
autoMine: true,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
accessControlManager = await hre.ethers.getContract("AccessControlManagerScenario");
|
|
48
|
+
}
|
|
49
|
+
const accessControlManagerAddress = network.live ? ADDRESSES[networkName].acm : accessControlManager?.address;
|
|
50
|
+
const proxyOwnerAddress = network.live ? ADDRESSES[networkName].timelock : deployer;
|
|
51
|
+
|
|
52
|
+
await deploy("BoundValidator", {
|
|
53
|
+
from: deployer,
|
|
54
|
+
log: true,
|
|
55
|
+
deterministicDeployment: false,
|
|
56
|
+
args: [vBNBAddress, VAIAddress],
|
|
57
|
+
proxy: {
|
|
58
|
+
owner: proxyOwnerAddress,
|
|
59
|
+
proxyContract: "OptimizedTransparentProxy",
|
|
60
|
+
execute: {
|
|
61
|
+
methodName: "initialize",
|
|
62
|
+
args: [accessControlManagerAddress],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const boundValidator = await hre.ethers.getContract("BoundValidator");
|
|
68
|
+
|
|
69
|
+
await deploy("ResilientOracle", {
|
|
70
|
+
from: deployer,
|
|
71
|
+
log: true,
|
|
72
|
+
deterministicDeployment: false,
|
|
73
|
+
args: [vBNBAddress, VAIAddress],
|
|
74
|
+
proxy: {
|
|
75
|
+
owner: proxyOwnerAddress,
|
|
76
|
+
proxyContract: "OptimizedTransparentProxy",
|
|
77
|
+
execute: {
|
|
78
|
+
methodName: "initialize",
|
|
79
|
+
args: [boundValidator.address, accessControlManagerAddress],
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
await deploy("ChainlinkOracle", {
|
|
85
|
+
contract: network.live ? "ChainlinkOracle" : "MockChainlinkOracle",
|
|
86
|
+
from: deployer,
|
|
87
|
+
log: true,
|
|
88
|
+
deterministicDeployment: false,
|
|
89
|
+
args: network.live ? [vBNBAddress, VAIAddress] : [],
|
|
90
|
+
proxy: {
|
|
91
|
+
owner: proxyOwnerAddress,
|
|
92
|
+
proxyContract: "OptimizedTransparentProxy",
|
|
93
|
+
execute: {
|
|
94
|
+
methodName: "initialize",
|
|
95
|
+
args: network.live ? [accessControlManagerAddress] : [],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
await deploy("TwapOracle", {
|
|
101
|
+
contract: network.live ? "TwapOracle" : "MockTwapOracle",
|
|
102
|
+
from: deployer,
|
|
103
|
+
log: true,
|
|
104
|
+
deterministicDeployment: false,
|
|
105
|
+
args: network.live ? [vBNBAddress, WBNBAddress, VAIAddress] : [],
|
|
106
|
+
proxy: {
|
|
107
|
+
owner: proxyOwnerAddress,
|
|
108
|
+
proxyContract: "OptimizedTransparentProxy",
|
|
109
|
+
execute: {
|
|
110
|
+
methodName: "initialize",
|
|
111
|
+
args: network.live ? [accessControlManagerAddress] : [vBNBAddress],
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const { pythOracleAddress } = ADDRESSES[networkName];
|
|
117
|
+
|
|
118
|
+
await deploy("PythOracle", {
|
|
119
|
+
contract: network.live ? "PythOracle" : "MockPythOracle",
|
|
120
|
+
from: deployer,
|
|
121
|
+
log: true,
|
|
122
|
+
deterministicDeployment: false,
|
|
123
|
+
args: network.live ? [vBNBAddress, VAIAddress] : [],
|
|
124
|
+
proxy: {
|
|
125
|
+
owner: proxyOwnerAddress,
|
|
126
|
+
proxyContract: "OptimizedTransparentProxy",
|
|
127
|
+
execute: {
|
|
128
|
+
methodName: "initialize",
|
|
129
|
+
args: network.live ? [pythOracleAddress, accessControlManagerAddress] : [pythOracleAddress],
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const { sidRegistryAddress } = ADDRESSES[networkName];
|
|
135
|
+
|
|
136
|
+
await deploy("BinanceOracle", {
|
|
137
|
+
contract: network.live ? "BinanceOracle" : "MockBinanceOracle",
|
|
138
|
+
from: deployer,
|
|
139
|
+
log: true,
|
|
140
|
+
deterministicDeployment: false,
|
|
141
|
+
args: network.live ? [vBNBAddress, VAIAddress] : [],
|
|
142
|
+
proxy: {
|
|
143
|
+
owner: proxyOwnerAddress,
|
|
144
|
+
proxyContract: "OptimizedTransparentProxy",
|
|
145
|
+
execute: {
|
|
146
|
+
methodName: "initialize",
|
|
147
|
+
args: network.live ? [sidRegistryAddress, accessControlManagerAddress] : [],
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const resilientOracle = await hre.ethers.getContract("ResilientOracle");
|
|
153
|
+
const pythOracle = await hre.ethers.getContract("PythOracle");
|
|
154
|
+
const chainlinkOracle = await hre.ethers.getContract("ChainlinkOracle");
|
|
155
|
+
const binanceOracle = await hre.ethers.getContract("BinanceOracle");
|
|
156
|
+
const twapOracle = await hre.ethers.getContract("TwapOracle");
|
|
157
|
+
|
|
158
|
+
await accessControlManager?.giveCallPermission(chainlinkOracle.address, "setTokenConfig(TokenConfig)", deployer);
|
|
159
|
+
await accessControlManager?.giveCallPermission(pythOracle.address, "setTokenConfig(TokenConfig)", deployer);
|
|
160
|
+
await accessControlManager?.giveCallPermission(resilientOracle.address, "setTokenConfig(TokenConfig)", deployer);
|
|
161
|
+
|
|
162
|
+
const resilientOracleOwner = await resilientOracle.owner();
|
|
163
|
+
const pythOracleOwner = await pythOracle.owner();
|
|
164
|
+
const binanceOracleOwner = await binanceOracle.owner();
|
|
165
|
+
const chainlinkOracleOwner = await chainlinkOracle.owner();
|
|
166
|
+
const twapOracleOwner = await twapOracle.owner();
|
|
167
|
+
const boundValidatorOwner = await boundValidator.owner();
|
|
168
|
+
|
|
169
|
+
if (resilientOracleOwner === deployer) {
|
|
170
|
+
await resilientOracle.transferOwnership(ADDRESSES[networkName].timelock);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (pythOracleOwner === deployer) {
|
|
174
|
+
await pythOracle.transferOwnership(ADDRESSES[networkName].timelock);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (binanceOracleOwner === deployer) {
|
|
178
|
+
await binanceOracle.transferOwnership(ADDRESSES[networkName].timelock);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (chainlinkOracleOwner === deployer) {
|
|
182
|
+
await chainlinkOracle.transferOwnership(ADDRESSES[networkName].timelock);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (twapOracleOwner === deployer) {
|
|
186
|
+
await twapOracle.transferOwnership(ADDRESSES[networkName].timelock);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (boundValidatorOwner === deployer) {
|
|
190
|
+
await boundValidator.transferOwnership(ADDRESSES[networkName].timelock);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export default func;
|
|
195
|
+
export const tags = ["deploy"];
|