Skip to content

VenusERC4626

VenusERC4626 is an upgradeable, ERC4626-compliant vault that wraps a Venus vToken, enabling standard ERC4626 vault interactions with the Venus Protocol. It manages deposits, withdrawals, minting, redeeming, and reward distribution, with additional access control and loop limit protections.

  • NO_ERROR (uint256, internal constant):
    Error code representing no errors in Venus operations.

  • vToken (VToken, public):
    The Venus vToken associated with this ERC4626 vault.

  • comptroller (IComptroller, public):
    The Venus Comptroller contract responsible for market operations.

  • rewardRecipient (address, public):
    The address that receives rewards distributed by the Venus Protocol.


  • ClaimRewards(uint256 amount, address indexed rewardToken)
    Emitted when rewards are claimed.

    • amount: The amount of reward tokens claimed.
    • rewardToken: The address of the reward token claimed.
  • RewardRecipientUpdated(address indexed oldRecipient, address indexed newRecipient)
    Emitted when the reward recipient address is updated.

    • oldRecipient: The previous reward recipient address.
    • newRecipient: The new reward recipient address.
  • SweepToken(address indexed token, address indexed receiver, uint256 amount)
    Emitted when tokens are swept from the contract.

    • token: The token address.
    • receiver: The receiver address.
    • amount: The amount swept.

  • VenusERC4626__VenusError(uint256 errorCode)
    Thrown when a Venus protocol call returns an error.

    • errorCode: The error code returned by Venus.
  • ERC4626__DepositMoreThanMax()
    Thrown when a deposit exceeds the maximum allowed.

  • ERC4626__MintMoreThanMax()
    Thrown when a mint operation exceeds the maximum allowed.

  • ERC4626__WithdrawMoreThanMax()
    Thrown when a withdrawal exceeds the maximum available assets.

  • ERC4626__RedeemMoreThanMax()
    Thrown when a redemption exceeds the maximum redeemable shares.

  • ERC4626__ZeroAmount(string operation)
    Thrown when attempting an operation with a zero amount.

    • operation: The name of the operation (e.g., “deposit”, “withdraw”, “mint”, “redeem”).
  • @custom:oz-upgrades-unsafe-allow constructor
    Disables initializers for the upgradeable contract pattern.

Initializes the VenusERC4626 vault with the associated vToken address.

function initialize(address vToken_) public initializer
NameTypeDescription
vToken_addressThe vToken associated with the vault, representing the yield-bearing asset.
  • Only the vToken address is set in this function.
  • initialize2 must be called to complete the configuration.

Completes the configuration of the VenusERC4626 vault by setting additional attributes.

function initialize2(address accessControlManager_, address rewardRecipient_, uint256 loopsLimit_, address vaultOwner_) public
NameTypeDescription
accessControlManager_addressThe address of the access control manager contract.
rewardRecipient_addressThe initial recipient of rewards.
loopsLimit_uint256The maximum number of loops for certain operations to enhance security.
vaultOwner_addressThe address of the vault owner.
  • Can only be called once.
  • Use with caution to avoid misconfiguration.

Sets the maximum number of loops for certain operations.

function setMaxLoopsLimit(uint256 loopsLimit) external
NameTypeDescription
loopsLimituint256The new maximum loops limit to be set.
  • Emits MaxLoopsLimitUpdated on success.
  • Controlled by the Access Control Manager (ACM).

Sets a new recipient for rewards distributed by the Venus Protocol.

function setRewardRecipient(address newRecipient) external
NameTypeDescription
newRecipientaddressThe address of the new reward recipient.
  • Emits RewardRecipientUpdated on success.
  • Controlled by the ACM.

Sweeps the specified token from the contract and sends it to the contract owner.

function sweepToken(IERC20Upgradeable token) external onlyOwner
NameTypeDescription
tokenIERC20UpgradeableAddress of the token.
  • Emits SweepToken on success.
  • Only the owner.

Claims rewards from all reward distributors associated with the vToken and transfers them to the reward recipient.

function claimRewards() external
  • Iterates through all reward distributors fetched from the comptroller, claims rewards, and transfers them if available.

Deposits assets into the vault, minting corresponding shares to the receiver.

function deposit(uint256 assets, address receiver) public override nonReentrant returns (uint256)
NameTypeDescription
assetsuint256The amount of assets to deposit.
receiveraddressThe address to receive shares.
NameTypeDescription
sharesuint256Amount of shares minted.
  • Overrides ERC4626Upgradeable deposit.
  • Includes non-reentrant protection and custom Venus logic.

Mints new shares of the vault, allocating the corresponding amount of assets to the receiver.

function mint(uint256 shares, address receiver) public override nonReentrant returns (uint256)
NameTypeDescription
sharesuint256The amount of shares to mint.
receiveraddressThe address to receive shares.
NameTypeDescription
assetsuint256Amount of assets deposited.
  • Overrides ERC4626Upgradeable mint.
  • Includes non-reentrant protection and custom Venus logic.

Withdraws assets from the vault, burning the corresponding amount of shares from the owner’s balance.

function withdraw(uint256 assets, address receiver, address owner) public override nonReentrant returns (uint256)
NameTypeDescription
assetsuint256The amount of assets to withdraw.
receiveraddressThe address to receive assets.
owneraddressThe address whose shares are burned.
NameTypeDescription
sharesuint256Amount of shares burned.
  • Overrides ERC4626Upgradeable withdraw.
  • Includes non-reentrant protection and custom Venus logic.

Redeems shares of the vault, returning the corresponding amount of assets to the receiver.

function redeem(uint256 shares, address receiver, address owner) public override nonReentrant returns (uint256)
NameTypeDescription
sharesuint256The amount of shares to redeem.
receiveraddressThe address to receive assets.
owneraddressThe address whose shares are redeemed.
NameTypeDescription
assetsuint256Amount of assets returned.
  • Overrides ERC4626Upgradeable redeem.
  • Includes non-reentrant protection and custom Venus logic.

Returns the total amount of assets managed by the vault, including both deposited assets and accrued rewards.

function totalAssets() public view virtual override returns (uint256)
NameTypeDescription
assetsuint256Total assets managed by the vault.
  • Overrides ERC4626Upgradeable totalAssets.

Returns the maximum deposit allowed, based on Venus supply caps.

function maxDeposit(address account) public view virtual override returns (uint256)
NameTypeDescription
accountaddressThe address of the account.
NameTypeDescription
amountuint256Maximum assets that can be deposited.
  • Returns 0 if minting is paused or the supply cap has been reached.

Returns the maximum amount of shares that can be minted.

function maxMint(address account) public view virtual override returns (uint256)
NameTypeDescription
accountaddressThe address of the account.
NameTypeDescription
sharesuint256Maximum shares that can be minted.
  • Derived from the maximum deposit amount converted to shares.

Returns the maximum amount of assets that can be withdrawn.

function maxWithdraw(address receiver) public view virtual override returns (uint256)
NameTypeDescription
receiveraddressThe address of the account withdrawing.
NameTypeDescription
amountuint256Maximum assets that can be withdrawn.
  • This value is limited by the available cash in the vault.

Returns the maximum amount of shares that can be redeemed.

function maxRedeem(address receiver) public view virtual override returns (uint256)
NameTypeDescription
receiveraddressThe address of the account redeeming.
NameTypeDescription
sharesuint256Maximum shares that can be redeemed.
  • Limited by the available cash in the vault.