How Is the Marginal Exchange Rate (Price) Calculated within a Constant Product AMM?
The marginal exchange rate, or the instantaneous price of one token in terms of the other, is calculated by taking the derivative of the constant product formula, $x y = k$. Specifically, the price of token Y in terms of token X is approximately the ratio of the token quantities in the pool, $x/y$.
This ratio changes with every trade, reflecting the new balance of assets in the pool.