账户
0x0a...dbba
0x0A...dbBA

0x0A...dbBA

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.23+commit.f704f362
语言
Solidity
合同源代码
文件 1 的 8:Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

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

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

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}
合同源代码
文件 2 的 8:IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC165 standard, as defined in the
 * https://eips.ethereum.org/EIPS/eip-165[EIP].
 *
 * 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[EIP 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);
}
合同源代码
文件 3 的 8:IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
合同源代码
文件 4 的 8:IERC721.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Required interface of an ERC721 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 ERC721 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 ERC721
     * 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);
}
合同源代码
文件 5 的 8:Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.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 Ownable is Context {
    address private _owner;

    /**
     * @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.
     */
    constructor(address initialOwner) {
        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) {
        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 {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
合同源代码
文件 6 的 8:Pausable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.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 Pausable is Context {
    bool private _paused;

    /**
     * @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 Initializes the contract in unpaused state.
     */
    constructor() {
        _paused = false;
    }

    /**
     * @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();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        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 {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }
}
合同源代码
文件 7 的 8:ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

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

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

    uint256 private _status;

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

    constructor() {
        _status = NOT_ENTERED;
    }

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

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

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

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

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
合同源代码
文件 8 的 8:WoofWorkLPStaking.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";

/* STRUCTS */

struct Pool {
    uint232 tvl;
    uint24 participants;
}

struct Option {
    uint128 apr;
    uint128 range;
}

struct Staking {
    bool nft;
    uint16 tokenId;
    uint232 amount;
    uint256 end;
    uint256 earning;
    uint256 revenuePerSecond;
    Option option;
}

/* EVENTS */

event LPSet(address lp);
event WoofSet(address woof);
event WoofworkerStakingDenied();

event WoofworkerStakingAllowed();

event WoofworkerAddressSet(address woofworkerAddress);

event OptionsUpdated(uint128[] aprs, uint128[] ranges);

event StakedWithoutNFT(address indexed wallet, uint256 amount, uint128 apr, uint128 range);

event UnstakeWithoutNFT(address indexed wallet, uint256 burnedAmount, uint256 withdrawnAmount);

event StakedWithNFT(address indexed wallet, uint96 indexed tokenId, uint256 amount, uint128 apr, uint128 range);

event UnstakeWithNFT(address indexed wallet, uint96 indexed tokenId, uint256 burnedAmount, uint256 withdrawnAmount);

/* ERRORS */

error NoContracts();
error NotStakedYet();
error AlreadyStaked();
error NothingStaked();
error NotTokenOwner();
error WithdrawFailed();
error NotAvailableYet();
error NotEnoughBalance();
error CoinTransferFailed();
error ExceedsOptionsLimit();
error InvalidWoofworkerId();
error InputsLengthsMismatch();
error WoofworkerAlreadyStaked();

/*
                                 __       __   ______    ______   ________  __       __   ______   _______   __    __                                           
                                |  \  _  |  \ /      \  /      \ |        \|  \  _  |  \ /      \ |       \ |  \  /  \                                          
                                | $$ / \ | $$|  $$$$$$\|  $$$$$$\| $$$$$$$$| $$ / \ | $$|  $$$$$$\| $$$$$$$\| $$ /  $$       __                                 
                                | $$/  $\| $$| $$  | $$| $$  | $$| $$__    | $$/  $\| $$| $$  | $$| $$__| $$| $$/  $$       |  \                                
                                | $$  $$$\ $$| $$  | $$| $$  | $$| $$  \   | $$  $$$\ $$| $$  | $$| $$    $$| $$  $$         \$$                                
                                | $$ $$\$$\$$| $$  | $$| $$  | $$| $$$$$   | $$ $$\$$\$$| $$  | $$| $$$$$$$\| $$$$$\         __                                 
                                | $$$$  \$$$$| $$__/ $$| $$__/ $$| $$      | $$$$  \$$$$| $$__/ $$| $$  | $$| $$ \$$\       |  \                                
                                | $$$    \$$$ \$$    $$ \$$    $$| $$      | $$$    \$$$ \$$    $$| $$  | $$| $$  \$$\       \$$                                
                                 \$$      \$$  \$$$$$$   \$$$$$$  \$$       \$$      \$$  \$$$$$$  \$$   \$$ \$$   \$$                                                                                                                                                                                                                                                               
     __        _______               __        __       __   ______    ______   ________         ______  ________   ______   __    __  ______  __    __   ______  
    |  \      |       \             /  \      |  \  _  |  \ /      \  /      \ |        \       /      \|        \ /      \ |  \  /  \|      \|  \  |  \ /      \ 
    | $$      | $$$$$$$\           /  $$      | $$ / \ | $$|  $$$$$$\|  $$$$$$\| $$$$$$$$      |  $$$$$$\\$$$$$$$$|  $$$$$$\| $$ /  $$ \$$$$$$| $$\ | $$|  $$$$$$\
    | $$      | $$__/ $$          /  $$       | $$/  $\| $$| $$  | $$| $$  | $$| $$__          | $$___\$$  | $$   | $$__| $$| $$/  $$   | $$  | $$$\| $$| $$ __\$$
    | $$      | $$    $$         /  $$        | $$  $$$\ $$| $$  | $$| $$  | $$| $$  \          \$$    \   | $$   | $$    $$| $$  $$    | $$  | $$$$\ $$| $$|    \
    | $$      | $$$$$$$         /  $$         | $$ $$\$$\$$| $$  | $$| $$  | $$| $$$$$          _\$$$$$$\  | $$   | $$$$$$$$| $$$$$\    | $$  | $$\$$ $$| $$ \$$$$
    | $$_____ | $$             /  $$          | $$$$  \$$$$| $$__/ $$| $$__/ $$| $$            |  \__| $$  | $$   | $$  | $$| $$ \$$\  _| $$_ | $$ \$$$$| $$__| $$
    | $$     \| $$            |  $$           | $$$    \$$$ \$$    $$ \$$    $$| $$             \$$    $$  | $$   | $$  | $$| $$  \$$\|   $$ \| $$  \$$$ \$$    $$
     \$$$$$$$$ \$$             \$$             \$$      \$$  \$$$$$$   \$$$$$$  \$$              \$$$$$$    \$$    \$$   \$$ \$$   \$$ \$$$$$$ \$$   \$$  \$$$$$$ 
                                                                                                                                                                                                                                                                                                                                                                                                                                 
*/

/// @title Woofwork Staking $LP / $WOOF (https://steaking.woofwork.io/)
/// @author bc.army (https://bc.army/)
/// @notice Platform to stake $LP (+ $WOOFWORKER) and earn revenue in $WOOF.
contract WoofworkStakingLPWoof is Ownable, Pausable, ReentrancyGuard {
    /* INITIALIZATION */

    constructor() Ownable(msg.sender) {
    }

    /* MAPPINGS */

    mapping(uint256 => Option) private _options;
    mapping(address => Staking) private _stakings;

    /* VARIABLES */

    Pool private pool;
    bool private _nftStaking;

    IERC20 private $LP;
    uint96 private constant UNIT_PERCENTAGE = 100;

    IERC20 private $WOOF;
    uint96 private constant WOOFWORKER_MAX_SUPPLY = 1000;

    uint96 private constant YEAR_TIMESTAMP = 365 days;
    address private constant PENALTY_ADDRESS = 0xeCE2473567d216715cA5753bCE0ed4aa58256d4a;

    IERC721 private $WOOFWORKER;
    uint48 private constant OPTIONS_LIMIT = 4;
    uint48 private constant PENALTY_PERCENTAGE = 10;

    /* MODIFIERS */

    modifier canStakeWoofworker() {
        if (!_nftStaking) revert NotAvailableYet();
        _;
    }

    modifier isTokenValid(uint256 tokenId) {
        if (tokenId == 0 || tokenId > WOOFWORKER_MAX_SUPPLY) {
            revert InvalidWoofworkerId();
        }
        _;
    }

    modifier isTokenOwner(uint256 tokenId) {
        if (msg.sender != $WOOFWORKER.ownerOf(tokenId)) {
            revert NotTokenOwner();
        }
        _;
    }

    modifier noContracts() {
        if (msg.sender != tx.origin) revert NoContracts();
        _;
    }

    modifier checkOptionId(uint256 optionId) {
        if (OPTIONS_LIMIT <= optionId) revert ExceedsOptionsLimit();
        _;
    }

    modifier checkBalanceLP(uint256 amount) {
        if ($LP.balanceOf(msg.sender) < amount) revert NotEnoughBalance();
        _;
    }

    /* GETTERS */

    function getPoolData() public view returns (Pool memory) {
        return pool;
    }

    function getWalletStakingData() public view returns (Staking memory) {
        return _stakings[msg.sender];
    }

    /* SETTERS */

    function withdraw() external payable onlyOwner nonReentrant {
        (bool success,) = (msg.sender).call{value: address(this).balance}("");
        if (!success) revert WithdrawFailed();
    }

    function setLP(address lp) external payable onlyOwner {
        $LP = IERC20(lp);
        emit LPSet(lp);
    }  

    function setWoof(address woof) external payable onlyOwner {
        $WOOF = IERC20(woof);
        emit WoofSet(woof);
    }  

    function allowStakingWoofworker() external payable onlyOwner {
        _nftStaking = true;
        emit WoofworkerStakingAllowed();
    }

    function denyStakingWoofworker() external payable onlyOwner {
        _nftStaking = false;
        emit WoofworkerStakingDenied();
    }

    function setWoofworker(address woofworker) external payable onlyOwner {
        $WOOFWORKER = IERC721(woofworker);
        emit WoofworkerAddressSet(woofworker);
    }

    function pause() external payable onlyOwner {
        _pause();
    }

    function unpause() external payable onlyOwner {
        _unpause();
    }

    function updateOptions(uint128[] memory aprs, uint128[] memory ranges) external payable onlyOwner {
        uint256 length = aprs.length;
        if (length != ranges.length || length != OPTIONS_LIMIT) {
            revert InputsLengthsMismatch();
        }
        for (uint256 i; i < length;) {
            _options[i] = Option(aprs[i], ranges[i]);
            assembly {
                i := add(i, 1)
            }
        }
        emit OptionsUpdated(aprs, ranges);
    }

    /**
     * @dev Stake tokens for the first time.
     *
     * Requirements:
     *
     * - '_paused' must be false.
     * - 'optionId' must be in range.
     * - 'tx.origin' must be 'msg.sender' to avoid contract calls.
     * - user LP balance must be equal or greater than 'amount'.
     *
     * Emits a {StakedWithoutNFT} event.
     */
    function firstStakeWithoutNFT(uint24 optionId, uint232 amount)
        external
        payable
        noContracts
        nonReentrant
        whenNotPaused
        checkOptionId(optionId)
        checkBalanceLP(amount)
    {
        // Get Staking Data
        Staking storage staking = _stakings[msg.sender];

        // Check Conditions
        if (staking.amount != 0) revert AlreadyStaked();

        // Execute Transfers
        if (!$LP.transferFrom(msg.sender, address(this), amount)) {
            revert CoinTransferFailed();
        }

        // Get Option Data
        Option memory option = _options[optionId];

        // Set Local Variables
        uint128 apr = option.apr;
        uint128 range = option.range;
        unchecked {
            // Update Staking Data
            staking.amount = amount;
            staking.option.apr = apr;
            staking.option.range = range;
            staking.end = block.timestamp + range;
            staking.revenuePerSecond = (amount + (amount * apr) / UNIT_PERCENTAGE) / YEAR_TIMESTAMP;

            // Update Pool Data
            pool.tvl += amount;
            ++pool.participants;
        }
        // Emit Event
        emit StakedWithoutNFT(msg.sender, amount, apr, range);
    }

    /**
     * @dev Stake tokens and NFT for the first time.
     *
     * Requirements:
     *
     * - '_paused' must be false.
     * - 'optionId' must be in range.
     * - LP must be not already staked by user.
     * - 'tokenId' must exists and 'msg.sender' must be the owner.
     * - 'tx.origin' must be 'msg.sender' to avoid contract calls.
     * - user LP balance must be equal or greater than 'amount'.
     *
     * Emits a {StakedWithNFT} event.
     */
    function firstStakeWithNFT(uint8 optionId, uint16 tokenId, uint232 amount)
        external
        payable
        noContracts
        nonReentrant
        whenNotPaused
        canStakeWoofworker
        isTokenValid(tokenId)
        isTokenOwner(tokenId)
        checkOptionId(optionId)
        checkBalanceLP(amount)
    {
        // Get Staking Data
        Staking storage staking = _stakings[msg.sender];

        // Check Conditions
        if (staking.amount != 0) revert AlreadyStaked();

        // Execute Transfers
        if (!$LP.transferFrom(msg.sender, address(this), amount)) {
            revert CoinTransferFailed();
        }
        $WOOFWORKER.transferFrom(msg.sender, address(this), tokenId);

        // Get Option Data
        Option memory option = _options[optionId];

        // Set Local Variables
        uint128 range = option.range;
        uint128 apr = option.apr + ((option.apr * _retrieveTokenBoost(tokenId)) / UNIT_PERCENTAGE);
        unchecked {
            // Update Staking Data
            staking.nft = true;
            staking.amount = amount;
            staking.option.apr = apr;
            staking.tokenId = tokenId;
            staking.revenuePerSecond = (amount + (amount * apr) / UNIT_PERCENTAGE) / YEAR_TIMESTAMP;
            staking.end = block.timestamp + range;

            // Update Pool Data
            pool.tvl += amount;
            ++pool.participants;
        }
        // Emit Event
        emit StakedWithNFT(msg.sender, tokenId, amount, apr, range);
    }

    /**
     * @dev Add tokens to current staking.
     *
     * Requirements:
     *
     * - '_paused' must be false.
     * - 'optionId' must be in range.
     * - LP must be already staked by user.
     * - 'tokenId' must exists and 'msg.sender' must be the owner.
     * - 'tx.origin' must be 'msg.sender' to avoid contract calls.
     * - user LP balance must be equal or greater than 'amount'.
     *
     * Emits a {StakedWithoutNFT} event.
     */
    function secondaryStakeWithoutNFT(uint232 amount)
        external
        payable
        noContracts
        nonReentrant
        whenNotPaused
        checkBalanceLP(amount)
    {
        // Get Staking Data
        Staking storage staking = _stakings[msg.sender];

        // Check Conditions
        if (staking.amount == 0) revert NotStakedYet();

        // Execute Transfers
        if (!$LP.transferFrom(msg.sender, address(this), amount)) {
            revert CoinTransferFailed();
        }

        // Set Local Variables
        uint256 end = staking.end;
        uint128 apr = staking.option.apr;
        uint128 range = staking.option.range;
        unchecked {
            // Update Staking Data
            staking.amount += amount;
            staking.end = block.timestamp + range;
            staking.earning +=
                staking.revenuePerSecond * (block.timestamp < end ? range - (end - block.timestamp) : range);

            // Update Pool Data
            pool.tvl += amount;
        }
        // Emit Event

        emit StakedWithoutNFT(msg.sender, amount, apr, range);
    }

    /**
     * @dev Add tokens and NFT to current staking.
     *
     * Requirements:
     *
     * - '_paused' must be false.
     * - 'optionId' must be in range.
     * - WOOF must be already staked by user.
     * - NFT must be not already staked by user.
     * - 'tokenId' must exists and 'msg.sender' must be the owner.
     * - 'tx.origin' must be 'msg.sender' to avoid contract calls.
     * - user WOOF balance must be equal or greater than 'amount'.
     *
     * Emits a {StakedWithNFT} event.
     */
    function secondaryStakeWithNFT(uint16 tokenId, uint232 amount)
        external
        payable
        noContracts
        nonReentrant
        whenNotPaused
        canStakeWoofworker
        isTokenValid(tokenId)
        isTokenOwner(tokenId)
        checkBalanceLP(amount)
    {
        // Get Staking Data
        Staking storage staking = _stakings[msg.sender];

        // Check Conditions
        if (staking.nft) revert WoofworkerAlreadyStaked();
        if (staking.amount == 0) revert NotStakedYet();

        // Execute Transfers
        if (!$LP.transferFrom(msg.sender, address(this), amount)) {
            revert CoinTransferFailed();
        }
        $WOOFWORKER.transferFrom(msg.sender, address(this), tokenId);

        // Set Local Variables
        uint256 end = staking.end;
        uint128 apr = staking.option.apr;
        uint128 range = staking.option.range;
        uint128 aprBoosted = apr + ((apr * _retrieveTokenBoost(tokenId)) / UNIT_PERCENTAGE);
        unchecked {
            // Update Staking Data
            staking.nft = true;
            staking.amount += amount;
            staking.tokenId = tokenId;
            staking.option.apr = aprBoosted;
            staking.end = block.timestamp + range;
            staking.earning +=
                staking.revenuePerSecond * (block.timestamp < end ? range - (end - block.timestamp) : range);
            staking.revenuePerSecond = amount + ((amount * aprBoosted) / UNIT_PERCENTAGE) / YEAR_TIMESTAMP;

            // Update Pool Data
            pool.tvl += amount;
        }
        // Emit Event
        emit StakedWithNFT(msg.sender, tokenId, amount, apr, range);
    }

    /**
     * @dev Unstake tokens.
     *
     * Requirements:
     *
     * - LP must be already staked by user.
     * - 'tx.origin' must be 'msg.sender' to avoid contract calls.
     *
     * Emits a {UnstakeWithNFT} or {UnstakeWithoutNFT} event.
     */
    function unstake() external payable noContracts nonReentrant {
        // Get Staking Data
        Staking storage staking = _stakings[msg.sender];

        // Check Conditions
        if (staking.amount == 0) revert NothingStaked();

        // Set Local Variables
        uint256 burnedAmount;
        uint256 withdrawnAmount;
        uint256 amount = staking.amount;

        if (block.timestamp < staking.end) {
            burnedAmount = amount / PENALTY_PERCENTAGE;
            withdrawnAmount = amount - burnedAmount;
            if (!$LP.transfer(msg.sender, withdrawnAmount) || !$LP.transfer(PENALTY_ADDRESS, burnedAmount)) {
                revert CoinTransferFailed();
            }
        } else {
            if (
                !$LP.transfer(msg.sender, amount)
                    || !$WOOF.transfer(msg.sender, staking.earning + (staking.revenuePerSecond * staking.option.range))
            ) revert CoinTransferFailed();
        }

        if (staking.nft) {
            $WOOFWORKER.transferFrom(address(this), msg.sender, staking.tokenId);
            emit UnstakeWithNFT(msg.sender, staking.tokenId, burnedAmount, withdrawnAmount);
        } else {
            emit UnstakeWithoutNFT(msg.sender, withdrawnAmount, burnedAmount);
        }

        pool.tvl -= uint232(amount);
        --pool.participants;

        delete _stakings[msg.sender];
    }

    /* HELPERS */

    function _retrieveTokenBoost(uint256 tokenId) private pure returns (uint128 boost) {
        if ((tokenId < 26) || (tokenId > 225 && tokenId < 251)) return 30;
        if ((tokenId > 175 && tokenId < 226) || (tokenId > 500 && tokenId < 601)) return 20;
        if ((tokenId > 75 && tokenId < 176) || (tokenId > 600 && tokenId < 701)) {
            return 10;
        }
        if ((tokenId > 250 && tokenId < 501) || (tokenId > 750 && tokenId < 1001)) return 5;
    }
}
设置
{
  "compilationTarget": {
    "WoofWorkLPStaking.sol": "WoofworkStakingLPWoof"
  },
  "evmVersion": "shanghai",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": []
}
ABI
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyStaked","type":"error"},{"inputs":[],"name":"CoinTransferFailed","type":"error"},{"inputs":[],"name":"EnforcedPause","type":"error"},{"inputs":[],"name":"ExceedsOptionsLimit","type":"error"},{"inputs":[],"name":"ExpectedPause","type":"error"},{"inputs":[],"name":"InputsLengthsMismatch","type":"error"},{"inputs":[],"name":"InvalidWoofworkerId","type":"error"},{"inputs":[],"name":"NoContracts","type":"error"},{"inputs":[],"name":"NotAvailableYet","type":"error"},{"inputs":[],"name":"NotEnoughBalance","type":"error"},{"inputs":[],"name":"NotStakedYet","type":"error"},{"inputs":[],"name":"NotTokenOwner","type":"error"},{"inputs":[],"name":"NothingStaked","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":"WithdrawFailed","type":"error"},{"inputs":[],"name":"WoofworkerAlreadyStaked","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"lp","type":"address"}],"name":"LPSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint128[]","name":"aprs","type":"uint128[]"},{"indexed":false,"internalType":"uint128[]","name":"ranges","type":"uint128[]"}],"name":"OptionsUpdated","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":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":true,"internalType":"uint96","name":"tokenId","type":"uint96"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"apr","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"range","type":"uint128"}],"name":"StakedWithNFT","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"apr","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"range","type":"uint128"}],"name":"StakedWithoutNFT","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":"wallet","type":"address"},{"indexed":true,"internalType":"uint96","name":"tokenId","type":"uint96"},{"indexed":false,"internalType":"uint256","name":"burnedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"withdrawnAmount","type":"uint256"}],"name":"UnstakeWithNFT","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"wallet","type":"address"},{"indexed":false,"internalType":"uint256","name":"burnedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"withdrawnAmount","type":"uint256"}],"name":"UnstakeWithoutNFT","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"woof","type":"address"}],"name":"WoofSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"woofworkerAddress","type":"address"}],"name":"WoofworkerAddressSet","type":"event"},{"anonymous":false,"inputs":[],"name":"WoofworkerStakingAllowed","type":"event"},{"anonymous":false,"inputs":[],"name":"WoofworkerStakingDenied","type":"event"},{"inputs":[],"name":"allowStakingWoofworker","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"denyStakingWoofworker","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint8","name":"optionId","type":"uint8"},{"internalType":"uint16","name":"tokenId","type":"uint16"},{"internalType":"uint232","name":"amount","type":"uint232"}],"name":"firstStakeWithNFT","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint24","name":"optionId","type":"uint24"},{"internalType":"uint232","name":"amount","type":"uint232"}],"name":"firstStakeWithoutNFT","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getPoolData","outputs":[{"components":[{"internalType":"uint232","name":"tvl","type":"uint232"},{"internalType":"uint24","name":"participants","type":"uint24"}],"internalType":"struct Pool","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getWalletStakingData","outputs":[{"components":[{"internalType":"bool","name":"nft","type":"bool"},{"internalType":"uint16","name":"tokenId","type":"uint16"},{"internalType":"uint232","name":"amount","type":"uint232"},{"internalType":"uint256","name":"end","type":"uint256"},{"internalType":"uint256","name":"earning","type":"uint256"},{"internalType":"uint256","name":"revenuePerSecond","type":"uint256"},{"components":[{"internalType":"uint128","name":"apr","type":"uint128"},{"internalType":"uint128","name":"range","type":"uint128"}],"internalType":"struct Option","name":"option","type":"tuple"}],"internalType":"struct Staking","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"tokenId","type":"uint16"},{"internalType":"uint232","name":"amount","type":"uint232"}],"name":"secondaryStakeWithNFT","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint232","name":"amount","type":"uint232"}],"name":"secondaryStakeWithoutNFT","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"lp","type":"address"}],"name":"setLP","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"woof","type":"address"}],"name":"setWoof","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"woofworker","type":"address"}],"name":"setWoofworker","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"unstake","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint128[]","name":"aprs","type":"uint128[]"},{"internalType":"uint128[]","name":"ranges","type":"uint128[]"}],"name":"updateOptions","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"payable","type":"function"}]