UNPKG

@rainfi/sdk

Version:

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

298 lines 11.5 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.userStatsBeet = exports.UserStats = exports.userStatsDiscriminator = void 0; const web3 = __importStar(require("@solana/web3.js")); const beet = __importStar(require("@metaplex-foundation/beet")); const beetSolana = __importStar(require("@metaplex-foundation/beet-solana")); exports.userStatsDiscriminator = [176, 223, 136, 27, 122, 79, 32, 227]; /** * Holds the data for the {@link UserStats} Account and provides de/serialization * functionality for that data * * @category Accounts * @category generated */ class UserStats { constructor(owner, totalLoan, totalMortgage, totalLiquidation, currentLoan, currentMortgage, createdAt, totalVolumeBorrower, totalVolumePool, points, creditScore, referrer, padding /* size: 24 */) { this.owner = owner; this.totalLoan = totalLoan; this.totalMortgage = totalMortgage; this.totalLiquidation = totalLiquidation; this.currentLoan = currentLoan; this.currentMortgage = currentMortgage; this.createdAt = createdAt; this.totalVolumeBorrower = totalVolumeBorrower; this.totalVolumePool = totalVolumePool; this.points = points; this.creditScore = creditScore; this.referrer = referrer; this.padding = padding; } /** * Creates a {@link UserStats} instance from the provided args. */ static fromArgs(args) { return new UserStats(args.owner, args.totalLoan, args.totalMortgage, args.totalLiquidation, args.currentLoan, args.currentMortgage, args.createdAt, args.totalVolumeBorrower, args.totalVolumePool, args.points, args.creditScore, args.referrer, args.padding); } /** * Deserializes the {@link UserStats} 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 UserStats.deserialize(accountInfo.data, offset); } /** * Retrieves the account info from the provided address and deserializes * the {@link UserStats} 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 UserStats account at ${address}`); } return UserStats.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.userStatsBeet); } /** * Deserializes the {@link UserStats} 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.userStatsBeet.deserialize(buf, offset); } /** * Serializes the {@link UserStats} 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.userStatsBeet.serialize(Object.assign({ accountDiscriminator: exports.userStatsDiscriminator }, this)); } /** * Returns the byteSize of a {@link Buffer} holding the serialized data of * {@link UserStats} */ static get byteSize() { return exports.userStatsBeet.byteSize; } /** * Fetches the minimum balance needed to exempt an account holding * {@link UserStats} 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(UserStats.byteSize, commitment); }); } /** * Determines if the provided {@link Buffer} has the correct byte size to * hold {@link UserStats} data. */ static hasCorrectByteSize(buf, offset = 0) { return buf.byteLength - offset === UserStats.byteSize; } /** * Returns a readable version of {@link UserStats} properties * and can be used to convert to JSON and/or logging */ pretty() { return { owner: this.owner.toBase58(), totalLoan: (() => { const x = this.totalLoan; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), totalMortgage: (() => { const x = this.totalMortgage; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), totalLiquidation: (() => { const x = this.totalLiquidation; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), currentLoan: (() => { const x = this.currentLoan; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), currentMortgage: (() => { const x = this.currentMortgage; 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; })(), totalVolumeBorrower: (() => { const x = this.totalVolumeBorrower; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), totalVolumePool: (() => { const x = this.totalVolumePool; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), points: (() => { const x = this.points; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), creditScore: (() => { const x = this.creditScore; if (typeof x.toNumber === 'function') { try { return x.toNumber(); } catch (_) { return x; } } return x; })(), referrer: this.referrer.toBase58(), padding: this.padding, }; } } exports.UserStats = UserStats; /** * @category Accounts * @category generated */ exports.userStatsBeet = new beet.BeetStruct([ ['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)], ['owner', beetSolana.publicKey], ['totalLoan', beet.u64], ['totalMortgage', beet.u64], ['totalLiquidation', beet.u64], ['currentLoan', beet.u64], ['currentMortgage', beet.u64], ['createdAt', beet.u64], ['totalVolumeBorrower', beet.u64], ['totalVolumePool', beet.u64], ['points', beet.u64], ['creditScore', beet.u64], ['referrer', beetSolana.publicKey], ['padding', beet.uniformFixedSizeArray(beet.u64, 24)], ], UserStats.fromArgs, 'UserStats'); //# sourceMappingURL=UserStats.js.map