Skip to main content
Technical reference for the Stableswapper swap instruction. For setup and examples, see Quickstart or Examples.

Swap Function

Contract: 0x57AB1E2c6289aCe985Bd5c5571EbF6d98CD41Ab7 (Key Addresses)

Function Signature

Parameters

Preconditions

  • The caller must have approved the Stableswapper contract to spend at least amountIn of tokenIn (ERC-20 approve)
  • Both tokenIn and tokenOut must be listed and swappable
  • The SWAP feature flag must be enabled
  • If the ALLOWLIST feature is enabled, msg.sender must be allowlisted
  • amountIn and minAmountOut must be greater than zero
  • tokenIn and tokenOut must be different addresses
  • recipient must not be the zero address

Fee Model

Fees are charged on the input token and deducted before the 1:1 swap calculation.Example: Swapping 100 USDC with a 1% fee (100 basis points):
  • User sends: 100 USDC
  • Fee: 1 USDC (sent to fee recipient)
  • User receives: 99 of the output token (normalized for decimals)

View Functions

Token State

Fee Configuration

Access Control

Feature flag values:

Events


Error Reference


Roles

The contract uses role-based access control. These roles are managed by the DEFAULT_ADMIN_ROLE holder.

Examples

Code samples for common swap scenarios

Quickstart

Get up and running in 10 minutes

Key Addresses

Program IDs and deployed addresses

Production Readiness

Helper functions and best practices