Skip to main content

ALTBCEquations

Git Source Author: @oscarsernarosero @mpetersoCode55 @cirsteve

State Variables

MOST_SIGNIFICANT_BIT_SET_TO_1

uint256 constant MOST_SIGNIFICANT_BIT_SET_TO_1 = 0x8000000000000000000000000000000000000000000000000000000000000000;

Functions

calculateS

The result will be a WAD number. This function calculates s(n) and stores it in the tbc definition as b.
function calculateS(ALTBCDef storage altbc, uint256 Xn) internal;
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition
Xnuint256the X value at n, this parameter is expected to be in WEI/WAD

calculateConstantC

This function expects the parameters to be WAD numbers, the result will also be a WAD number. This function calculates the constant C and stores it in the tbc definition.
function calculateConstantC(ALTBCDef storage altbc) internal;
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition

calculateC

The result for c will be in WAD ** 2. This function calculates the parameter c and stores it in the tbc definition. The result will be in WAD ** 2.
function calculateC(ALTBCDef storage altbc, uint256 Xn, uint256 DnLow, uint256 DnHigh) internal;
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition. Parameters used are expected to be in WAD ** 2.
Xnuint256the x coordinate, this parameter is expected to naturally be in WAD
DnLowuint256lower bits of the area under the curve, this parameter is expected to be multiplied by WAD ** 4
DnHighuint256higher bits of the area under the curve, this parameter is expected to be multiplied by WAD ** 4

calculatefx

The result for f(x) will be in WAD. This function calculates f(x) at n.
function calculatefx(ALTBCDef storage altbc, uint256 x) internal view returns (uint256 result);
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition
xuint256value for x at n, this parameter is expected to naturally be in WAD
Returns
NameTypeDescription
resultuint256the calculated f(x), this value will be a WAD number

calculateFxWAD4

The result for F(x) will be in WAD ** 4. This function calculates F(x) at n and returns the result as a 512 bit number.
function calculateFxWAD4(ALTBCDef storage altbc, uint256 x)
    internal
    view
    returns (uint256 resultLow, uint256 resultHigh);
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition
xuint256value for x at n, this parameter is expected to naturally be in WAD
Returns
NameTypeDescription
resultLowuint256the lower bits of the calculated F(x), this value will be a WAD ** 4 number
resultHighuint256the higher bits of the calculated F(x), this value will be a WAD ** 4 number

calculateFx

The result for F(x) will be in WAD. This function calculates F(x) at n.
function calculateFx(ALTBCDef storage altbc, uint256 x) internal view returns (uint256 result);
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition
xuint256value for x at n, this parameter is expected to naturally be in WAD
Returns
NameTypeDescription
resultuint256the calculated F(x), this value will be a WAD number

calculateDv

The result for Dv will be in WAD ** 2. This function calculates the virtual liquidity of the pool.
function calculateDv(ALTBCDef storage altbc) internal;
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition

calculateFxInverse

The result for F(D) inverse will be in WAD. This function calculates F(D) inverse at n.
function calculateFxInverse(ALTBCDef storage altbc, uint256 D) internal view returns (uint256 result);
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition
Duint256Area under the TBC curve before the nth transaction, this parameter is expected to be a WAD number
Returns
NameTypeDescription
resultuint256the calculated F(D) inverse, this value will be a WAD number

calculateCInitial

We proceed to increase numerator precision by multiplying it by WAD. In the case of third param, this means we need to make it square to put it inside the square root without effecting the math. We also multiply the subtrahend of the numerator by WAD to keep it consistent The result for c will be in WAD ** 2. This function calculates the intial value of c.
function calculateCInitial(ALTBCDef storage altbc) internal;
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition

calculateRMax

The result for RMax will be in WAD. This function calculates RMax at n which is the total revenue a developer can collect from the TBC at time n.
function calculateRMax(ALTBCDef storage altbc, uint256 Xn, uint256 R) internal view returns (uint256 result);
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition
Xnuint256the x coordinate, this parameter is expected to be value in WAD
Ruint256the amount of revenue accrued for the owner of the pool over the lifetime of the pool
Returns
NameTypeDescription
resultuint256the calculated RMax, this value will be a WAD number

rMaxNaturalLogCalc

The result for the natural logarithm of the ratio of xMin and Xn will be in WAD ** 2. this result needs to be multlied by -1 to be properly used in the RMax calculation This function calculates the natural logarithm of the ratio of xMin and Xn.
function rMaxNaturalLogCalc(ALTBCDef storage altbc, uint256 Xn) internal view returns (uint256 result);
Parameters
NameTypeDescription
altbcALTBCDefthe tbc definition
Xnuint256the x coordinate, this parameter is expected to be in WAD
Returns
NameTypeDescription
resultuint256the calculated natural logarithm of the ratio of xMin and Xn, this value will be a WAD ** 2 number