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() public
bytes32 UPGRADER_ROLE
struct NodeInfo {
uint256 nodeId;
enum VechainNodesDataTypes.NodeStrengthLevel nodeLevel;
address xNodeOwner;
bool isXNodeHolder;
bool isXNodeDelegated;
bool isXNodeDelegator;
bool isXNodeDelegatee;
address delegatee;
}
struct NodeManagementStorage {
contract ITokenAuction vechainNodesContract;
mapping(address => struct EnumerableSet.UintSet) delegateeToNodeIds;
mapping(uint256 => address) nodeIdToDelegatee;
}
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.
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.
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. |
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.
Name | Type | Description |
---|---|---|
delegatee | address | The address to delegate the node to. |
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.
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.
Name | Type | Description |
---|---|---|
vechainNodesContract | address | The new address of the VeChain Nodes contract. |
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.
Name | Type | Description |
---|---|---|
nodeId | uint256 | The ID of the node for which the manager address is being retrieved. |
Name | Type | Description |
---|---|---|
[0] | address | The address of the manager of the specified node. |
function getNodeIds(address user) public view returns (uint256[])
Retrieve the node IDs associated with a user, either through direct ownership or delegation.
Name | Type | Description |
---|---|---|
user | address | The address of the user to check. |
Name | Type | Description |
---|---|---|
[0] | uint256[] | uint256[] The node IDs associated with the user. |
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.
Name | Type | Description |
---|---|---|
user | address | The address of the user to check. |
nodeId | uint256 | The node ID to check for. |
Name | Type | Description |
---|---|---|
[0] | bool | bool True if the user is holding the node ID and it is a valid node. |
function isNodeDelegated(uint256 nodeId) public view returns (bool)
Check if a node is delegated.
Name | Type | Description |
---|---|---|
nodeId | uint256 | The node ID to check for. |
Name | Type | Description |
---|---|---|
[0] | bool | bool True if the node is delegated. |
function isNodeDelegator(address user) public view returns (bool)
Check if a user is a delegator.
Name | Type | Description |
---|---|---|
user | address | The address of the user to check. |
Name | Type | Description |
---|---|---|
[0] | bool | bool True if the user is a delegator. |
function isNodeHolder(address user) public view returns (bool)
Check if a user is a node holder (either directly or through delegation).
Name | Type | Description |
---|---|---|
user | address | The address of the user to check. |
Name | Type | Description |
---|---|---|
[0] | bool | bool True if the user is a node holder. |
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.
Name | Type | Description |
---|---|---|
user | address | The address of the user to check. |
Name | Type | Description |
---|---|---|
[0] | struct NodeManagement.NodeInfo[] | NodeInfo[] Array of node information structures. |
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.
Name | Type | Description |
---|---|---|
nodeId | uint256 | The token ID of the endorsing node. |
Name | Type | Description |
---|---|---|
[0] | enum VechainNodesDataTypes.NodeStrengthLevel | The node level of the specified token ID as a VechainNodesDataTypes.NodeStrengthLevel enum. |
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.
Name | Type | Description |
---|---|---|
user | address | The address of the user managing the nodes. |
Name | Type | Description |
---|---|---|
[0] | enum VechainNodesDataTypes.NodeStrengthLevel[] | VechainNodesDataTypes.NodeStrengthLevel[] The node levels of the nodes managed by the user. |
function getDirectNodeOwnership(address user) public view returns (uint256)
Check if a user directly owns a node (not delegated).
Name | Type | Description |
---|---|---|
user | address | The address of the user to check. |
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 The ID of the owned node (0 if none). |
function getVechainNodesContract() external view returns (contract ITokenAuction)
Returns the Vechain node contract instance.
Name | Type | Description |
---|---|---|
[0] | contract ITokenAuction | ITokenAuction The instance of the Vechain node contract. |
function version() external pure virtual returns (string)
Retrieves the current version of the contract.
Name | Type | Description |
---|---|---|
[0] | string | string The current version of the contract. |
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.
Name | Type | Description |
---|---|---|
array | uint256[] | The array to append to. |
element | uint256 | The element to append. |
Name | Type | Description |
---|---|---|
[0] | uint256[] | uint256[] The new array with the appended element. |
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.
Name | Type | Description |
---|---|---|
newImplementation | address | The address of the new contract implementation. |