Skip to content

Commit

Permalink
refactor lockAcquired
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Nov 22, 2023
1 parent 57330b2 commit c841c34
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions contracts/lens/Quoter.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.20;

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 {TickMath} from "@uniswap/v4-core/contracts/libraries/TickMath.sol";
import {IHooks} from "@uniswap/v4-core/contracts/interfaces/IHooks.sol";
Expand All @@ -12,6 +9,9 @@ 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 {PoolIdLibrary} from "@uniswap/v4-core/contracts/types/PoolId.sol";
import "../libraries/SwapIntention.sol";
import {IQuoter} from "../interfaces/IQuoter.sol";
import {PoolTicksCounter} from "../libraries/PoolTicksCounter.sol";

contract Quoter is IQuoter {
using PoolIdLibrary for PoolKey;
Expand Down Expand Up @@ -165,48 +165,40 @@ contract Quoter is IQuoter {
}

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

if (swapInfo.swapType == SwapType.ExactInputSingle) {
(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) =
_quoteExactInputSingle(abi.decode(swapInfo.params, (ExactInputSingleParams)));

bytes memory result = abi.encode(deltas, sqrtPriceX96After, tickAfter);
assembly {
revert(add(0x20, result), mload(result))
}
result = abi.encode(deltas, sqrtPriceX96After, tickAfter);
} else if (swapInfo.swapType == SwapType.ExactOutputSingle) {
(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) =
_quoteExactOutputSingle(abi.decode(swapInfo.params, (ExactOutputSingleParams)));

bytes memory result = abi.encode(deltas, sqrtPriceX96After, tickAfter);
assembly {
revert(add(0x20, result), mload(result))
}
result = abi.encode(deltas, sqrtPriceX96After, tickAfter);
} else if (swapInfo.swapType == SwapType.ExactInput) {
(
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksLoadedList
) = _quoteExactInput(abi.decode(swapInfo.params, (ExactInputParams)));

bytes memory result = abi.encode(deltaAmounts, sqrtPriceX96AfterList, initializedTicksLoadedList);
assembly {
revert(add(0x20, result), mload(result))
}
result = abi.encode(deltaAmounts, sqrtPriceX96AfterList, initializedTicksLoadedList);
} else if (swapInfo.swapType == SwapType.ExactOutput) {
(
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksLoadedList
) = _quoteExactOutput(abi.decode(swapInfo.params, (ExactOutputParams)));

bytes memory result = abi.encode(deltaAmounts, sqrtPriceX96AfterList, initializedTicksLoadedList);
assembly {
revert(add(0x20, result), mload(result))
}
result = abi.encode(deltaAmounts, sqrtPriceX96AfterList, initializedTicksLoadedList);
} else {
revert InvalidQuoteType();
}
assembly {
revert(add(0x20, result), mload(result))
}
}

function validateRevertReason(bytes memory reason) private pure returns (bytes memory) {
Expand Down

0 comments on commit c841c34

Please sign in to comment.