Skip to main content

ISwapper

Git Source

Title: ISwapper

Author: Golem Foundation

Minimal interface for pluggable token swap adapters

Implementations are expected to be stateless and hold no tokens between calls. The caller MUST approve this contract for at least amountIn of tokenIn before calling swap(); the implementation pulls tokens via transferFrom. Any unused tokenIn (e.g. from a partial fill) MUST be returned to msg.sender before swap() returns.

Note: security-contact: [email protected]

Quick Start - What Matters Most

Swappers follow a pull pattern. The caller approves amountIn; the swapper pulls tokenIn, performs the swap, sends tokenOut to the receiver, and must return unused tokenIn to the caller.

Every implementation must enforce minAmountOut and avoid retaining leftover balances.

Functions

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
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