UNPKG

@rainfi/sdk

Version:

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

440 lines 17.2 kB
"use strict"; /** * This code was GENERATED using the solita package. * Please DO NOT EDIT THIS FILE, instead rerun solita to update it or write a wrapper to add functionality. * * See: https://github.com/metaplex-foundation/solita */ 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.poolBeet = exports.Pool = exports.poolDiscriminator = void 0; const web3 = __importStar(require("@solana/web3.js")); const beet = __importStar(require("@metaplex-foundation/beet")); const beetSolana = __importStar(require("@metaplex-foundation/beet-solana")); const PoolStatus_1 = require("../types/PoolStatus"); const Curve_1 = require("../types/Curve"); const PoolCondition_1 = require("../types/PoolCondition"); const PoolLiquidation_1 = require("../types/PoolLiquidation"); const PoolCollection_1 = require("../types/PoolCollection"); exports.poolDiscriminator = [241, 154, 109, 4, 17, 177, 109, 188]; /** * Holds the data for the {@link Pool} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ class Pool { constructor(bump, owner, currency, oraclePoolUsd, oracleSolUsd, status, isCompounded, isShared, totalAmount, borrowedAmount, availableAmount, usableAmount, loanCurve, mortgageCurve, isMortgageEnabled, nftLocked, totalLiquidations, totalLoans, totalMortgages, totalInterest, depositedAt, createdAt, updatedAt, collectionsUpdatedAt, lastLoanAt, lastMortgageAt, conditions, liquidation, whitelist, depositedAmount, minAmountPerLoan, padding /* size: 14 */, collections /* size: 50 */) { this.bump = bump; this.owner = owner; this.currency = currency; this.oraclePoolUsd = oraclePoolUsd; this.oracleSolUsd = oracleSolUsd; this.status = status; this.isCompounded = isCompounded; this.isShared = isShared; this.totalAmount = totalAmount; this.borrowedAmount = borrowedAmount; this.availableAmount = availableAmount; this.usableAmount = usableAmount; this.loanCurve = loanCurve; this.mortgageCurve = mortgageCurve; this.isMortgageEnabled = isMortgageEnabled; this.nftLocked = nftLocked; this.totalLiquidations = totalLiquidations; this.totalLoans = totalLoans; this.totalMortgages = totalMortgages; this.totalInterest = totalInterest; this.depositedAt = depositedAt; this.createdAt = createdAt; this.updatedAt = updatedAt; this.collectionsUpdatedAt = collectionsUpdatedAt; this.lastLoanAt = lastLoanAt; this.lastMortgageAt = lastMortgageAt; this.conditions = conditions; this.liquidation = liquidation; this.whitelist = whitelist; this.depositedAmount = depositedAmount; this.minAmountPerLoan = minAmountPerLoan; this.padding = padding; this.collections = collections; } /** * Creates a {@link Pool} instance from the provided args. */ static fromArgs(args) { return new Pool(args.bump, args.owner, args.currency, args.oraclePoolUsd, args.oracleSolUsd, args.status, args.isCompounded, args.isShared, args.totalAmount, args.borrowedAmount, args.availableAmount, args.usableAmount, args.loanCurve, args.mortgageCurve, args.isMortgageEnabled, args.nftLocked, args.totalLiquidations, args.totalLoans, args.totalMortgages, args.totalInterest, args.depositedAt, args.createdAt, args.updatedAt, args.collectionsUpdatedAt, args.lastLoanAt, args.lastMortgageAt, args.conditions, args.liquidation, args.whitelist, args.depositedAmount, args.minAmountPerLoan, args.padding, args.collections); } /** * Deserializes the {@link Pool} from the data of the provided {@link web3.AccountInfo}. * @returns a tuple of the account data and the offset up to which the buffer was read to obtain it. */ static fromAccountInfo(accountInfo, offset = 0) { return Pool.deserialize(accountInfo.data, offset); } /** * Retrieves the account info from the provided address and deserializes * the {@link Pool} from its data. * * @throws Error if no account info is found at the address or if deserialization fails */ static fromAccountAddress(connection, address, commitmentOrConfig) { return __awaiter(this, void 0, void 0, function* () { const accountInfo = yield connection.getAccountInfo(address, commitmentOrConfig); if (accountInfo == null) { throw new Error(`Unable to find Pool account at ${address}`); } return Pool.fromAccountInfo(accountInfo, 0)[0]; }); } /** * Provides a {@link web3.Connection.getProgramAccounts} config builder, * to fetch accounts matching filters that can be specified via that builder. * * @param programId - the program that owns the accounts we are filtering */ static gpaBuilder(programId = new web3.PublicKey('RainEraPU5yDoJmTrHdYynK9739GkEfDsE4ffqce2BR')) { return beetSolana.GpaBuilder.fromStruct(programId, exports.poolBeet); } /** * Deserializes the {@link Pool} from the provided data Buffer. * @returns a tuple of the account data and the offset up to which the buffer was read to obtain it. */ static deserialize(buf, offset = 0) { return exports.poolBeet.deserialize(buf, offset); } /** * Serializes the {@link Pool} into a Buffer. * @returns a tuple of the created Buffer and the offset up to which the buffer was written to store it. */ serialize() { return exports.poolBeet.serialize(Object.assign({ accountDiscriminator: exports.poolDiscriminator }, this)); } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link Pool} */ static get byteSize() { return exports.poolBeet.byteSize; } /** * Fetches the minimum balance needed to exempt an account holding * {@link Pool} data from rent * * @param connection used to retrieve the rent exemption information */ static getMinimumBalanceForRentExemption(connection, commitment) { return __awaiter(this, void 0, void 0, function* () { return connection.getMinimumBalanceForRentExemption(Pool.byteSize, commitment); }); } /** * Determines if the provided {@link Buffer} has the correct byte size to * hold {@link Pool} data. */ static hasCorrectByteSize(buf, offset = 0) { return buf.byteLength - offset === Pool.byteSize; } /** * Returns a readable version of {@link Pool} properties * and can be used to convert to JSON and/or logging */ pretty() { return { bump: this.bump, owner: this.owner.toBase58(), currency: this.currency.toBase58(), oraclePoolUsd: this.oraclePoolUsd.toBase58(), oracleSolUsd: this.oracleSolUsd.toBase58(), status: 'PoolStatus.' + PoolStatus_1.PoolStatus[this.status], isCompounded: this.isCompounded, isShared: this.isShared, totalAmount: (() => { const x = this.totalAmount; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), borrowedAmount: (() => { const x = this.borrowedAmount; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), availableAmount: (() => { const x = this.availableAmount; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), usableAmount: (() => { const x = this.usableAmount; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), loanCurve: this.loanCurve, mortgageCurve: this.mortgageCurve, isMortgageEnabled: this.isMortgageEnabled, nftLocked: (() => { const x = this.nftLocked; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), totalLiquidations: (() => { const x = this.totalLiquidations; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), totalLoans: (() => { const x = this.totalLoans; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), totalMortgages: (() => { const x = this.totalMortgages; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), totalInterest: (() => { const x = this.totalInterest; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), depositedAt: (() => { const x = this.depositedAt; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), createdAt: (() => { const x = this.createdAt; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), updatedAt: (() => { const x = this.updatedAt; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), collectionsUpdatedAt: (() => { const x = this.collectionsUpdatedAt; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), lastLoanAt: (() => { const x = this.lastLoanAt; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), lastMortgageAt: (() => { const x = this.lastMortgageAt; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), conditions: this.conditions, liquidation: this.liquidation, whitelist: this.whitelist.toBase58(), depositedAmount: (() => { const x = this.depositedAmount; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), minAmountPerLoan: (() => { const x = this.minAmountPerLoan; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), padding: this.padding, collections: this.collections, }; } } exports.Pool = Pool; /** * @category Accounts * @category generated */ exports.poolBeet = new beet.BeetStruct([ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['bump', beet.u8], ['owner', beetSolana.publicKey], ['currency', beetSolana.publicKey], ['oraclePoolUsd', beetSolana.publicKey], ['oracleSolUsd', beetSolana.publicKey], ['status', PoolStatus_1.poolStatusBeet], ['isCompounded', beet.bool], ['isShared', beet.bool], ['totalAmount', beet.u64], ['borrowedAmount', beet.u64], ['availableAmount', beet.u64], ['usableAmount', beet.u64], ['loanCurve', Curve_1.curveBeet], ['mortgageCurve', Curve_1.curveBeet], ['isMortgageEnabled', beet.bool], ['nftLocked', beet.u64], ['totalLiquidations', beet.u64], ['totalLoans', beet.u64], ['totalMortgages', beet.u64], ['totalInterest', beet.u64], ['depositedAt', beet.u64], ['createdAt', beet.u64], ['updatedAt', beet.u64], ['collectionsUpdatedAt', beet.u64], ['lastLoanAt', beet.u64], ['lastMortgageAt', beet.u64], ['conditions', PoolCondition_1.poolConditionBeet], ['liquidation', PoolLiquidation_1.poolLiquidationBeet], ['whitelist', beetSolana.publicKey], ['depositedAmount', beet.u64], ['minAmountPerLoan', beet.u64], ['padding', beet.uniformFixedSizeArray(beet.u64, 14)], ['collections', beet.uniformFixedSizeArray(PoolCollection_1.poolCollectionBeet, 50)], ], Pool.fromArgs, 'Pool'); //# sourceMappingURL=Pool.js.map