Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions IMPLEMENTATION_SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# Admin Revoke Panel - Implementation Summary

## Branch

`admin-revoke-panel`

## Completed Tasks

### ✅ 1. List Revocable Schedules with Revoke Button

**File**: `frontend/src/components/GrantorPanel.tsx`

- Created grantor dashboard component
- Displays all schedules created by connected wallet
- Shows schedule cards with:
- Label and beneficiary address
- Status badges (Active, Revoked, Completed)
- Revocability indicator
- Vesting progress bar
- Token amounts breakdown (total, vested, claimed, unvested)
- Revoke button only visible for active, revocable schedules
- Integrated with Freighter wallet context

### ✅ 2. Confirmation Modal with Impact Summary

**File**: `frontend/src/components/RevokeModal.tsx`

- Created comprehensive revocation confirmation modal
- **Impact Summary includes**:
- Total amount allocated
- Already vested amount
- Already claimed amount
- Unvested amount to be revoked
- Tokens to be returned to grantor
- **User Experience**:
- Warning banner about irreversible action
- Schedule details display
- Clear breakdown of token distribution
- Note about beneficiary's remaining claimable tokens
- Loading states during calculation
- Success/error feedback

### ✅ 3. Build XDR for revoke() Contract Call

**Implementation in**: `RevokeModal.tsx` (handleRevoke function)

- Uses `buildTransaction()` utility from `network.ts`
- Constructs proper ScVal arguments:
- Grantor address (Address type)
- Schedule ID (u32 type)
- Calls `revoke` method on vesting contract
- Handles transaction simulation
- Proper error handling for simulation failures

### ✅ 4. Show Post-Revocation State Clearly

**Implementation across components**:

- **Success Modal**: Shows confirmation with returned token amount
- **Schedule List**: Updates to show "Revoked" status badge
- **Visual Indicators**:
- Red "Revoked" badge with ban icon
- Revoke button removed from revoked schedules
- Schedule remains visible in list for audit trail
- **Auto-refresh**: Schedule list refreshes after successful revocation

## Additional Features Implemented

### Tab Navigation

**File**: `frontend/src/app/vesting/page.tsx`

- Added tab system to vesting page
- "My Vesting" tab: Beneficiary view (existing)
- "Grantor Dashboard" tab: New admin/grantor view
- Clean tab switching with icons

### Vesting Calculation Logic

- Accurate vesting calculation considering:
- Cliff period (no vesting before cliff)
- Linear vesting after cliff
- Full vesting after total duration
- Real-time progress calculation

### Error Handling

- Wallet connection checks
- Transaction failure handling
- Clear error messages
- Graceful degradation

## Files Created/Modified

### New Files

1. `frontend/src/components/RevokeModal.tsx` - Revocation confirmation modal
2. `frontend/src/components/GrantorPanel.tsx` - Grantor dashboard
3. `frontend/docs/ADMIN_REVOKE_FEATURE.md` - Feature documentation
4. `IMPLEMENTATION_SUMMARY.md` - This file

### Modified Files

1. `frontend/src/app/vesting/page.tsx` - Added tab navigation

## Technical Stack

- React with TypeScript
- Stellar SDK for contract interaction
- Freighter wallet integration
- Tailwind CSS for styling
- Lucide React for icons

## Testing Notes

- Currently uses mock data for UI development
- Ready for contract integration when vesting contract is deployed
- All TypeScript checks pass with no diagnostics

## Next Steps for Production

1. Replace mock data with actual contract calls:
- `get_schedules_by_grantor()` to fetch schedules
- `get_progress()` for accurate vesting calculations
2. Configure `CONTRACTS.vesting` address in `network.ts`
3. Test with deployed vesting contract on testnet
4. Add loading states for contract calls
5. Implement proper error handling for contract-specific errors
6. Add transaction history/audit log
7. Consider adding batch revocation feature

## Contract Method Used

```rust
pub fn revoke(
env: Env,
grantor: Address,
schedule_id: u32,
) -> Result<i128, VestingError>
```

**Requirements**:

- Grantor must authenticate
- Schedule must exist and belong to grantor
- Schedule must be revocable
- Schedule must not already be revoked

**Returns**: Amount of unvested tokens returned to grantor
153 changes: 153 additions & 0 deletions frontend/docs/ADMIN_REVOKE_FEATURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
# Admin/Grantor Revoke Panel

## Overview

The Admin/Grantor Revoke Panel allows grantors (organizations or individuals who created vesting schedules) to revoke active vesting schedules and recover unvested tokens.

## Features

### 1. Grantor Dashboard

- **Location**: Vesting page → "Grantor Dashboard" tab
- **Access**: Available to any connected wallet that has created vesting schedules
- **Displays**:
- List of all vesting schedules created by the connected wallet
- Schedule status (Active, Revoked, Completed)
- Revocability indicator
- Vesting progress visualization
- Token amounts (total, vested, claimed, unvested)

### 2. Revoke Button

- **Visibility**: Only shown for schedules that are:
- Active (status = 0)
- Revocable (revocable = true)
- **Action**: Opens confirmation modal with impact summary

### 3. Revocation Confirmation Modal

Shows detailed impact before revocation:

- **Schedule Details**:
- Label/name
- Beneficiary address
- **Impact Summary**:
- Total amount allocated
- Already vested amount
- Already claimed amount
- Unvested amount (to be revoked)
- Tokens to be returned to grantor
- **Important Notes**:
- Warning that action cannot be undone
- Clarification that vested tokens remain claimable by beneficiary
- Only unvested tokens are returned

### 4. Transaction Flow

1. User clicks "Revoke" button
2. Modal calculates vesting progress and impact
3. User reviews impact summary
4. User confirms revocation
5. XDR is built for `revoke()` contract call
6. Transaction is signed via Freighter wallet
7. Transaction is submitted to Stellar network
8. Success confirmation shown
9. Schedule list refreshes to show updated state

### 5. Post-Revocation State

- Schedule status changes to "Revoked"
- Unvested tokens returned to grantor
- Vested tokens remain claimable by beneficiary
- Schedule no longer shows revoke button
- Visual indicator shows revoked status

## Technical Implementation

### Components

- **`GrantorPanel.tsx`**: Main dashboard component
- Fetches schedules by grantor
- Displays schedule cards with revoke buttons
- Calculates vesting progress
- Manages modal state

- **`RevokeModal.tsx`**: Confirmation modal
- Calculates revocation impact
- Builds XDR for revoke transaction
- Handles wallet signing
- Submits transaction
- Shows success/error states

### Contract Integration

- **Method**: `revoke(env: Env, grantor: Address, schedule_id: u32)`
- **Requirements**:
- Grantor must authenticate
- Schedule must exist
- Schedule must be revocable
- Schedule must not already be revoked
- **Returns**: Amount of unvested tokens returned (i128)

### Vesting Calculation

The modal calculates vested amount based on:

- Current time vs start time
- Cliff period (no vesting before cliff)
- Linear vesting after cliff
- Total duration

Formula:

```typescript
if (elapsed < cliff_duration) {
vested = 0;
} else if (elapsed >= total_duration) {
vested = total_amount;
} else {
vestingProgress = elapsed - cliff_duration;
vestingDuration = total_duration - cliff_duration;
vested = (total_amount * vestingProgress) / vestingDuration;
}
unvested = total_amount - vested;
```

## User Experience

### Navigation

1. Connect wallet via Freighter
2. Navigate to Vesting page
3. Click "Grantor Dashboard" tab
4. View list of created schedules
5. Click "Revoke" on desired schedule
6. Review impact and confirm

### Visual Feedback

- Loading states during data fetching
- Progress bars showing vesting status
- Color-coded status badges
- Clear token amount formatting
- Warning banners for irreversible actions
- Success/error notifications

### Error Handling

- Wallet not connected
- Schedule not found
- Unauthorized (not grantor)
- Schedule already revoked
- Schedule not revocable
- Transaction simulation failures
- Transaction submission failures

## Future Enhancements

- Real contract integration (currently using mock data)
- Batch revocation for multiple schedules
- Revocation history/audit log
- Email notifications to beneficiaries
- Partial revocation options
- Revocation reasons/notes
Loading