Automated Market Makers and Betting

Keir Finlow-Bates
10 min readSep 26, 2023

When I turned eighteen, a few of my friends and I dressed up in tuxedos, and went to the Kurhaus casino. This was the first and last time I ever gambled with a large sum of money — 100 guilders, or about 500$ in today’s money, which was a huge amount to me at that age.

I lost the lot in the space of about an hour.

I haven’t gambled a significant sum of money since, so it was a good lesson, but as a mathematician I’ve always been interested in gambling. From a professional outsider’s viewpoint, of course.

As a result I was more than happy when Charles Dray over at Resonance Security set up a meeting and I got to spend an hour chatting with Daniel J. Im, the CEO and founder of UBET Sports.

Especially given that UBET Sports is a decentralized sports betting company using an automated market maker to enable betting.

Probability and DeFi!

What could be more fun than that?

What is an AMM?

Automated Market Makers solve a tedious accounting problem in an interesting way. To understand them, you need to understand the problem first.

The standard way to keep track of an exchange rate, whether we are talking about stock prices or currency exchanges, is with an order book.

You have a list of how much of an item buyers want and what they are willing to pay for it, and a matching list of how much of an item the sellers are looking to offload, and what they’ll accept for it. When there’s a match between the two, a trade is executed, assets change hand, and you have a new “spot price” for the asset.

This works fine for a centralized system where the order book is stored in a database, and the cost of adding another “ask” or “bid” as a row in the database is nominal once the system has been implemented.

In a decentralized system using a smart contract, each of those orders has a much more significant cost. A smart contract on Ethereum that is storing hundreds of thousands of orders, most of which are so far from the current spot price that they’re not relevant, is going to have a tremendous data storage cost associated with it.

However, if you observe that “the price should rise if someone buys the asset, and the price should drop if someone sells it”, you may start to get the sense that there is another way that doesn’t involve storing lots of data.

Enter automated market makers, which I’ll now explain with an analogy.

The amazing chocolate vending machine

Imagine an unusual chocolate vending machine. You can put money in and get chocolate out, as is usually the case with vending machines.

But the first unusual feature is that you can also put chocolate in and get money out. Thus anyone can be either a customer, or someone who re-stocks the machine, or even both.

The second unusual feature is that the price of chocolate changes dynamically. As the stock of chocolate goes down, the machine assumes that chocolate has become more desirable, and puts the price up in response. In a fully efficient and free market, this makes sense. Similarly, if people are enthusiastically restocking the machine with chocolate, it starts to pay less and less for this, as chocolate has clearly become less desirable.

For the purposes of this analogy, we will pretend that no one consumes chocolate, or at least that chocolate is produced at approximately the rate that people eat it.

There is a simple formula for calculating what the price of chocolate or the payout in cash should be at any given point, and it is variously known as a bonded curve, or a hyperbolic function.

For any point on the red line, the x value times the y value is 10

For our chocolate machine, the equation is:

(amount of chocolate) × (amount of cash) = a constant

Let’s say there is 1000 grams of chocolate in the machine, and 10 dollars. Then 1000 × 10 = 10,000, so our constant is ten thousand.

If you want to withdraw 10 grams of chocolate, we know that the new balance will be:

990 × (cash in the machine) = 10,000

So the amount of cash that should be in the machine after your withdrawal is 10,000 ÷ 990 ≈ 10.101 dollars. Hence the machine will give you your 10 grams if you pay approximately 10 cents.

Let’s say that 500 grams of chocolate has been bought. Now our equation is

500 × (cash in the machine) = 10,000

That means that a) there are now twenty bucks in the machine, and b) if you want to buy 10 grams at this point, it’s going to cost you over 40 cents. Chocolate has become four times more expensive.

Ensuring that the price stays on the hyperbolic function makes sure that the price matches the supply and demand, and whenever the vending machine price is even slightly out of balance with the other chocolate markets out there, arbitrage seekers will naturally step in and conduct trades that bring it back in balance. They don’t care about the fact that their actions are synchronizing the chocolate vending machine marketplace with other marketplaces — they’re just looking for a quick profit, which happens to drive the AMM exchange rate towards the market rate as a side effect.

Enter the bookmaker

Forgetting the more complicate aspects of sports betting, let’s just look at a simple betting option: deciding whether to gamble on team A or team B winning in a match that is going to take place in a week.

I remember talking to a bookie in South London, back when I was a mathematics PhD student, and being amazed to discover that the odds for a given game didn’t depend on an objective analysis of the relative performance of team A and team B so much as on the number of bets placed on each, the odds for them, and the expected amount that would have to be paid out in either case.

The “odds” were simply an expression of the amount that gets paid out in the event of a win, and not an objective measure of the likelihood of a particular team winning.

It seems obvious now, but at the time it was a revelation. In particular, when the crowd favors an underdog football team or a beloved horse with a bad track record, the odds can shift wildly from what an objective analyst would suggest after a significant amount of research.

A bookmaker starts with an assessment of the sentiment towards the two teams, and sets the odds for each winning accordingly, with a slight shift to each to ensure that they make a profit (or they can charge the equivalent of a transaction fee — that also works).

Then, as more and more bets are placed, the odds are shifted again and again with each bet.

And so the bookmaker doesn’t care about the outcome. What they care about is ensuring that the bets, their odds, and the final payouts are all balanced. They keep track of this in the equivalent of an “order book”, hence the name “bookmaker”.

If a bet is placed on team A winning, the payout for subsequent bets of the same type are reduced, and the odds for bets on the opposing team B are improved. This used to be done manually, but with the advent of online betting and computer software, it can all be performed automatically, and much more rapidly and efficiently.

A synthesis

If you’ve been paying attention, the penny should now have dropped. A decentralized exchange, or DEX, functioning through the mechanisms of an automated market maker, can be seen as a means for placing a bet. As a speculator, when you exchange all your holdings of token A for token B, you are gambling on the value of token B going up in relation to token A.

So why not use an automated market maker (AMM) to adjust the odds on the outcome of a sporting event? That’s exactly how decentralized betting works.

There are, of course, a few differences between an AMM for a token exchange, and one for betting.

  1. a betting AMM can only run for the period between the announcement of an event, and the final result of the event, whereas a DEX runs indefinitely, or at least, until it is hacked
  2. there is a step before the AMM kicks in, in that a base currency, for example ether, or some stablecoin, is used to pay for the bet, which is then converted by minting conditional tokens for the different bet outcomes, and finally, by exchanging the tokens that do not correspond to the player’s chosen outcome into the conditional token that does correspond. This is the part where the AMM comes into play
  3. once a trusted oracle has reported the result of the event, only the conditional token corresponding to a win can be converted back to the base currency. This is how the winners claim their winnings.

Step 2 is worth a closer look.

Conditional tokens

To begin with — what exactly are conditional tokens?

A conditional token is a token used to represent a possible outcome, and only has value if that outcome occurs.

If we have a match between two teams, and exclude the possibility of a draw, then we can represent team A winning with a conditional token A, and team B winning with a conditional token B. If team A wins, token A can be cashed in for value, and token B is worthless.

Liquidity plus exchange equals a bet

And how does betting represented by conditional tokens work?

One way of understanding it, is that placing a bet is like becoming a liquidity provider, and then converting the liquidity of the conditional tokens that do not represent your chosen outcome into conditional tokens that do. Betting equals providing liquidity, immediately followed by an exchange.

For example, an AMM may start with a fund of 100$ in stablecoins, with 100 team A coins and 100 team B coins. The bonded curve value is now 100*100 = 10000.

The AMM thus represents the odds on team A are now 2/1 (a 2 dollar payout for each dollar bet), because total coins divided by team B coins is (100 + 100) ÷ 100 = 2/1.

I bet 5$ on team A winning. The AMM converts this into 5 team A coins and 5 team B coins. The bonded curve value is now 105*105 = 11025. This is too high.

To return to the original value of 10000, the AMM presents me with 5 team A coins because of my 5$ stake, and another 4.76 team A coins because I’m betting on team A winning, and that brings the AMM value back down to 10000. How come? The AMM now holds 95.24 team A coins, 105 team B coins, and note that 95.24*105=10000. The AMM also has 105$ in funding, five dollars more than before I placed my bet.

The new odds for anyone else coming along and betting on team A are reduced to (95.24+105) ÷ 105 = 1.9/1. My bet has shifted the odds, and subsequent bettors will get a lower return. The more people bet on team A, the lower the odds will get.

If team A now wins, I get 9.76 ÷ 105 * 105$ = 9.76$ in winnings from cashing in my team A coins.

Slippage

Note that I don’t get 10$ — my bet was reasonably large compared to the initial liquidity of the AMM. If you imagine my five dollar bet was five hundred one cent bets, then each cent placed as a bet shifted the odds slightly, and so my last cent did not get the favorable odds that the first cent did.

This is called slippage.

Impermanent loss

Also note that the initial liquidity provider has made a loss; this is an example of the “impermanent loss” that you may have read about when looking at decentralized exchange AMMs.

Not so impermanent in this case.

The liquidity providers were, inadvertently, placing counter-bets to cover my winnings. Their loss would have been reduced or even reversed if some people had placed bets on team B winning, illustrating the importance of the initial odds being close to the underlying real odds. This is one of the problems that UBET Sports has a proposed solution for.

Conclusion

If you want to learn more about using AMMs for betting, and find out about further measures that can be taken to reduce slippage and impermanent loss, do check out the UBET Sports paper, which explains how they have implemented their smart contract.

It goes into the points I made above in more technical detail, and a whole lot more, explaining various techniques they use to reduce impermanent loss, and the empirical experiments they conducted to verify that their contract works.

In the meantime, perhaps I’ll dig out my old tuxedo and try those roulette tables one more time. Or maybe I won’t.

Which do you think is more likely?

--

--

Keir Finlow-Bates
Keir Finlow-Bates

Written by Keir Finlow-Bates

I walk through the woods talking about blockchain

Responses (2)