25 lines
738 B
Solidity
25 lines
738 B
Solidity
pragma solidity ^0.8.20;
|
|
|
|
interface AggregatorV3Interface {
|
|
function latestRoundData() external view returns (
|
|
uint80 roundId,
|
|
int256 answer,
|
|
uint256 startedAt,
|
|
uint256 updatedAt,
|
|
uint80 answeredInRound
|
|
);
|
|
}
|
|
|
|
contract SPriceOracle {
|
|
AggregatorV3Interface public priceFeed;
|
|
|
|
constructor() {
|
|
priceFeed = AggregatorV3Interface(0x726D2E87d73567ecA1b75C063Bd09c1493655918);
|
|
}
|
|
/// @notice Returns the USD price of S in 1e18 based on API3
|
|
function getLatestPrice(address token) external view returns (uint256) {
|
|
(, int256 price,,,) = priceFeed.latestRoundData();
|
|
require(price > 0, "Invalid price from Chainlink");
|
|
return uint256(price);
|
|
}
|
|
} |