UNPKG

@kamino-finance/farms-sdk

Version:
161 lines 14.9 kB
import { OraclePrices } from "@kamino-finance/scope-sdk/dist/@codegen/scope/accounts"; import { Address, Instruction, Option, Rpc, Slot, SolanaRpcApi, TransactionSigner, UnixTimestamp } from "@solana/kit"; import Decimal from "decimal.js"; import { FarmState, UserState } from "./@codegen/farms/accounts"; import { FarmConfigOption, RewardInfo } from "./@codegen/farms/types/index"; import { FarmAndKey, FarmIncentives, UserAndKey, UserFarm } from "./models"; import { GlobalConfigFlagValueType } from "./utils"; import { GlobalConfigOption } from "./@codegen/farms/types"; import BN from "bn.js"; import { IFarmResponse, ILogger, MarketWithReserves, StrategyInfo, VaultInfo } from "./utils/farms"; import { SIZE_FARM_STATE, SIZE_GLOBAL_CONFIG } from "./accountSizes"; export { SIZE_FARM_STATE, SIZE_GLOBAL_CONFIG }; export interface UserPointsBreakdown { totalPoints: Decimal; currentBoost: Decimal; currentPointsPerDay: Decimal; perPositionBoost: Map<Address, Decimal>; perPositionPointsPerDay: Map<Address, Decimal>; } export interface RewardCurvePoint { startTs: number; rps: number; } export type PendingWithdrawalCooldownUnit = "seconds" | "slots"; export interface PendingWithdrawalCooldownStatus { userStateAddress?: Address; farm: Address; stakeTokenMint: Address; hasPendingWithdrawal: boolean; pendingWithdrawalUnstakeScaled: BN; canWithdraw: boolean; currentTimeUnit: BN; unlockAt: BN; remaining: BN; unit: PendingWithdrawalCooldownUnit; } export declare class Farms { private readonly _connection; private readonly _farmsProgramId; constructor(connection: Rpc<SolanaRpcApi>, farmsProgramId?: Address); getConnection(): Rpc<import("@solana/kit").RequestAirdropApi & import("@solana/kit").GetAccountInfoApi & import("@solana/kit").GetBalanceApi & import("@solana/kit").GetBlockApi & import("@solana/kit").GetBlockCommitmentApi & import("@solana/kit").GetBlockHeightApi & import("@solana/kit").GetBlockProductionApi & import("@solana/kit").GetBlocksApi & import("@solana/kit").GetBlocksWithLimitApi & import("@solana/kit").GetBlockTimeApi & import("@solana/kit").GetClusterNodesApi & import("@solana/kit").GetEpochInfoApi & import("@solana/kit").GetEpochScheduleApi & import("@solana/kit").GetFeeForMessageApi & import("@solana/kit").GetFirstAvailableBlockApi & import("@solana/kit").GetGenesisHashApi & import("@solana/kit").GetHealthApi & import("@solana/kit").GetHighestSnapshotSlotApi & import("@solana/kit").GetIdentityApi & import("@solana/kit").GetInflationGovernorApi & import("@solana/kit").GetInflationRateApi & import("@solana/kit").GetInflationRewardApi & import("@solana/kit").GetLargestAccountsApi & import("@solana/kit").GetLatestBlockhashApi & import("@solana/kit").GetLeaderScheduleApi & import("@solana/kit").GetMaxRetransmitSlotApi & import("@solana/kit").GetMaxShredInsertSlotApi & import("@solana/kit").GetMinimumBalanceForRentExemptionApi & import("@solana/kit").GetMultipleAccountsApi & import("@solana/kit").GetProgramAccountsApi & import("@solana/kit").GetRecentPerformanceSamplesApi & import("@solana/kit").GetRecentPrioritizationFeesApi & import("@solana/kit").GetSignaturesForAddressApi & import("@solana/kit").GetSignatureStatusesApi & import("@solana/kit").GetSlotApi & import("@solana/kit").GetSlotLeaderApi & import("@solana/kit").GetSlotLeadersApi & import("@solana/kit").GetStakeMinimumDelegationApi & import("@solana/kit").GetSupplyApi & import("@solana/kit").GetTokenAccountBalanceApi & import("@solana/kit").GetTokenAccountsByDelegateApi & import("@solana/kit").GetTokenAccountsByOwnerApi & import("@solana/kit").GetTokenLargestAccountsApi & import("@solana/kit").GetTokenSupplyApi & import("@solana/kit").GetTransactionApi & import("@solana/kit").GetTransactionCountApi & import("@solana/kit").GetVersionApi & import("@solana/kit").GetVoteAccountsApi & import("@solana/kit").IsBlockhashValidApi & import("@solana/kit").MinimumLedgerSlotApi & import("@solana/kit").SendTransactionApi & import("@solana/kit").SimulateTransactionApi>; getProgramID(): Address; getAllUserStatesForUser(user: Address): Promise<Array<UserAndKey>>; getUserStatesForUserAndFarm(user: Address, farm: Address): Promise<Array<UserAndKey>>; getAllUserStates(): Promise<UserAndKey[]>; getAllUserStatesWithFilter(isFarmDelegated: boolean): Promise<UserAndKey[]>; /** * Get all farms user states from an async generator filled with batches of max 100 user states each * @example * const userStateGenerator = farms.batchGetAllUserStates(); * for await (const userStates of userStateGenerator) { * console.log('got a batch of user states:', userStates.length); * } * @param isFarmDelegated - Optional filter to get only user states for farms that are delegated or not */ batchGetAllUserStates(isFarmDelegated?: boolean): AsyncGenerator<UserAndKey[], void, unknown>; getAllUserStatesForFarm(farm: Address): Promise<UserAndKey[]>; getFarmsForMint(mint: Address): Promise<Array<FarmAndKey>>; getAllFarmStates(): Promise<FarmAndKey[]>; /** * Get all farm configs and states categorized by type where possible (otehrwise standalone) * @param markets - Pre-fetched market data -> fetch via KaminoMarket.load() from klend-sdk * @param strategies - Pre-fetched strategy data -> fetch via Kamino.getAllStrategiesWithFilters() from kliquidity-sdk * @param vaults - Pre-fetched vault data -> fetch via KaminoManager.getAllVaults() from klend-sdk * @param logger - Optional logger for debugging */ getAllConfigsAndStates({ markets, strategies, vaults, logger, }: { markets: MarketWithReserves[]; strategies: StrategyInfo[]; vaults: VaultInfo[]; logger?: ILogger; }): Promise<{ collateralFarms: IFarmResponse[]; debtFarms: IFarmResponse[]; strategyFarms: IFarmResponse[]; earnVaultFarms: IFarmResponse[]; standaloneFarms: IFarmResponse[]; }>; getAllFarmStatesByPubkeys(keys: Address[]): Promise<FarmAndKey[]>; getStakedAmountForFarm(farm: Address): Promise<Decimal>; getStakedAmountForMintForFarm(_mint: Address, farm: Address): Promise<Decimal>; getStakedAmountForMint(mint: Address): Promise<Decimal>; getLockupDurationAndExpiry(farm: Address, user: Address, timestampNow: number): Promise<{ lockupRemainingDuration: number; farmLockupOriginalDuration: number; farmLockupExpiry: number; }>; getUserStateKeysForDelegatedFarm(user: Address, farm: Address, delegatees?: Address[]): Promise<Array<UserAndKey>>; getUserStateKeysForDelegatedFarmDeterministic(user: Address, farm: Address, delegatees: Address[]): Promise<Array<UserAndKey>>; getOraclePrices(farmState: FarmState): Promise<OraclePrices | null>; filterFarmsForStrategies(farmStates: FarmAndKey[], strategiesToInclude?: Set<Address>): FarmAndKey[]; filterFarmsForVaults(farmStates: FarmAndKey[], vaultsToInclude?: Set<Address>): FarmAndKey[]; getFarmStatesFromUserStates(userStates: UserAndKey[], strategiesToInclude?: Set<Address>, vaultsToInclude?: Set<Address>): Promise<FarmAndKey[]>; getUserPendingRewards(userState: UserState, farmState: FarmState, timestamp: Decimal, oraclePrices: OraclePrices | null): { userPendingRewardAmounts: Array<Decimal>; hasReward: boolean; }; getAllFarmsForUser(user: Address, timestamp: Decimal, strategiesToInclude?: Set<Address>, vaultsToInclude?: Set<Address>): Promise<Map<Address, UserFarm>>; getRewardsAPYForStrategy(strategy: Address): Promise<FarmIncentives>; getAllFarmsForUserMultiState(user: Address, timestamp: Decimal, strategiesToInclude?: Set<Address>, vaultsToInclude?: Set<Address>): Promise<Map<Address, UserFarm[]>>; getUserStateKeyForUndelegatedFarm(user: Address, farmAddress: Address): Promise<UserAndKey>; getCurrentTimeUnitForFarm(farmState: FarmState): Promise<BN>; getPendingWithdrawalCooldownStatus(userStateAddress: Address): Promise<PendingWithdrawalCooldownStatus>; getPendingWithdrawalCooldownStatusForUser(user: Address, farm: Address | FarmAndKey): Promise<PendingWithdrawalCooldownStatus>; getPendingWithdrawalCooldownStatusForWalletAndFarm(wallet: Address, farm: Address | FarmAndKey): Promise<PendingWithdrawalCooldownStatus>; getUserTokensInUndelegatedFarm(user: Address, farm: Address, tokenDecimals: number): Promise<Decimal>; getUserForUndelegatedFarm(user: Address, farmAddress: Address, timestamp: Decimal): Promise<UserFarm>; createNewUserIx(authority: TransactionSigner, farm: Address, user?: Address, delegatee?: Address): Promise<Instruction>; stakeIx(user: TransactionSigner, farm: Address, amountLamports: Decimal, stakeTokenMint: Address, scopePrices: Option<Address>): Promise<Instruction>; unstakeIx(user: TransactionSigner, farm: Address, amountLamports: Decimal, scopePrices: Option<Address>): Promise<Instruction>; withdrawUnstakedDepositIx(user: TransactionSigner, userState: Address, farmState: Address, stakeTokenMint: Address): Promise<Instruction>; claimForUserForFarmRewardIx(user: TransactionSigner, farm: Address, rewardMint: Address, isDelegated: boolean, rewardIndex?: number, delegatees?: Address[]): Promise<[[Address, Instruction][], Instruction[]]>; claimForUserForFarmAllRewardsIx(payer: TransactionSigner, user: Address, farm: Address, isDelegated: boolean, delegatees?: Address[]): Promise<Array<Instruction>>; transferOwnershipIx(user: TransactionSigner, userState: Address, newUser: Address): Promise<Instruction>; validateFarmStateForTransferOwnership(farmState: FarmState): void; transferOwnershipAllUserStatesIx(user: TransactionSigner, newUser: Address): Promise<Array<Instruction>>; createFarmIxs(admin: TransactionSigner, farm: TransactionSigner, globalConfig: Address, stakeTokenMint: Address): Promise<Instruction[]>; createFarmDelegatedIx(admin: TransactionSigner, farm: TransactionSigner, globalConfig: Address, farmDelegate: TransactionSigner): Promise<Instruction[]>; addRewardToFarmIx(admin: TransactionSigner, globalConfig: Address, farm: Address, mint: Address, tokenProgram: Address): Promise<Instruction>; addRewardAmountToFarmIx(payer: TransactionSigner, farm: Address, mint: Address, amount: Decimal, rewardIndexOverride?: number, decimalsOverride?: number, tokenProgramOverride?: Address, scopePricesOverride?: Option<Address>): Promise<Instruction>; rewardUserOnceIx(delegateAuthority: TransactionSigner, farmState: FarmAndKey, userState: Address, rewardMint: Address, amountLamports: bigint, expectedRewardsIssuedCumulative: bigint, userStateId: bigint): Promise<Instruction>; withdrawRewardAmountFromFarmIx(payer: TransactionSigner, farm: Address, mint: Address, amount: Decimal, rewardIndexOverride?: number, decimalsOverride?: number, tokenProgramOverride?: Address, scopePricesOverride?: Option<Address>): Promise<Instruction[]>; updateFarmConfigIx(admin: TransactionSigner, farm: Address, mint: Address, mode: FarmConfigOption, value: number | Address | number[] | RewardCurvePoint[] | bigint, rewardIndexOverride?: number, scopePricesOverride?: Option<Address>, newFarm?: boolean): Promise<Instruction>; refreshFarmIx(farm: Address, scopePrices: Option<Address>): Promise<Instruction>; refreshUserIx(userState: Address, farmState: Address, scopePrices: Option<Address>): Promise<Instruction>; createGlobalConfigIxs(admin: TransactionSigner, globalConfig: TransactionSigner): Promise<Instruction[]>; updateGlobalConfigIx(admin: TransactionSigner, globalConfig: Address, mode: GlobalConfigOption, flagValue: string, flagValueType: GlobalConfigFlagValueType): Promise<Instruction>; updateGlobalConfigAdminIx(admin: TransactionSigner, globalConfig: Address): Promise<Instruction>; updateSecondDelegatedAuthorityIx(admin: TransactionSigner, globalConfig: Address, farm: Address, newSecondDelegatedAuthority: Address): Promise<Instruction>; updateFarmAdminIx(admin: TransactionSigner, farm: Address): Promise<Instruction>; withdrawTreasuryIx(admin: TransactionSigner, globalConfig: Address, rewardMint: Address, rewardTokenProgram: Address, amount: bigint, withdrawAta?: Address): Promise<Instruction>; updateFarmRpsForRewardIx(payer: TransactionSigner, rewardMint: Address, farm: Address, rewardsPerSecond: number): Promise<Instruction>; topUpFarmForRewardIx(payer: TransactionSigner, rewardMint: Address, farm: Address, amountToTopUp: Decimal): Promise<Instruction>; fetchMultipleFarmStatesWithCheckedSize(keys: Address[]): Promise<(FarmState | null)[]>; private processRewardInfos; calculateFarmIncentivesApy(farm: FarmAndKey, getPriceByTokenMintDecimal: (mint: Address) => Promise<Decimal>, stakedTokenPrice: Decimal, stakedTokenDecimals: number, pricesMap?: Map<Address, Decimal>): Promise<FarmIncentives>; /** * Simulates the farm incentives APY after a stake or unstake operation. * @param farm - The farm to simulate the incentives APY for. * @param stakedTokenDelta - The difference between the current staked amount and the new staked amount (if positive, it's a stake, if negative, it's an unstake) * @param getPriceByTokenMintDecimal - A function to get the price of a token mint. * @param stakedTokenPrice - The price of the staked token. * @param stakedTokenDecimals - The decimals of the staked token. * @param pricesMap - A map of token mints to their prices. * @param verbose - Whether to log verbose information. * @returns The farm incentives APY after the stake or unstake operation. */ simulateFarmIncentivesApy(farm: FarmAndKey, stakedTokenDelta: Decimal, getPriceByTokenMintDecimal: (mint: Address) => Promise<Decimal>, stakedTokenPrice: Decimal, stakedTokenDecimals: number, pricesMap?: Map<Address, Decimal>, verbose?: boolean): Promise<FarmIncentives>; calculateRewardsForPeriods(reward: RewardInfo, rewardType: number, totalStakedAmount: Decimal, stakedTokenDecimals: number, price: Decimal): { dailyRewards: Decimal; weeklyRewards: Decimal; monthlyRewards: Decimal; yearlyRewards: Decimal; }; getRewardPerTimeUnitSecond(reward: RewardInfo): Decimal; } export declare function getCurrentTimeUnit(farm: FarmState, slot: Slot, timestamp: UnixTimestamp): Promise<Decimal>; export declare function calculatePendingWithdrawalCooldownStatus(farmState: FarmState, userState: UserState, currentTimeUnit: BN, userStateAddress?: Address): PendingWithdrawalCooldownStatus; export declare function getCurrentRps(farm: FarmState, rewardIndex: number, slot: Slot, timestamp: UnixTimestamp): Promise<number>; export declare const calcAvgBoost: (dollarValueBoosts: [Decimal, Decimal][]) => Decimal; //# sourceMappingURL=Farms.d.ts.map