Skip to main content

Backend and API

The smart contract is administered by a Cardinal-operated backend.

Worker

Worker runs every 12 seconds.

Steps:

  1. Calculate carry_t from Aave V3 on-chain and sUSDe or wstETH native yield.
  2. Call settleTick(carry_t, now, all_active_position_ids), batched if needed.
  3. Sync updated position state back to Postgres.
  4. Deploy spare capital into Aave V3 borrow loops via deployToAave.
  5. Read LP-Book Pool health.
  6. Trigger auto-deleverage if health factor falls below threshold or pool NAV drops more than 10% peak-to-trough.
  7. Update free_NAV and committed capacity in Postgres after each tick.

The same 12-second worker also calls settleNRH if 1 hour has elapsed since lastNRHSettlement.

settleNRH receives gross carry, not a spot read.

API

The Carry Perp endpoints:

GET /positions/:user
GET /market
GET /pool

GET /positions/:user reads from Postgres.

GET /market returns current carry, pool NAV, and remaining capacity.

GET /pool is LP-facing and returns NAV, free_NAV, withdrawal queue status, and LP-Book Pool health.

The Perpetual Negative Rate Hedge endpoints:

GET /policies/:user
GET /policy/:id/projection

Frontend

Frontend should include the ability to call state-writing methods:

  • open and close positions in The Carry Perp
  • LP deposit and withdrawal
  • open, close, top up, and adjust The Perpetual Negative Rate Hedge positions