UNPKG

@frakt-protocol/frakt-sdk

Version:

Frakt SDK for interacting with frakt.xyz protocols

53 lines (52 loc) 3 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.redeemWinningLotTicket = void 0; const anchor_1 = require("@project-serum/anchor"); const helpers_1 = require("../../helpers"); const common_1 = require("../../../common"); const __1 = require("../.."); const constants_1 = require("../../constants"); const redeemWinningLotTicket = ({ programId, connection, user, liquidationLot, liquidityPool, collectionInfo, loan, admin, lotTicket, royaltyAddress, nftMint, 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, liqOwnerBump] = 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); const editionId = (0, __1.getMetaplexEditionPda)(nftMint); const instr = program.instruction.redeemWinningLotTicket(bumpPoolsAuth, { accounts: { loan: loan, liquidityPool, liquidationLot, lotTicket, 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, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY, }, }); const transaction = new anchor_1.web3.Transaction().add(instr); yield sendTxn(transaction); }); exports.redeemWinningLotTicket = redeemWinningLotTicket;