Solidity API

NodeManagement

This contract manages node ownership and delegation within the VeBetter DAO ecosystem. It supports delegation, retrieval of managed nodes, and integration with VeChain Nodes and token auction contracts.

_The contract is upgradeable using the UUPS proxy pattern and implements role-based access control for secure upgrades.

———————— Version 2 ———————— - Add function to check if Node is delegated - Add function to check if user is a delegator - Add function to get users owned node ID - Add function to retrieve detailed information about a user’s nodes (both delegated and owned)_

constructor

constructor() public

UPGRADER_ROLE

bytes32 UPGRADER_ROLE

NodeInfo

struct NodeInfo {
  uint256 nodeId;
  enum VechainNodesDataTypes.NodeStrengthLevel nodeLevel;
  address xNodeOwner;
  bool isXNodeHolder;
  bool isXNodeDelegated;
  bool isXNodeDelegator;
  bool isXNodeDelegatee;
  address delegatee;
}

NodeManagementStorage

struct NodeManagementStorage {
  contract ITokenAuction vechainNodesContract;
  mapping(address => struct EnumerableSet.UintSet) delegateeToNodeIds;
  mapping(uint256 => address) nodeIdToDelegatee;
}

_getNodeManagementStorage

function _getNodeManagementStorage() internal pure returns (struct NodeManagement.NodeManagementStorage $)

Retrieve the storage reference for node delegation data.

Internal pure function to get the storage slot for node delegation data using inline assembly.

initialize

function initialize(address _vechainNodesContract, address _admin, address _upgrader) external

Initialize the contract with the specified VeChain Nodes contract, admin, and upgrader addresses.

This function initializes the contract and sets the initial values for the VeChain Nodes contract address and other roles. It should be called only once during deployment.

Parameters

Name Type Description
_vechainNodesContract address The address of the VeChain Nodes contract.
_admin address The address to be granted the default admin role.
_upgrader address The address to be granted the upgrader role.

delegateNode

function delegateNode(address delegatee) public virtual

Delegate a node to another address.

This function allows a node owner to delegate their node to another address.

Parameters

Name Type Description
delegatee address The address to delegate the node to.

removeNodeDelegation

function removeNodeDelegation() public virtual

Remove the delegation of a node.

This function allows a node owner to remove the delegation of their node, effectively revoking the delegatee’s access to the node.

setVechainNodesContract

function setVechainNodesContract(address vechainNodesContract) external

Set the address of the VeChain Nodes contract.

This function allows the admin to update the address of the VeChain Nodes contract.

Parameters

Name Type Description
vechainNodesContract address The new address of the VeChain Nodes contract.

getNodeManager

function getNodeManager(uint256 nodeId) public view returns (address)

Retrieves the address of the user managing the node ID endorsement either through ownership or delegation.

If the node is delegated, this function returns the delegatee’s address. If the node is not delegated, it returns the owner’s address.

Parameters

Name Type Description
nodeId uint256 The ID of the node for which the manager address is being retrieved.

Return Values

Name Type Description
[0] address The address of the manager of the specified node.

getNodeIds

function getNodeIds(address user) public view returns (uint256[])

Retrieve the node IDs associated with a user, either through direct ownership or delegation.

Parameters

Name Type Description
user address The address of the user to check.

Return Values

Name Type Description
[0] uint256[] uint256[] The node IDs associated with the user.

isNodeManager

function isNodeManager(address user, uint256 nodeId) public view virtual returns (bool)

Check if a user is holding a specific node ID either directly or through delegation.

Parameters

Name Type Description
user address The address of the user to check.
nodeId uint256 The node ID to check for.

Return Values

Name Type Description
[0] bool bool True if the user is holding the node ID and it is a valid node.

isNodeDelegated

function isNodeDelegated(uint256 nodeId) public view returns (bool)

Check if a node is delegated.

Parameters

Name Type Description
nodeId uint256 The node ID to check for.

Return Values

Name Type Description
[0] bool bool True if the node is delegated.

isNodeDelegator

function isNodeDelegator(address user) public view returns (bool)

Check if a user is a delegator.

Parameters

Name Type Description
user address The address of the user to check.

Return Values

Name Type Description
[0] bool bool True if the user is a delegator.

isNodeHolder

function isNodeHolder(address user) public view returns (bool)

Check if a user is a node holder (either directly or through delegation).

Parameters

Name Type Description
user address The address of the user to check.

Return Values

Name Type Description
[0] bool bool True if the user is a node holder.

getUserNodes

function getUserNodes(address user) public view returns (struct NodeManagement.NodeInfo[])

Retrieves detailed information about all of a user’s nodes, including owned and delegated nodes.

Parameters

Name Type Description
user address The address of the user to check.

Return Values

Name Type Description
[0] struct NodeManagement.NodeInfo[] NodeInfo[] Array of node information structures.

getNodeLevel

function getNodeLevel(uint256 nodeId) public view returns (enum VechainNodesDataTypes.NodeStrengthLevel)

Retrieves the node level of a given node ID.

Internal function to get the node level of a token ID. The node level is determined based on the metadata associated with the token ID.

Parameters

Name Type Description
nodeId uint256 The token ID of the endorsing node.

Return Values

Name Type Description
[0] enum VechainNodesDataTypes.NodeStrengthLevel The node level of the specified token ID as a VechainNodesDataTypes.NodeStrengthLevel enum.

getUsersNodeLevels

function getUsersNodeLevels(address user) public view returns (enum VechainNodesDataTypes.NodeStrengthLevel[])

Retrieves the node levels of a user’s managed nodes.

This function retrieves the node levels of the nodes managed by the specified user, either through ownership or delegation.

Parameters

Name Type Description
user address The address of the user managing the nodes.

Return Values

Name Type Description
[0] enum VechainNodesDataTypes.NodeStrengthLevel[] VechainNodesDataTypes.NodeStrengthLevel[] The node levels of the nodes managed by the user.

getDirectNodeOwnership

function getDirectNodeOwnership(address user) public view returns (uint256)

Check if a user directly owns a node (not delegated).

Parameters

Name Type Description
user address The address of the user to check.

Return Values

Name Type Description
[0] uint256 uint256 The ID of the owned node (0 if none).

getVechainNodesContract

function getVechainNodesContract() external view returns (contract ITokenAuction)

Returns the Vechain node contract instance.

Return Values

Name Type Description
[0] contract ITokenAuction ITokenAuction The instance of the Vechain node contract.

version

function version() external pure virtual returns (string)

Retrieves the current version of the contract.

Return Values

Name Type Description
[0] string string The current version of the contract.

_appendToArray

function _appendToArray(uint256[] array, uint256 element) internal pure returns (uint256[])

Appends an element to an array.

Internal function to append an element to an array.

Parameters

Name Type Description
array uint256[] The array to append to.
element uint256 The element to append.

Return Values

Name Type Description
[0] uint256[] uint256[] The new array with the appended element.

_authorizeUpgrade

function _authorizeUpgrade(address newImplementation) internal virtual

Authorize the upgrade to a new implementation.

Internal function to authorize the upgrade to a new contract implementation. This function is restricted to addresses with the upgrader role.

Parameters

Name Type Description
newImplementation address The address of the new contract implementation.