Skip to content

Commit

Permalink
feat: Revert style quoter (#73)
Browse files Browse the repository at this point in the history
* add PoolTicksCounter library

* quoter exact input single

* quoter test

* return deltas instead

* safe casting to correct types

* QuoteExactInput skeleton

* multiple entries

* break handleRevert by type

* quoteExactInput and unit tests

* more QuoteExactInput tests

* remove lgos

* remove commented out struct

* via-ir in ci

* remove unused imports/functions

* store iteration params locally instead of editing function input

* pull out sqrtPriceLimit to its own function

* PathKey to its own library

* rename initializedTicksCrossed to initializedTicksLoaded

* remove manual abi encoding in yul :p

* fix linter warnings for Quoter

* natspec for IQuoter

* feat: update v4-core

This commit updates v4 core to latest and fixes integration issues

* fix: tests

* style fixes

* inheritdoc

* ExactInSingleBatch

* fix: update tests

* fix: test router was borked

* exact out

* fix: alice comments

* fix ExactOutput

* add ExactOput unit tests

* add quoteExactOutputBatch

* remove solhint config

* remove newline

* add QuoteExactOutput in interface

* refactor lockAcquired

* move magic numbers to constants + doc

* add more natspec

* natspec

* named imports

* self-call branching

* remove old code

* remove console2 import

* refactor PathKeyLib

* amountOutCached

* inherit ILockCallback

* add base contracts and interfaces (#75)

* remove unused errors

* test lockAcquired reverts

* remove ...Batch interface

* REASON -> RESPONSE when valid

* complete natspec

* remove SwapInfo imports

* rename to SwapParameters

* move quoter structs into IQuoter interface

* update to latest core

* use prev values

* change twamm to use pool getters

* changes after merging main

* use --via-ir in cli

* fix formatting

* fix FullRange/TWAMM hook

* update ticks counter

* update Quoter test

* typo

* typo

* simplify handleRevertSingle

* merge QuoteInput/OutputSingle structs

* combine IQuoter structs

* using ... ordering

* update snapshots

* move amountOutCached into inner call

* using PathKeyLib for PathKey

* fix amountOutCached

* remove console2 import

* resurface revert reason

* clean up validateRevert

* update natsppec

* remove unused

---------

Co-authored-by: Mark Toda <[email protected]>
Co-authored-by: Tina <[email protected]>
Co-authored-by: Sara Reynolds <[email protected]>
  • Loading branch information
4 people authored Dec 20, 2023
1 parent 0b46125 commit 63d64fc
Show file tree
Hide file tree
Showing 37 changed files with 1,251 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve0After5Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2771
2687
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve200By13.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23377
22933
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve200By13Plus5.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
23624
23180
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserve5After5Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2798
2738
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserveOldest.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22396
21892
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserveOldestAfter5Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22695
22191
2 changes: 1 addition & 1 deletion .forge-snapshots/FullOracleObserveZero.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2130
2070
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddInitialLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
410761
407968
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeAddLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
204683
201962
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeFirstSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
156432
153306
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
897565
1112212
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidity.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
200057
197519
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeRemoveLiquidityAndRebalance.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
386095
379147
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSecondSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114700
111940
2 changes: 1 addition & 1 deletion .forge-snapshots/FullRangeSwap.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
154641
151523
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow10Slots.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
254711
254660
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow10SlotsCardinalityGreater.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
245393
245360
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow1Slot.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
54893
54869
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleGrow1SlotCardinalityGreater.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45575
45569
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleInitialize.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
72361
72316
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6618
6492
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveCurrentTime.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2130
2070
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2130
2070
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveLast20Seconds.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
88543
86878
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveLatestEqual.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2130
2070
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveLatestTransform.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2771
2687
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveMiddle.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6807
6684
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveOldest.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6319
6193
2 changes: 1 addition & 1 deletion .forge-snapshots/OracleObserveSinceMostRecent.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3466
3382
2 changes: 1 addition & 1 deletion .forge-snapshots/TWAMMSubmitOrder.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
146158
145648
106 changes: 106 additions & 0 deletions contracts/interfaces/IQuoter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.20;

import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {PathKey} from "../libraries/PathKey.sol";

/// @title Quoter Interface
/// @notice Supports quoting the delta amounts from exact input or exact output swaps.
/// @notice For each pool also tells you the number of initialized ticks loaded and the sqrt price of the pool after the swap.
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
/// to compute the result. They are also not gas efficient and should not be called on-chain.
interface IQuoter {
error InvalidLockAcquiredSender();
error InvalidLockCaller();
error InvalidQuoteBatchParams();
error InsufficientAmountOut();
error LockFailure();
error NotSelf();
error UnexpectedRevertBytes(bytes revertData);

struct PoolDeltas {
int128 currency0Delta;
int128 currency1Delta;
}

struct QuoteExactSingleParams {
PoolKey poolKey;
bool zeroForOne;
address recipient;
uint128 exactAmount;
uint160 sqrtPriceLimitX96;
bytes hookData;
}

struct QuoteExactParams {
Currency exactCurrency;
PathKey[] path;
address recipient;
uint128 exactAmount;
}

/// @notice Returns the delta amounts for a given exact input swap of a single pool
/// @param params The params for the quote, encoded as `QuoteExactInputSingleParams`
/// poolKey The key for identifying a V4 pool
/// zeroForOne If the swap is from currency0 to currency1
/// recipient The intended recipient of the output tokens
/// 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 deltaAmounts Delta amounts resulted from the swap
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
/// @return initializedTicksLoaded The number of initialized ticks that the swap loaded
function quoteExactInputSingle(QuoteExactSingleParams calldata params)
external
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded);

/// @notice Returns the delta amounts along the swap path for a given exact input swap
/// @param params the params for the quote, encoded as 'QuoteExactInputParams'
/// currencyIn The input currency of the swap
/// path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info
/// recipient The intended recipient of the output tokens
/// exactAmount The desired input amount
/// @return deltaAmounts Delta amounts along the path resulted from the swap
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
/// @return initializedTicksLoadedList List of the initialized ticks that the swap loaded for each pool in the path
function quoteExactInput(QuoteExactParams memory params)
external
returns (
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksLoadedList
);

/// @notice Returns the delta amounts for a given exact output swap of a single pool
/// @param params The params for the quote, encoded as `QuoteExactOutputSingleParams`
/// poolKey The key for identifying a V4 pool
/// zeroForOne If the swap is from currency0 to currency1
/// recipient The intended recipient of the output tokens
/// 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 deltaAmounts Delta amounts resulted from the swap
/// @return sqrtPriceX96After The sqrt price of the pool after the swap
/// @return initializedTicksLoaded The number of initialized ticks that the swap loaded
function quoteExactOutputSingle(QuoteExactSingleParams calldata params)
external
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded);

/// @notice Returns the delta amounts along the swap path for a given exact output swap
/// @param params the params for the quote, encoded as 'QuoteExactOutputParams'
/// currencyOut The output currency of the swap
/// path The path of the swap encoded as PathKeys that contains currency, fee, tickSpacing, and hook info
/// recipient The intended recipient of the output tokens
/// exactAmount The desired output amount
/// @return deltaAmounts Delta amounts along the path resulted from the swap
/// @return sqrtPriceX96AfterList List of the sqrt price after the swap for each pool in the path
/// @return initializedTicksLoadedList List of the initialized ticks that the swap loaded for each pool in the path
function quoteExactOutput(QuoteExactParams memory params)
external
returns (
int128[] memory deltaAmounts,
uint160[] memory sqrtPriceX96AfterList,
uint32[] memory initializedTicksLoadedList
);
}
Loading

0 comments on commit 63d64fc

Please sign in to comment.