State Variables
FLOAT_2
FLOAT_NEG_1
FLOAT_0
FLOAT_1
FLOAT_WAD
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.| 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.| Name | Type | Description |
|---|---|---|
altbc | ALTBCDef | the tbc definition |
x | packedFloat | value for x at n |
| 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.| Name | Type | Description |
|---|---|---|
altbc | ALTBCDef | the tbc definition |
x | packedFloat | value for x at n |
| 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.| 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 |
| 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.| Name | Type | Description |
|---|---|---|
altbc | ALTBCDef | the tbc definition |
Dn | packedFloat | the area under the curve. |
| Name | Type | Description |
|---|---|---|
newX | packedFloat | the calculated Xn+1 |
calculateC
This function calculates the parameter c and stores it in the tbc definition.| 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.| 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.| Name | Type | Description |
|---|---|---|
altbc | ALTBCDef | the tbc definition. |
Xn | packedFloat | the x coordinate |
| 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.| 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.| 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. |
| 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.| 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. |
| 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| Name | Type | Description |
|---|---|---|
altbc | ALTBCDef | the tbc definition. |
Xn | packedFloat | the x coordinate. |
multiplier | packedFloat | The value for multiplier for pool state |
| Name | Type | Description |
|---|---|---|
x | packedFloat | The updated x value. |