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
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); // SynchronousGet 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