STEAMM Developer Integration Guide

Table of Contents

Overview

STEAMM is a next-generation Automated Market Maker (AMM) protocol on Sui that maximizes capital efficiency through:

  • Modular Quoter System: Support for multiple AMM types (Constant Product, Oracle-based, Stable)

  • Liquidity Reutilization: Optional integration with Suilend lending markets for yield generation

  • Shared Liquidity Model: Banks aggregate liquidity across pools for improved efficiency

  • Yield-bearing LP Tokens: LPs earn both trading fees and lending yields

Key Benefits for Developers

  1. Flexible Integration: Choose between simple AMM pools or advanced yield-bearing pools

  2. Capital Efficiency: Up to 80% of idle liquidity can earn lending yields

  3. Multiple AMM Types: Constant product, oracle-based, and stable coin AMMs

  4. Composable Design: Easy integration with existing DeFi protocols

Architecture

Core Components

  • Registry: Global tracker of all pools and banks

  • Pool: Core AMM logic with modular quoter system

  • Bank: Manages liquidity and optional Suilend integration

  • Quoter: Pluggable AMM algorithms (CPMM, Oracle, Stable)

Token Flow

Quick Start

Dependencies

Add to your Move.toml:

Basic Pool Creation (No Suilend)

Basic Liquidity Operations

Pool Types

STEAMM supports three main quoter types:

1. Constant Product AMM (CPMM)

Best for: General trading pairs, volatile assets

Features:

  • Classic x*y=k formula with optional offset

  • Suitable for most token pairs

  • Predictable slippage curves

2. Oracle AMM (OMM)

Best for: Stablecoin pairs, reduced impermanent loss

Features:

  • Uses external price feeds

  • Dynamic fees based on volatility

  • Better for correlated assets

  • Requires Suilend integration (bTokens only)

3. Stable AMM

Best for: Highly correlated assets (USDC/USDT)

Creating Pools

Simple Pool (No Banks)

For basic AMM functionality without yield farming:

Advanced Pool with Suilend Integration

For yield-bearing pools that earn lending yields:

Liquidity Operations

Adding Liquidity

Simple Pool

Removing Liquidity

Simple Pool

Swapping

Understanding STEAMM's Swap Model

STEAMM uses an intent/execute pattern for swaps, especially important for yield pools:

  1. Intent: Declare intention to swap and get a quote

  2. Provision: Banks provision necessary liquidity from Suilend

  3. Execute: Perform the actual swap

  4. Rebalance: Optionally rebalance bank utilization

Simple Pool Swaps

Always use pool_script_v2 for yield pools - it handles the complex bToken conversions:

Oracle Pool Swaps

Getting Quotes

Always get quotes before executing swaps:

Script Versions: When to Use Which

  • pool_script: Original version, use for compatibility with older code

  • pool_script_v2: RECOMMENDED - cleaner API, better error handling

  • Direct pool calls: Only for simple pools without banks

Suilend Integration

Understanding Banks

Banks are the key component that enables Suilend integration:

  • Purpose: Aggregate liquidity from multiple pools

  • Yield Generation: Deploy idle liquidity to Suilend for lending yields

  • bTokens: Yield-bearing representations of underlying tokens (note: singular "btoken")

  • Utilization Management: Maintain liquidity buffers for instant swaps

Bank Lifecycle

  1. Creation: bank::create_bank() - Creates bank for a token type

  2. Lending Setup: bank.init_lending() - Enables Suilend integration

  3. Operation: Automatic yield generation and liquidity management

  4. Rebalancing: Periodic adjustment of Suilend exposure

Working with bTokens

Utilization Parameters

Target Utilization: Percentage of bank funds deployed to Suilend Buffer: Allowed deviation before rebalancing occurs

Benefits of Suilend Integration

  1. Additional Yield: LPs earn trading fees + lending yields

  2. Capital Efficiency: Up to 80% of idle liquidity generates yield

  3. Shared Liquidity: Multiple pools share deeper liquidity

  4. Automatic Management: Protocol handles Suilend interactions

When to Use Suilend Integration

Use Suilend Integration When:

  • You want maximum yield for LPs

  • Pool expects significant idle periods

  • Working with established tokens (USDC, SUI, etc.)

  • You can manage the additional complexity

Use Simple Pools When:

  • Rapid development needed

  • Working with new/experimental tokens

  • Minimizing smart contract dependencies

  • Token doesn't have Suilend market

Error Handling

Common Error Codes

Error
Code
Description
Solution

ESlippageExceeded

0

Output below minimum

Increase slippage tolerance

EInsufficientBankFunds

9

Bank liquidity too low

Wait for rebalancing or provide liquidity

ELendingAlreadyActive

5

Bank already has lending initialized

Check bank state before init

EInvalidBTokenDecimals

1

bToken must have 9 decimals

Fix token metadata

EInvalidLpDecimals

0

LP token must have 9 decimals

Fix LP token metadata

EEmptyBank

1

Bank has no funds

Add liquidity first

EInvariantViolation

0

CPMM invariant broken

Check swap parameters

Error Handling Patterns

Practical Integration

Integrating STEAMM into Your DeFi Protocol

1. Router Pattern

2. Yield Farming Integration

3. Arbitrage Bot Integration

Advanced Usage

Multi-Pool Routing

Fee Management and Revenue

Monitoring Pool Health

Code Examples

Complete Pool Setup

Trading Interface

Reference

Key Functions by Component

Registry

  • registry::init_for_testing() - Create registry for testing

  • Auto-registration happens when creating pools/banks

Bank

  • bank::create_bank() - Create new bank (package function)

  • bank.init_lending() - Enable Suilend integration

  • bank.mint_btoken() - Convert tokens to bTokens (singular!)

  • bank.burn_btoken() - Convert bTokens back to tokens (singular!)

  • bank.rebalance() - Manual rebalancing trigger

Pool

  • pool.deposit_liquidity() - Add liquidity

  • pool.redeem_liquidity() - Remove liquidity

  • pool.cpmm_swap() - Execute CPMM swap

  • pool.cpmm_quote_swap() - Get CPMM quote

Quoters

  • cpmm::new() - Create constant product pool

  • omm_v2::new() - Create oracle AMM pool (requires full parameters)

  • Various swap() and quote_swap() functions

  • pool_script_v2::deposit_liquidity() - PREFERRED - Add liquidity with banks

  • pool_script_v2::redeem_liquidity() - PREFERRED - Remove liquidity with banks

  • pool_script_v2::cpmm_swap() - PREFERRED - Swap with banks

  • pool_script_v2::quote_cpmm_swap() - PREFERRED - Quote with banks

Gas Optimization Tips

  1. Use Scripts: Always use pool_script_v2 functions for yield pools

  2. Batch Operations: Combine multiple operations when possible

  3. Pre-calculate: Get quotes off-chain when possible

  4. Rebalance Timing: Banks auto-rebalance, but manual triggers available

  5. Avoid Micro-transactions: Respect minimum token block sizes

Testing

Migration and Versioning

STEAMM uses versioned contracts. When integrating:

  1. Always check current versions in Move.toml files

  2. Use the latest published package addresses

  3. Handle version upgrades gracefully

  4. Test with the exact versions you'll use in production

Best Practices

  1. Start Simple: Begin with basic CPMM pools, add yield later

  2. Use Scripts: Always prefer pool_script_v2 for yield pools

  3. Monitor Health: Regularly check bank utilization and rebalancing needs

  4. Handle Errors: Implement proper error handling for common failure modes

  5. Test Thoroughly: Use the provided test utilities extensively

  6. Gas Awareness: Be mindful of gas costs, especially for bank operations