UniswapV3SwapperAdapter
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
| Name | Type | Description |
|---|---|---|
_router | address | Address of the Uniswap V3 SwapRouter |
_fee | uint24 | Fee tier for direct swaps or first hop (e.g., 3000 for 0.3%) |
_base | address | Optional base token for multi-hop routing (address(0) for direct swaps) |
_feeOut | uint24 | Fee 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
| Name | Type | Description |
|---|---|---|
tokenIn | address | Address of the input token |
tokenOut | address | Address of the output token |
amountIn | uint256 | Maximum amount of tokenIn to pull from msg.sender |
minAmountOut | uint256 | Minimum acceptable output amount (reverts if not met) |
receiver | address | Address to receive the output tokens |
Returns
| Name | Type | Description |
|---|---|---|
amountOut | uint256 | Actual 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();