ETH Price: $3,123.05 (+1.58%)
Gas: 4 Gwei

Contract

0xeA716Ed94964Ed0126Fb2fA3b546eD7F209cC2b8
 
Transaction Hash
Method
Block
From
To
Value
Issue Exact Set ...194199552024-03-12 15:40:2353 days ago1710258023IN
0xeA716Ed9...F209cC2b8
20.2993404 ETH0.0942987679.57667764
Redeem Exact Set...193766472024-03-06 14:12:1159 days ago1709734331IN
0xeA716Ed9...F209cC2b8
0 ETH0.13777399119.48647072
Issue Exact Set ...193348862024-02-29 18:14:3565 days ago1709230475IN
0xeA716Ed9...F209cC2b8
4.9981214 ETH0.08146678.45641302
Issue Exact Set ...193318962024-02-29 8:11:3565 days ago1709194295IN
0xeA716Ed9...F209cC2b8
29.99702847 ETH0.0647694751.75128692
Redeem Exact Set...193255602024-02-28 10:53:3566 days ago1709117615IN
0xeA716Ed9...F209cC2b8
0 ETH0.048482547.48210323
Redeem Exact Set...193255502024-02-28 10:51:3566 days ago1709117495IN
0xeA716Ed9...F209cC2b8
0 ETH0.0600066155.88483016
Redeem Exact Set...193255432024-02-28 10:50:1166 days ago1709117411IN
0xeA716Ed9...F209cC2b8
0 ETH0.0563187352.45055437
Issue Exact Set ...193220012024-02-27 22:55:3566 days ago1709074535IN
0xeA716Ed9...F209cC2b8
44.7999876 ETH0.0495091548.05216947
Issue Exact Set ...193124562024-02-26 14:52:3568 days ago1708959155IN
0xeA716Ed9...F209cC2b8
50.09662597 ETH0.0745863970.25913108
Redeem Exact Set...192608212024-02-19 9:13:5975 days ago1708334039IN
0xeA716Ed9...F209cC2b8
0 ETH0.0430624236.44003064
Redeem Exact Set...192592382024-02-19 3:52:4775 days ago1708314767IN
0xeA716Ed9...F209cC2b8
0 ETH0.0288035725.35019592
Issue Exact Set ...192587982024-02-19 2:22:5975 days ago1708309379IN
0xeA716Ed9...F209cC2b8
86.48938555 ETH0.0246683424.07813908
Redeem Exact Set...192493112024-02-17 18:18:5977 days ago1708193939IN
0xeA716Ed9...F209cC2b8
0 ETH0.0235140119.76344925
Issue Exact Set ...192484982024-02-17 15:34:2377 days ago1708184063IN
0xeA716Ed9...F209cC2b8
35.99563022 ETH0.0259967825.25899798
Redeem Exact Set...192299452024-02-15 1:05:2379 days ago1707959123IN
0xeA716Ed9...F209cC2b8
0 ETH0.0276246325.60867106
Issue Exact Set ...192241142024-02-14 5:25:4780 days ago1707888347IN
0xeA716Ed9...F209cC2b8
0 ETH0.0160883814.38693813
Redeem Exact Set...192159402024-02-13 1:53:3581 days ago1707789215IN
0xeA716Ed9...F209cC2b8
0 ETH0.0475517644.09367646
Redeem Exact Set...192108642024-02-12 8:50:2382 days ago1707727823IN
0xeA716Ed9...F209cC2b8
0 ETH0.0232067821.37180068
Issue Exact Set ...192027992024-02-11 5:38:3583 days ago1707629915IN
0xeA716Ed9...F209cC2b8
104.99536408 ETH0.0293682525.96564058
Issue Exact Set ...192027662024-02-11 5:31:5983 days ago1707629519IN
0xeA716Ed9...F209cC2b8
99.99982541 ETH0.0333903426.05295188
Issue Exact Set ...191573852024-02-04 20:41:4789 days ago1707079307IN
0xeA716Ed9...F209cC2b8
3.99964392 ETH0.0205582517.10418323
Issue Exact Set ...191571802024-02-04 19:59:5989 days ago1707076799IN
0xeA716Ed9...F209cC2b8
2.99978038 ETH0.0153265115.02287069
Issue Exact Set ...191571712024-02-04 19:58:1189 days ago1707076691IN
0xeA716Ed9...F209cC2b8
2.99978038 ETH0.0146816514.3907922
Redeem Exact Set...191405412024-02-02 11:54:1192 days ago1706874851IN
0xeA716Ed9...F209cC2b8
0 ETH0.0180299816.86984372
Redeem Exact Set...191405352024-02-02 11:52:5992 days ago1706874779IN
0xeA716Ed9...F209cC2b8
0 ETH0.020908219.54486914
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To Value
194199552024-03-12 15:40:2353 days ago1710258023
0xeA716Ed9...F209cC2b8
0.08769654 ETH
194199552024-03-12 15:40:2353 days ago1710258023
0xeA716Ed9...F209cC2b8
0.08769654 ETH
194199552024-03-12 15:40:2353 days ago1710258023
0xeA716Ed9...F209cC2b8
20.2993404 ETH
193766472024-03-06 14:12:1159 days ago1709734331
0xeA716Ed9...F209cC2b8
109.1225303 ETH
193766472024-03-06 14:12:1159 days ago1709734331
0xeA716Ed9...F209cC2b8
109.1225303 ETH
193348862024-02-29 18:14:3565 days ago1709230475
0xeA716Ed9...F209cC2b8
0.00316945 ETH
193348862024-02-29 18:14:3565 days ago1709230475
0xeA716Ed9...F209cC2b8
0.00316945 ETH
193348862024-02-29 18:14:3565 days ago1709230475
0xeA716Ed9...F209cC2b8
4.9981214 ETH
193348862024-02-29 18:14:3565 days ago1709230475
0xeA716Ed9...F209cC2b8
8.67805274 ETH
193348862024-02-29 18:14:3565 days ago1709230475
0xeA716Ed9...F209cC2b8
8.67805274 ETH
193318962024-02-29 8:11:3565 days ago1709194295
0xeA716Ed9...F209cC2b8
0.12140709 ETH
193318962024-02-29 8:11:3565 days ago1709194295
0xeA716Ed9...F209cC2b8
0.12140709 ETH
193318962024-02-29 8:11:3565 days ago1709194295
0xeA716Ed9...F209cC2b8
29.99702847 ETH
193255602024-02-28 10:53:3566 days ago1709117615
0xeA716Ed9...F209cC2b8
1.25734356 ETH
193255602024-02-28 10:53:3566 days ago1709117615
0xeA716Ed9...F209cC2b8
1.25734356 ETH
193255602024-02-28 10:53:3566 days ago1709117615
0xeA716Ed9...F209cC2b8
2.15743581 ETH
193255602024-02-28 10:53:3566 days ago1709117615
0xeA716Ed9...F209cC2b8
2.15743581 ETH
193255502024-02-28 10:51:3566 days ago1709117495
0xeA716Ed9...F209cC2b8
19.01362029 ETH
193255502024-02-28 10:51:3566 days ago1709117495
0xeA716Ed9...F209cC2b8
19.01362029 ETH
193255502024-02-28 10:51:3566 days ago1709117495
0xeA716Ed9...F209cC2b8
32.63121662 ETH
193255502024-02-28 10:51:3566 days ago1709117495
0xeA716Ed9...F209cC2b8
32.63121662 ETH
193255432024-02-28 10:50:1166 days ago1709117411
0xeA716Ed9...F209cC2b8
19.0075098 ETH
193255432024-02-28 10:50:1166 days ago1709117411
0xeA716Ed9...F209cC2b8
19.0075098 ETH
193255432024-02-28 10:50:1166 days ago1709117411
0xeA716Ed9...F209cC2b8
32.63121655 ETH
193255432024-02-28 10:50:1166 days ago1709117411
0xeA716Ed9...F209cC2b8
32.63121655 ETH
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
FlashMintLeveragedForCompound

Compiler Version
v0.6.10+commit.00c0fcaf

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion
File 1 of 42 : FlashMintLeveragedForCompound.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Math } from "@openzeppelin/contracts/math/Math.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import { IAToken } from "../interfaces/IAToken.sol";
import { ICErc20 } from "../interfaces/ICErc20.sol";
import { ICompoundLeverageModule } from "../interfaces/ICompoundLeverageModule.sol";

import { ICErc20Delegator } from "../interfaces/ICErc20Delegator.sol";
import { ICEther } from "../interfaces/ICEther.sol";

import { CErc20Storage } from "../interfaces/CErc20Storage.sol";
import { CompoundLeverageModuleStorage } from "../interfaces/CompoundLeverageModuleStorage.sol";

import { IDebtIssuanceModule } from "../interfaces/IDebtIssuanceModule.sol";
import { IController } from "../interfaces/IController.sol";
import { ISetToken } from "../interfaces/ISetToken.sol";
import { IWETH } from "../interfaces/IWETH.sol";
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";
import { UniSushiV2Library } from "../../external/contracts/UniSushiV2Library.sol";
import { FlashLoanReceiverBaseV2 } from "../../external/contracts/aaveV2/FlashLoanReceiverBaseV2.sol";
import { DEXAdapter } from "./DEXAdapter.sol";
import { Exponential } from "../lib/Exponential.sol";

/**
 * @title FlashMintLeveragedForCompound
 * @author Index Coop
 *
 * Contract for minting and redeeming a leveraged Set token.
 * Supports all tokens with one collateral Position in the form of a cToken and one debt position
 * The collateral underlying  must be available on an Aave flashloan.
 * The collateral and debt tokens must be available on Compound.
 * Input/Output tokens must be tradeable on supported dexes.
 */
contract FlashMintLeveragedForCompound is Exponential, ReentrancyGuard, FlashLoanReceiverBaseV2 {

    using DEXAdapter for DEXAdapter.Addresses;
    using Address for address payable;
    using SafeMath for uint256;
    using PreciseUnitMath for uint256;
    using SafeERC20 for IERC20;
    using SafeERC20 for ISetToken;

    /* ============ Structs ============ */

    struct LeveragedTokenData {
        address collateralCToken;
        uint256 cTokenAmount;
        address collateralToken;
        uint256 collateralAmount;
        address debtToken;
        uint256 debtAmount;
    }

    struct DecodedParams {
        ISetToken setToken;
        uint256 setAmount;
        address originalSender;
        bool isIssuance;
        address paymentToken;
        uint256 limitAmount;
        LeveragedTokenData leveragedTokenData;
        DEXAdapter.SwapData collateralAndDebtSwapData;
        DEXAdapter.SwapData paymentTokenSwapData;
    }

    /* ============ Constants ============= */

    uint256 constant private MAX_UINT256 = type(uint256).max;
    uint256 public constant ROUNDING_ERROR_MARGIN = 2;

    /* ============ Immutables ============ */
    
    address public immutable cEtherAddress;
    IController public immutable setController;
    IDebtIssuanceModule public immutable debtIssuanceModule;
    ICompoundLeverageModule public immutable compoundLeverageModule;

    /* ============ State Variables ============ */

    DEXAdapter.Addresses public addresses;

    /* ============ Events ============ */

    event FlashMint(
        address indexed _recipient,     // The recipient address of the minted Set token
        ISetToken indexed _setToken,    // The minted Set token
        address indexed _inputToken,    // The address of the input asset(ERC20/ETH) used to mint the Set tokens
        uint256 _amountInputToken,      // The amount of input tokens used for minting
        uint256 _amountSetIssued        // The amount of Set tokens received by the recipient
    );

    event FlashRedeem(
        address indexed _recipient,     // The recipient address which redeemed the Set token
        ISetToken indexed _setToken,    // The redeemed Set token
        address indexed _outputToken,   // The address of output asset(ERC20/ETH) received by the recipient
        uint256 _amountSetRedeemed,     // The amount of Set token redeemed for output tokens
        uint256 _amountOutputToken      // The amount of output tokens received by the recipient
    );

    /* ============ Modifiers ============ */

    modifier onlyLendingPool() {
        require(msg.sender == address(LENDING_POOL), "FlashMint: LENDING POOL ONLY");
        _;
    }

    modifier isValidPath(
        address[] memory _path,
        address _inputToken,
        address _outputToken
    )
    {
        if(_inputToken != _outputToken){
            require(
                _path[0] == _inputToken || (_inputToken == addresses.weth && _path[0] == DEXAdapter.ETH_ADDRESS),
                "FlashMint: INPUT_TOKEN_NOT_IN_PATH"
            );
            require(
                _path[_path.length-1] == _outputToken ||
                (_outputToken == addresses.weth && _path[_path.length-1] == DEXAdapter.ETH_ADDRESS),
                "FlashMint: OUTPUT_TOKEN_NOT_IN_PATH"
            );
        }
        _;
    }


    /* ============ Constructor ============ */

    /**
    * Sets various contract addresses
    *
    * @param _dexAddresses              Address of quickRouter, sushiRouter, uniV3Router, uniV3Router, curveAddressProvider, curveCalculator and weth. 
    * @param _setController             Set token controller used to verify a given token is a set
    * @param _debtIssuanceModule        DebtIssuanceModule used to issue and redeem tokens
    * @param _compoundLeverageModule    CompoundLeverageModule to sync before every mint / redemption
    * @param _aaveAddressProvider       Address of address provider for aaves addresses
    * @param _cEther                    Address of Compound's cEther token
    */
    constructor(
        DEXAdapter.Addresses memory _dexAddresses,
        IController _setController,
        IDebtIssuanceModule _debtIssuanceModule,
        ICompoundLeverageModule _compoundLeverageModule,
        address _aaveAddressProvider,
        address _cEther
    )
    public
    FlashLoanReceiverBaseV2(_aaveAddressProvider)
    {
        setController = _setController;
        debtIssuanceModule = _debtIssuanceModule;
        compoundLeverageModule = _compoundLeverageModule;
        addresses = _dexAddresses;
        cEtherAddress = _cEther;
    }

    /* ============ External Functions ============ */

    /**
     * Returns the collateral / debt token addresses and amounts for a leveraged index.
     *
     * @param _setToken     Address of the Set token to be minted / redeemed
     * @param _setAmount    Amount to mint / redeem
     * @param _isMint       Boolean indicating if the Set token is to be issued/minted or redeemed
     *
     * @return Struct containing the collateral / debt token addresses and amounts
     */
    function getLeveragedTokenData(
        ISetToken _setToken,
        uint256 _setAmount,
        bool _isMint
    )
    external
    view
    returns (LeveragedTokenData memory)
    {
        return _getLeveragedTokenData(_setToken, _setAmount, _isMint);
    }

    /**
     * Runs all the necessary approval functions required for a given ERC20 token.
     * This function can be called when a new token is added to a Set token during a rebalance.
     *
     * @param _token    Address of the token which needs approval
     */
    function approveToken(IERC20 _token) external {
        _approveToken(_token);
    }

    /**
     * Gets the input cost of issuing/minting a given amount of a Set token. This
     * function is not marked view, but should be static called off-chain.
     * This constraint is due to the need to interact with the Uniswap V3 quoter
     * contract and call sync on CompoundLeverageModule. 
     * @dev If the two SwapData paths contain the same tokens, there will be a slight error introduced in the result.
     *
     * @param _setToken                     Set token to mint
     * @param _setAmount                    Amount to mint
     * @param _swapDataDebtForCollateral    SwapData (token addresses and fee levels) to describe the swap path from debt to collateral token
     * @param _swapDataInputToken           SwapData (token addresses and fee levels) to describe the swap path from input to collateral token
     *
     * @return                              the amount of input tokens required to perfrom the issuance
     */
    function getIssueExactSet(
        ISetToken _setToken,
        uint256 _setAmount,
        DEXAdapter.SwapData memory _swapDataDebtForCollateral,
        DEXAdapter.SwapData memory _swapDataInputToken
    )
    external
    returns (uint256)
    {
        compoundLeverageModule.sync(_setToken, false);
        LeveragedTokenData memory issueInfo = _updateCompoundRateAndGetLeveragedTokenData(_setToken, _setAmount, true);
        uint256 collateralOwed = issueInfo.collateralAmount.preciseMul(1.0009 ether);
        uint256 borrowSaleProceeds = DEXAdapter.getAmountOut(addresses, _swapDataDebtForCollateral, issueInfo.debtAmount);
        collateralOwed = collateralOwed.sub(borrowSaleProceeds);
        return DEXAdapter.getAmountIn(addresses, _swapDataInputToken, collateralOwed);
    }

    /**
     * Gets the proceeds of a redemption of a given amount of a set token. This
     * function is not marked view, but should be static called from frontends.
     * This constraint is due to the need to interact with the Uniswap V3 quoter
     * contract and call sync on CompoundLeverageModule. 
     * @dev If the two SwapData paths contain the same tokens, there will be a slight error introduced in the result.
     *
     * @param _setToken                     Set token to redeem
     * @param _setAmount                    Amount to redeem
     * @param _swapDataCollateralForDebt    SwapData (token path and fee levels) describing the swap from collateral to debt token
     * @param _swapDataOutputToken          SwapData (token path and fee levels) describing the swap from collateral to output token
     *
     * @return                              amount of output token that would be obtained from the redemption
     */
    function getRedeemExactSet(
        ISetToken _setToken,
        uint256 _setAmount,
        DEXAdapter.SwapData memory _swapDataCollateralForDebt,
        DEXAdapter.SwapData memory _swapDataOutputToken
    )
    external
    returns (uint256)
    {
        compoundLeverageModule.sync(_setToken, true);
        LeveragedTokenData memory redeemInfo = _updateCompoundRateAndGetLeveragedTokenData(_setToken, _setAmount, false);
        uint256 debtOwed = redeemInfo.debtAmount.preciseMul(1.0009 ether);
        uint256 debtPurchaseCost = DEXAdapter.getAmountIn(addresses, _swapDataCollateralForDebt, debtOwed);
        uint256 extraCollateral = redeemInfo.collateralAmount.sub(debtPurchaseCost);
        return DEXAdapter.getAmountOut(addresses, _swapDataOutputToken, extraCollateral);
    }

    /**
     * Trigger redemption of Set token to pay the user with Eth
     *
     * @param _setToken                   Set token to redeem
     * @param _setAmount                  Amount to redeem
     * @param _minAmountOutputToken       Minimum amount of ETH to send to the user
     * @param _swapDataCollateralForDebt  SwapData (token path and fee levels) describing the swap from collateral token to debt token
     * @param _swapDataOutputToken        SwapData (token path and fee levels) describing the swap from collateral token to output token
     */
    function redeemExactSetForETH(
        ISetToken _setToken,
        uint256 _setAmount,
        uint256 _minAmountOutputToken,
        DEXAdapter.SwapData memory _swapDataCollateralForDebt,
        DEXAdapter.SwapData memory _swapDataOutputToken
    )
    external
    nonReentrant
    {
        _flashRedeem(
            _setToken,
            _setAmount,
            DEXAdapter.ETH_ADDRESS,
            _minAmountOutputToken,
            _swapDataCollateralForDebt,
            _swapDataOutputToken
        );
    }

    /**
     * Trigger redemption of Set token to pay the user with an arbitrary ERC20
     *
     * @param _setToken                   Set token to redeem
     * @param _setAmount                  Amount to redeem
     * @param _outputToken                Address of the ERC20 token to send to the user
     * @param _minAmountOutputToken       Minimum amount of output token to send to the user
     * @param _swapDataCollateralForDebt  SwapData (token path and fee levels) describing the swap from collateral token to debt token
     * @param _swapDataOutputToken        SwapData (token path and fee levels) describing the swap from collateral token to output token
     */
    function redeemExactSetForERC20(
        ISetToken _setToken,
        uint256 _setAmount,
        address _outputToken,
        uint256 _minAmountOutputToken,
        DEXAdapter.SwapData memory _swapDataCollateralForDebt,
        DEXAdapter.SwapData memory _swapDataOutputToken
    )
    external
    nonReentrant
    {
        _flashRedeem(
            _setToken,
            _setAmount,
            _outputToken,
            _minAmountOutputToken,
            _swapDataCollateralForDebt,
            _swapDataOutputToken
        );
    }

    /**
     * Trigger minting of Set token paying with any arbitrary ERC20 token.
     *
     * @param _setToken                     Set token to mint
     * @param _setAmount                    Amount to mint
     * @param _inputToken                   Input token to pay with
     * @param _maxAmountInputToken          Maximum amount of input token to spend
     * @param _swapDataDebtForCollateral    SwapData (token addresses and fee levels) to describe the swap path from debt to collateral token
     * @param _swapDataInputToken           SwapData (token addresses and fee levels) to describe the swap path from input to collateral token
     */
    function issueExactSetFromERC20(
        ISetToken _setToken,
        uint256 _setAmount,
        address _inputToken,
        uint256 _maxAmountInputToken,
        DEXAdapter.SwapData memory _swapDataDebtForCollateral,
        DEXAdapter.SwapData memory _swapDataInputToken
    )
    external
    nonReentrant
    {
        _flashMint(
            _setToken,
            _setAmount,
            _inputToken,
            _maxAmountInputToken,
            _swapDataDebtForCollateral,
            _swapDataInputToken
        );
    }

    /**
     * Trigger minting of set token paying with ETH.
     *
     * @param _setToken                     Set token to mint
     * @param _setAmount                    Amount to mint
     * @param _swapDataDebtForCollateral    SwapData (token addresses and fee levels) to describe the swap path from debt to collateral token
     * @param _swapDataInputToken           SwapData (token addresses and fee levels) to describe the swap path from eth to collateral token
     */
    function issueExactSetFromETH(
        ISetToken _setToken,
        uint256 _setAmount,
        DEXAdapter.SwapData memory _swapDataDebtForCollateral,
        DEXAdapter.SwapData memory _swapDataInputToken
    )
    external
    payable
    nonReentrant
    {
        _flashMint(
            _setToken,
            _setAmount,
            DEXAdapter.ETH_ADDRESS,
            msg.value,
            _swapDataDebtForCollateral,
            _swapDataInputToken
        );
    }

    /**
     * This is the callback function that will be called by the AaveLending Pool after flashloaned tokens have been sent
     * to this contract.
     * After exiting this function the Lending Pool will attempt to transfer back the loaned tokens + interest. If it fails to do so
     * the whole transaction gets reverted
     *
     * @param assets     Addresses of all assets that were borrowed
     * @param amounts    Amounts that were borrowed
     * @param premiums   Interest to be paid on top of borrowed amount
     * @param initiator  Address that initiated the flashloan
     * @param params     Encoded bytestring of other parameters from the original contract call to be used downstream
     *
     * @return           Boolean indicating success of the operation (fixed to true otherwise the whole transaction would be reverted by lending pool)
     */
    function executeOperation(
        address[] memory assets,
        uint256[] memory amounts,
        uint256[] memory premiums,
        address initiator,
        bytes memory params
    )
    external
    override
    onlyLendingPool
    returns (bool)
    {
        require(initiator == address(this), "FlashMint: INVALID FLASHLOAN INITIATOR");
        // assets.length must be 1.
        require(assets.length == 1, "FlashMint: TOO MANY ASSETS");
        require(amounts.length == 1, "FlashMint: TOO MANY AMOUNTS");
        require(premiums.length == 1, "FlashMint: TOO MANY PREMIUMS");
        
        DecodedParams memory decodedParams = abi.decode(params, (DecodedParams));

        if(decodedParams.isIssuance){
            _performMint(assets[0], amounts[0], premiums[0], decodedParams);
        } else {
            _performRedemption(assets[0], amounts[0], premiums[0], decodedParams);
        }

        return true;
    }

    /**
     * Runs all the necessary approval functions required for a list of ERC20 tokens.
     *
     * @param _tokens    Addresses of the tokens which need approval
     */
    function approveTokens(IERC20[] memory _tokens) external {
        for (uint256 i = 0; i < _tokens.length; i++) {
            _approveToken(_tokens[i]);
        }
    }

    /**
     * Runs all the necessary approval functions required before minting or redeeming a Set token. 
     * This function need to be called only once before the first time this smart contract is used
     * on any particular Set token.
     *
     * @param _setToken    Address of the SetToken being initialized
     */
    function approveSetToken(ISetToken _setToken) external {
        LeveragedTokenData memory leveragedTokenData = _updateCompoundRateAndGetLeveragedTokenData(_setToken, 1 ether, true);


        _approveToken(IERC20(leveragedTokenData.collateralCToken));
        _approveTokenToLendingPool(IERC20(leveragedTokenData.collateralToken));

        _approveToken(IERC20(leveragedTokenData.debtToken));
        _approveTokenToLendingPool(IERC20(leveragedTokenData.debtToken));
    }

    /* ============ Internal Functions ============ */

    /**
     * Performs all the necessary steps for minting using the collateral tokens obtained in the flashloan.
     *
     * @param _collateralToken            Address of the underlying collateral token that was loaned
     * @param _collateralTokenAmountNet   Amount of collateral token that was received as flashloan
     * @param _premium                    Premium / Interest that has to be returned to the lending pool on top of the loaned amount
     * @param _decodedParams              Struct containing token addresses / amounts to perform mint
     */
    function _performMint(
        address _collateralToken,
        uint256 _collateralTokenAmountNet,
        uint256 _premium,
        DecodedParams memory _decodedParams
    )
    internal
    {
        // Deposit collateral token obtained from flashloan to get the respective cToken position required for issuance
        _depositToCompound(_decodedParams.leveragedTokenData.collateralCToken, _collateralToken, _collateralTokenAmountNet);
        // Issue set using the cToken returned by deposit step
        _mintSet(_decodedParams.setToken, _decodedParams.setAmount, _decodedParams.originalSender);
        // Obtain necessary collateral tokens to repay flashloan
        uint amountInputTokenSpent = _obtainCollateralTokens(
            _collateralToken,
            _collateralTokenAmountNet + _premium,
            _decodedParams
        );
        require(amountInputTokenSpent <= _decodedParams.limitAmount, "FlashMint: INSUFFICIENT INPUT AMOUNT");
    }

    /**
     * Performs all the necessary steps for redemption using the debt tokens obtained in the flashloan
     *
     * @param _debtToken           Address of the debt token that was loaned
     * @param _debtTokenAmountNet  Amount of debt token that was received as flashloan
     * @param _premium             Premium / Interest that has to be returned to the lending pool on top of the loaned amount
     * @param _decodedParams       Struct containing token addresses / amounts to perform redemption
     */
    function _performRedemption(
        address _debtToken,
        uint256 _debtTokenAmountNet,
        uint256 _premium,
        DecodedParams memory _decodedParams
    )
    internal
    {
        // Redeem set using debt tokens obtained from flashloan
        _redeemSet(
            _decodedParams.setToken,
            _decodedParams.setAmount,
            _decodedParams.originalSender
        );

        _withdrawFromCompound(
            _decodedParams.leveragedTokenData.collateralCToken,
            _decodedParams.leveragedTokenData.cTokenAmount,
            _decodedParams.leveragedTokenData.collateralToken,
            _decodedParams.leveragedTokenData.collateralAmount
        );
        // Obtain debt tokens required to repay flashloan by swapping the underlying collateral tokens obtained in withdraw step
        uint256 collateralTokenSpent = _swapCollateralForDebtToken(
            _debtTokenAmountNet + _premium,
            _debtToken,
            _decodedParams.leveragedTokenData.collateralAmount,
            _decodedParams.leveragedTokenData.collateralToken,
            _decodedParams.collateralAndDebtSwapData
        );
        // Liquidate remaining collateral tokens for the payment token specified by user
        uint256 amountOutputToken = _liquidateCollateralTokens(
            collateralTokenSpent,
            _decodedParams.setToken,
            _decodedParams.setAmount,
            _decodedParams.originalSender,
            _decodedParams.paymentToken,
            _decodedParams.limitAmount,
            _decodedParams.leveragedTokenData.collateralToken,
            _decodedParams.leveragedTokenData.collateralAmount  - 2*ROUNDING_ERROR_MARGIN,
            _decodedParams.paymentTokenSwapData
        );
        require(amountOutputToken >= _decodedParams.limitAmount, "FlashMint: INSUFFICIENT OUTPUT AMOUNT");
    }


    /**
    * Returns the collateral / debt token addresses and amounts for a leveraged index
    *
    * @param _setToken      Address of the SetToken to be issued / redeemed
    * @param _setAmount     Amount of SetTokens to issue / redeem
    * @param _isMint        Boolean indicating if the SetToken is to be issued or redeemed
    *
    * @return Struct containing the collateral / debt token addresses and amounts
    */
    function _getBasicLeveragedTokenData(
        ISetToken _setToken,
        uint256 _setAmount,
        bool _isMint
    )
    internal
    view
    returns (LeveragedTokenData memory)
    {
        address[] memory components;
        uint256[] memory equityPositions;
        uint256[] memory debtPositions;
        LeveragedTokenData memory _leveragedTokenData;

        if(_isMint){
            (components, equityPositions, debtPositions) = debtIssuanceModule.getRequiredComponentIssuanceUnits(_setToken, _setAmount);
        } else {
            (components, equityPositions, debtPositions) = debtIssuanceModule.getRequiredComponentRedemptionUnits(_setToken, _setAmount);
        }
        
        require(equityPositions[0] == 0 || equityPositions[1] == 0, "FlashMint: TOO MANY EQUITY POSITIONS");
        
        require(debtPositions[0] == 0 || debtPositions[1] == 0, "FlashMint: TOO MANY DEBT POSITIONS");

        if(equityPositions[0] > 0){
            _leveragedTokenData.collateralCToken = components[0];
            _leveragedTokenData.cTokenAmount = equityPositions[0];
            _leveragedTokenData.debtToken = components[1];
            _leveragedTokenData.debtAmount = debtPositions[1];
        } else {
            _leveragedTokenData.collateralCToken = components[1];
            _leveragedTokenData.cTokenAmount = equityPositions[1];
            _leveragedTokenData.debtToken = components[0];
            _leveragedTokenData.debtAmount = debtPositions[0];
        }
        if (_leveragedTokenData.collateralCToken == cEtherAddress) {
            _leveragedTokenData.collateralToken = addresses.weth;
        } else {
            _leveragedTokenData.collateralToken = CErc20Storage(_leveragedTokenData.collateralCToken).underlying();
        }
        return _leveragedTokenData; 
    }


    /**
    * Returns the collateral / debt token addresses and amounts for a leveraged index
    *
    * @param _setToken     Address of the Set token to be minted / redeemed
    * @param _setAmount    Amount to mint / redeem
    * @param _isMint       Boolean indicating if the Set token is to be issued/minted or redeemed
    *
    * @return Struct containing the collateral / debt token addresses and amounts
    */
    function _getLeveragedTokenData(
        ISetToken _setToken,
        uint256 _setAmount,
        bool _isMint
    )
    internal
    view
    returns (LeveragedTokenData memory)
    {
        LeveragedTokenData memory _leveragedTokenData = _getBasicLeveragedTokenData(_setToken, _setAmount, _isMint);
        Exp memory exchangeRate = Exp({mantissa: ICEther(payable(_leveragedTokenData.collateralCToken)).exchangeRateStored()});
        (, uint256 collateralAmount) = mulScalarTruncate(exchangeRate, _leveragedTokenData.cTokenAmount);
        _leveragedTokenData.collateralAmount = collateralAmount + ROUNDING_ERROR_MARGIN;
        return _leveragedTokenData; 
    }

    /**
    * Returns the collateral / debt token addresses and amounts for a leveraged index
    *
    * @param _setToken     Address of the Set token to be minted / redeemed
    * @param _setAmount    Amount to mint / redeem
    * @param _isMint       Boolean indicating if the Set token is to be issued/minted or redeemed
    *
    * @return Struct containing the collateral / debt token addresses and amounts
    */
    function _updateCompoundRateAndGetLeveragedTokenData(
        ISetToken _setToken,
        uint256 _setAmount,
        bool _isMint
    )
    internal
    returns (LeveragedTokenData memory)
    {
        LeveragedTokenData memory _leveragedTokenData = _getBasicLeveragedTokenData(_setToken, _setAmount, _isMint);
        Exp memory exchangeRate = Exp({mantissa: ICEther(payable(_leveragedTokenData.collateralCToken)).exchangeRateCurrent()});
        (, uint256 collateralAmount) = mulScalarTruncate(exchangeRate, _leveragedTokenData.cTokenAmount);
        _leveragedTokenData.collateralAmount = collateralAmount + ROUNDING_ERROR_MARGIN;
        return _leveragedTokenData; 
    }


    /**
     * Approves max amount of given token to all exchange routers and the debt issuance module
     *
     * @param _token  Address of the token to be approved
     */
    function _approveToken(IERC20 _token) internal {
        _token.approve(address(debtIssuanceModule), MAX_UINT256);
    }

    /**
     * Initiates a flashloan call with the correct parameters for minting Set tokens in the callback
     * Borrows correct amount of collateral token and and forwards encoded memory to control mint in the callback.
     *
     * @param _setToken                     Set token to mint
     * @param _setAmount                    Amount to mint
     * @param _inputToken                   Input token to pay with
     * @param _maxAmountInputToken          Maximum amount of input token to spend
     * @param _swapDataDebtForCollateral    SwapData (token addresses and fee levels) to describe the swap path from debt to collateral token
     * @param _swapDataInputToken           SwapData (token addresses and fee levels) to describe the swap path from input to collateral token
     */
    function _flashMint(
        ISetToken _setToken,
        uint256 _setAmount,
        address _inputToken,
        uint256 _maxAmountInputToken,
        DEXAdapter.SwapData memory _swapDataDebtForCollateral,
        DEXAdapter.SwapData memory _swapDataInputToken
    )
    internal
    {
        // need to check (true or false to issue)
        compoundLeverageModule.sync(_setToken, true);

        LeveragedTokenData memory leveragedTokenData = _updateCompoundRateAndGetLeveragedTokenData(_setToken, _setAmount, true);

        address[] memory assets = new address[](1);
        assets[0] = leveragedTokenData.collateralToken;
        uint[] memory amounts =  new uint[](1);
        amounts[0] = leveragedTokenData.collateralAmount;
        bytes memory params = abi.encode(
            DecodedParams(
                _setToken,
                _setAmount,
                msg.sender,
                true,
                _inputToken,
                _maxAmountInputToken,
                leveragedTokenData,
                _swapDataDebtForCollateral,
                _swapDataInputToken
            )
        );
        _flashloan(assets, amounts, params);
    }

    /**
     * Initiates a flashloan call with the correct parameters for redeeming Set tokens in the callback
     *
     * @param _setToken                   Set token to redeem
     * @param _setAmount                  Amount to redeem
     * @param _outputToken                Address of the output token to send to the user
     * @param _minAmountOutputToken       Minimum amount of output token to send to the user
     * @param _swapDataCollateralForDebt  SwapData (token path and fee levels) describing the swap from collateral token to debt token
     * @param _swapDataOutputToken        SwapData (token path and fee levels) describing the swap from collateral token to output token
     */
    function _flashRedeem(
        ISetToken _setToken,
        uint256 _setAmount,
        address  _outputToken,
        uint256 _minAmountOutputToken,
        DEXAdapter.SwapData memory _swapDataCollateralForDebt,
        DEXAdapter.SwapData memory _swapDataOutputToken
    )
    internal
    {   
        compoundLeverageModule.sync(_setToken, true);
        LeveragedTokenData memory leveragedTokenData = _updateCompoundRateAndGetLeveragedTokenData(_setToken, _setAmount, false);
        address[] memory assets = new address[](1);
        assets[0] = leveragedTokenData.debtToken;
        uint[] memory amounts =  new uint[](1);
        amounts[0] = leveragedTokenData.debtAmount;

        bytes memory params = abi.encode(
            DecodedParams(
                _setToken,
                _setAmount,
                msg.sender,
                false,
                _outputToken,
                _minAmountOutputToken,
                leveragedTokenData,
                _swapDataCollateralForDebt,
                _swapDataOutputToken
            )
        );

        _flashloan(assets, amounts, params);

    }

    /**
     * Transfers output tokens to the user from redemption, if conversion is necessary,
     * exchanges collateral token for output token and then transfers them out.
     *
     * @param _collateralTokenSpent    Amount of collateral token spent to obtain the debt token required for redemption
     * @param _setToken                Set token to redeem
     * @param _setAmount               Amount to redeem
     * @param _originalSender          Account that initiated the redemption
     * @param _outputToken             Token to send to the user
     * @param _collateralToken         Collateral token to exchange for the output token
     * @param _collateralAmount        Amount to exchange
     * @param _minAmountOutputToken    Minimum amount of output token to send to the user
     * @param _swapData                SwapData (token path and fee levels) describing the swap from collateral token to output token
     *
     * @return Amount of output token returned to the user
     */
    function _liquidateCollateralTokens(
        uint256 _collateralTokenSpent,
        ISetToken _setToken,
        uint256 _setAmount,
        address _originalSender,
        address _outputToken,
        uint256 _minAmountOutputToken,
        address _collateralToken,
        uint256 _collateralAmount,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    returns (uint256)
    {
        require(_collateralAmount >= _collateralTokenSpent, "FlashMint: OVERSPENT COLLATERAL TOKEN");
        uint256 amountToReturn = _collateralAmount.sub(_collateralTokenSpent);
        uint256 outputAmount;
        if(_outputToken == DEXAdapter.ETH_ADDRESS){
            outputAmount = _liquidateCollateralTokensForETH(
                _collateralToken,
                amountToReturn,
                _originalSender,
                _minAmountOutputToken,
                _swapData
            );
        } else {
            outputAmount = _liquidateCollateralTokensForERC20(
                _collateralToken,
                amountToReturn,
                _originalSender,
                IERC20(_outputToken),
                _minAmountOutputToken,
                _swapData
            );
        }
        emit FlashRedeem(_originalSender, _setToken, _outputToken, _setAmount, outputAmount);
        return outputAmount;
    }

    /**
     * Returns the collateral token directly to the user.
     *
     * @param _collateralToken       Collateral token
     * @param _collateralRemaining   Amount of the collateral token remaining after buying required debt tokens
     * @param _originalSender        Original sender that is to receive the collateral token
     */
    function _returnCollateralTokensToSender(
        address _collateralToken,
        uint256 _collateralRemaining,
        address _originalSender
    )
    internal
    {
        IERC20(_collateralToken).transfer(_originalSender, _collateralRemaining);
    }

    /**
     * Exchanges the collateral tokens for the output tokens and transfers them to the user.
     *
     * @param _collateralToken       Collateral token
     * @param _collateralRemaining   Amount of the collateral tokens remaining after buying required debt tokens
     * @param _originalSender        Original sender that is to receive the output tokens
     * @param _outputToken           ERC20 token to return to the user
     * @param _minAmountOutputToken  Minimum amount of output token to send to the user
     * @param _swapData              SwapData (token path and fee levels) describing the swap from collateral token to output token
     *
     * @return Amount of output token returned to the user
     */
    function _liquidateCollateralTokensForERC20(
        address _collateralToken,
        uint256 _collateralRemaining,
        address _originalSender,
        IERC20 _outputToken,
        uint256 _minAmountOutputToken,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    returns (uint256)
    {
        if(address(_outputToken) == _collateralToken){
            _returnCollateralTokensToSender(_collateralToken, _collateralRemaining, _originalSender);
            return _collateralRemaining;
        }
        uint256 outputTokenAmount = _swapCollateralForOutputToken(
            _collateralToken,
            _collateralRemaining,
            address(_outputToken),
            _minAmountOutputToken,
            _swapData
        );
        _outputToken.transfer(_originalSender, outputTokenAmount);
        return outputTokenAmount;
    }

    /**
     * Exchanges the remaining collateral tokens for weth, unwraps that weth and returns native eth to the user.
     *
     * @param _collateralToken            Collateral token
     * @param _collateralRemaining        Amount of the collateral tokens remaining after buying required debt tokens
     * @param _originalSender             Original sender that is to receive the native eth
     * @param _minAmountOutputToken       Minimum amount of native eth to send to the user
     * @param _swapData                   SwapData (token path and fee levels) describing the swap from collateral token to eth
     *
     * @return Amount of eth returned to the user
     */
    function _liquidateCollateralTokensForETH(
        address _collateralToken,
        uint256 _collateralRemaining,
        address _originalSender,
        uint256 _minAmountOutputToken,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    isValidPath(_swapData.path, _collateralToken, addresses.weth)
    returns(uint256)
    {
        uint256 ethAmount = _swapCollateralForOutputToken(
            _collateralToken,
            _collateralRemaining,
            addresses.weth,
            _minAmountOutputToken,
            _swapData
        );
        if (ethAmount > 0) {
            IWETH(addresses.weth).withdraw(ethAmount);
            (payable(_originalSender)).sendValue(ethAmount);
        }
        return ethAmount;
    }

    /**
     * Obtains the collateral tokens necessary to return the flashloan by swapping the debt tokens obtained
     * from mint and making up the shortfall using the users funds.
     *
     * @param _collateralToken       Collateral token
     * @param _amountRequired        Amount required to repay the flashloan
     * @param _decodedParams         Struct containing decoded data from original call passed through via flashloan
     *
     * @return Amount of input token spent
     */
    function _obtainCollateralTokens(
        address _collateralToken,
        uint256 _amountRequired,
        DecodedParams memory _decodedParams
    )
    internal
    returns (uint256)
    {
        uint collateralTokenObtained =  _swapDebtForCollateralToken(
            _collateralToken,
            _decodedParams.leveragedTokenData.debtToken,
            _decodedParams.leveragedTokenData.debtAmount,
            _decodedParams.collateralAndDebtSwapData
        );

        uint collateralTokenShortfall = _amountRequired.sub(collateralTokenObtained) + ROUNDING_ERROR_MARGIN;
        uint amountInputToken;

        if(_decodedParams.paymentToken == DEXAdapter.ETH_ADDRESS){
            amountInputToken = _makeUpShortfallWithETH(
                _collateralToken,
                collateralTokenShortfall,
                _decodedParams.originalSender,
                _decodedParams.limitAmount,
                _decodedParams.paymentTokenSwapData
            );
        } else {
            amountInputToken = _makeUpShortfallWithERC20(
                _collateralToken,
                collateralTokenShortfall,
                _decodedParams.originalSender,
                IERC20(_decodedParams.paymentToken),
                _decodedParams.limitAmount,
                _decodedParams.paymentTokenSwapData
            );
        }
        emit FlashMint(
            _decodedParams.originalSender,
            _decodedParams.setToken,
            _decodedParams.paymentToken,
            amountInputToken,
            _decodedParams.setAmount
        );
        return amountInputToken;
    }

    /**
     * Mints Set tokens using the previously obtained collateral token.
     * Results in debt tokens being returned to the contract.
     *
     * @param _setToken         Set token to mint
     * @param _setAmount        Amount to mint
     * @param _originalSender   Account that initiated the mint, which will receive the set tokens
     */
    function _mintSet(ISetToken _setToken, uint256 _setAmount, address _originalSender) internal {
       
        debtIssuanceModule.issue(_setToken, _setAmount, _originalSender);
    }

    /**
     * Redeems Set tokens using the previously obtained debt token.
     * Results in collateral tokens being returned to the contract.
     *
     * @param _setToken         Set token to redeem
     * @param _setAmount        Amount to redeem
     * @param _originalSender   Adress that initiated the redemption which is the source of the set tokens to be redeemed
     */
    function _redeemSet(ISetToken _setToken, uint256 _setAmount, address _originalSender) internal {
        _setToken.safeTransferFrom(_originalSender, address(this), _setAmount);
        debtIssuanceModule.redeem(_setToken, _setAmount, address(this));
    }

    /**
     * Transfers the shortfall between the amount of tokens required to return flashloan and what was obtained
     * from swapping the debt tokens from the users address.
     *
     * @param _token                 Set token to exchange shortfall
     * @param _shortfall             Amount of tokens that the tx is short
     * @param _originalSender        Account of originator, transfer the Set tokens from that account
     */
    function _transferShortfallFromSender(
        address _token,
        uint256 _shortfall,
        address _originalSender
    )
    internal
    {
        if(_shortfall>0){
            IERC20(_token).safeTransferFrom(_originalSender, address(this), _shortfall);
        }
    }

    /**
     * Makes up the collateral token shortfall with user specified ERC20 token.
     *
     * @param _collateralToken             Collateral token
     * @param _collateralTokenShortfall    Amount of tokens that the tx is short after selling debt tokens
     * @param _originalSender              Originator account to return the tokens to
     * @param _inputToken                  Input token to pay with
     * @param _maxAmountInputToken         Maximum amount of input token to spend
     *
     * @return Amount of input token spent
     */
    function _makeUpShortfallWithERC20(
        address _collateralToken,
        uint256 _collateralTokenShortfall,
        address _originalSender,
        IERC20 _inputToken,
        uint256 _maxAmountInputToken,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    returns (uint256)
    {
        if(address(_inputToken) == _collateralToken){
            _transferShortfallFromSender(_collateralToken, _collateralTokenShortfall, _originalSender);
            return _collateralTokenShortfall;
        } else {
            _inputToken.transferFrom(_originalSender, address(this), _maxAmountInputToken);
            uint256 amountInputToken = _swapInputForCollateralToken(
                _collateralToken,
                _collateralTokenShortfall,
                address(_inputToken),
                _maxAmountInputToken,
                _swapData
            );
            if(amountInputToken < _maxAmountInputToken){
                _inputToken.transfer(_originalSender, _maxAmountInputToken.sub(amountInputToken));
            }
            return amountInputToken;
        }
    }

    /**
     * Makes up the collateral token shortfall with native eth.
     *
     * @param _collateralToken             Collateral token
     * @param _collateralTokenShortfall    Amount of tokens that the tx is short after selling debt tokens
     * @param _originalSender              Originator account to return the tokens to
     * @param _maxAmountEth                Maximum amount of eth to pay
     *
     * @return Amount of eth spent
     */
    function _makeUpShortfallWithETH(
        address _collateralToken,
        uint256 _collateralTokenShortfall,
        address _originalSender,
        uint256 _maxAmountEth,
        DEXAdapter.SwapData memory _swapData

    )
    internal
    returns(uint256)
    {
        IWETH(addresses.weth).deposit{value: _maxAmountEth}();

        uint256 amountEth = _swapInputForCollateralToken(
            _collateralToken,
            _collateralTokenShortfall,
            addresses.weth,
            _maxAmountEth,
            _swapData
        );

        if(_maxAmountEth > amountEth){
            uint256 amountEthReturn = _maxAmountEth.sub(amountEth);
            IWETH(addresses.weth).withdraw(amountEthReturn);
            (payable(_originalSender)).sendValue(amountEthReturn);
        }
        return amountEth;
    }

    /**
     * Swaps the debt tokens obtained from minting for the collateral tokens.
     *
     * @param _collateralToken            Collateral token to buy
     * @param _debtToken                  Debt token to sell
     * @param _debtAmount                 Amount of debt token to sell
     * @param _swapData                   SwapData (token path and fee levels) describing the swap from debt token to collateral token
     *
     * @return Amount of collateral token obtained
     */
    function _swapDebtForCollateralToken(
        address _collateralToken,
        address _debtToken,
        uint256 _debtAmount,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    isValidPath(_swapData.path, _debtToken, _collateralToken)
    returns (uint256)
    {
        return addresses.swapExactTokensForTokens(
            _debtAmount,
        // minAmountOut is 0 here since we are going to make up the shortfall with the input token.
        // Sandwich protection is provided by the check at the end against _maxAmountInputToken parameter specified by the user
            0,
            _swapData
        );
    }

    /**
     * Acquires debt tokens needed for flashloan repayment by swapping a portion of the collateral tokens obtained from redemption.
     *
     * @param _debtAmount             Amount of debt token to buy
     * @param _debtToken              Debt token
     * @param _collateralAmount       Amount of collateral token available (eg. maxAmountIn)
     * @param _collateralToken        Collateral token
     * @param _swapData               SwapData (token path and fee levels) describing the swap from collateral token to debt token
     *
     * @return Amount of collateral token spent
     */
    function _swapCollateralForDebtToken(
        uint256 _debtAmount,
        address _debtToken,
        uint256 _collateralAmount,
        address _collateralToken,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    isValidPath(_swapData.path, _collateralToken, _debtToken)
    returns (uint256)
    {
        return addresses.swapTokensForExactTokens(
            _debtAmount,
            _collateralAmount,
            _swapData
        );
    }

    /**
     * Acquires the required amount of collateral tokens by exchanging the input tokens.
     * Does nothing if collateral and input token are indentical.
     *
     * @param _collateralToken       Collateral token
     * @param _amountRequired        Amount required to repay the flashloan
     * @param _inputToken            Input token
     * @param _maxAmountInputToken   Maximum amount of input token to spend
     * @param _swapData              SwapData (token path and fee levels) describing the swap from input token to debt token
     *
     * @return Amount of input token spent
     */
    function _swapInputForCollateralToken(
        address _collateralToken,
        uint256 _amountRequired,
        address _inputToken,
        uint256 _maxAmountInputToken,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    isValidPath(
        _swapData.path,
        _inputToken,
        _collateralToken
    )
    returns (uint256)
    {
        if(_collateralToken == _inputToken) return _amountRequired;
        return addresses.swapTokensForExactTokens(
            _amountRequired,
            _maxAmountInputToken,
            _swapData
        );
    }


    /**
     * Swaps the collateral tokens obtained from redemption for the selected output token
     * If both tokens are the same, does nothing
     *
     * @param _collateralToken        Collateral token
     * @param _collateralTokenAmount  Amount to swap
     * @param _outputToken            ERC20 token to swap into
     * @param _minAmountOutputToken   Minimum amount of output token to receive
     * @param _swapData               SwapData (token path and fee levels) describing the swap from collateral token to output token
     *
     * @return Amount of output token obtained
     */
    function _swapCollateralForOutputToken(
        address _collateralToken,
        uint256 _collateralTokenAmount,
        address _outputToken,
        uint256 _minAmountOutputToken,
        DEXAdapter.SwapData memory _swapData
    )
    internal
    isValidPath(_swapData.path, _collateralToken, _outputToken)
    returns (uint256)
    {
        return addresses.swapExactTokensForTokens(
            _collateralTokenAmount,
            _minAmountOutputToken,
            _swapData
        );
    }

    /**
     * Deposit collateral to compound to obtain collateralCToken for mint.
     *
     * @param _cTokenAddress                cToken
     * @param _collateralToken              Collateral token
     * @param _depositAmount                Amount to deposit
     */
    function _depositToCompound(
        address _cTokenAddress,
        address _collateralToken,
        uint256 _depositAmount
    ) internal {
        if (_collateralToken != addresses.weth) {
            IERC20(_collateralToken).approve(_cTokenAddress, _depositAmount);
            ICErc20Delegator(_cTokenAddress).mint(_depositAmount);
        } else {
            IWETH(addresses.weth).withdraw(_depositAmount);
            ICEther(payable(_cTokenAddress)).mint{value: _depositAmount}();
        }
    }

    /**
     * Redeem Compound cToken for underlying collateral.  
     *
     * @param _cTokenAddress         cToken
     * @param _cTokenAmount          Amount to redeem
     * @param _collateralToken       Collateral token to withdraw
     * @param _collateralAmount      If collateral is ETH (eg. cETH), conver this amount to WETH.
     */
    function _withdrawFromCompound(
        address _cTokenAddress,
        uint256 _cTokenAmount,
        address _collateralToken,
        uint256 _collateralAmount
    ) internal returns (uint256){
        uint256 result;
        if (_collateralToken != addresses.weth) {
            result = ICErc20Delegator(_cTokenAddress).redeem(_cTokenAmount);
        } else {
            result = ICEther(payable(_cTokenAddress)).redeem(_cTokenAmount);
            IWETH(addresses.weth).deposit{value: (_collateralAmount - ROUNDING_ERROR_MARGIN)}();
        }
        return result;
    }


    /**
     * Approves max amount of token to Lending Pool.
     *
     * @param _token              Address of the token to approve
     */
    function _approveTokenToLendingPool(
        IERC20 _token
    )
    internal
    {
        _token.approve(address(LENDING_POOL), MAX_UINT256);
    }

    /**
     * Triggers the flashloan from the Lending Pool
     *
     * @param assets         Tokens to borrow 
     * @param amounts        Amounts of tokens to borrow
     * @param params         Encoded memory to forward to the executeOperation method
     */
    function _flashloan(
        address[] memory assets,
        uint256[] memory amounts,
        bytes memory params
    )
    internal
    {
        address receiverAddress = address(this);
        address onBehalfOf = address(this);
        uint16 referralCode = 0;
        uint256[] memory modes = new uint256[](assets.length);

        // 0 = no debt (flash), 1 = stable, 2 = variable
        for (uint256 i = 0; i < assets.length; i++) {
            modes[i] = 0;
        }

        LENDING_POOL.flashLoan(
            receiverAddress,
            assets,
            amounts,
            modes,
            onBehalfOf,
            params,
            referralCode
        );
    }

}

File 3 of 42 : Address.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.2 <0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        // solhint-disable-next-line no-inline-assembly
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        // solhint-disable-next-line avoid-low-level-calls, avoid-call-value
        (bool success, ) = recipient.call{ value: amount }("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain`call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
      return functionCall(target, data, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        require(isContract(target), "Address: call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.call{ value: value }(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data, string memory errorMessage) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.staticcall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return _verifyCallResult(success, returndata, errorMessage);
    }

    function _verifyCallResult(bool success, bytes memory returndata, string memory errorMessage) private pure returns(bytes memory) {
        if (success) {
            return returndata;
        } else {
            // Look for revert reason and bubble it up if present
            if (returndata.length > 0) {
                // The easiest way to bubble the revert reason is using memory via assembly

                // solhint-disable-next-line no-inline-assembly
                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 4 of 42 : IERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 5 of 42 : Math.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a >= b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow, so we distribute
        return (a / 2) + (b / 2) + ((a % 2 + b % 2) / 2);
    }
}

File 6 of 42 : SafeERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "./IERC20.sol";
import "../../math/SafeMath.sol";
import "../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using SafeMath for uint256;
    using Address for address;

    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        // solhint-disable-next-line max-line-length
        require((value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).add(value);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero");
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) { // Return data is optional
            // solhint-disable-next-line max-line-length
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 7 of 42 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Wrappers over Solidity's arithmetic operations with added overflow
 * checks.
 *
 * Arithmetic operations in Solidity wrap on overflow. This can easily result
 * in bugs, because programmers usually assume that an overflow raises an
 * error, which is the standard behavior in high level programming languages.
 * `SafeMath` restores this intuition by reverting the transaction when an
 * operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        uint256 c = a + b;
        if (c < a) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b > a) return (false, 0);
        return (true, a - b);
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) return (true, 0);
        uint256 c = a * b;
        if (c / a != b) return (false, 0);
        return (true, c);
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a / b);
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     *
     * _Available since v3.4._
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        if (b == 0) return (false, 0);
        return (true, a % b);
    }

    /**
     * @dev Returns the addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: division by zero");
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b > 0, "SafeMath: modulo by zero");
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        return a - b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryDiv}.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        return a % b;
    }
}

File 8 of 42 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor () internal {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and make it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 9 of 42 : IAToken.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.10;


interface IAToken {
  /**
   * @dev Returns the address of the underlying asset of this aToken (E.g. WETH for aWETH)
   **/
  function UNDERLYING_ASSET_ADDRESS() external view returns (address);
}

File 10 of 42 : ICErc20.sol
// SPDX-License-Identifier: Apache License, Version 2.0
pragma solidity 0.6.10;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";


/**
 * @title ICErc20
 *
 * Interface for interacting with Compound cErc20 tokens (e.g. Dai, USDC)
 */
interface ICErc20 is IERC20 {

    function borrowBalanceCurrent(address _account) external returns (uint256);

    function borrowBalanceStored(address _account) external view returns (uint256);

    function balanceOfUnderlying(address _account) external returns (uint256);

    /**
     * Calculates the exchange rate from the underlying to the CToken
     *
     * @notice Accrue interest then return the up-to-date exchange rate
     * @return Calculated exchange rate scaled by 1e18
     */
    function exchangeRateCurrent() external returns (uint256);

    function exchangeRateStored() external view returns (uint256);

    function underlying() external view returns (address);

    /**
     * Sender supplies assets into the market and receives cTokens in exchange
     *
     * @notice Accrues interest whether or not the operation succeeds, unless reverted
     * @param _mintAmount The amount of the underlying asset to supply
     * @return uint256 0=success, otherwise a failure
     */
    function mint(uint256 _mintAmount) external returns (uint256);

    /**
     * @notice Sender redeems cTokens in exchange for the underlying asset
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param _redeemTokens The number of cTokens to redeem into underlying
     * @return uint256 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function redeem(uint256 _redeemTokens) external returns (uint256);

    /**
     * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset
     * @dev Accrues interest whether or not the operation succeeds, unless reverted
     * @param _redeemAmount The amount of underlying to redeem
     * @return uint256 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function redeemUnderlying(uint256 _redeemAmount) external returns (uint256);

    /**
      * @notice Sender borrows assets from the protocol to their own address
      * @param _borrowAmount The amount of the underlying asset to borrow
      * @return uint256 0=success, otherwise a failure (see ErrorReporter.sol for details)
      */
    function borrow(uint256 _borrowAmount) external returns (uint256);

    /**
     * @notice Sender repays their own borrow
     * @param _repayAmount The amount to repay
     * @return uint256 0=success, otherwise a failure (see ErrorReporter.sol for details)
     */
    function repayBorrow(uint256 _repayAmount) external returns (uint256);
}

File 11 of 42 : ICompoundLeverageModule.sol
/*
    Copyright 2021 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
import { ISetToken } from "./ISetToken.sol";

interface ICompoundLeverageModule {
    function sync(ISetToken _setToken, bool _shouldAccrueInterest) external virtual;
}

File 12 of 42 : ICErc20Delegator.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

interface ICErc20Delegator {
    function _acceptAdmin() external returns(uint256);
    function _addReserves(uint256 addAmount) external returns(uint256);
    function _reduceReserves(uint256 reduceAmount) external returns(uint256);
    function _renounceAdminRights() external returns(uint256);
    function _renounceFuseAdminRights() external returns(uint256);
    function _resignImplementation() external;
    function _setAdminFee(uint256 newAdminFeeMantissa) external returns(uint256);
    function _setComptroller(address newComptroller) external returns(uint256);
    function _setFuseFee() external returns(uint256);
    function _setInterestRateModel(address newInterestRateModel) external returns(uint256);
    function _setPendingAdmin(address newPendingAdmin) external returns(uint256);
    function _setReserveFactor(uint256 newReserveFactorMantissa) external returns(uint256);
    function _withdrawAdminFees(uint256 withdrawAmount) external returns(uint256);
    function _withdrawFuseFees(uint256 withdrawAmount) external returns(uint256);
    function accrualBlockNumber() external view returns(uint256);
    function accrueInterest() external returns(uint256);
    function admin() external view returns(address);
    function adminFeeMantissa() external view returns(uint256);
    function adminHasRights() external view returns(bool);
    function allowance(address owner, address spender) external view returns(uint256);
    function approve(address spender, uint256 amount) external returns(bool);
    function balanceOf(address owner) external view returns(uint256);
    function balanceOfUnderlying(address owner) external returns(uint256);
    function borrow(uint256 borrowAmount) external returns(uint256);
    function borrowBalanceCurrent(address account) external returns(uint256);
    function borrowBalanceStored(address account) external view returns(uint256);
    function borrowIndex() external view returns(uint256);
    function borrowRatePerBlock() external view returns(uint256);
    function comptroller() external view returns(address);
    function decimals() external view returns(uint8);
    function exchangeRateCurrent() external returns(uint256);
    function exchangeRateStored() external view returns(uint256);
    function fuseAdminHasRights() external view returns(bool);
    function fuseFeeMantissa() external view returns(uint256);
    function getAccountSnapshot(address account) external view returns(uint256, uint256, uint256, uint256);
    function getCash() external view returns(uint256);
    function implementation() external view returns(address);
    function initialize(address comptroller_, address interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_, uint256 reserveFactorMantissa_, uint256 adminFeeMantissa_) external;
    function initialize(address underlying_, address comptroller_, address interestRateModel_, uint256 initialExchangeRateMantissa_, string memory name_, string memory symbol_, uint8 decimals_, uint256 reserveFactorMantissa_, uint256 adminFeeMantissa_) external;
    function interestRateModel() external view returns(address);
    function isCEther() external view returns(bool);
    function isCToken() external view returns(bool);
    function liquidateBorrow(address borrower, uint256 repayAmount, address cTokenCollateral) external returns(uint256);
    function mint(uint256 mintAmount) external returns(uint256);
    function name() external view returns(string memory);
    function pendingAdmin() external view returns(address);
    function redeem(uint256 redeemTokens) external returns(uint256);
    function redeemUnderlying(uint256 redeemAmount) external returns(uint256);
    function repayBorrow(uint256 repayAmount) external returns(uint256);
    function repayBorrowBehalf(address borrower, uint256 repayAmount) external returns(uint256);
    function reserveFactorMantissa() external view returns(uint256);
    function seize(address liquidator, address borrower, uint256 seizeTokens) external returns(uint256);
    function supplyRatePerBlock() external view returns(uint256);
    function symbol() external view returns(string memory);
    function totalAdminFees() external view returns(uint256);
    function totalBorrows() external view returns(uint256);
    function totalBorrowsCurrent() external returns(uint256);
    function totalFuseFees() external view returns(uint256);
    function totalReserves() external view returns(uint256);
    function totalSupply() external view returns(uint256);
    function transfer(address dst, uint256 amount) external returns(bool);
    function transferFrom(address src, address dst, uint256 amount) external returns(bool);
    function underlying() external view returns(address);
}

File 13 of 42 : ICEther.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

interface ICEther {
    function mint() external payable;
    function redeem(uint redeemTokens) external returns (uint);
    function redeemUnderlying(uint redeemAmount) external returns (uint);
    function borrow(uint borrowAmount) external returns (uint);
    function getCash() external view returns (uint);
    function exchangeRateStored() external view returns (uint);
    function exchangeRateCurrent() external returns (uint);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    receive() external payable;
}

File 14 of 42 : CErc20Storage.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

contract CErc20Storage {
    /**
     * @notice Underlying asset for this CToken
     */
    address public underlying;
}

File 15 of 42 : CompoundLeverageModuleStorage.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

contract CompoundLeverageModuleStorage {
    // Mapping of underlying to CToken. If ETH, then map WETH to cETH
    mapping(address => address) public underlyingToCToken;
}

File 16 of 42 : IDebtIssuanceModule.sol
/*
    Copyright 2020 Set Labs Inc.
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity >=0.6.10;

import { ISetToken } from "./ISetToken.sol";
import { IManagerIssuanceHook } from "./IManagerIssuanceHook.sol";

interface IDebtIssuanceModule {
    function getRequiredComponentIssuanceUnits(
        ISetToken _setToken,
        uint256 _quantity
    ) external view returns (address[] memory, uint256[] memory, uint256[] memory);
    function getRequiredComponentRedemptionUnits(
        ISetToken _setToken,
        uint256 _quantity
    ) external view returns (address[] memory, uint256[] memory, uint256[] memory);
    function issue(ISetToken _setToken, uint256 _quantity, address _to) external;
    function redeem(ISetToken _token, uint256 _quantity, address _to) external;
    function initialize(
        ISetToken _setToken,
        uint256 _maxManagerFee,
        uint256 _managerIssueFee,
        uint256 _managerRedeemFee,
        address _feeRecipient,
        IManagerIssuanceHook _managerIssuanceHook
    ) external;
}

File 17 of 42 : IController.sol
/*
    Copyright 2020 Set Labs Inc.
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;

interface IController {
    function addSet(address _setToken) external;
    function feeRecipient() external view returns(address);
    function getModuleFee(address _module, uint256 _feeType) external view returns(uint256);
    function isModule(address _module) external view returns(bool);
    function isSet(address _setToken) external view returns(bool);
    function isSystemContract(address _contractAddress) external view returns (bool);
    function resourceId(uint256 _id) external view returns(address);
}

File 18 of 42 : ISetToken.sol
// SPDX-License-Identifier: Apache License, Version 2.0
pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title ISetToken
 * @author Set Protocol
 *
 * Interface for operating with SetTokens.
 */
interface ISetToken is IERC20 {

    /* ============ Enums ============ */

    enum ModuleState {
        NONE,
        PENDING,
        INITIALIZED
    }

    /* ============ Structs ============ */
    /**
     * The base definition of a SetToken Position
     *
     * @param component           Address of token in the Position
     * @param module              If not in default state, the address of associated module
     * @param unit                Each unit is the # of components per 10^18 of a SetToken
     * @param positionState       Position ENUM. Default is 0; External is 1
     * @param data                Arbitrary data
     */
    struct Position {
        address component;
        address module;
        int256 unit;
        uint8 positionState;
        bytes data;
    }

    /**
     * A struct that stores a component's cash position details and external positions
     * This data structure allows O(1) access to a component's cash position units and
     * virtual units.
     *
     * @param virtualUnit               Virtual value of a component's DEFAULT position. Stored as virtual for efficiency
     *                                  updating all units at once via the position multiplier. Virtual units are achieved
     *                                  by dividing a "real" value by the "positionMultiplier"
     * @param componentIndex
     * @param externalPositionModules   List of external modules attached to each external position. Each module
     *                                  maps to an external position
     * @param externalPositions         Mapping of module => ExternalPosition struct for a given component
     */
    struct ComponentPosition {
      int256 virtualUnit;
      address[] externalPositionModules;
      mapping(address => ExternalPosition) externalPositions;
    }

    /**
     * A struct that stores a component's external position details including virtual unit and any
     * auxiliary data.
     *
     * @param virtualUnit       Virtual value of a component's EXTERNAL position.
     * @param data              Arbitrary data
     */
    struct ExternalPosition {
      int256 virtualUnit;
      bytes data;
    }


    /* ============ Functions ============ */

    function addComponent(address _component) external;
    function removeComponent(address _component) external;
    function editDefaultPositionUnit(address _component, int256 _realUnit) external;
    function addExternalPositionModule(address _component, address _positionModule) external;
    function removeExternalPositionModule(address _component, address _positionModule) external;
    function editExternalPositionUnit(address _component, address _positionModule, int256 _realUnit) external;
    function editExternalPositionData(address _component, address _positionModule, bytes calldata _data) external;

    function invoke(address _target, uint256 _value, bytes calldata _data) external returns(bytes memory);

    function editPositionMultiplier(int256 _newMultiplier) external;

    function mint(address _account, uint256 _quantity) external;
    function burn(address _account, uint256 _quantity) external;

    function lock() external;
    function unlock() external;

    function addModule(address _module) external;
    function removeModule(address _module) external;
    function initializeModule() external;

    function setManager(address _manager) external;

    function manager() external view returns (address);
    function moduleStates(address _module) external view returns (ModuleState);
    function getModules() external view returns (address[] memory);

    function getDefaultPositionRealUnit(address _component) external view returns(int256);
    function getExternalPositionRealUnit(address _component, address _positionModule) external view returns(int256);
    function getComponents() external view returns(address[] memory);
    function getExternalPositionModules(address _component) external view returns(address[] memory);
    function getExternalPositionData(address _component, address _positionModule) external view returns(bytes memory);
    function isExternalPositionModule(address _component, address _module) external view returns(bool);
    function isComponent(address _component) external view returns(bool);

    function positionMultiplier() external view returns (int256);
    function getPositions() external view returns (Position[] memory);
    function getTotalComponentRealUnits(address _component) external view returns(int256);

    function isInitializedModule(address _module) external view returns(bool);
    function isPendingModule(address _module) external view returns(bool);
    function isLocked() external view returns (bool);
}

File 19 of 42 : IWETH.sol
// SPDX-License-Identifier: Apache License, Version 2.0
pragma solidity >=0.6.10;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IWETH is IERC20 {
    function deposit() external payable;
    function withdraw(uint) external;
}

File 20 of 42 : PreciseUnitMath.sol
/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
import { SignedSafeMath } from "@openzeppelin/contracts/math/SignedSafeMath.sol";


/**
 * @title PreciseUnitMath
 * @author Set Protocol
 *
 * Arithmetic for fixed-point numbers with 18 decimals of precision. Some functions taken from
 * dYdX's BaseMath library.
 *
 * CHANGELOG:
 * - 9/21/20: Added safePower function
 */
library PreciseUnitMath {
    using SafeMath for uint256;
    using SignedSafeMath for int256;

    // The number One in precise units.
    uint256 constant internal PRECISE_UNIT = 10 ** 18;
    int256 constant internal PRECISE_UNIT_INT = 10 ** 18;

    // Max unsigned integer value
    uint256 constant internal MAX_UINT_256 = type(uint256).max;
    // Max and min signed integer value
    int256 constant internal MAX_INT_256 = type(int256).max;
    int256 constant internal MIN_INT_256 = type(int256).min;

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function preciseUnit() internal pure returns (uint256) {
        return PRECISE_UNIT;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function preciseUnitInt() internal pure returns (int256) {
        return PRECISE_UNIT_INT;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function maxUint256() internal pure returns (uint256) {
        return MAX_UINT_256;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function maxInt256() internal pure returns (int256) {
        return MAX_INT_256;
    }

    /**
     * @dev Getter function since constants can't be read directly from libraries.
     */
    function minInt256() internal pure returns (int256) {
        return MIN_INT_256;
    }

    /**
     * @dev Multiplies value a by value b (result is rounded down). It's assumed that the value b is the significand
     * of a number with 18 decimals precision.
     */
    function preciseMul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mul(b).div(PRECISE_UNIT);
    }

    /**
     * @dev Multiplies value a by value b (result is rounded towards zero). It's assumed that the value b is the
     * significand of a number with 18 decimals precision.
     */
    function preciseMul(int256 a, int256 b) internal pure returns (int256) {
        return a.mul(b).div(PRECISE_UNIT_INT);
    }

    /**
     * @dev Multiplies value a by value b (result is rounded up). It's assumed that the value b is the significand
     * of a number with 18 decimals precision.
     */
    function preciseMulCeil(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0 || b == 0) {
            return 0;
        }
        return a.mul(b).sub(1).div(PRECISE_UNIT).add(1);
    }

    /**
     * @dev Divides value a by value b (result is rounded down).
     */
    function preciseDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        return a.mul(PRECISE_UNIT).div(b);
    }


    /**
     * @dev Divides value a by value b (result is rounded towards 0).
     */
    function preciseDiv(int256 a, int256 b) internal pure returns (int256) {
        return a.mul(PRECISE_UNIT_INT).div(b);
    }

    /**
     * @dev Divides value a by value b (result is rounded up or away from 0).
     */
    function preciseDivCeil(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b != 0, "Cant divide by 0");

        return a > 0 ? a.mul(PRECISE_UNIT).sub(1).div(b).add(1) : 0;
    }

    /**
     * @dev Divides value a by value b (result is rounded down - positive numbers toward 0 and negative away from 0).
     */
    function divDown(int256 a, int256 b) internal pure returns (int256) {
        require(b != 0, "Cant divide by 0");
        require(a != MIN_INT_256 || b != -1, "Invalid input");

        int256 result = a.div(b);
        if (a ^ b < 0 && a % b != 0) {
            result -= 1;
        }

        return result;
    }

    /**
     * @dev Multiplies value a by value b where rounding is towards the lesser number. 
     * (positive values are rounded towards zero and negative values are rounded away from 0). 
     */
    function conservativePreciseMul(int256 a, int256 b) internal pure returns (int256) {
        return divDown(a.mul(b), PRECISE_UNIT_INT);
    }

    /**
     * @dev Divides value a by value b where rounding is towards the lesser number. 
     * (positive values are rounded towards zero and negative values are rounded away from 0). 
     */
    function conservativePreciseDiv(int256 a, int256 b) internal pure returns (int256) {
        return divDown(a.mul(PRECISE_UNIT_INT), b);
    }

    /**
    * @dev Performs the power on a specified value, reverts on overflow.
    */
    function safePower(
        uint256 a,
        uint256 pow
    )
        internal
        pure
        returns (uint256)
    {
        require(a > 0, "Value must be positive");

        uint256 result = 1;
        for (uint256 i = 0; i < pow; i++){
            uint256 previousResult = result;

            // Using safemath multiplication prevents overflows
            result = previousResult.mul(a);
        }

        return result;
    }
}

File 21 of 42 : UniSushiV2Library.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.5.0;

import '@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol';

import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";

library UniSushiV2Library {
    using SafeMath for uint;

    // returns sorted token addresses, used to handle return values from pairs sorted in this order
    function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
        require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
        (token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
        require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
    }

    // fetches and sorts the reserves for a pair
    function getReserves(address pair, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
        (address token0,) = sortTokens(tokenA, tokenB);
        (uint reserve0, uint reserve1,) = IUniswapV2Pair(pair).getReserves();
        (reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
    }

    // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
    function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
        require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
        require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        amountB = amountA.mul(reserveB) / reserveA;
    }

    // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
        require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint amountInWithFee = amountIn.mul(997);
        uint numerator = amountInWithFee.mul(reserveOut);
        uint denominator = reserveIn.mul(1000).add(amountInWithFee);
        amountOut = numerator / denominator;
    }

    // given an output amount of an asset and pair reserves, returns a required input amount of the other asset
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
        require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
        require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
        uint numerator = reserveIn.mul(amountOut).mul(1000);
        uint denominator = reserveOut.sub(amountOut).mul(997);
        amountIn = (numerator / denominator).add(1);
    }

    // performs chained getAmountOut calculations on any number of pairs
    function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[0] = amountIn;
        for (uint i; i < path.length - 1; i++) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
            amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
        }
    }

    // performs chained getAmountIn calculations on any number of pairs
    function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
        require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
        amounts = new uint[](path.length);
        amounts[amounts.length - 1] = amountOut;
        for (uint i = path.length - 1; i > 0; i--) {
            (uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
            amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
        }
    }
}

File 22 of 42 : FlashLoanReceiverBaseV2.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.8;

import { SafeMath } from '@openzeppelin/contracts/math/SafeMath.sol';
import { IERC20 } from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import { SafeERC20 } from '@openzeppelin/contracts/token/ERC20/SafeERC20.sol';
import { IFlashLoanReceiverV2 } from './../../../contracts/interfaces/IFlashLoanReceiverV2.sol';
import { ILendingPoolAddressesProviderV2 } from './../../../contracts/interfaces/ILendingPoolAddressesProviderV2.sol';
import { ILendingPoolV2 } from './../../../contracts/interfaces/ILendingPoolV2.sol';
import "./utils/Withdrawable.sol";

/** 
    !!!
    Never keep funds permanently on your FlashLoanReceiverBase contract as they could be 
    exposed to a 'griefing' attack, where the stored funds are used by an attacker.
    !!!
 */
abstract contract FlashLoanReceiverBaseV2 is IFlashLoanReceiverV2 {
  using SafeERC20 for IERC20;
  using SafeMath for uint256;

  ILendingPoolAddressesProviderV2 public immutable override ADDRESSES_PROVIDER;
  ILendingPoolV2 public immutable override LENDING_POOL;

  constructor(address provider) public {
    ADDRESSES_PROVIDER = ILendingPoolAddressesProviderV2(provider);
    LENDING_POOL = ILendingPoolV2(ILendingPoolAddressesProviderV2(provider).getLendingPool());
  }

  receive() payable external {}
}

File 23 of 42 : DEXAdapter.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

import { IUniswapV2Router02 } from "@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";

import { ICurveCalculator } from "../interfaces/external/ICurveCalculator.sol";
import { ICurveAddressProvider } from "../interfaces/external/ICurveAddressProvider.sol";
import { ICurvePoolRegistry } from "../interfaces/external/ICurvePoolRegistry.sol";
import { ICurvePool } from "../interfaces/external/ICurvePool.sol";
import { ISwapRouter} from "../interfaces/external/ISwapRouter.sol";
import { IQuoter } from "../interfaces/IQuoter.sol";
import { IWETH } from "../interfaces/IWETH.sol";
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";


/**
 * @title DEXAdapter
 * @author Index Coop
 *
 * Adapter to execute swaps on different DEXes
 */
library DEXAdapter {
    using SafeERC20 for IERC20;
    using PreciseUnitMath for uint256;
    using SafeMath for uint256;

    /* ============ Constants ============= */

    uint256 constant private MAX_UINT256 = type(uint256).max;
    address public constant ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
    uint256 public constant ROUNDING_ERROR_MARGIN = 2;

    /* ============ Enums ============ */

    enum Exchange { None, Quickswap, Sushiswap, UniV3, Curve }

    /* ============ Structs ============ */

    struct Addresses {
        address quickRouter;
        address sushiRouter;
        address uniV3Router;
        address uniV3Quoter;
        address curveAddressProvider;
        address curveCalculator;
        // Wrapped native token (WMATIC on polygon)
        address weth;
    }

    struct SwapData {
        address[] path;
        uint24[] fees;
        address pool;
        Exchange exchange;
    }

    struct CurvePoolData {
        int128 nCoins;
        uint256[8] balances;
        uint256 A;
        uint256 fee;
        uint256[8] rates;
        uint256[8] decimals;
    }

    /**
     * Swap exact tokens for another token on a given DEX.
     *
     * @param _addresses    Struct containing relevant smart contract addresses.
     * @param _amountIn     The amount of input token to be spent
     * @param _minAmountOut Minimum amount of output token to receive
     * @param _swapData     Swap data containing the path and fee levels (latter only used for uniV3)
     *
     * @return amountOut    The amount of output tokens
     */
    function swapExactTokensForTokens(
        Addresses memory _addresses,
        uint256 _amountIn,
        uint256 _minAmountOut,
        SwapData memory _swapData
    )
        external
        returns (uint256)
    {
        if (_swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
            return _amountIn;
        }

        if(_swapData.exchange == Exchange.Curve){
            return _swapExactTokensForTokensCurve(
                _swapData.path,
                _swapData.pool,
                _amountIn,
                _minAmountOut,
                _addresses
            );
        }
        if(_swapData.exchange== Exchange.UniV3){
            return _swapExactTokensForTokensUniV3(
                _swapData.path,
                _swapData.fees,
                _amountIn,
                _minAmountOut,
                ISwapRouter(_addresses.uniV3Router)
            );
        } else {
            return _swapExactTokensForTokensUniV2(
                _swapData.path,
                _amountIn,
                _minAmountOut,
                _getRouter(_swapData.exchange, _addresses)
            );
        }
    }


    /**
     * Swap tokens for exact amount of output tokens on a given DEX.
     *
     * @param _addresses    Struct containing relevant smart contract addresses.
     * @param _amountOut    The amount of output token required
     * @param _maxAmountIn  Maximum amount of input token to be spent
     * @param _swapData     Swap data containing the path and fee levels (latter only used for uniV3)
     *
     * @return amountIn     The amount of input tokens spent
     */
    function swapTokensForExactTokens(
        Addresses memory _addresses,
        uint256 _amountOut,
        uint256 _maxAmountIn,
        SwapData memory _swapData
    )
        external
        returns (uint256 amountIn)
    {
        if (_swapData.path[0] == _swapData.path[_swapData.path.length -1]) {
            return _amountOut;
        }

        if(_swapData.exchange == Exchange.Curve){
            return _swapTokensForExactTokensCurve(
                _swapData.path,
                _swapData.pool,
                _amountOut,
                _maxAmountIn,
                _addresses
            );
        }
        if(_swapData.exchange == Exchange.UniV3){
            return _swapTokensForExactTokensUniV3(
                _swapData.path,
                _swapData.fees,
                _amountOut,
                _maxAmountIn,
                ISwapRouter(_addresses.uniV3Router)
            );
        } else {
            return _swapTokensForExactTokensUniV2(
                _swapData.path,
                _amountOut,
                _maxAmountIn,
                _getRouter(_swapData.exchange, _addresses)
            );
        }
    }

    /**
     * Gets the output amount of a token swap.
     *
     * @param _swapData     the swap parameters
     * @param _addresses    Struct containing relevant smart contract addresses.
     * @param _amountIn     the input amount of the trade
     *
     * @return              the output amount of the swap
     */
    function getAmountOut(
        Addresses memory _addresses,
        SwapData memory _swapData,
        uint256 _amountIn
    )
        external
        returns (uint256)
    {
        if (_swapData.path.length == 0 || _swapData.path[0] == _swapData.path[_swapData.path.length-1]) {
            return _amountIn;
        }

        if (_swapData.exchange == Exchange.UniV3) {
            return _getAmountOutUniV3(_swapData, _addresses.uniV3Quoter, _amountIn);
        } else if (_swapData.exchange == Exchange.Curve) {
            (int128 i, int128 j) = _getCoinIndices(
                _swapData.pool,
                _swapData.path[0],
                _swapData.path[1],
                ICurveAddressProvider(_addresses.curveAddressProvider)
            );
            return _getAmountOutCurve(_swapData.pool, i, j, _amountIn, _addresses);
        } else {
            return _getAmountOutUniV2(
                _swapData,
                _getRouter(_swapData.exchange, _addresses),
                _amountIn
            );
        }
    }
    
    /**
     * Gets the input amount of a fixed output swap.
     *
     * @param _swapData     the swap parameters
     * @param _addresses    Struct containing relevant smart contract addresses.
     * @param _amountOut    the output amount of the swap
     *
     * @return              the input amount of the swap
     */
    function getAmountIn(
        Addresses memory _addresses,
        SwapData memory _swapData,
        uint256 _amountOut
    )
        external
        returns (uint256)
    {
        if (_swapData.path.length == 0 || _swapData.path[0] == _swapData.path[_swapData.path.length-1]) {
            return _amountOut;
        }

        if (_swapData.exchange == Exchange.UniV3) {
            return _getAmountInUniV3(_swapData, _addresses.uniV3Quoter, _amountOut);
        } else if (_swapData.exchange == Exchange.Curve) {
            (int128 i, int128 j) = _getCoinIndices(
                _swapData.pool,
                _swapData.path[0],
                _swapData.path[1],
                ICurveAddressProvider(_addresses.curveAddressProvider)
            );
            return _getAmountInCurve(_swapData.pool, i, j, _amountOut, _addresses);
        } else {
            return _getAmountInUniV2(
                _swapData,
                _getRouter(_swapData.exchange, _addresses),
                _amountOut
            );
        }
    }

    /**
     * Sets a max approval limit for an ERC20 token, provided the current allowance
     * is less than the required allownce.
     *
     * @param _token              Token to approve
     * @param _spender            Spender address to approve
     * @param _requiredAllowance  Target allowance to set
     */
    function _safeApprove(
        IERC20 _token,
        address _spender,
        uint256 _requiredAllowance
    )
        internal
    {
        uint256 allowance = _token.allowance(address(this), _spender);
        if (allowance < _requiredAllowance) {
            _token.safeIncreaseAllowance(_spender, MAX_UINT256 - allowance);
        }
    }

    /* ============ Private Methods ============ */

    /**
     *  Execute exact output swap via a UniV2 based DEX. (such as sushiswap);
     *
     * @param _path         List of token address to swap via. 
     * @param _amountOut    The amount of output token required
     * @param _maxAmountIn  Maximum amount of input token to be spent
     * @param _router       Address of the uniV2 router to use
     *
     * @return amountIn    The amount of input tokens spent
     */
    function _swapTokensForExactTokensUniV2(
        address[] memory _path,
        uint256 _amountOut,
        uint256 _maxAmountIn,
        IUniswapV2Router02 _router
    )
        private
        returns (uint256)
    {
        _safeApprove(IERC20(_path[0]), address(_router), _maxAmountIn);
        return _router.swapTokensForExactTokens(_amountOut, _maxAmountIn, _path, address(this), block.timestamp)[0];
    }

    /**
     *  Execute exact output swap via UniswapV3
     *
     * @param _path         List of token address to swap via. (In the order as
     *                      expected by uniV2, the first element being the input toen)
     * @param _fees         List of fee levels identifying the pools to swap via.
     *                      (_fees[0] refers to pool between _path[0] and _path[1])
     * @param _amountOut    The amount of output token required
     * @param _maxAmountIn  Maximum amount of input token to be spent
     * @param _uniV3Router  Address of the uniswapV3 router
     *
     * @return amountIn    The amount of input tokens spent
     */
    function _swapTokensForExactTokensUniV3(
        address[] memory _path,
        uint24[] memory _fees,
        uint256 _amountOut,
        uint256 _maxAmountIn,
        ISwapRouter _uniV3Router
    )
        private
        returns(uint256)
    {

        require(_path.length == _fees.length + 1, "ExchangeIssuance: PATHS_FEES_MISMATCH");
        _safeApprove(IERC20(_path[0]), address(_uniV3Router), _maxAmountIn);
        if(_path.length == 2){
            ISwapRouter.ExactOutputSingleParams memory params =
                ISwapRouter.ExactOutputSingleParams({
                    tokenIn: _path[0],
                    tokenOut: _path[1],
                    fee: _fees[0],
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountOut: _amountOut,
                    amountInMaximum: _maxAmountIn,
                    sqrtPriceLimitX96: 0
                });
            return _uniV3Router.exactOutputSingle(params);
        } else {
            bytes memory pathV3 = _encodePathV3(_path, _fees, true);
            ISwapRouter.ExactOutputParams memory params =
                ISwapRouter.ExactOutputParams({
                    path: pathV3,
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountOut: _amountOut,
                    amountInMaximum: _maxAmountIn
                });
            return _uniV3Router.exactOutput(params);
        }
    }

    /**
     *  Execute exact input swap via Curve
     *
     * @param _path         Path (has to be of length 2)
     * @param _pool         Address of curve pool to use
     * @param _amountIn     The amount of input token to be spent
     * @param _minAmountOut Minimum amount of output token to receive
     * @param _addresses    Struct containing relevant smart contract addresses.
     *
     * @return amountOut    The amount of output token obtained
     */
    function _swapExactTokensForTokensCurve(
        address[] memory _path,
        address _pool,
        uint256 _amountIn,
        uint256 _minAmountOut,
        Addresses memory _addresses
    )
        private
        returns (uint256 amountOut)
    {
        require(_path.length == 2, "ExchangeIssuance: CURVE_WRONG_PATH_LENGTH");
        (int128 i, int128 j) = _getCoinIndices(_pool, _path[0], _path[1], ICurveAddressProvider(_addresses.curveAddressProvider));

        if(_path[0] == ETH_ADDRESS){
            IWETH(_addresses.weth).withdraw(_amountIn);
        }

        amountOut = _exchangeCurve(i, j, _pool, _amountIn, _minAmountOut, _path[0]);

        if(_path[_path.length-1] == ETH_ADDRESS){
            IWETH(_addresses.weth).deposit{value: amountOut}();
        }

    }

    /**
     *  Execute exact output swap via Curve
     *
     * @param _path         Path (has to be of length 2)
     * @param _pool         Address of curve pool to use
     * @param _amountOut    The amount of output token required
     * @param _maxAmountIn  Maximum amount of input token to be spent
     *
     * @return amountOut    The amount of output token obtained
     */
    function _swapTokensForExactTokensCurve(
        address[] memory _path,
        address _pool,
        uint256 _amountOut,
        uint256 _maxAmountIn,
        Addresses memory _addresses
    )
        private
        returns (uint256)
    {
        require(_path.length == 2, "ExchangeIssuance: CURVE_WRONG_PATH_LENGTH");
        (int128 i, int128 j) = _getCoinIndices(_pool, _path[0], _path[1], ICurveAddressProvider(_addresses.curveAddressProvider));

        uint256 amountIn = _getAmountInCurve(
            _pool,
            i,
            j,
            _amountOut,
            _addresses
        );
        require(amountIn <= _maxAmountIn, "ExchangeIssuance: CURVE_OVERSPENT");

        if(_path[0] == ETH_ADDRESS){
            IWETH(_addresses.weth).withdraw(amountIn);
        }

        uint256 returnedAmountOut = _exchangeCurve(i, j, _pool, amountIn, _amountOut, _path[0]);
        require(_amountOut <= returnedAmountOut, "ExchangeIssuance: CURVE_UNDERBOUGHT");

        if(_path[_path.length-1] == ETH_ADDRESS){
            IWETH(_addresses.weth).deposit{ value: returnedAmountOut }();
        }

        return amountIn;
    }
    
    function _exchangeCurve(
        int128 _i,
        int128 _j,
        address _pool,
        uint256 _amountIn,
        uint256 _minAmountOut,
        address _from
    )
        private
        returns (uint256 amountOut)
    {
        ICurvePool pool = ICurvePool(_pool);
        if(_from == ETH_ADDRESS){
            amountOut = pool.exchange{value: _amountIn}(
                _i,
                _j,
                _amountIn,
                _minAmountOut
            );
        }
        else {
            IERC20(_from).approve(_pool, _amountIn);
            amountOut = pool.exchange(
                _i,
                _j,
                _amountIn,
                _minAmountOut
            );
        }
    }

    /**
     *  Calculate required input amount to get a given output amount via Curve swap
     *
     * @param _i            Index of input token as per the ordering of the pools tokens
     * @param _j            Index of output token as per the ordering of the pools tokens
     * @param _pool         Address of curve pool to use
     * @param _amountOut    The amount of output token to be received
     * @param _addresses    Struct containing relevant smart contract addresses.
     *
     * @return amountOut    The amount of output token obtained
     */
    function _getAmountInCurve(
        address _pool,
        int128 _i,
        int128 _j,
        uint256 _amountOut,
        Addresses memory _addresses
    )
        private
        view
        returns (uint256)
    {
        CurvePoolData memory poolData = _getCurvePoolData(_pool, ICurveAddressProvider(_addresses.curveAddressProvider));

        return ICurveCalculator(_addresses.curveCalculator).get_dx(
            poolData.nCoins,
            poolData.balances,
            poolData.A,
            poolData.fee,
            poolData.rates,
            poolData.decimals,
            false,
            _i,
            _j,
            _amountOut
        ) + ROUNDING_ERROR_MARGIN;
    }

    /**
     *  Calculate output amount of a Curve swap
     *
     * @param _i            Index of input token as per the ordering of the pools tokens
     * @param _j            Index of output token as per the ordering of the pools tokens
     * @param _pool         Address of curve pool to use
     * @param _amountIn     The amount of output token to be received
     * @param _addresses    Struct containing relevant smart contract addresses.
     *
     * @return amountOut    The amount of output token obtained
     */
    function _getAmountOutCurve(
        address _pool,
        int128 _i,
        int128 _j,
        uint256 _amountIn,
        Addresses memory _addresses
    )
        private
        view
        returns (uint256)
    {
        return ICurvePool(_pool).get_dy(_i, _j, _amountIn);
    }

    /**
     *  Get metadata on curve pool required to calculate input amount from output amount
     *
     * @param _pool                    Address of curve pool to use
     * @param _curveAddressProvider    Address of curve address provider
     *
     * @return Struct containing all required data to perform getAmountInCurve calculation
     */
    function _getCurvePoolData(
        address _pool,
        ICurveAddressProvider _curveAddressProvider
    ) private view returns(CurvePoolData memory)
    {
        ICurvePoolRegistry registry = ICurvePoolRegistry(_curveAddressProvider.get_registry());

        return CurvePoolData(
            int128(registry.get_n_coins(_pool)[0]),
            registry.get_balances(_pool),
            registry.get_A(_pool),
            registry.get_fees(_pool)[0],
            registry.get_rates(_pool),
            registry.get_decimals(_pool)
        );
    }
    
    /**
     *  Get token indices for given pool
     *  NOTE: This was necessary sine the get_coin_indices function of the CurvePoolRegistry did not work for StEth/ETH pool
     *
     * @param _pool                    Address of curve pool to use
     * @param _from                    Address of input token
     * @param _to                      Address of output token
     * @param _curveAddressProvider    Address of curve address provider
     *
     * @return i Index of input token
     * @return j Index of output token
     */
    function _getCoinIndices(
        address _pool,
        address _from,
        address _to,
        ICurveAddressProvider _curveAddressProvider
    )
        private
        view
        returns (int128 i, int128 j)
    {
        ICurvePoolRegistry registry = ICurvePoolRegistry(_curveAddressProvider.get_registry());

        // Set to out of range index to signal the coin is not found yet
        i = 9;
        j = 9;
        address[8] memory poolCoins = registry.get_coins(_pool);

        for(uint256 k = 0; k < 8; k++){
            if(poolCoins[k] == _from){
                i = int128(k);
            }
            else if(poolCoins[k] == _to){
                j = int128(k);
            }
            // ZeroAddress signals end of list
            if(poolCoins[k] == address(0) || (i != 9 && j != 9)){
                break;
            }
        }

        require(i != 9, "ExchangeIssuance: CURVE_FROM_NOT_FOUND");
        require(j != 9, "ExchangeIssuance: CURVE_TO_NOT_FOUND");

        return (i, j);
    }

    /**
     *  Execute exact input swap via UniswapV3
     *
     * @param _path         List of token address to swap via. 
     * @param _fees         List of fee levels identifying the pools to swap via.
     *                      (_fees[0] refers to pool between _path[0] and _path[1])
     * @param _amountIn     The amount of input token to be spent
     * @param _minAmountOut Minimum amount of output token to receive
     * @param _uniV3Router  Address of the uniswapV3 router
     *
     * @return amountOut    The amount of output token obtained
     */
    function _swapExactTokensForTokensUniV3(
        address[] memory _path,
        uint24[] memory _fees,
        uint256 _amountIn,
        uint256 _minAmountOut,
        ISwapRouter _uniV3Router
    )
        private
        returns (uint256)
    {
        require(_path.length == _fees.length + 1, "ExchangeIssuance: PATHS_FEES_MISMATCH");
        _safeApprove(IERC20(_path[0]), address(_uniV3Router), _amountIn);
        if(_path.length == 2){
            ISwapRouter.ExactInputSingleParams memory params =
                ISwapRouter.ExactInputSingleParams({
                    tokenIn: _path[0],
                    tokenOut: _path[1],
                    fee: _fees[0],
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountIn: _amountIn,
                    amountOutMinimum: _minAmountOut,
                    sqrtPriceLimitX96: 0
                });
            return _uniV3Router.exactInputSingle(params);
        } else {
            bytes memory pathV3 = _encodePathV3(_path, _fees, false);
            ISwapRouter.ExactInputParams memory params =
                ISwapRouter.ExactInputParams({
                    path: pathV3,
                    recipient: address(this),
                    deadline: block.timestamp,
                    amountIn: _amountIn,
                    amountOutMinimum: _minAmountOut
                });
            uint amountOut = _uniV3Router.exactInput(params);
            return amountOut;
        }
    }

    /**
     *  Execute exact input swap via UniswapV2
     *
     * @param _path         List of token address to swap via. 
     * @param _amountIn     The amount of input token to be spent
     * @param _minAmountOut Minimum amount of output token to receive
     * @param _router       Address of uniV2 router to use
     *
     * @return amountOut    The amount of output token obtained
     */
    function _swapExactTokensForTokensUniV2(
        address[] memory _path,
        uint256 _amountIn,
        uint256 _minAmountOut,
        IUniswapV2Router02 _router
    )
        private
        returns (uint256)
    {
        _safeApprove(IERC20(_path[0]), address(_router), _amountIn);
        return _router.swapExactTokensForTokens(_amountIn, _minAmountOut, _path, address(this), block.timestamp)[1];
    }

    /**
     * Gets the output amount of a token swap on Uniswap V2
     *
     * @param _swapData     the swap parameters
     * @param _router       the uniswap v2 router address
     * @param _amountIn     the input amount of the trade
     *
     * @return              the output amount of the swap
     */
    function _getAmountOutUniV2(
        SwapData memory _swapData,
        IUniswapV2Router02 _router,
        uint256 _amountIn
    )
        private
        view
        returns (uint256)
    {
        return _router.getAmountsOut(_amountIn, _swapData.path)[_swapData.path.length-1];
    }

    /**
     * Gets the input amount of a fixed output swap on Uniswap V2.
     *
     * @param _swapData     the swap parameters
     * @param _router       the uniswap v2 router address
     * @param _amountOut    the output amount of the swap
     *
     * @return              the input amount of the swap
     */
    function _getAmountInUniV2(
        SwapData memory _swapData,
        IUniswapV2Router02 _router,
        uint256 _amountOut
    )
        private
        view
        returns (uint256)
    {
        return _router.getAmountsIn(_amountOut, _swapData.path)[0];
    }

    /**
     * Gets the output amount of a token swap on Uniswap V3.
     *
     * @param _swapData     the swap parameters
     * @param _quoter       the uniswap v3 quoter
     * @param _amountIn     the input amount of the trade
     *
     * @return              the output amount of the swap
     */

    function _getAmountOutUniV3(
        SwapData memory _swapData,
        address _quoter,
        uint256 _amountIn
    )
        private
        returns (uint256)
    {
        bytes memory path = _encodePathV3(_swapData.path, _swapData.fees, false);
        return IQuoter(_quoter).quoteExactInput(path, _amountIn);
    }

    /**
     * Gets the input amount of a fixed output swap on Uniswap V3.
     *
     * @param _swapData     the swap parameters
     * @param _quoter       uniswap v3 quoter
     * @param _amountOut    the output amount of the swap
     *
     * @return              the input amount of the swap
     */
    function _getAmountInUniV3(
        SwapData memory _swapData,
        address _quoter,
        uint256 _amountOut
    )
        private
        returns (uint256)
    {
        bytes memory path = _encodePathV3(_swapData.path, _swapData.fees, true);
        return IQuoter(_quoter).quoteExactOutput(path, _amountOut);
    }

    /**
     * Encode path / fees to bytes in the format expected by UniV3 router
     *
     * @param _path          List of token address to swap via (starting with input token)
     * @param _fees          List of fee levels identifying the pools to swap via.
     *                       (_fees[0] refers to pool between _path[0] and _path[1])
     * @param _reverseOrder  Boolean indicating if path needs to be reversed to start with output token.
     *                       (which is the case for exact output swap)
     *
     * @return encodedPath   Encoded path to be forwared to uniV3 router
     */
    function _encodePathV3(
        address[] memory _path,
        uint24[] memory _fees,
        bool _reverseOrder
    )
        private
        pure
        returns(bytes memory encodedPath)
    {
        if(_reverseOrder){
            encodedPath = abi.encodePacked(_path[_path.length-1]);
            for(uint i = 0; i < _fees.length; i++){
                uint index = _fees.length - i - 1;
                encodedPath = abi.encodePacked(encodedPath, _fees[index], _path[index]);
            }
        } else {
            encodedPath = abi.encodePacked(_path[0]);
            for(uint i = 0; i < _fees.length; i++){
                encodedPath = abi.encodePacked(encodedPath, _fees[i], _path[i+1]);
            }
        }
    }

    function _getRouter(
        Exchange _exchange,
        Addresses memory _addresses
    )
        private
        pure
        returns (IUniswapV2Router02)
    {
        return IUniswapV2Router02(
            (_exchange == Exchange.Quickswap) ? _addresses.quickRouter : _addresses.sushiRouter
        );
    }
}

File 24 of 42 : Exponential.sol
pragma solidity 0.6.10;

/**
  * @title Careful Math
  * @author Compound
  * @notice Derived from OpenZeppelin's SafeMath library
  *         https://github.com/OpenZeppelin/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol
  */
contract CarefulMath {

    /**
     * @dev Possible error codes that we can return
     */
    enum MathError {
        NO_ERROR,
        DIVISION_BY_ZERO,
        INTEGER_OVERFLOW,
        INTEGER_UNDERFLOW
    }

    /**
    * @dev Multiplies two numbers, returns an error on overflow.
    */
    function mulUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (a == 0) {
            return (MathError.NO_ERROR, 0);
        }

        uint c = a * b;

        if (c / a != b) {
            return (MathError.INTEGER_OVERFLOW, 0);
        } else {
            return (MathError.NO_ERROR, c);
        }
    }

    /**
    * @dev Integer division of two numbers, truncating the quotient.
    */
    function divUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (b == 0) {
            return (MathError.DIVISION_BY_ZERO, 0);
        }

        return (MathError.NO_ERROR, a / b);
    }

    /**
    * @dev Subtracts two numbers, returns an error on overflow (i.e. if subtrahend is greater than minuend).
    */
    function subUInt(uint a, uint b) internal pure returns (MathError, uint) {
        if (b <= a) {
            return (MathError.NO_ERROR, a - b);
        } else {
            return (MathError.INTEGER_UNDERFLOW, 0);
        }
    }

    /**
    * @dev Adds two numbers, returns an error on overflow.
    */
    function addUInt(uint a, uint b) internal pure returns (MathError, uint) {
        uint c = a + b;

        if (c >= a) {
            return (MathError.NO_ERROR, c);
        } else {
            return (MathError.INTEGER_OVERFLOW, 0);
        }
    }

    /**
    * @dev add a and b and then subtract c
    */
    function addThenSubUInt(uint a, uint b, uint c) internal pure returns (MathError, uint) {
        (MathError err0, uint sum) = addUInt(a, b);

        if (err0 != MathError.NO_ERROR) {
            return (err0, 0);
        }

        return subUInt(sum, c);
    }
}


/**
 * @title Exponential module for storing fixed-decision decimals
 * @author Compound
 * @notice Exp is a struct which stores decimals with a fixed precision of 18 decimal places.
 *         Thus, if we wanted to store the 5.1, mantissa would store 5.1e18. That is:
 *         `Exp({mantissa: 5100000000000000000})`.
 */
contract Exponential is CarefulMath {
    uint constant expScale = 1e18;
    uint constant halfExpScale = expScale/2;
    uint constant mantissaOne = expScale;

    struct Exp {
        uint mantissa;
    }

    /**
     * @dev Creates an exponential from numerator and denominator values.
     *      Note: Returns an error if (`num` * 10e18) > MAX_INT,
     *            or if `denom` is zero.
     */
    function getExp(uint num, uint denom) pure internal returns (MathError, Exp memory) {
        (MathError err0, uint scaledNumerator) = mulUInt(num, expScale);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        (MathError err1, uint rational) = divUInt(scaledNumerator, denom);
        if (err1 != MathError.NO_ERROR) {
            return (err1, Exp({mantissa: 0}));
        }

        return (MathError.NO_ERROR, Exp({mantissa: rational}));
    }

    /**
     * @dev Adds two exponentials, returning a new exponential.
     */
    function addExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
        (MathError error, uint result) = addUInt(a.mantissa, b.mantissa);

        return (error, Exp({mantissa: result}));
    }

    /**
     * @dev Subtracts two exponentials, returning a new exponential.
     */
    function subExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
        (MathError error, uint result) = subUInt(a.mantissa, b.mantissa);

        return (error, Exp({mantissa: result}));
    }

    /**
     * @dev Multiply an Exp by a scalar, returning a new Exp.
     */
    function mulScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {
        (MathError err0, uint scaledMantissa) = mulUInt(a.mantissa, scalar);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        return (MathError.NO_ERROR, Exp({mantissa: scaledMantissa}));
    }

    /**
     * @dev Multiply an Exp by a scalar, then truncate to return an unsigned integer.
     */
    function mulScalarTruncate(Exp memory a, uint scalar) pure internal returns (MathError, uint) {
        (MathError err, Exp memory product) = mulScalar(a, scalar);
        if (err != MathError.NO_ERROR) {
            return (err, 0);
        }

        return (MathError.NO_ERROR, truncate(product));
    }

    /**
     * @dev Multiply an Exp by a scalar, truncate, then add an to an unsigned integer, returning an unsigned integer.
     */
    function mulScalarTruncateAddUInt(Exp memory a, uint scalar, uint addend) pure internal returns (MathError, uint) {
        (MathError err, Exp memory product) = mulScalar(a, scalar);
        if (err != MathError.NO_ERROR) {
            return (err, 0);
        }

        return addUInt(truncate(product), addend);
    }

    /**
     * @dev Divide an Exp by a scalar, returning a new Exp.
     */
    function divScalar(Exp memory a, uint scalar) pure internal returns (MathError, Exp memory) {
        (MathError err0, uint descaledMantissa) = divUInt(a.mantissa, scalar);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        return (MathError.NO_ERROR, Exp({mantissa: descaledMantissa}));
    }

    /**
     * @dev Divide a scalar by an Exp, returning a new Exp.
     */
    function divScalarByExp(uint scalar, Exp memory divisor) pure internal returns (MathError, Exp memory) {
        /*
          We are doing this as:
          getExp(mulUInt(expScale, scalar), divisor.mantissa)

          How it works:
          Exp = a / b;
          Scalar = s;
          `s / (a / b)` = `b * s / a` and since for an Exp `a = mantissa, b = expScale`
        */
        (MathError err0, uint numerator) = mulUInt(expScale, scalar);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }
        return getExp(numerator, divisor.mantissa);
    }

    /**
     * @dev Divide a scalar by an Exp, then truncate to return an unsigned integer.
     */
    function divScalarByExpTruncate(uint scalar, Exp memory divisor) pure internal returns (MathError, uint) {
        (MathError err, Exp memory fraction) = divScalarByExp(scalar, divisor);
        if (err != MathError.NO_ERROR) {
            return (err, 0);
        }

        return (MathError.NO_ERROR, truncate(fraction));
    }

    /**
     * @dev Multiplies two exponentials, returning a new exponential.
     */
    function mulExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {

        (MathError err0, uint doubleScaledProduct) = mulUInt(a.mantissa, b.mantissa);
        if (err0 != MathError.NO_ERROR) {
            return (err0, Exp({mantissa: 0}));
        }

        // We add half the scale before dividing so that we get rounding instead of truncation.
        //  See "Listing 6" and text above it at https://accu.org/index.php/journals/1717
        // Without this change, a result like 6.6...e-19 will be truncated to 0 instead of being rounded to 1e-18.
        (MathError err1, uint doubleScaledProductWithHalfScale) = addUInt(halfExpScale, doubleScaledProduct);
        if (err1 != MathError.NO_ERROR) {
            return (err1, Exp({mantissa: 0}));
        }

        (MathError err2, uint product) = divUInt(doubleScaledProductWithHalfScale, expScale);
        // The only error `div` can return is MathError.DIVISION_BY_ZERO but we control `expScale` and it is not zero.
        assert(err2 == MathError.NO_ERROR);

        return (MathError.NO_ERROR, Exp({mantissa: product}));
    }

    /**
     * @dev Multiplies two exponentials given their mantissas, returning a new exponential.
     */
    function mulExp(uint a, uint b) pure internal returns (MathError, Exp memory) {
        return mulExp(Exp({mantissa: a}), Exp({mantissa: b}));
    }

    /**
     * @dev Multiplies three exponentials, returning a new exponential.
     */
    function mulExp3(Exp memory a, Exp memory b, Exp memory c) pure internal returns (MathError, Exp memory) {
        (MathError err, Exp memory ab) = mulExp(a, b);
        if (err != MathError.NO_ERROR) {
            return (err, ab);
        }
        return mulExp(ab, c);
    }

    /**
     * @dev Divides two exponentials, returning a new exponential.
     *     (a/scale) / (b/scale) = (a/scale) * (scale/b) = a/b,
     *  which we can scale as an Exp by calling getExp(a.mantissa, b.mantissa)
     */
    function divExp(Exp memory a, Exp memory b) pure internal returns (MathError, Exp memory) {
        return getExp(a.mantissa, b.mantissa);
    }

    /**
     * @dev Truncates the given exp to a whole number value.
     *      For example, truncate(Exp{mantissa: 15 * expScale}) = 15
     */
    function truncate(Exp memory exp) pure internal returns (uint) {
        // Note: We are not using careful math here as we're performing a division that cannot fail
        return exp.mantissa / expScale;
    }

    /**
     * @dev Checks if first Exp is less than second Exp.
     */
    function lessThanExp(Exp memory left, Exp memory right) pure internal returns (bool) {
        return left.mantissa < right.mantissa; //TODO: Add some simple tests and this in another PR yo.
    }

    /**
     * @dev Checks if left Exp <= right Exp.
     */
    function lessThanOrEqualExp(Exp memory left, Exp memory right) pure internal returns (bool) {
        return left.mantissa <= right.mantissa;
    }

    /**
     * @dev returns true if Exp is exactly zero
     */
    function isZeroExp(Exp memory value) pure internal returns (bool) {
        return value.mantissa == 0;
    }
}

File 25 of 42 : IManagerIssuanceHook.sol
/*
    Copyright 2020 Set Labs Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;

import { ISetToken } from "./ISetToken.sol";

interface IManagerIssuanceHook {
    function invokePreIssueHook(ISetToken _setToken, uint256 _issueQuantity, address _sender, address _to) external;
    function invokePreRedeemHook(ISetToken _setToken, uint256 _redeemQuantity, address _sender, address _to) external;
}

File 26 of 42 : SignedSafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/**
 * @title SignedSafeMath
 * @dev Signed math operations with safety checks that revert on error.
 */
library SignedSafeMath {
    int256 constant private _INT256_MIN = -2**255;

    /**
     * @dev Returns the multiplication of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(int256 a, int256 b) internal pure returns (int256) {
        // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
        // benefit is lost if 'b' is also tested.
        // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
        if (a == 0) {
            return 0;
        }

        require(!(a == -1 && b == _INT256_MIN), "SignedSafeMath: multiplication overflow");

        int256 c = a * b;
        require(c / a == b, "SignedSafeMath: multiplication overflow");

        return c;
    }

    /**
     * @dev Returns the integer division of two signed integers. Reverts on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(int256 a, int256 b) internal pure returns (int256) {
        require(b != 0, "SignedSafeMath: division by zero");
        require(!(b == -1 && a == _INT256_MIN), "SignedSafeMath: division overflow");

        int256 c = a / b;

        return c;
    }

    /**
     * @dev Returns the subtraction of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(int256 a, int256 b) internal pure returns (int256) {
        int256 c = a - b;
        require((b >= 0 && c <= a) || (b < 0 && c > a), "SignedSafeMath: subtraction overflow");

        return c;
    }

    /**
     * @dev Returns the addition of two signed integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(int256 a, int256 b) internal pure returns (int256) {
        int256 c = a + b;
        require((b >= 0 && c >= a) || (b < 0 && c < a), "SignedSafeMath: addition overflow");

        return c;
    }
}

File 27 of 42 : IUniswapV2Pair.sol
pragma solidity >=0.5.0;

interface IUniswapV2Pair {
    event Approval(address indexed owner, address indexed spender, uint value);
    event Transfer(address indexed from, address indexed to, uint value);

    function name() external pure returns (string memory);
    function symbol() external pure returns (string memory);
    function decimals() external pure returns (uint8);
    function totalSupply() external view returns (uint);
    function balanceOf(address owner) external view returns (uint);
    function allowance(address owner, address spender) external view returns (uint);

    function approve(address spender, uint value) external returns (bool);
    function transfer(address to, uint value) external returns (bool);
    function transferFrom(address from, address to, uint value) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);
    function PERMIT_TYPEHASH() external pure returns (bytes32);
    function nonces(address owner) external view returns (uint);

    function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;

    event Mint(address indexed sender, uint amount0, uint amount1);
    event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
    event Swap(
        address indexed sender,
        uint amount0In,
        uint amount1In,
        uint amount0Out,
        uint amount1Out,
        address indexed to
    );
    event Sync(uint112 reserve0, uint112 reserve1);

    function MINIMUM_LIQUIDITY() external pure returns (uint);
    function factory() external view returns (address);
    function token0() external view returns (address);
    function token1() external view returns (address);
    function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
    function price0CumulativeLast() external view returns (uint);
    function price1CumulativeLast() external view returns (uint);
    function kLast() external view returns (uint);

    function mint(address to) external returns (uint liquidity);
    function burn(address to) external returns (uint amount0, uint amount1);
    function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
    function skim(address to) external;
    function sync() external;

    function initialize(address, address) external;
}

File 28 of 42 : IFlashLoanReceiverV2.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.10;

import { ILendingPoolAddressesProviderV2 } from "./ILendingPoolAddressesProviderV2.sol";
import { ILendingPoolV2 } from "./ILendingPoolV2.sol";

/**
 * @title IFlashLoanReceiverV2 interface
 * @notice Interface for the Aave fee IFlashLoanReceiver.
 * @author Aave
 * @dev implement this interface to develop a flashloan-compatible flashLoanReceiver contract
 **/
interface IFlashLoanReceiverV2 {
  function executeOperation(
    address[] calldata assets,
    uint256[] calldata amounts,
    uint256[] calldata premiums,
    address initiator,
    bytes calldata params
  ) external returns (bool);

  function ADDRESSES_PROVIDER() external view returns (ILendingPoolAddressesProviderV2);

  function LENDING_POOL() external view returns (ILendingPoolV2);
}

File 29 of 42 : ILendingPoolAddressesProviderV2.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.10;

/**
 * @title LendingPoolAddressesProvider contract
 * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles
 * - Acting also as factory of proxies and admin of those, so with right to change its implementations
 * - Owned by the Aave Governance
 * @author Aave
 **/
interface ILendingPoolAddressesProviderV2 {
  event MarketIdSet(string newMarketId);
  event LendingPoolUpdated(address indexed newAddress);
  event ConfigurationAdminUpdated(address indexed newAddress);
  event EmergencyAdminUpdated(address indexed newAddress);
  event LendingPoolConfiguratorUpdated(address indexed newAddress);
  event LendingPoolCollateralManagerUpdated(address indexed newAddress);
  event PriceOracleUpdated(address indexed newAddress);
  event LendingRateOracleUpdated(address indexed newAddress);
  event ProxyCreated(bytes32 id, address indexed newAddress);
  event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy);

  function getMarketId() external view returns (string memory);

  function setMarketId(string calldata marketId) external;

  function setAddress(bytes32 id, address newAddress) external;

  function setAddressAsProxy(bytes32 id, address impl) external;

  function getAddress(bytes32 id) external view returns (address);

  function getLendingPool() external view returns (address);

  function setLendingPoolImpl(address pool) external;

  function getLendingPoolConfigurator() external view returns (address);

  function setLendingPoolConfiguratorImpl(address configurator) external;

  function getLendingPoolCollateralManager() external view returns (address);

  function setLendingPoolCollateralManager(address manager) external;

  function getPoolAdmin() external view returns (address);

  function setPoolAdmin(address admin) external;

  function getEmergencyAdmin() external view returns (address);

  function setEmergencyAdmin(address admin) external;

  function getPriceOracle() external view returns (address);

  function setPriceOracle(address priceOracle) external;

  function getLendingRateOracle() external view returns (address);

  function setLendingRateOracle(address lendingRateOracle) external;
}

File 30 of 42 : ILendingPoolV2.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.10;
pragma experimental ABIEncoderV2;

import {ILendingPoolAddressesProviderV2} from "./ILendingPoolAddressesProviderV2.sol";
import {DataTypes} from "../../external/contracts/aaveV2/lib/DataTypes.sol";

interface ILendingPoolV2 {
  /**
   * @dev Emitted on deposit()
   * @param reserve The address of the underlying asset of the reserve
   * @param user The address initiating the deposit
   * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens
   * @param amount The amount deposited
   * @param referral The referral code used
   **/
  event Deposit(
    address indexed reserve,
    address user,
    address indexed onBehalfOf,
    uint256 amount,
    uint16 indexed referral
  );

  /**
   * @dev Emitted on withdraw()
   * @param reserve The address of the underlyng asset being withdrawn
   * @param user The address initiating the withdrawal, owner of aTokens
   * @param to Address that will receive the underlying
   * @param amount The amount to be withdrawn
   **/
  event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);

  /**
   * @dev Emitted on borrow() and flashLoan() when debt needs to be opened
   * @param reserve The address of the underlying asset being borrowed
   * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just
   * initiator of the transaction on flashLoan()
   * @param onBehalfOf The address that will be getting the debt
   * @param amount The amount borrowed out
   * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable
   * @param borrowRate The numeric rate at which the user has borrowed
   * @param referral The referral code used
   **/
  event Borrow(
    address indexed reserve,
    address user,
    address indexed onBehalfOf,
    uint256 amount,
    uint256 borrowRateMode,
    uint256 borrowRate,
    uint16 indexed referral
  );

  /**
   * @dev Emitted on repay()
   * @param reserve The address of the underlying asset of the reserve
   * @param user The beneficiary of the repayment, getting his debt reduced
   * @param repayer The address of the user initiating the repay(), providing the funds
   * @param amount The amount repaid
   **/
  event Repay(
    address indexed reserve,
    address indexed user,
    address indexed repayer,
    uint256 amount
  );

  /**
   * @dev Emitted on swapBorrowRateMode()
   * @param reserve The address of the underlying asset of the reserve
   * @param user The address of the user swapping his rate mode
   * @param rateMode The rate mode that the user wants to swap to
   **/
  event Swap(address indexed reserve, address indexed user, uint256 rateMode);

  /**
   * @dev Emitted on setUserUseReserveAsCollateral()
   * @param reserve The address of the underlying asset of the reserve
   * @param user The address of the user enabling the usage as collateral
   **/
  event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);

  /**
   * @dev Emitted on setUserUseReserveAsCollateral()
   * @param reserve The address of the underlying asset of the reserve
   * @param user The address of the user enabling the usage as collateral
   **/
  event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);

  /**
   * @dev Emitted on rebalanceStableBorrowRate()
   * @param reserve The address of the underlying asset of the reserve
   * @param user The address of the user for which the rebalance has been executed
   **/
  event RebalanceStableBorrowRate(address indexed reserve, address indexed user);

  /**
   * @dev Emitted on flashLoan()
   * @param target The address of the flash loan receiver contract
   * @param initiator The address initiating the flash loan
   * @param asset The address of the asset being flash borrowed
   * @param amount The amount flash borrowed
   * @param premium The fee flash borrowed
   * @param referralCode The referral code used
   **/
  event FlashLoan(
    address indexed target,
    address indexed initiator,
    address indexed asset,
    uint256 amount,
    uint256 premium,
    uint16 referralCode
  );

  /**
   * @dev Emitted when the pause is triggered.
   */
  event Paused();

  /**
   * @dev Emitted when the pause is lifted.
   */
  event Unpaused();

  /**
   * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via
   * LendingPoolCollateral manager using a DELEGATECALL
   * This allows to have the events in the generated ABI for LendingPool.
   * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
   * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
   * @param user The address of the borrower getting liquidated
   * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
   * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator
   * @param liquidator The address of the liquidator
   * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants
   * to receive the underlying collateral asset directly
   **/
  event LiquidationCall(
    address indexed collateralAsset,
    address indexed debtAsset,
    address indexed user,
    uint256 debtToCover,
    uint256 liquidatedCollateralAmount,
    address liquidator,
    bool receiveAToken
  );

  /**
   * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared
   * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal,
   * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it
   * gets added to the LendingPool ABI
   * @param reserve The address of the underlying asset of the reserve
   * @param liquidityRate The new liquidity rate
   * @param stableBorrowRate The new stable borrow rate
   * @param variableBorrowRate The new variable borrow rate
   * @param liquidityIndex The new liquidity index
   * @param variableBorrowIndex The new variable borrow index
   **/
  event ReserveDataUpdated(
    address indexed reserve,
    uint256 liquidityRate,
    uint256 stableBorrowRate,
    uint256 variableBorrowRate,
    uint256 liquidityIndex,
    uint256 variableBorrowIndex
  );

  /**
   * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
   * - E.g. User deposits 100 USDC and gets in return 100 aUSDC
   * @param asset The address of the underlying asset to deposit
   * @param amount The amount to be deposited
   * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
   *   wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
   *   is a different wallet
   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
   *   0 if the action is executed directly by the user, without any middle-man
   **/
  function deposit(
    address asset,
    uint256 amount,
    address onBehalfOf,
    uint16 referralCode
  ) external;

  /**
   * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
   * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
   * @param asset The address of the underlying asset to withdraw
   * @param amount The underlying amount to be withdrawn
   *   - Send the value type(uint256).max in order to withdraw the whole aToken balance
   * @param to Address that will receive the underlying, same as msg.sender if the user
   *   wants to receive it on his own wallet, or a different address if the beneficiary is a
   *   different wallet
   * @return The final amount withdrawn
   **/
  function withdraw(
    address asset,
    uint256 amount,
    address to
  ) external returns (uint256);

  /**
   * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
   * already deposited enough collateral, or he was given enough allowance by a credit delegator on the
   * corresponding debt token (StableDebtToken or VariableDebtToken)
   * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet
   *   and 100 stable/variable debt tokens, depending on the `interestRateMode`
   * @param asset The address of the underlying asset to borrow
   * @param amount The amount to be borrowed
   * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable
   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
   *   0 if the action is executed directly by the user, without any middle-man
   * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself
   * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
   * if he has been given credit delegation allowance
   **/
  function borrow(
    address asset,
    uint256 amount,
    uint256 interestRateMode,
    uint16 referralCode,
    address onBehalfOf
  ) external;

  /**
   * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned
   * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address
   * @param asset The address of the borrowed underlying asset previously borrowed
   * @param amount The amount to repay
   * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
   * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
   * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the
   * user calling the function if he wants to reduce/remove his own debt, or the address of any other
   * other borrower whose debt should be removed
   * @return The final amount repaid
   **/
  function repay(
    address asset,
    uint256 amount,
    uint256 rateMode,
    address onBehalfOf
  ) external returns (uint256);

  /**
   * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa
   * @param asset The address of the underlying asset borrowed
   * @param rateMode The rate mode that the user wants to swap to
   **/
  function swapBorrowRateMode(address asset, uint256 rateMode) external;

  /**
   * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve.
   * - Users can be rebalanced if the following conditions are satisfied:
   *     1. Usage ratio is above 95%
   *     2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been
   *        borrowed at a stable rate and depositors are not earning enough
   * @param asset The address of the underlying asset borrowed
   * @param user The address of the user to be rebalanced
   **/
  function rebalanceStableBorrowRate(address asset, address user) external;

  /**
   * @dev Allows depositors to enable/disable a specific deposited asset as collateral
   * @param asset The address of the underlying asset deposited
   * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise
   **/
  function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external;

  /**
   * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1
   * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives
   *   a proportionally amount of the `collateralAsset` plus a bonus to cover market risk
   * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
   * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
   * @param user The address of the borrower getting liquidated
   * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
   * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants
   * to receive the underlying collateral asset directly
   **/
  function liquidationCall(
    address collateralAsset,
    address debtAsset,
    address user,
    uint256 debtToCover,
    bool receiveAToken
  ) external;

  /**
   * @dev Allows smartcontracts to access the liquidity of the pool within one transaction,
   * as long as the amount taken plus a fee is returned.
   * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration.
   * For further details please visit https://developers.aave.com
   * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface
   * @param assets The addresses of the assets being flash-borrowed
   * @param amounts The amounts amounts being flash-borrowed
   * @param modes Types of the debt to open if the flash loan is not returned:
   *   0 -> Don't open any debt, just revert if funds can't be transferred from the receiver
   *   1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
   *   2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
   * @param onBehalfOf The address  that will receive the debt in the case of using on `modes` 1 or 2
   * @param params Variadic packed params to pass to the receiver as extra information
   * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
   *   0 if the action is executed directly by the user, without any middle-man
   **/
  function flashLoan(
    address receiverAddress,
    address[] calldata assets,
    uint256[] calldata amounts,
    uint256[] calldata modes,
    address onBehalfOf,
    bytes calldata params,
    uint16 referralCode
  ) external;

  /**
   * @dev Returns the user account data across all the reserves
   * @param user The address of the user
   * @return totalCollateralETH the total collateral in ETH of the user
   * @return totalDebtETH the total debt in ETH of the user
   * @return availableBorrowsETH the borrowing power left of the user
   * @return currentLiquidationThreshold the liquidation threshold of the user
   * @return ltv the loan to value of the user
   * @return healthFactor the current health factor of the user
   **/
  function getUserAccountData(address user)
    external
    view
    returns (
      uint256 totalCollateralETH,
      uint256 totalDebtETH,
      uint256 availableBorrowsETH,
      uint256 currentLiquidationThreshold,
      uint256 ltv,
      uint256 healthFactor
    );

  function initReserve(
    address reserve,
    address aTokenAddress,
    address stableDebtAddress,
    address variableDebtAddress,
    address interestRateStrategyAddress
  ) external;

  function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress)
    external;

  function setConfiguration(address reserve, uint256 configuration) external;

  /**
   * @dev Returns the configuration of the reserve
   * @param asset The address of the underlying asset of the reserve
   * @return The configuration of the reserve
   **/
  function getConfiguration(address asset)
    external
    view
    returns (DataTypes.ReserveConfigurationMap memory);

  /**
   * @dev Returns the configuration of the user across all the reserves
   * @param user The user address
   * @return The configuration of the user
   **/
  function getUserConfiguration(address user)
    external
    view
    returns (DataTypes.UserConfigurationMap memory);

  /**
   * @dev Returns the normalized income normalized income of the reserve
   * @param asset The address of the underlying asset of the reserve
   * @return The reserve's normalized income
   */
  function getReserveNormalizedIncome(address asset) external view returns (uint256);

  /**
   * @dev Returns the normalized variable debt per unit of asset
   * @param asset The address of the underlying asset of the reserve
   * @return The reserve normalized variable debt
   */
  function getReserveNormalizedVariableDebt(address asset) external view returns (uint256);

  /**
   * @dev Returns the state and configuration of the reserve
   * @param asset The address of the underlying asset of the reserve
   * @return The state of the reserve
   **/
  function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);

  function finalizeTransfer(
    address asset,
    address from,
    address to,
    uint256 amount,
    uint256 balanceFromAfter,
    uint256 balanceToBefore
  ) external;

  function getReservesList() external view returns (address[] memory);

  function getAddressesProvider() external view returns (ILendingPoolAddressesProviderV2);

  function setPause(bool val) external;

  function paused() external view returns (bool);
}

File 31 of 42 : Withdrawable.sol
pragma solidity ^0.6.10;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/**
    Ensures that any contract that inherits from this contract is able to
    withdraw funds that are accidentally received or stuck.
 */
 
contract Withdrawable is Ownable {
    using SafeERC20 for ERC20;
    address constant ETHER = address(0);

    event LogWithdraw(
        address indexed _from,
        address indexed _assetAddress,
        uint amount
    );

    /**
     * @dev Withdraw asset.
     * @param _assetAddress Asset to be withdrawn.
     */
    function withdraw(address _assetAddress) public onlyOwner {
        uint assetBalance;
        if (_assetAddress == ETHER) {
            address self = address(this); // workaround for a possible solidity bug
            assetBalance = self.balance;
            msg.sender.transfer(assetBalance);
        } else {
            assetBalance = ERC20(_assetAddress).balanceOf(address(this));
            ERC20(_assetAddress).safeTransfer(msg.sender, assetBalance);
        }
        emit LogWithdraw(msg.sender, _assetAddress, assetBalance);
    }
}

File 32 of 42 : DataTypes.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity ^0.6.10;

/**
 * @dev This is the Aave V2 DataTypes library.
 */
library DataTypes {
  // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties.
  struct ReserveData {
    //stores the reserve configuration
    ReserveConfigurationMap configuration;
    //the liquidity index. Expressed in ray
    uint128 liquidityIndex;
    //variable borrow index. Expressed in ray
    uint128 variableBorrowIndex;
    //the current supply rate. Expressed in ray
    uint128 currentLiquidityRate;
    //the current variable borrow rate. Expressed in ray
    uint128 currentVariableBorrowRate;
    //the current stable borrow rate. Expressed in ray
    uint128 currentStableBorrowRate;
    uint40 lastUpdateTimestamp;
    //tokens addresses
    address aTokenAddress;
    address stableDebtTokenAddress;
    address variableDebtTokenAddress;
    //address of the interest rate strategy
    address interestRateStrategyAddress;
    //the id of the reserve. Represents the position in the list of the active reserves
    uint8 id;
  }

  struct ReserveConfigurationMap {
    //bit 0-15: LTV
    //bit 16-31: Liq. threshold
    //bit 32-47: Liq. bonus
    //bit 48-55: Decimals
    //bit 56: Reserve is active
    //bit 57: reserve is frozen
    //bit 58: borrowing is enabled
    //bit 59: stable rate borrowing enabled
    //bit 60-63: reserved
    //bit 64-79: reserve factor
    uint256 data;
  }

  struct UserConfigurationMap {
    uint256 data;
  }

  enum InterestRateMode {NONE, STABLE, VARIABLE}
}

File 33 of 42 : ERC20.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../../utils/Context.sol";
import "./IERC20.sol";
import "../../math/SafeMath.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20 {
    using SafeMath for uint256;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * To select a different value for {decimals}, use {_setupDecimals}.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
        _decimals = 18;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the value {ERC20} uses, unless {_setupDecimals} is
     * called.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual override returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual override returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        _approve(_msgSender(), spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * Requirements:
     *
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    /**
     * @dev Moves tokens `amount` from `sender` to `recipient`.
     *
     * This is internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `sender` cannot be the zero address.
     * - `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     */
    function _transfer(address sender, address recipient, uint256 amount) internal virtual {
        require(sender != address(0), "ERC20: transfer from the zero address");
        require(recipient != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(sender, recipient, amount);

        _balances[sender] = _balances[sender].sub(amount, "ERC20: transfer amount exceeds balance");
        _balances[recipient] = _balances[recipient].add(amount);
        emit Transfer(sender, recipient, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply = _totalSupply.add(amount);
        _balances[account] = _balances[account].add(amount);
        emit Transfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        _balances[account] = _balances[account].sub(amount, "ERC20: burn amount exceeds balance");
        _totalSupply = _totalSupply.sub(amount);
        emit Transfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

    /**
     * @dev Sets {decimals} to a value other than the default one of 18.
     *
     * WARNING: This function should only be called from the constructor. Most
     * applications that interact with token contracts will not expect
     * {decimals} to ever change, and may work incorrectly if it does.
     */
    function _setupDecimals(uint8 decimals_) internal virtual {
        _decimals = decimals_;
    }

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be to transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}

File 34 of 42 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

import "../utils/Context.sol";
/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor () internal {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

File 35 of 42 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;

/*
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with GSN meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address payable) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes memory) {
        this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
        return msg.data;
    }
}

File 36 of 42 : IUniswapV2Router02.sol
pragma solidity >=0.6.2;

import './IUniswapV2Router01.sol';

interface IUniswapV2Router02 is IUniswapV2Router01 {
    function removeLiquidityETHSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountETH);
    function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountETH);

    function swapExactTokensForTokensSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    function swapExactETHForTokensSupportingFeeOnTransferTokens(
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external payable;
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

File 37 of 42 : ICurveCalculator.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

// Implementation: https://etherscan.io/address/0xc1DB00a8E5Ef7bfa476395cdbcc98235477cDE4E#readContract
interface ICurveCalculator {
    function get_dx(
        int128 n_coins,
        uint256[8] memory balances,
        uint256 amp,
        uint256 fee,
        uint256[8] memory rates,
        uint256[8] memory precisions,
        bool underlying,
        int128 i,
        int128 j,
        uint256 dy
    ) external view returns(uint256);

    function get_dy(
        int128 n_coins,
        uint256[8] memory balances,
        uint256 amp,
        uint256 fee,
        uint256[8] memory rates,
        uint256[8] memory precisions,
        bool underlying,
        int128 i,
        int128 j,
        uint256 dx
    ) external view returns(uint256);
}

File 38 of 42 : ICurveAddressProvider.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

// Implementation: https://etherscan.io/address/0x0000000022d53366457f9d5e68ec105046fc4383#readContract
interface ICurveAddressProvider {
    function get_registry() external view returns(address);
    function get_address(uint256 _id) external view returns(address);
}

File 39 of 42 : ICurvePoolRegistry.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

// Implementation: https://etherscan.io/address/0x90E00ACe148ca3b23Ac1bC8C240C2a7Dd9c2d7f5#readContract
interface ICurvePoolRegistry {
    // amplification factor
    function get_A(address _pool) external view returns(uint256);
    function get_balances(address _pool) external view returns(uint256[8] memory);
    function get_coins(address _pool) external view returns(address[8] memory);
    function get_coin_indices(address _pool, address _from, address _to) external view returns(int128, int128, bool);
    function get_decimals(address _pool) external view returns(uint256[8] memory);
    function get_n_coins(address _pool) external view returns(uint256[2] memory);
    function get_fees(address _pool) external view returns(uint256[2] memory);
    function get_rates(address _pool) external view returns(uint256[8] memory);
}

File 40 of 42 : ICurvePool.sol
/*
    Copyright 2022 Index Cooperative

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    http://www.apache.org/licenses/LICENSE-2.0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

    SPDX-License-Identifier: Apache License, Version 2.0
*/
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

// Implementation: https://etherscan.io/address/0x8e764bE4288B842791989DB5b8ec067279829809#writeContract
interface ICurvePool {
    function exchange(
        int128 i,
        int128 j,
        uint256 dx,
        uint256 min_dy
    ) external payable returns (uint256);

    function get_dy(
        int128 i,
        int128 j,
        uint256 dx
    ) external view returns (uint256);
}

File 41 of 42 : ISwapRouter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;


/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter {
    struct ExactInputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactInpuSingleParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

    struct ExactInputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountIn;
        uint256 amountOutMinimum;
    }

    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
    /// @return amountOut The amount of the received token
    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

    struct ExactOutputSingleParams {
        address tokenIn;
        address tokenOut;
        uint24 fee;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
        uint160 sqrtPriceLimitX96;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another token
    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

    struct ExactOutputParams {
        bytes path;
        address recipient;
        uint256 deadline;
        uint256 amountOut;
        uint256 amountInMaximum;
    }

    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
    /// @return amountIn The amount of the input token
    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}

File 42 of 42 : IQuoter.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

/// @title Quoter Interface
/// @notice Supports quoting the calculated amounts from exact input or exact output swaps
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
/// to compute the result. They are also not gas efficient and should not be called on-chain.
interface IQuoter {
    /// @notice Returns the amount out received for a given exact input swap without executing the swap
    /// @param path The path of the swap, i.e. each token pair and the pool fee
    /// @param amountIn The amount of the first token to swap
    /// @return amountOut The amount of the last token that would be received
    function quoteExactInput(bytes memory path, uint256 amountIn) external returns (uint256 amountOut);

    /// @notice Returns the amount out received for a given exact input but for a swap of a single pool
    /// @param tokenIn The token being swapped in
    /// @param tokenOut The token being swapped out
    /// @param fee The fee of the token pool to consider for the pair
    /// @param amountIn The desired input amount
    /// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
    /// @return amountOut The amount of `tokenOut` that would be received
    function quoteExactInputSingle(
        address tokenIn,
        address tokenOut,
        uint24 fee,
        uint256 amountIn,
        uint160 sqrtPriceLimitX96
    ) external returns (uint256 amountOut);

    /// @notice Returns the amount in required for a given exact output swap without executing the swap
    /// @param path The path of the swap, i.e. each token pair and the pool fee. Path must be provided in reverse order
    /// @param amountOut The amount of the last token to receive
    /// @return amountIn The amount of first token required to be paid
    function quoteExactOutput(bytes memory path, uint256 amountOut) external returns (uint256 amountIn);

    /// @notice Returns the amount in required to receive the given exact output amount but for a swap of a single pool
    /// @param tokenIn The token being swapped in
    /// @param tokenOut The token being swapped out
    /// @param fee The fee of the token pool to consider for the pair
    /// @param amountOut The desired output amount
    /// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
    /// @return amountIn The amount required as the input for the swap in order to receive `amountOut`
    function quoteExactOutputSingle(
        address tokenIn,
        address tokenOut,
        uint24 fee,
        uint256 amountOut,
        uint160 sqrtPriceLimitX96
    ) external returns (uint256 amountIn);
}

File 43 of 42 : IUniswapV2Router01.sol
pragma solidity >=0.6.2;

interface IUniswapV2Router01 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);

    function addLiquidity(
        address tokenA,
        address tokenB,
        uint amountADesired,
        uint amountBDesired,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB, uint liquidity);
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
    function removeLiquidity(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETH(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external returns (uint amountToken, uint amountETH);
    function removeLiquidityWithPermit(
        address tokenA,
        address tokenB,
        uint liquidity,
        uint amountAMin,
        uint amountBMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountA, uint amountB);
    function removeLiquidityETHWithPermit(
        address token,
        uint liquidity,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline,
        bool approveMax, uint8 v, bytes32 r, bytes32 s
    ) external returns (uint amountToken, uint amountETH);
    function swapExactTokensForTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapTokensForExactTokens(
        uint amountOut,
        uint amountInMax,
        address[] calldata path,
        address to,
        uint deadline
    ) external returns (uint[] memory amounts);
    function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);
    function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
        external
        returns (uint[] memory amounts);
    function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
        external
        payable
        returns (uint[] memory amounts);

    function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
    function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
    function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
    function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
    function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {
    "contracts/exchangeIssuance/DEXAdapter.sol": {
      "DEXAdapter": "0xbb02bcce1bdcc0b07e7870346d8b2ad9397d0fac"
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"components":[{"internalType":"address","name":"quickRouter","type":"address"},{"internalType":"address","name":"sushiRouter","type":"address"},{"internalType":"address","name":"uniV3Router","type":"address"},{"internalType":"address","name":"uniV3Quoter","type":"address"},{"internalType":"address","name":"curveAddressProvider","type":"address"},{"internalType":"address","name":"curveCalculator","type":"address"},{"internalType":"address","name":"weth","type":"address"}],"internalType":"struct DEXAdapter.Addresses","name":"_dexAddresses","type":"tuple"},{"internalType":"contract IController","name":"_setController","type":"address"},{"internalType":"contract IDebtIssuanceModule","name":"_debtIssuanceModule","type":"address"},{"internalType":"contract ICompoundLeverageModule","name":"_compoundLeverageModule","type":"address"},{"internalType":"address","name":"_aaveAddressProvider","type":"address"},{"internalType":"address","name":"_cEther","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"indexed":true,"internalType":"address","name":"_inputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amountInputToken","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amountSetIssued","type":"uint256"}],"name":"FlashMint","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"indexed":true,"internalType":"address","name":"_outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amountSetRedeemed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amountOutputToken","type":"uint256"}],"name":"FlashRedeem","type":"event"},{"inputs":[],"name":"ADDRESSES_PROVIDER","outputs":[{"internalType":"contract ILendingPoolAddressesProviderV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LENDING_POOL","outputs":[{"internalType":"contract ILendingPoolV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ROUNDING_ERROR_MARGIN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"addresses","outputs":[{"internalType":"address","name":"quickRouter","type":"address"},{"internalType":"address","name":"sushiRouter","type":"address"},{"internalType":"address","name":"uniV3Router","type":"address"},{"internalType":"address","name":"uniV3Quoter","type":"address"},{"internalType":"address","name":"curveAddressProvider","type":"address"},{"internalType":"address","name":"curveCalculator","type":"address"},{"internalType":"address","name":"weth","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"}],"name":"approveSetToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"_token","type":"address"}],"name":"approveToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"_tokens","type":"address[]"}],"name":"approveTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cEtherAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"compoundLeverageModule","outputs":[{"internalType":"contract ICompoundLeverageModule","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"debtIssuanceModule","outputs":[{"internalType":"contract IDebtIssuanceModule","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"premiums","type":"uint256[]"},{"internalType":"address","name":"initiator","type":"address"},{"internalType":"bytes","name":"params","type":"bytes"}],"name":"executeOperation","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_setAmount","type":"uint256"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataDebtForCollateral","type":"tuple"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataInputToken","type":"tuple"}],"name":"getIssueExactSet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_setAmount","type":"uint256"},{"internalType":"bool","name":"_isMint","type":"bool"}],"name":"getLeveragedTokenData","outputs":[{"components":[{"internalType":"address","name":"collateralCToken","type":"address"},{"internalType":"uint256","name":"cTokenAmount","type":"uint256"},{"internalType":"address","name":"collateralToken","type":"address"},{"internalType":"uint256","name":"collateralAmount","type":"uint256"},{"internalType":"address","name":"debtToken","type":"address"},{"internalType":"uint256","name":"debtAmount","type":"uint256"}],"internalType":"struct FlashMintLeveragedForCompound.LeveragedTokenData","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_setAmount","type":"uint256"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataCollateralForDebt","type":"tuple"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataOutputToken","type":"tuple"}],"name":"getRedeemExactSet","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_setAmount","type":"uint256"},{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"uint256","name":"_maxAmountInputToken","type":"uint256"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataDebtForCollateral","type":"tuple"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataInputToken","type":"tuple"}],"name":"issueExactSetFromERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_setAmount","type":"uint256"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataDebtForCollateral","type":"tuple"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataInputToken","type":"tuple"}],"name":"issueExactSetFromETH","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_setAmount","type":"uint256"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"_minAmountOutputToken","type":"uint256"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataCollateralForDebt","type":"tuple"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataOutputToken","type":"tuple"}],"name":"redeemExactSetForERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_setAmount","type":"uint256"},{"internalType":"uint256","name":"_minAmountOutputToken","type":"uint256"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataCollateralForDebt","type":"tuple"},{"components":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint24[]","name":"fees","type":"uint24[]"},{"internalType":"address","name":"pool","type":"address"},{"internalType":"enum DEXAdapter.Exchange","name":"exchange","type":"uint8"}],"internalType":"struct DEXAdapter.SwapData","name":"_swapDataOutputToken","type":"tuple"}],"name":"redeemExactSetForETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"setController","outputs":[{"internalType":"contract IController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

6101406040523480156200001257600080fd5b5060405162004acb38038062004acb8339810160408190526200003591620001de565b816001600081905550806001600160a01b03166080816001600160a01b031660601b81525050806001600160a01b0316630261bf8b6040518163ffffffff1660e01b815260040160206040518083038186803b1580156200009557600080fd5b505afa158015620000aa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620000d09190620001b8565b606090811b6001600160601b031990811660a090815297821b811660e05295811b86166101005293841b851661012052508551600180546001600160a01b03199081166001600160a01b0393841617909155602088015160028054831691841691909117905560408801516003805483169184169190911790558785015160048054831691841691909117905560808801516005805483169184169190911790559587015160068054881691831691909117905560c09687015160078054909716911617909455509190911b1690526200032e565b8051620001b28162000315565b92915050565b600060208284031215620001ca578081fd5b8151620001d78162000315565b9392505050565b600080600080600080868803610180811215620001f9578283fd5b60e081121562000207578283fd5b5060405160e081016001600160401b038111828210171562000227578384fd5b604052620002368989620001a5565b8152620002478960208a01620001a5565b60208201526200025b8960408a01620001a5565b60408201526200026f8960608a01620001a5565b6060820152620002838960808a01620001a5565b6080820152620002978960a08a01620001a5565b60a0820152620002ab8960c08a01620001a5565b60c08201529550620002c18860e08901620001a5565b9450620002d3886101008901620001a5565b9350620002e5886101208901620001a5565b9250620002f7886101408901620001a5565b915062000309886101608901620001a5565b90509295509295509295565b6001600160a01b03811681146200032b57600080fd5b50565b60805160601c60a05160601c60c05160601c60e05160601c6101005160601c6101205160601c614700620003cb600039806103fb52806105e552806108e05280610c0a528061119b52508061082e5280610f83528061145e528061150c5280611b065280611cc6525080610637525080610b8252806117785250806106665280610852528061115852806113b052508061037352506147006000f3fe6080604052600436106101185760003560e01c8063ac43070b116100a0578063c58bc7e011610064578063c58bc7e0146102e1578063d1d719ef14610301578063da0321cd14610321578063de836acf14610349578063f875572d1461035e5761011f565b8063ac43070b14610257578063af6f220a14610277578063b4dcfc771461028c578063b7711c63146102a1578063c4ba5db2146102c15761011f565b80637452ed1e116100e75780637452ed1e146101b357806380b2edd8146101e0578063848af32d146102005780638b2704ec14610215578063920f5c841461022a5761011f565b80630542975c14610124578063590c81c51461014f57806364718c1d1461017157806365dc803a1461019e5761011f565b3661011f57005b600080fd5b34801561013057600080fd5b50610139610371565b6040516101469190613da9565b60405180910390f35b34801561015b57600080fd5b5061016f61016a366004613802565b610395565b005b34801561017d57600080fd5b5061019161018c3660046138db565b6103e1565b60405161014691906145d3565b3480156101aa57600080fd5b506101396105e3565b3480156101bf57600080fd5b506101d36101ce36600461389a565b610607565b60405161014691906145c5565b3480156101ec57600080fd5b5061016f6101fb3660046137e6565b610624565b34801561020c57600080fd5b50610191610630565b34801561022157600080fd5b50610139610635565b34801561023657600080fd5b5061024a610245366004613634565b610659565b6040516101469190613eb8565b34801561026357600080fd5b5061016f61027236600461373a565b6107f8565b34801561028357600080fd5b5061013961082c565b34801561029857600080fd5b50610139610850565b3480156102ad57600080fd5b5061016f6102bc3660046137e6565b610874565b3480156102cd57600080fd5b506101916102dc3660046138db565b6108c6565b3480156102ed57600080fd5b5061016f6102fc366004613958565b610ac1565b34801561030d57600080fd5b5061016f61031c366004613802565b610b11565b34801561032d57600080fd5b50610336610b47565b6040516101469796959493929190613de1565b34801561035557600080fd5b50610139610b80565b61016f61036c3660046138db565b610ba4565b7f000000000000000000000000000000000000000000000000000000000000000081565b600260005414156103c15760405162461bcd60e51b81526004016103b8906143d3565b60405180910390fd5b60026000556103d4868686868686610bf3565b5050600160005550505050565b6040516367ff2f4160e11b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063cffe5e8290610433908890600190600401613ec3565b600060405180830381600087803b15801561044d57600080fd5b505af1158015610461573d6000803e3d6000fd5b5050505061046d61304c565b61047986866000610db3565b9050600061049c670de3e93f3bb040008360a00151610e8390919063ffffffff16565b9050600073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac63f943b31e600188856040518463ffffffff1660e01b81526004016104dc93929190614439565b60206040518083038186803b1580156104f457600080fd5b505af4158015610508573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052c9190613ae2565b90506000610547828560600151610eb690919063ffffffff16565b6040516301fae87160e61b815290915073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac90637eba1c4090610586906001908a908690600401614439565b60206040518083038186803b15801561059e57600080fd5b505af41580156105b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d69190613ae2565b9998505050505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b61060f61304c565b61061a848484610ede565b90505b9392505050565b61062d81610f5f565b50565b600281565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146106a35760405162461bcd60e51b81526004016103b89061425b565b6001600160a01b03831630146106cb5760405162461bcd60e51b81526004016103b890613f8f565b85516001146106ec5760405162461bcd60e51b81526004016103b8906142d7565b845160011461070d5760405162461bcd60e51b81526004016103b890614069565b835160011461072e5760405162461bcd60e51b81526004016103b890613f58565b61073661309d565b8280602001905181019061074a91906139df565b90508060600151156107a35761079e8760008151811061076657fe5b60200260200101518760008151811061077b57fe5b60200260200101518760008151811061079057fe5b602002602001015184611001565b6107eb565b6107eb876000815181106107b357fe5b6020026020010151876000815181106107c857fe5b6020026020010151876000815181106107dd57fe5b602002602001015184611065565b5060019695505050505050565b60005b81518110156108285761082082828151811061081357fe5b6020026020010151610f5f565b6001016107fb565b5050565b7f000000000000000000000000000000000000000000000000000000000000000081565b7f000000000000000000000000000000000000000000000000000000000000000081565b61087c61304c565b61089082670de0b6b3a76400006001610db3565b905061089f8160000151610f5f565b6108ac8160400151611134565b6108b98160800151610f5f565b6108288160800151611134565b6040516367ff2f4160e11b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063cffe5e82906109179088908590600401613ec3565b600060405180830381600087803b15801561093157600080fd5b505af1158015610945573d6000803e3d6000fd5b5050505061095161304c565b61095d86866001610db3565b90506000610980670de3e93f3bb040008360600151610e8390919063ffffffff16565b9050600073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac637eba1c406001888660a001516040518463ffffffff1660e01b81526004016109c493929190614439565b60206040518083038186803b1580156109dc57600080fd5b505af41580156109f0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a149190613ae2565b9050610a26828263ffffffff610eb616565b604051637ca1d98f60e11b815290925073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac9063f943b31e90610a659060019089908790600401614439565b60206040518083038186803b158015610a7d57600080fd5b505af4158015610a91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ab59190613ae2565b98975050505050505050565b60026000541415610ae45760405162461bcd60e51b81526004016103b8906143d3565b6002600055610b0585856000805160206146ab833981519152868686610bf3565b50506001600055505050565b60026000541415610b345760405162461bcd60e51b81526004016103b8906143d3565b60026000556103d4868686868686611184565b6001546002546003546004546005546006546007546001600160a01b039687169695861695948516949384169392831692918216911687565b7f000000000000000000000000000000000000000000000000000000000000000081565b60026000541415610bc75760405162461bcd60e51b81526004016103b8906143d3565b6002600055610be884846000805160206146ab833981519152348686611184565b505060016000555050565b6040516367ff2f4160e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063cffe5e8290610c42908990600190600401613ec3565b600060405180830381600087803b158015610c5c57600080fd5b505af1158015610c70573d6000803e3d6000fd5b50505050610c7c61304c565b610c8887876000610db3565b6040805160018082528183019092529192506060919060208083019080368337019050509050816080015181600081518110610cc057fe5b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526060918160200160208202803683370190505090508260a0015181600081518110610d0f57fe5b60200260200101818152505060606040518061012001604052808b6001600160a01b031681526020018a8152602001336001600160a01b03168152602001600015158152602001896001600160a01b0316815260200188815260200185815260200187815260200186815250604051602001610d8b9190614517565b6040516020818303038152906040529050610da783838361131c565b50505050505050505050565b610dbb61304c565b610dc361304c565b610dce85858561142c565b9050610dd8613117565b604051806020016040528083600001516001600160a01b031663bd6d894d6040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610e2257600080fd5b505af1158015610e36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5a9190613ae2565b81525090506000610e6f828460200151611859565b600201606085015250919695505050505050565b6000610ead670de0b6b3a7640000610ea1858563ffffffff6118ad16565b9063ffffffff6118e716565b90505b92915050565b600082821115610ed85760405162461bcd60e51b81526004016103b890613fd5565b50900390565b610ee661304c565b610eee61304c565b610ef985858561142c565b9050610f03613117565b604051806020016040528083600001516001600160a01b031663182df0f56040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4b57600080fd5b505afa158015610e36573d6000803e3d6000fd5b60405163095ea7b360e01b81526001600160a01b0382169063095ea7b390610faf907f00000000000000000000000000000000000000000000000000000000000000009060001990600401613e9f565b602060405180830381600087803b158015610fc957600080fd5b505af1158015610fdd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061082891906137ca565b60c081015151611012908585611919565b611029816000015182602001518360400151611aef565b60006110388584860184611b76565b90508160a0015181111561105e5760405162461bcd60e51b81526004016103b89061430e565b5050505050565b61107c816000015182602001518360400151611c94565b60c081015180516020820151604083015160609093015161109d9390611cff565b5060006110c3838501868460c00151606001518560c00151604001518660e00151611e8d565b905060006111068284600001518560200151866040015187608001518860a001518960c0015160400151600280028b60c0015160600151038b61010001516120db565b90508260a0015181101561112c5760405162461bcd60e51b81526004016103b890614191565b505050505050565b60405163095ea7b360e01b81526001600160a01b0382169063095ea7b390610faf907f00000000000000000000000000000000000000000000000000000000000000009060001990600401613e9f565b6040516367ff2f4160e11b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063cffe5e82906111d3908990600190600401613ec3565b600060405180830381600087803b1580156111ed57600080fd5b505af1158015611201573d6000803e3d6000fd5b5050505061120d61304c565b61121987876001610db3565b604080516001808252818301909252919250606091906020808301908036833701905050905081604001518160008151811061125157fe5b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526060918160200160208202803683370190505090508260600151816000815181106112a057fe5b60200260200101818152505060606040518061012001604052808b6001600160a01b031681526020018a8152602001336001600160a01b03168152602001600115158152602001896001600160a01b0316815260200188815260200185815260200187815260200186815250604051602001610d8b9190614517565b82513090819060009060609067ffffffffffffffff8111801561133e57600080fd5b50604051908082528060200260200182016040528015611368578160200160208202803683370190505b50905060005b875181101561139857600082828151811061138557fe5b602090810291909101015260010161136e565b5060405163ab9c4b5d60e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063ab9c4b5d906113f19087908b908b9087908a908d908b90600401613e22565b600060405180830381600087803b15801561140b57600080fd5b505af115801561141f573d6000803e3d6000fd5b5050505050505050505050565b61143461304c565b606080606061144161304c565b85156114f55760405163131e26b960e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063131e26b990611495908b908b90600401613e9f565b60006040518083038186803b1580156114ad57600080fd5b505afa1580156114c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526114e991908101906135b0565b9195509350915061159f565b6040516335c729db60e11b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636b8e53b690611543908b908b90600401613e9f565b60006040518083038186803b15801561155b57600080fd5b505afa15801561156f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261159791908101906135b0565b919550935091505b826000815181106115ac57fe5b6020026020010151600014806115d65750826001815181106115ca57fe5b60200260200101516000145b6115f25760405162461bcd60e51b81526004016103b890613f14565b816000815181106115ff57fe5b60200260200101516000148061162957508160018151811061161d57fe5b60200260200101516000145b6116455760405162461bcd60e51b81526004016103b89061410e565b60008360008151811061165457fe5b602002602001015111156116ee578360008151811061166f57fe5b60209081029190910101516001600160a01b031681528251839060009061169257fe5b6020026020010151816020018181525050836001815181106116b057fe5b60209081029190910101516001600160a01b031660808201528151829060019081106116d857fe5b60200260200101518160a0018181525050611776565b836001815181106116fb57fe5b60209081029190910101516001600160a01b0316815282518390600190811061172057fe5b60200260200101518160200181815250508360008151811061173e57fe5b60209081029190910101516001600160a01b031660808201528151829060009061176457fe5b60200260200101518160a00181815250505b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681600001516001600160a01b031614156117ca576007546001600160a01b0316604082015261184e565b80600001516001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561180757600080fd5b505afa15801561181b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183f9190613594565b6001600160a01b031660408201525b979650505050505050565b6000806000611866613117565b61187086866121bd565b9092509050600082600381111561188357fe5b1461189457509150600090506118a6565b600061189f82612225565b9350935050505b9250929050565b6000826118bc57506000610eb0565b828202828482816118c957fe5b0414610ead5760405162461bcd60e51b81526004016103b890614150565b60008082116119085760405162461bcd60e51b81526004016103b8906140d7565b81838161191157fe5b049392505050565b6007546001600160a01b03838116911614611a335760405163095ea7b360e01b81526001600160a01b0383169063095ea7b39061195c9086908590600401613e9f565b602060405180830381600087803b15801561197657600080fd5b505af115801561198a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ae91906137ca565b5060405163140e25ad60e31b81526001600160a01b0384169063a0712d68906119db9084906004016145d3565b602060405180830381600087803b1580156119f557600080fd5b505af1158015611a09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a2d9190613ae2565b50611aea565b600754604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90611a639084906004016145d3565b600060405180830381600087803b158015611a7d57600080fd5b505af1158015611a91573d6000803e3d6000fd5b50505050826001600160a01b0316631249c58b826040518263ffffffff1660e01b81526004016000604051808303818588803b158015611ad057600080fd5b505af1158015611ae4573d6000803e3d6000fd5b50505050505b505050565b6040516336bc7a3d60e11b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690636d78f47a90611b3f90869086908690600401613ede565b600060405180830381600087803b158015611b5957600080fd5b505af1158015611b6d573d6000803e3d6000fd5b50505050505050565b600080611b99858460c00151608001518560c0015160a001518660e00151612234565b905060006002611baf868463ffffffff610eb616565b01905060006000805160206146ab8339815191526001600160a01b031685608001516001600160a01b03161415611c0157611bfa878387604001518860a00151896101000151612424565b9050611c23565b611c208783876040015188608001518960a001518a6101000151612542565b90505b84608001516001600160a01b031685600001516001600160a01b031686604001516001600160a01b03167f9c1558194024d73db1b6fc2739c3070cacc4598122100dd6f7d3a3dd8cee5f36848960200151604051611c829291906145dc565b60405180910390a49695505050505050565b611caf6001600160a01b03841682308563ffffffff6126a716565b604051635c833bfd60e01b81526001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690635c833bfd90611b3f90869086903090600401613ede565b60075460009081906001600160a01b03858116911614611d9e5760405163db006a7560e01b81526001600160a01b0387169063db006a7590611d459088906004016145d3565b602060405180830381600087803b158015611d5f57600080fd5b505af1158015611d73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d979190613ae2565b9050611e84565b60405163db006a7560e01b81526001600160a01b0387169063db006a7590611dca9088906004016145d3565b602060405180830381600087803b158015611de457600080fd5b505af1158015611df8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e1c9190613ae2565b60075460408051630d0e30db60e41b815290519293506001600160a01b039091169163d0e30db091600119870191600480830192600092919082900301818588803b158015611e6a57600080fd5b505af1158015611e7e573d6000803e3d6000fd5b50505050505b95945050505050565b600081600001518386806001600160a01b0316826001600160a01b031614611feb57816001600160a01b031683600081518110611ec657fe5b60200260200101516001600160a01b03161480611f2e57506007546001600160a01b038381169116148015611f2e57506000805160206146ab8339815191526001600160a01b031683600081518110611f1b57fe5b60200260200101516001600160a01b0316145b611f4a5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b031683600185510381518110611f6457fe5b60200260200101516001600160a01b03161480611fcf57506007546001600160a01b038281169116148015611fcf57506000805160206146ab8339815191526001600160a01b031683600185510381518110611fbc57fe5b60200260200101516001600160a01b0316145b611feb5760405162461bcd60e51b81526004016103b890614218565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151636fd7d45f60e01b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92636fd7d45f9261207c9290918e918d918c910161440a565b60206040518083038186803b15801561209457600080fd5b505af41580156120a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cc9190613ae2565b93505b50505095945050505050565b6000898310156120fd5760405162461bcd60e51b81526004016103b890614292565b600061210f848c63ffffffff610eb616565b905060006001600160a01b0388166000805160206146ab83398151915214156121465761213f86838b8a88612705565b9050612157565b61215486838b8b8b896128fc565b90505b876001600160a01b03168b6001600160a01b03168a6001600160a01b03167f846f5655f4f8fa6ef5e4ad493e284e34854a83d000836d0493800c259ea970658d856040516121a69291906145dc565b60405180910390a49b9a5050505050505050505050565b60006121c7613117565b6000806121d8866000015186612963565b909250905060008260038111156121eb57fe5b1461220a575060408051602081019091526000815290925090506118a6565b60408051602081019091529081526000969095509350505050565b51670de0b6b3a7640000900490565b600081600001518486806001600160a01b0316826001600160a01b03161461239257816001600160a01b03168360008151811061226d57fe5b60200260200101516001600160a01b031614806122d557506007546001600160a01b0383811691161480156122d557506000805160206146ab8339815191526001600160a01b0316836000815181106122c257fe5b60200260200101516001600160a01b0316145b6122f15760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b03168360018551038151811061230b57fe5b60200260200101516001600160a01b0316148061237657506007546001600160a01b03828116911614801561237657506000805160206146ab8339815191526001600160a01b03168360018551038151811061236357fe5b60200260200101516001600160a01b0316145b6123925760405162461bcd60e51b81526004016103b890614218565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151630355f53b60e31b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92631aafa9d892610a659290918b916000918c910161440a565b60075460408051630d0e30db60e41b815290516000926001600160a01b03169163d0e30db0918691600480820192879290919082900301818588803b15801561246c57600080fd5b505af1158015612480573d6000803e3d6000fd5b5050600754600093506124a3925089915088906001600160a01b031687876129a2565b9050808411156125385760006124bf858363ffffffff610eb616565b600754604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d906124f09084906004016145d3565b600060405180830381600087803b15801561250a57600080fd5b505af115801561251e573d6000803e3d6000fd5b50612536925050506001600160a01b03871682612bb3565b505b9695505050505050565b6000866001600160a01b0316846001600160a01b0316141561257057612569878787612c4f565b5084612538565b6040516323b872dd60e01b81526001600160a01b038516906323b872dd906125a090889030908890600401613dbd565b602060405180830381600087803b1580156125ba57600080fd5b505af11580156125ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125f291906137ca565b50600061260288888787876129a2565b90508381101561184e576001600160a01b03851663a9059cbb8761262c878563ffffffff610eb616565b6040518363ffffffff1660e01b8152600401612649929190613e9f565b602060405180830381600087803b15801561266357600080fd5b505af1158015612677573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061269b91906137ca565b50979650505050505050565b6126ff846323b872dd60e01b8585856040516024016126c893929190613dbd565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612c70565b50505050565b80516007546000919087906001600160a01b03908116908216811461286057816001600160a01b03168360008151811061273b57fe5b60200260200101516001600160a01b031614806127a357506007546001600160a01b0383811691161480156127a357506000805160206146ab8339815191526001600160a01b03168360008151811061279057fe5b60200260200101516001600160a01b0316145b6127bf5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b0316836001855103815181106127d957fe5b60200260200101516001600160a01b0316148061284457506007546001600160a01b03828116911614801561284457506000805160206146ab8339815191526001600160a01b03168360018551038151811061283157fe5b60200260200101516001600160a01b0316145b6128605760405162461bcd60e51b81526004016103b890614218565b60075460009061287e908b908b906001600160a01b03168a8a612cff565b905080156120cc57600754604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d906128b69084906004016145d3565b600060405180830381600087803b1580156128d057600080fd5b505af11580156128e4573d6000803e3d6000fd5b506120cc925050506001600160a01b03891682612bb3565b6000866001600160a01b0316846001600160a01b0316141561292357612569878787612eee565b60006129328888878787612cff565b60405163a9059cbb60e01b81529091506001600160a01b0386169063a9059cbb906126499089908590600401613e9f565b60008083612976575060009050806118a6565b8383028385828161298357fe5b0414612997575060029150600090506118a6565b6000925090506118a6565b600081600001518487806001600160a01b0316826001600160a01b031614612b0057816001600160a01b0316836000815181106129db57fe5b60200260200101516001600160a01b03161480612a4357506007546001600160a01b038381169116148015612a4357506000805160206146ab8339815191526001600160a01b031683600081518110612a3057fe5b60200260200101516001600160a01b0316145b612a5f5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b031683600185510381518110612a7957fe5b60200260200101516001600160a01b03161480612ae457506007546001600160a01b038281169116148015612ae457506000805160206146ab8339815191526001600160a01b031683600185510381518110612ad157fe5b60200260200101516001600160a01b0316145b612b005760405162461bcd60e51b81526004016103b890614218565b866001600160a01b0316896001600160a01b03161415612b22578793506120cf565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151636fd7d45f60e01b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92636fd7d45f9261207c9290918d918c918c910161440a565b80471015612bd35760405162461bcd60e51b81526004016103b8906140a0565b6000826001600160a01b031682604051612bec90613da6565b60006040518083038185875af1925050503d8060008114612c29576040519150601f19603f3d011682016040523d82523d6000602084013e612c2e565b606091505b5050905080611aea5760405162461bcd60e51b81526004016103b89061400c565b8115611aea57611aea6001600160a01b03841682308563ffffffff6126a716565b6060612cc5826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612f6e9092919063ffffffff16565b805190915015611aea5780806020019051810190612ce391906137ca565b611aea5760405162461bcd60e51b81526004016103b890614389565b600081600001518685806001600160a01b0316826001600160a01b031614612e5d57816001600160a01b031683600081518110612d3857fe5b60200260200101516001600160a01b03161480612da057506007546001600160a01b038381169116148015612da057506000805160206146ab8339815191526001600160a01b031683600081518110612d8d57fe5b60200260200101516001600160a01b0316145b612dbc5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b031683600185510381518110612dd657fe5b60200260200101516001600160a01b03161480612e4157506007546001600160a01b038281169116148015612e4157506000805160206146ab8339815191526001600160a01b031683600185510381518110612e2e57fe5b60200260200101516001600160a01b0316145b612e5d5760405162461bcd60e51b81526004016103b890614218565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151630355f53b60e31b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92631aafa9d89261207c9290918d918c918c910161440a565b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb90612f1c9084908690600401613e9f565b602060405180830381600087803b158015612f3657600080fd5b505af1158015612f4a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ff91906137ca565b606061061a848460008585612f828561300d565b612f9e5760405162461bcd60e51b81526004016103b890614352565b60006060866001600160a01b03168587604051612fbb9190613d8a565b60006040518083038185875af1925050503d8060008114612ff8576040519150601f19603f3d011682016040523d82523d6000602084013e612ffd565b606091505b509150915061184e828286613013565b3b151590565b6060831561302257508161061d565b8251156130325782518084602001fd5b8160405162461bcd60e51b81526004016103b89190613f01565b6040518060c0016040528060006001600160a01b031681526020016000815260200160006001600160a01b031681526020016000815260200160006001600160a01b03168152602001600081525090565b60405180610120016040528060006001600160a01b031681526020016000815260200160006001600160a01b0316815260200160001515815260200160006001600160a01b03168152602001600081526020016130f861304c565b815260200161310561312a565b815260200161311261312a565b905290565b6040518060200160405280600081525090565b6040518060800160405280606081526020016060815260200160006001600160a01b031681526020016000600481111561311257fe5b8035610eb081614669565b8051610eb081614669565b600082601f830112613186578081fd5b813561319961319482614611565b6145ea565b8181529150602080830190848101818402860182018710156131ba57600080fd5b60005b848110156131e25781356131d081614669565b845292820192908201906001016131bd565b505050505092915050565b600082601f8301126131fd578081fd5b815161320b61319482614611565b81815291506020808301908481018184028601820187101561322c57600080fd5b60005b848110156131e257815161324281614669565b8452928201929082019060010161322f565b600082601f830112613264578081fd5b813561327261319482614611565b81815291506020808301908481018184028601820187101561329357600080fd5b60005b848110156131e257813584529282019290820190600101613296565b600082601f8301126132c2578081fd5b81516132d061319482614611565b8181529150602080830190848101818402860182018710156132f157600080fd5b60005b848110156131e2578151845292820192908201906001016132f4565b8051610eb08161467e565b8035610eb08161468c565b8051610eb08161468c565b600060c08284031215613342578081fd5b61334c60c06145ea565b9050815161335981614669565b815260208281015190820152604082015161337381614669565b604082015260608281015190820152608082015161339081614669565b8060808301525060a082015160a082015292915050565b6000608082840312156133b8578081fd5b6133c260806145ea565b9050813567ffffffffffffffff808211156133dc57600080fd5b6133e885838601613176565b83526020915081840135818111156133ff57600080fd5b84019050601f8101851361341257600080fd5b803561342061319482614611565b818152838101908385018584028501860189101561343d57600080fd5b600094505b83851015613468576134548982613589565b835260019490940193918501918501613442565b50808587015250505050506134808360408401613160565b6040820152613492836060840161331b565b606082015292915050565b6000608082840312156134ae578081fd5b6134b860806145ea565b9050815167ffffffffffffffff808211156134d257600080fd5b6134de858386016131ed565b83526020915081840151818111156134f557600080fd5b84019050601f8101851361350857600080fd5b805161351661319482614611565b818152838101908385018584028501860189101561353357600080fd5b600094505b8385101561355f57805161354b81614699565b835260019490940193918501918501613538565b5080858701525050505050613577836040840161316b565b60408201526134928360608401613326565b8035610eb081614699565b6000602082840312156135a5578081fd5b8151610ead81614669565b6000806000606084860312156135c4578182fd5b835167ffffffffffffffff808211156135db578384fd5b6135e7878388016131ed565b945060208601519150808211156135fc578384fd5b613608878388016132b2565b9350604086015191508082111561361d578283fd5b5061362a868287016132b2565b9150509250925092565b600080600080600060a0868803121561364b578283fd5b853567ffffffffffffffff80821115613662578485fd5b61366e89838a01613176565b9650602091508188013581811115613684578586fd5b6136908a828b01613254565b9650506040880135818111156136a4578586fd5b6136b08a828b01613254565b95505060608801356136c181614669565b93506080880135818111156136d4578384fd5b8089018a601f8201126136e5578485fd5b80359150828211156136f5578485fd5b613707601f8301601f191685016145ea565b92508183528a8483830101111561371c578485fd5b81848201858501375081019091019190915293969295509093509190565b6000602080838503121561374c578182fd5b823567ffffffffffffffff811115613762578283fd5b80840185601f820112613773578384fd5b8035915061378361319483614611565b828152838101908285018585028401860189101561379f578687fd5b8693505b8484101561269b5780356137b681614669565b8352600193909301929185019185016137a3565b6000602082840312156137db578081fd5b8151610ead8161467e565b6000602082840312156137f7578081fd5b8135610ead81614669565b60008060008060008060c0878903121561381a578384fd5b863561382581614669565b955060208701359450604087013561383c81614669565b935060608701359250608087013567ffffffffffffffff8082111561385f578283fd5b61386b8a838b016133a7565b935060a0890135915080821115613880578283fd5b5061388d89828a016133a7565b9150509295509295509295565b6000806000606084860312156138ae578081fd5b83356138b981614669565b92506020840135915060408401356138d08161467e565b809150509250925092565b600080600080608085870312156138f0578182fd5b84356138fb81614669565b935060208501359250604085013567ffffffffffffffff8082111561391e578384fd5b61392a888389016133a7565b9350606087013591508082111561393f578283fd5b5061394c878288016133a7565b91505092959194509250565b600080600080600060a0868803121561396f578283fd5b853561397a81614669565b94506020860135935060408601359250606086013567ffffffffffffffff808211156139a4578283fd5b6139b089838a016133a7565b935060808801359150808211156139c5578283fd5b506139d2888289016133a7565b9150509295509295909350565b6000602082840312156139f0578081fd5b815167ffffffffffffffff80821115613a07578283fd5b8184016101c08187031215613a1a578384fd5b613a256101206145ea565b9250613a31868261316b565b835260208101516020840152613a4a866040830161316b565b6040840152613a5c8660608301613310565b6060840152613a6e866080830161316b565b608084015260a081015160a0840152613a8a8660c08301613331565b60c084015261018081015182811115613aa1578485fd5b613aad8782840161349d565b60e0850152506101a081015182811115613ac5578485fd5b613ad18782840161349d565b610100850152509195945050505050565b600060208284031215613af3578081fd5b5051919050565b6001600160a01b03169052565b6000815180845260208085019450808401835b83811015613b3f5781516001600160a01b031687529582019590820190600101613b1a565b509495945050505050565b6000815180845260208085019450808401835b83811015613b3f57815187529582019590820190600101613b5d565b15159052565b60008151808452613b9781602086016020860161463d565b601f01601f19169290920160200192915050565b60058110613bb557fe5b9052565b80516001600160a01b03908116835260208083015182169084015260408083015182169084015260608083015182169084015260808083015182169084015260a08281015182169084015260c09182015116910152565b80516001600160a01b03908116835260208083015190840152604080830151821690840152606080830151908401526080808301519091169083015260a090810151910152565b6000815160808452613c6c6080850182613b07565b6020848101518683038783015280518084529193508301918491908401905b80831015613cb057835162ffffff168252928401926001929092019190840190613c8b565b506040868101516001600160a01b031690880152606080870151945061253890880185613bab565b805160808084528151908401819052600091602091839160a08701919084015b81841015613d1f5780516001600160a01b0316835260019390930192918401918401613cf8565b505084830151868203878501528051808352859350908401918401905b80841015613d6157825162ffffff168252600193909301929184019190840190613d3c565b5060408601519350613d766040880185613afa565b606086015193506125386060880185613bab565b60008251613d9c81846020870161463d565b9190910192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03978816815295871660208701529386166040860152918516606085015284166080840152831660a083015290911660c082015260e00190565b600060018060a01b03808a16835260e06020840152613e4460e084018a613b07565b8381036040850152613e56818a613b4a565b8481036060860152613e68818a613b4a565b915050818716608085015283810360a0850152613e858187613b7f565b9250505061ffff831660c083015298975050505050505050565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b6001600160a01b039290921682521515602082015260400190565b6001600160a01b0393841681526020810192909252909116604082015260600190565b600060208252610ead6020830184613b7f565b60208082526024908201527f466c6173684d696e743a20544f4f204d414e592045515549545920504f534954604082015263494f4e5360e01b606082015260800190565b6020808252601c908201527f466c6173684d696e743a20544f4f204d414e59205052454d49554d5300000000604082015260600190565b60208082526026908201527f466c6173684d696e743a20494e56414c494420464c4153484c4f414e20494e496040820152652a24a0aa27a960d11b606082015260800190565b6020808252601e908201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604082015260600190565b6020808252603a908201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260408201527f6563697069656e74206d61792068617665207265766572746564000000000000606082015260800190565b6020808252601b908201527f466c6173684d696e743a20544f4f204d414e5920414d4f554e54530000000000604082015260600190565b6020808252601d908201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604082015260600190565b6020808252601a908201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604082015260600190565b60208082526022908201527f466c6173684d696e743a20544f4f204d414e59204445425420504f534954494f6040820152614e5360f01b606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526025908201527f466c6173684d696e743a20494e53554646494349454e54204f555450555420416040820152641353d5539560da1b606082015260800190565b60208082526022908201527f466c6173684d696e743a20494e5055545f544f4b454e5f4e4f545f494e5f50416040820152610a8960f31b606082015260800190565b60208082526023908201527f466c6173684d696e743a204f55545055545f544f4b454e5f4e4f545f494e5f50604082015262082a8960eb1b606082015260800190565b6020808252601c908201527f466c6173684d696e743a204c454e44494e4720504f4f4c204f4e4c5900000000604082015260600190565b60208082526025908201527f466c6173684d696e743a204f5645525350454e5420434f4c4c41544552414c206040820152642a27a5a2a760d91b606082015260800190565b6020808252601a908201527f466c6173684d696e743a20544f4f204d414e5920415353455453000000000000604082015260600190565b60208082526024908201527f466c6173684d696e743a20494e53554646494349454e5420494e50555420414d60408201526313d5539560e21b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60006101406144198388613bb9565b8560e0840152846101008401528061012084015261184e81840185613cd8565b60006101206144518361444c8854614631565b613afa565b61445e6001870154614631565b61446b6020850182613afa565b506144796002870154614631565b6144866040850182613afa565b506144946003870154614631565b6144a16060850182613afa565b506144af6004870154614631565b6144bc6080850182613afa565b506144ca6005870154614631565b6144d760a0850182613afa565b506144e56006870154614631565b6144f260c0850182613afa565b508060e084015261450581840186613cd8565b91505082610100830152949350505050565b60006020825261452b602083018451613afa565b6020830151604083015260408301516145476060840182613afa565b50606083015161455a6080840182613b79565b50608083015161456d60a0840182613afa565b5060a083015160c083015260c083015161458a60e0840182613c10565b5060e08301516101c0806101a08501526145a86101e0850183613c57565b610100860151858203601f19018387015292506125388184613c57565b60c08101610eb08284613c10565b90815260200190565b918252602082015260400190565b60405181810167ffffffffffffffff8111828210171561460957600080fd5b604052919050565b600067ffffffffffffffff821115614627578081fd5b5060209081020190565b6001600160a01b031690565b60005b83811015614658578181015183820152602001614640565b838111156126ff5750506000910152565b6001600160a01b038116811461062d57600080fd5b801515811461062d57600080fd5b6005811061062d57600080fd5b62ffffff8116811461062d57600080fdfe000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeea26469706673582212208f20cff48f4a1e423403dbc8b38f7319632cfa7f4ab89a024b972d259cf79a1c64736f6c634300060a00330000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab60000000000000000000000000000000022d53366457f9d5e68ec105046fc4383000000000000000000000000c1db00a8e5ef7bfa476395cdbcc98235477cde4e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a4c8d221d8bb851f83aadd0223a8900a6921a34900000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb920000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f419000000000000000000000000b53c1a33016b2dc2ff3653530bff1848a515c8c50000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed5

Deployed Bytecode

0x6080604052600436106101185760003560e01c8063ac43070b116100a0578063c58bc7e011610064578063c58bc7e0146102e1578063d1d719ef14610301578063da0321cd14610321578063de836acf14610349578063f875572d1461035e5761011f565b8063ac43070b14610257578063af6f220a14610277578063b4dcfc771461028c578063b7711c63146102a1578063c4ba5db2146102c15761011f565b80637452ed1e116100e75780637452ed1e146101b357806380b2edd8146101e0578063848af32d146102005780638b2704ec14610215578063920f5c841461022a5761011f565b80630542975c14610124578063590c81c51461014f57806364718c1d1461017157806365dc803a1461019e5761011f565b3661011f57005b600080fd5b34801561013057600080fd5b50610139610371565b6040516101469190613da9565b60405180910390f35b34801561015b57600080fd5b5061016f61016a366004613802565b610395565b005b34801561017d57600080fd5b5061019161018c3660046138db565b6103e1565b60405161014691906145d3565b3480156101aa57600080fd5b506101396105e3565b3480156101bf57600080fd5b506101d36101ce36600461389a565b610607565b60405161014691906145c5565b3480156101ec57600080fd5b5061016f6101fb3660046137e6565b610624565b34801561020c57600080fd5b50610191610630565b34801561022157600080fd5b50610139610635565b34801561023657600080fd5b5061024a610245366004613634565b610659565b6040516101469190613eb8565b34801561026357600080fd5b5061016f61027236600461373a565b6107f8565b34801561028357600080fd5b5061013961082c565b34801561029857600080fd5b50610139610850565b3480156102ad57600080fd5b5061016f6102bc3660046137e6565b610874565b3480156102cd57600080fd5b506101916102dc3660046138db565b6108c6565b3480156102ed57600080fd5b5061016f6102fc366004613958565b610ac1565b34801561030d57600080fd5b5061016f61031c366004613802565b610b11565b34801561032d57600080fd5b50610336610b47565b6040516101469796959493929190613de1565b34801561035557600080fd5b50610139610b80565b61016f61036c3660046138db565b610ba4565b7f000000000000000000000000b53c1a33016b2dc2ff3653530bff1848a515c8c581565b600260005414156103c15760405162461bcd60e51b81526004016103b8906143d3565b60405180910390fd5b60026000556103d4868686868686610bf3565b5050600160005550505050565b6040516367ff2f4160e11b81526000906001600160a01b037f0000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f419169063cffe5e8290610433908890600190600401613ec3565b600060405180830381600087803b15801561044d57600080fd5b505af1158015610461573d6000803e3d6000fd5b5050505061046d61304c565b61047986866000610db3565b9050600061049c670de3e93f3bb040008360a00151610e8390919063ffffffff16565b9050600073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac63f943b31e600188856040518463ffffffff1660e01b81526004016104dc93929190614439565b60206040518083038186803b1580156104f457600080fd5b505af4158015610508573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061052c9190613ae2565b90506000610547828560600151610eb690919063ffffffff16565b6040516301fae87160e61b815290915073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac90637eba1c4090610586906001908a908690600401614439565b60206040518083038186803b15801561059e57600080fd5b505af41580156105b2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d69190613ae2565b9998505050505050505050565b7f0000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f41981565b61060f61304c565b61061a848484610ede565b90505b9392505050565b61062d81610f5f565b50565b600281565b7f000000000000000000000000a4c8d221d8bb851f83aadd0223a8900a6921a34981565b6000336001600160a01b037f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a916146106a35760405162461bcd60e51b81526004016103b89061425b565b6001600160a01b03831630146106cb5760405162461bcd60e51b81526004016103b890613f8f565b85516001146106ec5760405162461bcd60e51b81526004016103b8906142d7565b845160011461070d5760405162461bcd60e51b81526004016103b890614069565b835160011461072e5760405162461bcd60e51b81526004016103b890613f58565b61073661309d565b8280602001905181019061074a91906139df565b90508060600151156107a35761079e8760008151811061076657fe5b60200260200101518760008151811061077b57fe5b60200260200101518760008151811061079057fe5b602002602001015184611001565b6107eb565b6107eb876000815181106107b357fe5b6020026020010151876000815181106107c857fe5b6020026020010151876000815181106107dd57fe5b602002602001015184611065565b5060019695505050505050565b60005b81518110156108285761082082828151811061081357fe5b6020026020010151610f5f565b6001016107fb565b5050565b7f00000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb9281565b7f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a981565b61087c61304c565b61089082670de0b6b3a76400006001610db3565b905061089f8160000151610f5f565b6108ac8160400151611134565b6108b98160800151610f5f565b6108288160800151611134565b6040516367ff2f4160e11b81526000906001600160a01b037f0000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f419169063cffe5e82906109179088908590600401613ec3565b600060405180830381600087803b15801561093157600080fd5b505af1158015610945573d6000803e3d6000fd5b5050505061095161304c565b61095d86866001610db3565b90506000610980670de3e93f3bb040008360600151610e8390919063ffffffff16565b9050600073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac637eba1c406001888660a001516040518463ffffffff1660e01b81526004016109c493929190614439565b60206040518083038186803b1580156109dc57600080fd5b505af41580156109f0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a149190613ae2565b9050610a26828263ffffffff610eb616565b604051637ca1d98f60e11b815290925073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac9063f943b31e90610a659060019089908790600401614439565b60206040518083038186803b158015610a7d57600080fd5b505af4158015610a91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ab59190613ae2565b98975050505050505050565b60026000541415610ae45760405162461bcd60e51b81526004016103b8906143d3565b6002600055610b0585856000805160206146ab833981519152868686610bf3565b50506001600055505050565b60026000541415610b345760405162461bcd60e51b81526004016103b8906143d3565b60026000556103d4868686868686611184565b6001546002546003546004546005546006546007546001600160a01b039687169695861695948516949384169392831692918216911687565b7f0000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed581565b60026000541415610bc75760405162461bcd60e51b81526004016103b8906143d3565b6002600055610be884846000805160206146ab833981519152348686611184565b505060016000555050565b6040516367ff2f4160e11b81526001600160a01b037f0000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f419169063cffe5e8290610c42908990600190600401613ec3565b600060405180830381600087803b158015610c5c57600080fd5b505af1158015610c70573d6000803e3d6000fd5b50505050610c7c61304c565b610c8887876000610db3565b6040805160018082528183019092529192506060919060208083019080368337019050509050816080015181600081518110610cc057fe5b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526060918160200160208202803683370190505090508260a0015181600081518110610d0f57fe5b60200260200101818152505060606040518061012001604052808b6001600160a01b031681526020018a8152602001336001600160a01b03168152602001600015158152602001896001600160a01b0316815260200188815260200185815260200187815260200186815250604051602001610d8b9190614517565b6040516020818303038152906040529050610da783838361131c565b50505050505050505050565b610dbb61304c565b610dc361304c565b610dce85858561142c565b9050610dd8613117565b604051806020016040528083600001516001600160a01b031663bd6d894d6040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610e2257600080fd5b505af1158015610e36573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e5a9190613ae2565b81525090506000610e6f828460200151611859565b600201606085015250919695505050505050565b6000610ead670de0b6b3a7640000610ea1858563ffffffff6118ad16565b9063ffffffff6118e716565b90505b92915050565b600082821115610ed85760405162461bcd60e51b81526004016103b890613fd5565b50900390565b610ee661304c565b610eee61304c565b610ef985858561142c565b9050610f03613117565b604051806020016040528083600001516001600160a01b031663182df0f56040518163ffffffff1660e01b815260040160206040518083038186803b158015610f4b57600080fd5b505afa158015610e36573d6000803e3d6000fd5b60405163095ea7b360e01b81526001600160a01b0382169063095ea7b390610faf907f00000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb929060001990600401613e9f565b602060405180830381600087803b158015610fc957600080fd5b505af1158015610fdd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061082891906137ca565b60c081015151611012908585611919565b611029816000015182602001518360400151611aef565b60006110388584860184611b76565b90508160a0015181111561105e5760405162461bcd60e51b81526004016103b89061430e565b5050505050565b61107c816000015182602001518360400151611c94565b60c081015180516020820151604083015160609093015161109d9390611cff565b5060006110c3838501868460c00151606001518560c00151604001518660e00151611e8d565b905060006111068284600001518560200151866040015187608001518860a001518960c0015160400151600280028b60c0015160600151038b61010001516120db565b90508260a0015181101561112c5760405162461bcd60e51b81526004016103b890614191565b505050505050565b60405163095ea7b360e01b81526001600160a01b0382169063095ea7b390610faf907f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a99060001990600401613e9f565b6040516367ff2f4160e11b81526001600160a01b037f0000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f419169063cffe5e82906111d3908990600190600401613ec3565b600060405180830381600087803b1580156111ed57600080fd5b505af1158015611201573d6000803e3d6000fd5b5050505061120d61304c565b61121987876001610db3565b604080516001808252818301909252919250606091906020808301908036833701905050905081604001518160008151811061125157fe5b6001600160a01b0392909216602092830291909101909101526040805160018082528183019092526060918160200160208202803683370190505090508260600151816000815181106112a057fe5b60200260200101818152505060606040518061012001604052808b6001600160a01b031681526020018a8152602001336001600160a01b03168152602001600115158152602001896001600160a01b0316815260200188815260200185815260200187815260200186815250604051602001610d8b9190614517565b82513090819060009060609067ffffffffffffffff8111801561133e57600080fd5b50604051908082528060200260200182016040528015611368578160200160208202803683370190505b50905060005b875181101561139857600082828151811061138557fe5b602090810291909101015260010161136e565b5060405163ab9c4b5d60e01b81526001600160a01b037f0000000000000000000000007d2768de32b0b80b7a3454c06bdac94a69ddc7a9169063ab9c4b5d906113f19087908b908b9087908a908d908b90600401613e22565b600060405180830381600087803b15801561140b57600080fd5b505af115801561141f573d6000803e3d6000fd5b5050505050505050505050565b61143461304c565b606080606061144161304c565b85156114f55760405163131e26b960e01b81526001600160a01b037f00000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb92169063131e26b990611495908b908b90600401613e9f565b60006040518083038186803b1580156114ad57600080fd5b505afa1580156114c1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526114e991908101906135b0565b9195509350915061159f565b6040516335c729db60e11b81526001600160a01b037f00000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb921690636b8e53b690611543908b908b90600401613e9f565b60006040518083038186803b15801561155b57600080fd5b505afa15801561156f573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f1916820160405261159791908101906135b0565b919550935091505b826000815181106115ac57fe5b6020026020010151600014806115d65750826001815181106115ca57fe5b60200260200101516000145b6115f25760405162461bcd60e51b81526004016103b890613f14565b816000815181106115ff57fe5b60200260200101516000148061162957508160018151811061161d57fe5b60200260200101516000145b6116455760405162461bcd60e51b81526004016103b89061410e565b60008360008151811061165457fe5b602002602001015111156116ee578360008151811061166f57fe5b60209081029190910101516001600160a01b031681528251839060009061169257fe5b6020026020010151816020018181525050836001815181106116b057fe5b60209081029190910101516001600160a01b031660808201528151829060019081106116d857fe5b60200260200101518160a0018181525050611776565b836001815181106116fb57fe5b60209081029190910101516001600160a01b0316815282518390600190811061172057fe5b60200260200101518160200181815250508360008151811061173e57fe5b60209081029190910101516001600160a01b031660808201528151829060009061176457fe5b60200260200101518160a00181815250505b7f0000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed56001600160a01b031681600001516001600160a01b031614156117ca576007546001600160a01b0316604082015261184e565b80600001516001600160a01b0316636f307dc36040518163ffffffff1660e01b815260040160206040518083038186803b15801561180757600080fd5b505afa15801561181b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183f9190613594565b6001600160a01b031660408201525b979650505050505050565b6000806000611866613117565b61187086866121bd565b9092509050600082600381111561188357fe5b1461189457509150600090506118a6565b600061189f82612225565b9350935050505b9250929050565b6000826118bc57506000610eb0565b828202828482816118c957fe5b0414610ead5760405162461bcd60e51b81526004016103b890614150565b60008082116119085760405162461bcd60e51b81526004016103b8906140d7565b81838161191157fe5b049392505050565b6007546001600160a01b03838116911614611a335760405163095ea7b360e01b81526001600160a01b0383169063095ea7b39061195c9086908590600401613e9f565b602060405180830381600087803b15801561197657600080fd5b505af115801561198a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119ae91906137ca565b5060405163140e25ad60e31b81526001600160a01b0384169063a0712d68906119db9084906004016145d3565b602060405180830381600087803b1580156119f557600080fd5b505af1158015611a09573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a2d9190613ae2565b50611aea565b600754604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90611a639084906004016145d3565b600060405180830381600087803b158015611a7d57600080fd5b505af1158015611a91573d6000803e3d6000fd5b50505050826001600160a01b0316631249c58b826040518263ffffffff1660e01b81526004016000604051808303818588803b158015611ad057600080fd5b505af1158015611ae4573d6000803e3d6000fd5b50505050505b505050565b6040516336bc7a3d60e11b81526001600160a01b037f00000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb921690636d78f47a90611b3f90869086908690600401613ede565b600060405180830381600087803b158015611b5957600080fd5b505af1158015611b6d573d6000803e3d6000fd5b50505050505050565b600080611b99858460c00151608001518560c0015160a001518660e00151612234565b905060006002611baf868463ffffffff610eb616565b01905060006000805160206146ab8339815191526001600160a01b031685608001516001600160a01b03161415611c0157611bfa878387604001518860a00151896101000151612424565b9050611c23565b611c208783876040015188608001518960a001518a6101000151612542565b90505b84608001516001600160a01b031685600001516001600160a01b031686604001516001600160a01b03167f9c1558194024d73db1b6fc2739c3070cacc4598122100dd6f7d3a3dd8cee5f36848960200151604051611c829291906145dc565b60405180910390a49695505050505050565b611caf6001600160a01b03841682308563ffffffff6126a716565b604051635c833bfd60e01b81526001600160a01b037f00000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb921690635c833bfd90611b3f90869086903090600401613ede565b60075460009081906001600160a01b03858116911614611d9e5760405163db006a7560e01b81526001600160a01b0387169063db006a7590611d459088906004016145d3565b602060405180830381600087803b158015611d5f57600080fd5b505af1158015611d73573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d979190613ae2565b9050611e84565b60405163db006a7560e01b81526001600160a01b0387169063db006a7590611dca9088906004016145d3565b602060405180830381600087803b158015611de457600080fd5b505af1158015611df8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611e1c9190613ae2565b60075460408051630d0e30db60e41b815290519293506001600160a01b039091169163d0e30db091600119870191600480830192600092919082900301818588803b158015611e6a57600080fd5b505af1158015611e7e573d6000803e3d6000fd5b50505050505b95945050505050565b600081600001518386806001600160a01b0316826001600160a01b031614611feb57816001600160a01b031683600081518110611ec657fe5b60200260200101516001600160a01b03161480611f2e57506007546001600160a01b038381169116148015611f2e57506000805160206146ab8339815191526001600160a01b031683600081518110611f1b57fe5b60200260200101516001600160a01b0316145b611f4a5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b031683600185510381518110611f6457fe5b60200260200101516001600160a01b03161480611fcf57506007546001600160a01b038281169116148015611fcf57506000805160206146ab8339815191526001600160a01b031683600185510381518110611fbc57fe5b60200260200101516001600160a01b0316145b611feb5760405162461bcd60e51b81526004016103b890614218565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151636fd7d45f60e01b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92636fd7d45f9261207c9290918e918d918c910161440a565b60206040518083038186803b15801561209457600080fd5b505af41580156120a8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120cc9190613ae2565b93505b50505095945050505050565b6000898310156120fd5760405162461bcd60e51b81526004016103b890614292565b600061210f848c63ffffffff610eb616565b905060006001600160a01b0388166000805160206146ab83398151915214156121465761213f86838b8a88612705565b9050612157565b61215486838b8b8b896128fc565b90505b876001600160a01b03168b6001600160a01b03168a6001600160a01b03167f846f5655f4f8fa6ef5e4ad493e284e34854a83d000836d0493800c259ea970658d856040516121a69291906145dc565b60405180910390a49b9a5050505050505050505050565b60006121c7613117565b6000806121d8866000015186612963565b909250905060008260038111156121eb57fe5b1461220a575060408051602081019091526000815290925090506118a6565b60408051602081019091529081526000969095509350505050565b51670de0b6b3a7640000900490565b600081600001518486806001600160a01b0316826001600160a01b03161461239257816001600160a01b03168360008151811061226d57fe5b60200260200101516001600160a01b031614806122d557506007546001600160a01b0383811691161480156122d557506000805160206146ab8339815191526001600160a01b0316836000815181106122c257fe5b60200260200101516001600160a01b0316145b6122f15760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b03168360018551038151811061230b57fe5b60200260200101516001600160a01b0316148061237657506007546001600160a01b03828116911614801561237657506000805160206146ab8339815191526001600160a01b03168360018551038151811061236357fe5b60200260200101516001600160a01b0316145b6123925760405162461bcd60e51b81526004016103b890614218565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151630355f53b60e31b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92631aafa9d892610a659290918b916000918c910161440a565b60075460408051630d0e30db60e41b815290516000926001600160a01b03169163d0e30db0918691600480820192879290919082900301818588803b15801561246c57600080fd5b505af1158015612480573d6000803e3d6000fd5b5050600754600093506124a3925089915088906001600160a01b031687876129a2565b9050808411156125385760006124bf858363ffffffff610eb616565b600754604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d906124f09084906004016145d3565b600060405180830381600087803b15801561250a57600080fd5b505af115801561251e573d6000803e3d6000fd5b50612536925050506001600160a01b03871682612bb3565b505b9695505050505050565b6000866001600160a01b0316846001600160a01b0316141561257057612569878787612c4f565b5084612538565b6040516323b872dd60e01b81526001600160a01b038516906323b872dd906125a090889030908890600401613dbd565b602060405180830381600087803b1580156125ba57600080fd5b505af11580156125ce573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125f291906137ca565b50600061260288888787876129a2565b90508381101561184e576001600160a01b03851663a9059cbb8761262c878563ffffffff610eb616565b6040518363ffffffff1660e01b8152600401612649929190613e9f565b602060405180830381600087803b15801561266357600080fd5b505af1158015612677573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061269b91906137ca565b50979650505050505050565b6126ff846323b872dd60e01b8585856040516024016126c893929190613dbd565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152612c70565b50505050565b80516007546000919087906001600160a01b03908116908216811461286057816001600160a01b03168360008151811061273b57fe5b60200260200101516001600160a01b031614806127a357506007546001600160a01b0383811691161480156127a357506000805160206146ab8339815191526001600160a01b03168360008151811061279057fe5b60200260200101516001600160a01b0316145b6127bf5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b0316836001855103815181106127d957fe5b60200260200101516001600160a01b0316148061284457506007546001600160a01b03828116911614801561284457506000805160206146ab8339815191526001600160a01b03168360018551038151811061283157fe5b60200260200101516001600160a01b0316145b6128605760405162461bcd60e51b81526004016103b890614218565b60075460009061287e908b908b906001600160a01b03168a8a612cff565b905080156120cc57600754604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d906128b69084906004016145d3565b600060405180830381600087803b1580156128d057600080fd5b505af11580156128e4573d6000803e3d6000fd5b506120cc925050506001600160a01b03891682612bb3565b6000866001600160a01b0316846001600160a01b0316141561292357612569878787612eee565b60006129328888878787612cff565b60405163a9059cbb60e01b81529091506001600160a01b0386169063a9059cbb906126499089908590600401613e9f565b60008083612976575060009050806118a6565b8383028385828161298357fe5b0414612997575060029150600090506118a6565b6000925090506118a6565b600081600001518487806001600160a01b0316826001600160a01b031614612b0057816001600160a01b0316836000815181106129db57fe5b60200260200101516001600160a01b03161480612a4357506007546001600160a01b038381169116148015612a4357506000805160206146ab8339815191526001600160a01b031683600081518110612a3057fe5b60200260200101516001600160a01b0316145b612a5f5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b031683600185510381518110612a7957fe5b60200260200101516001600160a01b03161480612ae457506007546001600160a01b038281169116148015612ae457506000805160206146ab8339815191526001600160a01b031683600185510381518110612ad157fe5b60200260200101516001600160a01b0316145b612b005760405162461bcd60e51b81526004016103b890614218565b866001600160a01b0316896001600160a01b03161415612b22578793506120cf565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151636fd7d45f60e01b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92636fd7d45f9261207c9290918d918c918c910161440a565b80471015612bd35760405162461bcd60e51b81526004016103b8906140a0565b6000826001600160a01b031682604051612bec90613da6565b60006040518083038185875af1925050503d8060008114612c29576040519150601f19603f3d011682016040523d82523d6000602084013e612c2e565b606091505b5050905080611aea5760405162461bcd60e51b81526004016103b89061400c565b8115611aea57611aea6001600160a01b03841682308563ffffffff6126a716565b6060612cc5826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612f6e9092919063ffffffff16565b805190915015611aea5780806020019051810190612ce391906137ca565b611aea5760405162461bcd60e51b81526004016103b890614389565b600081600001518685806001600160a01b0316826001600160a01b031614612e5d57816001600160a01b031683600081518110612d3857fe5b60200260200101516001600160a01b03161480612da057506007546001600160a01b038381169116148015612da057506000805160206146ab8339815191526001600160a01b031683600081518110612d8d57fe5b60200260200101516001600160a01b0316145b612dbc5760405162461bcd60e51b81526004016103b8906141d6565b806001600160a01b031683600185510381518110612dd657fe5b60200260200101516001600160a01b03161480612e4157506007546001600160a01b038281169116148015612e4157506000805160206146ab8339815191526001600160a01b031683600185510381518110612e2e57fe5b60200260200101516001600160a01b0316145b612e5d5760405162461bcd60e51b81526004016103b890614218565b6040805160e0810182526001546001600160a01b03908116825260025481166020830152600354811682840152600480548216606084015260055482166080840152600654821660a084015260075490911660c08301529151630355f53b60e31b815273bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac92631aafa9d89261207c9290918d918c918c910161440a565b60405163a9059cbb60e01b81526001600160a01b0384169063a9059cbb90612f1c9084908690600401613e9f565b602060405180830381600087803b158015612f3657600080fd5b505af1158015612f4a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906126ff91906137ca565b606061061a848460008585612f828561300d565b612f9e5760405162461bcd60e51b81526004016103b890614352565b60006060866001600160a01b03168587604051612fbb9190613d8a565b60006040518083038185875af1925050503d8060008114612ff8576040519150601f19603f3d011682016040523d82523d6000602084013e612ffd565b606091505b509150915061184e828286613013565b3b151590565b6060831561302257508161061d565b8251156130325782518084602001fd5b8160405162461bcd60e51b81526004016103b89190613f01565b6040518060c0016040528060006001600160a01b031681526020016000815260200160006001600160a01b031681526020016000815260200160006001600160a01b03168152602001600081525090565b60405180610120016040528060006001600160a01b031681526020016000815260200160006001600160a01b0316815260200160001515815260200160006001600160a01b03168152602001600081526020016130f861304c565b815260200161310561312a565b815260200161311261312a565b905290565b6040518060200160405280600081525090565b6040518060800160405280606081526020016060815260200160006001600160a01b031681526020016000600481111561311257fe5b8035610eb081614669565b8051610eb081614669565b600082601f830112613186578081fd5b813561319961319482614611565b6145ea565b8181529150602080830190848101818402860182018710156131ba57600080fd5b60005b848110156131e25781356131d081614669565b845292820192908201906001016131bd565b505050505092915050565b600082601f8301126131fd578081fd5b815161320b61319482614611565b81815291506020808301908481018184028601820187101561322c57600080fd5b60005b848110156131e257815161324281614669565b8452928201929082019060010161322f565b600082601f830112613264578081fd5b813561327261319482614611565b81815291506020808301908481018184028601820187101561329357600080fd5b60005b848110156131e257813584529282019290820190600101613296565b600082601f8301126132c2578081fd5b81516132d061319482614611565b8181529150602080830190848101818402860182018710156132f157600080fd5b60005b848110156131e2578151845292820192908201906001016132f4565b8051610eb08161467e565b8035610eb08161468c565b8051610eb08161468c565b600060c08284031215613342578081fd5b61334c60c06145ea565b9050815161335981614669565b815260208281015190820152604082015161337381614669565b604082015260608281015190820152608082015161339081614669565b8060808301525060a082015160a082015292915050565b6000608082840312156133b8578081fd5b6133c260806145ea565b9050813567ffffffffffffffff808211156133dc57600080fd5b6133e885838601613176565b83526020915081840135818111156133ff57600080fd5b84019050601f8101851361341257600080fd5b803561342061319482614611565b818152838101908385018584028501860189101561343d57600080fd5b600094505b83851015613468576134548982613589565b835260019490940193918501918501613442565b50808587015250505050506134808360408401613160565b6040820152613492836060840161331b565b606082015292915050565b6000608082840312156134ae578081fd5b6134b860806145ea565b9050815167ffffffffffffffff808211156134d257600080fd5b6134de858386016131ed565b83526020915081840151818111156134f557600080fd5b84019050601f8101851361350857600080fd5b805161351661319482614611565b818152838101908385018584028501860189101561353357600080fd5b600094505b8385101561355f57805161354b81614699565b835260019490940193918501918501613538565b5080858701525050505050613577836040840161316b565b60408201526134928360608401613326565b8035610eb081614699565b6000602082840312156135a5578081fd5b8151610ead81614669565b6000806000606084860312156135c4578182fd5b835167ffffffffffffffff808211156135db578384fd5b6135e7878388016131ed565b945060208601519150808211156135fc578384fd5b613608878388016132b2565b9350604086015191508082111561361d578283fd5b5061362a868287016132b2565b9150509250925092565b600080600080600060a0868803121561364b578283fd5b853567ffffffffffffffff80821115613662578485fd5b61366e89838a01613176565b9650602091508188013581811115613684578586fd5b6136908a828b01613254565b9650506040880135818111156136a4578586fd5b6136b08a828b01613254565b95505060608801356136c181614669565b93506080880135818111156136d4578384fd5b8089018a601f8201126136e5578485fd5b80359150828211156136f5578485fd5b613707601f8301601f191685016145ea565b92508183528a8483830101111561371c578485fd5b81848201858501375081019091019190915293969295509093509190565b6000602080838503121561374c578182fd5b823567ffffffffffffffff811115613762578283fd5b80840185601f820112613773578384fd5b8035915061378361319483614611565b828152838101908285018585028401860189101561379f578687fd5b8693505b8484101561269b5780356137b681614669565b8352600193909301929185019185016137a3565b6000602082840312156137db578081fd5b8151610ead8161467e565b6000602082840312156137f7578081fd5b8135610ead81614669565b60008060008060008060c0878903121561381a578384fd5b863561382581614669565b955060208701359450604087013561383c81614669565b935060608701359250608087013567ffffffffffffffff8082111561385f578283fd5b61386b8a838b016133a7565b935060a0890135915080821115613880578283fd5b5061388d89828a016133a7565b9150509295509295509295565b6000806000606084860312156138ae578081fd5b83356138b981614669565b92506020840135915060408401356138d08161467e565b809150509250925092565b600080600080608085870312156138f0578182fd5b84356138fb81614669565b935060208501359250604085013567ffffffffffffffff8082111561391e578384fd5b61392a888389016133a7565b9350606087013591508082111561393f578283fd5b5061394c878288016133a7565b91505092959194509250565b600080600080600060a0868803121561396f578283fd5b853561397a81614669565b94506020860135935060408601359250606086013567ffffffffffffffff808211156139a4578283fd5b6139b089838a016133a7565b935060808801359150808211156139c5578283fd5b506139d2888289016133a7565b9150509295509295909350565b6000602082840312156139f0578081fd5b815167ffffffffffffffff80821115613a07578283fd5b8184016101c08187031215613a1a578384fd5b613a256101206145ea565b9250613a31868261316b565b835260208101516020840152613a4a866040830161316b565b6040840152613a5c8660608301613310565b6060840152613a6e866080830161316b565b608084015260a081015160a0840152613a8a8660c08301613331565b60c084015261018081015182811115613aa1578485fd5b613aad8782840161349d565b60e0850152506101a081015182811115613ac5578485fd5b613ad18782840161349d565b610100850152509195945050505050565b600060208284031215613af3578081fd5b5051919050565b6001600160a01b03169052565b6000815180845260208085019450808401835b83811015613b3f5781516001600160a01b031687529582019590820190600101613b1a565b509495945050505050565b6000815180845260208085019450808401835b83811015613b3f57815187529582019590820190600101613b5d565b15159052565b60008151808452613b9781602086016020860161463d565b601f01601f19169290920160200192915050565b60058110613bb557fe5b9052565b80516001600160a01b03908116835260208083015182169084015260408083015182169084015260608083015182169084015260808083015182169084015260a08281015182169084015260c09182015116910152565b80516001600160a01b03908116835260208083015190840152604080830151821690840152606080830151908401526080808301519091169083015260a090810151910152565b6000815160808452613c6c6080850182613b07565b6020848101518683038783015280518084529193508301918491908401905b80831015613cb057835162ffffff168252928401926001929092019190840190613c8b565b506040868101516001600160a01b031690880152606080870151945061253890880185613bab565b805160808084528151908401819052600091602091839160a08701919084015b81841015613d1f5780516001600160a01b0316835260019390930192918401918401613cf8565b505084830151868203878501528051808352859350908401918401905b80841015613d6157825162ffffff168252600193909301929184019190840190613d3c565b5060408601519350613d766040880185613afa565b606086015193506125386060880185613bab565b60008251613d9c81846020870161463d565b9190910192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03978816815295871660208701529386166040860152918516606085015284166080840152831660a083015290911660c082015260e00190565b600060018060a01b03808a16835260e06020840152613e4460e084018a613b07565b8381036040850152613e56818a613b4a565b8481036060860152613e68818a613b4a565b915050818716608085015283810360a0850152613e858187613b7f565b9250505061ffff831660c083015298975050505050505050565b6001600160a01b03929092168252602082015260400190565b901515815260200190565b6001600160a01b039290921682521515602082015260400190565b6001600160a01b0393841681526020810192909252909116604082015260600190565b600060208252610ead6020830184613b7f565b60208082526024908201527f466c6173684d696e743a20544f4f204d414e592045515549545920504f534954604082015263494f4e5360e01b606082015260800190565b6020808252601c908201527f466c6173684d696e743a20544f4f204d414e59205052454d49554d5300000000604082015260600190565b60208082526026908201527f466c6173684d696e743a20494e56414c494420464c4153484c4f414e20494e496040820152652a24a0aa27a960d11b606082015260800190565b6020808252601e908201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604082015260600190565b6020808252603a908201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260408201527f6563697069656e74206d61792068617665207265766572746564000000000000606082015260800190565b6020808252601b908201527f466c6173684d696e743a20544f4f204d414e5920414d4f554e54530000000000604082015260600190565b6020808252601d908201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604082015260600190565b6020808252601a908201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604082015260600190565b60208082526022908201527f466c6173684d696e743a20544f4f204d414e59204445425420504f534954494f6040820152614e5360f01b606082015260800190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526025908201527f466c6173684d696e743a20494e53554646494349454e54204f555450555420416040820152641353d5539560da1b606082015260800190565b60208082526022908201527f466c6173684d696e743a20494e5055545f544f4b454e5f4e4f545f494e5f50416040820152610a8960f31b606082015260800190565b60208082526023908201527f466c6173684d696e743a204f55545055545f544f4b454e5f4e4f545f494e5f50604082015262082a8960eb1b606082015260800190565b6020808252601c908201527f466c6173684d696e743a204c454e44494e4720504f4f4c204f4e4c5900000000604082015260600190565b60208082526025908201527f466c6173684d696e743a204f5645525350454e5420434f4c4c41544552414c206040820152642a27a5a2a760d91b606082015260800190565b6020808252601a908201527f466c6173684d696e743a20544f4f204d414e5920415353455453000000000000604082015260600190565b60208082526024908201527f466c6173684d696e743a20494e53554646494349454e5420494e50555420414d60408201526313d5539560e21b606082015260800190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60006101406144198388613bb9565b8560e0840152846101008401528061012084015261184e81840185613cd8565b60006101206144518361444c8854614631565b613afa565b61445e6001870154614631565b61446b6020850182613afa565b506144796002870154614631565b6144866040850182613afa565b506144946003870154614631565b6144a16060850182613afa565b506144af6004870154614631565b6144bc6080850182613afa565b506144ca6005870154614631565b6144d760a0850182613afa565b506144e56006870154614631565b6144f260c0850182613afa565b508060e084015261450581840186613cd8565b91505082610100830152949350505050565b60006020825261452b602083018451613afa565b6020830151604083015260408301516145476060840182613afa565b50606083015161455a6080840182613b79565b50608083015161456d60a0840182613afa565b5060a083015160c083015260c083015161458a60e0840182613c10565b5060e08301516101c0806101a08501526145a86101e0850183613c57565b610100860151858203601f19018387015292506125388184613c57565b60c08101610eb08284613c10565b90815260200190565b918252602082015260400190565b60405181810167ffffffffffffffff8111828210171561460957600080fd5b604052919050565b600067ffffffffffffffff821115614627578081fd5b5060209081020190565b6001600160a01b031690565b60005b83811015614658578181015183820152602001614640565b838111156126ff5750506000910152565b6001600160a01b038116811461062d57600080fd5b801515811461062d57600080fd5b6005811061062d57600080fd5b62ffffff8116811461062d57600080fdfe000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeea26469706673582212208f20cff48f4a1e423403dbc8b38f7319632cfa7f4ab89a024b972d259cf79a1c64736f6c634300060a0033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab60000000000000000000000000000000022d53366457f9d5e68ec105046fc4383000000000000000000000000c1db00a8e5ef7bfa476395cdbcc98235477cde4e000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a4c8d221d8bb851f83aadd0223a8900a6921a34900000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb920000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f419000000000000000000000000b53c1a33016b2dc2ff3653530bff1848a515c8c50000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed5

-----Decoded View---------------
Arg [0] : _dexAddresses (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [1] : _setController (address): 0xa4c8d221d8BB851f83aadd0223a8900A6921A349
Arg [2] : _debtIssuanceModule (address): 0x39F024d621367C044BacE2bf0Fb15Fb3612eCB92
Arg [3] : _compoundLeverageModule (address): 0x8d5174eD1dd217e240fDEAa52Eb7f4540b04F419
Arg [4] : _aaveAddressProvider (address): 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5
Arg [5] : _cEther (address): 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5

-----Encoded View---------------
12 Constructor Arguments found :
Arg [0] : 0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d
Arg [1] : 000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f
Arg [2] : 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
Arg [3] : 000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab6
Arg [4] : 0000000000000000000000000000000022d53366457f9d5e68ec105046fc4383
Arg [5] : 000000000000000000000000c1db00a8e5ef7bfa476395cdbcc98235477cde4e
Arg [6] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [7] : 000000000000000000000000a4c8d221d8bb851f83aadd0223a8900a6921a349
Arg [8] : 00000000000000000000000039f024d621367c044bace2bf0fb15fb3612ecb92
Arg [9] : 0000000000000000000000008d5174ed1dd217e240fdeaa52eb7f4540b04f419
Arg [10] : 000000000000000000000000b53c1a33016b2dc2ff3653530bff1848a515c8c5
Arg [11] : 0000000000000000000000004ddc2d193948926d02f9b1fe9e1daa0718270ed5


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.