Cost-Aware Funding-Regime Switching for a Fee-Exempt Delta-Neutral Perpetual Vault
maas is a spot and perp trading venue on Base Sepolia with a delta-neutral USDC vault. The vault holds each coin (BTC, ETH, HYPE) against an equal perp short, so price moves cancel and it earns the funding that longs pay shorts. The stack: Solidity contracts (Foundry, OpenZeppelin UUPS), a Rust order-book engine, Go services (gateway, settler, keeper, vault-keeper, recorder) on NATS and Postgres, a Next.js client, Pyth prices, Uniswap v4 for spot, Chainlink CRE for decisions and Arkiv for the public record.
Why existing venues don't work for this. A delta-neutral vault rebalances all the time: every deposit, withdrawal and mode change means buying or selling spot. On a normal DEX or CEX each of those trades pays a swap fee and slippage, and over hundreds of rebalances that cost eats the funding yield the vault exists to earn. The yield is only sustainable if the hedging leg costs close to nothing.
Negative funding. When funding turns negative, the short pays instead of earning, and a vault that stays hedged slowly bleeds money. Our Chainlink CRE workflow checks every hour, one minute after each funding print. It reads the vault's on-chain mode and the last 3 hourly rates per market, and moves a market to FLAT (all USDC) only when all 3 were negative. One bad hour doesn't trigger a costly unwind. A single positive print turns hedging back on. The vault accepts mode changes only through signed reports from the Chainlink forwarder, adds a 5-minute cooldown per market, and a keeper then unwinds in a safe order: close the short, then sell the coin, so the vault never holds a naked short.
Zero-fee hedging on Uniswap v4. We run our own v4 pools with a custom hook, MaasHook. beforeSwap returns a dynamic fee priced from Pyth: other traders pay 3 bps, plus more when their swap pushes the pool away from the oracle price, capped at 1%. The vault pays 0. The vault doesn't go through a router; it swaps directly through PoolManager.unlock and rejects any trade worse than the Pyth price minus a slippage limit. So rebalancing costs no fee and the hedge stays fully on-chain.
Fixing the LP side. A zero-fee vault needs deep pools, so LPs have to be paid. Every swap fee goes into a per-pool stream inside the hook, paid to full-range LPs per second over the next hour. Each hour a second CRE trigger builds an LP reward pot: half of the vault's 0.1% withdraw fees plus 10% of the funding it earned, capped by how much the vault traded in each pool. It sends a signed report, the vault re-checks the cap on-chain, and pays the pot into the hook through the same stream. Arkiv records every funding print, every CRE decision (with references to the exact prints behind it), hourly NAV and share-price snapshots, and every LP payout with its tx hash. The production CRE workflow reads its funding inputs from Arkiv, so the decision and its evidence share one public record.
JIT attacks. This setup is an ideal target for JIT liquidity: large, predictable vault rebalances plus an hourly reward drop at a known time. A JIT attacker would add a big, narrow position just before, take the fee or reward, and leave right after. The hook stops this in four ways. Fees and rewards are streamed over an hour, so liquidity held for one block earns one block of the stream. Only full-range positions are allowed, so liquidity can't be concentrated around the price. Every add or remove settles rewards first, so new liquidity can't claim rewards earned before it arrived. And the vault's swaps pay 0 fee, so the biggest trades have nothing to capture. The CRE reward pot is capped by real vault volume, so it can't be inflated, and Arkiv's LPEpoch records let anyone check payouts against the hook's on-chain Reward events.
maas is a spot and perp trading venue on Base Sepolia, with a delta-neutral USDC vault that earns perp funding while staying hedged against price moves.
Contracts are written in Solidity with Foundry. PerpExchange holds margin, settles trades, charges funding and runs liquidations. DeltaNeutralVault is an upgradeable ERC-4626 vault that holds coin against an equal perp short. MaasHook is our Uniswap v4 hook. Pyth is the price source for all of them: a Go keeper pushes Hermes updates on-chain and posts hourly funding rates.
Perps use a hybrid model. Traders sign orders off-chain (EIP-712) and send them to a Go gateway. A Rust matching engine runs the order book over NATS. A Go settler posts each matched fill to PerpExchange with a fresh Pyth update, and the contract re-checks every signature, margin requirement and price band itself. That keeps matching fast while custody stays fully on-chain. An indexer writes chain events to Postgres for the gateway's REST and WebSocket API, and a market-maker bot keeps the books liquid.
Spot has no matching engine at all. It runs entirely on our own Uniswap v4 pools. MaasHook sets an oracle-aware fee, lets the vault swap at 0 fee, and streams every fee to full-range LPs per second over an hour.
The vault is split into a decision side and an execution side. A Chainlink CRE workflow written in Go decides each market's mode (HEDGED or FLAT) from funding rates, plus an hourly LP payout. It reaches the vault through signed reports that only the Chainlink forwarder can deliver. A Go vault-keeper then carries out the trades: it buys or sells coin on v4 and opens or closes the short, always in an order that never leaves a naked short.
A Go recorder writes funding rates, decisions, hourly NAV snapshots and LP payouts to Arkiv. The Next.js client reads the vault's history straight from Arkiv instead of our server.
Partner benefits: Uniswap v4 gave us a hedge leg with no fee and a way to pay LPs. CRE gave us decentralized, verifiable decisions that the vault can enforce. Arkiv gave us a public audit trail anyone can query without a key.
Infrastructure is one AWS t3.small running docker compose, provisioned with Terraform and Ansible behind Caddy. The client deploys on Vercel.
Hacky bits: we deployed our own v4 PoolManager on Base Sepolia and mined the hook address for its permission bits. The hook trusts the test liquidity router to name the LP in hookData, pinned to tx.origin. The exact-output swap fee is carried from beforeSwap to afterSwap through transient storage. The recorder backfills missed hourly snapshots using historic eth_call. And we run CRE through its simulator with broadcast, using Chainlink's mock forwarder, against the live vault.

