📍4626 ETH Router

In order to allow raw Eth to be deposited and withdrawn from the system using the vault contract, a router has been created to allow this. The router accepts ETH, converts it to WETH, and then deposits the WETH into the 4626 vault.

This router is generic and is designed to be used by multiple projects without the need to deploy new instances even for different 4626 ETH Vaults.

The router interface has support for both mint and deposit functionality on the 4626 vault.

    /// @param vault The ERC4626 vault to mint shares from.
    /// @param to The address to mint shares to.
    /// @param shares The number of shares to mint.
    /// @param maxAmountIn The maximum amount of underlying
    /// assets required for the mint to succeed.
    function mint(
        MoonwellERC4626Eth vault,
        address to,
        uint256 shares,
        uint256 maxAmountIn
    ) public payable returns (uint256 amountIn);
    
    /// @param vault The ERC4626 vault to deposit assets into.
    /// @param to The address to mint shares to.
    /// @param amount The amount of assets to deposit.
    /// @param minSharesOut The minimum number of shares required for the deposit to succeed.
    function deposit(
        MoonwellERC4626Eth vault,
        address to,
        uint256 amount,
        uint256 minSharesOut
    ) public payable returns (uint256 sharesOut);

Both of these functions work by depositing all ETH sent to them into WETH, calling either deposit or mint on the specified 4626 vault, and then refunding all excess WETH leftover in the contract to the sender. Please note: refunds are denominated in WETH, not ETH. When calling the deposit function, the msg.value should match up with the parameter amount. When calling the mint, maxAmountIn should equal msg.value.

The router can only deposit on behalf of users. Withdrawals must take place by calling the underlying 4626 vault itself.

Last updated