UNPKG

@frakt-protocol/frakt-sdk

Version:

Frakt SDK for interacting with frakt.xyz protocols

44 lines (43 loc) 2.91 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.unstakeInFusion = void 0; const anchor_1 = require("@project-serum/anchor"); const spl_token_1 = require("@solana/spl-token"); const common_1 = require("../../common"); const unstakeInFusion = (programId, provider, userPublicKey, mintToStake, mintToHarvest, unstakeAmount) => __awaiter(void 0, void 0, void 0, function* () { const encoder = new TextEncoder(); let program = yield (0, common_1.returnAnchorMultiRewardStaking)(programId, provider); const [vaultOwnerPda, bump] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode("vaultownerpda"), programId.toBuffer()], program.programId); const userToStake = yield (0, common_1.findAssociatedTokenAddress)(userPublicKey, mintToStake); const vaultTokenAccountInput = yield (0, common_1.findAssociatedTokenAddress)(vaultOwnerPda, mintToStake); const [mainRouter, bumpRouter] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode("mainRouter"), mintToStake.toBuffer(), mintToHarvest.toBuffer()], program.programId); const [configInput, bumpConfigInput] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode("mainConfigAccountInput"), mintToStake.toBuffer(), mainRouter.toBuffer()], program.programId); const [stakeAccount, bumpStake] = yield anchor_1.web3.PublicKey.findProgramAddress([userPublicKey.toBuffer(), mainRouter.toBuffer()], program.programId); return program.instruction.unstakeSingle(bump, bumpConfigInput, bumpRouter, bumpStake, unstakeAmount, { accounts: { initializer: userPublicKey, userTokenAccountInput: userToStake, tokenMintInput: mintToStake, tokenMintOutput: mintToHarvest, vaultOwnerPda, vaultTokenAccountInput, stakeAccount: stakeAccount, mainRouter, configInput, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY, systemProgram: anchor_1.web3.SystemProgram.programId, tokenProgram: spl_token_1.TOKEN_PROGRAM_ID, associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, }, }); }); exports.unstakeInFusion = unstakeInFusion;