State Variables
tbc
Functions
constructor
constructor| Name | Type | Description |
|---|---|---|
_xToken | address | address of the X token (x axis) |
_yToken | address | address of the Y token (y axis) |
_lpToken | address | |
_inactiveLpId | uint256 | |
fees | FeeInfo | fee infomation |
_tbcInput | ALTBCInput | input parameters for the TBC |
_VERSION | string |
initializePool
This is the function to initialize the pool.| Name | Type | Description |
|---|---|---|
deployer | address | The address of the deployer |
initialLiq | uint256 | |
___wInactive | uint256 | initial inactive liquidity for the pool |
simulateLiquidityDeposit
This is the function to simulate a liquidity deposit into the pool.| Name | Type | Description |
|---|---|---|
_A | uint256 | The amount of xToken being deposited as liquidity in the simulation. |
_B | uint256 | The amount of yToken being deposited as liquidity in the simulation. |
| Name | Type | Description |
|---|---|---|
A | uint256 | calculated A value which is the amount of xToken that will be deposited |
B | uint256 | calculated B value which is the amount of yToken that will be deposited |
Q | uint256 | calculated Q value which is the ratio of this provided liquidity unit to the total liquidity of the pool |
ratio | int256 | calculated ratio of xToken to yToken required for the deposit |
qFloat | packedFloat | calculated qFloat value which is the ratio of this provided liquidity unit to the total liquidity of the pool in packedFloat format |
L | packedFloat |
tokenDepositUpdate
depositLiquidity
If the tokenId provided is owned by the lp, this tokenId will be updated based on liquidity deposit This is the function to deposit liquidity into the pool.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider. |
_A | uint256 | The amount of xToken being deposited as liquidity. |
_B | uint256 | The amount of yToken being deposited as liquidity. |
_minA | uint256 | The minimum acceptable amount of xToken actually deposited as liquidity. |
_minB | uint256 | The minimum acceptable amount of yToken actually deposited as liquidity. |
expires | uint256 | Timestamp at which the deposit transaction will expire. |
| Name | Type | Description |
|---|---|---|
A | uint256 | calculated A value |
B | uint256 | calculated B value |
simulateWithdrawLiquidity
This is the function to simulate a liquidity withdrawal from the pool. To get rj and uj, call the getLPToken function and pass in the rj and uj values| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider. |
uj | uint256 | The amount of liquidity being withdrawn |
_uj | packedFloat | The amount of liquidity being withdrawn in packedFloat format |
| Name | Type | Description |
|---|---|---|
Ax | uint256 | The amount of xToken to be received |
Ay | uint256 | The amount of yToken to be received |
revenueAccrued | uint256 | The amount of revenue accrued to the liquidity position |
q | packedFloat | The ratio of this provided liquidity unit to the total liquidity of the pool |
L | packedFloat | |
wj | packedFloat | |
rj | packedFloat |
withdrawPartialLiquidity
This is the function to withdraw partial liquidity from the pool.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider. |
uj | uint256 | The amount of liquidity being withdrawn |
recipient | address | address that receives withdrawn liquidity |
_minAx | uint256 | The minimum acceptable amount of xToken actually withdrawn from liquidity. |
_minAy | uint256 | The minimum acceptable amount of yToken actually withdrawn from liquidity. |
expires | uint256 | Timestamp at which the withdraw transaction will expire. |
withdrawAllLiquidity
This is the function to withdraw all token liquidity from the pool.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider. |
recipient | address | address that receives withdrawn liquidity |
_minAx | uint256 | The minimum acceptable amount of xToken actually withdrawn from liquidity. |
_minAy | uint256 | The minimum acceptable amount of yToken actually withdrawn from liquidity. |
expires | uint256 | Timestamp at which the withdraw transaction will expire. |
_withdrawLiquidity
This is the function to withdraw liquidity from the pool.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider. |
_uj | packedFloat | The amount of liquidity being withdrawn |
recipient | address | address that receives withdrawn liquidity |
_minAx | uint256 | The minimum acceptable amount of xToken actually withdrawn from liquidity. |
_minAy | uint256 | The minimum acceptable amount of yToken actually withdrawn from liquidity. |
_emitLiquidityWithdrawn
This is the function to emit the LiquidityWithdrawn event.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider. |
Ax | uint256 | The amount of xToken to be received |
Ay | uint256 | The amount of yToken to be received |
revenueAccrued | uint256 | The amount of revenue accrued to the liquidity position |
recipient | address | The address that receives the withdrawn liquidity |
withdrawRevenue
This is the function to withdraw revenue from the pool.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider. |
Q | uint256 | The amount of revenue being withdrawn |
recipient | address |
| Name | Type | Description |
|---|---|---|
revenue | uint256 | The amount of revenue being withdrawn |
revenueAvailable
This is the function to get the revenue available for a liquidity position.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId representing the liquidity position |
| Name | Type | Description |
|---|---|---|
_revenueAvailable | uint256 | The amount of revenue available for the liquidity position |
_getRevenueAvailable
This is the function to get the revenue available for a liquidity provider.| Name | Type | Description |
|---|---|---|
tokenId | uint256 | The tokenId owned by the liquidity provider |
| Name | Type | Description |
|---|---|---|
hn | packedFloat | The total revenue per liquidity unit for the pool |
_wj | packedFloat | The amount of liquidity units of the specified token |
_rj | packedFloat | The revenue accrued to the liquidity position |
_revenueAvailable | packedFloat | The amount of revenue available for the liquidity provider |
revenueAvailableUint | uint256 |
_spotPrice
x + 1 is used for returning the price of the next token sold, not the price of the last token sold This is the function to retrieve the current spot price of the x token.| Name | Type | Description |
|---|---|---|
sPrice | packedFloat | the price in YToken Decimals |
_updateParameters
This function updates the state of the math values of the pool._calculateAmountOfXRequiredBuyingY
This function calculates the amount of token X required for the user to purchase a specific amount of Token Y (buy y with x : out perspective).| Name | Type | Description |
|---|---|---|
_amountOfY | packedFloat | desired amount of token Y |
| Name | Type | Description |
|---|---|---|
amountOfX | packedFloat | required amount of token X |
_calculateAmountOfYRequiredBuyingX
This function calculates the amount of token Y required for the user to purchase a specific amount of Token X (buy x with y : out perspective).| Name | Type | Description |
|---|---|---|
_amountOfX | packedFloat | desired amount of token X (also known as An in the spec) |
| Name | Type | Description |
|---|---|---|
amountOfY | packedFloat | required amount of token Y |
_calculateAmountOfYReceivedSellingX
This function calculates the amount of token Y the user will receive when selling token X (sell x for y : in perspective).| Name | Type | Description |
|---|---|---|
_amountOfX | packedFloat | amount of token X to be sold |
| Name | Type | Description |
|---|---|---|
amountOfY | packedFloat | amount of token Y to be received |
_calculateAmountOfXReceivedSellingY
This function calculates the amount of token X the user will receive when selling token Y (sell y for x : in perspective).| Name | Type | Description |
|---|---|---|
_amountOfY | packedFloat | amount of token Y to be sold |
| Name | Type | Description |
|---|---|---|
amountOfX | packedFloat | amount of token X to be received |
_validateTBC
A helper function to validate most of constructor’s inputs.| Name | Type | Description |
|---|---|---|
_tbcInput | ALTBCInput | input parameters for the TBC |
checkInactiveLiquidity
The threshold is set to 1% of the active liquidity units Check for ration of inactive to active (token Id 2) liquidity, reverts if ratio is above threshold| Name | Type | Description |
|---|---|---|
_active | packedFloat | active liquidity units |
_inactive | packedFloat | inactive liquidity units |