diff --git a/contracts/lens/Quoter.sol b/contracts/lens/Quoter.sol index 28afa996..dc6ccf49 100644 --- a/contracts/lens/Quoter.sol +++ b/contracts/lens/Quoter.sol @@ -12,7 +12,6 @@ import {PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol"; import { SwapType, SwapInfo, - SwapIntention, ExactInputSingleParams, ExactInputSingleBatchParams, ExactInputParams, @@ -22,6 +21,7 @@ import { } from "../libraries/SwapIntention.sol"; import {IQuoter} from "../interfaces/IQuoter.sol"; import {PoolTicksCounter} from "../libraries/PoolTicksCounter.sol"; +import {PathKeyLib} from "../libraries/PathKey.sol"; contract Quoter is IQuoter { using PoolIdLibrary for PoolKey; @@ -256,7 +256,7 @@ contract Quoter is IQuoter { for (uint256 i = 0; i < pathLength; i++) { (PoolKey memory poolKey, bool zeroForOne) = - SwapIntention.getPoolAndSwapDirection(params.path[i], i == 0 ? params.currencyIn : prevCurrencyOut); + PathKeyLib.getPoolAndSwapDirection(params.path[i], i == 0 ? params.currencyIn : prevCurrencyOut); (, int24 tickBefore,,) = manager.getSlot0(poolKey.toId()); (BalanceDelta curDeltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap( @@ -308,7 +308,7 @@ contract Quoter is IQuoter { uint128 prevAmountIn; for (uint256 i = pathLength; i > 0; i--) { - (PoolKey memory poolKey, bool oneForZero) = SwapIntention.getPoolAndSwapDirection( + (PoolKey memory poolKey, bool oneForZero) = PathKeyLib.getPoolAndSwapDirection( params.path[i - 1], i == pathLength ? params.currencyOut : prevCurrencyIn ); diff --git a/contracts/libraries/PathKey.sol b/contracts/libraries/PathKey.sol index 4c0186ab..d13ccfce 100644 --- a/contracts/libraries/PathKey.sol +++ b/contracts/libraries/PathKey.sol @@ -4,6 +4,7 @@ pragma solidity ^0.8.20; import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol"; import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol"; +import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; struct PathKey { Currency intermediateCurrency; @@ -12,3 +13,18 @@ struct PathKey { IHooks hooks; bytes hookData; } + +library PathKeyLib { + function getPoolAndSwapDirection(PathKey memory params, Currency currencyIn) + internal + pure + returns (PoolKey memory poolKey, bool zeroForOne) + { + (Currency currency0, Currency currency1) = currencyIn < params.intermediateCurrency + ? (currencyIn, params.intermediateCurrency) + : (params.intermediateCurrency, currencyIn); + + zeroForOne = currencyIn == currency0; + poolKey = PoolKey(currency0, currency1, params.fee, params.tickSpacing, params.hooks); + } +} diff --git a/contracts/libraries/SwapIntention.sol b/contracts/libraries/SwapIntention.sol index ab02ffce..e6404812 100644 --- a/contracts/libraries/SwapIntention.sol +++ b/contracts/libraries/SwapIntention.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.20; -import {PathKey} from "./PathKey.sol"; +import {PathKey, PathKeyLib} from "./PathKey.sol"; import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol"; import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol"; import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol"; @@ -70,17 +70,4 @@ struct ExactOutputParams { uint160 sqrtPriceLimitX96; } -library SwapIntention { - function getPoolAndSwapDirection(PathKey memory params, Currency currencyIn) - internal - pure - returns (PoolKey memory poolKey, bool zeroForOne) - { - (Currency currency0, Currency currency1) = currencyIn < params.intermediateCurrency - ? (currencyIn, params.intermediateCurrency) - : (params.intermediateCurrency, currencyIn); - - zeroForOne = currencyIn == currency0; - poolKey = PoolKey(currency0, currency1, params.fee, params.tickSpacing, params.hooks); - } -} +library SwapIntention {} diff --git a/test/Quoter.t.sol b/test/Quoter.t.sol index 1b4f7f76..20043d51 100644 --- a/test/Quoter.t.sol +++ b/test/Quoter.t.sol @@ -3,7 +3,17 @@ pragma solidity ^0.8.20; import {Test} from "forge-std/Test.sol"; -import "../contracts/libraries/SwapIntention.sol"; +import { + SwapType, + SwapInfo, + ExactInputSingleParams, + ExactInputSingleBatchParams, + ExactInputParams, + ExactOutputSingleParams, + ExactOutputSingleBatchParams, + ExactOutputParams +} from "../contracts/libraries/SwapIntention.sol"; +import {PathKey} from "../contracts/libraries/PathKey.sol"; import {IQuoter} from "../contracts/interfaces/IQuoter.sol"; import {Quoter} from "../contracts/lens/Quoter.sol"; import {LiquidityAmounts} from "../contracts/libraries/LiquidityAmounts.sol";