@hubbleprotocol/hubble-sdk
Version:
Hubble Protocol client SDK
220 lines (219 loc) • 10.6 kB
TypeScript
import { HubbleConfig, SolanaCluster } from '@hubbleprotocol/hubble-config';
import { Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
import StakingPoolState from './models/StakingPoolState';
import StabilityPoolState from './models/StabilityPoolState';
import BorrowingMarketState from './models/BorrowingMarketState';
import UserStakingState from './models/UserStakingState';
import StabilityProviderState from './models/StabilityProviderState';
import UserMetadata from './models/UserMetadata';
import Loan from './models/Loan';
import Decimal from 'decimal.js';
import UserMetadataWithJson from './models/UserMetadataWithJson';
import StabilityProviderStateWithJson from './models/StabilityProviderStateWithJson';
import { HbbVault, HubblePrices, PsmReserve, UsdhVault } from './models';
import GlobalConfig from './models/GlobalConfig';
import { SwapInfo } from './models/SwapInfo';
import { TermsSignature } from './models/TermsSignature';
import { OraclePrices } from '@kamino-finance/scope-sdk';
export declare class Hubble {
private readonly _cluster;
private readonly _connection;
private readonly _scope;
readonly _config: HubbleConfig;
private readonly _provider;
private _borrowingProgram;
/**
* Create a new instance of the Hubble SDK class.
* @param cluster Name of the Solana cluster
* @param connection Connection to the Solana cluster
*/
constructor(cluster: SolanaCluster, connection: Connection, borrowingProgramId?: string);
/**
* Get Hubble's staking pool state.
* @return on-chain {@link StakingPoolState} from the borrowing program with numbers as lamports
*/
getStakingPoolState(): Promise<StakingPoolState>;
/**
* Get Hubble's stability pool state.
* @return on-chain {@link StabilityPoolState} from the borrowing program with numbers as lamports
*/
getStabilityPoolState(): Promise<StabilityPoolState>;
private borrowingMarketStateToDecimals;
/**
* @deprecated Deprecated since version 1.0.114.
* Please use getBorrowingMarketStateByPubkey or getBorrowingMarketStates and use the correct borrowing market state specified by the UserMetadata.
* Get Hubble's borrowing market state.
* @return on-chain {@link BorrowingMarketState} from the borrowing program with numbers as lamports
*/
getBorrowingMarketState(): Promise<BorrowingMarketState>;
/**
* Get Hubble's borrowing market state by public key.
* @return on-chain {@link BorrowingMarketState} from the borrowing program with numbers as lamports
*/
getBorrowingMarketStateByPubkey(pubkey: PublicKey): Promise<BorrowingMarketState>;
/**
* Get Hubble's borrowing market states.
* @return list of on-chain {@link BorrowingMarketState} from the borrowing program with numbers as lamports
*/
getBorrowingMarketStates(): Promise<BorrowingMarketState[]>;
/**
* Get user's staking state (staking stats).
* @param user Base58 encoded Public Key of the user
* @return on-chain {@link UserStakingState} from the borrowing program for the specific user with numbers as lamports
* or undefined if user has never used Hubble before or authorized HBB staking
*/
getUserStakingState(user: PublicKey | string): Promise<UserStakingState | undefined>;
/**
* Convert anchor's stability provider state with BN to stability provider state with decimals
* @param stabilityProviderState
*/
private static stabilityProviderStateToDecimals;
/**
* Get user's stability provider state (stability pool stats).
* @param user Base58 encoded Public Key of the user
* @return on-chain {@link StabilityProviderState} from the borrowing program for the specific user with numbers as lamports.
* Returns undefined if this user has never used Hubble Stability pool before and does not exist in Hubble on-chain data
*/
getUserStabilityProviderState(user: PublicKey | string): Promise<StabilityProviderState | undefined>;
/**
* Get all Hubble stability providers (stability pool stats).
* @return list of on-chain {@link StabilityProviderState} from the borrowing program
*/
getStabilityProviders(): Promise<StabilityProviderState[]>;
/**
* Get all non-zero Hubble user staking states.
* @return list of on-chain {@link UserStakingState} from the borrowing program
*/
getUserStakingStates(): Promise<UserStakingState[]>;
/**
* Get all Hubble stability providers (stability pool stats) and include raw JSON RPC responses in the return value.
* @return list of on-chain {@link StabilityProviderStateWithJson} from the borrowing program
*/
getStabilityProvidersIncludeJsonResponse(): Promise<StabilityProviderStateWithJson[]>;
/**
* Convert user metadata BN fields to Decimal
* @param user
* @private
*/
private static userMetadataToDecimals;
/**
* Get all of user's metadatas (borrowing state, debt, collateral stats...), user can have multiple borrowing accounts.
* @param user Base58 encoded Public Key of the user
* @return on-chain {@link UserMetadata} from the borrowing program for the specific user with numbers as lamports
*/
getUserMetadatas(user: PublicKey | string): Promise<UserMetadata[]>;
/**
* Get specific user metadata (borrowing state, debt, collateral stats...).
* @param metadata Base58 encoded Public Key of the user metadata
* @return on-chain {@link UserMetadata} from the borrowing program for the specific user with numbers as lamports
*/
getUserMetadata(metadata: PublicKey | string): Promise<UserMetadata>;
/**
* Get all Hubble user metadatas (borrowing state, debt, collateral stats...), one user can have multiple borrowing accounts.
* @return list of on-chain {@link UserMetadata} from the borrowing program for the specific user with numbers as lamports
*/
getAllUserMetadatas(): Promise<UserMetadata[]>;
/**
* Get all Hubble user metadatas (borrowing state, debt, collateral stats...) and include raw JSON RPC responses in the return value.
* @return list of on-chain {@link UserMetadata} from the borrowing program for the specific user with numbers as lamports
*/
getAllUserMetadatasIncludeJsonResponse(): Promise<UserMetadataWithJson[]>;
/**
* Get user's loans. Fetches all {@link UserMetadata} of the specified user and converts it to a human-friendly list of {@link Loan}.
* @param user Base58 encoded Public Key of the user
* @return User's loans with already converted on-chain data (from lamports to decimal values)
*/
getUserLoans(user: PublicKey | string): Promise<Loan[]>;
/**
* Get user's deposited stablecoin (USDH) in the stability pool.
* @param user Base58 encoded Public Key of the user
* @return Deposited stablecoin (USDH) in decimal format or
* undefined if user has never used Hubble before or authorized stability pool deposits
*/
getUserUsdhInStabilityPool(user: PublicKey | string): Promise<Decimal | undefined>;
/**
* Get user's USDH vault (usdh staked + liquidation rewards + hbb rewards)
* @param user Base58 encoded Public Key of the user
* @return USDH vault with amount of USDH staked, liquidation rewards and HBB rewards or
* undefined if user has never used Hubble before or authorized stability pool deposits
*/
getUserUsdhVault(user: PublicKey | string): Promise<UsdhVault | undefined>;
/**
* Get a list of epoch to scale to sum values for Hubble
* @return Array of epoch to scale to sum in decimal format
*/
getEpochToScaleToSum(): Promise<Decimal[]>;
/**
* Get the amount of staked HBB of a specific user.
* @param user Base58 encoded Public Key of the user
* @return HBB staked in decimal format or
* undefined if user has never used Hubble before or authorized HBB staking
*/
getUserStakedHbb(user: PublicKey | string): Promise<Decimal | undefined>;
/**
* Get the user's HBB vault (HBB staked + USDH rewards)
* @param user Base58 encoded Public Key of the user
* @return HBB vault with number of HBB staked and USDH rewards or
* undefined if user has never used Hubble before or authorized HBB staking
*/
getUserHbbVault(user: PublicKey | string): Promise<HbbVault | undefined>;
/**
* Get Hubble's treasury vault value
* @return Value of Hubble's treasury vault in decimal representation
*/
getTreasuryVault(): Promise<Decimal>;
/**
* Get circulating supply number of the Hubble (HBB) token.
* This also takes into account the locked HBB inside Streamflow vesting contracts and subtracts the locked HBB amount.
* @return Number of HBB in circulation in decimal representation
*/
getHbbCirculatingSupply(): Promise<Decimal>;
getUsdhCirculatingSupply(): Promise<Decimal>;
/**
* Get all token accounts that are holding HBB
*/
getHbbTokenAccounts(): Promise<{
pubkey: PublicKey;
account: import("@solana/web3.js").AccountInfo<Buffer | import("@solana/web3.js").ParsedAccountData>;
}[]>;
/**
* Get Hubble's global config values
*/
getGlobalConfig(): Promise<GlobalConfig>;
/**
* Get PSM reserve state
*/
getPsmReserve(): Promise<PsmReserve>;
/**
* Get PSM public key
*/
getPsmPublicKey(): Promise<PublicKey>;
/**
* Get the USDC -> USDH swap information
* @param usdcInAmount number of USDC tokens
* @param slippage
*/
getUsdcToUsdhSwap(usdcInAmount: Decimal, slippage?: Decimal): Promise<SwapInfo>;
/**
* Get the USDH -> USDC swap information
* @param usdhInAmount number of USDH tokens
* @param slippage
*/
getUsdhToUsdcSwap(usdhInAmount: Decimal, slippage?: Decimal): Promise<SwapInfo>;
/**
* Get the instruction to store the on chain owner signature of terms&conditions
* @param owner
* @param signature
*/
getUserTermsSignatureIx(owner: PublicKey, signature: Uint8Array): Promise<TransactionInstruction>;
/**
* Get the on-chain state of the terms&conditions signature for the owner
* @param owner
*/
getUserTermsSignatureState(owner: PublicKey): Promise<TermsSignature | null>;
/**
* Get all Scope prices used by Hubble
*/
getAllPrices(oraclePrices?: OraclePrices): Promise<HubblePrices>;
}
export default Hubble;