-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove counting tick crossing * add gas estimate return * refactor into revert library * remove cache struct * cache path key * Change return types * remove sqrt price after logic * Revert with custom error * comments * typo * factor base contract * move cache into transient storage * Remove cache entirely * PR comments * Refactor QuoterRevert library * remove sqrtPriceLimit
- Loading branch information
Showing
20 changed files
with
310 additions
and
640 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_exactInputSingle_oneForZero_multiplePositions.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
159043 | ||
143930 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_exactInputSingle_zeroForOne_multiplePositions.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
166396 | ||
149382 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
93637 | ||
78203 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
100303 | ||
82626 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_quoteExactInput_oneHop_1TickLoaded.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
141321 | ||
120491 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_quoteExactInput_oneHop_initializedAfter.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
164528 | ||
145414 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_quoteExactInput_oneHop_startingInitialized.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
98641 | ||
79437 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
234806 | ||
201179 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_quoteExactOutput_oneHop_1TickLoaded.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
161346 | ||
119782 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_quoteExactOutput_oneHop_2TicksLoaded.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
191453 | ||
149919 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_quoteExactOutput_oneHop_initializedAfter.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
161661 | ||
119850 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/Quoter_quoteExactOutput_oneHop_startingInitialized.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
136430 | ||
96549 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
275720 | ||
200630 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
|
||
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol"; | ||
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol"; | ||
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol"; | ||
import {QuoterRevert} from "../libraries/QuoterRevert.sol"; | ||
import {SafeCallback} from "../base/SafeCallback.sol"; | ||
import {PoolId, PoolIdLibrary} from "@uniswap/v4-core/src/types/PoolId.sol"; | ||
import {TickMath} from "@uniswap/v4-core/src/libraries/TickMath.sol"; | ||
|
||
abstract contract BaseV4Quoter is SafeCallback { | ||
using QuoterRevert for *; | ||
using PoolIdLibrary for PoolId; | ||
|
||
error NotEnoughLiquidity(PoolId poolId); | ||
error NotSelf(); | ||
error UnexpectedCallSuccess(); | ||
|
||
constructor(IPoolManager _poolManager) SafeCallback(_poolManager) {} | ||
|
||
/// @dev Only this address may call this function. Used to mimic internal functions, using an | ||
/// external call to catch and parse revert reasons | ||
modifier selfOnly() { | ||
if (msg.sender != address(this)) revert NotSelf(); | ||
_; | ||
} | ||
|
||
function _unlockCallback(bytes calldata data) internal override returns (bytes memory) { | ||
(bool success, bytes memory returnData) = address(this).call(data); | ||
// Every quote path gathers a quote, and then reverts either with QuoteSwap(quoteAmount) or alternative error | ||
if (success) revert UnexpectedCallSuccess(); | ||
// Bubble the revert string, whether a valid quote or an alternative error | ||
returnData.bubbleReason(); | ||
} | ||
|
||
/// @dev Execute a swap and return the balance delta | ||
/// @notice if amountSpecified < 0, the swap is exactInput, otherwise exactOutput | ||
function _swap(PoolKey memory poolKey, bool zeroForOne, int256 amountSpecified, bytes calldata hookData) | ||
internal | ||
returns (BalanceDelta swapDelta) | ||
{ | ||
swapDelta = poolManager.swap( | ||
poolKey, | ||
IPoolManager.SwapParams({ | ||
zeroForOne: zeroForOne, | ||
amountSpecified: amountSpecified, | ||
sqrtPriceLimitX96: zeroForOne ? TickMath.MIN_SQRT_PRICE + 1 : TickMath.MAX_SQRT_PRICE - 1 | ||
}), | ||
hookData | ||
); | ||
|
||
// Check that the pool was not illiquid. | ||
int128 amountSpecifiedActual = (zeroForOne == (amountSpecified < 0)) ? swapDelta.amount0() : swapDelta.amount1(); | ||
if (amountSpecifiedActual != amountSpecified) { | ||
revert NotEnoughLiquidity(poolKey.toId()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.