Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions FireHorsePriceConsumer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";

contract FireHorsePriceConsumer {
AggregatorV3Interface internal priceFeed;

constructor() {
// Plug Chainlink ETH/USD feed on Sepolia
priceFeed = AggregatorV3Interface(0x694AA1769357215DE4FAC081bf1f309aDC325306);
}

function getLatestPrice() public view returns (int) {
(, int price,,,) = priceFeed.latestRoundData(); // Returns price * 10^8
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate round freshness before using Chainlink answer

getLatestPrice() ignores the metadata returned by latestRoundData(), so checkSignal() can make LONG/SHORT decisions from stale or incomplete rounds when the feed is delayed or recovering. In those scenarios the contract returns a seemingly valid signal from outdated data, which can corrupt downstream strategy logic; add round-validity checks (for example updatedAt != 0 and answeredInRound >= roundId, plus an optional staleness window) before accepting price.

Useful? React with 👍 / 👎.

return price;
}

// Apply to your oracle: Trigger action if price > threshold
function checkSignal() external view returns (string memory) {
int price = getLatestPrice();
// Integrate your off-chain signal logic here (or via custom oracle)
return price > 3000 * 10**8 ? "LONG" : "SHORT";
}
}