Low Toxicity AMM — Trader’s Perspective

This is the second post in our series on designing a low-toxicity automated market-maker. Other posts in this series: part one.

Alexander Nezlobin
8 min readAug 29, 2022

Introduction

From a trader’s point view, the main function that an AMM offers is a simple swap, that is, trading some amount of one token for another. At a basic level, the protocol needs to answer the following two questions:

  1. How is the execution price determined for a given swap?
  2. Once the current swap is executed, how does it affect the execution prices for future swaps?

In this post, we provide high-level answers to these questions for our low-toxicity AMM (LTAMM). Our goal to describe a simple, workable algorithm. We will intentionally gloss over some of the technical details and potential refinements. Our primary focus will be on the features of the algorithm that are different from the existing AMMs and facilitate lower order flow toxicity.

Synthetic order book

The easiest way to explain our algorithm is with a synthetic order book. Let’s say Alice wants to purchase ETH with USDT. The LTAMM will accumulate all of its available ETH and USDT liquidity and create the following artificial order book.

Figure 1. Synthetic order book for the ETH/USDT pair.

Alice can buy the first unit of ETH at price askP or sell at price bidP. These prices are inclusive of the swap fee. (In general, when we refer to the bid or ask prices, we will always mean the after-fee ones.) The more ETH Alice wants to buy, the higher will be the execution price. For instance, she can take all liquidity between prices askP and P’ — the amount of ETH given by the shaded area between the two red vertical lines. Her average execution price will then be somewhere between askP and P’, closer to askP since the distribution of the ETH liquidity is declining in price.

When Alice’s swap is executed, the synthetic order book is adjusted in the following ways:

  1. P’ becomes the new ask price.
  2. The protocol’s mid-price, midP in Figure 1, immediately travels to the right the same distance as the ask price. Note that the mid-price will not be always exactly in the middle between the bid and ask prices. The importance of the mid-price will become clear soon.
  3. The bid side of the book is flattened so that its height at bidP matches the height of the ask side at the new ask price.
  4. The bid price stays the same.

Therefore, after Alice’s swap, the synthetic order book looks as follows. Dashed red and green lines show the distribution of liquidity prior to the swap, shaded areas show the distribution after.

Figure 2. Synthetic order book after Alice’s swap. Quantities in bold (L, midP, askP) have changed.

Why do we flatten the bid side and keep the bid price unchanged? Both of these actions are taken to ensure that LPs make a profit on quick round-trip transactions. The round-trip transactions, such as buying some amount of ETH and then quickly selling it back to the pool, must be profitable to LPs for two reasons.

First, this prevents price manipulation attacks in which an attacker artificially inflates the price of one asset, say ETH, and then benefits by buying the other asset, USDT, at a relatively small price. While our AMM will shift the USDT liquidity towards the new mid-price, it will only do so gradually over time. Therefore, a hypothetical attacker would need to incur the full cost of the attack but then compete for its benefits with other traders over multiple blocks. Making round-trip transactions profitable to LPs and unprofitable to the traders thus reduces the probability of price manipulation attacks.

The second reason for flattening the bid side and keeping the best bid unchanged after Alice’s swap is to make sure that LPs benefit from uninformed trades. Recall that, on average, LPs lose money on transactions with arbitrageurs. Therefore, for liquidity provision to be profitable, LPs must make money on trades that push the AMM price away from the efficient price. Yet not all of the profit from such transactions will accrue to LPs. Arbitrageurs will reap some of the benefit by trading in the opposite direction and pushing the AMM price back towards the efficient one. By providing liquidity for these opposite trades slowly and in limited quantities, LTAMM ensures that a larger share of gains from uninformed swaps stays with LPs.

Behavior over time

The main difference between LTAMM and most existing DEX protocols is that its synthetic order book is dynamic: it changes not only in response to user transactions but also with passage of time. Specifically, each period (say, at the beginning of each block), two transformations are applied to the order book as illustrated in Figure 3.

Figure 3. Order book evolution over time. Quantities in bold (L, bidP, askP) have changed. The new positions of ETH and USDT liquidity are colored solid red and green, respectively. The old liquidity positions are crosshatched.

First, both the bid and ask sides of the book are moved closer to the mid-price, reducing the after-fee bid-ask spread. The amount of such reduction is governed by the parameter we call shrinkage. For instance, if shrinkage=10%, then both bid and ask prices travel each block 10% of the distance towards to the mid-price, thus reducing the after-fee bid-ask spread by 10%. (Following large and sudden market shocks, even a 10% reduction in the spread can correspond to a significant change in the best bid or ask prices. As a security mechanism, one can impose a bound on the price improvement as a percentage of price. For example, the best bid price will generally travel 10% of the distance towards the mid-price but will increase by no more than 0.25% in a single move.)

The second change that is applied to the order book each period is steepening and is governed by the parameter we call growth. The amount of liquidity at the best bid and ask prices increases at rate given by growth, while the liquidity offered far away from the best bid and ask prices decreases. Ultimately, the total amounts of both ETH and USDT liquidity offered are still equal to the amounts of liquidity available in the pool. As a consequence, liquidity becomes more concentrated around the mid-price.

Intuitively, in the absence of swaps, the protocol behaves as a two-sided Dutch auction with mid-price serving as the reserve price for both sides. Each swap changes the reserve price and partially rolls back the auction for the opposite side of the book. This rollback is done so as to keep the best price on the opposite side of the book unchanged and the marginal liquidity equal at the best bid and ask prices.

Steady state

When a swap happens in the LTAMM protocol, the bid-ask spread expands and the distribution of liquidity flattens (Figure 2). Yet the protocol also automatically shrinks the bid-ask spread and steepens the distribution of liquidity over time (Figure 3). These two forces will constantly balance out each other. For instance, if trading volume is low, then the impact of incoming swaps on the distribution of liquidity will be small. The protocol will then keep concentrating liquidity and reducing the bid-ask spread. These actions will attract traders and increase the impact of their swaps on the liquidity distribution.

To gain some intuition for parameters growth and shrinkage, consider what happens in a steady state equilibrium when the forces described above exactly offset each other. For the height of the liquidity distribution to be stable, the percentage of liquidity swapped per block must be approximately equal to growth/2. This is because a swap on one side of the book decreases the height of both sides. For example, if growth is set equal to ten basis points (0.10%), then on average, in the steady state, five basis points the total ETH and USDT liquidity will be swapped per block.

We’ll skip the details, but this number can be used by LPs in several ways. A provider of one-way ETH liquidity can estimate that it will take close to 5.8 hours to convert one-half of the supplied liquidity into USDT. A provider of two-way liquidity can estimate that a dollar of liquidity will generate approximately 2.9 dollars in daily trading volume. (Both of these estimates require some additional assumptions: we assumed that there are four blocks per minute and that price movements in both directions are equally likely.)

The second parameter, shrinkage, determines the relation between the AMM’s bid-ask spread and the steady-state average price impact per block. The bid-ask spread changes from block to block according to the following process:

Spread[t+1] = (1-shrinkage)(Spread[t] + PI[t]),

where PI[t] is the total (gross) price impact of all swaps in block t and Spread[t] is the spread at the beginning of the block. Therefore, in steady state, the relation between spread and the average price impact per block is:

Spread = (1-shrinkage)PI/shrinkage.

For shrinkage = 10%, the bid-ask spread is approximately equal to nine block price impacts. Interpreting the bid-ask spread as two times the swap fee, this translates into a swap fee of 4.5 block price impacts.

For comparison, at the time of this writing, on Uniswap v3, the fees for ETH-USDC pair range from 2.5 block price impacts (for the 5-bps fee tier) to close to 100 block price impacts (for the 30-bps fee tier). The latter number is particularly high because there are many blocks without swaps in the pool with a 30-bps fee. Characterizing the optimal relation between the swap fee and the price impact per block is an interesting question, which we will save for one of the future posts. For now, we just note that parameter shrinkage allows LPs to target a particular steady state ratio between these two numbers in the LTAMM protocol.

Conclusion

This post describes one of the perspectives on the LTAMM protocol — namely, that of a trader. It sheds light on the implementation of some of the features that we described in our first post, such as: dynamic fees, continuous price discovery, automatic positioning and concentration of liquidity, predictable conversion of one-way liquidity, and cheap execution.

We still need to describe the implementation of other features, one of the most important of which is resistance to market manipulation attacks. As discussed above, the protocol already provides some such resistance. For instance, unless an attack can be sustained over many blocks, the attacker will not be able to benefit from manipulating the AMM price to make liquidity available at inefficient prices. Similarly, sandwich attacks are also significantly more difficult in the LTAMM protocol than in most existing protocols.

New features can, however, create new attack vectors. One example here is single-sided provision of liquidity. If all liquidity on one side (say, ETH) is provided by a single market participant, that market participant can still benefit from manipulating the LTAMM price by trading against his own liquidity. Attacks like this one need to be prevented with carefully designed incentives for LPs, which we will describe in our future posts.

Thoughts/ideas/suggestions? Leave a comment here or reach us at ltdex@pm.me.

--

--

Alexander Nezlobin

I am a professor at the London School of Economics, and I write about DeFi.