@quartz-labs/sdk
Version:
SDK for interacting with the Quartz Protocol
256 lines • 15.2 kB
TypeScript
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 upgrade a Quartz user account.
* @param spendLimitPerTransaction - The card spend limit per transaction.
* @param spendLimitPerTimeframe - The card spend limit per timeframe.
* @param timeframeInSlots - The timeframe in slots (eg: 216,000 for ~1 day).
* @returns {Promise<{
* ixs: TransactionInstruction[],
* lookupTables: AddressLookupTableAccount[],
* signers: Keypair[]
* }>} Object containing:
* - ixs: Array of instructions to upgrade 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 require an upgrade.
*/
makeUpgradeAccountIxs(spendLimitPerTransaction: BN, spendLimitPerTimeframe: BN, timeframeInSeconds: BN, nextTimeframeResetTimestamp: BN): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
makeFulfilDepositIxs(marketIndex: MarketIndex, caller: PublicKey): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
/**
* Creates instructions to rescue unsupported tokens from a Quartz rescue token.
* @param mint - The mint of the token to rescue.
* @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.
*/
makeRescueDepositIxs(destination: PublicKey, mint: 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, paidByUser?: boolean, destinationAddress?: PublicKey): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
/**
* 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.
*/
makeFulfilWithdrawIxs(orderAccount: PublicKey, caller: PublicKey): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
makeFeePaymentIxs(amountBaseUnits: number, marketIndex: MarketIndex, admin: Signer, 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 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.
*/
makeInitiateSpendLimitsIxs(spendLimitPerTransaction: BN, spendLimitPerTimeframe: BN, timeframeInSeconds: BN, nextTimeframeResetTimestamp: BN, paidByUser?: boolean): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
/**
* Creates instructions to update the card spend limits 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 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.
*/
makeFulfilSpendLimitsIxs(orderAccount: PublicKey, caller: PublicKey): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
/**
* Creates instructions to instantly increase the spend limits of a Quartz user account, skipping the time lock.
* @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, if the spend limits are invalid, or if the adjustment to spend limits results in a lower spend limit. Lowering spend limits must be done through adjustSpendLimits.
*/
makeIncreaseSpendLimitsIxs(spendLimitPerTransaction: BN, spendLimitPerTimeframe: BN, timeframeInSeconds: BN, nextTimeframeResetTimestamp: BN): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
/**
* Creates instructions to spend using the Quartz card.
* @param amountSpendBaseUnits - The amount of tokens to spend.
* @param spendCaller - The public key of the Quartz spend caller.
* @param spendFee - True means a percentage of the spend will be sent to the spend fee address.
* @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, spendCaller: Keypair): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
/**
* Creates instructions to repay a loan using collateral.
* @param caller - The public key of the caller, this can be the owner or someone else if account health is 0%.
* @param depositMarketIndex - The market index of the loan token to deposit.
* @param withdrawMarketIndex - The market index of the collateral token to withdraw.
* @param swapInstruction - The swap instruction to use. Deposit and withdrawn amounts are calculated by the balance change after this instruction.
* @param requireOwnerSignature - True means the owner must sign the transaction. This is for manually marking the account info when two signers are required.
* @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 caller does not have enough tokens.
* - the account health is above 0% and the caller is not the owner.
* - the account health is 0% and the caller is not the owner, but the health has not increased above 0% after the repay.
*/
makeCollateralRepayIxs(caller: PublicKey, depositMarketIndex: MarketIndex, withdrawMarketIndex: MarketIndex, swapInstruction: TransactionInstruction, requireOwnerSignature?: boolean): Promise<{
ixs: TransactionInstruction[];
lookupTables: AddressLookupTableAccount[];
signers: Keypair[];
}>;
}
//# sourceMappingURL=QuartzUser.class.d.ts.map