v3-core
v3-core copied to clipboard
Only part of the order is being executed using V3 Swap Router 1
I have been interacting with the ETH/USDC 5bp liquidity pool via the original V3 Swap router (Not V2). I've noticed that sometimes only part of my order is being filled.
For example, I recieve confirmation on my side that I have sent an order for X amount of ETH in exchange for Y USDC. When I check etherscan and my wallet, I notice I have only recieved 0.7X ETH in exchange for 0.7Y USDC.
To my understanding, there is nothing in the pool.sol contract that suggests this is possible? As my order is being processed, the pool should lock. See line 607 of v3-core/UniswapV3Pool.sol
> require(slot0Start.unlocked, 'LOK'); require( zeroForOne ? sqrtPriceLimitX96 < slot0Start.sqrtPriceX96 && sqrtPriceLimitX96 > TickMath.MIN_SQRT_RATIO : sqrtPriceLimitX96 > slot0Start.sqrtPriceX96 && sqrtPriceLimitX96 < TickMath.MAX_SQRT_RATIO, 'SPL' );
I do not recieve an 'SPL error', so theoretically the size I'm suggesting (X ETH) is within my allowed slippage bounds, and the full amount should be processed by the contract.
This has happened on several occasions where only 70-90% of the order Im sending is being processed. There are no error codes, so the transaction seems successful from all parties.
Please could someone look into this? Is it a problem with the original swap router I am using?
Thanks
Basically whatever sqrtPriceLimitX96
you pass, if the price moves beyond that during the swap, it stops there, so it's sort of partial swap. While the SPL require statement just checks if sqrtPriceLimitX96 makes sense. If you want to not have partial swaps, you can simply look at amountSpecified
and the return values of swap function and revert when partial swap (it should be equal to one of them based on swap dir and exactIn, if it's not eq then the swap was partial).
The SwapRouter contract allows to specify a min output amount (or max in), you can use that to ensure your swap was not partial (link).
Hi Zemse,
Thanks for the fast response. Apologies I should have clarified, I specify the minOutput amount as X Eth in this context. If the price required exceeds my maxInputAmount or SPL it should revert. Somehow I am only swapping for a fraction [0,1] of my minOutputAmount, with no error code.
I can see from my logs im submitting transactions with the required ETH amount, so I'm struggling to see a reason it shouldnt revert
Hey @wdqco - thanks for asking this question! Some more details on how exactly you constructed the transaction would be helpful. If you're using SwapRouter exactInput
with params.amountOutMinimum
set, it should revert if the swap returns less than that amount. Maybe if you could share a sanitized input data hex dump, that would help