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.

bytes16 private constant MULTIPLIER_INNER_LOG_B
bytes16 private constant MULTIPLIER_INNER_LOG_A
bytes16 private constant MULTIPLIER_INNER_ARCTAN
bytes16 private constant MULTIPLIER_FULL

helper functions

normalize(bytes16 x)

and

denormalize(uint256 a)

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 method fromInt to turn these numbers into the compliant hex and call the

  • perform 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=A+xfshareCfshare ratio4Price = A + x * \frac{fshare}{C} * {fshare\ ratio}^{4}

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)

fshare ratio=Vfsharefshare\ ratio = \frac{V}{fshare}

Therefore starting with the basic price formula from the introduction we get to the price formula as a function of V as such:

Price=a+fshareCV4fshare4=a+V4Cfshare3Price = a + \frac{fshare}{C} * \frac{{V}^{4}}{{fshare}^{4}} = a + \frac{{V}^{4}}{C * {fshare}^{3}}

To get the actual price over a supply change on the curve:

ΔT=ΔVP(V)\Delta T = \frac{\Delta V}{P(V)}
  • Δ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.

V0V1(dVp(V))\int_{V0}^{V1}{(\frac{dV}{p(V)})}

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.

AdjustedP(V)=V4Cfshare3Adjusted P(V) = \frac{V4}{C * {fshare}^{3}}

After some math simplification(please check original post), the final pseudocode is:

q = C * MCReth ^ 3
adjustedTokens = - q / (3 * (V0+Vbuy) ^ 3)+ q /(3 * V0 ^ 3)
adjustedPrice = Vbuy / adjustedTokens
finalPrice = adjustedPrice + A
tokensOut = deltaETH / finalPrice 

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