SwapRouter
The SwapRouter class encodes transaction calldata for executing swaps on the Hydrex router contract.
Import
typescript
import {
SwapRouter,
SWAP_ROUTER_ADDRESSES,
ChainId,
} from '@hydrexfi/hydrex-sdk';swapCallParameters
Static method that returns encoded calldata and value for a swap transaction. Works with both single-hop and multi-hop trades.
typescript
const { calldata, value } = SwapRouter.swapCallParameters(trade, {
slippageTolerance: new Percent(50, 10_000), // 0.5%
recipient: '0xYourWallet',
deadline: Math.floor(Date.now() / 1000) + 1200,
});
// Contract address for the transaction:
const to = SWAP_ROUTER_ADDRESSES[ChainId.Base];
// 0x6f4bE24d7dC93b6ffcBAb3Fd0747c5817Cea3F9eOptions
| Parameter | Type | Required | Description |
|---|---|---|---|
slippageTolerance | Percent | required | Maximum acceptable slippage as a Percent. E.g. new Percent(50, 10_000) = 0.5%. |
recipient | string | required | Address to receive the output tokens. |
deadline | number | required | Unix timestamp (seconds) after which the transaction will revert. |
inputTokenPermit | PermitOptions | optional | ERC-2612 permit data to approve the router without a separate approve tx. |
sqrtPriceLimitX96 | BigintIsh | optional | Optional price limit for the swap. Defaults to no limit. |
fee | FeeOptions | optional | Optional protocol fee configuration. |
ℹ
Native ETH
When the trade input is native ETH, include the returned
value as msg.value in your transaction. The router contract handles wrapping automatically.Contract Addresses
| Network | Address |
|---|---|
| Base Mainnet | 0x6f4bE24d7dC93b6ffcBAb3Fd0747c5817Cea3F9e |
| Base Sepolia | see SWAP_ROUTER_ADDRESSES[ChainId.BaseSepolia] |