UNPKG

@frakt-protocol/frakt-sdk

Version:

Frakt SDK for interacting with frakt.xyz protocols

54 lines (53 loc) 3.13 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.paybackLoanWithGraceIx = void 0; const anchor_1 = require("@project-serum/anchor"); const helpers_1 = require("../../helpers"); const common_1 = require("../../../common"); const constants_1 = require("../../constants"); const paybackLoanWithGraceIx = ({ programId, connection, user, admin, liquidationLot, loan, nftMint, liquidityPool, collectionInfo, royaltyAddress, }) => __awaiter(void 0, void 0, void 0, function* () { const encoder = new TextEncoder(); const program = (0, helpers_1.returnAnchorProgram)(programId, connection); const [communityPoolsAuthority, bumpPoolsAuth] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('nftlendingv2'), programId.toBuffer()], program.programId); const [liqOwner] = yield anchor_1.web3.PublicKey.findProgramAddress([encoder.encode('nftlendingv2'), liquidityPool.toBuffer()], program.programId); const nftUserTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(user, nftMint); const vaultNftTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(communityPoolsAuthority, nftMint); let instructions = []; const nftUserTokenAccountInfo = yield connection.getAccountInfo(nftUserTokenAccount); if (!nftUserTokenAccountInfo) instructions = instructions.concat((0, common_1.createAssociatedTokenAccountInstruction)(nftUserTokenAccount, user, user, nftMint)); const editionId = (0, helpers_1.getMetaplexEditionPda)(nftMint); const mainIx = program.instruction.paybackWithGrace(bumpPoolsAuth, { accounts: { loan: loan, liquidityPool, liquidationLot, collectionInfo, user: user, admin, nftMint: nftMint, nftUserTokenAccount: nftUserTokenAccount, royaltyAddress, liqOwner, communityPoolsAuthority, vaultNftTokenAccount, systemProgram: anchor_1.web3.SystemProgram.programId, tokenProgram: anchor_1.utils.token.TOKEN_PROGRAM_ID, associatedTokenProgram: anchor_1.utils.token.ASSOCIATED_PROGRAM_ID, metadataProgram: constants_1.METADATA_PROGRAM_PUBKEY, editionInfo: editionId, }, }); instructions = instructions.concat(mainIx); return { ixs: instructions }; }); exports.paybackLoanWithGraceIx = paybackLoanWithGraceIx;