Skip to content

Commit

Permalink
fix: do not expose round id in snapshot adapters yet
Browse files Browse the repository at this point in the history
Signed-off-by: Reinis Martinsons <reinis@umaproject.org>
  • Loading branch information
Reinis-FRP committed May 8, 2024
1 parent c8b0534 commit 88d7b91
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
3 changes: 1 addition & 2 deletions src/DiamondRootOval.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ abstract contract DiamondRootOval is IBaseController, IOval, IBaseOracleAdapter
* @notice Returns the latest data from the source.
* @return answer The latest answer in 18 decimals.
* @return updatedAt The timestamp of the answer.
* @return roundId The roundId of the answer.
*/
function getLatestSourceData() public view virtual returns (int256, uint256, uint256);
function getLatestSourceData() public view virtual returns (int256, uint256);

/**
* @notice Tries getting latest data as of requested timestamp. If this is not possible, returns the earliest data
Expand Down
7 changes: 3 additions & 4 deletions src/adapters/source-adapters/ChainlinkSourceAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ abstract contract ChainlinkSourceAdapter is DiamondRootOval {
* @notice Returns the latest data from the source.
* @return answer The latest answer in 18 decimals.
* @return updatedAt The timestamp of the answer.
* @return roundId The roundId of the answer.
*/
function getLatestSourceData() public view virtual override returns (int256, uint256, uint256) {
(uint80 roundId, int256 sourceAnswer,, uint256 updatedAt,) = CHAINLINK_SOURCE.latestRoundData();
return (DecimalLib.convertDecimals(sourceAnswer, SOURCE_DECIMALS, 18), updatedAt, roundId);
function getLatestSourceData() public view virtual override returns (int256, uint256) {
(, int256 sourceAnswer,, uint256 updatedAt,) = CHAINLINK_SOURCE.latestRoundData();
return (DecimalLib.convertDecimals(sourceAnswer, SOURCE_DECIMALS, 18), updatedAt);
}

// Tries getting latest data as of requested timestamp. If this is not possible, returns the earliest data available
Expand Down
17 changes: 7 additions & 10 deletions src/adapters/source-adapters/SnapshotSource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,27 @@ abstract contract SnapshotSource is DiamondRootOval {
struct Snapshot {
int256 answer;
uint256 timestamp;
uint256 roundId;
}

Snapshot[] public snapshots; // Historical answer and timestamp snapshots.

event SnapshotTaken(
uint256 snapshotIndex, uint256 indexed timestamp, int256 indexed answer, uint256 indexed roundId
);
event SnapshotTaken(uint256 snapshotIndex, uint256 indexed timestamp, int256 indexed answer);

/**
* @notice Returns the latest snapshot data.
* @return Snapshot The latest snapshot data.
*/
function latestSnapshotData() public view returns (Snapshot memory) {
if (snapshots.length > 0) return snapshots[snapshots.length - 1];
return Snapshot(0, 0, 0);
return Snapshot(0, 0);
}

/**
* @notice Snapshot the current source data.
*/
function snapshotData() public virtual override {
(int256 answer, uint256 timestamp, uint256 roundId) = getLatestSourceData();
Snapshot memory snapshot = Snapshot(answer, timestamp, roundId);
(int256 answer, uint256 timestamp) = getLatestSourceData();
Snapshot memory snapshot = Snapshot(answer, timestamp);
if (snapshot.timestamp == 0) return; // Should not store invalid data.

// We expect source timestamps to be increasing over time, but there is little we can do to recover if source
Expand All @@ -45,12 +42,12 @@ abstract contract SnapshotSource is DiamondRootOval {

snapshots.push(snapshot);

emit SnapshotTaken(snapshotIndex, snapshot.timestamp, snapshot.answer, snapshot.roundId);
emit SnapshotTaken(snapshotIndex, snapshot.timestamp, snapshot.answer);
}

function _tryLatestDataAt(uint256 timestamp, uint256 maxTraversal) internal view returns (Snapshot memory) {
(int256 answer, uint256 _timestamp, uint256 roundId) = getLatestSourceData();
Snapshot memory latestData = Snapshot(answer, _timestamp, roundId);
(int256 answer, uint256 _timestamp) = getLatestSourceData();
Snapshot memory latestData = Snapshot(answer, _timestamp);
// In the happy path there have been no source updates since requested time, so we can return the latest data.
// We can use timestamp property as it matches the block timestamp of the latest source update.
if (latestData.timestamp <= timestamp) return latestData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ abstract contract UniswapAnchoredViewSourceAdapter is SnapshotSource {
* @notice Returns the latest data from the source.
* @return answer The latest answer in 18 decimals.
* @return updatedAt The timestamp of the answer.
* @return roundId The roundId of the answer.
*/
function getLatestSourceData() public view override returns (int256, uint256, uint256) {
(uint80 latestRoundId,,, uint256 latestTimestamp,) = aggregator.latestRoundData();
function getLatestSourceData() public view override returns (int256, uint256) {
(,,, uint256 latestTimestamp,) = aggregator.latestRoundData();
int256 sourcePrice = int256(UNISWAP_ANCHORED_VIEW.getUnderlyingPrice(C_TOKEN));
return (DecimalLib.convertDecimals(sourcePrice, SOURCE_DECIMALS, 18), latestTimestamp, latestRoundId);
return (DecimalLib.convertDecimals(sourcePrice, SOURCE_DECIMALS, 18), latestTimestamp);
}

/**
Expand All @@ -71,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.
* @return roundId The roundId of the answer (0 for UniswapAnchoredView as it does not support historical lookups).
*/
function tryLatestDataAt(uint256 timestamp, uint256 maxTraversal)
public
Expand All @@ -80,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, snapshot.roundId);
return (DecimalLib.convertDecimals(snapshot.answer, SOURCE_DECIMALS, 18), snapshot.timestamp, 0);
}
}
2 changes: 1 addition & 1 deletion src/interfaces/IBaseOracleAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface IBaseOracleAdapter {
view
returns (int256 answer, uint256 timestamp, uint256 roundId);

function getLatestSourceData() external view returns (int256 answer, uint256 timestamp, uint256 roundId);
function getLatestSourceData() external view returns (int256 answer, uint256 timestamp);
}

0 comments on commit 88d7b91

Please sign in to comment.