Jupiter Object
The Jupiter Aggregator global object and methods.
Jupiter Object Documentation
The Jupiter
class provides methods to interact with the Jupiter decentralized exchange aggregator on the Solana blockchain. It supports watching swap events, fetching quotes, and executing swaps. This class extends the Subscribable
class, enabling subscription to Jupiter-related events.
Methods
watchSwaps
Description Watches for swap events executed via Jupiter and invokes a callback when a swap occurs.
Signature
public async watchSwaps(
callback: (event: JupiterSwap) => void
): Promise<SubscriptionResult>
Parameters
callback
((event: JupiterSwap) => void
): The callback function to handle swap events.
Returns
Promise<SubscriptionResult>
: The result of the subscription operation.
Example Usage
await jupiter.watchSwaps((event) => {
console.log("Swap event:", event);
});
quote
Description Fetches a swap quote based on the specified parameters, including input and output tokens, amounts, and slippage tolerance.
Signature
public async quote(request: JupiterQuoteRequest): Promise<QuoteResponse>
Parameters
request
(JupiterQuoteRequest
): An object containing the quote request details, such as:inputMint
(string
): The mint address of the input token.outputMint
(string
): The mint address of the output token.amount
(number | string
): The amount of the input token.slippageBps
(number
): The slippage tolerance in basis points.Other optional fields from
QuoteGetRequest
.
Returns
Promise<QuoteResponse>
: A quote response object containing swap details, such as routes, estimated amounts, and fees.
Example Usage
const quote = await jupiter.quote({
inputMint: "So11111111111111111111111111111111111111112", // SOL mint address
outputMint: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", // USDC mint address
amount: 1000000, // 1 SOL in lamports
slippageBps: 50, // 0.5% slippage tolerance
});
console.log(quote);
swap
Description Performs a swap using Jupiter, executing the transaction with the specified parameters.
Signature
public async swap(request: JupiterSwapRequest): Promise<JupiterSwapResponse>
Parameters
request
(JupiterSwapRequest
): An object containing the swap request details, including:routePlan
(any
): The swap route plan.wrapAndUnwrapSol
(boolean
): Whether to wrap/unwrap SOL during the swap.prioritizationFeeLamports
(number | string
): Optional. The prioritization fee in lamports for faster confirmation.
Returns
Promise<JupiterSwapResponse>
: An object containing:transaction
(Transaction | VersionedTransaction
): The swap transaction.lastValidBlockHeight
(number
): The last valid block height for the transaction.prioritizationFeeLamports
(number
): Optional. The prioritization fee in lamports.
Example Usage
const swapResponse = await jupiter.swap({
routePlan: myRoutePlan,
wrapAndUnwrapSol: true,
prioritizationFeeLamports: 5000,
});
console.log("Transaction:", swapResponse.transaction);
console.log("Last valid block height:", swapResponse.lastValidBlockHeight);
Types
JupiterSwap
Represents a Jupiter swap event.
type JupiterSwap = {
service: "jupiter";
transaction: VersionedTransactionResponse;
swap: {
owner: string;
transferAuthority: string;
programId: string;
signature: string;
timestamp: Date;
legCount: number;
volumeInUSD: number;
inSymbol: string;
inAmount: BigInt;
inAmountInDecimal?: number;
inAmountInUSD: number;
inMint: string;
outSymbol: string;
outAmount: BigInt;
outAmountInDecimal?: number;
outAmountInUSD: number;
outMint: string;
instruction: string;
exactInAmount: BigInt;
exactInAmountInUSD: number;
exactOutAmount: BigInt;
exactOutAmountInUSD: number;
swapData: JSON;
feeTokenPubkey?: string;
feeOwner?: string;
feeSymbol?: string;
feeAmount?: BigInt;
feeAmountInDecimal?: number;
feeAmountInUSD?: number;
feeMint?: string;
tokenLedger?: string;
lastAccount: string;
};
};
JupiterQuoteRequest
Request type for fetching a quote.
type JupiterQuoteRequest = Omit<QuoteGetRequest, "amount"> & {
amount: number | string;
};
JupiterSwapRequest
Request type for performing a swap.
type JupiterSwapRequest = Omit<
SwapRequest,
"userPublicKey" | "prioritizationFeeLamports"
> & {
prioritizationFeeLamports?: number | string;
};
RoboqoJupiterSwapResponse
Internal response type for a swap operation.
type RoboqoJupiterSwapResponse = {
transaction: string;
lastValidBlockHeight: number;
prioritizationFeeLamports?: number;
};
JupiterSwapResponse
Response type for a swap operation.
type JupiterSwapResponse = {
transaction: Transaction | VersionedTransaction;
lastValidBlockHeight: number;
prioritizationFeeLamports?: number;
};
Last updated