npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hubbleprotocol/hubble-sdk

v8.0.1

Published

Hubble Protocol client SDK

Downloads

1,149

Readme

Hubble SDK

The Hubble SDK is a TypeScript client SDK for easy access to Hubble Protocol on-chain data and operations.

Install

npm

npm install @hubbleprotocol/hubble-sdk

Usage

We use decimal.js for everything that can be bigger than Javascript's number.

Importing the Hubble SDK class:

// For ESM
import {Hubble} from "@hubbleprotocol/hubble-sdk";

// For CommonJS
const hubble = require("@hubbleprotocol/hubble-sdk");

Using the Hubble SDK class:

import {Hubble} from "@hubbleprotocol/hubble-sdk";
import { clusterApiUrl, Connection } from '@solana/web3.js';

// Initialize solana web3 connection
const cluster = 'mainnet-beta';
const connection = new Connection(clusterApiUrl(cluster));
const pubKey = 'aK2dDzV4B5kyxNrF9C5mwNP3yZJMHKeSSUe8LbuZhJY';

// Initialize Hubble SDK class
const hubble = new Hubble(cluster, connection);

// Get user's amount of staked HBB (Hubble token)
const stakedHbb = await hubble.getUserStakedHbb(pubKey);

// Get all of user's loans (debt + collateral)
const loans = await hubble.getUserLoans(pubKey);
for (const userLoan of loans) {
  // main collateral can be accessed by using property access:
  console.log('SOL', userLoan.collateral.sol);
  console.log('BTC', userLoan.collateral.btc);
  console.log('ETH', userLoan.collateral.eth);
  console.log('SRM', userLoan.collateral.srm);
  console.log('RAY', userLoan.collateral.ray);
  console.log('FTT', userLoan.collateral.ftt);
  console.log('MSOL', userLoan.collateral.msol);

  // extra collateral can be accessed by either using a helper function:
  console.log('STSOL', findInExtraCollateralByName('STSOL', userLoan.collateral.extraCollaterals));
  console.log('LDO', findInExtraCollateralByName('LDO', userLoan.collateral.extraCollaterals));
  // or using the map manually:
  const stsolId = ExtraCollateralMap.find((x) => x.name === 'STSOL').id;
  const ldoId = ExtraCollateralMap.find((x) => x.name === 'LDO').id;
  const stsol = userLoan.collateral.extraCollaterals.find((x) => x.tokenId.eq(stsolId));
  const ldo = userLoan.collateral.extraCollaterals.find((x) => x.tokenId.eq(ldoId));
}

// Get the amount of stablecoin (USDH) user has deposited in the stability pool
const usdh = await hubble.getUserUsdhInStabilityPool(pubKey);

// Get Hubble's treasury vault value
const treasuryVault = await hubble.getTreasuryVault();

// Get circulating supply of HBB token
const circulatingSupply = await hubble.getHbbCirculatingSupply();

// Get various on-chain data from the Hubble borrowing program
// This is the raw data that has not been converted yet (everything is in the lamports format)
const stakingPoolState = await hubble.getStakingPoolState();
const stabilityPoolState = await hubble.getStabilityPoolState();
const marketStates = await hubble.getBorrowingMarketStates();
const marketState = await hubble.getBorrowingMarketStateByPubkey(new PublicKey('FqkHHpETrpfgcA5SeH7PKKFDLGWM4tM7ZV31HfutTXNV'));
const allUserMetadatas = await hubble.getAllUserMetadatas(); //user metadatas = user's loans
const hbbTokenAccounts = await hubble.getHbbTokenAccounts();

// Get various user-specific on-chain data 
// This is the raw data that has not been converted yet (everything is in the lamports format)
const userStakingState = await hubble.getUserStakingState(pubKey);
const userStabilityProviderState = await hubble.getUserStabilityProviderState(pubKey);
const userMetadatas = await hubble.getUserMetadatas(pubKey); //user metadatas = user's loans

// Get peg stability module (PSM) reserve and swaps
const swapUsdhToUsdc = await hubble.getUsdhToUsdcSwap(new Decimal(1000));
const swapUsdcToUsdh = await hubble.getUsdcToUsdhSwap(new Decimal(500));
const psmReserve = await hubble.getPsmReserve();
const psmPubkey = await hubble.getPsmPublicKey();