BaseVault
Inherits: ERC4626Upgradeable, ReentrancyGuardUpgradeable
Title: BaseVault
Abstract base ERC-4626 vault providing shared mechanics for all Venus fixed-term vault types: fundraising (time-bounded deposit window), interest computation, settlement (protocol fee waterfall), and core state machine transitions.
Subcontracts (InstitutionalLoanVault) inherit this and add type-specific logic. Deployed as EIP-1167 minimal proxy clones by the respective VaultController.
Solidity API
Section titled “Solidity API”State Variables
Section titled “State Variables”uint256 public constant BPS = 10_000MANTISSA_ONE
Section titled “MANTISSA_ONE”uint256 public constant MANTISSA_ONE = 1e18uint256 public constant YEAR = 365 days_config
Section titled “_config”Immutable vault configuration set at initialization.
VaultConfig internal _config_runtime
Section titled “_runtime”Runtime state that changes during the vault lifecycle.
VaultRuntime internal _runtimevaultController
Section titled “vaultController”VaultController address — set to msg.sender during initialize.
address public vaultControllerpauseLevel
Section titled “pauseLevel”Current pause level (Unpaused, Partial, Complete).
PauseLevel public pauseLevelFunctions
Section titled “Functions”onlyController
Section titled “onlyController”Reverts if caller is not the VaultController.
modifier onlyController();whenNotPaused
Section titled “whenNotPaused”Reverts on any pause level (Partial or Complete). Used for general operations.
modifier whenNotPaused();whenNotCompletelyPaused
Section titled “whenNotCompletelyPaused”Reverts only on Complete pause. Repay and liquidation remain available during Partial pause.
modifier whenNotCompletelyPaused();closeVault
Section titled “closeVault”Transitions vault to Closed state. All operations are blocked after this point. Governance should only call this once all suppliers have withdrawn their funds.
Notes:
- error: InvalidState If vault is not in a terminal state (Matured/Failed/Liquidated).
- event: StateTransition Emitted for the terminal state -> Closed transition.
- event: VaultClosed Emitted with the previous terminal state.
function closeVault() external onlyController;partialPause
Section titled “partialPause”Partial pause — blocks general operations (deposits, collateral, borrowing). Repay and liquidation remain available so positions can still be defended/resolved.
Note: event: PauseLevelSet
function partialPause() external onlyController;completePause
Section titled “completePause”Complete pause — blocks all operations including repay and liquidation.
Note: event: PauseLevelSet
function completePause() external onlyController;unpause
Section titled “unpause”Removes all pause restrictions.
Note: event: PauseLevelSet
function unpause() external onlyController;Recovers any tokens stuck in the vault. Full balance is transferred.
Notes:
- error: NothingToSweep If the token balance is zero.
- event: TokensSwept
function sweep(address token) external onlyController;Parameters
| Name | Type | Description |
|---|---|---|
token | address | Token address to sweep. |
updateVaultState
Section titled “updateVaultState”Permissionless vault finalizer. Triggers state transitions and settlement.
function updateVaultState() external;outstandingDebt
Section titled “outstandingDebt”Total remaining debt. Decremented by repayments; zero when fully repaid.
function outstandingDebt() external view returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Outstanding debt in supply asset units. |
config
Section titled “config”Returns the vault configuration.
function config() external view returns (VaultConfig memory);Returns
| Name | Type | Description |
|---|---|---|
<none> | VaultConfig | Immutable VaultConfig struct set at initialization. |
runtime
Section titled “runtime”Returns the runtime state.
function runtime() external view returns (VaultRuntime memory);Returns
| Name | Type | Description |
|---|---|---|
<none> | VaultRuntime | Mutable VaultRuntime struct tracking lifecycle progress. |
Current vault lifecycle state.
function state() external view returns (VaultState);Returns
| Name | Type | Description |
|---|---|---|
<none> | VaultState | Current VaultState enum value. |
deposit
Section titled “deposit”Deposits supply assets during the Fundraising window. Clamps to remaining capacity instead of reverting on excess.
Notes:
- error: InvalidState If vault is not in Fundraising state.
- error: ExceedsMaxCap If clamped deposit amount is zero (vault at capacity).
function deposit(uint256 assets, address receiver) public override returns (uint256 shares);Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | Requested deposit amount in supply asset units. |
receiver | address | Address to receive minted shares. |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | Actual shares minted (may be less than requested if cap approached). |
Mints shares during the Fundraising window. Clamps to remaining capacity instead of reverting on excess.
Notes:
- error: InvalidState If vault is not in Fundraising state.
- error: ExceedsMaxCap If clamped share amount is zero (vault at capacity).
function mint(uint256 shares, address receiver) public override returns (uint256 assets);Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | Requested shares to mint. |
receiver | address | Address to receive minted shares. |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | Actual supply assets pulled (may be less than requested if cap approached). |
withdraw
Section titled “withdraw”Withdraws supply assets in terminal states. Advances state before checking max, enabling single-tx withdrawals when the vault is ready to transition (e.g. PendingSettlement -> Matured).
Notes:
- error: InvalidState If vault is not in a terminal state (Matured/Failed/Liquidated).
- error: ExceedsMaxCap If requested assets exceed the caller’s withdrawable balance.
function withdraw( uint256 assets, address receiver, address owner) public override returns (uint256 shares);Parameters
| Name | Type | Description |
|---|---|---|
assets | uint256 | Amount of supply assets to withdraw. |
receiver | address | Address to receive the assets. |
owner | address | Share holder address. |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | Shares burned. |
redeem
Section titled “redeem”Redeems shares for supply assets in terminal states. Advances state before checking max, enabling single-tx redemptions when the vault is ready to transition (e.g. PendingSettlement -> Matured).
Notes:
- error: InvalidState If vault is not in a terminal state (Matured/Failed/Liquidated).
- error: ExceedsMaxCap If requested shares exceed the caller’s redeemable balance.
function redeem( uint256 shares, address receiver, address owner) public override returns (uint256 assets);Parameters
| Name | Type | Description |
|---|---|---|
shares | uint256 | Shares to redeem. |
receiver | address | Address to receive the assets. |
owner | address | Share holder address. |
Returns
| Name | Type | Description |
|---|---|---|
assets | uint256 | Supply assets returned. |
totalAssets
Section titled “totalAssets”State-dependent total assets backing outstanding shares.
Matured/Failed/Liquidated: settlementAmount (decremented on each withdrawal). All other states: totalRaised.
function totalAssets() public view override returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Total assets in supply asset units. |
maxDeposit
Section titled “maxDeposit”Remaining deposit capacity in supply asset units. Zero outside Fundraising state.
function maxDeposit(address /* receiver */) public view override returns (uint256);Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Maximum depositable amount. |
maxMint
Section titled “maxMint”Share equivalent of maxDeposit.
function maxMint(address receiver) public view override returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
receiver | address | Receiver address (passed through to maxDeposit). |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Maximum mintable shares. |
maxWithdraw
Section titled “maxWithdraw”Withdrawable supply asset amount for a supplier. Zero outside terminal states.
function maxWithdraw(address owner) public view override returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
owner | address | Share holder address. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Maximum withdrawable supply asset amount. |
maxRedeem
Section titled “maxRedeem”Redeemable share amount for a supplier. Zero outside terminal states.
function maxRedeem(address owner) public view override returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
owner | address | Share holder address. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | Maximum redeemable share amount. |
Events
Section titled “Events”StateTransition
Section titled “StateTransition”event StateTransition(VaultState indexed from, VaultState indexed to, uint256 timestamp);VaultClosed
Section titled “VaultClosed”event VaultClosed(VaultState state);SettlementConfirmed
Section titled “SettlementConfirmed”event SettlementConfirmed(uint256 settlementAmount, uint256 protocolFee, uint256 surplus);ShortfallDetected
Section titled “ShortfallDetected”event ShortfallDetected(uint256 totalOwed, uint256 available);PSRNotificationFailed
Section titled “PSRNotificationFailed”event PSRNotificationFailed(address indexed psr, bytes reason);RaisedFundsClaimed
Section titled “RaisedFundsClaimed”event RaisedFundsClaimed(uint256 amount);Repaid
Section titled “Repaid”event Repaid(uint256 amount, uint256 remainingDebt);PauseLevelSet
Section titled “PauseLevelSet”event PauseLevelSet(PauseLevel oldLevel, PauseLevel newLevel);TokensSwept
Section titled “TokensSwept”event TokensSwept(address indexed token, address indexed recipient, uint256 amount);Errors
Section titled “Errors”InvalidState
Section titled “InvalidState”error InvalidState();SameStateTransition
Section titled “SameStateTransition”error SameStateTransition();BelowMinimumDepositAmount
Section titled “BelowMinimumDepositAmount”error BelowMinimumDepositAmount();ExceedsMaxCap
Section titled “ExceedsMaxCap”error ExceedsMaxCap();Unauthorized
Section titled “Unauthorized”error Unauthorized();AlreadyWithdrawn
Section titled “AlreadyWithdrawn”error AlreadyWithdrawn();NoOutstandingDebt
Section titled “NoOutstandingDebt”error NoOutstandingDebt();ZeroRepayAmount
Section titled “ZeroRepayAmount”error ZeroRepayAmount();NothingToSweep
Section titled “NothingToSweep”error NothingToSweep();PartiallyPaused
Section titled “PartiallyPaused”error PartiallyPaused();CompletelyPaused
Section titled “CompletelyPaused”error CompletelyPaused();