The Collatinator Facet is a core component of the Vaultinator Protocol that provides collateralized lending functionality. This document outlines the technical implementation details, including the contract architecture, function specifications, storage layout, and security considerations.
Contract Architecture
The Collatinator Facet follows the Diamond Standard (EIP-2535) pattern and is implemented as a facet that can be added to the Vaultinator Diamond. It interacts with various lending protocols through a standardized adapter pattern.
The Collatinator Facet uses the Diamond Storage pattern to store its state. The storage layout is defined in the LibCollatinatorStorage library.
Events
The Collatinator Facet emits the following events:
Security Considerations
Reentrancy Protection
The Collatinator 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 Collatinator Facet uses role-based access control to restrict access to certain functions. The access control is implemented through the Vaultinator Facet.
Pause Mechanism
The Collatinator Facet includes a pause mechanism that allows administrators to pause all operations in case of an emergency.
Health Factor Monitoring
The Collatinator Facet includes health factor monitoring to prevent liquidations. When a position's health factor drops below a certain threshold, the contract can take action to prevent liquidation.
Slippage Protection
The Collatinator Facet includes slippage protection for token exchanges. When creating or modifying positions, users can specify a minimum amount to receive or a maximum amount to pay.
Emergency Repayment
The Collatinator Facet includes an emergency repayment function that allows users to repay their debt in case of an emergency, bypassing some of the normal checks.
Integration with Other Facets
The Collatinator Facet integrates with other facets in the Vaultinator Protocol:
Vaultinator Facet: For vault management and access control
Yieldinator Facet: For using yield-generating assets as collateral
Stakinator Facet: For staking collateral assets
Vaultinator Integration
Yieldinator Integration
Stakinator Integration
Multi-Chain Support
The Collatinator Facet includes support for cross-chain collateral management, allowing users to create positions that span multiple blockchains.
Cross-Chain Position Creation
Cross-Chain Collateral Management
Cross-Chain Debt Management
Supported Lending Protocols
The Collatinator Facet supports multiple lending protocols through its adapter pattern:
Aave: Liquidity protocol for lending and borrowing
Compound: Algorithmic money market protocol
Euler Finance: Permissionless lending protocol
Benqi: Liquidity market protocol on Avalanche
Solend: Lending protocol on Solana
Each protocol has its own adapter that implements the ILendingAdapter interface, providing a consistent API for interacting with different protocols.
Conclusion
The Collatinator Facet is a powerful component of the Vaultinator Protocol that enables users to create and manage collateralized positions across multiple lending protocols. Its modular design, security features, and integration with other facets make it a flexible and robust solution for collateralized lending.
function emergencyRepay(uint256 positionId) external nonReentrant onlyPositionOwner(positionId) returns (bool) {
// Implementation details...
// This function bypasses the pause check and some other checks
// More implementation details...
emit EmergencyRepaid(positionId);
return true;
}
function createPositionFromVault(
uint256 vaultId,
address protocol,
address collateralAsset,
uint256 collateralAmount,
address debtAsset,
uint256 debtAmount
) external nonReentrant whenNotPaused onlyVaultOwner(vaultId) returns (uint256) {
// Implementation details...
// Transfer assets from vault to this contract
// Create position
// Update vault balance
// More implementation details...
emit VaultPositionCreated(vaultId, positionId, protocol, collateralAsset, collateralAmount, debtAsset, debtAmount);
return positionId;
}
function createPositionWithYield(
address protocol,
address yieldAdapter,
address collateralAsset,
uint256 collateralAmount,
address debtAsset,
uint256 debtAmount
) external nonReentrant whenNotPaused returns (uint256) {
// Implementation details...
// Deposit collateral to yield adapter
// Use yield-generating asset as collateral
// Create position
// More implementation details...
return positionId;
}
function createPositionWithStaking(
address protocol,
address stakingPool,
address collateralAsset,
uint256 collateralAmount,
address debtAsset,
uint256 debtAmount
) external nonReentrant whenNotPaused returns (uint256) {
// Implementation details...
// Stake collateral
// Use staked asset as collateral
// Create position
// More implementation details...
return positionId;
}
function createCrossChainPosition(
uint256 sourceChainId,
uint256 targetChainId,
address protocol,
address collateralAsset,
uint256 collateralAmount,
address debtAsset,
uint256 debtAmount
) external nonReentrant whenNotPaused returns (uint256) {
// Implementation details...
// Bridge collateral to target chain
// Create position on target chain
// More implementation details...
return positionId;
}
function addCrossChainCollateral(
uint256 positionId,
uint256 sourceChainId,
uint256 targetChainId,
uint256 amount
) external nonReentrant whenNotPaused onlyPositionOwner(positionId) returns (bool) {
// Implementation details...
// Bridge collateral to target chain
// Add collateral to position on target chain
// More implementation details...
return true;
}