Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/collinsville22/Sable/llms.txt

Use this file to discover all available pages before exploring further.

Overview

AVNU is the leading DEX aggregator on StarkNet, routing trades across multiple liquidity sources to find the best execution prices. Sable integrates AVNU for automated swaps in DCA orders, Turbo vault leverage loops, and private swaps.
AVNU aggregates liquidity from 10+ StarkNet DEXs including Ekubo, JediSwap, MySwap, SithSwap, and more.

What is AVNU?

AVNU is a DEX aggregator that:
  • Splits orders across multiple DEXs to minimize slippage
  • Optimizes routing to find the best price for any swap
  • Provides gasless swaps via a router contract
  • Supports all major StarkNet tokens

Key Features

  • Smart Order Routing: Automatically routes trades through optimal paths
  • Quote API: Get estimated output amounts before executing
  • Build API: Generate transaction calldata for seamless integration
  • Low Slippage: Split orders across venues to reduce price impact

How Sable Integrates with AVNU

Sable uses AVNU as the execution layer for all token swaps across three main features.

DCA Execution

The Smart DCA feature relies on AVNU to execute recurring BTC purchases.
DCA Flow:
  1. Keeper bot checks which orders are due
  2. For each order:
     ├── Fetch AVNU quote (USDC/ETH/STRK → WBTC)
     ├── Build swap transaction calldata
     └── Execute via DCA contract + AVNU Router
  3. User receives WBTC at best available price
Smart DCA adjusts order amounts using the Mayer Multiple (BTC price / 200-day average) — buy more when BTC is undervalued, less when overvalued.

Turbo Vault Swaps

The Turbo Vault uses AVNU to swap borrowed USDC back to WBTC for leverage loops.
Turbo Loop:
  1. Deposit WBTC to Vesu → borrow USDC
  2. Swap USDC → WBTC via AVNU Router
  3. Re-deposit WBTC to Vesu
  4. Repeat for 3-5x leverage
This amplifies the base Vesu lending APY by recursively increasing the position size.

Private Swaps

The Shielded Swap Pool uses AVNU to execute private swaps.
Private Swap Flow:
  1. User deposits WBTC to swap input pool (ZK shielded)
  2. Generates withdrawal proof targeting swap pool contract
  3. Swap pool receives WBTC → swaps via AVNU
  4. Output token (ETH/USDC/STRK) sent to recipient
  5. No on-chain link between depositor and recipient
Supported output tokens:
  • ETH: StarkNet native token
  • USDC: Stablecoin
  • STRK: StarkNet governance token

Contract Addresses

AVNU Router

The main contract for executing swaps on AVNU.
0x04270219d365d6b017231b52e92b3fb5d7c8378b05e9abc97724537a80e93b0f
View on Voyager

API Usage Examples

Sable integrates with AVNU via the AVNU REST API and on-chain router calls.

Get Swap Quote

// From: ~/workspace/source/src/lib/api/avnu.ts

import { getAvnuQuote, parseHexAmount } from "@/lib/api/avnu";

const USDC_ADDRESS = "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8";
const WBTC_ADDRESS = "0x03fe2b97c1fd336e750087d68b9b867997fd64a2661ff3ca5a7c771641e8e7ac";

// Swap 10 USDC → WBTC
const sellAmount = BigInt(10 * 1e6); // 10 USDC (6 decimals)

const quote = await getAvnuQuote(
  USDC_ADDRESS,
  WBTC_ADDRESS,
  sellAmount,
  userAddress // optional: for personalized routing
);

console.log(quote);
// {
//   quoteId: "abc123...",
//   sellTokenAddress: "0x053c91...",
//   sellAmount: "0x989680",        // 10 USDC in hex
//   buyTokenAddress: "0x03fe2b...",
//   buyAmount: "0x186a0",          // ~0.0001 WBTC in hex
//   priceImpact: 0.05,              // 0.05% slippage
//   routes: [
//     { name: "Ekubo", percent: 60 },
//     { name: "JediSwap", percent: 40 }
//   ],
//   estimatedSlippage: 0.03
// }

const buyAmountBigInt = parseHexAmount(quote.buyAmount);
console.log(`Will receive ${Number(buyAmountBigInt) / 1e8} WBTC`);

Build Swap Transaction

import { buildAvnuSwap } from "@/lib/api/avnu";

const calls = await buildAvnuSwap(
  quote.quoteId,
  userAddress,
  0.01 // 1% slippage tolerance
);

console.log(calls);
// [
//   {
//     contractAddress: "0x053c91...",  // USDC
//     entrypoint: "approve",
//     calldata: ["0x042702...", "0x989680", "0x0"]
//   },
//   {
//     contractAddress: "0x042702...",  // AVNU Router
//     entrypoint: "multi_route_swap",
//     calldata: [...]
//   }
// ]

// Execute via wallet
await account.execute(calls);

Integration in DCA Keeper

The DCA keeper bot uses AVNU to execute orders automatically.
// From: ~/workspace/source/scripts/dca_keeper.mjs

import { getAvnuQuote, buildAvnuSwap } from "@/lib/api/avnu";

// 1. Get quote for order
const quote = await getAvnuQuote(
  order.sellToken,
  WBTC_ADDRESS,
  adjustedAmount, // adjusted by Mayer Multiple
  dcaContractAddress
);

// 2. Build swap calldata
const swapCalls = await buildAvnuSwap(
  quote.quoteId,
  dcaContractAddress,
  0.015 // 1.5% slippage
);

// 3. Execute order via DCA contract
await dcaContract.execute_order(
  orderId,
  swapCalls,
  quote.buyAmount
);

AVNU API Endpoints

Base URL

https://starknet.api.avnu.fi

Get Quote

GET https://starknet.api.avnu.fi/swap/v3/quotes?
  sellTokenAddress=0x053c91...
  &buyTokenAddress=0x03fe2b...
  &sellAmount=0x989680
  &takerAddress=0x...
Parameters:
  • sellTokenAddress: Token to sell (hex address)
  • buyTokenAddress: Token to buy (hex address)
  • sellAmount: Amount to sell (hex, smallest units)
  • takerAddress: (Optional) User address for personalized routing
Returns: Array of quotes sorted by best price.

Build Swap

POST https://starknet.api.avnu.fi/swap/v3/build

{
  "quoteId": "abc123...",
  "takerAddress": "0x...",
  "slippage": 0.01,
  "includeApprove": true
}
Returns: Array of transaction calls (approve + swap) ready for execution.

Which Sable Features Use AVNU?

DCA Orders

Automated BTC PurchasesKeeper bot swaps USDC/ETH/STRK → WBTC via AVNU on every order execution.Smart DCA adjusts amounts based on Mayer Multiple.

Turbo Vault

Leverage Loop SwapsSwaps borrowed USDC → WBTC to re-deposit for recursive leverage.Enables 3-5x amplification of base lending yield.

Private Swaps

Zero-Knowledge Token SwapsSwap WBTC → ETH/USDC/STRK with full privacy.No on-chain link between depositor and recipient.

Curator Strategies

Vault RebalancingSome vault strategies may use AVNU for token swaps during rebalancing.

Quote and Build API

The AVNU integration follows a two-step flow:

Step 1: Get Quote

Purpose: Estimate output amount and optimal routing.
const quote = await getAvnuQuote(
  sellToken,
  buyToken,
  sellAmount,
  takerAddress
);
Returns:
  • buyAmount: Estimated output (hex)
  • routes: DEX split (e.g., 60% Ekubo + 40% Jedi)
  • priceImpact: Expected slippage
  • quoteId: Reference for building transaction

Step 2: Build Transaction

Purpose: Generate executable calldata.
const calls = await buildAvnuSwap(
  quote.quoteId,
  takerAddress,
  slippage
);
Returns: Array of contract calls:
  1. approve: Authorize AVNU Router to spend sell token
  2. multi_route_swap: Execute swap across optimal routes

Error Handling

try {
  const quote = await getAvnuQuote(sell, buy, amount);
  if (!quote) {
    throw new Error("No quotes available");
  }
  
  const calls = await buildAvnuSwap(quote.quoteId, user, 0.01);
  await account.execute(calls);
} catch (error) {
  if (error.message.includes("insufficient liquidity")) {
    // Handle low liquidity
  } else if (error.message.includes("slippage")) {
    // Retry with higher slippage tolerance
  }
}

External Resources

AVNU Documentation

Official AVNU protocol documentation

AVNU App

AVNU swap interface

AVNU API Reference

REST API for quotes and swap building

Integration Source Code: ~/workspace/source/src/lib/api/avnu.ts