How Is the ‘K’ Constant Maintained When a Trade Occurs in the Pool?
The 'k' constant is maintained by the trade itself. When a user deposits token X and withdraws token Y, the pool's reserve of X increases and the reserve of Y decreases.
The formula $x times y = k$ ensures that the product of the new, adjusted reserves of X and Y, minus the fees taken from the trade, equals the original 'k'. The fee is usually added back to the pool to slightly increase 'k' over time.