# Token Bonding Curves Explained

Published in

--

Now that all the ICO madness is dying down, a new form of token distribution seems to suddenly be taking off out of seemingly nowhere: the continuous token bonding curve. It’s a cleverly designed contract that creates its own market for the token without relying on exchanges. I’ve seen one or 2 explanations that breeze past the concept without fleshing it out properly so in this post I’ll attempt to explain what they are in as simple terms as possible. Warning: there will be a bit of maths later on but it isn’t essential for you to get the gist. After that, we’ll explore the implications.

## Definition

A bonding curve contract (bonding contract from now on) is one that issues its own tokens through buy and sell functions. To buy tokens, you send ether to the buy function which calculates the average price of the token in ether terms and issues you with the correct amount. The sell function works in reverse: first you provide the bonding contract with permission to take the amount of tokens you want to sell (ERC20.approve() ) and then you trigger the function to take those tokens from you. The contract will calculate the current average selling price and will send you the correct amount of ether.

## Scarcity

The contract places no hard limit on the number of tokens available. Instead there are 2 limiting factors:

1. the amount of ether in the world. If the price is 1 eth per token then you can’t buy more tokens than there is ether.
2. The price curve. This is where bonding contracts get interesting.

## Price

The actual price per token increases as the number of tokens issued increase. For instance, a very simple version of the contract specifies that the price in eth per token is equal to the number of tokens currently in existence. More specifically, to sell a token, the price is equal to the number of current tokens but to buy the price is equal to the number that will exist after you purchase. For instance, if there are 10 tokens in existence then selling 1 will earn you 10 eth. If you want to buy the 11th token, you’ll pay 11eth for it and so on.

Buying slides you up the price curve and selling slides you back down. In the example above, if there are 9 tokens in existence then we know that buying another token will cost 10eth. However, selling a token into the contract will earn us 9eth. If I sell another token, it will earn me 8eth. I could sell another 3 and be down to 5eth. But then if I buy, it will push the price up to 6eth again. So the price adjusts dynamically.

## Continuous

In reality, a person is not going to sell 1 token at a time. Instead they will sell in batches to save on gas costs. What happens if there are 10 tokens in existence and I want to sell 3 back into the contract? How much should it pay me? Choose from the following 3 which seems most reasonable:

1. It should pay me 10x3=30 eth because the current selling price is 10eth
2. It should pay me 8x3 =24 eth because after giving the contract 3 tokens, the price is down to 8eth.
3. It should give me 10+9+8 = 27 eth because that’s what I’d get paid if I paid 1 token at a time.

If you chose option 1, you’d have an unsustainable situation since the contract can only pay you with eth it already has. For illustration, suppose someone bought 1 token and then another person bought 1 token, then a third person bought a token and finally a fourth person bought a token. The contract would have 1+2+3+4= 10eth. Now all 4 people transfer their tokens to you and you want to sell them all at once for the highest price: 4eth. You’d be expecting 16eth in total but the contract only has 10eth to pay.

If you chose option 2, you’d be underpaid. For instance, if you sold 1 at a time, we know you’d get 27 so why should you be penalized for selling them all at once? The correct answer is of course option 3.

## Gas!

The non-intelligent way for a solidity programmer to design the sell function would be to loop through your tokens 1 at a time, selling each one and letting the price adjust downward. That would cost the same amount of gas as you just doing that yourself. So this implementation is pointless. Instead, we will use calculus to figure out the correct amount of ether in one go.

## Calculus

In the figure above, the price curve in eth is P=Q. Suppose there are Q0 tokens in existence and you wish to buy Q1-Q0. You won’t pay P0 because this is too low and you won’t pay P1 because it is too high. You need some midpoint price that would have the same effect as buying each token 1 at a time. From basic calculus, we know the area under the curve is the total amount of eth you will spend and to calculate that we simply take the definite integral between Q0 and Q1. Or, we calculate the definite integral between the origin and Q1 and subtract from it the integral between the origin and Q0 to get the area labelled A in red. The integral of the price function is

Let’s use real numbers now. Suppose the value of Q0 is 3 (implying P0 is also 3) and the value of Q1 is 7(implying P1 is also 7).

To calculate the area of A, we plug in the numbers:

This means that the amount of eth in total you’d have to pay is 20 eth. But before we purchase, we want to know what average price we’d pay per token. This is simple enough:

Using, calculus, the bonding contract can allow buying and selling of arbitrarily large quantities of tokens without spending more gas AND it ensures that the contract can always meet its ether obligations.

## Implications

Now that we know how it conceptually works, we’ll explore some of the big implications of the bonding contract that make it so much cooler than a traditional ICO:

1. If the buy and sell functions follow the same curve then ether can never be withdrawn from the contract. It has to remain 100% fully reserved. This means that project creators have to focus on making their token popular which aligns incentives between creators and users. They can’t launch an exit scam. In some cases, it might be desirable to create a spread between the buy and sell curves. All that this means is that you get less ether for selling than you’d pay for buying. The difference in ether is revenue to the creators. For instance, the buy price is P=Q² but the sell price is P=Q. This might seem like a nice way for project creators to orchestrate an exit scam. However, increasing interest in the ecosystem will still mean more revenue because the selling is an ongoing feature. In other words, churn generates more revenue than once off sales. So this feature still rewards projects with long term growth prospects over hit and run scams.
2. Just as so many ICOs promise, the bonding curve actually guarantees that early buyers will be able to sell at a profit, provided more buyers arrive. It naturally rewards early adopters and encourages word of mouth marketing.
3. Token buyers have an instant market, meaning that they don’t have to wait for the project creators to register with all the major exchanges. However, secondary exchanges will still help the ecosystem, especially when a spread between buy and sell functions exist. The price of the token is also 100% transparent at all times.
4. Accountability: Vitalik Buterin has suggested a DAICO as a way for ICOs to be governed according to a DAO which sets burn rates and gives the community the ability to freeze operations. The bonding curve model ensures that a spooked community can instantly hold the developers to account by selling all their tokens, driving the price to zero. At that point, even if there is a spread between buy and sell, the market has effectively dried up for the team.

## Conclusion

I hope this article explained in sufficient detail how this new and exciting token model works. Please let me know if I was unclear in any way and I’ll flesh it out and republish as needed.

Join Coinmonks Telegram Channel and Youtube Channel get daily Crypto News