0.1.7 • Published 8 months ago

@lifinity/sdk-v2-eclipse v0.1.7

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

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.

0.1.7

8 months ago

0.1.6

8 months ago

0.1.5

8 months ago

0.1.2

9 months ago

0.1.4

8 months ago

0.1.3

8 months ago

0.1.1

9 months ago

0.1.0

9 months ago