@symmetry-hq/baskets-v2-sdk
Version:
Symmetry Baskets V2 SDK
58 lines (57 loc) • 2.99 kB
JavaScript
;
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.sellDepositAfterRebalanceIx = sellDepositAfterRebalanceIx;
const web3_js_1 = require("@solana/web3.js");
const spl_token_1 = require("@solana/spl-token");
const programAccounts_1 = require("../../utils/programAccounts");
const constants_1 = require("../../utils/constants");
function sellDepositAfterRebalanceIx(params) {
return __awaiter(this, void 0, void 0, function* () {
// 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 = (0, programAccounts_1.getBasketPda)(basket);
// Get token accounts
const basketFromTokenAccount = (0, programAccounts_1.getAta)(basketPda, fromTokenMint);
const workerFromTokenAccount = (0, programAccounts_1.getAta)(payer, fromTokenMint);
const basketToTokenAccount = (0, programAccounts_1.getAta)(basketPda, toTokenMint);
const workerToTokenAccount = (0, programAccounts_1.getAta)(payer, toTokenMint);
// Get rebalance accounts
const rebalanceState = (0, programAccounts_1.getRebalanceStateAccount)();
const rebalanceFeeAccount = (0, programAccounts_1.getAta)(constants_1.REBALANCE_FEE_WALLET, toTokenMint);
// Build and return instruction
return yield program.methods
.sellDepositAfterRebalance(withdrawStateSeed)
.accountsStrict({
worker: payer,
basket,
basketPda,
withdrawState: withdrawStateData.ownAddress,
fromTokenMint,
basketFromTokenAccount,
workerFromTokenAccount,
toTokenMint,
basketToTokenAccount,
workerToTokenAccount,
rebalanceState,
rebalanceFeeAccount,
instructionsSysvar: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
systemProgram: web3_js_1.SystemProgram.programId,
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
})
.instruction();
});
}