Skip to content

Commit

Permalink
fix linter warnings for Quoter
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Nov 16, 2023
1 parent bd22b11 commit 1e0277b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
1 change: 1 addition & 0 deletions contracts/interfaces/IQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol";
interface IQuoter {
error InvalidQuoteType();
error InvalidQuoteTypeInRevert();
error InvalidLockAcquiredSender();
error UnexpectedRevertBytes();

struct NonZeroDeltaCurrency {
Expand Down
31 changes: 14 additions & 17 deletions contracts/lens/Quoter.sol
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.20;

import "forge-std/console2.sol";
import "../libraries/SwapIntention.sol";
import {IQuoter} from "../interfaces/IQuoter.sol";
import {PoolTicksCounter} from "../libraries/PoolTicksCounter.sol";
import {Hooks} from "@uniswap/v4-core/contracts/libraries/Hooks.sol";
import {SafeCast} from "@uniswap/v4-core/contracts/libraries/SafeCast.sol";
import {Pool} from "@uniswap/v4-core/contracts/libraries/Pool.sol";
import {TickMath} from "@uniswap/v4-core/contracts/libraries/TickMath.sol";
import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol";
import {IPoolManager} from "@uniswap/v4-core/contracts/interfaces/IPoolManager.sol";
import {BalanceDelta} from "@uniswap/v4-core/contracts/types/BalanceDelta.sol";
import {Currency} from "@uniswap/v4-core/contracts/types/Currency.sol";
import {PoolKey} from "@uniswap/v4-core/contracts/types/PoolKey.sol";
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol";
import {PoolManager} from "@uniswap/v4-core/contracts/PoolManager.sol";
import {PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol";

contract Quoter is IQuoter {
using PoolIdLibrary for PoolKey;
using Hooks for IHooks;

// v4 Singleton contract
IPoolManager immutable poolManager;
IPoolManager private immutable MANAGER;

constructor(address _poolManager) {
poolManager = IPoolManager(_poolManager);
MANAGER = IPoolManager(_poolManager);
}

function quoteExactInputSingle(ExactInputSingleParams memory params)
external
override
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded)
{
try poolManager.lock(abi.encode(SwapInfo(SwapType.ExactInputSingle, abi.encode(params)))) {}
try MANAGER.lock(abi.encode(SwapInfo(SwapType.ExactInputSingle, abi.encode(params)))) {}
catch (bytes memory reason) {
return _handleRevertExactInputSingle(reason, params.poolKey);
}
Expand All @@ -47,14 +43,16 @@ contract Quoter is IQuoter {
uint32[] memory initializedTicksLoadedList
)
{
try poolManager.lock(abi.encode(SwapInfo(SwapType.ExactInput, abi.encode(params)))) {}
try MANAGER.lock(abi.encode(SwapInfo(SwapType.ExactInput, abi.encode(params)))) {}
catch (bytes memory reason) {
return _handleRevertExactInput(reason);
}
}

function lockAcquired(bytes calldata encodedSwapIntention) external returns (bytes memory) {
require(msg.sender == address(poolManager));
if (msg.sender != address(MANAGER)) {
revert InvalidLockAcquiredSender();
}

SwapInfo memory swapInfo = abi.decode(encodedSwapIntention, (SwapInfo));

Expand Down Expand Up @@ -105,14 +103,13 @@ contract Quoter is IQuoter {
int24 tickAfter;
BalanceDelta deltas;
deltaAmounts = new int128[](2);
(, tickBefore,,) = poolManager.getSlot0(poolKey.toId());
(, tickBefore,,) = MANAGER.getSlot0(poolKey.toId());
reason = validateRevertReason(reason);
(deltas, sqrtPriceX96After, tickAfter) = abi.decode(reason, (BalanceDelta, uint160, int24));
deltaAmounts[0] = deltas.amount0();
deltaAmounts[1] = deltas.amount1();

initializedTicksLoaded =
PoolTicksCounter.countInitializedTicksLoaded(poolManager, poolKey, tickBefore, tickAfter);
initializedTicksLoaded = PoolTicksCounter.countInitializedTicksLoaded(MANAGER, poolKey, tickBefore, tickAfter);
}

function _handleRevertExactInput(bytes memory reason)
Expand Down Expand Up @@ -148,7 +145,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);
(, int24 tickBefore,,) = poolManager.getSlot0(poolKey.toId());
(, int24 tickBefore,,) = MANAGER.getSlot0(poolKey.toId());

ExactInputSingleParams memory singleParams = ExactInputSingleParams({
poolKey: poolKey,
Expand All @@ -169,7 +166,7 @@ contract Quoter is IQuoter {
prevCurrencyOut = params.path[i].intermediateCurrency;
sqrtPriceX96AfterList[i] = sqrtPriceX96After;
initializedTicksLoadedList[i] =
PoolTicksCounter.countInitializedTicksLoaded(poolManager, poolKey, tickBefore, tickAfter);
PoolTicksCounter.countInitializedTicksLoaded(MANAGER, poolKey, tickBefore, tickAfter);
}
}

Expand All @@ -193,7 +190,7 @@ contract Quoter is IQuoter {
uint160 sqrtPriceLimitX96,
bytes memory hookData
) private returns (BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) {
deltas = poolManager.swap(
deltas = MANAGER.swap(
poolKey,
IPoolManager.SwapParams({
zeroForOne: zeroForOne,
Expand All @@ -202,7 +199,7 @@ contract Quoter is IQuoter {
}),
hookData
);
(sqrtPriceX96After, tickAfter,,) = poolManager.getSlot0(poolKey.toId());
(sqrtPriceX96After, tickAfter,,) = MANAGER.getSlot0(poolKey.toId());
}

function _sqrtPriceLimitOrDefault(uint160 sqrtPriceLimitX96, bool zeroForOne) private pure returns (uint160) {
Expand Down

0 comments on commit 1e0277b

Please sign in to comment.