yarn install @lifinity/sdk-v2
- Get pools
import { getPools, LIFINITY_ECLIPSE_PROGRAM_ID } from '@lifinity/sdk-v2';
const connection: Connection = new Connection("https://api.mainnet-beta.solana.com");
const pools = await getPools(connection);
console.log("pools =", pools);
- Get swap amount
import { Connection, PublicKey } from '@solana/web3.js';
import { getAmountOut, LIFINITY_ECLIPSE_PROGRAM_ID } from '@lifinity/sdk-v2';
const connection: Connection = new Connection("https://api.mainnet-beta.solana.com");
const fromMint: PublicKey = new PublicKey("---Mint address of the input token---");
const toMint: PublicKey = new PublicKey("---Mint address of the output token---");
const amountIn: number = 1; // Input amount
const slippage: number = 1; // Slippage (%)
const pool = await getPool(connection, fromMint, toMint);
const ammData = await getAmm(connection, pool.ammPubkey);
const res = await getAmountOut(connection, ammData, amountIn, fromMint, slippage);
console.log("amountIn: number =", res.amountIn);
console.log("amountOut: number =", res.amountOut);
console.log("amountOutWithSlippage: number =", res.amountOutWithSlippage);
console.log("priceImpact: number =", res.priceImpact);
console.log("fee: number =", res.fee);
console.log("feePercent: number =", res.feePercent);
- Get swap instruction
import { Connection, PublicKey } from '@solana/web3.js';
import { getSwapInstruction } from '@lifinity/sdk-v2'
const connection: Connection = new Connection("https://api.mainnet-beta.solana.com");
const ownerAccount: PublicKey = new PublicKey("---User's Solana address---")
const fromMint: PublicKey = new PublicKey("---Mint address of the input token---");
const toMint: PublicKey = new PublicKey("---Mint address of the output token---");
const amountIn: number = 1; // Input amount
const minimumOut: number = 100; // Output amount
const fromUserAccount: PublicKey = new PublicKey("---User's input token account---");
const toUserAccount: PublicKey = new PublicKey("---User's output token account---");
const pool = await getPool(connection, fromMint, toMint);
const ammData = await getAmm(connection, pool.ammPubkey);
const swapInstruction = await getSwapInstruction(connection, ownerAccount, amountIn, minimumOut, ammData, fromMint, toMint, fromUserAccount, toUserAccount);
console.log("swapInstruction: TransactionInstruction =", swapInstruction);
Copyright © 2022 LIFINITY FOUNDATION All Rights Reserved.