UNPKG

liquidops

Version:

LiquidOps is an over-collateralised lending and borrowing protocol built on Arweave's L2 AO.

429 lines (396 loc) 12.1 kB
import { Quantity } from 'ao-tokens'; import { SpawnProcess } from '@permaweb/aoconnect/dist/lib/spawn'; import { SendMessage } from '@permaweb/aoconnect/dist/lib/message'; import { ReadResult } from '@permaweb/aoconnect/dist/lib/result'; import { Types } from '@permaweb/aoconnect/dist/dal'; interface AoUtils { spawn: SpawnProcess; message: SendMessage; result: ReadResult; signer: Types["signer"]; configs: Services; } type Services = { /** * - the mode to connect to ao ("legacy" or "mainnet") */ MODE?: "legacy" | "mainnet"; /** * - the url of the desried Gateway. */ GATEWAY_URL?: string; /** * - the url of the desired Arweave Gateway GraphQL Server */ GRAPHQL_URL?: string; /** * - the number of times to retry querying the gateway, utilizing an exponential backoff */ GRAPHQL_MAX_RETRIES?: number; /** * - the initial backoff, in milliseconds (moot if GRAPHQL_MAX_RETRIES is set to 0) */ GRAPHQL_RETRY_BACKOFF?: number; /** * - the url of the desried ao Messenger Unit. */ MU_URL?: string; /** * - the url of the desried ao Compute Unit. */ CU_URL?: string; }; interface TokenData { name: string; icon: string; ticker: string; address: string; oTicker: string; oAddress: string; controllerAddress: string; cleanTicker: string; denomination: bigint; collateralEnabled: boolean; baseDenomination: bigint; deprecated: boolean; oIcon: string; } declare const controllerAddress = "SmmMv0rJwfIDVM3RvY2-P729JFYwhdGSeGo2deynbfY"; declare const tokenData: Record<string, TokenData>; type SupportedTokensTickers = keyof typeof tokenData; type SupportedTokensAddresses = TokenData["address"]; type SupportedOTokensTickers = TokenData["oTicker"]; type SupportedOTokensAddresses = TokenData["oAddress"]; type SupportedControllerAddresses = TokenData["controllerAddress"]; declare const tokens: Record<SupportedTokensTickers, SupportedTokensAddresses>; declare const oTokens: Record<SupportedOTokensTickers, SupportedOTokensAddresses>; type TokenInput = SupportedTokensTickers | SupportedTokensAddresses; interface TokenInfo { tokenAddress: SupportedTokensAddresses; oTokenAddress: SupportedOTokensAddresses; controllerAddress: SupportedControllerAddresses; ticker: SupportedTokensTickers; } declare function tokenInput(token: TokenInput): TokenInfo; interface TransactionResult { status: boolean | "pending"; transferID: string; debitID?: string; creditID?: string; response?: string; } interface GetResult { transferID: string; tokenAddress: string; action: "lend" | "unLend" | "borrow" | "repay"; } type GetResultRes = boolean | "pending"; type WithResultOption<T> = ({ noResult?: true; } | { noResult?: false; }) & T; type Borrow = WithResultOption<{ token: TokenInput; quantity: BigInt; }>; interface BorrowRes extends TransactionResult { } type Repay = WithResultOption<{ token: TokenInput; quantity: BigInt; onBehalfOf?: string; }>; interface RepayRes extends TransactionResult { } interface GetTransactions { token: TokenInput; action: "lend" | "unLend" | "borrow" | "repay"; walletAddress: string; cursor?: string; } interface GetTransactionsRes { transactions: Transaction[]; pageInfo: { hasNextPage: boolean; cursor?: string; }; } interface Transaction { id: string; tags: Record<string, string>; block: { timestamp: number; }; } type Lend = WithResultOption<{ token: TokenInput; quantity: BigInt; }>; interface LendRes extends TransactionResult { } type UnLend = WithResultOption<{ token: TokenInput; quantity: BigInt; }>; interface UnLendRes extends TransactionResult { } interface GetLiquidationsRes { liquidations: Map<string, QualifyingPosition>; usdDenomination: BigInt; prices: RedstonePrices$1; } interface QualifyingPosition { debts: { ticker: string; quantity: BigInt; }[]; collaterals: { ticker: string; quantity: BigInt; }[]; /** The current discount percentage for this liquidation (multiplied by the precision factor) */ discount: BigInt; } type RedstonePrices$1 = Record<string, { t: number; a: string; v: number; }>; type GetDiscountedQuantityRes = BigInt; interface GetDiscountedQuantity { /** The token that will be sent pay for the dept of the target */ liquidated: { token: string; quantity: BigInt; }; /** The token received for the liquidation */ rewardToken: string; /** The position that qualified for the liquidation */ qualifyingPosition: QualifyingPosition; /** Redstone price data from getLiquidations() */ priceData: RedstonePrices$1; /** * Optionally validate the liqidated token quantity and the discounted quantity. * This will throw an error if any of these quantities are more than what the user * holds */ validateMax?: boolean; } type Liquidate = WithResultOption<{ token: TokenInput; rewardToken: TokenInput; targetUserAddress: string; quantity: BigInt; minExpectedQuantity: BigInt; }>; interface LiquidateRes extends TransactionResult { } interface GetBalances { token: TokenInput; } type GetBalancesRes = Record<string, bigint>; interface GetBorrowAPR { token: TokenInput; } type GetBorrowAPRRes = number; interface GetExchangeRate { token: TokenInput; quantity: BigInt; } type GetExchangeRateRes = BigInt; interface TokenPosition { borrowBalance: bigint; capacity: bigint; collateralization: bigint; liquidationLimit: bigint; ticker: string; } interface GlobalPosition { borrowBalanceUSD: bigint; capacityUSD: bigint; collateralizationUSD: bigint; liquidationLimitUSD: bigint; usdDenomination: bigint; tokenPositions: { [token: string]: TokenPosition; }; } type RedstonePrices = Record<string, { t: number; a: string; v: number; }>; interface GetGlobalPositionRes { globalPosition: GlobalPosition; prices: RedstonePrices; } interface GetGlobalPosition { walletAddress: string; } interface GetInfo { token: TokenInput; } interface GetInfoRes { collateralDenomination: string; liquidationThreshold: string; totalSupply: string; totalBorrows: string; valueLimit: string; name: string; collateralFactor: string; totalReserves: string; cash: string; oracle: string; logo: string; reserveFactor: string; denomination: string; collateralId: string; ticker: string; kinkParam: string; jumpRate: string; baseRate: string; utilization: string; initRate: string; oracleDelayTolerance: string; } interface GetPosition { token: TokenInput; recipient: string; } interface GetPositionRes { capacity: string; borrowBalance: string; collateralTicker: string; collateralDenomination: string; collateralization: string; liquidationLimit: string; } interface GetSupplyAPR { token: TokenInput; getInfoRes?: GetInfoRes; getBorrowAPRRes?: GetBorrowAPRRes; } type GetSupplyAPRRes = number; interface GetCooldown { recipient: string; token: string; } type GetCooldownRes = { onCooldown: false; } | { onCooldown: true; expiryBlock: number; remainingBlocks: number; }; interface GetAllPositions { token: TokenInput; } interface GetAllPositionsRes { [walletAddress: string]: { borrowBalance: BigInt; capacity: BigInt; collateralization: BigInt; liquidationLimit: BigInt; }; } interface GetHistoricalAPR { token: TokenInput; fillGaps?: boolean; } type GetHistoricalAPRRes = APR[]; interface APR { apr: number; timestamp: number; } interface GetBalance { tokenAddress: string; walletAddress: string; } type GetBalanceRes = Quantity; interface Transfer { token: TokenInput | string; recipient: string; quantity: BigInt; } interface TransferRes { id: string; status: boolean; } interface Tag { name: string; values: string | string[]; } interface TrackResult { process: string; message: string; targetProcess?: string; messageTimestamp?: number; validUntil?: number; validateOriginal?: boolean; match: { success?: ResultMatcher; fail?: ResultMatcher; }; } interface TrackResultRes { match: "success" | "fail"; message: PlainMessage; } interface SimpleTag { name: string; value: string; } interface PlainMessage { Anchor: string; Tags: SimpleTag[]; Target: string; Data: string; } interface ResultMatcher extends Omit<Partial<PlainMessage>, "Tags"> { Tags?: Tag[]; } interface GetEarnings { walletAddress: string; token: string; collateralization?: bigint; } interface GetEarningsRes { base: bigint; profit: bigint; startDate?: number; } type Configs = Services; type Signer = Types["signer"]; declare class LiquidOps { private signer; private configs; constructor(signer: Signer, configs?: Omit<Configs, "MODE">); borrow<T extends Borrow>(params: T): Promise<T["noResult"] extends true ? string : BorrowRes>; repay<T extends Repay>(params: T): Promise<T["noResult"] extends true ? string : RepayRes>; getTransactions(params: GetTransactions): Promise<GetTransactionsRes>; lend<T extends Lend>(params: T): Promise<T["noResult"] extends true ? string : LendRes>; unLend<T extends UnLend>(params: T): Promise<T["noResult"] extends true ? string : UnLendRes>; getEarnings(params: GetEarnings): Promise<GetEarningsRes>; getDiscountedQuantity(params: GetDiscountedQuantity): GetDiscountedQuantityRes; static liquidationPrecisionFactor: number; getLiquidations(): Promise<GetLiquidationsRes>; liquidate(params: Liquidate): Promise<LiquidateRes>; getBalances(params: GetBalances): Promise<GetBalancesRes>; getBorrowAPR(params: GetBorrowAPR): Promise<GetBorrowAPRRes>; getCooldown(params: GetCooldown): Promise<GetCooldownRes>; getExchangeRate(params: GetExchangeRate): Promise<GetExchangeRateRes>; getGlobalPosition(params: GetGlobalPosition): Promise<GetGlobalPositionRes>; getInfo(params: GetInfo): Promise<GetInfoRes>; getPosition(params: GetPosition): Promise<GetPositionRes>; getSupplyAPR(params: GetSupplyAPR): Promise<GetSupplyAPRRes>; getAllPositions(params: GetAllPositions): Promise<GetAllPositionsRes>; getHistoricalAPR(params: GetHistoricalAPR): Promise<GetHistoricalAPRRes>; getBalance(params: GetBalance): Promise<GetBalanceRes>; getResult(params: GetResult): Promise<GetResultRes>; transfer(params: Transfer): Promise<TransferRes>; trackResult(params: TrackResult): Promise<TrackResultRes | undefined>; static oTokens: Record<string, string>; static tokens: Record<string, string>; } export { type AoUtils, type Borrow, type BorrowRes, type Configs, type GetAllPositions, type GetAllPositionsRes, type GetBalance, type GetBalanceRes, type GetBalances, type GetBalancesRes, type GetBorrowAPR, type GetBorrowAPRRes, type GetDiscountedQuantity, type GetDiscountedQuantityRes, type GetExchangeRate, type GetExchangeRateRes, type GetGlobalPosition, type GetGlobalPositionRes, type GetHistoricalAPR, type GetHistoricalAPRRes, type GetInfo, type GetInfoRes, type GetLiquidationsRes, type GetPosition, type GetPositionRes, type GetResult, type GetResultRes, type GetSupplyAPR, type GetSupplyAPRRes, type GetTransactions, type GetTransactionsRes, type Lend, type LendRes, type Liquidate, type LiquidateRes, type QualifyingPosition, type RedstonePrices$1 as RedstonePrices, type Repay, type RepayRes, type Signer, type TokenData, type TokenInput, type TrackResult, type TrackResultRes, type Transfer, type TransferRes, type UnLend, type UnLendRes, controllerAddress, LiquidOps as default, oTokens, tokenData, tokenInput, tokens };