Skip to content

ETH Refund Logic Bug in V3 SDK SwapRouter #216

@beder-bourahmah-gluwa

Description

@beder-bourahmah-gluwa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions