Skip to main content
The getQuote function calculates a quote for a potential trade on the Exponent orderbook.

Usage

import { Connection } from "@solana/web3.js";

// Get the current Unix timestamp from the onchain clock
const clock = await connection.getClock();
const unixNow = Number(clock.unixTimestamp);

const quote = orderbook.getQuote({
  // Input amount in lamports
  inAmount: 1_000_000_000,
  // The direction of the trade
  direction: QuoteDirection.SY_TO_PT,
  // Current Unix timestamp from the onchain clock
  unixNow: unixNow,
  // The SY exchange rate (e.g., 1.000009210084)
  syExchangeRate: 1.000009210084,
});

console.log("Expected output:", quote.outAmount);
console.log("Maker fees:", quote.makerFees);
console.log("Taker fees:", quote.takerFees);

Parameters

ParameterTypeRequiredDescription
inAmountnumberYesInput amount in lamports
directionQuoteDirectionYesThe direction of the trade
unixNownumberYesCurrent Unix timestamp from the onchain clock
syExchangeRatenumberYesThe SY exchange rate (e.g., 1.000009210084)
priceApynumberNoPrice in APY percentage (e.g., 5.5 for 5.5%)

QuoteDirection

The QuoteDirection enum specifies the trade direction:
enum QuoteDirection {
  BASE_TO_YT,
  BASE_TO_PT,
  YT_TO_BASE,
  PT_TO_BASE,
  SY_TO_YT,
  SY_TO_PT,
  YT_TO_SY,
  PT_TO_SY,
}

Getting the Unix Timestamp

Use the onchain clock for accurate timing. Avoid Date.now() as it may drift from the onchain clock:
import { Connection } from "@solana/web3.js";

const connection = new Connection("https://api.mainnet-beta.solana.com");
const clock = await connection.getClock();
const unixNow = Number(clock.unixTimestamp);

Returns

Returns an object with:
  • outAmount - Expected output amount in lamports
  • makerFees - Total maker fees charged in lamports
  • takerFees - Total taker fees charged in lamports