Decentralized exchanges (DEXs) let people trade crypto-assets without depending on a regular centralized exchange in order to organize the order book and match each buyer with the seller. Most DEXs use AMMs (automated market makers) and liquidity pools.
The liquidity pool is composed of several tokens that can be traded against each other. These tokens are provided to the liquidity pool by liquidity providers thus creating the liquidity necessary for trading. In a simple constant-product automated market maker like Uniswap v2, the exchange rate is based on the ratio between the two token reserves, which looks like x × y = k.
In case a person purchases one token from the pool, then the amount of this token is reduced, while the amount of the other token is increased, changing the ratio between the tokens and consequently the exchange rate.
Thus, unlike a regular order book, the price in a liquidity pool depends directly on the liquidity and trading formulas.
Also, the size of the trade matters. While a small trade may only affect the pool price by a little bit, a large trade can have a significant effect on it. The difference between the expected price and the price received is associated with the price impact and slippage.
It should be noted, though, that the price of the asset as displayed on one DEX is not automatically a global market price.
Arbitrage makes it possible to make the asset price in different markets converge. Namely, if there are two markets with different prices for the same asset, a trader can buy from a cheaper market and sell to a more expensive one. As mentioned in the Uniswap documentation, traders engage in such activities when the price of a particular pool differs from the market price enough to cover their fees.
That is why prices on different exchanges tend to stay relatively close despite each one having a separate pool of liquidity.
The higher the liquidity of a particular market, the less the price may change with the trade.
Every DEX does not necessarily follow the same process for its pricing. The AMM formula could be different across different protocols; some could use concentrated liquidity, some stable assets formula, and even on-chain order book. Therefore, to suggest that all DEXs follow one particular formula is incorrect.
It is another critical consideration: in some cases, the price displayed on a DEX can be manipulated, especially when the protocol is using the spot price of the DEX itself as an oracle. Big trades could tamper the on-chain spot price temporarily, causing complications for the application relying on such price externally. TWAP and decentralized oracle could minimize such problems.
In other words, the process of price discovery in DEXs is based on liquidity, trading, pricing algorithms, and cross-market arbitrage.
The blockchain stores trades, while the way trades affect available prices is determined by the design of the exchange itself. It provides decentralized market price discovery without central order matching system.