0.1.6 • Published 1 year ago
@lightprotocol/jup-api-adapter v0.1.6
Jupiter Compression SDK
A wrapper for @jup-ag/api that adds Compressed Token support.
Installation
yarn add @lightprotocol/jup-api-adapterUsage
import { VersionedTransaction } from '@solana/web3.js';
import { createRpc } from '@lightprotocol/stateless.js';
import { createJupiterApiAdapterClient, TokenCompressionMode } from '@lightprotocol/jup-api-adapter';
// Create RPC connection with compression support
const connection = createRpc(RPC_URL, COMPRESSION_URL, COMPRESSION_URL);
// Initialize Jupiter API Adapter client
const jupiterApi = await createJupiterApiAdapterClient(connection);
// Get quote
const quote = await jupiterApi.quoteGetCompressed({
inputMint: INPUT_MINT.toBase58(),
outputMint: OUTPUT_MINT.toBase58(),
amount: AMOUNT,
onlyDirectRoutes: true,
slippageBps: 500,
}, TokenCompressionMode.DecompressInput);
// Get swap transaction
const swapResponse = await jupiterApi.swapPostCompressed({
swapRequest: {
userPublicKey: wallet.publicKey.toBase58(),
quoteResponse: quote,
}
}, { compressionMode: TokenCompressionMode.DecompressInput });
const tx = VersionedTransaction.deserialize(Buffer.from(swapResponse.swapTransaction, 'base64'));
tx.sign([wallet]);
// send ...For more code examples, see this repo.
Overview
Extends DefaultApi class with endpoints:
quoteGetCompressedquoteGetRawCompressedswapInstructionsPostCompressedswapInstructionsPostRawCompressedswapPostCompressedswapPostRawCompressed
Constraints when using one of the compression endpoints
swapModemust beExactInwrapAndUnwrapSolmust betrueskipUserAccountsRpcCallsmust befalseasLegacyTransactionmust befalseuseTokenLedgermust befalseallowOptimizedWrappedSolTokenAccountmust befalsedynamicComputeUnitLimitmust befalseprioritizationFeeLamportsnot supported yet (usecomputeUnitPriceMicroLamportsinstead)compressionModemust be one ofDecompressInput,DecompressAndCompress,CompressOutput.Instructions
- mutates
ComputeBudgetInstructionsto reflect higher cu usage. (PrioritizationFeeLamportsare not supported yet. UsecomputeUnitPriceMicroLamportsinstead.) - extends
addressLookupTableAddresseswith a lookup table for Light Protocol. - extends
setupInstructionsandcloseInstructionswithgetCreateAtaInstructions(tokenIn, tokenOut)getDecompressionSetupInstructions(tokenIn, tokenOut)getCleanupInstructions(tokenIn, tokenOut)
- mutates
Notes
- No safeguards added. Use at your own risk.