0xBeans Profile picture
@frame_xyz | Once upon a time a @coinbase engineer. Enjoys long walks on the beach and some Solidity. 사실 콩 안 좋아해.

Mar 22, 2022, 19 tweets

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.

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.

Second, we have to understand what NFTX is. I personally haven't used NFTX but "NFTX is a platform for creating liquid markets for illiquid Non-Fungible Tokens (NFTs)".

Essentially its a protocol where you can lock up your NFT in a vault and receive liquid ERC20 tokens back.

For example, you can lock up your BAYC (erc721) in a vault and get 1 vBAYC token (erc20) back. You can redeem an ape from the vault by giving back your vBAYC.

Why does this protocol exist? Out of scope again but essentially gives liquidity (erc20) to non liquid assets (erc721)

So now knowing all this, let's dive into the bot txn.

First, bored ape #1060 was transferred to the bot contract. This ape wasn't borrowed but actually bought from OS. We'll see why the bot bought an ape later in this thread.

(English is hard... "bought" "bot" lmao)

Next, the bot gets a flash loan of 5.2 vBAYC tokens from the NFTX vault.

Next, the bot swaps out its vBAYC tokens for 5 actual apes (5 apes have been transferred to the bot).

Notice the first ape doesnt come from the NFTX vault (since thats the ape the bot actually bought). So by this point, the bot has 6 apes in its possession.

Next, the bot calls to the $APE airdrop contract and claims all the $APE for all 6 apes. Netting ~$600K.

Finally, the bot transfers the apes back to the NFTX vault to redeem back vBAYC tokens to repay the loan.

So why did the bot need to buy its own bored ape?

It's because flash loans have a fee attached to them. Whenever you get a flash loan, you must pay a fee in addition to the original loan.

So the bot swapped its own bored ape (#1060) for vBAYC to pay off the flash loan fee.

The funny thing is, the fee only took a portion of the vBAYC tokens the bot redeemed for its own ape.

Since the bot has no need for extra vBAYC tokens, it just swapped its remaining vBAYC for 14 ETH.

What I find beautiful is that I assume this bot didn't have much competition for this strategy (I may be wrong on this).

MEV is super competitive, it's extremely hard to write a profitable MEV bot to arbitrage/frontrun because so many big brains are in the space (bot vs bot).

However, if you just look at extracting value in a place that no one else is looking at, you win.

Quoting @bertcmiller "If you're thinking about these things or looking for them, which not many ppl are, there's a lot of value to be captured".

The cherry on top is that boy genius @_anishagnihotri wrote this EXACT same strategy that borrowed punks from NFTX to mint Meebits last year.

The sad thing about this whole story is that I read Anish's strategy, thought it was really clever, and completely forgot about it lmao.

Guess Im ngmi in MEV... not big brain enough.

Just because I KNOW Im gonna get a question about this. "Is this ethical and is ethereum doomed".

Whether it's ethical is up for you to decide, but this is an open and permission-less system which not only creates these adversarial environments, but also leads to innovation.

If you really wanted to, there are 1000s of resources online and you can participate it MEV right now - everything is open source. Try asking a hedge fund to let you in on their front running secrets :)

Idk about you but, web3 is the most exciting space in the world.

Whether you find anything ethical or not is your opinion, but I can't think of any other industry where so many big brains are playing in an open field for anyone to spectate or join.

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling