IInvest Like the Best
← All frameworks
InnovationDoug Colkitt

The Single-Contract DEX Architecture

Collapse every pool into one smart contract to remove the gas, tax and latency frictions blocking on-chain price discovery.

Difficulty
Expert
Time to result
~months to results
Steps
6
Confidence
85%

Colkitt's design thesis for CrocSwap. In every prior decentralized exchange each pool is its own smart contract, so moving a quote from one fee tier to another means burning the position, transferring tokens back to your wallet, and depositing them into a different contract — an expensive, heavyweight operation that also creates taxable events. In a single-contract DEX all pools live inside one contract with internal data structures, so an arbitrarily long string of actions can be netted out at the end and collateral can rest at the exchange rather than round-tripping to the user. The engineering constraint is Ethereum's roughly 24-kilobyte contract size limit, solved with high-frequency-trading techniques like separating a hot path from a cold path. Claimed results: 10-25% cheaper trading and 50-70% lower LP gas costs.

Origin

Colkitt built CrocSwap after concluding, from MEV trading and Uniswap V3's launch, that concentrated liquidity was the future but that friction prevented anyone from using it actively.

Core principles

  • 01Frictions determine behaviour: high gas costs force set-and-forget liquidity
  • 02Netting beats settlement — don't move tokens you're going to move back
  • 03Collateral concentrated in one place unlocks margin and cross-margin
  • 04Optimise the 99% case even at the cost of the 1% case
  • 05A market is an ecosystem: retail and institutions both have to be served

How to run it

  1. 1

    Diagnose where the friction actually sits

    Map the cost of the actions an active liquidity provider must take. Changing a price range or moving between the 0.3% and 0.05% fee tiers requires burning a position, transferring tokens out, and redepositing them elsewhere — a heavyweight operation for what should be as cheap as widening a spread.

    Pro tip Compare each on-chain action to its traditional-market analogue; a high-frequency trader may cancel 99% of orders, implying a hundred transactions per trade.

  2. 2

    Collapse all pools into one smart contract

    Rather than deploying a separate contract per pool, track pools as internal data structures inside a single contract so positions can be moved between pools without tokens ever leaving.

    Watch out Ethereum caps single contract size at roughly 24 kilobytes to keep the chain healthy — the whole exchange must fit.

  3. 3

    Net an arbitrary string of actions

    Because everything lives in one contract, a user can execute a long sequence of operations and only the net position is settled at the end, eliminating repeated token transfers and their gas costs.

    Pro tip Netting also collapses the number of taxable events, which matters increasingly as institutions enter.

  4. 4

    Hold collateral at the exchange

    Let active traders leave balances at the DEX instead of transferring tokens back and forth on every trade, settling up only when they actually want the assets out — which is how NASDAQ already works for equities.

    Pro tip This is also what removes the incidental taxable events created when routing through an intermediate asset like Eth.

  5. 5

    Apply hot path / cold path optimisation

    Borrow the HFT engineering discipline: identify what happens 99% of the time and make that path as cheap and fast as possible, accepting that the rare path becomes slower. This is how the exchange fits inside the size limit.

    Pro tip You have to understand the entire stack bottom to top to know which trade-offs are worth making.

  6. 6

    Design for what concentrated collateral unlocks next

    With all collateral at a single point, margin, leverage, perpetuals and especially cross-margin between correlated markets become feasible — features DeFi has lacked because capital is scattered across thousands of contracts.

    Pro tip Cross-margin matters for price efficiency because relative-value traders take little net risk while using significant leverage.

In the wild

Moving between fee tiers

Under the conventional architecture, an LP quoting a Bitcoin/Eth pair at the 0.3% fee tier who wants to move to the 0.05% tier must burn the position, receive all tokens back into their wallet at significant gas cost, then transfer them into the other pool at further cost — and each leg is potentially a taxable event. On a single-contract DEX the same change is an internal bookkeeping update, because both pools live in the same contract.

→ Colkitt estimates over 50% lower gas for LPs, and as much as 70% for those actively moving quotes.

Sponsored pools for centralized venues

CrocSwap includes the ability to create pools with arbitrary permissions subject to approval by token holders. A centralized exchange such as Binance could create its own sponsored pool, let liquidity providers contribute to it, and show those quotes on its own venue — while the blockchain transparently records how much LPs earn and whether the sponsor is behaving well. Users need not hold a wallet or visit the DEX at all.

→ Provides a composable bridge letting centralized exchanges access DeFi liquidity in a permissioned but transparent way.

Common mistakes

Ignoring tax as a design constraint

Every token round-trip between wallet and pool is technically a taxable event, including incidental Eth received when routing from token X to token Y, which can cascade into realising gains on unrelated holdings.

Assuming out-of-range positions need no management

Because moving positions is expensive, LPs let them drift out of range and forget them, but they remain exposed to being filled in the wrong direction — the same toxicity a traditional market maker faces.

Building for only one side of the market

Serving only retail leaves you with no liquidity; serving only institutions leaves two trading firms unwilling to trade with each other all day. Both sides of the ecosystem are required.

Is it for you?

Best for

Protocol architects and active liquidity providers who need to move quotes frequently.

Not ideal for

Passive set-and-forget liquidity providers who touch a position once a year.

From the transcript

“With single contract DEX you don't need to do that because pools themselves live on the same contract.”

Doug Colkitt

“So if I can make this 10% faster at the cost of making the 1% case two times slower, that's a great trade off to…”

Doug Colkitt

“For the trader side, in terms of the gas cost, 10 to 20% lower, and actually we can get up to 25% lower fees on…”

Doug Colkitt

From the episode

Doug Colkitt - The Evolution of Markets - [Invest Like the Best, EP. 255]

Doug Colkitt

→