hoodvault-sdk
v0.1.0
Published
TypeScript SDK for the Hoodvault protocol on Robinhood Chain — lending, co-buy vaults, synthetic baskets and one-click leverage over tokenized stocks.
Maintainers
Readme
hoodvault-sdk
TypeScript SDK for the Hoodvault protocol on Robinhood Chain (chain id 4663) — borrow USDG
against tokenized stocks, co-own baskets in vaults, take oracle-settled synthetic basket exposure
(capped $30/basket pilot), and open one-click leverage.
Thin, typed wrappers over viem. All contract addresses and the 6 synthetic baskets are baked in, so the package is self-contained.
npm install hoodvault-sdk viemviem (^2.21.0) is a peer dependency — install it alongside so your app controls the version.
Quick start
import { HoodvaultClient, fromUsdg, fromWad, healthFactorToNumber } from 'hoodvault-sdk';
// read-only (defaults to the public RPC; override with HOODVAULT_RPC_URL or { rpcUrl })
const hv = new HoodvaultClient();
const reserve = await hv.lending.reserveAvailable();
console.log('pool reserve:', fromUsdg(reserve), 'USDG');
// per-basket synthetic index + remaining cap
for (const b of hv.synthetic.baskets()) {
const [index, capLeft] = await Promise.all([
hv.synthetic.basketIndex(b.id),
hv.synthetic.capLeft(b.id),
]);
console.log(`#${b.id} ${b.name}: index=${fromWad(index)} capLeft=${fromUsdg(capLeft)} USDG`);
}Signing transactions
Pass an account — a private-key hex or a viem Account. Amounts are native USDG (6 decimals);
use hv.toUsdg('12.5') to convert.
const hv = new HoodvaultClient({ account: process.env.PRIVATE_KEY as `0x${string}` });
const me = hv.address!;
// deposit collateral → borrow USDG
await hv.approve(collateralToken, hv.addresses.LendingPool, amount);
await hv.waitForReceipt(await hv.lending.deposit(collateralToken, amount));
await hv.waitForReceipt(await hv.lending.borrow(hv.toUsdg('50')));
const acct = await hv.lending.accountData(me);
console.log('debt:', fromWad(acct.debtUSDG), 'USD');
console.log('health factor:', healthFactorToNumber(acct.healthFactor));
// repay (needs USDG approval to the pool)
await hv.approve(hv.addresses.USDG, hv.addresses.LendingPool, hv.toUsdg('50'));
await hv.lending.repay(hv.toUsdg('50'));Synthetic baskets
The protocol is the counterparty: P&L is computed from the oracle and settled in USDG (no real stock is bought — a cash-settled derivative, capped at $30 per basket, pilot).
// open a $5 position in basket #1 (AI & Semiconductors)
await hv.approve(hv.addresses.USDG, hv.addresses.SyntheticVault, hv.toUsdg('5'));
await hv.waitForReceipt(await hv.synthetic.deposit(1, hv.toUsdg('5')));
// … later, read current value and close by positionId
console.log('value now:', fromUsdg(await hv.synthetic.positionValue(positionId)), 'USDG');
await hv.synthetic.redeem(positionId);Leverage
// first time only: approve collateral to the pool and set the router as operator
await hv.lending.setOperator(hv.addresses.LeverageRouter, true);
await hv.approve(collateralToken, hv.addresses.LendingPool, amount);
// leverage into a synthetic basket (id) or a real CoBuy vault (address)
await hv.leverage.openLeverageSynthetic(collateralToken, amount, hv.toUsdg('10'), 1);
// close (only the opener can)
await hv.leverage.closeLeverageSynthetic(positionId, 2n ** 255n);Real CoBuy vaults
const vaults = await hv.vaults.list();
for (const v of vaults) {
console.log(v, fromWad(await hv.vaults.nav(v)), await hv.vaults.basketOf(v));
}
await hv.vaults.deposit(vault, hv.toUsdg('5')); // needs USDG approval to the vaultWhat's exported
HoodvaultClientwith.lending,.vaults,.synthetic,.leveragemodules.ADDRESSES,BASKETS,CHAIN_ID,robinhoodChain,USDG_DECIMALS,SYNTH_CAP.- ABIs:
lendingPoolAbi,syntheticVaultAbi,leverageRouterAbi,vaultAbi,collateralManagerAbi, … (with typed events). - Client factories:
createHoodvaultPublicClient,createHoodvaultWalletClient. - Utils:
toUsdg/fromUsdg(6 dec),toWad/fromWad(1e18),healthFactorToNumber,maxBorrowNative,projectHealthFactor,formatUsd,parseHoodvaultError.
Units
- USDG is 6 decimals. Borrow/repay/deposit amounts are native USDG.
- Debt, prices, USD values and the health factor are WAD (1e18). Liquidation happens below
1e18.
Synthetic baskets are a capped pilot and a cash-settled derivative; not investment advice, not for public use pending regulatory review.
License
MIT
