creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "contracts/aave-protocol-v2/adapters/BaseUniswapAdapter.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport {PercentageMath} from '../protocol/libraries/math/PercentageMath.sol';\nimport {SafeMath} from '../dependencies/openzeppelin/contracts/SafeMath.sol';\nimport {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';\nimport {IERC20Detailed} from '../dependencies/openzeppelin/contracts/IERC20Detailed.sol';\nimport {SafeERC20} from '../dependencies/openzeppelin/contracts/SafeERC20.sol';\nimport {Ownable} from '../dependencies/openzeppelin/contracts/Ownable.sol';\nimport {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';\nimport {DataTypes} from '../protocol/libraries/types/DataTypes.sol';\nimport {IUniswapV2Router02} from '../interfaces/IUniswapV2Router02.sol';\nimport {IPriceOracleGetter} from '../interfaces/IPriceOracleGetter.sol';\nimport {IERC20WithPermit} from '../interfaces/IERC20WithPermit.sol';\nimport {FlashLoanReceiverBase} from '../flashloan/base/FlashLoanReceiverBase.sol';\nimport {IBaseUniswapAdapter} from './interfaces/IBaseUniswapAdapter.sol';\n\n/**\n * @title BaseUniswapAdapter\n * @notice Implements the logic for performing assets swaps in Uniswap V2\n * @author Aave\n **/\nabstract contract BaseUniswapAdapter is FlashLoanReceiverBase, IBaseUniswapAdapter, Ownable {\n  using SafeMath for uint256;\n  using PercentageMath for uint256;\n  using SafeERC20 for IERC20;\n\n  // Max slippage percent allowed\n  uint256 public constant override MAX_SLIPPAGE_PERCENT = 3000; // 30%\n  // FLash Loan fee set in lending pool\n  uint256 public constant override FLASHLOAN_PREMIUM_TOTAL = 9;\n  // USD oracle asset address\n  address public constant override USD_ADDRESS = 0x10F7Fc1F91Ba351f9C629c5947AD69bD03C05b96;\n\n  address public immutable override WETH_ADDRESS;\n  IPriceOracleGetter public immutable override ORACLE;\n  IUniswapV2Router02 public immutable override UNISWAP_ROUTER;\n\n  constructor(\n    ILendingPoolAddressesProvider addressesProvider,\n    IUniswapV2Router02 uniswapRouter,\n    address wethAddress\n  ) public FlashLoanReceiverBase(addressesProvider) {\n    ORACLE = IPriceOracleGetter(addressesProvider.getPriceOracle());\n    UNISWAP_ROUTER = uniswapRouter;\n    WETH_ADDRESS = wethAddress;\n  }\n\n  /**\n   * @dev Given an input asset amount, returns the maximum output amount of the other asset and the prices\n   * @param amountIn Amount of reserveIn\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @return uint256 Amount out of the reserveOut\n   * @return uint256 The price of out amount denominated in the reserveIn currency (18 decimals)\n   * @return uint256 In amount of reserveIn value denominated in USD (8 decimals)\n   * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals)\n   */\n  function getAmountsOut(\n    uint256 amountIn,\n    address reserveIn,\n    address reserveOut\n  ) external view override returns (uint256, uint256, uint256, uint256, address[] memory) {\n    AmountCalc memory results = _getAmountsOutData(reserveIn, reserveOut, amountIn);\n\n    return (\n      results.calculatedAmount,\n      results.relativePrice,\n      results.amountInUsd,\n      results.amountOutUsd,\n      results.path\n    );\n  }\n\n  /**\n   * @dev Returns the minimum input asset amount required to buy the given output asset amount and the prices\n   * @param amountOut Amount of reserveOut\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @return uint256 Amount in of the reserveIn\n   * @return uint256 The price of in amount denominated in the reserveOut currency (18 decimals)\n   * @return uint256 In amount of reserveIn value denominated in USD (8 decimals)\n   * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals)\n   */\n  function getAmountsIn(\n    uint256 amountOut,\n    address reserveIn,\n    address reserveOut\n  ) external view override returns (uint256, uint256, uint256, uint256, address[] memory) {\n    AmountCalc memory results = _getAmountsInData(reserveIn, reserveOut, amountOut);\n\n    return (\n      results.calculatedAmount,\n      results.relativePrice,\n      results.amountInUsd,\n      results.amountOutUsd,\n      results.path\n    );\n  }\n\n  /**\n   * @dev Swaps an exact `amountToSwap` of an asset to another\n   * @param assetToSwapFrom Origin asset\n   * @param assetToSwapTo Destination asset\n   * @param amountToSwap Exact amount of `assetToSwapFrom` to be swapped\n   * @param minAmountOut the min amount of `assetToSwapTo` to be received from the swap\n   * @return the amount received from the swap\n   */\n  function _swapExactTokensForTokens(\n    address assetToSwapFrom,\n    address assetToSwapTo,\n    uint256 amountToSwap,\n    uint256 minAmountOut,\n    bool useEthPath\n  ) internal returns (uint256) {\n    uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom);\n    uint256 toAssetDecimals = _getDecimals(assetToSwapTo);\n\n    uint256 fromAssetPrice = _getPrice(assetToSwapFrom);\n    uint256 toAssetPrice = _getPrice(assetToSwapTo);\n\n    uint256 expectedMinAmountOut = amountToSwap\n      .mul(fromAssetPrice.mul(10 ** toAssetDecimals))\n      .div(toAssetPrice.mul(10 ** fromAssetDecimals))\n      .percentMul(PercentageMath.PERCENTAGE_FACTOR.sub(MAX_SLIPPAGE_PERCENT));\n\n    require(expectedMinAmountOut < minAmountOut, 'minAmountOut exceed max slippage');\n\n    // Approves the transfer for the swap. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.\n    IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), 0);\n    IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), amountToSwap);\n\n    address[] memory path;\n    if (useEthPath) {\n      path = new address[](3);\n      path[0] = assetToSwapFrom;\n      path[1] = WETH_ADDRESS;\n      path[2] = assetToSwapTo;\n    } else {\n      path = new address[](2);\n      path[0] = assetToSwapFrom;\n      path[1] = assetToSwapTo;\n    }\n    uint256[] memory amounts = UNISWAP_ROUTER.swapExactTokensForTokens(\n      amountToSwap,\n      minAmountOut,\n      path,\n      address(this),\n      block.timestamp\n    );\n\n    emit Swapped(assetToSwapFrom, assetToSwapTo, amounts[0], amounts[amounts.length - 1]);\n\n    return amounts[amounts.length - 1];\n  }\n\n  /**\n   * @dev Receive an exact amount `amountToReceive` of `assetToSwapTo` tokens for as few `assetToSwapFrom` tokens as\n   * possible.\n   * @param assetToSwapFrom Origin asset\n   * @param assetToSwapTo Destination asset\n   * @param maxAmountToSwap Max amount of `assetToSwapFrom` allowed to be swapped\n   * @param amountToReceive Exact amount of `assetToSwapTo` to receive\n   * @return the amount swapped\n   */\n  function _swapTokensForExactTokens(\n    address assetToSwapFrom,\n    address assetToSwapTo,\n    uint256 maxAmountToSwap,\n    uint256 amountToReceive,\n    bool useEthPath\n  ) internal returns (uint256) {\n    uint256 fromAssetDecimals = _getDecimals(assetToSwapFrom);\n    uint256 toAssetDecimals = _getDecimals(assetToSwapTo);\n\n    uint256 fromAssetPrice = _getPrice(assetToSwapFrom);\n    uint256 toAssetPrice = _getPrice(assetToSwapTo);\n\n    uint256 expectedMaxAmountToSwap = amountToReceive\n      .mul(toAssetPrice.mul(10 ** fromAssetDecimals))\n      .div(fromAssetPrice.mul(10 ** toAssetDecimals))\n      .percentMul(PercentageMath.PERCENTAGE_FACTOR.add(MAX_SLIPPAGE_PERCENT));\n\n    require(maxAmountToSwap < expectedMaxAmountToSwap, 'maxAmountToSwap exceed max slippage');\n\n    // Approves the transfer for the swap. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.\n    IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), 0);\n    IERC20(assetToSwapFrom).safeApprove(address(UNISWAP_ROUTER), maxAmountToSwap);\n\n    address[] memory path;\n    if (useEthPath) {\n      path = new address[](3);\n      path[0] = assetToSwapFrom;\n      path[1] = WETH_ADDRESS;\n      path[2] = assetToSwapTo;\n    } else {\n      path = new address[](2);\n      path[0] = assetToSwapFrom;\n      path[1] = assetToSwapTo;\n    }\n\n    uint256[] memory amounts = UNISWAP_ROUTER.swapTokensForExactTokens(\n      amountToReceive,\n      maxAmountToSwap,\n      path,\n      address(this),\n      block.timestamp\n    );\n\n    emit Swapped(assetToSwapFrom, assetToSwapTo, amounts[0], amounts[amounts.length - 1]);\n\n    return amounts[0];\n  }\n\n  /**\n   * @dev Get the price of the asset from the oracle denominated in eth\n   * @param asset address\n   * @return eth price for the asset\n   */\n  function _getPrice(address asset) internal view returns (uint256) {\n    return ORACLE.getAssetPrice(asset);\n  }\n\n  /**\n   * @dev Get the decimals of an asset\n   * @return number of decimals of the asset\n   */\n  function _getDecimals(address asset) internal view returns (uint256) {\n    return IERC20Detailed(asset).decimals();\n  }\n\n  /**\n   * @dev Get the aToken associated to the asset\n   * @return address of the aToken\n   */\n  function _getReserveData(address asset) internal view returns (DataTypes.ReserveData memory) {\n    return LENDING_POOL.getReserveData(asset);\n  }\n\n  /**\n   * @dev Pull the ATokens from the user\n   * @param reserve address of the asset\n   * @param reserveAToken address of the aToken of the reserve\n   * @param user address\n   * @param amount of tokens to be transferred to the contract\n   * @param permitSignature struct containing the permit signature\n   */\n  function _pullAToken(\n    address reserve,\n    address reserveAToken,\n    address user,\n    uint256 amount,\n    PermitSignature memory permitSignature\n  ) internal {\n    if (_usePermit(permitSignature)) {\n      IERC20WithPermit(reserveAToken).permit(\n        user,\n        address(this),\n        permitSignature.amount,\n        permitSignature.deadline,\n        permitSignature.v,\n        permitSignature.r,\n        permitSignature.s\n      );\n    }\n\n    // transfer from user to adapter\n    IERC20(reserveAToken).safeTransferFrom(user, address(this), amount);\n\n    // withdraw reserve\n    LENDING_POOL.withdraw(reserve, amount, address(this));\n  }\n\n  /**\n   * @dev Tells if the permit method should be called by inspecting if there is a valid signature.\n   * If signature params are set to 0, then permit won't be called.\n   * @param signature struct containing the permit signature\n   * @return whether or not permit should be called\n   */\n  function _usePermit(PermitSignature memory signature) internal pure returns (bool) {\n    return\n      !(uint256(signature.deadline) == uint256(signature.v) && uint256(signature.deadline) == 0);\n  }\n\n  /**\n   * @dev Calculates the value denominated in USD\n   * @param reserve Address of the reserve\n   * @param amount Amount of the reserve\n   * @param decimals Decimals of the reserve\n   * @return whether or not permit should be called\n   */\n  function _calcUsdValue(\n    address reserve,\n    uint256 amount,\n    uint256 decimals\n  ) internal view returns (uint256) {\n    uint256 ethUsdPrice = _getPrice(USD_ADDRESS);\n    uint256 reservePrice = _getPrice(reserve);\n\n    return amount.mul(reservePrice).div(10 ** decimals).mul(ethUsdPrice).div(10 ** 18);\n  }\n\n  /**\n   * @dev Given an input asset amount, returns the maximum output amount of the other asset\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @param amountIn Amount of reserveIn\n   * @return Struct containing the following information:\n   *   uint256 Amount out of the reserveOut\n   *   uint256 The price of out amount denominated in the reserveIn currency (18 decimals)\n   *   uint256 In amount of reserveIn value denominated in USD (8 decimals)\n   *   uint256 Out amount of reserveOut value denominated in USD (8 decimals)\n   */\n  function _getAmountsOutData(\n    address reserveIn,\n    address reserveOut,\n    uint256 amountIn\n  ) internal view returns (AmountCalc memory) {\n    // Subtract flash loan fee\n    uint256 finalAmountIn = amountIn.sub(amountIn.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000));\n\n    if (reserveIn == reserveOut) {\n      uint256 reserveDecimals = _getDecimals(reserveIn);\n      address[] memory path = new address[](1);\n      path[0] = reserveIn;\n\n      return\n        AmountCalc(\n          finalAmountIn,\n          finalAmountIn.mul(10 ** 18).div(amountIn),\n          _calcUsdValue(reserveIn, amountIn, reserveDecimals),\n          _calcUsdValue(reserveIn, finalAmountIn, reserveDecimals),\n          path\n        );\n    }\n\n    address[] memory simplePath = new address[](2);\n    simplePath[0] = reserveIn;\n    simplePath[1] = reserveOut;\n\n    uint256[] memory amountsWithoutWeth;\n    uint256[] memory amountsWithWeth;\n\n    address[] memory pathWithWeth = new address[](3);\n    if (reserveIn != WETH_ADDRESS && reserveOut != WETH_ADDRESS) {\n      pathWithWeth[0] = reserveIn;\n      pathWithWeth[1] = WETH_ADDRESS;\n      pathWithWeth[2] = reserveOut;\n\n      try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, pathWithWeth) returns (\n        uint256[] memory resultsWithWeth\n      ) {\n        amountsWithWeth = resultsWithWeth;\n      } catch {\n        amountsWithWeth = new uint256[](3);\n      }\n    } else {\n      amountsWithWeth = new uint256[](3);\n    }\n\n    uint256 bestAmountOut;\n    try UNISWAP_ROUTER.getAmountsOut(finalAmountIn, simplePath) returns (\n      uint256[] memory resultAmounts\n    ) {\n      amountsWithoutWeth = resultAmounts;\n\n      bestAmountOut = (amountsWithWeth[2] > amountsWithoutWeth[1])\n        ? amountsWithWeth[2]\n        : amountsWithoutWeth[1];\n    } catch {\n      amountsWithoutWeth = new uint256[](2);\n      bestAmountOut = amountsWithWeth[2];\n    }\n\n    uint256 reserveInDecimals = _getDecimals(reserveIn);\n    uint256 reserveOutDecimals = _getDecimals(reserveOut);\n\n    uint256 outPerInPrice = finalAmountIn.mul(10 ** 18).mul(10 ** reserveOutDecimals).div(\n      bestAmountOut.mul(10 ** reserveInDecimals)\n    );\n\n    return\n      AmountCalc(\n        bestAmountOut,\n        outPerInPrice,\n        _calcUsdValue(reserveIn, amountIn, reserveInDecimals),\n        _calcUsdValue(reserveOut, bestAmountOut, reserveOutDecimals),\n        (bestAmountOut == 0) ? new address[](2) : (bestAmountOut == amountsWithoutWeth[1])\n          ? simplePath\n          : pathWithWeth\n      );\n  }\n\n  /**\n   * @dev Returns the minimum input asset amount required to buy the given output asset amount\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @param amountOut Amount of reserveOut\n   * @return Struct containing the following information:\n   *   uint256 Amount in of the reserveIn\n   *   uint256 The price of in amount denominated in the reserveOut currency (18 decimals)\n   *   uint256 In amount of reserveIn value denominated in USD (8 decimals)\n   *   uint256 Out amount of reserveOut value denominated in USD (8 decimals)\n   */\n  function _getAmountsInData(\n    address reserveIn,\n    address reserveOut,\n    uint256 amountOut\n  ) internal view returns (AmountCalc memory) {\n    if (reserveIn == reserveOut) {\n      // Add flash loan fee\n      uint256 amountIn = amountOut.add(amountOut.mul(FLASHLOAN_PREMIUM_TOTAL).div(10000));\n      uint256 reserveDecimals = _getDecimals(reserveIn);\n      address[] memory path = new address[](1);\n      path[0] = reserveIn;\n\n      return\n        AmountCalc(\n          amountIn,\n          amountOut.mul(10 ** 18).div(amountIn),\n          _calcUsdValue(reserveIn, amountIn, reserveDecimals),\n          _calcUsdValue(reserveIn, amountOut, reserveDecimals),\n          path\n        );\n    }\n\n    (uint256[] memory amounts, address[] memory path) = _getAmountsInAndPath(\n      reserveIn,\n      reserveOut,\n      amountOut\n    );\n\n    // Add flash loan fee\n    uint256 finalAmountIn = amounts[0].add(amounts[0].mul(FLASHLOAN_PREMIUM_TOTAL).div(10000));\n\n    uint256 reserveInDecimals = _getDecimals(reserveIn);\n    uint256 reserveOutDecimals = _getDecimals(reserveOut);\n\n    uint256 inPerOutPrice = amountOut.mul(10 ** 18).mul(10 ** reserveInDecimals).div(\n      finalAmountIn.mul(10 ** reserveOutDecimals)\n    );\n\n    return\n      AmountCalc(\n        finalAmountIn,\n        inPerOutPrice,\n        _calcUsdValue(reserveIn, finalAmountIn, reserveInDecimals),\n        _calcUsdValue(reserveOut, amountOut, reserveOutDecimals),\n        path\n      );\n  }\n\n  /**\n   * @dev Calculates the input asset amount required to buy the given output asset amount\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @param amountOut Amount of reserveOut\n   * @return uint256[] amounts Array containing the amountIn and amountOut for a swap\n   */\n  function _getAmountsInAndPath(\n    address reserveIn,\n    address reserveOut,\n    uint256 amountOut\n  ) internal view returns (uint256[] memory, address[] memory) {\n    address[] memory simplePath = new address[](2);\n    simplePath[0] = reserveIn;\n    simplePath[1] = reserveOut;\n\n    uint256[] memory amountsWithoutWeth;\n    uint256[] memory amountsWithWeth;\n    address[] memory pathWithWeth = new address[](3);\n\n    if (reserveIn != WETH_ADDRESS && reserveOut != WETH_ADDRESS) {\n      pathWithWeth[0] = reserveIn;\n      pathWithWeth[1] = WETH_ADDRESS;\n      pathWithWeth[2] = reserveOut;\n\n      try UNISWAP_ROUTER.getAmountsIn(amountOut, pathWithWeth) returns (\n        uint256[] memory resultsWithWeth\n      ) {\n        amountsWithWeth = resultsWithWeth;\n      } catch {\n        amountsWithWeth = new uint256[](3);\n      }\n    } else {\n      amountsWithWeth = new uint256[](3);\n    }\n\n    try UNISWAP_ROUTER.getAmountsIn(amountOut, simplePath) returns (\n      uint256[] memory resultAmounts\n    ) {\n      amountsWithoutWeth = resultAmounts;\n\n      return\n        (amountsWithWeth[0] < amountsWithoutWeth[0] && amountsWithWeth[0] != 0)\n          ? (amountsWithWeth, pathWithWeth)\n          : (amountsWithoutWeth, simplePath);\n    } catch {\n      return (amountsWithWeth, pathWithWeth);\n    }\n  }\n\n  /**\n   * @dev Calculates the input asset amount required to buy the given output asset amount\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @param amountOut Amount of reserveOut\n   * @return uint256[] amounts Array containing the amountIn and amountOut for a swap\n   */\n  function _getAmountsIn(\n    address reserveIn,\n    address reserveOut,\n    uint256 amountOut,\n    bool useEthPath\n  ) internal view returns (uint256[] memory) {\n    address[] memory path;\n\n    if (useEthPath) {\n      path = new address[](3);\n      path[0] = reserveIn;\n      path[1] = WETH_ADDRESS;\n      path[2] = reserveOut;\n    } else {\n      path = new address[](2);\n      path[0] = reserveIn;\n      path[1] = reserveOut;\n    }\n\n    return UNISWAP_ROUTER.getAmountsIn(amountOut, path);\n  }\n\n  /**\n   * @dev Emergency rescue for token stucked on this contract, as failsafe mechanism\n   * - Funds should never remain in this contract more time than during transactions\n   * - Only callable by the owner\n   **/\n  function rescueTokens(IERC20 token) external onlyOwner {\n    token.transfer(owner(), token.balanceOf(address(this)));\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/adapters/interfaces/IBaseUniswapAdapter.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport {IPriceOracleGetter} from '../../interfaces/IPriceOracleGetter.sol';\nimport {IUniswapV2Router02} from '../../interfaces/IUniswapV2Router02.sol';\n\ninterface IBaseUniswapAdapter {\n  event Swapped(address fromAsset, address toAsset, uint256 fromAmount, uint256 receivedAmount);\n\n  struct PermitSignature {\n    uint256 amount;\n    uint256 deadline;\n    uint8 v;\n    bytes32 r;\n    bytes32 s;\n  }\n\n  struct AmountCalc {\n    uint256 calculatedAmount;\n    uint256 relativePrice;\n    uint256 amountInUsd;\n    uint256 amountOutUsd;\n    address[] path;\n  }\n\n  function WETH_ADDRESS() external returns (address);\n\n  function MAX_SLIPPAGE_PERCENT() external returns (uint256);\n\n  function FLASHLOAN_PREMIUM_TOTAL() external returns (uint256);\n\n  function USD_ADDRESS() external returns (address);\n\n  function ORACLE() external returns (IPriceOracleGetter);\n\n  function UNISWAP_ROUTER() external returns (IUniswapV2Router02);\n\n  /**\n   * @dev Given an input asset amount, returns the maximum output amount of the other asset and the prices\n   * @param amountIn Amount of reserveIn\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @return uint256 Amount out of the reserveOut\n   * @return uint256 The price of out amount denominated in the reserveIn currency (18 decimals)\n   * @return uint256 In amount of reserveIn value denominated in USD (8 decimals)\n   * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals)\n   * @return address[] The exchange path\n   */\n  function getAmountsOut(\n    uint256 amountIn,\n    address reserveIn,\n    address reserveOut\n  ) external view returns (uint256, uint256, uint256, uint256, address[] memory);\n\n  /**\n   * @dev Returns the minimum input asset amount required to buy the given output asset amount and the prices\n   * @param amountOut Amount of reserveOut\n   * @param reserveIn Address of the asset to be swap from\n   * @param reserveOut Address of the asset to be swap to\n   * @return uint256 Amount in of the reserveIn\n   * @return uint256 The price of in amount denominated in the reserveOut currency (18 decimals)\n   * @return uint256 In amount of reserveIn value denominated in USD (8 decimals)\n   * @return uint256 Out amount of reserveOut value denominated in USD (8 decimals)\n   * @return address[] The exchange path\n   */\n  function getAmountsIn(\n    uint256 amountOut,\n    address reserveIn,\n    address reserveOut\n  ) external view returns (uint256, uint256, uint256, uint256, address[] memory);\n}\n"
      },
      "contracts/aave-protocol-v2/adapters/UniswapRepayAdapter.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport {BaseUniswapAdapter} from './BaseUniswapAdapter.sol';\nimport {ILendingPoolAddressesProvider} from '../interfaces/ILendingPoolAddressesProvider.sol';\nimport {IUniswapV2Router02} from '../interfaces/IUniswapV2Router02.sol';\nimport {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';\nimport {DataTypes} from '../protocol/libraries/types/DataTypes.sol';\n\n/**\n * @title UniswapRepayAdapter\n * @notice Uniswap V2 Adapter to perform a repay of a debt with collateral.\n * @author Aave\n **/\ncontract UniswapRepayAdapter is BaseUniswapAdapter {\n  struct RepayParams {\n    address collateralAsset;\n    uint256 collateralAmount;\n    uint256 rateMode;\n    PermitSignature permitSignature;\n    bool useEthPath;\n  }\n\n  constructor(\n    ILendingPoolAddressesProvider addressesProvider,\n    IUniswapV2Router02 uniswapRouter,\n    address wethAddress\n  ) public BaseUniswapAdapter(addressesProvider, uniswapRouter, wethAddress) {}\n\n  /**\n   * @dev Uses the received funds from the flash loan to repay a debt on the protocol on behalf of the user. Then pulls\n   * the collateral from the user and swaps it to the debt asset to repay the flash loan.\n   * The user should give this contract allowance to pull the ATokens in order to withdraw the underlying asset, swap it\n   * and repay the flash loan.\n   * Supports only one asset on the flash loan.\n   * @param assets Address of debt asset\n   * @param amounts Amount of the debt to be repaid\n   * @param premiums Fee of the flash loan\n   * @param initiator Address of the user\n   * @param params Additional variadic field to include extra params. Expected parameters:\n   *   address collateralAsset Address of the reserve to be swapped\n   *   uint256 collateralAmount Amount of reserve to be swapped\n   *   uint256 rateMode Rate modes of the debt to be repaid\n   *   uint256 permitAmount Amount for the permit signature\n   *   uint256 deadline Deadline for the permit signature\n   *   uint8 v V param for the permit signature\n   *   bytes32 r R param for the permit signature\n   *   bytes32 s S param for the permit signature\n   */\n  function executeOperation(\n    address[] calldata assets,\n    uint256[] calldata amounts,\n    uint256[] calldata premiums,\n    address initiator,\n    bytes calldata params\n  ) external override returns (bool) {\n    require(msg.sender == address(LENDING_POOL), 'CALLER_MUST_BE_LENDING_POOL');\n\n    RepayParams memory decodedParams = _decodeParams(params);\n\n    _swapAndRepay(\n      decodedParams.collateralAsset,\n      assets[0],\n      amounts[0],\n      decodedParams.collateralAmount,\n      decodedParams.rateMode,\n      initiator,\n      premiums[0],\n      decodedParams.permitSignature,\n      decodedParams.useEthPath\n    );\n\n    return true;\n  }\n\n  /**\n   * @dev Swaps the user collateral for the debt asset and then repay the debt on the protocol on behalf of the user\n   * without using flash loans. This method can be used when the temporary transfer of the collateral asset to this\n   * contract does not affect the user position.\n   * The user should give this contract allowance to pull the ATokens in order to withdraw the underlying asset\n   * @param collateralAsset Address of asset to be swapped\n   * @param debtAsset Address of debt asset\n   * @param collateralAmount Amount of the collateral to be swapped\n   * @param debtRepayAmount Amount of the debt to be repaid\n   * @param debtRateMode Rate mode of the debt to be repaid\n   * @param permitSignature struct containing the permit signature\n   * @param useEthPath struct containing the permit signature\n\n   */\n  function swapAndRepay(\n    address collateralAsset,\n    address debtAsset,\n    uint256 collateralAmount,\n    uint256 debtRepayAmount,\n    uint256 debtRateMode,\n    PermitSignature calldata permitSignature,\n    bool useEthPath\n  ) external {\n    DataTypes.ReserveData memory collateralReserveData = _getReserveData(collateralAsset);\n    DataTypes.ReserveData memory debtReserveData = _getReserveData(debtAsset);\n\n    address debtToken = DataTypes.InterestRateMode(debtRateMode) ==\n      DataTypes.InterestRateMode.STABLE\n      ? debtReserveData.stableDebtTokenAddress\n      : debtReserveData.variableDebtTokenAddress;\n\n    uint256 currentDebt = IERC20(debtToken).balanceOf(msg.sender);\n    uint256 amountToRepay = debtRepayAmount <= currentDebt ? debtRepayAmount : currentDebt;\n\n    if (collateralAsset != debtAsset) {\n      uint256 maxCollateralToSwap = collateralAmount;\n      if (amountToRepay < debtRepayAmount) {\n        maxCollateralToSwap = maxCollateralToSwap.mul(amountToRepay).div(debtRepayAmount);\n      }\n\n      // Get exact collateral needed for the swap to avoid leftovers\n      uint256[] memory amounts = _getAmountsIn(\n        collateralAsset,\n        debtAsset,\n        amountToRepay,\n        useEthPath\n      );\n      require(amounts[0] <= maxCollateralToSwap, 'slippage too high');\n\n      // Pull aTokens from user\n      _pullAToken(\n        collateralAsset,\n        collateralReserveData.aTokenAddress,\n        msg.sender,\n        amounts[0],\n        permitSignature\n      );\n\n      // Swap collateral for debt asset\n      _swapTokensForExactTokens(collateralAsset, debtAsset, amounts[0], amountToRepay, useEthPath);\n    } else {\n      // Pull aTokens from user\n      _pullAToken(\n        collateralAsset,\n        collateralReserveData.aTokenAddress,\n        msg.sender,\n        amountToRepay,\n        permitSignature\n      );\n    }\n\n    // Repay debt. Approves 0 first to comply with tokens that implement the anti frontrunning approval fix\n    IERC20(debtAsset).safeApprove(address(LENDING_POOL), 0);\n    IERC20(debtAsset).safeApprove(address(LENDING_POOL), amountToRepay);\n    LENDING_POOL.repay(debtAsset, amountToRepay, debtRateMode, msg.sender);\n  }\n\n  /**\n   * @dev Perform the repay of the debt, pulls the initiator collateral and swaps to repay the flash loan\n   *\n   * @param collateralAsset Address of token to be swapped\n   * @param debtAsset Address of debt token to be received from the swap\n   * @param amount Amount of the debt to be repaid\n   * @param collateralAmount Amount of the reserve to be swapped\n   * @param rateMode Rate mode of the debt to be repaid\n   * @param initiator Address of the user\n   * @param premium Fee of the flash loan\n   * @param permitSignature struct containing the permit signature\n   */\n  function _swapAndRepay(\n    address collateralAsset,\n    address debtAsset,\n    uint256 amount,\n    uint256 collateralAmount,\n    uint256 rateMode,\n    address initiator,\n    uint256 premium,\n    PermitSignature memory permitSignature,\n    bool useEthPath\n  ) internal {\n    DataTypes.ReserveData memory collateralReserveData = _getReserveData(collateralAsset);\n\n    // Repay debt. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.\n    IERC20(debtAsset).safeApprove(address(LENDING_POOL), 0);\n    IERC20(debtAsset).safeApprove(address(LENDING_POOL), amount);\n    uint256 repaidAmount = IERC20(debtAsset).balanceOf(address(this));\n    LENDING_POOL.repay(debtAsset, amount, rateMode, initiator);\n    repaidAmount = repaidAmount.sub(IERC20(debtAsset).balanceOf(address(this)));\n\n    if (collateralAsset != debtAsset) {\n      uint256 maxCollateralToSwap = collateralAmount;\n      if (repaidAmount < amount) {\n        maxCollateralToSwap = maxCollateralToSwap.mul(repaidAmount).div(amount);\n      }\n\n      uint256 neededForFlashLoanDebt = repaidAmount.add(premium);\n      uint256[] memory amounts = _getAmountsIn(\n        collateralAsset,\n        debtAsset,\n        neededForFlashLoanDebt,\n        useEthPath\n      );\n      require(amounts[0] <= maxCollateralToSwap, 'slippage too high');\n\n      // Pull aTokens from user\n      _pullAToken(\n        collateralAsset,\n        collateralReserveData.aTokenAddress,\n        initiator,\n        amounts[0],\n        permitSignature\n      );\n\n      // Swap collateral asset to the debt asset\n      _swapTokensForExactTokens(\n        collateralAsset,\n        debtAsset,\n        amounts[0],\n        neededForFlashLoanDebt,\n        useEthPath\n      );\n    } else {\n      // Pull aTokens from user\n      _pullAToken(\n        collateralAsset,\n        collateralReserveData.aTokenAddress,\n        initiator,\n        repaidAmount.add(premium),\n        permitSignature\n      );\n    }\n\n    // Repay flashloan. Approves for 0 first to comply with tokens that implement the anti frontrunning approval fix.\n    IERC20(debtAsset).safeApprove(address(LENDING_POOL), 0);\n    IERC20(debtAsset).safeApprove(address(LENDING_POOL), amount.add(premium));\n  }\n\n  /**\n   * @dev Decodes debt information encoded in the flash loan params\n   * @param params Additional variadic field to include extra params. Expected parameters:\n   *   address collateralAsset Address of the reserve to be swapped\n   *   uint256 collateralAmount Amount of reserve to be swapped\n   *   uint256 rateMode Rate modes of the debt to be repaid\n   *   uint256 permitAmount Amount for the permit signature\n   *   uint256 deadline Deadline for the permit signature\n   *   uint8 v V param for the permit signature\n   *   bytes32 r R param for the permit signature\n   *   bytes32 s S param for the permit signature\n   *   bool useEthPath use WETH path route\n   * @return RepayParams struct containing decoded params\n   */\n  function _decodeParams(bytes memory params) internal pure returns (RepayParams memory) {\n    (\n      address collateralAsset,\n      uint256 collateralAmount,\n      uint256 rateMode,\n      uint256 permitAmount,\n      uint256 deadline,\n      uint8 v,\n      bytes32 r,\n      bytes32 s,\n      bool useEthPath\n    ) = abi.decode(\n        params,\n        (address, uint256, uint256, uint256, uint256, uint8, bytes32, bytes32, bool)\n      );\n\n    return\n      RepayParams(\n        collateralAsset,\n        collateralAmount,\n        rateMode,\n        PermitSignature(permitAmount, deadline, v, r, s),\n        useEthPath\n      );\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/dependencies/openzeppelin/contracts/Address.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n  /**\n   * @dev Returns true if `account` is a contract.\n   *\n   * [IMPORTANT]\n   * ====\n   * It is unsafe to assume that an address for which this function returns\n   * false is an externally-owned account (EOA) and not a contract.\n   *\n   * Among others, `isContract` will return false for the following\n   * types of addresses:\n   *\n   *  - an externally-owned account\n   *  - a contract in construction\n   *  - an address where a contract will be created\n   *  - an address where a contract lived, but was destroyed\n   * ====\n   */\n  function isContract(address account) internal view returns (bool) {\n    // According to EIP-1052, 0x0 is the value returned for not-yet created accounts\n    // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned\n    // for accounts without code, i.e. `keccak256('')`\n    bytes32 codehash;\n    bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;\n    // solhint-disable-next-line no-inline-assembly\n    assembly {\n      codehash := extcodehash(account)\n    }\n    return (codehash != accountHash && codehash != 0x0);\n  }\n\n  /**\n   * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n   * `recipient`, forwarding all available gas and reverting on errors.\n   *\n   * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n   * of certain opcodes, possibly making contracts go over the 2300 gas limit\n   * imposed by `transfer`, making them unable to receive funds via\n   * `transfer`. {sendValue} removes this limitation.\n   *\n   * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n   *\n   * IMPORTANT: because control is transferred to `recipient`, care must be\n   * taken to not create reentrancy vulnerabilities. Consider using\n   * {ReentrancyGuard} or the\n   * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n   */\n  function sendValue(address payable recipient, uint256 amount) internal {\n    require(address(this).balance >= amount, 'Address: insufficient balance');\n\n    // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n    (bool success, ) = recipient.call{value: amount}('');\n    require(success, 'Address: unable to send value, recipient may have reverted');\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/dependencies/openzeppelin/contracts/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity 0.6.12;\n\n/*\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with GSN meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n  function _msgSender() internal view virtual returns (address payable) {\n    return msg.sender;\n  }\n\n  function _msgData() internal view virtual returns (bytes memory) {\n    this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691\n    return msg.data;\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/dependencies/openzeppelin/contracts/IERC20.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n  /**\n   * @dev Returns the amount of tokens in existence.\n   */\n  function totalSupply() external view returns (uint256);\n\n  /**\n   * @dev Returns the amount of tokens owned by `account`.\n   */\n  function balanceOf(address account) external view returns (uint256);\n\n  /**\n   * @dev Moves `amount` tokens from the caller's account to `recipient`.\n   *\n   * Returns a boolean value indicating whether the operation succeeded.\n   *\n   * Emits a {Transfer} event.\n   */\n  function transfer(address recipient, uint256 amount) external returns (bool);\n\n  /**\n   * @dev Returns the remaining number of tokens that `spender` will be\n   * allowed to spend on behalf of `owner` through {transferFrom}. This is\n   * zero by default.\n   *\n   * This value changes when {approve} or {transferFrom} are called.\n   */\n  function allowance(address owner, address spender) external view returns (uint256);\n\n  /**\n   * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n   *\n   * Returns a boolean value indicating whether the operation succeeded.\n   *\n   * IMPORTANT: Beware that changing an allowance with this method brings the risk\n   * that someone may use both the old and the new allowance by unfortunate\n   * transaction ordering. One possible solution to mitigate this race\n   * condition is to first reduce the spender's allowance to 0 and set the\n   * desired value afterwards:\n   * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n   *\n   * Emits an {Approval} event.\n   */\n  function approve(address spender, uint256 amount) external returns (bool);\n\n  /**\n   * @dev Moves `amount` tokens from `sender` to `recipient` using the\n   * allowance mechanism. `amount` is then deducted from the caller's\n   * allowance.\n   *\n   * Returns a boolean value indicating whether the operation succeeded.\n   *\n   * Emits a {Transfer} event.\n   */\n  function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);\n\n  /**\n   * @dev Emitted when `value` tokens are moved from one account (`from`) to\n   * another (`to`).\n   *\n   * Note that `value` may be zero.\n   */\n  event Transfer(address indexed from, address indexed to, uint256 value);\n\n  /**\n   * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n   * a call to {approve}. `value` is the new allowance.\n   */\n  event Approval(address indexed owner, address indexed spender, uint256 value);\n}\n"
      },
      "contracts/aave-protocol-v2/dependencies/openzeppelin/contracts/IERC20Detailed.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\nimport {IERC20} from './IERC20.sol';\n\ninterface IERC20Detailed is IERC20 {\n  function name() external view returns (string memory);\n\n  function symbol() external view returns (string memory);\n\n  function decimals() external view returns (uint8);\n}\n"
      },
      "contracts/aave-protocol-v2/dependencies/openzeppelin/contracts/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.6.0;\n\nimport './Context.sol';\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\ncontract Ownable is Context {\n  address private _owner;\n\n  event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n  /**\n   * @dev Initializes the contract setting the deployer as the initial owner.\n   */\n  constructor() internal {\n    address msgSender = _msgSender();\n    _owner = msgSender;\n    emit OwnershipTransferred(address(0), msgSender);\n  }\n\n  /**\n   * @dev Returns the address of the current owner.\n   */\n  function owner() public view returns (address) {\n    return _owner;\n  }\n\n  /**\n   * @dev Throws if called by any account other than the owner.\n   */\n  modifier onlyOwner() {\n    require(_owner == _msgSender(), 'Ownable: caller is not the owner');\n    _;\n  }\n\n  /**\n   * @dev Leaves the contract without owner. It will not be possible to call\n   * `onlyOwner` functions anymore. Can only be called by the current owner.\n   *\n   * NOTE: Renouncing ownership will leave the contract without an owner,\n   * thereby removing any functionality that is only available to the owner.\n   */\n  function renounceOwnership() public virtual onlyOwner {\n    emit OwnershipTransferred(_owner, address(0));\n    _owner = address(0);\n  }\n\n  /**\n   * @dev Transfers ownership of the contract to a new account (`newOwner`).\n   * Can only be called by the current owner.\n   */\n  function transferOwnership(address newOwner) public virtual onlyOwner {\n    require(newOwner != address(0), 'Ownable: new owner is the zero address');\n    emit OwnershipTransferred(_owner, newOwner);\n    _owner = newOwner;\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/dependencies/openzeppelin/contracts/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n\npragma solidity 0.6.12;\n\nimport {IERC20} from './IERC20.sol';\nimport {SafeMath} from './SafeMath.sol';\nimport {Address} from './Address.sol';\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n  using SafeMath for uint256;\n  using Address for address;\n\n  function safeTransfer(IERC20 token, address to, uint256 value) internal {\n    callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n  }\n\n  function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n    callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n  }\n\n  function safeApprove(IERC20 token, address spender, uint256 value) internal {\n    require(\n      (value == 0) || (token.allowance(address(this), spender) == 0),\n      'SafeERC20: approve from non-zero to non-zero allowance'\n    );\n    callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n  }\n\n  function callOptionalReturn(IERC20 token, bytes memory data) private {\n    require(address(token).isContract(), 'SafeERC20: call to non-contract');\n\n    // solhint-disable-next-line avoid-low-level-calls\n    (bool success, bytes memory returndata) = address(token).call(data);\n    require(success, 'SafeERC20: low-level call failed');\n\n    if (returndata.length > 0) {\n      // Return data is optional\n      // solhint-disable-next-line max-line-length\n      require(abi.decode(returndata, (bool)), 'SafeERC20: ERC20 operation did not succeed');\n    }\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/dependencies/openzeppelin/contracts/SafeMath.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations with added overflow\n * checks.\n *\n * Arithmetic operations in Solidity wrap on overflow. This can easily result\n * in bugs, because programmers usually assume that an overflow raises an\n * error, which is the standard behavior in high level programming languages.\n * `SafeMath` restores this intuition by reverting the transaction when an\n * operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n */\nlibrary SafeMath {\n  /**\n   * @dev Returns the addition of two unsigned integers, reverting on\n   * overflow.\n   *\n   * Counterpart to Solidity's `+` operator.\n   *\n   * Requirements:\n   * - Addition cannot overflow.\n   */\n  function add(uint256 a, uint256 b) internal pure returns (uint256) {\n    uint256 c = a + b;\n    require(c >= a, 'SafeMath: addition overflow');\n\n    return c;\n  }\n\n  /**\n   * @dev Returns the subtraction of two unsigned integers, reverting on\n   * overflow (when the result is negative).\n   *\n   * Counterpart to Solidity's `-` operator.\n   *\n   * Requirements:\n   * - Subtraction cannot overflow.\n   */\n  function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n    return sub(a, b, 'SafeMath: subtraction overflow');\n  }\n\n  /**\n   * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n   * overflow (when the result is negative).\n   *\n   * Counterpart to Solidity's `-` operator.\n   *\n   * Requirements:\n   * - Subtraction cannot overflow.\n   */\n  function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n    require(b <= a, errorMessage);\n    uint256 c = a - b;\n\n    return c;\n  }\n\n  /**\n   * @dev Returns the multiplication of two unsigned integers, reverting on\n   * overflow.\n   *\n   * Counterpart to Solidity's `*` operator.\n   *\n   * Requirements:\n   * - Multiplication cannot overflow.\n   */\n  function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n    // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n    // benefit is lost if 'b' is also tested.\n    // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n    if (a == 0) {\n      return 0;\n    }\n\n    uint256 c = a * b;\n    require(c / a == b, 'SafeMath: multiplication overflow');\n\n    return c;\n  }\n\n  /**\n   * @dev Returns the integer division of two unsigned integers. Reverts on\n   * division by zero. The result is rounded towards zero.\n   *\n   * Counterpart to Solidity's `/` operator. Note: this function uses a\n   * `revert` opcode (which leaves remaining gas untouched) while Solidity\n   * uses an invalid opcode to revert (consuming all remaining gas).\n   *\n   * Requirements:\n   * - The divisor cannot be zero.\n   */\n  function div(uint256 a, uint256 b) internal pure returns (uint256) {\n    return div(a, b, 'SafeMath: division by zero');\n  }\n\n  /**\n   * @dev Returns the integer division of two unsigned integers. Reverts with custom message on\n   * division by zero. The result is rounded towards zero.\n   *\n   * Counterpart to Solidity's `/` operator. Note: this function uses a\n   * `revert` opcode (which leaves remaining gas untouched) while Solidity\n   * uses an invalid opcode to revert (consuming all remaining gas).\n   *\n   * Requirements:\n   * - The divisor cannot be zero.\n   */\n  function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n    // Solidity only automatically asserts when dividing by 0\n    require(b > 0, errorMessage);\n    uint256 c = a / b;\n    // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n    return c;\n  }\n\n  /**\n   * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n   * Reverts when dividing by zero.\n   *\n   * Counterpart to Solidity's `%` operator. This function uses a `revert`\n   * opcode (which leaves remaining gas untouched) while Solidity uses an\n   * invalid opcode to revert (consuming all remaining gas).\n   *\n   * Requirements:\n   * - The divisor cannot be zero.\n   */\n  function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n    return mod(a, b, 'SafeMath: modulo by zero');\n  }\n\n  /**\n   * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n   * Reverts with custom message when dividing by zero.\n   *\n   * Counterpart to Solidity's `%` operator. This function uses a `revert`\n   * opcode (which leaves remaining gas untouched) while Solidity uses an\n   * invalid opcode to revert (consuming all remaining gas).\n   *\n   * Requirements:\n   * - The divisor cannot be zero.\n   */\n  function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {\n    require(b != 0, errorMessage);\n    return a % b;\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/flashloan/base/FlashLoanReceiverBase.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\nimport {SafeMath} from '../../dependencies/openzeppelin/contracts/SafeMath.sol';\nimport {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';\nimport {SafeERC20} from '../../dependencies/openzeppelin/contracts/SafeERC20.sol';\nimport {IFlashLoanReceiver} from '../interfaces/IFlashLoanReceiver.sol';\nimport {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';\nimport {ILendingPool} from '../../interfaces/ILendingPool.sol';\n\nabstract contract FlashLoanReceiverBase is IFlashLoanReceiver {\n  using SafeERC20 for IERC20;\n  using SafeMath for uint256;\n\n  ILendingPoolAddressesProvider public immutable override ADDRESSES_PROVIDER;\n  ILendingPool public immutable override LENDING_POOL;\n\n  constructor(ILendingPoolAddressesProvider provider) public {\n    ADDRESSES_PROVIDER = provider;\n    LENDING_POOL = ILendingPool(provider.getLendingPool());\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/flashloan/interfaces/IFlashLoanReceiver.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\nimport {ILendingPoolAddressesProvider} from '../../interfaces/ILendingPoolAddressesProvider.sol';\nimport {ILendingPool} from '../../interfaces/ILendingPool.sol';\n\n/**\n * @title IFlashLoanReceiver interface\n * @notice Interface for the Aave fee IFlashLoanReceiver.\n * @author Aave\n * @dev implement this interface to develop a flashloan-compatible flashLoanReceiver contract\n **/\ninterface IFlashLoanReceiver {\n  function executeOperation(\n    address[] calldata assets,\n    uint256[] calldata amounts,\n    uint256[] calldata premiums,\n    address initiator,\n    bytes calldata params\n  ) external returns (bool);\n\n  function ADDRESSES_PROVIDER() external view returns (ILendingPoolAddressesProvider);\n\n  function LENDING_POOL() external view returns (ILendingPool);\n}\n"
      },
      "contracts/aave-protocol-v2/interfaces/IERC20WithPermit.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\nimport {IERC20} from '../dependencies/openzeppelin/contracts/IERC20.sol';\n\ninterface IERC20WithPermit is IERC20 {\n  function permit(\n    address owner,\n    address spender,\n    uint256 value,\n    uint256 deadline,\n    uint8 v,\n    bytes32 r,\n    bytes32 s\n  ) external;\n}\n"
      },
      "contracts/aave-protocol-v2/interfaces/ILendingPool.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\npragma experimental ABIEncoderV2;\n\nimport {ILendingPoolAddressesProvider} from './ILendingPoolAddressesProvider.sol';\nimport {DataTypes} from '../protocol/libraries/types/DataTypes.sol';\n\ninterface ILendingPool {\n  /**\n   * @dev Emitted on deposit()\n   * @param reserve The address of the underlying asset of the reserve\n   * @param user The address initiating the deposit\n   * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens\n   * @param amount The amount deposited\n   * @param referral The referral code used\n   **/\n  event Deposit(\n    address indexed reserve,\n    address user,\n    address indexed onBehalfOf,\n    uint256 amount,\n    uint16 indexed referral\n  );\n\n  /**\n   * @dev Emitted on withdraw()\n   * @param reserve The address of the underlyng asset being withdrawn\n   * @param user The address initiating the withdrawal, owner of aTokens\n   * @param to Address that will receive the underlying\n   * @param amount The amount to be withdrawn\n   **/\n  event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);\n\n  /**\n   * @dev Emitted on borrow() and flashLoan() when debt needs to be opened\n   * @param reserve The address of the underlying asset being borrowed\n   * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just\n   * initiator of the transaction on flashLoan()\n   * @param onBehalfOf The address that will be getting the debt\n   * @param amount The amount borrowed out\n   * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable\n   * @param borrowRate The numeric rate at which the user has borrowed\n   * @param referral The referral code used\n   **/\n  event Borrow(\n    address indexed reserve,\n    address user,\n    address indexed onBehalfOf,\n    uint256 amount,\n    uint256 borrowRateMode,\n    uint256 borrowRate,\n    uint16 indexed referral\n  );\n\n  /**\n   * @dev Emitted on repay()\n   * @param reserve The address of the underlying asset of the reserve\n   * @param user The beneficiary of the repayment, getting his debt reduced\n   * @param repayer The address of the user initiating the repay(), providing the funds\n   * @param amount The amount repaid\n   **/\n  event Repay(\n    address indexed reserve,\n    address indexed user,\n    address indexed repayer,\n    uint256 amount\n  );\n\n  /**\n   * @dev Emitted on swapBorrowRateMode()\n   * @param reserve The address of the underlying asset of the reserve\n   * @param user The address of the user swapping his rate mode\n   * @param rateMode The rate mode that the user wants to swap to\n   **/\n  event Swap(address indexed reserve, address indexed user, uint256 rateMode);\n\n  /**\n   * @dev Emitted on setUserUseReserveAsCollateral()\n   * @param reserve The address of the underlying asset of the reserve\n   * @param user The address of the user enabling the usage as collateral\n   **/\n  event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);\n\n  /**\n   * @dev Emitted on setUserUseReserveAsCollateral()\n   * @param reserve The address of the underlying asset of the reserve\n   * @param user The address of the user enabling the usage as collateral\n   **/\n  event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);\n\n  /**\n   * @dev Emitted on rebalanceStableBorrowRate()\n   * @param reserve The address of the underlying asset of the reserve\n   * @param user The address of the user for which the rebalance has been executed\n   **/\n  event RebalanceStableBorrowRate(address indexed reserve, address indexed user);\n\n  /**\n   * @dev Emitted on flashLoan()\n   * @param target The address of the flash loan receiver contract\n   * @param initiator The address initiating the flash loan\n   * @param asset The address of the asset being flash borrowed\n   * @param amount The amount flash borrowed\n   * @param premium The fee flash borrowed\n   * @param referralCode The referral code used\n   **/\n  event FlashLoan(\n    address indexed target,\n    address indexed initiator,\n    address indexed asset,\n    uint256 amount,\n    uint256 premium,\n    uint16 referralCode\n  );\n\n  /**\n   * @dev Emitted when the pause is triggered.\n   */\n  event Paused();\n\n  /**\n   * @dev Emitted when the pause is lifted.\n   */\n  event Unpaused();\n\n  /**\n   * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via\n   * LendingPoolCollateral manager using a DELEGATECALL\n   * This allows to have the events in the generated ABI for LendingPool.\n   * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation\n   * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation\n   * @param user The address of the borrower getting liquidated\n   * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover\n   * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator\n   * @param liquidator The address of the liquidator\n   * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants\n   * to receive the underlying collateral asset directly\n   **/\n  event LiquidationCall(\n    address indexed collateralAsset,\n    address indexed debtAsset,\n    address indexed user,\n    uint256 debtToCover,\n    uint256 liquidatedCollateralAmount,\n    address liquidator,\n    bool receiveAToken\n  );\n\n  /**\n   * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared\n   * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal,\n   * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it\n   * gets added to the LendingPool ABI\n   * @param reserve The address of the underlying asset of the reserve\n   * @param liquidityRate The new liquidity rate\n   * @param stableBorrowRate The new stable borrow rate\n   * @param variableBorrowRate The new variable borrow rate\n   * @param liquidityIndex The new liquidity index\n   * @param variableBorrowIndex The new variable borrow index\n   **/\n  event ReserveDataUpdated(\n    address indexed reserve,\n    uint256 liquidityRate,\n    uint256 stableBorrowRate,\n    uint256 variableBorrowRate,\n    uint256 liquidityIndex,\n    uint256 variableBorrowIndex\n  );\n\n  /**\n   * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.\n   * - E.g. User deposits 100 USDC and gets in return 100 aUSDC\n   * @param asset The address of the underlying asset to deposit\n   * @param amount The amount to be deposited\n   * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user\n   *   wants to receive them on his own wallet, or a different address if the beneficiary of aTokens\n   *   is a different wallet\n   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.\n   *   0 if the action is executed directly by the user, without any middle-man\n   **/\n  function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external;\n\n  /**\n   * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned\n   * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC\n   * @param asset The address of the underlying asset to withdraw\n   * @param amount The underlying amount to be withdrawn\n   *   - Send the value type(uint256).max in order to withdraw the whole aToken balance\n   * @param to Address that will receive the underlying, same as msg.sender if the user\n   *   wants to receive it on his own wallet, or a different address if the beneficiary is a\n   *   different wallet\n   * @return The final amount withdrawn\n   **/\n  function withdraw(address asset, uint256 amount, address to) external returns (uint256);\n\n  /**\n   * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower\n   * already deposited enough collateral, or he was given enough allowance by a credit delegator on the\n   * corresponding debt token (StableDebtToken or VariableDebtToken)\n   * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet\n   *   and 100 stable/variable debt tokens, depending on the `interestRateMode`\n   * @param asset The address of the underlying asset to borrow\n   * @param amount The amount to be borrowed\n   * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable\n   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.\n   *   0 if the action is executed directly by the user, without any middle-man\n   * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself\n   * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator\n   * if he has been given credit delegation allowance\n   **/\n  function borrow(\n    address asset,\n    uint256 amount,\n    uint256 interestRateMode,\n    uint16 referralCode,\n    address onBehalfOf\n  ) external;\n\n  /**\n   * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned\n   * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address\n   * @param asset The address of the borrowed underlying asset previously borrowed\n   * @param amount The amount to repay\n   * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`\n   * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable\n   * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the\n   * user calling the function if he wants to reduce/remove his own debt, or the address of any other\n   * other borrower whose debt should be removed\n   * @return The final amount repaid\n   **/\n  function repay(\n    address asset,\n    uint256 amount,\n    uint256 rateMode,\n    address onBehalfOf\n  ) external returns (uint256);\n\n  /**\n   * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa\n   * @param asset The address of the underlying asset borrowed\n   * @param rateMode The rate mode that the user wants to swap to\n   **/\n  function swapBorrowRateMode(address asset, uint256 rateMode) external;\n\n  /**\n   * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve.\n   * - Users can be rebalanced if the following conditions are satisfied:\n   *     1. Usage ratio is above 95%\n   *     2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been\n   *        borrowed at a stable rate and depositors are not earning enough\n   * @param asset The address of the underlying asset borrowed\n   * @param user The address of the user to be rebalanced\n   **/\n  function rebalanceStableBorrowRate(address asset, address user) external;\n\n  /**\n   * @dev Allows depositors to enable/disable a specific deposited asset as collateral\n   * @param asset The address of the underlying asset deposited\n   * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise\n   **/\n  function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external;\n\n  /**\n   * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1\n   * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives\n   *   a proportionally amount of the `collateralAsset` plus a bonus to cover market risk\n   * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation\n   * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation\n   * @param user The address of the borrower getting liquidated\n   * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover\n   * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants\n   * to receive the underlying collateral asset directly\n   **/\n  function liquidationCall(\n    address collateralAsset,\n    address debtAsset,\n    address user,\n    uint256 debtToCover,\n    bool receiveAToken\n  ) external;\n\n  /**\n   * @dev Allows smartcontracts to access the liquidity of the pool within one transaction,\n   * as long as the amount taken plus a fee is returned.\n   * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration.\n   * For further details please visit https://developers.aave.com\n   * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface\n   * @param assets The addresses of the assets being flash-borrowed\n   * @param amounts The amounts amounts being flash-borrowed\n   * @param modes Types of the debt to open if the flash loan is not returned:\n   *   0 -> Don't open any debt, just revert if funds can't be transferred from the receiver\n   *   1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address\n   *   2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address\n   * @param onBehalfOf The address  that will receive the debt in the case of using on `modes` 1 or 2\n   * @param params Variadic packed params to pass to the receiver as extra information\n   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.\n   *   0 if the action is executed directly by the user, without any middle-man\n   **/\n  function flashLoan(\n    address receiverAddress,\n    address[] calldata assets,\n    uint256[] calldata amounts,\n    uint256[] calldata modes,\n    address onBehalfOf,\n    bytes calldata params,\n    uint16 referralCode\n  ) external;\n\n  /**\n   * @dev Returns the user account data across all the reserves\n   * @param user The address of the user\n   * @return totalCollateralETH the total collateral in ETH of the user\n   * @return totalDebtETH the total debt in ETH of the user\n   * @return availableBorrowsETH the borrowing power left of the user\n   * @return currentLiquidationThreshold the liquidation threshold of the user\n   * @return ltv the loan to value of the user\n   * @return healthFactor the current health factor of the user\n   **/\n  function getUserAccountData(\n    address user\n  )\n    external\n    view\n    returns (\n      uint256 totalCollateralETH,\n      uint256 totalDebtETH,\n      uint256 availableBorrowsETH,\n      uint256 currentLiquidationThreshold,\n      uint256 ltv,\n      uint256 healthFactor\n    );\n\n  function initReserve(\n    address reserve,\n    address aTokenAddress,\n    address stableDebtAddress,\n    address variableDebtAddress,\n    address interestRateStrategyAddress\n  ) external;\n\n  function setReserveInterestRateStrategyAddress(\n    address reserve,\n    address rateStrategyAddress\n  ) external;\n\n  function setConfiguration(address reserve, uint256 configuration) external;\n\n  /**\n   * @dev Returns the configuration of the reserve\n   * @param asset The address of the underlying asset of the reserve\n   * @return The configuration of the reserve\n   **/\n  function getConfiguration(\n    address asset\n  ) external view returns (DataTypes.ReserveConfigurationMap memory);\n\n  /**\n   * @dev Returns the configuration of the user across all the reserves\n   * @param user The user address\n   * @return The configuration of the user\n   **/\n  function getUserConfiguration(\n    address user\n  ) external view returns (DataTypes.UserConfigurationMap memory);\n\n  /**\n   * @dev Returns the normalized income normalized income of the reserve\n   * @param asset The address of the underlying asset of the reserve\n   * @return The reserve's normalized income\n   */\n  function getReserveNormalizedIncome(address asset) external view returns (uint256);\n\n  /**\n   * @dev Returns the normalized variable debt per unit of asset\n   * @param asset The address of the underlying asset of the reserve\n   * @return The reserve normalized variable debt\n   */\n  function getReserveNormalizedVariableDebt(address asset) external view returns (uint256);\n\n  /**\n   * @dev Returns the state and configuration of the reserve\n   * @param asset The address of the underlying asset of the reserve\n   * @return The state of the reserve\n   **/\n  function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);\n\n  function finalizeTransfer(\n    address asset,\n    address from,\n    address to,\n    uint256 amount,\n    uint256 balanceFromAfter,\n    uint256 balanceToBefore\n  ) external;\n\n  function getReservesList() external view returns (address[] memory);\n\n  function getAddressesProvider() external view returns (ILendingPoolAddressesProvider);\n\n  function setPause(bool val) external;\n\n  function paused() external view returns (bool);\n}\n"
      },
      "contracts/aave-protocol-v2/interfaces/ILendingPoolAddressesProvider.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\n/**\n * @title LendingPoolAddressesProvider contract\n * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles\n * - Acting also as factory of proxies and admin of those, so with right to change its implementations\n * - Owned by the Aave Governance\n * @author Aave\n **/\ninterface ILendingPoolAddressesProvider {\n  event MarketIdSet(string newMarketId);\n  event LendingPoolUpdated(address indexed newAddress);\n  event ConfigurationAdminUpdated(address indexed newAddress);\n  event EmergencyAdminUpdated(address indexed newAddress);\n  event LendingPoolConfiguratorUpdated(address indexed newAddress);\n  event LendingPoolCollateralManagerUpdated(address indexed newAddress);\n  event PriceOracleUpdated(address indexed newAddress);\n  event LendingRateOracleUpdated(address indexed newAddress);\n  event ProxyCreated(bytes32 id, address indexed newAddress);\n  event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy);\n\n  function getMarketId() external view returns (string memory);\n\n  function setMarketId(string calldata marketId) external;\n\n  function setAddress(bytes32 id, address newAddress) external;\n\n  function setAddressAsProxy(bytes32 id, address impl) external;\n\n  function getAddress(bytes32 id) external view returns (address);\n\n  function getLendingPool() external view returns (address);\n\n  function setLendingPoolImpl(address pool) external;\n\n  function getLendingPoolConfigurator() external view returns (address);\n\n  function setLendingPoolConfiguratorImpl(address configurator) external;\n\n  function getLendingPoolCollateralManager() external view returns (address);\n\n  function setLendingPoolCollateralManager(address manager) external;\n\n  function getPoolAdmin() external view returns (address);\n\n  function setPoolAdmin(address admin) external;\n\n  function getEmergencyAdmin() external view returns (address);\n\n  function setEmergencyAdmin(address admin) external;\n\n  function getPriceOracle() external view returns (address);\n\n  function setPriceOracle(address priceOracle) external;\n\n  function getLendingRateOracle() external view returns (address);\n\n  function setLendingRateOracle(address lendingRateOracle) external;\n}\n"
      },
      "contracts/aave-protocol-v2/interfaces/IPriceOracleGetter.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\n/**\n * @title IPriceOracleGetter interface\n * @notice Interface for the Aave price oracle.\n **/\n\ninterface IPriceOracleGetter {\n  /**\n   * @dev returns the asset price in ETH\n   * @param asset the address of the asset\n   * @return the ETH price of the asset\n   **/\n  function getAssetPrice(address asset) external view returns (uint256);\n}\n"
      },
      "contracts/aave-protocol-v2/interfaces/IUniswapV2Router02.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\ninterface IUniswapV2Router02 {\n  function swapExactTokensForTokens(\n    uint256 amountIn,\n    uint256 amountOutMin,\n    address[] calldata path,\n    address to,\n    uint256 deadline\n  ) external returns (uint256[] memory amounts);\n\n  function swapTokensForExactTokens(\n    uint256 amountOut,\n    uint256 amountInMax,\n    address[] calldata path,\n    address to,\n    uint256 deadline\n  ) external returns (uint256[] memory amounts);\n\n  function getAmountsOut(\n    uint256 amountIn,\n    address[] calldata path\n  ) external view returns (uint256[] memory amounts);\n\n  function getAmountsIn(\n    uint256 amountOut,\n    address[] calldata path\n  ) external view returns (uint256[] memory amounts);\n}\n"
      },
      "contracts/aave-protocol-v2/protocol/libraries/helpers/Errors.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\n/**\n * @title Errors library\n * @author Aave\n * @notice Defines the error messages emitted by the different contracts of the Aave protocol\n * @dev Error messages prefix glossary:\n *  - VL = ValidationLogic\n *  - MATH = Math libraries\n *  - CT = Common errors between tokens (AToken, VariableDebtToken and StableDebtToken)\n *  - AT = AToken\n *  - SDT = StableDebtToken\n *  - VDT = VariableDebtToken\n *  - LP = LendingPool\n *  - LPAPR = LendingPoolAddressesProviderRegistry\n *  - LPC = LendingPoolConfiguration\n *  - RL = ReserveLogic\n *  - LPCM = LendingPoolCollateralManager\n *  - P = Pausable\n */\nlibrary Errors {\n  //common errors\n  string public constant CALLER_NOT_POOL_ADMIN = '33'; // 'The caller must be the pool admin'\n  string public constant BORROW_ALLOWANCE_NOT_ENOUGH = '59'; // User borrows on behalf, but allowance are too small\n\n  //contract specific errors\n  string public constant VL_INVALID_AMOUNT = '1'; // 'Amount must be greater than 0'\n  string public constant VL_NO_ACTIVE_RESERVE = '2'; // 'Action requires an active reserve'\n  string public constant VL_RESERVE_FROZEN = '3'; // 'Action cannot be performed because the reserve is frozen'\n  string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = '4'; // 'The current liquidity is not enough'\n  string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = '5'; // 'User cannot withdraw more than the available balance'\n  string public constant VL_TRANSFER_NOT_ALLOWED = '6'; // 'Transfer cannot be allowed.'\n  string public constant VL_BORROWING_NOT_ENABLED = '7'; // 'Borrowing is not enabled'\n  string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = '8'; // 'Invalid interest rate mode selected'\n  string public constant VL_COLLATERAL_BALANCE_IS_0 = '9'; // 'The collateral balance is 0'\n  string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = '10'; // 'Health factor is lesser than the liquidation threshold'\n  string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = '11'; // 'There is not enough collateral to cover a new borrow'\n  string public constant VL_STABLE_BORROWING_NOT_ENABLED = '12'; // stable borrowing not enabled\n  string public constant VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY = '13'; // collateral is (mostly) the same currency that is being borrowed\n  string public constant VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = '14'; // 'The requested amount is greater than the max loan size in stable rate mode\n  string public constant VL_NO_DEBT_OF_SELECTED_TYPE = '15'; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'\n  string public constant VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = '16'; // 'To repay on behalf of an user an explicit amount to repay is needed'\n  string public constant VL_NO_STABLE_RATE_LOAN_IN_RESERVE = '17'; // 'User does not have a stable rate loan in progress on this reserve'\n  string public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = '18'; // 'User does not have a variable rate loan in progress on this reserve'\n  string public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = '19'; // 'The underlying balance needs to be greater than 0'\n  string public constant VL_DEPOSIT_ALREADY_IN_USE = '20'; // 'User deposit is already being used as collateral'\n  string public constant LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = '21'; // 'User does not have any stable rate loan for this reserve'\n  string public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = '22'; // 'Interest rate rebalance conditions were not met'\n  string public constant LP_LIQUIDATION_CALL_FAILED = '23'; // 'Liquidation call failed'\n  string public constant LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = '24'; // 'There is not enough liquidity available to borrow'\n  string public constant LP_REQUESTED_AMOUNT_TOO_SMALL = '25'; // 'The requested amount is too small for a FlashLoan.'\n  string public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = '26'; // 'The actual balance of the protocol is inconsistent'\n  string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = '27'; // 'The caller of the function is not the lending pool configurator'\n  string public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = '28';\n  string public constant CT_CALLER_MUST_BE_LENDING_POOL = '29'; // 'The caller of this function must be a lending pool'\n  string public constant CT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = '30'; // 'User cannot give allowance to himself'\n  string public constant CT_TRANSFER_AMOUNT_NOT_GT_0 = '31'; // 'Transferred amount needs to be greater than zero'\n  string public constant RL_RESERVE_ALREADY_INITIALIZED = '32'; // 'Reserve has already been initialized'\n  string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = '34'; // 'The liquidity of the reserve needs to be 0'\n  string public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = '35'; // 'The liquidity of the reserve needs to be 0'\n  string public constant LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = '36'; // 'The liquidity of the reserve needs to be 0'\n  string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = '37'; // 'The liquidity of the reserve needs to be 0'\n  string public constant LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '38'; // 'The liquidity of the reserve needs to be 0'\n  string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = '39'; // 'The liquidity of the reserve needs to be 0'\n  string public constant LPC_INVALID_ADDRESSES_PROVIDER_ID = '40'; // 'The liquidity of the reserve needs to be 0'\n  string public constant LPC_INVALID_CONFIGURATION = '75'; // 'Invalid risk parameters for the reserve'\n  string public constant LPC_CALLER_NOT_EMERGENCY_ADMIN = '76'; // 'The caller must be the emergency admin'\n  string public constant LPAPR_PROVIDER_NOT_REGISTERED = '41'; // 'Provider is not registered'\n  string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = '42'; // 'Health factor is not below the threshold'\n  string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = '43'; // 'The collateral chosen cannot be liquidated'\n  string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = '44'; // 'User did not borrow the specified currency'\n  string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = '45'; // \"There isn't enough liquidity available to liquidate\"\n  string public constant LPCM_NO_ERRORS = '46'; // 'No errors'\n  string public constant LP_INVALID_FLASHLOAN_MODE = '47'; //Invalid flashloan mode selected\n  string public constant MATH_MULTIPLICATION_OVERFLOW = '48';\n  string public constant MATH_ADDITION_OVERFLOW = '49';\n  string public constant MATH_DIVISION_BY_ZERO = '50';\n  string public constant RL_LIQUIDITY_INDEX_OVERFLOW = '51'; //  Liquidity index overflows uint128\n  string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = '52'; //  Variable borrow index overflows uint128\n  string public constant RL_LIQUIDITY_RATE_OVERFLOW = '53'; //  Liquidity rate overflows uint128\n  string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = '54'; //  Variable borrow rate overflows uint128\n  string public constant RL_STABLE_BORROW_RATE_OVERFLOW = '55'; //  Stable borrow rate overflows uint128\n  string public constant CT_INVALID_MINT_AMOUNT = '56'; //invalid amount to mint\n  string public constant LP_FAILED_REPAY_WITH_COLLATERAL = '57';\n  string public constant CT_INVALID_BURN_AMOUNT = '58'; //invalid amount to burn\n  string public constant LP_FAILED_COLLATERAL_SWAP = '60';\n  string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = '61';\n  string public constant LP_REENTRANCY_NOT_ALLOWED = '62';\n  string public constant LP_CALLER_MUST_BE_AN_ATOKEN = '63';\n  string public constant LP_IS_PAUSED = '64'; // 'Pool is paused'\n  string public constant LP_NO_MORE_RESERVES_ALLOWED = '65';\n  string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = '66';\n  string public constant RC_INVALID_LTV = '67';\n  string public constant RC_INVALID_LIQ_THRESHOLD = '68';\n  string public constant RC_INVALID_LIQ_BONUS = '69';\n  string public constant RC_INVALID_DECIMALS = '70';\n  string public constant RC_INVALID_RESERVE_FACTOR = '71';\n  string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = '72';\n  string public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = '73';\n  string public constant LP_INCONSISTENT_PARAMS_LENGTH = '74';\n  string public constant UL_INVALID_INDEX = '77';\n  string public constant LP_NOT_CONTRACT = '78';\n  string public constant SDT_STABLE_DEBT_OVERFLOW = '79';\n  string public constant SDT_BURN_EXCEEDS_BALANCE = '80';\n\n  enum CollateralManagerErrors {\n    NO_ERROR,\n    NO_COLLATERAL_AVAILABLE,\n    COLLATERAL_CANNOT_BE_LIQUIDATED,\n    CURRRENCY_NOT_BORROWED,\n    HEALTH_FACTOR_ABOVE_THRESHOLD,\n    NOT_ENOUGH_LIQUIDITY,\n    NO_ACTIVE_RESERVE,\n    HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,\n    INVALID_EQUAL_ASSETS_TO_SWAP,\n    FROZEN_RESERVE\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/protocol/libraries/math/PercentageMath.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\nimport {Errors} from '../helpers/Errors.sol';\n\n/**\n * @title PercentageMath library\n * @author Aave\n * @notice Provides functions to perform percentage calculations\n * @dev Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR\n * @dev Operations are rounded half up\n **/\n\nlibrary PercentageMath {\n  uint256 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals\n  uint256 constant HALF_PERCENT = PERCENTAGE_FACTOR / 2;\n\n  /**\n   * @dev Executes a percentage multiplication\n   * @param value The value of which the percentage needs to be calculated\n   * @param percentage The percentage of the value to be calculated\n   * @return The percentage of value\n   **/\n  function percentMul(uint256 value, uint256 percentage) internal pure returns (uint256) {\n    if (value == 0 || percentage == 0) {\n      return 0;\n    }\n\n    require(\n      value <= (type(uint256).max - HALF_PERCENT) / percentage,\n      Errors.MATH_MULTIPLICATION_OVERFLOW\n    );\n\n    return (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR;\n  }\n\n  /**\n   * @dev Executes a percentage division\n   * @param value The value of which the percentage needs to be calculated\n   * @param percentage The percentage of the value to be calculated\n   * @return The value divided the percentage\n   **/\n  function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {\n    require(percentage != 0, Errors.MATH_DIVISION_BY_ZERO);\n    uint256 halfPercentage = percentage / 2;\n\n    require(\n      value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR,\n      Errors.MATH_MULTIPLICATION_OVERFLOW\n    );\n\n    return (value * PERCENTAGE_FACTOR + halfPercentage) / percentage;\n  }\n}\n"
      },
      "contracts/aave-protocol-v2/protocol/libraries/types/DataTypes.sol": {
        "content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity 0.6.12;\n\nlibrary DataTypes {\n  // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties.\n  struct ReserveData {\n    //stores the reserve configuration\n    ReserveConfigurationMap configuration;\n    //the liquidity index. Expressed in ray\n    uint128 liquidityIndex;\n    //variable borrow index. Expressed in ray\n    uint128 variableBorrowIndex;\n    //the current supply rate. Expressed in ray\n    uint128 currentLiquidityRate;\n    //the current variable borrow rate. Expressed in ray\n    uint128 currentVariableBorrowRate;\n    //the current stable borrow rate. Expressed in ray\n    uint128 currentStableBorrowRate;\n    uint40 lastUpdateTimestamp;\n    //tokens addresses\n    address aTokenAddress;\n    address stableDebtTokenAddress;\n    address variableDebtTokenAddress;\n    //address of the interest rate strategy\n    address interestRateStrategyAddress;\n    //the id of the reserve. Represents the position in the list of the active reserves\n    uint8 id;\n  }\n\n  struct ReserveConfigurationMap {\n    //bit 0-15: LTV\n    //bit 16-31: Liq. threshold\n    //bit 32-47: Liq. bonus\n    //bit 48-55: Decimals\n    //bit 56: Reserve is active\n    //bit 57: reserve is frozen\n    //bit 58: borrowing is enabled\n    //bit 59: stable rate borrowing enabled\n    //bit 60-63: reserved\n    //bit 64-79: reserve factor\n    uint256 data;\n  }\n\n  struct UserConfigurationMap {\n    uint256 data;\n  }\n\n  enum InterestRateMode {\n    NONE,\n    STABLE,\n    VARIABLE\n  }\n}\n"
      }
    },
    "settings": {
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "evmVersion": "istanbul",
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}