Skip to content

Commit

Permalink
fix: hardcode round id to 1 at unsupported adapters
Browse files Browse the repository at this point in the history
Signed-off-by: Reinis Martinsons <[email protected]>
  • Loading branch information
Reinis-FRP committed May 9, 2024
1 parent 88d7b91 commit 1721a9e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/adapters/destination-adapters/ChainlinkDestinationAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;

import {SafeCast} from "openzeppelin-contracts/contracts/utils/math/SafeCast.sol";

import {DecimalLib} from "../lib/DecimalLib.sol";
import {IAggregatorV3} from "../../interfaces/chainlink/IAggregatorV3.sol";
import {DiamondRootOval} from "../../DiamondRootOval.sol";
Expand Down Expand Up @@ -39,15 +41,22 @@ abstract contract ChainlinkDestinationAdapter is DiamondRootOval, IAggregatorV3

/**
* @notice Returns the latest Round data.
* @return roundId The roundId of the latest answer.
* @return roundId The roundId of the latest answer (sources that do not support it hardcodes to 1).
* @return answer The latest answer in the configured number of decimals.
* @return startedAt The timestamp when the value was updated.
* @return updatedAt The timestamp when the value was updated.
* @return answeredInRound The roundId of the round in which the answer was computed.
* @return answeredInRound The roundId of the round in which the answer was computed (sources that do not support it
* hardcodes to 1).
*/
function latestRoundData() external view returns (uint80, int256, uint256, uint256, uint80) {
(int256 answer, uint256 updatedAt, uint256 roundId) = internalLatestData();
return
(uint80(roundId), DecimalLib.convertDecimals(answer, 18, decimals), updatedAt, updatedAt, uint80(roundId));

return (
SafeCast.toUint80(roundId),
DecimalLib.convertDecimals(answer, 18, decimals),
updatedAt,
updatedAt,
SafeCast.toUint80(roundId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ abstract contract UniswapAnchoredViewSourceAdapter is SnapshotSource {
* @param maxTraversal The maximum number of rounds to traverse when looking for historical data.
* @return answer The answer as of requested timestamp, or earliest available data if not available, in 18 decimals.
* @return updatedAt The timestamp of the answer.
* @return roundId The roundId of the answer (0 for UniswapAnchoredView as it does not support historical lookups).
* @return roundId The roundId of the answer (hardcoded to 1 as UniswapAnchoredView does not support it).
*/
function tryLatestDataAt(uint256 timestamp, uint256 maxTraversal)
public
Expand All @@ -79,6 +79,6 @@ abstract contract UniswapAnchoredViewSourceAdapter is SnapshotSource {
returns (int256, uint256, uint256)
{
Snapshot memory snapshot = _tryLatestDataAt(timestamp, maxTraversal);
return (DecimalLib.convertDecimals(snapshot.answer, SOURCE_DECIMALS, 18), snapshot.timestamp, 0);
return (DecimalLib.convertDecimals(snapshot.answer, SOURCE_DECIMALS, 18), snapshot.timestamp, 1);
}
}

0 comments on commit 1721a9e

Please sign in to comment.