Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Revert style quoter #73

Merged
merged 84 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
6313eb5
add PoolTicksCounter library
ConjunctiveNormalForm Nov 6, 2023
664c4ff
quoter exact input single
ConjunctiveNormalForm Nov 7, 2023
d67f597
quoter test
ConjunctiveNormalForm Nov 7, 2023
ee84418
return deltas instead
ConjunctiveNormalForm Nov 10, 2023
d68e464
safe casting to correct types
ConjunctiveNormalForm Nov 11, 2023
bc381b0
QuoteExactInput skeleton
ConjunctiveNormalForm Nov 11, 2023
3bd47d9
multiple entries
ConjunctiveNormalForm Nov 11, 2023
f75b87a
break handleRevert by type
ConjunctiveNormalForm Nov 12, 2023
a69c782
quoteExactInput and unit tests
ConjunctiveNormalForm Nov 15, 2023
4f9519f
more QuoteExactInput tests
ConjunctiveNormalForm Nov 15, 2023
7823167
remove lgos
ConjunctiveNormalForm Nov 15, 2023
e2d0c22
remove commented out struct
ConjunctiveNormalForm Nov 15, 2023
6ba70f4
via-ir in ci
ConjunctiveNormalForm Nov 15, 2023
b093a78
remove unused imports/functions
ConjunctiveNormalForm Nov 16, 2023
69c2c5b
store iteration params locally instead of editing function input
ConjunctiveNormalForm Nov 16, 2023
20af595
pull out sqrtPriceLimit to its own function
ConjunctiveNormalForm Nov 16, 2023
e3f6c7e
PathKey to its own library
ConjunctiveNormalForm Nov 16, 2023
a8a0ed1
rename initializedTicksCrossed to initializedTicksLoaded
ConjunctiveNormalForm Nov 16, 2023
bd22b11
remove manual abi encoding in yul :p
ConjunctiveNormalForm Nov 16, 2023
1e0277b
fix linter warnings for Quoter
ConjunctiveNormalForm Nov 16, 2023
ca62ec2
natspec for IQuoter
ConjunctiveNormalForm Nov 16, 2023
d526f75
feat: update v4-core
marktoda Nov 16, 2023
3e3ab5d
fix: tests
marktoda Nov 16, 2023
c5b8c22
style fixes
ConjunctiveNormalForm Nov 17, 2023
1d8f14f
inheritdoc
ConjunctiveNormalForm Nov 17, 2023
55db578
ExactInSingleBatch
ConjunctiveNormalForm Nov 17, 2023
4fe142c
fix: update tests
marktoda Nov 17, 2023
15a9c8a
fix: test router was borked
marktoda Nov 17, 2023
f12b2c3
exact out
ConjunctiveNormalForm Nov 18, 2023
0dc0c0b
fix: alice comments
marktoda Nov 20, 2023
3665d41
fix ExactOutput
ConjunctiveNormalForm Nov 20, 2023
f432926
add ExactOput unit tests
ConjunctiveNormalForm Nov 21, 2023
eb3441f
add quoteExactOutputBatch
ConjunctiveNormalForm Nov 21, 2023
94f1a20
remove solhint config
ConjunctiveNormalForm Nov 22, 2023
45fd156
remove newline
ConjunctiveNormalForm Nov 22, 2023
57330b2
add QuoteExactOutput in interface
ConjunctiveNormalForm Nov 22, 2023
c841c34
refactor lockAcquired
ConjunctiveNormalForm Nov 22, 2023
a13509b
move magic numbers to constants + doc
ConjunctiveNormalForm Nov 22, 2023
dcd6471
add more natspec
ConjunctiveNormalForm Nov 22, 2023
9fb0ab4
natspec
ConjunctiveNormalForm Nov 28, 2023
3f0e6a7
named imports
ConjunctiveNormalForm Nov 28, 2023
4a8e57a
self-call branching
ConjunctiveNormalForm Dec 4, 2023
b1c2292
remove old code
ConjunctiveNormalForm Dec 4, 2023
238a23e
remove console2 import
ConjunctiveNormalForm Dec 4, 2023
5daedb0
refactor PathKeyLib
ConjunctiveNormalForm Dec 4, 2023
b6a7373
amountOutCached
ConjunctiveNormalForm Dec 4, 2023
ebac179
inherit ILockCallback
ConjunctiveNormalForm Dec 4, 2023
1912701
add base contracts and interfaces (#75)
tinaszheng Nov 28, 2023
b683fe8
Merge branch 'main' into revert-quoter
ConjunctiveNormalForm Dec 4, 2023
7d123ac
remove unused errors
ConjunctiveNormalForm Dec 4, 2023
7bfcffb
test lockAcquired reverts
ConjunctiveNormalForm Dec 5, 2023
54373b1
remove ...Batch interface
ConjunctiveNormalForm Dec 5, 2023
6ecf72b
REASON -> RESPONSE when valid
ConjunctiveNormalForm Dec 5, 2023
a40476e
complete natspec
ConjunctiveNormalForm Dec 5, 2023
7e7b880
remove SwapInfo imports
ConjunctiveNormalForm Dec 5, 2023
cb15b3e
rename to SwapParameters
ConjunctiveNormalForm Dec 6, 2023
710705b
move quoter structs into IQuoter interface
ConjunctiveNormalForm Dec 6, 2023
311ff6f
update to latest core
snreynolds Dec 11, 2023
5f4b717
use prev values
snreynolds Dec 11, 2023
ffe3b05
change twamm to use pool getters
snreynolds Dec 11, 2023
d559965
Merge branch 'main' into update-v4-core
snreynolds Dec 11, 2023
6a72276
changes after merging main
snreynolds Dec 11, 2023
57183bd
use --via-ir in cli
snreynolds Dec 11, 2023
18d68e8
fix formatting
snreynolds Dec 14, 2023
fead64a
fix FullRange/TWAMM hook
snreynolds Dec 14, 2023
7dc6b82
Merge remote-tracking branch 'origin/update-v4-core' into revert-quoter
ConjunctiveNormalForm Dec 14, 2023
588ffde
update ticks counter
ConjunctiveNormalForm Dec 15, 2023
f6a5516
update Quoter test
ConjunctiveNormalForm Dec 15, 2023
9204cea
typo
ConjunctiveNormalForm Dec 18, 2023
678919f
typo
ConjunctiveNormalForm Dec 18, 2023
b7f737f
simplify handleRevertSingle
ConjunctiveNormalForm Dec 18, 2023
67772de
merge QuoteInput/OutputSingle structs
ConjunctiveNormalForm Dec 18, 2023
fbb6d1b
combine IQuoter structs
ConjunctiveNormalForm Dec 18, 2023
ad3a966
using ... ordering
ConjunctiveNormalForm Dec 18, 2023
b098593
Merge branch 'main' into revert-quoter
ConjunctiveNormalForm Dec 19, 2023
6a7882a
update snapshots
ConjunctiveNormalForm Dec 19, 2023
6a2b71f
move amountOutCached into inner call
ConjunctiveNormalForm Dec 19, 2023
88cbff3
using PathKeyLib for PathKey
ConjunctiveNormalForm Dec 19, 2023
c43f0f1
fix amountOutCached
ConjunctiveNormalForm Dec 19, 2023
f00e616
remove console2 import
ConjunctiveNormalForm Dec 20, 2023
753d11a
resurface revert reason
ConjunctiveNormalForm Dec 20, 2023
386a957
clean up validateRevert
ConjunctiveNormalForm Dec 20, 2023
91c018e
update natsppec
ConjunctiveNormalForm Dec 20, 2023
a657d5c
remove unused
ConjunctiveNormalForm Dec 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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