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
) external
Parameters:
_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:
function initDep(string calldata _rateModel) external
Parameters:
_rateModel
string
Identifier for the interest rate model contract inside the Registry.
Deposit
Function Signature:
function deposit(uint256 assets, address receiver) public override returns (uint256 shares)
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:
function withdraw(uint256 assets, address receiver, address owner) public override returns (uint256 shares)
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:
function lendTo(address account, uint amt) external returns (bool isFirstBorrow)
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:
function collectFrom(address account, uint amt) external returns (bool)
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:
function getBorrowBalance(address account) external view returns (uint)
Parameters:
account
address
Borrower address.
Returns: Amount of underlying tokens the user owes.
View Functions
Signature:
function totalAssets() public view override returns (uint)
Returns: Total assets managed by the vault = underlying balance + borrows + accrued interest.
Signature:
function getBorrows() public view returns (uint)
Returns: Total amount borrowed including interest accrued since the last update.
Signature:
function getRateFactor() internal view returns (uint)
Returns:
Rate factor calculated based on timestamp delta * interest rate per second
.
Signature:
function convertAssetToBorrowShares(uint amt) internal view returns (uint)
Parameters:
amt
uint
Amount in underlying token.
Returns: Equivalent amount in borrow shares.
Signature:
function convertBorrowSharesToAsset(uint debt) internal view returns (uint)
Parameters:
debt
uint
Amount in borrow shares.
Returns: Equivalent amount in underlying tokens.
Lifecycle Hooks
function beforeDeposit(uint, uint) internal override
Purpose: Updates interest state before a deposit.
function beforeWithdraw(uint, uint) internal override
Purpose: Updates interest state before a withdrawal.
State Management
Signature:
function updateState() public
Description:
Accrues interest since the last update and updates borrows
and lastUpdated
.
Admin Functions
Signature:
function updateOriginationFee(uint _originationFee) external
Parameters:
_originationFee
uint
New origination fee (scaled to 18 decimals).
Signature:
function updateMaxSupply(uint _maxSupply) external
Parameters:
_maxSupply
uint
New maximum total share supply.
Last updated