// Get references to the pop-up container and close button // Function to calculate the difference in days between two timestamps // Function to show or hide the popup based on visit history and closing action // Check if the popup has been closed before const popupClosed = localStorage.getItem('popupClosed'); // Boolean value stored as string // If the popup hasn't been closed, show it immediately popupContainer.style.display = 'flex'; // Show the pop-up sliderAdvertisement.style.display = 'none'; // Hide the slider while the pop-up is shown }, 5000); // Show after 5 seconds // Now apply the timing logic after the user has closed the popup // Calculate the days since the popup was last shown let showPopup = false; // Flag to track whether we should show the popup // Determine if the popup should be shown: // - First time visit (no lastShown value) // - Shown once per day for 3 days // - After 3 days, show every 3 days popupData.lastShown === null || // First time visitor (popupData.timesShown < 3 && daysSinceLastShown >= 1) || // Show once a day for first 3 days (popupData.timesShown >= 3 && daysSinceLastShown >= 3) // Show once every 3 days afterward showPopup = true; // The popup should be shown // Show the popup after 5 seconds popupContainer.style.display = 'flex'; // Show the pop-up sliderAdvertisement.style.display = 'none'; // Hide the slider while the pop-up is shown // Update popupData and store it // Show the slider if the popup is not shown // Ensure elements exist before using them // Call the function to handle popup display logic // Add click event listener to the close button popupContainer.style.display = 'none'; // Hide the pop-up sliderAdvertisement.style.display = 'flex'; // Show the slider advertisement when pop-up is closed localStorage.setItem('popupClosed', true); // Set popup as closed in localStorage // Reset timing logic after the popup is closed timesShown: 0 // Reset counter for daily/3-day logic

How Do Automated Market Makers (AMMs) Work?

How Do Automated Market Makers (AMMs) Work?

Share:

Maximize Gains, Minimize Effort – Only on CrowdSwap DEX

Seamless Swaps, Crosschain Transactions, and Exciting Opportunities.

How Do Automated Market Makers (AMMs) Work?
Table of Contents

Share:

On a chilly, snowy night in 2021, Stacy was sitting in the comfort of her house browsing through the internet when suddenly a pop-up appeared on her screen. It was an advertisement about a limited 40% discount for pre-ordering a brand new TV she had been hoping to buy for a long time. It was a great offer, but Stacy had no credit left because she had spent all her money a week before on Black Friday. So she decided to sell her old TV on a P2P platform to raise the deposit amount she needed to book her order. Unfortunately, it took four days for Stacy to sell her old TV at a reasonable price, and she missed the offer. But what if there was an entity that could facilitate the process so that Stacy wouldn’t have to wait that long? That’s what Automated Market Makers (AMMs) do; they help conduct a transaction with the liquidity they have.

The recent boom in decentralized finance (DeFi) has been made possible by two types of service: lending services on the one hand and exchange services on the other. Indeed, it is essential for an ecosystem that wants to be decentralized to allow exchanges that are also decentralized. The objective is simple: to enable users to exchange cryptocurrencies on a peer-to-peer basis without a trusted intermediary.

Within the family of decentralized exchanges, AMMs can implement several mechanisms. The most widespread in recent times is the automated market maker used by Uniswap, Balancer, or Curve. Let’s see how they work. 

What Is a Market Maker?

For several years, projects have tried to replicate the operation of traditional exchange platforms, aka centralized exchanges (CEXes), on the blockchain. Thus, we have seen the emergence of several decentralized trading platforms based on order books. Indeed, market makers are market players, ensuring that each order is completed by providing their liquidity, hoping to take advantage of the difference between the selling and buying price on a given market. It is these market makers who ensure the liquidity and usability of an exchange. 

In simpler terms, a market maker is an entity that takes buy and sell orders to provide liquidity and facilitates transactions in DeFi. With the help of market makers, buyers and sellers can conduct transactions without waiting for a counterparty to appear. However, these players were only sometimes present in the case of decentralized exchanges based on order books. This is where automated market makers come into play.

What Is an Automated Market Maker (AMM)?

As the name suggests, automated market makers are computer programs that replace the work of market makers. In practice, AMMs allow users to exchange (or swap if you will) cryptocurrencies on a peer-to-peer basis. However, in this case, the usual order book is replaced by liquidity pools deposited on smart contracts. The concept of liquidity pool is central to understanding what an AMM is and how it works.

What Is a Liquidity Pool?

Liquidity pools are formed from tokens provided by liquidity providers (LPs), locked in a smart contract to facilitate transactions in a DeFi protocol. The importance of liquidity to decentralized exchanges is that it determines how the price of a crypto asset changes. In markets with no or less liquidity, the open buy and sell orders are relatively limited. 

When the market is illiquid, a single trade can drastically change the price of assets. This can negatively impact the market, making it unpredictable and reducing its attractiveness. To tackle this issue, liquidity pools are essential, as they facilitate the exchange of a large number of assets.

Read more about liquidity pools .

How Do AMMs Work?

AMMs are based on mathematical formulas, making it possible to estimate the exchange rate between two assets. They also take into account the liquidities present in the protocol. Several formulas exist in AMMs, each having their advantages and disadvantages.

Constant Function Market Makers

Constant function market makers are the most common in the AMM family. Uniswap and the V1 of Bancor notably use these. These are based on a function x*y=k that sets the price for a pair of tokens based on available liquidity.

Thus, when the quantity of token x increases, that of y must decrease to keep the value of k constant. As the curve below shows, the advantage of this model is that it ensures that there will always be liquidity. However, as this decreases, prices increase exponentially. This phenomenon is called slippage.

Constant Function Market Makers

Mean Constant Maker Makers

Constant-mean market makers introduced another type of formula. These allow the addition of one or more other assets in addition to the two assets typically found on trading platforms.

In this case, the formula for three assets will be (x*y*z)^(1/3)=k, which allows exposure to several different assets and exchanges between these assets.

Hybrid Constant Function Market Makers

A third family of AMM, called hybrid, combines several functions to respond to particular problems. This is notably the case of the Curve formula, which combines two types of procedures: constant-function market makers and constant-sum market makers.

The function reduces slippage over a range of trades while heightening it in the case of significant transactions. Thus, most trades will have a linear exchange rate, and only larger quantities will be subject to slippage.

Trade Effortlessly

Ready to dive deeper? Our crypto exchange is simple and user-friendly, making trading a breeze

Conclusion

You can think of an automated market maker as a robot always willing to quote you between two assets. Using AMMs, you can trade with confidence and earn rewards by supplying liquidity to a liquidity pool. The rewards are calculated through various formulas and have different APYs and APRs. This allows anyone to become a market maker on an exchange and earn fees for providing liquidity. 

AMMs have genuinely carved out their niche in the DeFi space because they are simple and easy to use. Decentralized market making in this way is at the core of the crypto vision.

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Ahead of the Curve – Subscribe for CrowdSwap Updates & Offers!

Join our newsletter to get the latest news, trading tips, and special offers straight to your inbox!

CrowdSwap Newsletter

Ready to Supercharge Your Financial Knowledge?

Drop your email, and we'll deliver the Ultimate DeFi Guide straight to your inbox! πŸš€