Contract 0xe2e239fc02fa9bd61ec12eee9f117482544852e2 2

Txn Hash Method
Block
From
To
Value [Txn Fee]
0x3212f9bc28dafa32d488dfe6ab3d6cfd83f2d9fee3847ece6a0a08c0d40d8f24Set Manager225019972023-06-01 1:06:55322 days 16 hrs ago0xf8e8cc9607bd51f16cecc022775da879447e1fe5 IN  0xe2e239fc02fa9bd61ec12eee9f117482544852e20 BTT23.6025
0xb979e1cddf700f7f5cdfc594fa757070a80bb2996def688319cb3b05a1569e730x60806040225015952023-06-01 0:53:07322 days 16 hrs ago0xf8e8cc9607bd51f16cecc022775da879447e1fe5 IN  Create: ElkFarmFactory0 BTT761.9695
[ Download CSV Export 
Parent Txn Hash Block From To Value
Index Block
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.

Contract Source Code Verified (Exact Match)

Contract Name:
ElkFarmFactory

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]/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: contracts/interfaces/IElkPair.sol

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]/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]/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: 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/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/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/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/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/interfaces/IElkFarmFactory.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 IElkFarmFactory {
    event ContractCreated(address _newContract);
    event ManagerSet(address _farmManager);
    event FeeSet(uint256 _newFee);
    event FeesRecovered(uint256 _balanceRecovered);

    function getFarm(
        address _creator,
        address _lpTokenAddress
    ) external view returns (address);

    function getPermissionedFarm(
        address _creator,
        address _lpTokenAddress
    ) external view returns (address);

    function isFarm(address _farmAddress) external view returns (bool);

    function isPermissionedFarm(address _farmAddress) external view returns (bool);

    function allFarms(uint _index) external view returns (address);

    function allFarmsLength() external view returns (uint256);

    function farmManager() external view returns (address);

    function getCreator(address _farmAddress) external view returns (address);

    function feeToken() external view returns (IERC20);

    function fee() external view returns (uint256);

    function maxFee() external view returns (uint256);

    function oracleAddress() external view returns (address);

    function createNewRewards(
        address _lpTokenAddress,
        address _coverageTokenAddress,
        uint256 _coverageAmount,
        uint32 _coverageVestingDuration,
        address[] memory _rewardTokenAddresses,
        uint256 _rewardsDuration,
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    ) external;

     function createNewPermissonedRewards(
        address _lpTokenAddress,
        address _coverageTokenAddress,
        uint256 _coverageAmount,
        uint32 _coverageVestingDuration,
        address[] memory _rewardTokenAddresses,
        uint256 _rewardsDuration,
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    ) external;

    function setManager(address _managerAddress) external;

    function setFee(uint256 _newFee) external;

    function withdrawFees() external;

    function overrideOwnership(address _farmAddress) external;
}

// 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: @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]/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]/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/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/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/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/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/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);
    }
}

// File: contracts/ElkFactoryHelper.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 contains a helper function that creates new FarmingRewards contracts in the ElkFarmFactory
 * @notice this is a separate contract so that the FarmFactory contract is not too large
 */
library ElkFactoryHelper {
    /**
     * @notice creates a new 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(FarmingRewards).creationCode,
            _abi
        );

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

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

// File: contracts/ElkFarmFactory.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 that is used by users to create FarmingRewards contracts.
 * It stores each farm as it's created, as well as the current owner of each farm.
 * It also contains various uitlity functions for use by Elk.
 */
contract ElkFarmFactory is IElkFarmFactory, Ownable {
    using SafeERC20 for IERC20;
    
    /* ========== STATE VARIABLES ========== */

    /// @notice get list of farms associated with address
    mapping(address => mapping(address => address)) public getFarm;

    /// @notice get list of permissioned farms
    mapping(address => mapping(address => address)) public getPermissionedFarm;

    /// @notice check if given address is a farm
    mapping(address => bool) public isFarm;

    /// @notice check if given address is a permissioned farm
    mapping(address => bool) public isPermissionedFarm;

    /// @notice all farms associated with contract;
    address[] public allFarms;

    /// @notice address of farm manager
    address public farmManager;

    /// @notice get address of farm creator
    mapping(address => address) public getCreator;

    /// @notice ELK token
    IERC20 public feeToken = IERC20(0xeEeEEb57642040bE42185f49C52F7E9B38f8eeeE);

    /// @notice fee in feeToken.
    uint256 public fee = 1000 ether;

    /// @notice maximum allowed fee.
    uint256 public maxFee = 100000 ether;

    /// @notice oracle address
    address public oracleAddress;

    constructor(address _oracleAddress) {
        require(_oracleAddress != address(0), "NO");
        oracleAddress = _oracleAddress;
    }

    /**
     * @notice Main function in the contract. Creates a new FarmingRewards contract, stores the farm address by creator and the given LP token, and also stores the creator of the contract by the new farm address.  This is where the fee is taken from the user.
     * @dev each user is only able to create one FarmingRewards contract per LP token.
     * @param _lpTokenAddress The address of the LP token contract.
     * @param _coverageTokenAddress The address of the ILP coverage token contract.
     * @param _coverageAmount The amount of ILP coverage tokens to be distributed.
     * @param _coverageVestingDuration The duration of the vesting period for the ILP coverage tokens.
     * @param _rewardTokenAddresses The addresses of the reward tokens to be distributed.
     * @param _rewardsDuration The duration of the rewards period.
     * @param _depositFeeBps The deposit fee in basis points.
     * @param _withdrawalFeesBps The withdrawal fees in basis points.
     * @param _withdrawalFeeSchedule The schedule for the withdrawal fees.
     */
    function createNewRewards(
        address _lpTokenAddress,
        address _coverageTokenAddress,
        uint256 _coverageAmount,
        uint32 _coverageVestingDuration,
        address[] memory _rewardTokenAddresses,
        uint256 _rewardsDuration,
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    ) public {
        require(
            getFarm[msg.sender][_lpTokenAddress] == address(0),
            "FE"
        ); // single check is sufficient

        bytes memory abiCode = abi.encode(
            oracleAddress,
            _lpTokenAddress,
            _coverageTokenAddress,
            _coverageAmount,
            _coverageVestingDuration,
            _rewardTokenAddresses,
            _rewardsDuration,
            _depositFeeBps,
            _withdrawalFeesBps,
            _withdrawalFeeSchedule
        );
        bytes32 salt = keccak256(abi.encodePacked(_lpTokenAddress, msg.sender));

        _takeFee();

        address addr = ElkFactoryHelper.createFarmContract(
            abiCode,
            salt,
            farmManager
        );

        isFarm[addr] = true;
        getFarm[msg.sender][_lpTokenAddress] = addr;
        getCreator[addr] = msg.sender;
        allFarms.push(addr);

        emit ContractCreated(addr);
    }

    /**
     * @notice Creates a new PermissionedFarmingRewards contract, stores the farm address by creator and the given LP token, and also stores the creator of the contract by the new farm address.  This is where the fee is taken from the user.
     * @dev each user is only able to create one FarmingRewards contract per LP token.
     * @param _lpTokenAddress The address of the LP token contract.
     * @param _coverageTokenAddress The address of the ILP coverage token contract.
     * @param _coverageAmount The amount of ILP coverage tokens to be distributed.
     * @param _coverageVestingDuration The duration of the vesting period for the ILP coverage tokens.
     * @param _rewardTokenAddresses The addresses of the reward tokens to be distributed.
     * @param _rewardsDuration The duration of the rewards period.
     * @param _depositFeeBps The deposit fee in basis points.
     * @param _withdrawalFeesBps The withdrawal fees in basis points.
     * @param _withdrawalFeeSchedule The schedule for the withdrawal fees.
     */
    function createNewPermissonedRewards(
        address _lpTokenAddress,
        address _coverageTokenAddress,
        uint256 _coverageAmount,
        uint32 _coverageVestingDuration,
        address[] memory _rewardTokenAddresses,
        uint256 _rewardsDuration,
        uint16 _depositFeeBps,
        uint16[] memory _withdrawalFeesBps,
        uint32[] memory _withdrawalFeeSchedule
    ) public {
        require(
            getPermissionedFarm[msg.sender][_lpTokenAddress] == address(0),
            "PE"
        ); // single check is sufficient

        bytes memory abiCode = abi.encode(
            oracleAddress,
            _lpTokenAddress,
            _coverageTokenAddress,
            _coverageAmount,
            _coverageVestingDuration,
            _rewardTokenAddresses,
            _rewardsDuration,
            _depositFeeBps,
            _withdrawalFeesBps,
            _withdrawalFeeSchedule
        );
        bytes32 salt = keccak256(abi.encodePacked(_lpTokenAddress, msg.sender));

        _takeFee();

        address addr = ElkFactoryHelperPermissioned.createFarmContract(
            abiCode,
            salt,
            farmManager
        );

        isPermissionedFarm[addr] = true;
        getPermissionedFarm[msg.sender][_lpTokenAddress] = addr;
        getCreator[addr] = msg.sender;
        allFarms.push(addr);

        emit ContractCreated(addr);
    }

    /**
     * @return the number of farms created
     */
    function allFarmsLength() external view override returns (uint) {
        return allFarms.length;
    }

    /**
     * @notice Utility function to be used by Elk.  Changes which manager contract will be assigned ownership of each farm on creation. This is available in case any updates are made to the FarmManager contract.  Ownership is not changed retroactively, so any created farms will always have the same manager contract.
     * @param _managerAddress The address of the new manager contract.
     * @notice emits a ManagerSet event with the new manager address.
     */
    function setManager(address _managerAddress) external override onlyOwner {
        require(_managerAddress != address(0), "NM");
        farmManager = _managerAddress;
        emit ManagerSet(_managerAddress);
    }

    /**
     * @notice Takes fee for contract creation. Factory must be approved to spend the feeToken before creating a new farm.
     */
    function _takeFee() private {
        require(
            feeToken.balanceOf(msg.sender) >= fee,
            "NB"
        );
        feeToken.safeTransferFrom(msg.sender, address(this), fee);
    }

    /**
     * @notice Utility function used by Elk to change the fee amount charged on contract creation.  Can never be more than the maxFee set stored in the contract.
     * @param _newFee The new fee amount.
     * @notice emits a FeeSet event with the new fee amount.
     */
    function setFee(uint256 _newFee) external onlyOwner {
        require(_newFee < maxFee, "IF");
        fee = _newFee;
        emit FeeSet(_newFee);
    }

    /**
     * @notice Utility function used by Elk to recover the fees gathered by the factory.
     * @notice emits a FeesRecovered event with the amount recovered.
     */
    function withdrawFees() external onlyOwner {
        uint256 balance = feeToken.balanceOf(address(this));
        feeToken.safeTransfer(msg.sender, balance);
        emit FeesRecovered(balance);
    }

    /**
     * @notice Change ownership of a farm, only used by Elk.
     * @param _farmAddress The address of the farm to be changed.
     */
    function overrideOwnership(address _farmAddress) external onlyOwner {
        require(
            isFarm[_farmAddress] || isPermissionedFarm[_farmAddress],
            "NF1"
        );

        address creatorAddress = getCreator[_farmAddress];

        require(creatorAddress != msg.sender, "NF2");
        require(creatorAddress != address(0), "NF3");

        IFarmingRewards rewardsContract = IFarmingRewards(_farmAddress);
        address lpTokenAddress = address(rewardsContract.stakingToken());

        if (isFarm[_farmAddress]) {
            // allows creator to make another farm with same staking token, should we prevent this somehow?
            getFarm[creatorAddress][lpTokenAddress] = address(0);
            getFarm[msg.sender][lpTokenAddress] = _farmAddress;
            getCreator[_farmAddress] = msg.sender;
        } else {
            getPermissionedFarm[creatorAddress][lpTokenAddress] = address(0);
            getPermissionedFarm[msg.sender][lpTokenAddress] = _farmAddress;
            getCreator[_farmAddress] = msg.sender;
        }
    }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"_oracleAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_newContract","type":"address"}],"name":"ContractCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_newFee","type":"uint256"}],"name":"FeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_balanceRecovered","type":"uint256"}],"name":"FeesRecovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_farmManager","type":"address"}],"name":"ManagerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allFarms","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allFarmsLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_lpTokenAddress","type":"address"},{"internalType":"address","name":"_coverageTokenAddress","type":"address"},{"internalType":"uint256","name":"_coverageAmount","type":"uint256"},{"internalType":"uint32","name":"_coverageVestingDuration","type":"uint32"},{"internalType":"address[]","name":"_rewardTokenAddresses","type":"address[]"},{"internalType":"uint256","name":"_rewardsDuration","type":"uint256"},{"internalType":"uint16","name":"_depositFeeBps","type":"uint16"},{"internalType":"uint16[]","name":"_withdrawalFeesBps","type":"uint16[]"},{"internalType":"uint32[]","name":"_withdrawalFeeSchedule","type":"uint32[]"}],"name":"createNewPermissonedRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lpTokenAddress","type":"address"},{"internalType":"address","name":"_coverageTokenAddress","type":"address"},{"internalType":"uint256","name":"_coverageAmount","type":"uint256"},{"internalType":"uint32","name":"_coverageVestingDuration","type":"uint32"},{"internalType":"address[]","name":"_rewardTokenAddresses","type":"address[]"},{"internalType":"uint256","name":"_rewardsDuration","type":"uint256"},{"internalType":"uint16","name":"_depositFeeBps","type":"uint16"},{"internalType":"uint16[]","name":"_withdrawalFeesBps","type":"uint16[]"},{"internalType":"uint32[]","name":"_withdrawalFeeSchedule","type":"uint32[]"}],"name":"createNewRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"farmManager","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getCreator","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"getFarm","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"getPermissionedFarm","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isFarm","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isPermissionedFarm","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oracleAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_farmAddress","type":"address"}],"name":"overrideOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_newFee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_managerAddress","type":"address"}],"name":"setManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawFees","outputs":[],"stateMutability":"nonpayable","type":"function"}]

6080604052600880546001600160a01b03191673eeeeeb57642040be42185f49c52f7e9b38f8eeee179055683635c9adc5dea0000060095569152d02c7e14af6800000600a5534801561005157600080fd5b50604051620019e7380380620019e78339810160408190526100729161012f565b61007b336100df565b6001600160a01b0381166100ba5760405162461bcd60e51b81526020600482015260026024820152614e4f60f01b604482015260640160405180910390fd5b600b80546001600160a01b0319166001600160a01b039290921691909117905561015f565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006020828403121561014157600080fd5b81516001600160a01b038116811461015857600080fd5b9392505050565b611878806200016f6000396000f3fe608060405234801561001057600080fd5b50600436106101475760003560e01c8063715018a6116100c8578063a1d953f71161008c578063d0ebdbe711610066578063d0ebdbe71461032a578063ddca3f431461033d578063f2fde38b1461034657600080fd5b8063a1d953f7146102c0578063a89ae4ba146102f4578063ba7174df1461030757600080fd5b8063715018a6146102635780637bc6d4431461026b578063899af12b146102735780638da5cb5b14610286578063a02103091461029757600080fd5b80634b2d07cf1161010f5780634b2d07cf146101c3578063637012c7146101d6578063647846a51461020957806369fe0e2d1461021c5780636e5a296a1461022f57600080fd5b806301f59d161461014c57806335254289146101685780633ae21bb11461017d57806343acb9a914610190578063476343ee146101bb575b600080fd5b610155600a5481565b6040519081526020015b60405180910390f35b61017b6101763660046114a8565b610359565b005b61017b61018b366004611587565b610665565b6101a361019e3660046115ab565b6108db565b6040516001600160a01b03909116815260200161015f565b61017b610905565b6006546101a3906001600160a01b031681565b6101f96101e4366004611587565b60036020526000908152604090205460ff1681565b604051901515815260200161015f565b6008546101a3906001600160a01b031681565b61017b61022a3660046115ab565b6109cb565b6101a361023d3660046115c4565b60026020908152600092835260408084209091529082529020546001600160a01b031681565b61017b610a3e565b600554610155565b61017b6102813660046114a8565b610a52565b6000546001600160a01b03166101a3565b6101a36102a5366004611587565b6007602052600090815260409020546001600160a01b031681565b6101a36102ce3660046115c4565b60016020908152600092835260408084209091529082529020546001600160a01b031681565b600b546101a3906001600160a01b031681565b6101f9610315366004611587565b60046020526000908152604090205460ff1681565b61017b610338366004611587565b610d43565b61015560095481565b61017b610354366004611587565b610dd4565b3360009081526002602090815260408083206001600160a01b038d8116855292529091205416156103b65760405162461bcd60e51b8152602060048201526002602482015261504560f01b60448201526064015b60405180910390fd5b600b546040516000916103e9916001600160a01b03909116908c908c908c908c908c908c908c908c908c90602001611672565b60408051601f19818403018152908290526bffffffffffffffffffffffff1960608d811b8216602085015233901b1660348301529150600090604801604051602081830303815290604052805190602001209050610445610e4d565b60065460405163c82e8b9560e01b8152600091738369a8ece09312166096e59cdf7451ffa78997019163c82e8b959161049091879187916001600160a01b0390911690600401611789565b602060405180830381865af41580156104ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d191906117bb565b9050600160046000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055508060026000336001600160a01b03166001600160a01b0316815260200190815260200160002060008e6001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055503360076000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055506005819080600181540180825580915050600190039060005260206000200160009091909190916101000a8154816001600160a01b0302191690836001600160a01b031602179055507fcf78cf0d6f3d8371e1075c69c492ab4ec5d8cf23a1a239b6a51a1d00be7ca3128160405161064f91906001600160a01b0391909116815260200190565b60405180910390a1505050505050505050505050565b61066d610f0e565b6001600160a01b03811660009081526003602052604090205460ff16806106ac57506001600160a01b03811660009081526004602052604090205460ff165b6106de5760405162461bcd60e51b81526020600482015260036024820152624e463160e81b60448201526064016103ad565b6001600160a01b038082166000908152600760205260409020541633810361072e5760405162461bcd60e51b815260206004820152600360248201526227231960e91b60448201526064016103ad565b6001600160a01b03811661076a5760405162461bcd60e51b81526020600482015260036024820152624e463360e81b60448201526064016103ad565b60008290506000816001600160a01b03166372f702f36040518163ffffffff1660e01b81526004016020604051808303816000875af11580156107b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107d591906117bb565b6001600160a01b03851660009081526003602052604090205490915060ff1615610869576001600160a01b03808416600090815260016020818152604080842086861680865290835281852080546001600160a01b0319908116909155338087529484528286209186529083528185208054968b1696821687179055948452600790915290912080549092161790556108d5565b6001600160a01b03808416600090815260026020818152604080842086861680865290835281852080546001600160a01b0319908116909155338087529484528286209186529083528185208054968b1696821687179055948452600790915290912080549092161790555b50505050565b600581815481106108eb57600080fd5b6000918252602090912001546001600160a01b0316905081565b61090d610f0e565b6008546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015610956573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061097a91906117d8565b600854909150610994906001600160a01b03163383610f68565b6040518181527f6857c770f3cb43e9c19050a37dd914ec876241c1f4b487d26a1d4f5d3054f49b906020015b60405180910390a150565b6109d3610f0e565b600a548110610a095760405162461bcd60e51b815260206004820152600260248201526124a360f11b60448201526064016103ad565b60098190556040518181527f20461e09b8e557b77e107939f9ce6544698123aad0fc964ac5cc59b7df2e608f906020016109c0565b610a46610f0e565b610a506000610fd0565b565b3360009081526001602090815260408083206001600160a01b038d811685529252909120541615610aaa5760405162461bcd60e51b8152602060048201526002602482015261464560f01b60448201526064016103ad565b600b54604051600091610add916001600160a01b03909116908c908c908c908c908c908c908c908c908c90602001611672565b60408051601f19818403018152908290526bffffffffffffffffffffffff1960608d811b8216602085015233901b1660348301529150600090604801604051602081830303815290604052805190602001209050610b39610e4d565b60065460405163c82e8b9560e01b81526000917340d4014b60dd73c7087d39b895aad2a6985781759163c82e8b9591610b8491879187916001600160a01b0390911690600401611789565b602060405180830381865af4158015610ba1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc591906117bb565b9050600160036000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055508060016000336001600160a01b03166001600160a01b0316815260200190815260200160002060008e6001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055503360076000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055506005819080600181540180825580915050600190039060005260206000200160009091909190916101000a8154816001600160a01b0302191690836001600160a01b031602179055507fcf78cf0d6f3d8371e1075c69c492ab4ec5d8cf23a1a239b6a51a1d00be7ca3128160405161064f91906001600160a01b0391909116815260200190565b610d4b610f0e565b6001600160a01b038116610d865760405162461bcd60e51b81526020600482015260026024820152614e4d60f01b60448201526064016103ad565b600680546001600160a01b0319166001600160a01b0383169081179091556040519081527f60a0f5b9f9e81e98216071b85826681c796256fe3d1354ecb675580fba64fa69906020016109c0565b610ddc610f0e565b6001600160a01b038116610e415760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103ad565b610e4a81610fd0565b50565b6009546008546040516370a0823160e01b81523360048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610e98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ebc91906117d8565b1015610eef5760405162461bcd60e51b8152602060048201526002602482015261272160f11b60448201526064016103ad565b600954600854610a50916001600160a01b039091169033903090611020565b6000546001600160a01b03163314610a505760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016103ad565b6040516001600160a01b038316602482015260448101829052610fcb90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611058565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526108d59085906323b872dd60e01b90608401610f94565b60006110ad826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661112a9092919063ffffffff16565b805190915015610fcb57808060200190518101906110cb91906117f1565b610fcb5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016103ad565b60606111398484600085611141565b949350505050565b6060824710156111a25760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016103ad565b600080866001600160a01b031685876040516111be9190611813565b60006040518083038185875af1925050503d80600081146111fb576040519150601f19603f3d011682016040523d82523d6000602084013e611200565b606091505b50915091506112118783838761121c565b979650505050505050565b6060831561128b578251600003611284576001600160a01b0385163b6112845760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103ad565b5081611139565b61113983838151156112a05781518083602001fd5b8060405162461bcd60e51b81526004016103ad919061182f565b6001600160a01b0381168114610e4a57600080fd5b80356112da816112ba565b919050565b803563ffffffff811681146112da57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611332576113326112f3565b604052919050565b600067ffffffffffffffff821115611354576113546112f3565b5060051b60200190565b600082601f83011261136f57600080fd5b8135602061138461137f8361133a565b611309565b82815260059290921b840181019181810190868411156113a357600080fd5b8286015b848110156113c75780356113ba816112ba565b83529183019183016113a7565b509695505050505050565b803561ffff811681146112da57600080fd5b600082601f8301126113f557600080fd5b8135602061140561137f8361133a565b82815260059290921b8401810191818101908684111561142457600080fd5b8286015b848110156113c757611439816113d2565b8352918301918301611428565b600082601f83011261145757600080fd5b8135602061146761137f8361133a565b82815260059290921b8401810191818101908684111561148657600080fd5b8286015b848110156113c75761149b816112df565b835291830191830161148a565b60008060008060008060008060006101208a8c0312156114c757600080fd5b6114d08a6112cf565b98506114de60208b016112cf565b975060408a013596506114f360608b016112df565b955060808a013567ffffffffffffffff8082111561151057600080fd5b61151c8d838e0161135e565b965060a08c0135955061153160c08d016113d2565b945060e08c013591508082111561154757600080fd5b6115538d838e016113e4565b93506101008c013591508082111561156a57600080fd5b506115778c828d01611446565b9150509295985092959850929598565b60006020828403121561159957600080fd5b81356115a4816112ba565b9392505050565b6000602082840312156115bd57600080fd5b5035919050565b600080604083850312156115d757600080fd5b82356115e2816112ba565b915060208301356115f2816112ba565b809150509250929050565b600081518084526020808501945080840160005b8381101561163157815161ffff1687529582019590820190600101611611565b509495945050505050565b600081518084526020808501945080840160005b8381101561163157815163ffffffff1687529582019590820190600101611650565b60006101408083016001600160a01b03808f1685526020818f1681870152818e1660408701528c606087015263ffffffff8c1660808701528360a08701528293508a5180845261016087019450818c01935060005b818110156116e55784518416865294820194938201936001016116c7565b50505050508660c084015261170060e084018761ffff169052565b82810361010084015261171381866115fd565b9050828103610120840152611728818561163c565b9d9c50505050505050505050505050565b60005b8381101561175457818101518382015260200161173c565b50506000910152565b60008151808452611775816020860160208601611739565b601f01601f19169290920160200192915050565b60608152600061179c606083018661175d565b90508360208301526001600160a01b0383166040830152949350505050565b6000602082840312156117cd57600080fd5b81516115a4816112ba565b6000602082840312156117ea57600080fd5b5051919050565b60006020828403121561180357600080fd5b815180151581146115a457600080fd5b60008251611825818460208701611739565b9190910192915050565b6020815260006115a4602083018461175d56fea26469706673582212202c8051155a71d617f8a68b7b253702bb3594dcce008ce15ac2ae8e693cd6cdcf64736f6c634300081300330000000000000000000000008d09759d54a17aa31987a68f24fae2a4c41a3203

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101475760003560e01c8063715018a6116100c8578063a1d953f71161008c578063d0ebdbe711610066578063d0ebdbe71461032a578063ddca3f431461033d578063f2fde38b1461034657600080fd5b8063a1d953f7146102c0578063a89ae4ba146102f4578063ba7174df1461030757600080fd5b8063715018a6146102635780637bc6d4431461026b578063899af12b146102735780638da5cb5b14610286578063a02103091461029757600080fd5b80634b2d07cf1161010f5780634b2d07cf146101c3578063637012c7146101d6578063647846a51461020957806369fe0e2d1461021c5780636e5a296a1461022f57600080fd5b806301f59d161461014c57806335254289146101685780633ae21bb11461017d57806343acb9a914610190578063476343ee146101bb575b600080fd5b610155600a5481565b6040519081526020015b60405180910390f35b61017b6101763660046114a8565b610359565b005b61017b61018b366004611587565b610665565b6101a361019e3660046115ab565b6108db565b6040516001600160a01b03909116815260200161015f565b61017b610905565b6006546101a3906001600160a01b031681565b6101f96101e4366004611587565b60036020526000908152604090205460ff1681565b604051901515815260200161015f565b6008546101a3906001600160a01b031681565b61017b61022a3660046115ab565b6109cb565b6101a361023d3660046115c4565b60026020908152600092835260408084209091529082529020546001600160a01b031681565b61017b610a3e565b600554610155565b61017b6102813660046114a8565b610a52565b6000546001600160a01b03166101a3565b6101a36102a5366004611587565b6007602052600090815260409020546001600160a01b031681565b6101a36102ce3660046115c4565b60016020908152600092835260408084209091529082529020546001600160a01b031681565b600b546101a3906001600160a01b031681565b6101f9610315366004611587565b60046020526000908152604090205460ff1681565b61017b610338366004611587565b610d43565b61015560095481565b61017b610354366004611587565b610dd4565b3360009081526002602090815260408083206001600160a01b038d8116855292529091205416156103b65760405162461bcd60e51b8152602060048201526002602482015261504560f01b60448201526064015b60405180910390fd5b600b546040516000916103e9916001600160a01b03909116908c908c908c908c908c908c908c908c908c90602001611672565b60408051601f19818403018152908290526bffffffffffffffffffffffff1960608d811b8216602085015233901b1660348301529150600090604801604051602081830303815290604052805190602001209050610445610e4d565b60065460405163c82e8b9560e01b8152600091738369a8ece09312166096e59cdf7451ffa78997019163c82e8b959161049091879187916001600160a01b0390911690600401611789565b602060405180830381865af41580156104ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104d191906117bb565b9050600160046000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055508060026000336001600160a01b03166001600160a01b0316815260200190815260200160002060008e6001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055503360076000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055506005819080600181540180825580915050600190039060005260206000200160009091909190916101000a8154816001600160a01b0302191690836001600160a01b031602179055507fcf78cf0d6f3d8371e1075c69c492ab4ec5d8cf23a1a239b6a51a1d00be7ca3128160405161064f91906001600160a01b0391909116815260200190565b60405180910390a1505050505050505050505050565b61066d610f0e565b6001600160a01b03811660009081526003602052604090205460ff16806106ac57506001600160a01b03811660009081526004602052604090205460ff165b6106de5760405162461bcd60e51b81526020600482015260036024820152624e463160e81b60448201526064016103ad565b6001600160a01b038082166000908152600760205260409020541633810361072e5760405162461bcd60e51b815260206004820152600360248201526227231960e91b60448201526064016103ad565b6001600160a01b03811661076a5760405162461bcd60e51b81526020600482015260036024820152624e463360e81b60448201526064016103ad565b60008290506000816001600160a01b03166372f702f36040518163ffffffff1660e01b81526004016020604051808303816000875af11580156107b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107d591906117bb565b6001600160a01b03851660009081526003602052604090205490915060ff1615610869576001600160a01b03808416600090815260016020818152604080842086861680865290835281852080546001600160a01b0319908116909155338087529484528286209186529083528185208054968b1696821687179055948452600790915290912080549092161790556108d5565b6001600160a01b03808416600090815260026020818152604080842086861680865290835281852080546001600160a01b0319908116909155338087529484528286209186529083528185208054968b1696821687179055948452600790915290912080549092161790555b50505050565b600581815481106108eb57600080fd5b6000918252602090912001546001600160a01b0316905081565b61090d610f0e565b6008546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a0823190602401602060405180830381865afa158015610956573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061097a91906117d8565b600854909150610994906001600160a01b03163383610f68565b6040518181527f6857c770f3cb43e9c19050a37dd914ec876241c1f4b487d26a1d4f5d3054f49b906020015b60405180910390a150565b6109d3610f0e565b600a548110610a095760405162461bcd60e51b815260206004820152600260248201526124a360f11b60448201526064016103ad565b60098190556040518181527f20461e09b8e557b77e107939f9ce6544698123aad0fc964ac5cc59b7df2e608f906020016109c0565b610a46610f0e565b610a506000610fd0565b565b3360009081526001602090815260408083206001600160a01b038d811685529252909120541615610aaa5760405162461bcd60e51b8152602060048201526002602482015261464560f01b60448201526064016103ad565b600b54604051600091610add916001600160a01b03909116908c908c908c908c908c908c908c908c908c90602001611672565b60408051601f19818403018152908290526bffffffffffffffffffffffff1960608d811b8216602085015233901b1660348301529150600090604801604051602081830303815290604052805190602001209050610b39610e4d565b60065460405163c82e8b9560e01b81526000917340d4014b60dd73c7087d39b895aad2a6985781759163c82e8b9591610b8491879187916001600160a01b0390911690600401611789565b602060405180830381865af4158015610ba1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bc591906117bb565b9050600160036000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055508060016000336001600160a01b03166001600160a01b0316815260200190815260200160002060008e6001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055503360076000836001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a8154816001600160a01b0302191690836001600160a01b031602179055506005819080600181540180825580915050600190039060005260206000200160009091909190916101000a8154816001600160a01b0302191690836001600160a01b031602179055507fcf78cf0d6f3d8371e1075c69c492ab4ec5d8cf23a1a239b6a51a1d00be7ca3128160405161064f91906001600160a01b0391909116815260200190565b610d4b610f0e565b6001600160a01b038116610d865760405162461bcd60e51b81526020600482015260026024820152614e4d60f01b60448201526064016103ad565b600680546001600160a01b0319166001600160a01b0383169081179091556040519081527f60a0f5b9f9e81e98216071b85826681c796256fe3d1354ecb675580fba64fa69906020016109c0565b610ddc610f0e565b6001600160a01b038116610e415760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016103ad565b610e4a81610fd0565b50565b6009546008546040516370a0823160e01b81523360048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610e98573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610ebc91906117d8565b1015610eef5760405162461bcd60e51b8152602060048201526002602482015261272160f11b60448201526064016103ad565b600954600854610a50916001600160a01b039091169033903090611020565b6000546001600160a01b03163314610a505760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016103ad565b6040516001600160a01b038316602482015260448101829052610fcb90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611058565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6040516001600160a01b03808516602483015283166044820152606481018290526108d59085906323b872dd60e01b90608401610f94565b60006110ad826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661112a9092919063ffffffff16565b805190915015610fcb57808060200190518101906110cb91906117f1565b610fcb5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b60648201526084016103ad565b60606111398484600085611141565b949350505050565b6060824710156111a25760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b60648201526084016103ad565b600080866001600160a01b031685876040516111be9190611813565b60006040518083038185875af1925050503d80600081146111fb576040519150601f19603f3d011682016040523d82523d6000602084013e611200565b606091505b50915091506112118783838761121c565b979650505050505050565b6060831561128b578251600003611284576001600160a01b0385163b6112845760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000060448201526064016103ad565b5081611139565b61113983838151156112a05781518083602001fd5b8060405162461bcd60e51b81526004016103ad919061182f565b6001600160a01b0381168114610e4a57600080fd5b80356112da816112ba565b919050565b803563ffffffff811681146112da57600080fd5b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff81118282101715611332576113326112f3565b604052919050565b600067ffffffffffffffff821115611354576113546112f3565b5060051b60200190565b600082601f83011261136f57600080fd5b8135602061138461137f8361133a565b611309565b82815260059290921b840181019181810190868411156113a357600080fd5b8286015b848110156113c75780356113ba816112ba565b83529183019183016113a7565b509695505050505050565b803561ffff811681146112da57600080fd5b600082601f8301126113f557600080fd5b8135602061140561137f8361133a565b82815260059290921b8401810191818101908684111561142457600080fd5b8286015b848110156113c757611439816113d2565b8352918301918301611428565b600082601f83011261145757600080fd5b8135602061146761137f8361133a565b82815260059290921b8401810191818101908684111561148657600080fd5b8286015b848110156113c75761149b816112df565b835291830191830161148a565b60008060008060008060008060006101208a8c0312156114c757600080fd5b6114d08a6112cf565b98506114de60208b016112cf565b975060408a013596506114f360608b016112df565b955060808a013567ffffffffffffffff8082111561151057600080fd5b61151c8d838e0161135e565b965060a08c0135955061153160c08d016113d2565b945060e08c013591508082111561154757600080fd5b6115538d838e016113e4565b93506101008c013591508082111561156a57600080fd5b506115778c828d01611446565b9150509295985092959850929598565b60006020828403121561159957600080fd5b81356115a4816112ba565b9392505050565b6000602082840312156115bd57600080fd5b5035919050565b600080604083850312156115d757600080fd5b82356115e2816112ba565b915060208301356115f2816112ba565b809150509250929050565b600081518084526020808501945080840160005b8381101561163157815161ffff1687529582019590820190600101611611565b509495945050505050565b600081518084526020808501945080840160005b8381101561163157815163ffffffff1687529582019590820190600101611650565b60006101408083016001600160a01b03808f1685526020818f1681870152818e1660408701528c606087015263ffffffff8c1660808701528360a08701528293508a5180845261016087019450818c01935060005b818110156116e55784518416865294820194938201936001016116c7565b50505050508660c084015261170060e084018761ffff169052565b82810361010084015261171381866115fd565b9050828103610120840152611728818561163c565b9d9c50505050505050505050505050565b60005b8381101561175457818101518382015260200161173c565b50506000910152565b60008151808452611775816020860160208601611739565b601f01601f19169290920160200192915050565b60608152600061179c606083018661175d565b90508360208301526001600160a01b0383166040830152949350505050565b6000602082840312156117cd57600080fd5b81516115a4816112ba565b6000602082840312156117ea57600080fd5b5051919050565b60006020828403121561180357600080fd5b815180151581146115a457600080fd5b60008251611825818460208701611739565b9190910192915050565b6020815260006115a4602083018461175d56fea26469706673582212202c8051155a71d617f8a68b7b253702bb3594dcce008ce15ac2ae8e693cd6cdcf64736f6c63430008130033

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

0000000000000000000000008d09759d54a17aa31987a68f24fae2a4c41a3203

-----Decoded View---------------
Arg [0] : _oracleAddress (address): 0x8d09759d54a17aa31987a68f24fae2a4c41a3203

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000008d09759d54a17aa31987a68f24fae2a4c41a3203


Library Used


ElkFactoryHelperPermissioned : 0x8369a8ece09312166096e59cdf7451ffa7899701


Deployed ByteCode Sourcemap

107295:9661:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;108409:36;;;;;;;;;160:25:1;;;148:2;133:18;108409:36:0;;;;;;;;112193:1437;;;;;;:::i;:::-;;:::i;:::-;;115863:1090;;;;;;:::i;:::-;;:::i;107977:25::-;;;;;;:::i;:::-;;:::i;:::-;;;-1:-1:-1;;;;;5367:55:1;;;5349:74;;5337:2;5322:18;107977:25:0;5203:226:1;115504:204:0;;;:::i;108052:26::-;;;;;-1:-1:-1;;;;;108052:26:0;;;107755:38;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;5599:14:1;;5592:22;5574:41;;5562:2;5547:18;107755:38:0;5434:187:1;108213:75:0;;;;;-1:-1:-1;;;;;108213:75:0;;;115160:157;;;;;;:::i;:::-;;:::i;107622:74::-;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;107622:74:0;;;54437:103;;;:::i;113700:105::-;113782:8;:15;113700:105;;109748:1378;;;;;;:::i;:::-;;:::i;53789:87::-;53835:7;53862:6;-1:-1:-1;;;;;53862:6:0;53789:87;;108132:45;;;;;;:::i;:::-;;;;;;;;;;;;-1:-1:-1;;;;;108132:45:0;;;107503:62;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;107503:62:0;;;108486:28;;;;;-1:-1:-1;;;;;108486:28:0;;;107865:50;;;;;;:::i;:::-;;;;;;;;;;;;;;;;114293:219;;;;;;:::i;:::-;;:::i;108331:31::-;;;;;;54695:201;;;;;;:::i;:::-;;:::i;112193:1437::-;112657:10;112697:1;112637:31;;;:19;:31;;;;;;;;-1:-1:-1;;;;;112637:48:0;;;;;;;;;;;;:62;112615:114;;;;-1:-1:-1;;;112615:114:0;;6466:2:1;112615:114:0;;;6448:21:1;6505:1;6485:18;;;6478:29;-1:-1:-1;;;6523:18:1;;;6516:32;6565:18;;112615:114:0;;;;;;;;;112820:13;;112795:350;;112772:20;;112795:350;;-1:-1:-1;;;;;112820:13:0;;;;112848:15;;112878:21;;112914:15;;112944:24;;112983:21;;113019:16;;113050:14;;113079:18;;113112:22;;112795:350;;;:::i;:::-;;;;-1:-1:-1;;112795:350:0;;;;;;;;;;-1:-1:-1;;9478:2:1;9474:15;;;9470:24;;112795:350:0;113181:45;;9458:37:1;113215:10:0;9529:15:1;;9525:24;9511:12;;;9504:46;112795:350:0;-1:-1:-1;113156:12:0;;9566::1;;113181:45:0;;;;;;;;;;;;113171:56;;;;;;113156:71;;113240:10;:8;:10::i;:::-;113381:11;;113278:125;;-1:-1:-1;;;113278:125:0;;113263:12;;113278:28;;:47;;:125;;113340:7;;113362:4;;-1:-1:-1;;;;;113381:11:0;;;;113278:125;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;113263:140;;113443:4;113416:18;:24;113435:4;-1:-1:-1;;;;;113416:24:0;-1:-1:-1;;;;;113416:24:0;;;;;;;;;;;;;:31;;;;;;;;;;;;;;;;;;113509:4;113458:19;:31;113478:10;-1:-1:-1;;;;;113458:31:0;-1:-1:-1;;;;;113458:31:0;;;;;;;;;;;;:48;113490:15;-1:-1:-1;;;;;113458:48:0;-1:-1:-1;;;;;113458:48:0;;;;;;;;;;;;;:55;;;;;-1:-1:-1;;;;;113458:55:0;;;;;-1:-1:-1;;;;;113458:55:0;;;;;;113543:10;113524;:16;113535:4;-1:-1:-1;;;;;113524:16:0;-1:-1:-1;;;;;113524:16:0;;;;;;;;;;;;;:29;;;;;-1:-1:-1;;;;;113524:29:0;;;;;-1:-1:-1;;;;;113524:29:0;;;;;;113564:8;113578:4;113564:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;113564:19:0;;;;;-1:-1:-1;;;;;113564:19:0;;;;;;113601:21;113617:4;113601:21;;;;;-1:-1:-1;;;;;5367:55:1;;;;5349:74;;5337:2;5322:18;;5203:226;113601:21:0;;;;;;;;112604:1026;;;112193:1437;;;;;;;;;:::o;115863:1090::-;53675:13;:11;:13::i;:::-;-1:-1:-1;;;;;115964:20:0;::::1;;::::0;;;:6:::1;:20;::::0;;;;;::::1;;::::0;:56:::1;;-1:-1:-1::0;;;;;;115988:32:0;::::1;;::::0;;;:18:::1;:32;::::0;;;;;::::1;;115964:56;115942:109;;;::::0;-1:-1:-1;;;115942:109:0;;10998:2:1;115942:109:0::1;::::0;::::1;10980:21:1::0;11037:1;11017:18;;;11010:29;-1:-1:-1;;;11055:18:1;;;11048:33;11098:18;;115942:109:0::1;10796:326:1::0;115942:109:0::1;-1:-1:-1::0;;;;;116089:24:0;;::::1;116064:22;116089:24:::0;;;:10:::1;:24;::::0;;;;;::::1;116152:10;116134:28:::0;;116126:44:::1;;;::::0;-1:-1:-1;;;116126:44:0;;11329:2:1;116126:44:0::1;::::0;::::1;11311:21:1::0;11368:1;11348:18;;;11341:29;-1:-1:-1;;;11386:18:1;;;11379:33;11429:18;;116126:44:0::1;11127:326:1::0;116126:44:0::1;-1:-1:-1::0;;;;;116189:28:0;::::1;116181:44;;;::::0;-1:-1:-1;;;116181:44:0;;11660:2:1;116181:44:0::1;::::0;::::1;11642:21:1::0;11699:1;11679:18;;;11672:29;-1:-1:-1;;;11717:18:1;;;11710:33;11760:18;;116181:44:0::1;11458:326:1::0;116181:44:0::1;116238:31;116288:12;116238:63;;116312:22;116345:15;-1:-1:-1::0;;;;;116345:28:0::1;;:30;;;;;;;;;;;;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;-1:-1:-1::0;;;;;116393:20:0;::::1;;::::0;;;:6:::1;:20;::::0;;;;;116312:64;;-1:-1:-1;116393:20:0::1;;116389:557;;;-1:-1:-1::0;;;;;116539:23:0;;::::1;116589:1;116539:23:::0;;;:7:::1;:23;::::0;;;;;;;:39;;::::1;::::0;;;;;;;;;:52;;-1:-1:-1;;;;;;116539:52:0;;::::1;::::0;;;116614:10:::1;116606:19:::0;;;;;;;;;:35;;;;;;;;;:50;;;;::::1;::::0;;::::1;::::0;::::1;::::0;;116671:24;;;:10:::1;:24:::0;;;;;;:37;;;;::::1;;::::0;;116389:557:::1;;;-1:-1:-1::0;;;;;116741:35:0;;::::1;116803:1;116741:35:::0;;;:19:::1;:35;::::0;;;;;;;:51;;::::1;::::0;;;;;;;;;:64;;-1:-1:-1;;;;;;116741:64:0;;::::1;::::0;;;116840:10:::1;116820:31:::0;;;;;;;;;:47;;;;;;;;;:62;;;;::::1;::::0;;::::1;::::0;::::1;::::0;;116897:24;;;:10:::1;:24:::0;;;;;;:37;;;;::::1;;::::0;;116389:557:::1;115931:1022;;;115863:1090:::0;:::o;107977:25::-;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;107977:25:0;;-1:-1:-1;107977:25:0;:::o;115504:204::-;53675:13;:11;:13::i;:::-;115576:8:::1;::::0;:33:::1;::::0;-1:-1:-1;;;115576:33:0;;115603:4:::1;115576:33;::::0;::::1;5349:74:1::0;115558:15:0::1;::::0;-1:-1:-1;;;;;115576:8:0::1;::::0;:18:::1;::::0;5322::1;;115576:33:0::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;115620:8;::::0;115558:51;;-1:-1:-1;115620:42:0::1;::::0;-1:-1:-1;;;;;115620:8:0::1;115642:10;115558:51:::0;115620:21:::1;:42::i;:::-;115678:22;::::0;160:25:1;;;115678:22:0::1;::::0;148:2:1;133:18;115678:22:0::1;;;;;;;;115547:161;115504:204::o:0;115160:157::-;53675:13;:11;:13::i;:::-;115241:6:::1;;115231:7;:16;115223:31;;;::::0;-1:-1:-1;;;115223:31:0;;12450:2:1;115223:31:0::1;::::0;::::1;12432:21:1::0;12489:1;12469:18;;;12462:29;-1:-1:-1;;;12507:18:1;;;12500:32;12549:18;;115223:31:0::1;12248:325:1::0;115223:31:0::1;115265:3;:13:::0;;;115294:15:::1;::::0;160:25:1;;;115294:15:0::1;::::0;148:2:1;133:18;115294:15:0::1;14:177:1::0;54437:103:0;53675:13;:11;:13::i;:::-;54502:30:::1;54529:1;54502:18;:30::i;:::-;54437:103::o:0;109748:1378::-;110189:10;110229:1;110181:19;;;:7;:19;;;;;;;;-1:-1:-1;;;;;110181:36:0;;;;;;;;;;;;:50;110159:102;;;;-1:-1:-1;;;110159:102:0;;12780:2:1;110159:102:0;;;12762:21:1;12819:1;12799:18;;;12792:29;-1:-1:-1;;;12837:18:1;;;12830:32;12879:18;;110159:102:0;12578:325:1;110159:102:0;110352:13;;110327:350;;110304:20;;110327:350;;-1:-1:-1;;;;;110352:13:0;;;;110380:15;;110410:21;;110446:15;;110476:24;;110515:21;;110551:16;;110582:14;;110611:18;;110644:22;;110327:350;;;:::i;:::-;;;;-1:-1:-1;;110327:350:0;;;;;;;;;;-1:-1:-1;;9478:2:1;9474:15;;;9470:24;;110327:350:0;110713:45;;9458:37:1;110747:10:0;9529:15:1;;9525:24;9511:12;;;9504:46;110327:350:0;-1:-1:-1;110688:12:0;;9566::1;;110713:45:0;;;;;;;;;;;;110703:56;;;;;;110688:71;;110772:10;:8;:10::i;:::-;110901:11;;110810:113;;-1:-1:-1;;;110810:113:0;;110795:12;;110810:16;;:35;;:113;;110860:7;;110882:4;;-1:-1:-1;;;;;110901:11:0;;;;110810:113;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;110795:128;;110951:4;110936:6;:12;110943:4;-1:-1:-1;;;;;110936:12:0;-1:-1:-1;;;;;110936:12:0;;;;;;;;;;;;;:19;;;;;;;;;;;;;;;;;;111005:4;110966:7;:19;110974:10;-1:-1:-1;;;;;110966:19:0;-1:-1:-1;;;;;110966:19:0;;;;;;;;;;;;:36;110986:15;-1:-1:-1;;;;;110966:36:0;-1:-1:-1;;;;;110966:36:0;;;;;;;;;;;;;:43;;;;;-1:-1:-1;;;;;110966:43:0;;;;;-1:-1:-1;;;;;110966:43:0;;;;;;111039:10;111020;:16;111031:4;-1:-1:-1;;;;;111020:16:0;-1:-1:-1;;;;;111020:16:0;;;;;;;;;;;;;:29;;;;;-1:-1:-1;;;;;111020:29:0;;;;;-1:-1:-1;;;;;111020:29:0;;;;;;111060:8;111074:4;111060:19;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;111060:19:0;;;;;-1:-1:-1;;;;;111060:19:0;;;;;;111097:21;111113:4;111097:21;;;;;-1:-1:-1;;;;;5367:55:1;;;;5349:74;;5337:2;5322:18;;5203:226;114293:219:0;53675:13;:11;:13::i;:::-;-1:-1:-1;;;;;114385:29:0;::::1;114377:44;;;::::0;-1:-1:-1;;;114377:44:0;;13110:2:1;114377:44:0::1;::::0;::::1;13092:21:1::0;13149:1;13129:18;;;13122:29;-1:-1:-1;;;13167:18:1;;;13160:32;13209:18;;114377:44:0::1;12908:325:1::0;114377:44:0::1;114432:11;:29:::0;;-1:-1:-1;;;;;;114432:29:0::1;-1:-1:-1::0;;;;;114432:29:0;::::1;::::0;;::::1;::::0;;;114477:27:::1;::::0;5349:74:1;;;114477:27:0::1;::::0;5337:2:1;5322:18;114477:27:0::1;5203:226:1::0;54695:201:0;53675:13;:11;:13::i;:::-;-1:-1:-1;;;;;54784:22:0;::::1;54776:73;;;::::0;-1:-1:-1;;;54776:73:0;;13440:2:1;54776:73:0::1;::::0;::::1;13422:21:1::0;13479:2;13459:18;;;13452:30;13518:34;13498:18;;;13491:62;-1:-1:-1;;;13569:18:1;;;13562:36;13615:19;;54776:73:0::1;13238:402:1::0;54776:73:0::1;54860:28;54879:8;54860:18;:28::i;:::-;54695:201:::0;:::o;114662:204::-;114757:3;;114723:8;;:30;;-1:-1:-1;;;114723:30:0;;114742:10;114723:30;;;5349:74:1;-1:-1:-1;;;;;114723:8:0;;;;:18;;5322::1;;114723:30:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;:37;;114701:89;;;;-1:-1:-1;;;114701:89:0;;13847:2:1;114701:89:0;;;13829:21:1;13886:1;13866:18;;;13859:29;-1:-1:-1;;;13904:18:1;;;13897:32;13946:18;;114701:89:0;13645:325:1;114701:89:0;114854:3;;114801:8;;:57;;-1:-1:-1;;;;;114801:8:0;;;;114827:10;;114847:4;;114801:25;:57::i;53954:132::-;53835:7;53862:6;-1:-1:-1;;;;;53862:6:0;39076:10;54018:23;54010:68;;;;-1:-1:-1;;;54010:68:0;;14177:2:1;54010:68:0;;;14159:21:1;;;14196:18;;;14189:30;14255:34;14235:18;;;14228:62;14307:18;;54010:68:0;13975:356:1;34521:211:0;34665:58;;-1:-1:-1;;;;;14528:55:1;;34665:58:0;;;14510:74:1;14600:18;;;14593:34;;;34638:86:0;;34658:5;;-1:-1:-1;;;34688:23:0;14483:18:1;;34665:58:0;;;;-1:-1:-1;;34665:58:0;;;;;;;;;;;;;;-1:-1:-1;;;;;34665:58:0;-1:-1:-1;;;;;;34665:58:0;;;;;;;;;;34638:19;:86::i;:::-;34521:211;;;:::o;55056:191::-;55130:16;55149:6;;-1:-1:-1;;;;;55166:17:0;;;-1:-1:-1;;;;;;55166:17:0;;;;;;55199:40;;55149:6;;;;;;;55199:40;;55130:16;55199:40;55119:128;55056:191;:::o;34740:248::-;34911:68;;-1:-1:-1;;;;;14919:15:1;;;34911:68:0;;;14901:34:1;14971:15;;14951:18;;;14944:43;15003:18;;;14996:34;;;34884:96:0;;34904:5;;-1:-1:-1;;;34934:27:0;14813:18:1;;34911:68:0;14638:398:1;37588:716:0;38012:23;38038:69;38066:4;38038:69;;;;;;;;;;;;;;;;;38046:5;-1:-1:-1;;;;;38038:27:0;;;:69;;;;;:::i;:::-;38122:17;;38012:95;;-1:-1:-1;38122:21:0;38118:179;;38219:10;38208:30;;;;;;;;;;;;:::i;:::-;38200:85;;;;-1:-1:-1;;;38200:85:0;;15525:2:1;38200:85:0;;;15507:21:1;15564:2;15544:18;;;15537:30;15603:34;15583:18;;;15576:62;-1:-1:-1;;;15654:18:1;;;15647:40;15704:19;;38200:85:0;15323:406:1;11401:229:0;11538:12;11570:52;11592:6;11600:4;11606:1;11609:12;11570:21;:52::i;:::-;11563:59;11401:229;-1:-1:-1;;;;11401:229:0:o;12521:455::-;12691:12;12749:5;12724:21;:30;;12716:81;;;;-1:-1:-1;;;12716:81:0;;15936:2:1;12716:81:0;;;15918:21:1;15975:2;15955:18;;;15948:30;16014:34;15994:18;;;15987:62;-1:-1:-1;;;16065:18:1;;;16058:36;16111:19;;12716:81:0;15734:402:1;12716:81:0;12809:12;12823:23;12850:6;-1:-1:-1;;;;;12850:11:0;12869:5;12876:4;12850:31;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;12808:73;;;;12899:69;12926:6;12934:7;12943:10;12955:12;12899:26;:69::i;:::-;12892:76;12521:455;-1:-1:-1;;;;;;;12521:455:0:o;15094:644::-;15279:12;15308:7;15304:427;;;15336:10;:17;15357:1;15336:22;15332:290;;-1:-1:-1;;;;;8939:19:0;;;15546:60;;;;-1:-1:-1;;;15546:60:0;;16635:2:1;15546:60:0;;;16617:21:1;16674:2;16654:18;;;16647:30;16713:31;16693:18;;;16686:59;16762:18;;15546:60:0;16433:353:1;15546:60:0;-1:-1:-1;15643:10:0;15636:17;;15304:427;15686:33;15694:10;15706:12;16441:17;;:21;16437:388;;16673:10;16667:17;16730:15;16717:10;16713:2;16709:19;16702:44;16437:388;16800:12;16793:20;;-1:-1:-1;;;16793:20:0;;;;;;;;:::i;196:154:1:-;-1:-1:-1;;;;;275:5:1;271:54;264:5;261:65;251:93;;340:1;337;330:12;355:134;423:20;;452:31;423:20;452:31;:::i;:::-;355:134;;;:::o;494:163::-;561:20;;621:10;610:22;;600:33;;590:61;;647:1;644;637:12;662:127;723:10;718:3;714:20;711:1;704:31;754:4;751:1;744:15;778:4;775:1;768:15;794:275;865:2;859:9;930:2;911:13;;-1:-1:-1;;907:27:1;895:40;;965:18;950:34;;986:22;;;947:62;944:88;;;1012:18;;:::i;:::-;1048:2;1041:22;794:275;;-1:-1:-1;794:275:1:o;1074:183::-;1134:4;1167:18;1159:6;1156:30;1153:56;;;1189:18;;:::i;:::-;-1:-1:-1;1234:1:1;1230:14;1246:4;1226:25;;1074:183::o;1262:737::-;1316:5;1369:3;1362:4;1354:6;1350:17;1346:27;1336:55;;1387:1;1384;1377:12;1336:55;1423:6;1410:20;1449:4;1473:60;1489:43;1529:2;1489:43;:::i;:::-;1473:60;:::i;:::-;1567:15;;;1653:1;1649:10;;;;1637:23;;1633:32;;;1598:12;;;;1677:15;;;1674:35;;;1705:1;1702;1695:12;1674:35;1741:2;1733:6;1729:15;1753:217;1769:6;1764:3;1761:15;1753:217;;;1849:3;1836:17;1866:31;1891:5;1866:31;:::i;:::-;1910:18;;1948:12;;;;1786;;1753:217;;;-1:-1:-1;1988:5:1;1262:737;-1:-1:-1;;;;;;1262:737:1:o;2004:159::-;2071:20;;2131:6;2120:18;;2110:29;;2100:57;;2153:1;2150;2143:12;2168:666;2221:5;2274:3;2267:4;2259:6;2255:17;2251:27;2241:55;;2292:1;2289;2282:12;2241:55;2328:6;2315:20;2354:4;2378:60;2394:43;2434:2;2394:43;:::i;2378:60::-;2472:15;;;2558:1;2554:10;;;;2542:23;;2538:32;;;2503:12;;;;2582:15;;;2579:35;;;2610:1;2607;2600:12;2579:35;2646:2;2638:6;2634:15;2658:147;2674:6;2669:3;2666:15;2658:147;;;2740:22;2758:3;2740:22;:::i;:::-;2728:35;;2783:12;;;;2691;;2658:147;;2839:666;2892:5;2945:3;2938:4;2930:6;2926:17;2922:27;2912:55;;2963:1;2960;2953:12;2912:55;2999:6;2986:20;3025:4;3049:60;3065:43;3105:2;3065:43;:::i;3049:60::-;3143:15;;;3229:1;3225:10;;;;3213:23;;3209:32;;;3174:12;;;;3253:15;;;3250:35;;;3281:1;3278;3271:12;3250:35;3317:2;3309:6;3305:15;3329:147;3345:6;3340:3;3337:15;3329:147;;;3411:22;3429:3;3411:22;:::i;:::-;3399:35;;3454:12;;;;3362;;3329:147;;3510:1251;3712:6;3720;3728;3736;3744;3752;3760;3768;3776;3829:3;3817:9;3808:7;3804:23;3800:33;3797:53;;;3846:1;3843;3836:12;3797:53;3869:29;3888:9;3869:29;:::i;:::-;3859:39;;3917:38;3951:2;3940:9;3936:18;3917:38;:::i;:::-;3907:48;;4002:2;3991:9;3987:18;3974:32;3964:42;;4025:37;4058:2;4047:9;4043:18;4025:37;:::i;:::-;4015:47;;4113:3;4102:9;4098:19;4085:33;4137:18;4178:2;4170:6;4167:14;4164:34;;;4194:1;4191;4184:12;4164:34;4217:61;4270:7;4261:6;4250:9;4246:22;4217:61;:::i;:::-;4207:71;;4325:3;4314:9;4310:19;4297:33;4287:43;;4349:38;4382:3;4371:9;4367:19;4349:38;:::i;:::-;4339:48;;4440:3;4429:9;4425:19;4412:33;4396:49;;4470:2;4460:8;4457:16;4454:36;;;4486:1;4483;4476:12;4454:36;4509:62;4563:7;4552:8;4541:9;4537:24;4509:62;:::i;:::-;4499:72;;4624:3;4613:9;4609:19;4596:33;4580:49;;4654:2;4644:8;4641:16;4638:36;;;4670:1;4667;4660:12;4638:36;;4693:62;4747:7;4736:8;4725:9;4721:24;4693:62;:::i;:::-;4683:72;;;3510:1251;;;;;;;;;;;:::o;4766:247::-;4825:6;4878:2;4866:9;4857:7;4853:23;4849:32;4846:52;;;4894:1;4891;4884:12;4846:52;4933:9;4920:23;4952:31;4977:5;4952:31;:::i;:::-;5002:5;4766:247;-1:-1:-1;;;4766:247:1:o;5018:180::-;5077:6;5130:2;5118:9;5109:7;5105:23;5101:32;5098:52;;;5146:1;5143;5136:12;5098:52;-1:-1:-1;5169:23:1;;5018:180;-1:-1:-1;5018:180:1:o;5871:388::-;5939:6;5947;6000:2;5988:9;5979:7;5975:23;5971:32;5968:52;;;6016:1;6013;6006:12;5968:52;6055:9;6042:23;6074:31;6099:5;6074:31;:::i;:::-;6124:5;-1:-1:-1;6181:2:1;6166:18;;6153:32;6194:33;6153:32;6194:33;:::i;:::-;6246:7;6236:17;;;5871:388;;;;;:::o;6689:447::-;6741:3;6779:5;6773:12;6806:6;6801:3;6794:19;6832:4;6861:2;6856:3;6852:12;6845:19;;6898:2;6891:5;6887:14;6919:1;6929:182;6943:6;6940:1;6937:13;6929:182;;;7008:13;;7023:6;7004:26;6992:39;;7051:12;;;;7086:15;;;;6965:1;6958:9;6929:182;;;-1:-1:-1;7127:3:1;;6689:447;-1:-1:-1;;;;;6689:447:1:o;7141:451::-;7193:3;7231:5;7225:12;7258:6;7253:3;7246:19;7284:4;7313:2;7308:3;7304:12;7297:19;;7350:2;7343:5;7339:14;7371:1;7381:186;7395:6;7392:1;7389:13;7381:186;;;7460:13;;7475:10;7456:30;7444:43;;7507:12;;;;7542:15;;;;7417:1;7410:9;7381:186;;7597:1649;8083:4;8112:3;8153:2;8142:9;8138:18;-1:-1:-1;;;;;8256:2:1;8248:6;8244:15;8233:9;8226:34;8279:2;8329;8321:6;8317:15;8312:2;8301:9;8297:18;8290:43;8381:2;8373:6;8369:15;8364:2;8353:9;8349:18;8342:43;8421:6;8416:2;8405:9;8401:18;8394:34;8477:10;8469:6;8465:23;8459:3;8448:9;8444:19;8437:52;8526:2;8520:3;8509:9;8505:19;8498:31;8549:6;8538:17;;8584:6;8578:13;8615:6;8607;8600:22;8653:3;8642:9;8638:19;8631:26;;8692:2;8684:6;8680:15;8666:29;;8713:1;8723:178;8737:6;8734:1;8731:13;8723:178;;;8802:13;;8798:22;;8786:35;;8841:12;;;;8876:15;;;;8759:1;8752:9;8723:178;;;8727:3;;;;;8938:6;8932:3;8921:9;8917:19;8910:35;8954:46;8995:3;8984:9;8980:19;8972:6;6670;6659:18;6647:31;;6594:90;8954:46;9046:9;9041:3;9037:19;9031:3;9020:9;9016:19;9009:48;9080:40;9116:3;9108:6;9080:40;:::i;:::-;9066:54;;9169:9;9161:6;9157:22;9151:3;9140:9;9136:19;9129:51;9197:43;9233:6;9225;9197:43;:::i;:::-;9189:51;7597:1649;-1:-1:-1;;;;;;;;;;;;;7597:1649:1:o;9589:250::-;9674:1;9684:113;9698:6;9695:1;9692:13;9684:113;;;9774:11;;;9768:18;9755:11;;;9748:39;9720:2;9713:10;9684:113;;;-1:-1:-1;;9831:1:1;9813:16;;9806:27;9589:250::o;9844:270::-;9885:3;9923:5;9917:12;9950:6;9945:3;9938:19;9966:76;10035:6;10028:4;10023:3;10019:14;10012:4;10005:5;10001:16;9966:76;:::i;:::-;10096:2;10075:15;-1:-1:-1;;10071:29:1;10062:39;;;;10103:4;10058:50;;9844:270;-1:-1:-1;;9844:270:1:o;10119:416::-;10330:2;10319:9;10312:21;10293:4;10350:44;10390:2;10379:9;10375:18;10367:6;10350:44;:::i;:::-;10342:52;;10430:6;10425:2;10414:9;10410:18;10403:34;-1:-1:-1;;;;;10477:6:1;10473:55;10468:2;10457:9;10453:18;10446:83;10119:416;;;;;;:::o;10540:251::-;10610:6;10663:2;10651:9;10642:7;10638:23;10634:32;10631:52;;;10679:1;10676;10669:12;10631:52;10711:9;10705:16;10730:31;10755:5;10730:31;:::i;12059:184::-;12129:6;12182:2;12170:9;12161:7;12157:23;12153:32;12150:52;;;12198:1;12195;12188:12;12150:52;-1:-1:-1;12221:16:1;;12059:184;-1:-1:-1;12059:184:1:o;15041:277::-;15108:6;15161:2;15149:9;15140:7;15136:23;15132:32;15129:52;;;15177:1;15174;15167:12;15129:52;15209:9;15203:16;15262:5;15255:13;15248:21;15241:5;15238:32;15228:60;;15284:1;15281;15274:12;16141:287;16270:3;16308:6;16302:13;16324:66;16383:6;16378:3;16371:4;16363:6;16359:17;16324:66;:::i;:::-;16406:16;;;;;16141:287;-1:-1:-1;;16141:287:1:o;16791:219::-;16940:2;16929:9;16922:21;16903:4;16960:44;17000:2;16989:9;16985:18;16977:6;16960:44;:::i

Swarm Source

ipfs://2c8051155a71d617f8a68b7b253702bb3594dcce008ce15ac2ae8e693cd6cdcf
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.