@rainfi/sdk
Version:
This package is used to interact with Rain.fi protocol on Solana
351 lines • 13.6 kB
JavaScript
"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.loanBeet = exports.Loan = exports.loanDiscriminator = 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 LoanKind_1 = require("../types/LoanKind");
const LoanStatus_1 = require("../types/LoanStatus");
const Marketplace_1 = require("../types/Marketplace");
const Sale_1 = require("../types/Sale");
const Listing_1 = require("../types/Listing");
exports.loanDiscriminator = [20, 195, 70, 117, 165, 227, 182, 1];
/**
* Holds the data for the {@link Loan} Account and provides de/serialization
* functionality for that data
*
* @category Accounts
* @category generated
*/
class Loan {
constructor(kind, status, borrower, lender, pool, mint, currency, isCustom, isFrozen, price, interest, amount, duration, collection, liquidation, marketplace, sale, createdAt, expiredAt, repaidAt, soldAt, liquidatedAt, listing, isCompressedLoan, isDefi, collateralAmount, collateralDecimals, padding /* size: 5 */, padding1) {
this.kind = kind;
this.status = status;
this.borrower = borrower;
this.lender = lender;
this.pool = pool;
this.mint = mint;
this.currency = currency;
this.isCustom = isCustom;
this.isFrozen = isFrozen;
this.price = price;
this.interest = interest;
this.amount = amount;
this.duration = duration;
this.collection = collection;
this.liquidation = liquidation;
this.marketplace = marketplace;
this.sale = sale;
this.createdAt = createdAt;
this.expiredAt = expiredAt;
this.repaidAt = repaidAt;
this.soldAt = soldAt;
this.liquidatedAt = liquidatedAt;
this.listing = listing;
this.isCompressedLoan = isCompressedLoan;
this.isDefi = isDefi;
this.collateralAmount = collateralAmount;
this.collateralDecimals = collateralDecimals;
this.padding = padding;
this.padding1 = padding1;
}
/**
* Creates a {@link Loan} instance from the provided args.
*/
static fromArgs(args) {
return new Loan(args.kind, args.status, args.borrower, args.lender, args.pool, args.mint, args.currency, args.isCustom, args.isFrozen, args.price, args.interest, args.amount, args.duration, args.collection, args.liquidation, args.marketplace, args.sale, args.createdAt, args.expiredAt, args.repaidAt, args.soldAt, args.liquidatedAt, args.listing, args.isCompressedLoan, args.isDefi, args.collateralAmount, args.collateralDecimals, args.padding, args.padding1);
}
/**
* Deserializes the {@link Loan} 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 Loan.deserialize(accountInfo.data, offset);
}
/**
* Retrieves the account info from the provided address and deserializes
* the {@link Loan} 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 Loan account at ${address}`);
}
return Loan.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.loanBeet);
}
/**
* Deserializes the {@link Loan} 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.loanBeet.deserialize(buf, offset);
}
/**
* Serializes the {@link Loan} 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.loanBeet.serialize(Object.assign({ accountDiscriminator: exports.loanDiscriminator }, this));
}
/**
* Returns the byteSize of a {@link Buffer} holding the serialized data of
* {@link Loan}
*/
static get byteSize() {
return exports.loanBeet.byteSize;
}
/**
* Fetches the minimum balance needed to exempt an account holding
* {@link Loan} 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(Loan.byteSize, commitment);
});
}
/**
* Determines if the provided {@link Buffer} has the correct byte size to
* hold {@link Loan} data.
*/
static hasCorrectByteSize(buf, offset = 0) {
return buf.byteLength - offset === Loan.byteSize;
}
/**
* Returns a readable version of {@link Loan} properties
* and can be used to convert to JSON and/or logging
*/
pretty() {
return {
kind: 'LoanKind.' + LoanKind_1.LoanKind[this.kind],
status: 'LoanStatus.' + LoanStatus_1.LoanStatus[this.status],
borrower: this.borrower.toBase58(),
lender: this.lender.toBase58(),
pool: this.pool.toBase58(),
mint: this.mint.toBase58(),
currency: this.currency.toBase58(),
isCustom: this.isCustom,
isFrozen: this.isFrozen,
price: (() => {
const x = this.price;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
interest: (() => {
const x = this.interest;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
amount: (() => {
const x = this.amount;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
duration: (() => {
const x = this.duration;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
collection: this.collection,
liquidation: this.liquidation,
marketplace: 'Marketplace.' + Marketplace_1.Marketplace[this.marketplace],
sale: this.sale,
createdAt: (() => {
const x = this.createdAt;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
expiredAt: (() => {
const x = this.expiredAt;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
repaidAt: (() => {
const x = this.repaidAt;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
soldAt: (() => {
const x = this.soldAt;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
liquidatedAt: (() => {
const x = this.liquidatedAt;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
listing: this.listing,
isCompressedLoan: this.isCompressedLoan,
isDefi: this.isDefi,
collateralAmount: (() => {
const x = this.collateralAmount;
if (typeof x.toNumber === 'function') {
try {
return x.toNumber();
}
catch (_) {
return x;
}
}
return x;
})(),
collateralDecimals: this.collateralDecimals,
padding: this.padding,
padding1: this.padding1,
};
}
}
exports.Loan = Loan;
/**
* @category Accounts
* @category generated
*/
exports.loanBeet = new beet.BeetStruct([
['accountDiscriminator', beet.uniformFixedSizeArray(beet.u8, 8)],
['kind', LoanKind_1.loanKindBeet],
['status', LoanStatus_1.loanStatusBeet],
['borrower', beetSolana.publicKey],
['lender', beetSolana.publicKey],
['pool', beetSolana.publicKey],
['mint', beetSolana.publicKey],
['currency', beetSolana.publicKey],
['isCustom', beet.bool],
['isFrozen', beet.bool],
['price', beet.u64],
['interest', beet.u64],
['amount', beet.u64],
['duration', beet.u64],
['collection', beet.u32],
['liquidation', beet.u16],
['marketplace', Marketplace_1.marketplaceBeet],
['sale', Sale_1.saleBeet],
['createdAt', beet.u64],
['expiredAt', beet.u64],
['repaidAt', beet.u64],
['soldAt', beet.u64],
['liquidatedAt', beet.u64],
['listing', Listing_1.listingBeet],
['isCompressedLoan', beet.bool],
['isDefi', beet.bool],
['collateralAmount', beet.u64],
['collateralDecimals', beet.u8],
['padding', beet.uniformFixedSizeArray(beet.u64, 5)],
['padding1', beet.u32],
], Loan.fromArgs, 'Loan');
//# sourceMappingURL=Loan.js.map