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/ISCRYTokenFactory.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\ninterface ISCRYTokenFactory {\n    event TokenCreated(address indexed nativeToken, address indexed stashToken);\n\n    function isStashed(address token) external view returns (bool);\n    function nativeToStash(address token) external view returns (address);\n    function stashTokensLength() external view returns (uint);\n    function stashTokens(uint index) external view returns (address);\n    function getStashAddress(address nativeToken) external view returns (address);\n    function getOrCreateStashToken(address nativeToken) external returns (address stashToken);\n    function stashETH() external view returns (address);\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/interfaces/IStashToken.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.5.0;\n\nimport './ISCRYERC20.sol';\nimport './ISCRYPairTransferable.sol';\n\ninterface IStashToken is ISCRYPairTransferable {\n    // needs permit\n    function underlying() external returns (ISCRYERC20);\n    function depositFor(address to, uint256 amount) external returns (bool);\n    function depositForWithPermit(address to, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external returns (bool);\n    function deposit() external returns (uint256);\n    function depositTo(address to) external returns (uint256);\n    function withdrawTo(address account, uint amount) external returns (bool);\n    function withdrawFrom(address from, address to, 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/ISCRYNativeRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\nimport './ISCRYRouter.sol';\n\npragma solidity >=0.6.2;\n\ninterface ISCRYNativeRouter is ISCRYRouter {\n    function addLiquiditySingleNative(\n        address nativeToken,\n        address stashToken,\n        uint amountNativeDesired,\n        uint amountStashDesired,\n        uint amountNativeMin,\n        uint amountStashMin,\n        address to,\n        uint deadline\n    ) external returns (uint amountA, uint amountB, uint liquidity);\n    function addUnbalancedLiquiditySingleNative(\n        address nativeToken,\n        address stashToken,\n        uint amountNativeDesired,\n        uint amountStashDesired,\n        uint amountNativeMin,\n        uint amountStashMin,\n        address to,\n        uint deadline\n    ) external returns (uint amountA, uint amountB, uint liquidity);\n    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)\n        external\n        payable\n        returns (uint[] memory amounts);\n    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)\n        external\n        payable\n        returns (uint[] memory amounts);\n    function swapExactTokensForTokensSupportingFeeOnTransferTokens(\n        uint amountIn,\n        uint amountOutMin,\n        address[] calldata path,\n        address to,\n        uint deadline\n    ) external;\n    function swapExactETHForTokensSupportingFeeOnTransferTokens(\n        uint amountOutMin,\n        address[] calldata path,\n        address to,\n        uint deadline\n    ) external payable;\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/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/NativeLiquidityRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity =0.6.12;\n\npragma experimental ABIEncoderV2;\n\nimport '../core/interfaces/ISCRYERC20Permit.sol';\nimport '../core/interfaces/ISCRYTokenFactory.sol';\nimport '../core/interfaces/ISCRYFactory.sol';\nimport '../core/interfaces/IStashETH.sol';\nimport '../core/interfaces/IStashToken.sol';\nimport '../solidity-lib/libraries/TransferHelper.sol';\n\nimport './libraries/SCRYLibrary.sol';\nimport '../core/libraries/SafeMath.sol';\n\ncontract NativeLiquidityRouter {\n    using SafeMath for uint;\n\n    address public immutable factory;\n    address public immutable WETH;\n    address private immutable tokenFactory;\n    uint256 private constant MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;\n\n    modifier ensure(uint deadline) {\n        require(deadline >= block.timestamp, 'LiquidityRouter: EXPIRED');\n        _;\n    }\n\n    constructor(address _factory) public {\n        factory = _factory;\n        WETH = ISCRYFactory(_factory).stashETH();\n        tokenFactory = ISCRYFactory(_factory).tokenFactory();\n    }\n\n    // **** ADD LIQUIDITY ****\n     function createPairAndAddLiquidity(\n        address nativeTokenA,\n        address nativeTokenB,\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(nativeTokenA, nativeTokenB);\n        TransferHelper.safeTransferFrom(nativeTokenA, msg.sender, stashTokenA, amountADesired);\n        IStashToken(stashTokenA).depositTo(pair);\n        TransferHelper.safeTransferFrom(nativeTokenB, msg.sender, stashTokenB, amountBDesired);\n        IStashToken(stashTokenB).depositTo(pair);\n        return (amountADesired, amountBDesired, ISCRYPair(pair).mint(to));\n    }\n    function createETHPairAndAddLiquidity(\n        address nativeToken,\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(nativeToken, WETH);\n        TransferHelper.safeTransferFrom(nativeToken, msg.sender, stashToken, amountTokenDesired);\n        IStashToken(stashToken).depositTo(pair);\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    ) private 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\n    // ensure if you burned the liquidity you could get at least amountAMin and amountBMin back\n    function checkMintedAmount(uint liquidity, uint balanceA, uint balanceB, uint totalSupply, uint amountAMin, uint amountBMin) private pure returns (uint, uint, uint) {\n        uint amountA = liquidity.mul(balanceA) / totalSupply; \n        uint amountB = liquidity.mul(balanceB) / totalSupply;\n        require(amountA >= amountAMin, 'LiquidityRouter: INSUFFICIENT_A');\n        require(amountB >= amountBMin, 'LiquidityRouter: INSUFFICIENT_B');\n        return (amountA, amountB, liquidity);\n    }\n\n    // **** ADD LIQUIDITY NATIVE ***\n    function depositNativeToken(address token, uint amount, address pair) private {\n        address underlyingToken = address(IStashToken(token).underlying());\n        TransferHelper.safeTransferFrom(underlyingToken, msg.sender, token, amount);\n        IStashToken(token).depositTo(pair);\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    ) public virtual ensure(deadline) returns (uint, uint, uint) {\n        (uint amountA, uint amountB, address pair) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);\n        depositNativeToken(tokenA, amountA, pair);\n        depositNativeToken(tokenB, amountB, pair);\n        return (amountA, amountB, ISCRYPair(pair).mint(to));\n    }\n\n    // deposit underlying of nativeToken\n    function addLiquiditySingleNative(\n        address nativeToken,\n        address stashToken,\n        uint amountNativeDesired,\n        uint amountStashDesired,\n        uint amountNativeMin,\n        uint amountStashMin,\n        address to,\n        uint deadline\n    ) public virtual ensure(deadline) returns (uint, uint, uint) {\n        (uint amountNative, uint amountStash, address pair) = _addLiquidity(nativeToken, stashToken, amountNativeDesired, amountStashDesired, amountNativeMin, amountStashMin);\n        depositNativeToken(nativeToken, amountNative, pair);\n        TransferHelper.safeTransferFrom(stashToken, msg.sender, pair, amountStash);\n        return (amountNative, amountStash, 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    ) public 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        depositNativeToken(token, amountTokenDesired, pair);\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    ) public virtual ensure(deadline) returns (uint, uint, uint) {\n        address pair = ISCRYFactory(factory).getPair(tokenA, tokenB);\n        depositNativeToken(tokenA, amountADesired, pair);\n        depositNativeToken(tokenB, amountBDesired, pair);\n        return checkMintedAmount(ISCRYPair(pair).mint(to), ISCRYERC20Permit(tokenA).balanceOf(pair), ISCRYERC20Permit(tokenB).balanceOf(pair), ISCRYERC20Permit(pair).totalSupply(), amountAMin, amountBMin);\n    }\n\n    function addUnbalancedLiquiditySingleNative(\n        address nativeToken,\n        address stashToken,\n        uint amountNativeDesired,\n        uint amountStashDesired,\n        uint amountNativeMin,\n        uint amountStashMin,\n        address to,\n        uint deadline\n    ) public virtual ensure(deadline) returns (uint, uint, uint) {\n        address pair = ISCRYFactory(factory).getPair(nativeToken, stashToken);\n        depositNativeToken(nativeToken, amountNativeDesired, pair);\n        TransferHelper.safeTransferFrom(stashToken, msg.sender, pair, amountStashDesired);\n        return checkMintedAmount(ISCRYPair(pair).mint(to), ISCRYERC20Permit(nativeToken).balanceOf(pair), ISCRYERC20Permit(stashToken).balanceOf(pair), ISCRYERC20Permit(pair).totalSupply(), amountNativeMin, amountStashMin);\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 payable ensure(deadline) returns (uint amountToken, uint amountETH, uint liquidity) {\n        address pair = ISCRYFactory(factory).getPair(token, WETH);\n        depositNativeToken(token, amountTokenDesired, pair);\n        assert(IStashETH(WETH).depositFor{value: msg.value}(pair));\n        liquidity = ISCRYPair(pair).mint(to);\n        (amountToken, amountETH, liquidity) = checkMintedAmount(liquidity, ISCRYERC20Permit(token).balanceOf(pair), ISCRYERC20Permit(WETH).balanceOf(pair), ISCRYERC20Permit(pair).totalSupply(), amountTokenMin, amountETHMin);\n    }\n}\n"
      },
      "contracts/periphery/SCRYNativeRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity =0.6.12;\n\nimport '../core/interfaces/ISCRYERC20Permit.sol';\nimport '../core/interfaces/ISCRYFactory.sol';\nimport '../core/interfaces/ISCRYTokenFactory.sol';\nimport '../core/interfaces/IStashToken.sol';\nimport '../core/interfaces/IStashETH.sol';\nimport '../solidity-lib/libraries/TransferHelper.sol';\n\nimport './interfaces/ISCRYNativeRouter.sol';\nimport './libraries/SCRYLibrary.sol';\nimport '../core/libraries/SafeMath.sol';\n\nimport './NativeLiquidityRouter.sol';\n\ncontract SCRYNativeRouter is ISCRYNativeRouter {\n    using SafeMath for uint;\n\n    address public immutable override factory;\n    address public immutable STASH_ETH;\n    address public immutable tokenFactory;\n    address public immutable override liquidityRouter;\n    uint256 private constant MAX_INT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;\n\n    modifier ensure(uint deadline) {\n        require(deadline >= block.timestamp, 'EXPIRED');\n        // Not necessary because it won't be the default router, will be restricted by Pool\n        // require(tx.origin == msg.sender, 'INVALID SENDER');\n        _;\n    }\n\n    constructor(address _factory) public {\n        factory = _factory;\n        STASH_ETH = ISCRYFactory(_factory).stashETH();\n        tokenFactory = ISCRYFactory(_factory).tokenFactory();\n        liquidityRouter = address(new NativeLiquidityRouter(_factory));\n    }\n\n    receive() external payable {\n        assert(msg.sender == STASH_ETH);\n    }\n\n    function WETH() external override view returns (address) {\n      return STASH_ETH;\n    }\n    \n    // **** ADD LIQUIDITY ****\n    function createPairAndAddLiquidity(\n        address nativeTokenA,\n        address nativeTokenB,\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(NativeLiquidityRouter.createPairAndAddLiquidity.selector, \n            nativeTokenA, nativeTokenB, amountADesired, amountBDesired, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n\n    function createETHPairAndAddLiquidity(\n        address nativeToken,\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(NativeLiquidityRouter.createETHPairAndAddLiquidity.selector, \n            nativeToken, 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(NativeLiquidityRouter.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(NativeLiquidityRouter.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    ) external virtual override payable returns (uint amountToken, uint amountETH, uint liquidity) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(NativeLiquidityRouter.addLiquidityETH.selector, \n            token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\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 override payable returns (uint amountToken, uint amountETH, uint liquidity) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(NativeLiquidityRouter.addUnbalancedLiquidityETH.selector, \n            token, amountTokenDesired, amountTokenMin, amountETHMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n    function addLiquiditySingleNative(\n        address nativeToken,\n        address stashToken,\n        uint amountNativeDesired,\n        uint amountStashDesired,\n        uint amountNativeMin,\n        uint amountStashMin,\n        address to,\n        uint deadline\n    ) public virtual override ensure(deadline) returns (uint, uint, uint){\n        (uint amountNative, uint amountStash, address pair) = _addLiquidity(nativeToken, stashToken, amountNativeDesired, amountStashDesired, amountNativeMin, amountStashMin);\n        depositNativeToken(nativeToken, amountNative, pair);\n        TransferHelper.safeTransferFrom(stashToken, msg.sender, pair, amountStash);\n        return (amountNative, amountStash, 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    ) private 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 addUnbalancedLiquiditySingleNative(\n        address nativeToken,\n        address stashToken,\n        uint amountNativeDesired,\n        uint amountStashDesired,\n        uint amountNativeMin,\n        uint amountStashMin,\n        address to,\n        uint deadline\n    ) public virtual override ensure(deadline) returns (uint, uint, uint) {\n        (bool success, bytes memory result) = liquidityRouter.delegatecall(\n            abi.encodeWithSelector(NativeLiquidityRouter.addUnbalancedLiquiditySingleNative.selector, \n            nativeToken, stashToken, amountNativeDesired, amountStashDesired, amountNativeMin, amountStashMin, to, deadline));\n        require(success);\n        return abi.decode(result, (uint, uint, uint));\n    }\n\n    // **** REMOVE LIQUIDITY ****\n    // Found in SCRYRouter\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[] memory 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        depositNativeToken(path[0], amounts[0], SCRYLibrary.pairFor(factory, path[0], path[1]));\n        _swap(amounts, path, to);\n    }\n\n    function swapTokensForExactTokens(\n        uint amountOut,\n        uint amountInMax,\n        address[] memory 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        depositNativeToken(path[0], amounts[0], SCRYLibrary.pairFor(factory, path[0], path[1]));\n        _swap(amounts, path, to);\n    }\n    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)\n        public\n        virtual\n        override\n        payable\n        ensure(deadline)\n        returns (uint[] memory amounts)\n    {\n        require(path[0] == STASH_ETH, 'PATH');\n        amounts = SCRYLibrary.getAmountsOut(factory, msg.value, path);\n        require(amounts[amounts.length - 1] >= amountOutMin, 'OUTPUT');\n        address pair = SCRYLibrary.pairFor(factory, path[0], path[1]);\n        assert(IStashETH(STASH_ETH).depositFor{value: amounts[0]}(pair));\n        _swap(amounts, path, to);\n    }\n    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)\n        external\n        virtual\n        override\n        payable\n        ensure(deadline)\n        returns (uint[] memory amounts)\n    {\n        require(path[0] == STASH_ETH, 'PATH');\n        amounts = SCRYLibrary.getAmountsIn(factory, amountOut, path);\n        require(amounts[0] <= msg.value, 'INPUT');\n        assert(IStashETH(STASH_ETH).depositFor{value: amounts[0]}(SCRYLibrary.pairFor(factory, path[0], path[1])));\n        _swap(amounts, path, to);\n        // refund dust eth, if any\n        if (msg.value > amounts[0]) TransferHelper.safeTransferETH(msg.sender, msg.value - amounts[0]);\n    }\n\n    // **** SWAP (supporting fee-on-transfer tokens) ****\n    // requires the initial amount to have already been sent to the first pair\n    function _swapSupportingFeeOnTransferTokens(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            ISCRYPair pair = ISCRYPair(SCRYLibrary.pairFor(factory, input, output));\n            uint amountInput;\n            uint amountOutput;\n            { // scope to avoid stack too deep errors\n            (uint reserve0, uint reserve1) = pair.getReserves();\n            (uint reserveInput, uint reserveOutput) = input == token0 ? (reserve0, reserve1) : (reserve1, reserve0);\n            amountInput = ISCRYERC20Permit(input).balanceOf(address(pair)).sub(reserveInput);\n            amountOutput = SCRYLibrary.getAmountOut(amountInput, reserveInput, reserveOutput);\n            }\n            (uint amount0Out, uint amount1Out) = input == token0 ? (uint(0), amountOutput) : (amountOutput, uint(0));\n            address to = i < path.length - 2 ? SCRYLibrary.pairFor(factory, output, path[i + 2]) : _to;\n            pair.swap(amount0Out, amount1Out, to, new bytes(0));\n        }\n    }\n    function swapExactTokensForTokensSupportingFeeOnTransferTokens(\n        uint amountIn,\n        uint amountOutMin,\n        address[] memory path,\n        address to,\n        uint deadline\n    ) external virtual override ensure(deadline) {\n        depositNativeToken(path[0], amountIn, SCRYLibrary.pairFor(factory, path[0], path[1]));\n        uint balanceBefore = ISCRYERC20Permit(path[path.length - 1]).balanceOf(to);\n        _swapSupportingFeeOnTransferTokens(path, to);\n        require(\n            ISCRYERC20Permit(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,\n            'OUTPUT'\n        );\n    }\n    function swapExactETHForTokensSupportingFeeOnTransferTokens(\n        uint amountOutMin,\n        address[] calldata path,\n        address to,\n        uint deadline\n    )\n        external\n        virtual\n        override\n        payable\n        ensure(deadline)\n    {\n        require(path[0] == STASH_ETH, 'PATH');\n        uint amountIn = msg.value;\n        assert(IStashETH(STASH_ETH).depositFor{value: amountIn}(SCRYLibrary.pairFor(factory, path[0], path[1])));\n\n        uint balanceBefore = ISCRYERC20Permit(path[path.length - 1]).balanceOf(to);\n        _swapSupportingFeeOnTransferTokens(path, to);\n        require(\n            ISCRYERC20Permit(path[path.length - 1]).balanceOf(to).sub(balanceBefore) >= amountOutMin,\n            'OUTPUT'\n        );\n    }\n    function depositNativeToken(address token, uint amount, address pair) private {\n        address underlyingToken = address(IStashToken(token).underlying());\n        TransferHelper.safeTransferFrom(underlyingToken, msg.sender, token, amount);\n        IStashToken(token).depositTo(pair);\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": {}
    }
  }}