UNPKG

@quartz-labs/sdk

Version:

SDK for interacting with the Quartz Protocol

249 lines 14.4 kB
import type { DriftClient, UserAccount } from "@drift-labs/sdk"; import type { AddressLookupTableAccount, TransactionInstruction } from "@solana/web3.js"; import type { Pyra } from "./types/idl/pyra.js"; import type { Program } from "@coral-xyz/anchor"; import type { PublicKey } from "@solana/web3.js"; import BN from "bn.js"; import { MarketIndex } from "./config/tokens.js"; import { Keypair } from "@solana/web3.js"; import type { QuartzClient } from "./QuartzClient.class.js"; import type { WithdrawOrder } from "./index.browser.js"; import type { Connection } from "@solana/web3.js"; import type { Signer } from "@solana/web3.js"; export declare class QuartzUser { readonly pubkey: PublicKey; readonly vaultPubkey: PublicKey; readonly depositAddress: PublicKey; readonly spendLimitPerTransaction: BN; readonly spendLimitPerTimeframe: BN; readonly remainingSpendLimitPerTimeframe: BN; readonly nextTimeframeResetTimestamp: BN; readonly timeframeInSeconds: BN; private connection; private program; private quartzLookupTable; private client; private driftUser; private driftSigner; constructor(pubkey: PublicKey, connection: Connection, client: QuartzClient, program: Program<Pyra>, quartzLookupTable: AddressLookupTableAccount, driftClient: DriftClient, driftUserAccount: UserAccount, spendLimitPerTransaction: BN, spendLimitPerTimeframe: BN, remainingSpendLimitPerTimeframe: BN, nextTimeframeResetTimeframe: BN, timeframeInSeconds: BN); getHealth(): number; getRepayUsdcValueForTargetHealth(targetHealth: number, repayAssetWeight: number, repayLiabilityWeight: number): Promise<number>; getTotalCollateralValue(openWithdrawOrders?: WithdrawOrder[]): Promise<number>; getTotalSpotLiabilityValue(openWithdrawOrders?: WithdrawOrder[]): Promise<number>; getTotalWeightedCollateralValue(openWithdrawOrders?: WithdrawOrder[]): Promise<number>; getMarginRequirement(openWithdrawOrders?: WithdrawOrder[]): Promise<number>; getAvailableCreditUsdcBaseUnits(openWithdrawOrders?: WithdrawOrder[]): Promise<BN>; private validateOpenWithdrawOrders; getDepositAddressBalance(marketIndex: MarketIndex): Promise<BN>; getAllDepositAddressBalances(): Promise<Record<MarketIndex, BN>>; getTokenBalance(marketIndex: MarketIndex, openWithdrawOrders?: WithdrawOrder[]): Promise<BN>; getMultipleTokenBalances(marketIndices: MarketIndex[], openWithdrawOrders?: WithdrawOrder[]): Promise<Record<MarketIndex, BN>>; getWithdrawalLimit(marketIndex: MarketIndex, reduceOnly?: boolean, openWithdrawOrders?: WithdrawOrder[]): Promise<BN>; getMultipleWithdrawalLimits(marketIndices: MarketIndex[], reduceOnly?: boolean, openWithdrawOrders?: WithdrawOrder[]): Promise<Record<MarketIndex, BN>>; getLookupTables(): AddressLookupTableAccount[]; /** * Creates instructions to send tokens from the legacy deposit address to the owner. * @param mint - The mint of the token to withdraw. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to clear the legacy deposit address. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails, if the mint's ATA does not exist, or has 0 balance. */ makeClearLegacyDepositAddressIxs(mint: PublicKey): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to iniate and order to adjust the spend limits of a Quartz user account. * @param spendLimitPerTransaction - The new spend limit per transaction. * @param spendLimitPerTimeframe - The new spend limit per timeframe. * @param timeframeInSeconds - The new timeframe in seconds. * @param nextTimeframeResetTimestamp - The new next timeframe reset timestamp. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to adjust the spend limits. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails. Or if the spend limits are invalid. */ makeInitiateUpdateSpendLimitsIxs(payer: PublicKey, spendLimitPerTransaction: BN, spendLimitPerTimeframe: BN, nextTimeframeResetTimestamp: BN, timeframeInSeconds: BN): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to update the card spend limits of a Quartz user account. Time lock can be skipped if admin is a signer. * @param orderAccount - The public key of the spend limits order, which must be created with the initiateSpendLimits instruction. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to fulfil the spend limits order. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails. */ makeFulfilUpdateSpendLimitsIxs(orderAccount: PublicKey, admin?: PublicKey): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; makeUpdateSpendLimitsWithAdminIxs(payer: PublicKey, admin: PublicKey, spendLimitPerTransaction: BN, spendLimitPerTimeframe: BN, nextTimeframeResetTimestamp: BN, timeframeInSeconds: BN): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to update the card spend limits order of a Quartz user account. * @param orderAccount - The public key of the spend limits order, which must be created with the initiateSpendLimits instruction. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to cancel the spend limits order. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails. */ makeCancelUpdateSpendLimitsIxs(orderAccount: PublicKey): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to deposit tokens from the legacy deposit address into Drift. * @param marketIndex - The market index of the token to deposit. * @param payer - The public key of the payer. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to initiate a withdraw order. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails, if the mint's ATA does not exist, or has 0 balance. */ makeDepositIxs(marketIndex: MarketIndex, payer: PublicKey): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to iniaite a withdraw order from the Quartz user account, which will be fulfilled after the time lock. * @param amountBaseUnits - The amount of tokens to withdraw. * @param marketIndex - The market index of the token to withdraw. * @param reduceOnly - True means amount will be capped so a positive balance (collateral) cannot become a negative balance (loan). * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to initiate a withdraw order. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails. */ makeInitiateWithdrawIxs(amountBaseUnits: number, marketIndex: MarketIndex, reduceOnly: boolean, payer: PublicKey, destinationAddress?: PublicKey): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to fulfil a withdraw order from the Quartz user account. Can be skipped if admin is a signer. * @param orderAccount - The public key of the withdraw order, which must be created with the initiateWithdraw instruction. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to withdraw the token from the Quartz user account. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails. The transaction will fail if the account does not have enough tokens or, (when taking out a loan) the account health is not high enough for a loan. */ makeFulfilWithdrawIxs(orderAccount: PublicKey, payer: PublicKey, admin?: PublicKey, amountBaseUnits?: BN): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; makeFeePaymentIxs(admin: PublicKey, amountBaseUnits: number, marketIndex: MarketIndex, reduceOnly: boolean): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Signer[]; }>; /** * Creates instructions to withdraw a token from the Quartz user account. * @param orderAccount - The public key of the withdraw order, which must be created with the initiateWithdraw instruction. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to withdraw the token from the Quartz user account. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails. The transaction will fail if the account does not have enough tokens or, (when taking out a loan) the account health is not high enough for a loan. */ makeCancelWithdrawIxs(orderAccount: PublicKey): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to spend using the Quartz card. * @param amountSpendBaseUnits - The amount of tokens to spend. * @param amountFeeBaseUnits - The amount of tokens to send to the spend fee address. * @param marketIndex - The market index of the token to spend. * @param admin - The public key of the admin. * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to repay the loan using collateral. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. * @throw Error if the RPC connection fails. The transaction will fail if: * - the user does not have enough available tokens. * - the user's spend limit is exceeded. */ makeSpendIxs(amountSpendBaseUnits: number, amountFeeBaseUnits: number, marketIndex: MarketIndex, admin: PublicKey): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; /** * Creates instructions to swap two assets, both for swapping collateral and for selling collateral to repay a loan. * @param caller - The public key of the caller. This is the account that acually makes the swap in swapInstructions * @param payer - The public key of the payer. * @param marketIndexFrom - The market index of the asset to swap from. * @param marketIndexTo - The market index of the asset to swap to. * @param swapInstructions - The swap instructions to use, can be anything (eg: Jupiter, Titan, OKX DEX) * @returns {Promise<{ * ixs: TransactionInstruction[], * lookupTables: AddressLookupTableAccount[], * signers: Keypair[] * }>} Object containing: * - ixs: Array of instructions to swap assets. * - lookupTables: Array of lookup tables for building VersionedTransaction. * - signers: Array of signer keypairs that must sign the transaction the instructions are added to. */ makeSwapIxs(caller: PublicKey, payer: PublicKey, marketIndexFrom: MarketIndex, marketIndexTo: MarketIndex, swapInstructions: TransactionInstruction[], isOwnerSigner: boolean): Promise<{ ixs: TransactionInstruction[]; lookupTables: AddressLookupTableAccount[]; signers: Keypair[]; }>; } //# sourceMappingURL=QuartzUser.class.d.ts.map