2 min read

Candy Swaps 🍬🍫🍭

Happy Halloween! Here in the US, this holiday is all about candy. Kids go to great lengths dressing up and knocking on doors to haul home bags of free candy from their neighbors. That much of the tradition is fine, but the real fun begins back home. Not all candies are created equal and each kid has their favorites. Once they've eaten a few of their best pieces, it's time to swap with siblings and friends.

If everyone in your group had the same exact candy preferences, the exchange would be pretty boring. Fortunately, there always seems to be some kids who prefer chocolate, some who like fruit flavors, and one weirdo who overvalues the candy no one else wants.

In these small group settings, candy traders usually just haggle with an ad-hoc verbal order book. In other words, one kid says "I want Snickers" and another kid says "I've got Snickers. Do you have Reese's?" and then they discuss trading one for one, two for one, or some other exchange rate. Occasionally, another kid will chime in and offer a more favorable rate, undercutting a trade in progress.

Order books are very natural, but not the easiest thing to implement efficiently on a blockchain. Automated market makers (AMMs) are more common for decentralized exchanges. Let's look at how they work with candy.

On an AMM, if you want to facilitate trades between Twizzlers and Redvines, there needs to be a liquidity pool. You could have your parents (centralized) put up 100 of each type of candy for the pool, or you and your friends could contribute from your own candy (decentralized). Either way, the ratio you can trade one candy for another is based on the ratio in the liquidity pool.

Starting at 100:100, you can swap your 10 Twizzlers for 10 Redvines, paying a small fee to the liquidity providers. The next kid sees the pool is 110:90 and decides to swap 9 Redvines for 11 Twizzlers. The actual numbers will have fractions, but we'll leave it here for sake of simplicity.

Decentralized candy exchanging just makes sense. You wouldn't want your parents facilitating and taking a cut of every trade, though there's a valid argument for your parents stopping you from stealing your little brother's Snickers in exchange for a box of Red Hots. Free trade is good, but we need better decentralized consumer protection in crypto.

-Luke

P.S. 13 years ago to the day, Halloween 2009, Satoshi Nakamoto published the bitcoin whitepaper.