UNPKG

fbonds-core

Version:

Banx protocol sdk

63 lines (62 loc) 3.43 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.claimCnftPerpetualLoanCanopy = void 0; const constants_1 = require("../../../../constants"); const constants_2 = require("../../../../constants"); const helpers_1 = require("./../../../../helpers"); const anchor_1 = require("@coral-xyz/anchor"); const claimCnftPerpetualLoanCanopy = (_a) => __awaiter(void 0, [_a], void 0, function* ({ programId, connection, args, accounts, sendTxn, }) { const program = (0, helpers_1.returnAnchorProgram)(connection); const instructions = []; const [mutualBondTradeTxnVault] = yield anchor_1.web3.PublicKey.findProgramAddress([constants_1.ENCODER.encode(constants_2.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; instructions.push(yield program.methods .claimCnftPerpetualLoan(root, dataHash, creatorHash, nonce, index, proofPathAsAccounts.length) .accountsStrict({ bondTradeTransaction: accounts.bondTradeTransaction, fbond: accounts.fbond, user: accounts.userPubkey, mutualBondTradeTxnVault: mutualBondTradeTxnVault, systemProgram: anchor_1.web3.SystemProgram.programId, rent: anchor_1.web3.SYSVAR_RENT_PUBKEY, merkleTree: accounts.tree, treeAuthority: treeAuthority, bubblegumProgram: constants_1.BUBBLEGUM_PROGRAM_ID, compressionProgram: constants_1.SPL_ACCOUNT_COMPRESSION_PROGRAM_ID, logWrapper: constants_1.SPL_NOOP_PROGRAM_ID, uninitializedOldBondOfferV2: accounts.bondOffer, }) .remainingAccounts(proofPathAsAccounts) .instruction()); const transaction = new anchor_1.web3.Transaction(); for (let instruction of instructions) transaction.add(instruction); const signers = []; yield sendTxn(transaction, signers); return { instructions, signers, accounts: { fraktBond: accounts.fbond, bondOffer: accounts.bondOffer, bondTradeTransaction: accounts.bondTradeTransaction, } }; }); exports.claimCnftPerpetualLoanCanopy = claimCnftPerpetualLoanCanopy;