UNPKG

@frakters/nft-lending-v2

Version:

Client library for interacting with nft lenging solana program

166 lines (165 loc) 9.4 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; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodedTokenBuffersToUI = exports.decodedLoan = exports.decodedDeposit = exports.decodedPriceBasedLiquidityPool = exports.decodedTimeBasedLiquidityPool = exports.decodedCollectionInfo = exports.decodedLendingStake = void 0; const web3_js_1 = require("@solana/web3.js"); const anchor = __importStar(require("@project-serum/anchor")); const bn_js_1 = require("bn.js"); function decodedLendingStake(decodedLendingStake, address) { return { lendingStakePubkey: address.toBase58(), stakeType: Object.keys(decodedLendingStake.stakeType)[0], loan: (decodedLendingStake.loan || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")).toBase58(), stakeContract: (decodedLendingStake.stakeContract || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")).toBase58(), stakeConstractOptional: (decodedLendingStake.stakeConstractOptional || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")).toBase58(), stakeState: Object.keys(decodedLendingStake.stakeState)[0], identity: (decodedLendingStake.identity.toBase58() || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")), dataA: (decodedLendingStake.dataA.toBase58() || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")), dataB: (decodedLendingStake.dataB.toBase58() || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")), dataC: (decodedLendingStake.dataC.toBase58() || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")), dataD: (decodedLendingStake.dataD.toBase58() || new web3_js_1.PublicKey("So11111111111111111111111111111111111111112")), totalHarvested: decodedLendingStake.totalHarvested.toNumber(), totalHarvestedOptional: decodedLendingStake.totalHarvestedOptional.toNumber(), lastTime: decodedLendingStake.lastTime.toNumber() }; } exports.decodedLendingStake = decodedLendingStake; function decodedCollectionInfo(decodedCollection, address) { return { collectionInfoPubkey: address.toBase58(), creator: decodedCollection.creator.toBase58(), liquidityPool: decodedCollection.liquidityPool.toBase58(), pricingLookupAddress: decodedCollection.pricingLookupAddress.toBase58(), royaltyAddress: decodedCollection.royaltyAddress.toBase58(), royaltyFeeTime: decodedCollection.royaltyFeeTime.toNumber(), royaltyFeePrice: decodedCollection.royaltyFeePrice.toNumber(), loanToValue: decodedCollection.loanToValue.toNumber(), collaterizationRate: decodedCollection.collaterizationRate.toNumber(), availableLoanTypes: Object.keys(decodedCollection.availableLoanTypes)[0], expirationTime: decodedCollection.expirationTime.toNumber(), }; } exports.decodedCollectionInfo = decodedCollectionInfo; function decodedTimeBasedLiquidityPool(decodedLiquidityPool, address) { return { liquidityPoolPubkey: address.toBase58(), id: decodedLiquidityPool.id.toNumber(), rewardInterestRateTime: decodedLiquidityPool.rewardInterestRateTime.toNumber(), feeInterestRateTime: decodedLiquidityPool.feeInterestRateTime.toNumber(), rewardInterestRatePrice: decodedLiquidityPool.rewardInterestRatePrice.toNumber(), feeInterestRatePrice: decodedLiquidityPool.feeInterestRatePrice.toNumber(), liquidityAmount: decodedLiquidityPool.liquidityAmount.toNumber(), liqOwner: decodedLiquidityPool.liqOwner.toBase58(), amountOfStaked: decodedLiquidityPool.amountOfStaked.toNumber(), userRewardsAmount: decodedLiquidityPool.userRewardsAmount.toNumber(), apr: decodedLiquidityPool.apr.toNumber(), cumulative: decodedLiquidityPool.cumulative.toNumber(), lastTime: decodedLiquidityPool.lastTime.toNumber(), oldCumulative: decodedLiquidityPool.oldCumulative.toNumber(), period: decodedLiquidityPool.period.toNumber(), }; } exports.decodedTimeBasedLiquidityPool = decodedTimeBasedLiquidityPool; function decodedPriceBasedLiquidityPool(decodedLiquidityPool, address) { return { liquidityPoolPubkey: address.toBase58(), id: decodedLiquidityPool.id.toNumber(), baseBorrowRate: decodedLiquidityPool.baseBorrowRate, variableSlope1: decodedLiquidityPool.variableSlope1, variableSlope2: decodedLiquidityPool.variableSlope2, utilizationRateOptimal: decodedLiquidityPool.utilizationRateOptimal, reserveFactor: decodedLiquidityPool.reserveFactor, reserveAmount: decodedLiquidityPool.reserveAmount.toString(), liquidityAmount: decodedLiquidityPool.liquidityAmount.toNumber(), liqOwner: decodedLiquidityPool.liqOwner.toBase58(), amountOfStaked: decodedLiquidityPool.amountOfStaked.toNumber(), depositApr: decodedLiquidityPool.depositApr.toNumber(), depositCumulative: decodedLiquidityPool.depositCumulative.toNumber(), borrowApr: decodedLiquidityPool.borrowApr.toNumber(), borrowCumulative: decodedLiquidityPool.borrowCumulative.toNumber(), lastTime: decodedLiquidityPool.lastTime.toNumber(), depositCommission: decodedLiquidityPool.depositCommission, borrowCommission: decodedLiquidityPool.borrowCommission, }; } exports.decodedPriceBasedLiquidityPool = decodedPriceBasedLiquidityPool; function decodedDeposit(decodedDeposit, address) { return { depositPubkey: address.toBase58(), liquidityPool: decodedDeposit.liquidityPool.toBase58(), user: decodedDeposit.user.toBase58(), amount: decodedDeposit.amount.toNumber(), stakedAt: decodedDeposit.stakedAt.toNumber(), stakedAtCumulative: decodedDeposit.stakedAtCumulative.toNumber(), }; } exports.decodedDeposit = decodedDeposit; function decodedLoan(decodedLoan, address) { return { loanPubkey: address.toBase58(), user: decodedLoan.user.toBase58(), nftMint: decodedLoan.nftMint.toBase58(), nftUserTokenAccount: decodedLoan.nftUserTokenAccount.toBase58(), liquidityPool: decodedLoan.liquidityPool.toBase58(), collectionInfo: decodedLoan.collectionInfo.toBase58(), startedAt: decodedLoan.startedAt.toNumber(), expiredAt: new anchor.BN(decodedLoan.expiredAt || 0).toNumber(), finishedAt: decodedLoan.finishedAt.toNumber(), originalPrice: decodedLoan.originalPrice.toNumber(), amountToGet: decodedLoan.amountToGet.toNumber(), // amountToReturn: decodedLoan.amountToReturn.toNumber(), rewardAmount: decodedLoan.rewardAmount.toNumber(), feeAmount: decodedLoan.feeAmount.toNumber(), royaltyAmount: decodedLoan.royaltyAmount.toNumber(), borrowedAtCumulative: new anchor.BN(decodedLoan.rewardInterestRate || 0).toNumber(), alreadyPaidBack: new anchor.BN(decodedLoan.feeInterestRate || 0).toNumber(), loanStatus: Object.keys(decodedLoan.loanStatus)[0], loanType: Object.keys(decodedLoan.loanType)[0], }; } exports.decodedLoan = decodedLoan; function decodedTokenBuffersToUI(decodedTokenState, tokenAddress) { let amountNum = -1; try { amountNum = new bn_js_1.BN(decodedTokenState.amount, 10, 'le').toNumber(); } catch (err) { } return { tokenAccountPubkey: tokenAddress.toBase58(), mint: new web3_js_1.PublicKey(decodedTokenState.mint).toBase58(), owner: new web3_js_1.PublicKey(decodedTokenState.owner).toBase58(), amount: amountNum, amountBN: new bn_js_1.BN(decodedTokenState.amount, 10, 'le'), delegateOption: !!decodedTokenState.delegateOption, delegate: new web3_js_1.PublicKey(decodedTokenState.delegate).toBase58(), state: decodedTokenState.state, isNativeOption: !!decodedTokenState.isNativeOption, isNative: new bn_js_1.BN(decodedTokenState.isNative, 10, 'le').toNumber(), delegatedAmount: new bn_js_1.BN(decodedTokenState.delegatedAmount, 10, 'le').toNumber(), closeAuthorityOption: !!decodedTokenState.closeAuthorityOption, closeAuthority: new web3_js_1.PublicKey(decodedTokenState.closeAuthority).toBase58(), }; } exports.decodedTokenBuffersToUI = decodedTokenBuffersToUI;