-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create OracleLib to check for stale pricefeed data
- Loading branch information
Showing
3 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.28; | ||
|
||
import {AggregatorV3Interface} from "@chainlink/contracts/shared/interfaces/AggregatorV3Interface.sol"; | ||
|
||
library OracleLib { | ||
error OracleLib__StalePrice(); | ||
|
||
uint256 public constant TIMEOUT = 1 hours; | ||
|
||
function staleCheckLatestRoundData(AggregatorV3Interface priceFeed) | ||
public | ||
view | ||
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) | ||
{ | ||
(roundId, answer, startedAt, updatedAt, answeredInRound) = priceFeed.latestRoundData(); | ||
|
||
if (block.timestamp - updatedAt > TIMEOUT) { | ||
revert OracleLib__StalePrice(); | ||
} | ||
} | ||
} |