@hobba-io/core
v0.1.3
Published
Hobba SDK — shared on-chain logic (deposit/borrow flows, position reads, PDAs, constants, account resolvers) for the Hobba app, the embeddable widget and partner integrations.
Readme
@hobba-io/core
Hobba SDK — the shared on-chain logic behind app.hobba.io: deposit/borrow flows, position reads, projection math, PDAs, constants and account resolvers for the Hobba program on Solana. Consumed by the Hobba app, the embeddable widget and partner integrations.
Install
npm install @hobba-io/core @coral-xyz/anchor @solana/web3.js @solana/spl-token bn.jsThe Solana stack is declared as peer dependencies so your bundle holds exactly one copy of
@solana/web3.js / bn.js (two copies break instanceof PublicKey checks).
@kamino-finance/klend-sdk is an optional peer — only needed if you use the server-side
@hobba-io/core/rates subpath.
Bundler required. This package ships ESM with extensionless relative imports and is targeted at bundler consumers (Next.js/webpack, esbuild/tsup, Vite). It is not consumable from bare Node ESM without a bundler or a loader such as
tsx.
Quick start
import {
executeDepositBorrow,
executeAction,
getPosition,
getPositionMetrics,
getQuote,
getLimits,
parseCollateral,
parseUsdc,
CBBTC_MINT,
SOL_MINT,
} from "@hobba-io/core";
// One-call onboarding: routes the lender, initializes first-time users
// (origin id recorded on-chain), wraps SOL, resolves accounts/LUTs, sends
// and confirms with tick-error recovery.
const { depositSig, borrowSig, lender } = await executeDepositBorrow({
connection, // your web3.js Connection
signer, // { publicKey, signTransaction }
collateralMint: CBBTC_MINT, // or SOL_MINT
depositAmount: parseCollateral("0.01", CBBTC_MINT),
borrowAmount: parseUsdc("250"),
apiBaseUrl: "https://app.hobba.io", // Hobba backend serving /api/juplend-operate, /api/lut, ...
onStep: (s) => console.log(s),
});Follow-up actions on existing positions use executeAction({ action: "deposit" | "borrow" |
"repay" | "withdraw", amount, ... }); reads use getPosition / getPositionMetrics /
getQuote / getLimits with the same { connection, owner, collateralMint, apiBaseUrl } shape.
Pure-math variants (computePositionMetrics, computeQuote) accept pre-fetched inputs for
synchronous per-keystroke UI math.
Cluster selection
The program id baked into PROGRAM_ID is selected at build time from environment variables
your bundler must define/inline:
| Env | Program |
| --- | --- |
| NEXT_PUBLIC_MAINNET=true | mainnet Hobbakk1LmW2DhE4nAKnCeU1iK7V7pKHTq3ihaE2i8qG |
| NEXT_PUBLIC_STAGING=true | staging |
| (neither) | local/surfpool development id |
Next.js inlines NEXT_PUBLIC_* automatically; other bundlers should define
process.env.NEXT_PUBLIC_MAINNET accordingly.
Subpath exports
The root barrel carries the high-level flows and browser-safe helpers. Additional modules are
importable by subpath (all covered by the ./* export):
@hobba-io/core/constants,/pdas,/amountUtils,/marketConfig,/userState,/limits@hobba-io/core/idl(authoritative Anchor IDL asHOBBA_IDL)@hobba-io/core/vault/vaultAccounts,/kamino/obligationParser@hobba-io/core/juplend/tickMath,/juplend/tickUtils,/juplend/vaultConfigParser@hobba-io/core/oracle/scopePrice— server-leaning@hobba-io/core/rates— server-only (lazily requires the optional@kamino-finance/klend-sdkpeer for reserve decoding); keep it out of browser bundles
License
ISC
