Traders who buy and sell cryptocurrency utilize automated market makers due to their always available liquidity, instant accessibility, open nature of verifiable on-chain trades, the ability to maintain individual custody of funds, and so much more. But how does it work under the hood? What determines the price and how is this liquidity always available?
Each liquidity pool is managed by a smart contract that contains two tokens to make up a pair. The tokens are priced using a constant formula of
x * y = k. In this equation, x and y represent a pair's reserve balances. In other words, x and y are the amount of each token in the smart contract. These change any time liquidity is utilized in a trade. However, k, the product of multiplying x and y remains constant during a trade. This allows for the ratio, or price, to shift dynamically based on how much liquidity is being utilized for a trade, therefore there is always liquidity available.
x * y = k formula dictates the ratio, or price, when trading. The greater the amount of liquidity in a pool, the less price movement that occurs during a trade. This price movement is known as slippage - the amount of difference between the current ratio or price, and the ratio or price that will be executed based on the trade size. The lower the value of the order, the less slippage a trader will incur.
Let's say a liquidity pool consists of 200 USDT and 2 BNB. This sets the ratio or price at 100 USDT for 1 BNB. If Gene buys 3 USDT worth of BNB, Gene will pay very close to the 100 USDT per BNB ratio. However, if Gene buys 75 USDT of BNB, the ratio will significantly move, resulting in Gene paying far more than 100 USDT per BNB.