Skip to main content

VaultErrorController

The VaultErrorController is a utility contract that manages error messages for the Vault contract. It provides a way to associate error codes with human-readable error messages, improving the user experience when transactions fail.

Contract Overview

The VaultErrorController handles:
  • Storing error messages for specific error codes
  • Providing a centralized place for error message management
  • Allowing for error message updates without modifying the main Vault code
The VaultErrorController is primarily an administrative contract that helps with developer and user experience, rather than core protocol functionality.

Key Functions

Error Management

Sets error messages for multiple error codes at once.
Returns the error message for a specific error code.

Purpose and Benefits

The VaultErrorController serves several important purposes:
  1. Improved Developer Experience: By using error codes in the Vault with corresponding human-readable messages, debugging becomes easier
  2. Gas Efficiency: The Vault can use compact error codes rather than storing long error strings
  3. Upgradability: Error messages can be updated without changing the core Vault contract
  4. Standardization: Creates a consistent error reporting system across the protocol

Integration with Vault

The Vault contract interacts with the VaultErrorController when errors occur:
This pattern allows the Vault to focus on its core logic while delegating error message management to the VaultErrorController.

Error Code Pattern

The protocol uses a standardized error code system:
  • Error codes are unsigned integers, typically starting from 1
  • Each error code corresponds to a specific error condition
  • Error messages are human-readable strings that explain the error
For example:
  • Error code 1: “Vault: invalid _amount”
  • Error code 2: “Vault: token not whitelisted”
  • Error code 3: “Vault: _collateralToken not whitelisted”

Administrative Control

Only the contract owner (typically the governance) can update error messages:
This ensures that error messages remain consistent and accurate.

Example Usage

1

Setting Error Messages

The governance wants to set up error messages for the Vault.
2

Vault Using Error Messages

The Vault contract uses error codes when validating operations.
3

Updating Error Messages

Later, the governance decides to update some error messages for clarity.

Security Considerations

The VaultErrorController has minimal security implications since it only manages error messages and doesn’t affect the core functionality of the protocol. However, there are still a few considerations:
  • Access Control: Only the owner should be able to update error messages
  • Message Consistency: Error messages should accurately reflect the corresponding error conditions
  • Gas Efficiency: Error messages should be concise to minimize gas costs when they’re used
While error messages don’t affect the security of the protocol directly, accurate and clear error messages are important for usability and can help prevent user mistakes.