@algofi/js-sdk
Version:
The official Algofi JavaScript SDK
233 lines (232 loc) • 10.1 kB
TypeScript
import { Algodv2, Transaction, SuggestedParams } from "algosdk";
import AlgofiUser from "../../algofiUser";
import AssetAmount from "../../assetData/assetAmount";
import AssetDataClient from "../../assetData/assetDataClient";
import { MarketType } from "./lendingConfig";
import LendingClient from "./lendingClient";
import MarketConfig from "./marketConfig";
import Oracle from "./oracle";
export declare class MarketRewardsProgram {
market: Market;
programNumber: number;
rewardsPerSecond: number;
assetID: number;
issued: number;
claimed: number;
index: bigint;
projectedIndex: bigint;
/**
* Constructs a market rewards program class
*
* @param state - state of the market rewards program on chain
* @param programIndex - the index of the rewards program
*/
constructor(market: Market, state: {}, programIndex: number);
getAnnualRewards(): AssetAmount;
getSupplyRewardsAPR(): number;
getBorrowRewardsAPR(): number;
getSupplyRewardsPer1k(): number;
getBorrowRewardsPer1k(): number;
}
export default class Market {
localMinBalance: number;
algod: Algodv2;
lendingClient: LendingClient;
assetDataClient: AssetDataClient;
managerAppId: number;
appId: number;
address: string;
marketType: MarketType;
underlyingAssetId: number;
bAssetId: number;
optInEnabled: boolean;
supplyLimited: boolean;
borrowLimitted: boolean;
borrowFactor: number;
collateralFactor: number;
flashLoanFee: number;
flashLoanProtocolFee: number;
maxFlashLoanRatio: number;
liquidationIncentive: number;
liquidationFee: number;
reserveFactor: number;
underlyingSupplyCap: number;
underlyingBorrowCap: number;
baseInterestRate: number;
baseInterestSlope: number;
quadraticInterestAmplificationFactor: number;
targetUtilizationRatio: number;
oracle: Oracle;
underlyingCash: number;
underlyingBorrowed: number;
underlyingReserves: number;
borrowShareCirculation: number;
bAssetCirculation: number;
activeBAssetCollateral: number;
underlyingProtocolReserve: number;
latestTime: number;
borrowIndex: number;
impliedBorrowIndex: number;
rewardsLatestTime: number;
rewardsPrograms: any[];
rewardsEscrowAccount: string;
/**
* Constructor for the market class.
*
* @param algod - algod client
* @param lendingClient - lending client
* @param managerAppId - manager app idd
* @param marketConfig - market config
*/
constructor(algod: Algodv2, lendingClient: LendingClient, managerAppId: number, marketConfig: MarketConfig);
/**
* Function to get the application's global state and load in all of the
* updated values into the actual object.
*/
loadState(): Promise<void>;
getBorrowAPR(totalSupplied?: number, totalBorrowed?: number): number;
getSupplyAPR(totalSupplied?: number, totalBorrowed?: number): Promise<number>;
/**
* Gets the underlying supplied for a market.
*
* @param isProjected - bool if the underlying supply is projected based on deltaT
* @returns the underlying supplied for a market.
*/
getUnderlyingSupplied(isProjected?: boolean): number;
getTotalSupplied(): AssetAmount;
getTotalBorrowed(): AssetAmount;
getSupplyRewardsAPR(): number;
getBorrowRewardsAPR(): number;
private convertUnderlyingToUSD;
/**
* Converts the b asset to the underlying asset amount
*
* @param amount - the amount of the b asset we want to convert
* @returns the asset amount that corresponds to the b asset amount that we passed in.
*/
bAssetToUnderlying(amount: number): AssetAmount;
/**
* Converts the borrow shares to the acutal underlying asset amount those
* borrow shares represent.
*
* @param amount - amount of borrow shares we want to convert
* @returns the amount of the underlying that is represented by the amount of
* borrow shares that we passed in.
*/
borrowSharesToUnderlying(amount: number, roundResultUp?: boolean): AssetAmount;
/**
* Converts the underlying asset to b assets.
*
* @param amount - the amount of underlying we want to convert
* @param isProjected - bool if user wishes to project the b asset to underlying exchange
* @returns the corresponding amount of the b asset for the underlying that we
* passed in.
*/
underlyingToBAsset(underlyingAmount: AssetAmount, isProjected?: boolean): AssetAmount;
getMaximumWithdrawAmount(user: AlgofiUser, borrowUtilLimit?: number): AssetAmount;
getMaximumWithdrawBAsset(user: AlgofiUser, borrowUtilLimit?: number): AssetAmount;
getMaximumBorrowAmount(user: AlgofiUser, borrowUtilLimit?: number): AssetAmount;
getNewBorrowUtilQuote(user: AlgofiUser, collateralDelta: AssetAmount, borrowDelta: AssetAmount): number;
/**
* Constructs a series of transactions that are required for several other
* transactions in lending.
*
* @param params - parameters for the transaction
* @param user - the user to send the preamble transactions on behalf
* @returns a series of transactions that are required for several other
* transactions in lending.
*/
getPreambleTransactions(params: SuggestedParams, user: AlgofiUser, needsUserPosition: boolean): Promise<[Transaction[], number]>;
/**
* Constructs a series of transactions that mint b assets for the user.
*
* @param user - the user minting b assets
* @param underlyingAmount - how much of the underlying the user wants to mint
* @returns a series of transactions that mint b assets for the user.
*/
getMintTxns(user: AlgofiUser, underlyingAmount: AssetAmount): Promise<Transaction[]>;
/**
* Constructs a series of transactions that adds underlying collateral for the
* user.
*
* @param user - algofi user who wants to add underlying
* @param underlyingAmount - the amount of the underlying we want to add
* @returns a series of transactions that adds underlying collateral for the
* user.
*/
getAddUnderlyingCollateralTxns(user: AlgofiUser, underlyingAmount: AssetAmount): Promise<Transaction[]>;
/**
* Constructs a series of transactions that adds b asset collateral for a
* user.
*
* @param user - the user who is adding b assets
* @param bAssetAmount - the amount of b assets to add
* @returns a series of transactions that adds b asset collateral for a user.
*/
getAddBAssetCollateralTxns(user: AlgofiUser, bAssetAmount: AssetAmount): Promise<Transaction[]>;
/**
* Constructs a series of transactions that remove underlying collateral for a user.
*
* @param user - algofi user representing hte user that wants to remove underlying collateral
* @param underlyingAmount - algofi user representing the user we want to opt in
* @param removeMax - whether or not we want to remove the maximum amount
* @returns a series of transactions that remove underlying collateral for a user.
*/
getRemoveUnderlyingCollateralTxns(user: AlgofiUser, underlyingAmount: AssetAmount, removeMax?: boolean): Promise<Transaction[]>;
/**
* Constructs a series of transactions that remove underlying b asset
* collateral for a user.
*
* @param user - algofi user representing the user we want to remove b asset
* collateral for
* @param bAssetAmount - the amount of b asset collateral we want to move
* @returns a series of transactions that remove underlying b asset
* collateral for a user.
*/
getRemoveBAssetCollateralTxns(user: AlgofiUser, bAssetAmount: AssetAmount): Promise<Transaction[]>;
/**
* Constructs a series of transactions that represent a burning of b assets.
*
* @param user - algofi user representing the user we want to burn the b assets for
* @param bAssetAmount - the amount of b asset we want to burn
* @returns a series of transactions that represent a burning of b assets.
*/
getBurnTxns(user: AlgofiUser, bAssetAmount: AssetAmount): Promise<Transaction[]>;
/**
* Constructs a series of transactions that allow a user to borrow some amount
* of underlying from the market.
*
* @param user - algofi user representing the user we want to borrow for
* @param underlyingAmount - the amount of underlying to borrow
* @returns a series of transactions that allow a user to borrow some amount
* of underlying from the market.
*/
getBorrowTxns(user: AlgofiUser, underlyingAmount: AssetAmount): Promise<Transaction[]>;
/**
* Constructs a series of transactions that allow a user to repay some of
* their borrow.
*
* @param user - algofi user representing the user we want to borrow for
* @param underlyingAmount - the amount of underlying to repay
* @returns a series of transactions that allow a user to repay some of their
* borrow.
*/
getRepayBorrowTxns(user: AlgofiUser, underlyingAmount: AssetAmount, repayMax?: boolean): Promise<Transaction[]>;
/**
* Constructs a series of transactions that allow a user to claim their
* rewards from the market.
*
* @param user - algofi user representing the user we want to claim rewards
* for
* @returns a series of transactions that allow a user to claim their
* rewards from the market.
*/
getClaimRewardsTxns(user: AlgofiUser): Promise<Transaction[]>;
/**
* Constructs a series of transactions to sync the vault.
*
* @param user - algofi user representing the user we want to sync the vault for
* @returns a series of transactions to sync the vault.
*/
getSyncVaultTxns(user: AlgofiUser): Promise<Transaction[]>;
}