Documentation Index
Fetch the complete documentation index at: https://docs.forteamm.io/llms.txt
Use this file to discover all available pages before exploring further.
Git Source
Author:
@oscarsernarosero @mpetersoCode55 @cirsteve @palmerg4
State Variables
FLOAT_2
packedFloat constant FLOAT_2 = packedFloat.wrap(0x7f6c00000000000000000000000000000f0bdc21abb48db201e86d4000000000);
FLOAT_NEG_1
packedFloat constant FLOAT_NEG_1 = packedFloat.wrap(0x7f6d00000000000000000000000000000785ee10d5da46d900f436a000000000);
FLOAT_0
packedFloat constant FLOAT_0 = packedFloat.wrap(0);
FLOAT_1
packedFloat constant FLOAT_1 = packedFloat.wrap(0x7f6c00000000000000000000000000000785ee10d5da46d900f436a000000000);
FLOAT_WAD
packedFloat constant FLOAT_WAD =
packedFloat.wrap(57507338264406853159277167054180511853162945875507645848942038639672188469248);
Functions
calculateBn
The result will be a packedFloat
Bn is equal to V / (Xn + C) in the spec
This function calculates B(n) and stores it in the tbc definition as b.
function calculateBn(ALTBCDef storage altbc, packedFloat Xn) internal;
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition |
Xn | packedFloat | the X value at n |
calculatefx
The result for f(x) will be a packedFloat.
This equation is used to calculate the spot price of the x token and is equal to (bn * x) + cn
This function calculates f(x) at n.
function calculatefx(ALTBCDef storage altbc, packedFloat x) internal view returns (packedFloat result);
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition |
x | packedFloat | value for x at n |
Returns
| Name | Type | Description |
|---|
result | packedFloat | the calculated f(x), this value will be a packedFloat |
calculateDn
The result for Dn will be a packedFloat
This equation is used to calculate the area under the curve at n and is equal to (1/2)(bnx^2) + cnx
This function calculates D at n.
function calculateDn(ALTBCDef storage altbc, packedFloat x) internal view returns (packedFloat result);
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition |
x | packedFloat | value for x at n |
Returns
| Name | Type | Description |
|---|
result | packedFloat | result |
calculateH
This method is implemented using packedFloats and the float128 library
This equation in the spec is equal to (Ln + Zn) / (Wn - wInactive) + phi
This function calculates h at n which is the total revenue per unit of liquidity at time n.
function calculateH(ALTBCDef storage altbc, packedFloat L, packedFloat W, packedFloat wInactive, packedFloat phi)
internal
view
returns (packedFloat result);
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | |
L | packedFloat | the x coordinate |
W | packedFloat | the total amount of units of liquidity in circulation |
wInactive | packedFloat | |
phi | packedFloat | the total amount of units of liquidity in circulation |
Returns
| Name | Type | Description |
|---|
result | packedFloat | the calculated h |
calculateXofNPlus1
This method is implemented using packedFloats and the float128 library
This equation in the spec is equal to 2Dn / (c + sqrt(c^2 + 2bDn))
This function calculates the value of Xn+1.
function calculateXofNPlus1(ALTBCDef storage altbc, packedFloat Dn) internal view returns (packedFloat newX);
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition |
Dn | packedFloat | the area under the curve. |
Returns
| Name | Type | Description |
|---|
newX | packedFloat | the calculated Xn+1 |
calculateC
This function calculates the parameter c and stores it in the tbc definition.
function calculateC(ALTBCDef storage altbc, packedFloat Xn, packedFloat oldBn) internal;
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition. |
Xn | packedFloat | the x coordinate |
oldBn | packedFloat | the previous state of b |
calculateLastRevenueClaim
The result for last revenue claim will be a Float.
This function calculates the last revenue claim to be stored in the associated LPToken variable rj. The result will be a WAD value.
function calculateLastRevenueClaim(packedFloat hn, packedFloat wj, packedFloat r_hat, packedFloat w_hat)
internal
pure
returns (packedFloat);
Parameters
| Name | Type | Description |
|---|
hn | packedFloat | The revenue parameter. Expected to be a Float. |
wj | packedFloat | The share of the pool’s liquidity the associated LPToken represents. Expected to be a Float. |
r_hat | packedFloat | The current last revenue claim value of the associated LPToken. Expected to be a Float. |
w_hat | packedFloat | The current liquidity amount of the associated LPToken. Expected to be a Float. |
calculateL
This function calculates the parameter L.
function calculateL(ALTBCDef storage altbc, packedFloat Xn) internal view returns (packedFloat result);
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition. |
Xn | packedFloat | the x coordinate |
Returns
| Name | Type | Description |
|---|
result | packedFloat | the calculate L parameter. |
calculateZ
This function calculates the parameter Z, which is a balancing quantity used to ensure fair LP accounting.
function calculateZ(
ALTBCDef storage altbc,
packedFloat Ln,
packedFloat Wn,
packedFloat WIn,
packedFloat q,
bool withdrawal
) internal;
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition. |
Ln | packedFloat | the liquidity parameter. |
Wn | packedFloat | the total amount of units of liquidity in circulation. |
WIn | packedFloat | the total amount of units of liquidity in circulation. |
q | packedFloat | the liquidity units to receive in exchange for A and B |
withdrawal | bool | the boolean value for withdrawal |
calculateQ
This function calculates q.
function calculateQ(
ALTBCDef storage altbc,
packedFloat Xn,
packedFloat _A,
packedFloat _B,
packedFloat L,
packedFloat Dn
) internal view returns (packedFloat A, packedFloat B, packedFloat q);
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition. |
Xn | packedFloat | the x coordinate |
_A | packedFloat | The amount of incoming X Token. |
_B | packedFloat | The amount of incoming collateral. |
L | packedFloat | the liquidity parameter. |
Dn | packedFloat | The current area under the curve. |
Returns
| Name | Type | Description |
|---|
A | packedFloat | the actual amount to take for token x |
B | packedFloat | the actual amount to take for token y |
q | packedFloat | the liquidity units to receive in exchange for A and B |
calculateRevenueAvailable
This function calculates the revenue available for a given LPToken.
function calculateRevenueAvailable(packedFloat wj, packedFloat hn, packedFloat rj)
internal
pure
returns (packedFloat result);
Parameters
| Name | Type | Description |
|---|
wj | packedFloat | The share of the pool’s liquidity the associated LPToken represents. |
hn | packedFloat | The revenue parameter. |
rj | packedFloat | The last revenue claim for the associated LPToken. |
Returns
| Name | Type | Description |
|---|
result | packedFloat | The calculated revenue available for the LPToken. |
_liquidityUpdateHelper
This function updates related tbc variables when a liquidity deposit or withdrawal is made
function _liquidityUpdateHelper(ALTBCDef storage altbc, packedFloat Xn, packedFloat multiplier)
internal
returns (packedFloat x);
Parameters
| Name | Type | Description |
|---|
altbc | ALTBCDef | the tbc definition. |
Xn | packedFloat | the x coordinate. |
multiplier | packedFloat | The value for multiplier for pool state |
Returns
| Name | Type | Description |
|---|
x | packedFloat | The updated x value. |