UNPKG

hadeswap-sdk

Version:

HadeSwap SDK for interacting with protocol

64 lines (63 loc) 3.53 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.claimNft = void 0; const anchor_1 = require("@project-serum/anchor"); const token_1 = require("@project-serum/anchor/dist/cjs/utils/token"); const helpers_1 = require("../../helpers"); const constants_1 = require("../../constants"); const common_1 = require("../../../common"); const helpers_2 = require("../../../hadeswap-core/helpers"); const claimNft = ({ programId, connection, args, accounts }) => __awaiter(void 0, void 0, void 0, function* () { const program = (0, helpers_1.returnAnchorProgram)(programId, connection); const instructions = []; const [lot, lotSeed] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.ENCODER.encode(constants_1.LOT_PREFIX), accounts.auction.toBuffer(), accounts.nftMint.toBuffer()], program.programId); const [nftsOwner, nftsOwnerSeed] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.ENCODER.encode(constants_1.NFTS_OWNER_PREFIX), lot.toBuffer()], program.programId); const userNftTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(accounts.userPubkey, accounts.nftMint); const vaultNftTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(nftsOwner, accounts.nftMint); const editionId = (0, helpers_2.getMetaplexEditionPda)(accounts.nftMint); const metadataInfo = (0, helpers_1.getMetaplexMetadata)(accounts.nftMint); const ownerTokenRecord = (0, helpers_1.findTokenRecordPda)(accounts.nftMint, vaultNftTokenAccount); const destTokenRecord = (0, helpers_1.findTokenRecordPda)(accounts.nftMint, userNftTokenAccount); const ruleSet = yield (0, helpers_1.findRuleSetPDA)(args.payerRuleSet, args.nameForRuleSet); instructions.push(yield program.methods .claimNft(null) .accountsStrict({ auction: accounts.auction, user: accounts.userPubkey, lot: lot, nftMint: accounts.nftMint, nftsOwner: nftsOwner, nftUserTokenAccount: userNftTokenAccount, vaultTokenAccount: vaultNftTokenAccount, instructions: anchor_1.web3.SYSVAR_INSTRUCTIONS_PUBKEY, metadataInfo, ownerTokenRecord, destTokenRecord, editionInfo: editionId, authorizationRulesProgram: constants_1.AUTHORIZATION_RULES_PROGRAM, tokenProgram: token_1.TOKEN_PROGRAM_ID, associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID, systemProgram: anchor_1.web3.SystemProgram.programId, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY, }) .remainingAccounts([ { pubkey: ruleSet, isSigner: false, isWritable: false, }, ]) .instruction()); const signers = []; return { userTokenAccount: userNftTokenAccount, instructions, signers }; }); exports.claimNft = claimNft;