8.0.1 • Published 8 months ago

@hubbleprotocol/hubble-sdk v8.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

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();
8.0.1

8 months ago

5.0.20

1 year ago

5.0.13

1 year ago

5.0.16

1 year ago

6.0.0

11 months ago

7.0.0

10 months ago

8.0.0

10 months ago

5.0.12

1 year ago

5.0.4

1 year ago

5.0.0

1 year ago

4.0.0

1 year ago

3.0.29

1 year ago

3.0.20

2 years ago

3.0.17

2 years ago

2.2.57

2 years ago

2.2.55

2 years ago

2.2.53

2 years ago

2.2.54

2 years ago

2.2.51

2 years ago

2.2.52

2 years ago

2.2.50

2 years ago

3.0.10

2 years ago

2.1.9

2 years ago

2.2.17

2 years ago

2.2.0

2 years ago

2.2.7

2 years ago

3.0.4

2 years ago

3.0.1

2 years ago

3.0.6

2 years ago

3.0.0

2 years ago

2.1.8

2 years ago

2.1.0

2 years ago

2.2.48

2 years ago

2.2.40

2 years ago

2.0.0

2 years ago

1.0.283

2 years ago

1.0.279

2 years ago

1.0.294

2 years ago

2.0.11

2 years ago

2.0.24

2 years ago

1.0.263

2 years ago

1.0.268

2 years ago

1.0.269

2 years ago

1.0.254

2 years ago

1.0.257

2 years ago

1.0.256

2 years ago

1.0.275

2 years ago

1.0.276

2 years ago

1.0.271

2 years ago

1.0.270

2 years ago

1.0.273

2 years ago

1.0.272

2 years ago

1.0.253

2 years ago

1.0.200

2 years ago

1.0.204

2 years ago

1.0.222

2 years ago

1.0.221

2 years ago

1.0.227

2 years ago

1.0.229

2 years ago

1.0.223

2 years ago

1.0.226

2 years ago

1.0.225

2 years ago

1.0.217

2 years ago

1.0.216

2 years ago

1.0.215

2 years ago

1.0.209

2 years ago

1.0.244

2 years ago

1.0.240

2 years ago

1.0.246

2 years ago

1.0.245

2 years ago

1.0.248

2 years ago

1.0.194

2 years ago

1.0.196

2 years ago

1.0.195

2 years ago

1.0.239

2 years ago

1.0.235

2 years ago

1.0.236

2 years ago

1.0.164

3 years ago

1.0.167

2 years ago

1.0.166

2 years ago

1.0.161

3 years ago

1.0.163

3 years ago

1.0.162

3 years ago

1.0.168

2 years ago

1.0.154

3 years ago

1.0.156

3 years ago

1.0.155

3 years ago

1.0.158

3 years ago

1.0.157

3 years ago

1.0.159

3 years ago

1.0.189

2 years ago

1.0.188

2 years ago

1.0.184

2 years ago

1.0.181

2 years ago

1.0.176

2 years ago

1.0.178

2 years ago

1.0.177

2 years ago

1.0.171

2 years ago

1.0.174

2 years ago

1.0.173

2 years ago

1.0.179

2 years ago

1.0.170

2 years ago

1.0.193

2 years ago

1.0.190

2 years ago

1.0.192

2 years ago

1.0.143

3 years ago

1.0.142

3 years ago

1.0.145

3 years ago

1.0.144

3 years ago

1.0.141

3 years ago

1.0.147

3 years ago

1.0.146

3 years ago

1.0.132

3 years ago

1.0.134

3 years ago

1.0.133

3 years ago

1.0.136

3 years ago

1.0.135

3 years ago

1.0.128

3 years ago

1.0.127

3 years ago

1.0.106

3 years ago

1.0.103

3 years ago

1.0.105

3 years ago

1.0.121

3 years ago

1.0.120

3 years ago

1.0.122

3 years ago

1.0.88

3 years ago

1.0.87

3 years ago

1.0.86

3 years ago

1.0.85

3 years ago

1.0.89

3 years ago

1.0.110

3 years ago

1.0.112

3 years ago

1.0.111

3 years ago

1.0.118

3 years ago

1.0.117

3 years ago

1.0.119

3 years ago

1.0.114

3 years ago

1.0.113

3 years ago

1.0.116

3 years ago

1.0.115

3 years ago

1.0.91

3 years ago

1.0.90

3 years ago

1.0.98

3 years ago

1.0.62

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.63

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.77

3 years ago

1.0.76

3 years ago

1.0.75

3 years ago

1.0.74

3 years ago

1.0.79

3 years ago

1.0.84

3 years ago

1.0.83

3 years ago

1.0.81

3 years ago

1.0.55

3 years ago

1.0.54

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.48

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.52

3 years ago

1.0.29

3 years ago

1.0.39

3 years ago

1.0.28

3 years ago

1.0.38

3 years ago

1.0.40

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.42

3 years ago

1.0.31

3 years ago

1.0.41

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago