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.
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.
curl http://localhost:4443/pay/.pool
{
"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.
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}'
{
"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:
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}'
{
"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.
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}'
| Centralised Exchange | Pod AMM | |
|---|---|---|
| Operator | Company with servers | You, on your pod |
| KYC | Required | Nostr key (pseudonymous) |
| Custody | Exchange holds your funds | Webledger on your server |
| Pricing | Order book | x × y = k |
| Fees | 0.1–0.5% + withdrawal | 0.3% to liquidity providers |
| Downtime | Maintenance windows | Your server, your uptime |
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.
Part 10: Beyond Tokens. Blocktrails can anchor anything — not just fungible tokens. NFTs, smart contracts, git commits. The system is general-purpose. The payment series was just the beginning.