Inspiration

Sandwich radar was inspired by really poor financial management. Seriously. One of us used to be into trading memecoins and cryptocurrency as a whole. It's fun to see the volatility of your investments and you can make some good money really quickly if you're lucky enough. However, it's so unregulated and lawless that you can get scammed out of your investment just as easily. Especially in smaller pools, one of us had experienced a particularly devastating sandwich attack and learned about the phenomenon not soon after. When we saw this hackathon had a section dedicated to fintech, we pounced on it knowing we could genuinely make a difference in something that really affected one of us.

What it does

Sandwich radar advises DEX traders and defends against MEV sandwich attacks by estimating how likely a trade is to be targeted and by how profitable a sandwich on the trade would be. Our program does this by looking at the trade's size, pool depth, trading direction, time of day, quote asset, and on-chain activity and patterns to estimate if a searcher bot would be present. Then, using AMM mathematics, the program derives how profitable the trade would actually be and the probability that a bot would go for a trade of that level. Our program then finds what the slippage "sweet spot", where a trade would have the minimum expected total cost. The program also looks at the feasibility of splitting trades into multiple smaller trades to reduce risk at a greater rate while allowing some loss to fees. The Searcher's Ledger, Model Attribution, cost curve, and split ladder help users to understand where the model's predictions are coming from and give credit to the % likelihood of trade risk.

How we built it

We built a full-stack system using a React/Vite frontend, a Python/FastAPI backend, Supabase Postgres to support data infrastructure, and used Vercel for deployment. A live Solana data pipeline is continuously scanning through the blockchain, and storing normal and sandwiched swaps in our database. We trained a weighted logistic-regression model on real Solana mainnet transaction, using the 7 observable features outlined above to predict if an attack may happen or not. AI tools such as Claude Opus assisted in production of the website and database.

Challenges we ran into

Reliable, real-time blockchain data was our biggest struggle in creating our system. Free Solana RPC infrastructure cannot read everything from the enormous stream of data on the blockchain, so we had to design a sampling system which caught as many blocks as it was capable of while tracking the position and what blocks were successfully caught in the overall pool. Another issue we ran into was detecting if a trade was a sandwich or just unlucky trade. Sandwiches, while common enough to be a serious problem in blockchain data, only capture a small amount of profitable trades and in the absolutely huge stream of data, it's hard to examine and reliably predict every single sandwich. This also leads into the challenge with the unbalanced data, where we had to learn to put weights on the sandwiched and more important trades for steering the model's judgement of a trade. Overall, training the model was something very new to all members of this project, so keeping it stable and accurate was quite difficult for us.

Accomplishments that we're proud of

We were able to move a simple risk calculator off of synthetic and conceptual data to be backed with a real database that tracks real-time Solana mainnet activity. It was a big leap for the project and one that we believe really legitimizes and credits the website's prediction models. Our model also achieved a chronological holdout ROC AUC of ~0.842 which we are very proud of, demonstrating its accuracy and control. The optimization graph for slippage is another feature we are particularly proud of, answering more than just how your trade is risky, but if there's a better trade available. This website has turned a fairly complicated and nuanced problem into a usable interface with explanations at every step and we are incredibly proud to demonstrate that.

What we learned

We learned that combining hard math with ML prediction is extremely effective and beneficial for both models of prediction. Our model saw a very large jump in accuracy when putting and weighing the 2 systems together. We also all learned how to develop a machine learning model for the first time and train it on real data. It was incredibly rewarding to see the model learn and become more accurate as we tuned and trained it. We also learned that data quality is extremely important for a machine learning model. It could have 10x the data but if it's not extremely qualitative and just noise, our model wouldn't be nearly as accurate as it is and would likely stifle the accuracy of our predictions.

What's next for Sandwich Radar

We want to expand the Solana data pipeline to incorporate more of the real time trades happening on the blockchain. This would increase both the quantity and quality of our model, giving it a clearer picture to work with and more data to fine tune the scales it uses to analyze a trading environment. We want to add stronger probability calibration using historical sandwich datasets to give the model a better chance of associating the percentage of risk with the actual observed frequency of attacks. Ultimately, we want to extend our architecture to be beyond Solana from another chain and incorporate more coins into our prediction markets, turning Sandwich Radar into a baseline project for our Spider Fintech Society at the University of Richmond for students to work with and collaborate on.

Built With

Share this project:

Updates

Submission history