@venusprotocol/oracle 1.2.1 → 1.2.3

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.
Files changed (104) hide show
  1. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.dbg.json +1 -1
  2. package/artifacts/@openzeppelin/contracts/token/ERC20/ERC20.sol/ERC20.json +2 -2
  3. package/artifacts/@openzeppelin/contracts/token/ERC20/IERC20.sol/IERC20.dbg.json +1 -1
  4. package/artifacts/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol/IERC20Metadata.dbg.json +1 -1
  5. package/artifacts/@openzeppelin/contracts/utils/Context.sol/Context.dbg.json +1 -1
  6. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.dbg.json +1 -1
  7. package/artifacts/@openzeppelin/contracts/utils/math/SafeCast.sol/SafeCast.json +2 -2
  8. package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.dbg.json +1 -1
  9. package/artifacts/@openzeppelin/contracts/utils/math/SafeMath.sol/SafeMath.json +2 -2
  10. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.dbg.json +1 -1
  11. package/artifacts/@openzeppelin/contracts/utils/math/SignedMath.sol/SignedMath.json +2 -2
  12. package/artifacts/@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol/OwnableUpgradeable.dbg.json +1 -1
  13. package/artifacts/@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol/Initializable.dbg.json +1 -1
  14. package/artifacts/@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol/PausableUpgradeable.dbg.json +1 -1
  15. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.dbg.json +1 -1
  16. package/artifacts/@openzeppelin/contracts-upgradeable/utils/AddressUpgradeable.sol/AddressUpgradeable.json +2 -2
  17. package/artifacts/@openzeppelin/contracts-upgradeable/utils/ContextUpgradeable.sol/ContextUpgradeable.dbg.json +1 -1
  18. package/artifacts/build-info/4d2af5803ee95a57ec9aace7ed32201c.json +1 -0
  19. package/artifacts/build-info/766f05630947fa6d366a667b66c1141b.json +1 -0
  20. package/artifacts/contracts/PriceOracle.sol/PriceOracle.dbg.json +4 -0
  21. package/artifacts/contracts/PriceOracle.sol/PriceOracle.json +62 -0
  22. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.dbg.json +1 -1
  23. package/artifacts/contracts/ResilientOracle.sol/ResilientOracle.json +2 -2
  24. package/artifacts/contracts/interfaces/AggregatorV2V3Interface.sol/AggregatorV2V3Interface.dbg.json +1 -1
  25. package/artifacts/contracts/interfaces/BEP20Interface.sol/BEP20Interface.dbg.json +1 -1
  26. package/artifacts/contracts/interfaces/FeedRegistryInterface.sol/FeedRegistryInterface.dbg.json +1 -1
  27. package/artifacts/contracts/interfaces/OracleInterface.sol/BoundValidatorInterface.dbg.json +1 -1
  28. package/artifacts/contracts/interfaces/OracleInterface.sol/OracleInterface.dbg.json +1 -1
  29. package/artifacts/contracts/interfaces/OracleInterface.sol/ResilientOracleInterface.dbg.json +1 -1
  30. package/artifacts/contracts/interfaces/OracleInterface.sol/TwapInterface.dbg.json +1 -1
  31. package/artifacts/contracts/interfaces/PythInterface.sol/IPyth.dbg.json +1 -1
  32. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.dbg.json +1 -1
  33. package/artifacts/contracts/interfaces/PythInterface.sol/PythStructs.json +2 -2
  34. package/artifacts/contracts/interfaces/VBep20Interface.sol/VBep20Interface.dbg.json +1 -1
  35. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.dbg.json +1 -1
  36. package/artifacts/contracts/libraries/PancakeLibrary.sol/FixedPoint.json +2 -2
  37. package/artifacts/contracts/libraries/PancakeLibrary.sol/IPancakePair.dbg.json +1 -1
  38. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.dbg.json +1 -1
  39. package/artifacts/contracts/libraries/PancakeLibrary.sol/PancakeOracleLibrary.json +2 -2
  40. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.dbg.json +1 -1
  41. package/artifacts/contracts/oracles/BinanceOracle.sol/BinanceOracle.json +2 -2
  42. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.dbg.json +1 -1
  43. package/artifacts/contracts/oracles/BoundValidator.sol/BoundValidator.json +2 -2
  44. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.dbg.json +1 -1
  45. package/artifacts/contracts/oracles/ChainlinkOracle.sol/ChainlinkOracle.json +2 -2
  46. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.dbg.json +1 -1
  47. package/artifacts/contracts/oracles/PythOracle.sol/PythOracle.json +2 -2
  48. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.dbg.json +1 -1
  49. package/artifacts/contracts/oracles/TwapOracle.sol/TwapOracle.json +2 -2
  50. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.dbg.json +1 -1
  51. package/artifacts/contracts/oracles/mocks/MockBinanceFeedRegistry.sol/MockBinanceFeedRegistry.json +2 -2
  52. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.dbg.json +1 -1
  53. package/artifacts/contracts/oracles/mocks/MockBinanceOracle.sol/MockBinanceOracle.json +2 -2
  54. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.dbg.json +1 -1
  55. package/artifacts/contracts/oracles/mocks/MockChainlinkOracle.sol/MockChainlinkOracle.json +2 -2
  56. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.dbg.json +1 -1
  57. package/artifacts/contracts/oracles/mocks/MockPythOracle.sol/MockPythOracle.json +2 -2
  58. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.dbg.json +1 -1
  59. package/artifacts/contracts/oracles/mocks/MockTwapOracle.sol/MockTwapOracle.json +2 -2
  60. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.dbg.json +1 -1
  61. package/artifacts/contracts/test/BEP20Harness.sol/BEP20Harness.json +2 -2
  62. package/artifacts/contracts/test/MockPyth.sol/MockPyth.dbg.json +1 -1
  63. package/artifacts/contracts/test/MockPyth.sol/MockPyth.json +2 -2
  64. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.dbg.json +1 -1
  65. package/artifacts/contracts/test/MockSimpleOracle.sol/MockBoundValidator.json +2 -2
  66. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.dbg.json +1 -1
  67. package/artifacts/contracts/test/MockSimpleOracle.sol/MockSimpleOracle.json +2 -2
  68. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.dbg.json +1 -1
  69. package/artifacts/contracts/test/MockV3Aggregator.sol/MockV3Aggregator.json +2 -2
  70. package/artifacts/contracts/test/PancakePairHarness.sol/Math.dbg.json +1 -1
  71. package/artifacts/contracts/test/PancakePairHarness.sol/Math.json +2 -2
  72. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.dbg.json +1 -1
  73. package/artifacts/contracts/test/PancakePairHarness.sol/PancakePairHarness.json +2 -2
  74. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.dbg.json +1 -1
  75. package/artifacts/contracts/test/PancakePairHarness.sol/UQ112x112.json +2 -2
  76. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.dbg.json +1 -1
  77. package/artifacts/contracts/test/VBEP20Harness.sol/VBEP20Harness.json +2 -2
  78. package/contracts/PriceOracle.sol +16 -0
  79. package/contracts/ResilientOracle.sol +282 -0
  80. package/contracts/interfaces/AggregatorV2V3Interface.sol +60 -0
  81. package/contracts/interfaces/BEP20Interface.sol +97 -0
  82. package/contracts/interfaces/FeedRegistryInterface.sol +17 -0
  83. package/contracts/interfaces/OracleInterface.sol +23 -0
  84. package/contracts/interfaces/PythInterface.sol +180 -0
  85. package/contracts/interfaces/VBep20Interface.sol +11 -0
  86. package/contracts/libraries/PancakeLibrary.sol +81 -0
  87. package/contracts/oracles/BinanceOracle.sol +30 -0
  88. package/contracts/oracles/BoundValidator.sol +97 -0
  89. package/contracts/oracles/ChainlinkOracle.sol +172 -0
  90. package/contracts/oracles/PythOracle.sol +129 -0
  91. package/contracts/oracles/TwapOracle.sol +235 -0
  92. package/contracts/oracles/mocks/MockBinanceFeedRegistry.sol +32 -0
  93. package/contracts/oracles/mocks/MockBinanceOracle.sol +23 -0
  94. package/contracts/oracles/mocks/MockChainlinkOracle.sol +26 -0
  95. package/contracts/oracles/mocks/MockPythOracle.sol +31 -0
  96. package/contracts/oracles/mocks/MockTwapOracle.sol +30 -0
  97. package/contracts/test/BEP20Harness.sol +21 -0
  98. package/contracts/test/MockPyth.sol +88 -0
  99. package/contracts/test/MockSimpleOracle.sol +41 -0
  100. package/contracts/test/MockV3Aggregator.sol +91 -0
  101. package/contracts/test/PancakePairHarness.sol +103 -0
  102. package/contracts/test/VBEP20Harness.sol +21 -0
  103. package/package.json +3 -2
  104. package/artifacts/build-info/c88e3d40dfcb048309cae1c803479ead.json +0 -1
@@ -0,0 +1,282 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.0;
3
+ pragma experimental ABIEncoderV2;
4
+
5
+ import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
6
+ import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
7
+ import "./interfaces/OracleInterface.sol";
8
+
9
+ contract ResilientOracle is OwnableUpgradeable, PausableUpgradeable, ResilientOracleInterface {
10
+ uint256 public constant INVALID_PRICE = 0;
11
+
12
+ BoundValidatorInterface public boundValidator;
13
+
14
+ /**
15
+ * @dev oracle role, we have 3 roles at the moment
16
+ * MAIN: The most trustworthy price source
17
+ * PIVOT: Not so trustworthy price source, used as a loose sanity checker
18
+ * FALLBACK: The backup source when main oracle price is invalidated
19
+ */
20
+ enum OracleRole {
21
+ MAIN,
22
+ PIVOT,
23
+ FALLBACK
24
+ }
25
+
26
+ struct TokenConfig {
27
+ /// @notice vToken address
28
+ address vToken;
29
+ /// @notice `oracles` stores the oracles in the order of: [main, pivot, fallback],
30
+ /// it can be indexed with enum OracleRole value
31
+ address[3] oracles;
32
+ /// @notice `enableFlagsForOracles` stores the oracle enable statuses
33
+ /// for each oracle in the same order as `oracles`
34
+ bool[3] enableFlagsForOracles;
35
+ }
36
+
37
+ mapping(address => TokenConfig) private tokenConfigs;
38
+
39
+ event GlobalEnable(bool indexed isEnable);
40
+ event TokenConfigAdded(
41
+ address indexed token,
42
+ address indexed mainOracle,
43
+ address indexed pivotOracle,
44
+ address fallbackOracle
45
+ );
46
+ event OracleSet(address indexed vToken, address indexed oracle, uint256 indexed role);
47
+ event OracleEnabled(address indexed vToken, uint256 indexed role, bool indexed enable);
48
+
49
+ modifier notNullAddress(address someone) {
50
+ require(someone != address(0), "can't be zero address");
51
+ _;
52
+ }
53
+
54
+ /**
55
+ * @notice Check whether token config exist by checking whether vToken is zero address
56
+ * @dev vToken can't be set to zero, so it's suitable to be used to check
57
+ * @param vToken vtoken address
58
+ */
59
+ modifier checkTokenConfigExistance(address vToken) {
60
+ require(tokenConfigs[vToken].vToken != address(0), "token config must exist");
61
+ _;
62
+ }
63
+
64
+ function initialize(BoundValidatorInterface _boundValidator) public initializer {
65
+ require(address(_boundValidator) != address(0), "invaliud bound validator address");
66
+ boundValidator = _boundValidator;
67
+
68
+ __Ownable_init();
69
+ __Pausable_init();
70
+ }
71
+
72
+ /**
73
+ * @notice Pause protocol
74
+ */
75
+ function pause() external onlyOwner {
76
+ _pause();
77
+ }
78
+
79
+ /**
80
+ * @notice Unpause protocol
81
+ */
82
+ function unpause() external onlyOwner {
83
+ _unpause();
84
+ }
85
+
86
+ /**
87
+ * @dev Get token config by vToken address
88
+ * @param vToken vtoken address
89
+ */
90
+ function getTokenConfig(address vToken) external view returns (TokenConfig memory) {
91
+ return tokenConfigs[vToken];
92
+ }
93
+
94
+ /**
95
+ * @notice Get oracle & enabling status by vToken address
96
+ * @param vToken vtoken address
97
+ * @param role oracle role
98
+ */
99
+ function getOracle(address vToken, OracleRole role) public view returns (address oracle, bool enabled) {
100
+ oracle = tokenConfigs[vToken].oracles[uint256(role)];
101
+ enabled = tokenConfigs[vToken].enableFlagsForOracles[uint256(role)];
102
+ }
103
+
104
+ /**
105
+ * @notice Batch set token configs
106
+ * @param tokenConfigs_ token config array
107
+ */
108
+ function setTokenConfigs(TokenConfig[] memory tokenConfigs_) external onlyOwner {
109
+ require(tokenConfigs_.length != 0, "length can't be 0");
110
+ for (uint256 i = 0; i < tokenConfigs_.length; i++) {
111
+ setTokenConfig(tokenConfigs_[i]);
112
+ }
113
+ }
114
+
115
+ /**
116
+ * @notice Set single token configs, vToken MUST HAVE NOT be added before, and main oracle MUST NOT be zero address
117
+ * @param tokenConfig token config struct
118
+ */
119
+ function setTokenConfig(TokenConfig memory tokenConfig)
120
+ public
121
+ onlyOwner
122
+ notNullAddress(tokenConfig.vToken)
123
+ notNullAddress(tokenConfig.oracles[uint256(OracleRole.MAIN)])
124
+ {
125
+ tokenConfigs[tokenConfig.vToken] = tokenConfig;
126
+ emit TokenConfigAdded(
127
+ tokenConfig.vToken,
128
+ tokenConfig.oracles[uint256(OracleRole.MAIN)],
129
+ tokenConfig.oracles[uint256(OracleRole.PIVOT)],
130
+ tokenConfig.oracles[uint256(OracleRole.FALLBACK)]
131
+ );
132
+ }
133
+
134
+ /**
135
+ * @notice Set oracle of any type for the input vToken, input vToken MUST exist
136
+ * @param vToken vToken address
137
+ * @param oracle oracle address
138
+ * @param role oracle role
139
+ */
140
+ function setOracle(
141
+ address vToken,
142
+ address oracle,
143
+ OracleRole role
144
+ ) external onlyOwner notNullAddress(vToken) checkTokenConfigExistance(vToken) {
145
+ require(!(oracle == address(0) && role == OracleRole.MAIN), "can't set zero address to main oracle");
146
+ tokenConfigs[vToken].oracles[uint256(role)] = oracle;
147
+ emit OracleSet(vToken, oracle, uint256(role));
148
+ }
149
+
150
+ /**
151
+ * @notice Enable/disable oracle for the input vToken, input vToken MUST exist
152
+ * @param vToken vToken address
153
+ * @param role oracle role
154
+ * @param enable expected status
155
+ */
156
+ function enableOracle(
157
+ address vToken,
158
+ OracleRole role,
159
+ bool enable
160
+ ) external onlyOwner notNullAddress(vToken) checkTokenConfigExistance(vToken) {
161
+ tokenConfigs[vToken].enableFlagsForOracles[uint256(role)] = enable;
162
+ emit OracleEnabled(vToken, uint256(role), enable);
163
+ }
164
+
165
+ /**
166
+ * @notice Currently it calls the updateTwap
167
+ * @param vToken vToken address
168
+ */
169
+ function updatePrice(address vToken) external override {
170
+ (address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
171
+ if (pivotOracle != address(0) && pivotOracleEnabled) {
172
+ //if PIVOT oracle is PythOrcle it will revert so we need to catch the revert
173
+ try TwapInterface(pivotOracle).updateTwap(vToken) returns (uint256 _price) {} catch {}
174
+ }
175
+ }
176
+
177
+ /**
178
+ * @notice Get price of underlying asset of the input vToken, check flow:
179
+ * - check the global pausing status
180
+ * - check price from main oracle against pivot oracle
181
+ * - check price from fallback oracle against pivot oracle or main oracle if fails
182
+ * @param vToken vToken address
183
+ * @return price USD price in 18 decimals
184
+ */
185
+ function getUnderlyingPrice(address vToken) external view override returns (uint256) {
186
+ require(!paused(), "resilient oracle is paused");
187
+
188
+ uint256 price = _getMainOraclePrice(vToken);
189
+ if (price == INVALID_PRICE) {
190
+ price = _getFallbackOraclePrice(vToken);
191
+ }
192
+
193
+ require(price != INVALID_PRICE, "invalid resilient oracle price");
194
+ return price;
195
+ }
196
+
197
+ /**
198
+ * @notice This function won't revert when price is 0, because the fallback oracle may come to play later
199
+ * @param vToken vToken address
200
+ * @return price USD price in 18 decimals
201
+ */
202
+ function _getMainOraclePrice(address vToken) internal view returns (uint256) {
203
+ uint256 price = INVALID_PRICE;
204
+
205
+ (address mainOracle, bool mainOracleEnabled) = getOracle(vToken, OracleRole.MAIN);
206
+ if (mainOracleEnabled && mainOracle != address(0)) {
207
+ try OracleInterface(mainOracle).getUnderlyingPrice(vToken) returns (uint256 mainOraclePrice) {
208
+ price = mainOraclePrice;
209
+
210
+ (address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
211
+
212
+ if (pivotOracleEnabled && pivotOracle != address(0)) {
213
+ try OracleInterface(pivotOracle).getUnderlyingPrice(vToken) returns (uint256 pivotPrice) {
214
+ if (pivotPrice != INVALID_PRICE) {
215
+ bool isPriceValid = boundValidator.validatePriceWithAnchorPrice(vToken, price, pivotPrice);
216
+ if (!isPriceValid) {
217
+ return INVALID_PRICE;
218
+ }
219
+ }
220
+ } catch {}
221
+ }
222
+ } catch {}
223
+ }
224
+
225
+ return price;
226
+ }
227
+
228
+ /**
229
+ * @notice This function won't revert when price is 0, because the getUnderlyingPrice checks if pirce is > 0
230
+ * @param vToken vToken address
231
+ * @return price USD price in 18 decimals
232
+ */
233
+ function _getFallbackOraclePrice(address vToken) internal view returns (uint256) {
234
+ uint256 price = INVALID_PRICE;
235
+ bool compareWithMain = false;
236
+
237
+ (address fallbackOracle, bool fallbackEnabled) = getOracle(vToken, OracleRole.FALLBACK);
238
+ if (fallbackEnabled && fallbackOracle != address(0)) {
239
+ try OracleInterface(fallbackOracle).getUnderlyingPrice(vToken) returns (uint256 fallbackOraclePrice) {
240
+ price = fallbackOraclePrice;
241
+
242
+ (address pivotOracle, bool pivotOracleEnabled) = getOracle(vToken, OracleRole.PIVOT);
243
+ if (pivotOracleEnabled && pivotOracle != address(0)) {
244
+ try OracleInterface(pivotOracle).getUnderlyingPrice(vToken) returns (uint256 pivotPrice) {
245
+ if (pivotPrice != INVALID_PRICE) {
246
+ bool isPriceValid = boundValidator.validatePriceWithAnchorPrice(vToken, price, pivotPrice);
247
+ if (!isPriceValid) {
248
+ compareWithMain = true;
249
+ }
250
+ } else {
251
+ compareWithMain = true;
252
+ }
253
+ } catch {
254
+ compareWithMain = true;
255
+ }
256
+ } else {
257
+ compareWithMain = true;
258
+ }
259
+ } catch {}
260
+ }
261
+
262
+ if (compareWithMain) {
263
+ (address mainOracle, bool mainOracleEnabled) = getOracle(vToken, OracleRole.MAIN);
264
+ if (mainOracleEnabled && mainOracle != address(0)) {
265
+ try OracleInterface(mainOracle).getUnderlyingPrice(vToken) returns (uint256 mainOraclePrice) {
266
+ bool isPriceValid = boundValidator.validatePriceWithAnchorPrice(vToken, price, mainOraclePrice);
267
+ if (!isPriceValid) {
268
+ return INVALID_PRICE;
269
+ } else {
270
+ price = mainOraclePrice;
271
+ }
272
+ } catch {
273
+ price = INVALID_PRICE;
274
+ }
275
+ } else {
276
+ price = INVALID_PRICE;
277
+ }
278
+ }
279
+
280
+ return price;
281
+ }
282
+ }
@@ -0,0 +1,60 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.0;
3
+
4
+ /**
5
+ * @title The V2 & V3 Aggregator Interface
6
+ * @notice Solidity V0.5 does not allow interfaces to inherit from other
7
+ * interfaces so this contract is a combination of v0.5 AggregatorInterface.sol
8
+ * and v0.5 AggregatorV3Interface.sol.
9
+ */
10
+ interface AggregatorV2V3Interface {
11
+ //
12
+ // V2 Interface:
13
+ //
14
+ function latestAnswer() external view returns (int256);
15
+
16
+ function latestTimestamp() external view returns (uint256);
17
+
18
+ function latestRound() external view returns (uint256);
19
+
20
+ function getAnswer(uint256 roundId) external view returns (int256);
21
+
22
+ function getTimestamp(uint256 roundId) external view returns (uint256);
23
+
24
+ event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 timestamp);
25
+ event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt);
26
+
27
+ //
28
+ // V3 Interface:
29
+ //
30
+ function decimals() external view returns (uint8);
31
+
32
+ function description() external view returns (string memory);
33
+
34
+ function version() external view returns (uint256);
35
+
36
+ // getRoundData and latestRoundData should both raise "No data present"
37
+ // if they do not have data to report, instead of returning unset values
38
+ // which could be misinterpreted as actual reported values.
39
+ function getRoundData(uint80 _roundId)
40
+ external
41
+ view
42
+ returns (
43
+ uint80 roundId,
44
+ int256 answer,
45
+ uint256 startedAt,
46
+ uint256 updatedAt,
47
+ uint80 answeredInRound
48
+ );
49
+
50
+ function latestRoundData()
51
+ external
52
+ view
53
+ returns (
54
+ uint80 roundId,
55
+ int256 answer,
56
+ uint256 startedAt,
57
+ uint256 updatedAt,
58
+ uint80 answeredInRound
59
+ );
60
+ }
@@ -0,0 +1,97 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.0;
3
+
4
+ interface BEP20Interface {
5
+ /**
6
+ * @dev Returns the amount of tokens in existence.
7
+ */
8
+ function totalSupply() external view returns (uint256);
9
+
10
+ /**
11
+ * @dev Returns the token decimals.
12
+ */
13
+ function decimals() external view returns (uint8);
14
+
15
+ /**
16
+ * @dev Returns the token symbol.
17
+ */
18
+ function symbol() external view returns (string memory);
19
+
20
+ /**
21
+ * @dev Returns the token name.
22
+ */
23
+ function name() external view returns (string memory);
24
+
25
+ /**
26
+ * @dev Returns the bep token owner.
27
+ */
28
+ function getOwner() external view returns (address);
29
+
30
+ /**
31
+ * @dev Returns the amount of tokens owned by `account`.
32
+ */
33
+ function balanceOf(address account) external view returns (uint256);
34
+
35
+ /**
36
+ * @dev Moves `amount` tokens from the caller's account to `recipient`.
37
+ *
38
+ * Returns a boolean value indicating whether the operation succeeded.
39
+ *
40
+ * Emits a {Transfer} event.
41
+ */
42
+ function transfer(address recipient, uint256 amount) external returns (bool);
43
+
44
+ /**
45
+ * @dev Returns the remaining number of tokens that `spender` will be
46
+ * allowed to spend on behalf of `owner` through {transferFrom}. This is
47
+ * zero by default.
48
+ *
49
+ * This value changes when {approve} or {transferFrom} are called.
50
+ */
51
+ function allowance(address _owner, address spender) external view returns (uint256);
52
+
53
+ /**
54
+ * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
55
+ *
56
+ * Returns a boolean value indicating whether the operation succeeded.
57
+ *
58
+ * IMPORTANT: Beware that changing an allowance with this method brings the risk
59
+ * that someone may use both the old and the new allowance by unfortunate
60
+ * transaction ordering. One possible solution to mitigate this race
61
+ * condition is to first reduce the spender's allowance to 0 and set the
62
+ * desired value afterwards:
63
+ * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
64
+ *
65
+ * Emits an {Approval} event.
66
+ */
67
+ function approve(address spender, uint256 amount) external returns (bool);
68
+
69
+ /**
70
+ * @dev Moves `amount` tokens from `sender` to `recipient` using the
71
+ * allowance mechanism. `amount` is then deducted from the caller's
72
+ * allowance.
73
+ *
74
+ * Returns a boolean value indicating whether the operation succeeded.
75
+ *
76
+ * Emits a {Transfer} event.
77
+ */
78
+ function transferFrom(
79
+ address sender,
80
+ address recipient,
81
+ uint256 amount
82
+ ) external returns (bool);
83
+
84
+ /**
85
+ * @dev Emitted when `value` tokens are moved from one account (`from`) to
86
+ * another (`to`).
87
+ *
88
+ * Note that `value` may be zero.
89
+ */
90
+ event Transfer(address indexed from, address indexed to, uint256 value);
91
+
92
+ /**
93
+ * @dev Emitted when the allowance of a `spender` for an `owner` is set by
94
+ * a call to {approve}. `value` is the new allowance.
95
+ */
96
+ event Approval(address indexed owner, address indexed spender, uint256 value);
97
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.10;
3
+
4
+ interface FeedRegistryInterface {
5
+ function latestRoundDataByName(string memory base, string memory quote)
6
+ external
7
+ view
8
+ returns (
9
+ uint80 roundId,
10
+ int256 answer,
11
+ uint256 startedAt,
12
+ uint256 updatedAt,
13
+ uint80 answeredInRound
14
+ );
15
+
16
+ function decimalsByName(string memory base, string memory quote) external view returns (uint8);
17
+ }
@@ -0,0 +1,23 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.0;
3
+ pragma experimental ABIEncoderV2;
4
+
5
+ interface OracleInterface {
6
+ function getUnderlyingPrice(address vToken) external view returns (uint256);
7
+ }
8
+
9
+ interface ResilientOracleInterface is OracleInterface {
10
+ function updatePrice(address vToken) external;
11
+ }
12
+
13
+ interface TwapInterface is OracleInterface {
14
+ function updateTwap(address vToken) external returns (uint256);
15
+ }
16
+
17
+ interface BoundValidatorInterface {
18
+ function validatePriceWithAnchorPrice(
19
+ address vToken,
20
+ uint256 reporterPrice,
21
+ uint256 anchorPrice
22
+ ) external view returns (bool);
23
+ }
@@ -0,0 +1,180 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ pragma solidity ^0.8.0;
3
+
4
+ contract PythStructs {
5
+ //
6
+ // The confidence interval roughly corresponds to the standard error of a normal distribution.
7
+ // Both the price and confidence are stored in a fixed-point numeric representation,
8
+ // `x * (10^expo)`, where `expo` is the exponent.
9
+ //
10
+ // Please refer to the documentation at https://docs.pyth.network/consumers/best-practices for how
11
+ // to how this price safely.
12
+ struct Price {
13
+ // Price
14
+ int64 price;
15
+ // Confidence interval around the price
16
+ uint64 conf;
17
+ // Price exponent
18
+ int32 expo;
19
+ }
20
+
21
+ // PriceFeed represents a current aggregate price from pyth publisher feeds.
22
+ struct PriceFeed {
23
+ // The price ID.
24
+ bytes32 id;
25
+ // Product account key.
26
+ bytes32 productId;
27
+ // The current price.
28
+ int64 price;
29
+ // Confidence interval around the price.
30
+ uint64 conf;
31
+ // Price exponent.
32
+ int32 expo;
33
+ // Status of price.
34
+ PriceStatus status;
35
+ // Maximum number of allowed publishers that can contribute to a price.
36
+ uint32 maxNumPublishers;
37
+ // Number of publishers that made up current aggregate.
38
+ uint32 numPublishers;
39
+ // Exponentially moving average price.
40
+ int64 emaPrice;
41
+ // Exponentially moving average confidence interval.
42
+ uint64 emaConf;
43
+ // Unix timestamp describing when the price was published
44
+ uint64 publishTime;
45
+ // Price of previous price with TRADING status
46
+ int64 prevPrice;
47
+ // Confidence interval of previous price with TRADING status
48
+ uint64 prevConf;
49
+ // Unix timestamp describing when the previous price with TRADING status was published
50
+ uint64 prevPublishTime;
51
+ }
52
+
53
+ /* PriceStatus represents the availability status of a price feed.
54
+ UNKNOWN: The price feed is not currently updating for an unknown reason.
55
+ TRADING: The price feed is updating as expected.
56
+ HALTED: The price feed is not currently updating because trading in the product has been halted.
57
+ AUCTION: The price feed is not currently updating because an auction is setting the price.
58
+ */
59
+ enum PriceStatus {
60
+ UNKNOWN,
61
+ TRADING,
62
+ HALTED,
63
+ AUCTION
64
+ }
65
+ }
66
+
67
+ /// @title Consume prices from the Pyth Network (https://pyth.network/).
68
+ /// @author Pyth Data Association
69
+ interface IPyth {
70
+ /// @dev Emitted when an update for price feed with `id` is processed successfully.
71
+ /// @param id The Pyth Price Feed ID.
72
+ /// @param fresh True if the price update is more recent and stored.
73
+ /// @param chainId ID of the source chain that the batch price update containing this price.
74
+ /// This value comes from Wormhole,
75
+ /// you can find the corresponding chains at https://docs.wormholenetwork.com/wormhole/contracts.
76
+ /// @param sequenceNumber Sequence number of the batch price update containing this price.
77
+ /// @param lastPublishTime Publish time of the previously stored price.
78
+ /// @param publishTime Publish time of the given price update.
79
+ /// @param price Current price of the given price update.
80
+ /// @param conf Current confidence interval of the given price update.
81
+ event PriceFeedUpdate(
82
+ bytes32 indexed id,
83
+ bool indexed fresh,
84
+ uint16 chainId,
85
+ uint64 sequenceNumber,
86
+ uint64 lastPublishTime,
87
+ uint64 publishTime,
88
+ int64 price,
89
+ uint64 conf
90
+ );
91
+
92
+ /// @dev Emitted when a batch price update is processed successfully.
93
+ /// @param chainId ID of the source chain that the batch price update comes from.
94
+ /// @param sequenceNumber Sequence number of the batch price update.
95
+ /// @param batchSize Number of prices within the batch price update.
96
+ /// @param freshPricesInBatch Number of prices that were more recent and were stored.
97
+ event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber, uint256 batchSize, uint256 freshPricesInBatch);
98
+
99
+ /// @dev Emitted when a call to `updatePriceFeeds` is processed successfully.
100
+ /// @param sender Sender of the call (`msg.sender`).
101
+ /// @param batchCount Number of batches that this function processed.
102
+ /// @param fee Amount of paid fee for updating the prices.
103
+ event UpdatePriceFeeds(address indexed sender, uint256 batchCount, uint256 fee);
104
+
105
+ /// @notice Returns the current price and confidence interval.
106
+ /// @dev Reverts if the current price is not available.
107
+ /// @param id The Pyth Price Feed ID of which to fetch the current price and confidence interval.
108
+ /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
109
+ function getCurrentPrice(bytes32 id) external view returns (PythStructs.Price memory price);
110
+
111
+ /// @notice Returns the exponential moving average price and confidence interval.
112
+ /// @dev Reverts if the current exponential moving average price is not available.
113
+ /// @param id The Pyth Price Feed ID of which to fetch the current price and confidence interval.
114
+ /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
115
+ function getEmaPrice(bytes32 id) external view returns (PythStructs.Price memory price);
116
+
117
+ /// @notice Returns the latest available price, along with the timestamp when it was generated.
118
+ /// @dev This function returns the same price as `getCurrentPrice` in the case where a price was available
119
+ /// at the time this `PriceFeed` was published (`publish_time`). However, if a price was not available
120
+ /// at that time, this function returns the price from the latest time at which the price was available.
121
+ ///
122
+ /// The returned price can be from arbitrarily far in the past; this function makes no guarantees that
123
+ /// the returned price is recent or useful for any particular application.
124
+ ///
125
+ /// Users of this function should check the returned timestamp to ensure that the returned price is
126
+ /// sufficiently recent for their application. If you are considering using this function, it may be
127
+ /// safer / easier to use either `getCurrentPrice` or `getLatestAvailablePriceWithinDuration`.
128
+ /// @return price - please read the documentation of PythStructs.Price to understand how to use this safely.
129
+ /// @return publishTime - the UNIX timestamp of when this price was computed.
130
+ function getLatestAvailablePriceUnsafe(bytes32 id)
131
+ external
132
+ view
133
+ returns (PythStructs.Price memory price, uint64 publishTime);
134
+
135
+ /// @notice Returns the latest price as long as it was updated within `duration` seconds of the current time.
136
+ /// @dev This function is a sanity-checked version of `getLatestAvailablePriceUnchecked` which is useful in
137
+ /// applications that require a sufficiently-recent price. Reverts if the price wasn't updated sufficiently
138
+ /// recently.
139
+ function getLatestAvailablePriceWithinDuration(bytes32 id, uint64 duration)
140
+ external
141
+ view
142
+ returns (PythStructs.Price memory price);
143
+
144
+ /// @notice Update price feeds with given update messages.
145
+ /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
146
+ /// `getUpdateFee` with the length of the `updateData` array.
147
+ /// Prices will be updated if they are more recent than the current stored prices.
148
+ /// The call will succeed even if the update is not the most recent.
149
+ /// @dev Reverts if the transferred fee is not sufficient or the updateData is invalid.
150
+ /// @param updateData Array of price update data.
151
+ function updatePriceFeeds(bytes[] memory updateData) external payable;
152
+
153
+ /// @notice Wrapper around updatePriceFeeds that rejects fast if a price update is not necessary. A price update is
154
+ /// necessary if the current on-chain publishTime is older than the given publishTime. It relies solely on the
155
+ /// given `publishTimes` for the price feeds and
156
+ /// does not read the actual price update publish time within `updateData`.
157
+ ///
158
+ /// This method requires the caller to pay a fee in wei; the required fee can be computed by calling
159
+ /// `getUpdateFee` with the length of the `updateData` array.
160
+ ///
161
+ /// `priceIds` and `publishTimes` are two arrays with the same size that correspond to senders known publishTime
162
+ /// of each priceId when calling this method. If all of price feeds within `priceIds` have updated and have
163
+ /// a newer or equal publish time than the given publish time, it will reject the transaction to save gas.
164
+ /// Otherwise, it calls updatePriceFeeds method to update the prices.
165
+ ///
166
+ /// @dev Reverts if update is not needed or the transferred fee is not sufficient or the updateData is invalid.
167
+ /// @param updateData Array of price update data.
168
+ /// @param priceIds Array of price ids.
169
+ /// @param publishTimes Array of publishTimes. `publishTimes[i]` corresponds to known `publishTime` of `priceIds[i]`
170
+ function updatePriceFeedsIfNecessary(
171
+ bytes[] memory updateData,
172
+ bytes32[] memory priceIds,
173
+ uint64[] memory publishTimes
174
+ ) external payable;
175
+
176
+ /// @notice Returns the required fee to update an array of price updates.
177
+ /// @param updateDataSize Number of price updates.
178
+ /// @return feeAmount The required fee in Wei.
179
+ function getUpdateFee(uint256 updateDataSize) external view returns (uint256 feeAmount);
180
+ }
@@ -0,0 +1,11 @@
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./BEP20Interface.sol";
5
+
6
+ interface VBep20Interface is BEP20Interface {
7
+ /**
8
+ * @notice Underlying asset for this VToken
9
+ */
10
+ function underlying() external view returns (address);
11
+ }