Integration Quickstart
Add leverage to your platform in 4 API calls.
Overview
The Lavarage API lets you embed leveraged trading into any Solana application. You call the API to build an unsigned Solana transaction, the user signs it with their wallet, and you submit it to the network. That's it — no on-chain program knowledge required.
What you get:
- Unsigned VersionedTransactions ready to sign and submit
- Automatic offer matching — no need to find liquidity pools manually
- Support for any SPL token that has an active offer
- Both LONG and SHORT positions are fully supported
Base URL: https://api.lavarage.xyz
Prerequisites
- An API key — Apply here (https://v2.lavarage.xyz/partners)
- A Solana wallet adapter (or any signing implementation) on the client side
- A Solana RPC endpoint for transaction submission (Helius, Triton, or your own node)
Step 1: Find a Market
Call POST /api/v1/positions/quote-by-token to get a price preview and confirm a market exists for your token. This does not build a transaction — it just returns quote data.
curl -X POST https://api.lavarage.xyz/api/v1/positions/quote-by-token \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"baseTokenMint": "So11111111111111111111111111111111111111112",
"userPublicKey": "GsbwXfJraMomNxBcjK7xK2xQx5MQgQx4Ld8QkLeNmA3v",
"collateralAmount": "1000000000",
"leverage": 3,
"side": "LONG"
}'Response:
{
"inAmount": "1000000000",
"outAmount": "2950000000",
"priceImpactPct": "0.12",
"otherAmountThreshold": "2920500000",
"inputMint": "So11111111111111111111111111111111111111112",
"outputMint": "So11111111111111111111111111111111111111112",
"slippageBps": 50
}Step 2: Build the Transaction
Call POST /api/v1/positions/open-by-token to build the unsigned transaction. The server resolves the best liquidity pool automatically.
curl -X POST https://api.lavarage.xyz/api/v1/positions/open-by-token \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"baseTokenMint": "So11111111111111111111111111111111111111112",
"userPublicKey": "GsbwXfJraMomNxBcjK7xK2xQx5MQgQx4Ld8QkLeNmA3v",
"collateralAmount": "1000000000",
"leverage": 3,
"side": "LONG",
"slippageBps": 50
}'Response:
{
"transaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAkP...",
"positionAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
"lastValidBlockHeight": 285432100,
"quote": { "outAmount": "9950000000", "priceImpactPct": 0.12, "slippageBps": 50 }
}The transaction field is a base58-encoded VersionedTransaction.
Step 3: User Signs and Submits
Deserialise the transaction, have the user sign it, and submit to the network.
import { VersionedTransaction, Connection } from '@solana/web3.js'
import bs58 from 'bs58'
// Deserialise
const txBytes = bs58.decode(response.transaction)
const tx = VersionedTransaction.deserialize(txBytes)
// Sign with the user's wallet (Phantom, Solflare, etc.)
const signedTx = await wallet.signTransaction(tx)
// Submit
const connection = new Connection('https://api.mainnet-beta.solana.com')
const signature = await connection.sendRawTransaction(signedTx.serialize())
await connection.confirmTransaction(signature, 'confirmed')
console.log('Position opened:', signature)Step 4: Monitor and Close
Poll GET /api/v1/positions?owner=<wallet>&status=OPEN to monitor open positions, then build a close transaction when ready.
# Get a close quote first
curl -X POST https://api.lavarage.xyz/api/v1/positions/close-quote \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"positionAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
"userPublicKey": "GsbwXfJraMomNxBcjK7xK2xQx5MQgQx4Ld8QkLeNmA3v"
}'
# Then build the close transaction
curl -X POST https://api.lavarage.xyz/api/v1/positions/close \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"positionAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
"userPublicKey": "GsbwXfJraMomNxBcjK7xK2xQx5MQgQx4Ld8QkLeNmA3v",
"slippageBps": 50
}'Sign and submit the returned transaction field the same way as Step 3.
Updated 4 days ago