ETH Price: $3,087.98 (-1.33%)
Gas: 2 Gwei

Contract

0x9DA9992b5d01BD0EFb1EE8310E8011dc837bd476
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Issue Exact Set ...161257312022-12-06 12:23:59530 days ago1670329439IN
Index Protocol: Notional Flash Mint
0 ETH0.0167808914.01468648
Issue Exact Set ...161257092022-12-06 12:19:35530 days ago1670329175IN
Index Protocol: Notional Flash Mint
0 ETH0.0239517417.13030548
Issue Exact Set ...161193642022-12-05 15:00:59531 days ago1670252459IN
Index Protocol: Notional Flash Mint
0 ETH0.0217728616.53868236
Issue Exact Set ...161193352022-12-05 14:55:11531 days ago1670252111IN
Index Protocol: Notional Flash Mint
0 ETH0.0136260613.62606105
Redeem Exact Set...158673932022-10-31 10:18:11566 days ago1667211491IN
Index Protocol: Notional Flash Mint
0 ETH0.0142460312.28260271
Issue Exact Set ...158673782022-10-31 10:15:11566 days ago1667211311IN
Index Protocol: Notional Flash Mint
0 ETH0.0146021610.86850409
Redeem Exact Set...158449662022-10-28 7:08:47569 days ago1666940927IN
Index Protocol: Notional Flash Mint
0 ETH0.010749399.93892788
Issue Exact Set ...158449492022-10-28 7:05:23569 days ago1666940723IN
Index Protocol: Notional Flash Mint
0 ETH0.0147398811.95491248
Issue Exact Set ...158449352022-10-28 7:02:35569 days ago1666940555IN
Index Protocol: Notional Flash Mint
0 ETH0.013192168.84005283
Redeem Exact Set...158392202022-10-27 11:48:47570 days ago1666871327IN
Index Protocol: Notional Flash Mint
0 ETH0.0108955710.07631865
Redeem Exact Set...158392052022-10-27 11:45:47570 days ago1666871147IN
Index Protocol: Notional Flash Mint
0 ETH0.010974578.60389615
Issue Exact Set ...158390632022-10-27 11:17:23570 days ago1666869443IN
Index Protocol: Notional Flash Mint
0 ETH0.0220267516.03966562
0x60e06040158386802022-10-27 10:00:35570 days ago1666864835IN
 Create: FlashMintNotional
0 ETH0.076412420

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
FlashMintNotional

Compiler Version
v0.6.10+commit.00c0fcaf

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Apache-2.0 license
File 1 of 29 : FlashMintNotional.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 { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

import { IBasicIssuanceModule } from "../interfaces/IBasicIssuanceModule.sol";
import { IDebtIssuanceModule } from "../interfaces/IDebtIssuanceModule.sol";
import { INotionalTradeModule } from "../interfaces/INotionalTradeModule.sol";
import { IController } from "../interfaces/IController.sol";
import { ISetToken } from "../interfaces/ISetToken.sol";
import { IWrappedfCash } from "../interfaces/IWrappedfCash.sol";
import { IWrappedfCashFactory } from "../interfaces/IWrappedfCashFactory.sol";
import { IWETH } from "../interfaces/IWETH.sol";
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";
import { DEXAdapter } from "./DEXAdapter.sol";





/**
 * @title FlashMintNotional
 * @author Index Coop
 *
 * Contract for issuing and redeeming a Set Token that contains wrappedfCash position
 * Includes (in the issuance case):
 *    - Matching fCash components to their underlying asset
 *    - Swapping input token to underlying asset
 *    - Minting fCash positions from underlying asset
 *    - Issuing set token   
 */
contract FlashMintNotional is Ownable, ReentrancyGuard {

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

    struct TradeData {
        ISetToken setToken;
        uint256 amountSetToken;
        IERC20 paymentToken;
        uint256 limitAmount;
        address issuanceModule;
        bool isDebtIssuance;
        uint256 slippage;
        bool redeemMaturedPositions;
    }

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

    // Placeholder address to identify ETH where it is treated as if it was an ERC20 token
    address constant public ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

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

    IController public immutable setController;
    IWrappedfCashFactory public immutable wrappedfCashFactory;
    INotionalTradeModule public immutable notionalTradeModule;
    DEXAdapter.Addresses public addresses;
    uint256 public decodedIdGasLimit;

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

    event FlashMint(
        address indexed _recipient,     // The recipient address of the issued SetTokens
        ISetToken indexed _setToken,    // The issued SetToken
        IERC20 indexed _inputToken,     // The address of the input asset(ERC20/ETH) used to issue the SetTokens
        uint256 _amountInputToken,      // The amount of input tokens used for issuance
        uint256 _amountSetIssued        // The amount of SetTokens received by the recipient
    );

    event FlashRedeem(
        address indexed _recipient,     // The recipient adress of the output tokens obtained for redemption
        ISetToken indexed _setToken,    // The redeemed SetToken
        IERC20 indexed _outputToken,    // The address of output asset(ERC20/ETH) received by the recipient
        uint256 _amountSetRedeemed,     // The amount of SetTokens redeemed for output tokens
        uint256 _amountOutputToken      // The amount of output tokens received by the recipient
    );

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

    modifier isValidModule(address _issuanceModule) {
        require(setController.isModule(_issuanceModule), "FlashMint: INVALID ISSUANCE MODULE");
         _;
    }

    /**
    * Sets various contract addresses and gas limit for getDecodedId call
    * 
    * @param _weth                  Address of wrapped native token
    * @param _setController         SetToken controller used to verify a given token is a set
    * @param _wrappedfCashFactory   Factory contract creating new fCash wrappers
    * @param _notionalTradeModule   Module used to make sure matured positions are redeemed
    * @param _quickRouter           Address of quickswap router
    * @param _sushiRouter           Address of sushiswap router
    * @param _uniV3Router           Address of uniswap v3 router
    * @param _uniV3Quoter           Address of uniswap v3 quoter
    * @param _curveAddressProvider  Contract to get current implementation address of curve registry
    * @param _curveCalculator       Contract to calculate required input to receive given output in curve (for exact output swaps)
    * @param _decodedIdGasLimit     Gas limit for call to getDecodedID
    */
    constructor(
        address _weth,
        IController _setController,
        IWrappedfCashFactory _wrappedfCashFactory,
        INotionalTradeModule _notionalTradeModule,
        address _quickRouter,
        address _sushiRouter,
        address _uniV3Router,
        address _uniV3Quoter,
        address _curveAddressProvider,
        address _curveCalculator,
        uint256 _decodedIdGasLimit
    )
        public
    {
        setController = _setController;

        wrappedfCashFactory = _wrappedfCashFactory;
        notionalTradeModule = _notionalTradeModule;

        addresses.weth = _weth;
        addresses.quickRouter = _quickRouter;
        addresses.sushiRouter = _sushiRouter;
        addresses.uniV3Router = _uniV3Router;
        addresses.uniV3Quoter = _uniV3Quoter;
        addresses.curveAddressProvider = _curveAddressProvider;
        addresses.curveCalculator = _curveCalculator;

        decodedIdGasLimit = _decodedIdGasLimit;
    }

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


    /**
     * Returns component positions required for issuance 
     *
     * @param _issuanceModule    Address of issuance Module to use 
     * @param _isDebtIssuance    Flag indicating wether given issuance module is a debt issuance module
     * @param _setToken          Set token to issue
     * @param _amountSetToken    Amount of set token to issue
     */
    function getRequiredIssuanceComponents(address _issuanceModule, bool _isDebtIssuance, ISetToken _setToken, uint256 _amountSetToken) public view returns(address[] memory components, uint256[] memory positions) {
        if(_isDebtIssuance) { 
            (components, positions, ) = IDebtIssuanceModule(_issuanceModule).getRequiredComponentIssuanceUnits(_setToken, _amountSetToken);
        }
        else {
            (components, positions) = IBasicIssuanceModule(_issuanceModule).getRequiredComponentUnitsForIssue(_setToken, _amountSetToken);
        }
    }

    /**
     * Returns component positions required for Redemption 
     *
     * @param _issuanceModule    Address of issuance Module to use 
     * @param _isDebtIssuance    Flag indicating wether given issuance module is a debt issuance module
     * @param _setToken          Set token to issue
     * @param _amountSetToken    Amount of set token to issue
     */
    function getRequiredRedemptionComponents(address _issuanceModule, bool _isDebtIssuance, ISetToken _setToken, uint256 _amountSetToken) public view returns(address[] memory components, uint256[] memory positions) {
        if(_isDebtIssuance) { 
            (components, positions, ) = IDebtIssuanceModule(_issuanceModule).getRequiredComponentRedemptionUnits(_setToken, _amountSetToken);
        }
        else {
            components = _setToken.getComponents();
            positions = new uint256[](components.length);
            for(uint256 i = 0; i < components.length; i++) {
                uint256 unit = uint256(_setToken.getDefaultPositionRealUnit(components[i]));
                positions[i] = unit.preciseMul(_amountSetToken);
            }
        }
    }

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

    /**
     * @dev Update gas limit of call to getDecodedID in _isWrappedFCash
     * @param _decodedIdGasLimit   New gas limit for call to getDecodedID
     */
    function updateDecodedIdGasLimit(uint256 _decodedIdGasLimit) external onlyOwner {
        require(_decodedIdGasLimit != 0, "DecodedIdGasLimit cannot be zero");
        decodedIdGasLimit = _decodedIdGasLimit;
    }

    /**
     * Withdraw slippage to selected address
     *
     * @param _tokens    Addresses of tokens to withdraw, specifiy ETH_ADDRESS to withdraw ETH
     * @param _to        Address to send the tokens to
     */
    function withdrawTokens(IERC20[] calldata _tokens, address payable _to) external onlyOwner payable {
        for(uint256 i = 0; i < _tokens.length; i++) {
            if(address(_tokens[i]) == ETH_ADDRESS){
                _to.sendValue(address(this).balance);
            }
            else{
                _tokens[i].safeTransfer(_to, _tokens[i].balanceOf(address(this)));
            }
        }
    }


    /**
     * Returns components and units but replaces wrappefCash positions with the corresponding amount of underlying token needed to mint 
     *
     * @param _setToken          Address of the set token to redeem
     * @param _amountSetToken    Amount of set token to redeem
     * @param _issuanceModule    Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance    Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage          Relative slippage (with 18 decimals) to subtract from wrappedfCash's estimated redemption amount to allow for approximation error
     */
    function getFilteredComponentsRedemption(
        ISetToken _setToken,
        uint256 _amountSetToken,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage

    )
        external
        view
        returns (address[] memory filteredComponents, uint[] memory filteredUnits)
    {
        return _getFilteredComponentsRedemption(_setToken, _amountSetToken, _issuanceModule, _isDebtIssuance, _slippage);
    }

    /**
     * Returns filtered components after redeeming matured positions
     * THIS METHOD SHOULD ONLY BE CALLED WITH STATICCALL
     *
     * @param _setToken          Address of the set token to redeem
     * @param _amountSetToken    Amount of set token to redeem
     * @param _issuanceModule    Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance    Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage          Relative slippage (with 18 decimals) to subtract from wrappedfCash's estimated redemption amount to allow for approximation error
     */
    function getFilteredComponentsRedemptionAfterMaturityRedemption(
        ISetToken _setToken,
        uint256 _amountSetToken,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage
    )
        external
        returns (address[] memory filteredComponents, uint[] memory filteredUnits)
    {
        notionalTradeModule.redeemMaturedPositions(_setToken);
        return _getFilteredComponentsRedemption(_setToken, _amountSetToken, _issuanceModule, _isDebtIssuance, _slippage);
    }


    /**
     * Returns components and units but replaces wrappefCash positions with the corresponding amount of underlying token needed to mint 
     *
     * @param _setToken          Address of the set token to issue
     * @param _amountSetToken    Amount of set token to issue
     * @param _issuanceModule    Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance    Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage          Relative slippage (with 18 decimals) to add to wrappedfCash's estimated issuance cost to allow for approximation error
     */
    function getFilteredComponentsIssuance(
        ISetToken _setToken,
        uint256 _amountSetToken,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage
    )
        external
        view
        returns (address[] memory filteredComponents, uint[] memory filteredUnits)
    {
        (filteredComponents, filteredUnits, ) = _getFilteredComponentsIssuance(_setToken, _amountSetToken, _issuanceModule, _isDebtIssuance, _slippage);
    }

    /**
     * Returns filtered components after redeeming matured positions
     * THIS METHOD SHOULD ONLY BE CALLED WITH STATICCALL
     *
     * @param _setToken          Address of the set token to issue
     * @param _amountSetToken    Amount of set token to issue
     * @param _issuanceModule    Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance    Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage          Relative slippage (with 18 decimals) to add to wrappedfCash's estimated issuance cost to allow for approximation error
     */
    function getFilteredComponentsIssuanceAfterMaturityRedemption(
        ISetToken _setToken,
        uint256 _amountSetToken,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage

    )
        external
        returns (address[] memory filteredComponents, uint[] memory filteredUnits)
    {
        notionalTradeModule.redeemMaturedPositions(_setToken);
        (filteredComponents, filteredUnits, ) =  _getFilteredComponentsIssuance(_setToken, _amountSetToken, _issuanceModule, _isDebtIssuance, _slippage);

    }

    /**
     * Issue set token for ETH
     *
     * @param _setToken                  Address of the set token to issue
     * @param _amountSetToken            Amount of set token to issue
     * @param _swapData                  Swap data for each element of the filtered components in the same order as returned by getFilteredComponentsIssuance
     * @param _issuanceModule            Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance            Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage                  Relative slippage (with 18 decimals) to add to wrappedfCash's estimated issuance cost to allow for approximation error
     * @param _redeemMaturedPositions    Set to false to skip redeeming matured positions and save gas, wich will fail if there are any matured positions
     */
    function issueExactSetFromETH(
        ISetToken _setToken,
        uint256 _amountSetToken,
        DEXAdapter.SwapData[] memory _swapData,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage,
        bool _redeemMaturedPositions
    )
        isValidModule(_issuanceModule)
        external
        payable
        nonReentrant
        returns (uint256)
    {

        IWETH(addresses.weth).deposit{value: msg.value}();
        TradeData memory tradeData = TradeData(
            _setToken,
            _amountSetToken,
            IERC20(addresses.weth),
            msg.value,
            _issuanceModule,
            _isDebtIssuance,
            _slippage,
            _redeemMaturedPositions
        );
        uint256 totalInputTokenSpent = _issueExactSetFromToken(tradeData,  _swapData);
        uint256 amountTokenReturn = msg.value.sub(totalInputTokenSpent);
        if (amountTokenReturn > 0) {
            IWETH(addresses.weth).withdraw(amountTokenReturn);
            payable(msg.sender).transfer(amountTokenReturn);
        }
        return totalInputTokenSpent;
    }

    /**
     * Issue set token for ERC20 Token
     *
     * @param _setToken                  Address of the set token to issue
     * @param _amountSetToken            Amount of set token to issue
     * @param _inputToken                Address of the input token to spent
     * @param _maxAmountInputToken       Maximum amount of input token to spent
     * @param _swapData                  Configuration of swaps from input token to each element of the filtered components in the same order as returned by getFilteredComponentsIssuance
     * @param _issuanceModule            Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance            Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage                  Relative slippage (with 18 decimals) to add to wrappedfCash's estimated issuance cost to allow for approximation error
     * @param _redeemMaturedPositions    Set to false to skip redeeming matured positions and save gas, wich will fail if there are any matured positions
     */
    function issueExactSetFromToken(
        ISetToken _setToken,
        IERC20 _inputToken,
        uint256 _amountSetToken,
        uint256 _maxAmountInputToken,
        DEXAdapter.SwapData[] memory _swapData,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage,
        bool _redeemMaturedPositions
    )
        isValidModule(_issuanceModule)
        external
        nonReentrant
        returns (uint256)
    {

        _inputToken.safeTransferFrom(msg.sender, address(this), _maxAmountInputToken);
        TradeData memory tradeData = TradeData(
            _setToken,
            _amountSetToken,
            _inputToken,
            _maxAmountInputToken,
            _issuanceModule,
            _isDebtIssuance,
            _slippage,
            _redeemMaturedPositions
        );
        uint256 totalInputTokenSpent = _issueExactSetFromToken(tradeData, _swapData);
        _returnExcessInputToken(_inputToken, _maxAmountInputToken, totalInputTokenSpent);
        return totalInputTokenSpent;
    }

    /**
     * Redeem set token for selected output token
     *
     * @param _setToken                  Address of the set token to redeem
     * @param _amountSetToken            Amount of set token to redeem
     * @param _outputToken               Address of the output token to spent
     * @param _minOutputReceive          Minimum amount of output token to receive
     * @param _swapData                  Configuration of swaps from each element of the filtered components to the output token in the same order as returned by getFilteredComponentsIssuance
     * @param _issuanceModule            Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance            Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage                  Relative slippage (with 18 decimals) to subtract from wrappedfCash's estimated redemption amount to allow for approximation error
     * @param _redeemMaturedPositions    Set to false to skip redeeming matured positions and save gas, wich will fail if there are any matured positions
     */
    function redeemExactSetForToken(
        ISetToken _setToken,
        IERC20 _outputToken,
        uint256 _amountSetToken,
        uint256 _minOutputReceive,
        DEXAdapter.SwapData[] memory _swapData,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage,
        bool _redeemMaturedPositions
    )
        isValidModule(_issuanceModule)
        external
        nonReentrant
        returns (uint256)
    {

        TradeData memory tradeData = TradeData(
            _setToken,
            _amountSetToken,
            _outputToken,
            _minOutputReceive,
            _issuanceModule,
            _isDebtIssuance,
            _slippage,
            _redeemMaturedPositions
        );
        uint256 outputAmount = _redeemExactSetForToken(tradeData, _swapData);
        _outputToken.safeTransfer(msg.sender, outputAmount);
        return outputAmount;
    }

    /**
     * Redeem set token for eth
     *
     * @param _setToken                  Address of the set token to redeem
     * @param _amountSetToken            Amount of set token to redeem
     * @param _minOutputReceive          Minimum amount of output token to receive
     * @param _swapData                  Configuration of swaps from each element of the filtered components to the output token in the same order as returned by getFilteredComponentsIssuance
     * @param _issuanceModule            Address of the issuance module to use for getting raw list of components and units
     * @param _isDebtIssuance            Boolean indicating wether given issuance module is an instance of Debt- or BasicIssuanceModule
     * @param _slippage                  Relative slippage (with 18 decimals) to subtract from wrappedfCash's estimated redemption amount to allow for approximation error
     * @param _redeemMaturedPositions    Set to false to skip redeeming matured positions and save gas, wich will fail if there are any matured positions
     */
    function redeemExactSetForETH(
        ISetToken _setToken,
        uint256 _amountSetToken,
        uint256 _minOutputReceive,
        DEXAdapter.SwapData[] memory _swapData,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage,
        bool _redeemMaturedPositions
    )
        isValidModule(_issuanceModule)
        external
        nonReentrant
        returns (uint256)
    {

        
        TradeData memory tradeData = TradeData(
            _setToken,
            _amountSetToken,
            IERC20(addresses.weth),
            _minOutputReceive,
            _issuanceModule,
            _isDebtIssuance,
            _slippage,
            _redeemMaturedPositions
        );
        uint256 outputAmount = _redeemExactSetForToken(tradeData, _swapData);
        IWETH(addresses.weth).withdraw(outputAmount);
        payable(msg.sender).transfer(outputAmount);
        return outputAmount;
    }

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


    /**
     * Transfer in input token, swap for components, mint fCash positions and issue set
     */
    function _issueExactSetFromToken(
        TradeData memory _tradeData,
        DEXAdapter.SwapData[] memory _swapData
    )
        internal
        returns (uint256)
    {

        uint256 inputTokenBalanceBefore = _tradeData.paymentToken.balanceOf(address(this));
        if(_tradeData.redeemMaturedPositions) {
            notionalTradeModule.redeemMaturedPositions(_tradeData.setToken);
        }

        (address[] memory componentsBought, uint256[] memory amountsBought, uint256[] memory mappingToFilteredComponents) =  _buyComponentsForInputToken(
            _tradeData,
            _swapData
        );

        _mintWrappedFCashPositions(
            _tradeData,
            componentsBought,
            amountsBought,
            mappingToFilteredComponents
        );

        IBasicIssuanceModule(_tradeData.issuanceModule).issue(_tradeData.setToken, _tradeData.amountSetToken, msg.sender);

        require(inputTokenBalanceBefore.sub(_tradeData.paymentToken.balanceOf(address(this))) <= _tradeData.limitAmount, "FlashMint: OVERSPENT");

        emit FlashMint(msg.sender, _tradeData.setToken, _tradeData.paymentToken, _tradeData.limitAmount, _tradeData.amountSetToken);
        return inputTokenBalanceBefore.sub(_tradeData.paymentToken.balanceOf(address(this)));
    }

    /**
     * Redeem set, redeem fCash components, sell received tokens for output token and transfer proceds to the caller
     */
    function _redeemExactSetForToken(
        TradeData memory _tradeData,
        DEXAdapter.SwapData[] memory _swapData
    )
        internal
        returns (uint256)
    {

        uint256 outputTokenBalanceBefore = _tradeData.paymentToken.balanceOf(address(this));
        if(_tradeData.redeemMaturedPositions) {
            notionalTradeModule.redeemMaturedPositions(_tradeData.setToken);
        }
        _redeemExactSet(_tradeData.setToken, _tradeData.amountSetToken, _tradeData.issuanceModule);

        _redeemWrappedFCashPositions(_tradeData);
        _sellComponentsForOutputToken(_tradeData, _swapData);

        uint256 outputAmount = _tradeData.paymentToken.balanceOf(address(this)).sub(outputTokenBalanceBefore);

        require(outputAmount >= _tradeData.limitAmount, "FlashMint: UNDERBOUGHT");
        // Emit event
        emit FlashRedeem(msg.sender, _tradeData.setToken, _tradeData.paymentToken, _tradeData.amountSetToken, outputAmount);
        // Return output amount
        return outputAmount;
    }


    /**
     * Sells all components (after redemption of fCash positions) for the output token
     */
    function _sellComponentsForOutputToken(
        TradeData memory _tradeData,
        DEXAdapter.SwapData[] memory _swapData
    )
        internal
    {
        (address[] memory components, uint256[] memory componentUnits) = _getFilteredComponentsRedemption(
            _tradeData.setToken,
            _tradeData.amountSetToken,
            _tradeData.issuanceModule,
            _tradeData.isDebtIssuance,
            _tradeData.slippage
        );

        require(components.length == _swapData.length, "Components / Swapdata mismatch");

        for (uint256 i = 0; i < components.length; i++) {
            uint256 maxAmountSell = componentUnits[i];
            address component = components[i];
            // Component Address being zero means the filtered list is finished and all remaining components are 0 as well
            if(component == address(0)){
                break;
            }

            // If the component is equal to the output token we don't have to trade
            if(component != address(_tradeData.paymentToken)) {
                addresses.swapExactTokensForTokens(maxAmountSell, 0, _swapData[i]);
            }

        }
    }

    /**
     * Redeem all fCash positions for the underlying token
     */
    function _redeemWrappedFCashPositions(
        TradeData memory _tradeData
    ) 
    internal
    {
        (address[] memory components, uint256[] memory componentUnits) = getRequiredRedemptionComponents(
            _tradeData.issuanceModule,
            _tradeData.isDebtIssuance,
            _tradeData.setToken,
            _tradeData.amountSetToken
        );

        for (uint256 i = 0; i < components.length; i++) {
            address component = components[i];
            uint256 units = componentUnits[i];

            if(_isWrappedFCash(component)) {
                IWrappedfCash(component).redeemToUnderlying(units, address(this), 0);
            }
        }
    }

    /**
     * Mint all fCash positions from the underlying token
     */
    function _mintWrappedFCashPositions(
        TradeData memory _tradeData,
        address[] memory componentsBought,
        uint256[] memory amountsAvailable,
        uint256[] memory mappingToFilteredComponents
    ) 
    internal
    {
        (address[] memory components, uint256[] memory componentUnits) = getRequiredIssuanceComponents(
            _tradeData.issuanceModule,
            _tradeData.isDebtIssuance,
            _tradeData.setToken,
            _tradeData.amountSetToken
        );

        for (uint256 i = 0; i < components.length; i++) {
            address component = components[i];
            uint256 units = componentUnits[i];
            if(_isWrappedFCash(component)) {
                IERC20 underlyingToken = _getUnderlyingToken(IWrappedfCash(component));
                uint256 componentIndex = mappingToFilteredComponents[i];
                uint256 amountAvailable = amountsAvailable[componentIndex];
                underlyingToken.safeApprove(component, amountAvailable);
                uint256 underlyingBalanceBefore = underlyingToken.balanceOf(address(this));

                IWrappedfCash(component).mintViaUnderlying(amountAvailable, uint88(units), address(this), 0);

                uint256 amountSpent = underlyingBalanceBefore.sub(underlyingToken.balanceOf(address(this)));
                amountsAvailable[componentIndex] = amountsAvailable[componentIndex].sub(amountSpent);
            }
            IERC20(component).safeApprove(_tradeData.issuanceModule, units);
        }
    }

    /**
     * Get underlying token of fCash positions returning weth address in case underlying is eth
     */
    function _getUnderlyingToken(
        IWrappedfCash _wrappedfCash
    ) 
    internal
    view 
    returns(IERC20)
    {
        (IERC20 underlyingToken, bool isEth) = _wrappedfCash.getToken(true);
        if(isEth) {
            underlyingToken = IERC20(addresses.weth);
        }
        return underlyingToken;
    }



    /**
     * Transfers given amount of set token from the sender and redeems it for underlying components.
     * Obtained component tokens are sent to this contract. 
     *
     * @param _setToken     Address of the SetToken to be redeemed
     * @param _amount       Amount of SetToken to be redeemed
     */
    function _redeemExactSet(ISetToken _setToken, uint256 _amount, address _issuanceModule) internal returns (uint256) {
        _setToken.safeTransferFrom(msg.sender, address(this), _amount);
        _setToken.safeApprove(_issuanceModule, _amount);
        IBasicIssuanceModule(_issuanceModule).redeem(_setToken, _amount, address(this));
    }

    /**
     * Returns excess input token
     *
     * @param _inputToken         Address of the input token to return
     * @param _receivedAmount     Amount received by the caller
     * @param _spentAmount        Amount spent for issuance
     */
    function _returnExcessInputToken(IERC20 _inputToken, uint256 _receivedAmount, uint256 _spentAmount) internal {
        uint256 amountTokenReturn = _receivedAmount.sub(_spentAmount);
        if (amountTokenReturn > 0) {
            _inputToken.safeTransfer(msg.sender,  amountTokenReturn);
        }
    }

    /**
     * @dev Checks if a given address is an fCash position that was deployed from the factory
     */
    function _isWrappedFCash(address _fCashPosition) internal view returns(bool){
        if(!_fCashPosition.isContract()) {
            return false;
        }

        //Had to add this gas limit since this call wasted all the gas when directed to WETH in unittests
        try IWrappedfCash(_fCashPosition).getDecodedID{gas: decodedIdGasLimit}() returns(uint16 _currencyId, uint40 _maturity){
            try wrappedfCashFactory.computeAddress(_currencyId, _maturity) returns(address _computedAddress){
                return _fCashPosition == _computedAddress;
            } catch {
                return false;
            }
        } catch {
            return false;
        }
    }

    /**
     * @dev Returns estimated amount of underlying tokens spent on minting given amount of fCash, adding given slippage percentage
     */
    function _getUnderlyingTokensForMint(IWrappedfCash _fCashPosition, uint256 _fCashAmount, uint256 _slippage)
    internal
    view
    returns(uint256)
    {
        return _fCashPosition.previewMint(_fCashAmount).mul(1 ether + _slippage).div(1 ether);
    }

    /**
     * @dev Returns estimated amount of underlying tokens returned on redeeming given amount of fCash, subtracting given slippage percentage
     */
    function _getUnderlyingTokensForRedeem(IWrappedfCash _fCashPosition, uint256 _fCashAmount, uint256 _slippage)
    internal
    view
    returns(uint256)
    {
        return _fCashPosition.previewRedeem(_fCashAmount).mul(1 ether - _slippage).div(1 ether);
    }

    /**
     * @dev Helper method to find a given address in the list. Returns index+1 if found, 0 if not found.
     */
    function _findComponent(address[] memory _components, address _toFind)
    internal
    pure
    returns(uint256)
    {
        for(uint256 i = 0; i < _components.length; i++) {
            if(_components[i] == _toFind){
                return i + 1;
            }
        }
        return 0;
    }

    /**
     * @dev Swaps input token for required amounts of filtered components
     */
    function _buyComponentsForInputToken(
        TradeData memory _tradeData,
        DEXAdapter.SwapData[] memory _swapData
    ) 
    internal
    returns(address[] memory, uint256[] memory, uint256[] memory)
    {
        (address[] memory components, uint256[] memory componentUnits, uint256[] memory mappingToFilteredComponents) = _getFilteredComponentsIssuance(
            _tradeData.setToken,
            _tradeData.amountSetToken,
            _tradeData.issuanceModule,
            _tradeData.isDebtIssuance,
            _tradeData.slippage
        );

        require(components.length == _swapData.length, "Components / Swapdata mismatch");

        uint256[] memory boughtAmounts = new uint256[](components.length);

        for (uint256 i = 0; i < components.length; i++) {
            if(components[i] == address(0)){
                break;
            }

            // If the component is equal to the input token we don't have to trade
            if(components[i] != address(_tradeData.paymentToken)) {
                uint256 componentBalanceBefore = IERC20(components[i]).balanceOf(address(this));
                addresses.swapTokensForExactTokens(componentUnits[i], _tradeData.limitAmount, _swapData[i]);
                boughtAmounts[i] = IERC20(components[i]).balanceOf(address(this)).sub(componentBalanceBefore);
            } else {
                boughtAmounts[i] = componentUnits[i];
            }
        }

        return(components, boughtAmounts, mappingToFilteredComponents);
    }

    /**
     * @dev Returns expected of components received upon set tokens redemption, replacing fCash position with equivalent amount of underlying token
     */
    function _getFilteredComponentsRedemption(
        ISetToken _setToken,
        uint256 _amountSetToken,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage
    )
        internal
        view
        returns (address[] memory filteredComponents, uint[] memory filteredUnits)
    {
        (address[] memory components, uint256[] memory componentUnits) = getRequiredRedemptionComponents(_issuanceModule, _isDebtIssuance, _setToken, _amountSetToken);

        filteredComponents = new address[](components.length);
        filteredUnits = new uint256[](components.length);
        uint j = 0;

        for (uint256 i = 0; i < components.length; i++) {
            address component = components[i];
            uint256 units;

            if(_isWrappedFCash(component)) {
                units = _getUnderlyingTokensForRedeem(IWrappedfCash(component), componentUnits[i], _slippage);
                IERC20 underlyingToken = _getUnderlyingToken(IWrappedfCash(component));
                component = address(underlyingToken);
            }
            else {
                units = componentUnits[i];
            }

            uint256 componentIndex = _findComponent(filteredComponents, component);
            if(componentIndex > 0){
                filteredUnits[componentIndex - 1] = filteredUnits[componentIndex - 1].add(units);
            } else {
                filteredComponents[j] = component;
                filteredUnits[j] = units;
                j++;
            }
        }
    }

    /**
     * @dev Returns expected of components spent upon set tokens issuance, replacing fCash position with equivalent amount of underlying token
     */
    function _getFilteredComponentsIssuance(
        ISetToken _setToken,
        uint256 _amountSetToken,
        address _issuanceModule,
        bool _isDebtIssuance,
        uint256 _slippage
    )
        internal
        view
        returns (address[] memory filteredComponents, uint[] memory filteredUnits, uint256[] memory mappingToFilteredComponent)
    {
        (address[] memory components, uint256[] memory componentUnits) = getRequiredIssuanceComponents(_issuanceModule, _isDebtIssuance, _setToken, _amountSetToken);

        filteredComponents = new address[](components.length);
        filteredUnits = new uint256[](components.length);
        mappingToFilteredComponent = new uint256[](components.length);
        uint j = 0;

        for (uint256 i = 0; i < components.length; i++) {
            address component = components[i];
            uint256 units;

            if(_isWrappedFCash(component)) {
                units = _getUnderlyingTokensForMint(IWrappedfCash(component), componentUnits[i], _slippage);
                IERC20 underlyingToken = _getUnderlyingToken(IWrappedfCash(component));
                component = address(underlyingToken);
            }
            else {
                units = componentUnits[i];
            }

            uint256 componentIndex = _findComponent(filteredComponents, component);
            if(componentIndex > 0){
                filteredUnits[componentIndex - 1] = filteredUnits[componentIndex - 1].add(units);
                mappingToFilteredComponent[i] = componentIndex - 1;
            } else {
                filteredComponents[j] = component;
                filteredUnits[j] = units;
                mappingToFilteredComponent[i] = j;
                j++;
            }
        }
    }

    /**
     * @dev Fallback method to enable receiving eth when withrdawing from weth contract
     */
    receive() external payable {
        // required for weth.withdraw() to work properly
        require(msg.sender == addresses.weth, "FlashMint: Direct deposits not allowed");
    }

}

File 2 of 29 : 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 3 of 29 : 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 4 of 29 : 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 5 of 29 : 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 6 of 29 : 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 7 of 29 : 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 8 of 29 : 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 9 of 29 : 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 10 of 29 : 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 11 of 29 : 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);
}

File 12 of 29 : 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 13 of 29 : 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);
        // NOTE: The following was changed from always returning result at position [1] to returning the last element of the result array
        // With this change, the actual output is correctly returned also for multi-hop swaps
        // See https://github.com/IndexCoop/index-coop-smart-contracts/pull/116 
        uint256[] memory result = _router.swapExactTokensForTokens(_amountIn, _minAmountOut, _path, address(this), block.timestamp);
        // result = uint[] memory	The input token amount and all subsequent output token amounts.
        // we are usually only interested in the actual amount of the output token (so result element at the last place)
        return result[result.length-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 15 of 29 : IBasicIssuanceModule.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 IBasicIssuanceModule {
    function getRequiredComponentUnitsForIssue(
        ISetToken _setToken,
        uint256 _quantity
    ) external view returns(address[] memory, uint256[] memory);
    function issue(ISetToken _setToken, uint256 _quantity, address _to) external;
    function redeem(ISetToken _token, uint256 _quantity, address _to) external;
}

File 16 of 29 : 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);
    function owner() external view returns(address);
    function addFactory(address _factory) external;
    function addModule(address _module) external;
}

File 17 of 29 : 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 18 of 29 : 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 19 of 29 : INotionalTradeModule.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.6.10;
import { ISetToken } from "../interfaces/ISetToken.sol";

interface INotionalTradeModule {
    function redeemMaturedPositions(ISetToken) external;
    function initialize(ISetToken) external;
    function updateAllowedSetToken(ISetToken, bool) external;
    function owner() external view returns(address);
    function settleAccount(address) external;
    function setRedeemToUnderlying(ISetToken, bool) external;

}

File 20 of 29 : 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 21 of 29 : 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 22 of 29 : 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 23 of 29 : IWrappedfCash.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

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

/// @notice Different types of internal tokens
///  - UnderlyingToken: underlying asset for a cToken (except for Ether)
///  - cToken: Compound interest bearing token
///  - cETH: Special handling for cETH tokens
///  - Ether: the one and only
///  - NonMintable: tokens that do not have an underlying (therefore not cTokens)
enum TokenType {
    UnderlyingToken,
    cToken,
    cETH,
    Ether,
    NonMintable
}

interface IWrappedfCash {
    function initialize(uint16 currencyId, uint40 maturity) external;

    /// @notice Mints wrapped fCash ERC20 tokens
    function mintViaAsset(
        uint256 depositAmountExternal,
        uint88 fCashAmount,
        address receiver,
        uint32 minImpliedRate
    ) external;

    function mintViaUnderlying(
        uint256 depositAmountExternal,
        uint88 fCashAmount,
        address receiver,
        uint32 minImpliedRate
    ) external;

    function redeemToAsset(uint256 amount, address receiver, uint32 maxImpliedRate) external;
    function redeemToUnderlying(uint256 amount, address receiver, uint32 maxImpliedRate) external;

    /// @notice Returns the underlying fCash ID of the token
    function getfCashId() external view returns (uint256);

    /// @notice True if the fCash has matured, assets mature exactly on the block time
    function hasMatured() external view returns (bool);

    /// @notice Returns the components of the fCash idd
    function getDecodedID() external view returns (uint16 currencyId, uint40 maturity);

    /// @notice Returns the current market index for this fCash asset. If this returns
    /// zero that means it is idiosyncratic and cannot be traded.
    function getMarketIndex() external view returns (uint8);

    /// @notice Returns the token and precision of the token that this token settles
    /// to. For example, fUSDC will return the USDC token address and 1e6. The zero
    /// address will represent ETH.
    function getUnderlyingToken() external view returns (IERC20 underlyingToken, int256 underlyingPrecision);

    /// @notice Returns the asset token which the fCash settles to. This will be an interest
    /// bearing token like a cToken or aToken.
    function getAssetToken() external view returns (IERC20 assetToken, int256 assetPrecision, TokenType tokenType);

    function getToken(bool useUnderlying) external view returns (IERC20 token, bool isETH);

    function previewMint(uint256 shares) external view returns (uint256);

    function previewRedeem(uint256 shares) external view returns (uint256);
}


interface IWrappedfCashComplete is IWrappedfCash, IERC20 {}

File 24 of 29 : IWrappedfCashFactory.sol
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity 0.6.10;

interface IWrappedfCashFactory {
    function deployWrapper(uint16 currencyId, uint40 maturity) external returns(address);
    function computeAddress(uint16 currencyId, uint40 maturity) external view returns(address);
}

File 25 of 29 : 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 26 of 29 : 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 27 of 29 : 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 28 of 29 : 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 29 of 29 : 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 30 of 29 : 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;
    }
}

Settings
{
  "evmVersion": "istanbul",
  "libraries": {
    "contracts/exchangeIssuance/FlashMintNotional.sol:FlashMintNotional": {
      "DEXAdapter": "0xBb02bCCE1bdcc0b07E7870346D8b2ad9397D0fAC"
    }
  },
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_weth","type":"address"},{"internalType":"contract IController","name":"_setController","type":"address"},{"internalType":"contract IWrappedfCashFactory","name":"_wrappedfCashFactory","type":"address"},{"internalType":"contract INotionalTradeModule","name":"_notionalTradeModule","type":"address"},{"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":"uint256","name":"_decodedIdGasLimit","type":"uint256"}],"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":"contract IERC20","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":"contract IERC20","name":"_outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"_amountSetRedeemed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_amountOutputToken","type":"uint256"}],"name":"FlashRedeem","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"ETH_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"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":[],"name":"decodedIdGasLimit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"}],"name":"getFilteredComponentsIssuance","outputs":[{"internalType":"address[]","name":"filteredComponents","type":"address[]"},{"internalType":"uint256[]","name":"filteredUnits","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"}],"name":"getFilteredComponentsIssuanceAfterMaturityRedemption","outputs":[{"internalType":"address[]","name":"filteredComponents","type":"address[]"},{"internalType":"uint256[]","name":"filteredUnits","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"}],"name":"getFilteredComponentsRedemption","outputs":[{"internalType":"address[]","name":"filteredComponents","type":"address[]"},{"internalType":"uint256[]","name":"filteredUnits","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"}],"name":"getFilteredComponentsRedemptionAfterMaturityRedemption","outputs":[{"internalType":"address[]","name":"filteredComponents","type":"address[]"},{"internalType":"uint256[]","name":"filteredUnits","type":"uint256[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"}],"name":"getRequiredIssuanceComponents","outputs":[{"internalType":"address[]","name":"components","type":"address[]"},{"internalType":"uint256[]","name":"positions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"}],"name":"getRequiredRedemptionComponents","outputs":[{"internalType":"address[]","name":"components","type":"address[]"},{"internalType":"uint256[]","name":"positions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","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":"_swapData","type":"tuple[]"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"},{"internalType":"bool","name":"_redeemMaturedPositions","type":"bool"}],"name":"issueExactSetFromETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"contract IERC20","name":"_inputToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"},{"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":"_swapData","type":"tuple[]"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"},{"internalType":"bool","name":"_redeemMaturedPositions","type":"bool"}],"name":"issueExactSetFromToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"notionalTradeModule","outputs":[{"internalType":"contract INotionalTradeModule","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"},{"internalType":"uint256","name":"_minOutputReceive","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":"_swapData","type":"tuple[]"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"},{"internalType":"bool","name":"_redeemMaturedPositions","type":"bool"}],"name":"redeemExactSetForETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract ISetToken","name":"_setToken","type":"address"},{"internalType":"contract IERC20","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"_amountSetToken","type":"uint256"},{"internalType":"uint256","name":"_minOutputReceive","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":"_swapData","type":"tuple[]"},{"internalType":"address","name":"_issuanceModule","type":"address"},{"internalType":"bool","name":"_isDebtIssuance","type":"bool"},{"internalType":"uint256","name":"_slippage","type":"uint256"},{"internalType":"bool","name":"_redeemMaturedPositions","type":"bool"}],"name":"redeemExactSetForToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"setController","outputs":[{"internalType":"contract IController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_decodedIdGasLimit","type":"uint256"}],"name":"updateDecodedIdGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20[]","name":"_tokens","type":"address[]"},{"internalType":"address payable","name":"_to","type":"address"}],"name":"withdrawTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"wrappedfCashFactory","outputs":[{"internalType":"contract IWrappedfCashFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

60e06040523480156200001157600080fd5b50604051620042b1380380620042b183398101604081905262000034916200015c565b6000620000496001600160e01b036200014516565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a350600180556060998a1b6001600160601b0319908116608052988a1b891660a0529690981b90961660c052600880546001600160a01b03199081166001600160a01b039a8b1617909155600280548216958a1695909517909455600380548516938916939093179092556004805484169188169190911790556005805483169187169190911790556006805482169386169390931790925560078054909216939092169290921790915560095562000265565b3390565b805162000156816200024c565b92915050565b60008060008060008060008060008060006101608c8e0312156200017e578687fd5b8b516200018b816200024c565b60208d0151909b506200019e816200024c565b60408d0151909a50620001b1816200024c565b60608d0151909950620001c4816200024c565b60808d0151909850620001d7816200024c565b60a08d0151909750620001ea816200024c565b60c08d0151909650620001fd816200024c565b94506200020e8d60e08e0162000149565b9350620002208d6101008e0162000149565b9250620002328d6101208e0162000149565b91506101408c015190509295989b509295989b9093969950565b6001600160a01b03811681146200026257600080fd5b50565b60805160601c60a05160601c60c05160601c613fe9620002c8600039806109ea5280610c2452806112215280611430528061178a52508061136652806129a45250806103e452806107635280610a965280610cb252806110d75250613fe96000f3fe60806040526004361061012e5760003560e01c80637030aaa4116100ab578063b50452b21161006f578063b50452b21461032d578063da0321cd1461034d578063df0ba4f814610375578063e042a0af1461038a578063f2fde38b146103aa578063f633e0de146103ca57610168565b80637030aaa4146102b7578063715018a6146102cc5780638b2704ec146102e15780638da5cb5b14610303578063a734f06e1461031857610168565b806330519c5a116100f257806330519c5a146102175780635f20c7c91461023757806364eab7ff14610257578063658b457d146102775780636b211d8f1461029757610168565b80630da8acc91461016d5780630e8cc705146101a35780632111dd0e146101b657806329f82a55146101c95780632f5c5de8146101f757610168565b36610168576008546001600160a01b031633146101665760405162461bcd60e51b815260040161015d90613d42565b60405180910390fd5b005b600080fd5b34801561017957600080fd5b5061018d61018836600461359c565b6103df565b60405161019a9190613ea9565b60405180910390f35b6101666101b136600461331c565b6105cc565b61018d6101c4366004613502565b61075e565b3480156101d557600080fd5b506101e96101e43660046134a8565b6109c6565b60405161019a9291906138d5565b34801561020357600080fd5b506101e96102123660046134a8565b6109e5565b34801561022357600080fd5b506101e96102323660046134a8565b610a73565b34801561024357600080fd5b5061018d6102523660046133f1565b610a91565b34801561026357600080fd5b506101e96102723660046134a8565b610c1f565b34801561028357600080fd5b5061018d6102923660046133f1565b610cad565b3480156102a357600080fd5b506101e96102b23660046131b7565b610e1b565b3480156102c357600080fd5b5061018d611046565b3480156102d857600080fd5b5061016661104c565b3480156102ed57600080fd5b506102f66110d5565b60405161019a9190613829565b34801561030f57600080fd5b506102f66110f9565b34801561032457600080fd5b506102f6611108565b34801561033957600080fd5b506101e96103483660046131b7565b611120565b34801561035957600080fd5b506103626111e6565b60405161019a9796959493929190613857565b34801561038157600080fd5b506102f661121f565b34801561039657600080fd5b506101666103a5366004613695565b611243565b3480156103b657600080fd5b506101666103c536600461317f565b6112a4565b3480156103d657600080fd5b506102f6611364565b6000847f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166342f6e389826040518263ffffffff1660e01b815260040161042e9190613829565b60206040518083038186803b15801561044657600080fd5b505afa15801561045a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047e919061339c565b61049a5760405162461bcd60e51b815260040161015d90613d00565b600260015414156104bd5760405162461bcd60e51b815260040161015d90613dd2565b60026001556104ca612e88565b5060408051610100810182526001600160a01b03808d168252602082018c9052600854811692820192909252606081018a9052908716608082015285151560a082015260c0810185905283151560e08201526000610528828a611388565b600854604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d90610559908490600401613ea9565b600060405180830381600087803b15801561057357600080fd5b505af1158015610587573d6000803e3d6000fd5b505060405133925083156108fc02915083906000818181858888f193505050501580156105b8573d6000803e3d6000fd5b50600180559b9a5050505050505050505050565b6105d46115e7565b6001600160a01b03166105e56110f9565b6001600160a01b03161461060b5760405162461bcd60e51b815260040161015d90613c5f565b60005b828110156107585773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee84848381811061063757fe5b905060200201602081019061064c919061317f565b6001600160a01b03161415610679576106746001600160a01b0383164763ffffffff6115eb16565b610750565b6107508285858481811061068957fe5b905060200201602081019061069e919061317f565b6001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016106c99190613829565b60206040518083038186803b1580156106e157600080fd5b505afa1580156106f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107199190613640565b86868581811061072557fe5b905060200201602081019061073a919061317f565b6001600160a01b0316919063ffffffff61168c16565b60010161060e565b50505050565b6000847f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166342f6e389826040518263ffffffff1660e01b81526004016107ad9190613829565b60206040518083038186803b1580156107c557600080fd5b505afa1580156107d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107fd919061339c565b6108195760405162461bcd60e51b815260040161015d90613d00565b6002600154141561083c5760405162461bcd60e51b815260040161015d90613dd2565b600260015560085460408051630d0e30db60e41b815290516001600160a01b039092169163d0e30db0913491600480830192600092919082900301818588803b15801561088857600080fd5b505af115801561089c573d6000803e3d6000fd5b50505050506108a9612e88565b5060408051610100810182526001600160a01b03808c168252602082018b9052600854811692820192909252346060820152908716608082015285151560a082015260c0810185905283151560e08201526000610906828a6116e2565b9050600061091a348363ffffffff611a3416565b905080156109b357600854604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90610952908490600401613ea9565b600060405180830381600087803b15801561096c57600080fd5b505af1158015610980573d6000803e3d6000fd5b505060405133925083156108fc02915083906000818181858888f193505050501580156109b1573d6000803e3d6000fd5b505b50600180559a9950505050505050505050565b6060806109d68787878787611a5c565b50909890975095505050505050565b6060807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a2306c89886040518263ffffffff1660e01b8152600401610a349190613829565b600060405180830381600087803b158015610a4e57600080fd5b505af1158015610a62573d6000803e3d6000fd5b505050506109d68787878787611a5c565b606080610a838787878787611cb8565b915091509550959350505050565b6000847f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166342f6e389826040518263ffffffff1660e01b8152600401610ae09190613829565b60206040518083038186803b158015610af857600080fd5b505afa158015610b0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b30919061339c565b610b4c5760405162461bcd60e51b815260040161015d90613d00565b60026001541415610b6f5760405162461bcd60e51b815260040161015d90613dd2565b6002600155610b8f6001600160a01b038b1633308b63ffffffff611e8216565b610b97612e88565b6040518061010001604052808d6001600160a01b031681526020018b81526020018c6001600160a01b031681526020018a8152602001886001600160a01b03168152602001871515815260200186815260200185151581525090506000610bfe828a6116e2565b9050610c0b8c8b83611ea3565b600180559c9b505050505050505050505050565b6060807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663a2306c89886040518263ffffffff1660e01b8152600401610c6e9190613829565b600060405180830381600087803b158015610c8857600080fd5b505af1158015610c9c573d6000803e3d6000fd5b50505050610a838787878787611cb8565b6000847f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166342f6e389826040518263ffffffff1660e01b8152600401610cfc9190613829565b60206040518083038186803b158015610d1457600080fd5b505afa158015610d28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4c919061339c565b610d685760405162461bcd60e51b815260040161015d90613d00565b60026001541415610d8b5760405162461bcd60e51b815260040161015d90613dd2565b6002600155610d98612e88565b6040518061010001604052808d6001600160a01b031681526020018b81526020018c6001600160a01b031681526020018a8152602001886001600160a01b03168152602001871515815260200186815260200185151581525090506000610dff828a611388565b9050610c0b6001600160a01b038d16338363ffffffff61168c16565b6060808415610eb1576040516335c729db60e11b81526001600160a01b03871690636b8e53b690610e5290879087906004016138bc565b60006040518083038186803b158015610e6a57600080fd5b505afa158015610e7e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ea69190810190613299565b50909250905061103d565b836001600160a01b03166399d50d5d6040518163ffffffff1660e01b815260040160006040518083038186803b158015610eea57600080fd5b505afa158015610efe573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610f269190810190613207565b915081516001600160401b0381118015610f3f57600080fd5b50604051908082528060200260200182016040528015610f69578160200160208202803683370190505b50905060005b825181101561103b576000856001600160a01b03166366cb8d2f858481518110610f9557fe5b60200260200101516040518263ffffffff1660e01b8152600401610fb99190613829565b60206040518083038186803b158015610fd157600080fd5b505afa158015610fe5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110099190613640565b905061101b818663ffffffff611ed716565b83838151811061102757fe5b602090810291909101015250600101610f6f565b505b94509492505050565b60095481565b6110546115e7565b6001600160a01b03166110656110f9565b6001600160a01b03161461108b5760405162461bcd60e51b815260040161015d90613c5f565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b7f000000000000000000000000000000000000000000000000000000000000000081565b6000546001600160a01b031690565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b60608084156111575760405163131e26b960e01b81526001600160a01b0387169063131e26b990610e5290879087906004016138bc565b604051637a4ffd0360e01b81526001600160a01b03871690637a4ffd039061118590879087906004016138bc565b60006040518083038186803b15801561119d57600080fd5b505afa1580156111b1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111d99190810190613239565b9097909650945050505050565b6002546003546004546005546006546007546008546001600160a01b039687169695861695948516949384169392831692918216911687565b7f000000000000000000000000000000000000000000000000000000000000000081565b61124b6115e7565b6001600160a01b031661125c6110f9565b6001600160a01b0316146112825760405162461bcd60e51b815260040161015d90613c5f565b8061129f5760405162461bcd60e51b815260040161015d90613c94565b600955565b6112ac6115e7565b6001600160a01b03166112bd6110f9565b6001600160a01b0316146112e35760405162461bcd60e51b815260040161015d90613c5f565b6001600160a01b0381166113095760405162461bcd60e51b815260040161015d906139c4565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b7f000000000000000000000000000000000000000000000000000000000000000081565b60008083604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016113bb9190613829565b60206040518083038186803b1580156113d357600080fd5b505afa1580156113e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061140b9190613640565b90508360e001511561149757835160405163a2306c8960e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163a2306c89916114649190600401613829565b600060405180830381600087803b15801561147e57600080fd5b505af1158015611492573d6000803e3d6000fd5b505050505b6114ae846000015185602001518660800151611f08565b506114b884611fa8565b6114c28484612084565b60006115548286604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016114f89190613829565b60206040518083038186803b15801561151057600080fd5b505afa158015611524573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115489190613640565b9063ffffffff611a3416565b9050846060015181101561157a5760405162461bcd60e51b815260040161015d90613a0a565b84604001516001600160a01b031685600001516001600160a01b0316336001600160a01b03167f846f5655f4f8fa6ef5e4ad493e284e34854a83d000836d0493800c259ea970658860200151856040516115d5929190613ed7565b60405180910390a49150505b92915050565b3390565b8047101561160b5760405162461bcd60e51b815260040161015d90613b3c565b6000826001600160a01b03168260405161162490613826565b60006040518083038185875af1925050503d8060008114611661576040519150601f19603f3d011682016040523d82523d6000602084013e611666565b606091505b50509050806116875760405162461bcd60e51b815260040161015d90613adf565b505050565b6116878363a9059cbb60e01b84846040516024016116ab9291906138bc565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261225a565b60008083604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016117159190613829565b60206040518083038186803b15801561172d57600080fd5b505afa158015611741573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117659190613640565b90508360e00151156117f157835160405163a2306c8960e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163a2306c89916117be9190600401613829565b600060405180830381600087803b1580156117d857600080fd5b505af11580156117ec573d6000803e3d6000fd5b505050505b606080606061180087876122e9565b9250925092506118128784848461263e565b6080870151875160208901516040516336bc7a3d60e11b81526001600160a01b0390931692636d78f47a9261184d929091339060040161396e565b600060405180830381600087803b15801561186757600080fd5b505af115801561187b573d6000803e3d6000fd5b50505050866060015161191488604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016118b79190613829565b60206040518083038186803b1580156118cf57600080fd5b505afa1580156118e3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119079190613640565b869063ffffffff611a3416565b11156119325760405162461bcd60e51b815260040161015d90613bf0565b86604001516001600160a01b031687600001516001600160a01b0316336001600160a01b03167f9c1558194024d73db1b6fc2739c3070cacc4598122100dd6f7d3a3dd8cee5f368a606001518b60200151604051611991929190613ed7565b60405180910390a4611a2987604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016119cc9190613829565b60206040518083038186803b1580156119e457600080fd5b505afa1580156119f8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1c9190613640565b859063ffffffff611a3416565b979650505050505050565b600082821115611a565760405162461bcd60e51b815260040161015d90613aa8565b50900390565b6060806060806060611a7088888c8c611120565b9150915081516001600160401b0381118015611a8b57600080fd5b50604051908082528060200260200182016040528015611ab5578160200160208202803683370190505b50945081516001600160401b0381118015611acf57600080fd5b50604051908082528060200260200182016040528015611af9578160200160208202803683370190505b50935081516001600160401b0381118015611b1357600080fd5b50604051908082528060200260200182016040528015611b3d578160200160208202803683370190505b5092506000805b8351811015611ca9576000848281518110611b5b57fe5b602002602001015190506000611b70826128f5565b15611ba957611b9382868581518110611b8557fe5b60200260200101518c612a4a565b90506000611ba083612af6565b9250611bc09050565b848381518110611bb557fe5b602002602001015190505b6000611bcc8a84612b97565b90508015611c3957611bfd828a6001840381518110611be757fe5b6020026020010151612bed90919063ffffffff16565b896001830381518110611c0c57fe5b60200260200101818152505060018103888581518110611c2857fe5b602002602001018181525050611c9e565b828a8681518110611c4657fe5b60200260200101906001600160a01b031690816001600160a01b03168152505081898681518110611c7357fe5b60200260200101818152505084888581518110611c8c57fe5b60209081029190910101526001909401935b505050600101611b44565b50505050955095509592505050565b606080606080611cca87878b8b610e1b565b9150915081516001600160401b0381118015611ce557600080fd5b50604051908082528060200260200182016040528015611d0f578160200160208202803683370190505b50935081516001600160401b0381118015611d2957600080fd5b50604051908082528060200260200182016040528015611d53578160200160208202803683370190505b5092506000805b8351811015611e74576000848281518110611d7157fe5b602002602001015190506000611d86826128f5565b15611dbf57611da982868581518110611d9b57fe5b60200260200101518b612c12565b90506000611db683612af6565b9250611dd69050565b848381518110611dcb57fe5b602002602001015190505b6000611de28984612b97565b90508015611e1d57611dfd82896001840381518110611be757fe5b886001830381518110611e0c57fe5b602002602001018181525050611e69565b82898681518110611e2a57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505081888681518110611e5757fe5b60209081029190910101526001909401935b505050600101611d5a565b505050509550959350505050565b610758846323b872dd60e01b8585856040516024016116ab93929190613898565b6000611eb5838363ffffffff611a3416565b90508015610758576107586001600160a01b038516338363ffffffff61168c16565b6000611f01670de0b6b3a7640000611ef5858563ffffffff612c5a16565b9063ffffffff612c9416565b9392505050565b6000611f256001600160a01b03851633308663ffffffff611e8216565b611f3f6001600160a01b038516838563ffffffff612cc616565b604051635c833bfd60e01b81526001600160a01b03831690635c833bfd90611f6f9087908790309060040161396e565b600060405180830381600087803b158015611f8957600080fd5b505af1158015611f9d573d6000803e3d6000fd5b505050509392505050565b606080611fc783608001518460a0015185600001518660200151610e1b565b909250905060005b8251811015610758576000838281518110611fe657fe5b602002602001015190506000838381518110611ffe57fe5b60200260200101519050612011826128f5565b1561207a5760405163745d08d960e01b81526001600160a01b0383169063745d08d9906120479084903090600090600401613eb2565b600060405180830381600087803b15801561206157600080fd5b505af1158015612075573d6000803e3d6000fd5b505050505b5050600101611fcf565b6060806120a88460000151856020015186608001518760a001518860c00151611cb8565b9150915082518251146120cd5760405162461bcd60e51b815260040161015d90613a3a565b60005b82518110156122535760008282815181106120e757fe5b6020026020010151905060008483815181106120ff57fe5b6020026020010151905060006001600160a01b0316816001600160a01b0316141561212b575050612253565b86604001516001600160a01b0316816001600160a01b031614612249576040805160e0810182526002546001600160a01b039081168252600354811660208301526004548116928201929092526005548216606082015260065482166080820152600754821660a082015260085490911660c0820152865173bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac91631aafa9d89185906000908b90899081106121d057fe5b60200260200101516040518563ffffffff1660e01b81526004016121f79493929190613e5f565b60206040518083038186803b15801561220f57600080fd5b505af4158015612223573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122479190613640565b505b50506001016120d0565b5050505050565b60606122af826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612d899092919063ffffffff16565b80519091501561168757808060200190518101906122cd919061339c565b6116875760405162461bcd60e51b815260040161015d90613d88565b606080606080606080612313886000015189602001518a608001518b60a001518c60c00151611a5c565b925092509250865183511461233a5760405162461bcd60e51b815260040161015d90613a3a565b606083516001600160401b038111801561235357600080fd5b5060405190808252806020026020018201604052801561237d578160200160208202803683370190505b50905060005b845181101561262e5760006001600160a01b03168582815181106123a357fe5b60200260200101516001600160a01b031614156123bf5761262e565b89604001516001600160a01b03168582815181106123d957fe5b60200260200101516001600160a01b0316146125f95760008582815181106123fd57fe5b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016124309190613829565b60206040518083038186803b15801561244857600080fd5b505afa15801561245c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124809190613640565b6040805160e0810182526002546001600160a01b039081168252600354811660208301526004548116928201929092526005548216606082015260065482166080820152600754821660a082015260085490911660c0820152865191925073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac91636fd7d45f919088908690811061250757fe5b60200260200101518e606001518e878151811061252057fe5b60200260200101516040518563ffffffff1660e01b81526004016125479493929190613e5f565b60206040518083038186803b15801561255f57600080fd5b505af4158015612573573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125979190613640565b506125db818784815181106125a857fe5b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016114f89190613829565b8383815181106125e757fe5b60200260200101818152505050612626565b83818151811061260557fe5b602002602001015182828151811061261957fe5b6020026020010181815250505b600101612383565b5092989297509550909350505050565b60608061265d86608001518760a0015188600001518960200151611120565b909250905060005b82518110156128ec57600083828151811061267c57fe5b60200260200101519050600083838151811061269457fe5b602002602001015190506126a7826128f5565b156128c25760006126b783612af6565b905060008785815181106126c757fe5b6020026020010151905060008982815181106126df57fe5b602002602001015190506127078582856001600160a01b0316612cc69092919063ffffffff16565b6040516370a0823160e01b81526000906001600160a01b038516906370a0823190612736903090600401613829565b60206040518083038186803b15801561274e57600080fd5b505afa158015612762573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127869190613640565b6040516329cf140560e01b81529091506001600160a01b038716906329cf1405906127bc90859089903090600090600401613ee5565b600060405180830381600087803b1580156127d657600080fd5b505af11580156127ea573d6000803e3d6000fd5b50505050600061287c856001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161281f9190613829565b60206040518083038186803b15801561283757600080fd5b505afa15801561284b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061286f9190613640565b839063ffffffff611a3416565b90506128a4818d868151811061288e57fe5b6020026020010151611a3490919063ffffffff16565b8c85815181106128b057fe5b60200260200101818152505050505050505b60808901516128e2906001600160a01b038416908363ffffffff612cc616565b5050600101612665565b50505050505050565b6000612909826001600160a01b0316612d98565b61291557506000612a45565b816001600160a01b03166348d8f98d6009546040518263ffffffff1660e01b8152600401604080518083038187803b15801561295057600080fd5b5086fa93505050508015612981575060408051601f3d908101601f1916820190925261297e91810190613658565b60015b61298d57506000612a45565b6040516395fd976560e01b81526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906395fd9765906129db9085908590600401613e8e565b60206040518083038186803b1580156129f357600080fd5b505afa925050508015612a23575060408051601f3d908101601f19168201909252612a209181019061319b565b60015b612a3257600092505050612a45565b6001600160a01b03858116911614925050505b919050565b6000612aee670de0b6b3a7640000611ef584670de0b6b3a764000001876001600160a01b031663b3d7f6b9886040518263ffffffff1660e01b8152600401612a929190613ea9565b60206040518083038186803b158015612aaa57600080fd5b505afa158015612abe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ae29190613640565b9063ffffffff612c5a16565b949350505050565b6000806000836001600160a01b0316635148955160016040518263ffffffff1660e01b8152600401612b289190613963565b604080518083038186803b158015612b3f57600080fd5b505afa158015612b53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b7791906133b8565b915091508015612b90576008546001600160a01b031691505b5092915050565b6000805b8351811015612be357826001600160a01b0316848281518110612bba57fe5b60200260200101516001600160a01b03161415612bdb5760010190506115e1565b600101612b9b565b5060009392505050565b600082820183811015611f015760405162461bcd60e51b815260040161015d90613a71565b6000612aee670de0b6b3a7640000611ef584670de0b6b3a764000003876001600160a01b0316634cdad506886040518263ffffffff1660e01b8152600401612a929190613ea9565b600082612c69575060006115e1565b82820282848281612c7657fe5b0414611f015760405162461bcd60e51b815260040161015d90613c1e565b6000808211612cb55760405162461bcd60e51b815260040161015d90613bb9565b818381612cbe57fe5b049392505050565b801580612d4e5750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612cfc903090869060040161383d565b60206040518083038186803b158015612d1457600080fd5b505afa158015612d28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d4c9190613640565b155b612d6a5760405162461bcd60e51b815260040161015d90613e09565b6116878363095ea7b360e01b84846040516024016116ab9291906138bc565b6060612aee8484600085612d9e565b3b151590565b606082471015612dc05760405162461bcd60e51b815260040161015d90613b73565b612dc985612d98565b612de55760405162461bcd60e51b815260040161015d90613cc9565b60006060866001600160a01b03168587604051612e02919061380a565b60006040518083038185875af1925050503d8060008114612e3f576040519150601f19603f3d011682016040523d82523d6000602084013e612e44565b606091505b5091509150611a2982828660608315612e5e575081611f01565b825115612e6e5782518084602001fd5b8160405162461bcd60e51b815260040161015d9190613991565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081019190915290565b80356115e181613f8d565b600082601f830112612ee7578081fd5b8135612efa612ef582613f42565b613f1c565b818152915060208083019084810181840286018201871015612f1b57600080fd5b60005b84811015612f43578135612f3181613f8d565b84529282019290820190600101612f1e565b505050505092915050565b600082601f830112612f5e578081fd5b8151612f6c612ef582613f42565b818152915060208083019084810181840286018201871015612f8d57600080fd5b60005b84811015612f43578151612fa381613f8d565b84529282019290820190600101612f90565b600082601f830112612fc5578081fd5b8135612fd3612ef582613f42565b818152915060208083019084810160005b84811015612f435781358701608080601f19838c0301121561300557600080fd5b61300e81613f1c565b858301356001600160401b038082111561302757600080fd5b6130358d8984880101612ed7565b835260409150818501358181111561304c57600080fd5b61305a8e8a83890101613097565b898501525050606061306e8d828701612ecc565b8284015261307e8d858701613170565b9083015250865250509282019290820190600101612fe4565b600082601f8301126130a7578081fd5b81356130b5612ef582613f42565b8181529150602080830190848101818402860182018710156130d657600080fd5b6000805b8581101561310657823562ffffff811681146130f4578283fd5b855293830193918301916001016130da565b50505050505092915050565b600082601f830112613122578081fd5b8151613130612ef582613f42565b81815291506020808301908481018184028601820187101561315157600080fd5b60005b84811015612f4357815184529282019290820190600101613154565b8035600581106115e157600080fd5b600060208284031215613190578081fd5b8135611f0181613f8d565b6000602082840312156131ac578081fd5b8151611f0181613f8d565b600080600080608085870312156131cc578283fd5b84356131d781613f8d565b935060208501356131e781613fa5565b925060408501356131f781613f8d565b9396929550929360600135925050565b600060208284031215613218578081fd5b81516001600160401b0381111561322d578182fd5b612aee84828501612f4e565b6000806040838503121561324b578182fd5b82516001600160401b0380821115613261578384fd5b61326d86838701612f4e565b93506020850151915080821115613282578283fd5b5061328f85828601613112565b9150509250929050565b6000806000606084860312156132ad578081fd5b83516001600160401b03808211156132c3578283fd5b6132cf87838801612f4e565b945060208601519150808211156132e4578283fd5b6132f087838801613112565b93506040860151915080821115613305578283fd5b5061331286828701613112565b9150509250925092565b600080600060408486031215613330578081fd5b83356001600160401b0380821115613346578283fd5b81860187601f820112613357578384fd5b8035925081831115613367578384fd5b876020808502830101111561337a578384fd5b602090810195509193505084013561339181613f8d565b809150509250925092565b6000602082840312156133ad578081fd5b8151611f0181613fa5565b600080604083850312156133ca578182fd5b82516133d581613f8d565b60208401519092506133e681613fa5565b809150509250929050565b60008060008060008060008060006101208a8c03121561340f578687fd5b893561341a81613f8d565b985060208a013561342a81613f8d565b975060408a0135965060608a0135955060808a01356001600160401b03811115613452578586fd5b61345e8c828d01612fb5565b95505060a08a013561346f81613f8d565b935060c08a013561347f81613fa5565b925060e08a013591506101008a013561349781613fa5565b809150509295985092959850929598565b600080600080600060a086880312156134bf578283fd5b85356134ca81613f8d565b94506020860135935060408601356134e181613f8d565b925060608601356134f181613fa5565b949793965091946080013592915050565b600080600080600080600060e0888a03121561351c578081fd5b873561352781613f8d565b96506020880135955060408801356001600160401b03811115613548578182fd5b6135548a828b01612fb5565b955050606088013561356581613f8d565b9350608088013561357581613fa5565b925060a0880135915060c088013561358c81613fa5565b8091505092959891949750929550565b600080600080600080600080610100898b0312156135b8578182fd5b88356135c381613f8d565b9750602089013596506040890135955060608901356001600160401b038111156135eb578283fd5b6135f78b828c01612fb5565b955050608089013561360881613f8d565b935060a089013561361881613fa5565b925060c0890135915060e089013561362f81613fa5565b809150509295985092959890939650565b600060208284031215613651578081fd5b5051919050565b6000806040838503121561366a578182fd5b825161ffff8116811461367b578283fd5b602084015190925064ffffffffff811681146133e6578182fd5b6000602082840312156136a6578081fd5b5035919050565b6001600160a01b0316815260200190565b62ffffff16815260200190565b815260200190565b6001600160a01b03169052565b600581106136ea57fe5b9052565b80516001600160a01b03908116835260208083015182169084015260408083015182169084015260608083015182169084015260808083015182169084015260a08281015182169084015260c09182015116910152565b60006080830182516080855281815161375e8185613ea9565b60209450859390925084015b8184101561378d5761377d8382516136ad565b600194909401939250840161376a565b5050828501519150858103838701528082516137a98184613ea9565b86948601935091505b808410156137d7576137c58284516136be565b915084830192506001840193506137b2565b50604086015193506137ec60408801856136d3565b6060860151935061380060608801856136e0565b9695505050505050565b6000825161381c818460208701613f61565b9190910192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b03978816815295871660208701529386166040860152918516606085015284166080840152831660a083015290911660c082015260e00190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b604080825283519082018190526000906020906060840190828701845b82811015613915576139058483516136d3565b92840192908401906001016138f2565b5050508381038285015280855161392c8184613ea9565b91508387019250845b81811015613956576139488385516136cb565b938501939250600101613935565b5090979650505050505050565b901515815260200190565b6001600160a01b0393841681526020810192909252909116604082015260600190565b60006020825282518060208401526139b0816040850160208701613f61565b601f01601f19169190910160400192915050565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b602080825260169082015275119b185cda135a5b9d0e8815539111549093d551d21560521b604082015260600190565b6020808252601e908201527f436f6d706f6e656e7473202f205377617064617461206d69736d617463680000604082015260600190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252601e908201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604082015260600190565b6020808252603a908201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260408201527f6563697069656e74206d61792068617665207265766572746564000000000000606082015260800190565b6020808252601d908201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604082015260600190565b60208082526026908201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6040820152651c8818d85b1b60d21b606082015260800190565b6020808252601a908201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604082015260600190565b602080825260149082015273119b185cda135a5b9d0e8813d5915494d411539560621b604082015260600190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252818101527f4465636f64656449644761734c696d69742063616e6e6f74206265207a65726f604082015260600190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b60208082526022908201527f466c6173684d696e743a20494e56414c49442049535355414e4345204d4f44556040820152614c4560f01b606082015260800190565b60208082526026908201527f466c6173684d696e743a20446972656374206465706f73697473206e6f7420616040820152651b1b1bddd95960d21b606082015260800190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526036908201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60408201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606082015260800190565b6000610140613e6e83886136ee565b8560e08401528461010084015280610120840152611a2981840185613745565b61ffff92909216825264ffffffffff16602082015260400190565b90815260200190565b9283526001600160a01b0391909116602083015263ffffffff16604082015260600190565b918252602082015260400190565b9384526affffffffffffffffffffff9290921660208401526001600160a01b0316604083015263ffffffff16606082015260800190565b6040518181016001600160401b0381118282101715613f3a57600080fd5b604052919050565b60006001600160401b03821115613f57578081fd5b5060209081020190565b60005b83811015613f7c578181015183820152602001613f64565b838111156107585750506000910152565b6001600160a01b0381168114613fa257600080fd5b50565b8015158114613fa257600080fdfea26469706673582212204ce2aabc1893b80cf9e5e4a51977682fcd46207c9b7c0ec074517926384fd6d164736f6c634300060a0033000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000d2463675a099101e36d85278494268261a66603a0000000000000000000000005d051deb5db151c2172dcdccd42e6a2953e27261000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c434160000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab60000000000000000000000000000000022d53366457f9d5e68ec105046fc4383000000000000000000000000c1db00a8e5ef7bfa476395cdbcc98235477cde4e00000000000000000000000000000000000000000000000000000000000f4240

Deployed Bytecode

0x60806040526004361061012e5760003560e01c80637030aaa4116100ab578063b50452b21161006f578063b50452b21461032d578063da0321cd1461034d578063df0ba4f814610375578063e042a0af1461038a578063f2fde38b146103aa578063f633e0de146103ca57610168565b80637030aaa4146102b7578063715018a6146102cc5780638b2704ec146102e15780638da5cb5b14610303578063a734f06e1461031857610168565b806330519c5a116100f257806330519c5a146102175780635f20c7c91461023757806364eab7ff14610257578063658b457d146102775780636b211d8f1461029757610168565b80630da8acc91461016d5780630e8cc705146101a35780632111dd0e146101b657806329f82a55146101c95780632f5c5de8146101f757610168565b36610168576008546001600160a01b031633146101665760405162461bcd60e51b815260040161015d90613d42565b60405180910390fd5b005b600080fd5b34801561017957600080fd5b5061018d61018836600461359c565b6103df565b60405161019a9190613ea9565b60405180910390f35b6101666101b136600461331c565b6105cc565b61018d6101c4366004613502565b61075e565b3480156101d557600080fd5b506101e96101e43660046134a8565b6109c6565b60405161019a9291906138d5565b34801561020357600080fd5b506101e96102123660046134a8565b6109e5565b34801561022357600080fd5b506101e96102323660046134a8565b610a73565b34801561024357600080fd5b5061018d6102523660046133f1565b610a91565b34801561026357600080fd5b506101e96102723660046134a8565b610c1f565b34801561028357600080fd5b5061018d6102923660046133f1565b610cad565b3480156102a357600080fd5b506101e96102b23660046131b7565b610e1b565b3480156102c357600080fd5b5061018d611046565b3480156102d857600080fd5b5061016661104c565b3480156102ed57600080fd5b506102f66110d5565b60405161019a9190613829565b34801561030f57600080fd5b506102f66110f9565b34801561032457600080fd5b506102f6611108565b34801561033957600080fd5b506101e96103483660046131b7565b611120565b34801561035957600080fd5b506103626111e6565b60405161019a9796959493929190613857565b34801561038157600080fd5b506102f661121f565b34801561039657600080fd5b506101666103a5366004613695565b611243565b3480156103b657600080fd5b506101666103c536600461317f565b6112a4565b3480156103d657600080fd5b506102f6611364565b6000847f000000000000000000000000d2463675a099101e36d85278494268261a66603a6001600160a01b03166342f6e389826040518263ffffffff1660e01b815260040161042e9190613829565b60206040518083038186803b15801561044657600080fd5b505afa15801561045a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047e919061339c565b61049a5760405162461bcd60e51b815260040161015d90613d00565b600260015414156104bd5760405162461bcd60e51b815260040161015d90613dd2565b60026001556104ca612e88565b5060408051610100810182526001600160a01b03808d168252602082018c9052600854811692820192909252606081018a9052908716608082015285151560a082015260c0810185905283151560e08201526000610528828a611388565b600854604051632e1a7d4d60e01b81529192506001600160a01b031690632e1a7d4d90610559908490600401613ea9565b600060405180830381600087803b15801561057357600080fd5b505af1158015610587573d6000803e3d6000fd5b505060405133925083156108fc02915083906000818181858888f193505050501580156105b8573d6000803e3d6000fd5b50600180559b9a5050505050505050505050565b6105d46115e7565b6001600160a01b03166105e56110f9565b6001600160a01b03161461060b5760405162461bcd60e51b815260040161015d90613c5f565b60005b828110156107585773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee84848381811061063757fe5b905060200201602081019061064c919061317f565b6001600160a01b03161415610679576106746001600160a01b0383164763ffffffff6115eb16565b610750565b6107508285858481811061068957fe5b905060200201602081019061069e919061317f565b6001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016106c99190613829565b60206040518083038186803b1580156106e157600080fd5b505afa1580156106f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107199190613640565b86868581811061072557fe5b905060200201602081019061073a919061317f565b6001600160a01b0316919063ffffffff61168c16565b60010161060e565b50505050565b6000847f000000000000000000000000d2463675a099101e36d85278494268261a66603a6001600160a01b03166342f6e389826040518263ffffffff1660e01b81526004016107ad9190613829565b60206040518083038186803b1580156107c557600080fd5b505afa1580156107d9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107fd919061339c565b6108195760405162461bcd60e51b815260040161015d90613d00565b6002600154141561083c5760405162461bcd60e51b815260040161015d90613dd2565b600260015560085460408051630d0e30db60e41b815290516001600160a01b039092169163d0e30db0913491600480830192600092919082900301818588803b15801561088857600080fd5b505af115801561089c573d6000803e3d6000fd5b50505050506108a9612e88565b5060408051610100810182526001600160a01b03808c168252602082018b9052600854811692820192909252346060820152908716608082015285151560a082015260c0810185905283151560e08201526000610906828a6116e2565b9050600061091a348363ffffffff611a3416565b905080156109b357600854604051632e1a7d4d60e01b81526001600160a01b0390911690632e1a7d4d90610952908490600401613ea9565b600060405180830381600087803b15801561096c57600080fd5b505af1158015610980573d6000803e3d6000fd5b505060405133925083156108fc02915083906000818181858888f193505050501580156109b1573d6000803e3d6000fd5b505b50600180559a9950505050505050505050565b6060806109d68787878787611a5c565b50909890975095505050505050565b6060807f000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c434166001600160a01b031663a2306c89886040518263ffffffff1660e01b8152600401610a349190613829565b600060405180830381600087803b158015610a4e57600080fd5b505af1158015610a62573d6000803e3d6000fd5b505050506109d68787878787611a5c565b606080610a838787878787611cb8565b915091509550959350505050565b6000847f000000000000000000000000d2463675a099101e36d85278494268261a66603a6001600160a01b03166342f6e389826040518263ffffffff1660e01b8152600401610ae09190613829565b60206040518083038186803b158015610af857600080fd5b505afa158015610b0c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610b30919061339c565b610b4c5760405162461bcd60e51b815260040161015d90613d00565b60026001541415610b6f5760405162461bcd60e51b815260040161015d90613dd2565b6002600155610b8f6001600160a01b038b1633308b63ffffffff611e8216565b610b97612e88565b6040518061010001604052808d6001600160a01b031681526020018b81526020018c6001600160a01b031681526020018a8152602001886001600160a01b03168152602001871515815260200186815260200185151581525090506000610bfe828a6116e2565b9050610c0b8c8b83611ea3565b600180559c9b505050505050505050505050565b6060807f000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c434166001600160a01b031663a2306c89886040518263ffffffff1660e01b8152600401610c6e9190613829565b600060405180830381600087803b158015610c8857600080fd5b505af1158015610c9c573d6000803e3d6000fd5b50505050610a838787878787611cb8565b6000847f000000000000000000000000d2463675a099101e36d85278494268261a66603a6001600160a01b03166342f6e389826040518263ffffffff1660e01b8152600401610cfc9190613829565b60206040518083038186803b158015610d1457600080fd5b505afa158015610d28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d4c919061339c565b610d685760405162461bcd60e51b815260040161015d90613d00565b60026001541415610d8b5760405162461bcd60e51b815260040161015d90613dd2565b6002600155610d98612e88565b6040518061010001604052808d6001600160a01b031681526020018b81526020018c6001600160a01b031681526020018a8152602001886001600160a01b03168152602001871515815260200186815260200185151581525090506000610dff828a611388565b9050610c0b6001600160a01b038d16338363ffffffff61168c16565b6060808415610eb1576040516335c729db60e11b81526001600160a01b03871690636b8e53b690610e5290879087906004016138bc565b60006040518083038186803b158015610e6a57600080fd5b505afa158015610e7e573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610ea69190810190613299565b50909250905061103d565b836001600160a01b03166399d50d5d6040518163ffffffff1660e01b815260040160006040518083038186803b158015610eea57600080fd5b505afa158015610efe573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052610f269190810190613207565b915081516001600160401b0381118015610f3f57600080fd5b50604051908082528060200260200182016040528015610f69578160200160208202803683370190505b50905060005b825181101561103b576000856001600160a01b03166366cb8d2f858481518110610f9557fe5b60200260200101516040518263ffffffff1660e01b8152600401610fb99190613829565b60206040518083038186803b158015610fd157600080fd5b505afa158015610fe5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110099190613640565b905061101b818663ffffffff611ed716565b83838151811061102757fe5b602090810291909101015250600101610f6f565b505b94509492505050565b60095481565b6110546115e7565b6001600160a01b03166110656110f9565b6001600160a01b03161461108b5760405162461bcd60e51b815260040161015d90613c5f565b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b7f000000000000000000000000d2463675a099101e36d85278494268261a66603a81565b6000546001600160a01b031690565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b60608084156111575760405163131e26b960e01b81526001600160a01b0387169063131e26b990610e5290879087906004016138bc565b604051637a4ffd0360e01b81526001600160a01b03871690637a4ffd039061118590879087906004016138bc565b60006040518083038186803b15801561119d57600080fd5b505afa1580156111b1573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526111d99190810190613239565b9097909650945050505050565b6002546003546004546005546006546007546008546001600160a01b039687169695861695948516949384169392831692918216911687565b7f000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c4341681565b61124b6115e7565b6001600160a01b031661125c6110f9565b6001600160a01b0316146112825760405162461bcd60e51b815260040161015d90613c5f565b8061129f5760405162461bcd60e51b815260040161015d90613c94565b600955565b6112ac6115e7565b6001600160a01b03166112bd6110f9565b6001600160a01b0316146112e35760405162461bcd60e51b815260040161015d90613c5f565b6001600160a01b0381166113095760405162461bcd60e51b815260040161015d906139c4565b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b7f0000000000000000000000005d051deb5db151c2172dcdccd42e6a2953e2726181565b60008083604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016113bb9190613829565b60206040518083038186803b1580156113d357600080fd5b505afa1580156113e7573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061140b9190613640565b90508360e001511561149757835160405163a2306c8960e01b81526001600160a01b037f000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c43416169163a2306c89916114649190600401613829565b600060405180830381600087803b15801561147e57600080fd5b505af1158015611492573d6000803e3d6000fd5b505050505b6114ae846000015185602001518660800151611f08565b506114b884611fa8565b6114c28484612084565b60006115548286604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016114f89190613829565b60206040518083038186803b15801561151057600080fd5b505afa158015611524573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115489190613640565b9063ffffffff611a3416565b9050846060015181101561157a5760405162461bcd60e51b815260040161015d90613a0a565b84604001516001600160a01b031685600001516001600160a01b0316336001600160a01b03167f846f5655f4f8fa6ef5e4ad493e284e34854a83d000836d0493800c259ea970658860200151856040516115d5929190613ed7565b60405180910390a49150505b92915050565b3390565b8047101561160b5760405162461bcd60e51b815260040161015d90613b3c565b6000826001600160a01b03168260405161162490613826565b60006040518083038185875af1925050503d8060008114611661576040519150601f19603f3d011682016040523d82523d6000602084013e611666565b606091505b50509050806116875760405162461bcd60e51b815260040161015d90613adf565b505050565b6116878363a9059cbb60e01b84846040516024016116ab9291906138bc565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915261225a565b60008083604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016117159190613829565b60206040518083038186803b15801561172d57600080fd5b505afa158015611741573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117659190613640565b90508360e00151156117f157835160405163a2306c8960e01b81526001600160a01b037f000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c43416169163a2306c89916117be9190600401613829565b600060405180830381600087803b1580156117d857600080fd5b505af11580156117ec573d6000803e3d6000fd5b505050505b606080606061180087876122e9565b9250925092506118128784848461263e565b6080870151875160208901516040516336bc7a3d60e11b81526001600160a01b0390931692636d78f47a9261184d929091339060040161396e565b600060405180830381600087803b15801561186757600080fd5b505af115801561187b573d6000803e3d6000fd5b50505050866060015161191488604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016118b79190613829565b60206040518083038186803b1580156118cf57600080fd5b505afa1580156118e3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119079190613640565b869063ffffffff611a3416565b11156119325760405162461bcd60e51b815260040161015d90613bf0565b86604001516001600160a01b031687600001516001600160a01b0316336001600160a01b03167f9c1558194024d73db1b6fc2739c3070cacc4598122100dd6f7d3a3dd8cee5f368a606001518b60200151604051611991929190613ed7565b60405180910390a4611a2987604001516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016119cc9190613829565b60206040518083038186803b1580156119e457600080fd5b505afa1580156119f8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1c9190613640565b859063ffffffff611a3416565b979650505050505050565b600082821115611a565760405162461bcd60e51b815260040161015d90613aa8565b50900390565b6060806060806060611a7088888c8c611120565b9150915081516001600160401b0381118015611a8b57600080fd5b50604051908082528060200260200182016040528015611ab5578160200160208202803683370190505b50945081516001600160401b0381118015611acf57600080fd5b50604051908082528060200260200182016040528015611af9578160200160208202803683370190505b50935081516001600160401b0381118015611b1357600080fd5b50604051908082528060200260200182016040528015611b3d578160200160208202803683370190505b5092506000805b8351811015611ca9576000848281518110611b5b57fe5b602002602001015190506000611b70826128f5565b15611ba957611b9382868581518110611b8557fe5b60200260200101518c612a4a565b90506000611ba083612af6565b9250611bc09050565b848381518110611bb557fe5b602002602001015190505b6000611bcc8a84612b97565b90508015611c3957611bfd828a6001840381518110611be757fe5b6020026020010151612bed90919063ffffffff16565b896001830381518110611c0c57fe5b60200260200101818152505060018103888581518110611c2857fe5b602002602001018181525050611c9e565b828a8681518110611c4657fe5b60200260200101906001600160a01b031690816001600160a01b03168152505081898681518110611c7357fe5b60200260200101818152505084888581518110611c8c57fe5b60209081029190910101526001909401935b505050600101611b44565b50505050955095509592505050565b606080606080611cca87878b8b610e1b565b9150915081516001600160401b0381118015611ce557600080fd5b50604051908082528060200260200182016040528015611d0f578160200160208202803683370190505b50935081516001600160401b0381118015611d2957600080fd5b50604051908082528060200260200182016040528015611d53578160200160208202803683370190505b5092506000805b8351811015611e74576000848281518110611d7157fe5b602002602001015190506000611d86826128f5565b15611dbf57611da982868581518110611d9b57fe5b60200260200101518b612c12565b90506000611db683612af6565b9250611dd69050565b848381518110611dcb57fe5b602002602001015190505b6000611de28984612b97565b90508015611e1d57611dfd82896001840381518110611be757fe5b886001830381518110611e0c57fe5b602002602001018181525050611e69565b82898681518110611e2a57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505081888681518110611e5757fe5b60209081029190910101526001909401935b505050600101611d5a565b505050509550959350505050565b610758846323b872dd60e01b8585856040516024016116ab93929190613898565b6000611eb5838363ffffffff611a3416565b90508015610758576107586001600160a01b038516338363ffffffff61168c16565b6000611f01670de0b6b3a7640000611ef5858563ffffffff612c5a16565b9063ffffffff612c9416565b9392505050565b6000611f256001600160a01b03851633308663ffffffff611e8216565b611f3f6001600160a01b038516838563ffffffff612cc616565b604051635c833bfd60e01b81526001600160a01b03831690635c833bfd90611f6f9087908790309060040161396e565b600060405180830381600087803b158015611f8957600080fd5b505af1158015611f9d573d6000803e3d6000fd5b505050509392505050565b606080611fc783608001518460a0015185600001518660200151610e1b565b909250905060005b8251811015610758576000838281518110611fe657fe5b602002602001015190506000838381518110611ffe57fe5b60200260200101519050612011826128f5565b1561207a5760405163745d08d960e01b81526001600160a01b0383169063745d08d9906120479084903090600090600401613eb2565b600060405180830381600087803b15801561206157600080fd5b505af1158015612075573d6000803e3d6000fd5b505050505b5050600101611fcf565b6060806120a88460000151856020015186608001518760a001518860c00151611cb8565b9150915082518251146120cd5760405162461bcd60e51b815260040161015d90613a3a565b60005b82518110156122535760008282815181106120e757fe5b6020026020010151905060008483815181106120ff57fe5b6020026020010151905060006001600160a01b0316816001600160a01b0316141561212b575050612253565b86604001516001600160a01b0316816001600160a01b031614612249576040805160e0810182526002546001600160a01b039081168252600354811660208301526004548116928201929092526005548216606082015260065482166080820152600754821660a082015260085490911660c0820152865173bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac91631aafa9d89185906000908b90899081106121d057fe5b60200260200101516040518563ffffffff1660e01b81526004016121f79493929190613e5f565b60206040518083038186803b15801561220f57600080fd5b505af4158015612223573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122479190613640565b505b50506001016120d0565b5050505050565b60606122af826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b0316612d899092919063ffffffff16565b80519091501561168757808060200190518101906122cd919061339c565b6116875760405162461bcd60e51b815260040161015d90613d88565b606080606080606080612313886000015189602001518a608001518b60a001518c60c00151611a5c565b925092509250865183511461233a5760405162461bcd60e51b815260040161015d90613a3a565b606083516001600160401b038111801561235357600080fd5b5060405190808252806020026020018201604052801561237d578160200160208202803683370190505b50905060005b845181101561262e5760006001600160a01b03168582815181106123a357fe5b60200260200101516001600160a01b031614156123bf5761262e565b89604001516001600160a01b03168582815181106123d957fe5b60200260200101516001600160a01b0316146125f95760008582815181106123fd57fe5b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016124309190613829565b60206040518083038186803b15801561244857600080fd5b505afa15801561245c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124809190613640565b6040805160e0810182526002546001600160a01b039081168252600354811660208301526004548116928201929092526005548216606082015260065482166080820152600754821660a082015260085490911660c0820152865191925073bb02bcce1bdcc0b07e7870346d8b2ad9397d0fac91636fd7d45f919088908690811061250757fe5b60200260200101518e606001518e878151811061252057fe5b60200260200101516040518563ffffffff1660e01b81526004016125479493929190613e5f565b60206040518083038186803b15801561255f57600080fd5b505af4158015612573573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125979190613640565b506125db818784815181106125a857fe5b60200260200101516001600160a01b03166370a08231306040518263ffffffff1660e01b81526004016114f89190613829565b8383815181106125e757fe5b60200260200101818152505050612626565b83818151811061260557fe5b602002602001015182828151811061261957fe5b6020026020010181815250505b600101612383565b5092989297509550909350505050565b60608061265d86608001518760a0015188600001518960200151611120565b909250905060005b82518110156128ec57600083828151811061267c57fe5b60200260200101519050600083838151811061269457fe5b602002602001015190506126a7826128f5565b156128c25760006126b783612af6565b905060008785815181106126c757fe5b6020026020010151905060008982815181106126df57fe5b602002602001015190506127078582856001600160a01b0316612cc69092919063ffffffff16565b6040516370a0823160e01b81526000906001600160a01b038516906370a0823190612736903090600401613829565b60206040518083038186803b15801561274e57600080fd5b505afa158015612762573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127869190613640565b6040516329cf140560e01b81529091506001600160a01b038716906329cf1405906127bc90859089903090600090600401613ee5565b600060405180830381600087803b1580156127d657600080fd5b505af11580156127ea573d6000803e3d6000fd5b50505050600061287c856001600160a01b03166370a08231306040518263ffffffff1660e01b815260040161281f9190613829565b60206040518083038186803b15801561283757600080fd5b505afa15801561284b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061286f9190613640565b839063ffffffff611a3416565b90506128a4818d868151811061288e57fe5b6020026020010151611a3490919063ffffffff16565b8c85815181106128b057fe5b60200260200101818152505050505050505b60808901516128e2906001600160a01b038416908363ffffffff612cc616565b5050600101612665565b50505050505050565b6000612909826001600160a01b0316612d98565b61291557506000612a45565b816001600160a01b03166348d8f98d6009546040518263ffffffff1660e01b8152600401604080518083038187803b15801561295057600080fd5b5086fa93505050508015612981575060408051601f3d908101601f1916820190925261297e91810190613658565b60015b61298d57506000612a45565b6040516395fd976560e01b81526001600160a01b037f0000000000000000000000005d051deb5db151c2172dcdccd42e6a2953e2726116906395fd9765906129db9085908590600401613e8e565b60206040518083038186803b1580156129f357600080fd5b505afa925050508015612a23575060408051601f3d908101601f19168201909252612a209181019061319b565b60015b612a3257600092505050612a45565b6001600160a01b03858116911614925050505b919050565b6000612aee670de0b6b3a7640000611ef584670de0b6b3a764000001876001600160a01b031663b3d7f6b9886040518263ffffffff1660e01b8152600401612a929190613ea9565b60206040518083038186803b158015612aaa57600080fd5b505afa158015612abe573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ae29190613640565b9063ffffffff612c5a16565b949350505050565b6000806000836001600160a01b0316635148955160016040518263ffffffff1660e01b8152600401612b289190613963565b604080518083038186803b158015612b3f57600080fd5b505afa158015612b53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b7791906133b8565b915091508015612b90576008546001600160a01b031691505b5092915050565b6000805b8351811015612be357826001600160a01b0316848281518110612bba57fe5b60200260200101516001600160a01b03161415612bdb5760010190506115e1565b600101612b9b565b5060009392505050565b600082820183811015611f015760405162461bcd60e51b815260040161015d90613a71565b6000612aee670de0b6b3a7640000611ef584670de0b6b3a764000003876001600160a01b0316634cdad506886040518263ffffffff1660e01b8152600401612a929190613ea9565b600082612c69575060006115e1565b82820282848281612c7657fe5b0414611f015760405162461bcd60e51b815260040161015d90613c1e565b6000808211612cb55760405162461bcd60e51b815260040161015d90613bb9565b818381612cbe57fe5b049392505050565b801580612d4e5750604051636eb1769f60e11b81526001600160a01b0384169063dd62ed3e90612cfc903090869060040161383d565b60206040518083038186803b158015612d1457600080fd5b505afa158015612d28573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d4c9190613640565b155b612d6a5760405162461bcd60e51b815260040161015d90613e09565b6116878363095ea7b360e01b84846040516024016116ab9291906138bc565b6060612aee8484600085612d9e565b3b151590565b606082471015612dc05760405162461bcd60e51b815260040161015d90613b73565b612dc985612d98565b612de55760405162461bcd60e51b815260040161015d90613cc9565b60006060866001600160a01b03168587604051612e02919061380a565b60006040518083038185875af1925050503d8060008114612e3f576040519150601f19603f3d011682016040523d82523d6000602084013e612e44565b606091505b5091509150611a2982828660608315612e5e575081611f01565b825115612e6e5782518084602001fd5b8160405162461bcd60e51b815260040161015d9190613991565b6040805161010081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081019190915290565b80356115e181613f8d565b600082601f830112612ee7578081fd5b8135612efa612ef582613f42565b613f1c565b818152915060208083019084810181840286018201871015612f1b57600080fd5b60005b84811015612f43578135612f3181613f8d565b84529282019290820190600101612f1e565b505050505092915050565b600082601f830112612f5e578081fd5b8151612f6c612ef582613f42565b818152915060208083019084810181840286018201871015612f8d57600080fd5b60005b84811015612f43578151612fa381613f8d565b84529282019290820190600101612f90565b600082601f830112612fc5578081fd5b8135612fd3612ef582613f42565b818152915060208083019084810160005b84811015612f435781358701608080601f19838c0301121561300557600080fd5b61300e81613f1c565b858301356001600160401b038082111561302757600080fd5b6130358d8984880101612ed7565b835260409150818501358181111561304c57600080fd5b61305a8e8a83890101613097565b898501525050606061306e8d828701612ecc565b8284015261307e8d858701613170565b9083015250865250509282019290820190600101612fe4565b600082601f8301126130a7578081fd5b81356130b5612ef582613f42565b8181529150602080830190848101818402860182018710156130d657600080fd5b6000805b8581101561310657823562ffffff811681146130f4578283fd5b855293830193918301916001016130da565b50505050505092915050565b600082601f830112613122578081fd5b8151613130612ef582613f42565b81815291506020808301908481018184028601820187101561315157600080fd5b60005b84811015612f4357815184529282019290820190600101613154565b8035600581106115e157600080fd5b600060208284031215613190578081fd5b8135611f0181613f8d565b6000602082840312156131ac578081fd5b8151611f0181613f8d565b600080600080608085870312156131cc578283fd5b84356131d781613f8d565b935060208501356131e781613fa5565b925060408501356131f781613f8d565b9396929550929360600135925050565b600060208284031215613218578081fd5b81516001600160401b0381111561322d578182fd5b612aee84828501612f4e565b6000806040838503121561324b578182fd5b82516001600160401b0380821115613261578384fd5b61326d86838701612f4e565b93506020850151915080821115613282578283fd5b5061328f85828601613112565b9150509250929050565b6000806000606084860312156132ad578081fd5b83516001600160401b03808211156132c3578283fd5b6132cf87838801612f4e565b945060208601519150808211156132e4578283fd5b6132f087838801613112565b93506040860151915080821115613305578283fd5b5061331286828701613112565b9150509250925092565b600080600060408486031215613330578081fd5b83356001600160401b0380821115613346578283fd5b81860187601f820112613357578384fd5b8035925081831115613367578384fd5b876020808502830101111561337a578384fd5b602090810195509193505084013561339181613f8d565b809150509250925092565b6000602082840312156133ad578081fd5b8151611f0181613fa5565b600080604083850312156133ca578182fd5b82516133d581613f8d565b60208401519092506133e681613fa5565b809150509250929050565b60008060008060008060008060006101208a8c03121561340f578687fd5b893561341a81613f8d565b985060208a013561342a81613f8d565b975060408a0135965060608a0135955060808a01356001600160401b03811115613452578586fd5b61345e8c828d01612fb5565b95505060a08a013561346f81613f8d565b935060c08a013561347f81613fa5565b925060e08a013591506101008a013561349781613fa5565b809150509295985092959850929598565b600080600080600060a086880312156134bf578283fd5b85356134ca81613f8d565b94506020860135935060408601356134e181613f8d565b925060608601356134f181613fa5565b949793965091946080013592915050565b600080600080600080600060e0888a03121561351c578081fd5b873561352781613f8d565b96506020880135955060408801356001600160401b03811115613548578182fd5b6135548a828b01612fb5565b955050606088013561356581613f8d565b9350608088013561357581613fa5565b925060a0880135915060c088013561358c81613fa5565b8091505092959891949750929550565b600080600080600080600080610100898b0312156135b8578182fd5b88356135c381613f8d565b9750602089013596506040890135955060608901356001600160401b038111156135eb578283fd5b6135f78b828c01612fb5565b955050608089013561360881613f8d565b935060a089013561361881613fa5565b925060c0890135915060e089013561362f81613fa5565b809150509295985092959890939650565b600060208284031215613651578081fd5b5051919050565b6000806040838503121561366a578182fd5b825161ffff8116811461367b578283fd5b602084015190925064ffffffffff811681146133e6578182fd5b6000602082840312156136a6578081fd5b5035919050565b6001600160a01b0316815260200190565b62ffffff16815260200190565b815260200190565b6001600160a01b03169052565b600581106136ea57fe5b9052565b80516001600160a01b03908116835260208083015182169084015260408083015182169084015260608083015182169084015260808083015182169084015260a08281015182169084015260c09182015116910152565b60006080830182516080855281815161375e8185613ea9565b60209450859390925084015b8184101561378d5761377d8382516136ad565b600194909401939250840161376a565b5050828501519150858103838701528082516137a98184613ea9565b86948601935091505b808410156137d7576137c58284516136be565b915084830192506001840193506137b2565b50604086015193506137ec60408801856136d3565b6060860151935061380060608801856136e0565b9695505050505050565b6000825161381c818460208701613f61565b9190910192915050565b90565b6001600160a01b0391909116815260200190565b6001600160a01b0392831681529116602082015260400190565b6001600160a01b03978816815295871660208701529386166040860152918516606085015284166080840152831660a083015290911660c082015260e00190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6001600160a01b03929092168252602082015260400190565b604080825283519082018190526000906020906060840190828701845b82811015613915576139058483516136d3565b92840192908401906001016138f2565b5050508381038285015280855161392c8184613ea9565b91508387019250845b81811015613956576139488385516136cb565b938501939250600101613935565b5090979650505050505050565b901515815260200190565b6001600160a01b0393841681526020810192909252909116604082015260600190565b60006020825282518060208401526139b0816040850160208701613f61565b601f01601f19169190910160400192915050565b60208082526026908201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160408201526564647265737360d01b606082015260800190565b602080825260169082015275119b185cda135a5b9d0e8815539111549093d551d21560521b604082015260600190565b6020808252601e908201527f436f6d706f6e656e7473202f205377617064617461206d69736d617463680000604082015260600190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252601e908201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604082015260600190565b6020808252603a908201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260408201527f6563697069656e74206d61792068617665207265766572746564000000000000606082015260800190565b6020808252601d908201527f416464726573733a20696e73756666696369656e742062616c616e6365000000604082015260600190565b60208082526026908201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6040820152651c8818d85b1b60d21b606082015260800190565b6020808252601a908201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604082015260600190565b602080825260149082015273119b185cda135a5b9d0e8813d5915494d411539560621b604082015260600190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b6020808252818101527f4465636f64656449644761734c696d69742063616e6e6f74206265207a65726f604082015260600190565b6020808252601d908201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604082015260600190565b60208082526022908201527f466c6173684d696e743a20494e56414c49442049535355414e4345204d4f44556040820152614c4560f01b606082015260800190565b60208082526026908201527f466c6173684d696e743a20446972656374206465706f73697473206e6f7420616040820152651b1b1bddd95960d21b606082015260800190565b6020808252602a908201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6040820152691bdd081cdd58d8d9595960b21b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60208082526036908201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60408201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606082015260800190565b6000610140613e6e83886136ee565b8560e08401528461010084015280610120840152611a2981840185613745565b61ffff92909216825264ffffffffff16602082015260400190565b90815260200190565b9283526001600160a01b0391909116602083015263ffffffff16604082015260600190565b918252602082015260400190565b9384526affffffffffffffffffffff9290921660208401526001600160a01b0316604083015263ffffffff16606082015260800190565b6040518181016001600160401b0381118282101715613f3a57600080fd5b604052919050565b60006001600160401b03821115613f57578081fd5b5060209081020190565b60005b83811015613f7c578181015183820152602001613f64565b838111156107585750506000910152565b6001600160a01b0381168114613fa257600080fd5b50565b8015158114613fa257600080fdfea26469706673582212204ce2aabc1893b80cf9e5e4a51977682fcd46207c9b7c0ec074517926384fd6d164736f6c634300060a0033

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

000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000d2463675a099101e36d85278494268261a66603a0000000000000000000000005d051deb5db151c2172dcdccd42e6a2953e27261000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c434160000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab60000000000000000000000000000000022d53366457f9d5e68ec105046fc4383000000000000000000000000c1db00a8e5ef7bfa476395cdbcc98235477cde4e00000000000000000000000000000000000000000000000000000000000f4240

-----Decoded View---------------
Arg [0] : _weth (address): 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
Arg [1] : _setController (address): 0xD2463675a099101E36D85278494268261a66603A
Arg [2] : _wrappedfCashFactory (address): 0x5D051DeB5db151C2172dCdCCD42e6A2953E27261
Arg [3] : _notionalTradeModule (address): 0x600d9950c6ecAef98Cc42fa207E92397A6c43416
Arg [4] : _quickRouter (address): 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
Arg [5] : _sushiRouter (address): 0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F
Arg [6] : _uniV3Router (address): 0xE592427A0AEce92De3Edee1F18E0157C05861564
Arg [7] : _uniV3Quoter (address): 0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6
Arg [8] : _curveAddressProvider (address): 0x0000000022D53366457F9d5E68Ec105046FC4383
Arg [9] : _curveCalculator (address): 0xc1DB00a8E5Ef7bfa476395cdbcc98235477cDE4E
Arg [10] : _decodedIdGasLimit (uint256): 1000000

-----Encoded View---------------
11 Constructor Arguments found :
Arg [0] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [1] : 000000000000000000000000d2463675a099101e36d85278494268261a66603a
Arg [2] : 0000000000000000000000005d051deb5db151c2172dcdccd42e6a2953e27261
Arg [3] : 000000000000000000000000600d9950c6ecaef98cc42fa207e92397a6c43416
Arg [4] : 0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d
Arg [5] : 000000000000000000000000d9e1ce17f2641f24ae83637ab66a2cca9c378b9f
Arg [6] : 000000000000000000000000e592427a0aece92de3edee1f18e0157c05861564
Arg [7] : 000000000000000000000000b27308f9f90d607463bb33ea1bebb41c27ce5ab6
Arg [8] : 0000000000000000000000000000000022d53366457f9d5e68ec105046fc4383
Arg [9] : 000000000000000000000000c1db00a8e5ef7bfa476395cdbcc98235477cde4e
Arg [10] : 00000000000000000000000000000000000000000000000000000000000f4240


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  ]

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.