A multiply deposit creates a leveraged collateral position in a single, atomic transaction by combining an initial deposit with temporary liquidity.
When a multiply deposit is initiated, the protocol first temporarily borrows the debt token (for example, USDC) through a flash loan. The borrowed amount is swapped into the collateral token (for example, SOL) using KSwap (Kamino’s token swap SDK). The resulting collateral is then deposited into Kamino Lend. With the collateral in place, the position borrows the debt token against it, and the borrowed amount is used to repay the flash loan before the transaction completes. The result is a leveraged position with increased exposure to the collateral token and an outstanding debt balance.
Multiply Deposit with KSwap
Create a leveraged position in a single atomic transaction using Klend’s multiply feature with KSwap multi-route swap optimization.Import Dependencies
Import the required packages for Solana RPC communication, Kamino SDK operations, KSwap routing, and transaction building.Load Configuration and Initialize SDKs
Load the keypair and initialize RPC connections, the market, Scope for oracle prices, and KSwap for routing./path/to/your/keypair.json with the desired keypair path. The Scope SDK provides oracle price data, and the KSwap SDK enables multi-DEX routing for optimal swap execution.Fetch Multiply Lookup Tables
Fetch multiply-specific Address Lookup Tables (LUTs) from Kamino’s CDN to compress transaction size.Setup User Lookup Table
Generate setup instructions for creating or extending a user-specific lookup table with addresses needed for multiply operations.setupTxsIxs will be empty and the loop won’t execute.Check for Existing Obligation
Check if a multiply obligation already exists for this collateral/debt pair.null, a new obligation will be created using a flash loan to bootstrap the position.Get Scope Price Refresh Instructions
Fetch latest oracle prices for accurate collateral and debt valuation.Build Multi-Route Swap Instructions
Fetch the latest USDC/SOL price ratio to keep swap calculations accurate. Set the transaction compute budget and priority fee for reliable execution. Then use KSwap to generate multiple swap route options, with the quoter and swapper helper functions finding optimal paths. See the Helper Functions section below for the implementation of these utilities.Filter and Select Best Route
Prepare the Klend lookup tables for transaction compression.Fetch Blockhash and Load Lookup Tables
Fetch a fresh blockhash for the transaction.Helper Functions
The tutorial requires KSwap helper functions for price fetching and route building.kswap_utils.ts
kswap_utils.ts
Transaction Flow
View Transaction Flow Diagram
View Transaction Flow Diagram
Asset Flow
3x Leveraged Position: Step-by-Step
3x Leveraged Position: Step-by-Step
Key Concepts
Flash Loans
Flash Loans
- Zero upfront capital: Borrow large amounts without collateral
- Atomic execution: All operations succeed or fail together
- Leverage creation: Bootstrap leveraged positions in one transaction
- Risk-free: Transaction reverts if flash loan cannot be repaid
Multiply Obligation Type
Multiply Obligation Type
MultiplyObligation is a specialized obligation type that:- Defines position type: Multiply vs Leverage vs Vanilla
- Derives unique address: Via PDA using collateral/debt mints
- Supports multiple positions: Create different obligations with same tokens using ID parameter
- Creates new obligation: When none exists (indicated by
obligation: null)
Lookup Tables (LUTs)
Lookup Tables (LUTs)
- Storing common addresses: Frequently-used program accounts, reserves, oracles
- Index-based references: 1-byte index instead of 32-byte address
- Transaction compression: Enables complex transactions to fit within the 1232-byte limit
- Multiply-specific LUTs: Fetched from Kamino CDN per collateral/debt pair
- Critical for complex txns: Multiply operations wouldn’t fit without LUTs
KSwap Multi-Route Optimization
KSwap Multi-Route Optimization
- Route simulation: Tests each route for success server-side
- Transaction size selection: Prioritizes routes that fit within transaction limits
- Manual filtering: Provides simulation data for custom route selection logic
- Slippage protection: Guarantees minimum output amount
Commitment Levels
Commitment Levels
processed: Fastest, used for sending (no false timeout errors)confirmed: Medium speed, confirmed by majority of cluster stakefinalized: Slowest, used for blockhash (maximum security, ~32 blocks)- Recommended: Use
processedfor multiply transactions to avoid false errors