Swaps
Swaps are the most common way of interacting with the Uniswap protocol. For end-users, swapping is straightforward: you pick a token you own and another you want to trade for. When you make the swap, your current tokens are sold for an equivalent amount of the desired tokens, minus a fee. This fee goes to liquidity providers. Importantly, swapping on Uniswap doesn't require any special permissions.
Using web interfaces (websites) to swap via the Uniswap protocol may introduce additional permission structures, and may result in different execution behavior compared to using the Uniswap protocol directly. To learn more about the differences between the protocol and a web interface, see What is Uniswap.
Price Impact
Price impact is the change in the price of an asset due to the execution of a trade. When you swap one asset for another, you are essentially buying and selling those assets at the same time. This can cause the price of both assets to move, depending on the size of your trade and the liquidity of the market.
Imagine you are at a store and you want to buy 10 apples. The store has a sign that says apples are $1 each. However, the store only has 5 apples in stock. So, you are only able to buy 5 apples for $1 each. The other 5 apples are not available at this price.
Now, let's say you are willing to pay $1.50 each for the remaining 5 apples. The store owner agrees to sell you the apples for this price. So, you end up paying an average of $1.25 per apple.
This is similar to what can happen in a traditional order-book market. A limit-sell order is an order to sell a security at a specific price. If a large market-buy order comes in, it may deplete the available liquidity of the limit-sell order. This means that the market-buy order will continue to execute against subsequent limit-sell orders at higher prices. As a result, the final execution price of the market-buy order will be somewhere in between the two limit-sell prices against which the order was filled.
Here is an example of how this could happen:
Limit-sell order: Sell 100 shares of stock at $10 per share
Market-buy order: Buy 200 shares of stock
Execution:
The market-buy order will first be executed against the limit-sell order for 100 shares at $10 per share.
The market-buy order will then continue to execute against subsequent limit-sell orders at higher prices.
The final execution price of the market-buy order may be $10.50 per share.
Slippage
Slippage refers to potential changes in the price of a cryptocurrency while your transaction is pending.
When you submit a transaction on Ethereum, it gets processed based on the amount of "gas" (transaction fee) you offer. Higher fees lead to faster transactions. However, transactions with lower fees may take a while to be executed. During this waiting period, the price of the cryptocurrency can change because other transactions are happening.
To account for this, there's something called "slippage tolerance," which is a range within which you're okay with the price changing. For example, if you set a 1% slippage, your transaction will go through as long as the final price is within 1% of what you expected. If the price goes beyond this range, the transaction fails, and the swap doesn't happen.
Think of it like placing an order in a traditional market but not knowing the exact price you'll get if there's a delay before the order is executed. Slippage tolerance helps you set a limit on how much the price can change while your transaction is in progress.
Safety Checks
While a transaction is awaiting execution, both price impact and slippage are subject to potential changes. To safeguard users from significant alterations in the execution environment of their swap, the Uniswap protocol incorporates various safety checks. Among the commonly encountered safety measures are:
Expired:
Error triggered when a swap remains pending beyond a set deadline.
INSUFFICIENT_OUTPUT_AMOUNT:
Occurs when the estimated output amount provided by the Uniswap interface doesn't align with the user's expected received amount within the defined slippage tolerance.
This cancellation mechanism aims to shield users from significant and unfavorable price changes during the transaction processing period.
Last updated