Execution

The route data from the V2 API can be used directly with the MultiHopRouter smart contract. The V2 API provides ready-to-use transaction calldata, making execution simple.

Contract Address

0x744489ee3d540777a66f2cf297479745e0852f7a

Execution Methods

There are three primary ways to execute swaps with the MultiHopRouter:

1. Using the executeSwaps Function

The executeSwaps function provides positive slippage capture (50% capture rate) and custom fee collection:

function executeSwaps(
    address[] calldata tokens,
    uint256 amountIn,
    uint256 minAmountOut,
    uint256 expectedAmountOut,
    Swap[][] calldata hopSwaps,
    uint256 feeBps,
    address feeRecipient
) external payable nonReentrant returns (uint256 userAmountOut)

Required Parameters

Name
Type
Description
Required

tokens

address[]

Array of token addresses representing the swap path

Yes

amountIn

uint256

Amount of input tokens to swap

Yes

minAmountOut

uint256

Minimum amount of output tokens expected (slippage protection)

Yes

expectedAmountOut

uint256

Expected amount of output tokens (used for positive slippage calculation)

Yes

hopSwaps

Swap[][]

Array of swap configurations for each hop (obtained from the V2 API response)

Yes

feeBps

uint256

Fee in basis points (e.g., 100 = 1%) - automatically capped at 1% max

Yes

feeRecipient

address

Address to receive the fee (97.5% of fee goes here, 2.5% goes to protocol)

Yes

Features:

  • Positive Slippage Capture: Captures 50% of any positive slippage

    • If feeRecipient is specified: half of captured slippage goes to your wallet, half to protocol

    • If no feeRecipient is specified: protocol keeps all captured positive slippage

    • You can set feeBps=0 and still receive positive slippage by providing feeRecipient

  • Custom Fee Collection: Set your own fees up to 1% (100 basis points), or set to 0 for no fees

  • Revenue Sharing: You keep 97.5% of collected fees, protocol keeps 2.5%

  • Automatic Fee Handling: If feeBps is 0 or feeRecipient is zero address, no fee is taken. When fees are taken, your share (97.5%) is sent directly to feeRecipient during execution; the protocol share (2.5%) is sent to the protocol address.

2. Using the executeMultiHopSwap Function

The executeMultiHopSwap function is designed for searchers, arbitragers, and traders who build routes off-chain and don't want to share positive slippage:

Required Parameters

Name
Type
Description
Required

tokens

address[]

Array of token addresses representing the swap path

Yes

amountIn

uint256

Amount of input tokens to swap

Yes

minAmountOut

uint256

Minimum amount of output tokens expected (slippage protection)

Yes

hopSwaps

Swap[][]

Array of swap configurations for each hop

Yes

Features:

  • 0.03% fee on output amount (goes entirely to protocol)

  • No positive slippage sharing - you keep all

  • Simpler parameter set

3. Using Calldata Directly from V2 Route

The V2 API response includes ready-to-use transaction calldata in the execution.calldata field. This calldata can be sent directly to the contract without manually constructing function calls.

Example using the calldata:

Integrator Fee Payouts

  • Where fees go: When feeBps > 0 and feeRecipient is set, 97.5% of the fee amount is transferred directly to feeRecipient and 2.5% to the protocol address during the swap.

  • Zero-fee but capture slippage: You can set feeBps = 0 and still receive 50% of captured positive slippage by providing feeRecipient.

  • Zero recipient: If feeRecipient is unset or zero address, no custom fee is taken and any captured positive slippage goes fully to the protocol.

Hop Swaps Data Structure

For developers building their own routes or using the executeMultiHopSwap function, you need to understand the hop swaps data structure. This is also the same structure returned in the V2 API response under execution.details.hopSwaps:

Swap Struct

Hop Swaps Array Structure

Field Usage by DEX Type

Field
V2 DEXs (1,2,7,18,24)
V3 DEXs (3,4,5,8,10,12,17,19,22)
Others (6,9,11,13,14,16,20,21,23)

tokenIn

✅ Required

✅ Required

✅ Required

tokenOut

✅ Required

✅ Required

✅ Required

routerIndex

✅ Required

✅ Required

✅ Required

fee

❌ Ignored

✅ Required

❌ Ignored [1]

amountIn

✅ Required

✅ Required

✅ Required

stable

✅ Required

❌ Ignored

❌ Ignored

[1] For router index 14 (HyperBrick Liquidity Book), the fee field is used as the bin step (defaults to 25 if not provided).

This structure allows for complex multi-hop routing where each hop can split across multiple DEXs for optimal execution.

Native HYPE Unwrapping

When using the unwrapWHYPE=true parameter in the V2 API, the system automatically handles conversion from WHYPE to native HYPE at the end of swaps. This uses a special address convention:

Dead Address for Native HYPE

Address: 0x000000000000000000000000000000000000dEaD

When the dead address (0x000000000000000000000000000000000000dEaD) appears as the final tokenOut in your swap path, it represents native HYPE. The MultiHopRouter contract automatically:

  1. Receives WHYPE from the final swap step

  2. Unwraps WHYPE to native HYPE using the WHYPE contract

  3. Transfers native HYPE directly to your wallet

Usage Examples

In token arrays:

In hopSwaps structure:

Key Points

  • Automatic Detection: When the dead address is detected as the final output token, unwrapping is triggered automatically

  • No Manual Unwrapping: You don't need to call separate unwrap functions - the router handles everything

  • Gas Efficiency: Unwrapping happens in the same transaction as your swap

  • API Integration: Set unwrapWHYPE=true in V2 API calls to enable this feature automatically

Last updated