User Withdraw

ChatGPT said:

User Withdrawal Flow

The diagram shows the full process when a user withdraws their SOM tokens from the InsomniaVault.

Step-by-Step Process

  1. Withdraw Call

    • The user calls withdraw(shares, receiver) to redeem their vault shares for SOM tokens.

  2. Accumulate Points

    • The vault triggers accumulate(vault, user) in the PointsController to finalize the user’s point balance before reducing their shares.

  3. Preview Withdraw

    • The vault runs previewWithdraw(shares) to calculate the amount of SOM tokens owed to the user.

  4. Burn Shares

    • The vault executes _burn(user, shares) to destroy the user’s vault shares, reducing their proportional ownership.

  5. Lockup & Penalty Check

    • If the user withdraws before the lockup expires, the vault calculates an early exit penalty.

    • Penalty = withdraw amount × configured fee (in basis points).

  6. Vault Liquidity Check

    • If the vault doesn’t have enough idle SOM to fulfill the withdrawal, it calls the StrategyRouter to unwind(needed_amount, vault).

  7. Adapter Withdrawals

    • The StrategyRouter calls withdrawNative() on strategy adapters to free the required liquidity.

  8. Penalty Transfer (if applicable)

    • If a penalty applies, the calculated penalty portion is transferred to the Treasury.

  9. Transfer Net Amount

    • The vault transfers the remaining SOM (after penalty) to the user’s receiver address.

  10. Update User Index

  • The vault calls updateUserIndex(vault, user) in the PointsController to reflect the user’s new position in the global index.

  1. Emit Withdraw Event

  • A Withdraw event is emitted for transparency, allowing off-chain systems to track withdrawals.

Additional Notes

  • Partial Withdrawals: Users can withdraw a portion of their shares while leaving the rest to continue earning points and yield.

  • Penalty Mechanism: Ensures fairness by discouraging early exits and funding the treasury for protocol sustainability.

  • Liquidity Management: Withdrawals prioritize idle vault liquidity first, then unwind strategies only when necessary.

Last updated