@lifinity/sdk-v2-eclipse
TypeScript icon, indicating that this package has built-in type declarations

0.1.9 • Public • Published

lifinity-sdk-v2

Installation

yarn install @lifinity/sdk-v2

Usage

  • 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.

Readme

Keywords

none

Package Sidebar

Install

npm i @lifinity/sdk-v2-eclipse

Weekly Downloads

54

Version

0.1.9

License

MIT

Unpacked Size

163 kB

Total Files

34

Last publish

Collaborators

  • lifinity