UNPKG

fbonds-core

Version:

Banx protocol sdk

47 lines (46 loc) 2.59 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.swapToBanxSol = void 0; const anchor_1 = require("@coral-xyz/anchor"); const constants_1 = require("../../constants"); const common_1 = require("../../../common"); const spl_stake_pool_1 = require("@solana/spl-stake-pool"); const swapToBanxSol = (_a) => __awaiter(void 0, [_a], void 0, function* ({ programId, connection, accounts, args, sendTxn, }) { const instructions = []; // Create token account if not specified const associatedAddress = yield (0, common_1.findAssociatedTokenAddress)(accounts.userPubkey, constants_1.BANX_SOL_MINT); instructions.push(...(0, common_1.createAssociatedTokenAccountInstructionIdimpotent)(associatedAddress, accounts.userPubkey, accounts.userPubkey, constants_1.BANX_SOL_MINT)); const [withdrawAuthority] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.BANX_SOL_POOL.toBuffer(), Buffer.from('withdraw')], constants_1.SANCTUM_POOL_PROGRAM); let stakePoolInstr = spl_stake_pool_1.StakePoolInstruction.depositSol({ stakePool: constants_1.BANX_SOL_POOL, reserveStake: constants_1.RESERVE_STAKE_BANX_SOL, fundingAccount: accounts.userPubkey, destinationPoolAccount: associatedAddress, managerFeeAccount: constants_1.MANAGER_BANX_SOL_FEE, referralPoolAccount: associatedAddress, poolMint: constants_1.BANX_SOL_MINT, lamports: Number(args.amount), withdrawAuthority, }); stakePoolInstr.programId = constants_1.SANCTUM_POOL_PROGRAM; instructions.push(stakePoolInstr); const transaction = new anchor_1.web3.Transaction(); for (let instruction of instructions) transaction.add(instruction); let signers = []; yield sendTxn(transaction, signers); return { instructions, signers, }; }); exports.swapToBanxSol = swapToBanxSol;