๐Ÿ“ˆ
Bonding Curve

Branch Info

Author: Viraz Source code: https://github.com/scaffold-eth/scaffold-eth-examples/tree/chainlink-tutorial-1 Intended audience: Beginners/Intermediate Topics: Scaffold-eth basics, tokenomics, bonding curves
Learn about bonding curves and play around with the ๐Ÿ˜ƒ bonding curve token

Getting Started & Setting Up

1
git clone https://github.com/scaffold-eth/scaffold-eth-examples.git your-next-dapp
2
โ€‹
3
cd your-next-dapp
Copied!
1
yarn install
Copied!
1
yarn start
Copied!
in a second terminal window:
1
yarn chain
Copied!
in a third terminal window:
1
yarn deploy
Copied!
Use the faucet wallet to send your local account some funds in order to interact with the contract:
โ€‹โ€‹
โ€‹
โ€‹
Once you run the above steps you can then interact with the contract after clicking on "Example UI" and do all kinds of operations with SMILE Bonding Curve Contract.
โ€‹โ€‹
โ€‹
โ€‹
The subgraph has also been updated with the bonding curve contract so you can easily set it up seeing the instructions and interact with it with the help of the playground.
โ€‹โ€‹
โ€‹
โ€‹

What is a Bonding Curve ?

โ€‹โ€‹
โ€‹
โ€‹
A Bonding curve is a mathematical curve that defines a relationship between price and token supply, basically as a the supply of a token increases the it's price increases as well hece the price of nth token will be less than n+1th token and so on.

How it works ?

So basically it works like this during the deployment there is a Mock Dai contract that is deployed as well in addition to YourContract.sol and while the owner locks some mock dai into the contract to set the reserve amount which also demonstrates the use of approve and call i.e approving YourContract for spending mock dai and minting in the same block, then anyone can call the mint function lock up some eth and they get some SMILE (๐Ÿ˜ƒ) Tokens minted based on a formula discussed below, and in order to get your mock dai amount back you need to call burn() and burn the SMILE (๐Ÿ˜ƒ) tokens and based on the price at that point you get that amount of eth back.

Price Sensitivity

As mentioned below Purchase Return is basically the number of ๐Ÿ˜ƒ Tokens you get when you lock in your Mock DAI Tokens, now this and Sale Return depend on mainly 3 variables
  • ReserveTokensReceived The Amount of Mock DAI you decide to lock in.
  • ReserveTokenBalance The Mock DAI Tokens already locked before (for testing purposes when no ๐Ÿ˜ƒ Tokens have been minted yet we assume the ReserveTokenBalance to be 1 wei, in a mainnet scenario as soon as the contract is deployed we transfer a small amount i.e 1 wei worth of reserve token to the contract).
  • ReserveRatio Currently it is set at 10 % but let's see how different reserve ratio's affect the price.
โ€‹โ€‹
โ€‹
โ€‹
The diagram above shows some examples of bonding curves with different Reserve Ratios. In the bottom-left curve with a 10% Reserve Ratio, the price curve grow more aggressively with increasing supply. A Reserve Ratio higher than 10% would flatten towards the linear top-right shape as it approaches 50%.

Mathmatical Formula

  • Reserve Ratio When deploying we need to pass in a reserve ratio which currently is 100000(10 %) for high price sensitivity but can range from 0 - 100, higher reserve ratio between the Reserve Token balance and the SMILE (๐Ÿ˜ƒ) Token will result in lower price sensitivity, meaning that each buy and sell will have a less than proportionate effect on the SMILE (๐Ÿ˜ƒ) Tokenโ€™s price movement. Though it is calculated as Reserve Ratio = Reserve Token Balance / (SMILE Token Supply x SMILE Token Price)
  • Purchase Return The Amount of SMILE (๐Ÿ˜ƒ) Tokenโ€™s you get after you stake mock dai it is calculated as Purchase Return = SMILE Token Supply * ((1 + ReserveTokensReceived / ReserveTokenBalance) ^ (ReserveRatio) - 1)
  • Sale Return The Amount of Mock DAI you get based on the amount of SMILE (๐Ÿ˜ƒ) token's you choose to burn and the current price at that point it is calculated as Sale Return = ReserveTokenBalance * (1 - (1 - SMILE Token Received / SMILE Token Supply) ^ (1 / (ReserveRatio)))**