Skip to main content

CalculatorBase

Git Source Author: @oscarsernarosero @mpetersoCode55 @cirsteve This contract serves as the base for all the calculators.

Functions

_spotPrice

This is the function to retrieve the current spot price of the x token.
function _spotPrice(uint256 x) internal view virtual returns (uint256 sPrice);
Parameters
NameTypeDescription
xuint256tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade
Returns
NameTypeDescription
sPriceuint256the price in YToken Decimals

_updateParameters

This function updates the state of the math values of the pool.
function _updateParameters(uint256 x_old, uint256 x_current) public virtual;
Parameters
NameTypeDescription
x_olduint256the previous tracker for x
x_currentuint256the current tracker for x value

_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).
function _calculateAmountOfXRequiredBuyingY(uint256 _amountOfY, uint256 x)
    internal
    view
    virtual
    returns (uint256 amountOfX);
Parameters
NameTypeDescription
_amountOfYuint256desired amount of token Y
xuint256tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade
Returns
NameTypeDescription
amountOfXuint256required 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).
function _calculateAmountOfYRequiredBuyingX(uint256 _amountOfX, uint256 x)
    internal
    view
    virtual
    returns (uint256 amountOfY);
Parameters
NameTypeDescription
_amountOfXuint256desired amount of token X
xuint256tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade
Returns
NameTypeDescription
amountOfYuint256required 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).
function _calculateAmountOfYReceivedSellingX(uint256 _amountOfX, uint256 x)
    internal
    view
    virtual
    returns (uint256 amountOfY);
Parameters
NameTypeDescription
_amountOfXuint256amount of token X to be sold
xuint256tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade
Returns
NameTypeDescription
amountOfYuint256amount 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).
function _calculateAmountOfXReceivedSellingY(uint256 _amountOfY, uint256 x)
    internal
    view
    virtual
    returns (uint256 amountOfX);
Parameters
NameTypeDescription
_amountOfYuint256amount of token Y to be sold
xuint256tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade
Returns
NameTypeDescription
amountOfXuint256amount of token X to be received

_clearState

This function cleans the state of the calculator in the case of the pool closing.
function _clearState() internal virtual;

_calculateRMax

This function returns the amount of maximum revenue available to be withdrawn by the owner.
function _calculateRMax(uint256 x, uint256 R) internal view virtual returns (uint256);
Parameters
NameTypeDescription
xuint256tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade
Ruint256current lifitime revenue claimed
Returns
NameTypeDescription
<none>uint256the maximum revenue available to be withdrawn by the owner

_validateLiquidityAdd

This function validates the liquidity addition to ensure it does not exceed the max supply of xToken.
function _validateLiquidityAdd(uint256 x, uint256 afterBalance) internal view virtual;
Parameters
NameTypeDescription
xuint256tracker value for the net amount of xTokens sold to the public. Bare in mind that this value is offset by initial synthetic trade
afterBalanceuint256the balance of xToken after the addition