@hubbleprotocol/farms-sdk
Version:
120 lines (119 loc) • 11.7 kB
TypeScript
import { BN, Idl, Program } from "@coral-xyz/anchor";
import { Connection, PublicKey, Signer, Transaction, TransactionInstruction, TransactionSignature } from "@solana/web3.js";
import { UserFarm } from "./models";
import { FarmState } from "./rpc_client/accounts";
import Decimal from "decimal.js";
import { Keypair } from "@solana/web3.js";
import { GlobalConfigOptionKind, FarmConfigOptionKind } from "./rpc_client/types/index";
import { FarmAndKey, UserAndKey } from "./models";
import { OraclePrices } from "@hubbleprotocol/scope-sdk";
import { KaminoMarket, Position, PubkeyHashMap, PublicKeySet } from "@kamino-finance/klend-sdk";
import { Web3Client } from "./utils/sendTransactionsUtils";
export declare const farmsId: PublicKey;
export interface UserPointsBreakdown {
totalPoints: Decimal;
currentBoost: Decimal;
currentPointsPerDay: Decimal;
perPositionBoost: PubkeyHashMap<PublicKey, Decimal>;
perPositionPointsPerDay: PubkeyHashMap<PublicKey, Decimal>;
}
export interface RewardCurvePoint {
startTs: number;
rps: number;
}
export declare class Farms {
private readonly _connection;
private readonly _provider;
private readonly _farmsProgram;
private readonly _farmsProgramId;
constructor(connection: Connection);
getConnection(): Connection;
getProgramID(): PublicKey;
getProgram(): Program<Idl>;
getAllUserStatesForUser(user: PublicKey): 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);
* }
*/
batchGetAllUserStates(): AsyncGenerator<UserAndKey[], void, unknown>;
getAllUserStatesForFarm(farm: PublicKey): Promise<UserAndKey[]>;
getFarmsForMint(mint: PublicKey): Promise<Array<FarmAndKey>>;
getAllFarmStates(): Promise<FarmAndKey[]>;
getAllFarmStatesByPubkeys(keys: PublicKey[]): Promise<FarmAndKey[]>;
getStakedAmountForMintForFarm(mint: PublicKey, farm: PublicKey): Promise<Decimal>;
getStakedAmountForMint(mint: PublicKey): Promise<Decimal>;
getLockupDurationAndExpiry(farm: PublicKey, user: PublicKey): Promise<{
lockupRemainingDuration: number;
farmLockupOriginalDuration: number;
farmLockupExpiry: number;
}>;
getUserStateKeysForDelegatedFarm(user: PublicKey, farm: PublicKey, delegatees?: PublicKey[]): Promise<Array<UserAndKey>>;
getUserStateKeysForDelegatedFarmDeterministic(user: PublicKey, farm: PublicKey, delegatees: PublicKey[]): Promise<Array<UserAndKey>>;
getAllFarmsForUser(user: PublicKey, strategiesToInclude?: PublicKeySet<PublicKey>): Promise<PubkeyHashMap<PublicKey, UserFarm>>;
getUserStateKeyForUndelegatedFarm(user: PublicKey, farmAddress: PublicKey): Promise<UserAndKey>;
getUserForUndelegatedFarm(user: PublicKey, farmAddress: PublicKey): Promise<UserFarm>;
executeTransaction(ix: TransactionInstruction[], signer: Keypair, extraSigners?: Signer[], web3Client?: Web3Client, priorityFeeMultiplier?: number): Promise<TransactionSignature>;
createNewUserIx(user: PublicKey, farm: PublicKey): Promise<TransactionInstruction>;
createNewUser(user: Keypair, farm: PublicKey, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
stakeIx(user: PublicKey, farm: PublicKey, amountLamports: Decimal, stakeTokenMint: PublicKey, scopePrices: PublicKey): Promise<TransactionInstruction>;
stake(user: Keypair, farm: PublicKey, amountLamports: Decimal, stakeTokenMint: PublicKey, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
unstakeIx(user: PublicKey, farm: PublicKey, amountLamports: string, scopePrices: PublicKey): Promise<TransactionInstruction>;
unstake(user: Keypair, farm: PublicKey, sharesAmount: string, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
withdrawUnstakedDepositIx(user: PublicKey, userState: PublicKey, farmState: PublicKey, stakeTokenMint: PublicKey): Promise<TransactionInstruction>;
withdrawUnstakedDeposit(user: Keypair, farmState: PublicKey, tokenMint: PublicKey, userState: PublicKey, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
claimForUserForFarmRewardIx(user: PublicKey, farm: PublicKey, rewardMint: PublicKey, isDelegated: boolean, rewardIndex?: number, delegatees?: PublicKey[]): Promise<[
[PublicKey, TransactionInstruction][],
TransactionInstruction[]
]>;
claimForUserForFarmReward(user: Keypair, farm: PublicKey, rewardMint: PublicKey, isDelegated: boolean, rewardIndex: number | undefined, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
claimForUserForFarmAllRewardsIx(user: PublicKey, farm: PublicKey, isDelegated: boolean, delegatees?: PublicKey[]): Promise<Array<TransactionInstruction>>;
claimForUserForFarmAllRewards(user: Keypair, farm: PublicKey, isDelegated: boolean, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<Array<TransactionSignature>>;
transferOwnershipIx(user: PublicKey, userState: PublicKey, newUser: PublicKey): Promise<TransactionInstruction>;
transferOwnership(user: Keypair, userState: PublicKey, newUser: PublicKey, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
transferOwnershipAllUserStatesIx(user: PublicKey, newUser: PublicKey): Promise<Array<TransactionInstruction>>;
transferOwnershipAllUserStates(user: Keypair, newUser: PublicKey, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<Array<TransactionSignature>>;
createFarmIx(admin: PublicKey, farm: Keypair, globalConfig: PublicKey, stakeTokenMint: PublicKey): Promise<TransactionInstruction[]>;
createFarm(admin: Keypair, globalConfig: PublicKey, farm: Keypair, mint: PublicKey, mode: string | undefined, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
addRewardToFarmIx(admin: PublicKey, globalConfig: PublicKey, farm: PublicKey, mint: PublicKey, tokenProgram: PublicKey): Promise<TransactionInstruction>;
addRewardToFarm(admin: Keypair, globalConfig: PublicKey, farm: PublicKey, mint: PublicKey, tokenProgram: PublicKey, mode: string | undefined, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
addRewardAmountToFarmIx(payer: PublicKey, farm: PublicKey, mint: PublicKey, amount: Decimal, rewardIndexOverride?: number, decimalsOverride?: number, tokenProgramOverride?: PublicKey, scopePricesOverride?: PublicKey): Promise<TransactionInstruction>;
withdrawRewardAmountFromFarmIx(payer: PublicKey, farm: PublicKey, mint: PublicKey, amount: Decimal, rewardIndexOverride?: number, decimalsOverride?: number, tokenProgramOverride?: PublicKey, scopePricesOverride?: PublicKey): Promise<TransactionInstruction>;
addRewardAmountToFarm(payer: Keypair, farm: PublicKey, mint: PublicKey, amount: Decimal, mode: string, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
updateFarmConfigIx(admin: PublicKey, farm: PublicKey, mint: PublicKey, mode: FarmConfigOptionKind, value: number | PublicKey | number[] | RewardCurvePoint[], rewardIndexOverride?: number, scopePricesOverride?: PublicKey, newFarm?: boolean): Promise<TransactionInstruction>;
updateFarmConfig(admin: Keypair, farm: PublicKey, mint: PublicKey, updateMode: FarmConfigOptionKind, value: number | PublicKey, mode: string | undefined, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
refreshFarmIx(farm: PublicKey, scopePrices: PublicKey): Promise<TransactionInstruction>;
refreshFarm(payer: Keypair, farm: PublicKey, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
refreshUserIx(userState: PublicKey, farmState: PublicKey, scopePrices: PublicKey): Promise<TransactionInstruction>;
refreshUser(payer: Keypair, userState: PublicKey, farmState: PublicKey, scopePrices: PublicKey, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
createGlobalConfigIxs(admin: PublicKey, globalConfig: Keypair): Promise<TransactionInstruction[]>;
createGlobalConfig(admin: Keypair, globalConfig: Keypair, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
updateGlobalConfigIx(admin: PublicKey, globalConfig: PublicKey, mode: GlobalConfigOptionKind, flagValue: string, flagValueType: string): Promise<TransactionInstruction>;
updateGlobalConfigAdminIx(admin: PublicKey, globalConfig: PublicKey): Promise<TransactionInstruction>;
updateFarmAdminIx(admin: PublicKey, farm: PublicKey): Promise<TransactionInstruction>;
updateGlobalConfig(admin: Keypair, globalConfig: PublicKey, updateMode: GlobalConfigOptionKind, flagValue: string, flagValueType: string, mode: string, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
updateGlobalConfigAdmin(admin: Keypair, globalConfig: PublicKey, mode: string, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
updateFarmAdmin(admin: Keypair, farm: PublicKey, mode: string, priorityFeeMultiplier: number, web3Client?: Web3Client): Promise<TransactionSignature>;
withdrawTreasuryIx(admin: PublicKey, globalConfig: PublicKey, rewardMint: PublicKey, rewardTokenProgram: PublicKey, amount: BN, withdrawAta?: PublicKey): Promise<TransactionInstruction>;
withdrawTreasury(admin: Keypair, globalConfig: PublicKey, rewardMint: PublicKey, rewardTokenProgram: PublicKey, amount: BN, priorityFeeMultiplier: number, withdrawAta?: PublicKey, web3Client?: Web3Client): Promise<TransactionSignature>;
getAllPointsData(scopePricesPubkey: PublicKey, klendProgramId: PublicKey, kaminoMarketPubkey: PublicKey, pointsMint: PublicKey): Promise<PubkeyHashMap<PublicKey, UserPointsBreakdown>>;
processTxn(admin: Keypair, ixns: TransactionInstruction[], mode: string, priorityFeeMultiplier: number, debugMessage?: string, extraSigners?: Signer[], web3Client?: Web3Client): Promise<TransactionSignature>;
fetchMultipleFarmStatesWithCheckedSize(keys: PublicKey[]): Promise<(FarmState | null)[]>;
}
export declare function getCurrentTimeUnit(conn: Connection, farm: FarmState): Promise<Decimal>;
export declare function getCurrentRps(conn: Connection, farm: FarmState, rewardIndex: number): Promise<number>;
export declare function printMultisigTx(tx: Transaction): Promise<void>;
export declare function printSimulateTx(conn: Connection, tx: Transaction): Promise<void>;
export declare const calcAvgBoost: (dollarValueBoosts: [Decimal, Decimal][]) => Decimal;
export declare const calculatePointsPerDay: (kaminoMarket: KaminoMarket, user: PublicKey, mint: PublicKey, farmPubkeyToFarmStates: PubkeyHashMap<PublicKey, FarmState>, pointsMint: PublicKey, pointsFactor: number, position: Position, isCollateral: boolean, finalBoost: Decimal, scopePrices: OraclePrices | null) => Decimal;
export declare const getAllBoosts: (kaminoMarket: KaminoMarket) => {
perAssetCollBoosts: PubkeyHashMap<PublicKey, Decimal>;
perAssetDebtBoosts: PubkeyHashMap<PublicKey, Decimal>;
perAssetProductBoosts: PubkeyHashMap<PublicKey, Map<number, Decimal>>;
perProductBoosts: Map<number, Decimal>;
};