-
Notifications
You must be signed in to change notification settings - Fork 0
Add FireHorseConsumer Chainlink signal consumer contract #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.20; | ||
|
|
||
| import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; | ||
|
|
||
| contract FireHorseConsumer { | ||
| AggregatorV3Interface internal oracle; | ||
| address public owner; | ||
|
|
||
| constructor(address _oracle) { | ||
| oracle = AggregatorV3Interface(_oracle); | ||
| owner = msg.sender; | ||
| } | ||
|
|
||
| function getSignal() public view returns (string memory) { | ||
| (, int256 answer, , , ) = oracle.latestRoundData(); | ||
| return answer == 1 ? "LONG" : "SHORT"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
|
|
||
| function autoTrade() external { | ||
| require(msg.sender == owner, "Only owner"); | ||
|
|
||
| string memory sig = getSignal(); | ||
| sig; | ||
| // TODO: Integrate DEX execution logic based on signal. | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor accepts
_oraclewithout validation, so a misconfigured deployment (e.g.,address(0)or a non-aggregator address) will leave the contract unable to return a signal becauselatestRoundData()cannot be decoded as expected. Failing fast in the constructor with an address/code check prevents shipping a permanently broken consumer.Useful? React with 👍 / 👎.