UNPKG

@rainfi/sdk

Version:

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

303 lines (302 loc) 10.9 kB
import { CustomLoanFilter, LoanFilter, PoolFilter } from "./layout.utils"; import BN from 'bn.js'; import { Connection, PublicKey } from "@solana/web3.js"; import { Collection, Fees, FullUserStats, Loan, Request, Pool, SplPoolCollection, UserStats } from '../types/types'; import { createInitializeAccountInstruction } from '@solana/spl-token'; export { createInitializeAccountInstruction }; /** * Fetch all Rain pools depending on status. Default to 'active' pools * * @param connection A connection to a fullnode JSON RPC endpoint * @param status pool status: 'active' | 'inactive' | 'all' | 'custom' * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getAllPools(connection: Connection, status?: 'active' | 'inactive' | 'all' | 'custom', customFilter?: { key: PoolFilter; value: string; }[]): Promise<Pool[]>; /** * DEPRECATED Fetch all pools from rain with an open status. * * @param connection A connection to a fullnode JSON RPC endpoint * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getAllPoolAvailable(connection: Connection, customFilter?: { key: PoolFilter; value: string; }[]): Promise<Pool[]>; /** * Fetch loan from a lender address. * * @param connection A connection to a fullnode JSON RPC endpoint * @param address lender pubkey * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getLoansFromPool(connection: Connection, address: PublicKey, customFilter?: { key: LoanFilter; value: string; }[]): Promise<Loan[]>; /** * Fetch all loans from a borrower address. * * @param connection A connection to a fullnode JSON RPC endpoint * @param address borrower pubkey * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getLoansFromBorrower(connection: Connection, address: PublicKey, customFilter?: { key: LoanFilter; value: string; }[]): Promise<Loan[]>; /** * Fetch all loans from a collectionId. * * @param connection A connection to a fullnode JSON RPC endpoint * @param collectionId collection number/id * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getLoansFromCollectionId(connection: Connection, collectionId: number, customFilter?: { key: LoanFilter; value: string; }[]): Promise<Loan[]>; /** * Fetch all custom loans account from a borrower address. * * @param connection A connection to a fullnode JSON RPC endpoint * @param address borrower pubkey * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getCustomLoanOffersFromBorrower(connection: Connection, address: PublicKey, customFilter?: { key: CustomLoanFilter; value: string; }[]): Promise<{ loans: Request[]; mortgages: Request[]; }>; /** * Fetch all custom loans account from a lender address. * * @param connection A connection to a fullnode JSON RPC endpoint * @param address lender pubkey * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getCustomLoanOffersFromLender(connection: Connection, address: PublicKey, customFilter?: { key: CustomLoanFilter; value: string; }[]): Promise<{ loans: Request[]; mortgages: Request[]; }>; /** * Fetch all custom loans account for a given collectionId. * * @param connection A connection to a fullnode JSON RPC endpoint * @param collectionId lender pubkey * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getCustomLoanOffersFromCollectionId(connection: Connection, collectionId: number, customFilter?: { key: CustomLoanFilter; value: string; }[]): Promise<Request[]>; /** * Fetch pool for a given pool owner address. * * @param connection A connection to a fullnode JSON RPC endpoint * @param address owner of the pool pubkey * */ export declare function getPoolFromOwnerAddress(connection: Connection, address: PublicKey): Promise<Pool>; export declare function fetchPoolFromOwner(connection: Connection, owner: PublicKey): Promise<Pool>; /** * Fetch the user stats account of a given user. * * @param userPubkey user pubkey. * */ export declare function getUserStats(userPubkey: PublicKey): Promise<UserStats>; /** * get full user stats. * * @param connection A connection to a fullnode JSON RPC endpoint * @param user owner of the pool pubkey * @param mints Array of string | pubkey mint address to check, ex: ["So11111111111111111111111111111111111111112", "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"] * */ export declare function getFullUserStats(connection: Connection, user: PublicKey, mints?: string[] | PublicKey[]): Promise<FullUserStats | null>; /** * Fetch all users stats account. * * @param connection A connection to a fullnode JSON RPC endpoint * */ export declare function getAllUsersStats(connection: Connection): Promise<UserStats[]>; /** * fetch collection data for a specific pool. * * @param connection A connection to a fullnode JSON RPC endpoint * @param poolOwner owner of the pool pubkey * */ export declare function getWhitelistedCollectionFromPool(connection: Connection, poolOwner: PublicKey): Promise<Collection[]>; /** * fetch collection data from array of rain collection Ids. * * @param connection A connection to a fullnode JSON RPC endpoint * @param collectionsIds array of collection Ids * */ export declare function getWhitelistedCollectionFromIds(connection: Connection, collectionsIds: SplPoolCollection[], pool?: Pool): Promise<Collection[]>; /** * Fetch all collections existing in Rain. * * @param connection A connection to a fullnode JSON RPC endpoint * */ export declare function getAvailableCollections(connection: Connection): Promise<Collection[]>; /** * Get collection data parsed from collection address or collection Id. * * @param connection A connection to a fullnode JSON RPC endpoint * @param arg collection address or collection Id * */ export declare function getCollection(connection: Connection, arg: PublicKey | number): Promise<Collection>; /** * Fetch mortgage for a specific address. * * @param connection A connection to a fullnode JSON RPC endpoint * @param address mortgage account * @param from pool or borrower * @param ongoingMortgageOnly *OPTIONAL* default to true * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getMortgageFromAddress(connection: Connection, address: PublicKey, as: 'borrower' | 'pool', ongoingMortgageOnly?: boolean, customFilter?: { key: LoanFilter; value: string; }[]): Promise<Loan[]>; /** * Fetch ALL mortgages for a given collectionId. * * @param connection A connection to a fullnode JSON RPC endpoint * @param collectionId collection number/id * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getMortgagesFromCollectionId(connection: Connection, collectionId: number, customFilter?: { key: LoanFilter; value: string; }[]): Promise<Loan[]>; /** * get loans and mortgages for sale. * * @param connection A connection to a fullnode JSON RPC endpoint * @param collectionId OPTIONAL collection ID * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getDebtsForSale(connection: Connection, collectionId?: number, customFilter?: { key: LoanFilter; value: string; }[]): Promise<Loan[]>; /** * get sold loans and mortgages. * * @param connection A connection to a fullnode JSON RPC endpoint * @param customFilter Optional custom filter to fetch depending on custom condition * */ export declare function getDebtsSold(connection: Connection, customFilter?: { key: LoanFilter; value: string; }[]): Promise<Loan[]>; /** * Get pool filter for getProgramAccount function. * * @param payload * */ export declare function getFiltersPool(payload: { key: PoolFilter; value: string; }[]): any; /** * Get more readable pool account. * * @param data prettyfied pool account * */ export declare function parsePoolAccount(data: any): any; /** * Get more readable Loan account. * * @param data prettyfied loan account * */ export declare function parseLoanAccount(data: any): any; /** * Get more readable Custom Loan account. * * @param data prettyfied custom loan account * */ export declare function parseCustomLoanAccount(data: any): any; /** * Get more readable Collection account. * * @param data prettyfied Collection account * */ export declare function parseCollectionAccount(data: any): any; /** * Get the amount argument to pass to Borrow function. * * @param ltv loanToValue from the pool * @param amount amount to borrow, must be lower than floorPrice * (loanToValue / 10000) * */ export declare const computeAmount: (ltv: number, amount: number) => number; /** * Get the interest that user will pay with given parameter. * * @param amount amount user want to borrow in LAMPORTS * @param duration duration in days chosen by the user of the loan * @param interestRate param from pool in basis points, 100 points means 1% * @param totalAmount total liquidity of the pool in LAMPORTS * @param borrowedAmount currently borrowed liquidity of the pool in LAMPORTS * @param baseInterest param from pool in basis points, 100 points means 1% * @param maxDuration max duration of the loan in days * @param curveRate param from pool in basis points, 100 points means 1% * @param curveRateDay param from pool in basis points, 100 points means 1% * */ export declare const computeInterest: (amount: BN, duration: number, interestRate: number, totalAmount: BN, borrowedAmount: BN, baseInterest: number, maxDuration: number, curveRate: number, curveRateDay: number, kind?: 'mortgage' | 'loan') => { interestLamports: BN; interestPercentage: BN; rainFees: BN; }; /** * Get the interest for a LOAN that user will pay with given parameters. * * @param pool Pool account that will fund the loan * @param amount amount user want to borrow in lamports * @param duration duration in days chosen by the user of the loan * */ export declare const getFeesDetailed: (pool: Pool, amount: number, duration: number) => Fees; /** * Get the interest for a MORTGAGE that user will pay with given parameters. * * @param pool Pool account that will finance the mortgage * @param amount amount user want to borrow in lamports, should be 50% of the NFT price * @param duration duration in days chosen by the user of the loan * */ export declare const getMortgagesFeesDetailed: (pool: Pool, amount: number, duration: number) => Fees;