@symmetry-hq/liquidity-sdk
v0.0.48
Published
Exchange functionality using symmetry funds liquidity
Downloads
99
Readme
Symmetry Liquidity SDK
Exchange functionality using symmetry funds liquidity
Documentation: https://docs.symmetry.fi/sdks/liquidity-sdk
Initialization
import { TokenSwap } from "@symmetry-hq/liquidity-sdk";
let tokenSwap = await TokenSwap.init(
// rpc connection
connection: Connection,
// wallet (optional | can be provided later, using tokenSwap.setWallet
wallet: Wallet,
);
OR
import { TokenSwap } from "@symmetry-hq/liquidity-sdk";
let accountInfos = await TokenSwap.getAccountInfosForTokenSwap(connection);
let tokenSwap = new TokenSwap(accountInfos); // Synchronous
Update
await tokenSwap.updateLiquiditySources();
OR
let pubkeys: PublicKey[] = tokenSwap.getAccountsForUpdate(); // Synchronous
let accountInfos: AccountInfo<Buffer>[] =
await connection.getMultipleAccountsInfo(pubkeys);
tokenSwap.update(accountInfos); // Synchronous
Get output amount and Route data
let routeData: RouteData = tokenSwap.getRouteData( // Synchronous
tokenFrom: PublicKey, // mint address
tokenTo: PublicKey, // mint address
fromAmount: number,
);
type RouteData = {
fromAmount: number,
toAmount: number, // Expected output amount
fromTokenId: number,
toTokenId: number,
swapAccounts: {...} // accounts used for swap
}
Executing swap
let tx: TransactionSignature = await tokenSwap.executeSwap(
routeData,
fromTokenAccount?: PublicKey, // default = user's ATA
toTokenAccount?: PublicKey, // default = user's ATA
slippage?: number, // slippage percentage 1 = 1%, default = 0.5%
);
Helpers
// set wallet before executing swap if it wasn't provided upon initialization
tokenSwap.setWallet(wallet: Wallet); // Synchronous
// generate swap instruction
let instruction: TransactionInstruction = await tokenSwap
.generateSwapInstruction(
routeData: RouteData,
fromTokenAccount: PublicKey,
toTokenAccount: PublicKey,
user?: PublicKey, // no need to provide if wallet was provided,
slippage?: number, // slippage percentage 1 = 1%, default = 0.5%
);
// get available tokens for swap
let tokenList: {
tokenId: number,
coingeckoId: string,
tokenMint: string,
}[] = tokenSwap.getTokenList(); // Synchronous