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

ETH Refund Logic Bug in V3 SDK SwapRouter #216

Open
beder-bourahmah-gluwa opened this issue Dec 12, 2024 · 2 comments
Open

ETH Refund Logic Bug in V3 SDK SwapRouter #216

beder-bourahmah-gluwa opened this issue Dec 12, 2024 · 2 comments

Comments

@beder-bourahmah-gluwa
Copy link

There's a bug in the V3 SDK SwapRouter's swapCallParameters refund logic that can lead to users losing ETH in certain scenarios. The current implementation only triggers ETH refunds for EXACT_OUTPUT trades, but refunds should occur for any trade where native ETH is the input token.

// Current implementation
const mustRefund = sampleTrade.inputAmount.currency.isNative && sampleTrade.tradeType === TradeType.EXACT_OUTPUT

// Should be
const mustRefund = sampleTrade.inputAmount.currency.isNative

const mustRefund = sampleTrade.inputAmount.currency.isNative && sampleTrade.tradeType === TradeType.EXACT_OUTPUT

Impact

When performing EXACT_INPUT swaps with ETH as the input token, if the liquidity pool cannot fulfill the entire order, the unused ETH becomes trapped in the V3 router contract. This ETH remains stuck until the next user performs an EXACT_OUTPUT trade or any refundETH call, at which point the stuck ETH is incorrectly refunded to that subsequent user.

This issue has already been covered in articles such as this one.

@Zaim211
Copy link

Zaim211 commented Jan 3, 2025

server error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@Zaim211 @beder-bourahmah-gluwa and others