UNPKG

@rainfi/sdk

Version:

This package is used to interact with Rain.fi protocol on Solana

863 lines 36.1 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Pool = exports.Rain = void 0; const web3_js_1 = require("@solana/web3.js"); const errors = __importStar(require("./generated/errors")); const accounts = __importStar(require("./generated/accounts")); const utils = __importStar(require("./utils/fetch.utils")); const instructions = __importStar(require("./utils/instructions.utils")); const types = __importStar(require("./types/types")); const constant_1 = require("./utils/constant"); const spl_token_1 = require("@solana/spl-token"); const bs58_1 = __importDefault(require("bs58")); const anchor_1 = require("@coral-xyz/anchor"); class Rain { constructor(connection, wallet) { this.PUBKEY = constant_1.RAIN_PROGRAM; this.instructions = instructions; this.errors = errors; this.accounts = accounts; this.utils = utils; this.types = types; this.connection = connection; this.publicKey = wallet; } /** * Creates a _createPool_ instruction. * * @param args parameter of your pool, explained in the doc. * @param splAddress [Optional] SPL address of the currency of the pool, default to wSOL. * */ createPool(args_1) { return __awaiter(this, arguments, void 0, function* (args, splAddress = spl_token_1.NATIVE_MINT) { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.createPool(this.connection, this.publicKey, args, splAddress); }); } /** * Creates a _updatePool_ instruction. * * @param args parameter of your pool, explained in the doc. * */ updatePool(args) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey) { throw new Error("Wallet publickey not defined"); } return yield instructions.updatePool(this.publicKey, args); }); } /** * Creates a _updatePoolCollections_ instruction. * * @param collections Id of the collections that you want to authorize loan to. * */ updatePoolCollections(collections) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey) { throw new Error("Wallet publickey not defined"); } return yield instructions.updatePoolCollections(this.publicKey, collections); }); } /** * Creates a _borrow_ instruction. * * @param args BorrowArgs of your loan, explained in the doc. * @param referrer (optional) wallet address of the referrer to get a commission of the protocol fees. * */ borrow(args_1) { return __awaiter(this, arguments, void 0, function* (args, referrer = undefined, isCompressed = false) { var _a; if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } const borrowIxs = isCompressed ? yield instructions.borrowCompressed(this.connection, this.publicKey, Object.assign(Object.assign({}, args), { assetId: args.nftMint }), referrer) : yield instructions.borrow(this.connection, this.publicKey, args, referrer); const instruction_freeze = isCompressed ? [] : (_a = (yield instructions.freeze(this.connection, this.publicKey, borrowIxs.signers.publicKey, args.nftMint, args.poolOwner))) === null || _a === void 0 ? void 0 : _a.slice(1, 2); return { instruction: [...borrowIxs.instruction, ...instruction_freeze], signers: borrowIxs.signers }; }); } /** * Creates a _extendLoan_ instruction. * * @param args ExtendArgs of your loan, explained in the doc. * @param amountToRepay amount of interest to repay to close current loan * */ extend(args, amountToRepay) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.extendLoan(this.connection, this.publicKey, args, amountToRepay); }); } /** * Creates a _repayLoan_ instruction. * * @param loanAccount pubkey of the loan account. * @param amount total amount to repay. * */ repayLoan(loanAccount_1, amount_1) { return __awaiter(this, arguments, void 0, function* (loanAccount, amount, isCompressed = false) { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return isCompressed ? yield instructions.repayCompressedLoan(this.connection, this.publicKey, loanAccount, amount) : yield instructions.repayLoan(this.connection, this.publicKey, loanAccount, amount); }); } /** * Creates a _liquidate_ instruction. * * @param loanAccount pubkey of the loan account. * */ liquidate(loanAccount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.liquidate(this.connection, this.publicKey, loanAccount); }); } /** * Creates a _addLiquidity_ instruction. * * @param amount amount of SOL in lamports to add to pool. * */ addLiquidity(amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.addLiquidity(this.connection, this.publicKey, amount); }); } /** * Creates a _withdrawLiquidity_ instruction. * * @param amount amount of SOL in lamports to add to pool. * */ withdrawLiquidity(amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.withdrawLiquidity(this.connection, this.publicKey, amount); }); } /** * Creates a _updatePoolStatus_ instruction. * No parameter required since we can find the pool from the signer address. * If the pool is disabled, it will enabled it, if pool enabled, will disable it */ updatePoolStatus(status) { if (!this.publicKey) { throw new Error("Wallet publickey not defined"); } return instructions.updatePoolStatus(this.publicKey, status); } /** * Creates a _closePool_ instruction. * No parameter required since we can find the pool from the signer address. * This will DELETE THE POOL and delete all its data, be sure of what you are doing */ closePool(confirm = false) { if (!this.publicKey) { throw new Error("Wallet publickey not defined"); } if (!confirm) { throw new Error("This instruction is irreversible, re-run it with closePool(true) argument to force execute."); } return instructions.closePool(this.publicKey); } /** * Creates a _setMaxAmountUsable_ instruction. * * @param amount max amount usable in the pool. * */ setMaxAmountUsable(amount) { if (!this.publicKey) { throw new Error("Wallet publickey not defined"); } return instructions.setMaxAmountUsable(this.publicKey, amount); } /** * Creates a _makeLoanRequest_ instruction. * * @param args loanRequestArgs of your loan request, explained in the doc. * */ makeLoanRequest(args) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.makeLoanRequest(this.connection, this.publicKey, args); }); } /** * Creates a _cancelLoanRequest_ instruction. * * @param loanRequestAddress pubkey of the account holding the loan request data. * */ cancelLoanRequest(loanRequestAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.cancelLoanRequest(this.connection, this.publicKey, loanRequestAddress); }); } /** * Creates a _acceptLoanRequest_ instruction. * * @param loanRequestAddress pubkey of the account holding the loan request data. * */ acceptLoanRequest(loanRequestAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.acceptLoanRequest(this.connection, this.publicKey, loanRequestAddress); }); } /** * Creates a _poolCancelLoanProposal_ instruction. * * @param loanRequestAddress pubkey of the account holding the loan request data. * */ poolCancelLoanProposal(loanRequestAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.poolCancelLoanProposal(this.connection, this.publicKey, loanRequestAddress); }); } /** * Creates a _executeLoanRequest_ instructions. * * @param args ExecuteLoanRequestArgs TODO. * */ executeLoanRequest(args) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.executeLoanRequest(this.connection, this.publicKey, args); }); } /** * Creates a _buyMortgage_ instructions. * * @param args BuyArgs, see types. * */ buyMortgage(args) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Missing wallet, connection or owner"); } const instructions_buy = yield instructions.buyMortgage(this.connection, this.publicKey, args); const instruction_freeze = yield instructions.freeze(this.connection, this.publicKey, instructions_buy.signers.publicKey, args.nftMint, args.poolOwner); return { instruction: [...instructions_buy.instruction, ...instruction_freeze], signers: [instructions_buy.signers], }; }); } /** * Creates a _repayMortgage_ instructions. * * @param mortgageAddress mortgage account address * @param amount amount to repay * */ repayMortgage(mortgageAddress, amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Missing wallet, connection or owner"); } return instructions.repayLoan(this.connection, this.publicKey, mortgageAddress, amount); }); } /** * Creates a _sellMortgage_ instructions. * * @param mortgageAddress mortgage account pubkey. * @param nftMint pubkey of NFT. * @param price . * */ sellMortgage(mortgageAddress, nftMint, price) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.sellLoanMortgage(this.publicKey, mortgageAddress, nftMint, price); }); } /** * Creates a _buyListedMortgage_ instructions. * These instructions need to be sent in a Versioned Transaction, or in two separate transaction * * @param mortgage Mortgage account data. * @param poolOwner PublicKey. * */ buyListedMortgage(mortgage, poolOwner) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Missing wallet, connection or owner"); } const instructions_buy_mortgage = yield instructions.buyLoanMortgage(this.connection, this.publicKey, new web3_js_1.PublicKey(mortgage.accountAddress), mortgage.sale.salePrice); const instruction_freeze = yield instructions.freeze(this.connection, this.publicKey, instructions_buy_mortgage.signers.publicKey, new web3_js_1.PublicKey(mortgage.mint), poolOwner); return [ { ixs: instructions_buy_mortgage.instruction, signers: instructions_buy_mortgage.signers, }, { ixs: instruction_freeze, signers: null }, ]; }); } /** * get user stats. * * @param user owner of the pool pubkey * @param mints Array of string | pubkey mint address to check, ex: ["So11111111111111111111111111111111111111112", "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"] * */ getUserStats(user_1) { return __awaiter(this, arguments, void 0, function* (user, mints = [ "So11111111111111111111111111111111111111112", ]) { if (!this.connection) { throw new Error("Missing wallet, connection or owner"); } return yield utils.getFullUserStats(this.connection, user, mints); }); } /** * Creates a _unfreeze_ instructions. * * @param mortgageAddress mortgage account address * */ unfreeze(mortgageAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Missing wallet or connection"); } return yield instructions.unfreeze(this.connection, this.publicKey, mortgageAddress); }); } /** * Creates a _sellNft_ instructions. * * @param mortgageAddress mortgage account address * @param bestOrder order from tensor * */ sellNft(mortgageAddress, bestOrder, amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Missing wallet or connection"); } return yield instructions.sellNft(this.connection, this.publicKey, mortgageAddress, bestOrder, amount); }); } /** * Fetch all users stats account. * */ getAllUsersStats() { return __awaiter(this, void 0, void 0, function* () { if (!this.connection) { throw new Error("Missing wallet, connection or owner"); } return yield utils.getAllUsersStats(this.connection); }); } deserializePoolAccount(data) { return utils.parsePoolAccount(accounts.Pool.fromAccountInfo(data)[0].pretty()); } deserializeLoanAccount(data) { return utils.parseLoanAccount(accounts.Loan.fromAccountInfo(data)[0].pretty()); } deserializeCollectionAccount(data) { return utils.parseCollectionAccount(accounts.Collection.fromAccountInfo(data)[0].pretty()); } deserializeLoanRequestAccount(data) { return utils.parseCustomLoanAccount(accounts.Request.fromAccountInfo(data)[0].pretty()); } deserializeUserStatsAccount(data) { return accounts.UserStats.fromAccountInfo(data)[0].pretty(); } } exports.Rain = Rain; class Pool { constructor(connection, owner, publicKey) { this.owner = owner; this.connection = connection; this.publicKey = publicKey; } /** * Fetch pool data. */ fetch() { return __awaiter(this, void 0, void 0, function* () { if (!this.connection || !this.owner) { throw new Error("Please provide connection or owner"); } return yield utils.getPoolFromOwnerAddress(this.connection, this.owner); }); } /** * Get whitelisted collections from pool. */ collections() { return __awaiter(this, void 0, void 0, function* () { if (!this.connection || !this.owner) { throw new Error("Please provide connection or owner"); } return yield utils.getWhitelistedCollectionFromPool(this.connection, this.owner); }); } /** * Get all loans from pool, including current, liquidated and repaid ones. * @param type type of loans to fetch. 'all' | 'history' | 'ongoing' Default to 'all' */ loans(type, borrower) { return __awaiter(this, void 0, void 0, function* () { if (!this.connection || !this.owner) { throw new Error("Please provide connection or owner"); } let loans = []; switch (type) { case "all": loans = yield utils.getLoansFromPool(this.connection, this.owner); break; case "history": const liquidated = yield utils.getLoansFromPool(this.connection, this.owner, borrower ? [ { key: "status", value: "4" }, // liquidated { key: "borrower", value: borrower === null || borrower === void 0 ? void 0 : borrower.toBase58() }, ] : [ { key: "status", value: "4" }, // liquidated ]); const repaid = yield utils.getLoansFromPool(this.connection, this.owner, borrower ? [ { key: "status", value: "3" }, // repaid { key: "borrower", value: borrower === null || borrower === void 0 ? void 0 : borrower.toBase58() }, ] : [ { key: "status", value: "3" }, // repaid ]); loans = [...repaid, ...liquidated]; break; case "ongoing": loans = yield utils.getLoansFromPool(this.connection, this.owner, borrower ? [ { key: "status", value: "2" }, // ongoing { key: "borrower", value: borrower === null || borrower === void 0 ? void 0 : borrower.toBase58() }, ] : [ { key: "status", value: "2" }, // ongoing ]); break; default: loans = yield utils.getLoansFromPool(this.connection, this.owner); break; } return loans; }); } /** * Get all loans request from pool, including accepted and pending ones. * @param type type of loans request to fetch. 'all' | 'accepted' | 'pending' Default to 'all' */ loanRequests(type, borrower) { return __awaiter(this, void 0, void 0, function* () { if (!this.connection || !this.owner) { throw new Error("Please provide connection or owner"); } let loans = { loans: [], mortgages: [] }; switch (type) { case "all": loans = yield utils.getCustomLoanOffersFromLender(this.connection, this.owner); break; case "accepted": loans = yield utils.getCustomLoanOffersFromLender(this.connection, this.owner, borrower ? [ { key: "status", value: "2" }, // accepted { key: "borrower", value: borrower === null || borrower === void 0 ? void 0 : borrower.toBase58() }, ] : [ { key: "status", value: "2" }, // accepted ]); break; case "pending": loans = yield utils.getCustomLoanOffersFromLender(this.connection, this.owner, borrower ? [ { key: "status", value: "1" }, // pending { key: "borrower", value: borrower === null || borrower === void 0 ? void 0 : borrower.toBase58() }, ] : [ { key: "status", value: "1" }, // pending ]); break; default: loans = yield utils.getCustomLoanOffersFromLender(this.connection, this.owner); break; } return loans; }); } /** * Get all mortgages from pool, including ongoing, liquidated, and repaid ones. * @param type type of loans to fetch. 'all' | 'history' | 'ongoing' Default to 'all' */ mortgages(type, borrower) { return __awaiter(this, void 0, void 0, function* () { if (!this.connection || !this.owner) { throw new Error("Please provide connection or owner"); } let mortgages = []; switch (type) { case "all": mortgages = yield utils.getMortgageFromAddress(this.connection, borrower || this.owner, borrower ? "borrower" : "pool", false); break; case "history": const repaidValue = bs58_1.default.encode(new anchor_1.BN(1).toArrayLike(Buffer, "le", 1)); const liquidatedValue = bs58_1.default.encode(new anchor_1.BN(2).toArrayLike(Buffer, "le", 1)); const repaid = yield utils.getMortgageFromAddress(this.connection, this.owner, borrower ? "borrower" : "pool", false, borrower ? [ { key: "status", value: repaidValue }, // repaid { key: "borrower", value: borrower === null || borrower === void 0 ? void 0 : borrower.toBase58() }, ] : [ { key: "status", value: repaidValue }, // liquidated ]); const liquidated = yield utils.getMortgageFromAddress(this.connection, this.owner, borrower ? "borrower" : "pool", false, borrower ? [ { key: "status", value: liquidatedValue }, // liquidated { key: "borrower", value: borrower === null || borrower === void 0 ? void 0 : borrower.toBase58() }, ] : [ { key: "status", value: liquidatedValue }, // liquidated ]); mortgages = [...repaid, ...liquidated]; break; case "ongoing": mortgages = yield utils.getMortgageFromAddress(this.connection, borrower || this.owner, borrower ? "borrower" : "pool", true); break; default: mortgages = yield utils.getMortgageFromAddress(this.connection, borrower || this.owner, borrower ? "borrower" : "pool", true); break; } return mortgages; }); } /** * Get pool fees breakdown based on values given. * * @param amount amount to borrow, must be lower than floorPrice * (loanToValue / 100000) or collection.maxAmountToBorrow * @param duration duration in days of the loan * */ fees(amount, duration) { return __awaiter(this, void 0, void 0, function* () { if (!this.connection || !this.owner) { throw new Error("Please provide connection or owner"); } const pool = yield utils.getPoolFromOwnerAddress(this.connection, this.owner); return utils.getFeesDetailed(pool, amount, duration); }); } /** * Get mortgages pool fees breakdown based on values given. * * @param amount amount to borrow, must be lower or equal to floorPrice / 2 * @param duration duration in days of the loan * */ mortgagesFees(amount, duration) { return __awaiter(this, void 0, void 0, function* () { if (!this.connection || !this.owner) { throw new Error("Please provide connection or owner"); } const pool = yield utils.getPoolFromOwnerAddress(this.connection, this.owner); return utils.getMortgagesFeesDetailed(pool, amount, duration); }); } /** * Creates a _borrow_ instruction. * * @param nftMint pubkey of the NFT to use as collateral * @param duration duration in days of the loan, * @param amount amount of lamports that the borrower need, must be lower than collection.maxAmountToBorrow, * @param interest total interest user will pay * @param slippage max slippage in basis points, 100 points means 1%, default to 50 bps / 0.5% * */ borrow(nftMint_1, duration_1, amount_1, interest_1) { return __awaiter(this, arguments, void 0, function* (nftMint, duration, amount, interest, slippage = 50, referrerTa = undefined, lookupTable = undefined) { var _a; if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } const borrowIxs = yield instructions.borrow(this.connection, this.publicKey, { poolOwner: this.owner, nftMint, duration, amount, interest, slippage, lookupTable }, referrerTa); const instruction_freeze = (_a = (yield instructions.freeze(this.connection, this.publicKey, borrowIxs.signers.publicKey, nftMint, this.owner))) === null || _a === void 0 ? void 0 : _a.slice(1, 2); return { instruction: [...borrowIxs.instruction, ...instruction_freeze], signers: borrowIxs.signers }; }); } /** * Creates a _extend_ instruction. * * @param nftMint pubkey of the NFT to use as collateral * @param currentLoan current loan address, * @param duration duration in days of the loan, * @param amount amount of lamports that the borrower need, must be lower than collection.maxAmountToBorrow, * @param interest total interest user will pay * @param amountToRepay amount of interest to repay to close current loan * @param slippage max slippage in basis points, 100 points means 1%, default to 50 bps / 0.5% * */ extend(nftMint_1, currentLoan_1, duration_1, amount_1, interest_1) { return __awaiter(this, arguments, void 0, function* (nftMint, currentLoan, duration, amount, interest, slippage = 50, lookupTable = undefined) { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.extendLoan(this.connection, this.publicKey, { poolOwner: this.owner, loan: currentLoan, nftMint, duration, amount, interest, slippage, lookupTable }, amount); }); } /** * Creates a _repay_ instruction. * * @param loanAccount pubkey of the loan account. * @param amount total amount to repay. * */ repay(loanAccount, amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.repayLoan(this.connection, this.publicKey, loanAccount, amount); }); } /** * Creates a _makeLoanRequest_ instruction. * * @param nftMint pubkey of the NFT to use as collateral * @param duration duration in days of the loan, * @param amount amount of lamports that the borrower need, must be lower than collection.maxAmountToBorrow, * @param floorPrice floor price of collection * */ makeLoanRequest(nftMint, duration, amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.makeLoanRequest(this.connection, this.publicKey, { poolOwner: this.owner, nftMint, duration, amount, }); }); } /** * Creates a _cancelLoanRequest_ instruction. * * @param loanRequestAddress pubkey of the account holding the loan request data. * */ cancelLoanRequest(loanRequestAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.cancelLoanRequest(this.connection, this.publicKey, loanRequestAddress); }); } /** * Creates a _acceptLoanRequest_ instruction. * * @param loanRequestAddress pubkey of the account holding the loan request data. * */ acceptLoanRequest(loanRequestAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.acceptLoanRequest(this.connection, this.publicKey, loanRequestAddress); }); } /** * Creates a _poolCancelLoanProposal_ instruction. * * @param loanRequestAddress pubkey of the account holding the loan request data. * */ poolCancelLoanProposal(loanRequestAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection) { throw new Error("Wallet publickey not defined"); } return yield instructions.poolCancelLoanProposal(this.connection, this.publicKey, loanRequestAddress); }); } /** * Creates a _executeLoanRequest_ instructions. * * @param args ExecuteLoanRequestArgs TODO. * */ executeLoanRequest(args) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.executeLoanRequest(this.connection, this.publicKey, args); }); } /** * Creates a _buy_ instructions. * * @param args BuyArgs, see types. * */ buy(args) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } const instructions_buy = yield instructions.buyMortgage(this.connection, this.publicKey, Object.assign(Object.assign({}, args), { poolOwner: this.owner })); const instruction_freeze = yield instructions.freeze(this.connection, this.publicKey, instructions_buy.signers.publicKey, args.nftMint, this.owner); return { instruction: [...instructions_buy.instruction, ...instruction_freeze], signers: [instructions_buy.signers], }; }); } /** * Creates a _repayMortgage_ instructions. * * @param mortgageAddress mortgage account address * @param amount amount to repay * */ repayMortgage(mortgageAddress, amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return instructions.repayLoan(this.connection, this.publicKey, mortgageAddress, amount); }); } /** * Creates a _unfreeze_ instructions. * * @param mortgageAddress mortgage account address * */ unfreeze(mortgageAddress) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.unfreeze(this.connection, this.publicKey, mortgageAddress); }); } /** * Creates a _sellNft_ instructions. * * @param mortgageAddress mortgage account address * @param bestOrder order from tensor * */ sellNft(mortgageAddress, bestOrder, amount) { return __awaiter(this, void 0, void 0, function* () { if (!this.publicKey || !this.connection || !this.owner) { throw new Error("Missing wallet, connection or owner"); } return yield instructions.sellNft(this.connection, this.publicKey, mortgageAddress, bestOrder, amount); }); } } exports.Pool = Pool; //# sourceMappingURL=main.js.map