Skip to main content

ALTBCCalculator

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

State Variables

C_MIN

uint256 public constant C_MIN = 1e17;

C_MAX

uint256 public constant C_MAX = 1e36;

MIN_K

uint256 public constant MIN_K = 1e12;

MAX_K

uint256 public constant MAX_K = 1e17;

tbc

ALTBCDef public tbc;

Functions

constructor

constructor
constructor(
    address _xToken,
    address _yToken,
    uint16 _lpFee,
    uint16 _protocolFee,
    address _protocolFeeCollector,
    ALTBCInput memory _tbcInput,
    bool _liquidityRemovalAllowed,
    address sender
);
Parameters
NameTypeDescription
_xTokenaddressaddress of the X token (x axis)
_yTokenaddressaddress of the Y token (y axis)
_lpFeeuint16percentage of the fees in percentage basis points
_protocolFeeuint16percentage of the protocol fees in percentage basis points
_protocolFeeCollectoraddressthe address of the protocol fee collector
_tbcInputALTBCInputinput parameters for the TBC
_liquidityRemovalAllowedboolif true, liquidity can be removed at any time. Removal of liquidity forbidden otherwise.
senderaddressaddress 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.
function _spotPrice(uint256 x) internal view override 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) public override;
Parameters
NameTypeDescription
x_olduint256This parameter is not used in this function and is only present for backwards compatibility with the interface.
xuint256tracker 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).
function _calculateAmountOfXRequiredBuyingY(uint256 _amountOfY, uint256 x)
    internal
    view
    override
    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
    override
    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
    override
    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
    override
    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 override;

_validateTBC

A helper function to validate most of constructor’s inputs.
function _validateTBC(ALTBCInput memory _tbcInput) internal pure;
Parameters
NameTypeDescription
_tbcInputALTBCInputinput parameters for the TBC

_calculateRMax

This function calculates current revenue available
function _calculateRMax(uint256 x, uint256 R) internal view override returns (uint256 Rmax);
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
Ruint256the amount of revenue accrued for the owner of the pool over the lifetime of the pool
Returns
NameTypeDescription
Rmaxuint256the 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.
function _validateLiquidityAdd(uint256 x, uint256 afterBalance) internal view virtual override;
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