Skip to content

Feature/emergency withdraw#155

Open
Abidoyesimze wants to merge 2 commits intoedehvictor:mainfrom
Abidoyesimze:feature/emergency-withdraw
Open

Feature/emergency withdraw#155
Abidoyesimze wants to merge 2 commits intoedehvictor:mainfrom
Abidoyesimze:feature/emergency-withdraw

Conversation

@Abidoyesimze
Copy link
Copy Markdown
Contributor

closes #119

Summary

Adds a guaranteed emergency withdrawal path to let users exit directly from idle vault reserves if the main app/strategies are compromised, plus a minimal independently hostable UI page.
Motivation
If the frontend fails or a strategy appears unsafe, users need a simple, reliable escape hatch that avoids strategy interactions and queues.

What’s Included

Contract: yield_vault
emergency_withdraw(to, shares): burns shares and pays from idle reserves only.
set_emergency_penalty(admin, bps): optional haircut during emergency exits.
Events: emg_wd, emg_pen.
Internal accounting updates to maintain invariants.

Tests

Emulates partial allocation to strategy; withdraws only the idle portion.
Validates penalty application.
Minimal UI: emergency-ui Next.js app
/emergency page with clear warning and simple form (contract id, address, shares).
Designed for independent hosting (Vercel/IPFS).

Security

Skips external strategy/oracle calls; uses only contract’s token balance.
Burns shares and clamps to idle reserves, preventing over-withdraws.
Optional penalty (bps) set by admin.
Note: If/when per-user debt is added, gate emergency_withdraw behind a “no-active-debt(user)” check.

How to Test

Contracts:
From contracts/: cargo test -p yield_vault emergency::tests::
UI (optional):
cd emergency-ui && npm install && npm run build && npm start

Acceptance Criteria Mapping

Implement an emergency_withdraw that bypasses strategies: done.
Pulls from idle reserves only: enforced via contract balance.
Minimal independent /emergency page with warnings: added.
Warning about penalties/slippage: present in UI.
Security: no strategy calls; penalty optional; future hook for debt checks.

Checklist

[x] Contract functions and events
[x] Tests for idle-only and penalty cases
[x] Minimal emergency UI with warning
[x] Docs/comments on usage and security caveats

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 30, 2026

@Abidoyesimze is attempting to deploy a commit to the Edeh Victor's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 30, 2026

@Abidoyesimze Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@edehvictor
Copy link
Copy Markdown
Owner

@Abidoyesimze fix CI error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Emergency Eject" Contract Function & UI

2 participants