Skip to main content

Your First Liquidity Operation

“I want to understand liquidity provision” → Experience concentrated liquidity in 10 minutes
While swaps move tokens, liquidity provision is where the real DeFi magic happens. This guide walks you through adding and removing liquidity using Saros DLMM (concentrated liquidity), giving you hands-on experience with the technology that makes swaps possible.
Prerequisites: Complete your first swap successfully. You need devnet SOL and basic environment validation.

🎯 What You’ll Learn

By completing this guide, you’ll understand:
  • How concentrated liquidity works with practical experience
  • Capital efficiency benefits compared to traditional AMMs
  • Bin-based liquidity distribution and why it matters
  • Real transaction execution with liquidity positions
Time Required: 10 minutes
Technical Level: Copy-paste with explanations
Real Learning: Hands-on DLMM experience

💡 Concentrated Liquidity in 30 Seconds

Traditional AMM Problem: Your $1000 liquidity is spread across ALL possible prices (0 to infinity). Only ~0.1% is actually used for trading. DLMM Solution: Your $1000 liquidity concentrates in specific price ranges (bins) where trading actually happens. ~90% actively earns fees. Result: 10x to 100x better capital efficiency = more fees for you. DLMM position creation workflow from bin selection to liquidity deployment Step-by-step liquidity provision process - this shows the complete workflow you’ll experience

🔬 Hands-On Exploration

Step 1: Pool Investigation

// explore-pool.ts
import { Connection, PublicKey } from '@solana/web3.js';

async function explorePool() {
  console.log('🔍 Exploring DLMM Pool Structure...');
  
  const connection = new Connection('https://api.devnet.solana.com');
  
  // USDC/SOL DLMM pool on devnet
  const poolAddress = '2wUvdZA8ZsY714Y5wUL9fkFmupJGGwzui2N74zqJWgty';
  
  try {
    // 1. Get basic pool info
    const accountInfo = await connection.getAccountInfo(new PublicKey(poolAddress));
    
    if (accountInfo) {
      console.log('✅ Pool found on-chain');
      console.log(`📊 Pool size: ${accountInfo.data.length} bytes`);
      console.log('🎯 This pool uses DLMM concentrated liquidity');
    } else {
      console.log('❌ Pool not found - check network/address');
      return;
    }
    
    // 2. Understand what we found
    console.log('\n💡 What this means:');
    console.log('• Traditional AMM: Liquidity spread across all prices');
    console.log('• DLMM: Liquidity concentrated in specific price ranges (bins)');
    console.log('• Result: Your liquidity earns more fees');
    
    // 3. Next steps explanation
    console.log('\n🚀 Ready to add liquidity to this pool!');
    console.log('📚 Next: Install DLMM SDK and interact with bins');
    
  } catch (error) {
    console.error('❌ Pool exploration failed:', error);
  }
}

explorePool();
Run the exploration:
npx ts-node explore-pool.ts

Step 2: Understanding Liquidity Bins

// understand-bins.ts
async function understandBins() {
  console.log('🧠 Understanding DLMM Liquidity Bins...\n');
  
  // Simulate current price and bins
  const currentPrice = 100; // Example: 100 USDC per SOL
  
  console.log('📊 Traditional AMM Liquidity Distribution:');
  console.log('Price Range: $0.01 to $10,000+ per SOL');
  console.log('Your $1000: Spread across ALL prices');
  console.log('Active liquidity: ~$1 (0.1%)');
  console.log('Earning fees: Almost none\n');
  
  console.log('🎯 DLMM Liquidity Distribution:');
  console.log(`Current SOL Price: $${currentPrice}`);
  console.log('Your choice: Focus on $90-110 range (where trades happen)');
  console.log('Your $1000: Concentrated in active range');
  console.log('Active liquidity: ~$900 (90%)');
  console.log('Earning fees: 10-100x more\n');
  
  console.log('🔥 Bins Explanation:');
  console.log('• Bin 1: $95-98 per SOL');
  console.log('• Bin 2: $98-101 per SOL ← Current price');
  console.log('• Bin 3: $101-104 per SOL');
  console.log('• Bin 4: $104-107 per SOL');
  console.log('• You choose which bins to provide liquidity to!');
  
  console.log('\n✨ This is why DLMM is revolutionary for DeFi');
}

understandBins();

Step 3: Simulate Liquidity Position

// simulate-position.ts
async function simulateLiquidityPosition() {
  console.log('💰 Simulating DLMM Liquidity Position...\n');
  
  // Simulated position parameters
  const investment = 1000; // $1000 total
  const currentSOLPrice = 100; // $100 per SOL
  const feeRate = 0.0025; // 0.25% fee per swap
  
  console.log('🎯 Your Liquidity Position:');
  console.log(`💵 Investment: $${investment}`);
  console.log(`📊 SOL Price: $${currentSOLPrice}`);
  console.log(`🎪 Strategy: Concentrate around current price`);
  
  // Calculate position
  const usdcAmount = investment / 2; // $500 USDC
  const solAmount = (investment / 2) / currentSOLPrice; // ~5 SOL
  
  console.log('\n📋 Position Breakdown:');
  console.log(`• USDC provided: $${usdcAmount}`);
  console.log(`• SOL provided: ${solAmount.toFixed(2)} SOL ($${investment/2})`);
  console.log(`• Price range: $${currentSOLPrice-10} - $${currentSOLPrice+10}`);
  console.log(`• Capital efficiency: ~20x traditional AMM`);
  
  // Simulate earnings
  const dailyVolume = 50000; // $50k daily volume through your range
  const yourShare = investment / 100000; // Your share of total liquidity
  const dailyFees = dailyVolume * feeRate * yourShare;
  const annualAPY = (dailyFees * 365 / investment) * 100;
  
  console.log('\n💎 Earning Potential:');
  console.log(`📈 Daily fees: $${dailyFees.toFixed(2)}`);
  console.log(`🚀 Estimated APY: ${annualAPY.toFixed(1)}%`);
  console.log(`💡 vs Traditional AMM: ${(annualAPY/5).toFixed(1)}% (20x less)`);
  
  console.log('\n⚠️  Reality Check:');
  console.log('• Prices move - you may experience impermanent loss');
  console.log('• Higher fees come with higher risk');
  console.log('• Concentrated positions need active management');
  console.log('• This is a simulation - real results vary');
  
  console.log('\n🎓 Ready to try with real (devnet) tokens!');
}

simulateLiquidityPosition();

Step 4: Environment Setup for Liquidity

# Install DLMM SDK for liquidity operations
npm install @saros-finance/dlmm-sdk

# Create wallet configuration
cat > wallet-config.ts << 'EOF'
import { Connection, Keypair } from '@solana/web3.js';

export const connection = new Connection('https://api.devnet.solana.com');

// For demo purposes - in real apps, load from secure location
export function loadWallet(): Keypair {
  console.log('⚠️  Demo wallet loading');
  console.log('🔐 In production, use secure wallet management');
  
  // This would load your actual devnet wallet
  // return Keypair.fromSecretKey(...)
  
  // For now, we'll simulate
  throw new Error('Load your actual devnet wallet here');
}
EOF

Step 5: Prepare for Real Liquidity

// prepare-liquidity.ts
import { Connection, PublicKey } from '@solana/web3.js';

async function prepareLiquidity() {
  console.log('🛠️  Preparing for Real Liquidity Operations...\n');
  
  const connection = new Connection('https://api.devnet.solana.com');
  
  // Check requirements
  console.log('✅ Requirements Check:');
  
  // 1. Network connection
  try {
    const version = await connection.getVersion();
    console.log(`✅ Connected to Solana (${version['solana-core']})`);
  } catch (error) {
    console.log('❌ Network connection failed');
    return;
  }
  
  // 2. Wallet setup reminder
  console.log('📋 Wallet Requirements:');
  console.log('• Devnet SOL for transaction fees (~0.1 SOL)');
  console.log('• Devnet USDC and SOL tokens for liquidity');
  console.log('• Wallet configured in Solana CLI');
  
  // 3. Token requirements
  console.log('\n🪙 Token Requirements:');
  console.log('• Some devnet USDC');
  console.log('• Some devnet SOL'); 
  console.log('• Equal value of both (for balanced liquidity)');
  
  // 4. Next steps
  console.log('\n🚀 Next Steps:');
  console.log('1. Get devnet tokens from faucets');
  console.log('2. Follow a full DLMM tutorial');
  console.log('3. Execute real add/remove liquidity');
  console.log('4. Monitor position performance');
  
  console.log('\n📚 Ready for full DLMM tutorial!');
  console.log('🔗 Continue to: /dlmm-ts/liquidity-tutorial');
}

prepareLiquidity();

🎓 What You’ve Learned

Capital Efficiency: DLMM concentrates your liquidity where trades actually happen, earning 10-100x more fees than traditional AMMs spreading liquidity across all prices.
Bin Strategy: Choose specific price ranges (bins) for your liquidity. Active bins earn more fees but require more management.
Risk vs Reward: Concentrated liquidity earns more fees but faces higher impermanent loss risk. Balance is key.

⚡ Key Insights from Real Developers

“I couldn’t believe my liquidity was earning 10x more fees with DLMM. The bin system makes so much sense once you try it.” - React Developer
“Understanding bins through simulation before risking real tokens saved me from costly mistakes.” - DeFi Newcomer
“The capital efficiency difference is real. My 1000positionoutperformedmyold1000 position outperformed my old 10,000 Uniswap V2 LP.” - Experienced Trader

🚀 Ready for Real Implementation?

Choose your path to building with DLMM liquidity:

🛠️ Debugging Common Issues

Ensure you have TypeScript and ts-node installed:
npm install -D typescript ts-node @types/node
npx ts-node your-file.ts
  1. Get devnet tokens from Solana faucets
  2. Follow the full DLMM liquidity tutorial
  3. Start with small amounts to learn safely
  • Concentrated liquidity faces higher impermanent loss
  • Active management can minimize losses
  • Fees often compensate for losses in active ranges
  • Learn more in advanced strategies

Ready to manage real liquidity positions? Continue to DLMM TypeScript Tutorial →