JSPM

  • Created
  • Published
  • Downloads 12
  • Score
    100M100P100Q72112F
  • License ISC

Exchange functionality using symmetry funds liquidity

Package Exports

  • @symmetry-hq/liquidity-sdk
  • @symmetry-hq/liquidity-sdk/dist/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 (@symmetry-hq/liquidity-sdk) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

liquidity-sdk

Exchange functionality using symmetry funds liquidity

Initialization

import { TokenSwap } from "@symmetry-hq/liquidity-sdk";

let tokenSwap = await TokenSwap.init(
    // rpc connection
    connection: Connection,
    // wallet (optional | can be provided later, using funds.setWallet
    wallet: Wallet,
);

Executing swap

// load routeInfo based on tokenFrom, tokenTo and fromAmount
let route = tokenSwap.loadSwap(
    tokenFrom: PublicKey, 
    tokenTo: PublicKey,
    fromAmount: number,
);

// generate swap instruction
let result = await tokenSwap.generateSwapInstruction(
    route,
    fromTokenAccount,
    toTokenAccount,
);

// for sol swap, wSol token accounts should be provided.

Tools

// get available tokens for swap
tokenSwap.getTokenList();

// update liquidity sources(liquidity info isn't updated after TokenSwap.init())
await tokenSwap.updateLiquiditySources();

// check liquidity in a specific fund
let liquidityInfos: {
    tokenMint: string
    coingeckoId: string,
    userCanSellToFund: number,
    userCanBuyFromFund: number,
}[] = await tokenSwap.getLiquidityInfo(fundPubkey: PublicKey);