Skip to content

Commit

Permalink
move amountOutCached into inner call
Browse files Browse the repository at this point in the history
  • Loading branch information
ConjunctiveNormalForm committed Dec 19, 2023
1 parent 6a7882a commit 6a2b71f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions contracts/interfaces/IQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IQuoter {
error InvalidLockAcquiredSender();
error InvalidLockCaller();
error InvalidQuoteBatchParams();
error InsufficientAmountOut();
error LockFailure();
error NotSelf();
error UnexpectedRevertBytes();
Expand Down
11 changes: 9 additions & 2 deletions contracts/lens/Quoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ contract Quoter is IQuoter, ILockCallback {
override
returns (int128[] memory deltaAmounts, uint160 sqrtPriceX96After, uint32 initializedTicksLoaded)
{
if (params.sqrtPriceLimitX96 == 0) amountOutCached = params.exactAmount;

try manager.lock(address(this), abi.encodeWithSelector(this._quoteExactOutputSingle.selector, params)) {}
catch (bytes memory reason) {
if (params.sqrtPriceLimitX96 == 0) delete amountOutCached;
Expand Down Expand Up @@ -275,6 +273,9 @@ contract Quoter is IQuoter, ILockCallback {

/// @dev quote an ExactOutput swap on a pool, then revert with the result
function _quoteExactOutputSingle(QuoteExactSingleParams memory params) public selfOnly returns (bytes memory) {
// if no price limit has been specified, cache the output amount for comparison in the swap callback
if (params.sqrtPriceLimitX96 == 0) amountOutCached = params.exactAmount;

(, int24 tickBefore,) = manager.getSlot0(params.poolKey.toId());
(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap(
params.poolKey,
Expand All @@ -283,6 +284,8 @@ contract Quoter is IQuoter, ILockCallback {
params.sqrtPriceLimitX96,
params.hookData
);

if (amountOutCached != 0) delete amountOutCached;
int128[] memory deltaAmounts = new int128[](2);

deltaAmounts[0] = deltas.amount0();
Expand Down Expand Up @@ -313,6 +316,10 @@ contract Quoter is IQuoter, ILockCallback {
}),
hookData
);
// only exactOut case
if (amountOutCached != 0 && amountOutCached != uint256(int256(-deltas.amount1()))) {
revert InsufficientAmountOut();
}
(sqrtPriceX96After, tickAfter,) = manager.getSlot0(poolKey.toId());
}

Expand Down

0 comments on commit 6a2b71f

Please sign in to comment.