@algofi/lend
Version:
The official JavaScript SDK for the Algofi Lending Protocol
178 lines (177 loc) • 5.84 kB
TypeScript
import { Algodv2, Indexer } from "algosdk";
import { Asset } from "./asset";
export declare class Market {
algod: Algodv2;
marketAppId: number;
marketAddress: string;
marketCounter: number;
underlyingAssetId: number;
bankAssetId: number;
oracleAppId: number;
oraclePriceField: string;
oraclePriceScaleFactor: number;
collateralFactor: number;
liquidationIncentive: number;
reserveFactor: number;
baseInterestRate: number;
slope1: number;
slope2: number;
utilizationOptimal: number;
marketSupplyCapInDollars: number;
marketBorrowCapInDollars: number;
activeCollateral: number;
bankCirculation: number;
bankToUnderlyingExchange: number;
underlyingBorrowed: number;
outstandingBorrowShares: number;
underlyingCash: number;
underlyingReserves: number;
borrowUtil: number;
totalBorrowInterestRate: number;
totalSupplyInterestRate: number;
assetPrice: number;
asset: Asset;
historicalIndexer: Indexer;
/**
* This is the constructor for the Market class.
*
* **Note, do not call this to create a new market**. Instead call
* the static method init as there are asynchronous set up steps in
* creating an market and a constructor can only return an instance of
* the class and not a promise.
*
* #### Example
* ```typescript
* //Correct way to instantiate new market
* const newMarket = await Market.init(algodClient, historicalIndexerClient, marketAppId)
*
* //Incorrect way to instantiate new market
* const newMarket = new Market(algodClient, historicalIndexerClient, marketAppId)
* ```
*
* @param algodClient - algod client
* @param historicalIndexerClient - historical indexer client
* @param marketAppId - application id of the market we are interested in
*/
constructor(algodClient: Algodv2, historicalIndexerClient: Indexer, marketAppId: number);
/**
* This is the function that should be called when creating a new market.
* You pass everything you would to the constructor, but to this function
* instead and this returns the new and created market.
*
* #### Example
* ```typescript
* //Correct way to instantiate new market
* const newMarket = await Market.init(algodClient, historicalIndexerClient, marketAppId)
*
* //Incorrect way to instantiate new market
* const newMarket = new Market(algodClient, historicalIndexerClient, marketAppId)
* ```
*
* @param algodClient - algod client
* @param historicalIndexerClient - historical indexer client
* @param marketAppId - application id of the market we are interested in
* @returns a new instance of the market class fully constructed
*/
static init(algodClient: Algodv2, historicalIndexerClient: Indexer, marketAppId: number, initAsset?: boolean): Promise<Market>;
/**
* Method to fetch most recent market global state
*/
updateGlobalState(initAsset?: boolean): Promise<void>;
/**
* Returns the app id for this market
*
* @returns market app id
*/
getMarketAppId(): number;
/**
* Returns the market address for this market
*
* @returns market address
*/
getMarketAddress(): string;
/**
* Returns the market counter for this market
*
* @returns market counter
*/
getMarketCounter(): number;
/**
* Returns asset object for this market
*
* @returns asset
*/
getAsset(): Asset;
/**
* Returns active collateral for this market
*
* @returns active collateral
*/
getActiveCollateral(): number;
/**
* Returns bank circulation for this market
*
* @returns bank circulation
*/
getBankCirculation(): number;
/**
* Returns bank to underlying exchange for this market
*
* @returns bank to underlying exchange
*/
getBankToUnderlyingExchange(): number;
/**
* Returns underlying borrowed for this market
*
* @param block - specific block to get underlying borrowe for
* @returns
*/
getUnderlyingBorrowed(block?: number): Promise<number>;
/**
* Returns outstanding borrow shares for this market
*
* @returns outstanding borrow shares
*/
getOutstandingBorrowShares(): number;
/**
* Returns underlying cash for this market
*
* @param block - block to get underlying cash for
* @returns underlying cash
*/
getUnderlyingCash(block?: any): Promise<number>;
/**
* Returns underlying reserves for this market
*
* @param block - block to get underlying reserves for
* @returns underlying reserves
*/
getUnderlyingReserves(block?: any): Promise<number>;
/**
* Returns total borrow interest rate for this market
*
* @param block - block to get total borrow interest rate for
* @returns total borrow interest rate
*/
getTotalBorrowInterestRate(block?: any): Promise<number>;
/**
* Returns collateral factor for this market
* @returns collateral factor
*/
getCollateralFactor(): number;
/**
* Returns liquidation incentive for this market
*
* @returns liquidation incentive
*/
getLiquidationIncentive(): number;
/**
* Returns the market local state for address
*
* @param storageAddress - storage addres to get info for
* @returns market local state for address
*/
getStorageState(storageAddress: string): Promise<{
[key: string]: any;
}>;
}