Skip to content

Commit

Permalink
Fix Uniswap oracle crit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bread For The People committed Sep 1, 2020
1 parent 3715f47 commit f8ab6fa
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions contracts/lib/UniswapV2OracleLibrary.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity >=0.5.0;

import './IUniswapV2Pair.sol';
import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';
import './FixedPoint.sol';

// library with helper methods for oracles that are concerned with computing average prices
Expand All @@ -18,20 +18,20 @@ library UniswapV2OracleLibrary {
bool isToken0
) internal view returns (uint priceCumulative, uint32 blockTimestamp) {
blockTimestamp = currentBlockTimestamp();
(uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = UniswapPair(pair).getReserves();
(uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves();
if (isToken0) {
priceCumulative = UniswapPair(pair).price0CumulativeLast();
priceCumulative = IUniswapV2Pair(pair).price0CumulativeLast();

// if time has elapsed since the last update on the pair, mock the accumulated price values
if (blockTimestampLast != blockTimestamp) {
// subtraction overflow is desired
uint32 timeElapsed = blockTimestamp - blockTimestampLast;
// addition overflow is desired
// counterfactual
priceCumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed;
priceCumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed;
}
} else {
priceCumulative = UniswapPair(pair).price1CumulativeLast();
priceCumulative = IUniswapV2Pair(pair).price1CumulativeLast();
// if time has elapsed since the last update on the pair, mock the accumulated price values
if (blockTimestampLast != blockTimestamp) {
// subtraction overflow is desired
Expand Down

0 comments on commit f8ab6fa

Please sign in to comment.