Contract 0x8369a8ece09312166096e59cdf7451ffa7899701 1

Txn Hash Method
Block
From
To
Value [Txn Fee]
0xdd8c3922f450d7b399ca4b5a7f6647fe189c3d118b77dda7861de35609e916ba0x615cbf61225015912023-06-01 0:52:59301 days 9 hrs ago0xf8e8cc9607bd51f16cecc022775da879447e1fe5 IN  Create: ElkFactoryHelperPermissioned0 BTT2,581.3705
[ Download CSV Export 
Parent Txn Hash Block From To Value
Index Block
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ElkFactoryHelperPermissioned

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 300 runs

Other Settings:
default evmVersion, BSL 1.1 license

Contract Source Code (Solidity)

/**
 *Submitted for verification at bttcscan.com on 2023-06-01
*/

// SPDX-License-Identifier: BUSL-1.1
//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>
// - Elijah <[email protected]>
// - Snake <[email protected]>

// File: @openzeppelin/[email protected]/utils/Address.sol


// OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @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
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 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");

        (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 functionCallWithValue(target, data, 0, "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");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, 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) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // 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
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

// File: @openzeppelin/[email protected]/token/ERC20/extensions/draft-IERC20Permit.sol


// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

// File: @openzeppelin/[email protected]/security/ReentrancyGuard.sol


// OpenZeppelin Contracts (last updated v4.8.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

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

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

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

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

// File: @openzeppelin/[email protected]/utils/Context.sol


// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

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

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

// File: @openzeppelin/[email protected]/access/Ownable.sol


// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;


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

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

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

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

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

// File: contracts/interfaces/IElkPair.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>

pragma solidity >=0.5.0;

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

    function name() external pure returns (string memory);

    function symbol() external pure returns (string memory);

    function decimals() external pure returns (uint8);

    function totalSupply() external view returns (uint);

    function balanceOf(address _owner) external view returns (uint);

    function allowance(
        address _owner,
        address _spender
    ) external view returns (uint);

    function approve(address _spender, uint _value) external returns (bool);

    function transfer(address _to, uint _value) external returns (bool);

    function transferFrom(
        address _from,
        address _to,
        uint _value
    ) external returns (bool);

    function DOMAIN_SEPARATOR() external view returns (bytes32);

    function PERMIT_TYPEHASH() external pure returns (bytes32);

    function nonces(address _owner) external view returns (uint);

    function permit(
        address _owner,
        address _spender,
        uint _value,
        uint _deadline,
        uint8 _v,
        bytes32 _r,
        bytes32 _s
    ) external;

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

    function MINIMUM_LIQUIDITY() external pure returns (uint);

    function factory() external view returns (address);

    function token0() external view returns (address);

    function token1() external view returns (address);

    function getReserves()
        external
        view
        returns (
            uint112 _reserve0,
            uint112 _reserve1,
            uint32 _blockTimestampLast
        );

    function price0CumulativeLast() external view returns (uint);

    function price1CumulativeLast() external view returns (uint);

    function kLast() external view returns (uint);

    function mint(address _to) external returns (uint liquidity);

    function burn(address _to) external returns (uint amount0, uint amount1);

    function swap(
        uint _amount0Out,
        uint _amount1Out,
        address _to,
        bytes calldata _data
    ) external;

    function skim(address _to) external;

    function sync() external;

    function initialize(address, address) external;
}

// File: contracts/interfaces/IElkDexOracle.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>

pragma solidity >=0.8.0;

interface IElkDexOracle {
    struct Observation {
        uint timestamp;
        uint price0Cumulative;
        uint price1Cumulative;
    }

    function weth() external view returns (address);

    function factory() external view returns (address);

    function windowSize() external view returns (uint);

    function granularity() external view returns (uint8);

    function periodSize() external view returns (uint);

    function pairObservations(
        address _pair
    ) external view returns (Observation[] memory);

    function observationIndexOf(uint _timestamp) external view returns (uint);

    function update(address _tokenA, address _tokenB) external;

    function updateWeth(address _token) external;

    function consult(
        address _tokenIn,
        uint _amountIn,
        address _tokenOut
    ) external view returns (uint);

    function consultWeth(
        address _tokenIn,
        uint _amountIn
    ) external view returns (uint);
}

// File: @openzeppelin/[email protected]/token/ERC20/IERC20.sol


// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @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);

    /**
     * @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 `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, 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 `from` to `to` 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 from,
        address to,
        uint256 amount
    ) external returns (bool);
}

// File: @openzeppelin/[email protected]/token/ERC20/extensions/IERC20Metadata.sol


// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;


/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// File: @openzeppelin/[email protected]/token/ERC20/ERC20.sol


// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;




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

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * The default value of {decimals} is 18. To select a different value for
     * {decimals} you should overload it.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

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

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

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

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

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

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

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

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `amount`.
     */
    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual override returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, amount);
        _transfer(from, to, amount);
        return true;
    }

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

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

        return true;
    }

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

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

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

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

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

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

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

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

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

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

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `amount`.
     *
     * Does not update the allowance amount in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Might emit an {Approval} event.
     */
    function _spendAllowance(
        address owner,
        address spender,
        uint256 amount
    ) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            require(currentAllowance >= amount, "ERC20: insufficient allowance");
            unchecked {
                _approve(owner, spender, currentAllowance - amount);
            }
        }
    }

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

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

// File: @openzeppelin/[email protected]/token/ERC20/utils/SafeERC20.sol


// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;




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

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

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

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

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

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

    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

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

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

// File: contracts/interfaces/IStaking.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>

pragma solidity >=0.8.0;


interface IStaking {
    /* ========== STATE VARIABLES ========== */
    function stakingToken() external returns (IERC20);

    function totalSupply() external returns (uint256);

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

    /* ========== MUTATIVE FUNCTIONS ========== */
    function stake(uint256 _amount) external;

    function withdraw(uint256 _amount) external;

    function exit() external;

    function recoverERC20(
        address _tokenAddress,
        address _recipient,
        uint256 _amount
    ) external;

    /* ========== EVENTS ========== */

    // Emitted on staking
    event Staked(address indexed account, uint256 amount);

    // Emitted on withdrawal (including exit)
    event Withdrawn(address indexed account, uint256 amount);

    // Emitted on token recovery
    event Recovered(
        address indexed token,
        address indexed recipient,
        uint256 amount
    );
}

// File: contracts/Staking.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>
// - Elijah <[email protected]>
// - Snake <[email protected]>

pragma solidity >=0.8.0;






/**
 * Base contract implementing simple ERC20 token staking functionality (no staking rewards).
 */
contract Staking is ReentrancyGuard, Ownable, IStaking {
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */

    /// @notice Staking token interface
    IERC20 public immutable stakingToken;

    /// @notice Total supply of the staking token
    uint256 public totalSupply;

    /// @notice Account balances
    mapping(address => uint256) public balances;

    // Scaling factor: supply is always stored as wei (10**18) regardless of the token's decimals
    uint256 private supplyScalingFactor;

    /* ========== CONSTRUCTOR ========== */

    /// @param _stakingTokenAddress address of the token used for staking (must be ERC20)
    constructor(address _stakingTokenAddress) {
        require(_stakingTokenAddress != address(0), "E1");
        stakingToken = IERC20(_stakingTokenAddress);
        supplyScalingFactor = 1e18 / 10**ERC20(_stakingTokenAddress).decimals();
    }

    /**
     * @dev Stake tokens.
     * Note: the contract must have sufficient allowance for the staking token.
     * @param _amount amount to stake
     */
    function stake(uint256 _amount) public nonReentrant {
        uint256 originalAmount = _amount;
        _amount = _beforeStake(msg.sender, _amount);
        require(_amount > 0 && originalAmount > 0, "E2"); // Check after the hook
        totalSupply += _amount * supplyScalingFactor;
        balances[msg.sender] += _amount;
        stakingToken.safeTransferFrom(msg.sender, address(this), originalAmount);
        emit Staked(msg.sender, _amount);
    }

    /**
     * @dev Withdraw previously staked tokens.
     * @param _amount amount to withdraw
     */
    function withdraw(uint256 _amount) public nonReentrant {
        uint256 originalAmount = _amount;
        _amount = _beforeWithdraw(msg.sender, _amount);
        require(
            _amount > 0 && _amount <= balances[msg.sender] && originalAmount <= balances[msg.sender],
            "E3"
        ); // Check after the hook
        totalSupply -= originalAmount * supplyScalingFactor;
        balances[msg.sender] -= originalAmount;
        stakingToken.safeTransfer(msg.sender, _amount);
        emit Withdrawn(msg.sender, _amount);
    }

    /**
     * @dev Exit the farm, i.e., withdraw the entire token balance of the calling account
     */
    function exit() external {
        _beforeExit(msg.sender);
        withdraw(balances[msg.sender]);
    }

    /* ========== RESTRICTED FUNCTIONS ========== */

    /**
     * @dev Recover ERC20 tokens held in the contract.
     * Note: privileged governance function to recover tokens mistakenly sent to this contract address.
     * This function cannot be used to withdraw staking tokens.
     * @param _tokenAddress address of the token to recover
     * @param _recipient recovery address
     * @param _amount amount to withdraw
     * @ return withdrawn amount (may differ from input amount due to e.g., fees)
     */
    function recoverERC20(
        address _tokenAddress,
        address _recipient,
        uint256 _amount
    ) external nonReentrant onlyOwner {
        require(
            _tokenAddress != address(stakingToken),
            "E4"
        );
        _beforeRecoverERC20(_tokenAddress, _recipient, _amount);
        IERC20 token = IERC20(_tokenAddress);
        token.safeTransfer(_recipient, _amount);
        emit Recovered(_tokenAddress, _recipient, _amount);
    }

    /* ========== HOOKS ========== */

    /**
     * @dev Internal hook called before staking (in the stake() function).
     * @ param _account staker address
     * @param _amount amount being staken
     * @return amount to stake (may be changed by the hook)
     */
    function _beforeStake(
        address /*_account*/,
        uint256 _amount
    ) internal virtual returns (uint256) {
        return _amount;
    }

    /**
     * @dev Internal hook called before withdrawing (in the withdraw() function).
     * @ param _account withdrawer address
     * @param _amount amount being withdrawn
     * @return amount to withdraw (may be changed by the hook)
     */
    function _beforeWithdraw(
        address /*_account*/,
        uint256 _amount
    ) internal virtual returns (uint256) {
        return _amount;
    }

    /**
     * @dev Internal hook called before exiting (in the exit() function).
     * Note: since exit() calls withdraw() internally, the _beforeWithdraw() hook fill fire too.
     * @param _account address exiting
     */
    function _beforeExit(address _account) internal virtual {}

    /**
     * @dev Internal hook called before recovering tokens (in the recoverERC20() function).
     * @param _tokenAddress address of the token being recovered
     * @param _recipient recovery address
     * @param _amount amount being withdrawn
     */
    function _beforeRecoverERC20(
        address _tokenAddress,
        address _recipient,
        uint256 _amount
    ) internal virtual {}
}

// File: contracts/interfaces/IStakingFee.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>

pragma solidity >=0.8.0;


interface IStakingFee is IStaking {
    /* ========== STATE VARIABLES ========== */
    function feesUnit() external returns (uint256);

    function maxFee() external returns (uint256);

    function withdrawalFeeSchedule(uint256) external returns (uint256);

    function withdrawalFeesBps(uint256) external returns (uint256);

    function depositFeeBps() external returns (uint256);

    function collectedFees() external returns (uint256);

    function userLastStakedTime(address _user) external view returns (uint32);

    /* ========== VIEWS ========== */

    function depositFee(uint256 _depositAmount) external view returns (uint256);

    function withdrawalFee(
        address _account,
        uint256 _withdrawalAmount
    ) external view returns (uint256);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function recoverFees(address _recipient) external;
    
    /* ========== EVENTS ========== */

    // Emitted when fees are (re)configured
    event FeesSet(
        uint16 _depositFeeBps,
        uint16[] _withdrawalFeesBps,
        uint32[] _feeSchedule
    );

    // Emitted when a deposit fee is collected
    event DepositFeesCollected(address indexed _user, uint256 _amount);

    // Emitted when a withdrawal fee is collected
    event WithdrawalFeesCollected(address indexed _user, uint256 _amount);

    // Emitted when fees are recovered by governance
    event FeesRecovered(uint256 _amount);
}

// File: contracts/StakingFee.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>
// - Elijah <[email protected]>
// - Snake <[email protected]>

pragma solidity >=0.8.0;



/**
 * Contract implementing simple ERC20 token staking functionality and supporting deposit/withdrawal fees (no staking rewards).
 */
contract StakingFee is Staking, IStakingFee {
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */

    /// @notice Constant Fee Unit (1e4)
    uint256 public constant feesUnit = 10000;

    /// @notice Maximum fee (20%)
    uint256 public constant maxFee = 2000;

    /// @notice Schedule of withdrawal fees represented as a sorted array of durations
    /// @dev example: 10% after 1 hour, 1% after a day, 0% after a week => [3600, 86400]
    uint256[] public withdrawalFeeSchedule;

    /// @notice Withdrawal fees described in basis points (fee unit) represented as an array of the same length as withdrawalFeeSchedule
    /// @dev example: 10% after 1 hour, 1% after a day, 0% after a week => [1000, 100]
    uint256[] public withdrawalFeesBps;

    /// @notice Deposit (staking) fee in basis points (fee unit)
    uint256 public depositFeeBps;

    /// @notice Counter of collected fees
    uint256 public collectedFees;

    /// @notice Last staking time for each user
    mapping(address => uint32) public userLastStakedTime;

    /* ========== CONSTRUCTOR ========== */

    /**
     * @param _stakingTokenAddress address of the token used for staking (must be ERC20)
     * @param _depositFeeBps deposit fee in basis points
     * @param _withdrawalFeesBps aligned to fee schedule
     * @param _withdrawalFeeSchedule assumes a sorted array
     */
    constructor(
        address _stakingTokenAddress,
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    ) Staking(_stakingTokenAddress) {
        _setFees(_depositFeeBps, _withdrawalFeesBps, _withdrawalFeeSchedule);
    }

    /* ========== VIEWS ========== */

    /**
     * @dev Calculate the deposit fee for a given amount.
     * @param _depositAmount amount to stake
     * @return fee paid upon deposit
     */
    function depositFee(uint256 _depositAmount) public view returns (uint256) {
        return depositFeeBps > 0 ? (_depositAmount * depositFeeBps) / feesUnit : 0;
    }

    /**
     * @dev Calculate the withdrawal fee for a given amount.
     * @param _account user wallet address
     * @param _withdrawalAmount amount to withdraw
     * @return fee paid upon withdrawal
     */
    function withdrawalFee(
        address _account,
        uint256 _withdrawalAmount
    ) public view returns (uint256) {
        uint256 userLastStakedTimestampDiff = block.timestamp - userLastStakedTime[_account];
        uint256 withdrawalFeeAmount;
        for (uint i = 0; i < withdrawalFeeSchedule.length; ++i) {
            if (userLastStakedTimestampDiff < withdrawalFeeSchedule[i]) {
                withdrawalFeeAmount = (_withdrawalAmount * withdrawalFeesBps[i]) / feesUnit;
                break;
            }
        }
        return withdrawalFeeAmount;
    }


    /* ========== RESTRICTED FUNCTIONS ========== */

    /**
     * @dev Recover collected fees held in the contract.
     * Note: privileged function for governance
     * @param _recipient fee recovery address
     */
    function recoverFees(address _recipient) external onlyOwner nonReentrant {
        _beforeRecoverFees(_recipient);
        uint256 previousFees = collectedFees;
        collectedFees = 0;
        emit FeesRecovered(previousFees);
        stakingToken.safeTransfer(_recipient, previousFees);
    }

    /* ========== PRIVATE FUNCTIONS ========== */

    /**
     * @dev Configure the fees for this contract.
     * @param _depositFeeBps deposit fee in basis points
     * @param _withdrawalFeesBps withdrawal fees in basis points
     * @param _withdrawalFeeSchedule withdrawal fees schedule
     */
    function _setFees(
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    ) private {
        require(_withdrawalFeeSchedule.length == _withdrawalFeesBps.length && _withdrawalFeeSchedule.length <= 10 && _depositFeeBps <= maxFee, "E5");

        uint32 lastFeeSchedule = 0;
        uint256 lastWithdrawalFee = maxFee + 1;

        for (uint i = 0; i < _withdrawalFeeSchedule.length; ++i) {
            require(_withdrawalFeeSchedule[i] > lastFeeSchedule, "E7");
            require(_withdrawalFeesBps[i] < lastWithdrawalFee, "E8");
            lastFeeSchedule = _withdrawalFeeSchedule[i];
            lastWithdrawalFee = _withdrawalFeesBps[i];
        }

        withdrawalFeeSchedule = _withdrawalFeeSchedule;
        withdrawalFeesBps = _withdrawalFeesBps;
        depositFeeBps = _depositFeeBps;

        emit FeesSet(
            _depositFeeBps,
            _withdrawalFeesBps,
            _withdrawalFeeSchedule
        );
    }

    /* ========== HOOKS ========== */

    /**
     * @dev Override _beforeStake() hook to collect the deposit fee and update associated state
     */
    function _beforeStake(
        address _account,
        uint256 _amount
    ) internal virtual override returns (uint256) {
        uint256 fee = depositFee(_amount);
        userLastStakedTime[_account] = uint32(block.timestamp);
        if (fee > 0) {
            collectedFees += fee;
            emit DepositFeesCollected(_account, fee);
        }
        return super._beforeStake(_account, _amount - fee);
    }

    /**
     * @dev Override _beforeWithdrawl() hook to collect the withdrawal fee and update associated state
     */
    function _beforeWithdraw(
        address _account,
        uint256 _amount
    ) internal virtual override returns (uint256) {
        uint256 fee = withdrawalFee(_account, _amount);
        if (fee > 0) {
            collectedFees += fee;
            emit WithdrawalFeesCollected(_account, fee);
        }
        return super._beforeWithdraw(_account, _amount - fee);
    }

    /**
     * @dev Internal hook called before recovering fees (in the recoverFees() function).
     * @param _recipient recovery address
     */
    function _beforeRecoverFees(address _recipient) internal virtual {}
}

// File: contracts/interfaces/IStakingRewards.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>

pragma solidity >=0.8.0;


interface IStakingRewards is IStakingFee {
    /* ========== STATE VARIABLES ========== */

    function rewardTokens(uint256) external view returns (IERC20);

    function rewardTokenAddresses(
        address _rewardAddress
    ) external view returns (bool);

    function periodFinish() external view returns (uint256);

    function rewardsDuration() external view returns (uint256);

    function lastUpdateTime() external view returns (uint256);

    function rewardRates(
        address _rewardAddress
    ) external view returns (uint256);

    function rewardPerTokenStored(
        address _rewardAddress
    ) external view returns (uint256);

    // wallet address => token address => amount
    function userRewardPerTokenPaid(
        address _walletAddress,
        address _tokenAddress
    ) external view returns (uint256);

    function rewards(
        address _walletAddress,
        address _tokenAddress
    ) external view returns (uint256);

    /* ========== VIEWS ========== */

    function lastTimeRewardApplicable() external view returns (uint256);

    function rewardPerToken(
        address _tokenAddress
    ) external view returns (uint256);

    function earned(
        address _tokenAddress,
        address _account
    ) external view returns (uint256);

    /* ========== MUTATIVE FUNCTIONS ========== */

    function getReward(address _tokenAddress, address _recipient) external;

    function getRewards(address _recipient) external;

    // Must send reward before calling this!
    function startEmission(
        uint256[] memory _rewards,
        uint256 _duration
    ) external;

    function stopEmission(address _refundAddress) external;

    function recoverLeftoverReward(
        address _tokenAddress,
        address _recipient
    ) external;

    function addRewardToken(address _tokenAddress) external;

    function rewardTokenIndex(
        address _tokenAddress
    ) external view returns (int8);

    /* ========== EVENTS ========== */

    // Emitted when a reward is paid to an account
    event RewardPaid(
        address indexed _token,
        address indexed _account,
        uint256 _reward
    );

    // Emitted when a leftover reward is recovered
    event LeftoverRewardRecovered(address indexed _recipient, uint256 _amount);

    // Emitted when rewards emission is started
    event RewardsEmissionStarted(uint256[] _rewards, uint256 _duration);

    // Emitted when rewards emission ends
    event RewardsEmissionEnded();
}

// File: contracts/StakingRewards.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>
// - Elijah <[email protected]>
// - Snake <[email protected]>

pragma solidity >=0.8.0;



/**
 * Contract implementing simple ERC20 token staking functionality with staking rewards and deposit/withdrawal fees.
 */
contract StakingRewards is StakingFee, IStakingRewards {
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */

    /// @notice List of reward token interfaces
    IERC20[] public rewardTokens;

    /// @notice Reward token addresses (maps every reward token address to true, others to false)
    mapping(address => bool) public rewardTokenAddresses;

    /// @notice Timestamp when rewards stop emitting
    uint256 public periodFinish;

    /// @notice Duration for reward emission
    uint256 public rewardsDuration;

    /// @notice Last time the rewards were updated
    uint256 public lastUpdateTime;

    /// @notice Reward token rates (maps every reward token to an emission rate, i.e., how many tokens emitted per second)
    mapping(address => uint256) public rewardRates;

    /// @notice How many tokens are emitted per staked token
    mapping(address => uint256) public rewardPerTokenStored;

    /// @notice How many reward tokens were paid per user (token address => wallet address => amount)
    mapping(address => mapping(address => uint256))
        public userRewardPerTokenPaid;

    /// @notice Accumulator of reward tokens per user (token address => wallet address => amount)
    mapping(address => mapping(address => uint256)) public rewards;

    /* ========== CONSTRUCTOR ========== */

    /**
     * @param _stakingTokenAddress address of the token used for staking (must be ERC20)
     * @param _rewardTokenAddresses addresses the reward tokens (must be ERC20)
     * @param _rewardsDuration reward emission duration
     * @param _depositFeeBps deposit fee in basis points
     * @param _withdrawalFeesBps aligned to fee schedule
     * @param _withdrawalFeeSchedule assumes a sorted array
     */
    constructor(
        address _stakingTokenAddress,
        address[] memory _rewardTokenAddresses,
        uint256 _rewardsDuration,
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    )
        StakingFee(
            _stakingTokenAddress,
            _depositFeeBps,
            _withdrawalFeesBps,
            _withdrawalFeeSchedule
        )
    {
        require(_rewardTokenAddresses.length > 0, "E9");
        // update reward data structures
        for (uint i = 0; i < _rewardTokenAddresses.length; ++i) {
            address tokenAddress = _rewardTokenAddresses[i];
            _addRewardToken(tokenAddress);
        }
        rewardsDuration = _rewardsDuration;
    }

    /* ========== VIEWS ========== */

    /**
     * @notice Return the last time rewards are applicable (the lowest of the current timestamp and the rewards expiry timestamp).
     * @return timestamp
     */
    function lastTimeRewardApplicable() public view returns (uint256) {
        return block.timestamp < periodFinish ? block.timestamp : periodFinish;
    }

    /**
     * @notice Return the reward per staked token for a given reward token address.
     * @param _tokenAddress reward token address
     * @return amount of reward per staked token
     */
    function rewardPerToken(
        address _tokenAddress
    ) public view returns (uint256) {
        if (totalSupply == 0) {
            return rewardPerTokenStored[_tokenAddress];
        }
        return
            rewardPerTokenStored[_tokenAddress] +
            ((lastTimeRewardApplicable() - lastUpdateTime) *
                rewardRates[_tokenAddress] *
                10**ERC20(_tokenAddress).decimals()) /
            totalSupply;
    }

    /**
     * @notice Return the total reward earned by a user for a given reward token address.
     * @param _tokenAddress reward token address
     * @param _account user wallet address
     * @return amount earned
     */
    function earned(
        address _tokenAddress,
        address _account
    ) public view returns (uint256) {
        return
            (balances[_account] *
                (rewardPerToken(_tokenAddress) -
                    userRewardPerTokenPaid[_tokenAddress][_account])) /
            10**ERC20(_tokenAddress).decimals() +
            rewards[_tokenAddress][_account];
    }

    /* ========== MUTATIVE FUNCTIONS ========== */

    /**
     * @dev claim the specified token reward for a staker
     * @param _tokenAddress the address of the reward token
     * @param _recipient the address of the staker that should receive the reward
     * @ return amount of reward received
     */
    function getReward(
        address _tokenAddress,
        address _recipient
    ) public nonReentrant updateRewards(_recipient) {
        return _getReward(_tokenAddress, _recipient);
    }

    /**
     * @dev claim rewards for all the reward tokens for the staker
     * @param _recipient address of the recipient to receive the rewards
     */
    function getRewards(
        address _recipient
    ) public nonReentrant updateRewards(_recipient) {
        for (uint i = 0; i < rewardTokens.length; ++i) {
            _getReward(address(rewardTokens[i]), _recipient);
        }
    }

    /**
     * @dev Start the emission of rewards to stakers. The owner must send reward tokens to the contract before calling this function.
     * Note: Can only be called by owner when the contract is not emitting rewards.
     * @param _rewards array of rewards amounts for each reward token
     * @param _duration duration in seconds for which rewards will be emitted
     */
    function startEmission(
        uint256[] memory _rewards,
        uint256 _duration
    )
        public
        virtual
        nonReentrant
        onlyOwner
        whenNotEmitting
        updateRewards(address(0))
    {
        require(_duration > 0, "E10");
        require(_rewards.length == rewardTokens.length, "E11");

        _beforeStartEmission(_rewards, _duration);

        rewardsDuration = _duration;

        for (uint i = 0; i < rewardTokens.length; ++i) {
            IERC20 token = rewardTokens[i];
            address tokenAddress = address(token);
            rewardRates[tokenAddress] = _rewards[i] / rewardsDuration;

            // Ensure the provided reward amount is not more than the balance in the contract.
            // This keeps the reward rate in the right range, preventing overflows due to
            // very high values of rewardRate in the earned and rewardsPerToken functions;
            // Reward + leftover must be less than 2^256 / 10^18 to avoid overflow.
            uint256 balance = rewardTokens[i].balanceOf(address(this));
            if (tokenAddress != address(stakingToken)) {
                require(
                    rewardRates[tokenAddress] <= balance / rewardsDuration,
                    "E3"
                );
            } else {
                // Handle carefully where rewardsToken is the same as stakingToken (need to subtract total supply)
                require(
                    rewardRates[tokenAddress] <=
                        (balance - totalSupply) / rewardsDuration,
                    "E3"
                );
            }
        }

        lastUpdateTime = block.timestamp;
        periodFinish = block.timestamp + rewardsDuration;

        emit RewardsEmissionStarted(_rewards, _duration);
    }

    /**
     * @dev stop the reward emission process and transfer the remaining reward tokens to a specified address
     * Note: can only be called by owner when the contract is currently emitting rewards
     * @param _refundAddress the address to receive the remaining reward tokens
     */
    function stopEmission(
        address _refundAddress
    ) external nonReentrant onlyOwner whenEmitting {
        _beforeStopEmission(_refundAddress);
        uint256 remaining = 0;
        if (periodFinish > block.timestamp) {
            remaining = periodFinish - block.timestamp;
        }

        periodFinish = block.timestamp;

        for (uint i = 0; i < rewardTokens.length; ++i) {
            IERC20 token = rewardTokens[i];
            address tokenAddress = address(token);
            uint256 refund = rewardRates[tokenAddress] * remaining;
            if (refund > 0) {
                token.safeTransfer(_refundAddress, refund);
            }
        }

        emit RewardsEmissionEnded();
    }

    /**
     * @dev recover leftover reward tokens and transfer them to a specified recipient
     * Note: can only be called by owner when the contract is not emitting rewards
     * @param _tokenAddress address of the reward token to be recovered
     * @param _recipient address to receive the recovered reward tokens
     */
    function recoverLeftoverReward(
        address _tokenAddress,
        address _recipient
    ) external onlyOwner whenNotEmitting {
        require(totalSupply == 0, "E12");
        if (rewardTokenAddresses[_tokenAddress]) {
            _beforeRecoverLeftoverReward(_tokenAddress, _recipient);
            IERC20 token = IERC20(_tokenAddress);
            uint256 amount = token.balanceOf(address(this));
            if (amount > 0) {
                token.safeTransfer(_recipient, amount);
            }
            emit LeftoverRewardRecovered(_recipient, amount);
        }
    }

    /**
     * @dev add a reward token to the contract
     * Note: can only be called by owner when the contract is not emitting rewards
     * @param _tokenAddress address of the new reward token
     */
    function addRewardToken(
        address _tokenAddress
    ) external onlyOwner whenNotEmitting {
        _addRewardToken(_tokenAddress);
    }

    /**
     * @dev Return the array index of the provided token address (if applicable)
     * @param _tokenAddress address of the LP token
     * @return the array index for _tokenAddress or -1 if it is not a reward token
     */
    function rewardTokenIndex(
        address _tokenAddress
    ) public view returns (int8) {
        if (rewardTokenAddresses[_tokenAddress]) {
            for (uint i = 0; i < rewardTokens.length; ++i) {
                if (address(rewardTokens[i]) == _tokenAddress) {
                    return int8(int256(i));
                }
            }
        }
        return -1;
    }

    /* ========== PRIVATE FUNCTIONS ========== */

    /**
     * @dev Get the reward amount of a token for a specific recipient
     * @param _tokenAddress address of the token
     * @param _recipient address of the recipient
     */
    function _getReward(address _tokenAddress, address _recipient) private {
        require(msg.sender == owner() || msg.sender == _recipient, "E14");
        require(rewardTokenAddresses[_tokenAddress], "E13");
        uint256 reward = rewards[_tokenAddress][_recipient];
        if (reward > 0) {
            rewards[_tokenAddress][_recipient] = 0;
            IERC20(_tokenAddress).safeTransfer(_recipient, reward);
            emit RewardPaid(_tokenAddress, _recipient, reward);
        }
    }

    /**
     * @dev Add a token as a reward token
     * @param _tokenAddress address of the token to be added as a reward token
     */
    function _addRewardToken(address _tokenAddress) private {
        require(rewardTokens.length <= 15, "E15");
        require(_tokenAddress != address(0), "E1");
        if (!rewardTokenAddresses[_tokenAddress]) {
            rewardTokens.push(IERC20(_tokenAddress));
            rewardTokenAddresses[_tokenAddress] = true;
        }
    }

    /* ========== HOOKS ========== */

    /**
     * @dev Override _beforeStake() hook to ensure staking is only possible when rewards are emitting and update the rewards
     */
    function _beforeStake(
        address _account,
        uint256 _amount
    ) internal virtual override whenEmitting updateRewards(_account) returns (uint256) {
        return super._beforeStake(_account, _amount);
    }

    /**
     * @dev Override _beforeExit() hook to claim all rewards for the account exiting
     */
    function _beforeExit(address _account) internal virtual override {
        getRewards(_account); // getRewards calls updateRewards so we don't need to call it explicitly again here
        super._beforeExit(_account);
    }

    /**
     * @dev Override _beforeRecoverERC20() hook to prevent recovery of a reward token
     */
    function _beforeRecoverERC20(
        address _tokenAddress,
        address _recipient,
        uint256 _amount
    ) internal virtual override {
        require(!rewardTokenAddresses[_tokenAddress], "E16");
        super._beforeRecoverERC20(_tokenAddress, _recipient, _amount);
    }

    /**
     * @dev Internal hook called before starting the emission process (in the startEmission() function).
     * @param _rewards array of rewards per token.
     * @param _duration emission duration.
     */
    function _beforeStartEmission(
        uint256[] memory _rewards,
        uint256 _duration
    ) internal virtual {}

    /**
     * @dev Internal hook called before stopping the emission process (in the stopEmission() function).
     * @param _refundAddress address to refund the remaining reward to
     */
    function _beforeStopEmission(address _refundAddress) internal virtual {}

    /**
     * @dev Internal hook called before recovering leftover rewards (in the recoverLeftoverRewards() function).
     * @param _tokenAddress address of the token to recover
     * @param _recipient address to recover the leftover rewards to
     */
    function _beforeRecoverLeftoverReward(
        address _tokenAddress,
        address _recipient
    ) internal virtual {}

    /* ========== MODIFIERS ========== */

    /**
     * @dev Modifier to update rewards of a given account.
     * @param _account account to update rewards for
     */
    modifier updateRewards(address _account) {
        for (uint i = 0; i < rewardTokens.length; ++i) {
            address tokenAddress = address(rewardTokens[i]);
            rewardPerTokenStored[tokenAddress] = rewardPerToken(tokenAddress);
        }
        lastUpdateTime = lastTimeRewardApplicable();
        if (_account != address(0)) {
            for (uint i = 0; i < rewardTokens.length; ++i) {
                address tokenAddress = address(rewardTokens[i]);
                rewards[tokenAddress][_account] = earned(tokenAddress, _account);
                userRewardPerTokenPaid[tokenAddress][_account] = rewardPerTokenStored[tokenAddress];
            }
        }
        _;
    }

    /**
     * @dev Modifier to check if rewards are emitting.
     */
    modifier whenEmitting() {
        require(block.timestamp <= periodFinish, "E18");
        _;
    }

    /**
     * @dev Modifier to check if rewards are not emitting.
     */
    modifier whenNotEmitting() {
        require(block.timestamp > periodFinish, "E17");
        _;
    }
}

// File: contracts/interfaces/IFarmingRewards.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>

pragma solidity >=0.8.0;




interface IFarmingRewards is IStakingRewards {
    /// @notice Represents a snapshot of an LP position at a given timestamp
    struct Position {
        uint112 amount0;
        uint112 amount1;
        uint32 blockTimestamp;
    }

    /* ========== STATE VARIABLES ========== */

    function oracle() external returns (IElkDexOracle);

    function lpToken() external returns (IElkPair);

    function coverageTokenAddress() external returns (address);

    function coverageAmount() external returns (uint256);

    function coverageVestingDuration() external returns (uint256);

    function coverageRate() external returns (uint256);

    function coveragePerTokenStored() external returns (uint256);

    function userCoveragePerTokenPaid(
        address _tokenPaid
    ) external returns (uint256);

    function coverage(address _token) external returns (uint256);

    function lastStakedPosition(
        address _user
    )
        external
        returns (uint112 amount0, uint112 amount1, uint32 blockTimeStamp);

    /* ========== VIEWS ========== */

    function coveragePerToken() external view returns (uint256);

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

    /* ========== MUTATIVE FUNCTIONS ========== */

    function getCoverage(address _recipient) external;

    

    function startEmission(
        uint256[] memory _rewards,
        uint256 _coverage,
        uint256 _duration
    ) external;

    function recoverLeftoverCoverage(address _recipient) external;

    /* ========== EVENTS ========== */

    // Emitted when the coverage is paid to an account
    event CoveragePaid(address indexed account, uint256 coverage);

    // Emitted when the leftover coverage is recovered
    event LeftoverCoverageRecovered(address indexed recipient, uint256 amount);
}

// File: contracts/FarmingRewards.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>
// - Elijah <[email protected]>
// - Snake <[email protected]>

pragma solidity >=0.8.0;





/**
 * Contract implementing simple ERC20 token staking functionality with staking rewards, impermanent loss coverage, and deposit/withdrawal fees.
 */
contract FarmingRewards is StakingRewards, IFarmingRewards {
    using SafeERC20 for IERC20;

    /* ========== STATE VARIABLES ========== */

    /// @notice Interface to the ElkDex pricing oracle on this blockchain
    IElkDexOracle public immutable oracle;

    /// @notice Interface to the LP token that is staked in this farm
    IElkPair public immutable lpToken;

    /// @notice Address of the coverage token
    address public coverageTokenAddress;

    /// @notice Total amount of coverage available (worst case max amount)
    uint256 public coverageAmount;

    /// @notice Time until a farmed position is fully covered against impermanent loss (100%)
    uint256 public coverageVestingDuration;

    /// @notice Rate of coverage vesting
    uint256 public coverageRate;

    /// @notice Coverage amount per token staked in the farm
    uint256 public coveragePerTokenStored;

    /// @notice How much coverage was paid per user (wallet address => amount)
    mapping(address => uint256) public userCoveragePerTokenPaid;

    /// @notice Accumulator of coverage tokens per user (wallet address => amount)
    mapping(address => uint256) public coverage;

    /// @notice Last farming position for a given user (wallet address => position)
    mapping(address => Position) public lastStakedPosition;


    /* ========== CONSTRUCTOR ========== */

    /**
     * @param _oracleAddress address of the price oracle
     * @param _lpTokenAddress address of the staking LP token (must be an ElkDex LP)
     * @param _coverageTokenAddress address of the token that the coverage is paid in
     * @param _coverageAmount total amount of coverage
     * @param _coverageVestingDuration time it takes to vest 100% of the coverage (min. 1 day)
     * @param _rewardTokenAddresses addresses the reward tokens (must be ERC20)
     * @param _rewardsDuration reward emission duration
     * @param _depositFeeBps deposit fee in basis points
     * @param _withdrawalFeesBps aligned to fee schedule
     * @param _withdrawalFeeSchedule assumes a sorted array
     */
    constructor(
        address _oracleAddress,
        address _lpTokenAddress,
        address _coverageTokenAddress,
        uint256 _coverageAmount,
        uint32 _coverageVestingDuration,
        address[] memory _rewardTokenAddresses,
        uint256 _rewardsDuration,
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    )
        StakingRewards(
            _lpTokenAddress,
            _rewardTokenAddresses,
            _rewardsDuration,
            _depositFeeBps,
            _withdrawalFeesBps,
            _withdrawalFeeSchedule
        )
    {
        oracle = IElkDexOracle(_oracleAddress);
        lpToken = IElkPair(_lpTokenAddress);

        if (_coverageTokenAddress != address(0)) {
            require(
                lpToken.token0() == _coverageTokenAddress ||
                    lpToken.token1() == _coverageTokenAddress,
                "E19"
            );
            require(
                _coverageVestingDuration >= 24 * 3600 && _coverageVestingDuration <= rewardsDuration,
                "E21"
            );
        }

        require(
            lpToken.factory() == oracle.factory(),
            "E20"
        );

        coverageTokenAddress = _coverageTokenAddress;
        coverageAmount = _coverageAmount;
        coverageVestingDuration = _coverageVestingDuration;
    }

    // Optimized version below
    /*function coveragePerToken() public view returns (uint256) {
        if (totalSupply == 0) {
            return coveragePerTokenStored;
        }
        return
            // does this work for non 18 dec tokens?  rate = _coverage / rewardsDuration, here rate is converted back to 18 dec
            coveragePerTokenStored +
            ((lastTimeRewardApplicable() - lastUpdateTime) *
                coverageRate *
                10**ERC20(coverageTokenAddress).decimals()) /
            totalSupply;
    }*/

    /**
     * @dev Return the coverage per staked token (in coverage token amounts)
     * @return amount of coverage per staked token
     */
    function coveragePerToken() public view returns (uint256) {
        return totalSupply == 0 ? coveragePerTokenStored : coveragePerTokenStored + (((lastTimeRewardApplicable() - lastUpdateTime) * coverageRate * 10**ERC20(coverageTokenAddress).decimals()) / totalSupply);
    }

    // Code below optimizes this version of the function
    /*function coverageEarned(address _account) public view returns(uint256) {
        if (coverageTokenAddress == address(0)) {
            return 0;
        }
        uint256 hodlValue = lpValueWeth(lastStakedPosition[_account]);
        if (hodlValue == 0) {
            // prevent division by zero below // equivalent check would be lastStakedPosition[_account].blockTimestamp > 0
            return coverage[_account];
        }
        uint256 outValue = lpValueWeth(position(balances[_account]));
        uint256 cappedCoverage = (balances[_account] *
            (coveragePerToken() - userCoveragePerTokenPaid[_account])) / 1e18;
        uint256 vested = vestedCoverage(
            hodlValue,
            outValue,
            lastStakedPosition[_account].blockTimestamp
        );
        if (vested > cappedCoverage) {
            vested = cappedCoverage;
        }
        // amount * (hodl value - out value) / hodl value = amount * (1 - (out value / hodl value))
        return (vested - (vested * outValue) / hodlValue) + coverage[_account];
    }*/

   /**
     * @dev Return the total coverage earned by a user.
     * @param _account user wallet address
     * @return coverage amount earned
     */
    function coverageEarned(address _account) public view returns(uint256) {
        if (coverageTokenAddress == address(0)) {
            return 0;
        }
        Position memory lastStake = lastStakedPosition[_account];
        uint256 hodlValue = lpValueWeth(lastStake);
        if (hodlValue == 0) {
            return coverage[_account];
        }
        uint256 outValue = lpValueWeth(position(balances[_account]));
        uint256 balance = balances[_account];
        uint256 cappedCoverage = (balance * (coveragePerToken() - userCoveragePerTokenPaid[_account])) / 1e18;
        uint256 vested = vestedCoverage(hodlValue, outValue, lastStake.blockTimestamp);
        return (vested > cappedCoverage ? cappedCoverage : vested) - (vested * outValue) / hodlValue + coverage[_account];
    }


    /* ========== MUTATIVE FUNCTIONS ========== */

    // Optimized version of this below
    /*
    function getCoverage(
        address _recipient
    ) public nonReentrant updateCoverage(_recipient) {
        require(
            msg.sender == owner() || msg.sender == _recipient,
            "E14"
        );
        require(coverageTokenAddress != address(0), "E23");
        uint256 cov = coverage[_recipient];
        if (cov > 0) {
            coverage[_recipient] = 0;
            IERC20(coverageTokenAddress).safeTransfer(_recipient, cov);
            emit CoveragePaid(_recipient, cov);
        }
    }
    */

    /**
     * @dev claim the coverage for a staker
     * @param _recipient the address of the staker that should receive the coverage
     * @ return the amount of reward received
     */
     function getCoverage(address _recipient) 
        public 
        nonReentrant 
        updateCoverage(_recipient) 
    {
        require(msg.sender == owner() || msg.sender == _recipient, "E14");
        require(coverageTokenAddress != address(0), "E23");

        uint256 cov = coverage[_recipient];
        if (cov == 0) return;

        coverage[_recipient] = 0;
        IERC20(coverageTokenAddress).safeTransfer(_recipient, cov);
        emit CoveragePaid(_recipient, cov);
    }

    /**
     * @dev Set the coverage parameters if none were set in the constructor. Gives the option for farm owners to change coverage tokens.
     * Note: Can't change coverage token if coverage is already accumulated
     * @param _tokenAddress address of token to be used for coverage emissions
     * @param _coverageAmount total amount of coverage token to emit
     * @param _coverageVestingDuration vesting period in seconds that users need to have staked to claim coverage
     */
    function setCoverage(address _tokenAddress, uint256 _coverageAmount, uint32 _coverageVestingDuration) external onlyOwner whenNotEmitting {
        require(coveragePerTokenStored == 0, "E24");
        require(
            (lpToken.token0() == _tokenAddress || lpToken.token1() == _tokenAddress) &&
            (_coverageVestingDuration >= 24 * 3600) &&
            (_coverageVestingDuration <= rewardsDuration),
            "E19"
        );
        coverageTokenAddress = _tokenAddress;
        coverageAmount = _coverageAmount;
        coverageVestingDuration = _coverageVestingDuration;
    }

    // Override startEmission() so it calls the expanded function that includes the coverage amount
    /**
     * @dev Start the emission of rewards to stakers with no coverage. The owner must send reward tokens to the contract before calling this function.
     * Note: Can only be called by owner when the contract is not emitting rewards.
     * @param _rewards array of rewards amounts for each reward token
     * @param _duration duration in seconds for which rewards will be emitted
     */
    function startEmission(
        uint256[] memory _rewards,
        uint256 _duration
    ) public override(StakingRewards, IStakingRewards) onlyOwner {
        return startEmission(_rewards, 0, _duration);
    }

    /**
     * @dev Start the emission of rewards to stakers. The owner must send reward and coverage tokens to the contract before calling this function.
     * Note: Can only be called by owner when the contract is not emitting rewards.
     * @param _rewards array of rewards amounts for each reward token
     * @param _coverage total amount of coverage provided to users (worst case max)
     * @param _duration duration in seconds for which rewards will be emitted (and coverage will be active)
     */
    function startEmission(
        uint256[] memory _rewards,
        uint256 _coverage,
        uint256 _duration
    ) public onlyOwner updateCoverage(address(0)) {
        super.startEmission(_rewards, _duration);
        require(
            coverageVestingDuration <= rewardsDuration,
            "E22"
        ); // must check again

        coverageRate = _coverage / rewardsDuration; // rewardsDuration, not coverageVestingDuration which can be shorter!

        if (coverageTokenAddress != address(0) && _coverage > 0) {
            // Ensure the provided coverage amount is not more than the balance in the contract
            uint256 balance = IERC20(coverageTokenAddress).balanceOf(
                address(this)
            );
            int8 tokenIndex = rewardTokenIndex(coverageTokenAddress);
            if (tokenIndex >= 0) {
                balance -= _rewards[uint256(int256(tokenIndex))];
            }
            require(
                coverageRate <= balance / rewardsDuration,
                "E3"
            );
        }
    }

    /**
     * @dev recover leftover coverage tokens and transfer them to a specified recipient
     * Note: can only be called by owner when the contract is not emitting rewards
     * @param _recipient address to receive the recovered coverage tokens
     */
     function recoverLeftoverCoverage(address _recipient) public onlyOwner whenNotEmitting {
        require(totalSupply == 0 && coverageTokenAddress != address(0), "E12/E23");
        _beforeRecoverLeftoverCoverage(_recipient);
        IERC20 token = IERC20(coverageTokenAddress);
        uint256 amount = token.balanceOf(address(this));
        if (amount > 0) {
            token.safeTransfer(_recipient, amount);
            emit LeftoverCoverageRecovered(_recipient, amount);
        }
    }

    /* ========== PRIVATE FUNCTIONS ========== */

    /**
     * @dev Return the LP position for a given amount of LP token.
     * @param _amount the amount of LP token
     * @return the corresponding LP position (amount0, amount1, timestamp)
     */
    function position(uint256 _amount) private view returns (Position memory) {
        (uint112 reserve0, uint112 reserve1, uint32 timestamp) = lpToken.getReserves();
        uint256 totalAmount = lpToken.totalSupply();
        return Position(uint112((_amount * reserve0) / totalAmount), uint112((_amount * reserve1) / totalAmount), timestamp);
    }

    /**
     * @dev Return the value in WETH of the given LP position.
     * @param _position LP position
     * @return the value in WETH
     */
    function lpValueWeth(
        Position memory _position
    ) private view returns (uint256) {
        return
            oracle.consultWeth(lpToken.token0(), _position.amount0) +
            oracle.consultWeth(lpToken.token1(), _position.amount1);
    }
    
    /**
     * @dev Return the vested coverage in coverage token amount for the given HODL and OUT values since the provided timestamp.
     * @param _hodlValue the value (in WETH) if the tokens making up the LP were kept unpaired
     * @param _outValue the value (in WETH) of the LP token position
     * @param _lastTimestamp the start timestamp (when the LP token position was created)
     * @return vested coverage in coverage token amount
     */
    function vestedCoverage(
        uint256 _hodlValue,
        uint256 _outValue,
        uint32 _lastTimestamp
    ) private view returns (uint256) {
        uint256 timeElapsed = block.timestamp - _lastTimestamp;
        uint256 wethCov = _hodlValue > _outValue ? _hodlValue - _outValue : 0;
        uint256 tokenCoverage = wethCov == 0 ? 0 : oracle.consult(oracle.weth(), wethCov, coverageTokenAddress);
        if (timeElapsed >= coverageVestingDuration) {
            return tokenCoverage;
        }
        return (tokenCoverage * timeElapsed) / coverageVestingDuration;
    }

    /* ========== HOOKS ========== */

    /**
     * @dev Override _beforeStake() hook to ensure staking updates the coverage
     */
    function _beforeStake(
        address _account,
        uint256 _amount
    ) internal virtual override updateCoverage(_account) returns (uint256) {
        return super._beforeStake(_account, _amount);
    }

    /**
     * @dev Override _beforeWithdraw() hook to ensure withdrawing updates the coverage
     */
    function _beforeWithdraw(
        address _account,
        uint256 _amount
    ) internal virtual override updateCoverage(_account) returns (uint256) {
        return super._beforeWithdraw(_account, _amount);
    }

    /**
     * @dev Override _beforeExit() hook to claim all coverage for the account exiting
     */
    function _beforeExit(address _account) internal virtual override {
        if (coverageTokenAddress != address(0)) {
            getCoverage(_account);
        }
        super._beforeExit(_account);
    }

    /**
     * @dev Override _beforeRecoverERC20() hook to prevent recovery of a coverage token
     */
    function _beforeRecoverERC20(
        address _tokenAddress,
        address _recipient,
        uint256 _amount
    ) internal virtual override {
        require(
            _tokenAddress != coverageTokenAddress,
            "E16"
        );
        super._beforeRecoverERC20(_tokenAddress, _recipient, _amount);
    }

    // New hooks

    /**
     * @dev Internal hook called before recovering leftover coverage (in the recoverLeftoverCoverage() function).
     * @param _recipient address to recover the leftover coverage to
     */
    function _beforeRecoverLeftoverCoverage(
        address _recipient
    ) internal virtual {}

    /* ========== MODIFIERS ========== */

    /**
     * @dev Modifier to update the coverage of a given account.
     * @param _account account to update coverage for
     */
    modifier updateCoverage(address _account) {
        if (coverageTokenAddress != address(0)) {
            coveragePerTokenStored = coveragePerToken();
            lastUpdateTime = lastTimeRewardApplicable(); // it seems fine to redo this here
            oracle.update(lpToken.token0(), oracle.weth()); // update oracle for first token
            oracle.update(lpToken.token1(), oracle.weth()); // ditto for the second token
            if (_account != address(0)) {
                coverage[_account] = coverageEarned(_account);
                userCoveragePerTokenPaid[_account] = coveragePerTokenStored;
                lastStakedPosition[_account] = position(balances[_account]); // don't forget to reset the last position info
            }
        }
        _;
    }
}

// File: contracts/interfaces/IFarmingRewardsPermissioned.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>

pragma solidity >=0.8.0;


interface IFarmingRewardsPermissioned is IFarmingRewards {

    function setAddressPermission(address _walletAddress, bool _permission) external;

}

// File: contracts/FarmingRewardsPermissoned.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>
// - Elijah <[email protected]>
// - Snake <[email protected]>

pragma solidity >=0.8.0;



/**
 * Contract enabling staking permissions for FarmingRewards.
 */
contract FarmingRewardsPermissioned is
    FarmingRewards,
    IFarmingRewardsPermissioned
{
    mapping(address => bool) public permittedAddresses;

    /* ========== CONSTRUCTOR ========== */

    /**
     * @param _oracleAddress address of the price oracle
     * @param _lpTokenAddress address of the staking LP token (must be an ElkDex LP)
     * @param _coverageTokenAddress address of the token that the coverage is paid in
     * @param _coverageAmount total amount of coverage
     * @param _coverageVestingDuration time it takes to vest 100% of the coverage (min. 1 day)
     * @param _rewardTokenAddresses addresses the reward tokens (must be ERC20)
     * @param _rewardsDuration reward emission duration
     * @param _depositFeeBps deposit fee in basis points
     * @param _withdrawalFeesBps aligned to fee schedule
     * @param _withdrawalFeeSchedule assumes a sorted array
     */
    constructor(
        address _oracleAddress, // address of the price oracle
        address _lpTokenAddress, // address of the staking LP token (must be an ElkDex LP)
        address _coverageTokenAddress, // address of the token that the coverage is paid in
        uint256 _coverageAmount, // total amount of coverage
        uint32 _coverageVestingDuration, // time it takes to vest 100% of the coverage (min. 1 day)
        address[] memory _rewardTokenAddresses, // addresses the reward tokens (must be ERC20)
        uint256 _rewardsDuration, // reward emission duration
        uint16 _depositFeeBps, // deposit fee in basis points
        uint16[] memory _withdrawalFeesBps, // aligned to fee schedule
        uint32[] memory _withdrawalFeeSchedule // assumes a sorted array
    )
        FarmingRewards(
            _oracleAddress,
            _lpTokenAddress,
            _coverageTokenAddress,
            _coverageAmount,
            _coverageVestingDuration,
            _rewardTokenAddresses,
            _rewardsDuration,
            _depositFeeBps,
            _withdrawalFeesBps,
            _withdrawalFeeSchedule
        )
    {}

    /**
     * @notice set permission for an address
     * @param _walletAddress wallet address to set permission for
     * @param _permission permission to set
     */
    function setAddressPermission(
        address _walletAddress,
        bool _permission
    ) external onlyOwner {
        permittedAddresses[_walletAddress] = _permission;
    }

    /**
     * @dev Override _beforeStake() hook to ensure address is permitted to stake
     */
    function _beforeStake(
        address _account,
        uint256 _amount
    ) internal virtual override returns (uint256) {
        require(permittedAddresses[_account], "E25");
        return super._beforeStake(_account, _amount);
    }
}

// File: contracts/ElkFactoryHelperPermissioned.sol


//
// Copyright (c) 2023 ElkLabs
// License terms: https://github.com/elkfinance/faas/blob/main/LICENSE
//
// Authors:
// - Seth <[email protected]>
// - Baal <[email protected]>
// - Elijah <[email protected]>
// - Snake <[email protected]>

pragma solidity >=0.8.0;


/**
 * @title Library containing a helper function that creates new FarmingRewards contracts in the ElkFarmFactory. It was separated out due to contract size limitations.  Farm manager address must be passed in so that the ownership is always transfered to the FarmManager contract.
 */
library ElkFactoryHelperPermissioned {
    /**
     * @notice generates a permissioned FarmingRewards contract and transfers ownership to the provided farm manager
     * @param _abi the abi of the FarmingRewards contract
     * @param _salt the salt used to create the contract
     * @param _farmManager the address of the farm manager
     */
    function createFarmContract(
        bytes memory _abi,
        bytes32 _salt,
        address _farmManager
    ) external returns (address addr) {
        bytes memory bytecode = abi.encodePacked(
            type(FarmingRewardsPermissioned).creationCode,
            _abi
        );

        assembly {
            addr := create2(0, add(bytecode, 0x20), mload(bytecode), _salt)
            if iszero(extcodesize(addr)) {
                revert(0, 0)
            }
        }

        FarmingRewardsPermissioned(addr).transferOwnership(_farmManager);
    }
}

Contract ABI

[]

615cbf61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe7300000000000000000000000000000000000000003014608060405260043610620000375760003560e01c8063c82e8b95146200003c575b600080fd5b8180156200004957600080fd5b50620000616200005b36600462000187565b6200007d565b6040516001600160a01b03909116815260200160405180910390f35b60008060405180602001620000929062000146565b601f1982820381018352601f909101166040819052620000b89190879060200162000290565b6040516020818303038152906040529050838151602083016000f59150813b620000e157600080fd5b60405163f2fde38b60e01b81526001600160a01b03848116600483015283169063f2fde38b90602401600060405180830381600087803b1580156200012557600080fd5b505af11580156200013a573d6000803e3d6000fd5b50505050509392505050565b6159d880620002b283390190565b634e487b7160e01b600052604160045260246000fd5b80356001600160a01b03811681146200018257600080fd5b919050565b6000806000606084860312156200019d57600080fd5b833567ffffffffffffffff80821115620001b657600080fd5b818601915086601f830112620001cb57600080fd5b813581811115620001e057620001e062000154565b604051601f8201601f19908116603f011681019083821181831017156200020b576200020b62000154565b816040528281528960208487010111156200022557600080fd5b8260208601602083013760006020848301015280975050505050506020840135915062000255604085016200016a565b90509250925092565b6000815160005b8181101562000281576020818501810151868301520162000265565b50600093019283525090919050565b6000620002a9620002a283866200025e565b846200025e565b94935050505056fe60e06040523480156200001157600080fd5b50604051620059d8380380620059d8833981016040819052620000349162000ae3565b60016000558989898989898989898988858585858585838383836200005933620004d9565b6001600160a01b0381166200009a5760405162461bcd60e51b8152602060048201526002602482015261453160f01b60448201526064015b60405180910390fd5b6001600160a01b03811660808190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa158015620000e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200010b919062000be8565b6200011890600a62000d29565b6200012c90670de0b6b3a764000062000d3a565b600455506200013d8383836200052b565b505050506000855111620001795760405162461bcd60e51b8152602060048201526002602482015261453960f01b604482015260640162000091565b60005b8551811015620001cc5760008682815181106200019d576200019d62000d5d565b60200260200101519050620001b8816200072a60201b60201c565b50620001c48162000d73565b90506200017c565b505050600d919091555050506001600160a01b03808b1660a05289811660c0528816156200037c57876001600160a01b031660c0516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200023f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000265919062000d8f565b6001600160a01b03161480620002f25750876001600160a01b031660c0516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015620002c1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002e7919062000d8f565b6001600160a01b0316145b620003265760405162461bcd60e51b815260206004820152600360248201526245313960e81b604482015260640162000091565b620151808663ffffffff1610158015620003485750600d548663ffffffff1611155b6200037c5760405162461bcd60e51b815260206004820152600360248201526245323160e81b604482015260640162000091565b60a0516001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015620003bd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003e3919062000d8f565b6001600160a01b031660c0516001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200042d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000453919062000d8f565b6001600160a01b031614620004915760405162461bcd60e51b815260206004820152600360248201526204532360ec1b604482015260640162000091565b5050601380546001600160a01b0319166001600160a01b039790971696909617909555505060149190915563ffffffff166015555062000e5b9b505050505050505050505050565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b815181511480156200053f5750600a815111155b80156200055257506107d08361ffff1611155b620005855760405162461bcd60e51b8152602060048201526002602482015261453560f01b604482015260640162000091565b600080620005976107d0600162000dad565b905060005b8351811015620006b0578263ffffffff16848281518110620005c257620005c262000d5d565b602002602001015163ffffffff1611620006045760405162461bcd60e51b8152602060048201526002602482015261453760f01b604482015260640162000091565b818582815181106200061a576200061a62000d5d565b602002602001015161ffff16106200065a5760405162461bcd60e51b815260206004820152600260248201526108a760f31b604482015260640162000091565b8381815181106200066f576200066f62000d5d565b602002602001015192508481815181106200068e576200068e62000d5d565b602002602001015161ffff16915080620006a89062000d73565b90506200059c565b508251620006c69060059060208601906200082a565b508351620006dc90600690602087019062000882565b5061ffff85166007556040517fab4c36b25b04e6f8ac9915203aba1048c17841782324a583e98128b8c1c964f3906200071b9087908790879062000dc3565b60405180910390a15050505050565b600a54600f1015620007655760405162461bcd60e51b815260206004820152600360248201526245313560e81b604482015260640162000091565b6001600160a01b038116620007a25760405162461bcd60e51b8152602060048201526002602482015261453160f01b604482015260640162000091565b6001600160a01b0381166000908152600b602052604090205460ff166200082757600a805460018082019092557fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0319166001600160a01b0384169081179091556000908152600b60205260409020805460ff191690911790555b50565b82805482825590600052602060002090810192821562000870579160200282015b8281111562000870578251829063ffffffff169055916020019190600101906200084b565b506200087e929150620008c6565b5090565b82805482825590600052602060002090810192821562000870579160200282015b8281111562000870578251829061ffff16905591602001919060010190620008a3565b5b808211156200087e5760008155600101620008c7565b80516001600160a01b0381168114620008f557600080fd5b919050565b805163ffffffff81168114620008f557600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156200095057620009506200090f565b604052919050565b60006001600160401b038211156200097457620009746200090f565b5060051b60200190565b600082601f8301126200099057600080fd5b81516020620009a9620009a38362000958565b62000925565b82815260059290921b84018101918181019086841115620009c957600080fd5b8286015b84811015620009ef57620009e181620008dd565b8352918301918301620009cd565b509695505050505050565b805161ffff81168114620008f557600080fd5b600082601f83011262000a1f57600080fd5b8151602062000a32620009a38362000958565b82815260059290921b8401810191818101908684111562000a5257600080fd5b8286015b84811015620009ef5762000a6a81620009fa565b835291830191830162000a56565b600082601f83011262000a8a57600080fd5b8151602062000a9d620009a38362000958565b82815260059290921b8401810191818101908684111562000abd57600080fd5b8286015b84811015620009ef5762000ad581620008fa565b835291830191830162000ac1565b6000806000806000806000806000806101408b8d03121562000b0457600080fd5b62000b0f8b620008dd565b995062000b1f60208c01620008dd565b985062000b2f60408c01620008dd565b975060608b0151965062000b4660808c01620008fa565b60a08c01519096506001600160401b038082111562000b6457600080fd5b62000b728e838f016200097e565b965060c08d0151955062000b8960e08e01620009fa565b94506101008d015191508082111562000ba157600080fd5b62000baf8e838f0162000a0d565b93506101208d015191508082111562000bc757600080fd5b5062000bd68d828e0162000a78565b9150509295989b9194979a5092959850565b60006020828403121562000bfb57600080fd5b815160ff8116811462000c0d57600080fd5b9392505050565b634e487b7160e01b600052601160045260246000fd5b600181815b8085111562000c6b57816000190482111562000c4f5762000c4f62000c14565b8085161562000c5d57918102915b93841c939080029062000c2f565b509250929050565b60008262000c845750600162000d23565b8162000c935750600062000d23565b816001811462000cac576002811462000cb75762000cd7565b600191505062000d23565b60ff84111562000ccb5762000ccb62000c14565b50506001821b62000d23565b5060208310610133831016604e8410600b841016171562000cfc575081810a62000d23565b62000d08838362000c2a565b806000190482111562000d1f5762000d1f62000c14565b0290505b92915050565b600062000c0d60ff84168362000c73565b60008262000d5857634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b60006001820162000d885762000d8862000c14565b5060010190565b60006020828403121562000da257600080fd5b62000c0d82620008dd565b8082018082111562000d235762000d2362000c14565b60006060820161ffff80871684526020606081860152828751808552608087019150828901945060005b8181101562000e0d57855185168352948301949183019160010162000ded565b5050858103604087015286518082529082019350915080860160005b8381101562000e4d57815163ffffffff168552938201939082019060010162000e29565b509298975050505050505050565b60805160a05160c051614a3c62000f9c6000396000818161053601528181611557015281816115f30152818161190e01528181611aa101528181611ea90152818161203c0152818161282e0152818161295a01528181612a8001528181612b0a0152818161306c015281816131ff01528181613ce60152613e7901526000818161067f015281816118df0152818161199001528181611a7201528181611b2301528181611e7a01528181611f2b0152818161200d015281816120be015281816127ff0152818161292b01528181612c4301528181612c720152818161303d015281816130ee015281816131d00152818161328101528181613cb701528181613d6801528181613e4a0152613efb0152600081816105fa01528181610a6701528181610d78015281816117610152818161184e01526139590152614a3c6000f3fe608060405234801561001057600080fd5b50600436106103835760003560e01c80637aaeaf7f116101de578063a7309d7d1161010f578063e9fad8ee116100ad578063f2d176391161007c578063f2d176391461087d578063f2fde38b14610890578063f9cb1d04146108a3578063f9ea0778146108ac57600080fd5b8063e9fad8ee146107e9578063ebe2b12b146107f1578063ef2849b3146107fa578063f12297771461086a57600080fd5b8063c8f33c91116100e9578063c8f33c911461078f578063ca42303114610798578063e13d8722146107ab578063e70b9e27146107be57600080fd5b8063a7309d7d14610738578063ab87982714610773578063ad3bc5461461077c57600080fd5b806387e7ed3a1161017c57806399d531e11161015657806399d531e1146106e95780639ce43f90146106f25780639e3582c814610712578063a694fc3a1461072557600080fd5b806387e7ed3a146106bc5780638da5cb5b146106cf5780639003adfe146106e057600080fd5b80637cee932c116101b85780637cee932c146106675780637dc0d1d01461067a57806380faa57d146106a15780638194c178146106a957600080fd5b80637aaeaf7f146106385780637bb7bed11461064b5780637beb3d9f1461065e57600080fd5b8063423c485a116102b85780636b09169511610256578063715018a611610230578063715018a6146105ed57806372f702f3146105f5578063757767d71461061c57806379ee54f71461062557600080fd5b80636b0916951461059c5780636da9c58e146105af5780637035ab98146105c257600080fd5b806354feec3e1161029257806354feec3e1461051e5780635fcbd2851461053157806366aa01ca1461057057806367c0d00f1461059357600080fd5b8063423c485a146104e3578063486e63b1146104f6578063502cd30f146104fe57600080fd5b806327e235e31161032557806333024430116102ff5780633302443014610474578063386a9525146104945780633d3b26031461049d578063415be3b5146104bd57600080fd5b806327e235e31461042e5780632e1a7d4d1461044e5780632e9f06021461046157600080fd5b806318160ddd1161036157806318160ddd146103cc5780631c03e6cc146103d55780631db7efd8146103e8578063211dc32d1461041b57600080fd5b806301f59d161461038857806304a79e48146103a45780631171bda9146103b7575b600080fd5b6103916107d081565b6040519081526020015b60405180910390f35b6103916103b2366004614446565b6108bf565b6103ca6103c5366004614463565b610a55565b005b61039160025481565b6103ca6103e3366004614446565b610b4d565b61040b6103f6366004614446565b600b6020526000908152604090205460ff1681565b604051901515815260200161039b565b6103916104293660046144a4565b610b98565b61039161043c366004614446565b60036020526000908152604090205481565b6103ca61045c3660046144dd565b610ca3565b6103ca61046f36600461459c565b610de0565b610391610482366004614446565b60196020526000908152604090205481565b610391600d5481565b6103916104ab366004614446565b600f6020526000908152604090205481565b6104d06104cb366004614446565b610df8565b60405160009190910b815260200161039b565b6103916104f13660046144dd565b610e7e565b610391610eab565b61039161050c366004614446565b60186020526000908152604090205481565b61039161052c3660046144dd565b610f8b565b6105587f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161039b565b61040b61057e366004614446565b601b6020526000908152604090205460ff1681565b61039160145481565b6103ca6105aa3660046144a4565b610fac565b6103ca6105bd366004614446565b6110ed565b6103916105d03660046144a4565b601160209081526000928352604080842090915290825290205481565b6103ca611212565b6105587f000000000000000000000000000000000000000000000000000000000000000081565b61039160155481565b6103ca610633366004614446565b611226565b6103916106463660046145e1565b6113ac565b6105586106593660046144dd565b611462565b61039161271081565b6103ca61067536600461461b565b61148c565b6105587f000000000000000000000000000000000000000000000000000000000000000081565b6103916114bf565b6103ca6106b736600461465b565b6114d6565b6103ca6106ca366004614446565b611708565b6001546001600160a01b0316610558565b61039160085481565b61039160165481565b610391610700366004614446565b60106020526000908152604090205481565b6103916107203660046144dd565b611793565b6103ca6107333660046144dd565b6117a3565b61075e610746366004614446565b60096020526000908152604090205463ffffffff1681565b60405163ffffffff909116815260200161039b565b61039160075481565b6103ca61078a36600461469d565b6118a8565b610391600e5481565b6103ca6107a6366004614446565b611e44565b601354610558906001600160a01b031681565b6103916107cc3660046144a4565b601260209081526000928352604080842090915290825290205481565b6103ca612390565b610391600c5481565b61083e610808366004614446565b601a602052600090815260409020546001600160701b0380821691600160701b810490911690600160e01b900463ffffffff1683565b604080516001600160701b03948516815293909216602084015263ffffffff169082015260600161039b565b610391610878366004614446565b6123b2565b6103ca61088b3660046144a4565b6124b9565b6103ca61089e366004614446565b612621565b61039160175481565b6103ca6108ba366004614446565b612697565b6013546000906001600160a01b03166108da57506000919050565b6001600160a01b0382166000908152601a60209081526040808320815160608101835290546001600160701b038082168352600160701b82041693820193909352600160e01b90920463ffffffff169082015290610937826127fb565b90508060000361095f575050506001600160a01b031660009081526019602052604090205490565b6001600160a01b03841660009081526003602052604081205461098a9061098590612a5c565b6127fb565b6001600160a01b038616600090815260036020908152604080832054601890925282205492935091670de0b6b3a7640000906109c4610eab565b6109ce9190614701565b6109d89084614714565b6109e2919061472b565b905060006109f585858860400151612c08565b6001600160a01b03891660009081526019602052604090205490915085610a1c8684614714565b610a26919061472b565b838311610a335782610a35565b835b610a3f9190614701565b610a49919061474d565b98975050505050505050565b610a5d612dac565b610a65612e05565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b031603610ad05760405162461bcd60e51b8152602060048201526002602482015261114d60f21b60448201526064015b60405180910390fd5b610adb838383612e5f565b82610af06001600160a01b0382168484612eae565b826001600160a01b0316846001600160a01b03167ffff3b3844276f57024e0b42afec1a37f75db36511e43819a4f2a63ab7862b64884604051610b3591815260200190565b60405180910390a350610b486001600055565b505050565b610b55612e05565b600c544211610b8c5760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b610b9581612f11565b50565b6001600160a01b038083166000818152601260209081526040808320948616835293815283822054845163313ce56760e01b81529451929490939263313ce567926004808401939192918290030181865afa158015610bfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1f9190614760565b610c2a90600a614867565b6001600160a01b03808616600090815260116020908152604080832093881683529290522054610c59866123b2565b610c639190614701565b6001600160a01b038516600090815260036020526040902054610c869190614714565b610c90919061472b565b610c9a919061474d565b90505b92915050565b610cab612dac565b80610cb6338261300c565b9150600082118015610cd75750336000908152600360205260409020548211155b8015610cf25750336000908152600360205260409020548111155b610d235760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b600454610d309082614714565b60026000828254610d419190614701565b90915550503360009081526003602052604081208054839290610d65908490614701565b90915550610d9f90506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163384612eae565b60405182815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906020015b60405180910390a250610b956001600055565b610de8612e05565b610df4826000836118a8565b5050565b6001600160a01b0381166000908152600b602052604081205460ff1615610e755760005b600a54811015610e7357826001600160a01b0316600a8281548110610e4357610e43614876565b6000918252602090912001546001600160a01b031603610e635792915050565b610e6c8161488c565b9050610e1c565b505b50600019919050565b60008060075411610e90576000610c9d565b61271060075483610ea19190614714565b610c9d919061472b565b6000600254600014610f8457600254601360009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f0d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f319190614760565b610f3c90600a614867565b601654600e54610f4a6114bf565b610f549190614701565b610f5e9190614714565b610f689190614714565b610f72919061472b565b601754610f7f919061474d565b905090565b5060175490565b60058181548110610f9b57600080fd5b600091825260209091200154905081565b610fb4612dac565b8060005b600a54811015611021576000600a8281548110610fd757610fd7614876565b6000918252602090912001546001600160a01b03169050610ff7816123b2565b6001600160a01b0390911660009081526010602052604090205561101a8161488c565b9050610fb8565b5061102a6114bf565b600e556001600160a01b038116156110d85760005b600a548110156110d6576000600a828154811061105e5761105e614876565b6000918252602090912001546001600160a01b0316905061107f8184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556110cf8161488c565b905061103f565b505b6110e28383613435565b50610df46001600055565b6110f5612dac565b6110fd612e05565b600c544211156111355760405162461bcd60e51b815260206004820152600360248201526208a62760eb1b6044820152606401610ac7565b600042600c5411156111525742600c5461114f9190614701565b90505b42600c5560005b600a548110156111dd576000600a828154811061117857611178614876565b60009182526020808320909101546001600160a01b0316808352600f90915260408220549092508291906111ad908690614714565b905080156111c9576111c96001600160a01b0384168783612eae565b505050806111d69061488c565b9050611159565b506040517f9bad5e1e43bc35e89725967a54f4bc384078248a1ea5c315be3b260a68cbb17a90600090a150610b956001600055565b61121a612e05565b611224600061358a565b565b61122e612dac565b8060005b600a5481101561129b576000600a828154811061125157611251614876565b6000918252602090912001546001600160a01b03169050611271816123b2565b6001600160a01b039091166000908152601060205260409020556112948161488c565b9050611232565b506112a46114bf565b600e556001600160a01b038116156113525760005b600a54811015611350576000600a82815481106112d8576112d8614876565b6000918252602090912001546001600160a01b031690506112f98184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556113498161488c565b90506112b9565b505b60005b600a548110156113a057611390600a828154811061137557611375614876565b6000918252602090912001546001600160a01b031684613435565b6113998161488c565b9050611355565b5050610b956001600055565b6001600160a01b03821660009081526009602052604081205481906113d79063ffffffff1642614701565b90506000805b60055481101561145957600581815481106113fa576113fa614876565b9060005260206000200154831015611449576127106006828154811061142257611422614876565b9060005260206000200154866114389190614714565b611442919061472b565b9150611459565b6114528161488c565b90506113dd565b50949350505050565b600a818154811061147257600080fd5b6000918252602090912001546001600160a01b0316905081565b611494612e05565b6001600160a01b03919091166000908152601b60205260409020805460ff1916911515919091179055565b6000600c5442106114d15750600c5490565b504290565b6114de612e05565b600c5442116115155760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6017541561154b5760405162461bcd60e51b8152602060048201526003602482015262114c8d60ea1b6044820152606401610ac7565b826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115d791906148a5565b6001600160a01b0316148061167e5750826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561164f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061167391906148a5565b6001600160a01b0316145b80156116935750620151808163ffffffff1610155b80156116a75750600d548163ffffffff1611155b6116d95760405162461bcd60e51b815260206004820152600360248201526245313960e81b6044820152606401610ac7565b601380546001600160a01b0319166001600160a01b03949094169390931790925560145563ffffffff16601555565b611710612e05565b611718612dac565b6008805460009091556040518181527f6857c770f3cb43e9c19050a37dd914ec876241c1f4b487d26a1d4f5d3054f49b9060200160405180910390a16117886001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383612eae565b50610b956001600055565b60068181548110610f9b57600080fd5b6117ab612dac565b806117b633826135dc565b91506000821180156117c85750600081115b6117f95760405162461bcd60e51b8152602060048201526002602482015261229960f11b6044820152606401610ac7565b6004546118069083614714565b60026000828254611817919061474d565b9091555050336000908152600360205260408120805484929061183b90849061474d565b9091555061187690506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084613634565b60405182815233907f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d90602001610dcd565b6118b0612e05565b6013546000906001600160a01b031615611cc5576118cc610eab565b6017556118d76114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa15801561196a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198e91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119ec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1091906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611a5857600080fd5b505af1158015611a6c573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611afd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b2191906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ba391906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611beb57600080fd5b505af1158015611bff573d6000803e3d6000fd5b505050506001600160a01b03811615611cc557611c1b816108bf565b6001600160a01b0382166000908152601960209081526040808320939093556017546018825283832055600390522054611c5490612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b611ccf848361366c565b600d546015541115611d095760405162461bcd60e51b815260206004820152600360248201526222991960e91b6044820152606401610ac7565b600d54611d16908461472b565b6016556013546001600160a01b031615801590611d335750600083115b15611e3e576013546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015611d81573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611da591906148c2565b601354909150600090611dc0906001600160a01b0316610df8565b905060008160000b12611df857858160000b81518110611de257611de2614876565b602002602001015182611df59190614701565b91505b600d54611e05908361472b565b6016541115611e3b5760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b50505b50505050565b611e4c612dac565b60135481906001600160a01b03161561226057611e67610eab565b601755611e726114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f2991906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fab91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611ff357600080fd5b505af1158015612007573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612098573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120bc91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561211a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061213e91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b15801561218657600080fd5b505af115801561219a573d6000803e3d6000fd5b505050506001600160a01b03811615612260576121b6816108bf565b6001600160a01b03821660009081526019602090815260408083209390935560175460188252838320556003905220546121ef90612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b6001546001600160a01b03163314806122815750336001600160a01b038316145b6122b35760405162461bcd60e51b8152602060048201526003602482015262114c4d60ea1b6044820152606401610ac7565b6013546001600160a01b03166122f15760405162461bcd60e51b815260206004820152600360248201526245323360e81b6044820152606401610ac7565b6001600160a01b038216600090815260196020526040812054908190036123185750611788565b6001600160a01b0380841660009081526019602052604081205560135461234191168483612eae565b826001600160a01b03167fef4696bdcf47e292773442e4169d670e1b2d0d3f5ceff2a5c1e236c10109ee808260405161237c91815260200190565b60405180910390a25050610b956001600055565b61239933613ac3565b3360009081526003602052604090205461122490610ca3565b60006002546000036123da57506001600160a01b031660009081526010602052604090205490565b600254826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561241b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243f9190614760565b61244a90600a614867565b6001600160a01b0384166000908152600f6020526040902054600e5461246e6114bf565b6124789190614701565b6124829190614714565b61248c9190614714565b612496919061472b565b6001600160a01b038316600090815260106020526040902054610c9d919061474d565b6124c1612e05565b600c5442116124f85760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6002541561252e5760405162461bcd60e51b815260206004820152600360248201526222989960e91b6044820152606401610ac7565b6001600160a01b0382166000908152600b602052604090205460ff1615610df4576040516370a0823160e01b815230600482015282906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015612598573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125bc91906148c2565b905080156125d8576125d86001600160a01b0383168483612eae565b826001600160a01b03167fcaa95c7b01f93ffe197f5e7316a1a2f387c5bfff8cb445095f2110ff5c1b29958260405161261391815260200190565b60405180910390a250505050565b612629612e05565b6001600160a01b03811661268e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610ac7565b610b958161358a565b61269f612e05565b600c5442116126d65760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6002541580156126f057506013546001600160a01b031615155b6127265760405162461bcd60e51b81526020600482015260076024820152664531322f45323360c81b6044820152606401610ac7565b6013546040516370a0823160e01b81523060048201526001600160a01b039091169060009082906370a0823190602401602060405180830381865afa158015612773573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061279791906148c2565b90508015610b48576127b36001600160a01b0383168483612eae565b826001600160a01b03167fcf018d466bd581a77eafe1429d5f079ea9a4a7363785b0561c51c9a8f2925c3c826040516127ee91815260200190565b60405180910390a2505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631421f7307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561288a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128ae91906148a5565b60208501516040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526001600160701b03166024820152604401602060405180830381865afa158015612905573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061292991906148c2565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631421f7307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129da91906148a5565b855160405160e084901b6001600160e01b03191681526001600160a01b0390921660048301526001600160701b03166024820152604401602060405180830381865afa158015612a2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a5291906148c2565b610c9d919061474d565b604080516060810182526000808252602082018190529181019190915260008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015612adc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b0091906148f2565b92509250925060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b8a91906148c2565b9050604051806060016040528082866001600160701b031689612bad9190614714565b612bb7919061472b565b6001600160701b0316815260200182856001600160701b031689612bdb9190614714565b612be5919061472b565b6001600160701b031681526020018363ffffffff16815250945050505050919050565b600080612c1b63ffffffff841642614701565b90506000848611612c2d576000612c37565b612c378587614701565b905060008115612d70577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638c86f1e47f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612cce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cf291906148a5565b60135460405160e084901b6001600160e01b03191681526001600160a01b0392831660048201526024810187905291166044820152606401602060405180830381865afa158015612d47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d6b91906148c2565b612d73565b60005b90506015548310612d88579250612da5915050565b601554612d958483614714565b612d9f919061472b565b93505050505b9392505050565b600260005403612dfe5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610ac7565b6002600055565b6001546001600160a01b031633146112245760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610ac7565b6013546001600160a01b0390811690841603612ea35760405162461bcd60e51b815260206004820152600360248201526222989b60e91b6044820152606401610ac7565b610b48838383613ae6565b6040516001600160a01b038316602482015260448101829052610b4890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613b35565b600a54600f1015612f4a5760405162461bcd60e51b815260206004820152600360248201526245313560e81b6044820152606401610ac7565b6001600160a01b038116612f855760405162461bcd60e51b8152602060048201526002602482015261453160f01b6044820152606401610ac7565b6001600160a01b0381166000908152600b602052604090205460ff16610b9557600a805460018181019092557fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0384166001600160a01b031990911681179091556000908152600b60205260409020805460ff1916909117905550565b60135460009083906001600160a01b0316156134235761302a610eab565b6017556130356114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130ec91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561314a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061316e91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b1580156131b657600080fd5b505af11580156131ca573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561325b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061327f91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132dd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061330191906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b15801561334957600080fd5b505af115801561335d573d6000803e3d6000fd5b505050506001600160a01b0381161561342357613379816108bf565b6001600160a01b03821660009081526019602090815260408083209390935560175460188252838320556003905220546133b290612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b61342d8484613c07565b949350505050565b6001546001600160a01b03163314806134565750336001600160a01b038216145b6134885760405162461bcd60e51b8152602060048201526003602482015262114c4d60ea1b6044820152606401610ac7565b6001600160a01b0382166000908152600b602052604090205460ff166134d65760405162461bcd60e51b815260206004820152600360248201526245313360e81b6044820152606401610ac7565b6001600160a01b038083166000908152601260209081526040808320938516835292905220548015610b48576001600160a01b038084166000818152601260209081526040808320948716835293905291822091909155613538908383612eae565b816001600160a01b0316836001600160a01b03167f540798df468d7b23d11f156fdb954cb19ad414d150722a7b6d55ba369dea792e8360405161357d91815260200190565b60405180910390a3505050565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b0382166000908152601b602052604081205460ff1661362a5760405162461bcd60e51b815260206004820152600360248201526245323560e81b6044820152606401610ac7565b610c9a8383613c86565b6040516001600160a01b0380851660248301528316604482015260648101829052611e3e9085906323b872dd60e01b90608401612eda565b613674612dac565b61367c612e05565b600c5442116136b35760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6000805b600a54811015613720576000600a82815481106136d6576136d6614876565b6000918252602090912001546001600160a01b031690506136f6816123b2565b6001600160a01b039091166000908152601060205260409020556137198161488c565b90506136b7565b506137296114bf565b600e556001600160a01b038116156137d75760005b600a548110156137d5576000600a828154811061375d5761375d614876565b6000918252602090912001546001600160a01b0316905061377e8184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556137ce8161488c565b905061373e565b505b6000821161380d5760405162461bcd60e51b815260206004820152600360248201526204531360ec1b6044820152606401610ac7565b600a548351146138455760405162461bcd60e51b815260206004820152600360248201526245313160e81b6044820152606401610ac7565b600d82905560005b600a54811015613a68576000600a828154811061386c5761386c614876565b600091825260209091200154600d5486516001600160a01b039092169250829187908590811061389e5761389e614876565b60200260200101516138b0919061472b565b6001600160a01b0382166000908152600f6020526040812091909155600a8054859081106138e0576138e0614876565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613931573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061395591906148c2565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316146139ee57600d5461399d908261472b565b6001600160a01b0383166000908152600f602052604090205411156139e95760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b613a54565b600d546002546139fe9083614701565b613a08919061472b565b6001600160a01b0383166000908152600f60205260409020541115613a545760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b50505080613a619061488c565b905061384d565b5042600e819055600d54613a7b9161474d565b600c556040517faab1f55dce0d0e628e283ce1061d0afccffcf61f9c14391c899b5952492ce82190613ab0908590859061492e565b60405180910390a150610df46001600055565b6013546001600160a01b031615613add57613add81611e44565b610b95816140a7565b6001600160a01b0383166000908152600b602052604090205460ff1615610b485760405162461bcd60e51b815260206004820152600360248201526222989b60e91b6044820152606401610ac7565b6000613b8a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166140b09092919063ffffffff16565b805190915015610b485780806020019051810190613ba89190614976565b610b485760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610ac7565b600080613c1484846113ac565b90508015613c73578060086000828254613c2e919061474d565b90915550506040518181526001600160a01b038516907fd0b34aaed5c558a8df736a5aaf9a49b539c4e86fb3ee5a1ac76e0bec23cbdd03906020015b60405180910390a25b61342d84613c818386614701565b919050565b60135460009083906001600160a01b03161561409d57613ca4610eab565b601755613caf6114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613d42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d6691906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613dc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613de891906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015613e3057600080fd5b505af1158015613e44573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ed5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ef991906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f7b91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015613fc357600080fd5b505af1158015613fd7573d6000803e3d6000fd5b505050506001600160a01b0381161561409d57613ff3816108bf565b6001600160a01b038216600090815260196020908152604080832093909355601754601882528383205560039052205461402c90612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b61342d84846140bf565b610b9581611226565b606061342d8484600085614227565b6000600c544211156140f95760405162461bcd60e51b815260206004820152600360248201526208a62760eb1b6044820152606401610ac7565b8260005b600a54811015614166576000600a828154811061411c5761411c614876565b6000918252602090912001546001600160a01b0316905061413c816123b2565b6001600160a01b0390911660009081526010602052604090205561415f8161488c565b90506140fd565b5061416f6114bf565b600e556001600160a01b0381161561421d5760005b600a5481101561421b576000600a82815481106141a3576141a3614876565b6000918252602090912001546001600160a01b031690506141c48184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556142148161488c565b9050614184565b505b61342d8484614302565b6060824710156142885760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610ac7565b600080866001600160a01b031685876040516142a491906149b7565b60006040518083038185875af1925050503d80600081146142e1576040519150601f19603f3d011682016040523d82523d6000602084013e6142e6565b606091505b50915091506142f787838387614393565b979650505050505050565b60008061430e83610e7e565b6001600160a01b0385166000908152600960205260409020805463ffffffff19164263ffffffff1617905590508015613c73578060086000828254614353919061474d565b90915550506040518181526001600160a01b038516907f34f2a7363b1ef64b0b62a223c88cf3f54a68686acfcb9531d7deb46004f37c4690602001613c6a565b606083156144025782516000036143fb576001600160a01b0385163b6143fb5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ac7565b508161342d565b61342d83838151156144175781518083602001fd5b8060405162461bcd60e51b8152600401610ac791906149d3565b6001600160a01b0381168114610b9557600080fd5b60006020828403121561445857600080fd5b8135612da581614431565b60008060006060848603121561447857600080fd5b833561448381614431565b9250602084013561449381614431565b929592945050506040919091013590565b600080604083850312156144b757600080fd5b82356144c281614431565b915060208301356144d281614431565b809150509250929050565b6000602082840312156144ef57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261451d57600080fd5b8135602067ffffffffffffffff8083111561453a5761453a6144f6565b8260051b604051601f19603f8301168101818110848211171561455f5761455f6144f6565b60405293845285810183019383810192508785111561457d57600080fd5b83870191505b848210156142f757813583529183019190830190614583565b600080604083850312156145af57600080fd5b823567ffffffffffffffff8111156145c657600080fd5b6145d28582860161450c565b95602094909401359450505050565b600080604083850312156145f457600080fd5b82356145ff81614431565b946020939093013593505050565b8015158114610b9557600080fd5b6000806040838503121561462e57600080fd5b823561463981614431565b915060208301356144d28161460d565b63ffffffff81168114610b9557600080fd5b60008060006060848603121561467057600080fd5b833561467b81614431565b925060208401359150604084013561469281614649565b809150509250925092565b6000806000606084860312156146b257600080fd5b833567ffffffffffffffff8111156146c957600080fd5b6146d58682870161450c565b9660208601359650604090950135949350505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610c9d57610c9d6146eb565b8082028115828204841417610c9d57610c9d6146eb565b60008261474857634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115610c9d57610c9d6146eb565b60006020828403121561477257600080fd5b815160ff81168114612da557600080fd5b600181815b808511156147be5781600019048211156147a4576147a46146eb565b808516156147b157918102915b93841c9390800290614788565b509250929050565b6000826147d557506001610c9d565b816147e257506000610c9d565b81600181146147f857600281146148025761481e565b6001915050610c9d565b60ff841115614813576148136146eb565b50506001821b610c9d565b5060208310610133831016604e8410600b8410161715614841575081810a610c9d565b61484b8383614783565b806000190482111561485f5761485f6146eb565b029392505050565b6000610c9a60ff8416836147c6565b634e487b7160e01b600052603260045260246000fd5b60006001820161489e5761489e6146eb565b5060010190565b6000602082840312156148b757600080fd5b8151612da581614431565b6000602082840312156148d457600080fd5b5051919050565b80516001600160701b0381168114613c8157600080fd5b60008060006060848603121561490757600080fd5b614910846148db565b925061491e602085016148db565b9150604084015161469281614649565b604080825283519082018190526000906020906060840190828701845b828110156149675781518452928401929084019060010161494b565b50505092019290925292915050565b60006020828403121561498857600080fd5b8151612da58161460d565b60005b838110156149ae578181015183820152602001614996565b50506000910152565b600082516149c9818460208701614993565b9190910192915050565b60208152600082518060208401526149f2816040850160208701614993565b601f01601f1916919091016040019291505056fea2646970667358221220caf5ae5bfc549c81abf2e25839fe5a5772e84a0c442a8fc37ae88c6dc931e75f64736f6c63430008130033a2646970667358221220733176adbb525023069629f57a0edb1df13e2bcdd1c38fc671bf67636622adf264736f6c63430008130033

Deployed Bytecode

0x738369a8ece09312166096e59cdf7451ffa78997013014608060405260043610620000375760003560e01c8063c82e8b95146200003c575b600080fd5b8180156200004957600080fd5b50620000616200005b36600462000187565b6200007d565b6040516001600160a01b03909116815260200160405180910390f35b60008060405180602001620000929062000146565b601f1982820381018352601f909101166040819052620000b89190879060200162000290565b6040516020818303038152906040529050838151602083016000f59150813b620000e157600080fd5b60405163f2fde38b60e01b81526001600160a01b03848116600483015283169063f2fde38b90602401600060405180830381600087803b1580156200012557600080fd5b505af11580156200013a573d6000803e3d6000fd5b50505050509392505050565b6159d880620002b283390190565b634e487b7160e01b600052604160045260246000fd5b80356001600160a01b03811681146200018257600080fd5b919050565b6000806000606084860312156200019d57600080fd5b833567ffffffffffffffff80821115620001b657600080fd5b818601915086601f830112620001cb57600080fd5b813581811115620001e057620001e062000154565b604051601f8201601f19908116603f011681019083821181831017156200020b576200020b62000154565b816040528281528960208487010111156200022557600080fd5b8260208601602083013760006020848301015280975050505050506020840135915062000255604085016200016a565b90509250925092565b6000815160005b8181101562000281576020818501810151868301520162000265565b50600093019283525090919050565b6000620002a9620002a283866200025e565b846200025e565b94935050505056fe60e06040523480156200001157600080fd5b50604051620059d8380380620059d8833981016040819052620000349162000ae3565b60016000558989898989898989898988858585858585838383836200005933620004d9565b6001600160a01b0381166200009a5760405162461bcd60e51b8152602060048201526002602482015261453160f01b60448201526064015b60405180910390fd5b6001600160a01b03811660808190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa158015620000e5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906200010b919062000be8565b6200011890600a62000d29565b6200012c90670de0b6b3a764000062000d3a565b600455506200013d8383836200052b565b505050506000855111620001795760405162461bcd60e51b8152602060048201526002602482015261453960f01b604482015260640162000091565b60005b8551811015620001cc5760008682815181106200019d576200019d62000d5d565b60200260200101519050620001b8816200072a60201b60201c565b50620001c48162000d73565b90506200017c565b505050600d919091555050506001600160a01b03808b1660a05289811660c0528816156200037c57876001600160a01b031660c0516001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200023f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000265919062000d8f565b6001600160a01b03161480620002f25750876001600160a01b031660c0516001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015620002c1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620002e7919062000d8f565b6001600160a01b0316145b620003265760405162461bcd60e51b815260206004820152600360248201526245313960e81b604482015260640162000091565b620151808663ffffffff1610158015620003485750600d548663ffffffff1611155b6200037c5760405162461bcd60e51b815260206004820152600360248201526245323160e81b604482015260640162000091565b60a0516001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa158015620003bd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620003e3919062000d8f565b6001600160a01b031660c0516001600160a01b031663c45a01556040518163ffffffff1660e01b8152600401602060405180830381865afa1580156200042d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000453919062000d8f565b6001600160a01b031614620004915760405162461bcd60e51b815260206004820152600360248201526204532360ec1b604482015260640162000091565b5050601380546001600160a01b0319166001600160a01b039790971696909617909555505060149190915563ffffffff166015555062000e5b9b505050505050505050505050565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b815181511480156200053f5750600a815111155b80156200055257506107d08361ffff1611155b620005855760405162461bcd60e51b8152602060048201526002602482015261453560f01b604482015260640162000091565b600080620005976107d0600162000dad565b905060005b8351811015620006b0578263ffffffff16848281518110620005c257620005c262000d5d565b602002602001015163ffffffff1611620006045760405162461bcd60e51b8152602060048201526002602482015261453760f01b604482015260640162000091565b818582815181106200061a576200061a62000d5d565b602002602001015161ffff16106200065a5760405162461bcd60e51b815260206004820152600260248201526108a760f31b604482015260640162000091565b8381815181106200066f576200066f62000d5d565b602002602001015192508481815181106200068e576200068e62000d5d565b602002602001015161ffff16915080620006a89062000d73565b90506200059c565b508251620006c69060059060208601906200082a565b508351620006dc90600690602087019062000882565b5061ffff85166007556040517fab4c36b25b04e6f8ac9915203aba1048c17841782324a583e98128b8c1c964f3906200071b9087908790879062000dc3565b60405180910390a15050505050565b600a54600f1015620007655760405162461bcd60e51b815260206004820152600360248201526245313560e81b604482015260640162000091565b6001600160a01b038116620007a25760405162461bcd60e51b8152602060048201526002602482015261453160f01b604482015260640162000091565b6001600160a01b0381166000908152600b602052604090205460ff166200082757600a805460018082019092557fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0319166001600160a01b0384169081179091556000908152600b60205260409020805460ff191690911790555b50565b82805482825590600052602060002090810192821562000870579160200282015b8281111562000870578251829063ffffffff169055916020019190600101906200084b565b506200087e929150620008c6565b5090565b82805482825590600052602060002090810192821562000870579160200282015b8281111562000870578251829061ffff16905591602001919060010190620008a3565b5b808211156200087e5760008155600101620008c7565b80516001600160a01b0381168114620008f557600080fd5b919050565b805163ffffffff81168114620008f557600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f191681016001600160401b03811182821017156200095057620009506200090f565b604052919050565b60006001600160401b038211156200097457620009746200090f565b5060051b60200190565b600082601f8301126200099057600080fd5b81516020620009a9620009a38362000958565b62000925565b82815260059290921b84018101918181019086841115620009c957600080fd5b8286015b84811015620009ef57620009e181620008dd565b8352918301918301620009cd565b509695505050505050565b805161ffff81168114620008f557600080fd5b600082601f83011262000a1f57600080fd5b8151602062000a32620009a38362000958565b82815260059290921b8401810191818101908684111562000a5257600080fd5b8286015b84811015620009ef5762000a6a81620009fa565b835291830191830162000a56565b600082601f83011262000a8a57600080fd5b8151602062000a9d620009a38362000958565b82815260059290921b8401810191818101908684111562000abd57600080fd5b8286015b84811015620009ef5762000ad581620008fa565b835291830191830162000ac1565b6000806000806000806000806000806101408b8d03121562000b0457600080fd5b62000b0f8b620008dd565b995062000b1f60208c01620008dd565b985062000b2f60408c01620008dd565b975060608b0151965062000b4660808c01620008fa565b60a08c01519096506001600160401b038082111562000b6457600080fd5b62000b728e838f016200097e565b965060c08d0151955062000b8960e08e01620009fa565b94506101008d015191508082111562000ba157600080fd5b62000baf8e838f0162000a0d565b93506101208d015191508082111562000bc757600080fd5b5062000bd68d828e0162000a78565b9150509295989b9194979a5092959850565b60006020828403121562000bfb57600080fd5b815160ff8116811462000c0d57600080fd5b9392505050565b634e487b7160e01b600052601160045260246000fd5b600181815b8085111562000c6b57816000190482111562000c4f5762000c4f62000c14565b8085161562000c5d57918102915b93841c939080029062000c2f565b509250929050565b60008262000c845750600162000d23565b8162000c935750600062000d23565b816001811462000cac576002811462000cb75762000cd7565b600191505062000d23565b60ff84111562000ccb5762000ccb62000c14565b50506001821b62000d23565b5060208310610133831016604e8410600b841016171562000cfc575081810a62000d23565b62000d08838362000c2a565b806000190482111562000d1f5762000d1f62000c14565b0290505b92915050565b600062000c0d60ff84168362000c73565b60008262000d5857634e487b7160e01b600052601260045260246000fd5b500490565b634e487b7160e01b600052603260045260246000fd5b60006001820162000d885762000d8862000c14565b5060010190565b60006020828403121562000da257600080fd5b62000c0d82620008dd565b8082018082111562000d235762000d2362000c14565b60006060820161ffff80871684526020606081860152828751808552608087019150828901945060005b8181101562000e0d57855185168352948301949183019160010162000ded565b5050858103604087015286518082529082019350915080860160005b8381101562000e4d57815163ffffffff168552938201939082019060010162000e29565b509298975050505050505050565b60805160a05160c051614a3c62000f9c6000396000818161053601528181611557015281816115f30152818161190e01528181611aa101528181611ea90152818161203c0152818161282e0152818161295a01528181612a8001528181612b0a0152818161306c015281816131ff01528181613ce60152613e7901526000818161067f015281816118df0152818161199001528181611a7201528181611b2301528181611e7a01528181611f2b0152818161200d015281816120be015281816127ff0152818161292b01528181612c4301528181612c720152818161303d015281816130ee015281816131d00152818161328101528181613cb701528181613d6801528181613e4a0152613efb0152600081816105fa01528181610a6701528181610d78015281816117610152818161184e01526139590152614a3c6000f3fe608060405234801561001057600080fd5b50600436106103835760003560e01c80637aaeaf7f116101de578063a7309d7d1161010f578063e9fad8ee116100ad578063f2d176391161007c578063f2d176391461087d578063f2fde38b14610890578063f9cb1d04146108a3578063f9ea0778146108ac57600080fd5b8063e9fad8ee146107e9578063ebe2b12b146107f1578063ef2849b3146107fa578063f12297771461086a57600080fd5b8063c8f33c91116100e9578063c8f33c911461078f578063ca42303114610798578063e13d8722146107ab578063e70b9e27146107be57600080fd5b8063a7309d7d14610738578063ab87982714610773578063ad3bc5461461077c57600080fd5b806387e7ed3a1161017c57806399d531e11161015657806399d531e1146106e95780639ce43f90146106f25780639e3582c814610712578063a694fc3a1461072557600080fd5b806387e7ed3a146106bc5780638da5cb5b146106cf5780639003adfe146106e057600080fd5b80637cee932c116101b85780637cee932c146106675780637dc0d1d01461067a57806380faa57d146106a15780638194c178146106a957600080fd5b80637aaeaf7f146106385780637bb7bed11461064b5780637beb3d9f1461065e57600080fd5b8063423c485a116102b85780636b09169511610256578063715018a611610230578063715018a6146105ed57806372f702f3146105f5578063757767d71461061c57806379ee54f71461062557600080fd5b80636b0916951461059c5780636da9c58e146105af5780637035ab98146105c257600080fd5b806354feec3e1161029257806354feec3e1461051e5780635fcbd2851461053157806366aa01ca1461057057806367c0d00f1461059357600080fd5b8063423c485a146104e3578063486e63b1146104f6578063502cd30f146104fe57600080fd5b806327e235e31161032557806333024430116102ff5780633302443014610474578063386a9525146104945780633d3b26031461049d578063415be3b5146104bd57600080fd5b806327e235e31461042e5780632e1a7d4d1461044e5780632e9f06021461046157600080fd5b806318160ddd1161036157806318160ddd146103cc5780631c03e6cc146103d55780631db7efd8146103e8578063211dc32d1461041b57600080fd5b806301f59d161461038857806304a79e48146103a45780631171bda9146103b7575b600080fd5b6103916107d081565b6040519081526020015b60405180910390f35b6103916103b2366004614446565b6108bf565b6103ca6103c5366004614463565b610a55565b005b61039160025481565b6103ca6103e3366004614446565b610b4d565b61040b6103f6366004614446565b600b6020526000908152604090205460ff1681565b604051901515815260200161039b565b6103916104293660046144a4565b610b98565b61039161043c366004614446565b60036020526000908152604090205481565b6103ca61045c3660046144dd565b610ca3565b6103ca61046f36600461459c565b610de0565b610391610482366004614446565b60196020526000908152604090205481565b610391600d5481565b6103916104ab366004614446565b600f6020526000908152604090205481565b6104d06104cb366004614446565b610df8565b60405160009190910b815260200161039b565b6103916104f13660046144dd565b610e7e565b610391610eab565b61039161050c366004614446565b60186020526000908152604090205481565b61039161052c3660046144dd565b610f8b565b6105587f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b03909116815260200161039b565b61040b61057e366004614446565b601b6020526000908152604090205460ff1681565b61039160145481565b6103ca6105aa3660046144a4565b610fac565b6103ca6105bd366004614446565b6110ed565b6103916105d03660046144a4565b601160209081526000928352604080842090915290825290205481565b6103ca611212565b6105587f000000000000000000000000000000000000000000000000000000000000000081565b61039160155481565b6103ca610633366004614446565b611226565b6103916106463660046145e1565b6113ac565b6105586106593660046144dd565b611462565b61039161271081565b6103ca61067536600461461b565b61148c565b6105587f000000000000000000000000000000000000000000000000000000000000000081565b6103916114bf565b6103ca6106b736600461465b565b6114d6565b6103ca6106ca366004614446565b611708565b6001546001600160a01b0316610558565b61039160085481565b61039160165481565b610391610700366004614446565b60106020526000908152604090205481565b6103916107203660046144dd565b611793565b6103ca6107333660046144dd565b6117a3565b61075e610746366004614446565b60096020526000908152604090205463ffffffff1681565b60405163ffffffff909116815260200161039b565b61039160075481565b6103ca61078a36600461469d565b6118a8565b610391600e5481565b6103ca6107a6366004614446565b611e44565b601354610558906001600160a01b031681565b6103916107cc3660046144a4565b601260209081526000928352604080842090915290825290205481565b6103ca612390565b610391600c5481565b61083e610808366004614446565b601a602052600090815260409020546001600160701b0380821691600160701b810490911690600160e01b900463ffffffff1683565b604080516001600160701b03948516815293909216602084015263ffffffff169082015260600161039b565b610391610878366004614446565b6123b2565b6103ca61088b3660046144a4565b6124b9565b6103ca61089e366004614446565b612621565b61039160175481565b6103ca6108ba366004614446565b612697565b6013546000906001600160a01b03166108da57506000919050565b6001600160a01b0382166000908152601a60209081526040808320815160608101835290546001600160701b038082168352600160701b82041693820193909352600160e01b90920463ffffffff169082015290610937826127fb565b90508060000361095f575050506001600160a01b031660009081526019602052604090205490565b6001600160a01b03841660009081526003602052604081205461098a9061098590612a5c565b6127fb565b6001600160a01b038616600090815260036020908152604080832054601890925282205492935091670de0b6b3a7640000906109c4610eab565b6109ce9190614701565b6109d89084614714565b6109e2919061472b565b905060006109f585858860400151612c08565b6001600160a01b03891660009081526019602052604090205490915085610a1c8684614714565b610a26919061472b565b838311610a335782610a35565b835b610a3f9190614701565b610a49919061474d565b98975050505050505050565b610a5d612dac565b610a65612e05565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316836001600160a01b031603610ad05760405162461bcd60e51b8152602060048201526002602482015261114d60f21b60448201526064015b60405180910390fd5b610adb838383612e5f565b82610af06001600160a01b0382168484612eae565b826001600160a01b0316846001600160a01b03167ffff3b3844276f57024e0b42afec1a37f75db36511e43819a4f2a63ab7862b64884604051610b3591815260200190565b60405180910390a350610b486001600055565b505050565b610b55612e05565b600c544211610b8c5760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b610b9581612f11565b50565b6001600160a01b038083166000818152601260209081526040808320948616835293815283822054845163313ce56760e01b81529451929490939263313ce567926004808401939192918290030181865afa158015610bfb573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c1f9190614760565b610c2a90600a614867565b6001600160a01b03808616600090815260116020908152604080832093881683529290522054610c59866123b2565b610c639190614701565b6001600160a01b038516600090815260036020526040902054610c869190614714565b610c90919061472b565b610c9a919061474d565b90505b92915050565b610cab612dac565b80610cb6338261300c565b9150600082118015610cd75750336000908152600360205260409020548211155b8015610cf25750336000908152600360205260409020548111155b610d235760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b600454610d309082614714565b60026000828254610d419190614701565b90915550503360009081526003602052604081208054839290610d65908490614701565b90915550610d9f90506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163384612eae565b60405182815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906020015b60405180910390a250610b956001600055565b610de8612e05565b610df4826000836118a8565b5050565b6001600160a01b0381166000908152600b602052604081205460ff1615610e755760005b600a54811015610e7357826001600160a01b0316600a8281548110610e4357610e43614876565b6000918252602090912001546001600160a01b031603610e635792915050565b610e6c8161488c565b9050610e1c565b505b50600019919050565b60008060075411610e90576000610c9d565b61271060075483610ea19190614714565b610c9d919061472b565b6000600254600014610f8457600254601360009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f0d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f319190614760565b610f3c90600a614867565b601654600e54610f4a6114bf565b610f549190614701565b610f5e9190614714565b610f689190614714565b610f72919061472b565b601754610f7f919061474d565b905090565b5060175490565b60058181548110610f9b57600080fd5b600091825260209091200154905081565b610fb4612dac565b8060005b600a54811015611021576000600a8281548110610fd757610fd7614876565b6000918252602090912001546001600160a01b03169050610ff7816123b2565b6001600160a01b0390911660009081526010602052604090205561101a8161488c565b9050610fb8565b5061102a6114bf565b600e556001600160a01b038116156110d85760005b600a548110156110d6576000600a828154811061105e5761105e614876565b6000918252602090912001546001600160a01b0316905061107f8184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556110cf8161488c565b905061103f565b505b6110e28383613435565b50610df46001600055565b6110f5612dac565b6110fd612e05565b600c544211156111355760405162461bcd60e51b815260206004820152600360248201526208a62760eb1b6044820152606401610ac7565b600042600c5411156111525742600c5461114f9190614701565b90505b42600c5560005b600a548110156111dd576000600a828154811061117857611178614876565b60009182526020808320909101546001600160a01b0316808352600f90915260408220549092508291906111ad908690614714565b905080156111c9576111c96001600160a01b0384168783612eae565b505050806111d69061488c565b9050611159565b506040517f9bad5e1e43bc35e89725967a54f4bc384078248a1ea5c315be3b260a68cbb17a90600090a150610b956001600055565b61121a612e05565b611224600061358a565b565b61122e612dac565b8060005b600a5481101561129b576000600a828154811061125157611251614876565b6000918252602090912001546001600160a01b03169050611271816123b2565b6001600160a01b039091166000908152601060205260409020556112948161488c565b9050611232565b506112a46114bf565b600e556001600160a01b038116156113525760005b600a54811015611350576000600a82815481106112d8576112d8614876565b6000918252602090912001546001600160a01b031690506112f98184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556113498161488c565b90506112b9565b505b60005b600a548110156113a057611390600a828154811061137557611375614876565b6000918252602090912001546001600160a01b031684613435565b6113998161488c565b9050611355565b5050610b956001600055565b6001600160a01b03821660009081526009602052604081205481906113d79063ffffffff1642614701565b90506000805b60055481101561145957600581815481106113fa576113fa614876565b9060005260206000200154831015611449576127106006828154811061142257611422614876565b9060005260206000200154866114389190614714565b611442919061472b565b9150611459565b6114528161488c565b90506113dd565b50949350505050565b600a818154811061147257600080fd5b6000918252602090912001546001600160a01b0316905081565b611494612e05565b6001600160a01b03919091166000908152601b60205260409020805460ff1916911515919091179055565b6000600c5442106114d15750600c5490565b504290565b6114de612e05565b600c5442116115155760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6017541561154b5760405162461bcd60e51b8152602060048201526003602482015262114c8d60ea1b6044820152606401610ac7565b826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115d791906148a5565b6001600160a01b0316148061167e5750826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561164f573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061167391906148a5565b6001600160a01b0316145b80156116935750620151808163ffffffff1610155b80156116a75750600d548163ffffffff1611155b6116d95760405162461bcd60e51b815260206004820152600360248201526245313960e81b6044820152606401610ac7565b601380546001600160a01b0319166001600160a01b03949094169390931790925560145563ffffffff16601555565b611710612e05565b611718612dac565b6008805460009091556040518181527f6857c770f3cb43e9c19050a37dd914ec876241c1f4b487d26a1d4f5d3054f49b9060200160405180910390a16117886001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168383612eae565b50610b956001600055565b60068181548110610f9b57600080fd5b6117ab612dac565b806117b633826135dc565b91506000821180156117c85750600081115b6117f95760405162461bcd60e51b8152602060048201526002602482015261229960f11b6044820152606401610ac7565b6004546118069083614714565b60026000828254611817919061474d565b9091555050336000908152600360205260408120805484929061183b90849061474d565b9091555061187690506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016333084613634565b60405182815233907f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d90602001610dcd565b6118b0612e05565b6013546000906001600160a01b031615611cc5576118cc610eab565b6017556118d76114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa15801561196a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061198e91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156119ec573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611a1091906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611a5857600080fd5b505af1158015611a6c573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015611afd573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b2191906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611b7f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ba391906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611beb57600080fd5b505af1158015611bff573d6000803e3d6000fd5b505050506001600160a01b03811615611cc557611c1b816108bf565b6001600160a01b0382166000908152601960209081526040808320939093556017546018825283832055600390522054611c5490612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b611ccf848361366c565b600d546015541115611d095760405162461bcd60e51b815260206004820152600360248201526222991960e91b6044820152606401610ac7565b600d54611d16908461472b565b6016556013546001600160a01b031615801590611d335750600083115b15611e3e576013546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015611d81573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611da591906148c2565b601354909150600090611dc0906001600160a01b0316610df8565b905060008160000b12611df857858160000b81518110611de257611de2614876565b602002602001015182611df59190614701565b91505b600d54611e05908361472b565b6016541115611e3b5760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b50505b50505050565b611e4c612dac565b60135481906001600160a01b03161561226057611e67610eab565b601755611e726114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f05573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f2991906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015611f87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611fab91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015611ff357600080fd5b505af1158015612007573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612098573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906120bc91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561211a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061213e91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b15801561218657600080fd5b505af115801561219a573d6000803e3d6000fd5b505050506001600160a01b03811615612260576121b6816108bf565b6001600160a01b03821660009081526019602090815260408083209390935560175460188252838320556003905220546121ef90612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b6001546001600160a01b03163314806122815750336001600160a01b038316145b6122b35760405162461bcd60e51b8152602060048201526003602482015262114c4d60ea1b6044820152606401610ac7565b6013546001600160a01b03166122f15760405162461bcd60e51b815260206004820152600360248201526245323360e81b6044820152606401610ac7565b6001600160a01b038216600090815260196020526040812054908190036123185750611788565b6001600160a01b0380841660009081526019602052604081205560135461234191168483612eae565b826001600160a01b03167fef4696bdcf47e292773442e4169d670e1b2d0d3f5ceff2a5c1e236c10109ee808260405161237c91815260200190565b60405180910390a25050610b956001600055565b61239933613ac3565b3360009081526003602052604090205461122490610ca3565b60006002546000036123da57506001600160a01b031660009081526010602052604090205490565b600254826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561241b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061243f9190614760565b61244a90600a614867565b6001600160a01b0384166000908152600f6020526040902054600e5461246e6114bf565b6124789190614701565b6124829190614714565b61248c9190614714565b612496919061472b565b6001600160a01b038316600090815260106020526040902054610c9d919061474d565b6124c1612e05565b600c5442116124f85760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6002541561252e5760405162461bcd60e51b815260206004820152600360248201526222989960e91b6044820152606401610ac7565b6001600160a01b0382166000908152600b602052604090205460ff1615610df4576040516370a0823160e01b815230600482015282906000906001600160a01b038316906370a0823190602401602060405180830381865afa158015612598573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906125bc91906148c2565b905080156125d8576125d86001600160a01b0383168483612eae565b826001600160a01b03167fcaa95c7b01f93ffe197f5e7316a1a2f387c5bfff8cb445095f2110ff5c1b29958260405161261391815260200190565b60405180910390a250505050565b612629612e05565b6001600160a01b03811661268e5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610ac7565b610b958161358a565b61269f612e05565b600c5442116126d65760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6002541580156126f057506013546001600160a01b031615155b6127265760405162461bcd60e51b81526020600482015260076024820152664531322f45323360c81b6044820152606401610ac7565b6013546040516370a0823160e01b81523060048201526001600160a01b039091169060009082906370a0823190602401602060405180830381865afa158015612773573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061279791906148c2565b90508015610b48576127b36001600160a01b0383168483612eae565b826001600160a01b03167fcf018d466bd581a77eafe1429d5f079ea9a4a7363785b0561c51c9a8f2925c3c826040516127ee91815260200190565b60405180910390a2505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631421f7307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561288a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128ae91906148a5565b60208501516040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526001600160701b03166024820152604401602060405180830381865afa158015612905573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061292991906148c2565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316631421f7307f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156129b6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129da91906148a5565b855160405160e084901b6001600160e01b03191681526001600160a01b0390921660048301526001600160701b03166024820152604401602060405180830381865afa158015612a2e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a5291906148c2565b610c9d919061474d565b604080516060810182526000808252602082018190529181019190915260008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630902f1ac6040518163ffffffff1660e01b8152600401606060405180830381865afa158015612adc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b0091906148f2565b92509250925060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612b66573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b8a91906148c2565b9050604051806060016040528082866001600160701b031689612bad9190614714565b612bb7919061472b565b6001600160701b0316815260200182856001600160701b031689612bdb9190614714565b612be5919061472b565b6001600160701b031681526020018363ffffffff16815250945050505050919050565b600080612c1b63ffffffff841642614701565b90506000848611612c2d576000612c37565b612c378587614701565b905060008115612d70577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316638c86f1e47f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015612cce573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612cf291906148a5565b60135460405160e084901b6001600160e01b03191681526001600160a01b0392831660048201526024810187905291166044820152606401602060405180830381865afa158015612d47573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d6b91906148c2565b612d73565b60005b90506015548310612d88579250612da5915050565b601554612d958483614714565b612d9f919061472b565b93505050505b9392505050565b600260005403612dfe5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610ac7565b6002600055565b6001546001600160a01b031633146112245760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152606401610ac7565b6013546001600160a01b0390811690841603612ea35760405162461bcd60e51b815260206004820152600360248201526222989b60e91b6044820152606401610ac7565b610b48838383613ae6565b6040516001600160a01b038316602482015260448101829052610b4890849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152613b35565b600a54600f1015612f4a5760405162461bcd60e51b815260206004820152600360248201526245313560e81b6044820152606401610ac7565b6001600160a01b038116612f855760405162461bcd60e51b8152602060048201526002602482015261453160f01b6044820152606401610ac7565b6001600160a01b0381166000908152600b602052604090205460ff16610b9557600a805460018181019092557fc65a7bb8d6351c1cf70c95a316cc6a92839c986682d98bc35f958f4883f9d2a80180546001600160a01b0384166001600160a01b031990911681179091556000908152600b60205260409020805460ff1916909117905550565b60135460009083906001600160a01b0316156134235761302a610eab565b6017556130356114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156130c8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906130ec91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa15801561314a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061316e91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b1580156131b657600080fd5b505af11580156131ca573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561325b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061327f91906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156132dd573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061330191906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b15801561334957600080fd5b505af115801561335d573d6000803e3d6000fd5b505050506001600160a01b0381161561342357613379816108bf565b6001600160a01b03821660009081526019602090815260408083209390935560175460188252838320556003905220546133b290612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b61342d8484613c07565b949350505050565b6001546001600160a01b03163314806134565750336001600160a01b038216145b6134885760405162461bcd60e51b8152602060048201526003602482015262114c4d60ea1b6044820152606401610ac7565b6001600160a01b0382166000908152600b602052604090205460ff166134d65760405162461bcd60e51b815260206004820152600360248201526245313360e81b6044820152606401610ac7565b6001600160a01b038083166000908152601260209081526040808320938516835292905220548015610b48576001600160a01b038084166000818152601260209081526040808320948716835293905291822091909155613538908383612eae565b816001600160a01b0316836001600160a01b03167f540798df468d7b23d11f156fdb954cb19ad414d150722a7b6d55ba369dea792e8360405161357d91815260200190565b60405180910390a3505050565b600180546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b6001600160a01b0382166000908152601b602052604081205460ff1661362a5760405162461bcd60e51b815260206004820152600360248201526245323560e81b6044820152606401610ac7565b610c9a8383613c86565b6040516001600160a01b0380851660248301528316604482015260648101829052611e3e9085906323b872dd60e01b90608401612eda565b613674612dac565b61367c612e05565b600c5442116136b35760405162461bcd60e51b815260206004820152600360248201526245313760e81b6044820152606401610ac7565b6000805b600a54811015613720576000600a82815481106136d6576136d6614876565b6000918252602090912001546001600160a01b031690506136f6816123b2565b6001600160a01b039091166000908152601060205260409020556137198161488c565b90506136b7565b506137296114bf565b600e556001600160a01b038116156137d75760005b600a548110156137d5576000600a828154811061375d5761375d614876565b6000918252602090912001546001600160a01b0316905061377e8184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556137ce8161488c565b905061373e565b505b6000821161380d5760405162461bcd60e51b815260206004820152600360248201526204531360ec1b6044820152606401610ac7565b600a548351146138455760405162461bcd60e51b815260206004820152600360248201526245313160e81b6044820152606401610ac7565b600d82905560005b600a54811015613a68576000600a828154811061386c5761386c614876565b600091825260209091200154600d5486516001600160a01b039092169250829187908590811061389e5761389e614876565b60200260200101516138b0919061472b565b6001600160a01b0382166000908152600f6020526040812091909155600a8054859081106138e0576138e0614876565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015613931573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061395591906148c2565b90507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316826001600160a01b0316146139ee57600d5461399d908261472b565b6001600160a01b0383166000908152600f602052604090205411156139e95760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b613a54565b600d546002546139fe9083614701565b613a08919061472b565b6001600160a01b0383166000908152600f60205260409020541115613a545760405162461bcd60e51b8152602060048201526002602482015261453360f01b6044820152606401610ac7565b50505080613a619061488c565b905061384d565b5042600e819055600d54613a7b9161474d565b600c556040517faab1f55dce0d0e628e283ce1061d0afccffcf61f9c14391c899b5952492ce82190613ab0908590859061492e565b60405180910390a150610df46001600055565b6013546001600160a01b031615613add57613add81611e44565b610b95816140a7565b6001600160a01b0383166000908152600b602052604090205460ff1615610b485760405162461bcd60e51b815260206004820152600360248201526222989b60e91b6044820152606401610ac7565b6000613b8a826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166140b09092919063ffffffff16565b805190915015610b485780806020019051810190613ba89190614976565b610b485760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610ac7565b600080613c1484846113ac565b90508015613c73578060086000828254613c2e919061474d565b90915550506040518181526001600160a01b038516907fd0b34aaed5c558a8df736a5aaf9a49b539c4e86fb3ee5a1ac76e0bec23cbdd03906020015b60405180910390a25b61342d84613c818386614701565b919050565b60135460009083906001600160a01b03161561409d57613ca4610eab565b601755613caf6114bf565b600e819055507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015613d42573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613d6691906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613dc4573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613de891906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015613e3057600080fd5b505af1158015613e44573d6000803e3d6000fd5b505050507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c640752d7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015613ed5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ef991906148a5565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316633fc8cef36040518163ffffffff1660e01b8152600401602060405180830381865afa158015613f57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613f7b91906148a5565b6040516001600160e01b031960e085901b1681526001600160a01b03928316600482015291166024820152604401600060405180830381600087803b158015613fc357600080fd5b505af1158015613fd7573d6000803e3d6000fd5b505050506001600160a01b0381161561409d57613ff3816108bf565b6001600160a01b038216600090815260196020908152604080832093909355601754601882528383205560039052205461402c90612a5c565b6001600160a01b0382166000908152601a60209081526040918290208351815492850151949093015163ffffffff16600160e01b026001600160e01b036001600160701b03958616600160701b026001600160e01b0319909416959094169490941791909117919091169190911790555b61342d84846140bf565b610b9581611226565b606061342d8484600085614227565b6000600c544211156140f95760405162461bcd60e51b815260206004820152600360248201526208a62760eb1b6044820152606401610ac7565b8260005b600a54811015614166576000600a828154811061411c5761411c614876565b6000918252602090912001546001600160a01b0316905061413c816123b2565b6001600160a01b0390911660009081526010602052604090205561415f8161488c565b90506140fd565b5061416f6114bf565b600e556001600160a01b0381161561421d5760005b600a5481101561421b576000600a82815481106141a3576141a3614876565b6000918252602090912001546001600160a01b031690506141c48184610b98565b6001600160a01b039182166000818152601260209081526040808320958816808452958252808320949094559181526010825282812054601183528382209482529390915220556142148161488c565b9050614184565b505b61342d8484614302565b6060824710156142885760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b6064820152608401610ac7565b600080866001600160a01b031685876040516142a491906149b7565b60006040518083038185875af1925050503d80600081146142e1576040519150601f19603f3d011682016040523d82523d6000602084013e6142e6565b606091505b50915091506142f787838387614393565b979650505050505050565b60008061430e83610e7e565b6001600160a01b0385166000908152600960205260409020805463ffffffff19164263ffffffff1617905590508015613c73578060086000828254614353919061474d565b90915550506040518181526001600160a01b038516907f34f2a7363b1ef64b0b62a223c88cf3f54a68686acfcb9531d7deb46004f37c4690602001613c6a565b606083156144025782516000036143fb576001600160a01b0385163b6143fb5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ac7565b508161342d565b61342d83838151156144175781518083602001fd5b8060405162461bcd60e51b8152600401610ac791906149d3565b6001600160a01b0381168114610b9557600080fd5b60006020828403121561445857600080fd5b8135612da581614431565b60008060006060848603121561447857600080fd5b833561448381614431565b9250602084013561449381614431565b929592945050506040919091013590565b600080604083850312156144b757600080fd5b82356144c281614431565b915060208301356144d281614431565b809150509250929050565b6000602082840312156144ef57600080fd5b5035919050565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261451d57600080fd5b8135602067ffffffffffffffff8083111561453a5761453a6144f6565b8260051b604051601f19603f8301168101818110848211171561455f5761455f6144f6565b60405293845285810183019383810192508785111561457d57600080fd5b83870191505b848210156142f757813583529183019190830190614583565b600080604083850312156145af57600080fd5b823567ffffffffffffffff8111156145c657600080fd5b6145d28582860161450c565b95602094909401359450505050565b600080604083850312156145f457600080fd5b82356145ff81614431565b946020939093013593505050565b8015158114610b9557600080fd5b6000806040838503121561462e57600080fd5b823561463981614431565b915060208301356144d28161460d565b63ffffffff81168114610b9557600080fd5b60008060006060848603121561467057600080fd5b833561467b81614431565b925060208401359150604084013561469281614649565b809150509250925092565b6000806000606084860312156146b257600080fd5b833567ffffffffffffffff8111156146c957600080fd5b6146d58682870161450c565b9660208601359650604090950135949350505050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610c9d57610c9d6146eb565b8082028115828204841417610c9d57610c9d6146eb565b60008261474857634e487b7160e01b600052601260045260246000fd5b500490565b80820180821115610c9d57610c9d6146eb565b60006020828403121561477257600080fd5b815160ff81168114612da557600080fd5b600181815b808511156147be5781600019048211156147a4576147a46146eb565b808516156147b157918102915b93841c9390800290614788565b509250929050565b6000826147d557506001610c9d565b816147e257506000610c9d565b81600181146147f857600281146148025761481e565b6001915050610c9d565b60ff841115614813576148136146eb565b50506001821b610c9d565b5060208310610133831016604e8410600b8410161715614841575081810a610c9d565b61484b8383614783565b806000190482111561485f5761485f6146eb565b029392505050565b6000610c9a60ff8416836147c6565b634e487b7160e01b600052603260045260246000fd5b60006001820161489e5761489e6146eb565b5060010190565b6000602082840312156148b757600080fd5b8151612da581614431565b6000602082840312156148d457600080fd5b5051919050565b80516001600160701b0381168114613c8157600080fd5b60008060006060848603121561490757600080fd5b614910846148db565b925061491e602085016148db565b9150604084015161469281614649565b604080825283519082018190526000906020906060840190828701845b828110156149675781518452928401929084019060010161494b565b50505092019290925292915050565b60006020828403121561498857600080fd5b8151612da58161460d565b60005b838110156149ae578181015183820152602001614996565b50506000910152565b600082516149c9818460208701614993565b9190910192915050565b60208152600082518060208401526149f2816040850160208701614993565b601f01601f1916919091016040019291505056fea2646970667358221220caf5ae5bfc549c81abf2e25839fe5a5772e84a0c442a8fc37ae88c6dc931e75f64736f6c63430008130033a2646970667358221220733176adbb525023069629f57a0edb1df13e2bcdd1c38fc671bf67636622adf264736f6c63430008130033

Deployed ByteCode Sourcemap

102073:935:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;102430:575;;;;;;;;;;-1:-1:-1;102430:575:0;;;;;:::i;:::-;;:::i;:::-;;;-1:-1:-1;;;;;1597:55:1;;;1579:74;;1567:2;1552:18;102430:575:0;;;;;;;;102566:12;102591:21;102646:45;;;;;;;;:::i;:::-;-1:-1:-1;;102646:45:0;;;;;;;;;;;;;;;;102615:106;;102646:45;102706:4;;102646:45;102615:106;;:::i;:::-;;;;;;;;;;;;;102591:130;;102815:5;102804:8;102798:15;102791:4;102781:8;102777:19;102774:1;102766:55;102758:63;;102857:4;102845:17;102835:75;;102893:1;102890;102883:12;102835:75;102933:64;;-1:-1:-1;;;102933:64:0;;-1:-1:-1;;;;;1597:55:1;;;102933:64:0;;;1579:74:1;102933:50:0;;;;;1552:18:1;;102933:64:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;102580:425;102430:575;;;;;:::o;-1:-1:-1:-;;;;;;;;:::o;14:127:1:-;75:10;70:3;66:20;63:1;56:31;106:4;103:1;96:15;130:4;127:1;120:15;146:196;214:20;;-1:-1:-1;;;;;263:54:1;;253:65;;243:93;;332:1;329;322:12;243:93;146:196;;;:::o;347:1073::-;433:6;441;449;502:2;490:9;481:7;477:23;473:32;470:52;;;518:1;515;508:12;470:52;558:9;545:23;587:18;628:2;620:6;617:14;614:34;;;644:1;641;634:12;614:34;682:6;671:9;667:22;657:32;;727:7;720:4;716:2;712:13;708:27;698:55;;749:1;746;739:12;698:55;785:2;772:16;807:2;803;800:10;797:36;;;813:18;;:::i;:::-;888:2;882:9;856:2;942:13;;-1:-1:-1;;938:22:1;;;962:2;934:31;930:40;918:53;;;986:18;;;1006:22;;;983:46;980:72;;;1032:18;;:::i;:::-;1072:10;1068:2;1061:22;1107:2;1099:6;1092:18;1149:7;1142:4;1137:2;1133;1129:11;1125:22;1122:35;1119:55;;;1170:1;1167;1160:12;1119:55;1230:2;1223:4;1219:2;1215:13;1208:4;1200:6;1196:17;1183:50;1277:1;1270:4;1265:2;1257:6;1253:15;1249:26;1242:37;1298:6;1288:16;;;;;;;1351:4;1340:9;1336:20;1323:34;1313:44;;1376:38;1410:2;1399:9;1395:18;1376:38;:::i;:::-;1366:48;;347:1073;;;;;:::o;1664:322::-;1705:3;1743:5;1737:12;1767:1;1777:128;1791:6;1788:1;1785:13;1777:128;;;1888:4;1873:13;;;1869:24;;1863:31;1850:11;;;1843:52;1806:12;1777:128;;;-1:-1:-1;1960:1:1;1924:16;;1949:13;;;-1:-1:-1;1924:16:1;;1664:322;-1:-1:-1;1664:322:1:o;1991:261::-;2166:3;2191:55;2216:29;2241:3;2233:6;2216:29;:::i;:::-;2208:6;2191:55;:::i;:::-;2184:62;1991:261;-1:-1:-1;;;;1991:261:1:o

Swarm Source

ipfs://733176adbb525023069629f57a0edb1df13e2bcdd1c38fc671bf67636622adf2
Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.