Token-Pair Endpoints

Open positions by token mint address — no offer lookup needed.

Overview

The token-pair endpoints accept a baseTokenMint instead of an explicit offerPublicKey. The server automatically selects the best matching liquidity pool (offer) — you never need to query offers directly.

For new integrations, always use these endpoints. The offerPublicKey endpoints (POST /positions/open) exist for advanced use cases but require you to discover and manage offer addresses manually.

POST /api/v1/positions/quote-by-token

Get a price preview without building a transaction. Use this to display expected entry price, slippage, and fees before asking the user to confirm.

Request:

For SOL LONG, pass quoteTokenMint: USDC explicitly — there is no SOL/SOL offer; defaulting causes NO_OFFER_FOR_TOKEN because base==quote. The example below uses cbBTC LONG against USDC.

{
  "baseTokenMint": "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij",
  "userPublicKey": "GsbwXfJraMomNxBcjK7xK2xQx5MQgQx4Ld8QkLeNmA3v",
  "collateralAmount": "10000000",
  "leverage": 3,
  "side": "LONG",
  "quoteTokenMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "slippageBps": 50
}
FieldTypeRequiredDescription
baseTokenMintstringYesToken mint you want to go long/short on (base58)
userPublicKeystringYesUser's wallet address (base58)
collateralAmountstringYesCollateral in the quote token's smallest units (lamports for WSOL, 1e6 for USDC, 1e8 for cbBTC)
leveragenumberYesMultiplier between 1.1 and 100
sidestringYes"LONG" or "SHORT"
quoteTokenMintstringNo*Quote token. *Required for SOL LONG (pass USDC) — there is no SOL/SOL offer.
slippageBpsnumberNoSlippage tolerance in bps (default: 50, max: 10000)

Response: Returns a SwapQuote object:

{
  "inAmount": "10000000",
  "outAmount": "300",
  "priceImpactPct": "0.12",
  "otherAmountThreshold": "298",
  "inputMint": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
  "outputMint": "cbbtcf3aa214zXHbiAZQwf4122FBYbraNdFqgw4iMij",
  "slippageBps": 50
}

POST /api/v1/positions/open-by-token

Build an unsigned Solana transaction to open a leveraged position. Takes the same request shape as quote-by-token.

Request: Identical to quote-by-token above.

Response:

{
  "transaction": "AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAkP...",
  "positionAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
  "lastValidBlockHeight": 285432100,
  "quote": { "outAmount": "9950000000", "priceImpactPct": 0.12, "slippageBps": 50 }
}

Deserialise with VersionedTransaction.deserialize(bs58.decode(response.transaction)), sign with the user's wallet, and submit.

How Offer Matching Works

When you call open-by-token, the server:

  1. Queries active offers for the requested token pair and side
  2. Filters by available liquidity (must cover collateralAmount × (leverage - 1))
  3. Sorts by best terms (highest leverage limit, lowest utilization)
  4. Selects the top offer and builds the transaction against it

If no matching offer exists, the server returns 404 NO_OFFER_FOR_TOKEN.

Supported Sides

SideCollateral TokenWhat Happens
LONGWSOL (default) or USDCProtocol borrows SOL/USDC, swaps into the target token. Profit when price rises.
SHORTUSDCProtocol borrows the volatile token, swaps to USDC. Profit when price falls.

Short position support is currently in beta. Contact https://lavarage.xyz/partners for access.