ETH Price: $2,531.91 (+1.20%)

Contract

0x7d3f7EDD04916F3Cb2bC6740224c636B9AE43200
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Iterate Rebalanc...179384362023-08-18 1:34:35381 days ago1692322475IN
0x7d3f7EDD...B9AE43200
0 ETH0.0216074424.56122438
Iterate Rebalanc...179384002023-08-18 1:27:23381 days ago1692322043IN
0x7d3f7EDD...B9AE43200
0 ETH0.0259667129.51642371
Iterate Rebalanc...179383622023-08-18 1:19:47381 days ago1692321587IN
0x7d3f7EDD...B9AE43200
0 ETH0.0223878125.60940142
Iterate Rebalanc...179383412023-08-18 1:15:23381 days ago1692321323IN
0x7d3f7EDD...B9AE43200
0 ETH0.0240862227.37886547
Iterate Rebalanc...179383032023-08-18 1:07:47381 days ago1692320867IN
0x7d3f7EDD...B9AE43200
0 ETH0.0234786926.85726105
Iterate Rebalanc...179382972023-08-18 1:06:35381 days ago1692320795IN
0x7d3f7EDD...B9AE43200
0 ETH0.0245513627.9075861
Iterate Rebalanc...179382602023-08-18 0:59:11381 days ago1692320351IN
0x7d3f7EDD...B9AE43200
0 ETH0.0268014930.46531919
Iterate Rebalanc...179382342023-08-18 0:53:59381 days ago1692320039IN
0x7d3f7EDD...B9AE43200
0 ETH0.0339146738.79496109
Iterate Rebalanc...179382272023-08-18 0:52:35381 days ago1692319955IN
0x7d3f7EDD...B9AE43200
0 ETH0.0322758836.68806668
Iterate Rebalanc...179381882023-08-18 0:44:35381 days ago1692319475IN
0x7d3f7EDD...B9AE43200
0 ETH0.0222329325.27222222
Iterate Rebalanc...179381252023-08-18 0:31:35381 days ago1692318695IN
0x7d3f7EDD...B9AE43200
0 ETH0.0261004329.6684214
Iterate Rebalanc...179380912023-08-18 0:24:47381 days ago1692318287IN
0x7d3f7EDD...B9AE43200
0 ETH0.0266176930.25638495
Iterate Rebalanc...179380552023-08-18 0:17:35381 days ago1692317855IN
0x7d3f7EDD...B9AE43200
0 ETH0.0282665232.33404726
Iterate Rebalanc...179380512023-08-18 0:16:47381 days ago1692317807IN
0x7d3f7EDD...B9AE43200
0 ETH0.0302241734.35587919
Iterate Rebalanc...179380012023-08-18 0:06:47381 days ago1692317207IN
0x7d3f7EDD...B9AE43200
0 ETH0.0370578842.1237752
Iterate Rebalanc...179379592023-08-17 23:58:23381 days ago1692316703IN
0x7d3f7EDD...B9AE43200
0 ETH0.0341128438.7761456
Iterate Rebalanc...179379432023-08-17 23:55:11381 days ago1692316511IN
0x7d3f7EDD...B9AE43200
0 ETH0.0379443743.40453706
Iterate Rebalanc...179379342023-08-17 23:53:23381 days ago1692316403IN
0x7d3f7EDD...B9AE43200
0 ETH0.0372531142.34569152
Iterate Rebalanc...179378902023-08-17 23:44:35381 days ago1692315875IN
0x7d3f7EDD...B9AE43200
0 ETH0.0330810437.84137938
Iterate Rebalanc...179378852023-08-17 23:43:35381 days ago1692315815IN
0x7d3f7EDD...B9AE43200
0 ETH0.0350863439.88272269
Iterate Rebalanc...179378382023-08-17 23:34:11381 days ago1692315251IN
0x7d3f7EDD...B9AE43200
0 ETH0.0465398752.90197489
Iterate Rebalanc...177922792023-07-28 14:55:11402 days ago1690556111IN
0x7d3f7EDD...B9AE43200
0 ETH0.0278580531.86669909
Iterate Rebalanc...177633362023-07-24 13:43:47406 days ago1690206227IN
0x7d3f7EDD...B9AE43200
0 ETH0.0328929437.62607639
Iterate Rebalanc...177632952023-07-24 13:35:35406 days ago1690205735IN
0x7d3f7EDD...B9AE43200
0 ETH0.0355358740.64931
Iterate Rebalanc...177632542023-07-24 13:27:23406 days ago1690205243IN
0x7d3f7EDD...B9AE43200
0 ETH0.0352032740.52543618
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AaveV3LeverageStrategyExtension

Compiler Version
v0.6.10+commit.00c0fcaf

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, Apache-2.0 license
File 1 of 17 : AaveV3LeverageStrategyExtension.sol
/*
    Copyright 2023 Index Coop

    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 {AaveLeverageStrategyExtension} from "./AaveLeverageStrategyExtension.sol";

import {IBaseManager} from "../interfaces/IBaseManager.sol";

/**
 * @title AaveV3LeverageStrategyExtension
 * @author Index Coop
 *
 * Extension of AaveLeverageStrategyExtension to add endpoint for setting the eMode categoryId
 *
 */
contract AaveV3LeverageStrategyExtension is AaveLeverageStrategyExtension {
    constructor(
        IBaseManager _manager,
        ContractSettings memory _strategy,
        MethodologySettings memory _methodology,
        ExecutionSettings memory _execution,
        IncentiveSettings memory _incentive,
        string[] memory _exchangeNames,
        ExchangeSettings[] memory _exchangeSettings
    )
        public
        AaveLeverageStrategyExtension(
            _manager,
            _strategy,
            _methodology,
            _execution,
            _incentive,
            _exchangeNames,
            _exchangeSettings
        )
    {}

    /**
     * OPERATOR ONLY: Set eMode categoryId to new value
     *
     * @param _categoryId    eMode categoryId as defined on aaveV3
     */
    function setEModeCategory(uint8 _categoryId) external onlyOperator {
        _setEModeCategory(_categoryId);
    }

    function _setEModeCategory(uint8 _categoryId) internal {
        bytes memory setEmodeCallData =
            abi.encodeWithSignature("setEModeCategory(address,uint8)", address(strategy.setToken), _categoryId);
        invokeManager(address(strategy.leverageModule), setEmodeCallData);
    }
}

File 2 of 17 : 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 3 of 17 : 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 4 of 17 : 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 5 of 17 : 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 6 of 17 : 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 7 of 17 : SafeCast.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.6.0 <0.8.0;


/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such 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.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128) {
        require(value >= -2**127 && value < 2**127, "SafeCast: value doesn\'t fit in 128 bits");
        return int128(value);
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64) {
        require(value >= -2**63 && value < 2**63, "SafeCast: value doesn\'t fit in 64 bits");
        return int64(value);
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32) {
        require(value >= -2**31 && value < 2**31, "SafeCast: value doesn\'t fit in 32 bits");
        return int32(value);
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16) {
        require(value >= -2**15 && value < 2**15, "SafeCast: value doesn\'t fit in 16 bits");
        return int16(value);
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits.
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8) {
        require(value >= -2**7 && value < 2**7, "SafeCast: value doesn\'t fit in 8 bits");
        return int8(value);
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        require(value < 2**255, "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

File 8 of 17 : AaveLeverageStrategyExtension.sol
/*
    Copyright 2021 Set Labs Inc.

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

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

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

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

pragma solidity 0.6.10;
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 { SafeCast } from "@openzeppelin/contracts/utils/SafeCast.sol";
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";

import { BaseExtension } from "../lib/BaseExtension.sol";
import { IBaseManager } from "../interfaces/IBaseManager.sol";
import { IChainlinkAggregatorV3 } from "../interfaces/IChainlinkAggregatorV3.sol";
import { ILeverageModule } from "../interfaces/ILeverageModule.sol";
import { IProtocolDataProvider } from "../interfaces/IProtocolDataProvider.sol";
import { ISetToken } from "../interfaces/ISetToken.sol";
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";
import { StringArrayUtils } from "../lib/StringArrayUtils.sol";


/**
 * @title AaveLeverageStrategyExtension
 * @author Set Protocol
 *
 * Smart contract that enables trustless leverage tokens. This extension is paired with the AaveLeverageModule from Set protocol where module 
 * interactions are invoked via the IBaseManager contract. Any leveraged token can be constructed as long as the collateral and borrow asset 
 * is available on Aave. This extension contract also allows the operator to set an ETH reward to incentivize keepers calling the rebalance
 * function at different leverage thresholds.
 *
 */
contract AaveLeverageStrategyExtension is BaseExtension {
    using Address for address;
    using PreciseUnitMath for uint256;
    using SafeMath for uint256;
    using SafeCast for int256;
    using StringArrayUtils for string[];

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

    enum ShouldRebalance {
        NONE,                   // Indicates no rebalance action can be taken
        REBALANCE,              // Indicates rebalance() function can be successfully called
        ITERATE_REBALANCE,      // Indicates iterateRebalance() function can be successfully called
        RIPCORD                 // Indicates ripcord() function can be successfully called
    }

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

    struct ActionInfo {
        uint256 collateralBalance;                      // Balance of underlying held in Aave in base units (e.g. USDC 10e6)
        uint256 borrowBalance;                          // Balance of underlying borrowed from Aave in base units
        uint256 collateralValue;                        // Valuation in USD adjusted for decimals in precise units (10e18)
        uint256 borrowValue;                            // Valuation in USD adjusted for decimals in precise units (10e18)
        uint256 collateralPrice;                        // Price of collateral in precise units (10e18) from Chainlink
        uint256 borrowPrice;                            // Price of borrow asset in precise units (10e18) from Chainlink
        uint256 setTotalSupply;                         // Total supply of SetToken
    }

     struct LeverageInfo {
        ActionInfo action;
        uint256 currentLeverageRatio;                   // Current leverage ratio of Set
        uint256 slippageTolerance;                      // Allowable percent trade slippage in preciseUnits (1% = 10^16)
        uint256 twapMaxTradeSize;                       // Max trade size in collateral units allowed for rebalance action
        string exchangeName;                            // Exchange to use for trade
    }

    struct ContractSettings {
        ISetToken setToken;                             // Instance of leverage token
        ILeverageModule leverageModule;                 // Instance of Aave leverage module
        IProtocolDataProvider aaveProtocolDataProvider; // Instance of Aave protocol data provider
        IChainlinkAggregatorV3 collateralPriceOracle;   // Chainlink oracle feed that returns prices in 8 decimals for collateral asset
        IChainlinkAggregatorV3 borrowPriceOracle;       // Chainlink oracle feed that returns prices in 8 decimals for borrow asset
        IERC20 targetCollateralAToken;                  // Instance of target collateral aToken asset
        IERC20 targetBorrowDebtToken;                   // Instance of target borrow variable debt token asset
        address collateralAsset;                        // Address of underlying collateral
        address borrowAsset;                            // Address of underlying borrow asset
        uint256 collateralDecimalAdjustment;            // Decimal adjustment for chainlink oracle of the collateral asset. Equal to 28-collateralDecimals (10^18 * 10^18 / 10^decimals / 10^8)
        uint256 borrowDecimalAdjustment;                // Decimal adjustment for chainlink oracle of the borrowing asset. Equal to 28-borrowDecimals (10^18 * 10^18 / 10^decimals / 10^8)
    }

    struct MethodologySettings {
        uint256 targetLeverageRatio;                     // Long term target ratio in precise units (10e18)
        uint256 minLeverageRatio;                        // In precise units (10e18). If current leverage is below, rebalance target is this ratio
        uint256 maxLeverageRatio;                        // In precise units (10e18). If current leverage is above, rebalance target is this ratio
        uint256 recenteringSpeed;                        // % at which to rebalance back to target leverage in precise units (10e18)
        uint256 rebalanceInterval;                       // Period of time required since last rebalance timestamp in seconds
    }

    struct ExecutionSettings {
        uint256 unutilizedLeveragePercentage;            // Percent of max borrow left unutilized in precise units (1% = 10e16)
        uint256 slippageTolerance;                       // % in precise units to price min token receive amount from trade quantities
        uint256 twapCooldownPeriod;                      // Cooldown period required since last trade timestamp in seconds
    }

    struct ExchangeSettings {
        uint256 twapMaxTradeSize;                        // Max trade size in collateral base units
        uint256 exchangeLastTradeTimestamp;              // Timestamp of last trade made with this exchange
        uint256 incentivizedTwapMaxTradeSize;            // Max trade size for incentivized rebalances in collateral base units
        bytes leverExchangeData;                         // Arbitrary exchange data passed into rebalance function for levering up
        bytes deleverExchangeData;                       // Arbitrary exchange data passed into rebalance function for delevering
    }

    struct IncentiveSettings {
        uint256 etherReward;                             // ETH reward for incentivized rebalances
        uint256 incentivizedLeverageRatio;               // Leverage ratio for incentivized rebalances
        uint256 incentivizedSlippageTolerance;           // Slippage tolerance percentage for incentivized rebalances
        uint256 incentivizedTwapCooldownPeriod;          // TWAP cooldown in seconds for incentivized rebalances
    }

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

    event Engaged(uint256 _currentLeverageRatio, uint256 _newLeverageRatio, uint256 _chunkRebalanceNotional, uint256 _totalRebalanceNotional);
    event Rebalanced(
        uint256 _currentLeverageRatio,
        uint256 _newLeverageRatio,
        uint256 _chunkRebalanceNotional,
        uint256 _totalRebalanceNotional
    );
    event RebalanceIterated(
        uint256 _currentLeverageRatio,
        uint256 _newLeverageRatio,
        uint256 _chunkRebalanceNotional,
        uint256 _totalRebalanceNotional
    );
    event RipcordCalled(
        uint256 _currentLeverageRatio,
        uint256 _newLeverageRatio,
        uint256 _rebalanceNotional,
        uint256 _etherIncentive
    );
    event Disengaged(uint256 _currentLeverageRatio, uint256 _newLeverageRatio, uint256 _chunkRebalanceNotional, uint256 _totalRebalanceNotional);
    event MethodologySettingsUpdated(
        uint256 _targetLeverageRatio,
        uint256 _minLeverageRatio,
        uint256 _maxLeverageRatio,
        uint256 _recenteringSpeed,
        uint256 _rebalanceInterval
    );
    event ExecutionSettingsUpdated(
        uint256 _unutilizedLeveragePercentage,
        uint256 _twapCooldownPeriod,
        uint256 _slippageTolerance
    );
    event IncentiveSettingsUpdated(
        uint256 _etherReward,
        uint256 _incentivizedLeverageRatio,
        uint256 _incentivizedSlippageTolerance,
        uint256 _incentivizedTwapCooldownPeriod
    );
    event ExchangeUpdated(
        string _exchangeName,
        uint256 twapMaxTradeSize,
        uint256 exchangeLastTradeTimestamp,
        uint256 incentivizedTwapMaxTradeSize,
        bytes leverExchangeData,
        bytes deleverExchangeData
    );
    event ExchangeAdded(
        string _exchangeName,
        uint256 twapMaxTradeSize,
        uint256 exchangeLastTradeTimestamp,
        uint256 incentivizedTwapMaxTradeSize,
        bytes leverExchangeData,
        bytes deleverExchangeData
    );
    event ExchangeRemoved(
        string _exchangeName
    );

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

    /**
     * Throws if rebalance is currently in TWAP`
     */
    modifier noRebalanceInProgress() {
        require(twapLeverageRatio == 0, "Rebalance is currently in progress");
        _;
    }

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

    ContractSettings internal strategy;                             // Struct of contracts used in the strategy (SetToken, price oracles, leverage module etc)
    MethodologySettings internal methodology;                       // Struct containing methodology parameters
    ExecutionSettings internal execution;                           // Struct containing execution parameters
    mapping(string => ExchangeSettings) internal exchangeSettings;  // Mapping from exchange name to exchange settings
    IncentiveSettings internal incentive;                           // Struct containing incentive parameters for ripcord
    string[] public enabledExchanges;                               // Array containing enabled exchanges
    uint256 public twapLeverageRatio;                               // Stored leverage ratio to keep track of target between TWAP rebalances
    uint256 public globalLastTradeTimestamp;                        // Last rebalance timestamp. Current timestamp must be greater than this variable + rebalance interval to rebalance

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

    /**
     * Instantiate addresses, methodology parameters, execution parameters, and incentive parameters.
     *
     * @param _manager                  Address of IBaseManager contract
     * @param _strategy                 Struct of contract addresses
     * @param _methodology              Struct containing methodology parameters
     * @param _execution                Struct containing execution parameters
     * @param _incentive                Struct containing incentive parameters for ripcord
     * @param _exchangeNames            List of initial exchange names
     * @param _exchangeSettings         List of structs containing exchange parameters for the initial exchanges
     */
    constructor(
        IBaseManager _manager,
        ContractSettings memory _strategy,
        MethodologySettings memory _methodology,
        ExecutionSettings memory _execution,
        IncentiveSettings memory _incentive,
        string[] memory _exchangeNames,
        ExchangeSettings[] memory _exchangeSettings
    )
        public
        BaseExtension(_manager)
    {
        strategy = _strategy;
        methodology = _methodology;
        execution = _execution;
        incentive = _incentive;

        for (uint256 i = 0; i < _exchangeNames.length; i++) {
            _validateExchangeSettings(_exchangeSettings[i]);
            exchangeSettings[_exchangeNames[i]] = _exchangeSettings[i];
            enabledExchanges.push(_exchangeNames[i]);
        }

        _validateNonExchangeSettings(methodology, execution, incentive);
    }

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

    /**
     * OPERATOR ONLY: Engage to target leverage ratio for the first time. SetToken will borrow debt position from Aave and trade for collateral asset. If target
     * leverage ratio is above max borrow or max trade size, then TWAP is kicked off. To complete engage if TWAP, any valid caller must call iterateRebalance until target
     * is met.
     *
     * @param _exchangeName     the exchange used for trading
     */
    function engage(string memory _exchangeName) external onlyOperator {
        ActionInfo memory engageInfo = _createActionInfo();

        require(engageInfo.setTotalSupply > 0, "SetToken must have > 0 supply");
        require(engageInfo.collateralBalance > 0, "Collateral balance must be > 0");
        require(engageInfo.borrowBalance == 0, "Debt must be 0");

        LeverageInfo memory leverageInfo = LeverageInfo({
            action: engageInfo,
            currentLeverageRatio: PreciseUnitMath.preciseUnit(), // 1x leverage in precise units
            slippageTolerance: execution.slippageTolerance,
            twapMaxTradeSize: exchangeSettings[_exchangeName].twapMaxTradeSize,
            exchangeName: _exchangeName
        });

        // Calculate total rebalance units and kick off TWAP if above max borrow or max trade size
        (
            uint256 chunkRebalanceNotional,
            uint256 totalRebalanceNotional
        ) = _calculateChunkRebalanceNotional(leverageInfo, methodology.targetLeverageRatio, true);

        _lever(leverageInfo, chunkRebalanceNotional);

        _updateRebalanceState(
            chunkRebalanceNotional,
            totalRebalanceNotional,
            methodology.targetLeverageRatio,
            _exchangeName
        );

        emit Engaged(
            leverageInfo.currentLeverageRatio,
            methodology.targetLeverageRatio,
            chunkRebalanceNotional,
            totalRebalanceNotional
        );
    }

    /**
     * ONLY EOA AND ALLOWED CALLER: Rebalance product. If current leverage ratio is between the max and min bounds, then rebalance 
     * can only be called once the rebalance interval has elapsed since last timestamp. If outside the max and min, rebalance can be called anytime to bring leverage
     * ratio back to the max or min bounds. The methodology will determine whether to delever or lever.
     *
     * Note: If the calculated current leverage ratio is above the incentivized leverage ratio or in TWAP then rebalance cannot be called. Instead, you must call
     * ripcord() which is incentivized with a reward in Ether or iterateRebalance().
     *
     * @param _exchangeName     the exchange used for trading
     */
     function rebalance(string memory _exchangeName) external onlyEOA onlyAllowedCaller(msg.sender) {
        LeverageInfo memory leverageInfo = _getAndValidateLeveragedInfo(
            execution.slippageTolerance,
            exchangeSettings[_exchangeName].twapMaxTradeSize,
            _exchangeName
        );

        // use globalLastTradeTimestamps to prevent multiple rebalances being called with different exchanges during the epoch rebalance
        _validateNormalRebalance(leverageInfo, methodology.rebalanceInterval, globalLastTradeTimestamp);
        _validateNonTWAP();

        uint256 newLeverageRatio = _calculateNewLeverageRatio(leverageInfo.currentLeverageRatio);

        (
            uint256 chunkRebalanceNotional,
            uint256 totalRebalanceNotional
        ) = _handleRebalance(leverageInfo, newLeverageRatio);

        _updateRebalanceState(chunkRebalanceNotional, totalRebalanceNotional, newLeverageRatio, _exchangeName);

        emit Rebalanced(
            leverageInfo.currentLeverageRatio,
            newLeverageRatio,
            chunkRebalanceNotional,
            totalRebalanceNotional
        );
    }

    /**
     * ONLY EOA AND ALLOWED CALLER: Iterate a rebalance when in TWAP. TWAP cooldown period must have elapsed. If price moves advantageously, then exit without rebalancing
     * and clear TWAP state. This function can only be called when below incentivized leverage ratio and in TWAP state.
     *
     * @param _exchangeName     the exchange used for trading
     */
    function iterateRebalance(string memory _exchangeName) external onlyEOA onlyAllowedCaller(msg.sender) {
        LeverageInfo memory leverageInfo = _getAndValidateLeveragedInfo(
            execution.slippageTolerance,
            exchangeSettings[_exchangeName].twapMaxTradeSize,
            _exchangeName
        );

        // Use the exchangeLastTradeTimestamp since cooldown periods are measured on a per-exchange basis, allowing it to rebalance multiple time in quick
        // succession with different exchanges
        _validateNormalRebalance(leverageInfo, execution.twapCooldownPeriod, exchangeSettings[_exchangeName].exchangeLastTradeTimestamp);
        _validateTWAP();

        uint256 chunkRebalanceNotional;
        uint256 totalRebalanceNotional;
        if (!_isAdvantageousTWAP(leverageInfo.currentLeverageRatio)) {
            (chunkRebalanceNotional, totalRebalanceNotional) = _handleRebalance(leverageInfo, twapLeverageRatio);
        }

        // If not advantageous, then rebalance is skipped and chunk and total rebalance notional are both 0, which means TWAP state is
        // cleared
        _updateIterateState(chunkRebalanceNotional, totalRebalanceNotional, _exchangeName);

        emit RebalanceIterated(
            leverageInfo.currentLeverageRatio,
            twapLeverageRatio,
            chunkRebalanceNotional,
            totalRebalanceNotional
        );
    }

    /**
     * ONLY EOA: In case the current leverage ratio exceeds the incentivized leverage threshold, the ripcord function can be called by anyone to return leverage ratio
     * back to the max leverage ratio. This function typically would only be called during times of high downside volatility and / or normal keeper malfunctions. The caller
     * of ripcord() will receive a reward in Ether. The ripcord function uses it's own TWAP cooldown period, slippage tolerance and TWAP max trade size which are typically
     * looser than in regular rebalances.
     *
     * @param _exchangeName     the exchange used for trading
     */
    function ripcord(string memory _exchangeName) external onlyEOA {
        LeverageInfo memory leverageInfo = _getAndValidateLeveragedInfo(
            incentive.incentivizedSlippageTolerance,
            exchangeSettings[_exchangeName].incentivizedTwapMaxTradeSize,
            _exchangeName
        );

        // Use the exchangeLastTradeTimestamp so it can ripcord quickly with multiple exchanges
        _validateRipcord(leverageInfo, exchangeSettings[_exchangeName].exchangeLastTradeTimestamp);

        ( uint256 chunkRebalanceNotional, ) = _calculateChunkRebalanceNotional(leverageInfo, methodology.maxLeverageRatio, false);

        _delever(leverageInfo, chunkRebalanceNotional);

        _updateRipcordState(_exchangeName);

        uint256 etherTransferred = _transferEtherRewardToCaller(incentive.etherReward);

        emit RipcordCalled(
            leverageInfo.currentLeverageRatio,
            methodology.maxLeverageRatio,
            chunkRebalanceNotional,
            etherTransferred
        );
    }

    /**
     * OPERATOR ONLY: Return leverage ratio to 1x and delever to repay loan. This can be used for upgrading or shutting down the strategy. SetToken will redeem
     * collateral position and trade for debt position to repay Aave. If the chunk rebalance size is less than the total notional size, then this function will
     * delever and repay entire borrow balance on Aave. If chunk rebalance size is above max borrow or max trade size, then operator must
     * continue to call this function to complete repayment of loan. The function iterateRebalance will not work.
     *
     * Note: Delever to 0 will likely result in additional units of the borrow asset added as equity on the SetToken due to oracle price / market price mismatch
     *
     * @param _exchangeName     the exchange used for trading
     */
    function disengage(string memory _exchangeName) external onlyOperator {
        LeverageInfo memory leverageInfo = _getAndValidateLeveragedInfo(
            execution.slippageTolerance,
            exchangeSettings[_exchangeName].twapMaxTradeSize,
            _exchangeName
        );

        uint256 newLeverageRatio = PreciseUnitMath.preciseUnit();

        (
            uint256 chunkRebalanceNotional,
            uint256 totalRebalanceNotional
        ) = _calculateChunkRebalanceNotional(leverageInfo, newLeverageRatio, false);

        if (totalRebalanceNotional > chunkRebalanceNotional) {
            _delever(leverageInfo, chunkRebalanceNotional);
        } else {
            _deleverToZeroBorrowBalance(leverageInfo, totalRebalanceNotional);
        }

        emit Disengaged(
            leverageInfo.currentLeverageRatio,
            newLeverageRatio,
            chunkRebalanceNotional,
            totalRebalanceNotional
        );
    }

    /**
     * OPERATOR ONLY: Set methodology settings and check new settings are valid. Note: Need to pass in existing parameters if only changing a few settings. Must not be
     * in a rebalance.
     *
     * @param _newMethodologySettings          Struct containing methodology parameters
     */
    function setMethodologySettings(MethodologySettings memory _newMethodologySettings) external onlyOperator noRebalanceInProgress {
        methodology = _newMethodologySettings;

        _validateNonExchangeSettings(methodology, execution, incentive);

        emit MethodologySettingsUpdated(
            methodology.targetLeverageRatio,
            methodology.minLeverageRatio,
            methodology.maxLeverageRatio,
            methodology.recenteringSpeed,
            methodology.rebalanceInterval
        );
    }

    /**
     * OPERATOR ONLY: Set execution settings and check new settings are valid. Note: Need to pass in existing parameters if only changing a few settings. Must not be
     * in a rebalance.
     *
     * @param _newExecutionSettings          Struct containing execution parameters
     */
    function setExecutionSettings(ExecutionSettings memory _newExecutionSettings) external onlyOperator noRebalanceInProgress {
        execution = _newExecutionSettings;

        _validateNonExchangeSettings(methodology, execution, incentive);

        emit ExecutionSettingsUpdated(
            execution.unutilizedLeveragePercentage,
            execution.twapCooldownPeriod,
            execution.slippageTolerance
        );
    }

    /**
     * OPERATOR ONLY: Set incentive settings and check new settings are valid. Note: Need to pass in existing parameters if only changing a few settings. Must not be
     * in a rebalance.
     *
     * @param _newIncentiveSettings          Struct containing incentive parameters
     */
    function setIncentiveSettings(IncentiveSettings memory _newIncentiveSettings) external onlyOperator noRebalanceInProgress {
        incentive = _newIncentiveSettings;

        _validateNonExchangeSettings(methodology, execution, incentive);

        emit IncentiveSettingsUpdated(
            incentive.etherReward,
            incentive.incentivizedLeverageRatio,
            incentive.incentivizedSlippageTolerance,
            incentive.incentivizedTwapCooldownPeriod
        );
    }

    /**
     * OPERATOR ONLY: Add a new enabled exchange for trading during rebalances. New exchanges will have their exchangeLastTradeTimestamp set to 0. Adding
     * exchanges during rebalances is allowed, as it is not possible to enter an unexpected state while doing so.
     *
     * @param _exchangeName         Name of the exchange
     * @param _exchangeSettings     Struct containing exchange parameters
     */
    function addEnabledExchange(
        string memory _exchangeName,
        ExchangeSettings memory _exchangeSettings
    )
        external
        onlyOperator
    {
        require(exchangeSettings[_exchangeName].twapMaxTradeSize == 0, "Exchange already enabled");
        _validateExchangeSettings(_exchangeSettings);

        exchangeSettings[_exchangeName].twapMaxTradeSize = _exchangeSettings.twapMaxTradeSize;
        exchangeSettings[_exchangeName].incentivizedTwapMaxTradeSize = _exchangeSettings.incentivizedTwapMaxTradeSize;
        exchangeSettings[_exchangeName].leverExchangeData = _exchangeSettings.leverExchangeData;
        exchangeSettings[_exchangeName].deleverExchangeData = _exchangeSettings.deleverExchangeData;
        exchangeSettings[_exchangeName].exchangeLastTradeTimestamp = 0;

        enabledExchanges.push(_exchangeName);

        emit ExchangeAdded(
            _exchangeName,
            _exchangeSettings.twapMaxTradeSize,
            _exchangeSettings.exchangeLastTradeTimestamp,
            _exchangeSettings.incentivizedTwapMaxTradeSize,
            _exchangeSettings.leverExchangeData,
            _exchangeSettings.deleverExchangeData
        );
    }

    /**
     * OPERATOR ONLY: Removes an exchange. Reverts if the exchange is not already enabled. Removing exchanges during rebalances is allowed,
     * as it is not possible to enter an unexpected state while doing so.
     *
     * @param _exchangeName     Name of exchange to remove
     */
    function removeEnabledExchange(string memory _exchangeName) external onlyOperator {
        require(exchangeSettings[_exchangeName].twapMaxTradeSize != 0, "Exchange not enabled");

        delete exchangeSettings[_exchangeName];
        enabledExchanges.removeStorage(_exchangeName);

        emit ExchangeRemoved(_exchangeName);
    }

    /**
     * OPERATOR ONLY: Updates the settings of an exchange. Reverts if exchange is not already added. When updating an exchange, exchangeLastTradeTimestamp
     * is preserved. Updating exchanges during rebalances is allowed, as it is not possible to enter an unexpected state while doing so. Note: Need to
     * pass in all existing parameters even if only changing a few settings.
     *
     * @param _exchangeName         Name of the exchange
     * @param _exchangeSettings     Struct containing exchange parameters
     */
    function updateEnabledExchange(
        string memory _exchangeName,
        ExchangeSettings memory _exchangeSettings
    )
        external
        onlyOperator
    {
        require(exchangeSettings[_exchangeName].twapMaxTradeSize != 0, "Exchange not enabled");
        _validateExchangeSettings(_exchangeSettings);

        exchangeSettings[_exchangeName].twapMaxTradeSize = _exchangeSettings.twapMaxTradeSize;
        exchangeSettings[_exchangeName].incentivizedTwapMaxTradeSize = _exchangeSettings.incentivizedTwapMaxTradeSize;
        exchangeSettings[_exchangeName].leverExchangeData = _exchangeSettings.leverExchangeData;
        exchangeSettings[_exchangeName].deleverExchangeData = _exchangeSettings.deleverExchangeData;

        emit ExchangeUpdated(
            _exchangeName,
            _exchangeSettings.twapMaxTradeSize,
            _exchangeSettings.exchangeLastTradeTimestamp,
            _exchangeSettings.incentivizedTwapMaxTradeSize,
            _exchangeSettings.leverExchangeData,
            _exchangeSettings.deleverExchangeData
        );
    }

    /**
     * OPERATOR ONLY: Withdraw entire balance of ETH in this contract to operator. Rebalance must not be in progress
     */
    function withdrawEtherBalance() external onlyOperator noRebalanceInProgress {
        msg.sender.transfer(address(this).balance);
    }

    receive() external payable {}

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

    /**
     * Get current leverage ratio. Current leverage ratio is defined as the USD value of the collateral divided by the USD value of the SetToken. Prices for collateral
     * and borrow asset are retrieved from the Chainlink Price Oracle.
     *
     * return currentLeverageRatio         Current leverage ratio in precise units (10e18)
     */
    function getCurrentLeverageRatio() public view returns(uint256) {
        ActionInfo memory currentLeverageInfo = _createActionInfo();

        return _calculateCurrentLeverageRatio(currentLeverageInfo.collateralValue, currentLeverageInfo.borrowValue);
    }

    /**
     * Calculates the chunk rebalance size. This can be used by external contracts and keeper bots to calculate the optimal exchange to rebalance with.
     * Note: this function does not take into account timestamps, so it may return a nonzero value even when shouldRebalance would return ShouldRebalance.NONE for
     * all exchanges (since minimum delays have not elapsed)
     *
     * @param _exchangeNames    Array of exchange names to get rebalance sizes for
     *
     * @return sizes            Array of total notional chunk size. Measured in the asset that would be sold
     * @return sellAsset        Asset that would be sold during a rebalance
     * @return buyAsset         Asset that would be purchased during a rebalance
     */
    function getChunkRebalanceNotional(
        string[] calldata _exchangeNames
    )
        external
        view
        returns(uint256[] memory sizes, address sellAsset, address buyAsset)
    {

        uint256 newLeverageRatio;
        uint256 currentLeverageRatio = getCurrentLeverageRatio();
        bool isRipcord = false;

        // if over incentivized leverage ratio, always ripcord
        if (currentLeverageRatio > incentive.incentivizedLeverageRatio) {
            newLeverageRatio = methodology.maxLeverageRatio;
            isRipcord = true;
        // if we are in an ongoing twap, use the cached twapLeverageRatio as our target leverage
        } else if (twapLeverageRatio > 0) {
            newLeverageRatio = twapLeverageRatio;
        // if all else is false, then we would just use the normal rebalance new leverage ratio calculation
        } else {
            newLeverageRatio = _calculateNewLeverageRatio(currentLeverageRatio);
        }

        ActionInfo memory actionInfo = _createActionInfo();
        bool isLever = newLeverageRatio > currentLeverageRatio;

        sizes = new uint256[](_exchangeNames.length);

        for (uint256 i = 0; i < _exchangeNames.length; i++) {
    
            LeverageInfo memory leverageInfo = LeverageInfo({
                action: actionInfo,
                currentLeverageRatio: currentLeverageRatio,
                slippageTolerance: isRipcord ? incentive.incentivizedSlippageTolerance : execution.slippageTolerance,
                twapMaxTradeSize: isRipcord ?
                    exchangeSettings[_exchangeNames[i]].incentivizedTwapMaxTradeSize :
                    exchangeSettings[_exchangeNames[i]].twapMaxTradeSize,
                exchangeName: _exchangeNames[i]
            });

            (uint256 collateralNotional, ) = _calculateChunkRebalanceNotional(leverageInfo, newLeverageRatio, isLever);

            // _calculateBorrowUnits can convert both unit and notional values
            sizes[i] = isLever ? _calculateBorrowUnits(collateralNotional, leverageInfo.action) : collateralNotional;
        }

        sellAsset = isLever ? strategy.borrowAsset : strategy.collateralAsset;
        buyAsset = isLever ? strategy.collateralAsset : strategy.borrowAsset;
    }

    /**
     * Get current Ether incentive for when current leverage ratio exceeds incentivized leverage ratio and ripcord can be called. If ETH balance on the contract is
     * below the etherReward, then return the balance of ETH instead.
     *
     * return etherReward               Quantity of ETH reward in base units (10e18)
     */
    function getCurrentEtherIncentive() external view returns(uint256) {
        uint256 currentLeverageRatio = getCurrentLeverageRatio();

        if (currentLeverageRatio >= incentive.incentivizedLeverageRatio) {
            // If ETH reward is below the balance on this contract, then return ETH balance on contract instead
            return incentive.etherReward < address(this).balance ? incentive.etherReward : address(this).balance;
        } else {
            return 0;
        }
    }

    /**
     * Helper that checks if conditions are met for rebalance or ripcord. Returns an enum with 0 = no rebalance, 1 = call rebalance(), 2 = call iterateRebalance()
     * 3 = call ripcord()
     *
     * @return (string[] memory, ShouldRebalance[] memory)      List of exchange names and a list of enums representing whether that exchange should rebalance
     */
    function shouldRebalance() external view returns(string[] memory, ShouldRebalance[] memory) {
        uint256 currentLeverageRatio = getCurrentLeverageRatio();

        return _shouldRebalance(currentLeverageRatio, methodology.minLeverageRatio, methodology.maxLeverageRatio);
    }

    /**
     * Helper that checks if conditions are met for rebalance or ripcord with custom max and min bounds specified by caller. This function simplifies the
     * logic for off-chain keeper bots to determine what threshold to call rebalance when leverage exceeds max or drops below min. Returns an enum with
     * 0 = no rebalance, 1 = call rebalance(), 2 = call iterateRebalance(), 3 = call ripcord()
     *
     * @param _customMinLeverageRatio          Min leverage ratio passed in by caller
     * @param _customMaxLeverageRatio          Max leverage ratio passed in by caller
     *
     * @return (string[] memory, ShouldRebalance[] memory)      List of exchange names and a list of enums representing whether that exchange should rebalance
     */
    function shouldRebalanceWithBounds(
        uint256 _customMinLeverageRatio,
        uint256 _customMaxLeverageRatio
    )
        external
        view
        returns(string[] memory, ShouldRebalance[] memory)
    {
        require (
            _customMinLeverageRatio <= methodology.minLeverageRatio && _customMaxLeverageRatio >= methodology.maxLeverageRatio,
            "Custom bounds must be valid"
        );

        uint256 currentLeverageRatio = getCurrentLeverageRatio();

        return _shouldRebalance(currentLeverageRatio, _customMinLeverageRatio, _customMaxLeverageRatio);
    }

    /**
     * Gets the list of enabled exchanges
     */
    function getEnabledExchanges() external view returns (string[] memory) {
        return enabledExchanges;
    }

    /**
     * Explicit getter functions for parameter structs are defined as workaround to issues fetching structs that have dynamic types.
     */
    function getStrategy() external view returns (ContractSettings memory) { return strategy; }
    function getMethodology() external view returns (MethodologySettings memory) { return methodology; }
    function getExecution() external view returns (ExecutionSettings memory) { return execution; }
    function getIncentive() external view returns (IncentiveSettings memory) { return incentive; }
    function getExchangeSettings(string memory _exchangeName) external view returns (ExchangeSettings memory) {
        return exchangeSettings[_exchangeName];
    }

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

    /**
     * Calculate notional rebalance quantity, whether to chunk rebalance based on max trade size and max borrow and invoke lever on AaveLeverageModule
     *
     */
     function _lever(
        LeverageInfo memory _leverageInfo,
        uint256 _chunkRebalanceNotional
    )
        internal
    {
        uint256 collateralRebalanceUnits = _chunkRebalanceNotional.preciseDiv(_leverageInfo.action.setTotalSupply);

        uint256 borrowUnits = _calculateBorrowUnits(collateralRebalanceUnits, _leverageInfo.action);

        uint256 minReceiveCollateralUnits = _calculateMinCollateralReceiveUnits(collateralRebalanceUnits, _leverageInfo.slippageTolerance);

        bytes memory leverCallData = abi.encodeWithSignature(
            "lever(address,address,address,uint256,uint256,string,bytes)",
            address(strategy.setToken),
            strategy.borrowAsset,
            strategy.collateralAsset,
            borrowUnits,
            minReceiveCollateralUnits,
            _leverageInfo.exchangeName,
            exchangeSettings[_leverageInfo.exchangeName].leverExchangeData
        );

        invokeManager(address(strategy.leverageModule), leverCallData);
    }

    /**
     * Calculate delever units Invoke delever on AaveLeverageModule.
     */
    function _delever(
        LeverageInfo memory _leverageInfo,
        uint256 _chunkRebalanceNotional
    )
        internal
    {
        uint256 collateralRebalanceUnits = _chunkRebalanceNotional.preciseDiv(_leverageInfo.action.setTotalSupply);

        uint256 minRepayUnits = _calculateMinRepayUnits(collateralRebalanceUnits, _leverageInfo.slippageTolerance, _leverageInfo.action);

        bytes memory deleverCallData = abi.encodeWithSignature(
            "delever(address,address,address,uint256,uint256,string,bytes)",
            address(strategy.setToken),
            strategy.collateralAsset,
            strategy.borrowAsset,
            collateralRebalanceUnits,
            minRepayUnits,
            _leverageInfo.exchangeName,
            exchangeSettings[_leverageInfo.exchangeName].deleverExchangeData
        );

        invokeManager(address(strategy.leverageModule), deleverCallData);
    }

    /**
     * Invoke deleverToZeroBorrowBalance on AaveLeverageModule.
     */
    function _deleverToZeroBorrowBalance(
        LeverageInfo memory _leverageInfo,
        uint256 _chunkRebalanceNotional
    )
        internal
    {
        // Account for slippage tolerance in redeem quantity for the deleverToZeroBorrowBalance function
        uint256 maxCollateralRebalanceUnits = _chunkRebalanceNotional
            .preciseMul(PreciseUnitMath.preciseUnit().add(execution.slippageTolerance))
            .preciseDiv(_leverageInfo.action.setTotalSupply);

        bytes memory deleverToZeroBorrowBalanceCallData = abi.encodeWithSignature(
            "deleverToZeroBorrowBalance(address,address,address,uint256,string,bytes)",
            address(strategy.setToken),
            strategy.collateralAsset,
            strategy.borrowAsset,
            maxCollateralRebalanceUnits,
            _leverageInfo.exchangeName,
            exchangeSettings[_leverageInfo.exchangeName].deleverExchangeData
        );

        invokeManager(address(strategy.leverageModule), deleverToZeroBorrowBalanceCallData);
    }

    /**
     * Check whether to delever or lever based on the current vs new leverage ratios. Used in the rebalance() and iterateRebalance() functions
     *
     * return uint256           Calculated notional to trade
     * return uint256           Total notional to rebalance over TWAP
     */
    function _handleRebalance(LeverageInfo memory _leverageInfo, uint256 _newLeverageRatio) internal returns(uint256, uint256) {
        uint256 chunkRebalanceNotional;
        uint256 totalRebalanceNotional;
        if (_newLeverageRatio < _leverageInfo.currentLeverageRatio) {
            (
                chunkRebalanceNotional,
                totalRebalanceNotional
            ) = _calculateChunkRebalanceNotional(_leverageInfo, _newLeverageRatio, false);

            _delever(_leverageInfo, chunkRebalanceNotional);
        } else {
            (
                chunkRebalanceNotional,
                totalRebalanceNotional
            ) = _calculateChunkRebalanceNotional(_leverageInfo, _newLeverageRatio, true);

            _lever(_leverageInfo, chunkRebalanceNotional);
        }

        return (chunkRebalanceNotional, totalRebalanceNotional);
    }

    /**
     * Create the leverage info struct to be used in internal functions
     *
     * return LeverageInfo                Struct containing ActionInfo and other data
     */
    function _getAndValidateLeveragedInfo(uint256 _slippageTolerance, uint256 _maxTradeSize, string memory _exchangeName) internal view returns(LeverageInfo memory) {
        // Assume if maxTradeSize is 0, then the exchange is not enabled. This is enforced by addEnabledExchange and updateEnabledExchange
        require(_maxTradeSize > 0, "Must be valid exchange");

        ActionInfo memory actionInfo = _createActionInfo();

        require(actionInfo.setTotalSupply > 0, "SetToken must have > 0 supply");
        require(actionInfo.collateralBalance > 0, "Collateral balance must be > 0");
        require(actionInfo.borrowBalance > 0, "Borrow balance must exist");

        // Get current leverage ratio
        uint256 currentLeverageRatio = _calculateCurrentLeverageRatio(
            actionInfo.collateralValue,
            actionInfo.borrowValue
        );

        return LeverageInfo({
            action: actionInfo,
            currentLeverageRatio: currentLeverageRatio,
            slippageTolerance: _slippageTolerance,
            twapMaxTradeSize: _maxTradeSize,
            exchangeName: _exchangeName
        });
    }

    /**
     * Create the action info struct to be used in internal functions
     *
     * return ActionInfo                Struct containing data used by internal lever and delever functions
     */
    function _createActionInfo() internal view returns(ActionInfo memory) {
        ActionInfo memory rebalanceInfo;

        // Calculate prices from chainlink. Chainlink returns prices with 8 decimal places, but we need 36 - underlyingDecimals decimal places.
        // This is so that when the underlying amount is multiplied by the received price, the collateral valuation is normalized to 36 decimals. 
        // To perform this adjustment, we multiply by 10^(36 - 8 - underlyingDecimals)
        int256 rawCollateralPrice = strategy.collateralPriceOracle.latestAnswer();
        rebalanceInfo.collateralPrice = rawCollateralPrice.toUint256().mul(10 ** strategy.collateralDecimalAdjustment);
        int256 rawBorrowPrice = strategy.borrowPriceOracle.latestAnswer();
        rebalanceInfo.borrowPrice = rawBorrowPrice.toUint256().mul(10 ** strategy.borrowDecimalAdjustment);

        rebalanceInfo.collateralBalance = strategy.targetCollateralAToken.balanceOf(address(strategy.setToken));
        rebalanceInfo.borrowBalance = strategy.targetBorrowDebtToken.balanceOf(address(strategy.setToken));
        rebalanceInfo.collateralValue = rebalanceInfo.collateralPrice.preciseMul(rebalanceInfo.collateralBalance);
        rebalanceInfo.borrowValue = rebalanceInfo.borrowPrice.preciseMul(rebalanceInfo.borrowBalance);
        rebalanceInfo.setTotalSupply = strategy.setToken.totalSupply();

        return rebalanceInfo;
    }

    /**
     * Validate non-exchange settings in constructor and setters when updating.
     */
    function _validateNonExchangeSettings(
        MethodologySettings memory _methodology,
        ExecutionSettings memory _execution,
        IncentiveSettings memory _incentive
    )
        internal
        pure
    {
        require (
            _methodology.minLeverageRatio <= _methodology.targetLeverageRatio && _methodology.minLeverageRatio > 0,
            "Must be valid min leverage"
        );
        require (
            _methodology.maxLeverageRatio >= _methodology.targetLeverageRatio,
            "Must be valid max leverage"
        );
        require (
            _methodology.recenteringSpeed <= PreciseUnitMath.preciseUnit() && _methodology.recenteringSpeed > 0,
            "Must be valid recentering speed"
        );
        require (
            _execution.unutilizedLeveragePercentage <= PreciseUnitMath.preciseUnit(),
            "Unutilized leverage must be <100%"
        );
        require (
            _execution.slippageTolerance <= PreciseUnitMath.preciseUnit(),
            "Slippage tolerance must be <100%"
        );
        require (
            _incentive.incentivizedSlippageTolerance <= PreciseUnitMath.preciseUnit(),
            "Incentivized slippage tolerance must be <100%"
        );
        require (
            _incentive.incentivizedLeverageRatio >= _methodology.maxLeverageRatio,
            "Incentivized leverage ratio must be > max leverage ratio"
        );
        require (
            _methodology.rebalanceInterval >= _execution.twapCooldownPeriod,
            "Rebalance interval must be greater than TWAP cooldown period"
        );
        require (
            _execution.twapCooldownPeriod >= _incentive.incentivizedTwapCooldownPeriod,
            "TWAP cooldown must be greater than incentivized TWAP cooldown"
        );
    }

    /**
     * Validate an ExchangeSettings struct when adding or updating an exchange. Does not validate that twapMaxTradeSize < incentivizedMaxTradeSize since
     * it may be useful to disable exchanges for ripcord by setting incentivizedMaxTradeSize to 0.
     */
     function _validateExchangeSettings(ExchangeSettings memory _settings) internal pure {
         require(_settings.twapMaxTradeSize != 0, "Max TWAP trade size must not be 0");
     }

    /**
     * Validate that current leverage is below incentivized leverage ratio and cooldown / rebalance period has elapsed or outsize max/min bounds. Used
     * in rebalance() and iterateRebalance() functions
     */
    function _validateNormalRebalance(LeverageInfo memory _leverageInfo, uint256 _coolDown, uint256 _lastTradeTimestamp) internal view {
        require(_leverageInfo.currentLeverageRatio < incentive.incentivizedLeverageRatio, "Must be below incentivized leverage ratio");
        require(
            block.timestamp.sub(_lastTradeTimestamp) > _coolDown
            || _leverageInfo.currentLeverageRatio > methodology.maxLeverageRatio
            || _leverageInfo.currentLeverageRatio < methodology.minLeverageRatio,
            "Cooldown not elapsed or not valid leverage ratio"
        );
    }

    /**
     * Validate that current leverage is above incentivized leverage ratio and incentivized cooldown period has elapsed in ripcord()
     */
    function _validateRipcord(LeverageInfo memory _leverageInfo, uint256 _lastTradeTimestamp) internal view {
        require(_leverageInfo.currentLeverageRatio >= incentive.incentivizedLeverageRatio, "Must be above incentivized leverage ratio");
        // If currently in the midst of a TWAP rebalance, ensure that the cooldown period has elapsed
        require(_lastTradeTimestamp.add(incentive.incentivizedTwapCooldownPeriod) < block.timestamp, "TWAP cooldown must have elapsed");
    }

    /**
     * Validate TWAP in the iterateRebalance() function
     */
    function _validateTWAP() internal view {
        require(twapLeverageRatio > 0, "Not in TWAP state");
    }

    /**
     * Validate not TWAP in the rebalance() function
     */
    function _validateNonTWAP() internal view {
        require(twapLeverageRatio == 0, "Must call iterate");
    }

    /**
     * Check if price has moved advantageously while in the midst of the TWAP rebalance. This means the current leverage ratio has moved over/under
     * the stored TWAP leverage ratio on lever/delever so there is no need to execute a rebalance. Used in iterateRebalance()
     */
    function _isAdvantageousTWAP(uint256 _currentLeverageRatio) internal view returns (bool) {
        return (
            (twapLeverageRatio < methodology.targetLeverageRatio && _currentLeverageRatio >= twapLeverageRatio)
            || (twapLeverageRatio > methodology.targetLeverageRatio && _currentLeverageRatio <= twapLeverageRatio)
        );
    }

    /**
     * Calculate the current leverage ratio given a valuation of the collateral and borrow asset, which is calculated as collateral USD valuation / SetToken USD valuation
     *
     * return uint256            Current leverage ratio
     */
    function _calculateCurrentLeverageRatio(
        uint256 _collateralValue,
        uint256 _borrowValue
    )
        internal
        pure
        returns(uint256)
    {
        return _collateralValue.preciseDiv(_collateralValue.sub(_borrowValue));
    }

    /**
     * Calculate the new leverage ratio. The methodology reduces the size of each rebalance by weighting
     * the current leverage ratio against the target leverage ratio by the recentering speed percentage. The lower the recentering speed, the slower
     * the leverage token will move towards the target leverage each rebalance.
     *
     * return uint256          New leverage ratio
     */
    function _calculateNewLeverageRatio(uint256 _currentLeverageRatio) internal view returns(uint256) {
        // CLRt+1 = max(MINLR, min(MAXLR, CLRt * (1 - RS) + TLR * RS))
        // a: TLR * RS
        // b: (1- RS) * CLRt
        // c: (1- RS) * CLRt + TLR * RS
        // d: min(MAXLR, CLRt * (1 - RS) + TLR * RS)
        uint256 a = methodology.targetLeverageRatio.preciseMul(methodology.recenteringSpeed);
        uint256 b = PreciseUnitMath.preciseUnit().sub(methodology.recenteringSpeed).preciseMul(_currentLeverageRatio);
        uint256 c = a.add(b);
        uint256 d = Math.min(c, methodology.maxLeverageRatio);
        return Math.max(methodology.minLeverageRatio, d);
    }

    /**
     * Calculate total notional rebalance quantity and chunked rebalance quantity in collateral units.
     *
     * return uint256          Chunked rebalance notional in collateral units
     * return uint256          Total rebalance notional in collateral units
     */
    function _calculateChunkRebalanceNotional(
        LeverageInfo memory _leverageInfo,
        uint256 _newLeverageRatio,
        bool _isLever
    )
        internal
        view
        returns (uint256, uint256)
    {
        // Calculate absolute value of difference between new and current leverage ratio
        uint256 leverageRatioDifference = _isLever ? _newLeverageRatio.sub(_leverageInfo.currentLeverageRatio) : _leverageInfo.currentLeverageRatio.sub(_newLeverageRatio);

        uint256 totalRebalanceNotional = leverageRatioDifference.preciseDiv(_leverageInfo.currentLeverageRatio).preciseMul(_leverageInfo.action.collateralBalance);

        uint256 maxBorrow = _calculateMaxBorrowCollateral(_leverageInfo.action, _isLever);

        uint256 chunkRebalanceNotional = Math.min(Math.min(maxBorrow, totalRebalanceNotional), _leverageInfo.twapMaxTradeSize);

        return (chunkRebalanceNotional, totalRebalanceNotional);
    }

    /**
     * Calculate the max borrow / repay amount allowed in base units for lever / delever. This is due to overcollateralization requirements on
     * assets deposited in lending protocols for borrowing.
     *
     * For lever, max borrow is calculated as:
     * (Net borrow limit in USD - existing borrow value in USD) / collateral asset price adjusted for decimals
     *
     * For delever, max repay is calculated as:
     * Collateral balance in base units * (net borrow limit in USD - existing borrow value in USD) / net borrow limit in USD
     *
     * Net borrow limit for levering is calculated as:
     * The collateral value in USD * Aave collateral factor * (1 - unutilized leverage %)
     *
     * Net repay limit for delevering is calculated as:
     * The collateral value in USD * Aave liquiditon threshold * (1 - unutilized leverage %)
     *
     * return uint256          Max borrow notional denominated in collateral asset
     */
    function _calculateMaxBorrowCollateral(ActionInfo memory _actionInfo, bool _isLever) internal view returns(uint256) {
        
        // Retrieve collateral factor and liquidation threshold for the collateral asset in precise units (1e16 = 1%)
        ( , uint256 maxLtvRaw, uint256 liquidationThresholdRaw, , , , , , ,) = strategy.aaveProtocolDataProvider.getReserveConfigurationData(address(strategy.collateralAsset));

        // Normalize LTV and liquidation threshold to precise units. LTV is measured in 4 decimals in Aave which is why we must multiply by 1e14
        // for example ETH has an LTV value of 8000 which represents 80%
        if (_isLever) {
            uint256 netBorrowLimit = _actionInfo.collateralValue
                .preciseMul(maxLtvRaw.mul(10 ** 14))
                .preciseMul(PreciseUnitMath.preciseUnit().sub(execution.unutilizedLeveragePercentage));

            return netBorrowLimit
                .sub(_actionInfo.borrowValue)
                .preciseDiv(_actionInfo.collateralPrice);
        } else {
            uint256 netRepayLimit = _actionInfo.collateralValue
                .preciseMul(liquidationThresholdRaw.mul(10 ** 14))
                .preciseMul(PreciseUnitMath.preciseUnit().sub(execution.unutilizedLeveragePercentage));

            return _actionInfo.collateralBalance
                .preciseMul(netRepayLimit.sub(_actionInfo.borrowValue))
                .preciseDiv(netRepayLimit);
        }
    }

    /**
     * Derive the borrow units for lever. The units are calculated by the collateral units multiplied by collateral / borrow asset price.
     * Output is measured to borrow unit decimals.
     *
     * return uint256           Position units to borrow
     */
    function _calculateBorrowUnits(uint256 _collateralRebalanceUnits, ActionInfo memory _actionInfo) internal pure returns (uint256) {
        return _collateralRebalanceUnits.preciseMul(_actionInfo.collateralPrice).preciseDiv(_actionInfo.borrowPrice);
    }

    /**
     * Calculate the min receive units in collateral units for lever. Units are calculated as target collateral rebalance units multiplied by slippage tolerance
     * Output is measured in collateral asset decimals.
     *
     * return uint256           Min position units to receive after lever trade
     */
    function _calculateMinCollateralReceiveUnits(uint256 _collateralRebalanceUnits, uint256 _slippageTolerance) internal pure returns (uint256) {
        return _collateralRebalanceUnits.preciseMul(PreciseUnitMath.preciseUnit().sub(_slippageTolerance));
    }

    /**
     * Derive the min repay units from collateral units for delever. Units are calculated as target collateral rebalance units multiplied by slippage tolerance
     * and pair price (collateral oracle price / borrow oracle price). Output is measured in borrow unit decimals.
     *
     * return uint256           Min position units to repay in borrow asset
     */
    function _calculateMinRepayUnits(uint256 _collateralRebalanceUnits, uint256 _slippageTolerance, ActionInfo memory _actionInfo) internal pure returns (uint256) {
        return _collateralRebalanceUnits
            .preciseMul(_actionInfo.collateralPrice)
            .preciseDiv(_actionInfo.borrowPrice)
            .preciseMul(PreciseUnitMath.preciseUnit().sub(_slippageTolerance));
    }

    /**
     * Update last trade timestamp and if chunk rebalance size is less than total rebalance notional, store new leverage ratio to kick off TWAP. Used in
     * the engage() and rebalance() functions
     */
    function _updateRebalanceState(
        uint256 _chunkRebalanceNotional,
        uint256 _totalRebalanceNotional,
        uint256 _newLeverageRatio,
        string memory _exchangeName
    )
        internal
    {

        _updateLastTradeTimestamp(_exchangeName);

        if (_chunkRebalanceNotional < _totalRebalanceNotional) {
            twapLeverageRatio = _newLeverageRatio;
        }
    }

    /**
     * Update last trade timestamp and if chunk rebalance size is equal to the total rebalance notional, end TWAP by clearing state. This function is used
     * in iterateRebalance()
     */
    function _updateIterateState(uint256 _chunkRebalanceNotional, uint256 _totalRebalanceNotional, string memory _exchangeName) internal {

        _updateLastTradeTimestamp(_exchangeName);

        // If the chunk size is equal to the total notional meaning that rebalances are not chunked, then clear TWAP state.
        if (_chunkRebalanceNotional == _totalRebalanceNotional) {
            delete twapLeverageRatio;
        }
    }

    /**
     * Update last trade timestamp and if currently in a TWAP, delete the TWAP state. Used in the ripcord() function.
     */
    function _updateRipcordState(string memory _exchangeName) internal {

        _updateLastTradeTimestamp(_exchangeName);

        // If TWAP leverage ratio is stored, then clear state. This may happen if we are currently in a TWAP rebalance, and the leverage ratio moves above the
        // incentivized threshold for ripcord.
        if (twapLeverageRatio > 0) {
            delete twapLeverageRatio;
        }
    }

    /**
     * Update globalLastTradeTimestamp and exchangeLastTradeTimestamp values. This function updates both the exchange-specific and global timestamp so that the
     * epoch rebalance can use the global timestamp (since the global timestamp is always  equal to the most recently used exchange timestamp). This allows for
     * multiple rebalances to occur simultaneously since only the exchange-specific timestamp is checked for non-epoch rebalances.
     */
     function _updateLastTradeTimestamp(string memory _exchangeName) internal {
        globalLastTradeTimestamp = block.timestamp;
        exchangeSettings[_exchangeName].exchangeLastTradeTimestamp = block.timestamp;
     }

    /**
     * Transfer ETH reward to caller of the ripcord function. If the ETH balance on this contract is less than required
     * incentive quantity, then transfer contract balance instead to prevent reverts.
     *
     * return uint256           Amount of ETH transferred to caller
     */
    function _transferEtherRewardToCaller(uint256 _etherReward) internal returns(uint256) {
        uint256 etherToTransfer = _etherReward < address(this).balance ? _etherReward : address(this).balance;

        msg.sender.transfer(etherToTransfer);

        return etherToTransfer;
    }

    /**
     * Internal function returning the ShouldRebalance enum used in shouldRebalance and shouldRebalanceWithBounds external getter functions
     *
     * return ShouldRebalance         Enum detailing whether to rebalance, iterateRebalance, ripcord or no action
     */
    function _shouldRebalance(
        uint256 _currentLeverageRatio,
        uint256 _minLeverageRatio,
        uint256 _maxLeverageRatio
    )
        internal
        view
        returns(string[] memory, ShouldRebalance[] memory)
    {

        ShouldRebalance[] memory shouldRebalanceEnums = new ShouldRebalance[](enabledExchanges.length);

        for (uint256 i = 0; i < enabledExchanges.length; i++) {
            // If none of the below conditions are satisfied, then should not rebalance
            shouldRebalanceEnums[i] = ShouldRebalance.NONE;

            // If above ripcord threshold, then check if incentivized cooldown period has elapsed
            if (_currentLeverageRatio >= incentive.incentivizedLeverageRatio) {
                if (exchangeSettings[enabledExchanges[i]].exchangeLastTradeTimestamp.add(incentive.incentivizedTwapCooldownPeriod) < block.timestamp) {
                    shouldRebalanceEnums[i] = ShouldRebalance.RIPCORD;
                }
            } else {
                // If TWAP, then check if the cooldown period has elapsed
                if (twapLeverageRatio > 0) {
                    if (exchangeSettings[enabledExchanges[i]].exchangeLastTradeTimestamp.add(execution.twapCooldownPeriod) < block.timestamp) {
                        shouldRebalanceEnums[i] = ShouldRebalance.ITERATE_REBALANCE;
                    }
                } else {
                    // If not TWAP, then check if the rebalance interval has elapsed OR current leverage is above max leverage OR current leverage is below
                    // min leverage
                    if (
                        block.timestamp.sub(globalLastTradeTimestamp) > methodology.rebalanceInterval
                        || _currentLeverageRatio > _maxLeverageRatio
                        || _currentLeverageRatio < _minLeverageRatio
                    ) {
                        shouldRebalanceEnums[i] = ShouldRebalance.REBALANCE;
                    }
                }
            }
        }

        return (enabledExchanges, shouldRebalanceEnums);
    }
}

File 9 of 17 : IBaseManager.sol
/*
    Copyright 2021 Set Labs Inc.

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

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

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

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

pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

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

interface IBaseManager {
    function setToken() external returns(ISetToken);

    function methodologist() external returns(address);

    function operator() external returns(address);

    function interactManager(address _module, bytes calldata _encoded) external;

    function transferTokens(address _token, address _destination, uint256 _amount) external;
}

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

interface IChainlinkAggregatorV3 {
    function latestAnswer() external view returns (int256);
}

File 11 of 17 : ILeverageModule.sol
// SPDX-License-Identifier: Apache License, Version 2.0
pragma solidity 0.6.10;
pragma experimental "ABIEncoderV2";

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

interface ILeverageModule {
    function sync(
        ISetToken _setToken
    ) external;

    function lever(
        ISetToken _setToken,
        address _borrowAsset,
        address _collateralAsset,
        uint256 _borrowQuantity,
        uint256 _minReceiveQuantity,
        string memory _tradeAdapterName,
        bytes memory _tradeData
    ) external;

    function delever(
        ISetToken _setToken,
        address _collateralAsset,
        address _repayAsset,
        uint256 _redeemQuantity,
        uint256 _minRepayQuantity,
        string memory _tradeAdapterName,
        bytes memory _tradeData
    ) external;

    function gulp(
        ISetToken _setToken,
        address _collateralAsset,
        uint256 _minNotionalReceiveQuantity,
        string memory _tradeAdapterName,
        bytes memory _tradeData
    ) external;
}

File 12 of 17 : IProtocolDataProvider.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

interface IProtocolDataProvider {
  struct TokenData {
    string symbol;
    address tokenAddress;
  }

  function ADDRESSES_PROVIDER() external view returns (address);
  function getAllReservesTokens() external view returns (TokenData[] memory);
  function getAllATokens() external view returns (TokenData[] memory);
  function getReserveConfigurationData(address asset) external view returns (uint256 decimals, uint256 ltv, uint256 liquidationThreshold, uint256 liquidationBonus, uint256 reserveFactor, bool usageAsCollateralEnabled, bool borrowingEnabled, bool stableBorrowRateEnabled, bool isActive, bool isFrozen);
  function getReserveData(address asset) external view returns (uint256 availableLiquidity, uint256 totalStableDebt, uint256 totalVariableDebt, uint256 liquidityRate, uint256 variableBorrowRate, uint256 stableBorrowRate, uint256 averageStableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex, uint40 lastUpdateTimestamp);
  function getUserReserveData(address asset, address user) external view returns (uint256 currentATokenBalance, uint256 currentStableDebt, uint256 currentVariableDebt, uint256 principalStableDebt, uint256 scaledVariableDebt, uint256 stableBorrowRate, uint256 liquidityRate, uint40 stableRateLastUpdated, bool usageAsCollateralEnabled);
  function getReserveTokensAddresses(address asset) external view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress);
}

File 13 of 17 : 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 14 of 17 : AddressArrayUtils.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;

/**
 * @title AddressArrayUtils
 * @author Set Protocol
 *
 * Utility functions to handle Address Arrays
 *
 * CHANGELOG:
 * - 4/27/21: Added validatePairsWithArray methods
 */
library AddressArrayUtils {

    /**
     * Finds the index of the first occurrence of the given element.
     * @param A The input array to search
     * @param a The value to find
     * @return Returns (index and isIn) for the first occurrence starting from index 0
     */
    function indexOf(address[] memory A, address a) internal pure returns (uint256, bool) {
        uint256 length = A.length;
        for (uint256 i = 0; i < length; i++) {
            if (A[i] == a) {
                return (i, true);
            }
        }
        return (uint256(-1), false);
    }

    /**
    * Returns true if the value is present in the list. Uses indexOf internally.
    * @param A The input array to search
    * @param a The value to find
    * @return Returns isIn for the first occurrence starting from index 0
    */
    function contains(address[] memory A, address a) internal pure returns (bool) {
        (, bool isIn) = indexOf(A, a);
        return isIn;
    }

    /**
    * Returns true if there are 2 elements that are the same in an array
    * @param A The input array to search
    * @return Returns boolean for the first occurrence of a duplicate
    */
    function hasDuplicate(address[] memory A) internal pure returns(bool) {
        require(A.length > 0, "A is empty");

        for (uint256 i = 0; i < A.length - 1; i++) {
            address current = A[i];
            for (uint256 j = i + 1; j < A.length; j++) {
                if (current == A[j]) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * @param A The input array to search
     * @param a The address to remove
     * @return Returns the array with the object removed.
     */
    function remove(address[] memory A, address a)
        internal
        pure
        returns (address[] memory)
    {
        (uint256 index, bool isIn) = indexOf(A, a);
        if (!isIn) {
            revert("Address not in array.");
        } else {
            (address[] memory _A,) = pop(A, index);
            return _A;
        }
    }

    /**
     * @param A The input array to search
     * @param a The address to remove
     */
    function removeStorage(address[] storage A, address a)
        internal
    {
        (uint256 index, bool isIn) = indexOf(A, a);
        if (!isIn) {
            revert("Address not in array.");
        } else {
            uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here
            if (index != lastIndex) { A[index] = A[lastIndex]; }
            A.pop();
        }
    }

    /**
    * Removes specified index from array
    * @param A The input array to search
    * @param index The index to remove
    * @return Returns the new array and the removed entry
    */
    function pop(address[] memory A, uint256 index)
        internal
        pure
        returns (address[] memory, address)
    {
        uint256 length = A.length;
        require(index < A.length, "Index must be < A length");
        address[] memory newAddresses = new address[](length - 1);
        for (uint256 i = 0; i < index; i++) {
            newAddresses[i] = A[i];
        }
        for (uint256 j = index + 1; j < length; j++) {
            newAddresses[j - 1] = A[j];
        }
        return (newAddresses, A[index]);
    }

    /**
     * Returns the combination of the two arrays
     * @param A The first array
     * @param B The second array
     * @return Returns A extended by B
     */
    function extend(address[] memory A, address[] memory B) internal pure returns (address[] memory) {
        uint256 aLength = A.length;
        uint256 bLength = B.length;
        address[] memory newAddresses = new address[](aLength + bLength);
        for (uint256 i = 0; i < aLength; i++) {
            newAddresses[i] = A[i];
        }
        for (uint256 j = 0; j < bLength; j++) {
            newAddresses[aLength + j] = B[j];
        }
        return newAddresses;
    }

    /**
     * Validate that address and uint array lengths match. Validate address array is not empty
     * and contains no duplicate elements.
     *
     * @param A         Array of addresses
     * @param B         Array of uint
     */
    function validatePairsWithArray(address[] memory A, uint[] memory B) internal pure {
        require(A.length == B.length, "Array length mismatch");
        _validateLengthAndUniqueness(A);
    }

    /**
     * Validate that address and bool array lengths match. Validate address array is not empty
     * and contains no duplicate elements.
     *
     * @param A         Array of addresses
     * @param B         Array of bool
     */
    function validatePairsWithArray(address[] memory A, bool[] memory B) internal pure {
        require(A.length == B.length, "Array length mismatch");
        _validateLengthAndUniqueness(A);
    }

    /**
     * Validate that address and string array lengths match. Validate address array is not empty
     * and contains no duplicate elements.
     *
     * @param A         Array of addresses
     * @param B         Array of strings
     */
    function validatePairsWithArray(address[] memory A, string[] memory B) internal pure {
        require(A.length == B.length, "Array length mismatch");
        _validateLengthAndUniqueness(A);
    }

    /**
     * Validate that address array lengths match, and calling address array are not empty
     * and contain no duplicate elements.
     *
     * @param A         Array of addresses
     * @param B         Array of addresses
     */
    function validatePairsWithArray(address[] memory A, address[] memory B) internal pure {
        require(A.length == B.length, "Array length mismatch");
        _validateLengthAndUniqueness(A);
    }

    /**
     * Validate that address and bytes array lengths match. Validate address array is not empty
     * and contains no duplicate elements.
     *
     * @param A         Array of addresses
     * @param B         Array of bytes
     */
    function validatePairsWithArray(address[] memory A, bytes[] memory B) internal pure {
        require(A.length == B.length, "Array length mismatch");
        _validateLengthAndUniqueness(A);
    }

    /**
     * Validate address array is not empty and contains no duplicate elements.
     *
     * @param A          Array of addresses
     */
    function _validateLengthAndUniqueness(address[] memory A) internal pure {
        require(A.length > 0, "Array length must be > 0");
        require(!hasDuplicate(A), "Cannot duplicate addresses");
    }
}

File 15 of 17 : BaseExtension.sol
/*
    Copyright 2021 Set Labs Inc.

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

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

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

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

pragma solidity 0.6.10;

import { AddressArrayUtils } from "../lib/AddressArrayUtils.sol";
import { IBaseManager } from "../interfaces/IBaseManager.sol";

/**
 * @title BaseExtension
 * @author Set Protocol
 *
 * Abstract class that houses common extension-related state and functions.
 */
abstract contract BaseExtension {
    using AddressArrayUtils for address[];

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

    event CallerStatusUpdated(address indexed _caller, bool _status);
    event AnyoneCallableUpdated(bool indexed _status);

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

    /**
     * Throws if the sender is not the SetToken operator
     */
    modifier onlyOperator() {
        require(msg.sender == manager.operator(), "Must be operator");
        _;
    }

    /**
     * Throws if the sender is not the SetToken methodologist
     */
    modifier onlyMethodologist() {
        require(msg.sender == manager.methodologist(), "Must be methodologist");
        _;
    }

    /**
     * Throws if caller is a contract, can be used to stop flash loan and sandwich attacks
     */
    modifier onlyEOA() {
        require(msg.sender == tx.origin, "Caller must be EOA Address");
        _;
    }

    /**
     * Throws if not allowed caller
     */
    modifier onlyAllowedCaller(address _caller) {
        require(isAllowedCaller(_caller), "Address not permitted to call");
        _;
    }

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

    // Instance of manager contract
    IBaseManager public manager;

    // Boolean indicating if anyone can call function
    bool public anyoneCallable;

    // Mapping of addresses allowed to call function
    mapping(address => bool) public callAllowList;

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

    constructor(IBaseManager _manager) public { manager = _manager; }

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

    /**
     * OPERATOR ONLY: Toggle ability for passed addresses to call only allowed caller functions
     *
     * @param _callers           Array of caller addresses to toggle status
     * @param _statuses          Array of statuses for each caller
     */
    function updateCallerStatus(address[] calldata _callers, bool[] calldata _statuses) external onlyOperator {
        require(_callers.length == _statuses.length, "Array length mismatch");
        require(_callers.length > 0, "Array length must be > 0");
        require(!_callers.hasDuplicate(), "Cannot duplicate callers");

        for (uint256 i = 0; i < _callers.length; i++) {
            address caller = _callers[i];
            bool status = _statuses[i];
            callAllowList[caller] = status;
            emit CallerStatusUpdated(caller, status);
        }
    }

    /**
     * OPERATOR ONLY: Toggle whether anyone can call function, bypassing the callAllowlist
     *
     * @param _status           Boolean indicating whether to allow anyone call
     */
    function updateAnyoneCallable(bool _status) external onlyOperator {
        anyoneCallable = _status;
        emit AnyoneCallableUpdated(_status);
    }

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

    /**
     * Invoke manager to transfer tokens from manager to other contract.
     *
     * @param _token           Token being transferred from manager contract
     * @param _amount          Amount of token being transferred
     */
    function invokeManagerTransfer(address _token, address _destination, uint256 _amount) internal {
        manager.transferTokens(_token, _destination, _amount);
    }

    /**
     * Invoke call from manager
     *
     * @param _module           Module to interact with
     * @param _encoded          Encoded byte data
     */
    function invokeManager(address _module, bytes memory _encoded) internal {
        manager.interactManager(_module, _encoded);
    }

    /**
     * Determine if passed address is allowed to call function. If anyoneCallable set to true anyone can call otherwise needs to be approved.
     *
     * return bool              Boolean indicating if allowed caller
     */
    function isAllowedCaller(address _caller) internal view virtual returns (bool) {
        return anyoneCallable || callAllowList[_caller];
    }
}

File 16 of 17 : PreciseUnitMath.sol
/*
    Copyright 2020 Set Labs Inc.

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

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

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

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

pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

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


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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

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

        return result;
    }

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

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

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

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

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

        return result;
    }
}

File 17 of 17 : StringArrayUtils.sol
/*
    Copyright 2021 Set Labs Inc.

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

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

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

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

pragma solidity 0.6.10;

/**
 * @title StringArrayUtils
 * @author Set Protocol
 *
 * Utility functions to handle String Arrays
 */
library StringArrayUtils {

    /**
     * Finds the index of the first occurrence of the given element.
     * @param A The input string to search
     * @param a The value to find
     * @return Returns (index and isIn) for the first occurrence starting from index 0
     */
    function indexOf(string[] memory A, string memory a) internal pure returns (uint256, bool) {
        uint256 length = A.length;
        for (uint256 i = 0; i < length; i++) {
            if (keccak256(bytes(A[i])) == keccak256(bytes(a))) {
                return (i, true);
            }
        }
        return (uint256(-1), false);
    }

    /**
     * @param A The input array to search
     * @param a The string to remove
     */
    function removeStorage(string[] storage A, string memory a)
        internal
    {
        (uint256 index, bool isIn) = indexOf(A, a);
        if (!isIn) {
            revert("String not in array.");
        } else {
            uint256 lastIndex = A.length - 1; // If the array would be empty, the previous line would throw, so no underflow here
            if (index != lastIndex) { A[index] = A[lastIndex]; }
            A.pop();
        }
    }
}

Settings
{
  "evmVersion": "istanbul",
  "libraries": {},
  "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":"contract IBaseManager","name":"_manager","type":"address"},{"components":[{"internalType":"contract ISetToken","name":"setToken","type":"address"},{"internalType":"contract ILeverageModule","name":"leverageModule","type":"address"},{"internalType":"contract IProtocolDataProvider","name":"aaveProtocolDataProvider","type":"address"},{"internalType":"contract IChainlinkAggregatorV3","name":"collateralPriceOracle","type":"address"},{"internalType":"contract IChainlinkAggregatorV3","name":"borrowPriceOracle","type":"address"},{"internalType":"contract IERC20","name":"targetCollateralAToken","type":"address"},{"internalType":"contract IERC20","name":"targetBorrowDebtToken","type":"address"},{"internalType":"address","name":"collateralAsset","type":"address"},{"internalType":"address","name":"borrowAsset","type":"address"},{"internalType":"uint256","name":"collateralDecimalAdjustment","type":"uint256"},{"internalType":"uint256","name":"borrowDecimalAdjustment","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.ContractSettings","name":"_strategy","type":"tuple"},{"components":[{"internalType":"uint256","name":"targetLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"minLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"maxLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"recenteringSpeed","type":"uint256"},{"internalType":"uint256","name":"rebalanceInterval","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.MethodologySettings","name":"_methodology","type":"tuple"},{"components":[{"internalType":"uint256","name":"unutilizedLeveragePercentage","type":"uint256"},{"internalType":"uint256","name":"slippageTolerance","type":"uint256"},{"internalType":"uint256","name":"twapCooldownPeriod","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.ExecutionSettings","name":"_execution","type":"tuple"},{"components":[{"internalType":"uint256","name":"etherReward","type":"uint256"},{"internalType":"uint256","name":"incentivizedLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"incentivizedSlippageTolerance","type":"uint256"},{"internalType":"uint256","name":"incentivizedTwapCooldownPeriod","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.IncentiveSettings","name":"_incentive","type":"tuple"},{"internalType":"string[]","name":"_exchangeNames","type":"string[]"},{"components":[{"internalType":"uint256","name":"twapMaxTradeSize","type":"uint256"},{"internalType":"uint256","name":"exchangeLastTradeTimestamp","type":"uint256"},{"internalType":"uint256","name":"incentivizedTwapMaxTradeSize","type":"uint256"},{"internalType":"bytes","name":"leverExchangeData","type":"bytes"},{"internalType":"bytes","name":"deleverExchangeData","type":"bytes"}],"internalType":"struct AaveLeverageStrategyExtension.ExchangeSettings[]","name":"_exchangeSettings","type":"tuple[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bool","name":"_status","type":"bool"}],"name":"AnyoneCallableUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_caller","type":"address"},{"indexed":false,"internalType":"bool","name":"_status","type":"bool"}],"name":"CallerStatusUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_currentLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_chunkRebalanceNotional","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_totalRebalanceNotional","type":"uint256"}],"name":"Disengaged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_currentLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_chunkRebalanceNotional","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_totalRebalanceNotional","type":"uint256"}],"name":"Engaged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"_exchangeName","type":"string"},{"indexed":false,"internalType":"uint256","name":"twapMaxTradeSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"exchangeLastTradeTimestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"incentivizedTwapMaxTradeSize","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"leverExchangeData","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"deleverExchangeData","type":"bytes"}],"name":"ExchangeAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"_exchangeName","type":"string"}],"name":"ExchangeRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"_exchangeName","type":"string"},{"indexed":false,"internalType":"uint256","name":"twapMaxTradeSize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"exchangeLastTradeTimestamp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"incentivizedTwapMaxTradeSize","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"leverExchangeData","type":"bytes"},{"indexed":false,"internalType":"bytes","name":"deleverExchangeData","type":"bytes"}],"name":"ExchangeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_unutilizedLeveragePercentage","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_twapCooldownPeriod","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_slippageTolerance","type":"uint256"}],"name":"ExecutionSettingsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_etherReward","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_incentivizedLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_incentivizedSlippageTolerance","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_incentivizedTwapCooldownPeriod","type":"uint256"}],"name":"IncentiveSettingsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_targetLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_minLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_maxLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_recenteringSpeed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_rebalanceInterval","type":"uint256"}],"name":"MethodologySettingsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_currentLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_chunkRebalanceNotional","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_totalRebalanceNotional","type":"uint256"}],"name":"RebalanceIterated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_currentLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_chunkRebalanceNotional","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_totalRebalanceNotional","type":"uint256"}],"name":"Rebalanced","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_currentLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_newLeverageRatio","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_rebalanceNotional","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_etherIncentive","type":"uint256"}],"name":"RipcordCalled","type":"event"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"},{"components":[{"internalType":"uint256","name":"twapMaxTradeSize","type":"uint256"},{"internalType":"uint256","name":"exchangeLastTradeTimestamp","type":"uint256"},{"internalType":"uint256","name":"incentivizedTwapMaxTradeSize","type":"uint256"},{"internalType":"bytes","name":"leverExchangeData","type":"bytes"},{"internalType":"bytes","name":"deleverExchangeData","type":"bytes"}],"internalType":"struct AaveLeverageStrategyExtension.ExchangeSettings","name":"_exchangeSettings","type":"tuple"}],"name":"addEnabledExchange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"anyoneCallable","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"callAllowList","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"}],"name":"disengage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"enabledExchanges","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"}],"name":"engage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string[]","name":"_exchangeNames","type":"string[]"}],"name":"getChunkRebalanceNotional","outputs":[{"internalType":"uint256[]","name":"sizes","type":"uint256[]"},{"internalType":"address","name":"sellAsset","type":"address"},{"internalType":"address","name":"buyAsset","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentEtherIncentive","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCurrentLeverageRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEnabledExchanges","outputs":[{"internalType":"string[]","name":"","type":"string[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"}],"name":"getExchangeSettings","outputs":[{"components":[{"internalType":"uint256","name":"twapMaxTradeSize","type":"uint256"},{"internalType":"uint256","name":"exchangeLastTradeTimestamp","type":"uint256"},{"internalType":"uint256","name":"incentivizedTwapMaxTradeSize","type":"uint256"},{"internalType":"bytes","name":"leverExchangeData","type":"bytes"},{"internalType":"bytes","name":"deleverExchangeData","type":"bytes"}],"internalType":"struct AaveLeverageStrategyExtension.ExchangeSettings","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getExecution","outputs":[{"components":[{"internalType":"uint256","name":"unutilizedLeveragePercentage","type":"uint256"},{"internalType":"uint256","name":"slippageTolerance","type":"uint256"},{"internalType":"uint256","name":"twapCooldownPeriod","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.ExecutionSettings","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getIncentive","outputs":[{"components":[{"internalType":"uint256","name":"etherReward","type":"uint256"},{"internalType":"uint256","name":"incentivizedLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"incentivizedSlippageTolerance","type":"uint256"},{"internalType":"uint256","name":"incentivizedTwapCooldownPeriod","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.IncentiveSettings","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMethodology","outputs":[{"components":[{"internalType":"uint256","name":"targetLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"minLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"maxLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"recenteringSpeed","type":"uint256"},{"internalType":"uint256","name":"rebalanceInterval","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.MethodologySettings","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getStrategy","outputs":[{"components":[{"internalType":"contract ISetToken","name":"setToken","type":"address"},{"internalType":"contract ILeverageModule","name":"leverageModule","type":"address"},{"internalType":"contract IProtocolDataProvider","name":"aaveProtocolDataProvider","type":"address"},{"internalType":"contract IChainlinkAggregatorV3","name":"collateralPriceOracle","type":"address"},{"internalType":"contract IChainlinkAggregatorV3","name":"borrowPriceOracle","type":"address"},{"internalType":"contract IERC20","name":"targetCollateralAToken","type":"address"},{"internalType":"contract IERC20","name":"targetBorrowDebtToken","type":"address"},{"internalType":"address","name":"collateralAsset","type":"address"},{"internalType":"address","name":"borrowAsset","type":"address"},{"internalType":"uint256","name":"collateralDecimalAdjustment","type":"uint256"},{"internalType":"uint256","name":"borrowDecimalAdjustment","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.ContractSettings","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"globalLastTradeTimestamp","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"}],"name":"iterateRebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"contract IBaseManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"}],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"}],"name":"removeEnabledExchange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"}],"name":"ripcord","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"_categoryId","type":"uint8"}],"name":"setEModeCategory","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"unutilizedLeveragePercentage","type":"uint256"},{"internalType":"uint256","name":"slippageTolerance","type":"uint256"},{"internalType":"uint256","name":"twapCooldownPeriod","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.ExecutionSettings","name":"_newExecutionSettings","type":"tuple"}],"name":"setExecutionSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"etherReward","type":"uint256"},{"internalType":"uint256","name":"incentivizedLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"incentivizedSlippageTolerance","type":"uint256"},{"internalType":"uint256","name":"incentivizedTwapCooldownPeriod","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.IncentiveSettings","name":"_newIncentiveSettings","type":"tuple"}],"name":"setIncentiveSettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"targetLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"minLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"maxLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"recenteringSpeed","type":"uint256"},{"internalType":"uint256","name":"rebalanceInterval","type":"uint256"}],"internalType":"struct AaveLeverageStrategyExtension.MethodologySettings","name":"_newMethodologySettings","type":"tuple"}],"name":"setMethodologySettings","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shouldRebalance","outputs":[{"internalType":"string[]","name":"","type":"string[]"},{"internalType":"enum AaveLeverageStrategyExtension.ShouldRebalance[]","name":"","type":"uint8[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_customMinLeverageRatio","type":"uint256"},{"internalType":"uint256","name":"_customMaxLeverageRatio","type":"uint256"}],"name":"shouldRebalanceWithBounds","outputs":[{"internalType":"string[]","name":"","type":"string[]"},{"internalType":"enum AaveLeverageStrategyExtension.ShouldRebalance[]","name":"","type":"uint8[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"twapLeverageRatio","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_status","type":"bool"}],"name":"updateAnyoneCallable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_callers","type":"address[]"},{"internalType":"bool[]","name":"_statuses","type":"bool[]"}],"name":"updateCallerStatus","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"_exchangeName","type":"string"},{"components":[{"internalType":"uint256","name":"twapMaxTradeSize","type":"uint256"},{"internalType":"uint256","name":"exchangeLastTradeTimestamp","type":"uint256"},{"internalType":"uint256","name":"incentivizedTwapMaxTradeSize","type":"uint256"},{"internalType":"bytes","name":"leverExchangeData","type":"bytes"},{"internalType":"bytes","name":"deleverExchangeData","type":"bytes"}],"internalType":"struct AaveLeverageStrategyExtension.ExchangeSettings","name":"_exchangeSettings","type":"tuple"}],"name":"updateEnabledExchange","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawEtherBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

60806040523480156200001157600080fd5b5060405162005f0638038062005f068339810160408190526200003491620008b5565b600080546001600160a01b03199081166001600160a01b038a811691909117835588516002805484169183169190911790556020808a01516003805485169184169190911790556040808b01516004805486169185169190911790556060808c01516005805487169186169190911790556080808d015160068054881691871691909117905560a08d015160078054881691871691909117905560c08d015160088054881691871691909117905560e08d01516009805488169187169190911790556101008d0151600a80549097169516949094179094556101208b0151600b556101408b0151600c558951600d5589820151600e5589810151600f55898401516010559189015160115587516012558781015160135587820151601455865160165586015160175585015160185584015160195587908790879087908790879087905b82518110156200029b57620001a78282815181106200019357fe5b60200260200101516200033f60201b60201c565b818181518110620001b457fe5b60200260200101516015848381518110620001cb57fe5b6020026020010151604051620001e2919062000a66565b908152602001604051809103902060008201518160000155602082015181600101556040820151816002015560608201518160030190805190602001906200022c9291906200055a565b50608082015180516200024a9160048401916020909101906200055a565b50905050601a8382815181106200025d57fe5b602090810291909101810151825460018101845560009384529282902081516200029194919091019291909101906200055a565b5060010162000178565b506040805160a081018252600d548152600e54602080830191909152600f548284015260105460608084019190915260115460808085019190915284518083018652601254815260135481850152601454818701528551918201865260165482526017549382019390935260185494810194909452601954908401526200032b926001600160e01b036200036c16565b505050505050505050505050505062000dd4565b8051620003695760405162461bcd60e51b8152600401620003609062000c48565b60405180910390fd5b50565b825160208401511180159062000386575060008360200151115b620003a55760405162461bcd60e51b8152600401620003609062000cc0565b825160408401511015620003cd5760405162461bcd60e51b8152600401620003609062000a84565b620003e26200054d60201b620024971760201c565b836060015111158015620003fa575060008360600151115b620004195760405162461bcd60e51b8152600401620003609062000c89565b6200042e6200054d60201b620024971760201c565b82511115620004515760405162461bcd60e51b8152600401620003609062000baa565b620004666200054d60201b620024971760201c565b826020015111156200048c5760405162461bcd60e51b8152600401620003609062000abb565b620004a16200054d60201b620024971760201c565b81604001511115620004c75760405162461bcd60e51b8152600401620003609062000cf7565b826040015181602001511015620004f25760405162461bcd60e51b8152600401620003609062000beb565b8160400151836080015110156200051d5760405162461bcd60e51b8152600401620003609062000af0565b806060015182604001511015620005485760405162461bcd60e51b8152600401620003609062000b4d565b505050565b670de0b6b3a76400005b90565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106200059d57805160ff1916838001178555620005cd565b82800160010185558215620005cd579182015b82811115620005cd578251825591602001919060010190620005b0565b50620005db929150620005df565b5090565b6200055791905b80821115620005db5760008155600101620005e6565b8051620006098162000dbe565b92915050565b600082601f83011262000620578081fd5b815162000637620006318262000d6b565b62000d44565b818152915060208083019084810160005b84811015620006755762000662888484518a01016200076f565b8452928201929082019060010162000648565b505050505092915050565b600082601f83011262000691578081fd5b8151620006a2620006318262000d6b565b818152915060208083019084810160005b8481101562000675578151870160a080601f19838c03011215620006d657600080fd5b620006e18162000d44565b8583015181526040808401518783015260608085015182840152608091508185015160018060401b03808211156200071857600080fd5b620007288f8b848a01016200076f565b83860152858701519250808311156200074057600080fd5b5050620007528d89838801016200076f565b9183019190915250865250509282019290820190600101620006b3565b600082601f83011262000780578081fd5b81516001600160401b0381111562000796578182fd5b620007ab601f8201601f191660200162000d44565b9150808252836020828501011115620007c357600080fd5b620007d681602084016020860162000d8b565b5092915050565b600060608284031215620007ef578081fd5b620007fb606062000d44565b905081518152602082015160208201526040820151604082015292915050565b6000608082840312156200082d578081fd5b62000839608062000d44565b90508151815260208201516020820152604082015160408201526060820151606082015292915050565b600060a0828403121562000875578081fd5b6200088160a062000d44565b9050815181526020820151602082015260408201516040820152606082015160608201526080820151608082015292915050565b6000806000806000806000878903610340811215620008d2578384fd5b8851620008df8162000dbe565b9750610160601f198201811315620008f5578485fd5b620009008162000d44565b9150620009118b60208c01620005fc565b8252620009228b60408c01620005fc565b6020830152620009368b60608c01620005fc565b60408301526200094a8b60808c01620005fc565b60608301526200095e8b60a08c01620005fc565b6080830152620009728b60c08c01620005fc565b60a0830152620009868b60e08c01620005fc565b60c08301526101006200099c8c828d01620005fc565b60e0840152610120620009b28d828e01620005fc565b918401919091526101408b81015191840191909152908a0151908201529550620009e1896101808a0162000863565b9450620009f3896102208a01620007dd565b935062000a05896102808a016200081b565b6103008901519093506001600160401b038082111562000a23578384fd5b62000a318b838c016200060f565b93506103208a015191508082111562000a48578283fd5b5062000a578a828b0162000680565b91505092959891949750929550565b6000825162000a7a81846020870162000d8b565b9190910192915050565b6020808252601a908201527f4d7573742062652076616c6964206d6178206c65766572616765000000000000604082015260600190565b6020808252818101527f536c69707061676520746f6c6572616e6365206d757374206265203c31303025604082015260600190565b6020808252603c908201527f526562616c616e636520696e74657276616c206d75737420626520677265617460408201527f6572207468616e205457415020636f6f6c646f776e20706572696f6400000000606082015260800190565b6020808252603d908201527f5457415020636f6f6c646f776e206d757374206265206772656174657220746860408201527f616e20696e63656e746976697a6564205457415020636f6f6c646f776e000000606082015260800190565b60208082526021908201527f556e7574696c697a6564206c65766572616765206d757374206265203c3130306040820152602560f81b606082015260800190565b60208082526038908201527f496e63656e746976697a6564206c6576657261676520726174696f206d75737460408201527f206265203e206d6178206c6576657261676520726174696f0000000000000000606082015260800190565b60208082526021908201527f4d617820545741502074726164652073697a65206d757374206e6f74206265206040820152600360fc1b606082015260800190565b6020808252601f908201527f4d7573742062652076616c696420726563656e746572696e6720737065656400604082015260600190565b6020808252601a908201527f4d7573742062652076616c6964206d696e206c65766572616765000000000000604082015260600190565b6020808252602d908201527f496e63656e746976697a656420736c69707061676520746f6c6572616e63652060408201526c6d757374206265203c3130302560981b606082015260800190565b6040518181016001600160401b038111828210171562000d6357600080fd5b604052919050565b60006001600160401b0382111562000d81578081fd5b5060209081020190565b60005b8381101562000da857818101518382015260200162000d8e565b8381111562000db8576000848401525b50505050565b6001600160a01b03811681146200036957600080fd5b6151228062000de46000396000f3fe6080604052600436106101e75760003560e01c80637e80c93e11610102578063cb7f579611610095578063dde5aa6911610064578063dde5aa6914610597578063e81409d3146105b9578063f8bdbda8146105d9578063fdfb7091146105f9576101ee565b8063cb7f579614610508578063d330fd7f14610535578063d3d72afc14610555578063da39048014610575576101ee565b8063aea6cc80116100d1578063aea6cc801461049c578063b8e0eeb7146104bc578063c1c7ff0c146104de578063c31443bb146104f3576101ee565b80637e80c93e1461040a57806389861cf914610439578063aa31e5d114610467578063ae2c1d5f14610487576101ee565b806341212e9e1161017a578063633216f111610149578063633216f11461038857806363f8cb20146103a85780636ad5e3e1146103ca5780636db66d29146103ea576101ee565b806341212e9e14610306578063481c6a751461032657806357ff1bc8146103485780635a860bab14610368576101ee565b806324223322116101b6578063242233221461028f5780632d158e7d146102af5780632ec0090a146102d15780632ede5813146102e6576101ee565b806304d7f3e7146101f357806307da06031461021e578063095f0273146102405780631997789a14610262576101ee565b366101ee57005b600080fd5b3480156101ff57600080fd5b5061020861060e565b6040516102159190614f8c565b60405180910390f35b34801561022a57600080fd5b5061023361064c565b6040516102159190614e15565b34801561024c57600080fd5b5061026061025b366004613e9b565b6106d9565b005b34801561026e57600080fd5b5061028261027d366004613e9b565b6107ee565b6040516102159190614ee0565b34801561029b57600080fd5b506102606102aa366004613e9b565b61097b565b3480156102bb57600080fd5b506102c4610b09565b6040516102159190614502565b3480156102dd57600080fd5b50610260610b19565b3480156102f257600080fd5b50610260610301366004613fde565b610c1f565b34801561031257600080fd5b50610260610321366004613e9b565b610dcc565b34801561033257600080fd5b5061033b610edb565b6040516102159190614321565b34801561035457600080fd5b50610260610363366004613ece565b610eea565b34801561037457600080fd5b50610260610383366004613e67565b611105565b34801561039457600080fd5b506102606103a3366004614155565b611203565b3480156103b457600080fd5b506103bd6112c3565b6040516102159190614f40565b3480156103d657600080fd5b506102606103e5366004613e9b565b6112f0565b3480156103f657600080fd5b50610260610405366004613e9b565b61140c565b34801561041657600080fd5b5061042a610425366004613e27565b611575565b604051610215939291906144a4565b34801561044557600080fd5b5061045961045436600461408e565b6117e0565b604051610215929190614444565b34801561047357600080fd5b50610260610482366004614025565b61183a565b34801561049357600080fd5b506104596119fc565b3480156104a857600080fd5b506102c46104b7366004613d86565b611a29565b3480156104c857600080fd5b506104d1611a3e565b6040516102159190614fc6565b3480156104ea57600080fd5b506104d1611a7e565b3480156104ff57600080fd5b506104d1611a84565b34801561051457600080fd5b50610528610523366004614076565b611ab0565b604051610215919061450d565b34801561054157600080fd5b50610260610550366004613fa1565b611b56565b34801561056157600080fd5b50610260610570366004613ece565b611d01565b34801561058157600080fd5b5061058a611f7a565b6040516102159190614431565b3480156105a357600080fd5b506105ac612052565b6040516102159190614f61565b3480156105c557600080fd5b506102606105d4366004613dbe565b612087565b3480156105e557600080fd5b506102606105f4366004613e9b565b612297565b34801561060557600080fd5b506104d1612491565b610616613a19565b506040805160a081018252600d548152600e546020820152600f5491810191909152601054606082015260115460808201525b90565b610654613a48565b5060408051610160810182526002546001600160a01b039081168252600354811660208301526004548116928201929092526005548216606082015260065482166080820152600754821660a0820152600854821660c0820152600954821660e0820152600a54909116610100820152600b54610120820152600c5461014082015290565b3332146107015760405162461bcd60e51b81526004016106f8906146c9565b60405180910390fd5b610709613aa4565b61073a6016600201546015846040516107229190614295565b908152602001604051809103902060020154846124a3565b9050610767816015846040516107509190614295565b908152602001604051809103902060010154612585565b600061077a82600d6002015460006125e2565b5090506107878282612688565b61079083612760565b60006107a0601660000154612779565b90507f3ef50471c967ac74a1fec015a5fb439eefe1994f80029752c082a26c3133c9328360200151600d6002015484846040516107e09493929190614fe5565b60405180910390a150505050565b6107f6613ad9565b6015826040516108069190614295565b90815260200160405180910390206040518060a0016040529081600082015481526020016001820154815260200160028201548152602001600382018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108d65780601f106108ab576101008083540402835291602001916108d6565b820191906000526020600020905b8154815290600101906020018083116108b957829003601f168201915b505050918352505060048201805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815293820193929183018282801561096a5780601f1061093f5761010080835404028352916020019161096a565b820191906000526020600020905b81548152906001019060200180831161094d57829003601f168201915b50505050508152505090505b919050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156109ca57600080fd5b505af11580156109de573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a029190613da2565b6001600160a01b0316336001600160a01b031614610a325760405162461bcd60e51b81526004016106f890614639565b601581604051610a429190614295565b90815260405190819003602001902054610a6e5760405162461bcd60e51b81526004016106f890614dc3565b601581604051610a7e9190614295565b90815260405190819003602001902060008082556001820181905560028201819055610aad6003830182613b08565b610abb600483016000613b08565b50610acf9050601a8263ffffffff6127c216565b7fd6acd22a732277ebc5ff0aa733e7c08652f8a2921d88558372cce63e40cfdaae81604051610afe919061450d565b60405180910390a150565b600054600160a01b900460ff1681565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610b6857600080fd5b505af1158015610b7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba09190613da2565b6001600160a01b0316336001600160a01b031614610bd05760405162461bcd60e51b81526004016106f890614639565b601b5415610bf05760405162461bcd60e51b81526004016106f890614960565b60405133904780156108fc02916000818181858888f19350505050158015610c1c573d6000803e3d6000fd5b50565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610c6e57600080fd5b505af1158015610c82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca69190613da2565b6001600160a01b0316336001600160a01b031614610cd65760405162461bcd60e51b81526004016106f890614639565b601b5415610cf65760405162461bcd60e51b81526004016106f890614960565b80516016819055602080830151601781905560408085015160188190556060808701516019819055835160a081018552600d548152600e5481880152600f548186015260105481840152601154608080830191909152855180850187526012548152601354818a015260145481880152865191820187529881529687019590955292850191909152830152610d8c929091612949565b6016546017546018546019546040517f26bc8aa9f7ec6c447f7831dbe144ee8e1c6ca04e62959e63e5b8002b0b4a5ce194610afe94909390929091614fe5565b333214610deb5760405162461bcd60e51b81526004016106f8906146c9565b33610df581612ad9565b610e115760405162461bcd60e51b81526004016106f890614acd565b610e19613aa4565b610e48601260010154601585604051610e329190614295565b90815260405190819003602001902054856124a3565b9050610e5c81600d60040154601c54612b10565b610e64612b83565b6000610e738260200151612ba5565b9050600080610e828484612c26565b91509150610e9282828589612c7e565b7f6f55209924dba11af5ddabda4999b20d0ce3aa1847c56b67240ed1fc3590c1348460200151848484604051610ecb9493929190614fe5565b60405180910390a1505050505050565b6000546001600160a01b031681565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610f3957600080fd5b505af1158015610f4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f719190613da2565b6001600160a01b0316336001600160a01b031614610fa15760405162461bcd60e51b81526004016106f890614639565b601582604051610fb19190614295565b90815260405190819003602001902054610fdd5760405162461bcd60e51b81526004016106f890614dc3565b610fe681612c97565b8051604051601590610ff9908590614295565b90815260200160405180910390206000018190555080604001516015836040516110239190614295565b908152602001604051809103902060020181905550806060015160158360405161104d9190614295565b90815260200160405180910390206003019080519060200190611071929190613b4c565b5080608001516015836040516110879190614295565b908152602001604051809103902060040190805190602001906110ab929190613b4c565b507f53fdf113d6ccd58f1d643ab8402360c17a9d114d055d36c8766e84dfec76a93482826000015183602001518460400151856060015186608001516040516110f996959493929190614520565b60405180910390a15050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561115457600080fd5b505af1158015611168573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118c9190613da2565b6001600160a01b0316336001600160a01b0316146111bc5760405162461bcd60e51b81526004016106f890614639565b6000805460ff60a01b1916600160a01b83151590810291909117825560405190917f92f8cd47e301bde05ff0abd73cc198632f3ac64fa443a1afc3e47745b3ea1acb91a250565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561125257600080fd5b505af1158015611266573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061128a9190613da2565b6001600160a01b0316336001600160a01b0316146112ba5760405162461bcd60e51b81526004016106f890614639565b610c1c81612cb5565b6112cb613bc6565b5060408051606081018252601254815260135460208201526014549181019190915290565b33321461130f5760405162461bcd60e51b81526004016106f8906146c9565b3361131981612ad9565b6113355760405162461bcd60e51b81526004016106f890614acd565b61133d613aa4565b611356601260010154601585604051610e329190614295565b9050611389816012600201546015866040516113729190614295565b908152602001604051809103902060010154612b10565b611391612d1b565b6000806113a18360200151612d3d565b6113b7576113b183601b54612c26565b90925090505b6113c2828287612d74565b7fbba909c59ebdb6de1c7e9f168dae0e8934434ce708dda9f312d6f3a1d1a502598360200151601b5484846040516113fd9493929190614fe5565b60405180910390a15050505050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561145b57600080fd5b505af115801561146f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114939190613da2565b6001600160a01b0316336001600160a01b0316146114c35760405162461bcd60e51b81526004016106f890614639565b6114cb613aa4565b6114fa6012600101546015846040516114e49190614295565b90815260405190819003602001902054846124a3565b90506000611506612497565b9050600080611517848460006125e2565b91509150818111156115325761152d8483612688565b61153c565b61153c8482612d8f565b7fe7945163803ad02726587e34ca2c4a76ec8dbc6d0b3ddb72d7f93d794e59075984602001518484846040516113fd9493929190614fe5565b6060600080600080611585611a84565b6017549091506000908211156115a25750600f54915060016115c0565b601b54156115b457601b5492506115c0565b6115bd82612ba5565b92505b6115c8613be7565b6115d0612e7b565b90508284118867ffffffffffffffff811180156115ec57600080fd5b50604051908082528060200260200182016040528015611616578160200160208202803683370190505b50975060005b898110156117895761162c613aa4565b6040518060a001604052808581526020018781526020018661165057601354611654565b6018545b8152602001866116a15760158e8e8681811061166c57fe5b905060200281019061167e9190615023565b60405161168c929190614285565b908152604051908190036020019020546116e2565b60158e8e868181106116af57fe5b90506020028101906116c19190615023565b6040516116cf929190614285565b9081526020016040518091039020600201545b81526020018d8d858181106116f357fe5b90506020028101906117059190615023565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250929350915061174c90508289866125e2565b5090508361175a5780611768565b61176881836000015161319b565b8b848151811061177457fe5b6020908102919091010152505060010161161c565b50806117a0576009546001600160a01b03166117ad565b600a546001600160a01b03165b9650806117c557600a546001600160a01b03166117d2565b6009546001600160a01b03165b955050505050509250925092565b606080600d6001015484111580156117fa5750600f548310155b6118165760405162461bcd60e51b81526004016106f890614569565b6000611820611a84565b905061182d8186866131c3565b92509250505b9250929050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561188957600080fd5b505af115801561189d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c19190613da2565b6001600160a01b0316336001600160a01b0316146118f15760405162461bcd60e51b81526004016106f890614639565b601b54156119115760405162461bcd60e51b81526004016106f890614960565b8051600d819055602080830151600e819055604080850151600f81905560608087015160108190556080808901516011819055855160a0810187529889528888019690965287850193909352868201528582019390935281518084018352601254815260135481860152601454818401528251918201835260165482526017549482019490945260185491810191909152601954918101919091526119b7929190612949565b600d54600e54600f546010546011546040517f69b7cb6b3922c6a0381263018e3350f753caa251b7426259cc918065dc1c45bd95610afe959094909390929091615000565b6060806000611a09611a84565b9050611a2081600d60010154600d600201546131c3565b92509250509091565b60016020526000908152604090205460ff1681565b600080611a49611a84565b6017549091508110611a70576016544711611a645747611a68565b6016545b915050610649565b6000915050610649565b5090565b601c5481565b6000611a8e613be7565b611a96612e7b565b9050611aaa81604001518260600151613467565b91505090565b601a8181548110611abd57fe5b600091825260209182902001805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815293509091830182828015611b4e5780601f10611b2357610100808354040283529160200191611b4e565b820191906000526020600020905b815481529060010190602001808311611b3157829003601f168201915b505050505081565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015611ba557600080fd5b505af1158015611bb9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bdd9190613da2565b6001600160a01b0316336001600160a01b031614611c0d5760405162461bcd60e51b81526004016106f890614639565b601b5415611c2d5760405162461bcd60e51b81526004016106f890614960565b8051601281905560208083015160138190556040808501516014819055815160a081018352600d548152600e5481860152600f5481840152601054606080830191909152601154608080840191909152845180830186529788528787019590955286840192909252825193840183526016548452601754948401949094526018549183019190915260195490820152611cc69290612949565b6012546014546013546040517fb69986d7b36a79e7024b5654aa4006fbaeb1c553f3a0a8c79990b702fffd5cc693610afe9390929091614fcf565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015611d5057600080fd5b505af1158015611d64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d889190613da2565b6001600160a01b0316336001600160a01b031614611db85760405162461bcd60e51b81526004016106f890614639565b601582604051611dc89190614295565b9081526040519081900360200190205415611df55760405162461bcd60e51b81526004016106f890614b7c565b611dfe81612c97565b8051604051601590611e11908590614295565b9081526020016040518091039020600001819055508060400151601583604051611e3b9190614295565b9081526020016040518091039020600201819055508060600151601583604051611e659190614295565b90815260200160405180910390206003019080519060200190611e89929190613b4c565b508060800151601583604051611e9f9190614295565b90815260200160405180910390206004019080519060200190611ec3929190613b4c565b506000601583604051611ed69190614295565b90815260405160209181900382019020600190810192909255601a805492830181556000528351611f2c927f057c384a7d1c54f3a1b2e5e67b2617b8224fdfd1ea7234eea573a6ff665ff63e0191850190613b4c565b507fd2df566766a30e4280d446b04d14012600df99b449ec4c4afe9201ff36047e5382826000015183602001518460400151856060015186608001516040516110f996959493929190614520565b6060601a805480602002602001604051908101604052809291908181526020016000905b828210156120495760008481526020908190208301805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156120355780601f1061200a57610100808354040283529160200191612035565b820191906000526020600020905b81548152906001019060200180831161201857829003601f168201915b505050505081526020019060010190611f9e565b50505050905090565b61205a613c24565b50604080516080810182526016548152601754602082015260185491810191909152601954606082015290565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156120d657600080fd5b505af11580156120ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061210e9190613da2565b6001600160a01b0316336001600160a01b03161461213e5760405162461bcd60e51b81526004016106f890614639565b82811461215d5760405162461bcd60e51b81526004016106f890614663565b8261217a5760405162461bcd60e51b81526004016106f890614bb3565b6121b684848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061348992505050565b156121d35760405162461bcd60e51b81526004016106f890614a6e565b60005b838110156122905760008585838181106121ec57fe5b90506020020160208101906122019190613d86565b9050600084848481811061221157fe5b90506020020160208101906122269190613e67565b6001600160a01b03831660008181526001602052604090819020805460ff191684151517905551919250907fbbf89f81f443eef9b97bfd2b7e260c0f575050d4094a0027dcf5d3623d9ef3ad9061227e908490614502565b60405180910390a250506001016121d6565b5050505050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156122e657600080fd5b505af11580156122fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231e9190613da2565b6001600160a01b0316336001600160a01b03161461234e5760405162461bcd60e51b81526004016106f890614639565b612356613be7565b61235e612e7b565b905060008160c00151116123845760405162461bcd60e51b81526004016106f890614ca1565b80516123a25760405162461bcd60e51b81526004016106f890614c6a565b6020810151156123c45760405162461bcd60e51b81526004016106f890614aa5565b6123cc613aa4565b6040518060a001604052808381526020016123e5612497565b815260200160126001015481526020016015856040516124059190614295565b908152602001604051809103902060000154815260200184815250905060008061243683600d6000015460016125e2565b915091506124448383613538565b6124558282600d6000015488612c7e565b6020830151600d546040517fac3b8ab89a07bbb8dd4670bcfe29ef7d4eccea237222f49f997884d89947d53d926113fd92909186908690614fe5565b601b5481565b670de0b6b3a764000090565b6124ab613aa4565b600083116124cb5760405162461bcd60e51b81526004016106f890614cd8565b6124d3613be7565b6124db612e7b565b905060008160c00151116125015760405162461bcd60e51b81526004016106f890614ca1565b805161251f5760405162461bcd60e51b81526004016106f890614c6a565b60008160200151116125435760405162461bcd60e51b81526004016106f890614b45565b600061255782604001518360600151613467565b6040805160a08101825293845260208401919091528201959095526060810193909352506080820152919050565b601754602083015110156125ab5760405162461bcd60e51b81526004016106f890614bea565b60195442906125c190839063ffffffff61362816565b106125de5760405162461bcd60e51b81526004016106f890614d08565b5050565b600080600083612606576020860151612601908663ffffffff61364d16565b61261c565b602086015161261c90869063ffffffff61364d16565b865151602088015191925060009161264c919061264090859063ffffffff61367516565b9063ffffffff61369f16565b9050600061265e8860000151876136bd565b9050600061267961266f8385613823565b8a60600151613823565b99929850919650505050505050565b815160c001516000906126a290839063ffffffff61367516565b905060006126b98285604001518660000151613839565b600254600954600a5460808801516040519495506060946001600160a01b03948516949384169390921691879187916015906126f6908390614295565b908152602001604051809103902060040160405160240161271d979695949392919061438f565b60408051601f198184030181529190526020810180516001600160e01b03166313f74a0f60e21b179052600354909150612290906001600160a01b031682613871565b612769816138d1565b601b5415610c1c576000601b5550565b600080478310612789574761278b565b825b604051909150339082156108fc029083906000818181858888f193505050501580156127bb573d6000803e3d6000fd5b5092915050565b60008061289e84805480602002602001604051908101604052809291908181526020016000905b828210156128945760008481526020908190208301805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156128805780601f1061285557610100808354040283529160200191612880565b820191906000526020600020905b81548152906001019060200180831161286357829003601f168201915b5050505050815260200190600101906127e9565b50505050846138fe565b91509150806128bf5760405162461bcd60e51b81526004016106f8906149ff565b835460001901828114612919578481815481106128d857fe5b906000526020600020018584815481106128ee57fe5b906000526020600020019080546001816001161561010002031660029004612917929190613c4c565b505b8480548061292357fe5b60019003818190600052602060002001600061293f9190613b08565b9055505b50505050565b8251602084015111801590612962575060008360200151115b61297e5760405162461bcd60e51b81526004016106f890614d3f565b8251604084015110156129a35760405162461bcd60e51b81526004016106f890614692565b6129ab612497565b8360600151111580156129c2575060008360600151115b6129de5760405162461bcd60e51b81526004016106f890614c33565b6129e6612497565b82511115612a065760405162461bcd60e51b81526004016106f8906148bf565b612a0e612497565b82602001511115612a315760405162461bcd60e51b81526004016106f890614700565b612a39612497565b81604001511115612a5c5760405162461bcd60e51b81526004016106f890614d76565b826040015181602001511015612a845760405162461bcd60e51b81526004016106f8906149a2565b816040015183608001511015612aac5760405162461bcd60e51b81526004016106f89061476c565b806060015182604001511015612ad45760405162461bcd60e51b81526004016106f89061482b565b505050565b60008054600160a01b900460ff1680612b0a57506001600160a01b03821660009081526001602052604090205460ff165b92915050565b601754602084015110612b355760405162461bcd60e51b81526004016106f8906145a0565b81612b46428363ffffffff61364d16565b1180612b575750600f546020840151115b80612b675750600e546020840151105b612ad45760405162461bcd60e51b81526004016106f8906145e9565b601b5415612ba35760405162461bcd60e51b81526004016106f890614900565b565b601054600d546000918291612bbf9163ffffffff61369f16565b90506000612be484612640600d60030154612bd8612497565b9063ffffffff61364d16565b90506000612bf8838363ffffffff61362816565b90506000612c0b82600d60020154613823565b9050612c1c600d600101548261395d565b9695505050505050565b6000806000808560200151851015612c5857612c44868660006125e2565b9092509050612c538683612688565b612c73565b612c64868660016125e2565b9092509050612c738683613538565b909590945092505050565b612c87816138d1565b828410156129435750601b555050565b8051610c1c5760405162461bcd60e51b81526004016106f890614b04565b600254604051606091612cd8916001600160a01b03909116908490602401614415565b60408051601f198184030181529190526020810180516001600160e01b031663d9b210d360e01b1790526003549091506125de906001600160a01b031682613871565b6000601b5411612ba35760405162461bcd60e51b81526004016106f8906147c9565b6000600d60000154601b54108015612d575750601b548210155b80612b0a5750600d54601b54118015612b0a575050601b54101590565b612d7d816138d1565b81831415612ad4576000601b55505050565b6000612dd6836000015160c00151612dca612dbd601260010154612db1612497565b9063ffffffff61362816565b859063ffffffff61369f16565b9063ffffffff61367516565b600254600954600a5460808701516040519495506060946001600160a01b03948516949384169390921691869190601590612e12908390614295565b9081526020016040518091039020600401604051602401612e3896959493929190614335565b60408051601f198184030181529190526020810180516001600160e01b031663d4fd27eb60e01b179052600354909150612943906001600160a01b031682613871565b612e83613be7565b612e8b613be7565b600554604080516350d25bcd60e01b815290516000926001600160a01b0316916350d25bcd916004808301926020929190829003018186803b158015612ed057600080fd5b505afa158015612ee4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f089190613e83565b9050612f2b600260090154600a0a612f1f8361396d565b9063ffffffff61398f16565b6080830152600654604080516350d25bcd60e01b815290516000926001600160a01b0316916350d25bcd916004828101926020929190829003018186803b158015612f7557600080fd5b505afa158015612f89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fad9190613e83565b9050612fc46002600a0154600a0a612f1f8361396d565b60a08401526007546002546040516370a0823160e01b81526001600160a01b03928316926370a0823192612ffd92911690600401614321565b60206040518083038186803b15801561301557600080fd5b505afa158015613029573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061304d9190613e83565b83526008546002546040516370a0823160e01b81526001600160a01b03928316926370a082319261308392911690600401614321565b60206040518083038186803b15801561309b57600080fd5b505afa1580156130af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130d39190613e83565b6020840152825160808401516130ee9163ffffffff61369f16565b6040840152602083015160a084015161310c9163ffffffff61369f16565b6060840152600254604080516318160ddd60e01b815290516001600160a01b03909216916318160ddd91600480820192602092909190829003018186803b15801561315657600080fd5b505afa15801561316a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318e9190613e83565b60c0840152509091505090565b60006131bc8260a00151612dca84608001518661369f90919063ffffffff16565b9392505050565b6060806060601a8054905067ffffffffffffffff811180156131e457600080fd5b5060405190808252806020026020018201604052801561320e578160200160208202803683370190505b50905060005b601a5481101561338457600082828151811061322c57fe5b6020026020010190600381111561323f57fe5b9081600381111561324c57fe5b90525060175487106132e457426132a76016600301546015601a858154811061327157fe5b9060005260206000200160405161328891906142b1565b908152604051908190036020019020600101549063ffffffff61362816565b10156132df5760038282815181106132bb57fe5b602002602001019060038111156132ce57fe5b908160038111156132db57fe5b9052505b61337c565b601b541561331957426133056012600201546015601a858154811061327157fe5b10156132df5760028282815181106132bb57fe5b601154601c5461333090429063ffffffff61364d16565b118061333b57508487115b8061334557508587105b1561337c57600182828151811061335857fe5b6020026020010190600381111561336b57fe5b9081600381111561337857fe5b9052505b600101613214565b50601a8181805480602002602001604051908101604052809291908181526020016000905b828210156134545760008481526020908190208301805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156134405780601f1061341557610100808354040283529160200191613440565b820191906000526020600020905b81548152906001019060200180831161342357829003601f168201915b5050505050815260200190600101906133a9565b5050505091509250925050935093915050565b60006131bc61347c848463ffffffff61364d16565b849063ffffffff61367516565b6000808251116134ab5760405162461bcd60e51b81526004016106f890614df1565b60005b600183510381101561352f5760008382815181106134c857fe5b6020026020010151905060008260010190505b8451811015613525578481815181106134f057fe5b60200260200101516001600160a01b0316826001600160a01b0316141561351d5760019350505050610976565b6001016134db565b50506001016134ae565b50600092915050565b815160c0015160009061355290839063ffffffff61367516565b9050600061356482856000015161319b565b905060006135768386604001516139c9565b600254600a5460095460808901516040519495506060946001600160a01b03948516949384169390921691879187916015906135b3908390614295565b90815260200160405180910390206003016040516024016135da979695949392919061438f565b60408051601f198184030181529190526020810180516001600160e01b0316600162114b6960e21b0319179052600354909150613620906001600160a01b031682613871565b505050505050565b6000828201838110156131bc5760405162461bcd60e51b81526004016106f890614735565b60008282111561366f5760405162461bcd60e51b81526004016106f8906147f4565b50900390565b60006131bc8261369385670de0b6b3a764000063ffffffff61398f16565b9063ffffffff6139e716565b60006131bc670de0b6b3a7640000613693858563ffffffff61398f16565b60048054600954604051633e15014160e01b8152600093849384936001600160a01b0391821693633e150141936136f8939092169101614321565b6101406040518083038186803b15801561371157600080fd5b505afa158015613725573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061374991906140af565b50505050505050925092505083156137c657600061379b613771601260000154612bd8612497565b61264061378a86655af3107a400063ffffffff61398f16565b60408a01519063ffffffff61369f16565b90506137bc8660800151612dca88606001518461364d90919063ffffffff16565b9350505050612b0a565b60006137f56137dc601260000154612bd8612497565b61264061378a85655af3107a400063ffffffff61398f16565b90506137bc81612dca61381589606001518561364d90919063ffffffff16565b89519063ffffffff61369f16565b600081831061383257816131bc565b5090919050565b600061386961384a84612bd8612497565b6126408460a00151612dca86608001518961369f90919063ffffffff16565b949350505050565b600054604051634cf4f63b60e01b81526001600160a01b0390911690634cf4f63b906138a390859085906004016143f1565b600060405180830381600087803b1580156138bd57600080fd5b505af1158015613620573d6000803e3d6000fd5b42601c8190556040516015906138e8908490614295565b9081526040519081900360200190206001015550565b81516000908190815b8181101561394d57848051906020012086828151811061392357fe5b6020026020010151805190602001201415613945579250600191506118339050565b600101613907565b5060001995600095509350505050565b60008183101561383257816131bc565b600080821215611a7a5760405162461bcd60e51b81526004016106f89061492b565b60008261399e57506000612b0a565b828202828482816139ab57fe5b04146131bc5760405162461bcd60e51b81526004016106f890614a2d565b60006131bc6139da83612bd8612497565b849063ffffffff61369f16565b6000808211613a085760405162461bcd60e51b81526004016106f890614888565b818381613a1157fe5b049392505050565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b6040805161016081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905261014081019190915290565b6040518060a00160405280613ab7613be7565b8152602001600081526020016000815260200160008152602001606081525090565b6040518060a0016040528060008152602001600081526020016000815260200160608152602001606081525090565b50805460018160011615610100020316600290046000825580601f10613b2e5750610c1c565b601f016020900490600052602060002090810190610c1c9190613cc1565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10613b8d57805160ff1916838001178555613bba565b82800160010185558215613bba579182015b82811115613bba578251825591602001919060010190613b9f565b50611a7a929150613cc1565b60405180606001604052806000815260200160008152602001600081525090565b6040518060e00160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040518060800160405280600081526020016000815260200160008152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10613c855780548555613bba565b82800160010185558215613bba57600052602060002091601f016020900482015b82811115613bba578254825591600101919060010190613ca6565b61064991905b80821115611a7a5760008155600101613cc7565b60008083601f840112613cec578182fd5b50813567ffffffffffffffff811115613d03578182fd5b602083019150836020808302850101111561183357600080fd5b600082601f830112613d2d578081fd5b813567ffffffffffffffff811115613d43578182fd5b613d56601f8201601f191660200161506a565b9150808252836020828501011115613d6d57600080fd5b8060208401602084013760009082016020015292915050565b600060208284031215613d97578081fd5b81356131bc816150c9565b600060208284031215613db3578081fd5b81516131bc816150c9565b60008060008060408587031215613dd3578283fd5b843567ffffffffffffffff80821115613dea578485fd5b613df688838901613cdb565b90965094506020870135915080821115613e0e578384fd5b50613e1b87828801613cdb565b95989497509550505050565b60008060208385031215613e39578182fd5b823567ffffffffffffffff811115613e4f578283fd5b613e5b85828601613cdb565b90969095509350505050565b600060208284031215613e78578081fd5b81356131bc816150de565b600060208284031215613e94578081fd5b5051919050565b600060208284031215613eac578081fd5b813567ffffffffffffffff811115613ec2578182fd5b61386984828501613d1d565b60008060408385031215613ee0578081fd5b823567ffffffffffffffff80821115613ef7578283fd5b613f0386838701613d1d565b93506020850135915080821115613f18578283fd5b81850160a08188031215613f2a578384fd5b613f3460a061506a565b9250803583526020810135602084015260408101356040840152606081013582811115613f5f578485fd5b613f6b88828401613d1d565b606085015250608081013582811115613f82578485fd5b613f8e88828401613d1d565b6080850152505050809150509250929050565b600060608284031215613fb2578081fd5b613fbc606061506a565b8235815260208301356020820152604083013560408201528091505092915050565b600060808284031215613fef578081fd5b613ff9608061506a565b823581526020830135602082015260408301356040820152606083013560608201528091505092915050565b600060a08284031215614036578081fd5b61404060a061506a565b82358152602083013560208201526040830135604082015260608301356060820152608083013560808201528091505092915050565b600060208284031215614087578081fd5b5035919050565b600080604083850312156140a0578182fd5b50508035926020909101359150565b6000806000806000806000806000806101408b8d0312156140ce578788fd5b8a51995060208b0151985060408b0151975060608b0151965060808b0151955060a08b01516140fc816150de565b60c08c015190955061410d816150de565b60e08c015190945061411e816150de565b6101008c0151909350614130816150de565b6101208c0151909250614142816150de565b809150509295989b9194979a5092959850565b600060208284031215614166578081fd5b813560ff811681146131bc578182fd5b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b858110156141c95782840389526141b78483516141d6565b9885019893509084019060010161419f565b5091979650505050505050565b600081518084526141ee81602086016020860161509d565b601f01601f19169290920160200192915050565b60008154600180821660008114614220576001811461423e5761427c565b60028304607f16865260ff198316602087015260408601935061427c565b6002830480875261424e86615091565b60005b828110156142725781546020828b0101528482019150602081019050614251565b8801602001955050505b50505092915050565b6000828483379101908152919050565b600082516142a781846020870161509d565b9190910192915050565b60008083546001808216600081146142d057600181146142e757614316565b60ff198316865260028304607f1686019350614316565b600283048786526020808720875b8381101561430e5781548a8201529085019082016142f5565b505050860193505b509195945050505050565b6001600160a01b0391909116815260200190565b6001600160a01b0387811682528681166020830152851660408201526060810184905260c060808201819052600090614370908301856141d6565b82810360a08401526143828185614202565b9998505050505050505050565b6001600160a01b038881168252878116602083015286166040820152606081018590526080810184905260e060a082018190526000906143d1908301856141d6565b82810360c08401526143e38185614202565b9a9950505050505050505050565b6001600160a01b0383168152604060208201819052600090613869908301846141d6565b6001600160a01b0392909216825260ff16602082015260400190565b6000602082526131bc6020830184614183565b6000604082526144576040830185614183565b828103602084810191909152845180835285820192820190845b818110156144975784516004811061448557fe5b83529383019391830191600101614471565b5090979650505050505050565b606080825284519082018190526000906020906080840190828801845b828110156144dd578151845292840192908401906001016144c1565b5050506001600160a01b03958616918401919091529290931660409091015292915050565b901515815260200190565b6000602082526131bc60208301846141d6565b600060c0825261453360c08301896141d6565b876020840152866040840152856060840152828103608084015261455781866141d6565b83810360a08501526143e381866141d6565b6020808252601b908201527f437573746f6d20626f756e6473206d7573742062652076616c69640000000000604082015260600190565b60208082526029908201527f4d7573742062652062656c6f7720696e63656e746976697a6564206c6576657260408201526861676520726174696f60b81b606082015260800190565b60208082526030908201527f436f6f6c646f776e206e6f7420656c6170736564206f72206e6f742076616c6960408201526f64206c6576657261676520726174696f60801b606082015260800190565b60208082526010908201526f26bab9ba1031329037b832b930ba37b960811b604082015260600190565b602080825260159082015274082e4e4c2f240d8cadccee8d040dad2e6dac2e8c6d605b1b604082015260600190565b6020808252601a908201527f4d7573742062652076616c6964206d6178206c65766572616765000000000000604082015260600190565b6020808252601a908201527f43616c6c6572206d75737420626520454f412041646472657373000000000000604082015260600190565b6020808252818101527f536c69707061676520746f6c6572616e6365206d757374206265203c31303025604082015260600190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252603c908201527f526562616c616e636520696e74657276616c206d75737420626520677265617460408201527f6572207468616e205457415020636f6f6c646f776e20706572696f6400000000606082015260800190565b6020808252601190820152704e6f7420696e205457415020737461746560781b604082015260600190565b6020808252601e908201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604082015260600190565b6020808252603d908201527f5457415020636f6f6c646f776e206d757374206265206772656174657220746860408201527f616e20696e63656e746976697a6564205457415020636f6f6c646f776e000000606082015260800190565b6020808252601a908201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604082015260600190565b60208082526021908201527f556e7574696c697a6564206c65766572616765206d757374206265203c3130306040820152602560f81b606082015260800190565b6020808252601190820152704d7573742063616c6c206974657261746560781b604082015260600190565b6020808252818101527f53616665436173743a2076616c7565206d75737420626520706f736974697665604082015260600190565b60208082526022908201527f526562616c616e63652069732063757272656e746c7920696e2070726f677265604082015261737360f01b606082015260800190565b60208082526038908201527f496e63656e746976697a6564206c6576657261676520726174696f206d75737460408201527f206265203e206d6178206c6576657261676520726174696f0000000000000000606082015260800190565b60208082526014908201527329ba3934b733903737ba1034b71030b93930bc9760611b604082015260600190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526018908201527f43616e6e6f74206475706c69636174652063616c6c6572730000000000000000604082015260600190565b6020808252600e908201526d044656274206d75737420626520360941b604082015260600190565b6020808252601d908201527f41646472657373206e6f74207065726d697474656420746f2063616c6c000000604082015260600190565b60208082526021908201527f4d617820545741502074726164652073697a65206d757374206e6f74206265206040820152600360fc1b606082015260800190565b60208082526019908201527f426f72726f772062616c616e6365206d75737420657869737400000000000000604082015260600190565b60208082526018908201527f45786368616e676520616c726561647920656e61626c65640000000000000000604082015260600190565b60208082526018908201527f4172726179206c656e677468206d757374206265203e20300000000000000000604082015260600190565b60208082526029908201527f4d7573742062652061626f766520696e63656e746976697a6564206c6576657260408201526861676520726174696f60b81b606082015260800190565b6020808252601f908201527f4d7573742062652076616c696420726563656e746572696e6720737065656400604082015260600190565b6020808252601e908201527f436f6c6c61746572616c2062616c616e6365206d757374206265203e20300000604082015260600190565b6020808252601d908201527f536574546f6b656e206d7573742068617665203e203020737570706c79000000604082015260600190565b6020808252601690820152754d7573742062652076616c69642065786368616e676560501b604082015260600190565b6020808252601f908201527f5457415020636f6f6c646f776e206d757374206861766520656c617073656400604082015260600190565b6020808252601a908201527f4d7573742062652076616c6964206d696e206c65766572616765000000000000604082015260600190565b6020808252602d908201527f496e63656e746976697a656420736c69707061676520746f6c6572616e63652060408201526c6d757374206265203c3130302560981b606082015260800190565b602080825260149082015273115e18da185b99d9481b9bdd08195b98589b195960621b604082015260600190565b6020808252600a90820152694120697320656d70747960b01b604082015260600190565b600061016082019050614e29828451614176565b6020830151614e3b6020840182614176565b506040830151614e4e6040840182614176565b506060830151614e616060840182614176565b506080830151614e746080840182614176565b5060a0830151614e8760a0840182614176565b5060c0830151614e9a60c0840182614176565b5060e0830151614ead60e0840182614176565b5061010080840151614ec182850182614176565b5050610120838101519083015261014092830151929091019190915290565b600060208252825160208301526020830151604083015260408301516060830152606083015160a06080840152614f1a60c08401826141d6565b6080850151848203601f190160a08601529150614f3781836141d6565b95945050505050565b81518152602080830151908201526040918201519181019190915260600190565b8151815260208083015190820152604080830151908201526060918201519181019190915260800190565b600060a082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015292915050565b90815260200190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b948552602085019390935260408401919091526060830152608082015260a00190565b6000808335601e19843603018112615039578283fd5b8084018035925067ffffffffffffffff831115615054578384fd5b6020019250503681900382131561183357600080fd5b60405181810167ffffffffffffffff8111828210171561508957600080fd5b604052919050565b60009081526020902090565b60005b838110156150b85781810151838201526020016150a0565b838111156129435750506000910152565b6001600160a01b0381168114610c1c57600080fd5b8015158114610c1c57600080fdfea2646970667358221220aad1b3603fa967ded38c752d386579709038f2fdaf54e96ec77c7c545f22c2b564736f6c634300060a0033000000000000000000000000a7d11fa4b1ae979d2f8850aa33799a0bad253907000000000000000000000000e8888cdbc0a5958c29e7d91dae44897c7e64f9bc00000000000000000000000071e932715f5987077adc5a7aa245f38841e0dcbe0000000000000000000000007b4eb56e7cd4b454ba8ff71e4518426369a138a3000000000000000000000000536218f9e9eb48863970252233c8f271f554c2d00000000000000000000000008fffffd4afb6115b954bd326cbe7b4ba576818f6000000000000000000000000cc9ee9483f662091a1de4795249e24ac0ac2630f000000000000000000000000ea51d7853eefb32b6ee06b1c12e6dcca88be0ffe000000000000000000000000ae78736cd615f374d3085123a210448e74fc6393000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000006f05b59d3b2000000000000000000000000000000000000000000000000000006124fee993bc000000000000000000000000000000000000000000000000000075f610f70ed200000000000000000000000000000000000000000000000000000de0b6b3a7640000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000008e1bc9bf04000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083d6c7aab63600000000000000000000000000000000000000000000000000000011c37937e080000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001942616c616e636572563245786368616e676541646170746572000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000003635c9adc5dea0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000878678326eac90000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000201e19cf2d73a72ef1332c882f20534b6519be027600020000000000000000011200000000000000000000000000000000000000000000000000000000000000201e19cf2d73a72ef1332c882f20534b6519be0276000200000000000000000112

Deployed Bytecode

0x6080604052600436106101e75760003560e01c80637e80c93e11610102578063cb7f579611610095578063dde5aa6911610064578063dde5aa6914610597578063e81409d3146105b9578063f8bdbda8146105d9578063fdfb7091146105f9576101ee565b8063cb7f579614610508578063d330fd7f14610535578063d3d72afc14610555578063da39048014610575576101ee565b8063aea6cc80116100d1578063aea6cc801461049c578063b8e0eeb7146104bc578063c1c7ff0c146104de578063c31443bb146104f3576101ee565b80637e80c93e1461040a57806389861cf914610439578063aa31e5d114610467578063ae2c1d5f14610487576101ee565b806341212e9e1161017a578063633216f111610149578063633216f11461038857806363f8cb20146103a85780636ad5e3e1146103ca5780636db66d29146103ea576101ee565b806341212e9e14610306578063481c6a751461032657806357ff1bc8146103485780635a860bab14610368576101ee565b806324223322116101b6578063242233221461028f5780632d158e7d146102af5780632ec0090a146102d15780632ede5813146102e6576101ee565b806304d7f3e7146101f357806307da06031461021e578063095f0273146102405780631997789a14610262576101ee565b366101ee57005b600080fd5b3480156101ff57600080fd5b5061020861060e565b6040516102159190614f8c565b60405180910390f35b34801561022a57600080fd5b5061023361064c565b6040516102159190614e15565b34801561024c57600080fd5b5061026061025b366004613e9b565b6106d9565b005b34801561026e57600080fd5b5061028261027d366004613e9b565b6107ee565b6040516102159190614ee0565b34801561029b57600080fd5b506102606102aa366004613e9b565b61097b565b3480156102bb57600080fd5b506102c4610b09565b6040516102159190614502565b3480156102dd57600080fd5b50610260610b19565b3480156102f257600080fd5b50610260610301366004613fde565b610c1f565b34801561031257600080fd5b50610260610321366004613e9b565b610dcc565b34801561033257600080fd5b5061033b610edb565b6040516102159190614321565b34801561035457600080fd5b50610260610363366004613ece565b610eea565b34801561037457600080fd5b50610260610383366004613e67565b611105565b34801561039457600080fd5b506102606103a3366004614155565b611203565b3480156103b457600080fd5b506103bd6112c3565b6040516102159190614f40565b3480156103d657600080fd5b506102606103e5366004613e9b565b6112f0565b3480156103f657600080fd5b50610260610405366004613e9b565b61140c565b34801561041657600080fd5b5061042a610425366004613e27565b611575565b604051610215939291906144a4565b34801561044557600080fd5b5061045961045436600461408e565b6117e0565b604051610215929190614444565b34801561047357600080fd5b50610260610482366004614025565b61183a565b34801561049357600080fd5b506104596119fc565b3480156104a857600080fd5b506102c46104b7366004613d86565b611a29565b3480156104c857600080fd5b506104d1611a3e565b6040516102159190614fc6565b3480156104ea57600080fd5b506104d1611a7e565b3480156104ff57600080fd5b506104d1611a84565b34801561051457600080fd5b50610528610523366004614076565b611ab0565b604051610215919061450d565b34801561054157600080fd5b50610260610550366004613fa1565b611b56565b34801561056157600080fd5b50610260610570366004613ece565b611d01565b34801561058157600080fd5b5061058a611f7a565b6040516102159190614431565b3480156105a357600080fd5b506105ac612052565b6040516102159190614f61565b3480156105c557600080fd5b506102606105d4366004613dbe565b612087565b3480156105e557600080fd5b506102606105f4366004613e9b565b612297565b34801561060557600080fd5b506104d1612491565b610616613a19565b506040805160a081018252600d548152600e546020820152600f5491810191909152601054606082015260115460808201525b90565b610654613a48565b5060408051610160810182526002546001600160a01b039081168252600354811660208301526004548116928201929092526005548216606082015260065482166080820152600754821660a0820152600854821660c0820152600954821660e0820152600a54909116610100820152600b54610120820152600c5461014082015290565b3332146107015760405162461bcd60e51b81526004016106f8906146c9565b60405180910390fd5b610709613aa4565b61073a6016600201546015846040516107229190614295565b908152602001604051809103902060020154846124a3565b9050610767816015846040516107509190614295565b908152602001604051809103902060010154612585565b600061077a82600d6002015460006125e2565b5090506107878282612688565b61079083612760565b60006107a0601660000154612779565b90507f3ef50471c967ac74a1fec015a5fb439eefe1994f80029752c082a26c3133c9328360200151600d6002015484846040516107e09493929190614fe5565b60405180910390a150505050565b6107f6613ad9565b6015826040516108069190614295565b90815260200160405180910390206040518060a0016040529081600082015481526020016001820154815260200160028201548152602001600382018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156108d65780601f106108ab576101008083540402835291602001916108d6565b820191906000526020600020905b8154815290600101906020018083116108b957829003601f168201915b505050918352505060048201805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815293820193929183018282801561096a5780601f1061093f5761010080835404028352916020019161096a565b820191906000526020600020905b81548152906001019060200180831161094d57829003601f168201915b50505050508152505090505b919050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156109ca57600080fd5b505af11580156109de573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a029190613da2565b6001600160a01b0316336001600160a01b031614610a325760405162461bcd60e51b81526004016106f890614639565b601581604051610a429190614295565b90815260405190819003602001902054610a6e5760405162461bcd60e51b81526004016106f890614dc3565b601581604051610a7e9190614295565b90815260405190819003602001902060008082556001820181905560028201819055610aad6003830182613b08565b610abb600483016000613b08565b50610acf9050601a8263ffffffff6127c216565b7fd6acd22a732277ebc5ff0aa733e7c08652f8a2921d88558372cce63e40cfdaae81604051610afe919061450d565b60405180910390a150565b600054600160a01b900460ff1681565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610b6857600080fd5b505af1158015610b7c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ba09190613da2565b6001600160a01b0316336001600160a01b031614610bd05760405162461bcd60e51b81526004016106f890614639565b601b5415610bf05760405162461bcd60e51b81526004016106f890614960565b60405133904780156108fc02916000818181858888f19350505050158015610c1c573d6000803e3d6000fd5b50565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610c6e57600080fd5b505af1158015610c82573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ca69190613da2565b6001600160a01b0316336001600160a01b031614610cd65760405162461bcd60e51b81526004016106f890614639565b601b5415610cf65760405162461bcd60e51b81526004016106f890614960565b80516016819055602080830151601781905560408085015160188190556060808701516019819055835160a081018552600d548152600e5481880152600f548186015260105481840152601154608080830191909152855180850187526012548152601354818a015260145481880152865191820187529881529687019590955292850191909152830152610d8c929091612949565b6016546017546018546019546040517f26bc8aa9f7ec6c447f7831dbe144ee8e1c6ca04e62959e63e5b8002b0b4a5ce194610afe94909390929091614fe5565b333214610deb5760405162461bcd60e51b81526004016106f8906146c9565b33610df581612ad9565b610e115760405162461bcd60e51b81526004016106f890614acd565b610e19613aa4565b610e48601260010154601585604051610e329190614295565b90815260405190819003602001902054856124a3565b9050610e5c81600d60040154601c54612b10565b610e64612b83565b6000610e738260200151612ba5565b9050600080610e828484612c26565b91509150610e9282828589612c7e565b7f6f55209924dba11af5ddabda4999b20d0ce3aa1847c56b67240ed1fc3590c1348460200151848484604051610ecb9493929190614fe5565b60405180910390a1505050505050565b6000546001600160a01b031681565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015610f3957600080fd5b505af1158015610f4d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f719190613da2565b6001600160a01b0316336001600160a01b031614610fa15760405162461bcd60e51b81526004016106f890614639565b601582604051610fb19190614295565b90815260405190819003602001902054610fdd5760405162461bcd60e51b81526004016106f890614dc3565b610fe681612c97565b8051604051601590610ff9908590614295565b90815260200160405180910390206000018190555080604001516015836040516110239190614295565b908152602001604051809103902060020181905550806060015160158360405161104d9190614295565b90815260200160405180910390206003019080519060200190611071929190613b4c565b5080608001516015836040516110879190614295565b908152602001604051809103902060040190805190602001906110ab929190613b4c565b507f53fdf113d6ccd58f1d643ab8402360c17a9d114d055d36c8766e84dfec76a93482826000015183602001518460400151856060015186608001516040516110f996959493929190614520565b60405180910390a15050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561115457600080fd5b505af1158015611168573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061118c9190613da2565b6001600160a01b0316336001600160a01b0316146111bc5760405162461bcd60e51b81526004016106f890614639565b6000805460ff60a01b1916600160a01b83151590810291909117825560405190917f92f8cd47e301bde05ff0abd73cc198632f3ac64fa443a1afc3e47745b3ea1acb91a250565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561125257600080fd5b505af1158015611266573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061128a9190613da2565b6001600160a01b0316336001600160a01b0316146112ba5760405162461bcd60e51b81526004016106f890614639565b610c1c81612cb5565b6112cb613bc6565b5060408051606081018252601254815260135460208201526014549181019190915290565b33321461130f5760405162461bcd60e51b81526004016106f8906146c9565b3361131981612ad9565b6113355760405162461bcd60e51b81526004016106f890614acd565b61133d613aa4565b611356601260010154601585604051610e329190614295565b9050611389816012600201546015866040516113729190614295565b908152602001604051809103902060010154612b10565b611391612d1b565b6000806113a18360200151612d3d565b6113b7576113b183601b54612c26565b90925090505b6113c2828287612d74565b7fbba909c59ebdb6de1c7e9f168dae0e8934434ce708dda9f312d6f3a1d1a502598360200151601b5484846040516113fd9493929190614fe5565b60405180910390a15050505050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561145b57600080fd5b505af115801561146f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114939190613da2565b6001600160a01b0316336001600160a01b0316146114c35760405162461bcd60e51b81526004016106f890614639565b6114cb613aa4565b6114fa6012600101546015846040516114e49190614295565b90815260405190819003602001902054846124a3565b90506000611506612497565b9050600080611517848460006125e2565b91509150818111156115325761152d8483612688565b61153c565b61153c8482612d8f565b7fe7945163803ad02726587e34ca2c4a76ec8dbc6d0b3ddb72d7f93d794e59075984602001518484846040516113fd9493929190614fe5565b6060600080600080611585611a84565b6017549091506000908211156115a25750600f54915060016115c0565b601b54156115b457601b5492506115c0565b6115bd82612ba5565b92505b6115c8613be7565b6115d0612e7b565b90508284118867ffffffffffffffff811180156115ec57600080fd5b50604051908082528060200260200182016040528015611616578160200160208202803683370190505b50975060005b898110156117895761162c613aa4565b6040518060a001604052808581526020018781526020018661165057601354611654565b6018545b8152602001866116a15760158e8e8681811061166c57fe5b905060200281019061167e9190615023565b60405161168c929190614285565b908152604051908190036020019020546116e2565b60158e8e868181106116af57fe5b90506020028101906116c19190615023565b6040516116cf929190614285565b9081526020016040518091039020600201545b81526020018d8d858181106116f357fe5b90506020028101906117059190615023565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201829052509390945250929350915061174c90508289866125e2565b5090508361175a5780611768565b61176881836000015161319b565b8b848151811061177457fe5b6020908102919091010152505060010161161c565b50806117a0576009546001600160a01b03166117ad565b600a546001600160a01b03165b9650806117c557600a546001600160a01b03166117d2565b6009546001600160a01b03165b955050505050509250925092565b606080600d6001015484111580156117fa5750600f548310155b6118165760405162461bcd60e51b81526004016106f890614569565b6000611820611a84565b905061182d8186866131c3565b92509250505b9250929050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b15801561188957600080fd5b505af115801561189d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118c19190613da2565b6001600160a01b0316336001600160a01b0316146118f15760405162461bcd60e51b81526004016106f890614639565b601b54156119115760405162461bcd60e51b81526004016106f890614960565b8051600d819055602080830151600e819055604080850151600f81905560608087015160108190556080808901516011819055855160a0810187529889528888019690965287850193909352868201528582019390935281518084018352601254815260135481860152601454818401528251918201835260165482526017549482019490945260185491810191909152601954918101919091526119b7929190612949565b600d54600e54600f546010546011546040517f69b7cb6b3922c6a0381263018e3350f753caa251b7426259cc918065dc1c45bd95610afe959094909390929091615000565b6060806000611a09611a84565b9050611a2081600d60010154600d600201546131c3565b92509250509091565b60016020526000908152604090205460ff1681565b600080611a49611a84565b6017549091508110611a70576016544711611a645747611a68565b6016545b915050610649565b6000915050610649565b5090565b601c5481565b6000611a8e613be7565b611a96612e7b565b9050611aaa81604001518260600151613467565b91505090565b601a8181548110611abd57fe5b600091825260209182902001805460408051601f6002600019610100600187161502019094169390930492830185900485028101850190915281815293509091830182828015611b4e5780601f10611b2357610100808354040283529160200191611b4e565b820191906000526020600020905b815481529060010190602001808311611b3157829003601f168201915b505050505081565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015611ba557600080fd5b505af1158015611bb9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611bdd9190613da2565b6001600160a01b0316336001600160a01b031614611c0d5760405162461bcd60e51b81526004016106f890614639565b601b5415611c2d5760405162461bcd60e51b81526004016106f890614960565b8051601281905560208083015160138190556040808501516014819055815160a081018352600d548152600e5481860152600f5481840152601054606080830191909152601154608080840191909152845180830186529788528787019590955286840192909252825193840183526016548452601754948401949094526018549183019190915260195490820152611cc69290612949565b6012546014546013546040517fb69986d7b36a79e7024b5654aa4006fbaeb1c553f3a0a8c79990b702fffd5cc693610afe9390929091614fcf565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b158015611d5057600080fd5b505af1158015611d64573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d889190613da2565b6001600160a01b0316336001600160a01b031614611db85760405162461bcd60e51b81526004016106f890614639565b601582604051611dc89190614295565b9081526040519081900360200190205415611df55760405162461bcd60e51b81526004016106f890614b7c565b611dfe81612c97565b8051604051601590611e11908590614295565b9081526020016040518091039020600001819055508060400151601583604051611e3b9190614295565b9081526020016040518091039020600201819055508060600151601583604051611e659190614295565b90815260200160405180910390206003019080519060200190611e89929190613b4c565b508060800151601583604051611e9f9190614295565b90815260200160405180910390206004019080519060200190611ec3929190613b4c565b506000601583604051611ed69190614295565b90815260405160209181900382019020600190810192909255601a805492830181556000528351611f2c927f057c384a7d1c54f3a1b2e5e67b2617b8224fdfd1ea7234eea573a6ff665ff63e0191850190613b4c565b507fd2df566766a30e4280d446b04d14012600df99b449ec4c4afe9201ff36047e5382826000015183602001518460400151856060015186608001516040516110f996959493929190614520565b6060601a805480602002602001604051908101604052809291908181526020016000905b828210156120495760008481526020908190208301805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156120355780601f1061200a57610100808354040283529160200191612035565b820191906000526020600020905b81548152906001019060200180831161201857829003601f168201915b505050505081526020019060010190611f9e565b50505050905090565b61205a613c24565b50604080516080810182526016548152601754602082015260185491810191909152601954606082015290565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156120d657600080fd5b505af11580156120ea573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061210e9190613da2565b6001600160a01b0316336001600160a01b03161461213e5760405162461bcd60e51b81526004016106f890614639565b82811461215d5760405162461bcd60e51b81526004016106f890614663565b8261217a5760405162461bcd60e51b81526004016106f890614bb3565b6121b684848080602002602001604051908101604052809392919081815260200183836020028082843760009201919091525061348992505050565b156121d35760405162461bcd60e51b81526004016106f890614a6e565b60005b838110156122905760008585838181106121ec57fe5b90506020020160208101906122019190613d86565b9050600084848481811061221157fe5b90506020020160208101906122269190613e67565b6001600160a01b03831660008181526001602052604090819020805460ff191684151517905551919250907fbbf89f81f443eef9b97bfd2b7e260c0f575050d4094a0027dcf5d3623d9ef3ad9061227e908490614502565b60405180910390a250506001016121d6565b5050505050565b6000809054906101000a90046001600160a01b03166001600160a01b031663570ca7356040518163ffffffff1660e01b8152600401602060405180830381600087803b1580156122e657600080fd5b505af11580156122fa573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231e9190613da2565b6001600160a01b0316336001600160a01b03161461234e5760405162461bcd60e51b81526004016106f890614639565b612356613be7565b61235e612e7b565b905060008160c00151116123845760405162461bcd60e51b81526004016106f890614ca1565b80516123a25760405162461bcd60e51b81526004016106f890614c6a565b6020810151156123c45760405162461bcd60e51b81526004016106f890614aa5565b6123cc613aa4565b6040518060a001604052808381526020016123e5612497565b815260200160126001015481526020016015856040516124059190614295565b908152602001604051809103902060000154815260200184815250905060008061243683600d6000015460016125e2565b915091506124448383613538565b6124558282600d6000015488612c7e565b6020830151600d546040517fac3b8ab89a07bbb8dd4670bcfe29ef7d4eccea237222f49f997884d89947d53d926113fd92909186908690614fe5565b601b5481565b670de0b6b3a764000090565b6124ab613aa4565b600083116124cb5760405162461bcd60e51b81526004016106f890614cd8565b6124d3613be7565b6124db612e7b565b905060008160c00151116125015760405162461bcd60e51b81526004016106f890614ca1565b805161251f5760405162461bcd60e51b81526004016106f890614c6a565b60008160200151116125435760405162461bcd60e51b81526004016106f890614b45565b600061255782604001518360600151613467565b6040805160a08101825293845260208401919091528201959095526060810193909352506080820152919050565b601754602083015110156125ab5760405162461bcd60e51b81526004016106f890614bea565b60195442906125c190839063ffffffff61362816565b106125de5760405162461bcd60e51b81526004016106f890614d08565b5050565b600080600083612606576020860151612601908663ffffffff61364d16565b61261c565b602086015161261c90869063ffffffff61364d16565b865151602088015191925060009161264c919061264090859063ffffffff61367516565b9063ffffffff61369f16565b9050600061265e8860000151876136bd565b9050600061267961266f8385613823565b8a60600151613823565b99929850919650505050505050565b815160c001516000906126a290839063ffffffff61367516565b905060006126b98285604001518660000151613839565b600254600954600a5460808801516040519495506060946001600160a01b03948516949384169390921691879187916015906126f6908390614295565b908152602001604051809103902060040160405160240161271d979695949392919061438f565b60408051601f198184030181529190526020810180516001600160e01b03166313f74a0f60e21b179052600354909150612290906001600160a01b031682613871565b612769816138d1565b601b5415610c1c576000601b5550565b600080478310612789574761278b565b825b604051909150339082156108fc029083906000818181858888f193505050501580156127bb573d6000803e3d6000fd5b5092915050565b60008061289e84805480602002602001604051908101604052809291908181526020016000905b828210156128945760008481526020908190208301805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156128805780601f1061285557610100808354040283529160200191612880565b820191906000526020600020905b81548152906001019060200180831161286357829003601f168201915b5050505050815260200190600101906127e9565b50505050846138fe565b91509150806128bf5760405162461bcd60e51b81526004016106f8906149ff565b835460001901828114612919578481815481106128d857fe5b906000526020600020018584815481106128ee57fe5b906000526020600020019080546001816001161561010002031660029004612917929190613c4c565b505b8480548061292357fe5b60019003818190600052602060002001600061293f9190613b08565b9055505b50505050565b8251602084015111801590612962575060008360200151115b61297e5760405162461bcd60e51b81526004016106f890614d3f565b8251604084015110156129a35760405162461bcd60e51b81526004016106f890614692565b6129ab612497565b8360600151111580156129c2575060008360600151115b6129de5760405162461bcd60e51b81526004016106f890614c33565b6129e6612497565b82511115612a065760405162461bcd60e51b81526004016106f8906148bf565b612a0e612497565b82602001511115612a315760405162461bcd60e51b81526004016106f890614700565b612a39612497565b81604001511115612a5c5760405162461bcd60e51b81526004016106f890614d76565b826040015181602001511015612a845760405162461bcd60e51b81526004016106f8906149a2565b816040015183608001511015612aac5760405162461bcd60e51b81526004016106f89061476c565b806060015182604001511015612ad45760405162461bcd60e51b81526004016106f89061482b565b505050565b60008054600160a01b900460ff1680612b0a57506001600160a01b03821660009081526001602052604090205460ff165b92915050565b601754602084015110612b355760405162461bcd60e51b81526004016106f8906145a0565b81612b46428363ffffffff61364d16565b1180612b575750600f546020840151115b80612b675750600e546020840151105b612ad45760405162461bcd60e51b81526004016106f8906145e9565b601b5415612ba35760405162461bcd60e51b81526004016106f890614900565b565b601054600d546000918291612bbf9163ffffffff61369f16565b90506000612be484612640600d60030154612bd8612497565b9063ffffffff61364d16565b90506000612bf8838363ffffffff61362816565b90506000612c0b82600d60020154613823565b9050612c1c600d600101548261395d565b9695505050505050565b6000806000808560200151851015612c5857612c44868660006125e2565b9092509050612c538683612688565b612c73565b612c64868660016125e2565b9092509050612c738683613538565b909590945092505050565b612c87816138d1565b828410156129435750601b555050565b8051610c1c5760405162461bcd60e51b81526004016106f890614b04565b600254604051606091612cd8916001600160a01b03909116908490602401614415565b60408051601f198184030181529190526020810180516001600160e01b031663d9b210d360e01b1790526003549091506125de906001600160a01b031682613871565b6000601b5411612ba35760405162461bcd60e51b81526004016106f8906147c9565b6000600d60000154601b54108015612d575750601b548210155b80612b0a5750600d54601b54118015612b0a575050601b54101590565b612d7d816138d1565b81831415612ad4576000601b55505050565b6000612dd6836000015160c00151612dca612dbd601260010154612db1612497565b9063ffffffff61362816565b859063ffffffff61369f16565b9063ffffffff61367516565b600254600954600a5460808701516040519495506060946001600160a01b03948516949384169390921691869190601590612e12908390614295565b9081526020016040518091039020600401604051602401612e3896959493929190614335565b60408051601f198184030181529190526020810180516001600160e01b031663d4fd27eb60e01b179052600354909150612943906001600160a01b031682613871565b612e83613be7565b612e8b613be7565b600554604080516350d25bcd60e01b815290516000926001600160a01b0316916350d25bcd916004808301926020929190829003018186803b158015612ed057600080fd5b505afa158015612ee4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f089190613e83565b9050612f2b600260090154600a0a612f1f8361396d565b9063ffffffff61398f16565b6080830152600654604080516350d25bcd60e01b815290516000926001600160a01b0316916350d25bcd916004828101926020929190829003018186803b158015612f7557600080fd5b505afa158015612f89573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612fad9190613e83565b9050612fc46002600a0154600a0a612f1f8361396d565b60a08401526007546002546040516370a0823160e01b81526001600160a01b03928316926370a0823192612ffd92911690600401614321565b60206040518083038186803b15801561301557600080fd5b505afa158015613029573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061304d9190613e83565b83526008546002546040516370a0823160e01b81526001600160a01b03928316926370a082319261308392911690600401614321565b60206040518083038186803b15801561309b57600080fd5b505afa1580156130af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130d39190613e83565b6020840152825160808401516130ee9163ffffffff61369f16565b6040840152602083015160a084015161310c9163ffffffff61369f16565b6060840152600254604080516318160ddd60e01b815290516001600160a01b03909216916318160ddd91600480820192602092909190829003018186803b15801561315657600080fd5b505afa15801561316a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061318e9190613e83565b60c0840152509091505090565b60006131bc8260a00151612dca84608001518661369f90919063ffffffff16565b9392505050565b6060806060601a8054905067ffffffffffffffff811180156131e457600080fd5b5060405190808252806020026020018201604052801561320e578160200160208202803683370190505b50905060005b601a5481101561338457600082828151811061322c57fe5b6020026020010190600381111561323f57fe5b9081600381111561324c57fe5b90525060175487106132e457426132a76016600301546015601a858154811061327157fe5b9060005260206000200160405161328891906142b1565b908152604051908190036020019020600101549063ffffffff61362816565b10156132df5760038282815181106132bb57fe5b602002602001019060038111156132ce57fe5b908160038111156132db57fe5b9052505b61337c565b601b541561331957426133056012600201546015601a858154811061327157fe5b10156132df5760028282815181106132bb57fe5b601154601c5461333090429063ffffffff61364d16565b118061333b57508487115b8061334557508587105b1561337c57600182828151811061335857fe5b6020026020010190600381111561336b57fe5b9081600381111561337857fe5b9052505b600101613214565b50601a8181805480602002602001604051908101604052809291908181526020016000905b828210156134545760008481526020908190208301805460408051601f60026000196101006001871615020190941693909304928301859004850281018501909152818152928301828280156134405780601f1061341557610100808354040283529160200191613440565b820191906000526020600020905b81548152906001019060200180831161342357829003601f168201915b5050505050815260200190600101906133a9565b5050505091509250925050935093915050565b60006131bc61347c848463ffffffff61364d16565b849063ffffffff61367516565b6000808251116134ab5760405162461bcd60e51b81526004016106f890614df1565b60005b600183510381101561352f5760008382815181106134c857fe5b6020026020010151905060008260010190505b8451811015613525578481815181106134f057fe5b60200260200101516001600160a01b0316826001600160a01b0316141561351d5760019350505050610976565b6001016134db565b50506001016134ae565b50600092915050565b815160c0015160009061355290839063ffffffff61367516565b9050600061356482856000015161319b565b905060006135768386604001516139c9565b600254600a5460095460808901516040519495506060946001600160a01b03948516949384169390921691879187916015906135b3908390614295565b90815260200160405180910390206003016040516024016135da979695949392919061438f565b60408051601f198184030181529190526020810180516001600160e01b0316600162114b6960e21b0319179052600354909150613620906001600160a01b031682613871565b505050505050565b6000828201838110156131bc5760405162461bcd60e51b81526004016106f890614735565b60008282111561366f5760405162461bcd60e51b81526004016106f8906147f4565b50900390565b60006131bc8261369385670de0b6b3a764000063ffffffff61398f16565b9063ffffffff6139e716565b60006131bc670de0b6b3a7640000613693858563ffffffff61398f16565b60048054600954604051633e15014160e01b8152600093849384936001600160a01b0391821693633e150141936136f8939092169101614321565b6101406040518083038186803b15801561371157600080fd5b505afa158015613725573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061374991906140af565b50505050505050925092505083156137c657600061379b613771601260000154612bd8612497565b61264061378a86655af3107a400063ffffffff61398f16565b60408a01519063ffffffff61369f16565b90506137bc8660800151612dca88606001518461364d90919063ffffffff16565b9350505050612b0a565b60006137f56137dc601260000154612bd8612497565b61264061378a85655af3107a400063ffffffff61398f16565b90506137bc81612dca61381589606001518561364d90919063ffffffff16565b89519063ffffffff61369f16565b600081831061383257816131bc565b5090919050565b600061386961384a84612bd8612497565b6126408460a00151612dca86608001518961369f90919063ffffffff16565b949350505050565b600054604051634cf4f63b60e01b81526001600160a01b0390911690634cf4f63b906138a390859085906004016143f1565b600060405180830381600087803b1580156138bd57600080fd5b505af1158015613620573d6000803e3d6000fd5b42601c8190556040516015906138e8908490614295565b9081526040519081900360200190206001015550565b81516000908190815b8181101561394d57848051906020012086828151811061392357fe5b6020026020010151805190602001201415613945579250600191506118339050565b600101613907565b5060001995600095509350505050565b60008183101561383257816131bc565b600080821215611a7a5760405162461bcd60e51b81526004016106f89061492b565b60008261399e57506000612b0a565b828202828482816139ab57fe5b04146131bc5760405162461bcd60e51b81526004016106f890614a2d565b60006131bc6139da83612bd8612497565b849063ffffffff61369f16565b6000808211613a085760405162461bcd60e51b81526004016106f890614888565b818381613a1157fe5b049392505050565b6040518060a0016040528060008152602001600081526020016000815260200160008152602001600081525090565b6040805161016081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810182905261014081019190915290565b6040518060a00160405280613ab7613be7565b8152602001600081526020016000815260200160008152602001606081525090565b6040518060a0016040528060008152602001600081526020016000815260200160608152602001606081525090565b50805460018160011615610100020316600290046000825580601f10613b2e5750610c1c565b601f016020900490600052602060002090810190610c1c9190613cc1565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10613b8d57805160ff1916838001178555613bba565b82800160010185558215613bba579182015b82811115613bba578251825591602001919060010190613b9f565b50611a7a929150613cc1565b60405180606001604052806000815260200160008152602001600081525090565b6040518060e00160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081525090565b6040518060800160405280600081526020016000815260200160008152602001600081525090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10613c855780548555613bba565b82800160010185558215613bba57600052602060002091601f016020900482015b82811115613bba578254825591600101919060010190613ca6565b61064991905b80821115611a7a5760008155600101613cc7565b60008083601f840112613cec578182fd5b50813567ffffffffffffffff811115613d03578182fd5b602083019150836020808302850101111561183357600080fd5b600082601f830112613d2d578081fd5b813567ffffffffffffffff811115613d43578182fd5b613d56601f8201601f191660200161506a565b9150808252836020828501011115613d6d57600080fd5b8060208401602084013760009082016020015292915050565b600060208284031215613d97578081fd5b81356131bc816150c9565b600060208284031215613db3578081fd5b81516131bc816150c9565b60008060008060408587031215613dd3578283fd5b843567ffffffffffffffff80821115613dea578485fd5b613df688838901613cdb565b90965094506020870135915080821115613e0e578384fd5b50613e1b87828801613cdb565b95989497509550505050565b60008060208385031215613e39578182fd5b823567ffffffffffffffff811115613e4f578283fd5b613e5b85828601613cdb565b90969095509350505050565b600060208284031215613e78578081fd5b81356131bc816150de565b600060208284031215613e94578081fd5b5051919050565b600060208284031215613eac578081fd5b813567ffffffffffffffff811115613ec2578182fd5b61386984828501613d1d565b60008060408385031215613ee0578081fd5b823567ffffffffffffffff80821115613ef7578283fd5b613f0386838701613d1d565b93506020850135915080821115613f18578283fd5b81850160a08188031215613f2a578384fd5b613f3460a061506a565b9250803583526020810135602084015260408101356040840152606081013582811115613f5f578485fd5b613f6b88828401613d1d565b606085015250608081013582811115613f82578485fd5b613f8e88828401613d1d565b6080850152505050809150509250929050565b600060608284031215613fb2578081fd5b613fbc606061506a565b8235815260208301356020820152604083013560408201528091505092915050565b600060808284031215613fef578081fd5b613ff9608061506a565b823581526020830135602082015260408301356040820152606083013560608201528091505092915050565b600060a08284031215614036578081fd5b61404060a061506a565b82358152602083013560208201526040830135604082015260608301356060820152608083013560808201528091505092915050565b600060208284031215614087578081fd5b5035919050565b600080604083850312156140a0578182fd5b50508035926020909101359150565b6000806000806000806000806000806101408b8d0312156140ce578788fd5b8a51995060208b0151985060408b0151975060608b0151965060808b0151955060a08b01516140fc816150de565b60c08c015190955061410d816150de565b60e08c015190945061411e816150de565b6101008c0151909350614130816150de565b6101208c0151909250614142816150de565b809150509295989b9194979a5092959850565b600060208284031215614166578081fd5b813560ff811681146131bc578182fd5b6001600160a01b03169052565b6000815180845260208085018081965082840281019150828601855b858110156141c95782840389526141b78483516141d6565b9885019893509084019060010161419f565b5091979650505050505050565b600081518084526141ee81602086016020860161509d565b601f01601f19169290920160200192915050565b60008154600180821660008114614220576001811461423e5761427c565b60028304607f16865260ff198316602087015260408601935061427c565b6002830480875261424e86615091565b60005b828110156142725781546020828b0101528482019150602081019050614251565b8801602001955050505b50505092915050565b6000828483379101908152919050565b600082516142a781846020870161509d565b9190910192915050565b60008083546001808216600081146142d057600181146142e757614316565b60ff198316865260028304607f1686019350614316565b600283048786526020808720875b8381101561430e5781548a8201529085019082016142f5565b505050860193505b509195945050505050565b6001600160a01b0391909116815260200190565b6001600160a01b0387811682528681166020830152851660408201526060810184905260c060808201819052600090614370908301856141d6565b82810360a08401526143828185614202565b9998505050505050505050565b6001600160a01b038881168252878116602083015286166040820152606081018590526080810184905260e060a082018190526000906143d1908301856141d6565b82810360c08401526143e38185614202565b9a9950505050505050505050565b6001600160a01b0383168152604060208201819052600090613869908301846141d6565b6001600160a01b0392909216825260ff16602082015260400190565b6000602082526131bc6020830184614183565b6000604082526144576040830185614183565b828103602084810191909152845180835285820192820190845b818110156144975784516004811061448557fe5b83529383019391830191600101614471565b5090979650505050505050565b606080825284519082018190526000906020906080840190828801845b828110156144dd578151845292840192908401906001016144c1565b5050506001600160a01b03958616918401919091529290931660409091015292915050565b901515815260200190565b6000602082526131bc60208301846141d6565b600060c0825261453360c08301896141d6565b876020840152866040840152856060840152828103608084015261455781866141d6565b83810360a08501526143e381866141d6565b6020808252601b908201527f437573746f6d20626f756e6473206d7573742062652076616c69640000000000604082015260600190565b60208082526029908201527f4d7573742062652062656c6f7720696e63656e746976697a6564206c6576657260408201526861676520726174696f60b81b606082015260800190565b60208082526030908201527f436f6f6c646f776e206e6f7420656c6170736564206f72206e6f742076616c6960408201526f64206c6576657261676520726174696f60801b606082015260800190565b60208082526010908201526f26bab9ba1031329037b832b930ba37b960811b604082015260600190565b602080825260159082015274082e4e4c2f240d8cadccee8d040dad2e6dac2e8c6d605b1b604082015260600190565b6020808252601a908201527f4d7573742062652076616c6964206d6178206c65766572616765000000000000604082015260600190565b6020808252601a908201527f43616c6c6572206d75737420626520454f412041646472657373000000000000604082015260600190565b6020808252818101527f536c69707061676520746f6c6572616e6365206d757374206265203c31303025604082015260600190565b6020808252601b908201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604082015260600190565b6020808252603c908201527f526562616c616e636520696e74657276616c206d75737420626520677265617460408201527f6572207468616e205457415020636f6f6c646f776e20706572696f6400000000606082015260800190565b6020808252601190820152704e6f7420696e205457415020737461746560781b604082015260600190565b6020808252601e908201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604082015260600190565b6020808252603d908201527f5457415020636f6f6c646f776e206d757374206265206772656174657220746860408201527f616e20696e63656e746976697a6564205457415020636f6f6c646f776e000000606082015260800190565b6020808252601a908201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604082015260600190565b60208082526021908201527f556e7574696c697a6564206c65766572616765206d757374206265203c3130306040820152602560f81b606082015260800190565b6020808252601190820152704d7573742063616c6c206974657261746560781b604082015260600190565b6020808252818101527f53616665436173743a2076616c7565206d75737420626520706f736974697665604082015260600190565b60208082526022908201527f526562616c616e63652069732063757272656e746c7920696e2070726f677265604082015261737360f01b606082015260800190565b60208082526038908201527f496e63656e746976697a6564206c6576657261676520726174696f206d75737460408201527f206265203e206d6178206c6576657261676520726174696f0000000000000000606082015260800190565b60208082526014908201527329ba3934b733903737ba1034b71030b93930bc9760611b604082015260600190565b60208082526021908201527f536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f6040820152607760f81b606082015260800190565b60208082526018908201527f43616e6e6f74206475706c69636174652063616c6c6572730000000000000000604082015260600190565b6020808252600e908201526d044656274206d75737420626520360941b604082015260600190565b6020808252601d908201527f41646472657373206e6f74207065726d697474656420746f2063616c6c000000604082015260600190565b60208082526021908201527f4d617820545741502074726164652073697a65206d757374206e6f74206265206040820152600360fc1b606082015260800190565b60208082526019908201527f426f72726f772062616c616e6365206d75737420657869737400000000000000604082015260600190565b60208082526018908201527f45786368616e676520616c726561647920656e61626c65640000000000000000604082015260600190565b60208082526018908201527f4172726179206c656e677468206d757374206265203e20300000000000000000604082015260600190565b60208082526029908201527f4d7573742062652061626f766520696e63656e746976697a6564206c6576657260408201526861676520726174696f60b81b606082015260800190565b6020808252601f908201527f4d7573742062652076616c696420726563656e746572696e6720737065656400604082015260600190565b6020808252601e908201527f436f6c6c61746572616c2062616c616e6365206d757374206265203e20300000604082015260600190565b6020808252601d908201527f536574546f6b656e206d7573742068617665203e203020737570706c79000000604082015260600190565b6020808252601690820152754d7573742062652076616c69642065786368616e676560501b604082015260600190565b6020808252601f908201527f5457415020636f6f6c646f776e206d757374206861766520656c617073656400604082015260600190565b6020808252601a908201527f4d7573742062652076616c6964206d696e206c65766572616765000000000000604082015260600190565b6020808252602d908201527f496e63656e746976697a656420736c69707061676520746f6c6572616e63652060408201526c6d757374206265203c3130302560981b606082015260800190565b602080825260149082015273115e18da185b99d9481b9bdd08195b98589b195960621b604082015260600190565b6020808252600a90820152694120697320656d70747960b01b604082015260600190565b600061016082019050614e29828451614176565b6020830151614e3b6020840182614176565b506040830151614e4e6040840182614176565b506060830151614e616060840182614176565b506080830151614e746080840182614176565b5060a0830151614e8760a0840182614176565b5060c0830151614e9a60c0840182614176565b5060e0830151614ead60e0840182614176565b5061010080840151614ec182850182614176565b5050610120838101519083015261014092830151929091019190915290565b600060208252825160208301526020830151604083015260408301516060830152606083015160a06080840152614f1a60c08401826141d6565b6080850151848203601f190160a08601529150614f3781836141d6565b95945050505050565b81518152602080830151908201526040918201519181019190915260600190565b8151815260208083015190820152604080830151908201526060918201519181019190915260800190565b600060a082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015292915050565b90815260200190565b9283526020830191909152604082015260600190565b93845260208401929092526040830152606082015260800190565b948552602085019390935260408401919091526060830152608082015260a00190565b6000808335601e19843603018112615039578283fd5b8084018035925067ffffffffffffffff831115615054578384fd5b6020019250503681900382131561183357600080fd5b60405181810167ffffffffffffffff8111828210171561508957600080fd5b604052919050565b60009081526020902090565b60005b838110156150b85781810151838201526020016150a0565b838111156129435750506000910152565b6001600160a01b0381168114610c1c57600080fd5b8015158114610c1c57600080fdfea2646970667358221220aad1b3603fa967ded38c752d386579709038f2fdaf54e96ec77c7c545f22c2b564736f6c634300060a0033

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

000000000000000000000000a7d11fa4b1ae979d2f8850aa33799a0bad253907000000000000000000000000e8888cdbc0a5958c29e7d91dae44897c7e64f9bc00000000000000000000000071e932715f5987077adc5a7aa245f38841e0dcbe0000000000000000000000007b4eb56e7cd4b454ba8ff71e4518426369a138a3000000000000000000000000536218f9e9eb48863970252233c8f271f554c2d00000000000000000000000008fffffd4afb6115b954bd326cbe7b4ba576818f6000000000000000000000000cc9ee9483f662091a1de4795249e24ac0ac2630f000000000000000000000000ea51d7853eefb32b6ee06b1c12e6dcca88be0ffe000000000000000000000000ae78736cd615f374d3085123a210448e74fc6393000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000006f05b59d3b2000000000000000000000000000000000000000000000000000006124fee993bc000000000000000000000000000000000000000000000000000075f610f70ed200000000000000000000000000000000000000000000000000000de0b6b3a7640000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000008e1bc9bf04000000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000083d6c7aab63600000000000000000000000000000000000000000000000000000011c37937e080000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001942616c616e636572563245786368616e676541646170746572000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000003635c9adc5dea0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000878678326eac90000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000201e19cf2d73a72ef1332c882f20534b6519be027600020000000000000000011200000000000000000000000000000000000000000000000000000000000000201e19cf2d73a72ef1332c882f20534b6519be0276000200000000000000000112

-----Decoded View---------------
Arg [0] : _manager (address): 0xA7d11fa4b1AE979D2f8850aA33799a0bAd253907
Arg [1] : _strategy (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [2] : _methodology (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [3] : _execution (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [4] : _incentive (tuple): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]
Arg [5] : _exchangeNames (string[]): BalancerV2ExchangeAdapter
Arg [6] : _exchangeSettings (tuple[]): System.Collections.Generic.List`1[Nethereum.ABI.FunctionEncoding.ParameterOutput]

-----Encoded View---------------
41 Constructor Arguments found :
Arg [0] : 000000000000000000000000a7d11fa4b1ae979d2f8850aa33799a0bad253907
Arg [1] : 000000000000000000000000e8888cdbc0a5958c29e7d91dae44897c7e64f9bc
Arg [2] : 00000000000000000000000071e932715f5987077adc5a7aa245f38841e0dcbe
Arg [3] : 0000000000000000000000007b4eb56e7cd4b454ba8ff71e4518426369a138a3
Arg [4] : 000000000000000000000000536218f9e9eb48863970252233c8f271f554c2d0
Arg [5] : 0000000000000000000000008fffffd4afb6115b954bd326cbe7b4ba576818f6
Arg [6] : 000000000000000000000000cc9ee9483f662091a1de4795249e24ac0ac2630f
Arg [7] : 000000000000000000000000ea51d7853eefb32b6ee06b1c12e6dcca88be0ffe
Arg [8] : 000000000000000000000000ae78736cd615f374d3085123a210448e74fc6393
Arg [9] : 000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
Arg [10] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [11] : 000000000000000000000000000000000000000000000000000000000000000a
Arg [12] : 0000000000000000000000000000000000000000000000006f05b59d3b200000
Arg [13] : 0000000000000000000000000000000000000000000000006124fee993bc0000
Arg [14] : 00000000000000000000000000000000000000000000000075f610f70ed20000
Arg [15] : 0000000000000000000000000000000000000000000000000de0b6b3a7640000
Arg [16] : ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
Arg [17] : 000000000000000000000000000000000000000000000000002386f26fc10000
Arg [18] : 0000000000000000000000000000000000000000000000000008e1bc9bf04000
Arg [19] : 000000000000000000000000000000000000000000000000000000000000001e
Arg [20] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [21] : 00000000000000000000000000000000000000000000000083d6c7aab6360000
Arg [22] : 0000000000000000000000000000000000000000000000000011c37937e08000
Arg [23] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [24] : 0000000000000000000000000000000000000000000000000000000000000340
Arg [25] : 00000000000000000000000000000000000000000000000000000000000003c0
Arg [26] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [27] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [28] : 0000000000000000000000000000000000000000000000000000000000000019
Arg [29] : 42616c616e636572563245786368616e67654164617074657200000000000000
Arg [30] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [31] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [32] : 00000000000000000000000000000000000000000000003635c9adc5dea00000
Arg [33] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [34] : 0000000000000000000000000000000000000000000000878678326eac900000
Arg [35] : 00000000000000000000000000000000000000000000000000000000000000a0
Arg [36] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [37] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [38] : 1e19cf2d73a72ef1332c882f20534b6519be0276000200000000000000000112
Arg [39] : 0000000000000000000000000000000000000000000000000000000000000020
Arg [40] : 1e19cf2d73a72ef1332c882f20534b6519be0276000200000000000000000112


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.