Hubble IDL (Interface Description Language) is a package that contains the IDLs of Hubble on-chain programs used on Solana. The IDL can be used to generate a client to speak to Hubble on-chain programs. The IDL is generated by Anchor.
npm install @hubbleprotocol/hubble-idl
Import borrowing IDL JSON to your project:
// For ESM
import { BORROWING_IDL } from "@hubbleprotocol/hubble-idl";
// For CommonJS
const config = require("@hubbleprotocol/hubble-config"); //config.BORROWING_IDL
Dependencies required:
-
@coral-xyz/anchor
, -
@solana/web3.js
, -
@hubbleprotocol/hubble-config
.
Use borrowing IDL with Anchor to get the borrowing market state (using readonly wallet):
import { Connection, Keypair, PublicKey, clusterApiUrl } from '@solana/web3.js';
import { Idl, Program, AnchorProvider } from '@coral-xyz/anchor';
import { BORROWING_IDL } from '@hubbleprotocol/hubble-idl';
import { getConfigByEnv } from '@hubbleprotocol/hubble-config';
const mainnetConfig = getConfigByEnv('mainnet-beta');
const connection = new Connection(clusterApiUrl('mainnet-beta'));
const provider = new AnchorProvider(
connection,
{
publicKey: Keypair.generate().publicKey,
signAllTransactions: async (txs) => txs,
signTransaction: async (txs) => txs,
},
{ commitment: 'confirmed' }
);
const program = new Program(BORROWING_IDL, mainnetConfig.borrowing.programId, provider);
// get borrowing market state with Anchor
const state = await program.account.borrowingMarketState.fetch(mainnetConfig.borrowing.accounts.borrowingMarketState);