Skip to content

Commit

Permalink
Merge branch 'master' into reinis-frp/fix-bounded-union
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinis-FRP committed May 16, 2024
2 parents 05b2ae5 + 4e0428f commit 0fa0033
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ abstract contract UniswapAnchoredViewSourceAdapter is SnapshotSource {
*/
function tryLatestDataAt(uint256 timestamp, uint256 maxTraversal) public view override returns (int256, uint256) {
Snapshot memory snapshot = _tryLatestDataAt(timestamp, maxTraversal);
return (DecimalLib.convertDecimals(snapshot.answer, SOURCE_DECIMALS, 18), snapshot.timestamp);
return (snapshot.answer, snapshot.timestamp);
}
}
26 changes: 25 additions & 1 deletion test/fork/adapters/UniswapAnchoredViewSourceAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract UniswapAnchoredViewSourceAdapterTest is CommonTest {
assertTrue(latestAggregatorTimestamp == latestSourceTimestamp);
}

function testCorrectlyStandardizesOutputs() public {
function testCorrectlyStandardizesLatestOutputs() public {
// Repeat the same test as above, but with cWBTC where underlying has 8 decimals.
address cWBTC = 0xccF4429DB6322D5C611ee964527D42E5d685DD6a;
sourceAdapter = new TestedSourceAdapter(uniswapAnchoredView, cWBTC);
Expand All @@ -64,6 +64,30 @@ contract UniswapAnchoredViewSourceAdapterTest is CommonTest {
assertTrue(latestAggregatorTimestamp == latestSourceTimestamp);
}

function testCorrectlyStandardizesLatestAtOutputs() public {
// Repeat the same test for cWBTC as above, but for tryLatestDataAt.
uint256 targetTime = block.timestamp;

address cWBTC = 0xccF4429DB6322D5C611ee964527D42E5d685DD6a;
sourceAdapter = new TestedSourceAdapter(uniswapAnchoredView, cWBTC);
aggregator = IAccessControlledAggregatorV3(address(sourceAdapter.aggregator()));

// Fork ~24 hours (7200 blocks on mainnet) forward with persistent source adapter.
vm.makePersistent(address(sourceAdapter));
vm.createSelectFork("mainnet", targetBlock + 7200);
_whitelistOnAggregator();

// UniswapAnchoredView does not support historical lookups so this should still return latest data without snapshotting.
uint256 latestUniswapAnchoredViewAnswer = uniswapAnchoredView.getUnderlyingPrice(cWBTC);
uint256 latestAggregatorTimestamp = aggregator.latestTimestamp();
(int256 lookBackPrice, uint256 lookBackTimestamp) = sourceAdapter.tryLatestDataAt(targetTime, 100);

// WBTC has 8 decimals, so source price feed is scaled at (36 - 8) = 28 decimals.
uint256 standardizedAnswer = latestUniswapAnchoredViewAnswer / 10 ** (28 - 18);
assertTrue(int256(standardizedAnswer) == lookBackPrice);
assertTrue(latestAggregatorTimestamp == lookBackTimestamp);
}

function testReturnsLatestSourceDataNoSnapshot() public {
uint256 targetTime = block.timestamp;

Expand Down

0 comments on commit 0fa0033

Please sign in to comment.