Vaultinator Technical Details

The Vaultinator Facet is the core component of the Vaultinator Protocol that provides vault management functionality. This document outlines the technical implementation details, including the contract architecture, function specifications, storage layout, and security considerations.

Contract Architecture

The Vaultinator Facet follows the Diamond Standard (EIP-2535) pattern and is implemented as the primary facet of the Vaultinator Diamond. It manages vaults, assets, and access control for the entire protocol.

Class Diagram

┌─────────────────┐      ┌───────────────────┐      ┌───────────────────┐
│  VaultinatorFacet│─────►│  YieldinatorFacet │─────►│  CollatinatorFacet│
└─────────────────┘      └───────────────────┘      └───────────────────┘
         │                         ▲                          ▲
         │                         │                          │
         ▼                         │                          │
┌─────────────────┐      ┌───────────────────┐      ┌───────────────────┐
│  DiamondStorage  │─────►│StakinatorFacet    │      │  DiamondCutFacet  │
└─────────────────┘      └───────────────────┘      └───────────────────┘
         │                                                    ▲
         │                                                    │
         ▼                                                    │
┌─────────────────┐                                  ┌───────────────────┐
│VaultinatorStorage│                                  │DiamondLoupeFacet  │
└─────────────────┘                                  └───────────────────┘

Component Interaction

  1. Vaultinator Facet: The main contract that implements the vault management functionality

  2. Diamond Storage: The storage pattern used by the Diamond Standard

  3. Vaultinator Storage: The specific storage layout for the Vaultinator Facet

  4. Diamond Cut Facet: The facet that handles adding, replacing, and removing facets

  5. Diamond Loupe Facet: The facet that provides introspection functions for the diamond

Function Specifications

Vault Management

Creates a new vault.

  • Parameters:

    • name: The name of the vault

    • vaultType: The type of the vault (PERSONAL, MULTISIG, or DAO)

  • Returns: The ID of the created vault

  • Access Control: Anyone can call this function

  • Events Emitted: VaultCreated(uint256 indexed vaultId, address indexed owner, string name, VaultType vaultType)

Renames an existing vault.

  • Parameters:

    • vaultId: The ID of the vault

    • newName: The new name of the vault

  • Returns: bool indicating success

  • Access Control: Only the vault owner can call this function

  • Events Emitted: VaultRenamed(uint256 indexed vaultId, string newName)

Gets information about a vault.

  • Parameters:

    • vaultId: The ID of the vault

  • Returns: A Vault struct containing information about the vault

  • Access Control: Anyone can call this function

Gets a list of all vault IDs for a user.

  • Parameters:

    • user: The address of the user

  • Returns: An array of vault IDs

  • Access Control: Anyone can call this function

Asset Management

Deposits assets into a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • asset: The address of the asset to deposit

    • amount: The amount of the asset to deposit

  • Returns: bool indicating success

  • Access Control: Only the vault owner or authorized users can call this function

  • Events Emitted: Deposited(uint256 indexed vaultId, address indexed asset, uint256 amount)

Withdraws assets from a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • asset: The address of the asset to withdraw

    • amount: The amount of the asset to withdraw

  • Returns: bool indicating success

  • Access Control: Only the vault owner or authorized users can call this function

  • Events Emitted: Withdrawn(uint256 indexed vaultId, address indexed asset, uint256 amount)

Gets a list of all assets in a vault.

  • Parameters:

    • vaultId: The ID of the vault

  • Returns: An array of asset addresses

  • Access Control: Anyone can call this function

Gets the balance of an asset in a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • asset: The address of the asset

  • Returns: The balance of the asset

  • Access Control: Anyone can call this function

Access Control

Adds an authorized user to a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • user: The address of the user to authorize

    • role: The role to assign to the user

  • Returns: bool indicating success

  • Access Control: Only the vault owner can call this function

  • Events Emitted: AuthorizedUserAdded(uint256 indexed vaultId, address indexed user, bytes32 role)

Removes an authorized user from a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • user: The address of the user to remove

  • Returns: bool indicating success

  • Access Control: Only the vault owner can call this function

  • Events Emitted: AuthorizedUserRemoved(uint256 indexed vaultId, address indexed user)

Checks if a user is authorized for a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • user: The address of the user

  • Returns: bool indicating if the user is authorized

  • Access Control: Anyone can call this function

Gets the role of a user for a vault.

  • Parameters:

    • vaultId: The ID of the vault

    • user: The address of the user

  • Returns: The role of the user

  • Access Control: Anyone can call this function

Protocol Administration

Adds an administrator to the protocol.

  • Parameters:

    • admin: The address of the administrator to add

  • Returns: bool indicating success

  • Access Control: Only the contract owner can call this function

  • Events Emitted: AdminAdded(address indexed admin)

Removes an administrator from the protocol.

  • Parameters:

    • admin: The address of the administrator to remove

  • Returns: bool indicating success

  • Access Control: Only the contract owner can call this function

  • Events Emitted: AdminRemoved(address indexed admin)

Checks if an address is an administrator.

  • Parameters:

    • admin: The address to check

  • Returns: bool indicating if the address is an administrator

  • Access Control: Anyone can call this function

Pauses all protocol operations.

  • Returns: bool indicating success

  • Access Control: Only administrators can call this function

  • Events Emitted: ProtocolPaused(address indexed admin)

Unpauses all protocol operations.

  • Returns: bool indicating success

  • Access Control: Only administrators can call this function

  • Events Emitted: ProtocolUnpaused(address indexed admin)

Facet Management

Adds a new facet to the diamond.

  • Parameters:

    • facet: The address of the facet to add

    • functionSelectors: The function selectors to add

  • Returns: bool indicating success

  • Access Control: Only the contract owner can call this function

  • Events Emitted: FacetAdded(address indexed facet, bytes4[] functionSelectors)

Replaces an existing facet in the diamond.

  • Parameters:

    • facet: The address of the new facet

    • functionSelectors: The function selectors to replace

  • Returns: bool indicating success

  • Access Control: Only the contract owner can call this function

  • Events Emitted: FacetReplaced(address indexed facet, bytes4[] functionSelectors)

Removes a facet from the diamond.

  • Parameters:

    • functionSelectors: The function selectors to remove

  • Returns: bool indicating success

  • Access Control: Only the contract owner can call this function

  • Events Emitted: FacetRemoved(bytes4[] functionSelectors)

Storage Layout

The Vaultinator Facet uses the Diamond Storage pattern to store its state. The storage layout is defined in the LibVaultinatorStorage library.

Events

The Vaultinator Facet emits the following events:

Security Considerations

Reentrancy Protection

The Vaultinator Facet uses a reentrancy guard to prevent reentrancy attacks. All external functions that interact with other contracts are protected by the reentrancy guard.

Access Control

The Vaultinator Facet uses role-based access control to restrict access to certain functions. The access control is implemented through the vaultUserRoles mapping and the admins mapping.

Pause Mechanism

The Vaultinator Facet includes a pause mechanism that allows administrators to pause all operations in case of an emergency.

Ownership Transfer

The Vaultinator Facet includes a secure ownership transfer mechanism to prevent accidental transfers.

Vault Ownership Transfer

The Vaultinator Facet includes a secure vault ownership transfer mechanism.

Integration with Other Facets

The Vaultinator Facet is the core facet of the protocol and integrates with all other facets:

  1. Yieldinator Facet: For yield generation

  2. Collatinator Facet: For collateralized lending

  3. Stakinator Facet: For staking

Yieldinator Integration

Collatinator Integration

Stakinator Integration

Multi-Chain Support

The Vaultinator Facet includes support for cross-chain vault management, allowing users to manage assets across multiple blockchains.

Cross-Chain Vault Creation

Cross-Chain Asset Transfer

Vault Types

The Vaultinator Facet supports multiple vault types:

Personal Vault

Personal vaults are owned by a single user and can be managed by that user and any authorized users.

Multisig Vault

Multisig vaults require multiple signatures to perform certain operations.

DAO Vault

DAO vaults are governed by token holders and use a voting mechanism for decision-making.

Conclusion

The Vaultinator Facet is the core component of the Vaultinator Protocol that enables users to create and manage vaults for their assets. Its modular design, security features, and integration with other facets make it a flexible and robust solution for asset management.