Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Automated market maker

Shows: seed-authorized custody (13) · async message for strangers (9) · windows for expiry (16)

What is deployed

logos-blockchain/lez-programs: programs/amm is a constant-product pool deployed on the legacy testnet, which runs the v0.2.4 line. It is not an actor program: it is written against the v0.2.x interface, where a program receives whole accounts, returns their new contents and calls other programs with ChainedCall. Read its repository for its accounts and instructions; nothing in this guide applies to it directly.

The same pool as actors

A sketch, not built:

  • The pool is a public PDA of the AMM program (pattern 13). Its AMM actor holds the pair and the reserves; its balance actors for the two tokens hold the funds, and only the AMM can move them, by granting the seed. It is public because traders need its price and anyone must be able to trade against it (Where state lives).
  • A trader swaps with a root call to the pool’s AMM actor that marks the trader’s input balance actor as a signer (:sign in the CLI). The AMM sends that balance actor a SyncMessage Transfer to the pool, carrying the grant, as the mandate does in Payment requests. It computes the output from its reserves and pays it out of the pool’s other balance by seed (custody_transfer for the native token). The credit travels as an AsyncMessage, so a private trader receives it too (pattern 9): the trader’s transaction can promote it to their own private balance at once, or leave it stored, published in the clear, in which case the transaction introduces the address’s recovery binding.
  • A minimum output in the message limits slippage, and a validity window enforces the trader’s deadline (pattern 16).

What it leaks

Every pool actor is public, so each swap publishes its pair, direction and size, and the reserves after it. A private trader hides only who traded, behind a blinded address. Swaps of an unusual amount can be linked to each other by that amount.

The idea catalog records the stronger version as a negative result: an AMM with hidden reserves does not work under this model.