Skip to content

Commit

Permalink
Merge pull request #38 from Uniswap/final-update
Browse files Browse the repository at this point in the history
Update to latest periphery
  • Loading branch information
hensha256 authored Sep 23, 2024
2 parents 961ea03 + 535368a commit eb66a99
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/v4-periphery
Submodule v4-periphery updated 57 files
+1 −1 .forge-snapshots/PositionManager_burn_nonEmpty_native_withClose.snap
+1 −1 .forge-snapshots/PositionManager_burn_nonEmpty_native_withTakePair.snap
+1 −1 .forge-snapshots/PositionManager_burn_nonEmpty_withClose.snap
+1 −1 .forge-snapshots/PositionManager_burn_nonEmpty_withTakePair.snap
+1 −1 .forge-snapshots/PositionManager_collect_native.snap
+1 −1 .forge-snapshots/PositionManager_collect_sameRange.snap
+1 −1 .forge-snapshots/PositionManager_collect_withClose.snap
+1 −1 .forge-snapshots/PositionManager_collect_withTakePair.snap
+1 −1 .forge-snapshots/PositionManager_decreaseLiquidity_native.snap
+1 −1 .forge-snapshots/PositionManager_decreaseLiquidity_withClose.snap
+1 −1 .forge-snapshots/PositionManager_decreaseLiquidity_withTakePair.snap
+1 −1 .forge-snapshots/PositionManager_decrease_burnEmpty.snap
+1 −1 .forge-snapshots/PositionManager_decrease_burnEmpty_native.snap
+1 −1 .forge-snapshots/PositionManager_decrease_sameRange_allLiquidity.snap
+1 −1 .forge-snapshots/PositionManager_decrease_take_take.snap
+1 −1 .forge-snapshots/PositionManager_increaseLiquidity_erc20_withClose.snap
+1 −1 .forge-snapshots/PositionManager_increaseLiquidity_erc20_withSettlePair.snap
+1 −1 .forge-snapshots/PositionManager_increaseLiquidity_native.snap
+1 −1 .forge-snapshots/PositionManager_increase_autocompoundExcessFeesCredit.snap
+1 −1 .forge-snapshots/PositionManager_increase_autocompound_clearExcess.snap
+1 −1 .forge-snapshots/PositionManager_mint_native.snap
+1 −1 .forge-snapshots/PositionManager_mint_nativeWithSweep_withClose.snap
+1 −1 .forge-snapshots/PositionManager_mint_nativeWithSweep_withSettlePair.snap
+1 −1 .forge-snapshots/PositionManager_mint_onSameTickLower.snap
+1 −1 .forge-snapshots/PositionManager_mint_onSameTickUpper.snap
+1 −1 .forge-snapshots/PositionManager_mint_sameRange.snap
+1 −1 .forge-snapshots/PositionManager_mint_settleWithBalance_sweep.snap
+1 −1 .forge-snapshots/PositionManager_mint_warmedPool_differentRange.snap
+1 −1 .forge-snapshots/PositionManager_mint_withClose.snap
+1 −1 .forge-snapshots/PositionManager_mint_withSettlePair.snap
+1 −1 .forge-snapshots/PositionManager_multicall_initialize_mint.snap
+1 −1 .forge-snapshots/Quoter_exactInputSingle_oneForZero_multiplePositions.snap
+1 −1 .forge-snapshots/Quoter_exactInputSingle_zeroForOne_multiplePositions.snap
+1 −1 .forge-snapshots/Quoter_exactOutputSingle_oneForZero.snap
+1 −1 .forge-snapshots/Quoter_exactOutputSingle_zeroForOne.snap
+1 −1 .forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap
+1 −1 .forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap
+1 −1 .forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap
+1 −1 .forge-snapshots/Quoter_quoteExactInput_twoHops.snap
+1 −1 .forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap
+1 −1 .forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap
+1 −1 .forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap
+1 −1 .forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap
+1 −1 .forge-snapshots/Quoter_quoteExactOutput_twoHops.snap
+1 −1 .forge-snapshots/V4Router_ExactIn2Hops.snap
+1 −1 .forge-snapshots/V4Router_ExactIn3Hops.snap
+1 −1 .forge-snapshots/V4Router_ExactIn3Hops_nativeIn.snap
+1 −1 .forge-snapshots/V4Router_ExactOut2Hops.snap
+1 −1 .forge-snapshots/V4Router_ExactOut3Hops.snap
+1 −1 .forge-snapshots/V4Router_ExactOut3Hops_nativeIn.snap
+1 −1 .forge-snapshots/V4Router_ExactOut3Hops_nativeOut.snap
+12 −16 src/base/BaseV4Quoter.sol
+0 −3 src/interfaces/IQuoter.sol
+14 −20 src/lens/Quoter.sol
+13 −19 src/libraries/QuoterRevert.sol
+0 −13 src/libraries/SqrtPriceLimitHelper.sol
+83 −43 test/Quoter.t.sol
27 changes: 7 additions & 20 deletions src/MixedRouteQuoterV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import {UniswapV2Library} from "./libraries/UniswapV2Library.sol";
import {IUniswapV3SwapCallback} from "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol";
import {IUniswapV3Pool} from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {SafeCast} from "@uniswap/v3-core/contracts/libraries/SafeCast.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
Expand All @@ -12,7 +13,6 @@ import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {BaseV4Quoter} from "@uniswap/v4-periphery/src/base/BaseV4Quoter.sol";
import {QuoterRevert} from "@uniswap/v4-periphery/src/libraries/QuoterRevert.sol";
import {SqrtPriceLimitHelper} from "@uniswap/v4-periphery/src/libraries/SqrtPriceLimitHelper.sol";

import {CallbackValidation} from "./libraries/CallbackValidation.sol";
import {IMixedRouteQuoterV2} from "./interfaces/IMixedRouteQuoterV2.sol";
Expand All @@ -23,7 +23,6 @@ contract MixedRouteQuoterV2 is IUniswapV3SwapCallback, IMixedRouteQuoterV2, Base
using Path for bytes;
using SafeCast for uint256;
using QuoterRevert for *;
using SqrtPriceLimitHelper for uint160;

address public immutable uniswapV3Poolfactory;
address public immutable uniswapV2Poolfactory;
Expand Down Expand Up @@ -78,11 +77,11 @@ contract MixedRouteQuoterV2 is IUniswapV3SwapCallback, IMixedRouteQuoterV2, Base
address(this), // address(0) might cause issues with some tokens
zeroForOne,
params.amountIn.toInt256(),
params.sqrtPriceLimitX96.getSqrtPriceLimit(zeroForOne),
zeroForOne ? TickMath.MIN_SQRT_PRICE + 1 : TickMath.MAX_SQRT_PRICE - 1,
abi.encodePacked(params.tokenIn, params.fee, params.tokenOut)
) {} catch (bytes memory reason) {
gasEstimate = gasBefore - gasleft();
amountOut = reason.parseReturnData();
amountOut = reason.parseQuoteAmount();
}
}

Expand All @@ -97,7 +96,7 @@ contract MixedRouteQuoterV2 is IUniswapV3SwapCallback, IMixedRouteQuoterV2, Base
try poolManager.unlock(abi.encodeCall(this._quoteExactInputSingleV4, (params))) {}
catch (bytes memory reason) {
gasEstimate = gasBefore - gasleft();
amountOut = reason.parseReturnData();
amountOut = reason.parseQuoteAmount();
}
}

Expand All @@ -107,13 +106,8 @@ contract MixedRouteQuoterV2 is IUniswapV3SwapCallback, IMixedRouteQuoterV2, Base
selfOnly
returns (bytes memory)
{
BalanceDelta swapDelta = _swap(
params.poolKey,
params.zeroForOne,
-int256(int256(params.exactAmount)),
params.sqrtPriceLimitX96,
params.hookData
);
BalanceDelta swapDelta =
_swap(params.poolKey, params.zeroForOne, -int256(int256(params.exactAmount)), params.hookData);

// the output delta of a swap is positive
uint256 amountOut = params.zeroForOne ? uint128(swapDelta.amount1()) : uint128(swapDelta.amount0());
Expand Down Expand Up @@ -177,7 +171,6 @@ contract MixedRouteQuoterV2 is IUniswapV3SwapCallback, IMixedRouteQuoterV2, Base
poolKey: poolKey,
zeroForOne: tokenIn < tokenOut,
exactAmount: amountIn,
sqrtPriceLimitX96: 0,
hookData: hookData
})
);
Expand All @@ -187,13 +180,7 @@ contract MixedRouteQuoterV2 is IUniswapV3SwapCallback, IMixedRouteQuoterV2, Base
(address tokenIn, uint24 fee, address tokenOut) = path.decodeFirstV3Pool();

(uint256 _amountOut, uint256 _gasEstimate) = quoteExactInputSingleV3(
QuoteExactInputSingleV3Params({
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn,
fee: fee,
sqrtPriceLimitX96: 0
})
QuoteExactInputSingleV3Params({tokenIn: tokenIn, tokenOut: tokenOut, amountIn: amountIn, fee: fee})
);
gasEstimate += _gasEstimate;
amountIn = _amountOut;
Expand Down
4 changes: 0 additions & 4 deletions src/interfaces/IMixedRouteQuoterV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ interface IMixedRouteQuoterV2 {
address tokenOut;
uint256 amountIn;
uint24 fee;
uint160 sqrtPriceLimitX96;
}

struct QuoteExactInputSingleV4Params {
PoolKey poolKey;
bool zeroForOne;
uint256 exactAmount;
uint160 sqrtPriceLimitX96;
bytes hookData;
}

Expand Down Expand Up @@ -60,7 +58,6 @@ interface IMixedRouteQuoterV2 {
/// tokenOut The token being swapped out
/// fee The fee of the token pool to consider for the pair
/// amountIn The desired input amount
/// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
/// @return amountOut The amount of `tokenOut` that would be received
/// @return gasEstimate The estimate of the gas that the swap consumes
function quoteExactInputSingleV3(QuoteExactInputSingleV3Params calldata params)
Expand All @@ -72,7 +69,6 @@ interface IMixedRouteQuoterV2 {
/// poolKey The key for identifying a V4 pool
/// zeroForOne If the swap is from currency0 to currency1
/// exactAmount The desired input amount
/// sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
/// hookData arbitrary hookData to pass into the associated hooks
/// @return amountOut The amount of `tokenOut` that would be received
/// @return gasEstimate The estimate of the gas that the swap consumes
Expand Down

0 comments on commit eb66a99

Please sign in to comment.