paint-brush
Automated Market Makers: What You Need to Knowby@talktomaruf
1,230 reads
1,230 reads

Automated Market Makers: What You Need to Know

by Abubakar MarufJune 8th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The advent of DeFi is becoming a broader gateway to newer use cases in the crypto world. Even naysayers that initially thought DeFi to be an overhyped aspect of finance are biting their fingers for not joining the ride early. Although trading is 24/7 on DeFi, there's a protocol yet to be fully exploited by many users; or rather not widely known in DeFi. The protocol that allows users to transact directly with the smart contract is none other than the Automated Market Maker— AMM. It relies on a mathematical algorithm to peg a price for assets.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Automated Market Makers: What You Need to Know
Abubakar Maruf HackerNoon profile picture

The advent of DeFi is perpetually becoming a broader gateway to newer use cases in the crypto world. Even naysayers that initially thought DeFi to be an overhyped aspect of finance or a bubble that will fade away are biting their fingers for not joining the ride early.


Decentralized finance hitherto has kept its promise of decentralization in the financial system by disintermediating the giant centralized finance behemoths or intermediaries in the financial ecosystem as it portrays. No doubt, you can conduct P2P financial transactions on DeFi without interference from any party.


What if there is no one to trade with?


Although trading is 24/7 on DeFi, there's a protocol yet to be fully exploited by many users; or rather not widely known in DeFi. The protocol runs on a P2C—peer-to-contract—protocol where you deal directly with the smart contract (a self-enforcing automated strings of code- chiefly written in Solidity).


Do you fear that a smart can outsmart you?


A smart contract is a self-executing and predefined set of rules encoded in a computer programing to take action when the predefined condition has been met. It aims to create a trustless ecosystem where you have to trust the smart contract to act unbiased, favoring each party in a transaction.


So, if you can trust a smart contract for a favorable transaction, you should trust it that it can't con you.


The protocol that allows users to transact directly with the smart contract is none other than the Automated Market Maker— AMM.

What is an Automated Market Maker?

AMM is a decentralized exchange protocol—DEX—allowing users to deal directly with the smart contract. It relies on a mathematical algorithm to peg a price for assets. AMM is the DeFi version of the conventional "Order book" known with CEXes—centralized exchanges which use the matching engine to match orders.


The order book depicts a list of buying and selling orders for security, including the order history. It is developed to use smart contracts to mathematically set a price for assets.


Rather than using the conventional order book, AMM uses a pricing algorithm or formula to price assets. The formula is:


x * y = k


"x and y" are the amounts of respective tokens in liquidity, while constant "k" is the total amount of liquidity in the pool, which must always remain constant.


The above formula varies for each kind of AMMs protocol, as known with different platforms that utilize AMM like Bancor, Uniswap, Curve, and their ilk.



Before delving into the kinds of AMM, let's take a brief dive into the liquidity pool.

What is Liquidity Pool?

Liquidity generally refers to the seamless conversion of something—preferably an asset—to cash. In the crypto world, liquidity is the easiness of exchanging a token with another. On the other hand, a pool can be regarded as a gathering of entities or corporations formed to transact a particular or promote their common interest.


So, a liquidity pool refers to a pool or collection of crypto assets locked in a smart contract to enable trading crypto assets by providing users with the liquidity needed. It is the spine of DEX platforms where AMM is deployed to allow for users to become market makers.


Investors who pool their assets together for mutual benefits are known as Liquidity providers—LPs. They contribute a corresponding amount of two tokens—a stablecoin and any other unstable cryptocurrency or any pair of unstable cryptos—to a pool.

How Do LPs Earn Interest From Their Pooled Assets?

LPs are understandably the financers of AMM, and they earn interest via liquidity mining. By contributing their crypto asset to the pool, LPs earn interest from the trading fees charged to traders who trade within the pool.


Earnings are usually proportional to their contribution to the pool, i.e., they earn with respect to their share in the pool. For example, if a liquidity provider contributes 10% of the liquidity, such an LP will always get 10% of each trading fee.

Types of Automated Market Maker


There are two generations of the AMM:


  • First Generation: Constant Function Market Makers—CFMMs.
  • Second Generation

Constant Function Market Makers—CFMMs.

This is the first generation of AMM, where exchanges are established on a constant function such that the total asset or token reserved for trading pairs—liquidity pool—must remain constant in the smart contract where it is locked. Examples of CFMMs are:

Constant Product Market Maker—CPMM.

This model of CFFMs is established on the general algorithm x * y =k, which sets a range of prices for the paired tokens according to the quantities of each token available in the liquidity. If the supply of token x increases, the collection of token y must fall, and vice versa.


As the case may be, this simultaneous rise and fall of tokens are to sustain the constant k, which is the total amount of liquidity in the pool. When plotted, the result of this rise and fall is hyperbola such that liquidity is invariably available at ever-increasing prices that approach infinity on both ends. This model is notable with Bancor and also used by Uniswap.


Constant Sum Market Maker (CSMM)

This model is established on the formula x + y=k. This creates a straight line when plotted.


If the off-chain reference price between tokens x and y is not 1:1, two interwoven events are bound to happen:


  • The token with the higher quantity in the pool will be cheaper than the other token, and its price will go bullish. This will open an arbitrage window for arbitragers who will drain the cheaper token.

  • In the course of arbitrage, the cheaper token side of the pool will fall because all liquidity will shift to the other asset, leaving no liquidity for traders anymore.


The above events are why this model is hardly used. CSSM is suitable for trades with zero price impact but does not offer unlimited liquidity.

Constant Mean Market Maker (CMMM)

Balancer first introduced this model; it allows the development of AMMs with more than two tokens and weightings other than the conventional 50/50 distribution. Each reserve's weighted geometric mean remains constant.


Equation i is applicable for a liquidity pool with three tokens, while equation ii applies for four tokens. This facilitates swaps between any pool's assets and allows for varying exposure to different assets in the pool.

Advantages of Constant Function Market Makers

  • Fast and seamless exchange.
  • It enables traders to determine the price of a token without relying on third parties.

Traders do not need a cumbersome plan to make trades because they obtain the same price by participating all at once as they would from a series of modest trades.

Limitations of Constant Function Market Makers

  • Low/Limited capital power.
  • Complex financial risks like slippage, impermanent loss, short volatility, long volatility, etc.

What is Slippage?

Slippage is the discrepancy between the projected price of an order and the actual price when the order is eventually executed. The volatility of cryptocurrency causes crypto tokens to waver based on trading activities and volume. The slippage percentage indicates how much a particular asset's price has changed.

What is Impermanent Loss?

An Impermanent loss is a gross difference between the values of paired crypto tokens in AMM's liquidity pool. It is due to the contrasting value over time between depositing tokens in AMM and simply holding the tokens in your wallet. For instance, when you contribute to a pool of liquidity by depositing tokens, and the price of such tokens changes after a few minutes, hours, or days, the sum of money lost due to such changes is referred to as impermanent loss.

Second Generation of AMM

The Second Generation of AMMs is a series of novel projects with innovative blueprints that aim to address the limitations of the first generation of AMM.

They include:


  • Hybrid Automated Market Makers (HAMM)
  • Dynamic Automated Market Makers (DAMM)
  • Proactive Market Makers (PMM)
  • Virtual Automated Market Makers (VAMM)

Hybrid Automated Market Makers (HAMM)

Hybrid automated market makers are also termed Hybrid CFMM because it incorporates diverse functions and parameters to achieve certain features like reduced price impact for traders and reduced risk exposure for LPs.


HAMM uses an exchange rate curve that is generally linear and becomes parabolic only when the liquidity pool is pushed to its limits, allowing for extremely low price-impact trades. Because capital is used more efficiently, LPs earn more in charges—though on a reduced fee per-trade basis—yet arbitragers still benefit from rebalancing the pool.


An example of HAMM is the Curve finance AMMs which incorporate both CPMM and CSMM. Curve AMMs use an advanced formula to incorporate a CPMM and a CSMM to produce deeper liquidity pockets that reduce price impact within a specified range of trades.


The outcome is a hyperbola curve—blue line—with a linear exchange rate for most of the price curve and exponential prices near the outer bounds of the exchange rate.


Curve finance lets users make low-cost swaps between tokens with a generally stable 1:1 exchange rate. This indicates that its solution is primarily intended for stablecoins.

Dynamic Automated Market Makers (DAMM)

DAMM incorporates multiple dynamic variables into its formula to create a more substantial market maker that accommodates changing market conditions. Summarily, DAMM uses real-time price feed to ceaselessly and automatically adjust the pool price to the market price, giving no room for arbitragers.


An example of DAMM use cases is its integration in Sigmadex, which uses price feeds from Chainlink, alongside estimated volatility, to help distribute liquidity dynamically along the price curve. DAMM makes Sigmadex flexible.


Sigmadex can concentrate liquidity near the market price during low volatility to improve capital efficiency, and then expand it during high volatility to protect traders from impairment loss.

Proactive Market Maker (PMM)

PMM is a highly configured algorithm with active price discovery. This algorithm is adopted by DODO, which is capable of anticipating market conditions and proactively altering parameters such as asset ratio and curve slope, resulting in DODO pools that are flexible and adaptable for various use cases.


The DODO's PMM model can be configured to use external price oracles to minimize impermanent loss and achieve greater capital efficiency.

DODO's PMM uses the formula below


  • B = Base token (ask- side liquidity)
  • Q = Quote tokens (bid-side liquidity)
  • B0 = Original base tokens
  • Q0 = Original quote tokens
  • K = Configurable pool metric as mid-price
  • Pa = Price of token A
  • Pb = Price of token B

Virtual Automated Market Makers (VAMM)

Virtual Automated Market Maker is another novel type of AMM that extends its use case beyond token swaps to derivatives like perpetual contracts. Recall that the AMM has to do with token swap in DEXes; in the case of VAMMs, virtual assets, otherwise known as synthetic assets, are swapped instead of real tokens because there are no real tokens in the VAMMs.


Traders can only make leveraged trades based on collateral held in a smart contract. Rather than trading underlying assets, users trade synthetic assets and access the price movement of a wide range of crypto assets.


Users holding onto an open position in synthetic assets are prone to having their collateral liquidated should the price swing against them. The concept of VAMMs is to reduce price impact and impermanent loss and expose single tokens to synthetic assets.

Conclusion

AMM sought to offer a modernized order book on the decentralized ecosystem. As its use cases were being unraveled, it exhibited a perpetual development that gave rise to the first and second generations of AMM.


The second generation of AMM addresses the limitations of the first generation by trying to mitigate price impact and impermanent loss. In a particular case, it cancels out impermanent loss.


Photo by Possessed Photography on Unsplash