fbonds-core
Version:
Banx protocol sdk
49 lines (48 loc) • 2.54 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.closeTokenAccountBanxSol = void 0;
const anchor_1 = require("@coral-xyz/anchor");
const token_1 = require("@coral-xyz/anchor/dist/cjs/utils/token");
const spl_token_1 = require("@solana/spl-token");
const common_1 = require("../../../common");
const constants_1 = require("../../constants");
const helpers_1 = require("../../helpers");
const closeTokenAccountBanxSol = (_a) => __awaiter(void 0, [_a], void 0, function* ({ programId, connection, accounts, sendTxn, }) {
const program = (0, helpers_1.returnAnchorProgram)(connection);
const instructions = [];
const userBanxSolTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(accounts.userPubkey, constants_1.BANX_SOL_MINT);
const feeReciverBanxSolTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(accounts.feeReciver, constants_1.BANX_SOL_MINT);
instructions.push(yield program.methods
.closeTokenAccountsBanxSol()
.accountsStrict({
user: accounts.userPubkey,
systemProgram: anchor_1.web3.SystemProgram.programId,
rent: anchor_1.web3.SYSVAR_RENT_PUBKEY,
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID,
banxSolTokenAccount: userBanxSolTokenAccount,
protocolFeeReciver: accounts.feeReciver,
banxSolFeeTokenAccount: feeReciverBanxSolTokenAccount,
banxSolMint: constants_1.BANX_SOL_MINT,
})
.instruction());
const transaction = new anchor_1.web3.Transaction();
for (let instruction of instructions)
transaction.add(instruction);
const signers = [];
yield sendTxn(transaction, signers);
return {
instructions,
signers,
};
});
exports.closeTokenAccountBanxSol = closeTokenAccountBanxSol;