---
updatedAt: 2026-07-15T08:50:33.000Z
agentTools:
  projectIndex: https://lavarage-api.readme.io/llms.txt
---

# 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

1. An API key — apply at [https://v2.lavarage.xyz/partners](https://v2.lavarage.xyz/partners "https://v2.lavarage.xyz/partners") or submit `POST /api/v1/partners/apply`
2. A Solana wallet adapter (or any signing implementation) on the client side
3. 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.

> **For SOL LONG, pass&#x20;**`quoteTokenMint: USDC`**&#x20;explicitly** — there is no SOL/SOL offer; defaulting causes `NO_OFFER_FOR_TOKEN` because base==quote. The example below uses cbBTC LONG against USDC, which is a real market you can call right now.

```bash
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": "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij",
    "userPublicKey": "GsbwXfJraMomNxBcjK7xK2xQx5MQgQx4Ld8QkLeNmA3v",
    "collateralAmount": "10000000",
    "leverage": 3,
    "side": "LONG",
    "quoteTokenMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
  }'
```

**Response:**

```json
{
  "inAmount": "10000000",
  "outAmount": "300",
  "priceImpactPct": "0.12",
  "otherAmountThreshold": "298",
  "inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "outputMint": "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij",
  "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.

```bash
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": "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij",
    "userPublicKey": "GsbwXfJraMomNxBcjK7xK2xQx5MQgQx4Ld8QkLeNmA3v",
    "collateralAmount": "10000000",
    "leverage": 3,
    "side": "LONG",
    "quoteTokenMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "slippageBps": 50
  }'
```

**Response:**

```json
{
  "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.

```typescript
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.

```bash
# 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.