Bonding Curves for Algorand Assets

Introduction

A bonding curve is a mathematical concept that describes the relationship between the price and supply of an asset. The fundamental idea behind a bonding curve is that when a person acquires an asset available in a limited quantity, each subsequent participant will have to provide slightly more for it.

What is a bonding curve? - Coinbase

Bonding curves are often used for token launches on chains like Ethereum, where units are dynamically minted and burned by smart contracts.

Algorand offers native assets (ASAs) that can be created without smart contracts, with the constraint that the total supply of each asset has to be static.

But whilst the total supply is fixed, the circulating supply can vary as a smart contract releases or reclaims tokens over time.

In this context, a bonding curve could represent price as a function of circulating supply.

Linear Functions

Let's say we mint a new token called MOON, with a fixed total supply of 100 units.

Initially, all 100 units are held by a smart contract.

The circulating supply is the total supply (100) minus the smart contract's balance of the token:

The simplest example of price as a function of circulating supply would be where \(y = f(x) = x\):

When you make a purchase, you are moving the circulating supply from point \(a\) to point \(b\).

If I bought all 100 units of the token immediately, I would be moving the circulating supply from \(a = 0\) to \(b = 100\).

The price of the purchase is the area under the line between those two points:

In this simple case, it's easy to see visually that the cost is \(100^2 / 2 = 5000\).

What if the circulating supply is 40, and I want to purchase 20 units?:

We can use the difference of squares to calculate the area under the line.

It's the light green area \(b^2\) minus the dark green area \(a^2\), divided by two:

\(\frac{b^2 - a^2}{2} = \frac{60^2 - 40^2}{2} = 1000\)

Unfortunately, the area under the line from \(a\) to \(b\) isn't always going to be a whole number.

We can't divide beyond the base unit of either token being exchanged, so we need some way to find a price that is an integer.

Rounding up or down might be acceptable, but I also like the idea of taking the area above and below the line:

This will always be a whole number, and I can't think of a downside to this approach for the purpose of the bonding curve. The most important property is that the price of each unit is more than the price of the previous unit, and that is still preserved here.

Price is now represented by the orange line:

Slope & Intercept

Bonding curves can usually be parameterised for different use cases.

We can calculate the area above and below any straight line, without needing to use floating-point numbers.

Remembering back to high school maths, slope-intercept form is a linear equation with the structure \(y = mx + b\), where \(m\) is the slope and \(b\) is the intercept.

Let's say we want the price of each unit of MOON to be a constant 10 Algos.

We can pass 0 as the slope and 5 as the intercept:

If we want the price to trend towards the moon instead, we can set the slope to be 1,000 and the intercept to be 0:

The difference of squares formula doesn't work here, so let's figure out how to calculate prices.

If the current circulating supply is 62, and you want to buy 8 units:

The function of the blue line is \(f(x) = 1000x\).

The area of the rectangle is:

$$\displaylines{ \begin{aligned} & (f(a) + f(b)) \cdot (b - a) \\ &= (f(62) + f(70)) \cdot (70 - 62) \\ &= (62000 + 70000) \cdot (70 - 62) \\ &= 132000 \cdot 8 \\ &= 1056000 \\ \end{aligned} }$$

So the price of those 8 units is 1,056,000 Algos.

I think parameterised straight lines are probably sufficient for most token launch scenarios, but naturally people might also want to explore exponential curves, sigmoid functions, and other more exotic variants.

Curves

To determine the area under a bonding curve, we need to use calculus.

The Bancor formula is perhaps the most famous approach, but it uses some rather complicated code to handle fractional exponents in a smart contract.

What would happen if we approximated the price on an exponential curve using the formula discussed earlier?

Similar to the trapezium rule in calculus, the smaller the increment, the better the approximation of the curve:

So buying and selling smaller quantities gets you closer to the true price.

Buying all 100 units at once would incur a significant penalty, because the area under the curve is overestimated:

This property might actually be desirable. There are often disincentives for people buying and selling large quantities (anti-whale measures).

Of course with other types of curves, this could lead to underestimation.

It might also open up some more complex strategies and undesirable arbitrage opportunities.

If you have any thoughts on this approach, I'd love to hear them!

Summary

For linear functions, \((f(a) + f(b)) \cdot (b - a)\) is exactly twice the area below the line between point \(a\) and point \(b\).

This formula makes it easy to implement bonding curves in a smart contract, without needing to handle floating or fixed point numbers.

The same formula could also be applied to exponential curves, introducing a penalty for high-volume trades.