Skip to content
Β 
Β 

Latest commit

Β 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DotSafe Logo

DotSafe

AI-Powered Wallet Risk Guard for Passet Hub

Scan, score, and revoke risky token approvals β€” before they drain your wallet.

Solidity Next.js Polkadot Gemini AI License: MIT Tests Hackathon


Hackathon Track Stop Approvals


🧩 The Problem

Every time you interact with a dApp, you grant token approvals β€” permission for smart contracts to spend your tokens. Most users approve unlimited amounts and never think about it again.

The risk? A single exploited or malicious contract can drain your entire balance through a forgotten approval.

DotSafe solves this by giving you full visibility, AI-powered risk analysis, and one-click batch revocation on Passet Hub. It also monitors XCM-connected parachains from one dashboard so you can act before stale approvals become exploitable.


✨ Features

πŸ” Instant Approval Scanner

Scans all active ERC-20 and NFT approvals for your connected wallet. Fetches on-chain events, verifies live allowances, and filters out already-revoked permissions.

πŸ€– AI Risk Scoring

Each approval is analyzed by Google Gemini 2.0 Flash against multiple risk vectors β€” unverified code, unlimited allowances, contract age, proxy patterns, and more. Scores range from 0–100 with SAFE / CAUTION / DANGER ratings.

⚑ Batch Revoke

Select multiple risky approvals and revoke them all in a single transaction. No more tedious one-by-one revocations. Supports both ERC-20 and NFT (ERC-721/ERC-1155) approvals.

🌐 XCM Cross-Chain Guard

Monitor approvals across Polkadot parachains β€” Moonbeam, Astar, and Acala β€” via XCM (Cross-Consensus Messaging). Send risk alerts and request scans on remote chains.

πŸ“Š Risk Dashboard

Real-time analytics with an animated risk meter, approval breakdown by danger level, and actionable insights β€” all in a sleek, dark-themed interface.

πŸ›‘οΈ Approval Policies

Set per-token spending limits, time-bounded approval windows, and spender whitelists enforced on-chain through the ApprovalPolicy contract.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Frontend (Next.js 16)              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  β”‚ Dashboard  β”‚  β”‚ XCM Page β”‚  β”‚ Landing   β”‚            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β”‚        β”‚              β”‚                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
β”‚  β”‚   Hooks (Thirdweb SDK)   β”‚  β”‚  /api/score-contract β”‚  β”‚
β”‚  β”‚  β€’ useApprovalScanner    β”‚  β”‚  (Gemini AI Scoring) β”‚  β”‚
β”‚  β”‚  β€’ useBatchRevoke        β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚  β”‚  β€’ useXCMGuard           β”‚             β”‚              β”‚
β”‚  β”‚  β€’ useAIScoring          β”‚      β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚  β€’ useApprovalPolicy     β”‚      β”‚  Gemini 2.0 β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚    Flash     β”‚      β”‚
β”‚            β”‚                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜
             β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚             Passet Hub (420420417)            β”‚
     β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”‚
     β”‚  β”‚ Approval     β”‚ β”‚  Batch     β”‚ β”‚  XCM    β”‚  β”‚
     β”‚  β”‚ Scanner      β”‚ β”‚  Revoker   β”‚ β”‚  Guard  β”‚  β”‚
     β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
     β”‚                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
     β”‚                 β”‚      Approval Policy      β”‚ β”‚
     β”‚                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚ XCM
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚        Parachains      β”‚            β”‚
                    β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”  β”‚
                    β”‚  β”‚Moonbeam β”‚ β”‚ Astar  β”‚β”‚ β”‚ Acala β”‚  β”‚
                    β”‚  β”‚  2004   β”‚ β”‚  2006  β”‚β”‚ β”‚ 2000  β”‚  β”‚
                    β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Layer Technology
Smart Contracts Solidity 0.8.24 Β· Hardhat Β· OpenZeppelin 5.x
Frontend Next.js 16 Β· React 19 Β· TypeScript Β· Tailwind CSS 4
Web3 ThirdWeb SDK v5
AI Engine Google Gemini 2.0 Flash
State Zustand 5
Animations Framer Motion
Fonts Syne Β· Manrope Β· Space Mono
Chains Passet Hub (Chain ID 420420417)

πŸ“¦ Smart Contracts

Deployed Addresses

Contract Address
ApprovalScanner 0x723BE9931C1417Ef00B7f6f426e387Dc5099E602
BatchRevoker 0xe136a28958DBd9Ad3A8c942B91e01064f95a1E8f
XCMGuard 0x78e0C8c7a94122211E07b14562C5d781aDA748dC
ApprovalPolicy 0x19eDb13a0FA86a89aC7fD14f811769230B3Bf00A

ApprovalScanner

Read-only helper to verify live approval states on-chain.

Function Description
checkAllowance(token, owner, spender) Returns current ERC-20 allowance
checkApprovalForAll(nft, owner, operator) Checks NFT operator approval
batchCheckAllowances(tokens[], spenders[], wallet) Batch-check multiple allowances in one call
getAtRiskValue(tokens[], spenders[], wallet) Sum of all token value at risk

BatchRevoker

Execute multiple revocations atomically in a single transaction.

Function Description
batchRevokeERC20(tokens[], spenders[]) Revoke multiple ERC-20 approvals
batchRevokeNFT(nfts[], operators[]) Revoke NFT operator approvals
revokeERC20(token, spender) Single-revoke convenience method

Events: BatchRevoked(wallet, count) Β· SingleRevokeFailed(token, spender, index)

XCMGuard

Cross-chain approval monitoring via Polkadot XCM.

Function Description
sendRiskAlert(destParaId, suspicious, xcmMsg) Send risk alert to a parachain
requestCrossChainScan(destParaId, wallet, xcmMsg) Initiate remote chain scan
getMonitoredParachains() Returns monitored parachain IDs
isMonitored(paraId) Check if a parachain is monitored

ApprovalPolicy

User-configurable spending rules and trusted spender allowlists.

Function Description
registerWallet() Registers a wallet for policy management
setPolicy(token, maxAllowance, approvalWindow, whitelistOnly) Writes a token-specific approval policy
removePolicy(token) Removes a token-specific approval policy
addWhitelistEntry(spender) Adds a spender to the allowlist
removeWhitelistEntry(spender) Removes a spender from the allowlist

πŸš€ Getting Started

Prerequisites

  • Node.js β‰₯ 18
  • npm or yarn
  • A wallet with Passet Hub configured (Chain ID: 420420417)
  • Gemini API Key β€” Get one at ai.google.dev

1. Clone the Repository

git clone https://github.com/Shikhyy/DotSafe.git
cd DotSafe

2. Smart Contracts Setup

cd contracts
npm install

# Compile contracts & generate TypeChain types
npm run compile

# Run tests
npm run test

# Deploy to Passet Hub
npm run deploy:testnet

3. Frontend Setup

cd frontend
npm install

# Create environment file
cat > .env.local << EOF
GEMINI_API_KEY=your_gemini_api_key_here
NEXT_PUBLIC_THIRDWEB_CLIENT_ID=your_thirdweb_client_id
EOF

# Start development server
npm run dev

Open http://localhost:3000 and connect your wallet.


βš™οΈ Configuration

Environment Variables

Variable Required Description
GEMINI_API_KEY βœ… Google Gemini API key for AI risk scoring
NEXT_PUBLIC_THIRDWEB_CLIENT_ID βœ… ThirdWeb client ID for wallet connection
DEPLOYER_PRIVATE_KEY βœ…* Deployer wallet private key (*for contract deployment only)
POLKADOT_TESTNET_RPC ❌ Custom RPC endpoint for Passet Hub

Supported Networks

Network Chain ID Currency Explorer
Passet Hub 420420417 PAS (18 decimals) Subscan

XCM Monitored Parachains

Parachain Para ID Status
Moonbeam 2004 βœ… Active
Astar 2006 βœ… Active
Acala 2000 βœ… Active

πŸ§ͺ Testing

cd contracts
npm run test

73/73 tests passing βœ… β€” Test coverage includes:

  • ApprovalScanner (7 tests) β€” Allowance checks, batch operations, at-risk value calculations
  • BatchRevoker (13 tests) β€” Single/batch revocations, event emissions, input validation
  • XCMGuard (32 tests) β€” Parachain monitoring, cross-chain alerts, access control
  • ApprovalPolicy (21 tests) β€” Policy management, whitelist updates, registration flow

πŸ€– AI Risk Scoring Engine

API Routes

Route Method Description
/api/score-contract POST AI risk scoring via Gemini β€” returns risk level, score, and reasoning
/api/resolve-spender GET Resolve spender contract address to protocol name
/api/token-metadata GET Fetch token symbol, name, and decimals from on-chain

DotSafe uses Google Gemini 2.0 Flash to analyze each approved contract against multiple risk vectors:

Risk Factor Score Impact
Unverified source code +30
Unlimited allowance +25
Contract age < 30 days +20
Upgradeable proxy pattern +15
Approval idle > 90 days +10
Known audited contract βˆ’15

Risk Levels:

Level Score Range Action
🟒 SAFE 0 – 29 No action needed
🟑 CAUTION 30 – 59 Review recommended
πŸ”΄ DANGER 60 – 100 Revoke immediately

πŸ“ Project Structure

DotSafe/
β”œβ”€β”€ contracts/                  # Hardhat smart contract workspace
β”‚   β”œβ”€β”€ contracts/              # Solidity source files
β”‚   β”‚   β”œβ”€β”€ ApprovalScanner.sol # On-chain approval verification
β”‚   β”‚   β”œβ”€β”€ BatchRevoker.sol    # Atomic batch revocation
β”‚   β”‚   β”œβ”€β”€ XCMGuard.sol        # Cross-chain XCM monitoring
β”‚   β”‚   β”œβ”€β”€ ApprovalPolicy.sol  # On-chain approval rules
β”‚   β”‚   └── mocks/              # Test mock contracts
β”‚   β”œβ”€β”€ test/                   # Contract test suite
β”‚   β”œβ”€β”€ ignition/               # Deployment modules
β”‚   β”œβ”€β”€ typechain-types/        # Auto-generated TypeScript types
β”‚   └── hardhat.config.ts       # Hardhat configuration
β”‚
β”œβ”€β”€ frontend/                   # Next.js frontend application
β”‚   β”œβ”€β”€ app/                    # App router pages
β”‚   β”‚   β”œβ”€β”€ page.tsx            # Landing page
β”‚   β”‚   β”œβ”€β”€ dashboard/          # Main scanning dashboard
β”‚   β”‚   β”œβ”€β”€ policy/             # Approval policy manager
β”‚   β”‚   β”œβ”€β”€ history/            # Revocation history
β”‚   β”‚   β”œβ”€β”€ xcm/                # XCM cross-chain monitor
β”‚   β”‚   └── api/                # AI scoring API route
β”‚   β”œβ”€β”€ components/             # React components
β”‚   β”‚   β”œβ”€β”€ scanner/            # Approval list & risk cards
β”‚   β”‚   β”œβ”€β”€ stats/              # Risk meter analytics
β”‚   β”‚   β”œβ”€β”€ wallet/             # Wallet connection
β”‚   β”‚   └── xcm/                # Parachain cards
β”‚   β”œβ”€β”€ hooks/                  # Custom React hooks
β”‚   β”œβ”€β”€ lib/                    # Chains, ABIs, types, config
β”‚   └── store/                  # Zustand global state
β”‚
└── README.md

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-feature
  3. Commit your changes: git commit -m 'feat: add my feature'
  4. Push to the branch: git push origin feature/my-feature
  5. Open a Pull Request

🎬 Demo & Testing Guide

See DEMO.md for a step-by-step guide to test DotSafe, including:

  • Connecting a wallet on Passet Hub testnet
  • Scanning approvals and viewing AI risk scores
  • Batch revoking dangerous approvals
  • Managing approval policies
  • Exploring XCM cross-chain monitoring

Contract addresses on Passet Hub Testnet (420420417):

Contract Subscan Link
ApprovalScanner 0x723B...9602
BatchRevoker 0xe136...8f
XCMGuard 0x78e0...8dC
ApprovalPolicy 0x19eD...00A

πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file for details.


Built for the Polkadot ecosystem 🟣

Protecting wallets, one approval at a time.

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages