Automated Market Making Explained

Automated Market Makers (AMMs) are the engine of decentralized finance (DeFi). AMMs allow you to trade digital assets permissionlessly and automatically by using liquidity pools.

On Solana, AMMs are turbocharged by the network's high throughput and low latency, enabling high-frequency trading experiences that rival centralized exchanges.

Carbium Context: The Carbium Trading API acts as a "Meta-AMM" or aggregator. We don't just connect you to one pool; we route your trade across Raydium, Orca, Meteora, and others to find the best price with the lowest slippage.

1. The Core Concept: Liquidity Pools

At the heart of every AMM is a Liquidity Pool. Think of it as a smart contract "bucket" containing two different tokens, for example, SOL and USDC.

  • Traders trade against the bucket. To buy SOL, you throw USDC into the bucket and take SOL out.
  • Liquidity Providers (LPs) own the bucket. They deposit the tokens initially and earn a fee on every trade.

The Pricing Formula (Constant Product)

The most basic AMMs (like Uniswap V2 or Raydium Legacy) use the Constant Product Formula:

x * y = k

  • x: Quantity of Token A (e.g., SOL)
  • y: Quantity of Token B (e.g., USDC)
  • k: A constant value that must remain unchanged during a trade.

How it works: If you buy SOL from the pool, you decrease the supply of SOL ($x$) and increase the supply of USDC ($y$). To keep $k$ constant, the price of SOL must rise as it becomes scarcer in the pool.


2. Advanced Mechanics on Solana

Solana's architecture allows for more sophisticated AMM designs than older blockchains.

Concentrated Liquidity (CLMM)

Standard AMMs spread liquidity infinitely across all possible prices (from $0 to Infinity). This is inefficient because SOL is unlikely to trade at $1 or $1,000,000 tomorrow.

Concentrated Liquidity Market Makers (CLMMs), like Orca Whirlpools or Raydium CLMM, allow LPs to allocate their capital within a specific price range (e.g., SOL between $130 and $150).

  • Pros: Deeper liquidity around the current price means lower slippage for traders.
  • Cons: Higher risk of impermanent loss for LPs if the price moves out of range.

Hybrid Pools (Stable-Swap)

For assets that should have the same value (like USDC/USDT or SOL/mSOL), the x*y=k formula is inefficient.

  • Stable AMMs use a flatter curve formula, allowing large trades with almost zero price impact, as long as the assets maintain their peg.

3. Risks: Slippage & Impermanent Loss

Understanding these risks is critical for developers building trading bots or dashboards.

Slippage

The difference between the expected price of a trade and the executed price.

  • Why it happens: In a constant product pool, large trades shift the ratio of $x$ and $y$ significantly, causing the price per token to increase as you buy more.
  • Carbium Solution: Our API splits large orders into smaller chunks ("Jito Bundles" or "Smart Routing") across multiple pools to minimize this impact.

Impermanent Loss (IL)

A risk for Liquidity Providers. It occurs when the price of your deposited tokens changes compared to when you deposited them.

  • Example: If SOL doubles in price, an LP would have made more money simply holding the SOL in a wallet rather than providing liquidity, because the AMM rebalances by selling the winning asset (SOL) early.

4. Solana AMM Ecosystem Comparison

Developers often ask which AMM to integrate. The answer is: All of them (via Carbium).

FeatureRaydiumOrcaMeteora
TypeHybrid (Orderbook + AMM)Pure CLMMDynamic / DLMM
Best ForNew token launches, long-tail assetsMajor pairs (SOL/USDC), tight spreadsLPs seeking dynamic fees
Carbium Support✅ Fully Indexed✅ Fully Indexed✅ Fully Indexed

5. How Carbium Interacts with AMMs

When you call the Carbium CQ1, we perform Smart Quote:

  1. Quote: We scan the on-chain state of all major AMM pools (Raydium, Orca, etc.) in milliseconds using our bare-metal RPCs.
  2. Simulation: We simulate the trade against the constant product formula of each pool to calculate exact slippage.
  3. Routing: We construct a transaction that might look like: 50% via Raydium, 30% via Orca, 20% via Phoenix.
  4. Swap: The transaction is sent via Carbium RPC to ensure it lands even during congestion.

Developer Example: Fetching a Quote

This snippet shows how to get an aggregated quote that queries multiple AMMs instantly.

const response = await fetch('https://api.carbium.io/v1/quote?inputMint=SOL&outputMint=USDC&amount=1000000000');
const quote = await response.json();

console.log(`Best Route: ${quote.route}`);
// Output might be: "Raydium -> Orca (Split)"