DeFi Swap follows a constant product formula, where the product of the quantities of two tokens remain the same before and after a swap is performed.
The smart contract maintains a constant using the following function: x*y=k. In this case x = Token A, y = Token B, k = constant.
For each trade a certain amount of tokens are removed from the pool for an amount of the other token. To maintain k, the balances held by the smart contract are adjusted during the execution of the trade, therefore changing the price whenever someone makes a trade.
Price slippage depends on the ratio and quantity of tokens in the pool.