Generalizing Knowledge on DEXs with AMMs — Part II
In our previous post, we introduced the basics and mechanisms behind general AMM protocols. We also compared 4 of the major players: Uniswap v2, Balancer, Curve and DODO. Building upon the huge interest in Uniswap v3, we included the following sections in this second part of our research:
- Uniswap v3 formalization
- An overview table of many other AMM protocols
- DeFi protocols with AMM implementations
- Security issues, including AMM-related attacks
The second version of the paper extends the information discussed in Part I. It is a joint work with Jiahua Xu and Nazariy Vavryk UCL Centre for Blockchain Technologies, and Krzysztof Paruch from the Vienna University of Economics and Business. Let’s take another deep dive into AMMs and explore their environments.
To read more technical and in-depth explanations of the added sections, please read the paper. Any feedback is welcome and much appreciated.
Recap
Figure 1 gives a good summary of the basics discussed in the previous post. Different actors in the AMM are able to perform different actions that alter the state of the pool they are interacting with. Certain costs such as slippage impermanent loss are attached to using an AMM protocol
We have seen that every major AMM has its own flavor in designing its protocol, which leads to advantages in specific use-cases. Everyone can create a standard vanilla Uniswap, Balancer allows for different reserve weights, Curve only pools equal-peg stablecoins and DODO ensures there is no impermanent loss for liquidity providers.
Uniswap v3
Recently introduced, Uniswap v3 will be the latest version of the highest-volume AMM currently in existence. v3 introduces concentrated liquidity and multiple fee tiers. Liquidity providers are now able to concentrate their deposited liquidity into certain price ranges, leading up to 4000x capital efficiency compared to v2, and allows traders to execute their orders with low slippage.
Unlike Uniswap v2, the Uniswap v3 conservation function now contains a hyperparameter 𝒜 that determines how concentrated the LP provides the liquidity around the spot price. When 𝒜 → +∞, the covered price range approaches (0,∞), which is equal to Uniswap v2 with no capital efficiency. When 𝒜 → 1, liquidity is provided very close to the exchange rate, and thus very concentrated.
Overview of DEXs with AMMs
The above table gives an overview of the major DEX protocols implementing AMMs. The majority of protocols use a constant-product based conservation function, few have a constant-sum component. The latest versions of protocols, such as Uniswap v3 and Kyber 3.0 include a capital concentration component to increase capital efficiency. The Flash loan attack has some widely known examples, using one sole DEX as price oracle seems to be an often exploited design flaw. Ethereum is with no doubt home to the most used DEXs.
Other AMM implementing products
AMMs form the basis of other protocols that implement existing or invent newly designed bonding curves that facilitates the functionalities of these products.
Gyroscope protocol
Gyroscope is a stablecoin, backed by a reserve portfolio that diversifies all DeFi risks. Gyro Dollars can be minted for a price near $1 and can be redeemed for an amount worth near $1 in reserve assets, as determined through a new Automated Market Maker (AMM) design that balances risk in the system. Gyroscope includes a Primary-market AMM (P-AMM), through which Gyro Dollars are minted and redeemed, and a Secondary-market AMM (S-AMM) for Gyro Dollar trading.
Pods Finance
Pods is a decentralized non-custodial options protocol that allows users to create calls and or puts and trade them in the Options AMM. Users can participate as sellers and buy puts and calls in a liquidity pool or act as liquidity providers in such a pool. The specific AMM is one-sided and built to facilitate an initially illiquid options market and price option algorithmically using the Black-Scholes pricing model.
Balancer LBP
Liquidity Bootstrapping Pools (LBPs) are pools where controllers can change the parameters of the pool in controlled ways, unlike immutable pools. The idea of an LBP is to launch a token in a fair manner, by setting up a 2-token pool with a project token and a collateral token. The weights are initially set heavily in favor of the project token, then gradually “flip” to favor the collateral coin by the end of the sale.
Yield space
The YieldSpace paper introduces an automated liquidity provider for fixed yield tokens. A formula called the “constant power sum invariant” incorporates time to maturity as an input and ensures that the liquidity provider offers a constant interest rate — rather than price — for a given ratio of its reserves. fyTokens are synthetic tokens that are redeemable for a target asset after a fixed maturity date. The price of a fyToken floats freely before maturity, and that price implies a particular interest rate for borrowing or lending that asset until the fyToken’s maturity. Standard AMM protocols are capital-inefficient. By introducing the concept of a constant power sum formula, the writers want to build a liquidity provision formula that works in “yield space” instead of “price space”.
For more implementing products, we encourage you to read the paper.
AMM-related attacks
DEXs with AMMs are often involved in DeFi exploits. The following attack descriptions explain how AMM protocols themselves and the protocols implementing them are vulnerable.
Flash loan Oracle attacks
At the end of 2020, a series of flash loan-funded price oracle attacks caused exploits in numerous protocols. In this kind of attack, adversaries manipulate protocols that use a DEX as their sole price oracle.
The attack temporarily distorts the price of token A relative to token B. After the prices are arbitraged back, the attack leaves the loan taken from step 3 undercollateralized, jeopardizing the safety of lenders’ funds on PLF.
Examples of such attacks are exploits on Harvest finance, Value DeFi and Cheese bank.
Rug pull
The general idea of a rug pull is to lure people into buying the coin with no value, subsequently swapping this coin for ETH or another cryptocurrency with value. One method is to create a coin with the same name as an existing one. This attracts a lot of attention since everyone wants to pick up the coin at the lowest price possible. The coin is being bought up until, at one point, the original liquidity provider withdraws his liquidity which now exists of much more ETH and less of the valueless fake token.
Sandwich attacks
Combing front- and back-running, a “sandwich attacker” places his orders immediately before and after the victim’s trade transaction. The attacker uses front-running to cause victim losses, and then uses back-running to pocket benefits.
One example is a sandwich price attack, in which for example a large buy order is seen by a malicious actor. That actor buys before the initial transaction can go through, thus moving the price up. The original transaction is now executed. Afterwards, the malicious actor back-runs the transaction and sells the previously bought tokens for a higher price, pocketing the price difference.
Vampire Attack
In September 2020, Sushiswap performed a “Vampire attack”, effectively sucking liquidity out of Uniswap and depositing it in their own protocol.
In the first step of a Vampire attack, a new protocol incentives liquidity providers of another platform to stake their LP tokens into the protocol. In the case of Sushiswap, Uniswap LPs were rewarded with SUSHI tokens when they staked their LP tokens into the Sushiswap protocol. In the second stage, a migration of liquidity happens. The migration process was executed by a smart contract that took the Uniswap LP tokens in Sushiswap, converted those to the represented liquidity on Uniswap, transferred the assets to Sushiswap and got Sushiswap LP tokens in return. Effectively, Sushiswap migrated liquidity from Uniswap to Sushiswap, thereby moving $830 million to the newborn AMM, giving access to more volume and thus creating a more attractive proposition to users. Users’ Uniswap LP tokens got automatically replaced with Sushiswap LP tokens, representing the same liquidity.
Conclusion
In part I, we laid out the basic mechanics and principles of AMM protocols. The major protocols each add their own flavor to those mechanics.
In this part, we added one more AMM - Uniswap v3 -, which led us to a big overview table of major DEXs with AMMs. We introduced a number of AMM implementing products, showing that AMMs are of great use under the hood of other DeFi products. Finally, AMMs are often involved in different kinds of attacks and so these vulnerabilities should be accounted for in designing AMMs or protocols that use AMMs.
UCL Centre for Blockchain Technologies
Official Website: http://blockchain.cs.ucl.ac.uk/
Paper on ArXiv: https://arxiv.org/abs/2103.12732
Github: https://github.com/xujiahuayz/bondingcurves
Twitter: Simon DeFi , UCL CBT