🌀Quick Farm Simulator Metaverse Smart Token's Partnership With MintClub🌀
🪙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.
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.
The contract places no hard limit on the number of tokens available. Instead there are 2 limiting factors:
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.
The price curve. This is where bonding contracts get interesting.
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.
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:
It should pay me 10x3=30 eth because the current selling price is 10eth
It should pay me 8x3 =24 eth because after giving the contract 3 tokens, the price is down to 8eth.
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.
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.
https://qiq.vq.pe