0.0.13 • Published 2 days ago

@flowx-pkg/ts-sdk v0.0.13

Weekly downloads
-
License
MIT
Repository
-
Last release
2 days ago

Official FlowX Finance TypeScript SDK for Sui

An FlowX Typescript SDK is a software development kit that allows developers to interact with FlowX protocols using the Typescript programming language.

Features

  • Retrieve user liquidity.
  • Retrieve list farm genesix and user position.
  • Retrieve list farm FaaS and user position.

Getting Started

npm i @flowx-pkg/ts-sdk

FlowX SDK

1. Retrieve user liquidity

import {getLiquidity} from "@flowx-pkg/ts-sdk"

let address: string = "..." //required: user address
let sortType: string = "..." //optional (lpValue, userLpBalance, totalLpSupply)
let sortOrder: stringr = "..." //optional (ascending , descending)
let userLiquidity: ILiquidity = await getLiquidity(address, sortType, sortOrder)

2. Retrieve list farm genesix and user position

import {getGenesisFarm} from "@flowx-pkg/ts-sdk"

let address: string = "..." //optional: user address
let listGenesisX: IGenesisPoolsData[] = await getGenesisFarm(address)

3. Retrieve list farm FaaS v2 and user position

import {getFaasV2} from "@flowx-pkg/ts-sdk"

let address: string = "..." //optional: user address
let listFaaS: IFaasV2[] = await getFaasV2(address)

4. SWAP Function

import {calculateAmountIn, swapExactInput} from "@flowx-pkg/ts-sdk"

const coinIn = {
	type: "0x2::sui::SUI",
	symbol: "SUI",
	decimals: 9,
};
const coinOut = {
	type: "0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",
	symbol: "wUSDC",
	decimals: 6,
};

const data = await calculateAmountIn(0.8, coinIn, coinOut); //0.8 mean the amount you want to swap

const tx: TransactionBock = await swapExactInput(
	false, //it should be false for now
	data.amountIn, //amount want to swap
	data.amountOut, //amount want to receive
	data.trades, //trades from calculate amount
	coinIn, //coin In data
	coinOut, //coin Out data
	"YOUR_ACCOUNT_RECEIVE TOKEN", //amount swap
	0.005 //slippage (0.05%)
);

5. SWAP Aggregator

getSmartRouting

Retrieve the most optimal route of smart routing for swap and amount of token user may receive.

import {getSmartRouting} from "@flowx-pkg/ts-sdk"
const smartRouting:ISmartRouting  = await getSmartRouting(
	tokenIn,
	tokenOut,
	amountIn,
	signal,
	source
	)

interface ISmartRouting {
	paths: ISmartPathV3[],
	amountOut:string
}
ArgumentsDescriptionType
tokenInType of token instring
tokenOutType of token outstring
amountInAmmount of token instring
signalSignal to abort current queryAbortController
source(Optional) List dex that use to searching smart route. Default is included all dexArray("FLOWX","FLOWX_CLMM","KRIYA","TURBOS",CETUS", "AFTERMATH")

estimateGasFee

Estimate gas fee for conducting transaction, amount token out and list of amount token out from each path of smart routing

import {estimateGasFee} from "@flowx-pkg/ts-sdk"
const result:IEstimateGasResult|undefined  = await estimateGasFee(
	tx,
	account)

interface IEstimateGasResult {
	fee: string;
  	amountOut: string;
 	pathsAmountOut: string[];
}

txBuild

Retrieve the transaction block for swap

import {txBuild} from "@flowx-pkg/ts-sdk"
const tx: TransactionBock = await txBuild(
	listSmartPath,
	slippage,
	amountIn,
	amountOut,
	coinInType,
	account,
	pathsAmountOut)
ArgumentsDescriptionType
listSmartPathList all path of smart routing for current swap, each path may includes one or many routeISmartPathV3[]
slippageSlippage percent (Ex: 1% = 0.01)string
amountInAmount in by decimal value.string
amountOutAmount out by decimal value. In case build Tx for inspect transaction: This amount is equivalent to amountOut get from getSmartRouting. In case build Tx for actual transaction: This amount is equivalent to amountOut get from estimateGasFeestring
coinInTypeType of token instring
accountAddress conducting swap transactionstring
pathsAmountOut(Optional) List amount actual calculated after estimateGasFee. Add this argument may turn txBuild to tx for actual transaction. Pass it may turn txBuild to tx for devInpsecTransactionstring[]

Usage

import {txBuild, estimateGasFee, getSmartRouting} from "@flowx-pkg/ts-sdk"

const {paths,amountOut} = await getSmartRouting(coinInType,coinOutType,decimalInAmount,abortQuerySmartRef.current.signal)

const txb = await txBuild(paths,slippage,amountIn,amountOut,coinInType,account);

const { fee, amountOut:amountOutDev, pathsAmountOut } = await estimateGasFee(txb, account);

const tx = await txBuild(paths,slippage,amountIn,amountOutDev,coinInType,account,pathsAmountOut)
0.0.13

2 days ago

0.0.12

2 months ago

0.0.10

3 months ago

0.0.11

3 months ago

0.0.9

3 months ago

0.0.8

5 months ago

0.0.7

5 months ago

0.0.6

5 months ago

0.0.5

6 months ago

0.0.4

6 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago