P

Pessimistic Swaps

Uniswap token swap via Layer 2 pessimistic rollup

The problem Pessimistic Swaps solves

Uniswap token swaps are expensive and takes around ~115k gas per transaction. This project aims to solve this issue by batching users who wish to perform same token swaps. Instead of each user doing individual swap, a bunch of users are grouped together, their tokens are added together, the total sum of tokens are swapped in a single transaction and finally the swapped token is distributed to the users based on their initial share.
This is acheived by using a layer 2 "pessimistic" rollup which acts as a "super wallet" for the users. The rollup keeps track of the individual deposits and performs swap when a sufficient number of users are available. By doing batched transaction with batch size N, the total gas required from swap is reduced from N*x to just x.
The rollup is "pessimistic", it means that all the transactions are saved and applied on-chain.

Challenges I ran into

I had never worked on Layer 2 scaling projects before and I had no idea how rollups worked. I did research about merkle trees and how merkle proofs are used in rollups. The most challenging aspect of this project was finding good resources as most articles talk about the theoretical aspect but very less literature available which talks about the actual implementation of rollups. I mostly had to figure out the code part on my own.

Discussion