LockStakingETHV2

Description:

Multi-signature wallet contract requiring multiple confirmations for transaction execution.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "@openzeppelin/contracts/access/Ownable.sol": {
      "content": "// 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);
    }
}
"
    },
    "@openzeppelin/contracts/utils/Context.sol": {
      "content": "// 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;
    }
}
"
    },
    "@openzeppelin/contracts/utils/Pausable.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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 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());
    }
}
"
    },
    "@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
      "content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.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 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 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;
    }
}
"
    },
    "contracts/LockStakingETHV2.sol": {
      "content": "// SPDX-License-Identifier: MIT\r
pragma solidity ^0.8.20;\r
\r
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";\r
import {Pausable} from "@openzeppelin/contracts/utils/Pausable.sol";\r
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";\r
\r
/**\r
 * @title LockStakingETHV2\r
 * @notice ETH-only lockup staking with essential hardening.\r
 * - Stake via stake(lockId) sending ETH\r
 * - Lock options: 3m/6m/12m\r
 * - Per-user and global caps\r
 * - No payable fallback; non-stake functions enforce msg.value == 0\r
 * - Admin pause/unpause, emergency withdraw\r
 */\r
contract LockStakingETHV2 is ReentrancyGuard, Pausable, Ownable {\r
    uint256 public constant LOCK_3_MONTHS = 90 days;\r
    uint256 public constant LOCK_6_MONTHS = 180 days;\r
    uint256 public constant LOCK_12_MONTHS = 365 days;\r
\r
    // limits\r
    uint256 public maxPerStake = 1_000 ether;\r
    uint256 public maxPerUser = 10_000 ether;\r
    uint256 public maxGlobal = 100_000 ether;\r
\r
    struct Stake {\r
        uint256 amount;\r
        uint64 startTime;\r
        uint64 unlockTime;\r
        bool withdrawn;\r
    }\r
\r
    mapping(address => Stake[]) private userToStakes;\r
    mapping(address => uint256) public userTotalStaked;\r
    uint256 public totalStaked;\r
\r
    event Staked(address indexed user, uint256 indexed index, uint256 amount, uint256 unlockTime);\r
    event Unstaked(address indexed user, uint256 indexed index, uint256 amount);\r
    event LimitsUpdated(uint256 maxPerStake, uint256 maxPerUser, uint256 maxGlobal);\r
    event EmergencyWithdrawETH(uint256 amount, address indexed to);\r
\r
    constructor(address initialOwner) Ownable(initialOwner) {}\r
\r
    // ===== User =====\r
    function stake(uint8 lockId) external payable nonReentrant whenNotPaused {\r
        require(msg.value > 0, "stake: zero eth");\r
        require(msg.value <= maxPerStake, "stake: over per-stake cap");\r
        require(userTotalStaked[msg.sender] + msg.value <= maxPerUser, "stake: over user cap");\r
        require(totalStaked + msg.value <= maxGlobal, "stake: over global cap");\r
\r
        uint256 duration = _durationFor(lockId);\r
        uint64 start = uint64(block.timestamp);\r
        uint64 unlock = uint64(block.timestamp + duration);\r
\r
        userToStakes[msg.sender].push(Stake({\r
            amount: msg.value,\r
            startTime: start,\r
            unlockTime: unlock,\r
            withdrawn: false\r
        }));\r
\r
        userTotalStaked[msg.sender] += msg.value;\r
        totalStaked += msg.value;\r
\r
        emit Staked(msg.sender, userToStakes[msg.sender].length - 1, msg.value, unlock);\r
    }\r
\r
    function unstake(uint256 index) external nonReentrant {\r
        require(index < userToStakes[msg.sender].length, "stake: bad index");\r
        Stake storage s = userToStakes[msg.sender][index];\r
        require(!s.withdrawn, "stake: already withdrawn");\r
        require(block.timestamp >= s.unlockTime, "stake: locked");\r
\r
        s.withdrawn = true;\r
        uint256 amount = s.amount;\r
        userTotalStaked[msg.sender] -= amount;\r
        totalStaked -= amount;\r
\r
        (bool ok, ) = payable(msg.sender).call{ value: amount }("");\r
        require(ok, "stake: eth transfer failed");\r
\r
        emit Unstaked(msg.sender, index, amount);\r
    }\r
\r
    // ===== Views =====\r
    function getStakeCount(address user) external view returns (uint256) { return userToStakes[user].length; }\r
    function getStake(address user, uint256 index) external view returns (Stake memory) {\r
        require(index < userToStakes[user].length, "stake: bad index");\r
        return userToStakes[user][index];\r
    }\r
\r
    // ===== Admin =====\r
    function pause() external onlyOwner { _pause(); }\r
    function unpause() external onlyOwner { _unpause(); }\r
\r
    function setLimits(uint256 _maxPerStake, uint256 _maxPerUser, uint256 _maxGlobal) external onlyOwner {\r
        require(_maxPerStake > 0 && _maxPerUser > 0 && _maxGlobal > 0, "bad limits");\r
        maxPerStake = _maxPerStake;\r
        maxPerUser = _maxPerUser;\r
        maxGlobal = _maxGlobal;\r
        emit LimitsUpdated(_maxPerStake, _maxPerUser, _maxGlobal);\r
    }\r
\r
    function adminEmergencyWithdrawETH(uint256 amount, address to) external onlyOwner {\r
        require(to != address(0), "stake: to zero");\r
        (bool ok, ) = payable(to).call{ value: amount }("");\r
        require(ok, "stake: eth transfer failed");\r
        emit EmergencyWithdrawETH(amount, to);\r
    }\r
\r
    // ===== Internal =====\r
    function _durationFor(uint8 lockId) internal pure returns (uint256) {\r
        if (lockId == 0) return LOCK_3_MONTHS;\r
        if (lockId == 1) return LOCK_6_MONTHS;\r
        if (lockId == 2) return LOCK_12_MONTHS;\r
        revert("stake: bad lockId");\r
    }\r
\r
    // Block unsupported calls and ETH sends\r
    receive() external payable { revert("unsupported"); }\r
    fallback() external payable { revert("unsupported"); }\r
}\r
\r
\r
"
    }
  },
  "settings": {
    "optimizer": {
      "enabled": true,
      "runs": 200
    },
    "evmVersion": "paris",
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    }
  }
}}

Tags:
Multisig, Multi-Signature, Factory|addr:0x80777529a760498b42ec3b85f826947ef302a58e|verified:true|block:23504537|tx:0x9ade95e683c80b65702ba052d160ee6881a6349988df7e43e22f5dee1bcd34cf|first_check:1759582401

Submitted on: 2025-10-04 14:53:21

Comments

Log in to comment.

No comments yet.