{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/dex-v2/pool/BasePoolV2.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol",
        "node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol",
        "node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol",
        "node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol",
        "node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol",
        "node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol",
        "contracts/dex/utils/GasThrottle.sol",
        "contracts/shared/ProtocolConstants.sol",
        "contracts/interfaces/dex-v2/pool/IBasePoolV2.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract BasePoolV2 is\r\n    IBasePoolV2,\r\n    ProtocolConstants,\r\n    GasThrottle,\r\n    ERC721,\r\n    ReentrancyGuard\r\n{\r\n    /* ========== LIBRARIES ========== */\r\n\r\n    // Used for safe token transfers\r\n    using SafeERC20 for IERC20;\r\n\r\n    // Used by Uniswap-like TWAP mechanism\r\n    using UQ112x112 for uint224;\r\n\r\n    /* ========== STATE VARIABLES ========== */\r\n\r\n    // Address of native asset USDV.\r\n    IERC20 public immutable override nativeAsset;\r\n\r\n    // Denotes what tokens are actively supported by the system\r\n    mapping(IERC20 => bool) public override supported;\r\n\r\n    /*\r\n     * @dev A mapping of foreign asset to the pool's pair.\r\n     * Each pair is represents a pool of native and foreign assets and\r\n     * contains data such as the reserves of native and foreign assets and\r\n     * the liquidity units issues against the deposits of these assets.\r\n     **/\r\n    mapping(IERC20 => PairInfo) public pairInfo;\r\n\r\n    /*\r\n     * @dev A mapping representing positions of liquidity providers. Each position\r\n     * is an Non-fungible token that is mapped against amounts of native and foreign assets\r\n     * deposited across different pools of pairs the timestamp at which the position\r\n     * is created and the amount of liquidity of a particular pool assigned to the LP.\r\n     *\r\n     * Each position in the mapping is mapped against {positionId}.\r\n     **/\r\n    mapping(uint256 => Position) public positions;\r\n\r\n    // C4-Audit Fix for Issue # 142\r\n    // A unique id of the position created when liquidity is added to a pool.\r\n    uint256 public positionId;\r\n\r\n    // Address of the router contract (used for restriction)\r\n    address public router;\r\n\r\n    /* ========== CONSTRUCTOR ========== */\r\n\r\n    /*\r\n     * @dev Initializes the contract by setting address of native asset.\r\n     **/\r\n    constructor(IERC20 _nativeAsset) ERC721(\"Vader-V1-POS\", \"VLP\") {\r\n        require(\r\n            _nativeAsset != IERC20(_ZERO_ADDRESS),\r\n            \"BasePoolV2::constructor: Incorrect Arguments\"\r\n        );\r\n        nativeAsset = IERC20(_nativeAsset);\r\n    }\r\n\r\n    /* ========== VIEWS ========== */\r\n\r\n    /*\r\n     * @dev Accepts address of foreign asset {foreignAsset} to determine the pair (pool)\r\n     * and returns reserves amounts of native and foreign assets, and the last timestamp\r\n     * when cumulative prices for these assets were updated.\r\n     **/\r\n    function getReserves(IERC20 foreignAsset)\r\n        public\r\n        view\r\n        returns (\r\n            uint112 reserveNative,\r\n            uint112 reserveForeign,\r\n            uint32 blockTimestampLast\r\n        )\r\n    {\r\n        PairInfo storage pair = pairInfo[foreignAsset];\r\n        (reserveNative, reserveForeign, blockTimestampLast) = (\r\n            pair.reserveNative,\r\n            pair.reserveForeign,\r\n            pair.blockTimestampLast\r\n        );\r\n    }\r\n\r\n    /*\r\n     * @dev Accepts {id} of a liquidity position and returns foreign asset's\r\n     * address for that particular liquidity position.\r\n     **/\r\n    function positionForeignAsset(uint256 id)\r\n        external\r\n        view\r\n        override\r\n        returns (IERC20)\r\n    {\r\n        return positions[id].foreignAsset;\r\n    }\r\n\r\n    function pairSupply(IERC20 foreignAsset)\r\n        external\r\n        view\r\n        override\r\n        returns (uint256)\r\n    {\r\n        return pairInfo[foreignAsset].totalSupply;\r\n    }\r\n\r\n    /* ========== MUTATIVE FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev Allows depositing of liquidity to a pool/pair by accepting native and foreign assets\r\n     * and mints an NFT to the {to} address which records in {positions} mapping, the amounts\r\n     * of the native and foreign assets deposited and the liquidity units minted against.\r\n     *\r\n     * The pool/pair to accept the native and foreign assets against is determined by {foreignAsset}.\r\n     *\r\n     * Updates the total supply of liquidity units by adding currently minted liquidity units\r\n     * to {pair.totalSupply} of pair/pool.\r\n     *\r\n     * Updates the cumulative prices of native and foreign assets in pool/pair after minting the appropriate\r\n     * liquidity units.\r\n     *\r\n     * Requirements:\r\n     * - Amounts of native and foreign must be approved to the pool prior to calling the `mint` function.\r\n     * - The amount of {liquidity} to be minted must be greater than 0.\r\n     * - The param {foreignAsset} must be a supported token.\r\n     * - Can only be called by Router.\r\n     **/\r\n    function mint(\r\n        IERC20 foreignAsset,\r\n        uint256 nativeDeposit,\r\n        uint256 foreignDeposit,\r\n        address from,\r\n        address to\r\n    )\r\n        external\r\n        override\r\n        onlyRouter\r\n        supportedToken(foreignAsset)\r\n        returns (uint256 liquidity)\r\n    {\r\n        return _mint(foreignAsset, nativeDeposit, foreignDeposit, from, to);\r\n    }\r\n\r\n    /*\r\n     * @dev Allows redeeming of liquidity units by burning the NFT with {id} associated with the liquidity\r\n     * position.\r\n     *\r\n     * Computes the amounts of native and foreign assets from pool/pair against which the NFT with Id {id}\r\n     * was minted. The computed assets' amounts depends upon current reserves of assets and\r\n     * the liquidity associated with the position, and is transferred to the {to} address.\r\n     *\r\n     * Burns the redeemed NFT token and decreases {pair.totalSupply} by the {liquidity}\r\n     * associated with that NFT token.\r\n     *\r\n     * Updates the cumulative prices for native and foreign assets in pool/pair after transferring the assets\r\n     * to the {to} address.\r\n     *\r\n     * Requirements:\r\n     * - The NFT token being redeemed must be transferred to the contract prior to calling `_burn`.\r\n     * - The amount of native and foreign assets computed for transfer to {to} address must be greater\r\n     *   than 0.\r\n     **/\r\n    function _burn(uint256 id, address to)\r\n        internal\r\n        nonReentrant\r\n        returns (uint256 amountNative, uint256 amountForeign)\r\n    {\r\n        require(\r\n            ownerOf(id) == address(this),\r\n            \"BasePoolV2::burn: Incorrect Ownership\"\r\n        );\r\n\r\n        IERC20 foreignAsset = positions[id].foreignAsset;\r\n\r\n        (uint112 reserveNative, uint112 reserveForeign, ) = getReserves(\r\n            foreignAsset\r\n        ); // gas savings\r\n\r\n        uint256 liquidity = positions[id].liquidity;\r\n\r\n        PairInfo storage pair = pairInfo[foreignAsset];\r\n        uint256 _totalSupply = pair.totalSupply;\r\n        amountNative = (liquidity * reserveNative) / _totalSupply;\r\n        amountForeign = (liquidity * reserveForeign) / _totalSupply;\r\n\r\n        require(\r\n            amountNative > 0 && amountForeign > 0,\r\n            \"BasePoolV2::burn: Insufficient Liquidity Burned\"\r\n        );\r\n\r\n        pair.totalSupply = _totalSupply - liquidity;\r\n        _burn(id);\r\n\r\n        nativeAsset.safeTransfer(to, amountNative);\r\n        foreignAsset.safeTransfer(to, amountForeign);\r\n\r\n        _update(\r\n            foreignAsset,\r\n            reserveNative - amountNative,\r\n            reserveForeign - amountForeign,\r\n            reserveNative,\r\n            reserveForeign\r\n        );\r\n\r\n        emit Burn(msg.sender, amountNative, amountForeign, to);\r\n    }\r\n\r\n    /*\r\n     * @dev Allows swapping between two foreign assets from two different pools/pairs.\r\n     *\r\n     * It receives amount {foreignAmountIn} in {foreignAssetA} and returns the swapped amount in {foreignAssetB}.\r\n     *\r\n     * The amount {foreignAmountIn} is swapped to the native asset from the pair against {foreignAssetA} and the\r\n     * received native asset is swapped to foreign asset from the pair against {foreignAssetB}.\r\n     *\r\n     * Updates the cumulative prices for native and foreign assets across pools against assets {foreignAssetA} and\r\n     * {foreignAssetB}.\r\n     *\r\n     * Requirements:\r\n     * - The amount {foreignAmountIn} in {foreignAssetA} must be transferred to the contract prior to calling\r\n     *   the function `doubleSwap`.\r\n     * - The intermediary native asset retrieved from first swap must be greater than 0 and the reserve for native asset.\r\n     * - The foreign amount received from second swap must be greater than 0 and the reserve for foreign asset in the pair/pool\r\n     *   against that particular foreign asset.\r\n     * - The params {foreignAssetA} and {foreignAssetB} must be the supported tokens.\r\n     * - Can only be called by Router.\r\n     **/\r\n    function doubleSwap(\r\n        IERC20 foreignAssetA,\r\n        IERC20 foreignAssetB,\r\n        uint256 foreignAmountIn,\r\n        address to\r\n    )\r\n        external\r\n        override\r\n        onlyRouter\r\n        supportedToken(foreignAssetA)\r\n        supportedToken(foreignAssetB)\r\n        nonReentrant\r\n        validateGas\r\n        returns (uint256 foreignAmountOut)\r\n    {\r\n        (uint112 nativeReserve, uint112 foreignReserve, ) = getReserves(\r\n            foreignAssetA\r\n        ); // gas savings\r\n\r\n        require(\r\n            foreignReserve + foreignAmountIn <=\r\n                foreignAssetA.balanceOf(address(this)),\r\n            \"BasePoolV2::doubleSwap: Insufficient Tokens Provided\"\r\n        );\r\n\r\n        uint256 nativeAmountOut = VaderMath.calculateSwap(\r\n            foreignAmountIn,\r\n            foreignReserve,\r\n            nativeReserve\r\n        );\r\n\r\n        require(\r\n            nativeAmountOut > 0 && nativeAmountOut <= nativeReserve,\r\n            \"BasePoolV2::doubleSwap: Swap Impossible\"\r\n        );\r\n\r\n        _update(\r\n            foreignAssetA,\r\n            nativeReserve - nativeAmountOut,\r\n            foreignReserve + foreignAmountIn,\r\n            nativeReserve,\r\n            foreignReserve\r\n        );\r\n\r\n        emit Swap(\r\n            foreignAssetA,\r\n            msg.sender,\r\n            0,\r\n            foreignAmountIn,\r\n            nativeAmountOut,\r\n            0,\r\n            address(this)\r\n        );\r\n\r\n        (nativeReserve, foreignReserve, ) = getReserves(foreignAssetB); // gas savings\r\n\r\n        foreignAmountOut = VaderMath.calculateSwap(\r\n            nativeAmountOut,\r\n            nativeReserve,\r\n            foreignReserve\r\n        );\r\n\r\n        require(\r\n            foreignAmountOut > 0 && foreignAmountOut <= foreignReserve,\r\n            \"BasePoolV2::doubleSwap: Swap Impossible\"\r\n        );\r\n\r\n        _update(\r\n            foreignAssetB,\r\n            nativeReserve + nativeAmountOut,\r\n            foreignReserve - foreignAmountOut,\r\n            nativeReserve,\r\n            foreignReserve\r\n        );\r\n\r\n        emit Swap(\r\n            foreignAssetB,\r\n            msg.sender,\r\n            nativeAmountOut,\r\n            0,\r\n            0,\r\n            foreignAmountOut,\r\n            to\r\n        );\r\n\r\n        foreignAssetB.safeTransfer(to, foreignAmountOut);\r\n    }\r\n\r\n    /*\r\n     * @dev Allows swapping between native and foreign assets from within a single pair/pool determined\r\n     * by {foreignAsset}.\r\n     *\r\n     * It receives the source asset and computes the destination asset and transfers it to the {to} address.\r\n     *\r\n     * Updates the cumulative prices for native and foreign assets for the pair involved after performing swap.\r\n     *\r\n     * Returns the amount of destination tokens resulting from the swap.\r\n     *\r\n     * Requirements:\r\n     * - Param {nativeAmountIn} must be zero and {foreignAmountIn} must be non-zero\r\n     *   if the destination asset in swap is native asset.\r\n     * - Param {foreignAmountIn} must be zero and {nativeAmountIn} must be non zero\r\n     *   if the destination asset in swap is foreign asset.\r\n     * - Param {to} cannot be the addresses of native or foreign assets.\r\n     * - The source asset amount in the swap must be transferred to the pool prior to calling `swap`.\r\n     * - The source asset amount in the swap cannot exceed the source asset's reserve.\r\n     * - The destination asset's amount in the swap must be greater than 0 and not exceed destination\r\n     *   asset's reserve.\r\n     * - The param {foreignAsset} must be a supported token.\r\n     * - Can only be called by Router.\r\n     **/\r\n    function swap(\r\n        IERC20 foreignAsset,\r\n        uint256 nativeAmountIn,\r\n        uint256 foreignAmountIn,\r\n        address to\r\n    )\r\n        external\r\n        override\r\n        onlyRouter\r\n        supportedToken(foreignAsset)\r\n        nonReentrant\r\n        validateGas\r\n        returns (uint256)\r\n    {\r\n        require(\r\n            (nativeAmountIn > 0 && foreignAmountIn == 0) ||\r\n                (nativeAmountIn == 0 && foreignAmountIn > 0),\r\n            \"BasePoolV2::swap: Only One-Sided Swaps Supported\"\r\n        );\r\n        (uint112 nativeReserve, uint112 foreignReserve, ) = getReserves(\r\n            foreignAsset\r\n        ); // gas savings\r\n\r\n        uint256 nativeAmountOut;\r\n        uint256 foreignAmountOut;\r\n        {\r\n            // scope for _token{0,1}, avoids stack too deep errors\r\n            IERC20 _nativeAsset = nativeAsset;\r\n            require(\r\n                to != address(_nativeAsset) && to != address(foreignAsset),\r\n                \"BasePoolV2::swap: Invalid Receiver\"\r\n            );\r\n\r\n            if (foreignAmountIn > 0) {\r\n                nativeAmountOut = VaderMath.calculateSwap(\r\n                    foreignAmountIn,\r\n                    foreignReserve,\r\n                    nativeReserve\r\n                );\r\n                require(\r\n                    nativeAmountOut > 0 && nativeAmountOut <= nativeReserve,\r\n                    \"BasePoolV2::swap: Swap Impossible\"\r\n                );\r\n                _nativeAsset.safeTransfer(to, nativeAmountOut); // optimistically transfer tokens\r\n            } else {\r\n                foreignAmountOut = VaderMath.calculateSwap(\r\n                    nativeAmountIn,\r\n                    nativeReserve,\r\n                    foreignReserve\r\n                );\r\n                require(\r\n                    foreignAmountOut > 0 && foreignAmountOut <= foreignReserve,\r\n                    \"BasePoolV2::swap: Swap Impossible\"\r\n                );\r\n                foreignAsset.safeTransfer(to, foreignAmountOut); // optimistically transfer tokens\r\n            }\r\n        }\r\n\r\n        _update(\r\n            foreignAsset,\r\n            nativeReserve - nativeAmountOut + nativeAmountIn,\r\n            foreignReserve - foreignAmountOut + foreignAmountIn,\r\n            nativeReserve,\r\n            foreignReserve\r\n        );\r\n\r\n        emit Swap(\r\n            foreignAsset,\r\n            msg.sender,\r\n            nativeAmountIn,\r\n            foreignAmountIn,\r\n            nativeAmountOut,\r\n            foreignAmountOut,\r\n            to\r\n        );\r\n\r\n        return nativeAmountOut > 0 ? nativeAmountOut : foreignAmountOut;\r\n    }\r\n\r\n    /*\r\n     * @dev Allows withdrawing of unaccounted/unrealised foreign asset from the contract.\r\n     *\r\n     * Determines the realised amount of foreign asset from the pair against {foreignAsset}.\r\n     **/\r\n    function rescue(IERC20 foreignAsset) external {\r\n        uint256 foreignBalance = foreignAsset.balanceOf(address(this));\r\n        uint256 reserveForeign = pairInfo[foreignAsset].reserveForeign;\r\n\r\n        uint256 unaccounted = foreignBalance - reserveForeign;\r\n\r\n        foreignAsset.safeTransfer(msg.sender, unaccounted);\r\n    }\r\n\r\n    /* ========== RESTRICTED FUNCTIONS ========== */\r\n\r\n    /* ========== INTERNAL FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev See `mint`.\r\n     **/\r\n    function _mint(\r\n        IERC20 foreignAsset,\r\n        uint256 nativeDeposit,\r\n        uint256 foreignDeposit,\r\n        address from,\r\n        address to\r\n    ) internal nonReentrant returns (uint256 liquidity) {\r\n        (uint112 reserveNative, uint112 reserveForeign, ) = getReserves(\r\n            foreignAsset\r\n        ); // gas savings\r\n\r\n        nativeAsset.safeTransferFrom(from, address(this), nativeDeposit);\r\n        foreignAsset.safeTransferFrom(from, address(this), foreignDeposit);\r\n\r\n        PairInfo storage pair = pairInfo[foreignAsset];\r\n        uint256 totalLiquidityUnits = pair.totalSupply;\r\n        if (totalLiquidityUnits == 0) liquidity = nativeDeposit;\r\n        else\r\n            liquidity = VaderMath.calculateLiquidityUnits(\r\n                nativeDeposit,\r\n                reserveNative,\r\n                foreignDeposit,\r\n                reserveForeign,\r\n                totalLiquidityUnits\r\n            );\r\n\r\n        require(\r\n            liquidity > 0,\r\n            \"BasePoolV2::mint: Insufficient Liquidity Provided\"\r\n        );\r\n\r\n        uint256 id = positionId++;\r\n\r\n        pair.totalSupply = totalLiquidityUnits + liquidity;\r\n        _mint(to, id);\r\n\r\n        positions[id] = Position(\r\n            foreignAsset,\r\n            block.timestamp,\r\n            liquidity,\r\n            nativeDeposit,\r\n            foreignDeposit\r\n        );\r\n\r\n        _update(\r\n            foreignAsset,\r\n            reserveNative + nativeDeposit,\r\n            reserveForeign + foreignDeposit,\r\n            reserveNative,\r\n            reserveForeign\r\n        );\r\n\r\n        emit Mint(from, to, nativeDeposit, foreignDeposit);\r\n        emit PositionOpened(from, to, id, liquidity);\r\n    }\r\n\r\n    /*\r\n     * @dev Internally called to update the cumulative prices for native and foreign assets for\r\n     * the pair against {foreignAsset}. The updated prices depend upon the last reserves and\r\n     * updates the reserves for both of the assets corresponding to their\r\n     * current balances along with the timestamp.\r\n     *\r\n     * Requirements:\r\n     * - Params {balanceNative} and {balanceForeign} must not overflow type `uint112`.\r\n     *\r\n     **/\r\n    function _update(\r\n        IERC20 foreignAsset,\r\n        uint256 balanceNative,\r\n        uint256 balanceForeign,\r\n        uint112 reserveNative,\r\n        uint112 reserveForeign\r\n    ) internal {\r\n        require(\r\n            balanceNative <= type(uint112).max &&\r\n                balanceForeign <= type(uint112).max,\r\n            \"BasePoolV2::_update: Balance Overflow\"\r\n        );\r\n        uint32 blockTimestamp = uint32(block.timestamp % 2**32);\r\n        PairInfo storage pair = pairInfo[foreignAsset];\r\n        unchecked {\r\n            uint32 timeElapsed = blockTimestamp - pair.blockTimestampLast; // overflow is desired\r\n            if (timeElapsed > 0 && reserveNative != 0 && reserveForeign != 0) {\r\n                // * never overflows, and + overflow is desired\r\n                pair.priceCumulative.nativeLast +=\r\n                    uint256(\r\n                        UQ112x112.encode(reserveForeign).uqdiv(reserveNative)\r\n                    ) *\r\n                    timeElapsed;\r\n                pair.priceCumulative.foreignLast +=\r\n                    uint256(\r\n                        UQ112x112.encode(reserveNative).uqdiv(reserveForeign)\r\n                    ) *\r\n                    timeElapsed;\r\n            }\r\n        }\r\n        pair.reserveNative = uint112(balanceNative);\r\n        pair.reserveForeign = uint112(balanceForeign);\r\n        pair.blockTimestampLast = blockTimestamp;\r\n        emit Sync(foreignAsset, balanceNative, balanceForeign);\r\n    }\r\n\r\n    /* ========== PRIVATE FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev Private function that returns if the param {token} is a supported token\r\n     * or not.\r\n     **/\r\n    function _supportedToken(IERC20 token) private view {\r\n        require(\r\n            supported[token],\r\n            \"BasePoolV2::_supportedToken: Unsupported Token\"\r\n        );\r\n    }\r\n\r\n    /*\r\n     * @dev Private function that returns if {msg.sender} is a Router or not.\r\n     **/\r\n    function _onlyRouter() private view {\r\n        require(\r\n            msg.sender == router,\r\n            \"BasePoolV2::_onlyRouter: Only Router is allowed to call\"\r\n        );\r\n    }\r\n\r\n    /* ========== MODIFIERS ========== */\r\n\r\n    /*\r\n     * @dev Modifier that only allows continuation of execution\r\n     * if {msg.sender} is Router.\r\n     **/\r\n    modifier onlyRouter() {\r\n        _onlyRouter();\r\n        _;\r\n    }\r\n\r\n    /*\r\n     * @dev Modifier that only allows continuation of exectuion if the param\r\n     * {token} is a supported token.\r\n     **/\r\n    modifier supportedToken(IERC20 token) {\r\n        _supportedToken(token);\r\n        _;\r\n    }\r\n}"
}