PSA: Slippage vs Price Impact
in between the time you generate a quote and execute a swap, the state of the market-network changes. even with highly accurate simulation, for volatile tokens, the realized gap between quote and execution can be significant (in either direction). the name of this gap is called "slippage" and crucially, because we cant predict the future, its impossible to compute a priori. which is why you specify a "max slippage" or "slippage tolerance". that's your way of saying: if the actual onchain execution of this trade exceeds my quote by x%, revert.
so that's happening
in addition, when you trade on an AMM (regardless of whether you're doing so directly or via an aggregator/meta-aggregator that breaks your trade among among many AMMs) the price you get is determined by 1) the liquidity depth of the pool(s) you're trading in and, 2) the price range that depth is concentrated to. if the size of your trade is so large that it "chews through the book" or, in the case of AMMs, rapidly eats through the available liquidity range, it will continue ascending the price curve asymptotically toward infinity. which means you’ll end up paying an amount per token that exceeds current market price. put simply, if the size of your trade exceeds available liquidity you're gonna Get Rekt. this is called “price impact” and *can* be computed a priori.
*both* slippage *and* price impact are happening when you trade, but because volatility on majors is relatively low, and the size of your trade relative to liquidity depth is also low, you rarely notice
…until you try to swap $50M 😭