@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
|
@@ -8,12 +8,6 @@ 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
12
|
* PythOracle contract reads prices from actual Pyth oracle contract which accepts, verifies and stores the
|
|
19
13
|
* updated prices from external sources
|
|
@@ -25,6 +19,12 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
25
19
|
// To cast int64/int8 types from Pyth to unsigned types
|
|
26
20
|
using SafeCast for int256;
|
|
27
21
|
|
|
22
|
+
struct TokenConfig {
|
|
23
|
+
bytes32 pythId;
|
|
24
|
+
address asset;
|
|
25
|
+
uint64 maxStalePeriod;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
28
|
/// @notice Exponent scale (decimal precision) of prices
|
|
29
29
|
uint256 public constant EXP_SCALE = 1e18;
|
|
30
30
|
|
|
@@ -46,7 +46,7 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
46
46
|
mapping(address => TokenConfig) public tokenConfigs;
|
|
47
47
|
|
|
48
48
|
/// @notice Emit when setting a new pyth oracle address
|
|
49
|
-
event PythOracleSet(address indexed newPythOracle);
|
|
49
|
+
event PythOracleSet(address indexed oldPythOracle, address indexed newPythOracle);
|
|
50
50
|
|
|
51
51
|
/// @notice Emit when a token config is added
|
|
52
52
|
event TokenConfigAdded(address indexed vToken, bytes32 indexed pythId, uint64 indexed maxStalePeriod);
|
|
@@ -73,11 +73,13 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
73
73
|
* @custom:error Zero length error is thrown if length of the array in parameter is 0
|
|
74
74
|
*/
|
|
75
75
|
function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external {
|
|
76
|
-
_checkAccessAllowed("setTokenConfigs(TokenConfig[])");
|
|
77
76
|
if (tokenConfigs_.length == 0) revert("length can't be 0");
|
|
78
77
|
uint256 numTokenConfigs = tokenConfigs_.length;
|
|
79
|
-
for (uint256 i; i < numTokenConfigs;
|
|
78
|
+
for (uint256 i; i < numTokenConfigs; ) {
|
|
80
79
|
setTokenConfig(tokenConfigs_[i]);
|
|
80
|
+
unchecked {
|
|
81
|
+
++i;
|
|
82
|
+
}
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -91,9 +93,10 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
91
93
|
function setUnderlyingPythOracle(
|
|
92
94
|
IPyth underlyingPythOracle_
|
|
93
95
|
) external notNullAddress(address(underlyingPythOracle_)) {
|
|
94
|
-
_checkAccessAllowed("setUnderlyingPythOracle(
|
|
96
|
+
_checkAccessAllowed("setUnderlyingPythOracle(address)");
|
|
97
|
+
IPyth oldUnderlyingPythOracle = underlyingPythOracle;
|
|
95
98
|
underlyingPythOracle = underlyingPythOracle_;
|
|
96
|
-
emit PythOracleSet(address(underlyingPythOracle_));
|
|
99
|
+
emit PythOracleSet(address(oldUnderlyingPythOracle), address(underlyingPythOracle_));
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
/**
|
|
@@ -101,48 +104,36 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
101
104
|
* @param underlyingPythOracle_ Address of the Pyth oracle
|
|
102
105
|
* @param accessControlManager_ Address of the access control manager contract
|
|
103
106
|
*/
|
|
104
|
-
function initialize(
|
|
107
|
+
function initialize(
|
|
108
|
+
address underlyingPythOracle_,
|
|
109
|
+
address accessControlManager_
|
|
110
|
+
) external initializer notNullAddress(underlyingPythOracle_) {
|
|
105
111
|
__AccessControlled_init(accessControlManager_);
|
|
106
112
|
|
|
107
|
-
if (underlyingPythOracle_ == address(0)) revert("pyth oracle cannot be zero address");
|
|
108
113
|
underlyingPythOracle = IPyth(underlyingPythOracle_);
|
|
109
|
-
emit PythOracleSet(underlyingPythOracle_);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `vToken` can be a null address
|
|
114
|
-
* @param tokenConfig Token config struct
|
|
115
|
-
* @custom:access Only Governance
|
|
116
|
-
* @custom:error Range error is thrown if max stale period is zero
|
|
117
|
-
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
118
|
-
*/
|
|
119
|
-
function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
|
|
120
|
-
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
121
|
-
if (tokenConfig.maxStalePeriod == 0) revert("max stale period cannot be 0");
|
|
122
|
-
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
123
|
-
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
114
|
+
emit PythOracleSet(address(0), underlyingPythOracle_);
|
|
124
115
|
}
|
|
125
116
|
|
|
126
117
|
/**
|
|
127
118
|
* @notice Get price of underlying asset of the input vToken, under the hood this function
|
|
128
119
|
* get price from Pyth contract, the prices of which are updated externally
|
|
129
120
|
* @param vToken vToken address
|
|
130
|
-
* @return price Underlying price with a precision of
|
|
121
|
+
* @return price Underlying price with a precision of 18 decimals
|
|
131
122
|
* @custom:error Zero address error thrown if underlyingPythOracle address is null
|
|
132
123
|
* @custom:error Zero address error thrown if asset address is null
|
|
133
124
|
* @custom:error Range error thrown if price of Pyth oracle is not greater than zero
|
|
134
125
|
*/
|
|
135
|
-
function getUnderlyingPrice(
|
|
136
|
-
|
|
137
|
-
|
|
126
|
+
function getUnderlyingPrice(
|
|
127
|
+
address vToken
|
|
128
|
+
) external view override notNullAddress(address(underlyingPythOracle)) returns (uint256) {
|
|
138
129
|
address asset;
|
|
139
130
|
uint256 decimals;
|
|
140
131
|
|
|
141
132
|
// VBNB token doesn't have `underlying` method
|
|
142
|
-
if (
|
|
133
|
+
if (vToken == vBnb) {
|
|
143
134
|
asset = BNB_ADDR;
|
|
144
135
|
decimals = 18;
|
|
145
|
-
} else if (
|
|
136
|
+
} else if (vToken == vai) {
|
|
146
137
|
asset = vai;
|
|
147
138
|
decimals = 18;
|
|
148
139
|
} else {
|
|
@@ -171,4 +162,18 @@ contract PythOracle is AccessControlledV8, OracleInterface {
|
|
|
171
162
|
return ((price * EXP_SCALE) / (10 ** int256(-priceInfo.expo).toUint256())) * (10 ** (18 - decimals));
|
|
172
163
|
}
|
|
173
164
|
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @notice Set single token config. `maxStalePeriod` cannot be 0 and `vToken` can be a null address
|
|
168
|
+
* @param tokenConfig Token config struct
|
|
169
|
+
* @custom:access Only Governance
|
|
170
|
+
* @custom:error Range error is thrown if max stale period is zero
|
|
171
|
+
* @custom:error NotNullAddress error is thrown if asset address is null
|
|
172
|
+
*/
|
|
173
|
+
function setTokenConfig(TokenConfig memory tokenConfig) public notNullAddress(tokenConfig.asset) {
|
|
174
|
+
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
175
|
+
if (tokenConfig.maxStalePeriod == 0) revert("max stale period cannot be 0");
|
|
176
|
+
tokenConfigs[tokenConfig.asset] = tokenConfig;
|
|
177
|
+
emit TokenConfigAdded(tokenConfig.asset, tokenConfig.pythId, tokenConfig.maxStalePeriod);
|
|
178
|
+
}
|
|
174
179
|
}
|
|
@@ -7,30 +7,30 @@ import "../interfaces/OracleInterface.sol";
|
|
|
7
7
|
import "../interfaces/VBep20Interface.sol";
|
|
8
8
|
import "@venusprotocol/governance-contracts/contracts/Governance/AccessControlledV8.sol";
|
|
9
9
|
|
|
10
|
-
struct Observation {
|
|
11
|
-
uint256 timestamp;
|
|
12
|
-
uint256 acc;
|
|
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
|
-
|
|
31
10
|
contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
32
11
|
using FixedPoint for *;
|
|
33
12
|
|
|
13
|
+
struct Observation {
|
|
14
|
+
uint256 timestamp;
|
|
15
|
+
uint256 acc;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
struct TokenConfig {
|
|
19
|
+
/// @notice Asset address, which can't be zero address and can be used for existance check
|
|
20
|
+
address asset;
|
|
21
|
+
/// @notice Decimals of underlying asset respresented as 1e{decimals}
|
|
22
|
+
uint256 baseUnit;
|
|
23
|
+
/// @notice The address of Pancake pair
|
|
24
|
+
address pancakePool;
|
|
25
|
+
/// @notice Whether the token is paired with WBNB
|
|
26
|
+
bool isBnbBased;
|
|
27
|
+
/// @notice A flag identifies whether the Pancake pair is reversed
|
|
28
|
+
/// e.g. XVS-WBNB is reversed, while WBNB-XVS is not.
|
|
29
|
+
bool isReversedPool;
|
|
30
|
+
/// @notice The minimum window in seconds required between TWAP updates
|
|
31
|
+
uint256 anchorPeriod;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
34
|
/// @notice WBNB address
|
|
35
35
|
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
|
|
36
36
|
address public immutable WBNB;
|
|
@@ -44,8 +44,8 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
44
44
|
address public immutable vai;
|
|
45
45
|
|
|
46
46
|
/// @notice the base unit of WBNB and BUSD, which are the paired tokens for all assets
|
|
47
|
-
uint256 public constant
|
|
48
|
-
uint256 public constant
|
|
47
|
+
uint256 public constant BNB_BASE_UNIT = 1e18;
|
|
48
|
+
uint256 public constant BUSD_BASE_UNIT = 1e18;
|
|
49
49
|
|
|
50
50
|
/// @notice Configs by token
|
|
51
51
|
mapping(address => TokenConfig) public tokenConfigs;
|
|
@@ -101,12 +101,39 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
101
101
|
* @custom:error Zero length error thrown, if length of the config array is 0
|
|
102
102
|
*/
|
|
103
103
|
function setTokenConfigs(TokenConfig[] memory configs) external {
|
|
104
|
-
_checkAccessAllowed("setTokenConfigs(TokenConfig[])");
|
|
105
104
|
if (configs.length == 0) revert("length can't be 0");
|
|
106
105
|
uint256 numTokenConfigs = configs.length;
|
|
107
|
-
for (uint256 i; i < numTokenConfigs;
|
|
106
|
+
for (uint256 i; i < numTokenConfigs; ) {
|
|
108
107
|
setTokenConfig(configs[i]);
|
|
108
|
+
unchecked {
|
|
109
|
+
++i;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @notice Initializes the owner of the contract
|
|
116
|
+
* @param accessControlManager_ Address of the access control manager contract
|
|
117
|
+
*/
|
|
118
|
+
function initialize(address accessControlManager_) external initializer {
|
|
119
|
+
__AccessControlled_init(accessControlManager_);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
124
|
+
* @return anchorPrice anchor price of the underlying asset of the vToken
|
|
125
|
+
* @custom:error Missing error is thrown if token config does not exist
|
|
126
|
+
*/
|
|
127
|
+
function updateTwap(address vToken) external returns (uint256) {
|
|
128
|
+
address asset = _getUnderlyingAsset(vToken);
|
|
129
|
+
|
|
130
|
+
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
131
|
+
// Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
|
|
132
|
+
if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
|
|
133
|
+
if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
|
|
134
|
+
_updateTwapInternal(tokenConfigs[WBNB]);
|
|
109
135
|
}
|
|
136
|
+
return _updateTwapInternal(tokenConfigs[asset]);
|
|
110
137
|
}
|
|
111
138
|
|
|
112
139
|
/**
|
|
@@ -127,14 +154,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
127
154
|
return (price * (10 ** (18 - IERC20Metadata(asset).decimals())));
|
|
128
155
|
}
|
|
129
156
|
|
|
130
|
-
/**
|
|
131
|
-
* @notice Initializes the owner of the contract
|
|
132
|
-
* @param accessControlManager_ Address of the access control manager contract
|
|
133
|
-
*/
|
|
134
|
-
function initialize(address accessControlManager_) public initializer {
|
|
135
|
-
__AccessControlled_init(accessControlManager_);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
157
|
/**
|
|
139
158
|
* @notice Adds a single token config
|
|
140
159
|
* @param config token config struct
|
|
@@ -153,7 +172,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
153
172
|
_checkAccessAllowed("setTokenConfig(TokenConfig)");
|
|
154
173
|
|
|
155
174
|
if (config.anchorPeriod == 0) revert("anchor period must be positive");
|
|
156
|
-
if (config.baseUnit == 0) revert("base unit must be positive");
|
|
157
175
|
if (config.baseUnit != 10 ** IERC20Metadata(config.asset).decimals())
|
|
158
176
|
revert("base unit decimals must be same as asset decimals");
|
|
159
177
|
|
|
@@ -165,23 +183,6 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
165
183
|
emit TokenConfigAdded(config.asset, config.pancakePool, config.anchorPeriod);
|
|
166
184
|
}
|
|
167
185
|
|
|
168
|
-
/**
|
|
169
|
-
* @notice Updates the current token/BUSD price from PancakeSwap, with 18 decimals of precision.
|
|
170
|
-
* @return anchorPrice anchor price of the underlying asset of the vToken
|
|
171
|
-
* @custom:error Missing error is thrown if token config does not exist
|
|
172
|
-
*/
|
|
173
|
-
function updateTwap(address vToken) public returns (uint256) {
|
|
174
|
-
address asset = _getUnderlyingAsset(vToken);
|
|
175
|
-
|
|
176
|
-
if (tokenConfigs[asset].asset == address(0)) revert("asset not exist");
|
|
177
|
-
// Update & fetch WBNB price first, so we can calculate the price of WBNB paired token
|
|
178
|
-
if (asset != WBNB && tokenConfigs[asset].isBnbBased) {
|
|
179
|
-
if (tokenConfigs[WBNB].asset == address(0)) revert("WBNB not exist");
|
|
180
|
-
_updateTwapInternal(tokenConfigs[WBNB]);
|
|
181
|
-
}
|
|
182
|
-
return _updateTwapInternal(tokenConfigs[asset]);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
186
|
/**
|
|
186
187
|
* @notice Fetches the current token/WBNB and token/BUSD price accumulator from PancakeSwap.
|
|
187
188
|
* @return cumulative price of target token regardless of pair order
|
|
@@ -204,7 +205,7 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
204
205
|
* @custom:event Emits AnchorPriceUpdated event on successful update of observation with assset address,
|
|
205
206
|
* AnchorPrice, old observation timestamp and current timestamp
|
|
206
207
|
*/
|
|
207
|
-
function _updateTwapInternal(TokenConfig memory config)
|
|
208
|
+
function _updateTwapInternal(TokenConfig memory config) private returns (uint256) {
|
|
208
209
|
// pokeWindowValues already handled reversed pool cases,
|
|
209
210
|
// priceAverage will always be Token/BNB or Token/BUSD *twap** price.
|
|
210
211
|
(uint256 nowCumulativePrice, uint256 oldCumulativePrice, uint256 oldTimestamp) = pokeWindowValues(config);
|
|
@@ -214,7 +215,10 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
214
215
|
// This should be impossible, but better safe than sorry
|
|
215
216
|
if (block.timestamp < oldTimestamp) revert("now must come after before");
|
|
216
217
|
|
|
217
|
-
uint256 timeElapsed
|
|
218
|
+
uint256 timeElapsed;
|
|
219
|
+
unchecked {
|
|
220
|
+
timeElapsed = block.timestamp - oldTimestamp;
|
|
221
|
+
}
|
|
218
222
|
|
|
219
223
|
// Calculate Pancake *twap**
|
|
220
224
|
FixedPoint.uq112x112 memory priceAverage = FixedPoint.uq112x112(
|
|
@@ -224,15 +228,15 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
224
228
|
uint256 priceAverageMantissa = priceAverage.decode112with18();
|
|
225
229
|
|
|
226
230
|
// To cancel the decimals in cumulative price, we need to mulitply the average price with
|
|
227
|
-
// tokenBaseUnit / (
|
|
228
|
-
uint256 pairedTokenBaseUnit = config.isBnbBased ?
|
|
231
|
+
// tokenBaseUnit / (BNB_BASE_UNIT or BUSD_BASE_UNIT, which is 1e18)
|
|
232
|
+
uint256 pairedTokenBaseUnit = config.isBnbBased ? BNB_BASE_UNIT : BUSD_BASE_UNIT;
|
|
229
233
|
uint256 anchorPriceMantissa = (priceAverageMantissa * config.baseUnit) / pairedTokenBaseUnit;
|
|
230
234
|
|
|
231
235
|
// if this token is paired with BNB, convert its price to USD
|
|
232
236
|
if (config.isBnbBased) {
|
|
233
237
|
uint256 bnbPrice = prices[WBNB];
|
|
234
238
|
if (bnbPrice == 0) revert("bnb price is invalid");
|
|
235
|
-
anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) /
|
|
239
|
+
anchorPriceMantissa = (anchorPriceMantissa * bnbPrice) / BNB_BASE_UNIT;
|
|
236
240
|
}
|
|
237
241
|
|
|
238
242
|
if (anchorPriceMantissa == 0) revert("twap price cannot be 0");
|
|
@@ -256,18 +260,14 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
256
260
|
*/
|
|
257
261
|
function pokeWindowValues(
|
|
258
262
|
TokenConfig memory config
|
|
259
|
-
)
|
|
263
|
+
) private returns (uint256, uint256 startCumulativePrice, uint256 startCumulativeTimestamp) {
|
|
260
264
|
uint256 cumulativePrice = currentCumulativePrice(config);
|
|
261
265
|
uint256 currentTimestamp = block.timestamp;
|
|
262
266
|
uint256 windowStartTimestamp = currentTimestamp - config.anchorPeriod;
|
|
263
267
|
Observation[] memory storedObservations = observations[config.asset];
|
|
264
268
|
|
|
265
269
|
uint256 storedObservationsLength = storedObservations.length;
|
|
266
|
-
for (
|
|
267
|
-
uint256 windowStartIndex = windowStart[config.asset];
|
|
268
|
-
windowStartIndex < storedObservationsLength;
|
|
269
|
-
++windowStartIndex
|
|
270
|
-
) {
|
|
270
|
+
for (uint256 windowStartIndex = windowStart[config.asset]; windowStartIndex < storedObservationsLength; ) {
|
|
271
271
|
if (
|
|
272
272
|
(storedObservations[windowStartIndex].timestamp >= windowStartTimestamp) ||
|
|
273
273
|
(windowStartIndex == storedObservationsLength - 1)
|
|
@@ -279,6 +279,10 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
279
279
|
} else {
|
|
280
280
|
delete observations[config.asset][windowStartIndex];
|
|
281
281
|
}
|
|
282
|
+
|
|
283
|
+
unchecked {
|
|
284
|
+
++windowStartIndex;
|
|
285
|
+
}
|
|
282
286
|
}
|
|
283
287
|
|
|
284
288
|
observations[config.asset].push(Observation(currentTimestamp, cumulativePrice));
|
|
@@ -297,10 +301,10 @@ contract TwapOracle is AccessControlledV8, TwapInterface {
|
|
|
297
301
|
* @param vToken vToken address
|
|
298
302
|
* @return asset underlying asset address
|
|
299
303
|
*/
|
|
300
|
-
function _getUnderlyingAsset(address vToken)
|
|
301
|
-
if (
|
|
304
|
+
function _getUnderlyingAsset(address vToken) private view returns (address asset) {
|
|
305
|
+
if (vToken == vBnb) {
|
|
302
306
|
asset = WBNB;
|
|
303
|
-
} else if (
|
|
307
|
+
} else if (vToken == vai) {
|
|
304
308
|
asset = vai;
|
|
305
309
|
} else {
|
|
306
310
|
asset = VBep20Interface(vToken).underlying();
|
|
@@ -10,6 +10,10 @@ contract BEP20Harness is ERC20 {
|
|
|
10
10
|
decimalsInternal = decimals_;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
function faucet(uint256 amount) external {
|
|
14
|
+
_mint(msg.sender, amount);
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
function decimals() public view virtual override returns (uint8) {
|
|
14
18
|
return decimalsInternal;
|
|
15
19
|
}
|
|
@@ -18,8 +18,11 @@ contract MockPyth is AbstractPyth {
|
|
|
18
18
|
// simply update price feeds
|
|
19
19
|
function updatePriceFeedsHarness(PythStructs.PriceFeed[] calldata feeds) external {
|
|
20
20
|
require(feeds.length > 0, "feeds length must > 0");
|
|
21
|
-
for (uint256 i = 0; i < feeds.length;
|
|
21
|
+
for (uint256 i = 0; i < feeds.length; ) {
|
|
22
22
|
priceFeeds[feeds[i].id] = feeds[i];
|
|
23
|
+
unchecked {
|
|
24
|
+
++i;
|
|
25
|
+
}
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
|
|
@@ -41,7 +44,7 @@ contract MockPyth is AbstractPyth {
|
|
|
41
44
|
// We set it to 1.
|
|
42
45
|
uint16 chainId = 1;
|
|
43
46
|
|
|
44
|
-
for (uint256 i = 0; i < updateData.length;
|
|
47
|
+
for (uint256 i = 0; i < updateData.length; ) {
|
|
45
48
|
PythStructs.PriceFeed memory priceFeed = abi.decode(updateData[i], (PythStructs.PriceFeed));
|
|
46
49
|
|
|
47
50
|
bool fresh = false;
|
|
@@ -64,6 +67,10 @@ contract MockPyth is AbstractPyth {
|
|
|
64
67
|
priceFeed.price.price,
|
|
65
68
|
priceFeed.price.conf
|
|
66
69
|
);
|
|
70
|
+
|
|
71
|
+
unchecked {
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
// In the real contract, the input of this function contains multiple batches that each contain multiple prices.
|