APE Price: $0.19 (-0.01%)

Contract

0xf6d63abA77fb85A711d7cba09cE4189b0e42cD0a

Overview

APE Balance

Apechain LogoApechain LogoApechain Logo0 APE

APE Value

$0.00

More Info

Private Name Tags

Multichain Info

N/A
Transaction Hash
Block
From
To

There are no matching entries

Please try again later

View more zero value Internal Transactions in Advanced View mode

Advanced mode:

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
UserVault

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {ReentrancyGuardUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {Factory} from "./Factory.sol";

/**
 * @title UserVault
 * @notice User-owned vault contract for managing funds and NFT purchases
 * @dev Uses UUPS upgradeable pattern. Only owner can withdraw funds/NFTs.
 * Only authorized executors (via Factory) can execute purchases.
 * Implements checks-effects-interactions pattern and reentrancy guards.
 */
contract UserVault is
    UUPSUpgradeable,
    OwnableUpgradeable,
    ReentrancyGuardUpgradeable,
    PausableUpgradeable,
    IERC721Receiver
{
    /// @notice Factory contract address
    Factory public factory;

    /// @notice Withdrawal cooldown period in seconds (0 = disabled)
    uint256 public withdrawalCooldown;

    /// @notice Timestamp of last withdrawal
    uint256 public lastWithdrawalTime;

    /// @notice Total amount ever deposited
    uint256 public totalDeposited;

    /// @notice Total amount ever withdrawn
    uint256 public totalWithdrawn;

    /// @notice Total number of NFTs purchased
    uint256 public totalPurchases;

    /// @custom:error OnlyExecutor The caller is not an authorized executor
    error OnlyExecutor();

    /// @custom:error InsufficientBalance The vault does not have sufficient balance
    error InsufficientBalance(uint256 required, uint256 available);

    /// @custom:error CooldownActive Withdrawal cooldown is still active
    error CooldownActive(uint256 cooldownEndsAt);

    /// @custom:error InvalidFactory The factory address is invalid
    error InvalidFactory();

    /// @custom:error WithdrawFailed The withdrawal transaction failed
    error WithdrawFailed();

    /// @custom:error NFTTransferFailed The NFT transfer failed
    error NFTTransferFailed();

    /**
     * @notice Emitted when funds are deposited
     * @param depositor Address that deposited
     * @param amount Amount deposited in wei
     * @param newBalance New vault balance in wei
     */
    event Deposited(address indexed depositor, uint256 amount, uint256 newBalance);

    /**
     * @notice Emitted when funds are withdrawn
     * @param recipient Address that received the funds
     * @param amount Amount withdrawn in wei
     * @param newBalance New vault balance in wei
     */
    event Withdrawn(address indexed recipient, uint256 amount, uint256 newBalance);

    /**
     * @notice Emitted when an NFT is purchased
     * @param nftContract Address of the NFT contract
     * @param tokenId Token ID purchased
     * @param price Price paid in wei
     * @param marketplace Marketplace where purchase occurred
     * @param executor Address of the executor
     */
    event NFTPurchased(
        address indexed nftContract,
        uint256 indexed tokenId,
        uint256 price,
        address indexed marketplace,
        address executor
    );

    /**
     * @notice Emitted when an NFT is withdrawn
     * @param nftContract Address of the NFT contract
     * @param tokenId Token ID withdrawn
     * @param recipient Address that received the NFT
     */
    event NFTWithdrawn(address indexed nftContract, uint256 indexed tokenId, address indexed recipient);

    /**
     * @notice Emitted when withdrawal cooldown is updated
     * @param newCooldown New cooldown period in seconds
     */
    event WithdrawalCooldownUpdated(uint256 newCooldown);

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    /**
     * @notice Initialize the vault
     * @param vaultOwner Address of the vault owner
     * @param factoryAddress Address of the Factory contract
     * @dev Only the Factory can initialize vaults to prevent spoofing
     */
    function initialize(address vaultOwner, address factoryAddress) external initializer {
        if (factoryAddress == address(0)) revert InvalidFactory();
        // Ensure only the Factory can initialize this vault (prevents factory spoofing)
        if (msg.sender != factoryAddress) revert InvalidFactory();

        __Ownable_init(vaultOwner);
        __Pausable_init();
        __ReentrancyGuard_init();
        __UUPSUpgradeable_init();

        factory = Factory(factoryAddress);
        withdrawalCooldown = 0; // Default: no cooldown
    }

    /**
     * @notice Deposit funds to the vault
     * @dev Accepts native currency (APE on ApeChain). Silently ignores zero-value deposits.
     * @dev Removed nonReentrant as deposit() is inbound-only and doesn't need reentrancy protection.
     */
    function deposit() external payable whenNotPaused {
        if (msg.value == 0) return;

        totalDeposited += msg.value;

        emit Deposited(msg.sender, msg.value, address(this).balance);
    }

    /**
     * @notice Withdraw funds from the vault (owner only, respects cooldown)
     * @param amount Amount to withdraw in wei
     */
    function withdraw(uint256 amount) external onlyOwner whenNotPaused nonReentrant {
        if (amount == 0) return;

        uint256 balance = address(this).balance;
        if (amount > balance) revert InsufficientBalance(amount, balance);

        _checkCooldown();

        // Effects first
        totalWithdrawn += amount;
        lastWithdrawalTime = block.timestamp;

        // Interactions last
        (bool success, ) = msg.sender.call{value: amount}("");
        if (!success) revert WithdrawFailed();

        emit Withdrawn(msg.sender, amount, address(this).balance);
    }

    /**
     * @notice Withdraw all funds from the vault (owner only, respects cooldown)
     */
    function withdrawAll() external onlyOwner whenNotPaused nonReentrant {
        uint256 balance = address(this).balance;
        if (balance == 0) return;

        _checkCooldown();

        // Effects first
        totalWithdrawn += balance;
        lastWithdrawalTime = block.timestamp;

        // Interactions last
        (bool success, ) = msg.sender.call{value: balance}("");
        if (!success) revert WithdrawFailed();

        emit Withdrawn(msg.sender, balance, 0);
    }

    /**
     * @notice Emergency withdraw all funds (owner only, bypasses cooldown and pause)
     * @dev Intentionally bypasses pause() to allow recovery during emergencies.
     * Updates lastWithdrawalTime for consistency with cooldown tracking.
     */
    function emergencyWithdraw() external onlyOwner nonReentrant {
        uint256 balance = address(this).balance;
        if (balance == 0) return;

        // Effects first
        totalWithdrawn += balance;
        lastWithdrawalTime = block.timestamp;

        // Interactions last
        (bool success, ) = msg.sender.call{value: balance}("");
        if (!success) revert WithdrawFailed();

        emit Withdrawn(msg.sender, balance, 0);
    }

    /**
     * @notice Withdraw an NFT from the vault (owner only)
     * @param nftContract Address of the NFT contract
     * @param tokenId Token ID to withdraw
     * @dev Uses try/catch for ownerOf check as some NFTs may revert for non-existent tokens.
     * Falls back to safeTransferFrom which will revert if vault doesn't own the token.
     */
    function withdrawNFT(address nftContract, uint256 tokenId) external onlyOwner whenNotPaused nonReentrant {
        IERC721 nft = IERC721(nftContract);
        
        // Try to verify ownership (some NFTs revert for non-existent tokens)
        try nft.ownerOf(tokenId) returns (address owner) {
            if (owner != address(this)) revert NFTTransferFailed();
        } catch {
            // If ownerOf reverts, safeTransferFrom will handle the error
            // Continue to attempt transfer
        }

        // Effects first
        // Interactions last - safeTransferFrom will revert if vault doesn't own the token
        nft.safeTransferFrom(address(this), msg.sender, tokenId);

        emit NFTWithdrawn(nftContract, tokenId, msg.sender);
    }

    /**
     * @notice Execute a purchase (executor only)
     * @dev Only authorized executors can call this. Verifies executor via Factory.
     * Checks balance before execution. Transfers NFT to owner if possible, otherwise stores in vault.
     * @dev Collection blacklist check is performed on the collection address.
     * @param marketplace Address of the marketplace contract
     * @param collection Address of the NFT collection contract
     * @param data Calldata for the purchase transaction
     * @param value Amount of native currency to send with the call (in wei)
     */
    function executePurchase(address marketplace, address collection, bytes calldata data, uint256 value)
        external
        whenNotPaused
        nonReentrant
        returns (bool)
    {
        // Verify caller is authorized executor
        if (!factory.verifyExecutor(msg.sender)) revert OnlyExecutor();

        // Verify collection is not blacklisted
        factory.verifyNotBlacklisted(collection);

        // Check sufficient balance
        if (value > address(this).balance) {
            revert InsufficientBalance(value, address(this).balance);
        }

        uint256 balanceBefore = address(this).balance;

        // Execute the purchase call with value
        (bool success, ) = marketplace.call{value: value}(data);
        if (!success) return false;

        // Calculate actual balance change (may differ from value if ETH is sent back)
        uint256 balanceAfter = address(this).balance;
        uint256 balanceDelta = balanceBefore > balanceAfter ? balanceBefore - balanceAfter : 0;

        // Balance delta tracks actual net change (accounts for refunds)
        uint256 amountSpent = balanceDelta;

        // Note: Token ID should be parsed from marketplace events by indexers.
        totalPurchases++;
        emit NFTPurchased(collection, 0, amountSpent, marketplace, msg.sender);

        return true;
    }

    /**
     * @notice Set withdrawal cooldown period (owner only)
     * @param newCooldown Cooldown period in seconds (0 to disable)
     */
    function setWithdrawalCooldown(uint256 newCooldown) external onlyOwner {
        withdrawalCooldown = newCooldown;
        emit WithdrawalCooldownUpdated(newCooldown);
    }

    /**
     * @notice Pause the vault (owner only)
     */
    function pause() external onlyOwner {
        _pause();
    }

    /**
     * @notice Unpause the vault (owner only)
     */
    function unpause() external onlyOwner {
        _unpause();
    }

    /**
     * @notice Get the vault balance
     * @return balance Current balance in wei
     */
    function getBalance() external view returns (uint256 balance) {
        return address(this).balance;
    }

    /**
     * @notice Get withdrawal cooldown status
     * @return cooldownEndsAt Timestamp when cooldown ends (0 if not in cooldown)
     * @return inCooldown True if currently in cooldown
     */
    function getCooldownStatus() external view returns (uint256 cooldownEndsAt, bool inCooldown) {
        if (withdrawalCooldown == 0 || lastWithdrawalTime == 0) {
            return (0, false);
        }

        cooldownEndsAt = lastWithdrawalTime + withdrawalCooldown;
        inCooldown = block.timestamp < cooldownEndsAt;
    }

    /**
     * @notice Check if withdrawal cooldown is active
     * @dev Reverts if cooldown is active
     */
    function _checkCooldown() internal view {
        if (withdrawalCooldown == 0 || lastWithdrawalTime == 0) {
            return;
        }

        uint256 cooldownEndsAt = lastWithdrawalTime + withdrawalCooldown;
        if (block.timestamp < cooldownEndsAt) {
            revert CooldownActive(cooldownEndsAt);
        }
    }

    /**
     * @notice Handle ERC721 token reception
     * @dev Implements IERC721Receiver for receiving NFTs
     */
    function onERC721Received(address, address, uint256, bytes calldata) external pure override returns (bytes4) {
        return IERC721Receiver.onERC721Received.selector;
    }

    /**
     * @notice Authorize upgrade (UUPS requirement)
     * @dev Only owner can authorize upgrades
     */
    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}

    /**
     * @notice Receive function to accept native currency
     * @dev Directly accepts ETH without calling deposit() to avoid reentrancy conflicts.
     * Updates totalDeposited and emits event for consistency. Respects pause state.
     */
    receive() external payable whenNotPaused {
        if (msg.value == 0) return;

        totalDeposited += msg.value;
        emit Deposited(msg.sender, msg.value, address(this).balance);
    }

    /**
     * @notice Fallback function
     * @dev Directly accepts ETH without calling deposit() to avoid reentrancy conflicts.
     * Updates totalDeposited and emits event for consistency. Respects pause state.
     */
    fallback() external payable whenNotPaused {
        if (msg.value == 0) return;

        totalDeposited += msg.value;
        emit Deposited(msg.sender, msg.value, address(this).balance);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    function __Ownable_init(address initialOwner) internal onlyInitializing {
        __Ownable_init_unchained(initialOwner);
    }

    function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

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

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reinitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
     *
     * NOTE: Consider following the ERC-7201 formula to derive storage locations.
     */
    function _initializableStorageSlot() internal pure virtual returns (bytes32) {
        return INITIALIZABLE_STORAGE;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        bytes32 slot = _initializableStorageSlot();
        assembly {
            $.slot := slot
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.22;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC-1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

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

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Pausable
    struct PausableStorage {
        bool _paused;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Pausable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant PausableStorageLocation = 0xcd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f03300;

    function _getPausableStorage() private pure returns (PausableStorage storage $) {
        assembly {
            $.slot := PausableStorageLocation
        }
    }

    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    /**
     * @dev The operation failed because the contract is paused.
     */
    error EnforcedPause();

    /**
     * @dev The operation failed because the contract is not paused.
     */
    error ExpectedPause();

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    function __Pausable_init() internal onlyInitializing {
    }

    function __Pausable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        PausableStorage storage $ = _getPausableStorage();
        return $._paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        if (paused()) {
            revert EnforcedPause();
        }
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        if (!paused()) {
            revert ExpectedPause();
        }
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        PausableStorage storage $ = _getPausableStorage();
        $._paused = false;
        emit Unpaused(_msgSender());
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * 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 ReentrancyGuardUpgradeable is Initializable {
    // 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;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

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

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._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 {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // 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 {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // 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) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/draft-IERC1822.sol)

pragma solidity >=0.4.16;

/**
 * @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 9 of 21 : IERC1967.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1967.sol)

pragma solidity >=0.4.11;

/**
 * @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
 */
interface IERC1967 {
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/beacon/IBeacon.sol)

pragma solidity >=0.4.16;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/ERC1967/ERC1967Proxy.sol)

pragma solidity ^0.8.22;

import {Proxy} from "../Proxy.sol";
import {ERC1967Utils} from "./ERC1967Utils.sol";

/**
 * @dev This contract implements an upgradeable proxy. It is upgradeable because calls are delegated to an
 * implementation address that can be changed. This address is stored in storage in the location specified by
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967], so that it doesn't conflict with the storage layout of the
 * implementation behind the proxy.
 */
contract ERC1967Proxy is Proxy {
    /**
     * @dev Initializes the upgradeable proxy with an initial implementation specified by `implementation`.
     *
     * If `_data` is nonempty, it's used as data in a delegate call to `implementation`. This will typically be an
     * encoded function call, and allows initializing the storage of the proxy like a Solidity constructor.
     *
     * Requirements:
     *
     * - If `data` is empty, `msg.value` must be zero.
     */
    constructor(address implementation, bytes memory _data) payable {
        ERC1967Utils.upgradeToAndCall(implementation, _data);
    }

    /**
     * @dev Returns the current implementation address.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc`
     */
    function _implementation() internal view virtual override returns (address) {
        return ERC1967Utils.getImplementation();
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.21;

import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This library provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
 */
library ERC1967Utils {
    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit IERC1967.Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the ERC-1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit IERC1967.AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the ERC-1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit IERC1967.BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/Proxy.sol)

pragma solidity ^0.8.20;

/**
 * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM
 * instruction `delegatecall`. We refer to the second contract as the _implementation_ behind the proxy, and it has to
 * be specified by overriding the virtual {_implementation} function.
 *
 * Additionally, delegation to the implementation can be triggered manually through the {_fallback} function, or to a
 * different contract through the {_delegate} function.
 *
 * The success and return data of the delegated call will be returned back to the caller of the proxy.
 */
abstract contract Proxy {
    /**
     * @dev Delegates the current call to `implementation`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _delegate(address implementation) internal virtual {
        assembly {
            // Copy msg.data. We take full control of memory in this inline assembly
            // block because it will not return to Solidity code. We overwrite the
            // Solidity scratch pad at memory position 0.
            calldatacopy(0, 0, calldatasize())

            // Call the implementation.
            // out and outsize are 0 because we don't know the size yet.
            let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)

            // Copy the returned data.
            returndatacopy(0, 0, returndatasize())

            switch result
            // delegatecall returns 0 on error.
            case 0 {
                revert(0, returndatasize())
            }
            default {
                return(0, returndatasize())
            }
        }
    }

    /**
     * @dev This is a virtual function that should be overridden so it returns the address to which the fallback
     * function and {_fallback} should delegate.
     */
    function _implementation() internal view virtual returns (address);

    /**
     * @dev Delegates the current call to the address returned by `_implementation()`.
     *
     * This function does not return to its internal call site, it will return directly to the external caller.
     */
    function _fallback() internal virtual {
        _delegate(_implementation());
    }

    /**
     * @dev Fallback function that delegates calls to the address returned by `_implementation()`. Will run if no other
     * function in the contract matches the call data.
     */
    fallback() external payable virtual {
        _fallback();
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721.sol)

pragma solidity >=0.6.2;

import {IERC165} from "../../utils/introspection/IERC165.sol";

/**
 * @dev Required interface of an ERC-721 compliant contract.
 */
interface IERC721 is IERC165 {
    /**
     * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
     */
    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
     */
    event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);

    /**
     * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
     */
    event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

    /**
     * @dev Returns the number of tokens in ``owner``'s account.
     */
    function balanceOf(address owner) external view returns (uint256 balance);

    /**
     * @dev Returns the owner of the `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function ownerOf(uint256 tokenId) external view returns (address owner);

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;

    /**
     * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
     * are aware of the ERC-721 protocol to prevent tokens from being forever locked.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must exist and be owned by `from`.
     * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
     *   {setApprovalForAll}.
     * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
     *   a safe transfer.
     *
     * Emits a {Transfer} event.
     */
    function safeTransferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Transfers `tokenId` token from `from` to `to`.
     *
     * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC-721
     * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
     * understand this adds an external call which potentially creates a reentrancy vulnerability.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `tokenId` token must be owned by `from`.
     * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 tokenId) external;

    /**
     * @dev Gives permission to `to` to transfer `tokenId` token to another account.
     * The approval is cleared when the token is transferred.
     *
     * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
     *
     * Requirements:
     *
     * - The caller must own the token or be an approved operator.
     * - `tokenId` must exist.
     *
     * Emits an {Approval} event.
     */
    function approve(address to, uint256 tokenId) external;

    /**
     * @dev Approve or remove `operator` as an operator for the caller.
     * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
     *
     * Requirements:
     *
     * - The `operator` cannot be the address zero.
     *
     * Emits an {ApprovalForAll} event.
     */
    function setApprovalForAll(address operator, bool approved) external;

    /**
     * @dev Returns the account approved for `tokenId` token.
     *
     * Requirements:
     *
     * - `tokenId` must exist.
     */
    function getApproved(uint256 tokenId) external view returns (address operator);

    /**
     * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
     *
     * See {setApprovalForAll}
     */
    function isApprovedForAll(address owner, address operator) external view returns (bool);
}

File 15 of 21 : IERC721Receiver.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC721/IERC721Receiver.sol)

pragma solidity >=0.5.0;

/**
 * @title ERC-721 token receiver interface
 * @dev Interface for any contract that wants to support safeTransfers
 * from ERC-721 asset contracts.
 */
interface IERC721Receiver {
    /**
     * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
     * by `operator` from `from`, this function is called.
     *
     * It must return its Solidity selector to confirm the token transfer.
     * If any other value is returned or the interface is not implemented by the recipient, the transfer will be
     * reverted.
     *
     * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
     */
    function onERC721Received(
        address operator,
        address from,
        uint256 tokenId,
        bytes calldata data
    ) external returns (bytes4);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/Address.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @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 Errors.InsufficientBalance(address(this).balance, amount);
        }

        (bool success, bytes memory returndata) = recipient.call{value: amount}("");
        if (!success) {
            _revert(returndata);
        }
    }

    /**
     * @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
     * {Errors.FailedCall} 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 Errors.InsufficientBalance(address(this).balance, value);
        }
        (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 {Errors.FailedCall}) 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 {Errors.FailedCall} 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 {Errors.FailedCall}.
     */
    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
            assembly ("memory-safe") {
                revert(add(returndata, 0x20), mload(returndata))
            }
        } else {
            revert Errors.FailedCall();
        }
    }
}

File 17 of 21 : Errors.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of common custom errors used in multiple contracts
 *
 * IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
 * It is recommended to avoid relying on the error API for critical functionality.
 *
 * _Available since v5.1._
 */
library Errors {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error InsufficientBalance(uint256 balance, uint256 needed);

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

    /**
     * @dev The deployment failed.
     */
    error FailedDeployment();

    /**
     * @dev A necessary precompile is missing.
     */
    error MissingPrecompile(address);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (utils/introspection/IERC165.sol)

pragma solidity >=0.4.16;

/**
 * @dev Interface of the ERC-165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[ERC].
 *
 * Implementers can declare support of contract interfaces, which can then be
 * queried by others ({ERC165Checker}).
 *
 * For an implementation, see {ERC165}.
 */
interface IERC165 {
    /**
     * @dev Returns true if this contract implements the interface defined by
     * `interfaceId`. See the corresponding
     * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
     * to learn more about how these ids are created.
     *
     * This function call must use less than 30 000 gas.
     */
    function supportsInterface(bytes4 interfaceId) external view returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC-1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 *
 * TIP: Consider using this library along with {SlotDerivation}.
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct Int256Slot {
        int256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `Int256Slot` with member `value` located at `slot`.
     */
    function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns a `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns a `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        assembly ("memory-safe") {
            r.slot := store.slot
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {UUPSUpgradeable} from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
import {IERC1967} from "@openzeppelin/contracts/interfaces/IERC1967.sol";
import {ERC1967Proxy} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
import {IUserVault} from "./IUserVault.sol";

/**
 * @title Factory
 * @notice Factory contract for deploying and managing user vault contracts
 * @dev Uses UUPS upgradeable pattern. Deploys minimal proxy vaults (ERC-1967) for gas efficiency.
 * Manages executor whitelist and collection blacklist.
 */
contract Factory is UUPSUpgradeable, OwnableUpgradeable, PausableUpgradeable {
    /// @notice Address of the UserVault implementation contract
    address public vaultImplementation;

    /// @notice Mapping of vault address => owner address
    mapping(address => address) public vaultOwners;

    /// @notice Mapping of owner address => vault address
    mapping(address => address) public ownerVaults;

    /// @notice Mapping of executor address => is authorized
    mapping(address => bool) public executors;

    /// @notice Mapping of collection address => is blacklisted
    mapping(address => bool) public blacklistedCollections;

    /// @notice Mapping of vault address => is a factory-deployed vault
    mapping(address => bool) public isVault;

    /// @notice Total number of vaults deployed
    uint256 public totalVaults;

    /// @custom:error OnlyExecutor The caller is not an authorized executor
    error OnlyExecutor();

    /// @custom:error VaultAlreadyExists The owner already has a vault
    error VaultAlreadyExists();

    /// @custom:error InvalidImplementation The vault implementation address is invalid
    error InvalidImplementation();

    /// @custom:error CollectionIsBlacklisted The collection is blacklisted
    error CollectionIsBlacklisted(address collection);

    /**
     * @notice Emitted when a new vault is created
     * @param vault Address of the created vault
     * @param owner Address of the vault owner
     * @param vaultNumber Sequential vault number
     */
    event VaultCreated(address indexed vault, address indexed owner, uint256 vaultNumber);

    /**
     * @notice Emitted when an executor is added
     * @param executor Address of the executor
     */
    event ExecutorAdded(address indexed executor);

    /**
     * @notice Emitted when an executor is removed
     * @param executor Address of the executor
     */
    event ExecutorRemoved(address indexed executor);

    /**
     * @notice Emitted when a collection is blacklisted
     * @param collection Address of the blacklisted collection
     * @param reason Reason for blacklisting
     */
    event CollectionBlacklisted(address indexed collection, string reason);

    /**
     * @notice Emitted when a collection is removed from blacklist
     * @param collection Address of the removed collection
     */
    event CollectionUnblacklisted(address indexed collection);

    /**
     * @notice Emitted when vault implementation is updated
     * @param oldImplementation Previous implementation address
     * @param newImplementation New implementation address
     */
    event VaultImplementationUpdated(address indexed oldImplementation, address indexed newImplementation);

    /// @custom:oz-upgrades-unsafe-allow constructor
    constructor() {
        _disableInitializers();
    }

    /**
     * @notice Initialize the Factory contract
     * @param initialOwner Address of the contract owner
     * @param vaultImpl Address of the UserVault implementation
     */
    function initialize(address initialOwner, address vaultImpl) external initializer {
        if (vaultImpl == address(0)) revert InvalidImplementation();

        __Ownable_init(initialOwner);
        __Pausable_init();
        __UUPSUpgradeable_init();

        vaultImplementation = vaultImpl;
    }

    /**
     * @notice Create a new user vault for the caller
     * @dev Deploys a minimal proxy (ERC-1967) pointing to the vault implementation
     * @return vault Address of the newly created vault
     */
    function createVault() external whenNotPaused returns (address vault) {
        if (ownerVaults[msg.sender] != address(0)) revert VaultAlreadyExists();

        bytes memory initData = abi.encodeWithSelector(
            IUserVault.initialize.selector,
            msg.sender,
            address(this)
        );

        ERC1967Proxy proxy = new ERC1967Proxy(vaultImplementation, initData);
        vault = address(proxy);

        vaultOwners[vault] = msg.sender;
        ownerVaults[msg.sender] = vault;
        isVault[vault] = true;
        totalVaults++;

        emit VaultCreated(vault, msg.sender, totalVaults);
    }

    /**
     * @notice Add an executor to the whitelist
     * @param executor Address of the executor to add
     */
    function addExecutor(address executor) external onlyOwner {
        executors[executor] = true;
        emit ExecutorAdded(executor);
    }

    /**
     * @notice Remove an executor from the whitelist
     * @param executor Address of the executor to remove
     */
    function removeExecutor(address executor) external onlyOwner {
        executors[executor] = false;
        emit ExecutorRemoved(executor);
    }

    /**
     * @notice Blacklist a collection
     * @param collection Address of the collection to blacklist
     * @param reason Reason for blacklisting
     */
    function blacklistCollection(address collection, string calldata reason) external onlyOwner {
        blacklistedCollections[collection] = true;
        emit CollectionBlacklisted(collection, reason);
    }

    /**
     * @notice Remove a collection from blacklist
     * @param collection Address of the collection to unblacklist
     */
    function unblacklistCollection(address collection) external onlyOwner {
        blacklistedCollections[collection] = false;
        emit CollectionUnblacklisted(collection);
    }

    /**
     * @notice Check if an address is an authorized executor
     * @param executor Address to check
     * @return bool True if executor is authorized
     */
    function isExecutor(address executor) external view returns (bool) {
        return executors[executor];
    }

    /**
     * @notice Check if a collection is blacklisted
     * @param collection Address to check
     * @return bool True if collection is blacklisted
     */
    function isBlacklisted(address collection) external view returns (bool) {
        return blacklistedCollections[collection];
    }

    /**
     * @notice Get vault address for an owner
     * @param owner Address of the owner
     * @return vault Address of the vault, or address(0) if none exists
     */
    function getVault(address owner) external view returns (address vault) {
        return ownerVaults[owner];
    }

    /**
     * @notice Verify executor authorization (used by vault contracts)
     * @param executor Address to verify
     * @return bool True if executor is authorized
     */
    function verifyExecutor(address executor) external view returns (bool) {
        return executors[executor];
    }

    /**
     * @notice Verify collection is not blacklisted (used by vault contracts)
     * @param collection Address to check
     */
    function verifyNotBlacklisted(address collection) external view {
        if (blacklistedCollections[collection]) {
            revert CollectionIsBlacklisted(collection);
        }
    }

    /**
     * @notice Pause the factory (prevents vault creation)
     */
    function pause() external onlyOwner {
        _pause();
    }

    /**
     * @notice Unpause the factory
     */
    function unpause() external onlyOwner {
        _unpause();
    }

    /**
     * @notice Update the vault implementation address (for upgrades)
     * @param newImplementation Address of the new implementation
     * @dev Validates that newImplementation is a contract with code to prevent bricking deployments
     */
    function updateVaultImplementation(address newImplementation) external onlyOwner {
        if (newImplementation == address(0)) revert InvalidImplementation();
        
        // Ensure newImplementation is a contract (has code)
        uint256 codeSize;
        assembly {
            codeSize := extcodesize(newImplementation)
        }
        if (codeSize == 0) revert InvalidImplementation();

        address oldImplementation = vaultImplementation;
        vaultImplementation = newImplementation;
        
        emit VaultImplementationUpdated(oldImplementation, newImplementation);
    }

    /**
     * @notice Authorize upgrade (UUPS requirement)
     * @dev Only owner can authorize upgrades
     */
    function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

/**
 * @title IUserVault
 * @notice Interface for UserVault contract
 */
interface IUserVault {
    /**
     * @notice Initialize the vault
     * @param owner Address of the vault owner
     * @param factory Address of the Factory contract
     */
    function initialize(address owner, address factory) external;

    /**
     * @notice Deposit funds to the vault
     */
    function deposit() external payable;

    /**
     * @notice Withdraw funds from the vault
     * @param amount Amount to withdraw in wei
     */
    function withdraw(uint256 amount) external;

    /**
     * @notice Withdraw all funds from the vault
     */
    function withdrawAll() external;

    /**
     * @notice Withdraw an NFT from the vault
     * @param nftContract Address of the NFT contract
     * @param tokenId Token ID to withdraw
     */
    function withdrawNFT(address nftContract, uint256 tokenId) external;

    /**
     * @notice Execute a purchase (executor only)
     * @param marketplace Address of the marketplace contract
     * @param collection Address of the NFT collection contract
     * @param data Calldata for the purchase transaction
     * @param value Amount of native currency to send with the call (in wei)
     */
    function executePurchase(
        address marketplace,
        address collection,
        bytes calldata data,
        uint256 value
    ) external;

    /**
     * @notice Emergency withdraw (bypasses cooldown, owner only)
     */
    function emergencyWithdraw() external;

    /**
     * @notice Get the vault balance
     * @return balance Current balance in wei
     */
    function getBalance() external view returns (uint256 balance);

    /**
     * @notice Get the vault owner
     * @return owner Address of the owner
     */
    function owner() external view returns (address owner);
}

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

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"uint256","name":"cooldownEndsAt","type":"uint256"}],"name":"CooldownActive","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"FailedCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"required","type":"uint256"},{"internalType":"uint256","name":"available","type":"uint256"}],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidFactory","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"NFTTransferFailed","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"OnlyExecutor","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"inputs":[],"name":"WithdrawFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBalance","type":"uint256"}],"name":"Deposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContract","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"price","type":"uint256"},{"indexed":true,"internalType":"address","name":"marketplace","type":"address"},{"indexed":false,"internalType":"address","name":"executor","type":"address"}],"name":"NFTPurchased","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nftContract","type":"address"},{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"recipient","type":"address"}],"name":"NFTWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newCooldown","type":"uint256"}],"name":"WithdrawalCooldownUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newBalance","type":"uint256"}],"name":"Withdrawn","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"emergencyWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"marketplace","type":"address"},{"internalType":"address","name":"collection","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"executePurchase","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract Factory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getBalance","outputs":[{"internalType":"uint256","name":"balance","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCooldownStatus","outputs":[{"internalType":"uint256","name":"cooldownEndsAt","type":"uint256"},{"internalType":"bool","name":"inCooldown","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"vaultOwner","type":"address"},{"internalType":"address","name":"factoryAddress","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastWithdrawalTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newCooldown","type":"uint256"}],"name":"setWithdrawalCooldown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"totalDeposited","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalPurchases","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalWithdrawn","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"nftContract","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"withdrawNFT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawalCooldown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]

60a06040523060805234801561001457600080fd5b5061001d610022565b6100d4565b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00805468010000000000000000900460ff16156100725760405163f92ee8a960e01b815260040160405180910390fd5b80546001600160401b03908116146100d15780546001600160401b0319166001600160401b0390811782556040519081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50565b6080516119456100fd6000396000818161101801528181611041015261118701526119456000f3fe6080604052600436106101855760003560e01c80636ccd4842116100d1578063ad3cb1cc1161008a578063d6c89c6011610064578063d6c89c60146104bf578063db2e21bc146104d5578063f2fde38b146104ea578063ff50abdc1461050a576101ec565b8063ad3cb1cc14610459578063c45a015514610497578063d0e30db0146104b7576101ec565b80636ccd484214610389578063715018a6146103a95780638456cb59146103be578063853828b6146103d35780638da5cb5b146103e8578063981372e114610439576101ec565b80634b3197131161013e57806352d1902d1161011857806352d1902d1461030d5780635962a941146103225780635c975abb146103385780636088e93a14610369576101ec565b80634b319713146102ba5780634ddb926a146102d05780634f1ef286146102fa576101ec565b806312065fe0146101f4578063150b7a02146102165780632e1a7d4d1461024f57806334a014dc1461026f5780633f4ba83a14610285578063485cc9551461029a576101ec565b366101ec57610192610520565b34156101ea5734600360008282546101aa91906114e2565b90915550506040805134815247602082015233917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a25b005b610192610520565b34801561020057600080fd5b50475b6040519081526020015b60405180910390f35b34801561022257600080fd5b50610236610231366004611553565b610553565b6040516001600160e01b0319909116815260200161020d565b34801561025b57600080fd5b506101ea61026a3660046115c6565b610565565b34801561027b57600080fd5b5061020360025481565b34801561029157600080fd5b506101ea610697565b3480156102a657600080fd5b506101ea6102b53660046115df565b6106a7565b3480156102c657600080fd5b5061020360045481565b3480156102dc57600080fd5b506102e561082a565b6040805192835290151560208301520161020d565b6101ea61030836600461162e565b610867565b34801561031957600080fd5b50610203610886565b34801561032e57600080fd5b5061020360055481565b34801561034457600080fd5b506000805160206118d08339815191525460ff165b604051901515815260200161020d565b34801561037557600080fd5b506101ea6103843660046116f2565b6108a3565b34801561039557600080fd5b506103596103a436600461171e565b610a04565b3480156103b557600080fd5b506101ea610c3f565b3480156103ca57600080fd5b506101ea610c51565b3480156103df57600080fd5b506101ea610c61565b3480156103f457600080fd5b507f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b03165b6040516001600160a01b03909116815260200161020d565b34801561044557600080fd5b506101ea6104543660046115c6565b610d6a565b34801561046557600080fd5b5061048a604051806040016040528060058152602001640352e302e360dc1b81525081565b60405161020d91906117af565b3480156104a357600080fd5b50600054610421906001600160a01b031681565b6101ea610dae565b3480156104cb57600080fd5b5061020360015481565b3480156104e157600080fd5b506101ea610e0f565b3480156104f657600080fd5b506101ea6105053660046117e2565b610e2f565b34801561051657600080fd5b5061020360035481565b6000805160206118d08339815191525460ff16156105515760405163d93c066560e01b815260040160405180910390fd5b565b630a85bd0160e11b5b95945050505050565b61056d610e6a565b610575610520565b61057d610ec5565b801561067d5747808211156105b45760405163cf47918160e01b815260048101839052602481018290526044015b60405180910390fd5b6105bc610efd565b81600460008282546105ce91906114e2565b909155505042600255604051600090339084908381818185875af1925050503d8060008114610619576040519150601f19603f3d011682016040523d82523d6000602084013e61061e565b606091505b505090508061064057604051631d42c86760e21b815260040160405180910390fd5b6040805184815247602082015233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6910160405180910390a250505b61069460016000805160206118f083398151915255565b50565b61069f610e6a565b610551610f5f565b60006106b1610fb9565b805490915060ff600160401b820416159067ffffffffffffffff166000811580156106d95750825b905060008267ffffffffffffffff1660011480156106f65750303b155b905081158015610704575080155b156107225760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561074c57845460ff60401b1916600160401b1785555b6001600160a01b03861661077357604051637a44db9560e01b815260040160405180910390fd5b336001600160a01b0387161461079c57604051637a44db9560e01b815260040160405180910390fd5b6107a587610fe4565b6107ad610ff5565b6107b5610ffd565b6107bd610ff5565b600080546001600160a01b0319166001600160a01b038816178155600155831561082157845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b6000806001546000148061083e5750600254155b1561084c5750600091829150565b60015460025461085c91906114e2565b915081421090509091565b61086f61100d565b610878826110b2565b61088282826110ba565b5050565b600061089061117c565b506000805160206118b083398151915290565b6108ab610e6a565b6108b3610520565b6108bb610ec5565b6040516331a9108f60e11b81526004810182905282906001600160a01b03821690636352211e90602401602060405180830381865afa92505050801561091e575060408051601f3d908101601f1916820190925261091b918101906117ff565b60015b1561094e576001600160a01b038116301461094c576040516308c0b8b360e31b815260040160405180910390fd5b505b604051632142170760e11b8152306004820152336024820152604481018390526001600160a01b038216906342842e0e90606401600060405180830381600087803b15801561099c57600080fd5b505af11580156109b0573d6000803e3d6000fd5b50506040513392508491506001600160a01b038616907fc9e322753b88ef200a699612ee80267ec1889ce31dd470742469de7a75c3498290600090a45061088260016000805160206118f083398151915255565b6000610a0e610520565b610a16610ec5565b600054604051633d990f8f60e01b81523360048201526001600160a01b0390911690633d990f8f90602401602060405180830381865afa158015610a5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a82919061181c565b610a9f57604051633fdb5f0160e11b815260040160405180910390fd5b60005460405163145253f160e01b81526001600160a01b0387811660048301529091169063145253f19060240160006040518083038186803b158015610ae457600080fd5b505afa158015610af8573d6000803e3d6000fd5b5050505047821115610b265760405163cf47918160e01b8152600481018390524760248201526044016105ab565b60004790506000876001600160a01b0316848787604051610b4892919061183e565b60006040518083038185875af1925050503d8060008114610b85576040519150601f19603f3d011682016040523d82523d6000602084013e610b8a565b606091505b5050905080610b9e57600092505050610c28565b476000818411610baf576000610bb9565b610bb9828561184e565b600580549192508291906000610bce83611861565b9091555050604080518281523360208201526001600160a01b03808e1692600092918e16917fdd8b908eeba2b360768e83e04b5bf45f6fe09643c57d1150ad1efd2c6d08b5bf910160405180910390a46001955050505050505b61055c60016000805160206118f083398151915255565b610c47610e6a565b61055160006111c5565b610c59610e6a565b610551611236565b610c69610e6a565b610c71610520565b610c79610ec5565b476000819003610c895750610d53565b610c91610efd565b8060046000828254610ca391906114e2565b909155505042600255604051600090339083908381818185875af1925050503d8060008114610cee576040519150601f19603f3d011682016040523d82523d6000602084013e610cf3565b606091505b5050905080610d1557604051631d42c86760e21b815260040160405180910390fd5b604080518381526000602082015233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6910160405180910390a250505b61055160016000805160206118f083398151915255565b610d72610e6a565b60018190556040518181527faffdfb262211d5a9ecffa4a8ecc187283f999fcd7422a952d7c82136a2fa0da1906020015b60405180910390a150565b610db6610520565b3415610551573460036000828254610dce91906114e2565b90915550506040805134815247602082015233917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a2565b610e17610e6a565b610e1f610ec5565b476000819003610c915750610d53565b610e37610e6a565b6001600160a01b038116610e6157604051631e4fbdf760e01b8152600060048201526024016105ab565b610694816111c5565b33610e9c7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b0316146105515760405163118cdaa760e01b81523360048201526024016105ab565b6000805160206118f0833981519152805460011901610ef757604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b6001541580610f0c5750600254155b15610f1357565b6000600154600254610f2591906114e2565b9050804210156106945760405163c1ab61a160e01b8152600481018290526024016105ab565b60016000805160206118f083398151915255565b610f6761127f565b6000805160206118d0833981519152805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b039091168152602001610da3565b6000807ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005b92915050565b610fec6112af565b610694816112d4565b6105516112af565b6110056112af565b6105516112dc565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148061109457507f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166110886000805160206118b0833981519152546001600160a01b031690565b6001600160a01b031614155b156105515760405163703e46dd60e11b815260040160405180910390fd5b610694610e6a565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611114575060408051601f3d908101601f191682019092526111119181019061187a565b60015b61113c57604051634c9c8ce360e01b81526001600160a01b03831660048201526024016105ab565b6000805160206118b0833981519152811461116d57604051632a87526960e21b8152600481018290526024016105ab565b61117783836112e4565b505050565b306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146105515760405163703e46dd60e11b815260040160405180910390fd5b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3505050565b61123e610520565b6000805160206118d0833981519152805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833610fa1565b6000805160206118d08339815191525460ff1661055157604051638dfc202b60e01b815260040160405180910390fd5b6112b761133a565b61055157604051631afcd79f60e31b815260040160405180910390fd5b610e376112af565b610f4b6112af565b6112ed82611354565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a28051156113325761117782826113b9565b610882611426565b6000611344610fb9565b54600160401b900460ff16919050565b806001600160a01b03163b60000361138a57604051634c9c8ce360e01b81526001600160a01b03821660048201526024016105ab565b6000805160206118b083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060600080846001600160a01b0316846040516113d69190611893565b600060405180830381855af49150503d8060008114611411576040519150601f19603f3d011682016040523d82523d6000602084013e611416565b606091505b509150915061055c858383611445565b34156105515760405163b398979f60e01b815260040160405180910390fd5b60608261145a57611455826114a4565b61149d565b815115801561147157506001600160a01b0384163b155b1561149a57604051639996b31560e01b81526001600160a01b03851660048201526024016105ab565b50805b9392505050565b8051156114b357805160208201fd5b60405163d6bda27560e01b815260040160405180910390fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610fde57610fde6114cc565b6001600160a01b038116811461069457600080fd5b60008083601f84011261151c57600080fd5b50813567ffffffffffffffff81111561153457600080fd5b60208301915083602082850101111561154c57600080fd5b9250929050565b60008060008060006080868803121561156b57600080fd5b8535611576816114f5565b94506020860135611586816114f5565b935060408601359250606086013567ffffffffffffffff8111156115a957600080fd5b6115b58882890161150a565b969995985093965092949392505050565b6000602082840312156115d857600080fd5b5035919050565b600080604083850312156115f257600080fd5b82356115fd816114f5565b9150602083013561160d816114f5565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b6000806040838503121561164157600080fd5b823561164c816114f5565b9150602083013567ffffffffffffffff8082111561166957600080fd5b818501915085601f83011261167d57600080fd5b81358181111561168f5761168f611618565b604051601f8201601f19908116603f011681019083821181831017156116b7576116b7611618565b816040528281528860208487010111156116d057600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b6000806040838503121561170557600080fd5b8235611710816114f5565b946020939093013593505050565b60008060008060006080868803121561173657600080fd5b8535611741816114f5565b94506020860135611751816114f5565b9350604086013567ffffffffffffffff81111561176d57600080fd5b6117798882890161150a565b96999598509660600135949350505050565b60005b838110156117a657818101518382015260200161178e565b50506000910152565b60208152600082518060208401526117ce81604085016020870161178b565b601f01601f19169190910160400192915050565b6000602082840312156117f457600080fd5b813561149d816114f5565b60006020828403121561181157600080fd5b815161149d816114f5565b60006020828403121561182e57600080fd5b8151801515811461149d57600080fd5b8183823760009101908152919050565b81810381811115610fde57610fde6114cc565b600060018201611873576118736114cc565b5060010190565b60006020828403121561188c57600080fd5b5051919050565b600082516118a581846020870161178b565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbccd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220d1c168d57ef88454139b66a66557459b35ba2ef7097511b200c4e0e3625ebb8264736f6c63430008180033

Deployed Bytecode

0x6080604052600436106101855760003560e01c80636ccd4842116100d1578063ad3cb1cc1161008a578063d6c89c6011610064578063d6c89c60146104bf578063db2e21bc146104d5578063f2fde38b146104ea578063ff50abdc1461050a576101ec565b8063ad3cb1cc14610459578063c45a015514610497578063d0e30db0146104b7576101ec565b80636ccd484214610389578063715018a6146103a95780638456cb59146103be578063853828b6146103d35780638da5cb5b146103e8578063981372e114610439576101ec565b80634b3197131161013e57806352d1902d1161011857806352d1902d1461030d5780635962a941146103225780635c975abb146103385780636088e93a14610369576101ec565b80634b319713146102ba5780634ddb926a146102d05780634f1ef286146102fa576101ec565b806312065fe0146101f4578063150b7a02146102165780632e1a7d4d1461024f57806334a014dc1461026f5780633f4ba83a14610285578063485cc9551461029a576101ec565b366101ec57610192610520565b34156101ea5734600360008282546101aa91906114e2565b90915550506040805134815247602082015233917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a25b005b610192610520565b34801561020057600080fd5b50475b6040519081526020015b60405180910390f35b34801561022257600080fd5b50610236610231366004611553565b610553565b6040516001600160e01b0319909116815260200161020d565b34801561025b57600080fd5b506101ea61026a3660046115c6565b610565565b34801561027b57600080fd5b5061020360025481565b34801561029157600080fd5b506101ea610697565b3480156102a657600080fd5b506101ea6102b53660046115df565b6106a7565b3480156102c657600080fd5b5061020360045481565b3480156102dc57600080fd5b506102e561082a565b6040805192835290151560208301520161020d565b6101ea61030836600461162e565b610867565b34801561031957600080fd5b50610203610886565b34801561032e57600080fd5b5061020360055481565b34801561034457600080fd5b506000805160206118d08339815191525460ff165b604051901515815260200161020d565b34801561037557600080fd5b506101ea6103843660046116f2565b6108a3565b34801561039557600080fd5b506103596103a436600461171e565b610a04565b3480156103b557600080fd5b506101ea610c3f565b3480156103ca57600080fd5b506101ea610c51565b3480156103df57600080fd5b506101ea610c61565b3480156103f457600080fd5b507f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b03165b6040516001600160a01b03909116815260200161020d565b34801561044557600080fd5b506101ea6104543660046115c6565b610d6a565b34801561046557600080fd5b5061048a604051806040016040528060058152602001640352e302e360dc1b81525081565b60405161020d91906117af565b3480156104a357600080fd5b50600054610421906001600160a01b031681565b6101ea610dae565b3480156104cb57600080fd5b5061020360015481565b3480156104e157600080fd5b506101ea610e0f565b3480156104f657600080fd5b506101ea6105053660046117e2565b610e2f565b34801561051657600080fd5b5061020360035481565b6000805160206118d08339815191525460ff16156105515760405163d93c066560e01b815260040160405180910390fd5b565b630a85bd0160e11b5b95945050505050565b61056d610e6a565b610575610520565b61057d610ec5565b801561067d5747808211156105b45760405163cf47918160e01b815260048101839052602481018290526044015b60405180910390fd5b6105bc610efd565b81600460008282546105ce91906114e2565b909155505042600255604051600090339084908381818185875af1925050503d8060008114610619576040519150601f19603f3d011682016040523d82523d6000602084013e61061e565b606091505b505090508061064057604051631d42c86760e21b815260040160405180910390fd5b6040805184815247602082015233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6910160405180910390a250505b61069460016000805160206118f083398151915255565b50565b61069f610e6a565b610551610f5f565b60006106b1610fb9565b805490915060ff600160401b820416159067ffffffffffffffff166000811580156106d95750825b905060008267ffffffffffffffff1660011480156106f65750303b155b905081158015610704575080155b156107225760405163f92ee8a960e01b815260040160405180910390fd5b845467ffffffffffffffff19166001178555831561074c57845460ff60401b1916600160401b1785555b6001600160a01b03861661077357604051637a44db9560e01b815260040160405180910390fd5b336001600160a01b0387161461079c57604051637a44db9560e01b815260040160405180910390fd5b6107a587610fe4565b6107ad610ff5565b6107b5610ffd565b6107bd610ff5565b600080546001600160a01b0319166001600160a01b038816178155600155831561082157845460ff60401b19168555604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29060200160405180910390a15b50505050505050565b6000806001546000148061083e5750600254155b1561084c5750600091829150565b60015460025461085c91906114e2565b915081421090509091565b61086f61100d565b610878826110b2565b61088282826110ba565b5050565b600061089061117c565b506000805160206118b083398151915290565b6108ab610e6a565b6108b3610520565b6108bb610ec5565b6040516331a9108f60e11b81526004810182905282906001600160a01b03821690636352211e90602401602060405180830381865afa92505050801561091e575060408051601f3d908101601f1916820190925261091b918101906117ff565b60015b1561094e576001600160a01b038116301461094c576040516308c0b8b360e31b815260040160405180910390fd5b505b604051632142170760e11b8152306004820152336024820152604481018390526001600160a01b038216906342842e0e90606401600060405180830381600087803b15801561099c57600080fd5b505af11580156109b0573d6000803e3d6000fd5b50506040513392508491506001600160a01b038616907fc9e322753b88ef200a699612ee80267ec1889ce31dd470742469de7a75c3498290600090a45061088260016000805160206118f083398151915255565b6000610a0e610520565b610a16610ec5565b600054604051633d990f8f60e01b81523360048201526001600160a01b0390911690633d990f8f90602401602060405180830381865afa158015610a5e573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a82919061181c565b610a9f57604051633fdb5f0160e11b815260040160405180910390fd5b60005460405163145253f160e01b81526001600160a01b0387811660048301529091169063145253f19060240160006040518083038186803b158015610ae457600080fd5b505afa158015610af8573d6000803e3d6000fd5b5050505047821115610b265760405163cf47918160e01b8152600481018390524760248201526044016105ab565b60004790506000876001600160a01b0316848787604051610b4892919061183e565b60006040518083038185875af1925050503d8060008114610b85576040519150601f19603f3d011682016040523d82523d6000602084013e610b8a565b606091505b5050905080610b9e57600092505050610c28565b476000818411610baf576000610bb9565b610bb9828561184e565b600580549192508291906000610bce83611861565b9091555050604080518281523360208201526001600160a01b03808e1692600092918e16917fdd8b908eeba2b360768e83e04b5bf45f6fe09643c57d1150ad1efd2c6d08b5bf910160405180910390a46001955050505050505b61055c60016000805160206118f083398151915255565b610c47610e6a565b61055160006111c5565b610c59610e6a565b610551611236565b610c69610e6a565b610c71610520565b610c79610ec5565b476000819003610c895750610d53565b610c91610efd565b8060046000828254610ca391906114e2565b909155505042600255604051600090339083908381818185875af1925050503d8060008114610cee576040519150601f19603f3d011682016040523d82523d6000602084013e610cf3565b606091505b5050905080610d1557604051631d42c86760e21b815260040160405180910390fd5b604080518381526000602082015233917f92ccf450a286a957af52509bc1c9939d1a6a481783e142e41e2499f0bb66ebc6910160405180910390a250505b61055160016000805160206118f083398151915255565b610d72610e6a565b60018190556040518181527faffdfb262211d5a9ecffa4a8ecc187283f999fcd7422a952d7c82136a2fa0da1906020015b60405180910390a150565b610db6610520565b3415610551573460036000828254610dce91906114e2565b90915550506040805134815247602082015233917f73a19dd210f1a7f902193214c0ee91dd35ee5b4d920cba8d519eca65a7b488ca910160405180910390a2565b610e17610e6a565b610e1f610ec5565b476000819003610c915750610d53565b610e37610e6a565b6001600160a01b038116610e6157604051631e4fbdf760e01b8152600060048201526024016105ab565b610694816111c5565b33610e9c7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300546001600160a01b031690565b6001600160a01b0316146105515760405163118cdaa760e01b81523360048201526024016105ab565b6000805160206118f0833981519152805460011901610ef757604051633ee5aeb560e01b815260040160405180910390fd5b60029055565b6001541580610f0c5750600254155b15610f1357565b6000600154600254610f2591906114e2565b9050804210156106945760405163c1ab61a160e01b8152600481018290526024016105ab565b60016000805160206118f083398151915255565b610f6761127f565b6000805160206118d0833981519152805460ff191681557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b039091168152602001610da3565b6000807ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005b92915050565b610fec6112af565b610694816112d4565b6105516112af565b6110056112af565b6105516112dc565b306001600160a01b037f000000000000000000000000f6d63aba77fb85a711d7cba09ce4189b0e42cd0a16148061109457507f000000000000000000000000f6d63aba77fb85a711d7cba09ce4189b0e42cd0a6001600160a01b03166110886000805160206118b0833981519152546001600160a01b031690565b6001600160a01b031614155b156105515760405163703e46dd60e11b815260040160405180910390fd5b610694610e6a565b816001600160a01b03166352d1902d6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015611114575060408051601f3d908101601f191682019092526111119181019061187a565b60015b61113c57604051634c9c8ce360e01b81526001600160a01b03831660048201526024016105ab565b6000805160206118b0833981519152811461116d57604051632a87526960e21b8152600481018290526024016105ab565b61117783836112e4565b505050565b306001600160a01b037f000000000000000000000000f6d63aba77fb85a711d7cba09ce4189b0e42cd0a16146105515760405163703e46dd60e11b815260040160405180910390fd5b7f9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c19930080546001600160a01b031981166001600160a01b03848116918217845560405192169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3505050565b61123e610520565b6000805160206118d0833981519152805460ff191660011781557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833610fa1565b6000805160206118d08339815191525460ff1661055157604051638dfc202b60e01b815260040160405180910390fd5b6112b761133a565b61055157604051631afcd79f60e31b815260040160405180910390fd5b610e376112af565b610f4b6112af565b6112ed82611354565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a28051156113325761117782826113b9565b610882611426565b6000611344610fb9565b54600160401b900460ff16919050565b806001600160a01b03163b60000361138a57604051634c9c8ce360e01b81526001600160a01b03821660048201526024016105ab565b6000805160206118b083398151915280546001600160a01b0319166001600160a01b0392909216919091179055565b6060600080846001600160a01b0316846040516113d69190611893565b600060405180830381855af49150503d8060008114611411576040519150601f19603f3d011682016040523d82523d6000602084013e611416565b606091505b509150915061055c858383611445565b34156105515760405163b398979f60e01b815260040160405180910390fd5b60608261145a57611455826114a4565b61149d565b815115801561147157506001600160a01b0384163b155b1561149a57604051639996b31560e01b81526001600160a01b03851660048201526024016105ab565b50805b9392505050565b8051156114b357805160208201fd5b60405163d6bda27560e01b815260040160405180910390fd5b634e487b7160e01b600052601160045260246000fd5b80820180821115610fde57610fde6114cc565b6001600160a01b038116811461069457600080fd5b60008083601f84011261151c57600080fd5b50813567ffffffffffffffff81111561153457600080fd5b60208301915083602082850101111561154c57600080fd5b9250929050565b60008060008060006080868803121561156b57600080fd5b8535611576816114f5565b94506020860135611586816114f5565b935060408601359250606086013567ffffffffffffffff8111156115a957600080fd5b6115b58882890161150a565b969995985093965092949392505050565b6000602082840312156115d857600080fd5b5035919050565b600080604083850312156115f257600080fd5b82356115fd816114f5565b9150602083013561160d816114f5565b809150509250929050565b634e487b7160e01b600052604160045260246000fd5b6000806040838503121561164157600080fd5b823561164c816114f5565b9150602083013567ffffffffffffffff8082111561166957600080fd5b818501915085601f83011261167d57600080fd5b81358181111561168f5761168f611618565b604051601f8201601f19908116603f011681019083821181831017156116b7576116b7611618565b816040528281528860208487010111156116d057600080fd5b8260208601602083013760006020848301015280955050505050509250929050565b6000806040838503121561170557600080fd5b8235611710816114f5565b946020939093013593505050565b60008060008060006080868803121561173657600080fd5b8535611741816114f5565b94506020860135611751816114f5565b9350604086013567ffffffffffffffff81111561176d57600080fd5b6117798882890161150a565b96999598509660600135949350505050565b60005b838110156117a657818101518382015260200161178e565b50506000910152565b60208152600082518060208401526117ce81604085016020870161178b565b601f01601f19169190910160400192915050565b6000602082840312156117f457600080fd5b813561149d816114f5565b60006020828403121561181157600080fd5b815161149d816114f5565b60006020828403121561182e57600080fd5b8151801515811461149d57600080fd5b8183823760009101908152919050565b81810381811115610fde57610fde6114cc565b600060018201611873576118736114cc565b5060010190565b60006020828403121561188c57600080fd5b5051919050565b600082516118a581846020870161178b565b919091019291505056fe360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbccd5ed15c6e187e77e9aee88184c21f4f2182ab5827cb3b7e07fbedcd63f033009b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00a2646970667358221220d1c168d57ef88454139b66a66557459b35ba2ef7097511b200c4e0e3625ebb8264736f6c63430008180033

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
0xf6d63abA77fb85A711d7cba09cE4189b0e42cD0a
Loading...
Loading
Loading...
Loading
Loading...
Loading

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.