2.0.2 • Published 11 months ago
@lifinity/sdk-v2 v2.0.2
lifinity-sdk-v2
Installation
yarn install @lifinity/sdk-v2
Usage
- Get pools
import { getPools, LIFINITY_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_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.
2.0.2
11 months ago
1.0.26
1 year ago
2.0.1
11 months ago
2.0.0
11 months ago
1.0.25
1 year ago
1.0.24
2 years ago
1.0.23
2 years ago
1.0.22
2 years ago
1.0.21
2 years ago
1.0.20
2 years ago
1.0.19
2 years ago
1.0.17
2 years ago
1.0.16
2 years ago
1.0.15
2 years ago
1.0.14
2 years ago
1.0.13
2 years ago
1.0.12
2 years ago
1.0.10
2 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.2
3 years ago
1.0.4
3 years ago
1.0.1
3 years ago
1.0.0
3 years ago