Discover more from Degen Code
Welcome to Degen Code
Build your bot army and let them make money while you sleep
In late September, BowTiedBull published an article about arbitrage, cash-and-carry trades, and decentralized liquidity pools. I was unfamiliar with the concept of arbitrage, except for having seen it mentioned on Twitter. I understood the concept (exploit a price mismatch across disconnected markets) but not the execution. This all changed when I observed the arbitrage across the Synapse Protocol Arbitrum bridge, and reviewed the historical price action of de-pegged stablecoin pairs on DEXs.
It was a mind-altering experience seeing a few button clicks turn into money (ETH is money, didn’t you know?)
I am blessed with strong abstract thinking skills, so it was simple to take the general example and consider how it could be identified, repeated, and ultimately automated.
I studied web scraping and browser automation, then built a primitive notifier app that would text me whenever the arbitrage opportunity crossed some threshold. Nice start, but I was getting too many text messages during work meetings at my 9-5 with no way to act on them.
I went back to the drawing board, realizing that if I could build an app to identify opportunities and notify me, it’s not a big ask to have it execute on that same opportunity.
Only one problem: I’d have to learn Solidity to execute directly on smart contracts.
Or did I?
A week later I discovered the Rarity RPG on Fantom.
I thought it was pretty neat, so I played around with it on FTMscan, summoned a few characters and sent them on adventures using the Wallet Connect feature on the Contract tab.
After a few days of doing adventuring by hand, I had the thought a second time: This whole thing would be much better if I had the computer do it for me.
So I got to work, then quickly discovered this Banteg tweet —
Hmmm… Brownie you say? It seemed promising, so I got to work and quickly discovered that the open source world had already developed the tools I needed. All I needed was to learn how they worked, then get to building.
I learned Python, studied Solidity, then hacked an RPG bot together. I tested it, then published it to Github. It’s very niche so not many people are interested, but I got some nice feedback from a few Rarity fans.
Having successfully built a bot to do my RPG adventuring, I took a fresh look at the arbitrage problem.
With my framework in place from the RPG, it was easy to retool it to perform DEX trades. The only missing piece was learning how the various DEX swap contracts worked. Documentation is so-so on this topic, but I pieced it together. After all, the source code is out there for anyone dedicated enough to just read it.
I put in a few late night coding sessions before my Thanksgiving holiday, built a proof-of-concept arbitrage bot, funded it with 1 ETH worth of tokens, turned it on and watched it go.
I continued to tune it over the following weeks, hence the frequent late night shitposting on Twitter (you are following me, right anon?)
I get a special sort of thrill from watching my computer make me money. Even more satisfying? The code block that used to send me opportunity text messages now sends confirmations of completed arbitrage gains.
I’m confident that the bugs are (mostly) worked out, and the arbitrage bot has been running for 28 days as of this writing. It has managed a 137 percent difference (more than doubled the starting balance). The token itself has swung wildly relative to USD, but since 1 token = 1 token, I do not mind.
The arbitrage bot strategy gains from volatility, which is important. A strategy that pays during a bear market is one that keeps the “SELL” button out of my thoughts.
The exact tokens, pools, and chains I’m playing in will be for subscribers only, but I will share the wallet and links to the transaction history to prove that the concept works.
As Bull taught us in the arbitrage post, if you identify a 0.5% opportunity and do it once a week, you’ve made a 26% gain for no risk. AMM pools on DEXes offer persistent arbitrage opportunities, so this is a repeatable method.
The bot didn’t make 137% all at once, it did so with 0.5% trades a few hundred times.
Your Keys, Your Coins, Your Bot
My bot approach is non-custodial. You will control your keys at all times. I am not providing a downloadable, a script that may be compromised, or asking for deposits. You will build your own bot, secured by your key and running on your machine.
Do You Even Code Bro?
This newsletter will be very technical and heavily code-based. I develop primarily in Python using Linux. I spend a lot of time on the command line.
If this scares you, consider doing some reading on your own and watching some how-to videos. I recommend Automate the Boring Stuff with Python and Beyond the Basics with Python (both free to read online).
You can read through my free Linux & Self-Hosting Series if you want a sample of my writing. If you don’t know how to code, I will explain what I’m doing as we progress. If you already know how to code, you’re in much better shape.
There’s a lot of stuff I’ve learned in the last few months. I want my friends to make it to Degen Island with me, so I will teach you and share what I’ve learned.
Subscribers will learn —
How to interact with Ethereum Virtual Machine (EVM) compatible blockchains using their RPC APIs, including (but not limited to):
How to swap, deposit, claim rewards, etc. directly from a smart contract, including (but not limited to):
Uniswap v2 (and its forks)
How to code in Python
Procedural and object-oriented code
Built-in and module-specific data structures
How to transfer funds through cross-chain bridges via smart contract
How to get accurate DEX swap rates via smart contract
How to track gas prices and construct transactions to win gas wars
How to catch flash crashes on a DEX that does not offer limit orders
How to spot arbitrage bot activity on Etherscan (or similar), and how to crawl their transaction activity to find new pool opportunities
How to write tests for your code and track changes with git
How to simulate transactions locally and on testnet
How to set up and secure a virtual private server (VPS) for faster trade execution and better uptime
How to scrape and monitor web pages using Selenium
How to retrieve and parse JSON API data
The roadmap will change as I learn more and get into the Q&A and DMs with you, but these are topics I’m ready to address on day one.
Cheers to the future, anon.
This is the only free post, all future content will be for paid subscribers only.
Please DM me on Twitter, or email me at firstname.lastname@example.org, or comment below if you have questions.