UTokenVault

UTokenVault.sol is a core contract that manages the reserves and handles deposits, withdrawals, borrowing, and repaying of assets within the Unlockd Protocol.

Key functions:

function createMarket(
    IUTokenVault.CreateMarketParams calldata params
) external onlyAdmin 

Creates a new market for a specific underlying asset.

Parameters:

params: The parameters for creating the market.


function deposit(
    address underlyingAsset, 
    uint256 amount, 
    address onBehalfOf
) external

Deposits assets into the specified market.

Parameters:

underlyingAsset: The address of the underlying asset.

amount: The amount to deposit.

onBehalfOf: The address of the user to deposit on behalf of.


function withdraw(
    address underlyingAsset, 
    uint256 amount, 
    address to
) external

Withdraws assets from the specified market.

Parameters:

underlyingAsset: The address of the underlying asset.

amount: The amount to withdraw.

to: The address to withdraw the assets to.


function borrow(
    address underlyingAsset,
    bytes32 loanId,
    uint256 amount,
    address to,
    address onBehalfOf
) external onlyProtocol

Borrows assets from the specified market.

Parameters:

underlyingAsset: The address of the underlying asset.

loanId: The ID of the loan associated with the borrow.

amount: The amount to borrow.

to: The address to transfer the borrowed assets to.

onBehalfOf: The address of the user borrowing on behalf of.


function repay(
    address underlyingAsset,
    bytes32 loanId,
    uint256 amount,
    address from,
    address onBehalfOf
) external onlyProtocol

Repays a borrowed amount to the specified market.

Parameters:

underlyingAsset: The address of the underlying asset.

loanId: The ID of the loan to repay.

amount: The amount to repay.

from: The address to transfer the repayment from.

onBehalfOf: The address of the user repaying on behalf of.


function updateState(address underlyingAsset) external

This function updates the state of a reserve for a given underlying asset. It calculates the current liquidity and variable borrow rates based on the reserve's configuration and the market's supply and borrow balances. It also updates the reserve's indexes and performs any necessary actions based on the reserve's strategy.

Parameters:

underlyingAsset: The address of the underlying asset to update the state for.


function setActive(
    address underlyingAsset, 
    bool isActive
) external onlyEmergencyAdmin

This function allows an emergency admin to set the active state of a reserve for a given underlying asset. When a reserve is active, it allows deposits, withdrawals, borrowing, and repaying. When it is inactive, these actions are disabled.

Parameters:

underlyingAsset: The address of the underlying asset.

isActive: A boolean indicating whether to set the reserve as active or not.


function setFrozen(
    address underlyingAsset, 
    bool isFrozen
) external onlyEmergencyAdmin 

This function allows an emergency admin to set the frozen state of a reserve for a given underlying asset. When a reserve is frozen, it disables deposits, withdrawals, borrowing, and repaying, effectively halting all actions related to that reserve.

Parameters:

underlyingAsset: The address of the underlying asset.

isFrozen: A boolean indicating whether to set the reserve as frozen or not.


function setPaused(
    address underlyingAsset, 
    bool isPaused
) external onlyEmergencyAdmin

This function allows an emergency admin to set the paused state of a reserve for a given underlying asset. When a reserve is paused, it temporarily disables deposits, withdrawals, borrowing, and repaying, similar to the frozen state. However, the paused state is typically used for temporary maintenance or upgrades.

Parameters:

underlyingAsset: The address of the underlying asset.

isPaused: A boolean indicating whether to set the reserve as paused or not.


function setCaps(
    address underlyingAsset,
    uint256 minCap,
    uint256 depositCap,
    uint256 borrowCap
) external onlyEmergencyAdmin 

This function allows an emergency admin to set the caps for a reserve. The caps include the minimum cap, deposit cap, and borrow cap. These caps are used to limit the maximum amounts that can be deposited or borrowed from the reserve, helping to manage risk and maintain stability.

Parameters:

underlyingAsset: The address of the underlying asset.

minCap: The minimum cap for the reserve.

depositCap: The deposit cap for the reserve.

borrowCap: The borrow cap for the reserve.


function disableStrategy(
    address underlyingAsset
) external onlyEmergencyAdmin

This function allows an emergency admin to disable the strategy associated with a reserve. When a strategy is disabled, the reserve will no longer invest or withdraw funds from the strategy, and all assets will remain in the reserve.

Parameters:

underlyingAsset: The address of the underlying asset.


function updateReserveStrategy(
    address underlyingAsset,
    address newStrategy
) external onlyEmergencyAdmin 

This function allows an emergency admin to update the strategy associated with a reserve. It replaces the current strategy with a new one, allowing for dynamic changes to the investment strategy used by the reserve.

Parameters:

underlyingAsset: The address of the underlying asset.

newStrategy: The address of the new strategy for the reserve.


function validateReserveType(
    Constants.ReserveType currentReserveType,
    Constants.ReserveType reserveType
) external pure returns (bool) 

This function validates the compatibility of reserve types. It checks if the given reserve type is compatible with the current reserve type of a reserve. This is used to ensure that only compatible reserve types are allowed when updating or creating reserves

Parameters:

currentReserveType: The current reserve type.

reserveType: The reserve type to validate against.

Returns:

A boolean indicates whether the reserve types are compatible.


function getReserveData(
    address underlyingAsset
  ) external view returns (DataTypes.ReserveData memory) 

This function retrieves the reserve data for a given underlying asset. It returns a struct containing various information about the reserve, such as the liquidity index, variable borrow index, current rates, and configuration settings.

Parameters:

underlyingAsset: The address of the underlying asset.

Returns:

The reserve data for the given underlying asset.


function getScaledToken(
    address underlyingAsset
) external view returns (address)

This function retrieves the address of the scaled token associated with a given underlying asset. The scaled token represents the share of the underlying asset held by users in the reserve.

Parameters:

underlyingAsset: The address of the underlying asset.

Returns:

The address of the scaled token for the given underlying asset.


function getScaledTotalDebtMarket(
    address underlyingAsset
) external view returns (uint256)

This function retrieves the total scaled debt for a market associated with a given underlying asset. The scaled debt represents the total borrowing in the market, adjusted by the variable borrow index.

Parameters:

underlyingAsset: The address of the underlying asset.

Returns:

The total scaled debt for the market.


function getTotalDebtFromUser(
    address underlyingAsset,
    address user
) external view returns (uint256)

This function retrieves the total debt of a user in a market associated with a given underlying asset. It represents the user's total borrowing amount in the market.

Parameters:

underlyingAsset: The address of the underlying asset.

user: The address of the user.

Returns:

The total debt of the user in the market.


function getScaledTotalDebtFromUser(
    address underlyingAsset,
    address user
) external view returns (uint256)

This function retrieves the total scaled debt of a user in a market associated with a given underlying asset. The scaled debt represents the user's total borrowing amount, adjusted by the variable borrow index.

Parameters:

underlyingAsset: The address of the underlying asset.

user: The address of the user.

Returns:

The total scaled debt of the user in the market.


function getDebtFromLoanId(
    address underlyingAsset,
    bytes32 loanId
) external view returns (uint256) 

This function retrieves the debt associated with a specific loan ID in a market for a given underlying asset. It represents the borrowing amount tied to a particular loan.

Parameters:

underlyingAsset: The address of the underlying asset.

loanId: The ID of the loan.

Returns:

The debt associated with the loan ID in the market.


function getScaledDebtFromLoanId(
    address underlyingAsset,
    bytes32 loanId
) external view returns (uint256)

This function retrieves the scaled debt associated with a specific loan ID in a market for a given underlying asset. The scaled debt represents the borrowing amount tied to a particular loan, adjusted by the variable borrow index.

Parameters:

underlyingAsset: The address of the underlying asset.

loanId: The ID of the loan.

Returns:

The scaled debt associated with the loan ID in the market.


function getBalances(
    address underlyingAsset
) external view returns (DataTypes.MarketBalance memory) 

This function retrieves the balances for a given underlying asset in a market. It returns a struct containing information such as the total supply, total borrow, and last update timestamp.

Parameters:

underlyingAsset: The address of the underlying asset.

Returns:

The balances for the given underlying asset.


function getBalanceByUser(
    address underlyingAsset, 
    address user
) external view returns (uint256) 

This function retrieves the balance of a user in a market for a given underlying asset. It represents the user's supply balance in the market.

Parameters:

underlyingAsset: The address of the underlying asset.

user: The address of the user.

Returns:

The balance of the user in the market.


function getScaledBalanceByUser(
    address underlyingAsset,
    address user
) external view returns (uint256) 

This function retrieves the scaled balance of a user in a market for a given underlying asset. The scaled balance represents the user's supply balance, adjusted by the liquidity index.

Parameters:

underlyingAsset: The address of the underlying asset.

user: The address of the user.

Returns:

The scaled balance of the user in the market.


function totalSupply(
    address underlyingAsset
) external view returns (uint256)

This function retrieves the total supply of a market for a given underlying asset. It represents the total amount of the underlying asset supplied by users to the market.

Parameters:

underlyingAsset: The address of the underlying asset.

Returns:

The total supply of the market.


function totalAvailableSupply(
    address underlyingAsset
) external view returns (uint256) 

This function retrieves the total available supply of a market for a given underlying asset. It represents the total amount of the underlying asset that is available for borrowing or withdrawal, taking into account any assets invested in strategies.

Parameters:

underlyingAsset: The address of the underlying asset.

Returns:

The total available supply of the market.


function totalSupplyNotInvested(
    address underlyingAsset
) external view returns (uint256) 

This function retrieves the total supply not invested in strategies for a market associated with a given underlying asset. It represents the portion of the total supply that is not currently invested and is available for immediate use.

Parameters:

underlyingAsset: The address of the underlying asset.

Returns:

The total supply not invested in the market.

Last updated