creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/core/interfaces/ISCRYERC20.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\ninterface ISCRYERC20 {\n    // event Approval(address indexed owner, address indexed spender, uint value);\n    // event Transfer(address indexed from, address indexed to, uint value);\n\n    function name() external view returns (string memory);\n    function symbol() external view returns (string memory);\n    function decimals() external view returns (uint8);\n    function totalSupply() external view returns (uint);\n    function balanceOf(address owner) external view returns (uint);\n    function allowance(address owner, address spender) external view returns (uint);\n\n    function approve(address spender, uint value) external returns (bool);\n    function transfer(address to, uint value) external returns (bool);\n    function transferFrom(address from, address to, uint value) external returns (bool);\n}\n"
      },
      "contracts/core/interfaces/ISCRYERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\nimport './ISCRYERC20.sol';\n\ninterface ISCRYERC20Permit is ISCRYERC20 {\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n    function PERMIT_TYPEHASH() external pure returns (bytes32);\n    function nonces(address owner) external view returns (uint);\n\n    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;\n}"
      },
      "contracts/core/interfaces/ISCRYFactory.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\ninterface ISCRYFactory {\n    event PairCreated(address indexed token0, address indexed token1, address pair, uint);\n\n    function getPair(address tokenA, address tokenB) external view returns (address pair);\n    function allPairs(uint) external view returns (address pair);\n    function allPairsLength() external view returns (uint);\n    function lpTokens(address) external view returns (bool);\n\n    function createPair(address tokenA, address tokenB) external returns (address pair, address stashTokenA, address stashTokenB);\n    function oldMajor() external view returns (address);\n    function tokenFactory() external view returns (address);\n    function stashETH() external view returns (address);\n}\n"
      },
      "contracts/core/interfaces/ISCRYPair.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\nimport './ISCRYERC20Permit.sol';\n\ninterface ISCRYPair is ISCRYERC20Permit {\n    // event Mint(address indexed sender, uint amount0, uint amount1);\n    // event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);\n    // event Swap(\n    //     address indexed sender,\n    //     uint amount0In,\n    //     uint amount1In,\n    //     uint amount0Out,\n    //     uint amount1Out,\n    //     address indexed to\n    // );\n    // event Sync(uint128 reserve0, uint128 reserve1);\n\n    function MINIMUM_LIQUIDITY() external pure returns (uint);\n    function factory() external view returns (address);\n    function token0() external view returns (address);\n    function token1() external view returns (address);\n    function getReserves() external view returns (uint128 reserve0, uint128 reserve1);\n\n    function mint(address to) external returns (uint liquidity);\n    function burn(address to) external returns (uint amount0, uint amount1);\n    function burnUnbalanced(address to, uint token0Min, uint token1Min) external returns (uint amount0, uint amount1);\n    function burnUnbalancedForExactToken(address to, address exactToken, uint amountExactOut) external returns (uint, uint);\n    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;\n    function sync() external;\n\n    function setIsFlashSwapEnabled(bool _isFlashSwapEnabled) external;\n    function setFeeToAddresses(address _feeTo0, address _feeTo1) external;\n    function setRouter(address _router) external;\n    function getBurnFee() external view returns (uint256);\n}\n"
      },
      "contracts/core/interfaces/ISCRYPairTransferable.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\ninterface ISCRYPairTransferable {\n    function transferFromPool(address to, uint value) external returns (bool);\n    // function balanceOf(address owner) external returns (uint);\n}\n"
      },
      "contracts/core/interfaces/IStashETH.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\nimport './ISCRYPairTransferable.sol';\n\ninterface IStashETH is ISCRYPairTransferable {\n    function deposit() external payable returns (uint256);\n    function depositFor(address to) external payable returns (bool);\n    function withdraw(uint amount) external returns (bool);\n    function withdrawTo(address account, uint amount) external returns (bool);\n}"
      },
      "contracts/core/libraries/SafeMath.sol": {
        "content": "pragma solidity >=0.5.0;\n\n// a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)\n\nlibrary SafeMath {\n    function add(uint x, uint y) internal pure returns (uint z) {\n        require((z = x + y) >= x, 'ds-math-add-overflow');\n    }\n\n    function sub(uint x, uint y) internal pure returns (uint z) {\n        require((z = x - y) <= x, 'ds-math-sub-underflow');\n    }\n\n    function mul(uint x, uint y) internal pure returns (uint z) {\n        require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');\n    }\n}\n"
      },
      "contracts/periphery/interfaces/ISCRYRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.6.2;\n\ninterface ISCRYRouter {\n    function factory() external view returns (address);\n    function WETH() external view returns (address);\n    function liquidityRouter() external returns (address);\n\n    function createPairAndAddLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        address to,\n        uint deadline\n    ) external returns (uint, uint, uint);\n    function createETHPairAndAddLiquidity(\n        address token,\n        uint amountTokenDesired,\n        address to,\n        uint deadline\n    ) external payable returns (uint, uint, uint);\n    function addLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external returns (uint amountA, uint amountB, uint liquidity);\n    function addLiquidityETH(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline\n    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);\n    function addUnbalancedLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external returns (uint amountA, uint amountB, uint liquidity);\n    function addUnbalancedLiquidityETH(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline\n    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);\n    function swapExactTokensForTokens(\n        uint amountIn,\n        uint amountOutMin,\n        address[] calldata path,\n        address to,\n        uint deadline\n    ) external returns (uint[] memory amounts);\n    function swapTokensForExactTokens(\n        uint amountOut,\n        uint amountInMax,\n        address[] calldata path,\n        address to,\n        uint deadline\n    ) external returns (uint[] memory amounts);\n\n    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);\n    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);\n    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);\n    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);\n    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);\n}\n"
      },
      "contracts/periphery/interfaces/ISCRYStashRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\nimport './ISCRYRouter.sol';\n\npragma solidity >=0.6.2;\n\ninterface ISCRYStashRouter is ISCRYRouter{\n    function addLiquidityETHWithPermit(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);\n    function addUnbalancedLiquidityETHWithPermit(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);\n\n    function removeLiquidity(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external returns (uint amountA, uint amountB);\n    function removeLiquidityWithPermit(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external returns (uint amountA, uint amountB);\n    function removeUnbalancedLiquidity(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAExact,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external returns (uint, uint);\n    function removeUnbalancedLiquidityWithPermit(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAExact,\n        uint amountBMin,        \n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external returns (uint, uint);\n\n    function swapExactTokensForTokensWithPermit(\n        uint amountIn,\n        uint amountOutMin,\n        address[] calldata path,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external returns (uint[] memory amounts);\n    function swapTokensForExactTokensWithPermit(\n        uint amountOut,\n        uint amountInMax,\n        address[] calldata path,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external returns (uint[] memory amounts);\n}\n"
      },
      "contracts/periphery/interfaces/IWETH.sol": {
        "content": "pragma solidity >=0.5.0;\n\ninterface IWETH {\n    function deposit() external payable;\n    function transfer(address to, uint value) external returns (bool);\n    function withdraw(uint) external;\n}\n"
      },
      "contracts/periphery/libraries/SCRYLibrary.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0 <0.8.0;\n\nimport '../../core/interfaces/ISCRYPair.sol';\nimport '../../core/interfaces/ISCRYFactory.sol';\n\nimport \"../../core/libraries/SafeMath.sol\";\n\nlibrary SCRYLibrary {\n    using SafeMath for uint;\n\n    uint256 private constant MAX_FEE = 10000;\n\n    // returns sorted token addresses, used to handle return values from pairs sorted in this order\n    function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {\n        require(tokenA != tokenB, 'SCRYLibrary: IDENTICAL_ADDRESSES');\n        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);\n        require(token0 != address(0), 'SCRYLibrary: ZERO_ADDRESS');\n    }\n\n    // calculates the CREATE2 address for a pair without making any external calls\n    function pairFor(address factory, address tokenA, address tokenB) internal view returns (address pair) {\n        // (address token0, address token1) = sortTokens(tokenA, tokenB);\n        // pair = address(uint(keccak256(abi.encodePacked(\n        //         hex'ff',\n        //         factory,\n        //         keccak256(abi.encodePacked(token0, token1)),\n        //         hex'7839beac2ac0020a3a02011b7ba701c900dd2c735ec5f5acfcde63d845ce6517' // hardhat\n        //         // hex'f2b57fa1700ce1fa58cc33bd5169a52d4fee4581fe629136551e37fe91552963' // init code hash\n        //     ))));\n        pair = ISCRYFactory(factory).getPair(tokenA, tokenB);\n    }\n\n    function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB, address pair) {\n        (address token0,) = sortTokens(tokenA, tokenB);\n        pair = pairFor(factory, tokenA, tokenB);\n        (uint reserve0, uint reserve1) = ISCRYPair(pair).getReserves();\n        (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);\n    }\n\n    // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset\n    function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {\n        require(amountA > 0, 'SCRYLibrary: INSUFFICIENT_AMOUNT');\n        require(reserveA > 0 && reserveB > 0, 'SCRYLibrary: INSUFFICIENT_LIQUIDITYQ');\n        // amount * price\n        amountB = amountA.mul(reserveB) / reserveA;\n    }\n\n    // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset\n    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {\n        require(amountIn > 0, 'SCRYLibrary: INSUFFICIENT_INPUT_AMOUNT');\n        require(reserveIn > 0 && reserveOut > 0, 'SCRYLibrary: INSUFFICIENT_LIQUIDITY1');\n        uint numerator = amountIn.mul(reserveOut);\n        uint denominator = reserveIn.add(amountIn.mul(2));\n        amountOut = numerator / denominator;\n    }\n\n    // given an output amount of an asset and pair reserves, returns a required input amount of the other asset\n    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {\n        require(amountOut > 0, 'SCRYLibrary: INSUFFICIENT_OUTPUT_AMOUNT');\n        require(reserveIn > 0 && reserveOut > 0, 'SCRYLibrary: INSUFFICIENT_LIQUIDITY2');\n        uint numerator = reserveIn.mul(amountOut);\n        uint denominator = reserveOut.sub(amountOut.mul(2));\n        amountIn = (numerator / denominator).add(1);\n    }\n\n    // performs chained getAmountOut calculations on any number of pairs\n    function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {\n        require(path.length >= 2, 'SCRYLibrary: INVALID_PATH');\n        amounts = new uint[](path.length);\n        amounts[0] = amountIn;\n        for (uint i; i < path.length - 1; i++) {\n            (uint reserveIn, uint reserveOut,) = getReserves(factory, path[i], path[i + 1]);\n            amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);\n        }\n    }\n\n    // performs chained getAmountIn calculations on any number of pairs\n    function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {\n        require(path.length >= 2, 'SCRYLibrary: INVALID_PATH');\n        amounts = new uint[](path.length);\n        amounts[amounts.length - 1] = amountOut;\n        for (uint i = path.length - 1; i > 0; i--) {\n            (uint reserveIn, uint reserveOut,) = getReserves(factory, path[i - 1], path[i]);\n            amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);\n        }\n    }\n}\n"
      },
      "contracts/periphery/LiquidityRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity =0.6.12;\n\nimport '../core/interfaces/ISCRYERC20Permit.sol';\nimport '../core/interfaces/ISCRYERC20.sol';\nimport '../core/interfaces/ISCRYFactory.sol';\nimport '../core/interfaces/IStashETH.sol';\nimport '../solidity-lib/libraries/TransferHelper.sol';\n\nimport './interfaces/ISCRYRouter.sol';\nimport './libraries/SCRYLibrary.sol';\nimport '../core/libraries/SafeMath.sol';\n\ncontract LiquidityRouter {\n    using SafeMath for uint;\n\n    address public immutable factory;\n    address public immutable WETH;\n\n    modifier ensure(uint deadline) {\n        require(deadline >= block.timestamp, 'LiquidityRouter: EXPIRED');\n        _;\n    }\n\n    constructor(address _factory, address _WETH) public {\n        factory = _factory;\n        WETH = _WETH;\n    }\n\n    // **** ADD LIQUIDITY ****\n     function createPairAndAddLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        address to,\n        uint deadline\n    ) public virtual ensure(deadline) returns (uint, uint, uint) {\n        (address pair, address stashTokenA, address stashTokenB) = ISCRYFactory(factory).createPair(tokenA, tokenB);\n        TransferHelper.safeTransferFrom(stashTokenA, msg.sender, pair, amountADesired);\n        TransferHelper.safeTransferFrom(stashTokenB, msg.sender, pair, amountBDesired);\n        return (amountADesired, amountBDesired, ISCRYPair(pair).mint(to));\n    }\n    function createETHPairAndAddLiquidity(\n        address token,\n        uint amountTokenDesired,\n        address to,\n        uint deadline\n    ) public virtual payable ensure(deadline) returns (uint, uint, uint) {\n        (address pair, address stashToken, ) = ISCRYFactory(factory).createPair(token, WETH);\n        TransferHelper.safeTransferFrom(stashToken, msg.sender, pair, amountTokenDesired);\n        assert(IStashETH(WETH).depositFor{value: msg.value}(pair));\n\n        return (amountTokenDesired, msg.value, ISCRYPair(pair).mint(to));\n    }\n\n    function _addLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        uint amountAMin,\n        uint amountBMin\n    ) internal virtual view returns (uint amountA, uint amountB, address pair) {\n        uint reserveA;\n        uint reserveB;\n        (reserveA, reserveB, pair) = SCRYLibrary.getReserves(factory, tokenA, tokenB);\n        if (reserveA == 0 && reserveB == 0) {\n            (amountA, amountB) = (amountADesired, amountBDesired);\n        } else {\n            uint amountBOptimal = SCRYLibrary.quote(amountADesired, reserveA, reserveB);\n            if (amountBOptimal <= amountBDesired) {\n                // swap A for B\n                require(amountBOptimal >= amountBMin, 'LiquidityRouter: INSUFFICIENT_B_AMOUNT');\n                (amountA, amountB) = (amountADesired, amountBOptimal);\n                require(amountA >= amountAMin, 'LiquidityRouter: INSUFFICIENT_A_AMOUNT');\n            } else {\n                // swap B for A\n                uint amountAOptimal = SCRYLibrary.quote(amountBDesired, reserveB, reserveA);\n                assert(amountAOptimal <= amountADesired);\n                require(amountAOptimal >= amountAMin, 'LiquidityRouter: INSUFFICIENT_A_AMOUNT');\n                (amountA, amountB) = (amountAOptimal, amountBDesired);\n                require(amountB >= amountBMin, 'LiquidityRouter: INSUFFICIENT_B_AMOUNT');\n            }\n        }\n    }\n    function addLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external virtual ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {\n        address pair;\n        (amountA, amountB, pair) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);\n        TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountA);\n        TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountB);\n        liquidity = ISCRYPair(pair).mint(to);\n    }\n\n    function addLiquidityETH(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline\n    ) external virtual payable ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) {\n        address pair;\n        (amountToken, amountETH, pair) = _addLiquidity(\n            token,\n            WETH,\n            amountTokenDesired,\n            msg.value,\n            amountTokenMin,\n            amountETHMin\n        );\n        TransferHelper.safeTransferFrom(token, msg.sender, pair, amountToken);\n\n        assert(IStashETH(WETH).depositFor{value: amountETH}(pair));\n        liquidity = ISCRYPair(pair).mint(to);\n        // refund dust eth, if any\n        if (msg.value > amountETH) TransferHelper.safeTransferETH(msg.sender, msg.value - amountETH);\n    }\n\n    // amountAMin and amountBMin represent minimum amounts if liquidity were withdrawn equally\n    function addUnbalancedLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external virtual ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {\n        if (ISCRYFactory(factory).getPair(tokenA, tokenB) == address(0)) {\n            ISCRYFactory(factory).createPair(tokenA, tokenB);\n        }\n        address pair = ISCRYFactory(factory).getPair(tokenA, tokenB);\n        TransferHelper.safeTransferFrom(tokenA, msg.sender, pair, amountADesired);\n        TransferHelper.safeTransferFrom(tokenB, msg.sender, pair, amountBDesired);\n        liquidity = ISCRYPair(pair).mint(to);\n        (amountA, amountB) = checkMintedAmount(liquidity, pair, tokenA, tokenB, amountAMin, amountBMin);\n    }\n    \n    // ensure if you burned the liquidity you could get at least amountAMin and amountBMin back\n    function checkMintedAmount(uint liquidity, address pair, address tokenA, address tokenB, uint amountAMin, uint amountBMin) private view returns (uint amountA, uint amountB) {\n        uint balanceA = ISCRYERC20(tokenA).balanceOf(pair);\n        uint balanceB = ISCRYERC20(tokenB).balanceOf(pair);\n        uint totalSupply = ISCRYERC20(pair).totalSupply();\n        amountA = liquidity.mul(balanceA) / totalSupply; \n        amountB = liquidity.mul(balanceB) / totalSupply;\n        require(amountA >= amountAMin, 'LiquidityRouter: INSUFFICIENT_A');\n        require(amountB >= amountBMin, 'LiquidityRouter: INSUFFICIENT_B');\n    }\n\n    function addUnbalancedLiquidityETH(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline\n    ) external virtual payable ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) {\n        if (ISCRYFactory(factory).getPair(token, WETH) == address(0)) {\n            ISCRYFactory(factory).createPair(token, WETH);\n        }\n        address pair = ISCRYFactory(factory).getPair(token, WETH);\n        TransferHelper.safeTransferFrom(token, msg.sender, pair, amountTokenDesired); \n        assert(IStashETH(WETH).depositFor{value: msg.value}(pair));\n        liquidity = ISCRYPair(pair).mint(to);\n        (amountToken, amountETH) = checkMintedAmount(liquidity, pair, token, WETH, amountTokenMin, amountETHMin);\n    }\n\n    // **** REMOVE LIQUIDITY ****\n    function removeLiquidity(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) public virtual ensure(deadline) returns (uint amountA, uint amountB) {\n        address pair = SCRYLibrary.pairFor(factory, tokenA, tokenB);\n        ISCRYERC20(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair\n        (uint amount0, uint amount1) = ISCRYPair(pair).burn(to);\n        (address token0,) = SCRYLibrary.sortTokens(tokenA, tokenB);\n        (amountA, amountB) = tokenA == token0 ? (amount0, amount1) : (amount1, amount0);\n        require(amountA >= amountAMin, 'LiquidityRouter: INSUFFICIENT_A_AMOUNT');\n        require(amountB >= amountBMin, 'LiquidityRouter: INSUFFICIENT_B_AMOUNT');\n    }\n    function removeUnbalancedLiquidity(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAExact,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) public virtual ensure(deadline) returns (uint, uint) {\n        address pair = SCRYLibrary.pairFor(factory, tokenA, tokenB);\n        ISCRYERC20(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair\n        (uint amount0, uint amount1) = ISCRYPair(pair).burnUnbalancedForExactToken(to, tokenA, amountAExact);\n\n        (address token0,) = SCRYLibrary.sortTokens(tokenA, tokenB);\n        if (token0 == tokenA) {\n            // require(amount0 >= amountAExact, 'LiquidityRouter: INSUFFICIENT_A');\n            require(amount1 >= amountBMin, 'LiquidityRouter: INSUFFICIENT_B');\n            return (amount0, amount1);\n        } else {\n            require(amount0 >= amountBMin, 'LiquidityRouter: INSUFFICIENT_B');\n            // require(amount1 >= amountAExact, 'LiquidityRouter: INSUFFICIENT_A');\n            return (amount1, amount0);\n        }\n    }\n}\n"
      },
      "contracts/periphery/SCRYRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity =0.6.12;\n\nimport '../core/interfaces/ISCRYERC20Permit.sol';\nimport '../solidity-lib/libraries/TransferHelper.sol';\n\nimport './interfaces/ISCRYStashRouter.sol';\nimport './interfaces/IWETH.sol';\nimport './libraries/SCRYLibrary.sol';\nimport '../core/libraries/SafeMath.sol';\nimport './LiquidityRouter.sol';\n\ncontract SCRYRouter is ISCRYStashRouter {\n    using SafeMath for uint;\n\n    address public immutable override factory;\n    address public immutable override WETH;\n    address public immutable override liquidityRouter;\n\n    modifier ensure(uint deadline) {\n        require(deadline >= block.timestamp, 'EXPIRED');\n        // EOA only\n        require(tx.origin == msg.sender, 'INVALID SENDER');\n        _;\n    }\n\n    constructor(address _factory) public {\n        factory = _factory;\n        address _WETH = ISCRYFactory(_factory).stashETH();\n        liquidityRouter = address(new LiquidityRouter(_factory, _WETH));\n        WETH = _WETH;\n    }\n\n    receive() external payable {\n        assert(msg.sender == WETH);\n    }\n\n    // **** ADD LIQUIDITY ****\n    function createPairAndAddLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        address to,\n        uint deadline\n    ) external virtual override returns (uint, uint, uint) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.createPairAndAddLiquidity.selector, \n            tokenA, tokenB, amountADesired, amountBDesired, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n\n    function createETHPairAndAddLiquidity(\n        address token,\n        uint amountTokenDesired,\n        address to,\n        uint deadline\n    ) external virtual override payable returns (uint, uint, uint) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.createETHPairAndAddLiquidity.selector, \n            token, amountTokenDesired, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n\n    function addLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external virtual override returns (uint amountA, uint amountB, uint liquidity) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.addLiquidity.selector, \n            tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n    function addUnbalancedLiquidity(\n        address tokenA,\n        address tokenB,\n        uint amountADesired,\n        uint amountBDesired,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) external virtual override returns (uint amountA, uint amountB, uint liquidity) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.addUnbalancedLiquidity.selector, \n            tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n    function addLiquidityETH(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline\n    ) public virtual override payable returns (uint amountToken, uint amountETH, uint liquidity) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.addLiquidityETH.selector, \n            token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n    function addLiquidityETHWithPermit(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external virtual override payable returns (uint amountToken, uint amountETH, uint liquidity) {\n      _permit(token, amountTokenDesired, deadline, approveMax, v, r, s);\n      return addLiquidityETH(token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline);\n    }\n\n    function addUnbalancedLiquidityETH(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline\n    ) public virtual override payable returns (uint amountToken, uint amountETH, uint liquidity) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.addUnbalancedLiquidityETH.selector, \n            token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n\n    function addUnbalancedLiquidityETHWithPermit(\n        address token,\n        uint amountTokenDesired,\n        uint amountTokenMin,\n        uint amountETHMin,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external virtual override payable returns (uint amountToken, uint amountETH, uint liquidity) {\n      _permit(token, amountTokenDesired, deadline, approveMax, v, r, s);\n      return addUnbalancedLiquidityETH(token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline);\n    }\n\n    // **** REMOVE LIQUIDITY ****\n    function removeLiquidity(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) public virtual override returns (uint amountA, uint amountB) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.removeLiquidity.selector, \n            tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint));\n    } \n    function removeLiquidityWithPermit(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAMin,\n        uint amountBMin,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external virtual override returns (uint, uint) {\n        _permit(SCRYLibrary.pairFor(factory, tokenA, tokenB), liquidity, deadline, approveMax, v, r, s);\n        return removeLiquidity(tokenA, tokenB, liquidity, amountAMin, amountBMin, to, deadline);\n    }\n    function removeUnbalancedLiquidity(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAExact,\n        uint amountBMin,\n        address to,\n        uint deadline\n    ) public virtual override returns (uint, uint) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(LiquidityRouter.removeUnbalancedLiquidity.selector, \n            tokenA, tokenB, liquidity, amountAExact, amountBMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint));\n    }\n    function removeUnbalancedLiquidityWithPermit(\n        address tokenA,\n        address tokenB,\n        uint liquidity,\n        uint amountAExact,\n        uint amountBMin,       \n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) external virtual override returns (uint, uint) {\n        _permit(SCRYLibrary.pairFor(factory, tokenA, tokenB), liquidity, deadline, approveMax, v, r, s);\n        return removeUnbalancedLiquidity(tokenA, tokenB, liquidity, amountAExact, amountBMin, to, deadline);\n    }\n    function _permit(\n        address token, uint amount, uint deadline, \n        bool approveMax, uint8 v, bytes32 r, bytes32 s) internal {\n        ISCRYERC20Permit(token)\n            .permit(msg.sender, address(this), approveMax ? uint(-1) : amount, deadline, v, r, s);\n    }\n\n    // **** SWAP ****\n    function _swap(uint[] memory amounts, address[] memory path, address _to) internal virtual {\n        for (uint i; i < path.length - 1; i++) {\n            (address input, address output) = (path[i], path[i + 1]);\n            (address token0,) = SCRYLibrary.sortTokens(input, output);\n            uint amountOut = amounts[i + 1];\n            (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOut) : (amountOut, uint(0));\n            address to = i < path.length - 2 ? SCRYLibrary.pairFor(factory, output, path[i + 2]) : _to;\n            ISCRYPair(SCRYLibrary.pairFor(factory, input, output)).swap(\n                amount0Out, amount1Out, to, new bytes(0)\n            );\n        }\n    }\n    function swapExactTokensForTokens(\n        uint amountIn,\n        uint amountOutMin,\n        address[] calldata path,\n        address to,\n        uint deadline\n    ) public virtual override ensure(deadline) returns (uint[] memory amounts) {\n        amounts = SCRYLibrary.getAmountsOut(factory, amountIn, path);\n        require(amounts[amounts.length - 1] >= amountOutMin, 'OUTPUT');\n        TransferHelper.safeTransferFrom(\n            path[0], msg.sender, SCRYLibrary.pairFor(factory, path[0], path[1]), amounts[0]\n        );\n        _swap(amounts, path, to);\n    }\n    function swapTokensForExactTokens(\n        uint amountOut,\n        uint amountInMax,\n        address[] calldata path,\n        address to,\n        uint deadline\n    ) public virtual override ensure(deadline) returns (uint[] memory amounts) {\n        amounts = SCRYLibrary.getAmountsIn(factory, amountOut, path);\n        require(amounts[0] <= amountInMax, 'INPUT');\n        TransferHelper.safeTransferFrom(\n            path[0], msg.sender, SCRYLibrary.pairFor(factory, path[0], path[1]), amounts[0]\n        );\n        _swap(amounts, path, to);\n    }\n\n    // **** SWAP (supporting fee-on-transfer tokens) ****\n    // stashed tokens are not feeOnTransfer so not required\n\n    function swapExactTokensForTokensWithPermit(\n        uint amountIn,\n        uint amountOutMin,\n        address[] calldata path,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) public virtual override ensure(deadline) returns (uint[] memory amounts) {\n        _permit(path[0], amountIn, deadline, approveMax, v, r, s);\n        return swapExactTokensForTokens(amountIn, amountOutMin, path, to, deadline);\n    }\n    function swapTokensForExactTokensWithPermit(\n        uint amountOut,\n        uint amountInMax,\n        address[] calldata path,\n        address to,\n        uint deadline,\n        bool approveMax, uint8 v, bytes32 r, bytes32 s\n    ) public virtual override ensure(deadline) returns (uint[] memory amounts) {\n        _permit(path[0], amountInMax, deadline, approveMax, v, r, s);\n        return swapTokensForExactTokens(amountOut, amountInMax, path, to, deadline);\n    }\n\n    // **** LIBRARY FUNCTIONS ****\n    function quote(uint amountA, uint reserveA, uint reserveB) external pure virtual override returns (uint amountB) {\n        return SCRYLibrary.quote(amountA, reserveA, reserveB);\n    }\n    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut)\n        external\n        pure\n        virtual\n        override\n        returns (uint amountOut)\n    {\n        return SCRYLibrary.getAmountOut(amountIn, reserveIn, reserveOut);\n    }\n    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut)\n        external\n        pure\n        virtual\n        override\n        returns (uint amountIn)\n    {\n        return SCRYLibrary.getAmountIn(amountOut, reserveIn, reserveOut);\n    }\n    function getAmountsOut(uint amountIn, address[] calldata path)\n        external\n        view\n        virtual\n        override\n        returns (uint[] memory amounts)\n    {\n        return SCRYLibrary.getAmountsOut(factory, amountIn, path);\n    }\n    function getAmountsIn(uint amountOut, address[] calldata path)\n        external\n        view\n        virtual\n        override\n        returns (uint[] memory amounts)\n    {\n        return SCRYLibrary.getAmountsIn(factory, amountOut, path);\n    }\n}\n"
      },
      "contracts/solidity-lib/libraries/TransferHelper.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0-or-later\n\npragma solidity >=0.6.0;\n\n// helper methods for interacting with ERC20 tokens and sending ETH that do not consistently return true/false\nlibrary TransferHelper {\n    function safeApprove(\n        address token,\n        address to,\n        uint256 value\n    ) internal {\n        // bytes4(keccak256(bytes('approve(address,uint256)')));\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            'TransferHelper::safeApprove: approve failed'\n        );\n    }\n\n    function safeTransfer(\n        address token,\n        address to,\n        uint256 value\n    ) internal {\n        // bytes4(keccak256(bytes('transfer(address,uint256)')));\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            'TransferHelper::safeTransfer: transfer failed'\n        );\n    }\n\n    function safeTransferFrom(\n        address token,\n        address from,\n        address to,\n        uint256 value\n    ) internal {\n        // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));\n        (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));\n        require(\n            success && (data.length == 0 || abi.decode(data, (bool))),\n            'TransferHelper::transferFrom: transferFrom failed'\n        );\n    }\n\n    function safeTransferETH(address to, uint256 value) internal {\n        (bool success, ) = to.call{value: value}(new bytes(0));\n        require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');\n    }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 999999
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}