@algofi/lend
Version:
The official JavaScript SDK for the Algofi Lending Protocol
129 lines (128 loc) • 4.54 kB
TypeScript
import { Algodv2 } from "algosdk";
export declare class Asset {
algod: Algodv2;
underlyingAssetId: number;
bankAssetId: number;
oracleAppId: number;
oraclePriceField: string;
oraclePriceScaleFactor: number;
underlyingAssetInfo: {
[key: string]: any;
};
bankAssetInfo: {};
/**
* This is the constructor for the Asset class.
*
* **Note, do not call this to create a new asset**. Instead call
* the static method init as there are asynchronous set up steps in
* creating an asset and a constructor can only return an instance of
* the class and not a promise.
*
* #### Example
* ```typescript
* //Correct way to instantiate new asset
* const newAsset = await Asset.init(algodClient, underlyingAssetId, bankAssetId, oracleAppId, oraclePriceField, oraclePriceScaleFactor)
*
* //Incorrect way to instantiate new asset
* const newAsset = new Asset(algodClient, underlyingAssetId, bankAssetId, oracleAppId, oraclePriceField, oraclePriceScaleFactor)
* ```
*
* @param algodClient - algod client
* @param underlyingAssetId - id of underlying asset
* @param bankAssetId - bank asset id
* @param oracleAppId - oracle application id of underlying asset
* @param oraclePriceField - oracle price field of underlying asset
* @param oraclePriceScaleFactor - oracle price scale factor of underlying asset
*/
constructor(algodClient: Algodv2, underlyingAssetId: number, bankAssetId: number, oracleAppId?: number, oraclePriceField?: string, oraclePriceScaleFactor?: number);
/**
* This is the function that should be called when creating a new asset.
* You pass everything you would to the constructor, but to this function
* instead and this returns the new and created asset.
*
* #### Example
* ```typescript
* //Correct way to instantiate new asset
* const newAsset = await Asset.init(algodClient, underlyingAssetId, bankAssetId, oracleAppId, oraclePriceField, oraclePriceScaleFactor)
*
* //Incorrect way to instantiate new asset
* const newAsset = new Asset(algodClient, underlyingAssetId, bankAssetId, oracleAppId, oraclePriceField, oraclePriceScaleFactor)
* ```
*
* @param algodClient - algod client
* @param underlyingAssetId - id of underlying asset
* @param bankAssetId - bank asset id
* @param oracleAppId - oracle application id of underlying asset
* @param oraclePriceField - oracle price field of underlying asset
* @param oraclePriceScaleFactor - oracle price scale factor of underlying asset
* @returns a finished instance of the asset class.
*/
static init(algodClient: Algodv2, underlyingAssetId: number, bankAssetId: number, oracleAppId?: number, oraclePriceField?: string, oraclePriceScaleFactor?: number): Promise<Asset>;
/**
* Returns underlying asset id
*
* @returns underlying asset id
*/
getUnderlyingAssetId(): number;
/**
* Returns underlying asset info
*
* @returns underlying asset info as a dictionary
*/
getUnderlyingAssetInfo(): {};
/**
* Returns bank asset id
*
* @returns bank asset id
*/
getBankAssetId(): number;
/**
* Returns bank asset info
*
* @returns bank asset info as a dictionary
*/
getBankAssetInfo(): {};
/**
* Returns oracle app id
*
* @returns oracle app id
*/
getOracleAppId(): number;
/**
* Returns oracle price field
*
* @returns oracle price field
*/
getOraclePriceField(): string;
/**
* Returns oracle price scale factor
*
* @returns oracle price scale factor
*/
getOraclePriceScaleFactor(): number;
/**
* Returns the current raw oracle price
*
* @returns oracle price
*/
getRawPrice(): Promise<number>;
/**
* Returns decimals of asset
*
* @returns decimals
*/
getUnderlyingDecimals(): number;
/**
* Returns the current oracle price
*
* @returns oracle price
*/
getPrice(): Promise<number>;
/**
* Returns the usd value of the underlying amount (base units)
*
* @param amount - integer amount of base underlying units
* @returns usd value
*/
toUSD(amount: number): Promise<number>;
}