Prerequisites: Trading on Hyperliquid for order semantics and funding the account, Strategies for the general agent model.
Overview
All Scalar Field activity on Hyperliquid — chat trades and every strategy agent — settles into one exchange account per user (your EVM wallet address). The exchange only knows the account’s net position per coin. Agent isolation is implemented on the platform side as a ledger:- Each agent has its own cash balance and its own position book with signed quantities (negative = short).
- The sum of all agents’ claims on a symbol, plus any manual residual (positions you hold outside of agents), must equal what the exchange actually holds. Reconciliation verifies this continuously.
- Agent NAV =
cash + sum(qty x mark price). Because quantities are signed, a short position contributes negative market value.
- Margin and liquidation price. The exchange computes
margin_usedandliq_priceon the net account position. Agents do not carry their own margin model — an agent’s NAV tracks entry/exit prices, fees, and funding, not free collateral. - Collateral buckets. USDC sits in perps, spot, and HIP-3 builder-dex balances on the account. Agent cash is a bookkeeping ledger over that shared collateral, not a segregated wallet.
Signed Fill Accounting
Every fill (agent order, reconciled external fill, or attributed liquidation) moves an agent’s book with sign-aware transitions:
Cash moves with the fill: buys debit
qty x price (plus fees), sells credit qty x price (minus fees). Fees always debit cash. Opening a short therefore credits cash while market value goes negative — NAV is unchanged at the moment of the fill, then tracks PnL.
Funding
Hyperliquid settles funding hourly on every open perp position, crediting or debiting the account’s USDC. Since the exchange settles at the account level, the platform mirrors each settlement onto the agents that held the position.Attribution across agents
Funding is attributed per coin, pro-rata by signed quantity, using the account’s actual funding ledger (theuserFunding events Hyperliquid records for each settlement):
per_unit = -funding_rate x close price (longs pay when the rate is positive).
Watermarks within an agent
Each agent position carries a funding watermark — the timestamp through which funding has been applied:- Hours are applied strictly after the watermark, then the watermark advances. A 2-minute settlement lag is left so an in-flight settlement is never half-counted.
- Opening a position from flat, or flipping direction, resets the watermark to now — an agent never pays funding for hours it did not hold.
- Accrual looks back at most 168 hours (7 days); older unapplied hours are dropped rather than back-charged.
funding_paid counter. Each application emits a FUNDING_ACCRUED event in strategy.activity().
When accrual runs
Accrual is lazy — nothing runs on a timer inside the agent. It triggers whenever the ledger is about to be read or changed: Trigger points: everystrategy.state(), before every fill is applied, before a liquidation is attributed (funding is settled up to the liquidation timestamp first), and on unfreeze. If no hour boundary has passed since the watermark, the call is a no-op.
Exchange Liquidation
There are two different things called “liquidation”:strategy.liquidate()— a voluntary flatten: the agent submits closing orders through the normal execution path.- Exchange (forced) liquidation — Hyperliquid force-closes part or all of the account’s net position when margin runs out. This section covers the forced case.
Detection
Forced closes happen outside any agent’s order flow, so they surface as a divergence during reconciliation: the exchange’s net quantity no longer matches the sum of agent claims. On Hyperliquid, any divergence beyond a1e-6 quantity epsilon (in either direction — forced closes can hit longs or shorts) triggers a scan of the account’s recent fills for entries carrying Hyperliquid’s liquidation marker, looking back up to 72 hours.
Attribution across agents
Each liquidation fill is split among the agents holding the liquidated direction, plus the manual residual:Application within an agent
For each attributed share, in order:- Funding is settled first, up to the liquidation timestamp, at the pre-liquidation quantity.
- The share is applied as a sign-correct close at the actual liquidation price: a liquidated long realizes
share x (liq_px - avg_px)and creditsshare x liq_pxto cash; a liquidated short realizesshare x (avg_px - liq_px)and debits the buyback cost. The agent’s proportion of the liquidation fee is deducted from cash. - The close is recorded and the agent is paused with reason
account_liquidatedso it does not keep trading against a book that just changed underneath it.
What you see
Attribution is idempotent: each exchange fill is applied to an agent at most once, so repeated reconciliations never double-count.
Parameters
HIP-3 Builder Dexs
Hyperliquid’s HIP-3 builder-deployed perp dexs (symbolsH:<dex>:<coin>, e.g. H:xyz:AAPL) hold their own USDC collateral in separate clearinghouses on the same account:
- Account values aggregate them.
venue.account(account="HYPERLIQUID")reportsaccount_value,margin_used, andportfolio_valuesummed across the main dex and every HIP-3 dex, with per-dex USDC balance rows tagged with adexkey. - Agent ledgers are symbol-keyed, so HIP-3 positions flow through the same signed-fill, funding, and liquidation-attribution paths as main-dex perps — the dex only determines which collateral bucket backs the position at the exchange.
- Moving USDC between the spot, main perps, and HIP-3 buckets is a transfer on the account (done from the portfolio page), not an agent operation.
Related
- Trading on Hyperliquid — order semantics, account structure, funding the account
- Strategies — the general agent model and
strategy.*API - Reconciliation — aggregate verification and the freeze/unfreeze flow
- Hyperliquid Data — funding rates, positions, and fills for any wallet