11/11/2022
in-depthDeFiTrading and investment

in-depthDeFiTrading and investment
Main
Automated Market Maker (AMM) is a software algorithm for controlling liquidity and pricing crypto assets on decentralized exchanges.
AMM systems are widely used in the DeFi space, in particular on decentralized exchanges (DEXs) such as Uniswap, Balancer, Bancor and Curve.
To create decentralized markets, AMM uses liquidity in cryptocurrency public pools of several tokens locked in special smart contracts.
How did the automatic market maker (AMM) appear?
The Automated Market Maker (AMM) is an offline trading mechanism that powers most DeFi trading protocols. It ensures the movement of capital and the execution of exchange operations of users in the available crypto asset markets.
The first known developer to talk about implementing AMM was Alan Liu, a member of the Gnosis project team. His ideas were outlined Ethereum founder Vitalik Buterin on Reddit in 2016 and in personal blog in July 2017.
This concept formed the basis of the protocol of the Uniswap platform, received the first $100,000 grant from the Ethereum Foundation. In addition, Vitalik Buterin advised Uniswap developers.
Subsequently, AMM became widely known precisely thanks to Uniswap. At the same time, one of the first successful implementations of AMM is the Bancor Network platform, which raised $140 million through an ICO in June 2017.
How are liquidity pools related to AMM?
The key element necessary for the operation of AMM is the liquidity pool – a kind of storage of crypto assets in the form of a smart contract. The liquidity pool usually consists of two crypto assets and forms a market – an analogue of a trading pair on a centralized exchange.
Some pool members block their funds to generate income through exchange fees. Such users are called liquidity providers.
Another category is the direct users of the decentralized exchange, who exchange cryptocurrencies in the protocol (such operations are called “swap”) using one of the pools.
To better understand liquidity pools, consider what led to their creation.
The first DEX exchanges ran on Ethereum and traded on the standard order book used on centralized exchanges. For such a trading mechanism to be effective, it must have an extremely high transaction processing speed. Considering that transactions on a decentralized exchange are confirmed through the blockchain, the real speed and capabilities of such DEXs were extremely limited. AMM provided a solution to this problem.
Thus, AMM is a fundamentally different way to create an asset market, being a formula or rules according to which the protocol works with orders to buy or sell, as well as with user reserves.
How do liquidity pools work?
Pools can use two or more assets. For example, on the Uniswap exchange, you can create pools for paired tokens. The Balancer platform allows you to create pools for three or more tokens. And the Curve protocol is for asset-based pools with a similar value, such as ETH and a wrapped WETH token, or USDC and DAI. The operation of these pools is regulated by the AMM.
Each of these AMM-DEXs may use their own formulas and rules to interact with liquidity pools. For example, the Uniswap protocol uses the following formula: x * y = k.
In the equation, x and y represent the number of tokens available in the liquidity pool; k is a constant value called the invariant. In the case of Curve, the formulas x * y = k and x + y = k are used.
According to the formula x * y = k, the SushiSwap and PancakeSwap projects also work – this is the most common type of AMM-DEX.
How is an asset priced in a liquidity pool?
When liquidity is blocked in a pool, its provider receives special LP tokens confirming their share in the pool. They can be thought of as an IOU, the possession of which entitles you to receive commissions from exchange transactions on the exchange and return your share from the pool.
LP tokens are a transferable crypto asset that can be sold or exchanged on the open market, as well as invested in third-party DeFi applications.
The process of exchanging one asset for another through a liquidity pool is called a swap. The essence of the process is to add only one asset to the pool, instead of two, as is the case with LP. For conducting a swap, the pool charges a small commission, comparable to the commission for a transaction on a centralized exchange, that is, 0.1-0.3%. Commissions are distributed among liquidity providers in proportion to their share in the pool.
Example
Let’s create a conditional liquidity pool for the ETH/USDC pair. At a price of 1 ETH equal to 2000 USDC, it will be necessary to simultaneously block any number of these two coins in a smart contract in a ratio of 1:2000. At this price, the pool can have 100 ETH and 200,000 USDC.
The balance of assets in the pool is determined by their price. When the user decides to exchange 10 ETH using the pool described above, he will deposit his coins into the smart contract in a regular transaction. In exchange for his 10 ETH, he will receive 20,000 USDC (excluding exchange fees).
After this exchange, the pool balance will already be 110 ETH and 180,000 USDC. Therefore, the price of ETH in this particular pool will be around 1636 USDC instead of 2000 USDC in other markets. This situation attracts arbitrage traders who take advantage of the imbalance by adding USDC to the pool until the price reaches the market price of 2,000 USDC per 1 ETH.
What are the disadvantages of AMM?
Although AMM has been a breakthrough for trading and DeFi, it has a number of clear disadvantages. First, there is a high risk of price slippage when making swaps using AMM. In turn, this leads to risks of intermittent losses for LP and miner extractable value (MEV) for ordinary users.
To protect against such risks, other types of AMM are being created, such as the CowSwap project, which combines the developments of AMM-Balancer and the Gnosis protocol.
Secondly, unlike centralized exchanges, when trading through AMM, you can place only one type of orders. Limit orders or other types, such as Stop Loss, cannot be traded.
What is Impermanent Loss?
Intermittent losses (Impermanent Loss, IL) are temporary or unrealized losses when holding assets in the liquidity pool when using AMM-DEX. IL refers to Liquidity Providers (LPs), meaning the difference in price at the time the tokens were locked in the pool and the actual price at the time they were held. Losses are called unrealized because they are not fixed until the liquidity is withdrawn from the pool.
As an example, let’s take the liquidity pool on the Uniswap exchange, which works according to the classic formula x * y = k:
- The liquidity provider has locked 1 ETH and 2000 DAI. His share in the pool was 10%.
- In total, the pool contains 10 ETH and 20,000 DAI – the equivalent of 40,000 DAI.
- The pool balance did not change as there were no new liquidity providers.
- Let’s say the market price of ETH changes to 4000 DAI.
- Then arbitrage traders took advantage of the situation and changed the ratio in the pool by 5 ETH on the one hand and 20,000 DAI on the other. At the same time, the total pool size remained the original – 40,000 DAI.
- At this moment, the liquidity provider decided to withdraw its share from the pool – it is 10%.
- Given the current pool balance, he withdraws 0.5 ETH and 2000 DAI, although he initially added 1 ETH and 2000 DAI.
- The initial value of his share was 4000 DAI (1 ETH plus 2000 DAI) in terms of stablecoins. The value of assets at the time of withdrawal was the same 4000 DAI (0.5 ETH plus 2000 DAI)
- However, if the user were to simply hold their 1 ETH and 2,000 DAI, their asset value would be 6,000 DAI. This is the unrealized loss or gain when using AMM-DEX.
- The user will also receive 10% (proportional to their stake in the pool) of all pool fees as a reward for providing liquidity. The reward may be reduced, for example, due to taxes deducted to the developers or to the project treasury for future development.
This is a conditional example of a sharp increase in the price of one asset by 50%, without taking into account the many transactions of arbitrage traders and the time required to equalize the price.
an asset inside a pool with a price on centralized exchanges, where changes occur instantly.
With a “calm” market flow, variable movements are added to the calculation of non-permanent losses, as described in his blog StarkNet developer Pēteris Erins. As a result of these predictive calculations, the value of Impermanent Loss on a two-fold movement in the asset price will be about 5.7%. But this is only a forecast value – potential “losses” are very difficult to predict.
How to reduce risks when trading with AMM?
Before using the liquidity pool, you should calculate all possible commissions that you will have to pay at the time of depositing and planned withdrawal of assets.
It is necessary to take into account the possibility of asset price movement in both directions. Some potential issues, such as the risk of intermittent loss (IL), can be calculated in advance.
To calculate the IL indicator, you need to understand the nature of its origin. You can also use one of calculators non-permanent losses available on the Internet.
Found a mistake in the text? Select it and press CTRL+ENTER
Cryplogger Newsletters: Keep your finger on the pulse of the bitcoin industry!
11/11/2022
in-depthDeFiTrading and investment

in-depthDeFiTrading and investment
Main
Automated Market Maker (AMM) is a software algorithm for controlling liquidity and pricing crypto assets on decentralized exchanges.
AMM systems are widely used in the DeFi space, in particular on decentralized exchanges (DEXs) such as Uniswap, Balancer, Bancor and Curve.
To create decentralized markets, AMM uses liquidity in cryptocurrency public pools of several tokens locked in special smart contracts.
How did the automatic market maker (AMM) appear?
The Automated Market Maker (AMM) is an offline trading mechanism that powers most DeFi trading protocols. It ensures the movement of capital and the execution of exchange operations of users in the available crypto asset markets.
The first known developer to talk about implementing AMM was Alan Liu, a member of the Gnosis project team. His ideas were outlined Ethereum founder Vitalik Buterin on Reddit in 2016 and in personal blog in July 2017.
This concept formed the basis of the protocol of the Uniswap platform, received the first $100,000 grant from the Ethereum Foundation. In addition, Vitalik Buterin advised Uniswap developers.
Subsequently, AMM became widely known precisely thanks to Uniswap. At the same time, one of the first successful implementations of AMM is the Bancor Network platform, which raised $140 million through an ICO in June 2017.
How are liquidity pools related to AMM?
The key element necessary for the operation of AMM is the liquidity pool – a kind of storage of crypto assets in the form of a smart contract. The liquidity pool usually consists of two crypto assets and forms a market – an analogue of a trading pair on a centralized exchange.
Some pool members block their funds to generate income through exchange fees. Such users are called liquidity providers.
Another category is the direct users of the decentralized exchange, who exchange cryptocurrencies in the protocol (such operations are called “swap”) using one of the pools.
To better understand liquidity pools, consider what led to their creation.
The first DEX exchanges ran on Ethereum and traded on the standard order book used on centralized exchanges. For such a trading mechanism to be effective, it must have an extremely high transaction processing speed. Considering that transactions on a decentralized exchange are confirmed through the blockchain, the real speed and capabilities of such DEXs were extremely limited. AMM provided a solution to this problem.
Thus, AMM is a fundamentally different way to create an asset market, being a formula or rules according to which the protocol works with orders to buy or sell, as well as with user reserves.
How do liquidity pools work?
Pools can use two or more assets. For example, on the Uniswap exchange, you can create pools for paired tokens. The Balancer platform allows you to create pools for three or more tokens. And the Curve protocol is for asset-based pools with a similar value, such as ETH and a wrapped WETH token, or USDC and DAI. The operation of these pools is regulated by the AMM.
Each of these AMM-DEXs may use their own formulas and rules to interact with liquidity pools. For example, the Uniswap protocol uses the following formula: x * y = k.
In the equation, x and y represent the number of tokens available in the liquidity pool; k is a constant value called the invariant. In the case of Curve, the formulas x * y = k and x + y = k are used.
According to the formula x * y = k, the SushiSwap and PancakeSwap projects also work – this is the most common type of AMM-DEX.
How is an asset priced in a liquidity pool?
When liquidity is blocked in a pool, its provider receives special LP tokens confirming their share in the pool. They can be thought of as an IOU, the possession of which entitles you to receive commissions from exchange transactions on the exchange and return your share from the pool.
LP tokens are a transferable crypto asset that can be sold or exchanged on the open market, as well as invested in third-party DeFi applications.
The process of exchanging one asset for another through a liquidity pool is called a swap. The essence of the process is to add only one asset to the pool, instead of two, as is the case with LP. For conducting a swap, the pool charges a small commission, comparable to the commission for a transaction on a centralized exchange, that is, 0.1-0.3%. Commissions are distributed among liquidity providers in proportion to their share in the pool.
Example
Let’s create a conditional liquidity pool for the ETH/USDC pair. At a price of 1 ETH equal to 2000 USDC, it will be necessary to simultaneously block any number of these two coins in a smart contract in a ratio of 1:2000. At this price, the pool can have 100 ETH and 200,000 USDC.
The balance of assets in the pool is determined by their price. When the user decides to exchange 10 ETH using the pool described above, he will deposit his coins into the smart contract in a regular transaction. In exchange for his 10 ETH, he will receive 20,000 USDC (excluding exchange fees).
After this exchange, the pool balance will already be 110 ETH and 180,000 USDC. Therefore, the price of ETH in this particular pool will be around 1636 USDC instead of 2000 USDC in other markets. This situation attracts arbitrage traders who take advantage of the imbalance by adding USDC to the pool until the price reaches the market price of 2,000 USDC per 1 ETH.
What are the disadvantages of AMM?
Although AMM has been a breakthrough for trading and DeFi, it has a number of clear disadvantages. First, there is a high risk of price slippage when making swaps using AMM. In turn, this leads to risks of intermittent losses for LP and miner extractable value (MEV) for ordinary users.
To protect against such risks, other types of AMM are being created, such as the CowSwap project, which combines the developments of AMM-Balancer and the Gnosis protocol.
Secondly, unlike centralized exchanges, when trading through AMM, you can place only one type of orders. Limit orders or other types, such as Stop Loss, cannot be traded.
What is Impermanent Loss?
Intermittent losses (Impermanent Loss, IL) are temporary or unrealized losses when holding assets in the liquidity pool when using AMM-DEX. IL refers to Liquidity Providers (LPs), meaning the difference in price at the time the tokens were locked in the pool and the actual price at the time they were held. Losses are called unrealized because they are not fixed until the liquidity is withdrawn from the pool.
As an example, let’s take the liquidity pool on the Uniswap exchange, which works according to the classic formula x * y = k:
- The liquidity provider has locked 1 ETH and 2000 DAI. His share in the pool was 10%.
- In total, the pool contains 10 ETH and 20,000 DAI – the equivalent of 40,000 DAI.
- The pool balance did not change as there were no new liquidity providers.
- Let’s say the market price of ETH changes to 4000 DAI.
- Then arbitrage traders took advantage of the situation and changed the ratio in the pool by 5 ETH on the one hand and 20,000 DAI on the other. At the same time, the total pool size remained the original – 40,000 DAI.
- At this moment, the liquidity provider decided to withdraw its share from the pool – it is 10%.
- Given the current pool balance, he withdraws 0.5 ETH and 2000 DAI, although he initially added 1 ETH and 2000 DAI.
- The initial value of his share was 4000 DAI (1 ETH plus 2000 DAI) in terms of stablecoins. The value of assets at the time of withdrawal was the same 4000 DAI (0.5 ETH plus 2000 DAI)
- However, if the user were to simply hold their 1 ETH and 2,000 DAI, their asset value would be 6,000 DAI. This is the unrealized loss or gain when using AMM-DEX.
- The user will also receive 10% (proportional to their stake in the pool) of all pool fees as a reward for providing liquidity. The reward may be reduced, for example, due to taxes deducted to the developers or to the project treasury for future development.
This is a conditional example of a sharp increase in the price of one asset by 50%, without taking into account the many transactions of arbitrage traders and the time required to equalize the price.
an asset inside a pool with a price on centralized exchanges, where changes occur instantly.
With a “calm” market flow, variable movements are added to the calculation of non-permanent losses, as described in his blog StarkNet developer Pēteris Erins. As a result of these predictive calculations, the value of Impermanent Loss on a two-fold movement in the asset price will be about 5.7%. But this is only a forecast value – potential “losses” are very difficult to predict.
How to reduce risks when trading with AMM?
Before using the liquidity pool, you should calculate all possible commissions that you will have to pay at the time of depositing and planned withdrawal of assets.
It is necessary to take into account the possibility of asset price movement in both directions. Some potential issues, such as the risk of intermittent loss (IL), can be calculated in advance.
To calculate the IL indicator, you need to understand the nature of its origin. You can also use one of calculators non-permanent losses available on the Internet.
Found a mistake in the text? Select it and press CTRL+ENTER
Cryplogger Newsletters: Keep your finger on the pulse of the bitcoin industry!