Skip to content

Commit

Permalink
feat: change answer thresholds to percentage tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurka-o committed May 23, 2024
1 parent 6ae2610 commit 099af32
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config/chainlinkFeed.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"answerValueCeiling": 1815634312,
"answerValueFloor": 1615634312,
"answerDesiredValue": 144378,
"answerPercentageDriftTolerance": 10,
"blockNumber": 44706000,
"feedAddress": "0x1594F325afc4f8dc4E4ad0A3F758f48B1F72930a",
"heartbeat": 4000,
Expand Down
18 changes: 13 additions & 5 deletions tests/feeds/chainlink/ChainlinkFeed.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ contract ChainlinkFeedTest is Test {
}

struct JsonConfig {
uint256 answerValueCeiling;
uint256 answerValueFloor;
int256 answerDesiredValue;
int256 answerPercentageDriftTolerance;
uint64 blockNumber;
address feedAddress;
uint256 heartbeat;
Expand Down Expand Up @@ -59,12 +59,20 @@ contract ChainlinkFeedTest is Test {

function test_AnswerValue() public {
(uint80 latestRoundId,,,,) = feed.latestRoundData();
int256 answerCeiling;
int256 answerFloor;
int256 answerDriftAbsolute;

for (uint80 index = latestRoundId; index > latestRoundId - config.roundCount; index--) {
(,,, uint256 answer,) = feed.getRoundData(index);
(, int256 answer,,,) = feed.getRoundData(index);

assertGt(answer, config.answerValueFloor);
assertLt(answer, config.answerValueCeiling);
answerDriftAbsolute =
config.answerDesiredValue * config.answerPercentageDriftTolerance / 100;
answerCeiling = config.answerDesiredValue + answerDriftAbsolute;
answerFloor = config.answerDesiredValue - answerDriftAbsolute;

assertLt(answer, answerCeiling);
assertGt(answer, answerFloor);
}
}

Expand Down

0 comments on commit 099af32

Please sign in to comment.