Skip to content

[V4-SDK] maxHopSlippage added to action SWAP_EXACT_IN makes the swap consumes incorrect amount of input token #458

@juroberttyb

Description

@juroberttyb

Issue

  • v4-sdk from 1.22.1 to 1.23.0 introduces maxHopSlippage to action SWAP_EXACT_IN, yet the swap consumes uncertain amount of input token after adding it.
    • amountOutMinimum = minAmountOut.quotient, the swap fails.
    • amountOutMinimum = 0, the swap passes, yet the consumed amount of input token is incorrect. (<2% in the given example)

Environment

  • Anvil fork of unichain mainnet at block number 34779300

Example

Code

  route = await router.route(
    amountIn,
    USDC,
    EXACT_INPUT,
    {
type: SwapType.UNIVERSAL_ROUTER,
version: UniversalRouterVersion.V2_0,
...
    },
    {
protocols: [Protocol.V4],
maxSplits: 1,
maxSwapsPerPath: 2,
    }
  );

  ...

v4Planner.addAction(Actions.SWAP_EXACT_IN, [{
  currencyIn: wbtcAddr,
  path: pathKeys,
  maxHopSlippage: [],
  amountIn: wbtcAmount.toString(),
  amountOutMinimum: "0"
}]);
v4Planner.addAction(Actions.SETTLE_ALL, [wbtcAddr, wbtcAmount.toString()]);
v4Planner.addAction(Actions.TAKE_ALL, [usdcAddr, "0"]);

...

const tx = await universalRouter.execute(commands, inputs, swapDeadline, {
  gasPrice,
  gasLimit,
  value: 0,
});

Log

[2025-12-12T08:22:45.250Z]  Route details: 1 route(s), protocols: V4
[2025-12-12T08:22:45.250Z]  Route type: MULTI-HOP (2 pools)
[2025-12-12T08:22:45.250Z]  Complete routing path:
[2025-12-12T08:22:45.250Z]    Start: WBTC (0x0555E30da8f98308EdB960aa94C0Db47230d2B9c)
[2025-12-12T08:22:45.250Z]    → Pool 1:
[2025-12-12T08:22:45.250Z]        token0: ETH (0x0000000000000000000000000000000000000000)
[2025-12-12T08:22:45.250Z]        token1: WBTC (0x0555E30da8f98308EdB960aa94C0Db47230d2B9c)
[2025-12-12T08:22:45.250Z]        fee: 500, tickSpacing: 10
[2025-12-12T08:22:45.250Z]        hooks: 0x0000000000000000000000000000000000000000
[2025-12-12T08:22:45.250Z]        output: ETH (0x0000000000000000000000000000000000000000)
[2025-12-12T08:22:45.250Z]    → Pool 2:
[2025-12-12T08:22:45.250Z]        token0: ETH (0x0000000000000000000000000000000000000000)
[2025-12-12T08:22:45.250Z]        token1: USDC (0x078D782b760474a361dDA0AF3839290b0EF57AD6)
[2025-12-12T08:22:45.250Z]        fee: 500, tickSpacing: 10
[2025-12-12T08:22:45.250Z]        hooks: 0x0000000000000000000000000000000000000000
[2025-12-12T08:22:45.250Z]        output: USDC (0x078D782b760474a361dDA0AF3839290b0EF57AD6)
[2025-12-12T08:22:45.250Z]    End: USDC (0x078D782b760474a361dDA0AF3839290b0EF57AD6)
[2025-12-12T08:22:45.250Z] [INFO] Route found: 30.697809 USDC output, price impact: 0.1000%
[2025-12-12T08:22:45.250Z]    PathKey 1: intermediateCurrency=0x0000000000000000000000000000000000000000, fee=500
[2025-12-12T08:22:45.250Z]    PathKey 2: intermediateCurrency=0x078D782b760474a361dDA0AF3839290b0EF57AD6, fee=500
[2025-12-12T08:22:45.250Z]  SWAP_EXACT_IN params: amountIn=32893, amountOutMinimum=30393870
[2025-12-12T08:22:45.251Z]  TAKE_ALL: currency=0x078D782b760474a361dDA0AF3839290b0EF57AD6, minAmount=30393870
[2025-12-12T08:22:45.251Z]  SETTLE_ALL: currency=0x0555E30da8f98308EdB960aa94C0Db47230d2B9c, maxAmount=32893
[2025-12-12T08:22:45.255Z]  Balances BEFORE swap: WBTC=0.00032893, USDC=0.0
[2025-12-12T08:22:47.365Z]  Swap confirmed in block 34779406
[2025-12-12T08:22:47.369Z]  Balances AFTER swap: WBTC=0.00032253, USDC=0.596664
[2025-12-12T08:22:47.369Z]  ===== SWAP DELTA ANALYSIS =====
[2025-12-12T08:22:47.369Z]  Expected WBTC consumed: 0.00032893 WBTC
[2025-12-12T08:22:47.369Z]  Actual WBTC consumed:   0.0000064 WBTC
[2025-12-12T08:22:47.369Z]  Consumption ratio:      1.94%
[2025-12-12T08:22:47.369Z]  Expected USDC received: ~30.697809 USDC
[2025-12-12T08:22:47.369Z]  Actual USDC received:   0.596664 USDC
[2025-12-12T08:22:47.369Z]  ================================
[2025-12-12T08:22:47.369Z]  ⚠️  WARNING: Less than 99% of WBTC was consumed! This suggests the swap did not execute as expected.

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