UNPKG

@frakt-protocol/frakt-sdk

Version:

Frakt SDK for interacting with frakt.xyz protocols

66 lines (65 loc) 3.35 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.paybackLoan = 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 paybackLoan = ({ programId, connection, user, admin, loan, nftMint, liquidityPool, collectionInfo, royaltyAddress, paybackAmount = new anchor_1.BN(0), sendTxn, }) => __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 editionId = (0, helpers_1.getMetaplexEditionPda)(nftMint); const instruction = program.instruction.paybackLoan(bumpPoolsAuth, paybackAmount, { accounts: { loan: loan, liquidityPool: liquidityPool, collectionInfo, user: user, admin, nftMint: nftMint, nftUserTokenAccount: nftUserTokenAccount, royaltyAddress, liqOwner, communityPoolsAuthority, systemProgram: anchor_1.web3.SystemProgram.programId, tokenProgram: anchor_1.utils.token.TOKEN_PROGRAM_ID, // associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID, metadataProgram: constants_1.METADATA_PROGRAM_PUBKEY, editionInfo: editionId, }, }); // program.instruction.paybackLoan(bumpPoolsAuth, { // accounts: { // loan: loan, // liquidityPool: liquidityPool, // collectionInfo, // user: user, // admin, // nftMint: nftMint, // nftUserTokenAccount: nftUserTokenAccount, // royaltyAddress, // liqOwner, // communityPoolsAuthority, // systemProgram: web3.SystemProgram.programId, // tokenProgram: utils.token.TOKEN_PROGRAM_ID, // // associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID, // metadataProgram: METADATA_PROGRAM_PUBKEY, // editionInfo: editionId, // }, // }); const transaction = new anchor_1.web3.Transaction().add(instruction); yield sendTxn(transaction); }); exports.paybackLoan = paybackLoan;