Проверенный контрактЧастичноеMIT
StakingStorage
Адрес0xd806eace550ea2903dcd76abc73f96c0bc8e8790
- Баланс
0 ETH
- Транзакций
2
- Компилятор
solc 0.8.28
- Тот же код
ещё 1 контракт
Подробности
- Компилятор
- solc 0.8.28+commit.7893614a
- Язык
- solidity
- Оптимизация
- Да, 200 прогонов
- Версия EVM
- cancun
- Лицензия
- MIT
- Совпадение
- Частичноекод создания: да, код в сети: да
- Проверен на Sourcify
- Создан в блоке
- 26 405 082
- Транзакция создания
- 0xf46d477614…cf041713e7
StakingStorage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20 ^0.8.28;
// lib/openzeppelin-contracts/contracts/utils/Context.sol
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.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 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;
}
}
// lib/openzeppelin-contracts/contracts/access/Ownable.sol
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.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);
}
}
// src/StakingStorage.sol
/// @title 质押结算数据。金额单位是整枚 USDT
contract StakingStorage is Ownable {
address public staking;
mapping(address => mapping(uint256 => uint256)) public userPeriodMatched;
mapping(address => mapping(uint256 => bool)) public userPeriodClaimed;
mapping(address => mapping(uint256 => uint256)) public userPeriodTeamReward;
mapping(address => uint256[]) public userMatchedPeriods;
mapping(address => mapping(uint256 => bool)) public userMatchedPeriodSeen;
/// @notice 某期有匹配入账的用户列表(清算分批遍历)
mapping(uint256 => address[]) public periodMatchedUsers;
mapping(uint256 => mapping(address => bool)) public periodMatchedUserSeen;
mapping(address => uint256[]) public userTeamPeriods;
mapping(address => mapping(uint256 => bool)) public userTeamPeriodSeen;
/// @notice 是否已成为有效地址(有上级且至少匹配成功过一次)
mapping(address => bool) public isEffective;
/// @notice 直推有效地址数量
mapping(address => uint256) public effectiveDirectCount;
/// @notice 团队业绩(只增不减,不含自己)
mapping(address => uint256) public teamVolume;
/// @notice 历史最高达成等级 0–6(不因掉排单清零)
mapping(address => uint8) public historicalMaxLevel;
/// @notice 直推中历史曾达成过 >= level 的人数;level 取 1–5
mapping(address => mapping(uint8 => uint256)) public histChildCount;
error ZeroAddress();
error NotStaking();
modifier onlyStaking() {
if (msg.sender != staking || staking == address(0)) revert NotStaking();
_;
}
constructor() Ownable(msg.sender) {}
function setStaking(address staking_) external onlyOwner {
if (staking_ == address(0)) revert ZeroAddress();
staking = staking_;
}
function userMatchedPeriodCount(address user) external view returns (uint256) {
return userMatchedPeriods[user].length;
}
function periodMatchedUserCount(uint256 period) external view returns (uint256) {
return periodMatchedUsers[period].length;
}
function userTeamPeriodCount(address user) external view returns (uint256) {
return userTeamPeriods[user].length;
}
function addMatched(address user, uint256 period, uint256 amount) external onlyStaking {
if (!userMatchedPeriodSeen[user][period]) {
userMatchedPeriodSeen[user][period] = true;
userMatchedPeriods[user].push(period);
}
if (!periodMatchedUserSeen[period][user]) {
periodMatchedUserSeen[period][user] = true;
periodMatchedUsers[period].push(user);
}
userPeriodMatched[user][period] += amount;
}
function setClaimed(address user, uint256 period) external onlyStaking {
userPeriodClaimed[user][period] = true;
}
function addTeamReward(address user, uint256 period, uint256 amount) external onlyStaking {
if (!userTeamPeriodSeen[user][period]) {
userTeamPeriodSeen[user][period] = true;
userTeamPeriods[user].push(period);
}
userPeriodTeamReward[user][period] += amount;
}
function markEffective(address user) external onlyStaking returns (bool firstTime) {
if (isEffective[user]) return false;
isEffective[user] = true;
return true;
}
function addEffectiveDirect(address parent) external onlyStaking {
unchecked {
++effectiveDirectCount[parent];
}
}
function addTeamVolume(address user, uint256 amount) external onlyStaking {
if (amount == 0) return;
teamVolume[user] += amount;
}
/// @notice 提升历史最高等级;返回是否发生变化
function raiseHistoricalMaxLevel(
address user,
uint8 newLevel
) external onlyStaking returns (uint8 oldLevel, bool raised) {
oldLevel = historicalMaxLevel[user];
if (newLevel <= oldLevel) return (oldLevel, false);
historicalMaxLevel[user] = newLevel;
return (oldLevel, true);
}
function addHistChildCount(
address parent,
uint8 fromExclusive,
uint8 toInclusive
) external onlyStaking {
for (uint8 L = fromExclusive + 1; L <= toInclusive; ) {
unchecked {
++histChildCount[parent][L];
++L;
}
}
}
/// @notice 按业绩与直推条件计算潜在等级(不含「正常排单」门槛)
function computePotentialLevel(address user) public view returns (uint8) {
if (effectiveDirectCount[user] < 3) return 0;
uint256 vol = teamVolume[user];
if (vol >= 110 && histChildCount[user][5] >= 2) return 6;
if (vol >= 90 && histChildCount[user][4] >= 2) return 5;
if (vol >= 70 && histChildCount[user][3] >= 2) return 4;
if (vol >= 50 && histChildCount[user][2] >= 2) return 3;
if (vol >= 30 && histChildCount[user][1] >= 2) return 2;
if (vol >= 10) return 1;
return 0;
}
}Настройки компилятораПоказать
{
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun"
}Исходный код и метаданные: Sourcify.
Исходный код принадлежит авторам контракта.