Introducing CoFiX: a Next-Generation AMM

Haseeb Qureshi
Dragonfly Research
Published in
7 min readOct 7, 2020

AMMs today are the most successful products in DeFi. The massive trading volumes of Uniswap testify to the power of permissionless AMMs.

But AMMs like Uniswap are exceedingly simple. While simplicity is at first a virtue — it’s much easier to bootstrap and secure a simple product — it also eventually becomes a liability. Over time, it will be harder and harder for Uniswap to keep pace with the cutting edge of algorithms.

Uniswap uses only a single variable in determining its pricing: the quantity of assets it holds in inventory. Smart market makers care about their inventory, but they also care about external volumes, historical price data, and real-time volatility. These inputs are essential to pricing risk correctly.

When you have no prior knowledge about the asset in question, Uniswap works great. But of course, most of the trading volume, even for Uniswap, is in the most traded pairs like ETH/USDT. Competitive market making on those pairs will only become more and more sophisticated. Over time, Uniswap’s one-size-fits-all pricing function will get outcompeted by specialized approaches, as I’ve argued in a previous essay.

Uniswap’s synthetic “order book” vs real order books. Credit: Parsec Finance

In light of Uniswap’s success, it’s easy to lose sight of what AMMs are supposed to be. They are not supposed to be dumb token vending machines. AMM stands for automated market maker — that is, algorithms that emulate what intelligent market makers would do. As AMMs ingest more data and incorporate more advanced algorithms, they will eventually become decentralized agents that make markets just as effectively as humans do today.

This is the direction DeFi will inevitably evolve — making AMMs gradually smarter and smarter until they approximate humans and compete with centralized market makers. This vision seems far away today.

Enter CoFiX.

Computational Finance

CoFiX is a next-generation AMM that uses external oracle data to inform its pricing algorithm. By taking into account historical volatility and other pair-specific parameters, it tailors its pricing function closer to how an intelligent market maker would. By offering better spreads during periods of low volatility and becoming more conservative during adverse market conditions, CoFiX can become a more profitable market maker while usually offering more competitive pricing than Uniswap. It can do all this while minimizing impermanent loss and without giving up as much in profits to arbitrageurs.

You might ask: why would you want to couple an AMM to an oracle? Isn’t Uniswap better because it doesn’t use any oracle?

Here’s the problem.

Take a liquid pair like ETH/USDT. A rational market maker would concentrate their liquidity in this market around the mid-market price. But Uniswap withholds a significant portion of its inventory at the tails — it behaves as though it has limit orders all the way up the book, stretched out deep in either direction. This is the constant product rule in action.

Uniswap’s ETH/USDT “depth chart” as of 9/28/2020

Uniswap might want to concentrate more liquidity around the market price when volatility is low. But Uniswap doesn’t know when volatility is low!

Worse than that, Uniswap doesn’t even know the mid-market price!

Uniswap is unable to react to changes in the outside world, whether in price or volatility. When a large trade happens, Uniswap has no choice but to assume the exogenous price must have changed.

Unable to see past this fog of war, Uniswap relies on its size, hoping that its spread won’t be too bad and that trading fees will make up for the impermanent loss.

Remember, Uniswap has $2B locked up in the protocol! This might seem good, but it shows how incredibly capital inefficient it is. It means Uniswap only has about ~30% daily turnover, which is extremely low for a market maker in crypto.

Because CoFiX uses an external oracle, it knows the mid-market price, the staleness of that price, and the historical volatility (unlike DODO or Bancor v2, neither of which incorporate volatility). This lets CoFiX approximate, ever closer, the decision-making of a true market maker.

But the devil is in the details. Which oracle does CoFiX use? And how reliable is that oracle?

Don’t sleep on NEST

NEST is probably the single largest DeFi project that has completely flown under the radar of the West. It is arguably the largest community-driven DeFi project in China, and for the last 6 months, even before the recent DeFi bull run, NEST was one of the most used contracts on Ethereum. In spite of the DeFi mania, today it’s in the top 5 gas guzzlers, above even Chainlink.

Largest gas consumers on Ethereum as of 9/28/2020. Credit: EthGasStation

The NEST oracle is CoFiX’s secret weapon. So what is NEST?

NEST’s mechanics are actually quite simple. At a high level, here’s how it works.

Anyone can claim that “the price of ETH/USDT is 1 ETH to 350 USDT.” To back this claim, they have to put up 1 ETH and 350 USDT in a public order, where anyone can take either side of that trade. If the price is right, then the market should be indifferent to taking the order.

But if the pricing is wrong — say the true price of ETH is 375 USDT — then an arbitrageur would pay 350 USDT to buy their cheap ETH and go sell it elsewhere. However, to claim the order, the arbitrageur needs to post their own order of a larger size. That arbitrageur would then post 2 ETH / 750 USDT, which they claim is actually the true price. (If they claim that the price moved more than 10%, the algorithm requires them to post a 10x larger order.) And if they posted an incorrect price, someone else could come by and one-up them as well, making the amounts staked increase exponentially.

This game continues until an open order sits on the book long enough to get confirmed without ever getting “one-upped.” That gets reported as the oracle price. The poster of that price gets rewarded with NEST tokens. This is how NEST tokens are “mined.” (The minimum quote size is currently 10 ETH.)

The insight here is that in an efficient market, an unclaimed two-way price quote is an oracle. If this quote has not been arbitraged, then you can assume that the price is correct. This makes for an elegant and simple oracle design for any assets that are already tokenized on-chain (TBTC originally considered a similar oracle design).

And it works! NEST currently quotes ETH/USDT about once every 2.5 minutes — when the network was less congested, it was quoting roughly once every 4 blocks.

Quoting frequency as of 9/26/2020. Credit: NEST WeChat Community

This is much more real-time than Chainlink, whose nodes report price updates roughly once every 45 minutes (with an explicit SLA to update every 3 hours or on every 0.5% price change). Most AMMs we’ve seen that use external oracles rely on Chainlink, including DODO and Bancor v2. As an example, DODO LPs have seen massive impermanent loss due to traders frontrunning the infrequent Chainlink oracle updates.

By harnessing the power and consistency of the NEST oracle, CoFiX is able to offer tighter quotes and competitive spreads with less exposure to impermanent loss.

The NEST price feed is extremely tight (9/26/2020). Credit: NEST WeChat Community

Because NEST is a Chinese DeFi project, it hasn’t gotten a lot of attention in the West. But it’s been one of the strongest community-driven oracles we’ve seen on Ethereum. You can think of it like the YFI of oracles in China — completely decentralized with a vibrant, active community of developers. It’s high time that NEST and its ecosystem gets some recognition in the West. If you want to learn more, you can dive deeper into some of NEST’s documentation.

Launch Date

CoFiX is launching in a few days with 90% of the tokens to be distributed via liquidity mining. Like NEST, it has a decentralized community working to get it off the ground, many of whom are pseudonymous. The energy around the project is electric, and we’d love to see more people from the West get involved. Crypto is global, and CoFiX is excited to introduce itself to the Western DeFi community.

Two years ago, DeFi was the domain of hackers and hobbyists. DeFi has now come into its own, and its infancy will soon be behind us. We’re excited to see CoFiX push forward the vanguard of AMMs.

If you’re interested in getting involved, either to develop on the platform (full white paper here), to trade on the exchange, or to liquidity mine by providing inventory, check out their documentation and join the Telegram. (The English translations are a little rocky, but they could use your help on that! Get involved!)

DeFi is global, so we’ll be participating alongside you.

https://upscri.be/f/y7mgqv

Disclosure: Dragonfly is an investor in CoFiX and holds a position in NEST.

--

--

Haseeb Qureshi
Dragonfly Research

Investor at Dragonfly Capital. Formerly Metastable, @Airbnb, @earndotcom. Writer. Effective Altruist. Former poker pro. One always finds one's burden again.