Skip to the article
Web3 Hub

Markets, protocols and policy, reported

How to build an ERC-4626 deposit and cooldown flow in Umbrella

Build an ERC-4626 deposit and cooldown flow by approving the underlying, depositing shares, waiting for maxRedeem, then previewing and redeeming inside the window.

By Web3 Hub Newsroom2 min read

How to build an ERC-4626 deposit and cooldown flow in Umbrella

A complete ERC-4626 stake-token flow approves the underlying, deposits it, starts cooldown, and redeems only when maxRedeem is above zero. The example assumes a connected wallet holds the underlying asset and is on the stake token’s chain.

Read the stake token address and call asset() to identify the underlying before building the form. Aave’s Umbrella documentation describes stake tokens backed by wrapped aTokens, such as waUSDC for stkwaUSDC. For product copy about Aave staking, connect this implementation to how Aave staking fits an idle-stablecoin route so users can choose their route before they deposit.

Build the flow

  1. Confirm the token and wallet. Check the chain, stake token address, connected wallet, underlying address from asset(), and the wallet’s underlying balance. Use the returned underlying address for balance and allowance reads.

  2. Approve the exact deposit amount. Read allowance for the wallet and stake token contract. If it is short, call approve with the deposit amount and the stake token as spender, then wait for the approval transaction to confirm. ERC-4626 deposit reverts when allowance is insufficient.

  3. Preview and deposit. Call previewDeposit(assets) to show the expected shares, then call deposit(assets, receiver). After confirmation, read the minted share amount from the Deposit event and show it in the account.

  4. Start cooldown. Call cooldown() and store its transaction so the interface can show that the request is pending, then running. Aave Umbrella documentation describes this cooldown as part of the stake-token withdrawal flow.

  5. Wait for the redeem window. Poll maxRedeem(owner) and keep the redeem button disabled while it returns zero. EIP-4626 requires maxRedeem and maxWithdraw to return zero when withdrawals are disabled, including temporarily; use the live maxRedeem value to limit the shares the user can redeem. If the window lapses before the transaction lands, start cooldown again.

  6. Preview, redeem, and verify. When maxRedeem is above zero, call previewRedeem(shares) for the selected amount and show the expected underlying, then call redeem(shares, receiver, owner) within the window. EIP-4626 says previewRedeem must not account for withdrawal limits, so the preview does not replace the maxRedeem gate. A slash during cooldown can lower assets per share; refresh the preview at exit rather than showing the deposit-time estimate. Treat the flow as complete when the Withdraw event is emitted and the wallet’s underlying balance increases.