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