UNPKG

@symmetry-hq/baskets-v2-sdk

Version:

Symmetry Baskets V2 SDK

52 lines (51 loc) 2.75 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.withdrawIx = withdrawIx; // Core dependencies const anchor_1 = require("@coral-xyz/anchor"); const web3_js_1 = require("@solana/web3.js"); const spl_token_1 = require("@solana/spl-token"); const programAccounts_1 = require("../../utils/programAccounts"); const token_1 = require("@coral-xyz/anchor/dist/cjs/utils/token"); const constants_1 = require("../../utils/constants"); function withdrawIx(params) { return __awaiter(this, void 0, void 0, function* () { // Destructure params const { program, seller, basket, withdrawStateSeed, amountToWithdraw, destinationMint, rebalance } = params; // Get basket token mint const basketTokenMint = (0, programAccounts_1.getBasketTokenMintAccount)(basket); // Get withdraw state account const withdrawState = (0, programAccounts_1.getWithdrawStateAccount)(withdrawStateSeed); // Get token accounts const sellerBasketTokenAccount = (0, programAccounts_1.getAta)(seller, basketTokenMint); const basketWithdrawFeesWallet = (0, programAccounts_1.getWithdrawFeesWallet)(basket); const basketWithdrawFeesTokenAccount = (0, programAccounts_1.getAta)(basketWithdrawFeesWallet, basketTokenMint); const automationFeeWallet = constants_1.AUTOMATION_FEE_WALLET; // Build and return instruction return yield program.methods .basketSell(withdrawStateSeed, new anchor_1.BN(amountToWithdraw), rebalance ? 1 : 0, destinationMint) .accountsStrict({ seller, basket, basketTokenMint, sellerBasketTokenAccount, withdrawState, basketWithdrawFeesWallet, basketWithdrawFeesTokenAccount, automationFeeWallet, systemProgram: web3_js_1.SystemProgram.programId, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID, associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID, }) .instruction(); }); }