fbonds-core
Version:
Banx protocol sdk
74 lines (73 loc) • 4.1 kB
JavaScript
"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.removePerpetualListingCnft = void 0;
const token_1 = require("@coral-xyz/anchor/dist/cjs/utils/token");
const anchor_1 = require("@coral-xyz/anchor");
const spl_account_compression_1 = require("@solana/spl-account-compression");
const constants_1 = require("../../../constants");
const helpers_1 = require("../../../helpers");
const removePerpetualListingCnft = (_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_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;
const [rentVault, rentVaultBump] = yield anchor_1.web3.PublicKey.findProgramAddress([
constants_1.ENCODER.encode(constants_1.RENT_VAULT),
], program.programId);
instructions.push(yield program.methods
.removePerpetualListingCnft(args.isBorrowerListing, root, dataHash, creatorHash, nonce, index, proofPathAsAccounts.length)
.accountsStrict({
user: accounts.userPubkey,
systemProgram: anchor_1.web3.SystemProgram.programId,
rent: anchor_1.web3.SYSVAR_RENT_PUBKEY,
tokenProgram: token_1.TOKEN_PROGRAM_ID,
associatedTokenProgram: token_1.ASSOCIATED_PROGRAM_ID,
bondTradeTransaction: accounts.oldBondTradeTransaction,
fraktBond: accounts.fraktBond,
metadataProgram: constants_1.METADATA_PROGRAM_PUBKEY,
authorizationRulesProgram: constants_1.AUTHORIZATION_RULES_PROGRAM,
uninitializedTokenMint: accounts.nftMint,
instructions: anchor_1.web3.SYSVAR_INSTRUCTIONS_PUBKEY,
mutualBondTradeTxnVault,
treeAuthority: treeAuthority,
bubblegumProgram: constants_1.BUBBLEGUM_PROGRAM_ID,
compressionProgram: spl_account_compression_1.SPL_ACCOUNT_COMPRESSION_PROGRAM_ID,
logWrapper: spl_account_compression_1.SPL_NOOP_PROGRAM_ID,
merkleTree: accounts.tree,
bondOffer: accounts.bondOffer,
rentVault
})
.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.fraktBond,
bondOffer: accounts.bondOffer,
bondTradeTransaction: accounts.oldBondTradeTransaction,
}
};
});
exports.removePerpetualListingCnft = removePerpetualListingCnft;