Uniswap v4 · Ethereum

Mnemis

A market maker with no memory charges the trade that corrects it exactly what it charges everyone else. Mnemis remembers — and prices the difference.

The problem

Every AMM quotes the past at the price of the present

An automated market maker knows the price it is at. It knows nothing about the price it has been.

So when the market moves and the pool has not yet caught up, the first trade through it is the most profitable order available in that block — and it is charged the same fee as a fifty-dollar buy from someone who has not looked at a chart. That gap is not a rounding error. It is the largest single transfer out of liquidity providers in decentralised finance, it has a name in the literature, and every major AMM in production pays it every day by design.

The usual answer is an oracle. Consult an external feed, discover the real price, charge accordingly. That works, on the roughly four hundred pairs an oracle provider is willing to cover, at whatever latency the feed updates, for as long as somebody keeps paying for the updates.

Mnemis does not consult anything. The pool is quoted against its own history.

The memory

Nine observations, one storage slot

A pool's entire recollection of what it has been worth fits in thirty-two bytes. Nine ticks at twenty-four bits each is two hundred and sixteen; a write cursor takes four more and a timestamp thirty-two, and the whole structure lands inside a single word with four bits to spare.

9 × int24  ·  216 bits cursor  ·  4 bits timestamp  ·  32 bits reserved  ·  4

One SLOAD, forever

Nine separate observations would be nine storage reads on the swap path. This is one, and it is why reading memory and running a nineteen-comparator median costs a trader nothing measurable.

The word is the commitment

memoryOf(poolId) is one eth_getStorageAt away. Anyone can decode it and recompute the median the contract used, with no indexer, no subgraph, and no trust in anybody's API.

The median

A mean bends. A median breaks.

A time-weighted average can be moved by one trade. Push the price far enough for long enough and the average follows you, in proportion to how hard you pushed. That is the entire attack surface of a TWAP, and it is why they ship with manipulation-cost tables.

A median cannot be moved at all until you own more than half the observations. Five of these nine. And because writes are spaced by a minimum interval, owning five means holding the pool away from its true price across five separate intervals, paying arbitrage on every block in between — with no partial credit for the first four.

The median does not drift toward an attacker as they spend. It does not move, and then it moves. That is a different shape of cost from a TWAP, not merely a larger one.

fork test · real PoolManager · real pool · real liquidity

  observations 1–4 manipulated   median unchanged   ← four is nothing
  observation  5   manipulated   median flips       ← five is everything

test_memoryAcceptsOneObservationPerIntervalAndTheMedianFollows  PASS

That test is not a comment claiming the property. It drives a live mainnet-fork pool off its median, lands observations one interval at a time, and asserts the median is untouched at four and moved at five.

The mechanism

The inverted curve

Two swaps of identical size, in the same pool, in the same block, are not the same trade. One pushes price away from everything the pool has recently been worth. The other brings it back.

Mnemis prices the direction. The two curves meet at the median and open outward from it — cheap coming home, dear leaving. Drag the price and watch them separate.

x is not the deviation

It is the deviation in units of memory — divided by the range the pool itself remembers. Fifty ticks is a violent dislocation in a stablecoin pair and an uneventful minute in a new token. One schedule states the same thing about both.

Which is why there is no admin

A schedule in absolute ticks would need per-pool tuning, and there is nobody to do it. A pool that has been volatile forgives volatility; a pool that has been flat does not. Neither needs to be told which it is.

What it costs

Measured, not estimated

Memory write10,058gas, once per interval
Between writes0one SLOAD, already warm
Hook runtime8,513bytes
Tests40unit, fuzz and mainnet fork
Median verified50,000random orderings vs. a full sort

The median is a nineteen-comparator selection network — six operations cheaper than sorting, and it answers the only question asked. The comparator count is fixed, so the gas cost of reading memory does not depend on what the memory contains: a swap cannot be made more expensive by arranging the price history it is quoted against.

The shape of the thing

What Mnemis does not have

Recalibration means a new hook and a new pool. That is the cost of the list above, and it is the right side of the trade.

Honestly

What memory is not

Memory is not truth. A pool held away from fair value long enough will remember the wrong number. What the median buys is that holding it there is the only way in — there is no cheaper partial attack, and no credit for trying.

There are no zero-knowledge proofs in this contract, and there should not be. A verifier on the swap path costs roughly a quarter of a million gas and would buy nothing here: the thing worth proving is what the pool remembered, and that is already public, already on-chain, and already one storage read from anybody who wants it. Thirty-two bytes that anyone can decode and check is a stronger guarantee than a proof nobody runs.

The hook reads PoolManager's storage directly rather than through StateLibrary — cheaper, and immune to that library changing shape between releases. It is a hard-coded assumption about a contract this project does not control, so a fork test asserts it against StateLibrary on every run.

The token

MNEM does nothing, on purpose

Fixed supply, minted once, at construction. No owner, no minter, no pause, no blacklist, no transfer tax, no reflection, no rebase, no cooldown, no max-wallet, no trading toggle. Nothing in the contract reads the caller, the block, or any other contract.

That is load-bearing twice. Once for the argument — Mnemis claims a pool can defend its own liquidity providers using nothing but its own price history, and a token that reached into transfers would contradict that in the one place anyone can check. And once for the machinery: a fee-on-transfer token breaks v4's accounting. The pool is told one amount and receives another, and every downstream balance is wrong by the difference.

The hook does not import the token, does not reference it, and works identically on pools that have never heard of it.