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

[Chore] Update v4-core:latest #100

Merged
merged 19 commits into from
Mar 15, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
fix: flip delta signs
saucepoint committed Mar 14, 2024
commit 171ad9e9c1e48ed011aaa29eaaffe860a042be3d
40 changes: 20 additions & 20 deletions contracts/lens/Quoter.sol
Original file line number Diff line number Diff line change
@@ -175,23 +175,23 @@ contract Quoter is IQuoter, ILockCallback {
for (uint256 i = 0; i < pathLength; i++) {
(PoolKey memory poolKey, bool zeroForOne) =
params.path[i].getPoolAndSwapDirection(i == 0 ? params.exactCurrency : cache.prevCurrency);
(, cache.tickBefore,) = manager.getSlot0(poolKey.toId());
(, cache.tickBefore,,) = manager.getSlot0(poolKey.toId());

(cache.curDeltas, cache.sqrtPriceX96After, cache.tickAfter) = _swap(
poolKey,
zeroForOne,
int256(int128(i == 0 ? params.exactAmount : cache.prevAmount)),
-int256(int128(i == 0 ? params.exactAmount : cache.prevAmount)),
0,
params.path[i].hookData
);

(cache.deltaIn, cache.deltaOut) = zeroForOne
? (cache.curDeltas.amount0(), cache.curDeltas.amount1())
: (cache.curDeltas.amount1(), cache.curDeltas.amount0());
? (-cache.curDeltas.amount0(), -cache.curDeltas.amount1())
: (-cache.curDeltas.amount1(), -cache.curDeltas.amount0());
result.deltaAmounts[i] += cache.deltaIn;
result.deltaAmounts[i + 1] += cache.deltaOut;

cache.prevAmount = zeroForOne ? uint128(-cache.curDeltas.amount1()) : uint128(-cache.curDeltas.amount0());
cache.prevAmount = zeroForOne ? uint128(cache.curDeltas.amount1()) : uint128(cache.curDeltas.amount0());
cache.prevCurrency = params.path[i].intermediateCurrency;
result.sqrtPriceX96AfterList[i] = cache.sqrtPriceX96After;
result.initializedTicksLoadedList[i] =
@@ -206,20 +206,20 @@ contract Quoter is IQuoter, ILockCallback {

/// @dev quote an ExactInput swap on a pool, then revert with the result
function _quoteExactInputSingle(QuoteExactSingleParams memory params) public selfOnly returns (bytes memory) {
(, int24 tickBefore,) = manager.getSlot0(params.poolKey.toId());
(, int24 tickBefore,,) = manager.getSlot0(params.poolKey.toId());

(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap(
params.poolKey,
params.zeroForOne,
int256(int128(params.exactAmount)),
-int256(int128(params.exactAmount)),
params.sqrtPriceLimitX96,
params.hookData
);

int128[] memory deltaAmounts = new int128[](2);

deltaAmounts[0] = deltas.amount0();
deltaAmounts[1] = deltas.amount1();
deltaAmounts[0] = -deltas.amount0();
deltaAmounts[1] = -deltas.amount1();

uint32 initializedTicksLoaded =
PoolTicksCounter.countInitializedTicksLoaded(manager, params.poolKey, tickBefore, tickAfter);
@@ -249,20 +249,20 @@ contract Quoter is IQuoter, ILockCallback {
params.path[i - 1], i == pathLength ? params.exactCurrency : cache.prevCurrency
);

(, cache.tickBefore,) = manager.getSlot0(poolKey.toId());
(, cache.tickBefore,,) = manager.getSlot0(poolKey.toId());

(cache.curDeltas, cache.sqrtPriceX96After, cache.tickAfter) =
_swap(poolKey, !oneForZero, -int256(uint256(curAmountOut)), 0, params.path[i - 1].hookData);
_swap(poolKey, !oneForZero, int256(uint256(curAmountOut)), 0, params.path[i - 1].hookData);

// always clear because sqrtPriceLimitX96 is set to 0 always
delete amountOutCached;
(cache.deltaIn, cache.deltaOut) = !oneForZero
? (cache.curDeltas.amount0(), cache.curDeltas.amount1())
: (cache.curDeltas.amount1(), cache.curDeltas.amount0());
? (-cache.curDeltas.amount0(), -cache.curDeltas.amount1())
: (-cache.curDeltas.amount1(), -cache.curDeltas.amount0());
result.deltaAmounts[i - 1] += cache.deltaIn;
result.deltaAmounts[i] += cache.deltaOut;

cache.prevAmount = !oneForZero ? uint128(cache.curDeltas.amount0()) : uint128(cache.curDeltas.amount1());
cache.prevAmount = !oneForZero ? uint128(-cache.curDeltas.amount0()) : uint128(-cache.curDeltas.amount1());
cache.prevCurrency = params.path[i - 1].intermediateCurrency;
result.sqrtPriceX96AfterList[i - 1] = cache.sqrtPriceX96After;
result.initializedTicksLoadedList[i - 1] =
@@ -280,20 +280,20 @@ contract Quoter is IQuoter, ILockCallback {
// 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());
(, int24 tickBefore,,) = manager.getSlot0(params.poolKey.toId());
(BalanceDelta deltas, uint160 sqrtPriceX96After, int24 tickAfter) = _swap(
params.poolKey,
params.zeroForOne,
-int256(uint256(params.exactAmount)),
int256(uint256(params.exactAmount)),
params.sqrtPriceLimitX96,
params.hookData
);

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

deltaAmounts[0] = deltas.amount0();
deltaAmounts[1] = deltas.amount1();
deltaAmounts[0] = -deltas.amount0();
deltaAmounts[1] = -deltas.amount1();

uint32 initializedTicksLoaded =
PoolTicksCounter.countInitializedTicksLoaded(manager, params.poolKey, tickBefore, tickAfter);
@@ -322,10 +322,10 @@ contract Quoter is IQuoter, ILockCallback {
hookData
);
// only exactOut case
if (amountOutCached != 0 && amountOutCached != uint128(zeroForOne ? -deltas.amount1() : -deltas.amount0())) {
if (amountOutCached != 0 && amountOutCached != uint128(zeroForOne ? deltas.amount1() : deltas.amount0())) {
revert InsufficientAmountOut();
}
(sqrtPriceX96After, tickAfter,) = manager.getSlot0(poolKey.toId());
(sqrtPriceX96After, tickAfter,,) = manager.getSlot0(poolKey.toId());
}

/// @dev return either the sqrtPriceLimit from user input, or the max/min value possible depending on trade direction
2 changes: 1 addition & 1 deletion test/Quoter.t.sol
Original file line number Diff line number Diff line change
@@ -587,7 +587,7 @@ contract QuoterTest is Test, Deployers {

function setupPoolWithZeroTickInitialized(PoolKey memory poolKey) internal {
PoolId poolId = poolKey.toId();
(uint160 sqrtPriceX96,,) = manager.getSlot0(poolId);
(uint160 sqrtPriceX96,,,) = manager.getSlot0(poolId);
if (sqrtPriceX96 == 0) {
manager.initialize(poolKey, SQRT_RATIO_1_1, ZERO_BYTES);
}