Your Pod Is an Exchange

Automated market making with constant-product
April 2026 · melvin.me · Part 9 of Solid Articles

1. The Problem with Order Books

In Part 8, Alice and Bob traded manually — sell orders, waiting for someone to fill them. That works, but it's slow. What if nobody wants to trade right now? What if the price is wrong?

An Automated Market Maker (AMM) solves this. It's a pool of two currencies that prices swaps instantly using a formula. No waiting. No order book. Just math.

2. The Formula

x × y = k The product of the two reserves stays constant

If the pool has 1000 tbtc3 and 5000 tbtc4, then k = 1000 × 5000 = 5,000,000. When you swap, the formula adjusts the reserves to keep k constant. Big swaps move the price more. Small swaps move it less. Supply and demand, encoded in arithmetic.

This is the same formula Uniswap uses. Except it runs on your pod, not on Ethereum.

3. Check the Pool

curl http://localhost:4443/pay/.pool
200 OK
{
  "pair": ["tbtc3", "tbtc4"],
  "reserves": {"tbtc3": 0, "tbtc4": 0},
  "k": 0,
  "fee": 0.003,
  "totalShares": 0
}

Empty pool. Anyone can see the reserves and calculate the exchange rate. Let's fill it.

4. Add Liquidity

Anyone can add liquidity to the pool and earn fees from swaps:

curl -X POST http://localhost:4443/pay/.pool \
  -H "Authorization: Nostr $NIP98_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"action": "add-liquidity", "tbtc3": 100000, "tbtc4": 100000}'
200 OK
{
  "action": "add-liquidity",
  "deposited": {"tbtc3": 100000, "tbtc4": 100000},
  "shares": 100000,
  "totalShares": 100000,
  "reserves": {"tbtc3": 100000, "tbtc4": 100000},
  "k": 10000000000
}

100K of each currency in the pool. k = 10,000,000,000. Now swap:

5. Swap

Sell 10,000 tbtc3 for tbtc4:

curl -X POST http://localhost:4443/pay/.pool \
  -H "Authorization: Nostr $NIP98_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"action": "swap", "sell": "tbtc3", "amount": 10000}'
200 OK
{
  "action": "swap",
  "sold": {"unit": "tbtc3", "amount": 10000},
  "bought": {"unit": "tbtc4", "amount": 9066},
  "price": 1.103,
  "fee": 30,
  "reserves": {"tbtc3": 110000, "tbtc4": 90934}
}

You sold 10,000 tbtc3 and got 9,066 tbtc4. Not 10,000 — the constant-product formula means larger trades get worse prices. The 0.3% fee (30 tbtc3) stays in the pool, slightly increasing k. The pool now has more tbtc3 and less tbtc4 — the price of tbtc3 dropped relative to tbtc4.

6. Remove Liquidity

When you remove liquidity, you get back your share plus accumulated fees:

curl -X POST http://localhost:4443/pay/.pool \
  -H "Authorization: Nostr $NIP98_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"action": "remove-liquidity", "share": 0.5}'

Your currencies go into the pool. Every swap pays a 0.3% fee that grows the pool's reserves. When you remove liquidity, you get back your share plus accumulated fees.

curl -X POST http://localhost:4443/pay/.pool \
  -H "Authorization: Nostr $NIP98_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"action": "remove-liquidity", "share": 0.5}'

7. Why This Exists

Centralised ExchangePod AMM
OperatorCompany with serversYou, on your pod
KYCRequiredNostr key (pseudonymous)
CustodyExchange holds your fundsWebledger on your server
PricingOrder bookx × y = k
Fees0.1–0.5% + withdrawal0.3% to liquidity providers
DowntimeMaintenance windowsYour server, your uptime
DeFi without the blockchain

This is the Uniswap model running on a personal web server, not a smart contract chain. The constant-product formula is identical. The difference: it runs in 50 lines of JavaScript on your pod, not in Solidity on Ethereum. No gas fees. No MEV. No bridge exploits. Just HTTP and math.