liquidops
Version:
LiquidOps is an over-collateralised lending and borrowing protocol built on Arweave's L2 AO.
469 lines (434 loc) • 14.6 kB
TypeScript
import { Quantity } from 'ao-tokens';
import * as _permaweb_aoconnect_dist_lib_process_id from '@permaweb/aoconnect/dist/lib/process-id';
import * as _permaweb_aoconnect_dist_lib_messages from '@permaweb/aoconnect/dist/lib/messages';
import * as _permaweb_aoconnect_dist_dal from '@permaweb/aoconnect/dist/dal';
import * as _permaweb_aoconnect_dist_lib_assign from '@permaweb/aoconnect/dist/lib/assign';
import * as _permaweb_aoconnect_dist_lib_dryrun from '@permaweb/aoconnect/dist/lib/dryrun';
import * as _permaweb_aoconnect_dist_lib_unmonitor from '@permaweb/aoconnect/dist/lib/unmonitor';
import * as _permaweb_aoconnect_dist_lib_monitor from '@permaweb/aoconnect/dist/lib/monitor';
import * as _permaweb_aoconnect_dist_lib_spawn from '@permaweb/aoconnect/dist/lib/spawn';
import * as _permaweb_aoconnect_dist_lib_message from '@permaweb/aoconnect/dist/lib/message';
import * as _permaweb_aoconnect_dist_lib_results from '@permaweb/aoconnect/dist/lib/results';
import * as _permaweb_aoconnect_dist_lib_result from '@permaweb/aoconnect/dist/lib/result';
declare const legacyConnect: () => {
MODE: any;
result: _permaweb_aoconnect_dist_lib_result.ReadResult;
results: _permaweb_aoconnect_dist_lib_results.ReadResults;
message: _permaweb_aoconnect_dist_lib_message.SendMessage;
spawn: _permaweb_aoconnect_dist_lib_spawn.SpawnProcess;
monitor: _permaweb_aoconnect_dist_lib_monitor.SendMonitor;
unmonitor: _permaweb_aoconnect_dist_lib_unmonitor.SendMonitor;
dryrun: _permaweb_aoconnect_dist_lib_dryrun.DryRun;
assign: _permaweb_aoconnect_dist_lib_assign.Assign;
createDataItemSigner: (wallet: any) => _permaweb_aoconnect_dist_dal.Types["signer"];
signMessage: ({ process, data, tags, anchor, signer }: {
process: any;
data: any;
tags: any;
anchor: any;
signer: any;
}) => any;
sendSignedMessage: ({ id, raw }: {
id: any;
raw: any;
}) => any;
getMessages: _permaweb_aoconnect_dist_lib_messages.Messages;
getLastSlot: _permaweb_aoconnect_dist_lib_process_id.ProcessId;
getMessageById: ProcessId;
};
type LegacyConnectResult = ReturnType<typeof legacyConnect>;
type SpawnProcess = LegacyConnectResult["spawn"];
type SendMessage = LegacyConnectResult["message"];
type ReadResult = LegacyConnectResult["result"];
type Services = {
GATEWAY_URL?: string;
GRAPHQL_URL?: string;
GRAPHQL_MAX_RETRIES?: number;
GRAPHQL_RETRY_BACKOFF?: number;
MU_URL?: string;
CU_URL?: string;
};
interface AoUtils {
spawn: SpawnProcess;
message: SendMessage;
result: ReadResult;
signer: any;
configs: Services;
}
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;
borrowingDisabled: boolean;
borrowingDisabledReason: '' | 'Deprecated token.' | 'AO airdrop.';
}
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;
}
interface GetLiquidationsMapRes {
/** The wallet/user address that owns this position */
walletAddress: string;
/** Current amount borrowed by this wallet in USD (formatted) */
borrowBalance: number;
/** Current collateral value for this wallet in USD (formatted) */
collateralizationUSD: number;
/** Maximum amount this wallet can borrow before liquidation in USD (formatted) */
liquidationLimit: number;
/** How close to liquidation (0-100%): 0 = no debt, 100+ = liquidatable */
proximityPercentage: number;
/** Risk level: Safe (<70%), Warning (70-89%), Danger (90-99%), Liquidatable (100%+) */
status: "Safe" | "Warning" | "Danger" | "Liquidatable";
/** Additional amount this wallet can still borrow before hitting liquidation in USD (formatted) */
remainingCapacity: number;
}
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 GetPrice {
token: TokenInput | string;
}
type GetPriceRes = number;
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;
declare class LiquidOps {
private signer;
private configs;
constructor(signer: any, 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>;
static liquidationPrecisionFactor: number;
getDiscountedQuantity(params: GetDiscountedQuantity): GetDiscountedQuantityRes;
getLiquidationsMap(): Promise<GetLiquidationsMapRes[]>;
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>;
getPrice(params: GetPrice): Promise<GetPriceRes>;
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 TokenData, type TokenInput, type TrackResult, type TrackResultRes, type Transfer, type TransferRes, type UnLend, type UnLendRes, controllerAddress, LiquidOps as default, oTokens, tokenData, tokenInput, tokens };