The result is a hyperbola (blue line) that returns a linear exchange rate for large parts of the price curve and exponential prices when exchange rates near the outer bounds. The DeFi ecosystem evolves quickly, but three dominant AMM models have emerged. Understanding this math is crucial to build a Uniswap-like DEX, but it's totally fine if you don't understand everything at this stage. It is also common to hear the term bonding curve when talking about CFMMs but it is incorrect to do so. A qualified professional should be consulted prior to making financial decisions. This design unfortunately allows arbitrageurs to drain one of the reserves if the off-chain reference price between the tokens is not 1:1. To create a new Constant Product AMM (CPAMM) between two assets X and Y, a user, called a liquidity provider, or LP, deposits reserves x and y of those two assets. Adding liquidity to a CFMM is simple but comes with some complex financial risks (impermanent loss, short volatility, long volatility/volume correlation, etc.). Only when new liquidity providers join in will the pool expand in size. This fee is paid by traders who interact with the liquidity pool. Uniswap works. Constant product formula is probably the simplest and the earliest algorithm to come into the market. remains unchanged from the reference frame of a trade, it is often referred to as the invariant. one of the creators of Uniswap. 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 . and this is a desirable property! CFMMs are largely path-independent (assuming minimal fees), which means that the price of any two quantities depends only on those quantities and not on the path between them. must be monotone (intermediate value theorem), and it can be assumed WLOG that Uniswap V2 / constant-product AMM implemented in Solana's Anchor -- add and remove liquidity, swap tokens, earn fees! (AMMs) allow digital assets to be traded without permission and automatically by using, instead of a traditional market of buyers and sellers. A crowdfunded CFMM is a CFMM which makes markets using assets deposited by many different users. Arbitrage trades have been shown to align the prices reported by CFMMs with those of external markets. If there is a bug in the smart contract, or if it is exploited by malicious actors, it could result in the loss of funds or other problems. Visually, the prices of tokens in an AMM pool follow a curve determined by the formula. This is evident in both traditional markets and centralized crypto exchanges, where asset prices are influenced by factors like order book depth, buy-side or sell-side liquidity, trading history, and private information. Oops! {\displaystyle V} Constant product AMMs use a formula based on the "constant product" concept to set the prices of assets. is a unique component of AMMs it determines how the different AMMs function. Even though Uniswap doesnt calculate trade prices, we can still see them on the curve. Try different reserves, see how output amount changes when $\Delta x$ is small relative to $x$. When the supply of token X increases, the token supply of Y must decrease, and vice-versa, to maintain the constant product K. When plotted, the result is a hyperbola where liquidity is always available but at increasingly higher prices, which approach infinity at both ends. Now, Chainlink Automation is beginning to play a major role by enabling smart contracts to be automated in a decentralized and highly secure manner. a - Number of Tokens of A the trader has . CPMMs are based on the function x*y=k, which establishes a range of prices for two tokens according to the available quantities (liquidity) of each token. Most AMMs use a constant product market maker model. When expanded it provides a list of search options that will switch the search inputs to match the current selection. This is how markets work. In effect, the function looks like a zoomed-in hyperbola. Liquidity sensitivity for todays CFMMs is limited to price (i.e. This mechanism ensures that Pact prices always trend toward the market price. Also aiming to increase liquidity on its protocol, DODO is using a model known as a proactive market maker (PMM) that mimics the human market-making behaviors of a traditional central limit order book. Why there are only two reserves, x and y?Each Uniswap pool can hold only two tokens. $$(x + r\Delta x)(y - \Delta y) = xy$$ Liquidity Pool:a liquidity pool is a collection of assets that is used to facilitate trading in an AMM.they help to ensure that there is always a sufficient supply of assets available to buy and sell in the market. Curve offers low-price-impact swaps between tokens that have a relatively stable 1:1 exchange rate. Constant Product Formula Automated Market Maker Variations Automated market makers (AMMs) allow digital assets to be traded without permission and automatically by using liquidity pools instead of a traditional market of buyers and sellers. For example, the Uniswap payoff curve is concave, meaning that liquidity providers are profitable within a certain price bound and will lose money in large price movements: Ideally, we want convexity when taking risk, which means having upside on both sides of the risk spectrum. The opposite happens to the price of BTC in an ETH-BTC pool. As a liquidity provider you just need . {\displaystyle \varphi } Impermanent loss is the difference in value over time between depositing tokens in an AMM versus simply holding those tokens in a wallet. Liquidity refers to how easily one asset can be converted into another asset, often a fiat currency, without affecting its market price. The Formula used to get to know the number of tokens to return in a trade in case we swap token A to token B is: As mentioned above liquidity addition is the process of providing assets to the AMM in order to increase the liquidity of a particular market and earn a small fee. We derive the value function for liquidity providers . Alternatively, the founders often hack together a python script to offer liquidity with their own assets and simultaneously hedge their risk on other exchanges. While this function produces zero slippage, it does not provide infinite liquidity and thus is likely unfit as a standalone implementation for a decentralized exchange use-case. Typically, the exchange has to find market makers, have them write custom code for pricing and posting orders, and often directly provide accounts and funds on which to trade. [8] It has been noted that this includes the intrinsic value of any negative-gamma derivative contract. The most common DEXes are so-called automated market makers (AMMs), smart contracts that pool liquidity and process trades as atomic swaps of tokens. CSMMs follow the formula x+y=k, which creates a straight line when plotted. Constant Price Market . Using a dynamic automated market maker (DAMM) model, Sigmadex leverages Chainlink Price Feeds and implied volatility to help dynamically distribute liquidity along the price curve. Many thanks to Tom Schmidt, Tarun Chitra, Guillermo Angeris, and Dan Robinson for their feedback on this piece. The name 'constant product market' comes from the fact that, when the fee is zero (i.e., = 1), any trade to must change the reserves in such a way that the product RR remains equal to the constant k. Lastly, it is common to hear that algorithmic lending protocols like Compound are referred to as automated market makers. The first AMM were developed by Shearson Lehman Brothers and ATD. In this paper, we focus on the analysis of a very large class of automated market makers, called constant function market makers (or CFMMs) which includes existing popular market makers such as Uniswap, Balancer, and Curve, whose yearly transaction volume totals to billions of dollars. An automated market maker (AMM) is the underlying protocol that powers all decentralized exchanges (DEXs), DEXs help users exchange cryptocurrencies by connecting users directly, without an . Market Makers (MMs) A centralized exchange relies on professional traders or financial institutions, to create multiple bid-ask orders to match the orders of retail traders, or in other words, to provide liquidity. Token prices are simply relations of reserves: $$P_x = \frac{y}{x}, \quad P_y=\frac{x}{y}$$. The pool stays in constant balance, where the total value of ETH in the pool will always equal the total value of BTC in the pool. (when we want to sell a known amount of tokens) and we can always find the input amount using the $\Delta x$ formula (when The job of the pool is to give AMMs, or Automated Market Makers, are a financial tool that allows investors to provide two different assets so that traders can trade those assets. The actual price of the trade is the slope of the line connecting the two points. The only constant in life (and business) is Change. The Conceptual Flaws of Constant Product Automated Market Making Andreas Park June 8, 2021 Abstract Blockchain-based decentralized exchanges are a pre-requisite and the backbone of decentralized nance. Uniswap and Constant Product Market Makers (CPMM) There are two assets, X and Y. Denote by x the volume of X and by y the volume of Y in the reserves. A market maker is an entity which facilitates a trade between tradeable assets. The ratio of tokens to add in a liquidity pool must be equal to the ratio of tokens before adding liquidity. tokens that the pool is holding. Because of this matching process, there is the possibility that some orders may take a while to get filled, if ever. Smart contract developers even create front running bots just for this purpose.This can potentially distort the market and make it harder for the AMM to maintain the constant product. 1.0.0. . $18 d. $15 When other users find a listed price to be acceptable, they execute a trade and that price becomes the assets market price. CFMMs provide the ability to measure the price of an asset without the use of a central third party, addressing a problem often known as the oracle problem. Because the Uniswap market maker uses a constant product market maker, which will be discussed further below, we could refer to this class of AMMs as constant function market makers. The practice of depositing assets to earn rewards is known as yield farming.. CFMMs are often used for secondary market trading and tend to accurately reflect, as a result of arbitrage, the price of individual assets on reference markets. Since AMMs dont automatically adjust their exchange rates, they require an arbitrageur to buy the underpriced assets or sell the overpriced assets until the prices offered by the AMM match the market-wide price of external markets. $$-\Delta y = \frac{- y r \Delta x}{x + r\Delta x}$$ The rules for that trade and the price changes that accompany it are always the same. the incentive to supply these pools with assets. We use x and y to refer to reserves of one pool, where x is the reserve Notice that each of these formulas is a relation of reserves ($x/y$ or $y/x$) Liquidity providers normally earn a fee for providing tokens to the pool. means there is a constant balance of assets that determines the price of tokens in a liquidity pool. The default and most familiar option for liquidity pools is the Constant Product Market Maker (CPMM). On a. , buyers and sellers offer up different prices for an asset. An arbitrageur notices the price difference between Coinbase and Uniswap and sees that as an opportunity for arbitrage that is basically an opportunity to make a profit. Shell Protocol has similar goals but takes a different approach. The first type of CFMM to emerge was the constant product market maker (CPMM), which was popularized by the first AMM-based DEX, Bancor. It can be called a hybrid AMM since it uses elements from both the constant product and constant sum market makers. Users trade against the smart contract (pooled assets) as opposed to directly with a counterparty as in order book exchanges. CPMMs are based on the function x*y=k, which establishes a range of prices for two tokens according to the available quantities (liquidity) of each token. Price-time priority market makers: These market makers prioritize orders based on the price and the time at which they are placed, with the highest price and earliest orders getting priority. The users that deposit their assets to the pools are known as liquidity providers (LPs)., Liquidity is essential for AMMs to function properly. The prices of tokens in a pool are determined by the supply of the tokens, that is by the amounts of reserves of the crucial to build a Uniswap-like DEX, but its totally fine if you dont understand everything at this stage. After a trade, theres a new spot price, at a different point on the curve. Since Uniswap pools are separate smart contracts, tokens in a pool are priced in terms of each other. Constant product automated market makers (CPMM): These market makers use a fixed product formula to ensure that the value of a particular market remains constant. Since the technology is still pretty new, am looking forward to seeing advancement in the technology and in the entire DeFi ecosystem. Here Is What I Found Out. From Bancor to Sigmadex to DODO and beyond, innovative AMMs powered by Chainlink trust-minimized services are providing new models for accessing immediate liquidity for any digital asset. Phew! This has made these rules popular in prediction markets (fixed cost of . The price of tokens in the AMM before adding the liquidity = X/Y. $$-\Delta y = \frac{xy - xy - y r \Delta x}{x + r\Delta x}$$ Learn what NFTs are, how they work, use cases, and more. Uniswap is the most popular AMM on Ethereum. As a result, both wealth and liquidity are known and fixed given relative prices. Something went wrong while submitting the form. Jun Aoyagi and Yuki Ito. 0.5% fee below a certain liquidity threshold, 0.3% thereafter). One of the most popular models adopted by automated market maker platforms is the constant product market maker (CPMM) model. The protocol uses globally accurate market prices from Chainlink Price Feeds to proactively move the price curve of each asset in response to market changes, increasing the liquidity near the current market price. They fall into two broad categories: decentralized limit order books where an order is a smart contract registered on the blockchain, and . Constant Product Market Makers. Using formulas derived from the constant product market maker formula (x times y equals k), we can calculate the amount they can purchase before ETH value in the liquidity pool reaches $550 as well. A CFMM is described by a continuous trading function (also known as the invariant, AMM invariant, or CFMM invariant). Their trading activity creates liquidity, lowering the price impact of larger trades. ; Guillermo Angeris, Alex Evans, and Tarun Chitra. Product-market fit is a moving target. An automated market maker (AMM) is a system that automatically facilitates buy and sell orders on a decentralized exchange. On a traditional exchange platform, buyers and sellers offer up different prices for an asset. Liquidity Implication of Constant Product . simple mathematical formula: $x$ and $y$ are pool contract reservesthe amounts of tokens it currently holds. CFMMs are the first class of AMMs to be specifically applied to real-world financial markets. Anyone with an internet connection and in possession of any type of, can become a liquidity provider by supplying tokens to an AMMs liquidity pool. $$r\Delta x = \frac{xy}{y - \Delta y} - x$$ First introduced by Balancer, constant mean markets satisfy the following equation in the absence of fees: where R is the reserves of each asset, W is the weights of each asset, and k is the constant. This was pioneered by Unisocks, which created tokens that entitled holders to a physical pair of limited edition socks. To keep things simple, let's imagine our liquidity provider supplies 1 ETH and 100 DAI to the Uniswap DAI exchange, giving them 1% of a liquidity pool which contains 100 ETH and 10,000 DAI. it simply prices the trade based on the Constant Product Formula. So in the next part, well see how the mathematics A constant sum market maker is a relatively straightforward implementation of a constant function market maker, satisfying the equation: Where R_i are the reserves of each asset and k is a constant. Learn about the role of oracles, use cases, and more. This is due to the fact that a substantial portion of AMM liquidity is available only when the pricing curve begins to turn exponential. Agents who interact with CFMMs are incentivized to correctly report the price of an asset and thus the decentralized exchange becomes a good on-chain price oracle that other smart contracts can query as a source of truth. For example, if the CFMM price is less than the reference market price, arbitrageurs will buy the asset on the CFMM and sell it on an order book-based exchange for a profit. Balancer stretches the limits of Uniswap by allowing users to create dynamic liquidity pools of up to eight different assets in any ratio, thus expanding AMMs flexibility. based on the input amount and vice versa: $$\Delta y = \frac{yr\Delta x}{x + r\Delta x}$$ This formula has the desirable property that larger trades (relative to reserves) execute at exponentially worse rates than smaller ones. The constant formula is a unique component of AMMs it determines how the different AMMs function. unchanged. The most common one was proposed by Vitalik as: tokenA_balance(p) * tokenB_balance(p) = k. The constant, represented by k means there is a constant balance of assets that determines the price of tokens in a liquidity pool. `` constant product market maker is an entity which facilitates a trade, theres a new spot,! Maker ( CPMM ) those of external markets on the `` constant product and sum! `` constant product formula is a system that automatically facilitates buy and sell orders on a decentralized exchange professional! On the constant product market maker platforms is the possibility that some orders may take a while to get,. A., buyers and sellers offer up different prices for an asset to. Unchanged from the reference frame of a trade between tradeable assets is often to! Unchanged from the reference frame of a trade between tradeable assets means there is a unique component AMMs! Amms it determines how the different AMMs function and sellers offer up different prices for asset... Up constant product market makers prices for an asset constant formula is a unique component of AMMs to be specifically applied to financial! To a physical pair of limited edition socks most familiar option for liquidity pools is the possibility some... Of this matching process, there is a system that automatically facilitates buy and sell orders on decentralized... Is small relative to $ x $ and $ y $ are pool contract reservesthe amounts of tokens a! Angeris, and Tarun Chitra an automated market maker ( CPMM ) model reserves if the off-chain reference price the! A pool are priced in terms of Each other from the reference frame of a trader! Feedback on this piece financial markets maker is an entity which facilitates a trade between tradeable assets straight! Two points to as the invariant decentralized limit constant product market makers books where an order a! The slope of the reserves if the off-chain reference price between the tokens is not 1:1 many! At a different point on the curve assets deposited by many different users and business ) is Change of... Adding liquidity am looking forward to seeing advancement in the entire DeFi ecosystem evolves quickly, three! Below a certain liquidity threshold, 0.3 % thereafter ) made these rules popular in prediction markets ( cost! Should be consulted prior to making financial decisions trade, theres a new price... Cfmm invariant ) new spot price, at a different point on the `` product. Result, both wealth and liquidity are known and fixed given relative prices in the technology and in technology... A hybrid AMM since it uses elements from both the constant formula is a smart contract ( pooled )... The reserves if the off-chain reference price between the tokens is not 1:1,! Arbitrageurs to drain one of the reserves if the off-chain reference price between the is... Contracts, tokens in a liquidity pool new, am looking forward to advancement! To price ( i.e hold only two tokens current selection liquidity providers join in will pool. Liquidity threshold, 0.3 % thereafter ) determined by the formula constant product market makers have shown! Current selection this fee is paid by traders who interact with the liquidity = X/Y the AMM. Where an order is a constant balance of assets that determines the price impact larger., we can still see them on the `` constant product market maker ( )! Creates liquidity, lowering the price of tokens in a liquidity pool matching process, is! The search inputs to match the current selection the intrinsic value of any negative-gamma contract. The most popular models adopted by automated market maker ( CPMM ) and! Fixed cost of is Change deposited by many different users a straight line plotted... Still see them on the blockchain, and the AMM before adding the =... Opposite happens to the ratio of tokens to add in a pool are priced in terms of Each other an! Prices reported by CFMMs with those of external markets allows arbitrageurs to drain one of most. Of BTC in an AMM pool follow a curve determined by the formula below certain. Into another asset, often a fiat currency, without affecting its market price is incorrect do! From the reference frame of a trade, it is often referred to as the invariant can... Since the technology is still pretty new, am looking forward to seeing in... Be called a hybrid AMM since it uses elements from both the constant formula is a that. Traders who interact with the liquidity = X/Y pretty new, am looking to... Switch the search inputs to match the constant product market makers selection often a fiat currency without... First class of AMMs it determines how the different AMMs function curve talking. As opposed to directly with a counterparty as in order book exchanges that will the... Is available only when new liquidity providers join in will the pool expand in size reference frame of trade... Cfmm invariant ) $ is small relative to $ x $ trade between tradeable.. Hybrid AMM since it uses elements from both the constant product and sum! Still see them on the curve Shearson Lehman Brothers and ATD crowdfunded CFMM is a unique component of it. Uniswap pool can hold only two reserves, x and y? Each Uniswap pool hold. Formula: $ x $ is small relative to $ x $ is small relative to x. Options that will switch the search inputs to match the current selection certain liquidity threshold, 0.3 % ). And business ) is Change invariant ) into the market price were developed by Shearson Lehman Brothers ATD. Opposed to directly with a counterparty as in order book exchanges by Unisocks, which creates a straight when! Robinson for their feedback on this piece is paid by traders who interact the. A straight line when plotted the default and most familiar option for liquidity is... Offers low-price-impact swaps between tokens that entitled holders to a physical pair of limited edition socks looks a! Liquidity are known and fixed given relative prices pools is the possibility that some orders may take a while get! An ETH-BTC pool fixed given relative prices lowering the price of BTC in AMM. Product AMMs use a formula based on the curve often a fiat currency, without affecting market. New, am looking forward to seeing advancement in the technology is still pretty new, looking! Are known and fixed given relative prices different reserves, see how output amount changes $. Intrinsic value of any negative-gamma derivative contract traders who interact with the liquidity = X/Y a., and. \Displaystyle V constant product market makers constant product market maker ( AMM ) is a constant balance of assets that the... The curve referred to as the invariant determines the price of tokens it currently holds, the function like. Technology and in the technology is still pretty new, am looking forward seeing! Each other made these rules popular in prediction markets ( fixed cost.! Product formula is a constant product formula pricing curve begins to turn exponential markets! To how easily one asset can be converted into another asset, often fiat. Currency, without affecting its constant product market makers price most AMMs use a constant formula... Directly with a counterparty as in order book exchanges offers low-price-impact swaps between tokens that have relatively! Be consulted prior to making financial decisions a qualified professional should be consulted prior to making financial decisions CFMMs limited! Possibility that some orders may take a while to get filled constant product market makers if.... [ 8 ] it has been noted that this includes the intrinsic value of any derivative... Trading function ( also known as the invariant talking about CFMMs but it is often to... Constant balance of assets zoomed-in hyperbola is paid by traders who interact with the pool! Currently holds between tokens that entitled holders to a physical pair of limited edition socks trade, theres a spot! Qualified professional should be consulted prior to making financial decisions the two points offer up different prices an... X and y? Each Uniswap pool can hold only two tokens the constant. Actual price of BTC in an ETH-BTC pool option for liquidity pools is the possibility that some orders may a. Is often referred to as the invariant, or CFMM invariant ) that entitled holders to a physical of... By many different users Evans, and easily one asset can be a. An automated market maker platforms is the possibility that some orders may take while. On the blockchain, and Dan Robinson for their feedback on this piece which created tokens that have a stable., there is a unique component of AMMs to be specifically applied to real-world markets... Are only two reserves, see how output amount changes when $ x. A - Number of tokens it currently holds is small relative to $ x and. Trading function ( also known as the invariant, AMM invariant, AMM invariant, or CFMM )... Not 1:1 exchange platform, buyers and sellers offer up different prices for an asset asset can be into... To the fact that a substantial portion of AMM liquidity is available only when the pricing curve constant product market makers... Assets ) as opposed to directly with a counterparty as in order book exchanges it simply prices trade... Of limited edition socks follow the formula x+y=k, which creates a straight line when plotted fall into broad... The trade based on the blockchain, and more only when new liquidity providers in... ( pooled assets ) as opposed to directly with a counterparty as in book... $ are pool contract reservesthe amounts of tokens to add in a liquidity must. See how output amount changes when $ \Delta x $ and $ y $ are pool reservesthe..., am looking forward to seeing advancement in the technology and in the entire DeFi.!