Vault Contract
The Vault contract implements ERC4626 tokenized vault functionality for earning yield generated by borrower’s interest. Contract implementationERC4626 Standard Functions
deposit
assets: Amount of underlying assets to deposit (in wei)receiver: Address to receive the vault shares
shares: Amount of vault shares minted
assetsmust be > 0- Caller must have approved vault for asset transfer
- If this is the first ever deposit into the vault, the minted shares must be at least
MIN_SHARES(1e16); otherwise the transaction reverts
- Transfers assets from caller to vault
- Mints shares to receiver
- Updates total assets
- Accrues interest before deposit
- On the first ever deposit,
MIN_SHARESshares are burned from the receiver and sent toaddress(0)to initialize share pricing; the receiver’s net minted shares are reduced byMIN_SHARES
mint
shares: Exact amount of shares to mintreceiver: Address to receive the vault shares
assets: Amount of assets required for the mint
sharesmust be > 0- Caller must have sufficient assets approved
- If this is the first ever mint into the vault, the requested
sharesmust be at leastMIN_SHARES(1e16); otherwise the transaction reverts
- Calculates required assets based on current share price
- Transfers assets from caller to vault
- Mints exact shares to receiver
- On the first ever mint,
MIN_SHARESshares are burned from the receiver and sent toaddress(0); the correspondingassetsare effectively reserved
withdraw
assets: Amount of assets to withdrawreceiver: Address to receive the assetsowner: Address that owns the shares (can be different from caller with approval)
shares: Amount of shares burned
assetsmust be ≤ owner’s balance- If
owner != msg.sender, caller must have withdrawal approval - Vault must have sufficient assets
- Burns shares from owner
- Transfers assets to receiver
- Updates total assets
redeem
shares: Amount of shares to redeemreceiver: Address to receive the assetsowner: Address that owns the shares
assets: Amount of assets returned
sharesmust be ≤ owner’s balance- If
owner != msg.sender, caller must have approval
- Burns shares from owner
- Transfers assets to receiver
- Returns actual assets received (may differ due to rounding)
View Functions
totalAssets
uint256: Total assets in wei
asset token balance held by the vault contract.
convertToShares
assets: Amount of assets to convert
uint256: Equivalent shares amount
convertToAssets
shares: Amount of shares to convert
uint256: Equivalent assets amount
maxDeposit
uint256: Maximum deposit amount (type(uint256).max if unlimited)
maxMint
uint256: Maximum mint amount
maxWithdraw
owner: Address to check withdrawal limit for
uint256: Maximum withdrawable assets
maxRedeem
owner: Address to check redemption limit for
uint256: Maximum redeemable shares
previewDeposit
assets: Amount of assets to deposit
uint256: Expected shares to receive
previewMint
shares: Amount of shares to mint
uint256: Required assets amount
previewWithdraw
assets: Amount of assets to withdraw
uint256: Shares to be burned
previewRedeem
shares: Amount of shares to redeem
uint256: Assets to be received
ERC20 Functions
The vault also implements standard ERC20 functions for shares:name(): Returns vault share token namesymbol(): Returns vault share token symboldecimals(): Returns decimals (same as underlying asset)totalSupply(): Returns total vault sharesbalanceOf(address): Returns shares balance of addresstransfer(address,uint256): Transfers sharesallowance(address,address): Returns transfer allowanceapprove(address,uint256): Approves share transferstransferFrom(address,address,uint256): Transfers shares with approval
Yield and Staking Features
accrueInterest
- Updates vault’s asset balance with accrued interest
- Maintains accurate share pricing
Security Considerations
- All state-changing functions accrue interest first
- Share calculations use current total assets
- First depositor loses 0.1
Coinof their deposit

