0xBeans.eth Profile picture
Mar 21 23 tweets 5 min read
Here's the awaited follow up :)

I'll clarify some questions that people have asked and also go over some easy ways to prevent getting sandwiched.
How does the bot sell their coins at a higher price if the buyer already bought coins?

On DEX's, there is no buyer/seller. You're swapping tokens directly from a liquidity pool based on *math* that makes this profitable (I wont go over how DEX's work, lots of resources online).
Is this the same as front running?

Yes and no. Sandwich attacks are also known as frontrun/backruns (cause you submit 2 txns, 1 ahead and 1 behind the sandwiched txn).

However, there are other front-run attacks.

All sandwiches are frontruns, not all frontruns are sandwiches.
Is this ethical?

Would you rather get front-run by TradFi hedge funds behind closed doors with no possibility of stopping it? Or prefer to have it happen in an open and transparent way where *anyone* could theoretically participate (and have mitigation strategies).
Isn't this illegal in TradFi?

When has making something illegal ever stopped financial institutions from making money in illegal ways?

Anyone remember the PFOF debacle with Robinhood/Citadel? 100% legal.
Do I get rekt on every txn?

No. Not all txns are exploitable. Bots will "simulate" sandwiching your txn to see if its profitable for them.

Even if you do get sandwiched, 99% of ppl will lose out on the slippage THEY set. Most of the time it's a negligible amount you lose
If bots can be spotted that easily, why is there no mechanism to just weed out bot txns?

Not all bots are "bad". It's impossible to censor MEV bots with 100% accuracy since txns are just txns.

Also this would go against the censorship resistant ethos of web3.
BECAUSE ETH is decentralized and non censorable (and because crypto markets are inefficient), this leads to adversarial environments where value can be extracted.

As the industry grows, matures and becomes efficient, there will be less of this.
First, some pre-requisite knowledge before learning how to prevent sandwiching

This was the image I showed of how an MEV bot looks at the public mem pool. This is slightly wrong because not every txn can be front run and it's not like bots can just pick ANY txn to make profit.
What bots actually do is *simulate* front running txns to see if it's profitable. If profitable, they will attempt to sandwich you.

But if bots sandwich certain txns, can other bots sandwich the bot sandwiching? .Yes they can, since bot txns will go into the mempool too
This is where something called Flashbots come in.

Essentially, Flashbots is a private relayer that sends txns (more specifically "bundles") directly to miners (skipping the mem pool entirely).

You can think of bundles as a bundle of txns in a specific order.
Bots can send bundles to the Flashbots relayer (a private hosted service) that sends txns directly miners, entirely skipping the public mem pool (so no other bots can see the txn).

Essentially, these are private txns.
General steps:

1. Create a bundle of txns.
2. Send it to Flashbots relayer (private hosted service no one can read from).
3. Flashbots sends it to miners for it to be mined.

Because this skips the mem pool, Flashbot txns just "appear" on the chain without that txn idle period.
You can tell a txn was mined using Flashbots on Etherscan.
So after knowing this, here are some basic things you can do to prevent your txns from getting front run:

First, a simple way is setting your slippage tolerance low (< 1%). Doing this will prevent you from actually buying any tokens if there's too much of a price swing.
The problem with this is txns will mostly fail for volatile tokens or tokens with little liquidity since there will be large price swings by the time your txn is mined (or your buy order may even swing the price of the token out of your slippage tolerance).
The second way is to use Flashbots relayer yourself.

You can add the Flashbots RPC to your met*mask and send txns through Flashbots so they dont end up in the public mem pool.
A "problem" with this is that Flashbots is still in beta so your txn might fail or take longer to confirm (since they're trying to incentivize miners to mine your txn privately - there is more to this but too technical for this thread).

Flashbots is also centralized.
Lastly, you can use services like @MEVprotection and @EdenNetwork that supposedly have MEV protection built into their services.

I personally have never used these so DYOR and dont blame me if something goes wrong.
Personally, I still use regular txns that go to the mem pool for 90% of my eth activity but I will use Flashbots to trade anything volatile (like $APE this past week).

I default to using public mem pool unless there's a chance I could get severely rekt, then I'll use Flashbots.
So while I do caution you to be careful, I wouldn't worry too much about getting rekt.

Not in a cocky way, but if Im not getting obliterated by bots, you probably aren't either 🤷‍♂️

Just be mindful of this stuff and when in doubt, use Flashbots and always set your slippage
There's a lot of technical details I glossed over for Flashbots and front running, but for the purpose of the everyday user, this should be enough to protect a majority of you.

Hope you learned something :)

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with 0xBeans.eth

0xBeans.eth Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @0x_Beans

Mar 22
Gonna end the $APE content with 1 final thread. Let's dive into how this absolute fucking chad borrowed 5 bored apes, claimed $APE for all of them, returned the apes, and subsequently netted ~600k.

A story of how a bot looked for value where no one else did. Image
First we have to understand what flash loans are.

Flash loans are a DeFi concept that allow a contract to borrow large sums of money as long as the loan gets paid back within 1 txn.

If the loan isn't paid back in 1 txn, everything is reverted (as if nothing happened).
"How" this all happens in 1 txn is beyond the scope of this thread.

Typically flash loans are used for arbitrage, front running, etc. Here's an example of how you would use a flash loan if you detected an arbitrage opportunity. Image
Read 19 tweets
Mar 19
The viral txn of an MEV bot "selling 2.4 $APE for 946 ETH"

A few people asked me how this happened. In short, it didnt happen.

Seems like a lot of people that got hooked on NFTs weren't around during DeFi Summer in 2020 and arent familiar with MEV bots. Let me try to explain :)
This txn is only 1 of 3 that are relevant. The bot didn't make $2.7M (and no trader paid $2.7M).

This is known as a sandwich attack. A lot of smart ppl have explained this, but Ill go over how this works with a real example (Im assuming you know how eth works on a high level).
Every time you send a txn to eth, it doesn't get mined immediately and inserted into the blockchain. Your txn actually gets sent to a pool with other txns - this is known as the mem pool.

Your txn sits idle until a miner decides to pick up your txn and mine it.
Read 19 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(