creation_sourcecode: {{
    "language": "Solidity",
    "sources": {
      "@openzeppelin/contracts/access/Ownable.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../utils/Context.sol\";\n\n/**\n * @dev Contract module which provides a basic access control mechanism, where\n * there is an account (an owner) that can be granted exclusive access to\n * specific functions.\n *\n * By default, the owner account will be the one that deploys the contract. This\n * can later be changed with {transferOwnership}.\n *\n * This module is used through inheritance. It will make available the modifier\n * `onlyOwner`, which can be applied to your functions to restrict their use to\n * the owner.\n */\nabstract contract Ownable is Context {\n    address private _owner;\n\n    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);\n\n    /**\n     * @dev Initializes the contract setting the deployer as the initial owner.\n     */\n    constructor() {\n        _transferOwnership(_msgSender());\n    }\n\n    /**\n     * @dev Throws if called by any account other than the owner.\n     */\n    modifier onlyOwner() {\n        _checkOwner();\n        _;\n    }\n\n    /**\n     * @dev Returns the address of the current owner.\n     */\n    function owner() public view virtual returns (address) {\n        return _owner;\n    }\n\n    /**\n     * @dev Throws if the sender is not the owner.\n     */\n    function _checkOwner() internal view virtual {\n        require(owner() == _msgSender(), \"Ownable: caller is not the owner\");\n    }\n\n    /**\n     * @dev Leaves the contract without owner. It will not be possible to call\n     * `onlyOwner` functions. Can only be called by the current owner.\n     *\n     * NOTE: Renouncing ownership will leave the contract without an owner,\n     * thereby disabling any functionality that is only available to the owner.\n     */\n    function renounceOwnership() public virtual onlyOwner {\n        _transferOwnership(address(0));\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Can only be called by the current owner.\n     */\n    function transferOwnership(address newOwner) public virtual onlyOwner {\n        require(newOwner != address(0), \"Ownable: new owner is the zero address\");\n        _transferOwnership(newOwner);\n    }\n\n    /**\n     * @dev Transfers ownership of the contract to a new account (`newOwner`).\n     * Internal function without access restriction.\n     */\n    function _transferOwnership(address newOwner) internal virtual {\n        address oldOwner = _owner;\n        _owner = newOwner;\n        emit OwnershipTransferred(oldOwner, newOwner);\n    }\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in\n * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].\n *\n * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by\n * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't\n * need to send a transaction, and thus is not required to hold Ether at all.\n *\n * ==== Security Considerations\n *\n * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature\n * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be\n * considered as an intention to spend the allowance in any specific way. The second is that because permits have\n * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should\n * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be\n * generally recommended is:\n *\n * ```solidity\n * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {\n *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}\n *     doThing(..., value);\n * }\n *\n * function doThing(..., uint256 value) public {\n *     token.safeTransferFrom(msg.sender, address(this), value);\n *     ...\n * }\n * ```\n *\n * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of\n * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also\n * {SafeERC20-safeTransferFrom}).\n *\n * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so\n * contracts should have entry points that don't rely on permit.\n */\ninterface IERC20Permit {\n    /**\n     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,\n     * given ``owner``'s signed approval.\n     *\n     * IMPORTANT: The same issues {IERC20-approve} has related to transaction\n     * ordering also apply here.\n     *\n     * Emits an {Approval} event.\n     *\n     * Requirements:\n     *\n     * - `spender` cannot be the zero address.\n     * - `deadline` must be a timestamp in the future.\n     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`\n     * over the EIP712-formatted function arguments.\n     * - the signature must use ``owner``'s current nonce (see {nonces}).\n     *\n     * For more information on the signature format, see the\n     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP\n     * section].\n     *\n     * CAUTION: See Security Considerations above.\n     */\n    function permit(\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) external;\n\n    /**\n     * @dev Returns the current nonce for `owner`. This value must be\n     * included whenever a signature is generated for {permit}.\n     *\n     * Every successful call to {permit} increases ``owner``'s nonce by one. This\n     * prevents a signature from being used multiple times.\n     */\n    function nonces(address owner) external view returns (uint256);\n\n    /**\n     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.\n     */\n    // solhint-disable-next-line func-name-mixedcase\n    function DOMAIN_SEPARATOR() external view returns (bytes32);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/IERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n    /**\n     * @dev Emitted when `value` tokens are moved from one account (`from`) to\n     * another (`to`).\n     *\n     * Note that `value` may be zero.\n     */\n    event Transfer(address indexed from, address indexed to, uint256 value);\n\n    /**\n     * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n     * a call to {approve}. `value` is the new allowance.\n     */\n    event Approval(address indexed owner, address indexed spender, uint256 value);\n\n    /**\n     * @dev Returns the amount of tokens in existence.\n     */\n    function totalSupply() external view returns (uint256);\n\n    /**\n     * @dev Returns the amount of tokens owned by `account`.\n     */\n    function balanceOf(address account) external view returns (uint256);\n\n    /**\n     * @dev Moves `amount` tokens from the caller's account to `to`.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transfer(address to, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Returns the remaining number of tokens that `spender` will be\n     * allowed to spend on behalf of `owner` through {transferFrom}. This is\n     * zero by default.\n     *\n     * This value changes when {approve} or {transferFrom} are called.\n     */\n    function allowance(address owner, address spender) external view returns (uint256);\n\n    /**\n     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * IMPORTANT: Beware that changing an allowance with this method brings the risk\n     * that someone may use both the old and the new allowance by unfortunate\n     * transaction ordering. One possible solution to mitigate this race\n     * condition is to first reduce the spender's allowance to 0 and set the\n     * desired value afterwards:\n     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n     *\n     * Emits an {Approval} event.\n     */\n    function approve(address spender, uint256 amount) external returns (bool);\n\n    /**\n     * @dev Moves `amount` tokens from `from` to `to` using the\n     * allowance mechanism. `amount` is then deducted from the caller's\n     * allowance.\n     *\n     * Returns a boolean value indicating whether the operation succeeded.\n     *\n     * Emits a {Transfer} event.\n     */\n    function transferFrom(address from, address to, uint256 amount) external returns (bool);\n}\n"
      },
      "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\nimport \"../extensions/IERC20Permit.sol\";\nimport \"../../../utils/Address.sol\";\n\n/**\n * @title SafeERC20\n * @dev Wrappers around ERC20 operations that throw on failure (when the token\n * contract returns false). Tokens that return no value (and instead revert or\n * throw on failure) are also supported, non-reverting calls are assumed to be\n * successful.\n * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,\n * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.\n */\nlibrary SafeERC20 {\n    using Address for address;\n\n    /**\n     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeTransfer(IERC20 token, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n    }\n\n    /**\n     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the\n     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.\n     */\n    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {\n        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));\n    }\n\n    /**\n     * @dev Deprecated. This function has issues similar to the ones found in\n     * {IERC20-approve}, and its usage is discouraged.\n     *\n     * Whenever possible, use {safeIncreaseAllowance} and\n     * {safeDecreaseAllowance} instead.\n     */\n    function safeApprove(IERC20 token, address spender, uint256 value) internal {\n        // safeApprove should only be called when setting an initial allowance,\n        // or when resetting it to zero. To increase and decrease it, use\n        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'\n        require(\n            (value == 0) || (token.allowance(address(this), spender) == 0),\n            \"SafeERC20: approve from non-zero to non-zero allowance\"\n        );\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n    }\n\n    /**\n     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        uint256 oldAllowance = token.allowance(address(this), spender);\n        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));\n    }\n\n    /**\n     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful.\n     */\n    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {\n        unchecked {\n            uint256 oldAllowance = token.allowance(address(this), spender);\n            require(oldAllowance >= value, \"SafeERC20: decreased allowance below zero\");\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));\n        }\n    }\n\n    /**\n     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,\n     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval\n     * to be set to zero before setting it to a non-zero value, such as USDT.\n     */\n    function forceApprove(IERC20 token, address spender, uint256 value) internal {\n        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);\n\n        if (!_callOptionalReturnBool(token, approvalCall)) {\n            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\n            _callOptionalReturn(token, approvalCall);\n        }\n    }\n\n    /**\n     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.\n     * Revert on invalid signature.\n     */\n    function safePermit(\n        IERC20Permit token,\n        address owner,\n        address spender,\n        uint256 value,\n        uint256 deadline,\n        uint8 v,\n        bytes32 r,\n        bytes32 s\n    ) internal {\n        uint256 nonceBefore = token.nonces(owner);\n        token.permit(owner, spender, value, deadline, v, r, s);\n        uint256 nonceAfter = token.nonces(owner);\n        require(nonceAfter == nonceBefore + 1, \"SafeERC20: permit did not succeed\");\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     */\n    function _callOptionalReturn(IERC20 token, bytes memory data) private {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that\n        // the target address contains contract code and also asserts for success in the low-level call.\n\n        bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n        require(returndata.length == 0 || abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n    }\n\n    /**\n     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement\n     * on the return value: the return value is optional (but if data is returned, it must not be false).\n     * @param token The token targeted by the call.\n     * @param data The call data (encoded using abi.encode or one of its variants).\n     *\n     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.\n     */\n    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {\n        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since\n        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false\n        // and not revert is the subcall reverts.\n\n        (bool success, bytes memory returndata) = address(token).call(data);\n        return\n            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Address.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)\n\npragma solidity ^0.8.1;\n\n/**\n * @dev Collection of functions related to the address type\n */\nlibrary Address {\n    /**\n     * @dev Returns true if `account` is a contract.\n     *\n     * [IMPORTANT]\n     * ====\n     * It is unsafe to assume that an address for which this function returns\n     * false is an externally-owned account (EOA) and not a contract.\n     *\n     * Among others, `isContract` will return false for the following\n     * types of addresses:\n     *\n     *  - an externally-owned account\n     *  - a contract in construction\n     *  - an address where a contract will be created\n     *  - an address where a contract lived, but was destroyed\n     *\n     * Furthermore, `isContract` will also return true if the target contract within\n     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,\n     * which only has an effect at the end of a transaction.\n     * ====\n     *\n     * [IMPORTANT]\n     * ====\n     * You shouldn't rely on `isContract` to protect against flash loan attacks!\n     *\n     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets\n     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract\n     * constructor.\n     * ====\n     */\n    function isContract(address account) internal view returns (bool) {\n        // This method relies on extcodesize/address.code.length, which returns 0\n        // for contracts in construction, since the code is only stored at the end\n        // of the constructor execution.\n\n        return account.code.length > 0;\n    }\n\n    /**\n     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to\n     * `recipient`, forwarding all available gas and reverting on errors.\n     *\n     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost\n     * of certain opcodes, possibly making contracts go over the 2300 gas limit\n     * imposed by `transfer`, making them unable to receive funds via\n     * `transfer`. {sendValue} removes this limitation.\n     *\n     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].\n     *\n     * IMPORTANT: because control is transferred to `recipient`, care must be\n     * taken to not create reentrancy vulnerabilities. Consider using\n     * {ReentrancyGuard} or the\n     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].\n     */\n    function sendValue(address payable recipient, uint256 amount) internal {\n        require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n        (bool success, ) = recipient.call{value: amount}(\"\");\n        require(success, \"Address: unable to send value, recipient may have reverted\");\n    }\n\n    /**\n     * @dev Performs a Solidity function call using a low level `call`. A\n     * plain `call` is an unsafe replacement for a function call: use this\n     * function instead.\n     *\n     * If `target` reverts with a revert reason, it is bubbled up by this\n     * function (like regular Solidity function calls).\n     *\n     * Returns the raw returned data. To convert to the expected return value,\n     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].\n     *\n     * Requirements:\n     *\n     * - `target` must be a contract.\n     * - calling `target` with `data` must not revert.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, \"Address: low-level call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with\n     * `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, 0, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but also transferring `value` wei to `target`.\n     *\n     * Requirements:\n     *\n     * - the calling contract must have an ETH balance of at least `value`.\n     * - the called Solidity function must be `payable`.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {\n        return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but\n     * with `errorMessage` as a fallback revert reason when `target` reverts.\n     *\n     * _Available since v3.1._\n     */\n    function functionCallWithValue(\n        address target,\n        bytes memory data,\n        uint256 value,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        require(address(this).balance >= value, \"Address: insufficient balance for call\");\n        (bool success, bytes memory returndata) = target.call{value: value}(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {\n        return functionStaticCall(target, data, \"Address: low-level static call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a static call.\n     *\n     * _Available since v3.3._\n     */\n    function functionStaticCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.staticcall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {\n        return functionDelegateCall(target, data, \"Address: low-level delegate call failed\");\n    }\n\n    /**\n     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],\n     * but performing a delegate call.\n     *\n     * _Available since v3.4._\n     */\n    function functionDelegateCall(\n        address target,\n        bytes memory data,\n        string memory errorMessage\n    ) internal returns (bytes memory) {\n        (bool success, bytes memory returndata) = target.delegatecall(data);\n        return verifyCallResultFromTarget(target, success, returndata, errorMessage);\n    }\n\n    /**\n     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling\n     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.\n     *\n     * _Available since v4.8._\n     */\n    function verifyCallResultFromTarget(\n        address target,\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal view returns (bytes memory) {\n        if (success) {\n            if (returndata.length == 0) {\n                // only check isContract if the call was successful and the return data is empty\n                // otherwise we already know that it was a contract\n                require(isContract(target), \"Address: call to non-contract\");\n            }\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    /**\n     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the\n     * revert reason or using the provided one.\n     *\n     * _Available since v4.3._\n     */\n    function verifyCallResult(\n        bool success,\n        bytes memory returndata,\n        string memory errorMessage\n    ) internal pure returns (bytes memory) {\n        if (success) {\n            return returndata;\n        } else {\n            _revert(returndata, errorMessage);\n        }\n    }\n\n    function _revert(bytes memory returndata, string memory errorMessage) private pure {\n        // Look for revert reason and bubble it up if present\n        if (returndata.length > 0) {\n            // The easiest way to bubble the revert reason is using memory via assembly\n            /// @solidity memory-safe-assembly\n            assembly {\n                let returndata_size := mload(returndata)\n                revert(add(32, returndata), returndata_size)\n            }\n        } else {\n            revert(errorMessage);\n        }\n    }\n}\n"
      },
      "@openzeppelin/contracts/utils/Context.sol": {
        "content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n    function _msgSender() internal view virtual returns (address) {\n        return msg.sender;\n    }\n\n    function _msgData() internal view virtual returns (bytes calldata) {\n        return msg.data;\n    }\n\n    function _contextSuffixLength() internal view virtual returns (uint256) {\n        return 0;\n    }\n}\n"
      },
      "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Callback for IUniswapV3PoolActions#swap\n/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface\ninterface IUniswapV3SwapCallback {\n    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.\n    /// @dev In the implementation you must pay the pool tokens owed for the swap.\n    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.\n    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.\n    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.\n    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by\n    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.\n    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call\n    function uniswapV3SwapCallback(\n        int256 amount0Delta,\n        int256 amount1Delta,\n        bytes calldata data\n    ) external;\n}\n"
      },
      "@uniswap/v3-core/contracts/libraries/FixedPoint96.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.4.0;\n\n/// @title FixedPoint96\n/// @notice A library for handling binary fixed point numbers, see https://en.wikipedia.org/wiki/Q_(number_format)\n/// @dev Used in SqrtPriceMath.sol\nlibrary FixedPoint96 {\n    uint8 internal constant RESOLUTION = 96;\n    uint256 internal constant Q96 = 0x1000000000000000000000000;\n}\n"
      },
      "@uniswap/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Immutable state\n/// @notice Functions that return immutable state of the router\ninterface IPeripheryImmutableState {\n    /// @return Returns the address of the Uniswap V3 factory\n    function factory() external view returns (address);\n\n    /// @return Returns the address of WETH9\n    function WETH9() external view returns (address);\n}\n"
      },
      "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.7.5;\npragma abicoder v2;\n\nimport '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';\n\n/// @title Router token swapping functionality\n/// @notice Functions for swapping tokens via Uniswap V3\ninterface ISwapRouter is IUniswapV3SwapCallback {\n    struct ExactInputSingleParams {\n        address tokenIn;\n        address tokenOut;\n        uint24 fee;\n        address recipient;\n        uint256 deadline;\n        uint256 amountIn;\n        uint256 amountOutMinimum;\n        uint160 sqrtPriceLimitX96;\n    }\n\n    /// @notice Swaps `amountIn` of one token for as much as possible of another token\n    /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata\n    /// @return amountOut The amount of the received token\n    function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);\n\n    struct ExactInputParams {\n        bytes path;\n        address recipient;\n        uint256 deadline;\n        uint256 amountIn;\n        uint256 amountOutMinimum;\n    }\n\n    /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path\n    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata\n    /// @return amountOut The amount of the received token\n    function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);\n\n    struct ExactOutputSingleParams {\n        address tokenIn;\n        address tokenOut;\n        uint24 fee;\n        address recipient;\n        uint256 deadline;\n        uint256 amountOut;\n        uint256 amountInMaximum;\n        uint160 sqrtPriceLimitX96;\n    }\n\n    /// @notice Swaps as little as possible of one token for `amountOut` of another token\n    /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata\n    /// @return amountIn The amount of the input token\n    function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);\n\n    struct ExactOutputParams {\n        bytes path;\n        address recipient;\n        uint256 deadline;\n        uint256 amountOut;\n        uint256 amountInMaximum;\n    }\n\n    /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)\n    /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata\n    /// @return amountIn The amount of the input token\n    function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);\n}\n"
      },
      "contracts/interfaces/IAlgebraSwapCallback.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Callback for IAlgebraPoolActions#swap\n/// @notice Any contract that calls IAlgebraPoolActions#swap must implement this interface\n/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:\n/// https://github.com/Uniswap/v3-core/tree/main/contracts/interfaces\ninterface IAlgebraSwapCallback {\n  /// @notice Called to `msg.sender` after executing a swap via IAlgebraPool#swap.\n  /// @dev In the implementation you must pay the pool tokens owed for the swap.\n  /// The caller of this method must be checked to be a AlgebraPool deployed by the canonical AlgebraFactory.\n  /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.\n  /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by\n  /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.\n  /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by\n  /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.\n  /// @param data Any data passed through by the caller via the IAlgebraPoolActions#swap call\n  function algebraSwapCallback(\n    int256 amount0Delta,\n    int256 amount1Delta,\n    bytes calldata data\n  ) external;\n}\n"
      },
      "contracts/interfaces/IDecentralizedIndex.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\n\ninterface IDecentralizedIndex is IERC20 {\n  enum IndexType {\n    WEIGHTED,\n    UNWEIGHTED\n  }\n\n  struct Config {\n    address partner;\n    bool hasTransferTax;\n    bool blacklistTKNpTKNPoolV2;\n  }\n\n  // all fees: 1 == 0.01%, 10 == 0.1%, 100 == 1%\n  struct Fees {\n    uint16 burn;\n    uint16 bond;\n    uint16 debond;\n    uint16 buy;\n    uint16 sell;\n    uint16 partner;\n  }\n\n  struct IndexAssetInfo {\n    address token;\n    uint256 weighting;\n    uint256 basePriceUSDX96;\n    address c1; // arbitrary contract/address field we can use for an index\n    uint256 q1; // arbitrary quantity/number field we can use for an index\n  }\n\n  event Create(address indexed newIdx, address indexed wallet);\n  event Initialize(address indexed wallet, address v2Pool);\n  event Bond(\n    address indexed wallet,\n    address indexed token,\n    uint256 amountTokensBonded,\n    uint256 amountTokensMinted\n  );\n  event Debond(address indexed wallet, uint256 amountDebonded);\n  event AddLiquidity(\n    address indexed wallet,\n    uint256 amountTokens,\n    uint256 amountDAI\n  );\n  event RemoveLiquidity(address indexed wallet, uint256 amountLiquidity);\n  event SetPartner(address indexed wallet, address newPartner);\n  event SetPartnerFee(address indexed wallet, uint16 newFee);\n\n  function BOND_FEE() external view returns (uint16);\n\n  function DEBOND_FEE() external view returns (uint16);\n\n  function FLASH_FEE_AMOUNT_DAI() external view returns (uint256);\n\n  function PAIRED_LP_TOKEN() external view returns (address);\n\n  function indexType() external view returns (IndexType);\n\n  function created() external view returns (uint256);\n\n  function lpStakingPool() external view returns (address);\n\n  function lpRewardsToken() external view returns (address);\n\n  function partner() external view returns (address);\n\n  function getIdxPriceUSDX96() external view returns (uint256, uint256);\n\n  function isAsset(address token) external view returns (bool);\n\n  function getAllAssets() external view returns (IndexAssetInfo[] memory);\n\n  function getInitialAmount(\n    address sToken,\n    uint256 sAmount,\n    address tToken\n  ) external view returns (uint256);\n\n  function getTokenPriceUSDX96(address token) external view returns (uint256);\n\n  function processPreSwapFeesAndSwap() external;\n\n  function bond(address token, uint256 amount, uint256 amountMintMin) external;\n\n  function debond(\n    uint256 amount,\n    address[] memory token,\n    uint8[] memory percentage\n  ) external;\n\n  function addLiquidityV2(\n    uint256 idxTokens,\n    uint256 daiTokens,\n    uint256 slippage,\n    uint256 deadline\n  ) external;\n\n  function removeLiquidityV2(\n    uint256 lpTokens,\n    uint256 minTokens,\n    uint256 minDAI,\n    uint256 deadline\n  ) external;\n\n  function flash(\n    address recipient,\n    address token,\n    uint256 amount,\n    bytes calldata data\n  ) external;\n}\n"
      },
      "contracts/interfaces/IPEAS.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\n\ninterface IPEAS is IERC20 {\n  event Burn(address indexed user, uint256 amount);\n\n  function burn(uint256 amount) external;\n}\n"
      },
      "contracts/interfaces/IProtocolFeeRouter.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport './IProtocolFees.sol';\n\ninterface IProtocolFeeRouter {\n  function protocolFees() external view returns (IProtocolFees);\n}\n"
      },
      "contracts/interfaces/IProtocolFees.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IProtocolFees {\n  event SetYieldAdmin(uint256 newFee);\n  event SetYieldBurn(uint256 newFee);\n\n  function DEN() external view returns (uint256);\n\n  function yieldAdmin() external view returns (uint256);\n\n  function yieldBurn() external view returns (uint256);\n}\n"
      },
      "contracts/interfaces/IRewardsWhitelister.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IRewardsWhitelister {\n  function whitelist(address token) external view returns (bool);\n}\n"
      },
      "contracts/interfaces/ISwapRouterAlgebra.sol": {
        "content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.7.5;\npragma abicoder v2;\n\nimport './IAlgebraSwapCallback.sol';\n\n/// @title Router token swapping functionality\n/// @notice Functions for swapping tokens via Algebra\n/// @dev Credit to Uniswap Labs under GPL-2.0-or-later license:\n/// https://github.com/Uniswap/v3-periphery\ninterface ISwapRouterAlgebra is IAlgebraSwapCallback {\n  struct ExactInputSingleParams {\n    address tokenIn;\n    address tokenOut;\n    address recipient;\n    uint256 deadline;\n    uint256 amountIn;\n    uint256 amountOutMinimum;\n    uint160 limitSqrtPrice;\n  }\n\n  /// @notice Swaps `amountIn` of one token for as much as possible of another token\n  /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata\n  /// @return amountOut The amount of the received token\n  function exactInputSingle(\n    ExactInputSingleParams calldata params\n  ) external payable returns (uint256 amountOut);\n\n  struct ExactInputParams {\n    bytes path;\n    address recipient;\n    uint256 deadline;\n    uint256 amountIn;\n    uint256 amountOutMinimum;\n  }\n\n  /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path\n  /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata\n  /// @return amountOut The amount of the received token\n  function exactInput(\n    ExactInputParams calldata params\n  ) external payable returns (uint256 amountOut);\n\n  struct ExactOutputSingleParams {\n    address tokenIn;\n    address tokenOut;\n    uint24 fee;\n    address recipient;\n    uint256 deadline;\n    uint256 amountOut;\n    uint256 amountInMaximum;\n    uint160 limitSqrtPrice;\n  }\n\n  /// @notice Swaps as little as possible of one token for `amountOut` of another token\n  /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata\n  /// @return amountIn The amount of the input token\n  function exactOutputSingle(\n    ExactOutputSingleParams calldata params\n  ) external payable returns (uint256 amountIn);\n\n  struct ExactOutputParams {\n    bytes path;\n    address recipient;\n    uint256 deadline;\n    uint256 amountOut;\n    uint256 amountInMaximum;\n  }\n\n  /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)\n  /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata\n  /// @return amountIn The amount of the input token\n  function exactOutput(\n    ExactOutputParams calldata params\n  ) external payable returns (uint256 amountIn);\n\n  /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path\n  /// @dev Unlike standard swaps, handles transferring from user before the actual swap.\n  /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata\n  /// @return amountOut The amount of the received token\n  function exactInputSingleSupportingFeeOnTransferTokens(\n    ExactInputSingleParams calldata params\n  ) external returns (uint256 amountOut);\n}\n"
      },
      "contracts/interfaces/ITokenRewards.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface ITokenRewards {\n  event AddShares(address indexed wallet, uint256 amount);\n\n  event RemoveShares(address indexed wallet, uint256 amount);\n\n  event ClaimReward(address indexed wallet);\n\n  event DistributeReward(\n    address indexed wallet,\n    address indexed token,\n    uint256 amount\n  );\n\n  event DepositRewards(\n    address indexed wallet,\n    address indexed token,\n    uint256 amount\n  );\n\n  function totalShares() external view returns (uint256);\n\n  function totalStakers() external view returns (uint256);\n\n  function rewardsToken() external view returns (address);\n\n  function trackingToken() external view returns (address);\n\n  function depositFromPairedLpToken(\n    uint256 amount,\n    uint256 slippageOverride\n  ) external;\n\n  function depositRewards(address token, uint256 amount) external;\n\n  function claimReward(address wallet) external;\n\n  function setShares(\n    address wallet,\n    uint256 amount,\n    bool sharesRemoving\n  ) external;\n}\n"
      },
      "contracts/interfaces/IV3TwapUtilities.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\ninterface IV3TwapUtilities {\n  function getV3Pool(\n    address v3Factory,\n    address token0,\n    address token1\n  ) external view returns (address);\n\n  function getV3Pool(\n    address v3Factory,\n    address token0,\n    address token1,\n    uint24 poolFee\n  ) external view returns (address);\n\n  function getPoolPriceUSDX96(\n    address pricePool,\n    address nativeStablePool,\n    address WETH9\n  ) external view returns (uint256);\n\n  function sqrtPriceX96FromPoolAndInterval(\n    address pool\n  ) external view returns (uint160);\n\n  function priceX96FromSqrtPriceX96(\n    uint160 sqrtPriceX96\n  ) external pure returns (uint256);\n}\n"
      },
      "contracts/libraries/BokkyPooBahsDateTimeLibrary.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\n// ----------------------------------------------------------------------------\n// BokkyPooBah's DateTime Library v1.00\n//\n// A gas-efficient Solidity date and time library\n//\n// https://github.com/bokkypoobah/BokkyPooBahsDateTimeLibrary\n//\n// Tested date range 1970/01/01 to 2345/12/31\n//\n// Conventions:\n// Unit      | Range         | Notes\n// :-------- |:-------------:|:-----\n// timestamp | >= 0          | Unix timestamp, number of seconds since 1970/01/01 00:00:00 UTC\n// year      | 1970 ... 2345 |\n// month     | 1 ... 12      |\n// day       | 1 ... 31      |\n// hour      | 0 ... 23      |\n// minute    | 0 ... 59      |\n// second    | 0 ... 59      |\n// dayOfWeek | 1 ... 7       | 1 = Monday, ..., 7 = Sunday\n//\n//\n// Enjoy. (c) BokkyPooBah / Bok Consulting Pty Ltd 2018.\n//\n// GNU Lesser General Public License 3.0\n// https://www.gnu.org/licenses/lgpl-3.0.en.html\n// ----------------------------------------------------------------------------\n\nlibrary BokkyPooBahsDateTimeLibrary {\n  uint constant SECONDS_PER_DAY = 24 * 60 * 60;\n  int constant OFFSET19700101 = 2440588;\n\n  // ------------------------------------------------------------------------\n  // Calculate year/month/day from the number of days since 1970/01/01 using\n  // the date conversion algorithm from\n  //   http://aa.usno.navy.mil/faq/docs/JD_Formula.php\n  // and adding the offset 2440588 so that 1970/01/01 is day 0\n  //\n  // int L = days + 68569 + offset\n  // int N = 4 * L / 146097\n  // L = L - (146097 * N + 3) / 4\n  // year = 4000 * (L + 1) / 1461001\n  // L = L - 1461 * year / 4 + 31\n  // month = 80 * L / 2447\n  // dd = L - 2447 * month / 80\n  // L = month / 11\n  // month = month + 2 - 12 * L\n  // year = 100 * (N - 49) + year + L\n  // ------------------------------------------------------------------------\n  function _daysToDate(\n    uint _days\n  ) internal pure returns (uint year, uint month, uint day) {\n    int __days = int(_days);\n\n    int L = __days + 68569 + OFFSET19700101;\n    int N = (4 * L) / 146097;\n    L = L - (146097 * N + 3) / 4;\n    int _year = (4000 * (L + 1)) / 1461001;\n    L = L - (1461 * _year) / 4 + 31;\n    int _month = (80 * L) / 2447;\n    int _day = L - (2447 * _month) / 80;\n    L = _month / 11;\n    _month = _month + 2 - 12 * L;\n    _year = 100 * (N - 49) + _year + L;\n\n    year = uint(_year);\n    month = uint(_month);\n    day = uint(_day);\n  }\n\n  function timestampToDate(\n    uint timestamp\n  ) internal pure returns (uint year, uint month, uint day) {\n    (year, month, day) = _daysToDate(timestamp / SECONDS_PER_DAY);\n  }\n}\n"
      },
      "contracts/TokenRewards.sol": {
        "content": "// SPDX-License-Identifier: MIT\npragma solidity ^0.8.19;\n\nimport '@openzeppelin/contracts/access/Ownable.sol';\nimport '@openzeppelin/contracts/token/ERC20/IERC20.sol';\nimport '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';\nimport '@openzeppelin/contracts/utils/Context.sol';\nimport '@uniswap/v3-core/contracts/libraries/FixedPoint96.sol';\nimport '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';\nimport '@uniswap/v3-periphery/contracts/interfaces/IPeripheryImmutableState.sol';\nimport './interfaces/IDecentralizedIndex.sol';\nimport './interfaces/IPEAS.sol';\nimport './interfaces/IRewardsWhitelister.sol';\nimport './interfaces/IProtocolFees.sol';\nimport './interfaces/IProtocolFeeRouter.sol';\nimport './interfaces/ISwapRouterAlgebra.sol';\nimport './interfaces/ITokenRewards.sol';\nimport './interfaces/IV3TwapUtilities.sol';\nimport './libraries/BokkyPooBahsDateTimeLibrary.sol';\n\ncontract TokenRewards is ITokenRewards, Context {\n  using SafeERC20 for IERC20;\n\n  uint256 constant PRECISION = 10 ** 36;\n  uint24 constant REWARDS_POOL_FEE = 10000; // 1%\n  address immutable V3_ROUTER;\n  address immutable INDEX_FUND;\n  address immutable PAIRED_LP_TOKEN;\n  IProtocolFeeRouter immutable PROTOCOL_FEE_ROUTER;\n  IRewardsWhitelister immutable REWARDS_WHITELISTER;\n  IV3TwapUtilities immutable V3_TWAP_UTILS;\n\n  struct Reward {\n    uint256 excluded;\n    uint256 realized;\n  }\n\n  address public immutable override trackingToken;\n  address public immutable override rewardsToken; // main rewards token\n  uint256 public override totalShares;\n  uint256 public override totalStakers;\n  mapping(address => uint256) public shares;\n  // reward token => user => Reward\n  mapping(address => mapping(address => Reward)) public rewards;\n\n  uint256 _rewardsSwapSlippage = 20; // 2%\n  // reward token => amount\n  mapping(address => uint256) _rewardsPerShare;\n  // reward token => amount\n  mapping(address => uint256) public rewardsDistributed;\n  // reward token => amount\n  mapping(address => uint256) public rewardsDeposited;\n  // reward token => month => amount\n  mapping(address => mapping(uint256 => uint256)) public rewardsDepMonthly;\n  // all deposited rewards tokens\n  address[] _allRewardsTokens;\n  mapping(address => bool) _depositedRewardsToken;\n\n  constructor(\n    IProtocolFeeRouter _feeRouter,\n    IRewardsWhitelister _rewardsWhitelist,\n    IV3TwapUtilities _v3TwapUtilities,\n    address _v3Router,\n    address _indexFund,\n    address _pairedLpToken,\n    address _trackingToken,\n    address _rewardsToken\n  ) {\n    PROTOCOL_FEE_ROUTER = _feeRouter;\n    REWARDS_WHITELISTER = _rewardsWhitelist;\n    V3_TWAP_UTILS = _v3TwapUtilities;\n    V3_ROUTER = _v3Router;\n    INDEX_FUND = _indexFund;\n    PAIRED_LP_TOKEN = _pairedLpToken;\n    trackingToken = _trackingToken;\n    rewardsToken = _rewardsToken;\n  }\n\n  function setShares(\n    address _wallet,\n    uint256 _amount,\n    bool _sharesRemoving\n  ) external override {\n    require(_msgSender() == trackingToken, 'UNAUTHORIZED');\n    _setShares(_wallet, _amount, _sharesRemoving);\n  }\n\n  function _setShares(\n    address _wallet,\n    uint256 _amount,\n    bool _sharesRemoving\n  ) internal {\n    _processFeesIfApplicable();\n    if (_sharesRemoving) {\n      _removeShares(_wallet, _amount);\n      emit RemoveShares(_wallet, _amount);\n    } else {\n      _addShares(_wallet, _amount);\n      emit AddShares(_wallet, _amount);\n    }\n  }\n\n  function _addShares(address _wallet, uint256 _amount) internal {\n    if (shares[_wallet] > 0) {\n      _distributeReward(_wallet);\n    }\n    uint256 sharesBefore = shares[_wallet];\n    totalShares += _amount;\n    shares[_wallet] += _amount;\n    if (sharesBefore == 0 && shares[_wallet] > 0) {\n      totalStakers++;\n    }\n    _resetExcluded(_wallet);\n  }\n\n  function _removeShares(address _wallet, uint256 _amount) internal {\n    require(shares[_wallet] > 0 && _amount <= shares[_wallet], 'RE');\n    _distributeReward(_wallet);\n    totalShares -= _amount;\n    shares[_wallet] -= _amount;\n    if (shares[_wallet] == 0) {\n      totalStakers--;\n    }\n    _resetExcluded(_wallet);\n  }\n\n  function _processFeesIfApplicable() internal {\n    IDecentralizedIndex(INDEX_FUND).processPreSwapFeesAndSwap();\n  }\n\n  function depositFromPairedLpToken(\n    uint256 _amountTknDepositing,\n    uint256 _slippageOverride\n  ) public override {\n    require(PAIRED_LP_TOKEN != rewardsToken, 'R');\n    require(_slippageOverride <= 200, 'MS'); // 20%\n    if (_amountTknDepositing > 0) {\n      IERC20(PAIRED_LP_TOKEN).safeTransferFrom(\n        _msgSender(),\n        address(this),\n        _amountTknDepositing\n      );\n    }\n    uint256 _amountTkn = IERC20(PAIRED_LP_TOKEN).balanceOf(address(this));\n    require(_amountTkn > 0, 'A');\n    uint256 _adminAmt;\n    (uint256 _yieldAdminFee, ) = _getYieldFees();\n    if (_yieldAdminFee > 0) {\n      _adminAmt =\n        (_amountTkn * _yieldAdminFee) /\n        PROTOCOL_FEE_ROUTER.protocolFees().DEN();\n      _amountTkn -= _adminAmt;\n    }\n    (address _token0, address _token1) = PAIRED_LP_TOKEN < rewardsToken\n      ? (PAIRED_LP_TOKEN, rewardsToken)\n      : (rewardsToken, PAIRED_LP_TOKEN);\n    address _pool;\n    if (block.chainid == 42161) {\n      _pool = V3_TWAP_UTILS.getV3Pool(\n        IPeripheryImmutableState(V3_ROUTER).factory(),\n        _token0,\n        _token1\n      );\n    } else {\n      _pool = V3_TWAP_UTILS.getV3Pool(\n        IPeripheryImmutableState(V3_ROUTER).factory(),\n        _token0,\n        _token1,\n        REWARDS_POOL_FEE\n      );\n    }\n    uint160 _rewardsSqrtPriceX96 = V3_TWAP_UTILS\n      .sqrtPriceX96FromPoolAndInterval(_pool);\n    uint256 _rewardsPriceX96 = V3_TWAP_UTILS.priceX96FromSqrtPriceX96(\n      _rewardsSqrtPriceX96\n    );\n    uint256 _amountOut = _token0 == PAIRED_LP_TOKEN\n      ? (_rewardsPriceX96 * _amountTkn) / FixedPoint96.Q96\n      : (_amountTkn * FixedPoint96.Q96) / _rewardsPriceX96;\n\n    IERC20(PAIRED_LP_TOKEN).safeIncreaseAllowance(V3_ROUTER, _amountTkn);\n    uint256 _slippage = _slippageOverride > 0\n      ? _slippageOverride\n      : _rewardsSwapSlippage;\n    _swapForRewards(\n      _amountTkn,\n      _amountOut,\n      _slippage,\n      _slippageOverride > 0,\n      _adminAmt\n    );\n  }\n\n  function depositRewards(address _token, uint256 _amount) external override {\n    require(_amount > 0, 'A');\n    require(_isValidRewardsToken(_token), 'V');\n    uint256 _rewardsBalBefore = IERC20(_token).balanceOf(address(this));\n    IERC20(_token).safeTransferFrom(_msgSender(), address(this), _amount);\n    _depositRewards(\n      _token,\n      IERC20(_token).balanceOf(address(this)) - _rewardsBalBefore\n    );\n  }\n\n  function _depositRewards(address _token, uint256 _amountTotal) internal {\n    if (!_depositedRewardsToken[_token]) {\n      _depositedRewardsToken[_token] = true;\n      _allRewardsTokens.push(_token);\n    }\n    if (_amountTotal == 0) {\n      return;\n    }\n    if (totalShares == 0) {\n      require(_token == rewardsToken, 'R');\n      _burnRewards(_amountTotal);\n      return;\n    }\n\n    uint256 _depositAmount = _amountTotal;\n    if (_token == rewardsToken) {\n      (, uint256 _yieldBurnFee) = _getYieldFees();\n      if (_yieldBurnFee > 0) {\n        uint256 _burnAmount = (_amountTotal * _yieldBurnFee) /\n          PROTOCOL_FEE_ROUTER.protocolFees().DEN();\n        if (_burnAmount > 0) {\n          _burnRewards(_burnAmount);\n          _depositAmount -= _burnAmount;\n        }\n      }\n    }\n    rewardsDeposited[_token] += _depositAmount;\n    rewardsDepMonthly[_token][\n      beginningOfMonth(block.timestamp)\n    ] += _depositAmount;\n    _rewardsPerShare[_token] += (PRECISION * _depositAmount) / totalShares;\n    emit DepositRewards(_msgSender(), _token, _depositAmount);\n  }\n\n  function _distributeReward(address _wallet) internal {\n    if (shares[_wallet] == 0) {\n      return;\n    }\n    for (uint256 _i; _i < _allRewardsTokens.length; _i++) {\n      address _token = _allRewardsTokens[_i];\n      uint256 _amount = getUnpaid(_token, _wallet);\n      rewards[_token][_wallet].realized += _amount;\n      rewards[_token][_wallet].excluded = _cumulativeRewards(\n        _token,\n        shares[_wallet]\n      );\n      if (_amount > 0) {\n        rewardsDistributed[_token] += _amount;\n        IERC20(_token).safeTransfer(_wallet, _amount);\n        emit DistributeReward(_wallet, _token, _amount);\n      }\n    }\n  }\n\n  function _resetExcluded(address _wallet) internal {\n    for (uint256 _i; _i < _allRewardsTokens.length; _i++) {\n      address _token = _allRewardsTokens[_i];\n      rewards[_token][_wallet].excluded = _cumulativeRewards(\n        _token,\n        shares[_wallet]\n      );\n    }\n  }\n\n  function _burnRewards(uint256 _burnAmount) internal {\n    try IPEAS(rewardsToken).burn(_burnAmount) {} catch {\n      IERC20(rewardsToken).safeTransfer(address(0xdead), _burnAmount);\n    }\n  }\n\n  function _isValidRewardsToken(address _token) internal view returns (bool) {\n    return _token == rewardsToken || REWARDS_WHITELISTER.whitelist(_token);\n  }\n\n  function _getYieldFees()\n    internal\n    view\n    returns (uint256 _admin, uint256 _burn)\n  {\n    IProtocolFees _fees = PROTOCOL_FEE_ROUTER.protocolFees();\n    if (address(_fees) != address(0)) {\n      _admin = _fees.yieldAdmin();\n      _burn = _fees.yieldBurn();\n    }\n  }\n\n  function _swapForRewards(\n    uint256 _amountIn,\n    uint256 _amountOut,\n    uint256 _slippage,\n    bool _isSlipOverride,\n    uint256 _adminAmt\n  ) internal {\n    uint256 _rewardsBalBefore = IERC20(rewardsToken).balanceOf(address(this));\n    if (block.chainid == 42161) {\n      try\n        ISwapRouterAlgebra(V3_ROUTER).exactInputSingle(\n          ISwapRouterAlgebra.ExactInputSingleParams({\n            tokenIn: PAIRED_LP_TOKEN,\n            tokenOut: rewardsToken,\n            recipient: address(this),\n            deadline: block.timestamp,\n            amountIn: _amountIn,\n            amountOutMinimum: (_amountOut * (1000 - _slippage)) / 1000,\n            limitSqrtPrice: 0\n          })\n        )\n      {\n        if (_adminAmt > 0) {\n          IERC20(PAIRED_LP_TOKEN).safeTransfer(\n            Ownable(address(V3_TWAP_UTILS)).owner(),\n            _adminAmt\n          );\n        }\n        _rewardsSwapSlippage = 20;\n        _depositRewards(\n          rewardsToken,\n          IERC20(rewardsToken).balanceOf(address(this)) - _rewardsBalBefore\n        );\n      } catch {\n        if (!_isSlipOverride && _rewardsSwapSlippage < 200) {\n          _rewardsSwapSlippage += 10;\n        }\n        IERC20(PAIRED_LP_TOKEN).safeDecreaseAllowance(V3_ROUTER, _amountIn);\n      }\n    } else {\n      try\n        ISwapRouter(V3_ROUTER).exactInputSingle(\n          ISwapRouter.ExactInputSingleParams({\n            tokenIn: PAIRED_LP_TOKEN,\n            tokenOut: rewardsToken,\n            fee: REWARDS_POOL_FEE,\n            recipient: address(this),\n            deadline: block.timestamp,\n            amountIn: _amountIn,\n            amountOutMinimum: (_amountOut * (1000 - _slippage)) / 1000,\n            sqrtPriceLimitX96: 0\n          })\n        )\n      {\n        if (_adminAmt > 0) {\n          IERC20(PAIRED_LP_TOKEN).safeTransfer(\n            Ownable(address(V3_TWAP_UTILS)).owner(),\n            _adminAmt\n          );\n        }\n        _rewardsSwapSlippage = 10;\n        _depositRewards(\n          rewardsToken,\n          IERC20(rewardsToken).balanceOf(address(this)) - _rewardsBalBefore\n        );\n      } catch {\n        if (_rewardsSwapSlippage < 200) {\n          _rewardsSwapSlippage += 10;\n        }\n        IERC20(PAIRED_LP_TOKEN).safeDecreaseAllowance(V3_ROUTER, _amountIn);\n      }\n    }\n  }\n\n  function beginningOfMonth(uint256 _timestamp) public pure returns (uint256) {\n    (, , uint256 _dayOfMonth) = BokkyPooBahsDateTimeLibrary.timestampToDate(\n      _timestamp\n    );\n    return _timestamp - ((_dayOfMonth - 1) * 1 days) - (_timestamp % 1 days);\n  }\n\n  function claimReward(address _wallet) external override {\n    _distributeReward(_wallet);\n    emit ClaimReward(_wallet);\n  }\n\n  function getUnpaid(\n    address _token,\n    address _wallet\n  ) public view returns (uint256) {\n    if (shares[_wallet] == 0) {\n      return 0;\n    }\n    uint256 earnedRewards = _cumulativeRewards(_token, shares[_wallet]);\n    uint256 rewardsExcluded = rewards[_token][_wallet].excluded;\n    if (earnedRewards <= rewardsExcluded) {\n      return 0;\n    }\n    return earnedRewards - rewardsExcluded;\n  }\n\n  function _cumulativeRewards(\n    address _token,\n    uint256 _share\n  ) internal view returns (uint256) {\n    return (_share * _rewardsPerShare[_token]) / PRECISION;\n  }\n}\n"
      }
    },
    "settings": {
      "metadata": {
        "bytecodeHash": "none"
      },
      "optimizer": {
        "enabled": true,
        "runs": 200
      },
      "outputSelection": {
        "*": {
          "*": [
            "evm.bytecode",
            "evm.deployedBytecode",
            "devdoc",
            "userdoc",
            "metadata",
            "abi"
          ]
        }
      },
      "libraries": {}
    }
  }}