Run the whole stack locally, run the tests, deploy to HyperEVM testnet and mainnet, activate the HyperCore account and seed the vault.
The contracts are not deployed on any chain yet. The fastest way to see the full loop is the local devnet:
http://localhost:3105. The app is labelled Local devnet throughout.git clone --recurse-submodules https://github.com/kunal-drall/counterbook && cd counterbook
pnpm install
pnpm devnetThe scenario covers:
sweep() and recentering, then a second deposit sized with quoteDeposit that gets its unused HYPE back.Swap event and the SDK.poke() placing the hook's maker order, which rests on the simulated book and fills, or is cancelled on TTL.pnpm devnet --exit stops after the scenario, and --capture also writes screenshots to tools/local-devnet/.state/screenshots/. With the devnet up, pnpm devnet:scenario runs the walkthrough again.
Flags, internals and troubleshooting are in tools/local-devnet/README.md.
From the repository root:
# contracts
cd contracts && forge build && forge test # 133 tests
FOUNDRY_PROFILE=ci forge test # fuzz at 10,000 runs
forge coverage --ir-minimum --report summary --no-match-coverage "(test|script)/"
# SDK
pnpm --filter @counterbook/sdk typecheck && pnpm --filter @counterbook/sdk test
# web (app, landing and these docs)
pnpm --filter web exec tsc --noEmit && pnpm --filter web buildThe contract tests run in layers:
| Layer | What it covers |
|---|---|
| Unit tests | Fee vectors (shared with the SDK through test/vectors), unit conversions pinned to live values, tick and lot rounding, CoreWriter bytes against the documented layout and hyper-evm-lib's encoding |
| Mocks | Precompiles replaced with vm.etch: normal, reverting, empty, gas-burning, zero-value, wrong-length and oversized reads. A CoreWriter mock records actions. HyperCoreSim, an exchange simulator, applies actions and bridge credits two blocks later, rejects an ALO that would cross on arrival without a trace, holds funds for resting orders, and can lengthen the delay or drop cancels. |
| Fuzz | Fee bounds, the swap path under any read failure (I1, I2), the CoreAgent whitelist over any input (I5) |
| Invariants | A handler running deposits, redemptions, claims, swaps, arbitrage, pokes, fills, sweeps, recenters, crystallisations, market moves and attacks, with fail_on_revert; checks I1 to I7 and that claims stay backed |
| Audit regression | test/audit/AuditRegression.t.sol: each review finding's proof of concept with its assertion turned around |
| Router quoting | test/Quoter.t.sol: Uniswap's V4Quoter quotes equal the executed outputs, including with the vault skewed |
| Live reads (opt-in) | test/fork/HyperCoreLive.t.sol, skipped unless HYPERCORE_LIVE=true: fetches the real mainnet BBO, perp oracle and spot price bytes with eth_call, replays them at the precompile addresses, and checks that HyperCoreReader decodes them exactly |
Coverage, measured with forge coverage --ir-minimum: 97.27% of lines and 80.50% of branches.
Deployment never puts a private key in a file, an environment variable or a command argument. Nothing in the repository broadcasts by itself, and the contracts have not been deployed anywhere yet. The steps below follow contracts/README.md, which has the full commands.
Import the deployer into a keystore.
cast wallet import counterbook-deployer --interactiveEvery script then runs with --account counterbook-deployer --password-file <file> (or a hardware wallet).
Enable big blocks for the deployer. Each deployment transaction needs 5 to 8M gas, more than a 3M-gas small block. The deployer must be a HyperCore user (it has received a HyperCore asset such as USDC). Then run node tools/hl-actions/big-blocks.mjs --account counterbook-deployer --password-file <file> (add --mainnet for 999), which sends the HyperCore action {"type": "evmUserModify", "usingBigBlocks": true} signed through cast. --off switches back.
Read the reference price. Forge simulates without the precompiles, so read the BBO the pool will be initialized at with cast call on 0x…080e (asset 11035 on testnet, 10107 on mainnet) and pass the two words as REF_BID and REF_ASK.
Dry run, then broadcast.
cd contracts
REF_BID=... REF_ASK=... CURATOR=0x... PROTOCOL_FEE_RECIPIENT=0x... \
forge script script/Deploy.s.sol:DeployTestnet --rpc-url hyperevm_testnet \
--account counterbook-deployer --password-file <file> --sender <deployer>The script deploys VaultLib, mines a CREATE2 salt with HookMiner for exactly beforeInitialize | beforeAddLiquidity | beforeSwap | afterSwap (deployer 0x4e59b44847b379578588920cA78FbF26c0B4956C), deploys the hook there, deploys the vault (which deploys its CoreAgent), calls hook.wire(vault) and initializes the pool with fee = DYNAMIC_FEE_FLAG at the reference sqrtPriceX96. On testnet it first deploys a PoolManager and StateView. Add --broadcast (and --skip-simulation) to send it; use DeployMainnet for 999.
Record the deployment. A broadcast writes contracts/deployments/<chainId>.json and packages/sdk/src/deployments/<chainId>.json. Fill the transaction hashes and the real deploy block from the receipts with python3 -I script/record-deployment.py <chainId>. The SDK's getDeployment, the app and the addresses on these docs read that file. Until it exists they hold null and every surface shows the network as not deployed.
Activate the CoreAgent on HyperCore. Credit its HyperCore account with at least 1 USDC, with a spot send from a funded HyperCore account. Confirm coreAgent.coreAccountActive() returns true (precompile 0x810). Until it does, the hook skips rebalancing and sweep() sends no pulls.
Seed the vault. The first deposit sets the vault's composition, usually 50/50 by value at the reference price. Later deposits are proportional; size them with quoteDeposit. Call sweep() to fund the HyperCore float (this also puts HYPE on HyperCore, which pays for USDC transfers back), wait until inTransit() is false, then recenter() to place the position.
Prove a rebalance. Move the vault past the soft band, or wait for HyperCore to move it, then trigger the fast loop with a swap or poke(). Record the transaction hash, the CoreWriter RawAction log, and the matching order on HyperCore (openOrders or orderStatus by cloid for the CoreAgent address).
Switch big blocks off for the deployer if it should go back to small blocks.
A real maker order needs a vault of about 105 USDC or more: one order is at most 10% of NAV by code, and HyperCore's minimum order is 10 USDC. After seeding a mainnet vault, the curator should pause deposits with setDepositsPaused(true) until a professional audit.
HyperEVM testnet is the intended rehearsal before mainnet. Testnet HYPE could not be obtained for the hookathon, so nothing is deployed there yet.
uniswap field.@1035 (asset id 11035), perp index 135, HYPE token index 1105, USDC 0x2B3370eE501B4a559b57D449569354196457D8Ab, CoreDepositWallet 0x0B80659a4076E9E93C7DbE0f10675A16a3e5C206.DeployConfig.sol therefore sets the basis, spread and gap caps to 20% (ceilings 25%), beta to 0.05, gapTolerance to 5%, maxOrderDeviation to 15% and the reprice tolerance to 10%. With mainnet values, every swap would read DISLOCATED and every vault guard would revert.https://rpc.hyperliquid-testnet.xyz/evm. HyperCore info API: https://api.hyperliquid-testnet.xyz/info.Mainnet uses Uniswap's PoolManager at 0x12D4Fd9C5DeDd00ab8a0bCe2CF0167bbf94b6B1F and the mainnet mandate (@107, asset id 10107, perp 159, HYPE token 150). Follow the same steps with DeployMainnet and the mainnet RPC, https://rpc.hyperliquid.xyz/evm. A mainnet deployment was declined for the hookathon. Deploying and funding mainnet contracts needs the maintainers' approval.