Files
smom-dbis-138/frontend-dapp/ADMIN_PANEL_README.md
2026-03-02 12:14:09 -08:00

402 lines
13 KiB
Markdown

# Admin Panel - Mainnet Tether & Transaction Mirror
## Overview
A comprehensive web-based admin panel (dApp) for managing the MainnetTether, TransactionMirror, and TwoWayTokenBridge smart contracts on Ethereum Mainnet. This enhanced admin panel integrates advanced features from the Impersonator project including multi-signature wallet support, transaction management, impersonation mode, and comprehensive security features.
## Features
### Core Contract Administration
#### 🎯 Mainnet Tether Admin
- View contract information (admin address, pause status, anchored block count)
- Pause/Unpause contract
- Change admin address
- Query state proofs by block number
- View contract on Etherscan
#### 📋 Transaction Mirror Admin
- View contract information (admin address, pause status, mirrored transaction count)
- Pause/Unpause contract
- Change admin address
- Query mirrored transactions by transaction hash
- View contract on Etherscan
#### 🌉 Two-Way Bridge Admin
- View contract information (admin, canonical token, fee token, destination chains)
- Change admin address
- Add/update/remove destination chains
- Update fee token address
- View configured destination chains
- View contract on Etherscan (when deployed)
### Advanced Features
#### 📊 Dashboard
- Real-time analytics and statistics
- Admin activity overview
- Contract health monitoring
- Transaction success rate tracking
- Recent actions and audit logs
#### 👥 Multi-Signature Admin
- Create multi-sig proposals for admin actions
- Approval workflow (require multiple signatures)
- Visual approval status indicators
- Execute approved proposals
- Support for Gnosis Safe wallets
#### 🎭 Wallet Impersonation
- Impersonate any Ethereum address for testing
- Test admin functions from different perspectives
- View contract state as different addresses
- Toggle impersonation on/off
- Address validation and checksumming
#### 📝 Transaction Management
- Transaction queue with priority levels (LOW, NORMAL, HIGH, URGENT)
- Transaction history and status tracking
- Failed transaction retry mechanism
- Real-time status polling and confirmation tracking
- Batch operations for multiple actions
#### ⛽ Gas Optimization
- Real-time gas price recommendations from Etherscan
- Gas estimation for transactions
- EIP-1559 support (maxFeePerGas, maxPriorityFeePerGas)
- Cost calculation and optimization suggestions
- Multiple urgency levels (slow, standard, fast)
#### 📋 Transaction Templates
- Predefined action templates
- Custom template builder
- Scheduled recurring actions (daily, weekly)
- Template categories (maintenance, emergency, configuration)
- Quick execution from templates
#### 🔄 Batch Operations
- Execute multiple admin actions in sequence
- Enable/disable individual actions
- Batch pause/unpause across contracts
- Sequential execution with delays
#### 👁️ Transaction Preview & Simulation
- Preview transactions before execution
- Decode function parameters
- Gas estimation
- Dry run simulation
- Transaction details display
#### 🔄 Transaction Retry
- Automatic retry for failed transactions
- Manual retry with updated parameters
- Retry history tracking
- Error analysis and resolution
#### 🚨 Emergency Controls
- Emergency pause all contracts simultaneously
- Confirmation requirements (type "EMERGENCY")
- Circuit breakers
- Recovery procedures
- Emergency action logging
#### 👤 Role-Based Access Control
- Multiple permission levels (Super Admin, Operator, Viewer)
- Granular permissions per function
- Role assignment and management
- Permission matrix display
- Access control enforcement
#### ⏰ Time-Locked Actions
- Schedule sensitive operations with time delays
- Configurable delay periods
- Admin transfer protection
- Threshold change protection
- Scheduled execution tracking
#### 💼 Wallet Management
- Deploy new Safe wallets for admin use
- Owner management (add/remove)
- Threshold configuration
- Wallet balance display
- Multi-wallet support
#### 💰 Wallet Balances
- Real-time balance monitoring
- Multiple wallet tracking
- Native token balances (ETH)
- Token balance support (future)
- Balance history
#### 💾 Wallet Backup & Export
- Encrypted wallet configuration backup
- Secure data export/import
- Password-protected backups
- Complete admin data backup
- Audit log export
#### 🌐 Multi-Chain Admin
- Chain selector and switching
- Multi-chain contract management
- Unified admin interface
- Chain-specific configurations
- Cross-chain operations (future)
#### ⏲️ Scheduled Actions
- Cron-like scheduling for recurring tasks
- Daily and weekly schedules
- Automatic execution
- Schedule management
- Next execution tracking
#### 🔧 Off-Chain Services Integration
- State Anchoring Service status monitoring
- Transaction Mirroring Service status
- Service health checks
- Endpoint configuration
- Service information display
#### 📜 Audit Logs
- Complete audit trail of all admin actions
- Searchable and filterable logs
- Export to JSON
- Status filtering (success/failure)
- Timestamp tracking
#### ⚡ Priority Queue
- Transaction queuing with priority levels
- Queue management UI
- Priority-based execution
- Queue filtering
- Next execution tracking
#### 🔐 Session Management
- Auto-logout after inactivity
- Session timeout (configurable, default 1 hour)
- Session time remaining display
- Activity tracking
- Secure session storage
#### 📈 Analytics & Monitoring
- Admin activity metrics
- Contract health indicators
- Transaction analytics
- Success rate tracking
- Performance metrics
## Prerequisites
1. **Wallet Connection**: MetaMask, WalletConnect, or Coinbase Wallet
2. **Network**: Must be connected to **Ethereum Mainnet** (Chain ID: 1)
3. **Admin Privileges**: Your wallet address must be the admin of the contract
## Contract Addresses
- **MainnetTether**: `0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619`
- **TransactionMirror**: `0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9`
- **TwoWayTokenBridge L1**: Not deployed (will show warning if accessed)
## Usage
### Accessing the Admin Panel
1. Start the development server:
```bash
cd frontend-dapp
npm run dev
```
2. Navigate to `http://localhost:3002/admin` (or click "Admin" in the navigation)
3. Connect your wallet:
- Click the "Connect Wallet" button
- Select your wallet provider (MetaMask, WalletConnect, etc.)
- Ensure you're connected to Ethereum Mainnet
4. Verify you're the admin:
- The admin panel will show the current admin address
- Only the admin address can execute write operations
### Common Operations
#### Pausing/Unpausing Contracts
1. Navigate to the appropriate tab (Mainnet Tether or Transaction Mirror)
2. Click "Pause Contract" to pause or "Unpause Contract" to resume
3. Confirm the transaction in your wallet
4. Wait for confirmation (transaction will be shown with Etherscan link)
#### Changing Admin Address
1. Enter the new admin address in the "New Admin Address" field
2. Click "Set Admin"
3. Confirm the transaction in your wallet
4. **Important**: Ensure the new admin address is correct - this cannot be undone without the new admin
#### Adding Destination Chain (TwoWay Bridge)
1. Enter the chain selector (e.g., `16015286601757825753` for Chain 138)
2. Enter the L2 bridge contract address
3. Click "Add Destination"
4. Confirm the transaction
## Security Features
### Enhanced Security Measures
1. **Encrypted Storage**: Sensitive wallet data encrypted using Web Crypto API (AES-GCM)
2. **Rate Limiting**: Configurable rate limits for admin functions to prevent abuse
3. **Session Management**: Auto-logout after inactivity (default 1 hour)
4. **Time-Locked Actions**: Sensitive operations require time delays
5. **Multi-Signature Support**: Support for Gnosis Safe multi-sig wallets
6. **Audit Logging**: Complete audit trail of all admin actions
7. **Role-Based Access**: Granular permissions and access control
8. **Emergency Procedures**: Emergency pause controls with confirmation
### Security Considerations
⚠️ **CRITICAL**: Admin functions have significant security implications:
1. **Admin Transfer**: Changing the admin address transfers all control. Make sure the new address is correct and secure.
2. **Pause Function**: Pausing a contract stops all operations. Only pause in emergency situations.
3. **Private Key Security**: Never share your admin private key. Use hardware wallets for admin accounts when possible.
4. **Multi-sig Recommendation**: Use multi-sig wallets (Gnosis Safe) for production deployments
5. **Impersonation Mode**: Only use impersonation for testing - all actions are logged
6. **Time-Locked Actions**: Use time locks for sensitive operations like admin changes
7. **Backup Security**: Keep wallet backup passwords secure and stored separately
8. **Rate Limiting**: Be aware of rate limits to avoid lockouts during emergencies
## Technical Details
### Technology Stack
- **React** + **TypeScript**: UI framework
- **wagmi** + **viem**: Web3 integration and contract interactions
- **Tailwind CSS**: Styling with utility-first approach
- **React Router**: Navigation
- **react-hot-toast**: Notifications
- **@safe-global/protocol-kit**: Gnosis Safe SDK integration (replaces deprecated safe-core-sdk)
- **@safe-global/api-kit**: Safe API client
- **ethers.js**: Additional Ethereum utilities (v5)
- **Web Crypto API**: Encryption for sensitive data storage
### Contract Interaction
The admin panel uses wagmi hooks for contract interactions:
- `useReadContract`: Read contract state (admin, paused, counts, etc.)
- `useWriteContract`: Execute write operations (pause, setAdmin, etc.)
- `useWaitForTransactionReceipt`: Monitor transaction confirmations
### ABIs
Contract ABIs are located in:
- `src/abis/MainnetTether.ts`
- `src/abis/TransactionMirror.ts`
- `src/abis/TwoWayTokenBridge.ts`
### Configuration
Contract addresses are configured in:
- `src/config/contracts.ts`
## Development
### Project Structure
```
frontend-dapp/
├── src/
│ ├── pages/
│ │ └── AdminPanel.tsx # Main admin panel page
│ ├── components/
│ │ └── admin/
│ │ ├── MainnetTetherAdmin.tsx
│ │ ├── TransactionMirrorAdmin.tsx
│ │ ├── TwoWayBridgeAdmin.tsx
│ │ ├── AdminDashboard.tsx
│ │ ├── MultiSigAdmin.tsx
│ │ ├── ImpersonationMode.tsx
│ │ ├── TransactionQueue.tsx
│ │ ├── TransactionRetry.tsx
│ │ ├── GasOptimizer.tsx
│ │ ├── BatchOperations.tsx
│ │ ├── TransactionTemplates.tsx
│ │ ├── TransactionPreview.tsx
│ │ ├── EmergencyControls.tsx
│ │ ├── RoleBasedAccess.tsx
│ │ ├── TimeLockedActions.tsx
│ │ ├── WalletDeployment.tsx
│ │ ├── WalletBalance.tsx
│ │ ├── WalletBackup.tsx
│ │ ├── MultiChainAdmin.tsx
│ │ ├── ScheduledActions.tsx
│ │ ├── OffChainServices.tsx
│ │ ├── AuditLogViewer.tsx
│ │ ├── TransactionQueuePriority.tsx
│ │ ├── OwnerManagement.tsx
│ │ ├── TransactionStatusPoller.tsx
│ │ └── SessionManager.tsx
│ ├── contexts/
│ │ └── AdminContext.tsx # Admin state management
│ ├── types/
│ │ └── admin.ts # TypeScript types
│ ├── utils/
│ │ ├── constants.ts # Constants and configuration
│ │ ├── encryption.ts # Encryption utilities
│ │ ├── security.ts # Security utilities
│ │ ├── rateLimiter.ts # Rate limiting
│ │ ├── sessionManager.ts # Session management
│ │ └── ens.ts # ENS utilities
│ ├── helpers/
│ │ └── admin/
│ │ └── gasOracle.ts # Gas price oracle
│ ├── abis/ # Contract ABIs
│ ├── config/
│ │ └── contracts.ts # Contract addresses
│ └── App.tsx # Routes configuration
```
### Adding New Features
1. **New Contract Function**: Add the function to the appropriate ABI file
2. **UI Component**: Update the corresponding admin component
3. **Testing**: Test on a testnet first before using on mainnet
## Troubleshooting
### "Please switch to Ethereum Mainnet"
- Ensure your wallet is connected to Mainnet (Chain ID: 1)
- Click your wallet extension and switch networks
### "Transaction failed" or "User rejected"
- Verify you have sufficient ETH for gas fees
- Ensure you're the contract admin
- Check the transaction error details in your wallet
### Contract not loading
- Verify contract addresses in `src/config/contracts.ts`
- Check RPC provider connectivity
- Ensure contracts are deployed on Mainnet
### TwoWayTokenBridge shows "Not Deployed"
- This is expected if the contract hasn't been deployed yet
- Set the address in `src/config/contracts.ts` once deployed
## Support
For issues or questions:
1. Check contract addresses and network connection
2. Verify admin privileges
3. Review transaction errors in wallet
4. Check Etherscan for contract state
## Links
- MainnetTether on Etherscan: https://etherscan.io/address/0x15DF1D5BFDD8Aa4b380445D4e3E9B38d34283619
- TransactionMirror on Etherscan: https://etherscan.io/address/0x4CF42c4F1dBa748601b8938be3E7ABD732E87cE9
---
**Last Updated**: 2025-01-22