Skip to main content

CurveSwapper

Git Source

Inherits: ISwapper

Title: CurveSwapper

Author: Golem Foundation

ISwapper adapter for direct Curve StableSwap pool exchanges

Performs single-pool swaps between correlated/pegged ERC20 assets via Curve's StableSwap invariant, which provides near-zero slippage for pegged pairs. Each deployment is configured for a specific pool and token pair via immutables. Uses direct pool calls (not the Curve Router) for gas efficiency since the exact pool is known at deploy time. Key Curve pools on Ethereum mainnet:

  • stETH/ETH: 0xDC24316b9AE028F1497c275EB9192a3Ea0f67022 (indices: 0=ETH, 1=stETH)
  • rETH/wstETH: 0x447ddd4960d9fdbf6af9a790560d0af76795cb08 (indices: 0=rETH, 1=wstETH)
  • 3Pool: 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1c7 (indices: 0=DAI, 1=USDC, 2=USDT) LIMITATIONS:
  • ERC20-to-ERC20 only. Does not handle native ETH output (pools that return ETH require wrapping to WETH which is not supported). For ETH-involving swaps, use UniswapV3SwapperAdapter with WETH instead.
  • Only supports Curve V1 (StableSwap) pools with int128 indices. This contract is fully immutable and holds no tokens between calls.

Note: security-contact: [email protected]

Quick Start - What Matters Most

Curve adapter for the ISwapper pull pattern. It validates the configured pool token indices, enforces minimum output, sends output to the receiver, and returns unused input to the caller.

State Variables

pool

The Curve pool to swap through

address public immutable pool

indexIn

Index of the input token in the Curve pool

int128 public immutable indexIn

indexOut

Index of the output token in the Curve pool

int128 public immutable indexOut

tokenIn

The expected input token for this swapper instance

address public immutable tokenIn

tokenOut

The expected output token for this swapper instance

address public immutable tokenOut

Functions

constructor

Creates a CurveSwapper configured for a specific pool and token pair

constructor(address _pool, int128 _indexIn, int128 _indexOut, address _tokenIn, address _tokenOut) ;

Parameters

NameTypeDescription
_pooladdressAddress of the Curve StableSwap pool
_indexInint128Index of tokenIn in the pool's coins array
_indexOutint128Index of tokenOut in the pool's coins array
_tokenInaddressAddress of the input token (must match pool.coins[_indexIn])
_tokenOutaddressAddress of the output token (must match pool.coins[_indexOut])

swap

Execute a token swap and send output to receiver

Uses balance measurement for compatibility with legacy Curve pools (e.g., 3Pool) whose exchange() does not return the output amount.

function swap(address _tokenIn, address _tokenOut, uint256 amountIn, uint256 minAmountOut, address receiver)
external
override
returns (uint256 amountOut);

Parameters

NameTypeDescription
_tokenInaddress
_tokenOutaddress
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

InvalidPool

Thrown when the pool address is zero

error InvalidPool();

InvalidToken

Thrown when a token address is zero or does not match the configured pair

error InvalidToken();

InvalidIndices

Thrown when pool indices are identical

error InvalidIndices();

TokenIndexMismatch

Thrown when a token address does not match the pool's coins at the given index

error TokenIndexMismatch();