@rainfi/sdk
Version:
This package is used to interact with Rain.fi protocol on Solana
399 lines (398 loc) • 14.7 kB
TypeScript
/// <reference types="node" />
import { AccountInfo, Connection, Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
import * as errors from "./generated/errors";
import * as accounts from "./generated/accounts";
import * as utils from "./utils/fetch.utils";
import * as instructions from "./utils/instructions.utils";
import * as types from "./types/types";
import { PoolStatus } from "./generated";
export declare class Rain {
connection: Connection | undefined;
publicKey: PublicKey | undefined;
constructor(connection?: Connection, wallet?: PublicKey);
readonly PUBKEY: PublicKey;
readonly instructions: typeof instructions;
readonly errors: typeof errors;
readonly accounts: typeof accounts;
readonly utils: typeof utils;
readonly types: typeof types;
/**
* Creates a _createPool_ instruction.
*
* @param args parameter of your pool, explained in the doc.
* @param splAddress [Optional] SPL address of the currency of the pool, default to wSOL.
*
*/
createPool(args: types.CreatePoolArgs, splAddress?: PublicKey): Promise<TransactionInstruction[]>;
/**
* Creates a _updatePool_ instruction.
*
* @param args parameter of your pool, explained in the doc.
*
*/
updatePool(args: types.UpdatePoolArgs): Promise<TransactionInstruction>;
/**
* Creates a _updatePoolCollections_ instruction.
*
* @param collections Id of the collections that you want to authorize loan to.
*
*/
updatePoolCollections(collections: types.UserInputPoolCollection[]): Promise<TransactionInstruction>;
/**
* Creates a _borrow_ instruction.
*
* @param args BorrowArgs of your loan, explained in the doc.
* @param referrer (optional) wallet address of the referrer to get a commission of the protocol fees.
*
*/
borrow(args: types.BorrowArgs, referrer?: PublicKey | undefined, isCompressed?: boolean): Promise<{
instruction: TransactionInstruction[];
signers: Keypair;
}>;
/**
* Creates a _extendLoan_ instruction.
*
* @param args ExtendArgs of your loan, explained in the doc.
* @param amountToRepay amount of interest to repay to close current loan
*
*/
extend(args: types.ExtendArgs, amountToRepay: number): Promise<{
instruction: TransactionInstruction[];
signers: Keypair;
}>;
/**
* Creates a _repayLoan_ instruction.
*
* @param loanAccount pubkey of the loan account.
* @param amount total amount to repay.
*
*/
repayLoan(loanAccount: PublicKey, amount: number, isCompressed?: boolean): Promise<TransactionInstruction[]>;
/**
* Creates a _liquidate_ instruction.
*
* @param loanAccount pubkey of the loan account.
*
*/
liquidate(loanAccount: PublicKey): Promise<TransactionInstruction>;
/**
* Creates a _addLiquidity_ instruction.
*
* @param amount amount of SOL in lamports to add to pool.
*
*/
addLiquidity(amount: number): Promise<TransactionInstruction[]>;
/**
* Creates a _withdrawLiquidity_ instruction.
*
* @param amount amount of SOL in lamports to add to pool.
*
*/
withdrawLiquidity(amount: number): Promise<TransactionInstruction[]>;
/**
* Creates a _updatePoolStatus_ instruction.
* No parameter required since we can find the pool from the signer address.
* If the pool is disabled, it will enabled it, if pool enabled, will disable it
*/
updatePoolStatus(status: PoolStatus): TransactionInstruction;
/**
* Creates a _closePool_ instruction.
* No parameter required since we can find the pool from the signer address.
* This will DELETE THE POOL and delete all its data, be sure of what you are doing
*/
closePool(confirm?: boolean): TransactionInstruction;
/**
* Creates a _setMaxAmountUsable_ instruction.
*
* @param amount max amount usable in the pool.
*
*/
setMaxAmountUsable(amount: number): TransactionInstruction;
/**
* Creates a _makeLoanRequest_ instruction.
*
* @param args loanRequestArgs of your loan request, explained in the doc.
*
*/
makeLoanRequest(args: types.LoanRequestArgs): Promise<TransactionInstruction>;
/**
* Creates a _cancelLoanRequest_ instruction.
*
* @param loanRequestAddress pubkey of the account holding the loan request data.
*
*/
cancelLoanRequest(loanRequestAddress: PublicKey): Promise<TransactionInstruction>;
/**
* Creates a _acceptLoanRequest_ instruction.
*
* @param loanRequestAddress pubkey of the account holding the loan request data.
*
*/
acceptLoanRequest(loanRequestAddress: PublicKey): Promise<TransactionInstruction>;
/**
* Creates a _poolCancelLoanProposal_ instruction.
*
* @param loanRequestAddress pubkey of the account holding the loan request data.
*
*/
poolCancelLoanProposal(loanRequestAddress: PublicKey): Promise<TransactionInstruction>;
/**
* Creates a _executeLoanRequest_ instructions.
*
* @param args ExecuteLoanRequestArgs TODO.
*
*/
executeLoanRequest(args: types.ExecuteLoanRequestArgs): Promise<{
instruction: TransactionInstruction[];
signers: Keypair;
}>;
/**
* Creates a _buyMortgage_ instructions.
*
* @param args BuyArgs, see types.
*
*/
buyMortgage(args: types.BuyArgs): Promise<{
instruction: TransactionInstruction[];
signers: Keypair[];
}>;
/**
* Creates a _repayMortgage_ instructions.
*
* @param mortgageAddress mortgage account address
* @param amount amount to repay
*
*/
repayMortgage(mortgageAddress: PublicKey, amount: number): Promise<TransactionInstruction[]>;
/**
* Creates a _sellMortgage_ instructions.
*
* @param mortgageAddress mortgage account pubkey.
* @param nftMint pubkey of NFT.
* @param price .
*
*/
sellMortgage(mortgageAddress: PublicKey, nftMint: PublicKey, price: number): Promise<TransactionInstruction>;
/**
* Creates a _buyListedMortgage_ instructions.
* These instructions need to be sent in a Versioned Transaction, or in two separate transaction
*
* @param mortgage Mortgage account data.
* @param poolOwner PublicKey.
*
*/
buyListedMortgage(mortgage: types.Loan, poolOwner: PublicKey): Promise<{
ixs: TransactionInstruction[];
signers: Keypair | null;
}[]>;
/**
* get user stats.
*
* @param user owner of the pool pubkey
* @param mints Array of string | pubkey mint address to check, ex: ["So11111111111111111111111111111111111111112", "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"]
*
*/
getUserStats(user: PublicKey, mints?: string[] | PublicKey[]): Promise<types.FullUserStats | null>;
/**
* Creates a _unfreeze_ instructions.
*
* @param mortgageAddress mortgage account address
*
*/
unfreeze(mortgageAddress: PublicKey): Promise<TransactionInstruction[]>;
/**
* Creates a _sellNft_ instructions.
*
* @param mortgageAddress mortgage account address
* @param bestOrder order from tensor
*
*/
sellNft(mortgageAddress: PublicKey, bestOrder: {
address: string;
sellNowPrice: number;
}, amount?: number): Promise<TransactionInstruction[]>;
/**
* Fetch all users stats account.
*
*/
getAllUsersStats(): Promise<types.UserStats[]>;
deserializePoolAccount(data: AccountInfo<Buffer>): types.Pool;
deserializeLoanAccount(data: AccountInfo<Buffer>): types.Loan;
deserializeCollectionAccount(data: AccountInfo<Buffer>): types.Collection;
deserializeLoanRequestAccount(data: AccountInfo<Buffer>): types.Request;
deserializeUserStatsAccount(data: AccountInfo<Buffer>): types.UserStats;
}
export declare class Pool {
owner: PublicKey;
connection: Connection;
publicKey: PublicKey | undefined;
constructor(connection: Connection, owner: PublicKey, publicKey?: PublicKey);
/**
* Fetch pool data.
*/
fetch(): Promise<types.Pool>;
/**
* Get whitelisted collections from pool.
*/
collections(): Promise<types.Collection[]>;
/**
* Get all loans from pool, including current, liquidated and repaid ones.
* @param type type of loans to fetch. 'all' | 'history' | 'ongoing' Default to 'all'
*/
loans(type: "all" | "history" | "ongoing", borrower?: PublicKey): Promise<types.Loan[]>;
/**
* Get all loans request from pool, including accepted and pending ones.
* @param type type of loans request to fetch. 'all' | 'accepted' | 'pending' Default to 'all'
*/
loanRequests(type: "all" | "accepted" | "pending", borrower?: PublicKey): Promise<{
loans: types.Request[];
mortgages: types.Request[];
}>;
/**
* Get all mortgages from pool, including ongoing, liquidated, and repaid ones.
* @param type type of loans to fetch. 'all' | 'history' | 'ongoing' Default to 'all'
*/
mortgages(type: "all" | "history" | "ongoing" | "for_sale", borrower?: PublicKey): Promise<types.Loan[]>;
/**
* Get pool fees breakdown based on values given.
*
* @param amount amount to borrow, must be lower than floorPrice * (loanToValue / 100000) or collection.maxAmountToBorrow
* @param duration duration in days of the loan
*
*/
fees(amount: number, duration: number): Promise<types.Fees>;
/**
* Get mortgages pool fees breakdown based on values given.
*
* @param amount amount to borrow, must be lower or equal to floorPrice / 2
* @param duration duration in days of the loan
*
*/
mortgagesFees(amount: number, duration: number): Promise<types.Fees>;
/**
* Creates a _borrow_ instruction.
*
* @param nftMint pubkey of the NFT to use as collateral
* @param duration duration in days of the loan,
* @param amount amount of lamports that the borrower need, must be lower than collection.maxAmountToBorrow,
* @param interest total interest user will pay
* @param slippage max slippage in basis points, 100 points means 1%, default to 50 bps / 0.5%
*
*/
borrow(nftMint: PublicKey, duration: number, amount: number, interest: number, slippage?: number, referrerTa?: PublicKey | undefined, lookupTable?: PublicKey | undefined): Promise<{
instruction: TransactionInstruction[];
signers: Keypair;
}>;
/**
* Creates a _extend_ instruction.
*
* @param nftMint pubkey of the NFT to use as collateral
* @param currentLoan current loan address,
* @param duration duration in days of the loan,
* @param amount amount of lamports that the borrower need, must be lower than collection.maxAmountToBorrow,
* @param interest total interest user will pay
* @param amountToRepay amount of interest to repay to close current loan
* @param slippage max slippage in basis points, 100 points means 1%, default to 50 bps / 0.5%
*
*/
extend(nftMint: PublicKey, currentLoan: PublicKey, duration: number, amount: number, interest: number, slippage?: number, lookupTable?: PublicKey | undefined): Promise<{
instruction: TransactionInstruction[];
signers: Keypair;
}>;
/**
* Creates a _repay_ instruction.
*
* @param loanAccount pubkey of the loan account.
* @param amount total amount to repay.
*
*/
repay(loanAccount: PublicKey, amount: number): Promise<TransactionInstruction[]>;
/**
* Creates a _makeLoanRequest_ instruction.
*
* @param nftMint pubkey of the NFT to use as collateral
* @param duration duration in days of the loan,
* @param amount amount of lamports that the borrower need, must be lower than collection.maxAmountToBorrow,
* @param floorPrice floor price of collection
*
*/
makeLoanRequest(nftMint: PublicKey, duration: number, amount: number): Promise<TransactionInstruction>;
/**
* Creates a _cancelLoanRequest_ instruction.
*
* @param loanRequestAddress pubkey of the account holding the loan request data.
*
*/
cancelLoanRequest(loanRequestAddress: PublicKey): Promise<TransactionInstruction>;
/**
* Creates a _acceptLoanRequest_ instruction.
*
* @param loanRequestAddress pubkey of the account holding the loan request data.
*
*/
acceptLoanRequest(loanRequestAddress: PublicKey): Promise<TransactionInstruction>;
/**
* Creates a _poolCancelLoanProposal_ instruction.
*
* @param loanRequestAddress pubkey of the account holding the loan request data.
*
*/
poolCancelLoanProposal(loanRequestAddress: PublicKey): Promise<TransactionInstruction>;
/**
* Creates a _executeLoanRequest_ instructions.
*
* @param args ExecuteLoanRequestArgs TODO.
*
*/
executeLoanRequest(args: types.ExecuteLoanRequestArgs): Promise<{
instruction: TransactionInstruction[];
signers: Keypair;
}>;
/**
* Creates a _buy_ instructions.
*
* @param args BuyArgs, see types.
*
*/
buy(args: {
nftMint: PublicKey;
seller?: PublicKey;
auctionHousePubkey?: PublicKey;
escrowAddress?: PublicKey;
marketplace: "solanart" | "auction_house" | "hadeswap" | "tensorswap_order" | "tensorswap_listing";
interest: number;
slippage: number;
price: number;
amount: number;
duration: number;
}): Promise<{
instruction: TransactionInstruction[];
signers: Keypair[];
}>;
/**
* Creates a _repayMortgage_ instructions.
*
* @param mortgageAddress mortgage account address
* @param amount amount to repay
*
*/
repayMortgage(mortgageAddress: PublicKey, amount: number): Promise<TransactionInstruction[]>;
/**
* Creates a _unfreeze_ instructions.
*
* @param mortgageAddress mortgage account address
*
*/
unfreeze(mortgageAddress: PublicKey): Promise<TransactionInstruction[]>;
/**
* Creates a _sellNft_ instructions.
*
* @param mortgageAddress mortgage account address
* @param bestOrder order from tensor
*
*/
sellNft(mortgageAddress: PublicKey, bestOrder: {
address: string;
sellNowPrice: number;
}, amount?: number): Promise<TransactionInstruction[]>;
}