# Week 4 - Emergency Protocols

Quest 1: Lock Your Vault (Emergency Freeze) (10 minutes)

**What you're doing:** Using the emergency lock feature to freeze your vault.

**The Scenario:** You think your wallet might be compromised. You want to freeze everything immediately.

#### Understanding Lock

* **FREEZES** all deposits and withdrawals
* Requires guardian approval to execute (creates a guardian transaction)
* Prevents anyone from moving assets once locked
* Can only be unlocked with guardian approval

#### Trigger the Lock

1. Go to your vault dashboard
2. Look at the right panel (Settings section) - below the vault name and total asset value
3. Click the **"Lock Vault"** button (outlined button with lock icon)
4. A confirmation modal appears with warning:
   * "This will prevent all transactions until unlocked"
   * "Requires guardian approval to complete"
   * "This action cannot be undone without guardian consensus"
5. Click **"Lock Vault"** in the confirmation modal
6. This creates a **guardian transaction** that requires approval
7. Switch to your guardian wallets to approve the lock request
8. Once guardians approve (meeting threshold), **your vault is LOCKED 🔒**

#### What Happened

* All pending withdrawal/transfer requests stay pending but can't execute
* No new deposits allowed (Deposit button is disabled)
* No new withdrawals allowed (Withdraw button is disabled)
* No transfers allowed (Transfer button is disabled)
* You'll see **"Vault Locked"** badge displayed prominently (red badge below vault name)

#### Try These (they should fail)

1. Try to deposit tokens → ❌ **Blocked** - "Vault is locked"
2. Try to request withdrawal → ❌ **Blocked** - "Cannot submit while locked"
3. Try to transfer assets → ❌ **Blocked**

**Good!** Your assets are frozen and safe.

✅ **Quest Complete!** You've successfully locked your vault.

***

### Quest 2: Unlock Your Vault (15 minutes)

**What you're doing:** Unfreezing your vault after the emergency is over.

**The Scenario:** You've secured your wallet and confirmed there's no threat. Now you want to unlock your vault.

#### Request Unlock

1. Still on vault dashboard (with **"Vault Locked"** badge showing in red)
2. Look at the right panel (Settings section)
3. The button now says **"Unlock Vault"** (same location as Lock button)
4. Click **"Unlock Vault"**
5. A confirmation modal appears
6. Click **"Unlock Vault"** in the confirmation modal
7. This creates an **UNLOCK REQUEST** that requires guardian approval

**Why guardian approval?** If a hacker got your wallet, you don't want them to be able to unlock your vault immediately. Guardians provide protection.

#### Get Guardian Approvals

1. Switch to Guardian 1 wallet
2. Go to the vault dashboard
3. Click the **"Pending Transactions"** tab (should be selected by default)
4. You'll see the unlock request in the list
5. Click **"Approve"** button on the unlock transaction
6. Confirm the transaction in your wallet
7. Switch to Guardian 2 wallet
8. Go to the vault dashboard
9. Click **"Pending Transactions"** tab
10. Click **"Approve"** on the unlock request
11. Confirm the transaction
12. **On the second approval (meeting threshold), the unlock executes automatically**

#### Verify Vault is Unlocked

1. Switch back to your main wallet
2. Go to the vault dashboard
3. Check vault status → ✅ **"Vault Locked" badge is gone** (no red badge)
4. Try depositing tokens → ✅ **Deposit button is enabled** - Works again!
5. Try requesting withdrawal → ✅ **Withdraw button is enabled** - Works again!

#### What you learned

* Lock requires guardian approval (creates a guardian transaction)
* Unlock also requires guardian approval (security layer)
* The vault owner can't bypass guardians for locking or unlocking

✅ **Quest Complete!** You've successfully unlocked your vault.

***

### Quest 3: Vault Recovery - Guardian Initiated (25 minutes)

**What you're doing:** Testing what happens if a vault owner loses access and guardians need to transfer the vault to a new owner.

**The Scenario:** Your main wallet is permanently compromised or lost. Guardians need to move your vault to your new wallet address.

#### Important Distinction

* **Transfer** = Owner wants to move vault (owner initiates, guardians approve)
* **Recovery** = Owner is locked out (guardian initiates, other guardians approve)

#### Setup

1. Identify your "new owner" address (another wallet you control, or a friend's address for testing)
2. Make sure you can access this wallet
3. Note your current vault owner address

#### Initiate Recovery (As a Guardian)

1. **Switch to Guardian 1 wallet**
2. Go to the vault dashboard
3. Look at the right panel (Settings section) - below the vault name
4. You'll see a **"Recover Vault"** button (orange/amber colored button)
5. Click **"Recover Vault"**
6. A recovery modal opens
7. Enter the **NEW OWNER ADDRESS** (your recovery wallet) in the input field
8. The modal validates:
   * Address must be valid (starts with 0x, 42 characters)
   * Must be different from current owner
   * Must be different from your current wallet address
9. Click **"Initiate Recovery"** or **"Continue"** button
10. This creates a guardian transaction that requires other guardians' approval

**Important:** This creates TWO things:

* A guardian-protected request (needs approvals from other guardians)
* A 7-day delay period for safety

#### Other Guardians Approve

1. Switch to Guardian 2 wallet
2. Go to the vault dashboard
3. Click the **"Pending Transactions"** tab
4. You'll see a **"Recover Vault"** request in the list
5. Click **"Details"** to see full information:
   * Shows current owner address
   * Shows proposed new owner address
   * Shows recovery initiation details
6. Click **"Approve"** button on the recovery request
7. Confirm the transaction in your wallet
8. **If you need more approvals** (e.g., 3/3 threshold):
   * Switch to Guardian 3 wallet
   * Go to vault dashboard → **"Pending Transactions"** tab
   * Click **"Approve"** on the recovery request
   * Confirm transaction

#### Wait for Delay Period

**For testing purposes, you won't wait 7 days**, but understand:

* After guardians approve, there's a 7-day waiting period
* This gives the real owner time to intervene if this was a mistake
* After 7 days, anyone can execute the recovery

#### Execute Recovery (After 7 Days)

**Note:** In production, you would wait 7 days. For testing, understand this step:

1. After guardians approve and 7 days pass, the recovery can be executed
2. Go to the vault dashboard as a guardian
3. You'll see the vault is in **"Recovery Mode"** (orange badge)
4. The **"Recover Vault"** button changes to **"Execute Recovery"** (green button)
5. Click **"Execute Recovery"**
6. A recovery modal opens showing the pending recovery details
7. Click **"Execute Recovery"** or **"Confirm"** button
8. Confirm the transaction
9. The vault NFT transfers to the new owner
10. The new owner has full control
11. All assets remain safely in the vault

#### Verify (If you complete the full cycle)

1. Switch to the NEW owner wallet
2. Check your NFT balance - you should see the vault NFT
3. You can now control the vault
4. All assets are safe inside
5. Old owner can no longer access the vault

#### What you learned

* Recovery is a multi-step process with built-in delays
* Guardian consensus is required
* The 7-day delay provides safety against mistakes
* Assets remain secure throughout the process

✅ **Quest Complete!** You understand the recovery mechanism.

***

### Quest 4: Lock Cancels Recovery (Security Test) (15 minutes)

**What you're doing:** Testing a security feature where locking a vault can stop an unauthorized recovery attempt.

**The Scenario:** Guardians mistakenly started a recovery, but you (the owner) still have access. You want to stop it!

#### Setup

1. Have guardians initiate a recovery (like in Quest 3)
2. Get guardian approvals
3. **DON'T wait the 7 days** - leave it pending
4. You (vault owner) notice this unauthorized recovery request

#### Stop the Recovery

1. **As the vault owner**, quickly LOCK the vault
2. Go to vault dashboard
3. Look at the right panel (Settings section)
4. Click **"Lock Vault"** button
5. Click **"Lock Vault"** in the confirmation modal
6. This creates a lock request that requires guardian approval
7. Get guardian approvals for the lock (same as Quest 1)
8. Once locked, the recovery request gets **AUTOMATICALLY CANCELLED** ❌
9. The vault enters locked state and recovery cannot proceed

#### Unlock and Verify

1. Now request to unlock the vault (requires guardian approval)
2. Get guardian approvals
3. Vault unlocks
4. Go check pending requests
5. The recovery request should be **gone** - it was cancelled by the lock

#### What you learned

* Lock is a powerful defensive tool
* It can stop unauthorized recovery attempts
* But you still need guardians to unlock (balanced security)
* This protects you if guardians make a mistake

✅ **Quest Complete!** You understand the security interplay between lock and recovery.

***

### Quest 5: Guardian-Initiated Lock (10 minutes)

**What you're doing:** Testing that guardians can also lock a vault in an emergency.

**The Scenario:** A guardian notices suspicious activity and wants to freeze the vault immediately.

#### Guardian Locks the Vault

1. **Switch to Guardian 1 wallet**
2. Go to the vault dashboard
3. Look at the right panel (Settings section) - below the vault name
4. Click **"Lock Vault"** button (same button as owner sees)
5. Click **"Lock Vault"** in the confirmation modal
6. This creates a lock request that requires guardian approval
7. Switch to other guardian wallets to approve the lock
8. **Once guardians approve (meeting threshold), the vault locks**

**Why this is important:**

* If your wallet is compromised and you can't act
* Guardians can step in to protect your assets
* It's an emergency brake anyone can pull

#### Owner Can't Immediately Unlock

1. Switch back to owner wallet
2. Try to unlock
3. You'll need to create an unlock request
4. Which requires... guardian approval!
5. So guardians can protect you even if you don't want them to (in an emergency)

#### Proper Unlock Process

1. Owner requests unlock
2. Guardians review the situation
3. Once it's confirmed safe, guardians approve unlock
4. Vault unlocks when threshold is met

#### What you learned

* Both owner and guardians can initiate lock (creates guardian transaction)
* Lock requires guardian approval to execute
* Unlock also requires guardian approval
* This creates a safety net for emergencies while maintaining consensus

✅ **Quest Complete!** You understand guardian emergency powers.

***

### Week 4 Tips

* **Lock requires guardian approval** - owner or guardian initiates, but needs consensus to execute
* **Unlock requires guardian approval** - prevents hackers from unlocking
* **Lock cancels pending recovery** - defensive tool for vault owner
* **7-day delay on recovery** - gives real owner time to intervene
* **Guardians can protect you** - even against your own compromised wallet
* **Lock/Unlock buttons** are in the right panel (Settings section) on the dashboard

***

### Need Help?

**Can't unlock my vault?**

* This is correct! Unlock requires guardian approval
* Switch to guardian wallets and approve the unlock request
* Once threshold is met, vault unlocks automatically

**Recovery request disappeared?**

* Did you lock the vault? Lock cancels pending recovery requests
* This is a security feature to protect against unauthorized recovery

**Guardian can't initiate recovery?**

* Make sure you're using a guardian wallet, not the owner wallet
* Check that the vault contract address is correct
* Verify the new owner address is valid

***

### Completion Reward

🎖️ **Emergency Response Expert Badge**

* Recovery Specialist achievement
* Security Guardian title

Continue to Week 5: Chaos & Integration Testing →
