File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed
express-relay/easy_lend/contracts
my_first_pyth_app/contracts/src Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -85,7 +85,8 @@ contract EasyLend is IExpressRelayFeeReceiver {
85
85
*/
86
86
function _getPrice (bytes32 id ) internal view returns (uint256 ) {
87
87
IPyth oracle = IPyth (payable (_oracle));
88
- return convertToUint (oracle.getPrice (id), 18 );
88
+ // Get the price if it is not older than 60 seconds.
89
+ return convertToUint (oracle.getPriceNoOlderThan (id, 60 ), 18 );
89
90
}
90
91
91
92
function getAllowUndercollateralized () public view returns (bool ) {
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ contract MyFirstPythContract {
14
14
}
15
15
16
16
function mint () public payable {
17
- PythStructs.Price memory price = pyth.getPrice (ethUsdPriceId);
17
+ // Get the price if it is not older than 60 seconds.
18
+ PythStructs.Price memory price = pyth.getPriceNoOlderThan (ethUsdPriceId, 60 );
18
19
19
20
uint ethPrice18Decimals = (uint (uint64 (price.price)) * (10 ** 18 )) /
20
21
(10 ** uint8 (uint32 (- 1 * price.expo)));
@@ -41,4 +42,4 @@ contract MyFirstPythContract {
41
42
// Error raised if the payment is not sufficient
42
43
error InsufficientFee ();
43
44
}
44
-
45
+
Original file line number Diff line number Diff line change @@ -65,11 +65,14 @@ contract OracleSwap {
65
65
uint256 updateFee = pyth.getUpdateFee (pythUpdateData);
66
66
pyth.updatePriceFeeds {value: updateFee}(pythUpdateData);
67
67
68
- PythStructs.Price memory currentBasePrice = pyth.getPrice (
69
- baseTokenPriceId
68
+ // Get the prices if they are not older than 60 seconds.
69
+ PythStructs.Price memory currentBasePrice = pyth.getPriceNoOlderThan (
70
+ baseTokenPriceId,
71
+ 60
70
72
);
71
- PythStructs.Price memory currentQuotePrice = pyth.getPrice (
72
- quoteTokenPriceId
73
+ PythStructs.Price memory currentQuotePrice = pyth.getPriceNoOlderThan (
74
+ quoteTokenPriceId,
75
+ 60
73
76
);
74
77
75
78
// Note: this code does all arithmetic with 18 decimal points. This approach should be fine for most
You can’t perform that action at this time.
0 commit comments