Vault
The Vault is an ERC4626-compliant vault where lenders deposit the borrowed token (e.g., USDC, WETH) to earn yield from borrower interest. Each lending market has its own isolated vault instance deployed by the LendFactory.
The vault's pricePerShare increases over time as borrowers pay interest. It implements the full ERC20 and ERC4626 interfaces, with additional Curve-specific methods for APR reporting and supply limits.
The vault uses a dead shares mechanism (minting 1000 shares to the zero address on initialization) to protect against ERC4626 inflation attacks.
Vault.vyERC4626 — Deposits and Withdrawals
deposit
Vault.deposit(_assets: uint256, _receiver: address) -> uint256Deposits the specified amount of borrowed tokens into the vault and mints shares to the receiver.
| Input | Type | Description |
|---|---|---|
_assets | uint256 | Amount of borrowed tokens to deposit |
_receiver | address | Address to receive the minted vault shares |
Returns: number of shares minted (uint256).
Emits: Deposit event.
<>Source code▼
▶Example▼
mint
Vault.mint(_shares: uint256, _receiver: address) -> uint256Mints an exact number of vault shares by depositing the required amount of borrowed tokens.
| Input | Type | Description |
|---|---|---|
_shares | uint256 | Exact number of shares to mint |
_receiver | address | Address to receive the minted shares |
Returns: amount of assets deposited (uint256).
Emits: Deposit event.
<>Source code▼
▶Example▼
withdraw
Vault.withdraw(_assets: uint256, _receiver: address, _owner: address) -> uint256Withdraws an exact amount of borrowed tokens by burning the required vault shares.
| Input | Type | Description |
|---|---|---|
_assets | uint256 | Exact amount of borrowed tokens to withdraw |
_receiver | address | Address to receive the withdrawn tokens |
_owner | address | Address whose shares are burned |
Returns: number of shares burned (uint256).
Emits: Withdraw event.
<>Source code▼
▶Example▼
redeem
Vault.redeem(_shares: uint256, _receiver: address, _owner: address) -> uint256Burns an exact number of vault shares and returns the corresponding borrowed tokens.
| Input | Type | Description |
|---|---|---|
_shares | uint256 | Exact number of shares to burn |
_receiver | address | Address to receive the withdrawn tokens |
_owner | address | Address whose shares are burned |
Returns: amount of assets withdrawn (uint256).
Emits: Withdraw event.
<>Source code▼
▶Example▼
ERC4626 — Preview and Limits
totalAssets
Vault.totalAssets() -> uint256: viewReturns the total amount of borrowed tokens managed by the vault, including tokens lent out to borrowers (tracked by the controller's debt accounting).
Returns: total assets (uint256).
<>Source code▼
▶Example▼
convertToShares
Vault.convertToShares(_assets: uint256) -> uint256: viewReturns the number of vault shares that would be minted for a given amount of assets.
| Input | Type | Description |
|---|---|---|
_assets | uint256 | Amount of assets |
Returns: equivalent shares (uint256).
<>Source code▼
▶Example▼
convertToAssets
Vault.convertToAssets(_shares: uint256) -> uint256: viewReturns the amount of assets that a given number of shares is worth.
| Input | Type | Description |
|---|---|---|
_shares | uint256 | Amount of shares |
Returns: equivalent assets (uint256).
<>Source code▼
▶Example▼
previewDeposit
Vault.previewDeposit(_assets: uint256) -> uint256: viewSimulates a deposit and returns the number of shares that would be minted. Rounds down.
| Input | Type | Description |
|---|---|---|
_assets | uint256 | Amount of assets to deposit |
Returns: shares that would be minted (uint256).
<>Source code▼
▶Example▼
previewMint
Vault.previewMint(_shares: uint256) -> uint256: viewSimulates a mint and returns the amount of assets required. Rounds up.
| Input | Type | Description |
|---|---|---|
_shares | uint256 | Number of shares to mint |
Returns: assets required (uint256).
<>Source code▼
▶Example▼
previewWithdraw
Vault.previewWithdraw(_assets: uint256) -> uint256: viewSimulates a withdrawal and returns the number of shares that would be burned. Rounds up.
| Input | Type | Description |
|---|---|---|
_assets | uint256 | Amount of assets to withdraw |
Returns: shares that would be burned (uint256).
<>Source code▼
▶Example▼
previewRedeem
Vault.previewRedeem(_shares: uint256) -> uint256: viewSimulates a redemption and returns the amount of assets that would be returned. Rounds down.
| Input | Type | Description |
|---|---|---|
_shares | uint256 | Number of shares to redeem |
Returns: assets that would be returned (uint256).
<>Source code▼
▶Example▼
maxDeposit
Vault.maxDeposit(_receiver: address) -> uint256: viewReturns the maximum amount of assets that can be deposited for a given receiver, considering the supply limit.
| Input | Type | Description |
|---|---|---|
_receiver | address | Receiver address |
Returns: max depositable assets (uint256).
<>Source code▼
▶Example▼
maxMint
Vault.maxMint(_receiver: address) -> uint256: viewReturns the maximum number of shares that can be minted for a given receiver.
| Input | Type | Description |
|---|---|---|
_receiver | address | Receiver address |
Returns: max mintable shares (uint256).
<>Source code▼
▶Example▼
maxWithdraw
Vault.maxWithdraw(_owner: address) -> uint256: viewReturns the maximum amount of assets that can be withdrawn by a given owner, limited by available liquidity.
| Input | Type | Description |
|---|---|---|
_owner | address | Owner of the shares |
Returns: max withdrawable assets (uint256).
<>Source code▼
▶Example▼
maxRedeem
Vault.maxRedeem(_owner: address) -> uint256: viewReturns the maximum number of shares that can be redeemed by a given owner.
| Input | Type | Description |
|---|---|---|
_owner | address | Owner of the shares |
Returns: max redeemable shares (uint256).
<>Source code▼
▶Example▼
pricePerShare
Vault.pricePerShare() -> uint256: viewReturns the current price per share, scaled to 1e18. Increases over time as interest accrues.
Returns: price per share (uint256).
<>Source code▼
▶Example▼
APR
borrow_apr
Vault.borrow_apr() -> uint256: viewReturns the current annualized borrow rate as reported by the monetary policy, scaled to 1e18.
Returns: borrow APR (uint256).
<>Source code▼
▶Example▼
lend_apr
Vault.lend_apr() -> uint256: viewReturns the current annualized lending rate — the effective yield lenders earn after accounting for utilization and admin fees, scaled to 1e18.
Returns: lend APR (uint256).
<>Source code▼
▶Example▼
Vault Info
asset
Vault.asset() -> address: viewReturns the address of the underlying borrowed token (the ERC4626 asset).
Returns: asset address (address).
<>Source code▼
▶Example▼
borrowed_token
Vault.borrowed_token() -> address: viewReturns the borrowed token address.
Returns: token address (address).
<>Source code▼
▶Example▼
collateral_token
Vault.collateral_token() -> address: viewReturns the collateral token address for this market.
Returns: token address (address).
<>Source code▼
▶Example▼
controller
Vault.controller() -> address: viewReturns the LendController address associated with this vault.
Returns: controller address (address).
<>Source code▼
▶Example▼
amm
Vault.amm() -> address: viewReturns the AMM (LLAMMA) address associated with this vault.
Returns: AMM address (address).
<>Source code▼
▶Example▼
factory
Vault.factory() -> address: viewReturns the factory that deployed this vault.
Returns: factory address (address).
<>Source code▼
▶Example▼
Admin
set_max_supply
Vault.set_max_supply(_max_supply: uint256)This function is only callable by the admin, which is the factory owner.
Sets the maximum supply cap for the vault. When set, deposits that would push totalSupply above this limit are rejected.
| Input | Type | Description |
|---|---|---|
_max_supply | uint256 | New maximum supply cap (0 = unlimited) |
Emits: SetMaxSupply event.
<>Source code▼
▶Example▼
admin
Vault.admin() -> address: viewReturns the admin of the vault, which is the owner of the factory contract.
Returns: admin address (address).
<>Source code▼
▶Example▼
ERC20
The vault implements the full ERC20 interface for vault share tokens.
transfer
Vault.transfer(_to: address, _value: uint256) -> boolTransfers vault shares to another address.
| Input | Type | Description |
|---|---|---|
_to | address | Recipient address |
_value | uint256 | Amount of shares to transfer |
Returns: success (bool).
Emits: Transfer event.
<>Source code▼
▶Example▼
transferFrom
Vault.transferFrom(_from: address, _to: address, _value: uint256) -> boolTransfers vault shares from one address to another, using the caller's allowance.
| Input | Type | Description |
|---|---|---|
_from | address | Sender address |
_to | address | Recipient address |
_value | uint256 | Amount of shares to transfer |
Returns: success (bool).
Emits: Transfer event.
<>Source code▼
▶Example▼
approve
Vault.approve(_spender: address, _value: uint256) -> boolApproves an address to spend vault shares on behalf of the caller.
| Input | Type | Description |
|---|---|---|
_spender | address | Address to approve |
_value | uint256 | Allowance amount |
Returns: success (bool).
Emits: Approval event.
<>Source code▼
▶Example▼
increaseAllowance
Vault.increaseAllowance(_spender: address, _add_value: uint256) -> boolIncreases the allowance for a spender by a given amount.
| Input | Type | Description |
|---|---|---|
_spender | address | Address whose allowance to increase |
_add_value | uint256 | Amount to add to the current allowance |
Returns: success (bool).
Emits: Approval event.
<>Source code▼
▶Example▼
decreaseAllowance
Vault.decreaseAllowance(_spender: address, _sub_value: uint256) -> boolDecreases the allowance for a spender by a given amount.
| Input | Type | Description |
|---|---|---|
_spender | address | Address whose allowance to decrease |
_sub_value | uint256 | Amount to subtract from the current allowance |
Returns: success (bool).
Emits: Approval event.