Back to portfolioPortfolio

Engram

A Uniswap v4 pool whose fee is set, trade by trade, by a small neural network stored on chain. The network can be replaced only by a better one, found in sealed, time-locked training rounds that anyone can enter.

Role
Design, economic model, Solidity, testing, launch and website
Deployed
5 October 2026, 21:40 UTCContracts at block 26,128,922; pool opened at block 26,128,981
Contracts
Five, all verifiedEtherscan and Sourcify, exact match
Testing
90 mainnet-fork checksTwo adversarial reviews before deployment
Stack
Solidity 0.8.28 (via IR), Uniswap v4, drand, EIP-2537, JavaScript
Hook permissions
0x20CC
The Engram network: ten input features, eight hidden units, one output 10 features, int8 8 hidden units, ReLU 1 output f0 sizef1 directionf2 gapf3 blockf4 flowf5 volatilityf6 trendf7 memoryf8 freshf9 streak markout in bps fee

The living network

109 bytes: W1 8x10, b1, W2, b2, two shifts

Ten int8 features go in, eight hidden ReLU units combine them, and one number comes out: the markout the network expects for this trade, in basis points. The hook turns it into the trade’s LP fee.

LP fee = clamp(0.30% + prediction, 0.05%, 3.00%)

Hover or tap a feature to see how the hook encodes it.

Fig. 1. The mind in the pool. The network the hook asks on every swap, drawn at its real size: 80 weights from the features to the hidden layer, 8 to the output. Feature definitions are quoted from the hook’s source. The live network on mainnet is the default one, which predicts zero for every trade.

The project

Engram is an ERC-20 token with a single Uniswap v4 pool, native ETH against ENGRAM. Its hook, the Hippocampus, reads ten features of every trade, asks a 109-byte neural network what the trade’s markout will be (how far the price keeps moving in the trade’s direction afterwards), and sets that trade’s liquidity-provider fee from the answer.

The network is not fixed. Once a day a second contract, the Dreams, grades sealed candidate networks on trades that did not exist when the candidates were submitted. A candidate takes over only if it clearly beats both the network in place and a flat fee. Nobody chooses the winner; the grading does.

The problem

Liquidity providers lose money to informed flow: trades that already know where the price is going. A flat fee charges an arbitrage bot and an ordinary buyer the same amount. Dynamic-fee hooks in Uniswap v4 can price that difference, but the AI-driven launch I analysed at the time ran its model off chain, and a single wallet could upgrade both its token and its hook. The fee was whatever that wallet said it was.

Engram puts the whole loop on chain: the features, the model, the grading and the replacement. Nobody, the owner included, can set the fee or change the code. A model can only be replaced by one that predicts better, and the bounty for a better model is priced below what it would cost an outsider to fake one.

What I built

  1. An economic model, before any Solidity

    A day-stepped JavaScript model of the pool, its traders and its trainers set the constants: the 0.30% base fee, the 0.04% trainers’ pot, the 3% promotion margin and the bounty rule. It changed the design twice: labels run from the price a trade leaves, and the bounty pays per unit of improvement.

  2. Five contracts and a shared library

    The token, the Hippocampus hook, the Dreams, a drand signature verifier (the Beacon) and a Launcher. The network’s arithmetic, the Cortex, is one library used by both the hook and the Dreams, so a model is graded by exactly the code that will later price trades with it.

  3. A JavaScript twin

    A BigInt mirror of the network and of the hook’s features, and a drand time-lock encoder, so a browser can seal a candidate exactly as the contract will read it.

  4. A mainnet-fork simulation

    90 checks against the live Uniswap v4 contracts, with thousands of swaps run in lockstep with the JavaScript mirror.

  5. Two adversarial reviews

    Full reviews before deployment found two high and four medium-severity issues. Each was fixed and reproduced in the simulation, or, where no clean fix existed, stated in the contract.

  6. A two-step launch

    A launch page deployed every contract with the pool closed, verified the source on Etherscan and Sourcify, and only then let the owner open trading. A read-back then checked 18 values on mainnet.

  7. The project website

    Pages that read every figure from the chain, a trainer that runs in the browser, and the buttons that let anyone seed, grade and finalize a round.

Brand and website

Engram is designed as an anatomy atlas. Every page of the website is a numbered plate with a figure and a caption, set in Vollkorn on warm paper, with ink line drawings and a single carmine accent for what the mind is doing. The X profile picture, the banner and the post cards are drawn as plates of the same atlas, so the site and the account read as one book.

Palette
Paper #F2ECDFInk #1C1A17Carmine #A8322ASepia #6B5440
Type
Vollkorn and Vollkorn SC for text and plate titlesCutive Mono for data
Engram profile picture: a single neuron drawn in black ink, with carmine dots
Profile picture: one neuron, in ink.
Engram X banner: a section of the hippocampus drawn as neurons, some in carmine
X banner: a hippocampus section; the engram in carmine.
Engram plate titled Perception, listing the ten features a trade is read as
Plate: Perception, the ten features.
Engram plate titled The Dreams, showing the five steps of a training round
Plate: The Dreams, five steps of a round.
Engram plate titled The Fees, showing what each trade pays and where it goes
Plate: The Fees, and where they go.
Engram website page The Mind in Time, with a spiral of every remembered trade
Website: The Mind in Time.
Engram website page The Lab in the dark theme, with every training attempt
Website, dark theme: The Lab.
Engram website on a phone
On a phone.

How it works

  1. 1Perceive

    The hook reads ten features of the trade: its size against the pool, its direction, the time since the last swap, other swaps in the block, recent flow, volatility, trend, and the trading wallet’s own record.

  2. 2Predict

    The living network turns those ten numbers into one: the markout it expects for this trade, in basis points.

  3. 3Price

    The trade’s LP fee is 0.30% plus the prediction, held between 0.05% and 3.00%. A trade the network expects to be informed pays more.

  4. 4Charge

    The hook also takes 1.04% of the trade’s ETH side: 1.00% for the owner and 0.04% for the trainers’ pot.

  5. 5Remember

    Eight remembered trades later, the trade’s markout is known. It is written to a hash-chained trace, and the wallet’s record moves by the trade’s weight.

  6. 6Dream

    Once a day, sealed candidates are graded on the newest trades. A candidate replaces the living network only if it beats both it and the flat fee by 3%.

SwapA trade of 0.005 ETH or more

Smaller trades pay their fees but are never remembered, so dust cannot move anyone’s record.

Ring of 8It waits for eight more trades
LabelIts markout becomes known

Measured from the price the trade left, so its own impact never counts. Clipped to plus or minus 200 bps.

TraceIt joins a hash chain

keccak256(previous, trace). Every 512 traces close a segment and store a checkpoint the Dreams can grade against.

Fig. 2. How a trade becomes a memory, step by step as Hippocampus._remember does it.

Seal. Candidates for round r are committed with a 0.01 ETH bond, optionally time-locked to the drand round published when window r closes.

Trade. The day’s remembered trades become the test set. No candidate can change, and none can be read.

Reveal. Anyone opens a candidate against its commitment, from its own key or from the time-lock.

Seed. The drand signature is checked on chain; its hash draws up to four of the window’s segments of 512 trades.

Grade. Anyone hands in a drawn segment; it is checked against the hash chain and every named candidate is scored.

Finalize. A candidate 3% better than both the living and the default network takes over and is paid; a living network worse than the default is retired.

Fig. 3. One training round on a 66-hour axis. Rounds settle strictly in order, and every step is open to anyone.

The contracts, reviewed

Supply and minting

One billion ENGRAM were created once, when the token was deployed, and all of them went to the launch. No function can create more.

For developers

INITIAL_SUPPLY = 1_000_000_000 ether is minted to msg.sender, the Launcher, in the constructor. There is no mint. Launcher.open() places the band and sends any ENGRAM it could not hold to the owner.

Burning

Any holder can destroy their own tokens. When the locked position’s fees are collected, whatever the network charged above the base rate is destroyed too.

For developers

burn(value) and burnFrom(from, value) against an allowance. Launcher.collect() burns the excess ENGRAM with Engram.burn and sends the excess ETH to 0x...dEaD.

Transfers

A plain ERC-20: no transfer tax, no blacklist, no trading switch. Approvals can also be signed off chain.

For developers

Standard transfer, transferFrom and approve. EIP-2612 permit refuses an s in the upper half of the curve order, so a signature has one form only, and rebuilds the domain separator if the chain id changes.

Fees

Every trade pays the hook 1.04% of its ETH side, and an LP fee that the network sets for that trade, between 0.05% and 3.00%. A swap that names an ETH amount and fills only partly is refused, so nobody pays a fee on ETH that never traded.

For developers

beforeSwap returns the LP fee with the override flag, in pips: base 3,000, floor 500, ceiling 30,000. The hook fee is a BeforeSwapDelta when ETH is the specified side and an afterSwap return delta otherwise, minted to the hook as ERC-6909 claims. Mismatched fills revert PartialFill.

int256 pred = Cortex.forward(Cortex.load(champion), f);
int256 fee = FEE_BASE + pred * 100;
if (fee < FEE_MIN) fee = FEE_MIN;
if (fee > FEE_MAX) fee = FEE_MAX;

The model

The network is a small data contract of 109 bytes. Only the Dreams can change which network the hook uses, and only at the end of a public round.

For developers

champion points at a contract whose code is STOP followed by the 109 bytes; Cortex.load reads them with extcodecopy, and the forward pass is unrolled assembly because grading runs it 512 times per segment per model. setChampion reverts NotDreams for any other caller.

Rewards for trainers

A trainer whose network takes over is paid from the trainers’ pot by how much it improved. Every candidate that is fully graded gets its 0.01 ETH bond back. Winners collect their payment themselves.

For developers

bounty = 4 x windowPot x (bar - loss) / bar, capped at the pot, plus bonds forfeited since the last win, credited to owed[winner] and paid by pull(). Promotion needs loss < bar x 0.97 with bar = min(living, default).

Owner and admin powers

There is no administrator. The owner wallet could open the pool once; since then it can only receive. It cannot change the code, the fees, the model or anyone’s balance.

For developers

Launcher.open() is owner-only and once-only (AlreadyOpen). No contract has a pause, an upgrade path or a setter. payOwner() and collect() can be called by anyone and pay only the owner.

Liquidity

All launch liquidity sits in one position owned by the Launcher contract, which has no function to withdraw, move or burn it. Its fees go to the owner at the base 0.30% rate; anything above that is destroyed, so a greedier network earns the owner nothing.

For developers

The position NFT is minted to the Launcher in open(). collect() runs DECREASE_LIQUIDITY with zero liquidity and TAKE_PAIR, then pays fees x atBase / charged per currency from the hook’s fee tallies, all of it when charged <= atBase.

Randomness

The only outside input is drand, a public randomness network. Its signatures are checked on chain against drand’s public key, so nobody can choose or predict the value that seals candidates and draws the grading sample.

For developers

The Beacon verifies BLS12-381 signatures on G1 against quicknet’s G2 key with the EIP-2537 precompiles (map-to-curve and pairing). The key is fixed in eight immutables; a round’s randomness is the SHA-256 of its signature.

Testing and security

90Checks in a mainnet-fork simulation, thousands of swaps in lockstep with the JavaScript mirror
18Values read back from mainnet after deployment: every address, immutable and key
2 + 4High and medium-severity findings across two adversarial reviews, all addressed before launch

The first review found that anyone could void any training round by seeding it with an empty range past the last segment; the fix pins the range to segments that exist, with checkpoint times checked at both ends. The second found that a quiet window with a single segment could be bought whole right after the deadline; now the segment that straddles the deadline is never drawn, so a round needs two completed segments.

Swaps and round steps measured on a mainnet fork against a living network; the hook adds 73,555 to 77,799 gas to a swap. The last two rows are the launch transactions on mainnet.
OperationGasPlain pool
Buy, exact input of 0.01 ETH166,98289,658
Sell, exact input173,19695,397
Buy, exact output169,20195,646
Sell, exact output of 0.01 ETH172,53094,806
Submit a sealed candidate104,630
Reveal a candidate134,785
Seed a round275,251
Grade one segment of 512 trades8,856,083 to 8,926,208
Finalize a round182,007
Collect the locked position’s fees171,935
Deploy every contract, pool closed (mainnet)6,645,852
Open the pool (mainnet)633,757

Limits, stated plainly

  1. Memory follows the wallet that signs the transaction. A wallet that rotates always looks new, and a relayer shares one memory for everyone it carries.
  2. The network sees only what is on chain. It cannot know the future, and its reach is bounded: the LP fee stays between 0.05% and 3.00%, and the 1.04% hook fee never changes.
  3. Rounds do not run themselves. Someone has to seed, grade and finalize each one, in order. Anyone may, and trainers have reason to. A window needs at least two completed segments of 512 remembered trades to be graded at all.
  4. Grading uses a sample: up to four segments of 512 trades, not every trade.
  5. The owner receives 1% of every trade, so it can trade in this pool almost for free. That makes faking an improvement cheaper for the owner than for anyone else. The most it could win that way is the trainers’ pot, and a greedier network would earn it nothing.

Status on chain

Read from Ethereum mainnet on 20 October 2026, block 26,234,001

  • The pool prices every trade with the default network, a flat 0.30% LP fee. No candidate has been promoted.
  • The hook had written 5,779 trades to its trace: 11 complete segments of 512, and 147 in the open one.
  • No training round has been finalized yet. Rounds settle strictly in order, and round 1 is still waiting for someone to finalize it.

Contracts

Contracts on Ethereum mainnet
ContractAddressVerified source

EngramERC-20 token

0x56C915D92E24255fdC52eb114a31399c432B7Cc6

HippocampusUniswap v4 hook

0x0Ee851f1fe2f4BDbA79FeE78969E329C136CA0cc

DreamsTraining rounds

0xC1182B08DD2B95f1477baa1dFD0741Eb06b1Ce9f

Beacondrand signature verifier

0xaea57Aa43Db8960F13fF366D1d8Fd83F340fa7D9

LauncherLaunch and liquidity custody

0x7AD86367Bd4e12b7e0BA15e6D05754CE8E723acD

All five are verified on Etherscan and on Sourcify with an exact match, metadata included. Compiler: solc 0.8.28, via IR, 200 optimizer runs, EVM target Cancun.