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
Withdraw Call
The user calls
withdraw(shares, receiver)
to redeem their vault shares for SOM tokens.
Accumulate Points
The vault triggers
accumulate(vault, user)
in the PointsController to finalize the user’s point balance before reducing their shares.
Preview Withdraw
The vault runs
previewWithdraw(shares)
to calculate the amount of SOM tokens owed to the user.
Burn Shares
The vault executes
_burn(user, shares)
to destroy the user’s vault shares, reducing their proportional ownership.
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).
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)
.
Adapter Withdrawals
The StrategyRouter calls
withdrawNative()
on strategy adapters to free the required liquidity.
Penalty Transfer (if applicable)
If a penalty applies, the calculated penalty portion is transferred to the Treasury.
Transfer Net Amount
The vault transfers the remaining SOM (after penalty) to the user’s receiver address.
Update User Index
The vault calls
updateUserIndex(vault, user)
in the PointsController to reflect the user’s new position in the global index.
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