JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 191
  • Score
    100M100P100Q130602F
  • License MIT

lifinity sdk v2

Package Exports

  • @lifinity/sdk-v2
  • @lifinity/sdk-v2/lib/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@lifinity/sdk-v2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.