Skip to content

IAssetAdapter Interface

Overview

The IAssetAdapter interface is the core abstraction that enables the RAAC system to work with any type of collateral asset. This interface standardizes how different asset types (ERC20, ERC721, ERC1155, RWA tokens, etc.) interact with the LendingPool, allowing for maximum flexibility and future extensibility.

Purpose

  • Asset Agnostic Design: Allows the LendingPool to work with any collateral type without knowing the specific implementation details
  • Standardized Operations: Provides a consistent interface for deposit, withdrawal, valuation, and transfer operations
  • Flexible Data Encoding: Uses bytes calldata data to handle different asset-specific parameters (amounts, token IDs, etc.)
  • Position Management: Enables unique position identification and tracking across different asset types
  • Validation & Safety: Includes validation methods to ensure data integrity and proper asset handling

Interface Definition

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

/// @title IAsssetAdapter
/// @notice Interface that all asset adapters must implement
interface IAssetAdapter {
    // Core operations
    function deposit(address user, bytes calldata data) external;
    function withdraw(address user, bytes calldata data) external;
    function transferAsset(address user, bytes calldata data, address to) external;

    // Valuation methods
    function getAssetValue(address user, bytes calldata data) external view returns (uint256);
    function getWithdrawValue(address user, bytes calldata data) external view returns (uint256);
    function getTotalAssetValue(address user) external view returns (uint256);

    // Position management
    function getPositionKey(bytes calldata data) external view returns (bytes32 positionKey);
    function getPositionKeys(address user) external view returns (bytes32[] memory keys);

    // Asset information
    function getAssetToken() external view returns (address);
    function getAssetType() external pure returns (string memory);
    function supportsPartialWithdraw() external pure returns (bool);

    // Validation
    function validate(address user, bytes calldata data) external view;
    function validateLiquidationData(address user, bytes calldata data) external view returns(bool);

    // Configuration
    function setPriceOracle(address _oracle) external;
}

Function Reference (Simplified)

Core Operations

Function Use for Inputs Returns / Effects
deposit(address user, bytes data) Deposit collateral into adapter (user, data) Pulls asset from user, updates accounting
withdraw(address user, bytes data) Withdraw collateral back to user (user, data) Transfers asset to user, updates accounting
transferAsset(address user, bytes data, address to) Move collateral (e.g., liquidation) (user, data, to) Reassigns ownership, updates accounting

Valuation

Function Use for Inputs Returns
getAssetValue(address user, bytes data) Get value of a specific position (user, data) uint256 (USD, 18 decimals)
getWithdrawValue(address user, bytes data) Value of assets to withdraw (user, data) uint256
getTotalAssetValue(address user) Total collateral value (user) uint256

Position Management

Function Use for Inputs Returns
getPositionKey(bytes data) Unique key for position (data) bytes32
getPositionKeys(address user) All position keys of user (user) bytes32[]

Asset Info

Function Use for Returns
getAssetToken() Underlying asset contract address
getAssetType() Asset type identifier string
supportsPartialWithdraw() Partial withdrawal supported bool

Validation & Config

Function Use for Inputs Returns / Effects
validate(address user, bytes data) Check data validity (user, data) Reverts if invalid
validateLiquidationData(address user, bytes data) Check liquidation inputs (user, data) bool
setPriceOracle(address _oracle) Update price oracle (_oracle) Owner-only update

Implementation Guidelines

Data Encoding Standards

Different asset types should encode their data consistently:

Asset Type Data Format Example
ERC20 abi.encode(amount) abi.encode(1000e18)
ERC721 abi.encode(tokenId) abi.encode(123)
ERC1155 abi.encode(tokenId, amount) abi.encode(456, 1)

Integration with LendingPool

The IAssetAdapter interface integrates with the LendingPool through:

  1. Registration: Adapters must be registered via registerAdapter()
  2. Validation: All adapter calls are validated before execution
  3. Position Tracking: Position keys are used for mapping user collateral
  4. Health Factor: Asset values feed into health factor calculations
  5. Liquidation: Transfer operations enable collateral seizure

Each implementation should follow the interface specification while handling the specific requirements of their asset type.

Adapter-Specific Helper Interfaces

On top of the base IAssetAdapter, each asset type can optionally expose additional helper methods that are useful outside the core smart contract flow (e.g., for indexers, analytics, or UI). These helpers are not required by the LendingPool but are helpful for discovery and UX.

ERC721 Helper Interface

// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;

/// @title IERC721AssetAdapter
/// @notice Adapter for ERC721 collateral, prices in crvUSD (18 decimals)
/// @dev Only the registered LendingPool may invoke deposit/withdraw
interface IERC721Adapter {

    /// @notice Returns the list of tokenIds deposited by a user
    /// @param user User address
    /// @return tokenIds Array of deposited tokenIds
    function getDepositedTokens(address user) external returns (uint256[] memory tokenIds);

    /// @notice Returns the depositor (owner) of a given tokenId
    /// @param tokenId The NFT tokenId
    /// @return owner Address of the user who deposited this tokenId
    function getDepositor(uint256 tokenId) external returns (address owner);

    /// @notice Return the deposited NFT tokenId for `user` at position `index`
    /// @param user The NFT tokenId
    /// @param index The NFT tokenId
    /// @return tokenId Address of the user who deposited this tokenId
    /// @dev reverts if index ≥ total deposited
    function tokenOfOwnerByIndex(address user, uint256 index) external view returns (uint256 tokenId);
}

ERC20 Helper Interface

/// @notice custom methods belonging to ERC20 Adapter only
interface IERC20Adapter {
    /// @notice Returns the raw asset balance of the user
    /// @param user The address of the user
    function balanceOf(address user) external returns (uint256);
}

These helper interfaces are intended for read-oriented integrations and can be extended per adapter as needed without affecting the core protocol interface.