Skip to content

0xperp/awesome-amm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 

Repository files navigation

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

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.

    Constant

  • 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”.

    Stableswap

  • 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.

    Constant Mean

  • 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

    Concentrated Liquidity

    Concentrated Liquidity Distribution

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.

    Front-running Resistance

    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

Swap bridge

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.

Swap bridge call

Resources

Products

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

Products

Derivatives

Options AMMs

There have been various implementations for an AMM that can be used for buying and selling of options.

Orderbooks

AMMs and Orderbooks

Other

Assorted Reading

Awesome Lists

About

Collection of AMMs, Orderbooks, and everything in between

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •