TimelockedWXRPVault

Description:

ERC20 token contract with Factory capabilities. Standard implementation for fungible tokens on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

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

/*
 * Timelocked WXRP Vault (owner-only)
 * - You deposit Wrapped XRP (ERC-20) directly from your wallet.
 * - Funds are locked until the immutable unlockTime.
 * - After unlock, you withdraw to your wallet.
 */

/* ---------- Minimal IERC20 ---------- */
interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address a) external view returns (uint256);
    function allowance(address o, address s) external view returns (uint256);
    function approve(address s, uint256 v) external returns (bool);
    function transfer(address to, uint256 v) external returns (bool);
    function transferFrom(address f, address to, uint256 v) external returns (bool);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

/* ---------- Minimal ReentrancyGuard ---------- */
abstract contract ReentrancyGuard {
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED     = 2;
    uint256 private _status;
    constructor() { _status = _NOT_ENTERED; }
    modifier nonReentrant() {
        require(_status != _ENTERED, "ReentrancyGuard: reentrant");
        _status = _ENTERED;
        _;
        _status = _NOT_ENTERED;
    }
}

/* ---------- Vault ---------- */
contract TimelockedWXRPVault is ReentrancyGuard {
    // Immutable config (cannot be changed after deployment)
    address public immutable owner;
    IERC20  public immutable wxrp;
    uint256 public immutable unlockTime;  // unix timestamp

    event Deposited(uint256 amount);
    event Withdrawn(uint256 amount);

    modifier onlyOwner() {
        require(msg.sender == owner, "not owner");
        _;
    }

    constructor(address _wxrp, uint256 _unlockTime) {
        require(_wxrp != address(0), "invalid token");
        require(_unlockTime > block.timestamp, "unlock must be in future");
        owner      = msg.sender;
        wxrp       = IERC20(_wxrp);
        unlockTime = _unlockTime; // immutable
    }

    /// @notice Deposit WXRP from your wallet into the vault (approve first).
    function deposit(uint256 amount) external nonReentrant onlyOwner {
        require(amount > 0, "amount=0");
        bool ok = wxrp.transferFrom(msg.sender, address(this), amount);
        require(ok, "transferFrom failed");
        emit Deposited(amount);
    }

    /// @notice Withdraw all WXRP after timelock to the owner wallet.
    function withdrawAll() external nonReentrant onlyOwner {
        require(block.timestamp >= unlockTime, "locked");
        uint256 bal = wxrp.balanceOf(address(this));
        require(bal > 0, "nothing to withdraw");
        bool ok = wxrp.transfer(owner, bal);
        require(ok, "transfer failed");
        emit Withdrawn(bal);
    }

    /// @notice View current WXRP balance held by the vault.
    function getBalance() external view returns (uint256) {
        return wxrp.balanceOf(address(this));
    }
}

Tags:
ERC20, Token, Factory|addr:0xd2fde873d592bf80556a2c413757121c3e19203a|verified:true|block:23495620|tx:0x1c6d7f74c5e080890c2adf8dab2a608950f8fba30f63a1633b79e7983e3d2410|first_check:1759483343

Submitted on: 2025-10-03 11:22:24

Comments

Log in to comment.

No comments yet.