SwapRouter

The SwapRouter contract provides functions to execute swaps through VinuSwap pools.

Source: contracts/periphery/SwapRouter.sol

Overview

The SwapRouter is a stateless contract that:

  • Routes swaps through single or multiple pools

  • Handles exact input and exact output swaps

  • Manages VC ↔ WVC conversions

  • Provides deadline and slippage protection

Inheritance

SwapRouter
├── ISwapRouter
├── PeripheryImmutableState
├── PeripheryValidation
├── PeripheryPaymentsWithFee
├── Multicall
└── SelfPermit

Functions

exactInputSingle

Swaps a fixed amount of one token for a maximum possible amount of another.

Parameters:

Field
Description

tokenIn

Address of input token

tokenOut

Address of output token

fee

Pool fee tier

recipient

Output token recipient

deadline

Transaction deadline

amountIn

Exact amount to swap

amountOutMinimum

Minimum acceptable output

sqrtPriceLimitX96

Price limit (0 for no limit)

Returns:

Name
Type
Description

amountOut

uint256

Amount of output token received

Example:


exactInput

Swaps a fixed amount through multiple pools (multi-hop).

Parameters:

Field
Description

path

Encoded swap path (token, fee, token, fee, token...)

recipient

Output token recipient

deadline

Transaction deadline

amountIn

Exact amount to swap

amountOutMinimum

Minimum acceptable output

Path Encoding:

Example:


exactOutputSingle

Swaps a minimum possible amount of one token for a fixed amount of another.

Parameters:

Field
Description

tokenIn

Address of input token

tokenOut

Address of output token

fee

Pool fee tier

recipient

Output token recipient

deadline

Transaction deadline

amountOut

Exact amount to receive

amountInMaximum

Maximum acceptable input

sqrtPriceLimitX96

Price limit (0 for no limit)

Returns:

Name
Type
Description

amountIn

uint256

Amount of input token spent

Example:


exactOutput

Swaps a minimum possible amount through multiple pools for a fixed output.

Parameters:

Note: For exact output, the path is encoded in reverse order (output token first).

Path Encoding for Exact Output:


uniswapV3SwapCallback

Callback from pool during swap. Handles payment of input tokens.

Parameters:

Name
Type
Description

amount0Delta

int256

Token0 amount owed (positive) or received (negative)

amount1Delta

int256

Token1 amount owed (positive) or received (negative)

_data

bytes

Encoded callback data

Note: This is an internal callback. Do not call directly.

Payment Functions

unwrapWVC

Unwraps WVC to VC.

sweepToken

Transfers the full balance of a token.

refundETH

Refunds any ETH left in the contract.

Multicall

multicall

Executes multiple router calls in a single transaction.

Example:

Permit Functions

selfPermit

Approves tokens via ERC20 permit signature.

selfPermitIfNecessary

Calls permit only if current allowance is insufficient.

Common Patterns

Swap VC for Tokens

Swap Tokens for VC

Swap with Permit (Gasless Approval)

Error Messages

Error
Meaning

Transaction too old

Deadline exceeded

Too little received

Output below minimum

Too much requested

Input above maximum

Invalid callback

Callback from non-pool address

Interface

Last updated