{
    "Function": "slitherConstructorVariables",
    "File": "contracts/dex/pool/BasePool.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol",
        "node_modules/@openzeppelin/contracts/access/Ownable.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/pool/IBasePool.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract BasePool is IBasePool, GasThrottle, ERC721, Ownable, ReentrancyGuard {\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 (Vader or USDV).\r\n    IERC20 public immutable nativeAsset;\r\n\r\n    // Address of foreign asset with which the native asset is paired in the pool.\r\n    IERC20 public immutable foreignAsset;\r\n\r\n    // Cumulative price of native asset.\r\n    uint256 public priceNativeCumulativeLast;\r\n\r\n    // Cumulative price of foreign asset.\r\n    uint256 public priceForeignCumulativeLast;\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, the timestamp at which the position is created and the amount of\r\n     * liquidity 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    // A unique id the of the position created when liquidity is added to the pool.\r\n    uint256 public positionId;\r\n\r\n    // Total amount of liquidity units minted.\r\n    uint256 public totalSupply;\r\n\r\n    // Name of the contract.\r\n    string private _name;\r\n\r\n    // Total amount of the native asset realised by the contract.\r\n    uint112 private _reserveNative; // uses single storage slot, accessible via getReserves\r\n\r\n    // Total amount of the foreign asset realised by the contract.\r\n    uint112 private _reserveForeign; // uses single storage slot, accessible via getReserves\r\n\r\n    // Last timestamp at which the cumulative prices for native and foreign assets were updated.\r\n    uint32 private _blockTimestampLast; // uses single storage slot, accessible via getReserves\r\n\r\n    /* ========== CONSTRUCTOR ========== */\r\n\r\n    /*\r\n     * @dev Initialized the contract state setting the addresses for native and foreign assets.\r\n     *\r\n     * Also computes the name of the contract and stores it in the contract's state.\r\n     **/\r\n    constructor(IERC20Extended _nativeAsset, IERC20Extended _foreignAsset)\r\n        ERC721(\"Vader LP\", \"VLP\")\r\n    {\r\n        nativeAsset = IERC20(_nativeAsset);\r\n        foreignAsset = IERC20(_foreignAsset);\r\n\r\n        string memory calculatedName = string(\r\n            abi.encodePacked(\"Vader USDV /\", _foreignAsset.symbol(), \" LP\")\r\n        );\r\n        _name = calculatedName;\r\n    }\r\n\r\n    /* ========== VIEWS ========== */\r\n\r\n    /*\r\n     * @dev Returns the realised amount of native and foreign assets, and the last timestamp\r\n     * at which the cumulative prices for native and foreign assets were updated.\r\n     **/\r\n    function getReserves()\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        reserveNative = _reserveNative;\r\n        reserveForeign = _reserveForeign;\r\n        blockTimestampLast = _blockTimestampLast;\r\n    }\r\n\r\n    // Returns the name of the contract.\r\n    function name() public view override returns (string memory) {\r\n        return _name;\r\n    }\r\n\r\n    /* ========== MUTATIVE FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev Allows depositing of liquidity to the pool by accepting native and foreign assets\r\n     * and mints an NFT to the {to} address which records the amounts of the native and foreign\r\n     * assets deposited and the liquidity units minted against it in {positions} mapping.\r\n     *\r\n     * Updates the total supply of liquidity units by adding currently minted liquidity units\r\n     * to {totalSupply}.\r\n     *\r\n     * Updates the cumulative prices of native and foreign assets after minting the appropriate\r\n     * liquidity units.\r\n     *\r\n     * Requirements:\r\n     * - Amounts of native and foreign must be sent to the pool prior to calling `mint` such that\r\n     *   balance of pool for both assets must be greater than their corresponding reserves.\r\n     * - The amount of {liquidity} to be minted must be greater than 0.\r\n     **/\r\n    function mint(address to)\r\n        external\r\n        override\r\n        nonReentrant\r\n        returns (uint256 liquidity)\r\n    {\r\n        (uint112 reserveNative, uint112 reserveForeign, ) = getReserves(); // gas savings\r\n        uint256 balanceNative = nativeAsset.balanceOf(address(this));\r\n        uint256 balanceForeign = foreignAsset.balanceOf(address(this));\r\n        uint256 nativeDeposit = balanceNative - reserveNative;\r\n        uint256 foreignDeposit = balanceForeign - reserveForeign;\r\n\r\n        uint256 totalLiquidityUnits = totalSupply;\r\n        if (totalLiquidityUnits == 0)\r\n            liquidity = nativeDeposit; // TODO: Contact ThorChain on proper approach\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            \"BasePool::mint: Insufficient Liquidity Provided\"\r\n        );\r\n\r\n        uint256 id = positionId++;\r\n\r\n        totalSupply += liquidity;\r\n        _mint(to, id);\r\n\r\n        positions[id] = Position(\r\n            block.timestamp,\r\n            liquidity,\r\n            nativeDeposit,\r\n            foreignDeposit\r\n        );\r\n\r\n        _update(balanceNative, balanceForeign, reserveNative, reserveForeign);\r\n\r\n        emit Mint(msg.sender, to, nativeDeposit, foreignDeposit);\r\n        emit PositionOpened(msg.sender, id, liquidity);\r\n    }\r\n\r\n    /*\r\n     * @dev Allows redeeming of liquidity units by burning the NFT associated with the liquidity\r\n     * position.\r\n     *\r\n     * Computes the amounts of native and foreign assets depending upon current reserves of assets and\r\n     * the liquidity associated with the position, and transfers them to the {to} address.\r\n     *\r\n     * Burns the redeemed NFT token and decreases {totalSupply} by the {liquidity}\r\n     * associated with that NFT token.\r\n     *\r\n     * Updates the cumulative prices for native and foreign assets 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 pool 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            \"BasePool::burn: Incorrect Ownership\"\r\n        );\r\n\r\n        (uint112 reserveNative, uint112 reserveForeign, ) = getReserves(); // gas savings\r\n        IERC20 _nativeAsset = nativeAsset; // gas savings\r\n        IERC20 _foreignAsset = foreignAsset; // gas savings\r\n        uint256 nativeBalance = IERC20(_nativeAsset).balanceOf(address(this));\r\n        uint256 foreignBalance = IERC20(_foreignAsset).balanceOf(address(this));\r\n\r\n        uint256 liquidity = positions[id].liquidity;\r\n\r\n        uint256 _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee\r\n        amountNative = (liquidity * nativeBalance) / _totalSupply; // using balances ensures pro-rata distribution\r\n        amountForeign = (liquidity * foreignBalance) / _totalSupply; // using balances ensures pro-rata distribution\r\n\r\n        require(\r\n            amountNative > 0 && amountForeign > 0,\r\n            \"BasePool::burn: Insufficient Liquidity Burned\"\r\n        );\r\n\r\n        totalSupply -= liquidity;\r\n        _burn(id);\r\n\r\n        _nativeAsset.safeTransfer(to, amountNative);\r\n        _foreignAsset.safeTransfer(to, amountForeign);\r\n\r\n        nativeBalance = _nativeAsset.balanceOf(address(this));\r\n        foreignBalance = _foreignAsset.balanceOf(address(this));\r\n\r\n        _update(nativeBalance, foreignBalance, reserveNative, reserveForeign);\r\n\r\n        emit Burn(msg.sender, amountNative, amountForeign, to);\r\n    }\r\n\r\n    /*\r\n     * @dev  Allows swapping between native and foreign assets. It receives the source asset\r\n     * and computes the destination asset and transfers it to the {to} address.\r\n     *\r\n     * Internally calls {swap} function.\r\n     **/\r\n    function swap(\r\n        uint256 nativeAmountIn,\r\n        uint256 foreignAmountIn,\r\n        address to,\r\n        bytes calldata\r\n    ) external override returns (uint256) {\r\n        return swap(nativeAmountIn, foreignAmountIn, to);\r\n    }\r\n\r\n    /*\r\n     * @dev Allows swapping between native and foreign assets. It receives the source asset\r\n     * 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 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     **/\r\n    function swap(\r\n        uint256 nativeAmountIn,\r\n        uint256 foreignAmountIn,\r\n        address to\r\n    ) public override nonReentrant validateGas returns (uint256) {\r\n        require(\r\n            (nativeAmountIn > 0 && foreignAmountIn == 0) ||\r\n                (nativeAmountIn == 0 && foreignAmountIn > 0),\r\n            \"BasePool::swap: Only One-Sided Swaps Supported\"\r\n        );\r\n        (uint112 nativeReserve, uint112 foreignReserve, ) = getReserves(); // gas savings\r\n\r\n        uint256 nativeBalance;\r\n        uint256 foreignBalance;\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            IERC20 _foreignAsset = foreignAsset;\r\n            nativeBalance = _nativeAsset.balanceOf(address(this));\r\n            foreignBalance = _foreignAsset.balanceOf(address(this));\r\n\r\n            require(\r\n                to != address(_nativeAsset) && to != address(_foreignAsset),\r\n                \"BasePool::swap: Invalid Receiver\"\r\n            );\r\n\r\n            if (foreignAmountIn > 0) {\r\n                require(\r\n                    foreignAmountIn <= foreignBalance - foreignReserve,\r\n                    \"BasePool::swap: Insufficient Tokens Provided\"\r\n                );\r\n                require(\r\n                    foreignAmountIn <= foreignReserve,\r\n                    \"BasePool::swap: Unfavourable Trade\"\r\n                );\r\n\r\n                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                    \"BasePool::swap: Swap Impossible\"\r\n                );\r\n\r\n                _nativeAsset.safeTransfer(to, nativeAmountOut); // optimistically transfer tokens\r\n            } else {\r\n                require(\r\n                    nativeAmountIn <= nativeBalance - nativeReserve,\r\n                    \"BasePool::swap: Insufficient Tokens Provided\"\r\n                );\r\n                require(\r\n                    nativeAmountIn <= nativeReserve,\r\n                    \"BasePool::swap: Unfavourable Trade\"\r\n                );\r\n\r\n                foreignAmountOut = VaderMath.calculateSwap(\r\n                    nativeAmountIn,\r\n                    nativeReserve,\r\n                    foreignReserve\r\n                );\r\n\r\n                require(\r\n                    foreignAmountOut > 0 && foreignAmountOut <= foreignReserve,\r\n                    \"BasePool::swap: Swap Impossible\"\r\n                );\r\n\r\n                _foreignAsset.safeTransfer(to, foreignAmountOut); // optimistically transfer tokens\r\n            }\r\n\r\n            nativeBalance = _nativeAsset.balanceOf(address(this));\r\n            foreignBalance = _foreignAsset.balanceOf(address(this));\r\n        }\r\n\r\n        _update(nativeBalance, foreignBalance, nativeReserve, foreignReserve);\r\n\r\n        emit Swap(\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    /* ========== RESTRICTED FUNCTIONS ========== */\r\n\r\n    /* ========== INTERNAL FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev Internally called to update the cumulative prices for native and foreign assets depending\r\n     * upon the last reserves and updates the reserves for both of the assets corresponding to their\r\n     * current balances along with the {_blockTimestampLast}.\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        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            \"BasePool::_update: Balance Overflow\"\r\n        );\r\n        uint32 blockTimestamp = uint32(block.timestamp % 2**32);\r\n        unchecked {\r\n            uint32 timeElapsed = blockTimestamp - _blockTimestampLast; // overflow is desired\r\n            if (timeElapsed > 0 && reserveNative != 0 && reserveForeign != 0) {\r\n                // * never overflows, and + overflow is desired\r\n                priceNativeCumulativeLast +=\r\n                    uint256(\r\n                        UQ112x112.encode(reserveForeign).uqdiv(reserveNative)\r\n                    ) *\r\n                    timeElapsed;\r\n                priceForeignCumulativeLast +=\r\n                    uint256(\r\n                        UQ112x112.encode(reserveNative).uqdiv(reserveForeign)\r\n                    ) *\r\n                    timeElapsed;\r\n            }\r\n        }\r\n        _reserveNative = uint112(balanceNative);\r\n        _reserveForeign = uint112(balanceForeign);\r\n        _blockTimestampLast = blockTimestamp;\r\n        emit Sync(balanceNative, balanceForeign);\r\n    }\r\n\r\n    /* ========== PRIVATE FUNCTIONS ========== */\r\n\r\n    /* ========== MODIFIERS ========== */\r\n}"
}