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, TSLAx) 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 xStocks
Create a leveraged position in a single atomic transaction using Klend’s multiply feature and KSwap multi-route swap optimization.Import Dependencies
@kamino-finance/kswap-sdk 2.9.0. It’s the last version on @solana/kit 2, which @kamino-finance/klend-sdk 13 uses; 3.x moved to kit 8.Load Configuration and Initialize SDKs
Set Up a New Wallet
The leverage functions expect the wallet’s Kamino user metadata to exist. A wallet that has never used Kamino sends one setup transaction first.Load the Multiply Obligation
A Multiply position is its own obligation, addressed by the collateral and debt mints. It’snull until the first deposit creates it.Get Scope Price Refresh Instructions
Define the Swap Helpers
The SDK asks for swaps through two callbacks: a quoter that prices the swap and a swapper that returns its instructions. Both use every KSwap route, sorted by output.Build the Leverage Routes
The SDK builds one candidate transaction per swap route: flash borrow USDC, swap it to TSLAx, deposit, borrow USDC, repay the flash loan.selectedTokenMint is the token you deposit: the debt token (USDC) here, or the collateral token. quoteBufferBps inflates only the amount used for the quote; 0 quotes the exact swap amount and leaves price moves to the slippage setting.Fetch Lookup Tables
Fetch Kamino’s lookup tables for each candidate transaction, one request per candidate./luts/find-minimal takes one transaction’s worth of addresses (between 64 and 128), so a single request for all candidates is rejected.Pick the Route That Fits
Compress each candidate with its route’s lookup tables and Kamino’s, then take the best-output one that fits in a transaction.Sign and Send
Transaction Flow
View Transaction Flow Diagram
View Transaction Flow Diagram
Asset Flow
2x Leveraged TSLAx Position: Step-by-Step
2x Leveraged TSLAx Position: Step-by-Step
Initial State
- Wallet: 10 USDC
- Position: None
Flash Borrow
- Flash loan: 10 USDC (temporary)
- Available: 20 USDC total
Swap & Deposit
- Swap 20 USDC to TSLAx via KSwap
- Deposit TSLAx as collateral
Borrow & Repay
- Borrow 10 USDC against collateral
- Repay 10 USDC flash loan
Final Position
- Collateral: TSLAx ($20 value)
- Debt: 10 USDC
- Net Equity: 10 USDC
- Leverage: 2x
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)
KSwap Multi-Route Optimization
KSwap Multi-Route Optimization
- Multi-DEX routing: Tests routes across Jupiter, OKX, dFlow, and other DEX aggregators
- Route choice: Sorted by output; the best-output route that fits in one transaction is sent
- Slippage protection: Each route enforces a minimum output within the slippage setting
- Automatic ATA creation: Handles token account creation and SOL wrapping/unwrapping
Borrow and Multiply SDK Methods
MultiplyObligation. Vanilla operations use VanillaObligation. The obligation type determines which PDA is derived for your position.