UNPKG

@ajna-finance/sdk

Version:

A typescript SDK that can be used to create Dapps in Ajna ecosystem.

294 lines (293 loc) 13.3 kB
import { Contract as ContractMulti, Provider as ProviderMulti } from 'ethcall'; import { BigNumber, Contract, Signer } from 'ethers'; import { Address, AuctionStatus, CallData, Loan, PoolInfoUtils, SignerOrProvider } from '../types'; import { ClaimableReserveAuction } from './ClaimableReserveAuction'; import { PoolUtils } from './PoolUtils'; import { Liquidation } from './Liquidation'; import { Bucket } from './Bucket'; export interface LoanEstimate extends Loan { /** hypothetical lowest utilized price (LUP) assuming additional debt was drawn */ lup: BigNumber; /** index of this hypothetical LUP */ lupIndex: number; } export interface DebtInfo { /** total unaccrued debt in pool at the current block height */ pendingDebt: BigNumber; /** debt accrued by pool as of the last pool interaction */ accruedDebt: BigNumber; /** debt under liquidation */ debtInAuction: BigNumber; } export interface KickerInfo { /** liquidation bond able to be withdrawn */ claimable: BigNumber; /** liquidation bond not yet able to be withdrawn */ locked: BigNumber; } export interface PriceInfo { /** price of the highest price bucket with deposit */ hpb: BigNumber; /** fenwick index of the HPB */ hpbIndex: number; /** highest threshold price */ htp: BigNumber; /** fenwick index of the HTP */ htpIndex: number; /** lowest utilized price */ lup: BigNumber; /** fenwick index of the LUP */ lupIndex: number; /** lowest bucket at which withdrawals are locked due to liquidation debt */ llb: BigNumber; /** fenwick index of the lowest liquidation locked bucket */ llbIndex: number; } export interface Stats { /** amount of liquidity in the pool (including utilized liquidity) */ poolSize: BigNumber; /** pending amount of debt in the pool */ debt: BigNumber; /** amount of debt under liquidation */ liquidationDebt: BigNumber; /** number of loans in the pool */ loansCount: number; /** minimum amount of debt a borrower can draw */ minDebtAmount: BigNumber; /** collateralization ratio expressed as percentage */ collateralization: BigNumber; /** meaningful actual utilization of the pool (MAU) */ actualUtilization: BigNumber; /** pool target utilization (TU), related to inverse of collateralization */ targetUtilization: BigNumber; /** the amount of excess quote tokens */ reserves: BigNumber; /** denominated in quote token, or `0` if no reserves can be auctioned */ claimableReserves: BigNumber; /** amount of claimable reserves which has not yet been taken */ claimableReservesRemaining: BigNumber; /** current price at which `1` quote token may be purchased, denominated in `Ajna` */ reserveAuctionPrice: BigNumber; /** interest rate paid by borrowers */ borrowRate: BigNumber; /** the timestamp of the last interest rate update. */ interestRateLastUpdated: Date; /** can be multiplied by t0debt (obtained elsewhere) to determine current debt */ pendingInflator: BigNumber; } /** * Abstract baseclass used for pools, regardless of collateral type. */ export declare abstract class Pool { provider: SignerOrProvider; contract: Contract; contractMulti: ContractMulti; poolInfoContractUtils: PoolInfoUtils; contractUtilsMulti: ContractMulti; poolAddress: Address; collateralAddress: Address; collateralSymbol?: string; quoteAddress: Address; quoteSymbol?: string; ajnaAddress: Address; name: string; utils: PoolUtils; ethcallProvider: ProviderMulti; lenderHelper: Contract; constructor(provider: SignerOrProvider, poolAddress: string, ajnaAddress: string, contract: Contract, contractMulti: ContractMulti); initialize(): Promise<void>; /** * Approve this pool to manage Ajna token. * @param signer pool user * @param allowance approval amount (or MaxUint256) * @returns promise to transaction */ ajnaApprove(signer: Signer, allowance: BigNumber): Promise<import("../types").WrappedTransaction>; /** * Approve this pool to manage quote token. * @param signer pool user * @param allowance normalized approval amount (or MaxUint256) * @returns promise to transaction */ quoteApprove(signer: Signer, allowance: BigNumber): Promise<import("../types").WrappedTransaction>; /** * Retrieves pool reference prices. * @returns {@link PriceInfo} */ getPrices(): Promise<PriceInfo>; /** * Retrieves pool statistics. * @returns {@link Stats} */ getStats(): Promise<Stats>; /** * Measuring from highest price bucket with liquidity, determines index at which all liquidity in * the book has been utilized by specified debt; useful for estimating LUP. * @param debtAmount pool debt to be applied to liquidity * @returns fenwick index */ depositIndex(debtAmount: BigNumber): Promise<any>; /** * Enables signer to bundle transactions together atomically in a single request. * @param signer consumer initiating transactions * @param callData array of transactions to sign and submit * @returns promise to transaction */ multicall(signer: Signer, callData: Array<CallData>): Promise<import("../types").WrappedTransaction>; lpAllowance(index: BigNumber, spender: Address, owner: Address): Promise<any>; increaseLPAllowance(signer: Signer, indexes: Array<number>, amounts: Array<BigNumber>): Promise<import("../types").WrappedTransaction>; /** * Checks if LP allowances are sufficient to memorialize position. * @param signer Consumer initiating transactions. * @param indices Fenwick index of the desired bucket. * @returns `true` if LP allowances are sufficient to memorialize position otherwise `false`. */ areLPAllowancesSufficient(signer: Signer, indices: Array<number>): Promise<boolean>; /** * @param minPrice lowest desired price * @param maxPrice highest desired price * @returns array of {@link Bucket}s between specified prices */ getBucketsByPriceRange(minPrice: BigNumber, maxPrice: BigNumber): Bucket[]; /** Retrieves origination fee rate for this pool; multiply by new debt to get fee. @returns origination fee rate, in WAD precision */ getOriginationFeeRate(): Promise<BigNumber>; /** * Retrieve information for a specific loan. * @param borrowerAddress identifies the loan * @returns {@link Loan} */ getLoan(borrowerAddress: Address): Promise<Loan>; /** * Retrieve information for a list of loans. * @param borrowerAddresses identifies the loans * @returns map of Loans, indexed by borrowerAddress */ getLoans(borrowerAddresses: Array<Address>): Promise<Map<Address, Loan>>; /** * @param borrowerAddress identifies the loan under liquidation * @returns {@link Liquidation} models liquidation of a specific loan */ getLiquidation(borrowerAddress: Address): Liquidation; /** * Retrieve statuses for multiple liquidations from the PoolInfoUtils contract. * @param borrowerAddresses identifies loans under liquidation * @returns map of AuctionStatuses, indexed by borrower address */ getLiquidationStatuses(borrowerAddresses: Array<Address>): Promise<Map<Address, AuctionStatus>>; /** * Calculates bond required to liquidate a borrower. * @param npTpRatio relationship between neutral price and threshold price * @param borrowerDebt loan debt * @returns required liquidation bond, in WAD precision */ calculateLiquidationBond(npTpRatio: BigNumber, borrowerDebt: BigNumber): BigNumber; /** * Calculate a loan's neutral price. * @param thresholdPrice loan debt * 1.04 / pledged collateral * @param npTpRatio relationship between neutral price and threshold price * @returns neutral price, in WAD precision */ calculateNeutralPrice(thresholdPrice: BigNumber, npTpRatio: BigNumber): BigNumber; /** * Calculate neutral price to threshold price approx. "ratio". * @param rate current pool "borrower" interest rate * @returns relationship between the neutral price and threshold price */ calculateNpTpRatio(rate: BigNumber): BigNumber; /** * Initiates a liquidation of a loan. * @param signer kicker * @param borrowerAddress identifies the loan to liquidate * @param limitIndex reverts if neutral price of loan drops below this bucket before TX processed * @returns promise to transaction */ kick(signer: Signer, borrowerAddress: Address, limitIndex?: number): Promise<import("../types").WrappedTransaction>; /** * Checks whether threshold price of a loan is currently above the LUP; * does NOT estimate whether it would be profitable to liquidate the loan. * @param borrowerAddress identifies the loan to check * @returns true if loan may be liquidated, otherwise false */ isKickable(borrowerAddress: Address): Promise<boolean>; /** * Retrieves status of an auction kicker's liquidation bond. * @param kickerAddress identifies the actor who kicked liquidations */ kickerInfo(kickerAddress: Address): Promise<KickerInfo>; /** * Called by kickers to withdraw liquidation bond from one or more auctions kicked. * @param signer kicker * @param maxAmount optional amount of bond to withdraw; defaults to all * @returns promise to transaction */ withdrawBonds(signer: Signer, maxAmount?: BigNumber): Promise<import("../types").WrappedTransaction>; /** * Estimates how drawing more debt and/or pledging more collateral would impact loan. * @param borrowerAddress identifies the loan * @param debtAmount additional amount of debt to draw (or 0) * @param collateralAmount additional amount of collateral to pledge (or 0) * @returns {@link LoanEstimate} */ estimateLoan(borrowerAddress: Address, debtAmount: BigNumber, collateralAmount: BigNumber): Promise<LoanEstimate>; /** * Estimates how repaying debt and/or pulling collateral would impact loan. * @param borrowerAddress identifies the loan * @param debtAmount amount of debt to repay (or 0) * @param collateralAmount amount of collateral to pull (or 0) * @returns {@link LoanEstimate} */ estimateRepay(borrowerAddress: Address, debtAmount: BigNumber, collateralAmount: BigNumber): Promise<LoanEstimate>; /** * Determines whether interest rate will increase, decrease, or remain the same as a result of * updating the interest rate, without regard to the 12-hour rate update interval. * @param poolStats pool statistics obtained from @link{Pool.getStats} */ estimateUpdateInterest(poolStats: Stats): BigNumber; /** * May be called periodically by actors to adjust interest rate if no other TXes have occurred * in the past 12 hours. * @param signer actor who wants to update the interest rate * @returns transaction */ updateInterest(signer: Signer): Promise<import("../types").WrappedTransaction>; /** * Updates the neutral price of a borrower's own loan, often useful after partial repayment. * @param borrower borrower who wishes to stamp their own loan */ stampLoan(signer: Signer): Promise<import("../types").WrappedTransaction>; /** * Returns `Claimable Reserve Auction` (`CRA`) wrapper object. * @returns CRA wrapper object */ getClaimableReserveAuction(): ClaimableReserveAuction; /** * Create a new empty LP token for the purpose of memorializing lender position(s). * @param signer lender * @param subset optional subset of NFT ids in pool * @returns promise to transaction */ mintLPToken(signer: Signer, subset?: Array<number>): Promise<import("../types").WrappedTransaction>; /** * Burn an empty LP token which has already been redeemed for LP in all buckets. * @param signer LP token holder * @param tokenId identifies the empty token to burn * @returns promise to transaction */ burnLPToken(signer: Signer, tokenId: BigNumber): Promise<import("../types").WrappedTransaction>; approvePositionManagerLPTransferor(signer: Signer): Promise<import("../types").WrappedTransaction>; /** * Approve lend helper to manage quote token. * @param signer pool user * @param allowance normalized approval amount (or MaxUint256) * @returns promise to transaction */ quoteApproveHelper(signer: Signer, allowance: BigNumber): Promise<import("../types").WrappedTransaction>; approveLenderHelperLPTransferor(signer: Signer): Promise<import("../types").WrappedTransaction>; isLenderHelperLPTransferorApproved(signer: Signer): Promise<boolean>; increaseLenderHelperLPAllowance(signer: Signer, indexes: Array<number>, amounts: Array<BigNumber>): Promise<import("../types").WrappedTransaction>; isLPTransferorApproved(signer: Signer): Promise<boolean>; revokePositionManagerLPTransferor(signer: Signer): Promise<import("../types").WrappedTransaction>; }