Docs

Stock pools

Provide liquidity

Deposit stock and USDG into a BookVault, follow the daily UTC roll, then withdraw in kind and claim, with viem and cast examples.

Markdown
On this page

This guide takes you through one full cycle in a BookVault, the LP book behind each stock/USDG pool: deposit, the daily roll, shares, withdrawal and claim.

Prerequisites

  • A wallet on Robinhood Chain (4663) with ETH for gas, USDG, and the stock token of the pool (or USDG only, for a zap).
  • The pool's book address. There is one BookVault proxy per pool. Addresses publish at launch on Network; the examples use BOOK.

Read the book and its terms#

Each book reports its stock, USDG and the ProtocolConfig it reads. Fees come from one BookTerms record that applies to every book. No fee values are hard-coded; the council sets them within these caps:

TermCapMeaning
mgmtFeeBps300Per year, on the value of outside shares
perfFeeBps5,000On gain above the book's high-water mark
withdrawFeeBps100Kept by the book for holders who stay
nftBps2,000Share of every fee paid to the Stingvestors pot
settleDelay1 minute to 12 hoursWait after 00:00 UTC before the roll

Raising a fee, or any change to nftBps, settleDelay, feeRecipient, nftPot or keeper, waits the 2-day timelock. Cuts to the other fees apply at once.

import { createPublicClient, createWalletClient, defineChain, http, parseAbi } from "viem";
import { privateKeyToAccount } from "viem/accounts";

export const robinhood = defineChain({
  id: 4663,
  name: "Robinhood Chain",
  nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
  rpcUrls: { default: { http: ["https://rpc.mainnet.chain.robinhood.com"] } },
});

export const BOOK = "0x..."; // addresses publish at launch
export const account = privateKeyToAccount(process.env.PK as `0x${string}`);
export const pub = createPublicClient({ chain: robinhood, transport: http() });
export const wallet = createWalletClient({ account, chain: robinhood, transport: http() });

export const bookAbi = parseAbi([
  "function stock() view returns (address)",
  "function usdg() view returns (address)",
  "function config() view returns (address)",
  "function value() view returns (uint256)",
  "function quote(uint256 stockAmount, uint256 usdgAmount) view returns (uint256)",
  "function requestDeposit(uint256 stockAmount, uint256 usdgAmount)",
  "function zapFloor(uint256 usdgIn) view returns (uint256)",
  "function zapDeposit(uint256 usdgIn, uint256 minStockOut) returns (uint256 stockIn, uint256 usdgQueued)",
  "function cancelDeposit() returns (uint256 stockAmount, uint256 usdgAmount)",
  "function roll()",
  "function realize(address account)",
  "function accountOf(address account) view returns ((uint256 shares, uint256 locked, uint256 assetPending, uint256 depositPending, uint256 assetOwed, uint256 owed))",
  "function balanceOf(address account) view returns (uint256)",
  "function requestWithdraw(uint256 shares)",
  "function cancelWithdraw() returns (uint256 shares)",
  "function claim() returns (uint256 stockPaid, uint256 usdgPaid)",
]);
export const erc20 = parseAbi([
  "function approve(address spender, uint256 amount) returns (bool)",
  "function decimals() view returns (uint8)",
]);
const configAbi = parseAbi([
  "function bookTerms() view returns ((uint16 mgmtFeeBps, uint16 perfFeeBps, uint16 withdrawFeeBps, uint16 nftBps, uint16 maxSlippageBps, uint32 settleDelay, address feeRecipient, address nftPot, address keeper))",
]);

const config = await pub.readContract({ address: BOOK, abi: bookAbi, functionName: "config" });
export const terms = await pub.readContract({ address: config, abi: configAbi, functionName: "bookTerms" });

Queue a deposit in kind#

Approve the book for both tokens, then call requestDeposit(stockAmount, usdgAmount). The book pulls the tokens now and queues them for the next roll. Several requests on one UTC day merge into one. Use quote(stockAmount, usdgAmount) to see the value the roll will credit: stock at the lower of TWAP and spot, plus USDG at par.

Reverts with DomainError while the ENTRY domain is paused, and with ZeroAmount if both amounts are zero.

import { parseUnits } from "viem";
import { BOOK, account, bookAbi, erc20, pub, wallet } from "./setup";

const [stock, usdg] = await Promise.all([
  pub.readContract({ address: BOOK, abi: bookAbi, functionName: "stock" }),
  pub.readContract({ address: BOOK, abi: bookAbi, functionName: "usdg" }),
]);
const stockDec = await pub.readContract({ address: stock, abi: erc20, functionName: "decimals" });
const stockAmount = parseUnits("2", stockDec);
const usdgAmount = parseUnits("500", 6);

await wallet.writeContract({ address: stock, abi: erc20, functionName: "approve", args: [BOOK, stockAmount] });
await wallet.writeContract({ address: usdg, abi: erc20, functionName: "approve", args: [BOOK, usdgAmount] });
const hash = await wallet.writeContract({
  address: BOOK, abi: bookAbi, functionName: "requestDeposit", args: [stockAmount, usdgAmount],
});
await pub.waitForTransactionReceipt({ hash });

Or zap in from USDG only#

zapDeposit(usdgIn, minStockOut) buys the stock share of your USDG through MakerHook.swap in the same transaction, at the pool's current mix, then queues the stock and the leftover USDG. The swap pays the pool's normal fee, including the closed-hours floor. Read zapFloor(usdgIn) for a fair minStockOut: it prices the stock at the higher of spot and TWAP, less maxSlippageBps.

zapFloor reverts with BookOffTwap when spot sits more than maxSlippageBps ticks from TWAP; wait for the pool to settle. The zap reverts with Slippage if the swap buys less than minStockOut, and with DomainError while paused.

const usdgIn = parseUnits("1000", 6);
const minStockOut = await pub.readContract({ address: BOOK, abi: bookAbi, functionName: "zapFloor", args: [usdgIn] });

await wallet.writeContract({ address: usdg, abi: erc20, functionName: "approve", args: [BOOK, usdgIn] });
await wallet.writeContract({ address: BOOK, abi: bookAbi, functionName: "zapDeposit", args: [usdgIn, minStockOut] });

Cancel the same day if you change your mind#

The cutoff is 00:00 UTC. Until then, cancelDeposit() returns today's whole request in kind. After midnight the request belongs to the next roll and cannot be cancelled. Reverts with NothingQueued if you have no request for today.

await wallet.writeContract({ address: BOOK, abi: bookAbi, functionName: "cancelDeposit" });

Roll the day#

roll() runs once per UTC day, from settleDelay after 00:00 UTC. For the first hour only BookTerms.keeper may call it; after that anyone can. It settles every day up to yesterday in one call. Reverts with RollNotDue before the window opens or once the day is rolled.

Fig. 1A UTC day in a BookVault
Who may roll00:00 UTC + settleDelay:the keeper for one hour,then anyoneUTC DAY DrequestDepositstock + USDG in kind,or zapDeposit with USDGrequestWithdrawcancel the same day onlyroll(), once per UTC dayGain over holdingvs holding; lower of TWAP and spot1Take feesmgmt, and perf above the alpha HWM2Harvest to USDGidle USDG first, then a pool slice3Pay feesnftBps to the pot, the rest onward4Price and settleshares, deposits, in-kind exits5Stingvestors VestorPotnftBps of the feesFee recipientthe rest, to the outbox SafeClaimrealize shares; claim() paysUSDG and stockUTC day DrequestDepositin kind, orzapDeposit with USDGrequestWithdrawshares; cancelthe same day onlyAfter settleDelay: the keeper first, then anyoneroll()Gain over holdingvs holding; lower of TWAP and spot1Take feesmgmt, and perf above the alpha HWM2Harvest to USDGidle USDG first, then a pool slice3Pay feesnftBps to the pot, the rest onward4Price and settleshares, deposits, in-kind exits5Fees go toStingvestors potnftBps of the feesFee recipientthe rest, outbox SafeThen claimClaimrealize shares; claim() pays USDG and stock
A Robinhood book takes deposits in kind, rolls once a day after settleDelay, pays its fees in USDG and settles deposits and withdrawals in kind.

The roll runs in this order:

  1. It pokes the hook, which collects pool fees into idle and checks the breaker.
  2. It measures gain over holding: the book's holdings now against what it held after the last roll, valued at both TWAP and spot, taking the lower.
  3. It charges the management fee on outside shares for the days elapsed, and the performance fee on the part of the gain that lifts the book above its high-water mark. Losing days pay no performance fee.
  4. It turns the fees into USDG: idle USDG first, then a pool slice sold through the hook with a TWAP-based floor. If the sale fails, the rest stays due for the next roll.
  5. It pays nftBps of the fees to BookTerms.nftPot, the Stingvestors VestorPot, and the rest to BookTerms.feeRecipient, the council's outbox Safe. That Safe bridges the USDG to Hyperliquid and calls HyperRevenueRouter.notifyRevenue. A refused payment is deferred and retried each roll.
  6. It prices shares, executes the queued deposits and then the withdrawals, and redeploys idle tokens.

Deposits are valued with stock at the lower of TWAP and spot. If they exceed the book's deposit cap, every outside request is cut pro rata and the rest is refunded in kind to your owed balance. A pool that refuses the add, for example while paused, refunds the same way.

await wallet.writeContract({ address: BOOK, abi: bookAbi, functionName: "roll" });

Realize your shares#

Shares minted at the roll sit in the book's own entry until they are realized. Your next request, transfer or claim realizes them, or anyone can call realize(account). accountOf(account).shares counts them before and after. Book shares are a normal ERC-20 once realized.

await wallet.writeContract({ address: BOOK, abi: bookAbi, functionName: "realize", args: [account.address] });
const acct = await pub.readContract({ address: BOOK, abi: bookAbi, functionName: "accountOf", args: [account.address] });
console.log(acct.shares, acct.assetOwed, acct.owed);

Request a withdrawal#

requestWithdraw(shares) locks free shares in the book for the next roll. It is never paused. cancelWithdraw() returns today's request before 00:00 UTC. At the roll you receive a pro-rata slice of the pool, the book's held stock and its idle USDG, in kind. withdrawFeeBps stays in the book for the holders who remain; it is waived when every share leaves.

Reverts with SharesShort if you ask for more than your free shares, and with ZeroAmount for zero.

const shares = await pub.readContract({ address: BOOK, abi: bookAbi, functionName: "balanceOf", args: [account.address] });
await wallet.writeContract({ address: BOOK, abi: bookAbi, functionName: "requestWithdraw", args: [shares] });

Claim your tokens#

After the roll, claim() pays your owed stock and USDG. USDG must transfer or the call reverts. If the stock token refuses the transfer, the stock stays owed and you can claim it later. Refunded deposits are claimed the same way.

const { result } = await pub.simulateContract({ account, address: BOOK, abi: bookAbi, functionName: "claim" });
console.log("stock", result[0], "usdg", result[1]);
await wallet.writeContract({ address: BOOK, abi: bookAbi, functionName: "claim" });

Where to go next#

These docs describe the architecture and smart contracts across Hyperliquid L1 (HyperEVM) (chain id 999) and Robinhood Chain (chain id 4663). Nothing here is investment advice or a promise of returns. DegenHive is not affiliated with, endorsed by, or sponsored by Hyperliquid, Robinhood Markets, Inc., Nasdaq, Inc., or their affiliates.