Skip to main content
Git Source Inherits: PoolBase, Initializable Author: @oscarsernarosero @mpetersoCode55 @cirsteve This contract serves the purpose of facilitating swaps between a pair of tokens, where one is an xToken and the other one is a yToken.

State Variables

tbc

ALTBCDef public tbc;

Functions

constructor

constructor
constructor(
    address _xToken,
    address _yToken,
    address _lpToken,
    uint256 _inactiveLpId,
    FeeInfo memory fees,
    ALTBCInput memory _tbcInput,
    string memory _VERSION
) PoolBase(_xToken, _yToken, _lpToken, _inactiveLpId, fees);
Parameters
NameTypeDescription
_xTokenaddressaddress of the X token (x axis)
_yTokenaddressaddress of the Y token (y axis)
_lpTokenaddress
_inactiveLpIduint256
feesFeeInfofee infomation
_tbcInputALTBCInputinput parameters for the TBC
_VERSIONstring

initializePool

This is the function to initialize the pool.
function initializePool(address deployer, uint256 initialLiq, uint256 ___wInactive) external onlyOwner initializer;
Parameters
NameTypeDescription
deployeraddressThe address of the deployer
initialLiquint256
___wInactiveuint256initial inactive liquidity for the pool

simulateLiquidityDeposit

This is the function to simulate a liquidity deposit into the pool.
function simulateLiquidityDeposit(uint256 _A, uint256 _B)
    public
    view
    returns (uint256 A, uint256 B, uint256 Q, int256 ratio, packedFloat qFloat, packedFloat L);
Parameters
NameTypeDescription
_Auint256The amount of xToken being deposited as liquidity in the simulation.
_Buint256The amount of yToken being deposited as liquidity in the simulation.
Returns
NameTypeDescription
Auint256calculated A value which is the amount of xToken that will be deposited
Buint256calculated B value which is the amount of yToken that will be deposited
Quint256calculated Q value which is the ratio of this provided liquidity unit to the total liquidity of the pool
ratioint256calculated ratio of xToken to yToken required for the deposit
qFloatpackedFloatcalculated qFloat value which is the ratio of this provided liquidity unit to the total liquidity of the pool in packedFloat format
LpackedFloat

tokenDepositUpdate

function tokenDepositUpdate(uint256 tokenId, packedFloat wj) internal returns (uint256);

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.
function depositLiquidity(uint256 tokenId, uint256 _A, uint256 _B, uint256 _minA, uint256 _minB, uint256 expires)
    external
    whenNotPaused
    checkExpiration(expires)
    returns (uint256 A, uint256 B);
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider.
_Auint256The amount of xToken being deposited as liquidity.
_Buint256The amount of yToken being deposited as liquidity.
_minAuint256The minimum acceptable amount of xToken actually deposited as liquidity.
_minBuint256The minimum acceptable amount of yToken actually deposited as liquidity.
expiresuint256Timestamp at which the deposit transaction will expire.
Returns
NameTypeDescription
Auint256calculated A value
Buint256calculated 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
function simulateWithdrawLiquidity(uint256 tokenId, uint256 uj, packedFloat _uj)
    public
    view
    returns (
        uint256 Ax,
        uint256 Ay,
        uint256 revenueAccrued,
        packedFloat q,
        packedFloat L,
        packedFloat wj,
        packedFloat rj
    );
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider.
ujuint256The amount of liquidity being withdrawn
_ujpackedFloatThe amount of liquidity being withdrawn in packedFloat format
Returns
NameTypeDescription
Axuint256The amount of xToken to be received
Ayuint256The amount of yToken to be received
revenueAccrueduint256The amount of revenue accrued to the liquidity position
qpackedFloatThe ratio of this provided liquidity unit to the total liquidity of the pool
LpackedFloat
wjpackedFloat
rjpackedFloat

withdrawPartialLiquidity

This is the function to withdraw partial liquidity from the pool.
function withdrawPartialLiquidity(
    uint256 tokenId,
    uint256 uj,
    address recipient,
    uint256 _minAx,
    uint256 _minAy,
    uint256 expires
) external checkExpiration(expires);
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider.
ujuint256The amount of liquidity being withdrawn
recipientaddressaddress that receives withdrawn liquidity
_minAxuint256The minimum acceptable amount of xToken actually withdrawn from liquidity.
_minAyuint256The minimum acceptable amount of yToken actually withdrawn from liquidity.
expiresuint256Timestamp at which the withdraw transaction will expire.

withdrawAllLiquidity

This is the function to withdraw all token liquidity from the pool.
function withdrawAllLiquidity(uint256 tokenId, address recipient, uint256 _minAx, uint256 _minAy, uint256 expires)
    external
    checkExpiration(expires);
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider.
recipientaddressaddress that receives withdrawn liquidity
_minAxuint256The minimum acceptable amount of xToken actually withdrawn from liquidity.
_minAyuint256The minimum acceptable amount of yToken actually withdrawn from liquidity.
expiresuint256Timestamp at which the withdraw transaction will expire.

_withdrawLiquidity

This is the function to withdraw liquidity from the pool.
function _withdrawLiquidity(uint256 tokenId, packedFloat _uj, address recipient, uint256 _minAx, uint256 _minAy)
    internal;
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider.
_ujpackedFloatThe amount of liquidity being withdrawn
recipientaddressaddress that receives withdrawn liquidity
_minAxuint256The minimum acceptable amount of xToken actually withdrawn from liquidity.
_minAyuint256The minimum acceptable amount of yToken actually withdrawn from liquidity.

_emitLiquidityWithdrawn

This is the function to emit the LiquidityWithdrawn event.
function _emitLiquidityWithdrawn(uint256 tokenId, uint256 Ax, uint256 Ay, uint256 revenueAccrued, address recipient)
    private;
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider.
Axuint256The amount of xToken to be received
Ayuint256The amount of yToken to be received
revenueAccrueduint256The amount of revenue accrued to the liquidity position
recipientaddressThe address that receives the withdrawn liquidity

withdrawRevenue

This is the function to withdraw revenue from the pool.
function withdrawRevenue(uint256 tokenId, uint256 Q, address recipient) external returns (uint256 revenue);
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider.
Quint256The amount of revenue being withdrawn
recipientaddress
Returns
NameTypeDescription
revenueuint256The amount of revenue being withdrawn

revenueAvailable

This is the function to get the revenue available for a liquidity position.
function revenueAvailable(uint256 tokenId) public view returns (uint256 _revenueAvailable);
Parameters
NameTypeDescription
tokenIduint256The tokenId representing the liquidity position
Returns
NameTypeDescription
_revenueAvailableuint256The amount of revenue available for the liquidity position

_getRevenueAvailable

This is the function to get the revenue available for a liquidity provider.
function _getRevenueAvailable(uint256 tokenId)
    internal
    view
    returns (
        packedFloat hn,
        packedFloat _wj,
        packedFloat _rj,
        packedFloat _revenueAvailable,
        uint256 revenueAvailableUint
    );
Parameters
NameTypeDescription
tokenIduint256The tokenId owned by the liquidity provider
Returns
NameTypeDescription
hnpackedFloatThe total revenue per liquidity unit for the pool
_wjpackedFloatThe amount of liquidity units of the specified token
_rjpackedFloatThe revenue accrued to the liquidity position
_revenueAvailablepackedFloatThe amount of revenue available for the liquidity provider
revenueAvailableUintuint256

_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() internal view override returns (packedFloat sPrice);
Returns
NameTypeDescription
sPricepackedFloatthe price in YToken Decimals

_updateParameters

This function updates the state of the math values of the pool.
function _updateParameters() internal override;

_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(packedFloat _amountOfY)
    internal
    view
    override
    returns (packedFloat amountOfX);
Parameters
NameTypeDescription
_amountOfYpackedFloatdesired amount of token Y
Returns
NameTypeDescription
amountOfXpackedFloatrequired 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(packedFloat _amountOfX)
    internal
    view
    override
    returns (packedFloat amountOfY);
Parameters
NameTypeDescription
_amountOfXpackedFloatdesired amount of token X (also known as An in the spec)
Returns
NameTypeDescription
amountOfYpackedFloatrequired 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(packedFloat _amountOfX)
    internal
    view
    override
    returns (packedFloat amountOfY);
Parameters
NameTypeDescription
_amountOfXpackedFloatamount of token X to be sold
Returns
NameTypeDescription
amountOfYpackedFloatamount 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(packedFloat _amountOfY)
    internal
    view
    override
    returns (packedFloat amountOfX);
Parameters
NameTypeDescription
_amountOfYpackedFloatamount of token Y to be sold
Returns
NameTypeDescription
amountOfXpackedFloatamount of token X to be received

_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

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
function checkInactiveLiquidity(packedFloat _active, packedFloat _inactive) internal pure;
Parameters
NameTypeDescription
_activepackedFloatactive liquidity units
_inactivepackedFloatinactive liquidity units

retrieveH

function retrieveH() public view returns (packedFloat h);

_emitCurveState

function _emitCurveState() internal override;