Bonding Curve Formula
This document is a simple guide on changing variables within the Fairside Formula. This is not an in depth mathematical guide rather an introduction from an engineering point of view
Overview
The FS Formula is a combination of mathematical equations that handle how the Fairside curve works.
The FS Formula makes use of the ABDKMathQuad.sol
library which helps solidity calculate
IEEE 754 quadruple-precision binary floating-point numbers (quadruple precision numbers) in byte16
Changing constants :
Changing either A or C constants in the FS Formular code is not just a changing the variable of byte16 to another byte 16 in the codebase, some other mathematical equations have to be done.
helper functions
and
can be used to convert number between uint256 and bytes16 format.
Steps
Given an A constant of 0.00015 to effect this change on the codebase one must do the following steps.
Convert it to fractions which is 3 / 2000
Use the
ABDKMathQuad.sol
methodfromInt
to turn these numbers into the compliant hex and call theperform division using the
div
functions
There are maths formulae in comments above each of the defined methods outline above, use Chatgpt or any calculator to derive the value of those methods.
Bonding Curve
Fairside followed this post as for the implementation of our bonding curve.
Bonding curve formula is defined as following:
Price: the $Fair token price.
A and C: constants defined as 0.00015 and 55,000,000 respectively
Fshare: The minimum amount of capital required to support existing cost sharing measured it in ETH. The Fshare is a combination of off-chain actuarial calculations to manage the reserve capital and maintain financial strength to support the ongoing product operations. The output is dynamic based on the amount of memberships. However, the output of this formula remains constant during bonding and unbonding computations of $Fair. Fshare:
Fshare ratio: Ratio of Capital Pool funds to the Minimum Capital Requirement(fShare)
Therefore starting with the basic price formula from the introduction we get to the price formula as a function of V as such:
To get the actual price over a supply change on the curve:
ΔT be a very small change in the token supply
ΔV the corresponding very small change in V
P(V) — the point price at value V.
This means that for an infinitesimally small change in V equal to ΔV, we get an infinitesimally small change in token supply T equal to ΔT. Key assumption: for this change we assume P(V) constant since the change in V is very small.
To find out the tokens to be minted for a large ΔV (let that be called ethIn) which takes us from V0 to V1 = V0 + ethIn in total asset value, we would want to integrate the formula above with respect to V to get the resulting token amount T to be minted.
Due to limitation on solidity, the above integration function could be difficult to be implemented. An approximated solution is used which is more computational efficient.
After some math simplification(please check original post), the final pseudocode is:
After some invariant tests, we conclude that the approximated implementation could generate almost same results as the original results(implemented in other language as test reference). The deviation is a little bit higher during the early day when the curve reserve is small comparing to the size of the delta.
Last updated