-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge branch 'main' into position-descriptor
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {ParseBytes} from "@uniswap/v4-core/src/libraries/ParseBytes.sol"; | ||
|
||
library QuoterRevert { | ||
using QuoterRevert for bytes; | ||
using ParseBytes for bytes; | ||
|
||
/// @notice error thrown when invalid revert bytes are thrown by the quote | ||
error UnexpectedRevertBytes(bytes revertData); | ||
|
||
/// @notice error thrown containing the quote as the data, to be caught and parsed later | ||
error QuoteSwap(uint256 amount); | ||
|
||
/// @notice reverts, where the revert data is the provided bytes | ||
/// @dev called when quoting, to record the quote amount in an error | ||
/// @dev QuoteSwap is used to differentiate this error from other errors thrown when simulating the swap | ||
function revertQuote(uint256 quoteAmount) internal pure { | ||
revert QuoteSwap(quoteAmount); | ||
} | ||
|
||
/// @notice reverts using the revertData as the reason | ||
/// @dev to bubble up both the valid QuoteSwap(amount) error, or an alternative error thrown during simulation | ||
function bubbleReason(bytes memory revertData) internal pure { | ||
// mload(revertData): the length of the revert data | ||
// add(revertData, 0x20): a pointer to the start of the revert data | ||
assembly ("memory-safe") { | ||
revert(add(revertData, 0x20), mload(revertData)) | ||
} | ||
} | ||
|
||
/// @notice validates whether a revert reason is a valid swap quote or not | ||
/// if valid, it decodes the quote to return. Otherwise it reverts. | ||
function parseQuoteAmount(bytes memory reason) internal pure returns (uint256 quoteAmount) { | ||
// If the error doesnt start with QuoteSwap, we know this isnt a valid quote to parse | ||
// Instead it is another revert that was triggered somewhere in the simulation | ||
if (reason.parseSelector() != QuoteSwap.selector) { | ||
revert UnexpectedRevertBytes(reason); | ||
} | ||
|
||
// reason -> reason+0x1f is the length of the reason string | ||
// reason+0x20 -> reason+0x23 is the selector of QuoteSwap | ||
// reason+0x24 -> reason+0x43 is the quoteAmount | ||
assembly ("memory-safe") { | ||
quoteAmount := mload(add(reason, 0x24)) | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.