How it works
ZAMM uses liquidity deposited by stakers to place limit orders on the orderbook corresponding to the well-known x * y = k formula, and rebalances its orders every time it is hit.
Providing liquidity to the ZAMM is slightly different from typical spot AMMs. When staking, LPs deposit both base and quote tokens (for SOL-PERP, that would be SOL and USDC), but when they withdraw, they will receive a combination of SOL/USDC/SOL-PERP [see details below].This way ZAMM is able to ensure that it is properly collateralized at all times.
Here is the more detailed breakdown of what happens inside a ZAMM:

1. LP deposits base and quote into ZAMM

LP deposits funds into the ZAMM and these funds are now part of ZAMM’s margin account.

2. LP calls ZAMM’s crank and rebalances the orders

After the deposit, the LP calls the rebalance instruction. On rebalance, ZAMM cancels all of its orders and places new ones. Now that ZAMM has more funds, it can place orders with larger sizes.

3. Traders trade on the open market

When traders trade on the exchange, they now have access to both active market maker liquidity and passive ZAMM liquidity.

4. ZAMM rebalances continuously

Every time someone trades against the ZAMM, or when a new LP joins, the xy=k formula shifts. This leads to ZAMM rebalancing its existing order sizes, and levels.

5. LP withdraws

In a typical AMM, the staker would have initially deposited X amount of SOL and Y amount of USDC; after some time, he would have been able to withdraw X’ amount of SOL and Y’ amount of USDC. Because ZAMM is not trading on top of SOL-USDC orderbook, but rather on SOL-PERP orderbook, ZAMM’s SOL balance always remains the same. Consequently, there is a chance that if ZAMM lets users withdraw SOL, it will eventually run out of SOL to hand out.
To avoid such a bank run, ZAMM also passes on a position to the staker. This means that on withdrawal, users receive, Y’ amount of USDC, X amount of SOL and X’ — X amount of SOL-PERP(note that if X’-X is negative it means that user will receive a short position).