ETH Price: $3,398.22 (+2.96%)

Contract

0x3913245cB9c636EF8904a7A863B332082F0c58B0
 
Transaction Hash
Method
Block
From
To
0x60a06040201915442024-06-28 17:01:47148 days ago1719594107IN
 Create: CowExecutor
0 ETH0.016817357.95922021

View more zero value Internal Transactions in Advanced View mode

Advanced mode:
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
CowExecutor

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
paris EvmVersion
File 1 of 30 : CowExecutor.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import "@1inch/solidity-utils/contracts/libraries/RevertReasonParser.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "../libs/TokenLibrary.sol";
import "../Errors.sol";
import "./CowKyberExecutor.sol";
import "./CowMaverickExecutor.sol";
import "./CowMaverickV2Executor.sol";
import "./CowPancakeV3Executor.sol";
import "./CowUniswapV3Executor.sol";
import "../libs/SafeERC20Ext.sol";

contract CowExecutor is
    CowKyberExecutor,
    CowMaverickExecutor,
    CowMaverickV2Executor,
    CowPancakeV3Executor,
    CowUniswapV3Executor
{
    using TokenLibrary for IERC20;
    using SafeERC20Ext for IERC20;
    using SafeERC20 for IERC20;


    error Unauthorized();
    error ReceivedLessThanMinReturn(uint256, uint256);

    string public constant DESCRIPTION = "CowExecutor";

    address private immutable cowSettlementContract;

    uint256 private constant MIN_ALLOWANCE_REQUIRED = 2**250;

    constructor(address _cowSettlementContract) {
        cowSettlementContract = _cowSettlementContract;
    }

    modifier onlyCowSettlementContract() {
        if (msg.sender != cowSettlementContract) {
            revert Unauthorized();
        }
        _;
    }

    function guardedUnlimitedApprovedInteractionCall(uint256 minReturn, IERC20 sourceToken, IERC20 targetToken, address approveTarget, bool shouldTransfer, address target, bytes memory data) external payable onlyCowSettlementContract() {
        {
            bool shouldRevert;
            assembly {
                let sig := and(mload(add(data, 0x20)), 0xffffffff00000000000000000000000000000000000000000000000000000000)
                shouldRevert := eq(sig, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            }
            if (shouldRevert) {
                revert TransferFromNotAllowed();
            }
        }

        uint256 currentAllowance = sourceToken.allowance(address(this), approveTarget);
        if (currentAllowance < MIN_ALLOWANCE_REQUIRED) {
            if (currentAllowance > 0) {
                sourceToken.setAllowance(approveTarget, 0);
            }
            sourceToken.setAllowance(approveTarget, type(uint256).max);
        }

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory result) = target.call{value: msg.value}(data);
        if (!success) {
            string memory reason = RevertReasonParser.parse(
                result,
                "CowEx: "
            );
            revert(reason);
        }

        // decode response as uint256
        uint256 received;
        assembly {
            received := mload(add(result, 0x20))
        }

        if (received < minReturn) {
            revert ReceivedLessThanMinReturn(received, minReturn);
        }
        if (shouldTransfer) {
            targetToken.safeTransfer(msg.sender, received);
        }
    }

    function guardedUnlimitedApprovedInteractionValidatedBalanceCall(uint256 minReturn, IERC20 sourceToken, IERC20 targetToken, address approveTarget, address target, address recipient, bytes memory data) external payable onlyCowSettlementContract() {
        {
            bool shouldRevert;
            assembly {
                let sig := and(mload(add(data, 0x20)), 0xffffffff00000000000000000000000000000000000000000000000000000000)
                shouldRevert := eq(sig, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            }
            if (shouldRevert) {
                revert TransferFromNotAllowed();
            }
        }

        uint256 currentAllowance = sourceToken.allowance(address(this), approveTarget);
        if (currentAllowance < MIN_ALLOWANCE_REQUIRED) {
            if (currentAllowance > 0) {
                sourceToken.setAllowance(approveTarget, 0);
            }
            sourceToken.setAllowance(approveTarget, type(uint256).max);
        }

        uint256 targetBalanceBefore = targetToken.balanceOf(address(recipient));

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory result) = target.call{value: msg.value}(data);
        if (!success) {
            string memory reason = RevertReasonParser.parse(
                result,
                "CowEx: "
            );
            revert(reason);
        }

        uint256 received = targetToken.balanceOf(address(recipient)) - targetBalanceBefore;

        if (received < minReturn) {
            revert ReceivedLessThanMinReturn(received, minReturn);
        }

        if (recipient == address(this)) {
            targetToken.safeTransfer(msg.sender, received);
        }
    }

    function guardedReturnAmountCall(uint256 minReturn, address target, bytes memory data) external payable onlyCowSettlementContract() {
        {
            bool shouldRevert;
            assembly {
                let sig := and(mload(add(data, 0x20)), 0xffffffff00000000000000000000000000000000000000000000000000000000)
                shouldRevert := eq(sig, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            }
            if (shouldRevert) {
                revert TransferFromNotAllowed();
            }
        }

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory result) = target.call{value: msg.value}(data);
        if (!success) {
            string memory reason = RevertReasonParser.parse(
                result,
                "CowEx: "
            );
            revert(reason);
        }

        // decode response as uint256
        uint256 received;
        assembly {
            received := mload(add(result, 0x20))
        }

        if (received < minReturn) {
            revert ReceivedLessThanMinReturn(received, minReturn);
        }
    }

    function guardedUncheckedCall(address target, bytes memory data) external payable onlyCowSettlementContract() {
        {
            bool shouldRevert;
            assembly {
                let sig := and(mload(add(data, 0x20)), 0xffffffff00000000000000000000000000000000000000000000000000000000)
                shouldRevert := eq(sig, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            }
            if (shouldRevert) {
                revert TransferFromNotAllowed();
            }
        }

        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory result) = target.call{value: msg.value}(data);
        if (!success) {
            string memory reason = RevertReasonParser.parse(
                result,
                "CowEx: "
            );
            revert(reason);
        }
    }
}

File 2 of 30 : RevertReasonParser.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./StringUtil.sol";

/** @title Library that allows to parse unsuccessful arbitrary calls revert reasons.
 * See https://solidity.readthedocs.io/en/latest/control-structures.html#revert for details.
 * Note that we assume revert reason being abi-encoded as Error(string) so it may fail to parse reason
 * if structured reverts appear in the future.
 *
 * All unsuccessful parsings get encoded as Unknown(data) string
 */
library RevertReasonParser {
    using StringUtil for uint256;
    using StringUtil for bytes;

    error InvalidRevertReason();

    bytes4 private constant _ERROR_SELECTOR = bytes4(keccak256("Error(string)"));
    bytes4 private constant _PANIC_SELECTOR = bytes4(keccak256("Panic(uint256)"));

    /// @dev Parses error `data` and returns actual with `prefix`.
    function parse(bytes memory data, string memory prefix) internal pure returns (string memory) {
        // https://solidity.readthedocs.io/en/latest/control-structures.html#revert
        // We assume that revert reason is abi-encoded as Error(string)
        bytes4 selector;
        if (data.length >= 4) {
            assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
                selector := mload(add(data, 0x20))
            }
        }

        // 68 = 4-byte selector + 32 bytes offset + 32 bytes length
        if (selector == _ERROR_SELECTOR && data.length >= 68) {
            string memory reason;
            assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
                // 68 = 32 bytes data length + 4-byte selector + 32 bytes offset
                reason := add(data, 68)
            }
            /*
                revert reason is padded up to 32 bytes with ABI encoder: Error(string)
                also sometimes there is extra 32 bytes of zeros padded in the end:
                https://github.com/ethereum/solidity/issues/10170
                because of that we can't check for equality and instead check
                that string length + extra 68 bytes is equal or greater than overall data length
            */
            if (data.length >= 68 + bytes(reason).length) {
                return string.concat(prefix, "Error(", reason, ")");
            }
        }
        // 36 = 4-byte selector + 32 bytes integer
        else if (selector == _PANIC_SELECTOR && data.length == 36) {
            uint256 code;
            assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
                // 36 = 32 bytes data length + 4-byte selector
                code := mload(add(data, 36))
            }
            return string.concat(prefix, "Panic(", code.toHex(), ")");
        }
        return string.concat(prefix, "Unknown(", data.toHex(), ")");
    }
}

File 3 of 30 : StringUtil.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/// @title Library with gas-efficient string operations
library StringUtil {
    function toHex(uint256 value) internal pure returns (string memory) {
        return toHex(abi.encodePacked(value));
    }

    function toHex(address value) internal pure returns (string memory) {
        return toHex(abi.encodePacked(value));
    }

    /// @dev this is the assembly adaptation of highly optimized toHex16 code from Mikhail Vladimirov
    /// https://stackoverflow.com/a/69266989
    function toHex(bytes memory data) internal pure returns (string memory result) {
        assembly ("memory-safe") { // solhint-disable-line no-inline-assembly
            function _toHex16(input) -> output {
                output := or(
                    and(input, 0xFFFFFFFFFFFFFFFF000000000000000000000000000000000000000000000000),
                    shr(64, and(input, 0x0000000000000000FFFFFFFFFFFFFFFF00000000000000000000000000000000))
                )
                output := or(
                    and(output, 0xFFFFFFFF000000000000000000000000FFFFFFFF000000000000000000000000),
                    shr(32, and(output, 0x00000000FFFFFFFF000000000000000000000000FFFFFFFF0000000000000000))
                )
                output := or(
                    and(output, 0xFFFF000000000000FFFF000000000000FFFF000000000000FFFF000000000000),
                    shr(16, and(output, 0x0000FFFF000000000000FFFF000000000000FFFF000000000000FFFF00000000))
                )
                output := or(
                    and(output, 0xFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000),
                    shr(8, and(output, 0x00FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF0000))
                )
                output := or(
                    shr(4, and(output, 0xF000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000)),
                    shr(8, and(output, 0x0F000F000F000F000F000F000F000F000F000F000F000F000F000F000F000F00))
                )
                output := add(
                    add(0x3030303030303030303030303030303030303030303030303030303030303030, output),
                    mul(
                        and(
                            shr(4, add(output, 0x0606060606060606060606060606060606060606060606060606060606060606)),
                            0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F
                        ),
                        7 // Change 7 to 39 for lower case output
                    )
                )
            }

            result := mload(0x40)
            let length := mload(data)
            let resultLength := shl(1, length)
            let toPtr := add(result, 0x22) // 32 bytes for length + 2 bytes for '0x'
            mstore(0x40, add(toPtr, resultLength)) // move free memory pointer
            mstore(add(result, 2), 0x3078) // 0x3078 is right aligned so we write to `result + 2`
            // to store the last 2 bytes in the beginning of the string
            mstore(result, add(resultLength, 2)) // extra 2 bytes for '0x'

            for {
                let fromPtr := add(data, 0x20)
                let endPtr := add(fromPtr, length)
            } lt(fromPtr, endPtr) {
                fromPtr := add(fromPtr, 0x20)
            } {
                let rawData := mload(fromPtr)
                let hexData := _toHex16(rawData)
                mstore(toPtr, hexData)
                toPtr := add(toPtr, 0x20)
                hexData := _toHex16(shl(128, rawData))
                mstore(toPtr, hexData)
                toPtr := add(toPtr, 0x20)
            }
        }
    }
}

File 4 of 30 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @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.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
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].
     *
     * CAUTION: See Security Considerations above.
     */
    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 5 of 30 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @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 value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` 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 value) external returns (bool);
}

File 6 of 30 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

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

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @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).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // 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 cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

File 7 of 30 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @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://consensys.net/diligence/blog/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.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @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 or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * 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.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @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`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) 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 FailedInnerCall();
        }
    }
}

File 8 of 30 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.20;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }
}

File 9 of 30 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @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;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    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
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // 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;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}

File 10 of 30 : IUniswapV3SwapCallback.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

File 11 of 30 : IUniswapV3Pool.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import './pool/IUniswapV3PoolImmutables.sol';
import './pool/IUniswapV3PoolState.sol';
import './pool/IUniswapV3PoolDerivedState.sol';
import './pool/IUniswapV3PoolActions.sol';
import './pool/IUniswapV3PoolOwnerActions.sol';
import './pool/IUniswapV3PoolEvents.sol';

/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
    IUniswapV3PoolImmutables,
    IUniswapV3PoolState,
    IUniswapV3PoolDerivedState,
    IUniswapV3PoolActions,
    IUniswapV3PoolOwnerActions,
    IUniswapV3PoolEvents
{

}

File 12 of 30 : IUniswapV3PoolActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
    /// @notice Sets the initial price for the pool
    /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
    /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
    function initialize(uint160 sqrtPriceX96) external;

    /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
    /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
    /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
    /// on tickLower, tickUpper, the amount of liquidity, and the current price.
    /// @param recipient The address for which the liquidity will be created
    /// @param tickLower The lower tick of the position in which to add liquidity
    /// @param tickUpper The upper tick of the position in which to add liquidity
    /// @param amount The amount of liquidity to mint
    /// @param data Any data that should be passed through to the callback
    /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
    /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
    function mint(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount,
        bytes calldata data
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Collects tokens owed to a position
    /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
    /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
    /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
    /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
    /// @param recipient The address which should receive the fees collected
    /// @param tickLower The lower tick of the position for which to collect fees
    /// @param tickUpper The upper tick of the position for which to collect fees
    /// @param amount0Requested How much token0 should be withdrawn from the fees owed
    /// @param amount1Requested How much token1 should be withdrawn from the fees owed
    /// @return amount0 The amount of fees collected in token0
    /// @return amount1 The amount of fees collected in token1
    function collect(
        address recipient,
        int24 tickLower,
        int24 tickUpper,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);

    /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
    /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
    /// @dev Fees must be collected separately via a call to #collect
    /// @param tickLower The lower tick of the position for which to burn liquidity
    /// @param tickUpper The upper tick of the position for which to burn liquidity
    /// @param amount How much liquidity to burn
    /// @return amount0 The amount of token0 sent to the recipient
    /// @return amount1 The amount of token1 sent to the recipient
    function burn(
        int24 tickLower,
        int24 tickUpper,
        uint128 amount
    ) external returns (uint256 amount0, uint256 amount1);

    /// @notice Swap token0 for token1, or token1 for token0
    /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
    /// @param recipient The address to receive the output of the swap
    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
    /// @param data Any data to be passed through to the callback
    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);

    /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
    /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
    /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
    /// with 0 amount{0,1} and sending the donation amount(s) from the callback
    /// @param recipient The address which will receive the token0 and token1 amounts
    /// @param amount0 The amount of token0 to send
    /// @param amount1 The amount of token1 to send
    /// @param data Any data to be passed through to the callback
    function flash(
        address recipient,
        uint256 amount0,
        uint256 amount1,
        bytes calldata data
    ) external;

    /// @notice Increase the maximum number of price and liquidity observations that this pool will store
    /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
    /// the input observationCardinalityNext.
    /// @param observationCardinalityNext The desired minimum number of observations for the pool to store
    function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}

File 13 of 30 : IUniswapV3PoolDerivedState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
    /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
    /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
    /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
    /// you must call it with secondsAgos = [3600, 0].
    /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
    /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
    /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
    /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
    /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
    /// timestamp
    function observe(uint32[] calldata secondsAgos)
        external
        view
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);

    /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
    /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
    /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
    /// snapshot is taken and the second snapshot is taken.
    /// @param tickLower The lower tick of the range
    /// @param tickUpper The upper tick of the range
    /// @return tickCumulativeInside The snapshot of the tick accumulator for the range
    /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
    /// @return secondsInside The snapshot of seconds per liquidity for the range
    function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
        external
        view
        returns (
            int56 tickCumulativeInside,
            uint160 secondsPerLiquidityInsideX128,
            uint32 secondsInside
        );
}

File 14 of 30 : IUniswapV3PoolEvents.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
    /// @notice Emitted exactly once by a pool when #initialize is first called on the pool
    /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
    /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
    /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
    event Initialize(uint160 sqrtPriceX96, int24 tick);

    /// @notice Emitted when liquidity is minted for a given position
    /// @param sender The address that minted the liquidity
    /// @param owner The owner of the position and recipient of any minted liquidity
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity minted to the position range
    /// @param amount0 How much token0 was required for the minted liquidity
    /// @param amount1 How much token1 was required for the minted liquidity
    event Mint(
        address sender,
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted when fees are collected by the owner of a position
    /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
    /// @param owner The owner of the position for which fees are collected
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount0 The amount of token0 fees collected
    /// @param amount1 The amount of token1 fees collected
    event Collect(
        address indexed owner,
        address recipient,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount0,
        uint128 amount1
    );

    /// @notice Emitted when a position's liquidity is removed
    /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
    /// @param owner The owner of the position for which liquidity is removed
    /// @param tickLower The lower tick of the position
    /// @param tickUpper The upper tick of the position
    /// @param amount The amount of liquidity to remove
    /// @param amount0 The amount of token0 withdrawn
    /// @param amount1 The amount of token1 withdrawn
    event Burn(
        address indexed owner,
        int24 indexed tickLower,
        int24 indexed tickUpper,
        uint128 amount,
        uint256 amount0,
        uint256 amount1
    );

    /// @notice Emitted by the pool for any swaps between token0 and token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the output of the swap
    /// @param amount0 The delta of the token0 balance of the pool
    /// @param amount1 The delta of the token1 balance of the pool
    /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
    /// @param liquidity The liquidity of the pool after the swap
    /// @param tick The log base 1.0001 of price of the pool after the swap
    event Swap(
        address indexed sender,
        address indexed recipient,
        int256 amount0,
        int256 amount1,
        uint160 sqrtPriceX96,
        uint128 liquidity,
        int24 tick
    );

    /// @notice Emitted by the pool for any flashes of token0/token1
    /// @param sender The address that initiated the swap call, and that received the callback
    /// @param recipient The address that received the tokens from flash
    /// @param amount0 The amount of token0 that was flashed
    /// @param amount1 The amount of token1 that was flashed
    /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
    /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
    event Flash(
        address indexed sender,
        address indexed recipient,
        uint256 amount0,
        uint256 amount1,
        uint256 paid0,
        uint256 paid1
    );

    /// @notice Emitted by the pool for increases to the number of observations that can be stored
    /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
    /// just before a mint/swap/burn.
    /// @param observationCardinalityNextOld The previous value of the next observation cardinality
    /// @param observationCardinalityNextNew The updated value of the next observation cardinality
    event IncreaseObservationCardinalityNext(
        uint16 observationCardinalityNextOld,
        uint16 observationCardinalityNextNew
    );

    /// @notice Emitted when the protocol fee is changed by the pool
    /// @param feeProtocol0Old The previous value of the token0 protocol fee
    /// @param feeProtocol1Old The previous value of the token1 protocol fee
    /// @param feeProtocol0New The updated value of the token0 protocol fee
    /// @param feeProtocol1New The updated value of the token1 protocol fee
    event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);

    /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
    /// @param sender The address that collects the protocol fees
    /// @param recipient The address that receives the collected protocol fees
    /// @param amount0 The amount of token0 protocol fees that is withdrawn
    /// @param amount0 The amount of token1 protocol fees that is withdrawn
    event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}

File 15 of 30 : IUniswapV3PoolImmutables.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
    /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
    /// @return The contract address
    function factory() external view returns (address);

    /// @notice The first of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token0() external view returns (address);

    /// @notice The second of the two tokens of the pool, sorted by address
    /// @return The token contract address
    function token1() external view returns (address);

    /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
    /// @return The fee
    function fee() external view returns (uint24);

    /// @notice The pool tick spacing
    /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
    /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
    /// This value is an int24 to avoid casting even though it is always positive.
    /// @return The tick spacing
    function tickSpacing() external view returns (int24);

    /// @notice The maximum amount of position liquidity that can use any tick in the range
    /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
    /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
    /// @return The max amount of liquidity per tick
    function maxLiquidityPerTick() external view returns (uint128);
}

File 16 of 30 : IUniswapV3PoolOwnerActions.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
    /// @notice Set the denominator of the protocol's % share of the fees
    /// @param feeProtocol0 new protocol fee for token0 of the pool
    /// @param feeProtocol1 new protocol fee for token1 of the pool
    function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;

    /// @notice Collect the protocol fee accrued to the pool
    /// @param recipient The address to which collected protocol fees should be sent
    /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
    /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
    /// @return amount0 The protocol fee collected in token0
    /// @return amount1 The protocol fee collected in token1
    function collectProtocol(
        address recipient,
        uint128 amount0Requested,
        uint128 amount1Requested
    ) external returns (uint128 amount0, uint128 amount1);
}

File 17 of 30 : IUniswapV3PoolState.sol
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
    /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
    /// when accessed externally.
    /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
    /// tick The current tick of the pool, i.e. according to the last tick transition that was run.
    /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
    /// boundary.
    /// observationIndex The index of the last oracle observation that was written,
    /// observationCardinality The current maximum number of observations stored in the pool,
    /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
    /// feeProtocol The protocol fee for both tokens of the pool.
    /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
    /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
    /// unlocked Whether the pool is currently locked to reentrancy
    function slot0()
        external
        view
        returns (
            uint160 sqrtPriceX96,
            int24 tick,
            uint16 observationIndex,
            uint16 observationCardinality,
            uint16 observationCardinalityNext,
            uint8 feeProtocol,
            bool unlocked
        );

    /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal0X128() external view returns (uint256);

    /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
    /// @dev This value can overflow the uint256
    function feeGrowthGlobal1X128() external view returns (uint256);

    /// @notice The amounts of token0 and token1 that are owed to the protocol
    /// @dev Protocol fees will never exceed uint128 max in either token
    function protocolFees() external view returns (uint128 token0, uint128 token1);

    /// @notice The currently in range liquidity available to the pool
    /// @dev This value has no relationship to the total liquidity across all ticks
    function liquidity() external view returns (uint128);

    /// @notice Look up information about a specific tick in the pool
    /// @param tick The tick to look up
    /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
    /// tick upper,
    /// liquidityNet how much liquidity changes when the pool price crosses the tick,
    /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
    /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
    /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
    /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
    /// secondsOutside the seconds spent on the other side of the tick from the current tick,
    /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
    /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
    /// In addition, these values are only relative and must be used only in comparison to previous snapshots for
    /// a specific position.
    function ticks(int24 tick)
        external
        view
        returns (
            uint128 liquidityGross,
            int128 liquidityNet,
            uint256 feeGrowthOutside0X128,
            uint256 feeGrowthOutside1X128,
            int56 tickCumulativeOutside,
            uint160 secondsPerLiquidityOutsideX128,
            uint32 secondsOutside,
            bool initialized
        );

    /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
    function tickBitmap(int16 wordPosition) external view returns (uint256);

    /// @notice Returns the information about a position by the position's key
    /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
    /// @return _liquidity The amount of liquidity in the position,
    /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
    /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
    /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
    /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
    function positions(bytes32 key)
        external
        view
        returns (
            uint128 _liquidity,
            uint256 feeGrowthInside0LastX128,
            uint256 feeGrowthInside1LastX128,
            uint128 tokensOwed0,
            uint128 tokensOwed1
        );

    /// @notice Returns data about a specific observation index
    /// @param index The element of the observations array to fetch
    /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
    /// ago, rather than at a specific index in the array.
    /// @return blockTimestamp The timestamp of the observation,
    /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
    /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
    /// Returns initialized whether the observation has been initialized and the values are safe to use
    function observations(uint256 index)
        external
        view
        returns (
            uint32 blockTimestamp,
            int56 tickCumulative,
            uint160 secondsPerLiquidityCumulativeX128,
            bool initialized
        );
}

File 18 of 30 : Constants.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

uint256 constant _ONE = 1e18;

address constant MAVERICK_FACTORY = 0xEb6625D65a0553c9dBc64449e56abFe519bd9c9B;
address constant MAVERICKV2_FACTORY = 0x0A7e848Aca42d879EF06507Fca0E7b33A0a63c1e;

File 19 of 30 : CowKyberExecutor.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "../interfaces/Kyber.sol";
import "../Errors.sol";

/**
 * @title KyberExecutor
 * @notice Base contract that contains Kyber specific logic.
 * Kyber requires specific interface to be implemented so we have to provide a compliant implementation
 */
abstract contract CowKyberExecutor is ISwapCallback {
    using SafeERC20 for IERC20;
    using SafeCast for uint256;

    bytes32 private constant SELECTORS = 0x0dfe1681d21220a7c79a590e0000000000000000000000000000000000000000;
    bytes32 private constant INIT_CODE_HASH = 0x00e263aaa3a2c06a89b53217a9e7aad7e15613490a72e0f95f303c4de2dc7045;
    bytes32 private constant PREFIXED_FACTORY = 0xffc7a590291e07b9fe9e64b86c58fd8fc764308c4a0000000000000000000000;
    uint256 private constant ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;

    function swapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external override {
        bool isBadPool;
        uint256 amountIn;
        uint256 amountOut;
        IERC20 token;

        uint256 minReturn;
        address cowSettlement;

        assembly {
            function reRevert() {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }

            let workingAddress := mload(0x40) // EVM free memory pointer
            mstore(workingAddress, SELECTORS)

            // we need to write hash just after the address PREFIXED_FACTORY constant in place of its zeroes,
            // hence offset is 21 bytes
            let feeTokensAddress := add(workingAddress, 21)
            if iszero(staticcall(gas(), caller(), workingAddress, 0x4, feeTokensAddress, 0x20)) {
                reRevert()
            }
            if iszero(staticcall(gas(), caller(), add(workingAddress, 0x4), 0x4, add(feeTokensAddress, 32), 0x20)) {
                reRevert()
            }
            if iszero(staticcall(gas(), caller(), add(workingAddress, 0x8), 0x4, add(feeTokensAddress, 64), 0x20)) {
                reRevert()
            }

            switch sgt(amount0Delta, 0)
            case 1 {
                amountIn := amount0Delta
                amountOut := sub(0, amount1Delta) // negate
                token := mload(feeTokensAddress)
            }
            default {
                amountIn := amount1Delta
                amountOut := sub(0, amount0Delta) // negate
                token := mload(add(feeTokensAddress, 32))
            }

            mstore(workingAddress, PREFIXED_FACTORY)
            mstore(feeTokensAddress, keccak256(feeTokensAddress, 96))
            mstore(add(feeTokensAddress, 32), INIT_CODE_HASH)
            let pool := and(keccak256(workingAddress, 85), ADDRESS_MASK)
            isBadPool := xor(pool, caller())

            minReturn := calldataload(data.offset)
            cowSettlement := calldataload(add(data.offset, 32))
        }

        if (isBadPool) {
            revert BadUniswapV3LikePool(UniswapV3LikeProtocol.Kyber);
        }

        if (amountOut < minReturn) {
            revert MinReturnError(amountOut, minReturn);
        }

        token.safeTransferFrom(cowSettlement, msg.sender, amountIn);
    }
}

File 20 of 30 : CowMaverickExecutor.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "../Errors.sol";
import "../interfaces/Maverick.sol";
import "../Constants.sol";

abstract contract CowMaverickExecutor is IMaverickSwapCallback {
    using SafeERC20 for IERC20;
    using SafeCast for uint256;

    IMaverickFactory private constant FACTORY = IMaverickFactory(MAVERICK_FACTORY);

    function swapCallback(
        uint256 amountIn,
        uint256 amountOut,
        bytes calldata data
    ) external override {
        bool isBadPool = !FACTORY.isFactoryPool(msg.sender);

        if (isBadPool) {
            revert BadUniswapV3LikePool(UniswapV3LikeProtocol.Maverick);
        }

        IERC20 token;
        uint256 minReturn;
        address cowSettlement;

        assembly {
            token := calldataload(data.offset)
            minReturn := calldataload(add(data.offset, 0x20))
            cowSettlement := calldataload(add(data.offset, 0x40))
        }

        if (amountOut < minReturn) {
            revert MinReturnError(amountOut, minReturn);
        }

        token.safeTransferFrom(cowSettlement, msg.sender, amountIn);
    }
}

File 21 of 30 : CowMaverickV2Executor.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "../Errors.sol";
import "../interfaces/MaverickV2.sol";
import "../Constants.sol";

abstract contract CowMaverickV2Executor is IMaverickV2SwapCallback {
    using SafeERC20 for IERC20;
    using SafeCast for uint256;

    IMaverickV2Factory private constant FACTORY = IMaverickV2Factory(MAVERICKV2_FACTORY);

    function maverickV2SwapCallback(
        IERC20 tokenIn,
        uint256 amountIn,
        uint256 amountOut,
        bytes calldata data
    ) external override {
        bool isBadPool = !FACTORY.isFactoryPool(msg.sender);

        if (isBadPool) {
            revert BadUniswapV3LikePool(UniswapV3LikeProtocol.MaverickV2);
        }

        uint256 minReturn;
        address cowSettlement;

        assembly {
            minReturn := calldataload(data.offset)
            cowSettlement := calldataload(add(data.offset, 0x20))
        }

        if (amountOut < minReturn) {
            revert MinReturnError(amountOut, minReturn);
        }

        tokenIn.safeTransferFrom(cowSettlement, msg.sender, amountIn);
    }
}

File 22 of 30 : CowPancakeV3Executor.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "../interfaces/PancakeV3.sol";
import "../Errors.sol";

/**
 * @title PancakeV3Executor
 * @notice Base contract that contains PancakeV3 specific logic.
 * PancakeV3 requires specific interface to be implemented so we have to provide a compliant implementation
 */
abstract contract CowPancakeV3Executor is IPancakeV3SwapCallback {
    using SafeERC20 for IERC20;
    using SafeCast for uint256;

    bytes32 private constant SELECTORS = 0x0dfe1681d21220a7ddca3f430000000000000000000000000000000000000000;
    bytes32 private constant INIT_CODE_HASH = 0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2;
    bytes32 private constant PREFIXED_DEPLOYER = 0xff41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c90000000000000000000000;
    uint256 private constant ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;

    function pancakeV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external override {
        bool isBadPool;
        uint256 amountIn;
        uint256 amountOut;
        IERC20 token;

        uint256 minReturn;
        address cowSettlement;

        assembly {
            function reRevert() {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }

            let workingAddress := mload(0x40) // EVM free memory pointer
            mstore(workingAddress, SELECTORS)

            // we need to write hash just after the address PREFIXED_FACTORY constant in place of its zeroes,
            // hence offset is 21 bytes
            let feeTokensAddress := add(workingAddress, 21)
            if iszero(staticcall(gas(), caller(), workingAddress, 0x4, feeTokensAddress, 0x20)) {
                reRevert()
            }
            if iszero(staticcall(gas(), caller(), add(workingAddress, 0x4), 0x4, add(feeTokensAddress, 32), 0x20)) {
                reRevert()
            }
            if iszero(staticcall(gas(), caller(), add(workingAddress, 0x8), 0x4, add(feeTokensAddress, 64), 0x20)) {
                reRevert()
            }

            switch sgt(amount0Delta, 0)
            case 1 {
                amountIn := amount0Delta
                amountOut := sub(0, amount1Delta) // negate
                token := mload(feeTokensAddress)
            }
            default {
                amountIn := amount1Delta
                amountOut := sub(0, amount0Delta) // negate
                token := mload(add(feeTokensAddress, 32))
            }

            mstore(workingAddress, PREFIXED_DEPLOYER)
            mstore(feeTokensAddress, keccak256(feeTokensAddress, 96))
            mstore(add(feeTokensAddress, 32), INIT_CODE_HASH)
            let pool := and(keccak256(workingAddress, 85), ADDRESS_MASK)
            isBadPool := xor(pool, caller())

            minReturn := calldataload(data.offset)
            cowSettlement := calldataload(add(data.offset, 32))
        }

        if (isBadPool) {
            revert BadUniswapV3LikePool(UniswapV3LikeProtocol.Pancake);
        }

        if (amountOut < minReturn) {
            revert MinReturnError(amountOut, minReturn);
        }

        token.safeTransferFrom(cowSettlement, msg.sender, amountIn);
    }
}

File 23 of 30 : CowUniswapV3Executor.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeCast.sol";
import "../Errors.sol";

/**
 * @title UniswapV3Executor
 * @notice Base contract that contains Uniswap V3 specific logic.
 * Uniswap V3 requires specific interface to be implemented so we have to provide a compliant implementation
 */
abstract contract CowUniswapV3Executor is IUniswapV3SwapCallback {
    using SafeERC20 for IERC20;
    using SafeCast for uint256;

    bytes32 private constant SELECTORS = 0x0dfe1681d21220a7ddca3f430000000000000000000000000000000000000000;
    bytes32 private constant INIT_CODE_HASH = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
    bytes32 private constant PREFIXED_FACTORY_UNI3  = 0xff1F98431c8aD98523631AE4a59f267346ea31F9840000000000000000000000;
    bytes32 private constant PREFIXED_FACTORY_SUSHI = 0xffbACEB8eC6b9355Dfc0269C18bac9d6E2Bdc29C4F0000000000000000000000;
    uint256 private constant ADDRESS_MASK = 0x000000000000000000000000ffffffffffffffffffffffffffffffffffffffff;

    function uniswapV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external override {
        bool isBadPool;
        uint256 amountIn;
        uint256 amountOut;
        IERC20 token;

        uint256 minReturn;
        address cowSettlement;

        assembly {
            function reRevert() {
                let ptr := mload(0x40)
                returndatacopy(ptr, 0, returndatasize())
                revert(ptr, returndatasize())
            }

            let workingAddress := mload(0x40) // EVM free memory pointer
            mstore(workingAddress, SELECTORS)

            // we need to write hash just after the address PREFIXED_FACTORY constant in place of its zeroes,
            // hence offset is 21 bytes
            let feeTokensAddress := add(workingAddress, 21)
            if iszero(staticcall(gas(), caller(), workingAddress, 0x4, feeTokensAddress, 0x20)) {
                reRevert()
            }
            if iszero(staticcall(gas(), caller(), add(workingAddress, 0x4), 0x4, add(feeTokensAddress, 32), 0x20)) {
                reRevert()
            }
            if iszero(staticcall(gas(), caller(), add(workingAddress, 0x8), 0x4, add(feeTokensAddress, 64), 0x20)) {
                reRevert()
            }

            switch sgt(amount0Delta, 0)
            case 1 {
                amountIn := amount0Delta
                amountOut := sub(0, amount1Delta) // negate
                token := mload(feeTokensAddress)
            }
            default {
                amountIn := amount1Delta
                amountOut := sub(0, amount0Delta) // negate
                token := mload(add(feeTokensAddress, 32))
            }

            let poolType := calldataload(add(data.offset, 64))

            switch poolType
            case 0 {
                mstore(workingAddress, PREFIXED_FACTORY_UNI3)
            }
            case 1 {
                mstore(workingAddress, PREFIXED_FACTORY_SUSHI)
            }
            default {
                mstore(workingAddress, 0x0) // TODO: revert with proper message
            }

            mstore(feeTokensAddress, keccak256(feeTokensAddress, 96))
            mstore(add(feeTokensAddress, 32), INIT_CODE_HASH)
            let pool := and(keccak256(workingAddress, 85), ADDRESS_MASK)
            isBadPool := xor(pool, caller())

            minReturn := calldataload(data.offset)
            cowSettlement := calldataload(add(data.offset, 32))
        }

        if (isBadPool) {
            revert BadUniswapV3LikePool(UniswapV3LikeProtocol.Uniswap);
        }

        if (amountOut < minReturn) {
            revert MinReturnError(amountOut, minReturn);
        }

        token.safeTransferFrom(cowSettlement, msg.sender, amountIn);
    }
}

File 24 of 30 : Errors.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

enum EnumType {
    SourceTokenInteraction,
    TargetTokenInteraction,
    CallType
}

enum UniswapV3LikeProtocol {
    Uniswap,
    Kyber,
    Maverick,
    MaverickV2,
    Pancake,
    Camelot
}

error EthValueAmountMismatch();
error EthValueSourceTokenMismatch();
error MinReturnError(uint256, uint256);
error EmptySwapOnExecutor();
error EmptySwap();
error ZeroInput();
error ZeroRecipient();
error TransactionExpired(uint256, uint256);
error PermitNotAllowedForEthSwap();
error SwapTotalAmountCannotBeZero();
error SwapAmountCannotBeZero();
error DirectEthDepositIsForbidden();
error MStableInvalidSwapType(uint256);
error AddressCannotBeZero();
error TransferFromNotAllowed();
error EnumOutOfRangeValue(EnumType, uint256);
error BadUniswapV3LikePool(UniswapV3LikeProtocol);
error ERC1820InterfactionForbidden();
error SingleOutputTokenAllowed(address, address);
error TransferCallbackCallerIsNotOrderBook();
error UnknownPoolType(uint256);

File 25 of 30 : Kyber.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

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

/// @title Callback for IPool#swap
/// @notice Any contract that calls IPool#swap must implement this interface
interface ISwapCallback {
  /// @notice Called to `msg.sender` after swap execution of IPool#swap.
  /// @dev This function's implementation must pay tokens owed to the pool for the swap.
  /// The caller of this method must be checked to be a Pool deployed by the canonical Factory.
  /// deltaQty0 and deltaQty1 can both be 0 if no tokens were swapped.
  /// @param deltaQty0 The token0 quantity that was sent (negative) or must be received (positive) by the pool by
  /// the end of the swap. If positive, the callback must send deltaQty0 of token0 to the pool.
  /// @param deltaQty1 The token1 quantity that was sent (negative) or must be received (positive) by the pool by
  /// the end of the swap. If positive, the callback must send deltaQty1 of token1 to the pool.
  /// @param data Data passed through by the caller via the IPool#swap call
  function swapCallback(
    int256 deltaQty0,
    int256 deltaQty1,
    bytes calldata data
  ) external;
}


interface IPoolActions {
  /// @notice Swap token0 -> token1, or vice versa
  /// @dev This method's caller receives a callback in the form of ISwapCallback#swapCallback
  /// @dev swaps will execute up to limitSqrtP or swapQty is fully used
  /// @param recipient The address to receive the swap output
  /// @param swapQty The swap quantity, which implicitly configures the swap as exact input (>0), or exact output (<0)
  /// @param isToken0 Whether the swapQty is specified in token0 (true) or token1 (false)
  /// @param limitSqrtP the limit of sqrt price after swapping
  /// could be MAX_SQRT_RATIO-1 when swapping 1 -> 0 and MIN_SQRT_RATIO+1 when swapping 0 -> 1 for no limit swap
  /// @param data Any data to be passed through to the callback
  /// @return qty0 Exact token0 qty sent to recipient if < 0. Minimally received quantity if > 0.
  /// @return qty1 Exact token1 qty sent to recipient if < 0. Minimally received quantity if > 0.
  function swap(
    address recipient,
    int256 swapQty,
    bool isToken0,
    uint160 limitSqrtP,
    bytes calldata data
  ) external returns (int256 qty0, int256 qty1);
}

interface IPoolStorage {
  /// @notice The first of the two tokens of the pool, sorted by address
  /// @return The token contract address
  function token0() external view returns (IERC20);

  /// @notice The second of the two tokens of the pool, sorted by address
  /// @return The token contract address
  function token1() external view returns (IERC20);
}

// solhint-disable-next-line no-empty-blocks
interface IPool is IPoolActions, IPoolStorage {}

File 26 of 30 : Maverick.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface IMaverickPool {
    struct State {
        int32 activeTick;
        uint8 status;
        uint128 binCounter;
        uint64 protocolFeeRatio;
    }

    function getState() external view returns (State memory);

    function swap(
        address recipient,
        uint256 amount,
        bool tokenAIn,
        bool exactOutput,
        uint256 sqrtPriceLimit,
        bytes calldata data
    ) external returns (uint256 amountIn, uint256 amountOut);
}

interface IMaverickSwapCallback {
    function swapCallback(
        uint256 amountIn,
        uint256 amountOut,
        bytes calldata data
    ) external;
}

interface IMaverickFactory {
    function isFactoryPool(address pool) external view returns (bool);
}

File 27 of 30 : MaverickV2.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

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

interface IMaverickV2Pool {
    struct State {
        uint128 reserveA;
        uint128 reserveB;
        int64 lastTwaD8;
        int64 lastLogPriceD8;
        uint40 lastTimestamp;
        int32 activeTick;
        bool isLocked;
        uint32 binCounter;
        uint8 protocolFeeRatioD3;
    }
    struct TickState {
        uint128 reserveA;
        uint128 reserveB;
        uint128 totalSupply;
        uint32[4] binIdsByTick;
    }
    struct BinState {
        uint128 mergeBinBalance;
        uint128 tickBalance;
        uint128 totalSupply;
        uint8 kind;
        int32 tick;
        uint32 mergeId;
    }
    struct SwapParams {
        uint256 amount;
        bool tokenAIn;
        bool exactOutput;
        int32 tickLimit;
    }
    function getState() external view returns (State memory);

    function swap(address recipient, SwapParams memory params, bytes calldata data)
    external
    returns (uint256 amountIn, uint256 amountOut);
}

interface IMaverickV2SwapCallback {
    function maverickV2SwapCallback(
        IERC20 tokenIn,
        uint256 amountIn,
        uint256 amountOut,
        bytes calldata data
    ) external;
}

interface IMaverickV2Factory {
    function isFactoryPool(address pool) external view returns (bool);
}

File 28 of 30 : PancakeV3.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

interface IPancakeV3Pool {
    /// @notice Swap token0 for token1, or token1 for token0
    /// @dev The caller of this method receives a callback in the form of IPancakeV3SwapCallback#pancakeV3SwapCallback
    /// @param recipient The address to receive the output of the swap
    /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
    /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
    /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
    /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
    /// @param data Any data to be passed through to the callback
    /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
    /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
    function swap(
        address recipient,
        bool zeroForOne,
        int256 amountSpecified,
        uint160 sqrtPriceLimitX96,
        bytes calldata data
    ) external returns (int256 amount0, int256 amount1);
}

/// @title Callback for IPancakeV3PoolActions#swap
/// @notice Any contract that calls IPancakeV3PoolActions#swap must implement this interface
interface IPancakeV3SwapCallback {
    /// @notice Called to `msg.sender` after executing a swap via IPancakeV3Pool#swap.
    /// @dev In the implementation you must pay the pool tokens owed for the swap.
    /// The caller of this method must be checked to be a PancakeV3Pool deployed by the canonical PancakeV3Factory.
    /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
    /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
    /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
    /// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
    /// @param data Any data passed through by the caller via the IPancakeV3PoolActions#swap call
    function pancakeV3SwapCallback(
        int256 amount0Delta,
        int256 amount1Delta,
        bytes calldata data
    ) external;
}

interface IPancakeV3Factory {
    function isFactoryPool(address pool) external view returns (bool);
}

File 29 of 30 : SafeERC20Ext.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

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

library SafeERC20Ext {
    error SafeERC20FailedOperationBarter(address token);

    using Address for address;

    /// @notice Overwrites current allowance to new value. This might be unsafe for some uses so be careful
    function setAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, value)));
    }

    /**
     * @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);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperationBarter(address(token));
        }
    }
}

File 30 of 30 : TokenLibrary.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;
pragma abicoder v1;

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

/**
 * @title TokenLibrary
 * @notice Library for basic interactions with tokens (such as deposits, withdrawals, transfers)
 */
library TokenLibrary {
    using SafeERC20 for IERC20;

    function isEth(IERC20 token) internal pure returns(bool) {
        return address(token) == address(0) || address(token) == address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
    }

    function universalBalanceOf(IERC20 token, address account) internal view returns (uint256) {
        if (isEth(token)) {
            return account.balance;
        } else {
            return token.balanceOf(account);
        }
    }

    function universalTransfer(IERC20 token, address payable to, uint256 amount) internal {
        if (amount == 0) {
            return;
        }
        if (isEth(token)) {
            to.transfer(amount);
        } else {
            token.safeTransfer(to, amount);
        }
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 1000000
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"_cowSettlementContract","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[{"internalType":"enum UniswapV3LikeProtocol","name":"","type":"uint8"}],"name":"BadUniswapV3LikePool","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"MinReturnError","type":"error"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"ReceivedLessThanMinReturn","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperationBarter","type":"error"},{"inputs":[],"name":"TransferFromNotAllowed","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"DESCRIPTION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"guardedReturnAmountCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"guardedUncheckedCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"contract IERC20","name":"sourceToken","type":"address"},{"internalType":"contract IERC20","name":"targetToken","type":"address"},{"internalType":"address","name":"approveTarget","type":"address"},{"internalType":"bool","name":"shouldTransfer","type":"bool"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"guardedUnlimitedApprovedInteractionCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"contract IERC20","name":"sourceToken","type":"address"},{"internalType":"contract IERC20","name":"targetToken","type":"address"},{"internalType":"address","name":"approveTarget","type":"address"},{"internalType":"address","name":"target","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"guardedUnlimitedApprovedInteractionValidatedBalanceCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"maverickV2SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"pancakeV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"amount0Delta","type":"int256"},{"internalType":"int256","name":"amount1Delta","type":"int256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"uniswapV3SwapCallback","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60a06040523480156200001157600080fd5b506040516200265638038062002656833981016040819052620000349162000046565b6001600160a01b031660805262000078565b6000602082840312156200005957600080fd5b81516001600160a01b03811681146200007157600080fd5b9392505050565b6080516125ad620000a9600039600081816104110152818161087e01528181610bcf015261106a01526125ad6000f3fe6080604052600436106100b15760003560e01c8063d7bb6ce411610069578063f1ae88561161004e578063f1ae885614610164578063fa461e33146101c3578063fa483e72146101e357600080fd5b8063d7bb6ce41461013e578063f0784eb21461015157600080fd5b806367ca7c911161009a57806367ca7c91146100eb578063923b8a2a1461010b578063ce71781f1461012b57600080fd5b806323a69e75146100b65780634379435e146100d8575b600080fd5b3480156100c257600080fd5b506100d66100d1366004611f9a565b610203565b005b6100d66100e63660046120e9565b6103f9565b3480156100f757600080fd5b506100d6610106366004612139565b6105e5565b34801561011757600080fd5b506100d6610126366004611f9a565b610728565b6100d66101393660046121b1565b610866565b6100d661014c366004612255565b610bb7565b6100d661015f3660046122b2565b611052565b34801561017057600080fd5b506101ad6040518060400160405280600b81526020017f436f774578656375746f7200000000000000000000000000000000000000000081525081565b6040516101ba919061232f565b60405180910390f35b3480156101cf57600080fd5b506100d66101de366004611f9a565b61124a565b3480156101ef57600080fd5b506100d66101fe366004611f9a565b6113f4565b60008060008060008061021d565b6040513d6000823e3d81fd5b6040517f0dfe1681d21220a7ddca3f430000000000000000000000000000000000000000815260158101602081600484335afa61025c5761025c610211565b60208082016004808501335afa61027557610275610211565b602060408201600460088501335afa61029057610290610211565b60008c13600181146102b1578b97508c6000039650602082015195506102bf565b8c97508b6000039650815195505b507fff41ff9aa7e16b8b1a8a8dc4f0efacd93d02d071c9000000000000000000000082526060812081527f6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e260208201525073ffffffffffffffffffffffffffffffffffffffff6055822016905033811896505087359150602088013590508515610382576040517fca275977000000000000000000000000000000000000000000000000000000008152600490810180825b815260200191505060405180910390fd5b818410156103cb57604080517f643f0c86000000000000000000000000000000000000000000000000000000008152600481018690526024810184905290519081900360440190fd5b6103ed73ffffffffffffffffffffffffffffffffffffffff8416823388611555565b50505050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610468576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd000000000000000000000000000000000000000000000000000000001480156104e9576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506000808373ffffffffffffffffffffffffffffffffffffffff1634846040516105139190612380565b60006040518083038185875af1925050503d8060008114610550576040519150601f19603f3d011682016040523d82523d6000602084013e610555565b606091505b5091509150816105df5760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b9050806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6919061232f565b60405180910390fd5b50505050565b604080517f578eaca40000000000000000000000000000000000000000000000000000000081523360048201529051600091730a7e848aca42d879ef06507fca0e7b33a0a63c1e9163578eaca4916024808201926020929091908290030181865afa158015610658573d6000803e3d6000fd5b505050506040513d602081101561066e57600080fd5b505115905080156106ac576040517fca2759770000000000000000000000000000000000000000000000000000000081526003906004018082610371565b82356020840135818610156106fc57604080517f643f0c86000000000000000000000000000000000000000000000000000000008152600481018890526024810184905290519081900360440190fd5b61071e73ffffffffffffffffffffffffffffffffffffffff891682338a611555565b5050505050505050565b604080517f578eaca4000000000000000000000000000000000000000000000000000000008152336004820152905160009173eb6625d65a0553c9dbc64449e56abfe519bd9c9b9163578eaca4916024808201926020929091908290030181865afa15801561079b573d6000803e3d6000fd5b505050506040513d60208110156107b157600080fd5b505115905080156107ef576040517fca2759770000000000000000000000000000000000000000000000000000000081526002906004018082610371565b8235602084013560408501358187101561084457604080517f643f0c86000000000000000000000000000000000000000000000000000000008152600481018990526024810184905290519081900360440190fd5b61071e73ffffffffffffffffffffffffffffffffffffffff841682338b611555565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016146108d5576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd00000000000000000000000000000000000000000000000000000000148015610956576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff85811660248301526000919088169063dd62ed3e90604401602060405180830381865afa1580156109cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f1919061239c565b90507f0400000000000000000000000000000000000000000000000000000000000000811015610a84578015610a4357610a4373ffffffffffffffffffffffffffffffffffffffff8816866000611740565b610a8473ffffffffffffffffffffffffffffffffffffffff8816867fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611740565b6000808473ffffffffffffffffffffffffffffffffffffffff163485604051610aad9190612380565b60006040518083038185875af1925050503d8060008114610aea576040519150601f19603f3d011682016040523d82523d6000602084013e610aef565b606091505b509150915081610b3a5760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b60208101518a811015610b83576040517f1d932c9500000000000000000000000000000000000000000000000000000000815260048101829052602481018c90526044016105d6565b8615610baa57610baa73ffffffffffffffffffffffffffffffffffffffff8a1633836117d2565b5050505050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001614610c26576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd00000000000000000000000000000000000000000000000000000000148015610ca7576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff85811660248301526000919088169063dd62ed3e90604401602060405180830381865afa158015610d1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d42919061239c565b90507f0400000000000000000000000000000000000000000000000000000000000000811015610dd5578015610d9457610d9473ffffffffffffffffffffffffffffffffffffffff8816866000611740565b610dd573ffffffffffffffffffffffffffffffffffffffff8816867fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611740565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908816906370a0823190602401602060405180830381865afa158015610e45573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e69919061239c565b90506000808673ffffffffffffffffffffffffffffffffffffffff163486604051610e949190612380565b60006040518083038185875af1925050503d8060008114610ed1576040519150601f19603f3d011682016040523d82523d6000602084013e610ed6565b606091505b509150915081610f215760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff878116600483015260009185918c16906370a0823190602401602060405180830381865afa158015610f92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb6919061239c565b610fc091906123e4565b90508b811015611006576040517f1d932c9500000000000000000000000000000000000000000000000000000000815260048101829052602481018d90526044016105d6565b3073ffffffffffffffffffffffffffffffffffffffff8816036110445761104473ffffffffffffffffffffffffffffffffffffffff8b1633836117d2565b505050505050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016146110c1576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd00000000000000000000000000000000000000000000000000000000148015611142576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506000808373ffffffffffffffffffffffffffffffffffffffff16348460405161116c9190612380565b60006040518083038185875af1925050503d80600081146111a9576040519150601f19603f3d011682016040523d82523d6000602084013e6111ae565b606091505b5091509150816111f95760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b602081015185811015611242576040517f1d932c9500000000000000000000000000000000000000000000000000000000815260048101829052602481018790526044016105d6565b505050505050565b6000806000806000806040517f0dfe1681d21220a7ddca3f430000000000000000000000000000000000000000815260158101602081600484335afa61129257611292610211565b60208082016004808501335afa6112ab576112ab610211565b602060408201600460088501335afa6112c6576112c6610211565b60008c13600181146112e7578b97508c6000039650602082015195506112f5565b8c97508b6000039650815195505b5060408a0135808015611313576001811461133b576000845261135f565b7fff1f98431c8ad98523631ae4a59f267346ea31f9840000000000000000000000845261135f565b7fffbaceb8ec6b9355dfc0269c18bac9d6e2bdc29c4f000000000000000000000084525b50506060812081527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460208201525073ffffffffffffffffffffffffffffffffffffffff6055822016905033811896505087359150602088013590508515610382576040517fca2759770000000000000000000000000000000000000000000000000000000081526000906004018082610371565b6000806000806000806040517f0dfe1681d21220a7c79a590e0000000000000000000000000000000000000000815260158101602081600484335afa61143c5761143c610211565b60208082016004808501335afa61145557611455610211565b602060408201600460088501335afa61147057611470610211565b60008c1360018114611491578b97508c60000396506020820151955061149f565b8c97508b6000039650815195505b507fffc7a590291e07b9fe9e64b86c58fd8fc764308c4a000000000000000000000082526060812081527ee263aaa3a2c06a89b53217a9e7aad7e15613490a72e0f95f303c4de2dc704560208201525073ffffffffffffffffffffffffffffffffffffffff6055822016905033811896505087359150602088013590508515610382576040517fca2759770000000000000000000000000000000000000000000000000000000081526001906004018082610371565b60405173ffffffffffffffffffffffffffffffffffffffff84811660248301528381166044830152606482018390526105df9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611810565b6060600060048451106115f2575060208301515b7fffffffff0000000000000000000000000000000000000000000000000000000081167f08c379a00000000000000000000000000000000000000000000000000000000014801561164557506044845110155b156116955760448481018051909161165d91906123f7565b85511061168f57838160405160200161167792919061240a565b6040516020818303038152906040529250505061173a565b5061170c565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f4e487b71000000000000000000000000000000000000000000000000000000001480156116e7575083516024145b1561170c576024840151836116fb826118a6565b60405160200161167792919061248c565b82611716856118ce565b6040516020016117279291906124d8565b6040516020818303038152906040529150505b92915050565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790526117cd908490611d07565b505050565b60405173ffffffffffffffffffffffffffffffffffffffff8381166024830152604482018390526117cd91859182169063a9059cbb90606401611597565b600061183273ffffffffffffffffffffffffffffffffffffffff841683611da5565b90508051600014158015611857575080806020019051810190611855919061255a565b155b156117cd576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff841660048201526024016105d6565b606061173a826040516020016118be91815260200190565b6040516020818303038152906040525b6060604051905081518060011b6022830181810160405261307860028501526002820184526020850191508282015b80831015611cfe578251611af381600077ffffffffffffffff00000000000000000000000000000000821660401c7fffffffffffffffff00000000000000000000000000000000000000000000000083161790507bffffffff000000000000000000000000ffffffff0000000000000000811660201c7fffffffff000000000000000000000000ffffffff00000000000000000000000082161790507dffff000000000000ffff000000000000ffff000000000000ffff00000000811660101c7fffff000000000000ffff000000000000ffff000000000000ffff00000000000082161790507eff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000811660081c7fff000000ff000000ff000000ff000000ff000000ff000000ff000000ff00000082161790507f0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f00811660081c7ff000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000821660041c17905060077f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f7f0606060606060606060606060606060606060606060606060606060606060606830160041c1602817f303030303030303030303030303030303030303030303030303030303030303001019050919050565b808452602084019350611ceb8260801b600077ffffffffffffffff00000000000000000000000000000000821660401c7fffffffffffffffff00000000000000000000000000000000000000000000000083161790507bffffffff000000000000000000000000ffffffff0000000000000000811660201c7fffffffff000000000000000000000000ffffffff00000000000000000000000082161790507dffff000000000000ffff000000000000ffff000000000000ffff00000000811660101c7fffff000000000000ffff000000000000ffff000000000000ffff00000000000082161790507eff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000811660081c7fff000000ff000000ff000000ff000000ff000000ff000000ff000000ff00000082161790507f0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f00811660081c7ff000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000821660041c17905060077f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f7f0606060606060606060606060606060606060606060606060606060606060606830160041c1602817f303030303030303030303030303030303030303030303030303030303030303001019050919050565b84525050602092830192909101906118fd565b50505050919050565b6000611d2973ffffffffffffffffffffffffffffffffffffffff841683611da5565b90508051600014158015611d515750808060200190516020811015611d4d57600080fd5b5051155b156117cd57604080517fb12cca1f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8516600482015290519081900360240190fd5b6060611db383836000611dba565b9392505050565b606081471015611df8576040517fcd7860590000000000000000000000000000000000000000000000000000000081523060048201526024016105d6565b6000808573ffffffffffffffffffffffffffffffffffffffff168486604051611e219190612380565b60006040518083038185875af1925050503d8060008114611e5e576040519150601f19603f3d011682016040523d82523d6000602084013e611e63565b606091505b5091509150611e73868383611e7d565b9695505050505050565b606082611e9257611e8d82611f0c565b611db3565b8151158015611eb6575073ffffffffffffffffffffffffffffffffffffffff84163b155b15611f05576040517f9996b31500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff851660048201526024016105d6565b5080611db3565b805115611f1c5780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b60008083601f840112611f6357600080fd5b50813567ffffffffffffffff811115611f7b57600080fd5b602083019150836020828501011115611f9357600080fd5b9250929050565b60008060008060608587031215611fb057600080fd5b8435935060208501359250604085013567ffffffffffffffff811115611fd557600080fd5b611fe187828801611f51565b95989497509550505050565b73ffffffffffffffffffffffffffffffffffffffff81168114611f4e57600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f83011261204f57600080fd5b813567ffffffffffffffff8082111561206a5761206a61200f565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019082821181831017156120b0576120b061200f565b816040528381528660208588010111156120c957600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080604083850312156120fc57600080fd5b823561210781611fed565b9150602083013567ffffffffffffffff81111561212357600080fd5b61212f8582860161203e565b9150509250929050565b60008060008060006080868803121561215157600080fd5b853561215c81611fed565b94506020860135935060408601359250606086013567ffffffffffffffff81111561218657600080fd5b61219288828901611f51565b969995985093965092949392505050565b8015158114611f4e57600080fd5b600080600080600080600060e0888a0312156121cc57600080fd5b8735965060208801356121de81611fed565b955060408801356121ee81611fed565b945060608801356121fe81611fed565b9350608088013561220e816121a3565b925060a088013561221e81611fed565b915060c088013567ffffffffffffffff81111561223a57600080fd5b6122468a828b0161203e565b91505092959891949750929550565b600080600080600080600060e0888a03121561227057600080fd5b87359650602088013561228281611fed565b9550604088013561229281611fed565b945060608801356122a281611fed565b9350608088013561220e81611fed565b6000806000606084860312156122c757600080fd5b8335925060208401356122d981611fed565b9150604084013567ffffffffffffffff8111156122f557600080fd5b6123018682870161203e565b9150509250925092565b60005b8381101561232657818101518382015260200161230e565b50506000910152565b602081526000825180602084015261234e81604085016020870161230b565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b6000825161239281846020870161230b565b9190910192915050565b6000602082840312156123ae57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561173a5761173a6123b5565b8082018082111561173a5761173a6123b5565b6000835161241c81846020880161230b565b7f4572726f72280000000000000000000000000000000000000000000000000000908301908152835161245681600684016020880161230b565b7f290000000000000000000000000000000000000000000000000000000000000060069290910191820152600701949350505050565b6000835161249e81846020880161230b565b7f50616e6963280000000000000000000000000000000000000000000000000000908301908152835161245681600684016020880161230b565b600083516124ea81846020880161230b565b7f556e6b6e6f776e28000000000000000000000000000000000000000000000000908301908152835161252481600884016020880161230b565b7f290000000000000000000000000000000000000000000000000000000000000060089290910191820152600901949350505050565b60006020828403121561256c57600080fd5b8151611db3816121a356fea2646970667358221220381562409ae60ffe3a34c9c31b73422b5d6f4641c0433489b7a0a341d540b05264736f6c634300081800330000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab41

Deployed Bytecode

0x6080604052600436106100b15760003560e01c8063d7bb6ce411610069578063f1ae88561161004e578063f1ae885614610164578063fa461e33146101c3578063fa483e72146101e357600080fd5b8063d7bb6ce41461013e578063f0784eb21461015157600080fd5b806367ca7c911161009a57806367ca7c91146100eb578063923b8a2a1461010b578063ce71781f1461012b57600080fd5b806323a69e75146100b65780634379435e146100d8575b600080fd5b3480156100c257600080fd5b506100d66100d1366004611f9a565b610203565b005b6100d66100e63660046120e9565b6103f9565b3480156100f757600080fd5b506100d6610106366004612139565b6105e5565b34801561011757600080fd5b506100d6610126366004611f9a565b610728565b6100d66101393660046121b1565b610866565b6100d661014c366004612255565b610bb7565b6100d661015f3660046122b2565b611052565b34801561017057600080fd5b506101ad6040518060400160405280600b81526020017f436f774578656375746f7200000000000000000000000000000000000000000081525081565b6040516101ba919061232f565b60405180910390f35b3480156101cf57600080fd5b506100d66101de366004611f9a565b61124a565b3480156101ef57600080fd5b506100d66101fe366004611f9a565b6113f4565b60008060008060008061021d565b6040513d6000823e3d81fd5b6040517f0dfe1681d21220a7ddca3f430000000000000000000000000000000000000000815260158101602081600484335afa61025c5761025c610211565b60208082016004808501335afa61027557610275610211565b602060408201600460088501335afa61029057610290610211565b60008c13600181146102b1578b97508c6000039650602082015195506102bf565b8c97508b6000039650815195505b507fff41ff9aa7e16b8b1a8a8dc4f0efacd93d02d071c9000000000000000000000082526060812081527f6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e260208201525073ffffffffffffffffffffffffffffffffffffffff6055822016905033811896505087359150602088013590508515610382576040517fca275977000000000000000000000000000000000000000000000000000000008152600490810180825b815260200191505060405180910390fd5b818410156103cb57604080517f643f0c86000000000000000000000000000000000000000000000000000000008152600481018690526024810184905290519081900360440190fd5b6103ed73ffffffffffffffffffffffffffffffffffffffff8416823388611555565b50505050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab411614610468576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd000000000000000000000000000000000000000000000000000000001480156104e9576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506000808373ffffffffffffffffffffffffffffffffffffffff1634846040516105139190612380565b60006040518083038185875af1925050503d8060008114610550576040519150601f19603f3d011682016040523d82523d6000602084013e610555565b606091505b5091509150816105df5760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b9050806040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105d6919061232f565b60405180910390fd5b50505050565b604080517f578eaca40000000000000000000000000000000000000000000000000000000081523360048201529051600091730a7e848aca42d879ef06507fca0e7b33a0a63c1e9163578eaca4916024808201926020929091908290030181865afa158015610658573d6000803e3d6000fd5b505050506040513d602081101561066e57600080fd5b505115905080156106ac576040517fca2759770000000000000000000000000000000000000000000000000000000081526003906004018082610371565b82356020840135818610156106fc57604080517f643f0c86000000000000000000000000000000000000000000000000000000008152600481018890526024810184905290519081900360440190fd5b61071e73ffffffffffffffffffffffffffffffffffffffff891682338a611555565b5050505050505050565b604080517f578eaca4000000000000000000000000000000000000000000000000000000008152336004820152905160009173eb6625d65a0553c9dbc64449e56abfe519bd9c9b9163578eaca4916024808201926020929091908290030181865afa15801561079b573d6000803e3d6000fd5b505050506040513d60208110156107b157600080fd5b505115905080156107ef576040517fca2759770000000000000000000000000000000000000000000000000000000081526002906004018082610371565b8235602084013560408501358187101561084457604080517f643f0c86000000000000000000000000000000000000000000000000000000008152600481018990526024810184905290519081900360440190fd5b61071e73ffffffffffffffffffffffffffffffffffffffff841682338b611555565b3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab4116146108d5576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd00000000000000000000000000000000000000000000000000000000148015610956576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff85811660248301526000919088169063dd62ed3e90604401602060405180830381865afa1580156109cd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109f1919061239c565b90507f0400000000000000000000000000000000000000000000000000000000000000811015610a84578015610a4357610a4373ffffffffffffffffffffffffffffffffffffffff8816866000611740565b610a8473ffffffffffffffffffffffffffffffffffffffff8816867fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611740565b6000808473ffffffffffffffffffffffffffffffffffffffff163485604051610aad9190612380565b60006040518083038185875af1925050503d8060008114610aea576040519150601f19603f3d011682016040523d82523d6000602084013e610aef565b606091505b509150915081610b3a5760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b60208101518a811015610b83576040517f1d932c9500000000000000000000000000000000000000000000000000000000815260048101829052602481018c90526044016105d6565b8615610baa57610baa73ffffffffffffffffffffffffffffffffffffffff8a1633836117d2565b5050505050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab411614610c26576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd00000000000000000000000000000000000000000000000000000000148015610ca7576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff85811660248301526000919088169063dd62ed3e90604401602060405180830381865afa158015610d1e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d42919061239c565b90507f0400000000000000000000000000000000000000000000000000000000000000811015610dd5578015610d9457610d9473ffffffffffffffffffffffffffffffffffffffff8816866000611740565b610dd573ffffffffffffffffffffffffffffffffffffffff8816867fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611740565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908816906370a0823190602401602060405180830381865afa158015610e45573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e69919061239c565b90506000808673ffffffffffffffffffffffffffffffffffffffff163486604051610e949190612380565b60006040518083038185875af1925050503d8060008114610ed1576040519150601f19603f3d011682016040523d82523d6000602084013e610ed6565b606091505b509150915081610f215760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff878116600483015260009185918c16906370a0823190602401602060405180830381865afa158015610f92573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fb6919061239c565b610fc091906123e4565b90508b811015611006576040517f1d932c9500000000000000000000000000000000000000000000000000000000815260048101829052602481018d90526044016105d6565b3073ffffffffffffffffffffffffffffffffffffffff8816036110445761104473ffffffffffffffffffffffffffffffffffffffff8b1633836117d2565b505050505050505050505050565b3373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab4116146110c1576040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60208101517fffffffff00000000000000000000000000000000000000000000000000000000167f23b872dd00000000000000000000000000000000000000000000000000000000148015611142576040517f3a67746c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b506000808373ffffffffffffffffffffffffffffffffffffffff16348460405161116c9190612380565b60006040518083038185875af1925050503d80600081146111a9576040519150601f19603f3d011682016040523d82523d6000602084013e6111ae565b606091505b5091509150816111f95760006105a0826040518060400160405280600781526020017f436f7745783a20000000000000000000000000000000000000000000000000008152506115de565b602081015185811015611242576040517f1d932c9500000000000000000000000000000000000000000000000000000000815260048101829052602481018790526044016105d6565b505050505050565b6000806000806000806040517f0dfe1681d21220a7ddca3f430000000000000000000000000000000000000000815260158101602081600484335afa61129257611292610211565b60208082016004808501335afa6112ab576112ab610211565b602060408201600460088501335afa6112c6576112c6610211565b60008c13600181146112e7578b97508c6000039650602082015195506112f5565b8c97508b6000039650815195505b5060408a0135808015611313576001811461133b576000845261135f565b7fff1f98431c8ad98523631ae4a59f267346ea31f9840000000000000000000000845261135f565b7fffbaceb8ec6b9355dfc0269c18bac9d6e2bdc29c4f000000000000000000000084525b50506060812081527fe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b5460208201525073ffffffffffffffffffffffffffffffffffffffff6055822016905033811896505087359150602088013590508515610382576040517fca2759770000000000000000000000000000000000000000000000000000000081526000906004018082610371565b6000806000806000806040517f0dfe1681d21220a7c79a590e0000000000000000000000000000000000000000815260158101602081600484335afa61143c5761143c610211565b60208082016004808501335afa61145557611455610211565b602060408201600460088501335afa61147057611470610211565b60008c1360018114611491578b97508c60000396506020820151955061149f565b8c97508b6000039650815195505b507fffc7a590291e07b9fe9e64b86c58fd8fc764308c4a000000000000000000000082526060812081527ee263aaa3a2c06a89b53217a9e7aad7e15613490a72e0f95f303c4de2dc704560208201525073ffffffffffffffffffffffffffffffffffffffff6055822016905033811896505087359150602088013590508515610382576040517fca2759770000000000000000000000000000000000000000000000000000000081526001906004018082610371565b60405173ffffffffffffffffffffffffffffffffffffffff84811660248301528381166044830152606482018390526105df9186918216906323b872dd906084015b604051602081830303815290604052915060e01b6020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050611810565b6060600060048451106115f2575060208301515b7fffffffff0000000000000000000000000000000000000000000000000000000081167f08c379a00000000000000000000000000000000000000000000000000000000014801561164557506044845110155b156116955760448481018051909161165d91906123f7565b85511061168f57838160405160200161167792919061240a565b6040516020818303038152906040529250505061173a565b5061170c565b7fffffffff0000000000000000000000000000000000000000000000000000000081167f4e487b71000000000000000000000000000000000000000000000000000000001480156116e7575083516024145b1561170c576024840151836116fb826118a6565b60405160200161167792919061248c565b82611716856118ce565b6040516020016117279291906124d8565b6040516020818303038152906040529150505b92915050565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b3000000000000000000000000000000000000000000000000000000001790526117cd908490611d07565b505050565b60405173ffffffffffffffffffffffffffffffffffffffff8381166024830152604482018390526117cd91859182169063a9059cbb90606401611597565b600061183273ffffffffffffffffffffffffffffffffffffffff841683611da5565b90508051600014158015611857575080806020019051810190611855919061255a565b155b156117cd576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff841660048201526024016105d6565b606061173a826040516020016118be91815260200190565b6040516020818303038152906040525b6060604051905081518060011b6022830181810160405261307860028501526002820184526020850191508282015b80831015611cfe578251611af381600077ffffffffffffffff00000000000000000000000000000000821660401c7fffffffffffffffff00000000000000000000000000000000000000000000000083161790507bffffffff000000000000000000000000ffffffff0000000000000000811660201c7fffffffff000000000000000000000000ffffffff00000000000000000000000082161790507dffff000000000000ffff000000000000ffff000000000000ffff00000000811660101c7fffff000000000000ffff000000000000ffff000000000000ffff00000000000082161790507eff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000811660081c7fff000000ff000000ff000000ff000000ff000000ff000000ff000000ff00000082161790507f0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f00811660081c7ff000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000821660041c17905060077f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f7f0606060606060606060606060606060606060606060606060606060606060606830160041c1602817f303030303030303030303030303030303030303030303030303030303030303001019050919050565b808452602084019350611ceb8260801b600077ffffffffffffffff00000000000000000000000000000000821660401c7fffffffffffffffff00000000000000000000000000000000000000000000000083161790507bffffffff000000000000000000000000ffffffff0000000000000000811660201c7fffffffff000000000000000000000000ffffffff00000000000000000000000082161790507dffff000000000000ffff000000000000ffff000000000000ffff00000000811660101c7fffff000000000000ffff000000000000ffff000000000000ffff00000000000082161790507eff000000ff000000ff000000ff000000ff000000ff000000ff000000ff0000811660081c7fff000000ff000000ff000000ff000000ff000000ff000000ff000000ff00000082161790507f0f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f00811660081c7ff000f000f000f000f000f000f000f000f000f000f000f000f000f000f000f000821660041c17905060077f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f7f0606060606060606060606060606060606060606060606060606060606060606830160041c1602817f303030303030303030303030303030303030303030303030303030303030303001019050919050565b84525050602092830192909101906118fd565b50505050919050565b6000611d2973ffffffffffffffffffffffffffffffffffffffff841683611da5565b90508051600014158015611d515750808060200190516020811015611d4d57600080fd5b5051155b156117cd57604080517fb12cca1f00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8516600482015290519081900360240190fd5b6060611db383836000611dba565b9392505050565b606081471015611df8576040517fcd7860590000000000000000000000000000000000000000000000000000000081523060048201526024016105d6565b6000808573ffffffffffffffffffffffffffffffffffffffff168486604051611e219190612380565b60006040518083038185875af1925050503d8060008114611e5e576040519150601f19603f3d011682016040523d82523d6000602084013e611e63565b606091505b5091509150611e73868383611e7d565b9695505050505050565b606082611e9257611e8d82611f0c565b611db3565b8151158015611eb6575073ffffffffffffffffffffffffffffffffffffffff84163b155b15611f05576040517f9996b31500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff851660048201526024016105d6565b5080611db3565b805115611f1c5780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b60008083601f840112611f6357600080fd5b50813567ffffffffffffffff811115611f7b57600080fd5b602083019150836020828501011115611f9357600080fd5b9250929050565b60008060008060608587031215611fb057600080fd5b8435935060208501359250604085013567ffffffffffffffff811115611fd557600080fd5b611fe187828801611f51565b95989497509550505050565b73ffffffffffffffffffffffffffffffffffffffff81168114611f4e57600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f83011261204f57600080fd5b813567ffffffffffffffff8082111561206a5761206a61200f565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019082821181831017156120b0576120b061200f565b816040528381528660208588010111156120c957600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080604083850312156120fc57600080fd5b823561210781611fed565b9150602083013567ffffffffffffffff81111561212357600080fd5b61212f8582860161203e565b9150509250929050565b60008060008060006080868803121561215157600080fd5b853561215c81611fed565b94506020860135935060408601359250606086013567ffffffffffffffff81111561218657600080fd5b61219288828901611f51565b969995985093965092949392505050565b8015158114611f4e57600080fd5b600080600080600080600060e0888a0312156121cc57600080fd5b8735965060208801356121de81611fed565b955060408801356121ee81611fed565b945060608801356121fe81611fed565b9350608088013561220e816121a3565b925060a088013561221e81611fed565b915060c088013567ffffffffffffffff81111561223a57600080fd5b6122468a828b0161203e565b91505092959891949750929550565b600080600080600080600060e0888a03121561227057600080fd5b87359650602088013561228281611fed565b9550604088013561229281611fed565b945060608801356122a281611fed565b9350608088013561220e81611fed565b6000806000606084860312156122c757600080fd5b8335925060208401356122d981611fed565b9150604084013567ffffffffffffffff8111156122f557600080fd5b6123018682870161203e565b9150509250925092565b60005b8381101561232657818101518382015260200161230e565b50506000910152565b602081526000825180602084015261234e81604085016020870161230b565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169190910160400192915050565b6000825161239281846020870161230b565b9190910192915050565b6000602082840312156123ae57600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8181038181111561173a5761173a6123b5565b8082018082111561173a5761173a6123b5565b6000835161241c81846020880161230b565b7f4572726f72280000000000000000000000000000000000000000000000000000908301908152835161245681600684016020880161230b565b7f290000000000000000000000000000000000000000000000000000000000000060069290910191820152600701949350505050565b6000835161249e81846020880161230b565b7f50616e6963280000000000000000000000000000000000000000000000000000908301908152835161245681600684016020880161230b565b600083516124ea81846020880161230b565b7f556e6b6e6f776e28000000000000000000000000000000000000000000000000908301908152835161252481600884016020880161230b565b7f290000000000000000000000000000000000000000000000000000000000000060089290910191820152600901949350505050565b60006020828403121561256c57600080fd5b8151611db3816121a356fea2646970667358221220381562409ae60ffe3a34c9c31b73422b5d6f4641c0433489b7a0a341d540b05264736f6c63430008180033

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

0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab41

-----Decoded View---------------
Arg [0] : _cowSettlementContract (address): 0x9008D19f58AAbD9eD0D60971565AA8510560ab41

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000009008d19f58aabd9ed0d60971565aa8510560ab41


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.