Skip to content
Verified contractPartialMIT

NODERewardManagementV2

Address0xb4c90ff9af3108cf9fa21385ab14aa36acfb3efe
Balance

0 ETH

 

Transactions

4

 

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
25,849,040
Creation transaction
0x1c8cde6f28…42818aa044
Libraries
project/contracts/NODERewardManagement.sol:IterableMappingV20x9868…904405

project/contracts/NODERewardManagement.sol

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

library SafeMathNR {
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }

    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        require(b <= a, "SafeMath: subtraction overflow");
        return a - b;
    }

    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) return 0;
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }
}

library IterableMappingV2 {
    struct Map {
        address[] keys;
        mapping(address => uint256) values;
        mapping(address => uint256) indexOf;
        mapping(address => bool) inserted;
        mapping(address => uint256) l1cnt;
        mapping(address => uint256) l2cnt;
        mapping(address => uint256) l3cnt;
    }

    function get(Map storage map, address key) public view returns (uint256) {
        return map.values[key];
    }

    function getKeyAtIndex(Map storage map, uint256 index) public view returns (address) {
        return map.keys[index];
    }

    function size(Map storage map) public view returns (uint256) {
        return map.keys.length;
    }

    function set(Map storage map, address key, uint256 val, uint256 l1cnt, uint256 l2cnt, uint256 l3cnt) public {
        if (map.inserted[key]) {
            map.values[key] = val;
        } else {
            map.inserted[key] = true;
            map.values[key] = val;
            map.indexOf[key] = map.keys.length;
            map.l1cnt[key] = l1cnt;
            map.l2cnt[key] = l2cnt;
            map.l3cnt[key] = l3cnt;
            map.keys.push(key);
        }
    }

    function remove(Map storage map, address key) public {
        if (!map.inserted[key]) return;
        delete map.inserted[key];
        delete map.values[key];
        uint256 index = map.indexOf[key];
        uint256 lastIndex = map.keys.length - 1;
        address lastKey = map.keys[lastIndex];
        map.indexOf[lastKey] = index;
        delete map.indexOf[key];
        map.keys[index] = lastKey;
        map.keys.pop();
    }

    function getL1Counter(Map storage map, address user) public view returns (uint256) {
        return map.l1cnt[user];
    }

    function getL2Counter(Map storage map, address user) public view returns (uint256) {
        return map.l2cnt[user];
    }

    function getL3Counter(Map storage map, address user) public view returns (uint256) {
        return map.l3cnt[user];
    }

    function updateL1Counter(Map storage map, address user, uint256 cntnew) public {
        map.l1cnt[user] = cntnew;
    }

    function updateL2Counter(Map storage map, address user, uint256 cntnew) public {
        map.l2cnt[user] = cntnew;
    }

    function updateL3Counter(Map storage map, address user, uint256 cntnew) public {
        map.l3cnt[user] = cntnew;
    }
}

contract NODERewardManagementV2 {
    using SafeMathNR for uint256;
    using IterableMappingV2 for IterableMappingV2.Map;

    IterableMappingV2.Map private nodeOwners;

    /// @dev Prices/rewards scaled to the BlockV4 (BLOCK) ERC-20 (6 decimals).
    uint256 public nodePrice = 100 * 10 ** 6;
    uint256 public nodePriceL2 = 500 * 10 ** 6;
    uint256 public nodePriceL3 = 1000 * 10 ** 6;

    uint256 public rewardPerNode = 125 * 10 ** 4;
    uint256 public rewardPerNodeL2 = 75 * 10 ** 5;
    uint256 public rewardPerNodeL3 = 1875 * 10 ** 4;

    uint256 public claimTime = 6 hours;

    address public gateKeeper;
    address public token;

    /// @notice Extra contracts allowed to mutate node state (e.g. the V4 swap hook + the manager).
    /// @dev The single `token` slot is not enough once both the manager (claims) and the hook
    ///      (auto buy/sell nodes) must write. Authorized callers are managed by the gateKeeper.
    mapping(address => bool) public authorized;

    bool public distribution;

    uint256 public totalNodesCreated;
    uint256 public totalRewardStaked;
    uint256 public lastRebase;

    event AuthorizedUpdated(address indexed account, bool allowed);

    constructor() {
        gateKeeper = msg.sender;
        lastRebase = block.timestamp;
    }

    modifier onlySentry() {
        require(
            msg.sender == token || msg.sender == gateKeeper || authorized[msg.sender],
            "BLOCK: unauthorized"
        );
        _;
    }

    function setManager(address token_) external onlySentry {
        token = token_;
    }

    /// @notice Grant/revoke a writer (the manager for claims, the hook for auto nodes).
    function setAuthorized(address account, bool allowed) external onlySentry {
        authorized[account] = allowed;
        emit AuthorizedUpdated(account, allowed);
    }

    function distributeRewards() private returns (bool) {
        distribution = true;
        uint256 numberOfnodeOwners = nodeOwners.keys.length;
        address user;
        uint256 l1;
        uint256 l2;
        uint256 l3;
        uint256 staked;
        uint256 totalstaked;
        require(numberOfnodeOwners > 0, "DISTRI REWARDS: NO NODE OWNERS");
        require((lastRebase - 30 minutes) < block.timestamp, "No time passed to rebase");

        for (uint256 i = 0; i < numberOfnodeOwners; i++) {
            user = nodeOwners.getKeyAtIndex(i);
            l1 = nodeOwners.getL1Counter(user);
            l2 = nodeOwners.getL2Counter(user);
            l3 = nodeOwners.getL3Counter(user);
            staked = nodeOwners.get(user);
            staked += l1 * rewardPerNode + l2 * rewardPerNodeL2 + l3 * rewardPerNodeL3;
            nodeOwners.set(user, staked, l1, l2, l3);
            totalstaked += staked;
        }
        distribution = false;
        totalRewardStaked = totalstaked;
        lastRebase = block.timestamp + claimTime;
        return true;
    }

    function distributeRewardsIDX(uint256 idx1, uint256 idx2) private returns (bool) {
        distribution = true;
        uint256 numberOfnodeOwners = nodeOwners.keys.length;
        address user;
        uint256 l1;
        uint256 l2;
        uint256 l3;
        uint256 staked;
        uint256 totalstaked;

        if (idx1 == 0) {
            totalstaked = 0;
        } else {
            totalstaked = totalRewardStaked;
        }

        require(numberOfnodeOwners > 0, "DISTRI REWARDS: NO NODE OWNERS");
        require((lastRebase - 30 minutes) < block.timestamp);

        for (uint256 i = idx1; i < idx2; i++) {
            user = nodeOwners.getKeyAtIndex(i);
            l1 = nodeOwners.getL1Counter(user);
            l2 = nodeOwners.getL2Counter(user);
            l3 = nodeOwners.getL3Counter(user);
            staked = nodeOwners.get(user);
            staked += l1 * rewardPerNode + l2 * rewardPerNodeL2 + l3 * rewardPerNodeL3;
            nodeOwners.set(user, staked, l1, l2, l3);
            totalstaked += staked;
        }
        distribution = false;
        totalRewardStaked = totalstaked;
        lastRebase = block.timestamp + claimTime;
        return true;
    }

    function createNodeV2(address account, uint256 l, uint256 cnt) external onlySentry {
        uint256 aux;
        if (!nodeOwners.inserted[account]) {
            nodeOwners.set(account, 0, 0, 0, 0);
        }
        if (l == 1) {
            aux = nodeOwners.getL1Counter(account) + cnt;
            nodeOwners.updateL1Counter(account, aux);
        } else if (l == 2) {
            aux = nodeOwners.getL2Counter(account) + cnt;
            nodeOwners.updateL2Counter(account, aux);
        } else {
            aux = nodeOwners.getL3Counter(account) + cnt;
            nodeOwners.updateL3Counter(account, aux);
        }
        totalNodesCreated += cnt;
    }

    function _burn(address account, uint256 l) public onlySentry {
        uint256 cnt;
        if (l == 1) {
            cnt = nodeOwners.getL1Counter(account) - 1;
            nodeOwners.updateL1Counter(account, cnt);
        } else if (l == 2) {
            cnt = nodeOwners.getL2Counter(account) - 1;
            nodeOwners.updateL2Counter(account, cnt);
        } else {
            cnt = nodeOwners.getL3Counter(account) - 1;
            nodeOwners.updateL3Counter(account, cnt);
        }
        totalNodesCreated--;
    }

    /// @notice Burn up to `cnt` nodes of tier `l` from `account`, capped at what they hold.
    /// @dev Safe for the swap hook: never underflows and never reverts on a normal sell.
    /// @return burned The number of nodes actually removed.
    function _burnMany(address account, uint256 l, uint256 cnt) external onlySentry returns (uint256 burned) {
        uint256 have;
        if (l == 1) have = nodeOwners.getL1Counter(account);
        else if (l == 2) have = nodeOwners.getL2Counter(account);
        else have = nodeOwners.getL3Counter(account);

        burned = cnt > have ? have : cnt;
        if (burned == 0) return 0;

        if (l == 1) nodeOwners.updateL1Counter(account, have - burned);
        else if (l == 2) nodeOwners.updateL2Counter(account, have - burned);
        else nodeOwners.updateL3Counter(account, have - burned);

        totalNodesCreated -= burned;
    }

    function _cashoutAllNodesReward(address account) external onlySentry {
        uint256 l1 = nodeOwners.getL1Counter(account);
        uint256 l2 = nodeOwners.getL2Counter(account);
        uint256 l3 = nodeOwners.getL3Counter(account);
        nodeOwners.set(account, 0, l1, l2, l3);
    }

    function _getRewardAmountOf(address account) external view returns (uint256) {
        return nodeOwners.get(account);
    }

    function _getL1Counter(address account) external view returns (uint256) {
        return nodeOwners.getL1Counter(account);
    }

    function _getL2Counter(address account) external view returns (uint256) {
        return nodeOwners.getL2Counter(account);
    }

    function _getL3Counter(address account) external view returns (uint256) {
        return nodeOwners.getL3Counter(account);
    }

    function _getNodeHolders() external view returns (uint256) {
        return nodeOwners.keys.length;
    }

    function _changeNodePriceL1(uint256 newNodePrice) external onlySentry {
        nodePrice = newNodePrice;
    }

    function _changeNodePriceL2(uint256 newNodePrice) external onlySentry {
        nodePriceL2 = newNodePrice;
    }

    function _changeNodePriceL3(uint256 newNodePrice) external onlySentry {
        nodePriceL3 = newNodePrice;
    }

    function _changeRewardPerNodeL1(uint256 newPrice) external onlySentry {
        rewardPerNode = newPrice;
    }

    function _changeRewardPerNodeL2(uint256 newPrice) external onlySentry {
        rewardPerNodeL2 = newPrice;
    }

    function _changeRewardPerNodeL3(uint256 newPrice) external onlySentry {
        rewardPerNodeL3 = newPrice;
    }

    function _changeClaimTime(uint256 newTime) external onlySentry {
        claimTime = newTime;
    }

    function isNodeOwner(address account) private view returns (bool) {
        return nodeOwners.getL1Counter(account) > 0 || nodeOwners.getL2Counter(account) > 0 || nodeOwners.getL3Counter(account) > 0;
    }

    function _isNodeOwner(address account) external view returns (bool) {
        return isNodeOwner(account);
    }

    function _distributeRewards() external onlySentry returns (bool) {
        return distributeRewards();
    }

    function _distributeRewardsIDX(uint256 idx1, uint256 idx2) external onlySentry returns (bool) {
        return distributeRewardsIDX(idx1, idx2);
    }
}
Compiler settingsShow
{
  "libraries": {
    "project/contracts/NODERewardManagement.sol": {
      "IterableMappingV2": "0x9868e03995468bfd9b712635cc6b315f27904405"
    }
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "shanghai",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.