Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Wallet Autopilot πŸš€

Automated wallet health management for Monad Testnet

The Wallet Autopilot is a comprehensive wallet health management dashboard and automation system built for the Monad testnet hackathon. It allows users to monitor and automate wallet maintenance through MetaMask Smart Accounts and Delegations.

🎯 Core Features

  • Auto-Revoke: Automatically revokes risky or unused token allowances
  • Spam Cleanup: Detects and removes spam tokens from wallets
  • Dust Consolidation: Consolidates small token balances into primary assets (ETH/USDC)
  • Delegated Execution: Agent performs actions on behalf of users via scoped permissions
  • Health Score Dashboard: Visual wallet health metrics and real-time monitoring

πŸ—οΈ Architecture

Frontend (Next.js 15 + React 19)
    ↓
Backend Agent Service (Node.js)
    ↓
Envio Indexer (Real-time blockchain events)
    ↓
Monad Testnet (Chain ID: 41454)

πŸ› οΈ Tech Stack

Frontend

  • Framework: Next.js 15 with React 19 RC
  • React 19 Features: React Compiler, useOptimistic, useTransition, Server Actions
  • Styling: Tailwind CSS
  • Web3: Wagmi v2, Viem, MetaMask Delegation Toolkit
  • State: TanStack Query (React Query)

Backend

  • Runtime: Node.js with TypeScript
  • Blockchain: Viem, MetaMask Delegation Toolkit
  • Indexing: Envio HyperIndex
  • Automation: Node-cron for scheduled checks
  • API: Express.js REST API

Blockchain

  • Network: Monad Testnet
  • Account Abstraction: MetaMask Smart Accounts (Hybrid Implementation)
  • Indexer: Envio for real-time event tracking

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm/pnpm
  • MetaMask wallet with Monad testnet configured
  • Monad testnet tokens (MON) from faucet

1. Clone and Install

# Clone repository
git clone <your-repo-url>
cd wallet-autopilot

# Install frontend dependencies
cd frontend
npm install

# Install backend dependencies
cd ../backend
npm install

2. Configure Environment Variables

Frontend (frontend/.env.local):

NEXT_PUBLIC_MONAD_RPC_URL=https://testnet.monad.xyz
NEXT_PUBLIC_MONAD_CHAIN_ID=41454
NEXT_PUBLIC_AGENT_ADDRESS=0x... # Your agent's address
NEXT_PUBLIC_API_URL=http://localhost:3001

Backend (backend/.env):

MONAD_RPC_URL=https://testnet.monad.xyz
AGENT_PRIVATE_KEY=0x... # Your agent's private key
AGENT_ADDRESS=0x... # Your agent's address
ENVIO_API_URL=http://localhost:8080/v1/graphql
PORT=3001

3. Set Up Envio Indexer

cd backend
pnpm install envio
pnpm envio dev

This will start the Envio indexer locally with Hasura GraphQL API on port 8080.

4. Run the Application

Terminal 1 - Backend Agent:

cd backend
npm run dev

Terminal 2 - Frontend:

cd frontend
npm run dev

Visit http://localhost:3000 to see the app!

5. Using Docker (Alternative)

docker-compose up

πŸ“š Project Structure

wallet-autopilot/
β”œβ”€β”€ frontend/                 # Next.js 15 + React 19 app
β”‚   β”œβ”€β”€ app/                 # Next.js app router
β”‚   β”‚   β”œβ”€β”€ page.tsx        # Main dashboard page
β”‚   β”‚   β”œβ”€β”€ layout.tsx      # Root layout with providers
β”‚   β”‚   └── providers.tsx   # Wagmi & React Query providers
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ WalletConnect.tsx
β”‚   β”‚   β”œβ”€β”€ HealthScore.tsx
β”‚   β”‚   β”œβ”€β”€ DelegationControls.tsx
β”‚   β”‚   └── AllowancesTable.tsx
β”‚   β”œβ”€β”€ hooks/              # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ useSmartAccount.ts
β”‚   β”‚   β”œβ”€β”€ useDelegation.ts
β”‚   β”‚   └── useWalletHealth.ts
β”‚   β”œβ”€β”€ lib/                # Utilities and configurations
β”‚   β”‚   β”œβ”€β”€ monad.ts       # Monad network config
β”‚   β”‚   β”œβ”€β”€ wagmi.ts       # Wagmi configuration
β”‚   β”‚   └── metamask.ts    # MetaMask integration
β”‚   └── types/              # TypeScript types
β”‚
β”œβ”€β”€ backend/                 # Node.js agent service
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ agent/          # Core agent logic
β”‚   β”‚   β”‚   β”œβ”€β”€ delegationRegistry.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ monitor.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ executor.ts
β”‚   β”‚   β”‚   └── ruleEngine.ts
β”‚   β”‚   β”œβ”€β”€ services/       # External services
β”‚   β”‚   β”‚   └── envio.ts
β”‚   β”‚   β”œβ”€β”€ config/
β”‚   β”‚   β”‚   └── monad.ts
β”‚   β”‚   └── index.ts        # Express server
β”‚   β”œβ”€β”€ abis/               # Contract ABIs
β”‚   β”œβ”€β”€ schema.graphql      # Envio GraphQL schema
β”‚   └── envio.config.yaml   # Envio configuration
β”‚
└── docs/                    # Documentation
    β”œβ”€β”€ claude.md           # Project context
    β”œβ”€β”€ Frontend.md         # React 19 guide
    β”œβ”€β”€ Metamask.md         # Smart Accounts guide
    β”œβ”€β”€ Envio.md            # Indexer setup
    β”œβ”€β”€ AgentService.md     # Backend guide
    β”œβ”€β”€ Monad.md            # Network guide
    └── Testing.md          # Testing guide

πŸ”‘ Key Features Implementation

1. Smart Account Creation

Users create a MetaMask Hybrid Smart Account on Monad testnet:

const smartAccount = await createSmartAccount(ownerAddress);

2. Delegation Granting

Users grant scoped delegation to the agent for specific actions:

const delegation = createDelegation({
  scope: {
    type: 'functionCall',
    targets: [tokenAddress],
    selectors: ['approve(address,uint256)'],
  },
  to: agentAccount,
  from: userSmartAccount,
});

3. Automated Monitoring

The agent monitors wallets every 5 minutes using Envio indexer data:

// Agent checks for risky approvals
const riskyApprovals = await getRiskyApprovals(walletAddress);
const actions = ruleEngine.evaluateAllApprovals(riskyApprovals);

4. Delegated Execution

Agent executes revocations without user signatures:

await executeDelegatedTransaction({
  smartAccount,
  delegation,
  transaction: {
    to: tokenAddress,
    data: revokeApprovalCalldata,
  },
});

πŸ§ͺ Testing

Unit Tests

# Frontend
cd frontend
npm test

# Backend
cd backend
npm test

E2E Tests

cd frontend
npm run test:e2e

πŸ“Š API Endpoints

Backend REST API (http://localhost:3001)

  • GET /api/wallet/:address/health - Get wallet health score
  • GET /api/wallet/:address/approvals - Get all approvals
  • GET /api/wallet/:address/approvals/risky - Get risky approvals
  • POST /api/delegation/register - Register new delegation
  • GET /api/delegation/:address - Get delegations for wallet

Envio GraphQL API (http://localhost:8080/v1/graphql)

query GetWalletHealth($address: String!) {
  WalletHealth(where: { walletAddress: { _eq: $address } }) {
    healthScore
    riskyApprovals
    spamTokens
  }
}

πŸ” Security Considerations

  1. Private Keys: Never commit .env files. Agent's private key must be secured.
  2. Delegation Scope: Agent only has permissions for approved actions.
  3. User Control: Users can revoke delegation instantly.
  4. Audit Trail: All automated actions are logged.

🌐 Monad Testnet Configuration

Add to MetaMask

await window.ethereum.request({
  method: 'wallet_addEthereumChain',
  params: [{
    chainId: '0xa1f6',
    chainName: 'Monad Testnet',
    rpcUrls: ['https://testnet.monad.xyz'],
    nativeCurrency: {
      name: 'Monad',
      symbol: 'MON',
      decimals: 18
    },
    blockExplorerUrls: ['https://explorer.testnet.monad.xyz']
  }]
});

πŸŽ“ Learning Resources

πŸ“ Development Workflow

  1. Start Envio Indexer: cd backend && pnpm envio dev
  2. Start Backend Agent: cd backend && npm run dev
  3. Start Frontend: cd frontend && npm run dev
  4. Connect MetaMask to Monad testnet
  5. Create Smart Account in the UI
  6. Grant Delegation to enable autopilot
  7. Monitor Dashboard for automated actions

πŸ› Troubleshooting

Common Issues

React Compiler Errors:

  • Ensure React 19 RC is installed
  • Check ESLint plugin configuration

Smart Account Not Deploying:

  • Check you have MON tokens for gas
  • Verify Monad RPC URL is correct

Envio Not Indexing:

  • Check contract addresses in envio.config.yaml
  • Verify network configuration

Delegation Failing:

  • Ensure delegation scope matches actions
  • Check agent has proper permissions

🀝 Contributing

This project was built for the Monad Testnet Hackathon. Contributions are welcome!

πŸ“„ License

MIT

πŸ† Hackathon Success Criteria

βœ… Functional Demo:

  • Working MetaMask Smart Accounts integration
  • Delegation flow functional
  • Deployed on Monad testnet

βœ… Automation Impact:

  • Successfully auto-revoke risky approvals
  • Detect and act on spam/dust tokens
  • Health score improvement demonstrated

βœ… User Experience:

  • Intuitive React 19 dashboard with instant feedback
  • Clear delegation visibility and control
  • Smooth transitions and optimistic updates

Built with ❀️ for Monad Testnet Hackathon πŸš€

About

The Wallet Autopilot is a personal wallet health management dashboard that allows users to monitor and automate wallet maintenance.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages