VToken
Overview
The VToken contract is a custom lending token contract based on the ERC4626 standard. It wraps around an ERC20 token and extends functionalities to enable lending/borrowing with interest accrual, fees, and risk management.
It is designed to be composable, modular, and DeFi protocol-compatible, including roles like accountManager, interest rateModel, and integrations through a central Registry.
Initialization
Signature:
function init(
ERC20 _asset,
string calldata _name,
string calldata _symbol,
IRegistry _registry,
uint _originationFee,
address _treasury,
uint _reserveShares,
uint _maxSupply
) externalParameters:
_asset
ERC20
Address of the underlying token being lent (e.g. USDC, DAI).
_name
string
Human-readable name for the VToken (e.g. "vUSDC").
_symbol
string
Token symbol for the VToken (e.g. "vUSDC").
_registry
IRegistry
Contract used for resolving other system components like rate models.
_originationFee
uint
Fee (in 18 decimals) charged when a user borrows.
_treasury
address
Address where fees are sent.
_reserveShares
uint
Shares minted to address(0) to control utilization curve.
_maxSupply
uint
Cap on the maximum shares that can be minted.
Signature:
Parameters:
_rateModel
string
Identifier for the interest rate model contract inside the Registry.
Deposit
Function Signature:
Parameters:
assets
uint256
The amount of the underlying asset to deposit into the vault.
receiver
address
The address to receive the minted vault shares.
Returns:
shares
uint256
Amount of vault shares minted to the receiver.
Description:
Deposits a specified amount of asset into the vault, and mints corresponding shares to the receiver. This function updates the interest rate model and internal accounting through beforeDeposit().
Withdraw
Function Signature:
Parameters:
assets
uint256
Amount of the underlying asset to withdraw from the vault.
receiver
address
Address that will receive the withdrawn asset.
owner
address
Address whose shares will be burned. If msg.sender != owner, allowance must be given.
Returns:
shares
uint256
Amount of shares burned to withdraw the requested assets.
Description:
Burns enough shares from owner to withdraw assets to receiver. Internal accounting and interest model are updated through beforeWithdraw().
Lending and Borrowing
Signature:
Parameters:
account
address
Address of the borrower.
amt
uint
Amount of tokens to lend.
Returns:
isFirstBorrow - true if the user is borrowing for the first time (no borrow shares before).
Signature:
Parameters:
account
address
Address of the borrower.
amt
uint
Amount to collect from the borrower (in underlying asset).
Returns:
true if borrower has no debt left after collection.
Signature:
Parameters:
account
address
Borrower address.
Returns: Amount of underlying tokens the user owes.
View Functions
Signature:
Returns: Total assets managed by the vault = underlying balance + borrows + accrued interest.
Signature:
Returns: Total amount borrowed including interest accrued since the last update.
Signature:
Returns:
Rate factor calculated based on timestamp delta * interest rate per second.
Signature:
Parameters:
amt
uint
Amount in underlying token.
Returns: Equivalent amount in borrow shares.
Signature:
Parameters:
debt
uint
Amount in borrow shares.
Returns: Equivalent amount in underlying tokens.
Lifecycle Hooks
Purpose: Updates interest state before a deposit.
Purpose: Updates interest state before a withdrawal.
State Management
Signature:
Description:
Accrues interest since the last update and updates borrows and lastUpdated.
Admin Functions
Signature:
Parameters:
_originationFee
uint
New origination fee (scaled to 18 decimals).
Signature:
Parameters:
_maxSupply
uint
New maximum total share supply.
Last updated