ALTBCCalculator
Git Source Inherits: CalculatorBase, Constants Author: @oscarsernarosero @mpetersoCode55 @cirsteve This contract serves as the base for all the calculators.State Variables
C_MIN
C_MAX
MIN_K
MAX_K
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) |
_lpFee | uint16 | percentage of the fees in percentage basis points |
_protocolFee | uint16 | percentage of the protocol fees in percentage basis points |
_protocolFeeCollector | address | the address of the protocol fee collector |
_tbcInput | ALTBCInput | input parameters for the TBC |
_liquidityRemovalAllowed | bool | if true, liquidity can be removed at any time. Removal of liquidity forbidden otherwise. |
sender | address | address of the to-be owner |
_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 |
|---|---|---|
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade |
| Name | Type | Description |
|---|---|---|
sPrice | uint256 | the price in YToken Decimals |
_updateParameters
This function updates the state of the math values of the pool.| Name | Type | Description |
|---|---|---|
x_old | uint256 | This parameter is not used in this function and is only present for backwards compatibility with the interface. |
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade |
_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 | uint256 | desired amount of token Y |
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade |
| Name | Type | Description |
|---|---|---|
amountOfX | uint256 | 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 | uint256 | desired amount of token X |
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade |
| Name | Type | Description |
|---|---|---|
amountOfY | uint256 | 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 | uint256 | amount of token X to be sold |
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade |
| Name | Type | Description |
|---|---|---|
amountOfY | uint256 | 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 | uint256 | amount of token Y to be sold |
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade. |
| Name | Type | Description |
|---|---|---|
amountOfX | uint256 | amount of token X to be received |
_clearState
This function cleans the state of the calculator in the case of the pool closing._validateTBC
A helper function to validate most of constructor’s inputs.| Name | Type | Description |
|---|---|---|
_tbcInput | ALTBCInput | input parameters for the TBC |
_calculateRMax
This function calculates current revenue available| Name | Type | Description |
|---|---|---|
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade |
R | uint256 | the amount of revenue accrued for the owner of the pool over the lifetime of the pool |
| Name | Type | Description |
|---|---|---|
Rmax | uint256 | the amount of revenue available to be pulled in native yToken decimals |
_validateLiquidityAdd
This function validates the liquidity addition to ensure it does not exceed the max supply of xToken.| Name | Type | Description |
|---|---|---|
x | uint256 | tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade |
afterBalance | uint256 | the balance of xToken after the addition |