Awesome
Awesome AMM
List of AMM and Orderbook Resources
An overview of the prominent designs and large implementations
Automated Market Makers
History
A collection of the earliest posts regarding what came to be the automated market maker and it's many variations
- Vitalik: Let's run on-chain decentralized exchanges the way we run prediction markets
- Martin Köppelmann: Gnosis Market Maker Orderbook
- Nick Johnson: Euler
- Vitalik: Improving front running resistance of x*y=k market makers
- Alan Lu: Building a Decentralized Exchange in Ethereum
A collection of popular iterations of various designs (listed below)
Designs
-
Constant Product
Formula:
(R_a - delta_a)(R_b + fees * delta_b) = k
Simplified Formula:x * y = k
Where R_α and R_β are reserves of each asset and γ is the transaction fee. Trading any amount of either asset must change the reserves in such a way that, when the fee is zero, the product R_αR_β remains equal to the constant k. This is often simplified in the form of xy=k, where x and y are the reserves of each asset. In practice, because Uniswap charges a 0.3% trading fee that is added to reserves, each trade actually increases k.
<p align="center"> <img src="./images/constant_product.png" alt="Constant"/> </p> -
Stableswap (Hybrid)
Where x is the reserves for each asset, n is the number of assets, D is an invariant that represents the value in the reserve, and A is the “amplification coefficient”, which is a tunable constant that provides an effect similar to leverage and influences the range of asset prices that will be profitable for liquidity providers (i.e. the higher the asset volatility, the higher A should be).
Function:
An^n SUM(x_i) + D = ADn^n + D^(n+1) / n^n ∏ x_i
This function acts as a constant sum when the portfolio is balanced and shifts towards a constant product as the portfolio becomes more imbalanced. In effect, the function looks like a “zoomed-in hyperbola”.
<p align="center"> <img src="./images/stableswap.png" alt="Stableswap"/> </p> -
Constant Mean
A constant mean market maker is a generalization of a constant product market maker, allowing for more than two assets and weights outside of 50/50. First introduced by Balancer, constant mean markets satisfy the following equation in the absence of fees:
Formula:
k = ∏_n R^W_i
where R is the reserves of each asset, W is the weights of each asset, and k is the constant. In other words, in the absence of fees, constant mean markets ensure that the weighted geometric mean of the reserves remains constant.
<p align="center"> <img src="./images/constant_mean.png" alt="Constant Mean"/> </p> -
Concentrated Liquidity
The defining idea of Uniswap v3 is concentrated liquidity: liquidity that is allocated within a custom price range. In earlier versions, liquidity was distributed uniformly along the price curve between 0 and infinity.
The previously uniform distribution allowed trading across the entire price interval (0, ∞) without any loss of liquidity. However, in many pools, the majority of the liquidity was never used.
Concentrated Liquidity relies on the concept of virtual liquidity which can be read and derived in their whitepaper
<p align="center"> <img src="./images/concentrated_liquidity.png" alt="Concentrated Liquidity"/> </p> <p align="center"> <img src="./images/concentrated_liquidity_distribution.png" alt="Concentrated Liquidity Distribution"/> </p>
Source Constant Function Market Makers: DeFi’s “Zero to One” Innovation
-
Front-running Resistance
AMMs use swap fees to earn profits for their liquidity providers. Liquidity providers are ultimately compensated via these fees. But if the pricing function significantly misprices the assets in the pool, as might happen after a sudden exogenous price crash, liquidity providers lose potential profit to arbitrageurs who purchase the mispriced assets.
An AMM can thus maximize its profit in one of two ways: maximizing trading fees, or minimizing arbitrageur profits. Mooniswap seeks specifically to pursue the latter strategy: by introducing virtual balances, arbitrageurs are less able to profit on temporarily mispriced pools, leaving more profit for liquidity providers.
In Mooniswap, when a swap takes place, the pool does not immediately offer a profitable trade in the opposite direction. Instead, it slowly improves the price over some period of time. The following chart shows how several trades would significantly increase the constant-product invariant from point X to point Q.
<p align="center"> <img src="./images/front-running_resistance.png" alt="Front-running Resistance"/> </p>After the above swap takes place, the virtual balance for the opposite swap will linearly move from point A to point X. At some point before this full transition takes place, arbitrageurs will attempt to exploit the smaller temporary arbitrage opportunities along the way. For example, when the virtual balance reaches point B, an arbitrageur may choose to arbitrage the price back to the true price at point C. Note that points A and C (and the origin) are located on the same line, which means they have the same price. The chart depicts three sequential arbitrage trades (BC, DE, ZQ) until the real balance reaches an equilibrium price at point Q.
Source Mooniswap Whitepaper
AMM Aggregator
Rango V2 smart contract aggregates and optimizes EVM chains through Uni V2, V3, curve pools and prominent well-audited bridges. Rango V2 employs the diamond design pattern in its architecture, incorporating facets, middlewares, and helper/library contracts. This transition automates a modular design similar to Ethereum Improvement Proposal (EIP) 2535, uniting over 250 EVM smart contracts.
There are two main type of contracts:
Diamond
: Handles swap and bridge transactions(RangoDiamond.sol)
.Middlewares
: Receives token and messages on destination chain and handles the transaction.
The functionality and support for each bridge is handled by a separate facet. All swapping protocols are handled by a single facet.
For example:
Axelar (Satellite): RangoSatelliteFacet.sol
,
THORChain: RangoThorchainFacet.sol
,
Stargate: RangoStargateFacet.sol
,
Stargate Middleware: RangoStargateMiddleware.sol
,
1inch, Paraswap, uniswap v2, v3 & forks etc: RangoSwapperFacet.sol
Rango provides a versatile cross-chain service (API/SDK/widget) that helps dApps and wallets get free from hassles of connecting to various AMMs and blockchains, tracking transactions, verifying third-party providers, etc. The API consists of just a few endpoints that have abstracted away a very huge amount of complexity in the server's side, such that making a fully-working cross-chain dApp over any Ethereum-based blockchains is a piece of cake.
<p align="center"> <img src="https://github.com/user-attachments/assets/be419ead-1562-4c62-8e83-15ca5140ec1a" alt="Swap bridge call"/> </p>Resources
- Swap aggregation
- Supported AMMs & chains
- Smart contracts architecture
- Audit reports
- Widget examples for different frameworks
- Report bug or contribute
Products
- Rango app
- Plug-and-play widget integration docs
- Widget test live demo
- Customize widget
- SDK integration docs
- New token listing
Virtual Automated Market Makers
A virtual automated market maker (vAMM) uses formulas, such as constant product, but only as a price discovery mechanism.
Generally a vAMM product is designed with a "clearing house" or "controller" contract in which all of the collateral deposited is held.
vAMMs are primmarily used for perpetual future contracts in which the collateral in the clearing house backs virtual assets that users can trade.
Following the release of Perpetual Protocol's first vAMM there have been many iterations since, particularly with the price discovery mechanism.
Resources
- Drift: dAMM Deep Dive
- Perpetual Protocol: A deep dive into our vAMM
- Perpetual Protocol: vAMM Documentation
- Perpetual Protocol V2 Design
- On vAMM's unnecessity for liquidity pool
Products
Derivatives
- Concentrated Liquidity and Option Payoffs
- Uniswap V3 LP Tokens as Perpetual Put and Call Options
- Synthetic Options and Short Calls in Uniswap V3
- A Guide for Choosing Optimal Uniswap V3 LP Positions, Part 1
- How to Create Perpetual Options in Uniswap v3
- Understanding the Value of Uniswap v3 Liquidity Positions
- Pricing Uniswap v3 LP Positions: Towards a New Options Paradigm?
- On-chain Volatility and Uniswap v3
- Calculating the Expected Value of the Impermanent Loss in Uniswap
- How to deploy delta-neutral liquidity in Uniswap — or why Euler Finance is a game changer for liquidity providers
- Designing a constant volatility AMM
- Panoptic
- Replicated Market Makers
- Other use cases of AMMs for pricing
Options AMMs
There have been various implementations for an AMM that can be used for buying and selling of options.
Orderbooks
- 0x Protocol
- DyDX
- Serum
- Tonic
- Spin
- Orderly
- Fusotao
- Searcher Limit Order Book
- 1inch Limit Order Protocol
AMMs and Orderbooks
- Just in Time Liquidity
- First posted about in Hacker News by Doug Colkitt
- JIT Liquidity in Crocswap Whitepaper
- Quantifyng ‘Just-in-Time’ liquidity in Uniswap v3
- Impermanent Loss and JIT Liquidity in the Uniswap ETH/USDC 0.3% Pool
- Uniswap V3 JITters
- Uniswap V3 JIT Volume
- Daniel Robinson - Uniswap v3, or How I Learned To Stop Worrying And Love Concentrated Liquidity
- 01 zAMM
- Liquidity deposited by stakers is placed as limit orders on the orderbook following the constant product formula
- Similar to Raydium and Atrix
- How it Works
- Introducing Drift V2: Just in Time Liquidity
Other
- Cowswap
- Crocswap
- TWAMM
- Sovryn
- Blackholeswap
- Proactive Market Makers
- Rainbow Network
- Polymarket
- Augur
- GooseFX
Assorted Reading
- A window into AMM 2.0 — Introducing Volatility Adjusted Fee
- Introducing Volatility-Adjusted Fees
- The Dominance of Uniswap v3 Liquidity
- Uniswap v3: The Universal AMM
- Liquidity Mining on Uniswap v3
- Understanding Automated Market-Makers, Part 1: Price Impact
- An analysis of Uniswap markets
- AMMs as serviced infrastructure
- The Economics of Automated Market Makers
- A General Framework for Impermanent Loss in Automated Market Makers
- Concentrated Liquidity in Automated Market Makers
- Optimal Fees for Geometric Mean Market Makers
- Improved Price Oracles: Constant Function Market Makers
- Optimal Routing for Constant Function Market Makers
- When does the tail wag the dog? Curvature and market making
- Yield Space: An automated Liquidity Provider for Fixed Tokens
- Part 1: A brief overview of 1st generation AMMs
- Part 2: A brief look into 2nd generation AMMs
- Dynamic Curves for Decentralized Autonomous Cryptocurrency Exchanges
- Price Discovery and AMMs
- Automated Market Makers (AMMs): Versioning Up
- Automated Market Makers (Book)