Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
36 changes: 8 additions & 28 deletions src/MixedQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ contract MixedQuoter is IMixedQuoter, IPancakeV3SwapCallback, Multicall {
*/

/// @inheritdoc IPancakeV3SwapCallback
function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory data)
external
view
override
{
function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory data) external view override {
require(amount0Delta > 0 || amount1Delta > 0); // swaps entirely within 0-liquidity regions are not supported
(address tokenIn, address tokenOut, uint24 fee) = abi.decode(data, (address, address, uint24));
V3SmartRouterHelper.verifyCallback(factoryV3, tokenIn, tokenOut, fee);
Expand Down Expand Up @@ -144,7 +140,8 @@ contract MixedQuoter is IMixedQuoter, IPancakeV3SwapCallback, Multicall {
? (zeroForOne ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1)
: params.sqrtPriceLimitX96,
abi.encode(params.tokenIn, params.tokenOut, params.fee)
) {} catch (bytes memory reason) {
) {}
catch (bytes memory reason) {
gasEstimate = gasBefore - gasleft();
return handleV3Revert(reason, pool, gasEstimate);
}
Expand Down Expand Up @@ -273,11 +270,7 @@ contract MixedQuoter is IMixedQuoter, IPancakeV3SwapCallback, Multicall {
if (!withContext) {
(amountIn,,, gasEstimateForCurAction) = quoteExactInputSingleV3(
QuoteExactInputSingleV3Params({
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn,
fee: fee,
sqrtPriceLimitX96: 0
tokenIn: tokenIn, tokenOut: tokenOut, amountIn: amountIn, fee: fee, sqrtPriceLimitX96: 0
})
);
} else {
Expand All @@ -292,11 +285,7 @@ contract MixedQuoter is IMixedQuoter, IPancakeV3SwapCallback, Multicall {
amountIn += accAmountIn;
(swapAmountOut,,, gasEstimateForCurAction) = quoteExactInputSingleV3(
QuoteExactInputSingleV3Params({
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn,
fee: fee,
sqrtPriceLimitX96: 0
tokenIn: tokenIn, tokenOut: tokenOut, amountIn: amountIn, fee: fee, sqrtPriceLimitX96: 0
})
);
MixedQuoterRecorder.setPoolSwapTokenAccumulation(poolHash, amountIn, swapAmountOut, zeroForOne);
Expand Down Expand Up @@ -383,10 +372,7 @@ contract MixedQuoter is IMixedQuoter, IPancakeV3SwapCallback, Multicall {
if (!withContext) {
(amountIn, gasEstimateForCurAction) = quoteExactInputSingleStable(
QuoteExactInputSingleStableParams({
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn,
flag: 2
tokenIn: tokenIn, tokenOut: tokenOut, amountIn: amountIn, flag: 2
})
);
} else {
Expand All @@ -400,10 +386,7 @@ contract MixedQuoter is IMixedQuoter, IPancakeV3SwapCallback, Multicall {
amountIn += accAmountIn;
(swapAmountOut, gasEstimateForCurAction) = quoteExactInputSingleStable(
QuoteExactInputSingleStableParams({
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn,
flag: 2
tokenIn: tokenIn, tokenOut: tokenOut, amountIn: amountIn, flag: 2
})
);
MixedQuoterRecorder.setPoolSwapTokenAccumulation(poolHash, amountIn, swapAmountOut, zeroForOne);
Expand All @@ -415,10 +398,7 @@ contract MixedQuoter is IMixedQuoter, IPancakeV3SwapCallback, Multicall {
// params[actionIndex] is zero bytes
(amountIn, gasEstimateForCurAction) = quoteExactInputSingleStable(
QuoteExactInputSingleStableParams({
tokenIn: tokenIn,
tokenOut: tokenOut,
amountIn: amountIn,
flag: 3
tokenIn: tokenIn, tokenOut: tokenOut, amountIn: amountIn, flag: 3
})
);
} else {
Expand Down
4 changes: 1 addition & 3 deletions src/interfaces/IERC721Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@ interface IERC721Permit is IERC721 {
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
payable;
function permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable;
}
4 changes: 1 addition & 3 deletions src/interfaces/ISelfPermit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ interface ISelfPermit {
/// @param v Must produce valid secp256k1 signature from the holder along with `r` and `s`
/// @param r Must produce valid secp256k1 signature from the holder along with `v` and `s`
/// @param s Must produce valid secp256k1 signature from the holder along with `r` and `v`
function selfPermit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external
payable;
function selfPermit(address token, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external payable;

/// @notice Permits this contract to spend a given token from `msg.sender`
/// @dev The `owner` is always msg.sender and the `spender` is always address(this).
Expand Down
6 changes: 1 addition & 5 deletions src/libraries/CalldataDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,7 @@ library CalldataDecoder {
}

/// @dev equivalent to: abi.decode(params, (Currency, uint256)) in calldata
function decodeCurrencyAndUint256(bytes calldata params)
internal
pure
returns (Currency currency, uint256 amount)
{
function decodeCurrencyAndUint256(bytes calldata params) internal pure returns (Currency currency, uint256 amount) {
assembly ("memory-safe") {
if lt(params.length, 0x40) {
mstore(0, SLICE_ERROR_SELECTOR)
Expand Down
1 change: 0 additions & 1 deletion src/libraries/external/V3SmartRouterHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ library V3SmartRouterHelper {
/**
* Stable *************************************************
*/

// get the pool info in stable swap
function getStableInfo(address stableSwapFactory, address input, address output, uint256 flag)
internal
Expand Down
8 changes: 2 additions & 6 deletions src/pool-bin/interfaces/IBinQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ interface IBinQuoter is IQuoter {
/// exactAmount The desired input amount
/// @return amountOut The output quote for the exactIn swap
/// @return gasEstimate Estimated gas units used for the swap
function quoteExactInput(QuoteExactParams memory params)
external
returns (uint256 amountOut, uint256 gasEstimate);
function quoteExactInput(QuoteExactParams memory params) external returns (uint256 amountOut, uint256 gasEstimate);

/// @notice Returns the delta amounts for a given exact output swap of a single pool
/// @param params The params for the quote, encoded as `QuoteExactSingleParams`
Expand All @@ -63,7 +61,5 @@ interface IBinQuoter is IQuoter {
/// exactAmount The desired output amount
/// @return amountIn The input quote for the exactOut swap
/// @return gasEstimate Estimated gas units used for the swap
function quoteExactOutput(QuoteExactParams memory params)
external
returns (uint256 amountIn, uint256 gasEstimate);
function quoteExactOutput(QuoteExactParams memory params) external returns (uint256 amountIn, uint256 gasEstimate);
}
11 changes: 2 additions & 9 deletions src/pool-cl/CLPositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,7 @@ contract CLPositionManager is
(liquidityDelta, feesAccrued) = clPoolManager.modifyLiquidity(
poolKey,
ICLPoolManager.ModifyLiquidityParams({
tickLower: info.tickLower(),
tickUpper: info.tickUpper(),
liquidityDelta: liquidityChange,
salt: salt
tickLower: info.tickLower(), tickUpper: info.tickUpper(), liquidityDelta: liquidityChange, salt: salt
}),
hookData
);
Expand Down Expand Up @@ -494,11 +491,7 @@ contract CLPositionManager is
}

/// @inheritdoc ICLPositionManager
function getPoolAndPositionInfo(uint256 tokenId)
public
view
returns (PoolKey memory poolKey, CLPositionInfo info)
{
function getPoolAndPositionInfo(uint256 tokenId) public view returns (PoolKey memory poolKey, CLPositionInfo info) {
info = positionInfo[tokenId];
poolKey = poolKeys[info.poolId()];
}
Expand Down
18 changes: 9 additions & 9 deletions src/pool-cl/CLRouterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ abstract contract CLRouterBase is ICLRouterBase, DeltaResolver {
_getFullCredit(params.zeroForOne ? params.poolKey.currency0 : params.poolKey.currency1).toUint128();
}
uint128 amountOut = _swapExactPrivate(
params.poolKey, params.zeroForOne, -int256(uint256(amountIn)), params.hookData
).toUint128();
params.poolKey, params.zeroForOne, -int256(uint256(amountIn)), params.hookData
).toUint128();
if (amountOut < params.amountOutMinimum) {
revert IInfinityRouter.TooLittleReceived(params.amountOutMinimum, amountOut);
}
Expand Down Expand Up @@ -70,9 +70,10 @@ abstract contract CLRouterBase is ICLRouterBase, DeltaResolver {
amountOut =
_getFullDebt(params.zeroForOne ? params.poolKey.currency1 : params.poolKey.currency0).toUint128();
}
uint128 amountIn = (
-_swapExactPrivate(params.poolKey, params.zeroForOne, int256(uint256(amountOut)), params.hookData)
).toUint128();
uint128 amountIn = (-_swapExactPrivate(
params.poolKey, params.zeroForOne, int256(uint256(amountOut)), params.hookData
))
.toUint128();
if (amountIn > params.amountInMaximum) {
revert IInfinityRouter.TooMuchRequested(params.amountInMaximum, amountIn);
}
Expand All @@ -95,11 +96,10 @@ abstract contract CLRouterBase is ICLRouterBase, DeltaResolver {
pathKey = params.path[i - 1];
(PoolKey memory poolKey, bool oneForZero) = pathKey.getPoolAndSwapDirection(currencyOut);
// The output delta will always be negative, except for when interacting with certain hook pools
amountIn = (
uint256(
amountIn = (uint256(
-int256(_swapExactPrivate(poolKey, !oneForZero, int256(uint256(amountOut)), pathKey.hookData))
)
).toUint128();
))
.toUint128();

amountOut = amountIn;
currencyOut = pathKey.intermediateCurrency;
Expand Down
5 changes: 3 additions & 2 deletions src/pool-cl/base/CLNotifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ abstract contract CLNotifier is ICLNotifier {
// remove the subscriber
delete subscriber[tokenId];

bool success =
_call(_subscriber, abi.encodeCall(ICLSubscriber.notifyBurn, (tokenId, owner, info, liquidity, feesAccrued)));
bool success = _call(
_subscriber, abi.encodeCall(ICLSubscriber.notifyBurn, (tokenId, owner, info, liquidity, feesAccrued))
);

if (!success) {
_subscriber.bubbleUpAndRevertWith(ICLSubscriber.notifyBurn.selector, BurnNotificationReverted.selector);
Expand Down
5 changes: 3 additions & 2 deletions src/pool-cl/base/ERC721Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ abstract contract ERC721Permit is ERC721, IERC721Permit, EIP712, UnorderedNonce
}

function _isApprovedOrOwner(address spender, uint256 tokenId) internal view returns (bool) {
return spender == ownerOf(tokenId) || getApproved[tokenId] == spender
|| isApprovedForAll[ownerOf(tokenId)][spender];
return
spender == ownerOf(tokenId) || getApproved[tokenId] == spender
|| isApprovedForAll[ownerOf(tokenId)][spender];
}
}
8 changes: 2 additions & 6 deletions src/pool-cl/interfaces/ICLQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ interface ICLQuoter is IQuoter {
/// exactAmount The desired input amount
/// @return amountOut The output quote for the exactIn swap
/// @return gasEstimate Estimated gas units used for the swap
function quoteExactInput(QuoteExactParams memory params)
external
returns (uint256 amountOut, uint256 gasEstimate);
function quoteExactInput(QuoteExactParams memory params) external returns (uint256 amountOut, uint256 gasEstimate);

/// @notice Returns the delta amounts for a given exact output swap of a single pool
/// @param params The params for the quote, encoded as `QuoteExactSingleParams`
Expand All @@ -63,7 +61,5 @@ interface ICLQuoter is IQuoter {
/// exactAmount The desired output amount
/// @return amountIn The input quote for the exactOut swap
/// @return gasEstimate Estimated gas units used for the swap
function quoteExactOutput(QuoteExactParams memory params)
external
returns (uint256 amountIn, uint256 gasEstimate);
function quoteExactOutput(QuoteExactParams memory params) external returns (uint256 amountIn, uint256 gasEstimate);
}
10 changes: 2 additions & 8 deletions src/pool-cl/lens/CLQuoter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ contract CLQuoter is ICLQuoter, BaseInfinityQuoter {
}

/// @inheritdoc ICLQuoter
function quoteExactInput(QuoteExactParams memory params)
external
returns (uint256 amountOut, uint256 gasEstimate)
{
function quoteExactInput(QuoteExactParams memory params) external returns (uint256 amountOut, uint256 gasEstimate) {
uint256 gasBefore = gasleft();
try vault.lock(abi.encodeCall(this._quoteExactInput, (params))) {}
catch (bytes memory reason) {
Expand All @@ -80,10 +77,7 @@ contract CLQuoter is ICLQuoter, BaseInfinityQuoter {
}

/// @inheritdoc ICLQuoter
function quoteExactOutput(QuoteExactParams memory params)
external
returns (uint256 amountIn, uint256 gasEstimate)
{
function quoteExactOutput(QuoteExactParams memory params) external returns (uint256 amountIn, uint256 gasEstimate) {
uint256 gasBefore = gasleft();
try vault.lock(abi.encodeCall(this._quoteExactOutput, (params))) {}
catch (bytes memory reason) {
Expand Down
4 changes: 1 addition & 3 deletions src/pool-cl/lens/TickLens.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ contract TickLens is ITickLens {
int24 populatedTick = ((int24(tickBitmapIndex) << 8) + int24(int256(i))) * tickSpacing;
Tick.Info memory tickInfo = poolManager.getPoolTickInfo(id, populatedTick);
populatedTicks[--numberOfPopulatedTicks] = PopulatedTick({
tick: populatedTick,
liquidityNet: tickInfo.liquidityNet,
liquidityGross: tickInfo.liquidityGross
tick: populatedTick, liquidityNet: tickInfo.liquidityNet, liquidityGross: tickInfo.liquidityGross
});
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/pool-cl/libraries/CLPositionInfoLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ library CLPositionInfoLibrary {
{
bytes25 _poolId = bytes25(PoolId.unwrap(_poolKey.toId()));
assembly {
info :=
or(
or(and(MASK_UPPER_200_BITS, _poolId), shl(TICK_UPPER_OFFSET, and(MASK_24_BITS, _tickUpper))),
shl(TICK_LOWER_OFFSET, and(MASK_24_BITS, _tickLower))
)
info := or(
or(and(MASK_UPPER_200_BITS, _poolId), shl(TICK_UPPER_OFFSET, and(MASK_24_BITS, _tickUpper))),
shl(TICK_LOWER_OFFSET, and(MASK_24_BITS, _tickLower))
)
}
}
}
8 changes: 6 additions & 2 deletions src/pool-cl/libraries/LiquidityAmounts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ library LiquidityAmounts {
uint256 amount0,
uint256 amount1
) internal pure returns (uint128 liquidity) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioAX96 > sqrtRatioBX96) {
(sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
}

if (sqrtRatioX96 <= sqrtRatioAX96) {
liquidity = getLiquidityForAmount0(sqrtRatioAX96, sqrtRatioBX96, amount0);
Expand Down Expand Up @@ -116,7 +118,9 @@ library LiquidityAmounts {
uint160 sqrtRatioBX96,
uint128 liquidity
) internal pure returns (uint256 amount0, uint256 amount1) {
if (sqrtRatioAX96 > sqrtRatioBX96) (sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
if (sqrtRatioAX96 > sqrtRatioBX96) {
(sqrtRatioAX96, sqrtRatioBX96) = (sqrtRatioBX96, sqrtRatioAX96);
}

if (sqrtRatioX96 <= sqrtRatioAX96) {
amount0 = getAmount0ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity);
Expand Down
25 changes: 5 additions & 20 deletions test/MixedQuoter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,7 @@ contract MixedQuoterTest is

(uint256 _amountOut, uint256 _gasEstimate) = clQuoter.quoteExactInputSingle(
IQuoter.QuoteExactSingleParams({
poolKey: poolKey,
zeroForOne: true,
exactAmount: 1 ether,
hookData: ZERO_BYTES
poolKey: poolKey, zeroForOne: true, exactAmount: 1 ether, hookData: ZERO_BYTES
})
);
assertEq(_amountOut, amountOut);
Expand Down Expand Up @@ -1036,10 +1033,7 @@ contract MixedQuoterTest is

(uint256 _amountOut, uint256 _gasEstimate) = clQuoter.quoteExactInputSingle(
IQuoter.QuoteExactSingleParams({
poolKey: poolKey,
zeroForOne: false,
exactAmount: 1 ether,
hookData: ZERO_BYTES
poolKey: poolKey, zeroForOne: false, exactAmount: 1 ether, hookData: ZERO_BYTES
})
);
assertEq(_amountOut, amountOut);
Expand Down Expand Up @@ -1072,10 +1066,7 @@ contract MixedQuoterTest is

(uint256 _amountOut, uint256 _gasEstimate) = clQuoter.quoteExactInputSingle(
IQuoter.QuoteExactSingleParams({
poolKey: poolKeyWithWETH,
zeroForOne: true,
exactAmount: 1 ether,
hookData: ZERO_BYTES
poolKey: poolKeyWithWETH, zeroForOne: true, exactAmount: 1 ether, hookData: ZERO_BYTES
})
);
assertEq(_amountOut, amountOut);
Expand All @@ -1102,10 +1093,7 @@ contract MixedQuoterTest is

(uint256 _amountOut, uint256 _gasEstimate) = binQuoter.quoteExactInputSingle(
IQuoter.QuoteExactSingleParams({
poolKey: binPoolKey,
zeroForOne: true,
exactAmount: 1 ether,
hookData: ZERO_BYTES
poolKey: binPoolKey, zeroForOne: true, exactAmount: 1 ether, hookData: ZERO_BYTES
})
);
assertEq(_amountOut, amountOut);
Expand Down Expand Up @@ -1285,10 +1273,7 @@ contract MixedQuoterTest is

(uint256 _amountOut, uint256 _gasEstimate) = binQuoter.quoteExactInputSingle(
IQuoter.QuoteExactSingleParams({
poolKey: binPoolKey,
zeroForOne: false,
exactAmount: 1 ether,
hookData: ZERO_BYTES
poolKey: binPoolKey, zeroForOne: false, exactAmount: 1 ether, hookData: ZERO_BYTES
})
);
assertEq(_amountOut, amountOut);
Expand Down
5 changes: 3 additions & 2 deletions test/Multicall.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ contract MulticallTest is Test {

function test_multicall_firstRevert() public {
bytes[] memory calls = new bytes[](2);
calls[0] =
abi.encodeWithSelector(MockMulticall(multicall).functionThatRevertsWithString.selector, "First call failed");
calls[0] = abi.encodeWithSelector(
MockMulticall(multicall).functionThatRevertsWithString.selector, "First call failed"
);
calls[1] = abi.encodeWithSelector(MockMulticall(multicall).functionThatReturnsTuple.selector, 1, 2);

vm.expectRevert("First call failed");
Expand Down
Loading