UNPKG

fbonds-core

Version:

Banx protocol sdk

83 lines (82 loc) 4.26 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.sendNftByAdmin = void 0; const anchor_1 = require("@coral-xyz/anchor"); const common_1 = require("../../../../../common"); const constants_1 = require("../../../../constants"); const helpers_1 = require("../../../../helpers"); const sendNftByAdmin = (_a) => __awaiter(void 0, [_a], void 0, function* ({ programId, connection, args, accounts, sendTxn, }) { const program = (0, helpers_1.returnAnchorProgram)(connection); const instructions = []; const bond = accounts.fbond; const collateralTokenMint = bond.fbondTokenMint; const userTokenAccount = yield (0, common_1.findAssociatedTokenAddress)(accounts.userPubkey, collateralTokenMint); const EMPTY_ROOT = new Array(32).fill(0); const [mutualBondTradeTxnVault] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.ENCODER.encode(constants_1.MUTUAL_BOND_TRADE_TXN_VAULT)], program.programId); const [treeAuthority, _bump2] = anchor_1.web3.PublicKey.findProgramAddressSync([accounts.tree.toBuffer()], constants_1.BUBBLEGUM_PROGRAM_ID); const canopyDepth = yield (0, helpers_1.getTreeCanopyDepth)(accounts.tree, connection); const proofPathAsAccounts = (0, helpers_1.mapProof)(args.proof, canopyDepth); const root = (0, helpers_1.decode)(args.proof.root); const dataHash = (0, helpers_1.decode)(args.cnftParams.dataHash); const creatorHash = (0, helpers_1.decode)(args.cnftParams.creatorHash); const nonce = new anchor_1.BN(args.cnftParams.leafId); const index = args.cnftParams.leafId; let remainingAccount = [ { pubkey: treeAuthority, isSigner: false, isWritable: true, }, { pubkey: accounts.tree, isSigner: false, isWritable: true, }, { pubkey: constants_1.SPL_NOOP_PROGRAM_ID, isSigner: false, isWritable: true, }, { pubkey: constants_1.SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, isSigner: false, isWritable: true, }, { pubkey: constants_1.BUBBLEGUM_PROGRAM_ID, isSigner: false, isWritable: true, }, ]; // instructions.push(...createAssociatedTokenAccountInstruction(userTokenAccount, accounts.userPubkey, accounts.userPubkey, bond.fbondTokenMint)); // instructions.push(...createAssociatedTokenAccountInstruction(mutualBondTokenAccount,accounts.userPubkey,mutualBondTradeTxnVault,bond.fbondTokenMint)) instructions.push(yield program.methods .sendNftByAdmin(args.type, root, dataHash, creatorHash, nonce, index, proofPathAsAccounts.length) .accountsStrict({ user: accounts.userPubkey, systemProgram: anchor_1.web3.SystemProgram.programId, mutualBondTradeTxnVault: mutualBondTradeTxnVault, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY }) .remainingAccounts([...remainingAccount, ...proofPathAsAccounts]) .instruction()); const transaction = new anchor_1.web3.Transaction(); transaction.add(anchor_1.web3.ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 100000 })); transaction.add(anchor_1.web3.ComputeBudgetProgram.setComputeUnitLimit({ units: 1000000 })); for (const instruction of instructions) transaction.add(instruction); const signers = []; // const signers = []; yield sendTxn(transaction, signers); return { instructions, signers }; }); exports.sendNftByAdmin = sendNftByAdmin;