Skip to content
log(swap)

Contracts

Six core contracts, no factory. A new market of either shape is an initialize call, not a deployment. Beside them sit the policies every F-pool is born under, and the registry that approves them.

contractroleruntime size
ManagerC.solThe C singleton. Every concentrated market: swap loop, ladder, fee kernel, accumulators, ERC-6909 (positions and token claims), flash accounting.23,379 B — 1,197 under EIP-170
ManagerF.solThe F singleton. Fungible claims, one shared floor ξˉ=xˉ−Q/L\bar\xi = \bar x - Q/L, nn bases and one quote per pool, generations; its own lock, its own ERC-6909 space. Holds no parameter and no kind: it asks the pool's policy.24,332 B — 244 under EIP-170
RouterC.solUser entry for every C market: multicall, blended mint, zap, burn, claim, update/move, multi-hop paths. Slippage and deadline on every mutating entry; Permit2 optional. One contract.17,297 B
RouterF.solUser entry for every F pool: the three kinds of swap and the quoter, zap in, zap out, roll-in. Slippage and deadline on every mutating entry; Permit2 optional.12,268 B
LensC.solRead-only over the C manager: ladder derivations, previews, and the views evicted from the manager for size. Holds no storage; redeployable freely.11,974 B
LensF.solRead-only over the F manager: previews, the holder's book, and the state views decoded from the manager's storage. Holds no storage; redeployable freely.9,598 B
PolicyRegistry.solThe protocol's list of approved F-pool policies, and the one hand that may move a live pool to another approved policy of the same kind.4,056 B
policies/The four F-pool policies — PublicPolicy, PrivatePolicy, PolPolicy, PadPolicy — each the rules of one kind. See The F-pool.5.3–7.7 kB each

Plus types/PoolKeyC.sol and types/PoolKeyF.sol (the identity structs) and libraries/ — LogswapMath, TickBitmap, Transient.

Two singletons, a router each

The F singleton sits beside the C singleton, not inside it. Mathematically it is the C manager's degenerate case — one position class, one shared floor — so one specification covers both and it introduces no new invariant.

They hold separate locks, because a distinct contract is a distinct transient namespace. Each has its own router and lens (096): nothing in a manager points at a router, and a second Permit2 spender is a second signature, not a second on-chain approval.

Both halves settle the same way — open the lock, run the operations as deltas, pay the manager directly from the payer. Neither router custodies anything.

Market identity: the key is the authentication

poolId = keccak256(abi.encode(key))

The key is the full economic tuple and nothing else, and it travels in calldata on every operation, verified against the hash. Three consequences worth internalising:

  1. The hash is the authentication. A forged key resolves to an uninitialized pool and the call stops at PoolNotInitialized. There is no registry to poison and no address to spoof.
  2. Parameters cost zero storage reads. They arrive in calldata and are checked by hashing — which is where the singleton buys back most of what the extra indirection costs.
  3. Creating a market is a call. initialize validates parameter ranges, rejects base == quote, probes the quote's decimals for the minimum backstop, and seeds the price. It is permissionless.

The ERC-6909 id space

One token space, two receipt types, split structurally on bit 255 — not probabilistically.

bit 255idintrospection
Positionset(1<<255) | (keccak256(poolId ‖ packed) >> 1)idInfo[id] → (poolId, packed), written on first mint
Token claimclearuint160(token) — always < 22552^{255}the id is the token address
reservedclear[2160,2255)[2^{160}, 2^{255})future receipt types

packed carries the floor index in the low 32 bits and the cap index in bits 32–63, with a zero cap field meaning uncapped (an index plus the 2312^{31} offset can never be 0).

Hashed ids lose direct unpack() introspection. Two things restore it: the idInfo registry answers on-chain at any time, and IdRegistered(id, poolId, floor, cap, capped) — emitted once, when a class is first created — puts the mapping in the log stream, so an indexer builds it by replay instead of an RPC call per id. What the hash buys is a flat global id space needing no per-market coordination.

Why the surface is split the way it is

Which contract hosts which action is currently decided by EIP-170 headroom, not by design. The SDK hides the manager/router/lens split for exactly that reason: a future re-homing should be an SDK patch, not a breaking change for consumers.

The C manager keeps typed getters — getPool, ticks, deltaOf, isUnlocked, nonzeroDeltaCount — so every C read is ABI-checked instead of slot-offset-coupled. The F manager took v4's escape hatch to make room for the cap and the lien: it exposes v4's raw extsload, its state is decoded on chain by the PoolStateF library (as v4's StateLibrary does), and the lens re-exposes it off chain (pool, bundleOf, dividendOf, lienOf). The storage layout is therefore a read surface on F, pinned by a test against the manager's own storage.