Skip to main content

UniswapV3SwapperAdapter

Git Source

Inherits: ISwapper

Title: UniswapV3SwapperAdapter

Author: Golem Foundation

ISwapper adapter for Uniswap V3 exact-input swaps

Supports both single-hop and multi-hop (via intermediate base token) swaps. Single-hop: tokenIn --(fee)--> tokenOut Multi-hop: tokenIn --(fee)--> base --(feeOut)--> tokenOut The routing mode is determined by the base constructor parameter:

  • base == address(0): always single-hop with fee
  • base != address(0): multi-hop unless tokenIn or tokenOut IS the base token, in which case it falls back to single-hop with the appropriate fee tier Uniswap V3 Router on Ethereum mainnet: 0xE592427A0AEce92De3Edee1F18E0157C05861564 Common base token (WETH): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 Common fee tiers: 100 (0.01%), 500 (0.05%), 3000 (0.3%), 10000 (1%) This contract is fully immutable and holds no tokens between calls.

Note: security-contact: [email protected]

Quick Start - What Matters Most

Uniswap V3 adapter for the ISwapper pull pattern. It supports single-hop and multihop swaps, handles exact input swaps, clears approvals, and returns leftover input.

State Variables

router

The Uniswap V3 SwapRouter address

address public immutable router

fee

Fee tier for direct swaps or the first hop (tokenIn -> base)

uint24 public immutable fee

base

Optional intermediate token for multi-hop routing (address(0) = direct swap)

address public immutable base

feeOut

Fee tier for the second hop (base -> tokenOut), only used when base != address(0)

uint24 public immutable feeOut

Functions

constructor

Creates a UniswapV3SwapperAdapter with fixed routing configuration

constructor(address _router, uint24 _fee, address _base, uint24 _feeOut) ;

Parameters

NameTypeDescription
_routeraddressAddress of the Uniswap V3 SwapRouter
_feeuint24Fee tier for direct swaps or first hop (e.g., 3000 for 0.3%)
_baseaddressOptional base token for multi-hop routing (address(0) for direct swaps)
_feeOutuint24Fee tier for second hop when using multi-hop (ignored if _base is address(0))

swap

Execute a token swap and send output to receiver

The caller MUST have approved this contract for at least amountIn of tokenIn before calling. The implementation pulls via transferFrom(msg.sender, this, amountIn) and returns any unused tokenIn to msg.sender before returning. Reverts if output is less than minAmountOut.

function swap(address tokenIn, address tokenOut, uint256 amountIn, uint256 minAmountOut, address receiver)
external
override
returns (uint256 amountOut);

Parameters

NameTypeDescription
tokenInaddressAddress of the input token
tokenOutaddressAddress of the output token
amountInuint256Maximum amount of tokenIn to pull from msg.sender
minAmountOutuint256Minimum acceptable output amount (reverts if not met)
receiveraddressAddress to receive the output tokens

Returns

NameTypeDescription
amountOutuint256Actual amount of tokenOut sent to receiver

Errors

InvalidRouter

Thrown when the router address is zero

error InvalidRouter();

InvalidToken

Thrown when a token address is zero

error InvalidToken();