UNPKG

@symmetry-hq/baskets-v2-sdk

Version:

Symmetry Baskets V2 SDK

64 lines (55 loc) 2.32 kB
// Core dependencies import { Program } from "@coral-xyz/anchor"; import { PublicKey, SystemProgram, SYSVAR_INSTRUCTIONS_PUBKEY, TransactionInstruction } from "@solana/web3.js"; import { TOKEN_PROGRAM_ID } from "@solana/spl-token"; // Local imports import { BasketsProgram } from "../../idl/types"; import { getAta, getBasketPda, getRebalanceStateAccount } from "../../utils/programAccounts"; import { REBALANCE_FEE_WALLET } from "../../utils/constants"; import { WithdrawState } from "../../state/withdrawState"; export async function sellDepositAfterRebalanceIx(params: { program: Program<BasketsProgram>, withdrawStateData: WithdrawState, payer: PublicKey, fromTokenMint: PublicKey, }): Promise<TransactionInstruction> { // Destructure params const { program, withdrawStateData, payer, fromTokenMint } = params; const toTokenMint = withdrawStateData.destinationMint; // Get withdraw state data and seeds const withdrawStateSeed = withdrawStateData.withdrawStateSeed; const basket = withdrawStateData.basket; // Get basket pda const basketPda = getBasketPda(basket); // Get token accounts const basketFromTokenAccount = getAta(basketPda, fromTokenMint); const workerFromTokenAccount = getAta(payer, fromTokenMint); const basketToTokenAccount = getAta(basketPda, toTokenMint); const workerToTokenAccount = getAta(payer, toTokenMint); // Get rebalance accounts const rebalanceState = getRebalanceStateAccount(); const rebalanceFeeAccount = getAta(REBALANCE_FEE_WALLET, toTokenMint); // Build and return instruction return await program.methods .sellDepositAfterRebalance( withdrawStateSeed ) .accountsStrict({ worker: payer, basket, basketPda, withdrawState: withdrawStateData.ownAddress, fromTokenMint, basketFromTokenAccount, workerFromTokenAccount, toTokenMint, basketToTokenAccount, workerToTokenAccount, rebalanceState, rebalanceFeeAccount, instructionsSysvar: SYSVAR_INSTRUCTIONS_PUBKEY, systemProgram: SystemProgram.programId, tokenProgram: TOKEN_PROGRAM_ID, }) .instruction(); }