import { Address, Commitment, GetAccountInfoApi, GetBalanceApi, GetMinimumBalanceForRentExemptionApi, GetMultipleAccountsApi, GetProgramAccountsApi, GetSlotApi, GetTokenAccountBalanceApi, Rpc } from '@solana/kit'; import type { LedgerInstant } from '../utils/ledger'; import { KaminoObligation } from './obligation'; import { KaminoReserve, KaminoReserveRpcApi, ReserveWithAddress } from './reserve'; import { LendingMarket, ReferrerTokenState, Reserve, UserMetadata } from '../@codegen/klend/accounts'; import { AllOracleAccounts, ObligationType, ReserveKind } from '../utils'; import Decimal from 'decimal.js'; import { Scope } from '@kamino-finance/scope-sdk'; import { OraclePrices } from '@kamino-finance/scope-sdk/dist/@codegen/scope/accounts/OraclePrices'; import { KaminoPrices } from '@kamino-finance/kliquidity-sdk'; import { PermissionedOp } from './permission'; export type KaminoMarketRpcApi = GetAccountInfoApi & GetMultipleAccountsApi & GetProgramAccountsApi & GetSlotApi & GetMinimumBalanceForRentExemptionApi & GetTokenAccountBalanceApi & GetBalanceApi; export interface ReserveRewardInfo { rewardsPerSecond: Decimal; rewardsRemaining: Decimal; rewardApr: Decimal; rewardMint: Address; totalInvestmentUsd: Decimal; rewardPrice: number; } export declare class KaminoMarket { private readonly rpc; readonly address: Address; state: LendingMarket; reserves: Map; reservesActive: Map; readonly programId: Address; readonly farmsProgramId: Address; private readonly recentSlotDurationMs; readonly scopeFeeds: Set
; private constructor(); /** * TESTING ONLY! * * Used to create mock markets for testing */ static createMarket(rpc: Rpc, state: LendingMarket, marketAddress: Address, reserves: Map, recentSlotDurationMs: number, programId?: Address): KaminoMarket; /** * Load a new market with all of its associated reserves * @param rpc * @param marketAddress * @param recentSlotDurationMs * @param programId * @param withReserves */ static load(rpc: Rpc, marketAddress: Address, recentSlotDurationMs: number, programId?: Address, withReserves?: boolean, farmsProgramId?: Address): Promise; static loadWithReserves(connection: Rpc, market: LendingMarket, reserves: Map, marketAddress: Address, recentSlotDurationMs: number, programId?: Address, farmsProgramId?: Address): KaminoMarket; static loadMultiple(connection: Rpc, markets: Address[], recentSlotDurationMs: number, programId?: Address, withReserves?: boolean, oracleAccounts?: AllOracleAccounts, farmsProgramId?: Address): Promise>; static loadMultipleWithReserves(connection: Rpc, markets: Address[], reserves: Map>, recentSlotDurationMs: number, programId?: Address, farmsProgramId?: Address): Promise>; reload(): Promise; reloadSingleReserve(reservePk: Address, reserveData?: Reserve): Promise; /** * Get the address of this market * @return market address public key */ getAddress(): Address; /** * Get a list of reserves for this market */ getReserves(): Array; getElevationGroup(elevationGroup: number): import("../@codegen/klend/types").ElevationGroup; /** * Returns this market's elevation group of the given ID, or `null` for the default group `0`, or throws an error * (including the given description) if the requested group does not exist. */ getExistingElevationGroup(elevationGroupId: number, description?: string): ElevationGroupDescription | null; getMinNetValueObligation(): Decimal; /** * Get the authority PDA of this market * @return market authority public key */ getLendingMarketAuthority(): Promise
; getName(): string; /** * True if any op in `op` is gated by the market's permissioning authority, for an operation touching * `opReserves`. An op is gated when the market itself gates it, or when any of the touched reserves * does — but only on a market that has a permissioning authority, since without one there is nobody * who could authorize it and the reserves' own flags lie dormant. * * Pass every reserve the operation touches; a reserve omitted here is a gate not seen. Passing `[]` still * applies the market's own gating — it means "this operation touches no reserve", not "check nothing". */ requiresPermissioner(op: PermissionedOp, opReserves: KaminoReserve[]): boolean; /** Address authorized to sign for permissioned ops on this market. */ getPermissioningAuthority(): Address | undefined; getObligationDepositByWallet(owner: Address, depositReserveAddress: Address, obligationType: ObligationType): Promise; getObligationBorrowByWallet(owner: Address, borrowReserveAddress: Address, obligationType: ObligationType): Promise; getTotalDepositTVL(): Decimal; getTotalBorrowTVL(): Decimal; getMaxLeverageForPair(collReserveAddress: Address, debtReserveAddress: Address): number; getCommonElevationGroupsForPair(collReserve: KaminoReserve, debtReserve: KaminoReserve): number[]; /** * The elevation group an on-chain deposit+borrow of this (collateral, debt) pair auto-selects: the common * elevation group with the highest LTV, or `0` (no emode / default) when the pair shares no usable group. * * Single source of truth for the "preferred group for a borrow pair" rule — used by `KaminoAction` when building * deposit+borrow ixs and by the swap-debt migration preview/validation so all three stay consistent. */ getPreferredElevationGroupForBorrowPair(collReserve: KaminoReserve, debtReserve: KaminoReserve): number; getMaxAndLiquidationLtvAndBorrowFactorForPair(collReserveAddress: Address, debtReserveAddress: Address, elevationGroup?: number): { maxLtv: number; liquidationLtv: number; borrowFactor: number; }; getTotalProductTvl(productType: ObligationType, currentLedgerInstant: LedgerInstant): Promise<{ tvl: Decimal; borrows: Decimal; deposits: Decimal; avgLeverage: Decimal; }>; /** * * @returns Number of active obligations in the market */ getNumberOfObligations(currentLedgerInstant: LedgerInstant): Promise; getObligationByWallet(Address: Address, obligationType: ObligationType): Promise; /** * @returns The max borrowable amount for leverage positions */ getMaxLeverageBorrowableAmount(collReserve: KaminoReserve, debtReserve: KaminoReserve, currentLedgerInstant: LedgerInstant, requestElevationGroup: boolean, obligation?: KaminoObligation): Decimal; loadReserves(oracleAccounts?: AllOracleAccounts): Promise; refreshAll(): Promise; getReserveByAddress(address: Address): KaminoReserve | undefined; /** * Returns this market's reserve of the given address, or throws an error (including the given description) if such * reserve does not exist. */ getExistingReserveByAddress(address: Address, description?: string): KaminoReserve; /** * Returns all reserves for the given mint address (both float rate and fixed rate). * * @param mint The liquidity mint address * @returns Array of all reserves for this mint */ getReservesByMint(address: Address): KaminoReserve[]; getExistingReservesByMint(address: Address, description?: string): KaminoReserve[]; getLiquidityTokenProgramByMint(mint: Address): Address; /** * Returns this market's reserve matching the given mint address and reserve kind. * Since a market can have multiple reserves for the same mint (with different terms), * the reserve kind specifies which reserve to select. * * Example for fixed-term reserves: * const fixedReserveKind = new FixedReserveKind(new BN(30 * 24 * 60 * 60), 500); // 30 days, 5% borrow rate * const fixedReserve = market.getReserveByMintAndKind(tokenMint, fixedReserveKind)!; * @param mint The liquidity mint address * @param reserveKind The reserve kind to match (e.g., FloatRateReserveKind or FixedRateReserveKind) */ getReserveByMintAndKind(mint: Address, reserveKind: ReserveKind): KaminoReserve | undefined; /** * Returns this market's reserve matching the given mint address and reserve kind, * or throws an error if not found. * * @param mint The liquidity mint address * @param reserveKind The reserve kind to match * @param description Optional description for the error message */ getExistingReserveByMintAndKind(mint: Address, reserveKind: ReserveKind, description?: string): KaminoReserve; /** * Returns this market's float rate reserve for the given mint address. * Float rate reserves are reserves without a fixed term (debtTermSeconds = 0). * * @param mint The liquidity mint address * @returns The float rate reserve, or undefined if not found */ getFloatRateReserveByMint(mint: Address): KaminoReserve | undefined; /** * Returns this market's float rate reserve for the given mint address, * or throws an error if not found. * * @param mint The liquidity mint address * @param description Optional description for the error message * @returns The float rate reserve */ getExistingFloatRateReserveByMint(mint: Address, description?: string): KaminoReserve; /** * Returns all fixed rate reserves for the given mint address. * Fixed rate reserves have a non-zero debt term (debtTermSeconds > 0). * * @param mint The liquidity mint address * @returns Array of all fixed rate reserves for this mint */ getFixedRateReservesByMint(mint: Address): KaminoReserve[]; /** * Returns all maturity-timestamp reserves for the given mint address. * * @param mint The liquidity mint address * @returns Array of all maturity-timestamp reserves for this mint */ getMaturityTimestampReservesByMint(mint: Address): KaminoReserve[]; /** * Returns all reserves for the given symbol (both float rate and fixed rate). * * @param symbol The reserve symbol * @returns Array of all reserves for this symbol */ getReservesBySymbol(symbol: string): KaminoReserve[]; getExistingReservesBySymbol(symbol: string, description?: string): KaminoReserve[]; /** * Returns this market's reserve matching the given symbol and reserve kind. * Since a market can have multiple reserves for the same symbol (with different terms), * the reserve kind specifies which reserve to select. * * @param symbol The reserve symbol * @param reserveKind The reserve kind to match (e.g., FloatRateReserveKind or FixedRateReserveKind) */ getReserveBySymbolAndKind(symbol: string, reserveKind: ReserveKind): KaminoReserve | undefined; /** * Returns this market's reserve matching the given symbol and reserve kind, * or throws an error if not found. * * @param symbol The reserve symbol * @param reserveKind The reserve kind to match * @param description Optional description for the error message */ getExistingReserveBySymbolAndKind(symbol: string, reserveKind: ReserveKind, description?: string): KaminoReserve; /** * Returns this market's float rate reserve for the given symbol. * Float rate reserves are reserves without a fixed term (debtTermSeconds = 0). * * @param symbol The reserve symbol * @returns The float rate reserve, or undefined if not found */ getFloatRateReserveBySymbol(symbol: string): KaminoReserve | undefined; /** * Returns this market's float rate reserve for the given symbol, * or throws an error if not found. * * @param symbol The reserve symbol * @param description Optional description for the error message * @returns The float rate reserve */ getExistingFloatRateReserveBySymbol(symbol: string, description?: string): KaminoReserve; /** * Returns all fixed rate reserves for the given symbol. * Fixed rate reserves have a non-zero debt term (debtTermSeconds > 0). * * @param symbol The reserve symbol * @returns Array of all fixed rate reserves for this symbol */ getFixedRateReservesBySymbol(symbol: string): KaminoReserve[]; /** * Returns all maturity-timestamp reserves for the given symbol. * * @param symbol The reserve symbol * @returns Array of all maturity-timestamp reserves for this symbol */ getMaturityTimestampReservesBySymbol(symbol: string): KaminoReserve[]; getReserveMintBySymbol(symbol: string): Address; getReserveFarmInfo(reserveAddress: Address, getRewardPrice: (mint: Address) => Promise): Promise<{ borrowingRewards: ReserveRewardInfo; depositingRewards: ReserveRewardInfo; }>; getRewardInfoForFarm(farmAddress: Address, totalInvestmentUsd: Decimal, getRewardPrice: (mint: Address) => Promise): Promise; calculateRewardAPR(rewardPerSecondLamports: number, rewardPriceUsd: number, totalInvestmentUsd: Decimal, rewardDecimals: number): Decimal; /** * Get all obligations for lending market, optionally filter by obligation tag * This function will likely require an RPC capable of returning more than the default 100k rows in a single scan * * @param tag */ getAllObligationsForMarket(currentLedgerInstant: LedgerInstant, tag?: number): Promise; /** * Get all obligations for lending market from an async generator filled with batches of 100 obligations each * @param tag * @example * const obligationsGenerator = market.batchGetAllObligationsForMarket(); * for await (const obligations of obligationsGenerator) { * console.log('got a batch of # obligations:', obligations.length); * } */ batchGetAllObligationsForMarket(currentLedgerInstant: LedgerInstant, tag?: number): AsyncGenerator; getAllObligationsByTag(tag: number, market: Address, currentLedgerInstant: LedgerInstant): Promise; /** * Retrieves all obligations that have deposited into the specified reserve. * * Iterates through all possible deposit slots up to DEPOSITS_LIMIT, applying filters to fetch obligations * from the program accounts where the deposited reserve matches the provided address. For each matching * obligation, it decodes the account data, validates ownership, and constructs KaminoObligation instances * with calculated rates. * * @param {Address} reserve - The address of the reserve to filter deposited obligations by. * @returns {Promise} A promise that resolves to an array of KaminoObligation objects representing all obligations that have deposited into the specified reserve. * @throws {Error} If an account is invalid or does not belong to this program, or if obligation parsing fails. */ getAllObligationsByDepositedReserve(reserve: Address, currentLedgerInstant: LedgerInstant): Promise; /** * Retrieves all obligations that have borrowed from the specified reserve. * * Iterates through all possible borrow slots up to BORROWS_LIMIT, applying filters to fetch obligations * from the program accounts where the borrowed reserve matches the provided address. For each matching * obligation, it decodes the account data, validates ownership, and constructs KaminoObligation instances * with calculated rates. * * @param {Address} reserve - The address of the reserve to filter borrowed obligations by. * @returns {Promise} A promise that resolves to an array of KaminoObligation objects * representing all obligations that have borrowed from the specified reserve. * @throws {Error} If an account is invalid or does not belong to this program, or if obligation parsing fails. */ getAllObligationsByBorrowedReserve(reserve: Address, currentLedgerInstant: LedgerInstant): Promise; getAllUserObligations(user: Address, currentLedgerInstant: LedgerInstant, commitment?: Commitment): Promise; getAllUserObligationsForReserve(user: Address, reserve: Address, currentLedgerInstant: LedgerInstant): Promise; getUserVanillaObligation(user: Address): Promise; isReserveInObligation(obligation: KaminoObligation, reserve: Address): boolean; getUserObligationsByTag(tag: number, user: Address, currentLedgerInstant: LedgerInstant): Promise; getObligationByAddress(address: Address): Promise; getMultipleObligationsByAddress(addresses: Address[], currentLedgerInstant: LedgerInstant): Promise<(KaminoObligation | null)[]>; /** * Get the user metadata PDA and fetch and return the user metadata state if it exists * @return [address, userMetadataState] - The address of the user metadata PDA and the user metadata state, or null if it doesn't exist */ getUserMetadata(user: Address): Promise<[Address, UserMetadata | null]>; getReferrerTokenStateForReserve(referrer: Address, reserve: Address): Promise<[Address, ReferrerTokenState | null]>; getAllReferrerTokenStates(referrer: Address): Promise>; getAllReferrerFeesUnclaimed(referrer: Address): Promise>; getReferrerFeesUnclaimedForReserve(referrer: Address, reserve: KaminoReserve): Promise; getReferrerFeesCumulativeForReserve(referrer: Address, reserve: KaminoReserve): Promise; getAllReferrerFeesCumulative(referrer: Address): Promise>; getReferrerUrl(baseUrl: string, referrer: Address): string; getReferrerFromUrl(baseUrl: string, url: string): Address; /** * Get the underlying rpc passed when instantiating this market * @return rpc */ getRpc(): Rpc; /** * Get all scope OraclePrices accounts for all market reserves * @param scope */ getReserveOraclePrices(scope: Scope): Promise>; /** * Get all Scope prices used by all the market reserves */ getAllScopePrices(scope: Scope, allOraclePrices: Map): Promise; /** * Get all Scope/Pyth/Switchboard prices used by all the market reserves */ getAllPrices(oracleAccounts?: AllOracleAccounts): Promise; getCumulativeBorrowRatesByReserve(currentLedgerInstant: LedgerInstant): Map; getCollateralExchangeRatesByReserve(currentLedgerInstant: LedgerInstant): Map; private setPriceIfExist; getRecentSlotDurationMs(): number; getMarketElevationGroupDescriptions(): ElevationGroupDescription[]; getElevationGroupsForMintsCombination(collLiquidityMints: Address[], debtLiquidityMint?: Address): ElevationGroupDescription[]; getElevationGroupsForReservesCombination(collReserves: Address[], debtReserve?: Address): ElevationGroupDescription[]; } export type BorrowCapsAndCounters = { utilizationCap: Decimal; utilizationCurrentValue: Decimal; netWithdrawalCap: Decimal; netWithdrawalCurrentValue: Decimal; netWithdrawalLastUpdateTs: Decimal; netWithdrawalIntervalDurationSeconds: Decimal; globalDebtCap: Decimal; globalTotalBorrowed: Decimal; debtOutsideEmodeCap: Decimal; borrowedOutsideEmode: Decimal; debtAgainstCollateralReserveCaps: { collateralReserve: Address; elevationGroup: number; maxDebt: Decimal; currentValue: Decimal; }[]; }; export type ElevationGroupDescription = { collateralReserves: Set
; collateralLiquidityMints: Set
; debtReserve: Address; debtLiquidityMint: Address; elevationGroup: number; maxReservesAsCollateral: number; }; export type KlendPrices = { scope: KaminoPrices; pyth: KaminoPrices; switchboard: KaminoPrices; }; export declare function getReserveStatesForMarket(marketAddress: Address, rpc: Rpc, programId: Address): Promise; /** * `reserveRewardsMaxAprBps` is the market's `LendingMarket::reserveRewardsMaxAprBps`; pass it * when you already hold the market state to save a network call, otherwise the market is fetched * to read it. */ export declare function getReservesForMarket(marketAddress: Address, rpc: Rpc, programId: Address, recentSlotDurationMs: number, reserveRewardsMaxAprBps?: number, oracleAccounts?: AllOracleAccounts): Promise>; /** * `reserveRewardsMaxAprBps` is the parent market's `LendingMarket::reserveRewardsMaxAprBps`; pass * it when you already hold the market state to save a network call, otherwise the reserve's * lending market is fetched to read it. */ export declare function getSingleReserve(reservePk: Address, rpc: Rpc, recentSlotDurationMs: number, reserveData?: Reserve, oracleAccounts?: AllOracleAccounts, reserveRewardsMaxAprBps?: number, programId?: Address): Promise; export declare function getReservesActive(reserves: Map): Map; /** * * @param kaminoMarket * @param reserves */ export declare function getTokenIdsForScopeRefresh(kaminoMarket: KaminoMarket, reserves: Address[]): Map; //# sourceMappingURL=market.d.ts.map