fix(v3-sdk): refund unspent ETH on native exact-input swaps - #698
Open
gomesalexandre wants to merge 2 commits into
Open
fix(v3-sdk): refund unspent ETH on native exact-input swaps#698gomesalexandre wants to merge 2 commits into
gomesalexandre wants to merge 2 commits into
Conversation
`SwapRouter.swapCallParameters` only appended a `refundETH` call for exact-output trades. But a native-input exact-input swap sends `msg.value` equal to the exact input amount, and `exactInputSingle` can stop early against `sqrtPriceLimitX96` and consume less than that, so the remainder gets stuck in the router until some later exact-output swap happens to sweep it. Refund whenever the input currency is native, matching the periphery's own "always sweep" pattern. `refundETH` is a no-op when the router holds no ETH, so exact-input swaps without a price limit are unaffected beyond a negligible extra call. closes Uniswap#216
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #216
what
SwapRouter.swapCallParameters(v3-sdk) only appends arefundETHsweep for exact-output trades. A native-input exact-input swap can leave ETH stuck in the router.why
For a native-input trade
msg.valueis set to the input amount. For exact-input that is the exactamountIn, andexactInputSingleis encoded withsqrtPriceLimitX96: options.sqrtPriceLimitX96 ?? 0. If a caller sets a price limit and the swap stops early against it, less thanamountInis consumed and the remainder sits in the router until some later exact-output swap happens to sweep it.how
Refund whenever the input currency is native, not only for exact-output:
refundETHis a no-op when the router holds no ETH, so exact-input swaps without a price limit are unaffected beyond a negligible extra call. This matches the periphery's own always-sweep pattern.tests
sqrtPriceLimitX96set now producesmulticall(exactInputSingle, refundETH)(refundETH selector0x12210e8a)--max-warnings 0) and prettier clean. The four native-exact-input tests fail against the previous implementation.