UNPKG

@algofi/lend

Version:

The official JavaScript SDK for the Algofi Lending Protocol

429 lines (428 loc) 17.4 kB
import { Algodv2, Indexer, SuggestedParams } from "algosdk"; import { TransactionGroup } from "../utils"; import { StakingContract } from "./stakingContract"; import { Manager } from "./manager"; import { Market } from "./market"; import { Asset } from "./asset"; export declare class Client { scaleFactor: number; borrowSharesInit: number; parameterScaleFactor: number; algod: Algodv2; indexerClient: Indexer; historicalIndexer: Indexer; chain: string; userAddress: string; initRound: number; activeOrderedSymbols: string[]; maxOrderedSymbols: string[]; maxAtomicOptInOrderedSymbols: string[]; manager: Manager; markets: { [key: string]: Market; }; stakingContractInfo: { [key: string]: { [key: string]: number; }; }; stakingContracts: { [key: string]: StakingContract; }; /** * * This is the constructor for the Client class. * * **Note, do not call this to create a new client**. Instead call * the static method init as there are asynchronous set up steps in * creating an client and a constructor can only return an instance of * the class and not a promise. * * #### Example * ```typescript * //Correct way to instantiate new client * const client = await Client.init(algodClient, indexerClient, historicalIndexerClient, userAddress, chain) * * //Incorrect way to instantiate new client * const client = new Client(algodClient, indexerClient, historicalIndexerClient, userAddress, chain) * ``` * * @param algodClient - algod client * @param indexerClient - indexer client * @param historicalIndexerClient - indexer client * @param userAddress - account address of user * @param chain - specified chain we want the client to run on */ constructor(algodClient: Algodv2, indexerClient: Indexer, historicalIndexerClient: Indexer, userAddress: string, chain: string); /** * This is the function that should be called when creating a new client. * You pass everything you would to the constructor, but to this function * instead and this returns the new and created client. * * #### Example * ```typescript * //Correct way to instantiate new client * const client = await Client.init(algodClient, indexerClient, historicalIndexerClient, userAddress, chain) * * //Incorrect way to instantiate new client * const client = new Client(algodClient, indexerClient, historicalIndexerClient, userAddress, chain) * ``` * * @param algodClient - algod client * @param indexerClient - indexer client * @param historicalIndexerClient - indexer client * @param userAddress - account address of user * @param chain - specified chain we want the client to run on * @returns an instance of the client class fully constructed */ static init(algodClient: Algodv2, indexerClient: Indexer, historicalIndexerClient: Indexer, userAddress: string, chain: string, fetchStaking?: boolean): Promise<Client>; /** * Initializes the transactions parameters for the client. * * @returns default parameters for transactions */ getDefaultParams(): Promise<SuggestedParams>; /** * Returns a dictionary of information about the user. * * @param address - address to get info for * @returns a dictionary of information about the user */ getUserInfo(address?: string): Promise<{ [key: string]: any; }>; /** * Returns a boolean if the user address is opted into an application with id appId. * * @param appId - id of the application * @param address - address to get information for * @returns boolean if user is opted into application with id appId */ isOptedIntoApp(appId: number, address?: string): Promise<boolean>; /** * Returns a boolean if the user is opted into an asset with id assetId. * * @param assetId - id of the asset * @param address - address to get info for * @returns boolean if user is opted into an asset */ isOptedIntoAsset(assetId: number, address?: string): Promise<boolean>; /** * Returns a dictionary of user balances by assetid. * * @param address - address to get info for * @returns amount of asset */ getUserBalances(address?: string): Promise<{ [key: string]: number; }>; /** * Returns amount of asset in user's balance with asset id assetId. * * @param assetId - id of the asset, * @param address - address to get info for * @returns amount of asset that the user has */ getUserBalance(assetId?: number, address?: string): Promise<number>; /** * Returns a dictionary with the lending market state for a given address (must be opted in). * * @param address - address to get info for; if null, will use address supplied when creating client * @returns dictionary that represents the state of user */ getUserState(address?: string): Promise<{ [key: string]: any; }>; /** * Returns a dictionary witht he lending market state for a given storage address. * * @param storageAddress - address to get info for; if null will use address supplied when creating client * @returns dictionary that represents the storage state of a user */ getStorageState(storageAddress?: string): Promise<{ [key: string]: any; }>; /** * Returns a dictionary with the staking contract state for the named staking contract and selected address * * @param stakingContractName - name of the staking contract to query * @param address - address to get info for; if null will use address supplied when creating client * @returns state representing staking contract info of user */ getUserStakingContractState(stakingContractName: string, address?: string): Promise<{}>; /** * Returns the manager object representing the manager of this client. * * @returns manager */ getManager(): Manager; /** * Returns the market object for the given symbol. * * @param symbol - market symbol * @returns market */ getMarket(symbol: string): Market; /** * Returns a dictionary of active markets by symbol * * @returns markets dictionary */ getActiveMarkets(): { [key: string]: Market; }; /** * Returns a staking contract with the given title * * @param title - staking contract name * @returns staking contract with the given name */ getStakingContract(title: string): StakingContract; /** * Returns a ditionary of all staking contracts * * @returns staking contracts dictionary */ getStakingContracts(): { [key: string]: StakingContract; }; /** * Returns the asset object for the requested symbol * * @param symbol - symbol of the asset * @returns asset object with the provided symbol */ getAsset(symbol: string): Asset; /** * Returns the max opt in market application ids * * @returns list of max opt in market application ids */ getMaxAtomicOptInMarketAppIds(): number[]; /** * Returns a dictionary of the asset objects for each active market * * @returns dictionary of asset objects */ getActiveAssets(): { [key: string]: Asset; }; /** * Returns the active asset ids * * @returns list of active asset ids */ getActiveAssetIds(): number[]; /** * Returns the active bank asset ids * * @returns list of active bank asset ids */ getActiveBankAssetIds(): number[]; /** * Returns the list of symbols of the active assets * * @returns list of symbols for active assets */ getActiveOrderedSymbols(): string[]; /** * Returns a dictionary of raw oracle prices of the active assets pulled from their oracles * * @returns dictionary of int prices */ getRawPrices(): { [key: string]: number; }; /** * Returns a dictionary of dollarized float prices of the assets pulled from their oracles * * @returns dictionary of int prices */ getPrices(): { [key: string]: number; }; /** * Returns a list of storage accounts for the given manager app id * * @param stakingContractName - name of staking contract * @returns list of storage accounts */ getStorageAccounts(stakingContractName?: string): Promise<{}[]>; /** * Returns the list of active oracle app ids * * @returns list of acdtive oracle app ids */ getActiveOracleAppIds(): number[]; /** * Returns the list of the active market app ids * * @returns list of active market app ids */ getActiveMarketAppIds(): number[]; /** * Returns the list of the active market addresses * * @returns list of active market addresses */ getActiveMarketAddresses(): string[]; /** * Returns an opt in transaction group * * @param storageAddress - storage address to fund and rekey * @param address - address to send add collateral transaction group from; defulats to client user address * @returns */ prepareOptinTransactions(storageAddress: string, address?: string): Promise<TransactionGroup>; /** * Returns an add collateral transaction group * * @param symbol - symbol to add collateral with * @param amount - amount of collateral to add * @param address - address to send add collateral transaction group from; defaults to clint user address * @returns */ prepareAddCollateralTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a borrow transaction group * * @param symbol - symbol to borrow * @param amount - amount to borrow * @param address - address to send borrow transaction group from; defaults to client user address * @returns borrow transaction group */ prepareBorrowTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a burn transaction group * * @param symbol - symbol to burn * @param amount - amount of bAsset to burn * @param address - address to send burn transaction group from; defaults to client user address * @returns burn transaction group */ prepareBurnTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a claim rewards transaction group * * @param address - address to send claim rewards from; defaults to client user address * @returns claim rewards transaction group */ prepareClaimRewardsTransactions(address?: string): Promise<TransactionGroup>; /** * Returns a liquidate transaction group * * @param targetStorageAddress - storage address to liquidate * @param borrowSymbol - symbol to repay * @param amount - amount to repay * @param collateralSymbol - symbol to seize collateral from * @param address - address to send liquidate transaction group from; defaults to client user address * @returns liquidate transaction group */ prepareLiquidateTransactions(targetStorageAddress: string, borrowSymbol: string, amount: number, collateralSymbol: string, address?: string): Promise<TransactionGroup>; /** * Returns a mint transaction group * * @param symbol - symbol to mint * @param amount - amount of mint * @param address - address to send mint transacdtion group from; defaults to client user address * @returns mint transaction group */ prepareMintTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a mint to collateral transaction group * * @param symbol - symbol to mint * @param amount - amount to mint to collateral * @param address - address to send mint to collateral transaction group from; defaults to client user address * @returns mint to collateral transaction group */ prepareMintToCollateralTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a remove collateral transaction group * * @param symbol - symbol to remove collateral from * @param amount - amount of collateral to remove * @param address - address to send remove collateral transaction group from; defaults to client user address * @returns remove collateral transaction group */ prepareRemoveCollateralTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a remove collateral undrlying transaction group * * @param symbol - symbol to remove collateral from * @param amount - amount of collateral to remove * @param address - address to send remove collateral underlying transaction group from; defaults to client user address * @returns remove collateral underlying transaction group */ prepareRemoveCollateralUnderlyingTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a repay borrow transaction group * * @param symbol - symbol to repay * @param amount - amount of repay * @param address - address to send repay borrow transaction group from; defaults to client user address * @returns */ prepareRepayBorrowTransactions(symbol: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a staking contract optin transaction group * * @param stakingContractName - name of staking contract to opt into * @param storageAddress - storage address to fund and rekey * @param address - address to create optin transaction group for; defaults to client user address * @returns staking contract opt in transaction group */ prepareStakingContractOptinTransactions(stakingContractName: string, storageAddress: string, address?: string): Promise<TransactionGroup>; /** * Returns a staking contract stake transaction group * * @param stakingContractName - name of staking contract to stake on * @param amount - amount of stake * @param address - address to send stake transaction group from; defaults to client user address * @returns stake transacdtion group */ prepareStakeTransactions(stakingContractName: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a staking contract unstake transactiong group * * @param stakingContractName - name of staking contract to unstake on * @param amount - amount of unstake * @param address - address to send unstake transaction group from; defaults to client user address * @returns unstake transaction group */ prepareUnstakeTransactions(stakingContractName: string, amount: number, address?: string): Promise<TransactionGroup>; /** * Returns a staking contract claim rewards transaction group * * @param stakingContractName - name of staking contract to unstake on * @param address - address to send claim rewards transaction group from; defaults to client user address * @returns unstake transaction group */ prepareClaimStakingRewardsTransactions(stakingContractName: string, address?: string): Promise<TransactionGroup>; /** * Submits and waits for a transaction group to finish if specified * * @param transactionGroup - signed transaction group * @param wait - boolean to tell whether you want to wait or not * @returns a dictionary with the txid of the group transaction */ submit(transactionGroup: Uint8Array, wait?: boolean): Promise<{}>; } /** * Creates a new generic testnet client * * @param algodClient - Algod client for interacting with the network * @param indexerClient - Indexer client for interacting with the network * @param userAddress - address of the user * @returns a new and fuilly constructed algofi testnet client */ export declare function newAlgofiTestnetClient(algodClient?: Algodv2, indexerClient?: Indexer, userAddress?: string): Promise<Client>; /** * Creates a new generic mainnet client * * @param algodClient - Algod client for interacting with the network * @param indexerClient - Indexer client for interacting with the network * @param userAddress - address of the user * @returns a new and fully constructed algofi mainnet client */ export declare function newAlgofiMainnetClient(algodClient?: Algodv2, indexerClient?: Indexer, userAddress?: string): Promise<Client>;