Vaultinator Facet Integration Guide

This guide provides developers with the information needed to integrate with the Vaultinator Facet, the core component of the Vaultinator Protocol. It covers the basic interaction patterns, contract interfaces, and best practices for building applications that leverage vault functionality.

Interface Overview

The Vaultinator Facet exposes a comprehensive set of functions through the IVaultinatorFacet interface:

interface IVaultinatorFacet {
    // Vault management
    function createVault(string calldata name, VaultType vaultType) external returns (uint256 vaultId);
    function deposit(uint256 vaultId, address asset, uint256 amount) external returns (bool);
    function withdraw(uint256 vaultId, address asset, uint256 amount) external returns (bool);
    function transferBetweenVaults(uint256 fromVaultId, uint256 toVaultId, address asset, uint256 amount) external returns (bool);
    
    // Access control
    function grantAccess(uint256 vaultId, address user, bytes32 role) external returns (bool);
    function revokeAccess(uint256 vaultId, address user, bytes32 role) external returns (bool);
    function hasRole(uint256 vaultId, address user, bytes32 role) external view returns (bool);
    
    // Vault configuration
    function updateVaultConfig(uint256 vaultId, bytes calldata configData) external returns (bool);
    function setVaultStrategy(uint256 vaultId, address strategy) external returns (bool);
    function getVaultConfig(uint256 vaultId) external view returns (VaultConfig memory);
    
    // Protocol administration
    function updateProtocolParams(bytes calldata paramsData) external returns (bool);
    function setProtocolFee(uint256 feePercentage) external returns (bool);
    function pauseProtocol() external returns (bool);
    function unpauseProtocol() external returns (bool);
    
    // View functions
    function getVault(uint256 vaultId) external view returns (VaultInfo memory);
    function getUserVaults(address user) external view returns (uint256[] memory);
    function getVaultAssets(uint256 vaultId) external view returns (AssetInfo[] memory);
    function getVaultBalance(uint256 vaultId, address asset) external view returns (uint256);
}

Basic Integration Pattern

To integrate with the Vaultinator Facet, you'll need to:

  1. Import the appropriate interface

  2. Create a contract instance using the Diamond address

  3. Call functions on the facet through the Diamond

Example in Solidity

Example in JavaScript (ethers.js)

Common Integration Scenarios

1. Creating and Managing Vaults

2. Managing Vault Assets

3. Managing Vault Access

4. Integrating with Other Facets

Event Monitoring

The Vaultinator Facet emits events for all significant actions. Monitoring these events is crucial for building responsive applications.

Key Events

Monitoring Example (ethers.js)

Error Handling

The Vaultinator Facet uses descriptive error messages and custom errors. Handle these appropriately in your integration:

Security Best Practices

When integrating with the Vaultinator Facet, follow these security best practices:

  1. Access Control: Implement proper access control in your application to match the vault's access control system

  2. Input Validation: Validate all user inputs before sending transactions

  3. Transaction Monitoring: Monitor transaction status and handle failures gracefully

  4. Error Handling: Implement comprehensive error handling for all interactions

  5. Emergency Handling: Implement procedures for handling protocol emergencies, such as when the protocol is paused

Gas Optimization

When integrating with the Vaultinator Facet, consider these gas optimization techniques:

  1. Batch Operations: Use batch functions where available to reduce the number of transactions

  2. Gas Price Management: Set appropriate gas prices based on network conditions

  3. State Caching: Cache on-chain state in your application to reduce view function calls

  4. Optimistic UI Updates: Update your UI optimistically while waiting for transaction confirmation

Advanced Integration Patterns

1. Vault Strategy Integration

2. Multi-Signature Vault Management

3. Vault Analytics Integration