{
    "Function": "slitherConstructorConstantVariables",
    "File": "contracts/dex/router/VaderRouter.sol",
    "Parent Contracts": [
        "node_modules/@openzeppelin/contracts/access/Ownable.sol",
        "node_modules/@openzeppelin/contracts/utils/Context.sol",
        "contracts/shared/ProtocolConstants.sol",
        "contracts/interfaces/dex/router/IVaderRouter.sol"
    ],
    "High-Level Calls": [],
    "Internal Calls": [],
    "Library Calls": [],
    "Low-Level Calls": [],
    "Code": "contract VaderRouter is IVaderRouter, ProtocolConstants, Ownable {\r\n    /* ========== LIBRARIES ========== */\r\n\r\n    // Used for safe token transfers\r\n    using SafeERC20 for IERC20;\r\n\r\n    /* ========== STATE VARIABLES ========== */\r\n\r\n    // The address of Vader pool factory contract.\r\n    IVaderPoolFactory public immutable factory;\r\n\r\n    // The address of Reserve contract.\r\n    IVaderReserve public reserve;\r\n\r\n    /* ========== CONSTRUCTOR ========== */\r\n\r\n    /*\r\n     * @dev Initializes contract's state by setting the vader pool factory address.\r\n     *\r\n     * Requirements:\r\n     * - Vader pool factory address must not be zero.\r\n     **/\r\n    constructor(IVaderPoolFactory _factory) {\r\n        require(\r\n            _factory != IVaderPoolFactory(_ZERO_ADDRESS),\r\n            \"VaderRouter::constructor: Incorrect Arguments\"\r\n        );\r\n\r\n        factory = _factory;\r\n    }\r\n\r\n    /* ========== VIEWS ========== */\r\n\r\n    /* ========== MUTATIVE FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev Allows adding of liquidity to the Vader pools.\r\n     *\r\n     * Internally calls {addLiquidity} function.\r\n     *\r\n     * Returns the amounts of assetA and assetB used in liquidity and\r\n     * the amount of liquidity units minted.\r\n     **/\r\n    // NOTE: For Uniswap V2 compliancy, necessary due to stack too deep\r\n    function addLiquidity(\r\n        IERC20 tokenA,\r\n        IERC20 tokenB,\r\n        uint256 amountADesired,\r\n        uint256 amountBDesired,\r\n        uint256, // amountAMin = unused\r\n        uint256, // amountBMin = unused\r\n        address to,\r\n        uint256 deadline\r\n    )\r\n        external\r\n        override\r\n        returns (\r\n            uint256 amountA,\r\n            uint256 amountB,\r\n            uint256 liquidity\r\n        )\r\n    {\r\n        return\r\n            addLiquidity(\r\n                tokenA,\r\n                tokenB,\r\n                amountADesired,\r\n                amountBDesired,\r\n                to,\r\n                deadline\r\n            );\r\n    }\r\n\r\n    /*\r\n     * @dev Allows adding of liquidity to the Vader pools.\r\n     *\r\n     * Internally calls {_addLiquidity} function.\r\n     *\r\n     * Transfers the amounts of tokenA and tokenB from {msg.sender} to the pool.\r\n     *\r\n     * Calls the {mint} function on the pool to deposit liquidity on the behalf of\r\n     * {to} address.\r\n     *\r\n     * Returns the amounts of assetA and assetB used in liquidity and\r\n     * the amount of liquidity units minted.\r\n     *\r\n     * Requirements:\r\n     * - The current timestamp has not exceeded the param {deadline}.\r\n     **/\r\n    function addLiquidity(\r\n        IERC20 tokenA,\r\n        IERC20 tokenB,\r\n        uint256 amountADesired,\r\n        uint256 amountBDesired,\r\n        address to,\r\n        uint256 deadline\r\n    )\r\n        public\r\n        override\r\n        ensure(deadline)\r\n        returns (\r\n            uint256 amountA,\r\n            uint256 amountB,\r\n            uint256 liquidity\r\n        )\r\n    {\r\n        IVaderPool pool;\r\n        (pool, amountA, amountB) = _addLiquidity(\r\n            address(tokenA),\r\n            address(tokenB),\r\n            amountADesired,\r\n            amountBDesired\r\n        );\r\n        tokenA.safeTransferFrom(msg.sender, address(pool), amountA);\r\n        tokenB.safeTransferFrom(msg.sender, address(pool), amountB);\r\n        liquidity = pool.mint(to);\r\n    }\r\n\r\n    /*\r\n     * @dev Allows removing of liquidity by {msg.sender} and transfers the\r\n     * underlying assets to {to} address.\r\n     *\r\n     * Transfers the NFT with Id {id} representing user's position, to the pool address,\r\n     * so the pool is able to burn it in the `burn` function call.\r\n     *\r\n     * Calls the `burn` function on the pool contract.\r\n     *\r\n     * Calls the `reimburseImpermanentLoss` on reserve contract to cover impermanent loss\r\n     * for the liquidity being removed.\r\n     *\r\n     * Requirements:\r\n     * - The underlying assets amounts of {amountA} and {amountB} must\r\n     *   be greater than or equal to {amountAMin} and {amountBMin}, respectively.\r\n     * - The current timestamp has not exceeded the param {deadline}.\r\n     **/\r\n    function removeLiquidity(\r\n        address tokenA,\r\n        address tokenB,\r\n        uint256 id,\r\n        uint256 amountAMin,\r\n        uint256 amountBMin,\r\n        address to,\r\n        uint256 deadline\r\n    )\r\n        public\r\n        override\r\n        ensure(deadline)\r\n        returns (uint256 amountA, uint256 amountB)\r\n    {\r\n        IVaderPool pool = factory.getPool(tokenA, tokenB);\r\n\r\n        pool.transferFrom(msg.sender, address(pool), id);\r\n\r\n        (\r\n            uint256 amountNative,\r\n            uint256 amountForeign,\r\n            uint256 coveredLoss\r\n        ) = pool.burn(id, to);\r\n\r\n        (amountA, amountB) = tokenA == factory.nativeAsset()\r\n            ? (amountNative, amountForeign)\r\n            : (amountForeign, amountNative);\r\n\r\n        require(\r\n            amountA >= amountAMin,\r\n            \"UniswapV2Router: INSUFFICIENT_A_AMOUNT\"\r\n        );\r\n        require(\r\n            amountB >= amountBMin,\r\n            \"UniswapV2Router: INSUFFICIENT_B_AMOUNT\"\r\n        );\r\n\r\n        reserve.reimburseImpermanentLoss(msg.sender, coveredLoss);\r\n    }\r\n\r\n    /*\r\n     * @dev Allows swapping of exact source token amount to destination\r\n     * token amount.\r\n     *\r\n     * Internally calls {_swap} function.\r\n     *\r\n     * Requirements:\r\n     * - The destination amount {amountOut} must greater than or equal to param {amountOutMin}.\r\n     * - The current timestamp has not exceeded the param {deadline}.\r\n     **/\r\n    function swapExactTokensForTokens(\r\n        uint256 amountIn,\r\n        uint256 amountOutMin,\r\n        address[] calldata path,\r\n        address to,\r\n        uint256 deadline\r\n    ) external virtual override ensure(deadline) returns (uint256 amountOut) {\r\n        amountOut = _swap(amountIn, path, to);\r\n\r\n        require(\r\n            amountOut >= amountOutMin,\r\n            \"VaderRouter::swapExactTokensForTokens: Insufficient Trade Output\"\r\n        );\r\n    }\r\n\r\n    /*\r\n     * @dev Allows swapping of source token amount to exact destination token\r\n     * amount.\r\n     *\r\n     * Internally calls {calculateInGivenOut} and {_swap} functions.\r\n     *\r\n     * Requirements:\r\n     * - Param {amountInMax} must be greater than or equal to the source amount computed {amountIn}.\r\n     * - The current timestamp has not exceeded the param {deadline}.\r\n     **/\r\n    function swapTokensForExactTokens(\r\n        uint256 amountOut,\r\n        uint256 amountInMax,\r\n        address[] calldata path,\r\n        address to,\r\n        uint256 deadline\r\n    ) external virtual ensure(deadline) returns (uint256 amountIn) {\r\n        amountIn = calculateInGivenOut(amountOut, path);\r\n\r\n        require(\r\n            amountInMax >= amountIn,\r\n            \"VaderRouter::swapTokensForExactTokens: Large Trade Input\"\r\n        );\r\n\r\n        _swap(amountIn, path, to);\r\n    }\r\n\r\n    /* ========== RESTRICTED FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev Sets the reserve address and renounces contract's ownership.\r\n     *\r\n     * Requirements:\r\n     * - Only existing owner can call this function.\r\n     * - Param {_reserve} cannot be a zero address.\r\n     **/\r\n    function initialize(IVaderReserve _reserve) external onlyOwner {\r\n        require(\r\n            _reserve != IVaderReserve(_ZERO_ADDRESS),\r\n            \"VaderRouter::initialize: Incorrect Reserve Specified\"\r\n        );\r\n\r\n        reserve = _reserve;\r\n\r\n        renounceOwnership();\r\n    }\r\n\r\n    /* ========== INTERNAL FUNCTIONS ========== */\r\n\r\n    /* ========== PRIVATE FUNCTIONS ========== */\r\n\r\n    /*\r\n     * @dev Allows swapping of assets from within a single Vader pool or\r\n     * across two different Vader pools.\r\n     *\r\n     * In case of a single Vader pool, the native asset can be swapped for foreign\r\n     * asset and vice versa.\r\n     *\r\n     * In case of two Vader pools, the foreign asset is swapped for native asset from\r\n     * the first Vader pool and the native asset retrieved from the first Vader pool is swapped\r\n     * for foreign asset from the second Vader pool.\r\n     *\r\n     * Requirements:\r\n     * - Param {path} length can be either 2 or 3.\r\n     * - If the {path} length is 3 the index 0 and 1 must contain foreign assets' addresses\r\n     *   and index 1 must contain native asset's address.\r\n     * - If the {path} length is 2 then either of indexes must contain foreign asset's address\r\n     *   and the other one must contain native asset's address.\r\n     **/\r\n    // TODO: Refactor with central pool, perhaps diminishes security? would need directSwap & bridgeSwap\r\n    function _swap(\r\n        uint256 amountIn,\r\n        address[] calldata path,\r\n        address to\r\n    ) private returns (uint256 amountOut) {\r\n        if (path.length == 3) {\r\n            require(\r\n                path[0] != path[1] &&\r\n                    path[1] == factory.nativeAsset() &&\r\n                    path[2] != path[1],\r\n                \"VaderRouter::_swap: Incorrect Path\"\r\n            );\r\n\r\n            IVaderPool pool0 = factory.getPool(path[0], path[1]);\r\n            IVaderPool pool1 = factory.getPool(path[1], path[2]);\r\n\r\n            IERC20(path[0]).safeTransferFrom(\r\n                msg.sender,\r\n                address(pool0),\r\n                amountIn\r\n            );\r\n\r\n            return pool1.swap(0, pool0.swap(amountIn, 0, address(pool1)), to);\r\n        } else {\r\n            require(\r\n                path.length == 2,\r\n                \"VaderRouter::_swap: Incorrect Path Length\"\r\n            );\r\n            address nativeAsset = factory.nativeAsset();\r\n            require(path[0] != path[1], \"VaderRouter::_swap: Incorrect Path\");\r\n\r\n            IVaderPool pool = factory.getPool(path[0], path[1]);\r\n            IERC20(path[0]).safeTransferFrom(\r\n                msg.sender,\r\n                address(pool),\r\n                amountIn\r\n            );\r\n            if (path[0] == nativeAsset) {\r\n                return pool.swap(amountIn, 0, to);\r\n            } else {\r\n                require(\r\n                    path[1] == nativeAsset,\r\n                    \"VaderRouter::_swap: Incorrect Path\"\r\n                );\r\n                return pool.swap(0, amountIn, to);\r\n            }\r\n        }\r\n    }\r\n\r\n    /*\r\n     * @dev An internal function that returns Vader pool's address against\r\n     * the provided assets of {tokenA} and {tokenB} if it exists, otherwise\r\n     * a new Vader pool created against the provided assets.\r\n     **/\r\n    // NOTE: DEX allows asymmetric deposits\r\n    function _addLiquidity(\r\n        address tokenA,\r\n        address tokenB,\r\n        uint256 amountADesired,\r\n        uint256 amountBDesired\r\n    )\r\n        private\r\n        returns (\r\n            IVaderPool pool,\r\n            uint256 amountA,\r\n            uint256 amountB\r\n        )\r\n    {\r\n        // create the pair if it doesn't exist yet\r\n        pool = factory.getPool(tokenA, tokenB);\r\n        if (pool == IVaderPool(_ZERO_ADDRESS)) {\r\n            pool = factory.createPool(tokenA, tokenB);\r\n        }\r\n\r\n        (amountA, amountB) = (amountADesired, amountBDesired);\r\n    }\r\n\r\n    /*\r\n     * @dev Returns the amount of source asset given the amount of destination asset.\r\n     *\r\n     * Calls the {calculateSwapReverse} on VaderMath library to compute the source\r\n     * token amount.\r\n     *\r\n     * Requirements:\r\n     * - Param {path} length can be either 2 or 3.\r\n     * - If the {path} length is 3 the index 0 and 1 must contain foreign assets' addresses\r\n     *   and index 1 must contain native asset's address.\r\n     * - If the {path} length is 2 then either of indexes must contain foreign asset's address\r\n     *   and the other one must contain native asset's address.\r\n     **/\r\n    function calculateInGivenOut(uint256 amountOut, address[] calldata path)\r\n        public\r\n        view\r\n        returns (uint256 amountIn)\r\n    {\r\n        if (path.length == 2) {\r\n            address nativeAsset = factory.nativeAsset();\r\n            IVaderPool pool = factory.getPool(path[0], path[1]);\r\n            (uint256 nativeReserve, uint256 foreignReserve, ) = pool\r\n                .getReserves();\r\n            if (path[0] == nativeAsset) {\r\n                return\r\n                    VaderMath.calculateSwapReverse(\r\n                        amountOut,\r\n                        nativeReserve,\r\n                        foreignReserve\r\n                    );\r\n            } else {\r\n                return\r\n                    VaderMath.calculateSwapReverse(\r\n                        amountOut,\r\n                        foreignReserve,\r\n                        nativeReserve\r\n                    );\r\n            }\r\n        } else {\r\n            IVaderPool pool0 = factory.getPool(path[0], path[1]);\r\n            IVaderPool pool1 = factory.getPool(path[1], path[2]);\r\n            (uint256 nativeReserve0, uint256 foreignReserve0, ) = pool0\r\n                .getReserves();\r\n            (uint256 nativeReserve1, uint256 foreignReserve1, ) = pool1\r\n                .getReserves();\r\n\r\n            return\r\n                VaderMath.calculateSwapReverse(\r\n                    VaderMath.calculateSwapReverse(\r\n                        amountOut,\r\n                        nativeReserve1,\r\n                        foreignReserve1\r\n                    ),\r\n                    foreignReserve0,\r\n                    nativeReserve0\r\n                );\r\n        }\r\n    }\r\n\r\n    /*\r\n     * @dev Returns the amount of destination asset given the amount of source asset.\r\n     *\r\n     * Calls the {calculateSwap} on VaderMath library to compute the destination\r\n     * token amount.\r\n     *\r\n     * Requirements:\r\n     * - Param {path} length can be either 2 or 3.\r\n     * - If the {path} length is 3 the index 0 and 1 must contain foreign assets' addresses\r\n     *   and index 1 must contain native asset's address.\r\n     * - If the {path} length is 2 then either of indexes must contain foreign asset's address\r\n     *   and the other one must contain native asset's address.\r\n     **/\r\n    function calculateOutGivenIn(uint256 amountIn, address[] calldata path)\r\n        external\r\n        view\r\n        returns (uint256 amountOut)\r\n    {\r\n        if (path.length == 2) {\r\n            address nativeAsset = factory.nativeAsset();\r\n            IVaderPool pool = factory.getPool(path[0], path[1]);\r\n            (uint256 nativeReserve, uint256 foreignReserve, ) = pool\r\n                .getReserves();\r\n            if (path[0] == nativeAsset) {\r\n                return\r\n                    VaderMath.calculateSwap(\r\n                        amountIn,\r\n                        nativeReserve,\r\n                        foreignReserve\r\n                    );\r\n            } else {\r\n                return\r\n                    VaderMath.calculateSwap(\r\n                        amountIn,\r\n                        foreignReserve,\r\n                        nativeReserve\r\n                    );\r\n            }\r\n        } else {\r\n            IVaderPool pool0 = factory.getPool(path[0], path[1]);\r\n            IVaderPool pool1 = factory.getPool(path[1], path[2]);\r\n            (uint256 nativeReserve0, uint256 foreignReserve0, ) = pool0\r\n                .getReserves();\r\n            (uint256 nativeReserve1, uint256 foreignReserve1, ) = pool1\r\n                .getReserves();\r\n\r\n            return\r\n                VaderMath.calculateSwap(\r\n                    VaderMath.calculateSwap(\r\n                        amountIn,\r\n                        nativeReserve1,\r\n                        foreignReserve1\r\n                    ),\r\n                    foreignReserve0,\r\n                    nativeReserve0\r\n                );\r\n        }\r\n    }\r\n\r\n    /* ========== MODIFIERS ========== */\r\n\r\n    // Guard ensuring that the current timestamp has not exceeded the param {deadline}.\r\n    modifier ensure(uint256 deadline) {\r\n        require(deadline >= block.timestamp, \"VaderRouter::ensure: Expired\");\r\n        _;\r\n    }\r\n}"
}