UNPKG

@frakters/nft-lending-v2

Version:

Client library for interacting with nft lenging solana program

80 lines (79 loc) 5.57 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.fetchAndParseCollectionInfo = exports.fetchAndParsePriceBasedLiquidityPool = exports.fetchAndParseTimeBasedLiquidityPool = exports.fetchAndParseLoan = exports.fetchAndParseDeposit = exports.fetchAndParseLiquidationLot = exports.fetchAndParseNftAttempts = exports.fetchAndParseLotTicket = void 0; const index_1 = require("./../index"); const fetchAndParseLotTicket = ({ lotTicketPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); const lotTicketRaw = yield nftLendingProgram.account.lotTicket.fetch(lotTicketPubkey, 'confirmed'); const lotTicket = (0, index_1.objectBNsAndPubkeysToNums)({ account: lotTicketRaw, publicKey: lotTicketPubkey, }); return lotTicket; }); exports.fetchAndParseLotTicket = fetchAndParseLotTicket; const fetchAndParseNftAttempts = ({ nftAttemptsPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); const nftAttemptsRaw = yield nftLendingProgram.account.nftAttempts.fetch(nftAttemptsPubkey, 'confirmed'); const nftAttempts = (0, index_1.objectBNsAndPubkeysToNums)({ account: nftAttemptsRaw, publicKey: nftAttemptsPubkey, }); return nftAttempts; }); exports.fetchAndParseNftAttempts = fetchAndParseNftAttempts; const fetchAndParseLiquidationLot = ({ liquidationLotPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); const liquidationLotRaw = yield nftLendingProgram.account.liquidationLot.fetch(liquidationLotPubkey, 'confirmed'); const liquidationLot = (0, index_1.objectBNsAndPubkeysToNums)({ account: liquidationLotRaw, publicKey: liquidationLotPubkey, }); return liquidationLot; }); exports.fetchAndParseLiquidationLot = fetchAndParseLiquidationLot; const fetchAndParseDeposit = ({ depositPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); const depositRaw = yield nftLendingProgram.account.deposit.fetch(depositPubkey, 'confirmed'); const deposit = index_1.accounts.decodedDeposit(depositRaw, depositPubkey); return deposit; }); exports.fetchAndParseDeposit = fetchAndParseDeposit; const fetchAndParseLoan = ({ loanPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); const loanRaw = yield nftLendingProgram.account.loan.fetch(loanPubkey, 'confirmed'); const loan = index_1.accounts.decodedLoan(loanRaw, loanPubkey); return loan; }); exports.fetchAndParseLoan = fetchAndParseLoan; const fetchAndParseTimeBasedLiquidityPool = ({ timeBasedLiquidityPoolPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); const liquidityPoolRaw = yield nftLendingProgram.account.liquidityPool.fetch(timeBasedLiquidityPoolPubkey, 'confirmed'); const liquidityPool = index_1.accounts.decodedTimeBasedLiquidityPool(liquidityPoolRaw, timeBasedLiquidityPoolPubkey); return liquidityPool; }); exports.fetchAndParseTimeBasedLiquidityPool = fetchAndParseTimeBasedLiquidityPool; const fetchAndParsePriceBasedLiquidityPool = ({ priceBasedLiquidityPoolPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); const liquidityPoolRaw = yield nftLendingProgram.account.priceBasedLiquidityPool.fetch(priceBasedLiquidityPoolPubkey, 'confirmed'); const liquidityPool = index_1.accounts.decodedPriceBasedLiquidityPool(liquidityPoolRaw, priceBasedLiquidityPoolPubkey); return liquidityPool; }); exports.fetchAndParsePriceBasedLiquidityPool = fetchAndParsePriceBasedLiquidityPool; const fetchAndParseCollectionInfo = ({ collectionInfoPubkey, programId, connection, }) => __awaiter(void 0, void 0, void 0, function* () { const nftLendingProgram = yield index_1.utils.returnAnchorProgram(programId, connection); // should be confirmed everywhere const collectionInfoRaw = yield nftLendingProgram.account.collectionInfo.fetch(collectionInfoPubkey, 'confirmed'); const collectionInfo = index_1.accounts.decodedCollectionInfo(collectionInfoRaw, collectionInfoPubkey); return collectionInfo; }); exports.fetchAndParseCollectionInfo = fetchAndParseCollectionInfo;