Skip to content

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.

uint256 public constant BPS = 10_000
uint256 public constant MANTISSA_ONE = 1e18
uint256 public constant YEAR = 365 days

Immutable vault configuration set at initialization.

VaultConfig internal _config

Runtime state that changes during the vault lifecycle.

VaultRuntime internal _runtime

VaultController address — set to msg.sender during initialize.

address public vaultController

Current pause level (Unpaused, Partial, Complete).

PauseLevel public pauseLevel

Reverts if caller is not the VaultController.

modifier onlyController();

Reverts on any pause level (Partial or Complete). Used for general operations.

modifier whenNotPaused();

Reverts only on Complete pause. Repay and liquidation remain available during Partial pause.

modifier whenNotCompletelyPaused();

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;

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;

Complete pause — blocks all operations including repay and liquidation.

Note: event: PauseLevelSet

function completePause() external onlyController;

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

NameTypeDescription
tokenaddressToken address to sweep.

Permissionless vault finalizer. Triggers state transitions and settlement.

function updateVaultState() external;

Total remaining debt. Decremented by repayments; zero when fully repaid.

function outstandingDebt() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256Outstanding debt in supply asset units.

Returns the vault configuration.

function config() external view returns (VaultConfig memory);

Returns

NameTypeDescription
<none>VaultConfigImmutable VaultConfig struct set at initialization.

Returns the runtime state.

function runtime() external view returns (VaultRuntime memory);

Returns

NameTypeDescription
<none>VaultRuntimeMutable VaultRuntime struct tracking lifecycle progress.

Current vault lifecycle state.

function state() external view returns (VaultState);

Returns

NameTypeDescription
<none>VaultStateCurrent VaultState enum value.

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

NameTypeDescription
assetsuint256Requested deposit amount in supply asset units.
receiveraddressAddress to receive minted shares.

Returns

NameTypeDescription
sharesuint256Actual 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

NameTypeDescription
sharesuint256Requested shares to mint.
receiveraddressAddress to receive minted shares.

Returns

NameTypeDescription
assetsuint256Actual supply assets pulled (may be less than requested if cap approached).

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

NameTypeDescription
assetsuint256Amount of supply assets to withdraw.
receiveraddressAddress to receive the assets.
owneraddressShare holder address.

Returns

NameTypeDescription
sharesuint256Shares burned.

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

NameTypeDescription
sharesuint256Shares to redeem.
receiveraddressAddress to receive the assets.
owneraddressShare holder address.

Returns

NameTypeDescription
assetsuint256Supply assets returned.

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

NameTypeDescription
<none>uint256Total assets in supply asset units.

Remaining deposit capacity in supply asset units. Zero outside Fundraising state.

function maxDeposit(address /* receiver */) public view override returns (uint256);

Returns

NameTypeDescription
<none>uint256Maximum depositable amount.

Share equivalent of maxDeposit.

function maxMint(address receiver) public view override returns (uint256);

Parameters

NameTypeDescription
receiveraddressReceiver address (passed through to maxDeposit).

Returns

NameTypeDescription
<none>uint256Maximum mintable shares.

Withdrawable supply asset amount for a supplier. Zero outside terminal states.

function maxWithdraw(address owner) public view override returns (uint256);

Parameters

NameTypeDescription
owneraddressShare holder address.

Returns

NameTypeDescription
<none>uint256Maximum withdrawable supply asset amount.

Redeemable share amount for a supplier. Zero outside terminal states.

function maxRedeem(address owner) public view override returns (uint256);

Parameters

NameTypeDescription
owneraddressShare holder address.

Returns

NameTypeDescription
<none>uint256Maximum redeemable share amount.
event StateTransition(VaultState indexed from, VaultState indexed to, uint256 timestamp);
event VaultClosed(VaultState state);
event SettlementConfirmed(uint256 settlementAmount, uint256 protocolFee, uint256 surplus);
event ShortfallDetected(uint256 totalOwed, uint256 available);
event PSRNotificationFailed(address indexed psr, bytes reason);
event RaisedFundsClaimed(uint256 amount);
event Repaid(uint256 amount, uint256 remainingDebt);
event PauseLevelSet(PauseLevel oldLevel, PauseLevel newLevel);
event TokensSwept(address indexed token, address indexed recipient, uint256 amount);
error InvalidState();
error SameStateTransition();
error BelowMinimumDepositAmount();
error ExceedsMaxCap();
error Unauthorized();
error AlreadyWithdrawn();
error NoOutstandingDebt();
error ZeroRepayAmount();
error NothingToSweep();
error PartiallyPaused();
error CompletelyPaused();