@venusprotocol/oracle 1.6.11-dev.8 → 1.6.11
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/README.md +33 -10
- package/contracts/ResilientOracle.sol +60 -18
- package/contracts/oracles/BinanceOracle.sol +22 -17
- package/contracts/oracles/BoundValidator.sol +43 -38
- package/contracts/oracles/ChainlinkOracle.sol +35 -34
- package/contracts/oracles/PythOracle.sol +30 -27
- package/contracts/oracles/TwapOracle.sol +61 -56
- package/deployments/bscmainnet/BinanceOracle.json +45 -45
- package/deployments/bscmainnet/BinanceOracle_Implementation.json +34 -34
- package/deployments/bscmainnet/BinanceOracle_Proxy.json +43 -43
- package/deployments/bscmainnet/BoundValidator.json +46 -46
- package/deployments/bscmainnet/BoundValidator_Implementation.json +44 -52
- package/deployments/bscmainnet/BoundValidator_Proxy.json +43 -43
- package/deployments/bscmainnet/ChainlinkOracle.json +46 -52
- package/deployments/bscmainnet/ChainlinkOracle_Implementation.json +45 -51
- package/deployments/bscmainnet/ChainlinkOracle_Proxy.json +43 -43
- package/deployments/bscmainnet/DefaultProxyAdmin.json +15 -15
- package/deployments/bscmainnet/PythOracle.json +61 -54
- package/deployments/bscmainnet/PythOracle_Implementation.json +54 -48
- package/deployments/bscmainnet/PythOracle_Proxy.json +52 -51
- package/deployments/bscmainnet/ResilientOracle.json +47 -52
- package/deployments/bscmainnet/ResilientOracle_Implementation.json +62 -65
- package/deployments/bscmainnet/ResilientOracle_Proxy.json +45 -45
- package/deployments/bscmainnet/TwapOracle.json +67 -67
- package/deployments/bscmainnet/TwapOracle_Implementation.json +83 -83
- package/deployments/bscmainnet/TwapOracle_Proxy.json +44 -44
- package/deployments/bscmainnet/solcInputs/{3c9df0f4b407c3d8079629dd6ddb913e.json → aae9f1601b873a5a4704ede73ede10cb.json} +9 -54
- 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.js +2 -2
- package/dist/deploy/1-deploy-oracles.js.map +1 -1
- package/package.json +1 -1
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorInterface.sol/AggregatorInterface.json +0 -138
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.json +0 -249
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.dbg.json +0 -4
- package/artifacts/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol/AggregatorV3Interface.json +0 -122
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/access/AccessControl.sol/AccessControl.json +0 -215
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/access/IAccessControl.sol/IAccessControl.json +0 -183
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +0 -297
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.json +0 -194
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.json +0 -233
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/Strings.sol/Strings.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/introspection/ERC165.sol/ERC165.json +0 -30
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/introspection/IERC165.sol/IERC165.json +0 -30
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/Math.sol/Math.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +0 -10
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +0 -10
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol/Ownable2StepUpgradeable.json +0 -115
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.json +0 -76
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.json +0 -24
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.json +0 -63
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +0 -10
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +0 -4
- package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.json +0 -24
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.dbg.json +0 -4
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlManager.sol/AccessControlManager.json +0 -369
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.dbg.json +0 -4
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol/AccessControlledV8.json +0 -181
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.dbg.json +0 -4
- package/artifacts/@venusprotocol/governance-contracts/contracts/Governance/IAccessControlManagerV8.sol/IAccessControlManagerV8.json +0 -282
- package/artifacts/build-info/0fa2b75b56480052b72f8190a534e534.json +0 -1
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +0 -4
- package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +0 -617
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.json +0 -79
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.json +0 -40
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.json +0 -30
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.json +0 -43
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.json +0 -49
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PublicResolverInterface.sol/PublicResolverInterface.json +0 -30
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/AbstractPyth.json +0 -545
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.json +0 -446
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +0 -4
- package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +0 -10
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/SIDRegistryInterface.sol/SIDRegistryInterface.json +0 -30
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +0 -4
- package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.json +0 -246
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +0 -10
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.json +0 -60
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +0 -4
- package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +0 -10
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +0 -342
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +0 -4
- package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +0 -392
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +0 -468
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +0 -439
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +0 -663
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +0 -116
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +0 -144
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +0 -144
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +0 -163
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +0 -4
- package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +0 -163
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.dbg.json +0 -4
- package/artifacts/contracts/test/AccessControlManager.sol/AccessControlManagerScenario.json +0 -364
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +0 -4
- package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +0 -328
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +0 -4
- package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +0 -684
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +0 -4
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +0 -95
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +0 -4
- package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +0 -72
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +0 -4
- package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +0 -306
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +0 -10
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +0 -158
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +0 -4
- package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +0 -10
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +0 -4
- package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +0 -346
|
@@ -8,15 +8,11 @@ import "../interfaces/OracleInterface.sol";
|
|
|
8
8
|
import "../interfaces/VBep20Interface.sol";
|
|
9
9
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
10
10
|
|
|
11
|
-
struct TokenConfig {
|
|
12
|
-
bytes32 pythId;
|
|
13
|
-
address asset;
|
|
14
|
-
uint64 maxStalePeriod;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
11
|
/**
|
|
18
|
-
* PythOracle
|
|
19
|
-
*
|
|
12
|
+
* @title PythOracle
|
|
13
|
+
* @author Venus
|
|
14
|
+
* @notice PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores
|
|
15
|
+
* the updated prices from external sources
|
|
20
16
|
*/
|
|
21
17
|
contract PythOracle is AccessControlledV8, OracleInterface {
|
|
22
18
|
// To calculate 10 ** n(which is a signed type)
|
|
@@ -25,6 +21,12 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
25
21
|
// To cast int64/int8 types from Pyth to unsigned types
|
|
26
22
|
using SafeCast for int256;
|
|
27
23
|
|
|
24
|
+
struct TokenConfig {
|
|
25
|
+
bytes32 pythId;
|
|
26
|
+
address asset;
|
|
27
|
+
uint64 maxStalePeriod;
|
|
28
|
+
}
|
|
29
|
+
|
|
28
30
|
/// @notice Exponent scale (decimal precision) of prices
|
|
29
31
|
uint256 public constant EXP_SCALE = 1e18;
|
|
30
32
|
|
|
@@ -46,7 +48,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
46
48
|
mapping(address => TokenConfig) public tokenConfigs;
|
|
47
49
|
|
|
48
50
|
/// @notice Emit when setting a new pyth oracle address
|
|
49
|
-
event PythOracleSet(address indexed newPythOracle);
|
|
51
|
+
event PythOracleSet(address indexed oldPythOracle, address indexed newPythOracle);
|
|
50
52
|
|
|
51
53
|
/// @notice Emit when a token config is added
|
|
52
54
|
event TokenConfigAdded(address indexed vToken, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
|
|
@@ -94,8 +96,9 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
94
96
|
IPyth underlyingPythOracle_
|
|
95
97
|
) external notNullAddress(address(underlyingPythOracle_)) {
|
|
96
98
|
_checkAccessAllowed("setUnderlyingPythOracle(address)");
|
|
99
|
+
IPyth oldUnderlyingPythOracle = underlyingPythOracle;
|
|
97
100
|
underlyingPythOracle = underlyingPythOracle_;
|
|
98
|
-
emit PythOracleSet(address(underlyingPythOracle_));
|
|
101
|
+
emit PythOracleSet(address(oldUnderlyingPythOracle), address(underlyingPythOracle_));
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
/**
|
|
@@ -106,25 +109,11 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
106
109
|
function initialize(
|
|
107
110
|
address underlyingPythOracle_,
|
|
108
111
|
address accessControlManager_
|
|
109
|
-
)
|
|
112
|
+
) external initializer notNullAddress(underlyingPythOracle_) {
|
|
110
113
|
__AccessControlled_init(accessControlManager_);
|
|
111
114
|
|
|
112
115
|
underlyingPythOracle = IPyth(underlyingPythOracle_);
|
|
113
|
-
emit PythOracleSet(underlyingPythOracle_);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `vToken` can be a null address
|
|
118
|
-
* @param tokenConfig Token config struct
|
|
119
|
-
* @custom:access Only Governance
|
|
120
|
-
* @custom:error Range error is thrown if max stale period is zero
|
|
121
|
-
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
122
|
-
*/
|
|
123
|
-
function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
|
|
124
|
-
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
125
|
-
if (tokenConfig.maxStalePeriod == 0) revert("max stale period cannot be 0");
|
|
126
|
-
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
127
|
-
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
116
|
+
emit PythOracleSet(address(0), underlyingPythOracle_);
|
|
128
117
|
}
|
|
129
118
|
|
|
130
119
|
/**
|
|
@@ -138,7 +127,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
138
127
|
*/
|
|
139
128
|
function getUnderlyingPrice(
|
|
140
129
|
address vToken
|
|
141
|
-
)
|
|
130
|
+
) external view override notNullAddress(address(underlyingPythOracle)) returns (uint256) {
|
|
142
131
|
address asset;
|
|
143
132
|
uint256 decimals;
|
|
144
133
|
|
|
@@ -175,4 +164,18 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
175
164
|
return ((price * EXP_SCALE) / (10 ** int256(-priceInfo.expo).toUint256())) * (10 ** (18 - decimals));
|
|
176
165
|
}
|
|
177
166
|
}
|
|
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
|
+
}
|
|
178
181
|
}
|
|
@@ -7,30 +7,35 @@ import "../interfaces/OracleInterface.sol";
|
|
|
7
7
|
import "../interfaces/VBep20Interface.sol";
|
|
8
8
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
struct TokenConfig {
|
|
16
|
-
/// @notice Asset address, which can't be zero address and can be used for existance check
|
|
17
|
-
address asset;
|
|
18
|
-
/// @notice Decimals of underlying asset
|
|
19
|
-
uint256 baseUnit;
|
|
20
|
-
/// @notice The address of Pancake pair
|
|
21
|
-
address pancakePool;
|
|
22
|
-
/// @notice Whether the token is paired with WBNB
|
|
23
|
-
bool isBnbBased;
|
|
24
|
-
/// @notice A flag identifies whether the Pancake pair is reversed
|
|
25
|
-
/// e.g. XVS-WBNB is not reversed, while WBNB-XVS is.
|
|
26
|
-
bool isReversedPool;
|
|
27
|
-
/// @notice The minimum window in seconds required between TWAP updates
|
|
28
|
-
uint256 anchorPeriod;
|
|
29
|
-
}
|
|
30
|
-
|
|
10
|
+
/**
|
|
11
|
+
* @title TwapOracle
|
|
12
|
+
* @author Venus
|
|
13
|
+
* @notice This oracle fetches price of assets from PancakeSwap.
|
|
14
|
+
*/
|
|
31
15
|
contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
32
16
|
using FixedPoint for *;
|
|
33
17
|
|
|
18
|
+
struct Observation {
|
|
19
|
+
uint256 timestamp;
|
|
20
|
+
uint256 acc;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
struct TokenConfig {
|
|
24
|
+
/// @notice Asset address, which can't be zero address and can be used for existance check
|
|
25
|
+
address asset;
|
|
26
|
+
/// @notice Decimals of underlying asset represented as 1e{decimals}
|
|
27
|
+
uint256 baseUnit;
|
|
28
|
+
/// @notice The address of Pancake pair
|
|
29
|
+
address pancakePool;
|
|
30
|
+
/// @notice Whether the token is paired with WBNB
|
|
31
|
+
bool isBnbBased;
|
|
32
|
+
/// @notice A flag identifies whether the Pancake pair is reversed
|
|
33
|
+
/// e.g. XVS-WBNB is reversed, while WBNB-XVS is not.
|
|
34
|
+
bool isReversedPool;
|
|
35
|
+
/// @notice The minimum window in seconds required between TWAP updates
|
|
36
|
+
uint256 anchorPeriod;
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
/// @notice WBNB address
|
|
35
40
|
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
36
41
|
address public immutable WBNB;
|
|
@@ -44,8 +49,8 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
44
49
|
address public immutable vai;
|
|
45
50
|
|
|
46
51
|
/// @notice the base unit of WBNB and BUSD, which are the paired tokens for all assets
|
|
47
|
-
uint256 public constant
|
|
48
|
-
uint256 public constant
|
|
52
|
+
uint256 public constant BNB_BASE_UNIT = 1e18;
|
|
53
|
+
uint256 public constant BUSD_BASE_UNIT = 1e18;
|
|
49
54
|
|
|
50
55
|
/// @notice Configs by token
|
|
51
56
|
mapping(address => TokenConfig) public tokenConfigs;
|
|
@@ -111,6 +116,31 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
111
116
|
}
|
|
112
117
|
}
|
|
113
118
|
|
|
119
|
+
/**
|
|
120
|
+
* @notice Initializes the owner of the contract
|
|
121
|
+
* @param accessControlManager_ Address of the access control manager contract
|
|
122
|
+
*/
|
|
123
|
+
function initialize(address accessControlManager_) external initializer {
|
|
124
|
+
__AccessControlled_init(accessControlManager_);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
129
|
+
* @return anchorPrice anchor price of the underlying asset of the vToken
|
|
130
|
+
* @custom:error Missing error is thrown if token config does not exist
|
|
131
|
+
*/
|
|
132
|
+
function updateTwap(address vToken) external returns (uint256) {
|
|
133
|
+
address asset = _getUnderlyingAsset(vToken);
|
|
134
|
+
|
|
135
|
+
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
136
|
+
// Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
|
|
137
|
+
if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
|
|
138
|
+
if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
|
|
139
|
+
_updateTwapInternal(tokenConfigs[WBNB]);
|
|
140
|
+
}
|
|
141
|
+
return _updateTwapInternal(tokenConfigs[asset]);
|
|
142
|
+
}
|
|
143
|
+
|
|
114
144
|
/**
|
|
115
145
|
* @notice Get the underlying TWAP price for the given vToken
|
|
116
146
|
* @param vToken vToken address
|
|
@@ -129,14 +159,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
129
159
|
return (price * (10 ** (18 - IERC20Metadata(asset).decimals())));
|
|
130
160
|
}
|
|
131
161
|
|
|
132
|
-
/**
|
|
133
|
-
* @notice Initializes the owner of the contract
|
|
134
|
-
* @param accessControlManager_ Address of the access control manager contract
|
|
135
|
-
*/
|
|
136
|
-
function initialize(address accessControlManager_) public initializer {
|
|
137
|
-
__AccessControlled_init(accessControlManager_);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
162
|
/**
|
|
141
163
|
* @notice Adds a single token config
|
|
142
164
|
* @param config token config struct
|
|
@@ -166,23 +188,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
166
188
|
emit TokenConfigAdded(config.asset, config.pancakePool, config.anchorPeriod);
|
|
167
189
|
}
|
|
168
190
|
|
|
169
|
-
/**
|
|
170
|
-
* @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
171
|
-
* @return anchorPrice anchor price of the underlying asset of the vToken
|
|
172
|
-
* @custom:error Missing error is thrown if token config does not exist
|
|
173
|
-
*/
|
|
174
|
-
function updateTwap(address vToken) public returns (uint256) {
|
|
175
|
-
address asset = _getUnderlyingAsset(vToken);
|
|
176
|
-
|
|
177
|
-
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
178
|
-
// Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
|
|
179
|
-
if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
|
|
180
|
-
if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
|
|
181
|
-
_updateTwapInternal(tokenConfigs[WBNB]);
|
|
182
|
-
}
|
|
183
|
-
return _updateTwapInternal(tokenConfigs[asset]);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
191
|
/**
|
|
187
192
|
* @notice Fetches the current token/WBNB and token/BUSD price accumulator from PancakeSwap.
|
|
188
193
|
* @return cumulative price of target token regardless of pair order
|
|
@@ -205,7 +210,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
205
210
|
* @custom:event Emits AnchorPriceUpdated event on successful update of observation with assset address,
|
|
206
211
|
* AnchorPrice, old observation timestamp and current timestamp
|
|
207
212
|
*/
|
|
208
|
-
function _updateTwapInternal(TokenConfig memory config)
|
|
213
|
+
function _updateTwapInternal(TokenConfig memory config) private returns (uint256) {
|
|
209
214
|
// pokeWindowValues already handled reversed pool cases,
|
|
210
215
|
// priceAverage will always be Token/BNB or Token/BUSD *twap** price.
|
|
211
216
|
(uint256 nowCumulativePrice, uint256 oldCumulativePrice, uint256 oldTimestamp) = pokeWindowValues(config);
|
|
@@ -228,15 +233,15 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
228
233
|
uint256 priceAverageMantissa = priceAverage.decode112with18();
|
|
229
234
|
|
|
230
235
|
// To cancel the decimals in cumulative price, we need to mulitply the average price with
|
|
231
|
-
// tokenBaseUnit / (
|
|
232
|
-
uint256 pairedTokenBaseUnit = config.isBnbBased ?
|
|
236
|
+
// tokenBaseUnit / (BNB_BASE_UNIT or BUSD_BASE_UNIT, which is 1e18)
|
|
237
|
+
uint256 pairedTokenBaseUnit = config.isBnbBased ? BNB_BASE_UNIT : BUSD_BASE_UNIT;
|
|
233
238
|
uint256 anchorPriceMantissa = (priceAverageMantissa * config.baseUnit) / pairedTokenBaseUnit;
|
|
234
239
|
|
|
235
240
|
// if this token is paired with BNB, convert its price to USD
|
|
236
241
|
if (config.isBnbBased) {
|
|
237
242
|
uint256 bnbPrice = prices[WBNB];
|
|
238
243
|
if (bnbPrice == 0) revert("bnb price is invalid");
|
|
239
|
-
anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) /
|
|
244
|
+
anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / BNB_BASE_UNIT;
|
|
240
245
|
}
|
|
241
246
|
|
|
242
247
|
if (anchorPriceMantissa == 0) revert("twap price cannot be 0");
|
|
@@ -260,7 +265,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
260
265
|
*/
|
|
261
266
|
function pokeWindowValues(
|
|
262
267
|
TokenConfig memory config
|
|
263
|
-
)
|
|
268
|
+
) private returns (uint256, uint256 startCumulativePrice, uint256 startCumulativeTimestamp) {
|
|
264
269
|
uint256 cumulativePrice = currentCumulativePrice(config);
|
|
265
270
|
uint256 currentTimestamp = block.timestamp;
|
|
266
271
|
uint256 windowStartTimestamp = currentTimestamp - config.anchorPeriod;
|
|
@@ -301,10 +306,10 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
301
306
|
* @param vToken vToken address
|
|
302
307
|
* @return asset underlying asset address
|
|
303
308
|
*/
|
|
304
|
-
function _getUnderlyingAsset(address vToken)
|
|
305
|
-
if (
|
|
309
|
+
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
|
|
310
|
+
if (vToken == vBnb) {
|
|
306
311
|
asset = WBNB;
|
|
307
|
-
} else if (
|
|
312
|
+
} else if (vToken == vai) {
|
|
308
313
|
asset = vai;
|
|
309
314
|
} else {
|
|
310
315
|
asset = VBep20Interface(vToken).underlying();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"address": "
|
|
2
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
3
3
|
"abi": [
|
|
4
4
|
{
|
|
5
5
|
"anonymous": false,
|
|
@@ -257,7 +257,7 @@
|
|
|
257
257
|
{
|
|
258
258
|
"inputs": [
|
|
259
259
|
{
|
|
260
|
-
"internalType": "
|
|
260
|
+
"internalType": "address",
|
|
261
261
|
"name": "vToken",
|
|
262
262
|
"type": "address"
|
|
263
263
|
}
|
|
@@ -448,83 +448,83 @@
|
|
|
448
448
|
"type": "constructor"
|
|
449
449
|
}
|
|
450
450
|
],
|
|
451
|
-
"transactionHash": "
|
|
451
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
452
452
|
"receipt": {
|
|
453
453
|
"to": null,
|
|
454
454
|
"from": "0xa05f990d647287e4E84715b813BC000aEA970467",
|
|
455
|
-
"contractAddress": "
|
|
456
|
-
"transactionIndex":
|
|
455
|
+
"contractAddress": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
456
|
+
"transactionIndex": 109,
|
|
457
457
|
"gasUsed": "718007",
|
|
458
|
-
"logsBloom": "
|
|
459
|
-
"blockHash": "
|
|
460
|
-
"transactionHash": "
|
|
458
|
+
"logsBloom": "0x00000000000000000000000000100000400000000000020000800000000000000000000000000000000000000200000000000000000000000000000000008000000000000000000000008000000002000001000000000100000000000000000000000000020000000000000000000800000000800000002000000000000000400000000000000000000000000000000000000000000080000000000000800000000000000000000000000000000400000000000000808000000000000000000000000020000000000000000000040000000000000402000000000000000020000000000000000000000000000000000000000800400000000000000000000000",
|
|
459
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b",
|
|
460
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
461
461
|
"logs": [
|
|
462
462
|
{
|
|
463
|
-
"transactionIndex":
|
|
464
|
-
"blockNumber":
|
|
465
|
-
"transactionHash": "
|
|
466
|
-
"address": "
|
|
463
|
+
"transactionIndex": 109,
|
|
464
|
+
"blockNumber": 28525842,
|
|
465
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
466
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
467
467
|
"topics": [
|
|
468
468
|
"0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b",
|
|
469
|
-
"
|
|
469
|
+
"0x00000000000000000000000073760d55bf10cf9d265a126d349bdd5f64326c0e"
|
|
470
470
|
],
|
|
471
471
|
"data": "0x",
|
|
472
|
-
"logIndex":
|
|
473
|
-
"blockHash": "
|
|
472
|
+
"logIndex": 279,
|
|
473
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
474
474
|
},
|
|
475
475
|
{
|
|
476
|
-
"transactionIndex":
|
|
477
|
-
"blockNumber":
|
|
478
|
-
"transactionHash": "
|
|
479
|
-
"address": "
|
|
476
|
+
"transactionIndex": 109,
|
|
477
|
+
"blockNumber": 28525842,
|
|
478
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
479
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
480
480
|
"topics": [
|
|
481
481
|
"0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0",
|
|
482
482
|
"0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
483
483
|
"0x000000000000000000000000a05f990d647287e4e84715b813bc000aea970467"
|
|
484
484
|
],
|
|
485
485
|
"data": "0x",
|
|
486
|
-
"logIndex":
|
|
487
|
-
"blockHash": "
|
|
486
|
+
"logIndex": 280,
|
|
487
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
488
488
|
},
|
|
489
489
|
{
|
|
490
|
-
"transactionIndex":
|
|
491
|
-
"blockNumber":
|
|
492
|
-
"transactionHash": "
|
|
493
|
-
"address": "
|
|
490
|
+
"transactionIndex": 109,
|
|
491
|
+
"blockNumber": 28525842,
|
|
492
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
493
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
494
494
|
"topics": ["0x66fd58e82f7b31a2a5c30e0888f3093efe4e111b00cd2b0c31fe014601293aa0"],
|
|
495
495
|
"data": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000004788629abc6cfca10f9f969efdeaa1cf70c23555",
|
|
496
|
-
"logIndex":
|
|
497
|
-
"blockHash": "
|
|
496
|
+
"logIndex": 281,
|
|
497
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
498
498
|
},
|
|
499
499
|
{
|
|
500
|
-
"transactionIndex":
|
|
501
|
-
"blockNumber":
|
|
502
|
-
"transactionHash": "
|
|
503
|
-
"address": "
|
|
500
|
+
"transactionIndex": 109,
|
|
501
|
+
"blockNumber": 28525842,
|
|
502
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
503
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
504
504
|
"topics": ["0x7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498"],
|
|
505
505
|
"data": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
506
|
-
"logIndex":
|
|
507
|
-
"blockHash": "
|
|
506
|
+
"logIndex": 282,
|
|
507
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
508
508
|
},
|
|
509
509
|
{
|
|
510
|
-
"transactionIndex":
|
|
511
|
-
"blockNumber":
|
|
512
|
-
"transactionHash": "
|
|
513
|
-
"address": "
|
|
510
|
+
"transactionIndex": 109,
|
|
511
|
+
"blockNumber": 28525842,
|
|
512
|
+
"transactionHash": "0x03a4a8fcacc4f419b580d655095d686ecfc42541abe064985b93a24f5e5bdfda",
|
|
513
|
+
"address": "0x594810b741d136f1960141C0d8Fb4a91bE78A820",
|
|
514
514
|
"topics": ["0x7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f"],
|
|
515
|
-
"data": "
|
|
516
|
-
"logIndex":
|
|
517
|
-
"blockHash": "
|
|
515
|
+
"data": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000001bb765b741a5f3c2a338369dab539385534e3343",
|
|
516
|
+
"logIndex": 283,
|
|
517
|
+
"blockHash": "0x6d780878d8d16cfa0b602110bae91b8285809d2123b42279b02cdfddfa63196b"
|
|
518
518
|
}
|
|
519
519
|
],
|
|
520
|
-
"blockNumber":
|
|
521
|
-
"cumulativeGasUsed": "
|
|
520
|
+
"blockNumber": 28525842,
|
|
521
|
+
"cumulativeGasUsed": "11886540",
|
|
522
522
|
"status": 1,
|
|
523
523
|
"byzantium": true
|
|
524
524
|
},
|
|
525
525
|
"args": [
|
|
526
|
-
"
|
|
527
|
-
"
|
|
526
|
+
"0x73760D55bF10cf9D265A126D349bdd5f64326c0e",
|
|
527
|
+
"0x1BB765b741A5f3C2A338369DAb539385534E3343",
|
|
528
528
|
"0x485cc95500000000000000000000000008ced32a7f3eec915ba84415e9c07a72869779560000000000000000000000004788629abc6cfca10f9f969efdeaa1cf70c23555"
|
|
529
529
|
],
|
|
530
530
|
"numDeployments": 1,
|
|
@@ -536,7 +536,7 @@
|
|
|
536
536
|
"methodName": "initialize",
|
|
537
537
|
"args": ["0x08CEd32a7f3eeC915Ba84415e9C07a7286977956", "0x4788629ABc6cFCA10F9f969efdEAa1cF70c23555"]
|
|
538
538
|
},
|
|
539
|
-
"implementation": "
|
|
539
|
+
"implementation": "0x73760D55bF10cf9D265A126D349bdd5f64326c0e",
|
|
540
540
|
"devdoc": {
|
|
541
541
|
"details": "This contract implements a proxy that is upgradeable by an admin. To avoid https://medium.com/nomic-labs-blog/malicious-backdoors-in-ethereum-proxies-62629adf3357[proxy selector clashing], which can potentially be used in an attack, this contract uses the https://blog.openzeppelin.com/the-transparent-proxy-pattern/[transparent proxy pattern]. This pattern implies two things that go hand in hand: 1. If any account other than the admin calls the proxy, the call will be forwarded to the implementation, even if that call matches one of the admin functions exposed by the proxy itself. 2. If the admin calls the proxy, it can access the admin functions, but its calls will never be forwarded to the implementation. If the admin tries to call a function on the implementation it will fail with an error that says \"admin cannot fallback to proxy target\". These properties mean that the admin account can only be used for admin actions like upgrading the proxy or changing the admin, so it's best if it's a dedicated account that is not used for anything else. This will avoid headaches due to sudden errors when trying to call a function from the proxy implementation. Our recommendation is for the dedicated account to be an instance of the {ProxyAdmin} contract. If set up this way, you should think of the `ProxyAdmin` instance as the real administrative interface of your proxy.",
|
|
542
542
|
"kind": "dev",
|