@kamino-finance/farms-sdk
Version:
66 lines • 4.86 kB
TypeScript
import { Address, IInstruction, Rpc, GetBalanceApi, Lamports, GetTokenAccountBalanceApi, TransactionSigner, GetMinimumBalanceForRentExemptionApi, GetAccountInfoApi } from "@solana/kit";
import { Decimal } from "decimal.js";
import { FarmState, UserState, GlobalConfig } from "../@codegen/farms/accounts";
export declare const WAD: Decimal;
export type GlobalConfigFlagValueType = "number" | "bool" | "publicKey";
export declare function collToLamportsDecimal(amount: Decimal.Value, decimals: number): Decimal;
export declare function lamportsToCollDecimal(amount: Decimal.Value, decimals: number): Decimal;
export declare function decimalToBN(value: Decimal): bigint;
export interface GlobalConfigAccounts {
globalAdmin: TransactionSigner;
globalConfig: TransactionSigner;
treasuryVaults: Array<Address>;
treasuryVaultAuthority: Address;
globalAdminRewardAtas: Array<Address>;
}
export interface FarmAccounts {
farmAdmin: TransactionSigner;
farmState: TransactionSigner;
tokenMint: Address;
farmVault: Address;
rewardVaults: Array<Address>;
farmVaultAuthority: Address;
rewardMints: Array<Address>;
adminRewardAtas: Array<Address>;
}
export declare function checkIfAccountExists(connection: Rpc<GetAccountInfoApi>, account: Address): Promise<boolean>;
/**
* Get the custom program error code if there's any in the error message and return parsed error code hex to number string
* @param errMessage string - error message that would contain the word "custom program error:" if it's a customer program error
* @returns [boolean, string] - probably not a custom program error if false otherwise the second element will be the code number in string
*/
export declare const getCustomProgramErrorCode: (errMessage: string) => [boolean, string];
/**
*
* Maps the private Anchor type ProgramError to a normal Error.
* Pass ProgramErr.msg as the Error message so that it can be used with chai matchers
*
* @param fn - function which may throw an anchor ProgramError
*/
export declare function mapAnchorError<T>(fn: Promise<T>): Promise<T>;
export declare function getTokenAccountBalance(rpc: Rpc<GetTokenAccountBalanceApi>, tokenAccount: Address): Promise<Decimal>;
export declare function getTokenAccountBalanceLamports(rpc: Rpc<GetTokenAccountBalanceApi>, tokenAccount: Address): Promise<number>;
export declare function getSolBalanceInLamports(rpc: Rpc<GetBalanceApi>, account: Address): Promise<Lamports>;
export declare function getSolBalance(rpc: Rpc<GetBalanceApi>, account: Address): Promise<Decimal>;
export declare function createAddExtraComputeUnitsTransaction(units: number): IInstruction;
export declare function u16ToBytes(num: number): Uint8Array<ArrayBuffer>;
export declare function accountExist(rpc: Rpc<GetAccountInfoApi>, account: Address): Promise<boolean>;
export declare function fetchFarmStateWithRetry(rpc: Rpc<GetAccountInfoApi>, addr: Address): Promise<FarmState | null>;
export declare function fetchGlobalConfigWithRetry(rpc: Rpc<GetAccountInfoApi>, addr: Address): Promise<GlobalConfig>;
export declare function fetchUserStateWithRetry(rpc: Rpc<GetAccountInfoApi>, addr: Address): Promise<UserState>;
export declare function getTreasuryVaultPDA(programId: Address, globalConfig: Address, rewardMint: Address): Promise<Address>;
export declare function getTreasuryAuthorityPDA(farmsProgramId: Address, globalConfig: Address): Promise<Address>;
export declare function getFarmAuthorityPDA(farmsProgramId: Address, farmState: Address): Promise<Address>;
export declare function getFarmVaultPDA(farmsProgramId: Address, farmState: Address, tokenMint: Address): Promise<Address>;
export declare function getRewardVaultPDA(programId: Address, farmState: Address, rewardMint: Address): Promise<Address>;
export declare function getUserStatePDA(programId: Address, farmState: Address, owner: Address): Promise<Address>;
export declare function getGlobalConfigValue(flagValueType: GlobalConfigFlagValueType, flagValue: string): number[];
export declare function createKeypairRentExemptIx(rpc: Rpc<GetMinimumBalanceForRentExemptionApi>, payer: TransactionSigner, account: TransactionSigner, size: bigint, programId?: Address): Promise<IInstruction>;
export declare function sleep(ms: number): Promise<unknown>;
export declare function scaleDownWads(value: bigint): number;
export declare function convertAmountToStake(amount: Decimal, totalStaked: Decimal, totalAmount: Decimal): Decimal;
export declare const parseTokenSymbol: (tokenSymbol: number[]) => string;
export declare function retryAsync(fn: () => Promise<any>, retriesLeft?: number, interval?: number): Promise<any>;
export declare function noopProfiledFunctionExecution(promise: Promise<any>): Promise<any>;
export declare function isValidPubkey(address?: Address): address is Address;
//# sourceMappingURL=utils.d.ts.map