hackquest logo

Metacow

First social DEX with ERC-7715 automated copy trading. Follow traders, auto-copy swaps in <5s via MetaMask permissions. Real-time indexing by Envio. Fully non-custodial.

视频

技术栈

Ethers
Web3
Next
Node
Solidity
Metamask Flask

描述

MetaCow DEX - Social Trading with Automated Copy Trading

The First Social DEX with Under 5 Second Automated Copy Trading

metacow.vercel.app | Twitter @metacowdex | YouTube Demo

Powered by ERC-7715 Advanced Permissions & Envio Real-Time Indexing


🎯 Overview

MetaCow DEX is a revolutionary decentralized exchange that combines social trading with automated copy trading. Follow successful traders and automatically replicate their trades in under 5 seconds - without manual approvals, while maintaining complete custody of your funds.

The Magic:

  1. Trader swaps

  2. Envio indexes in <1 second

  3. Your trade executes automatically

  4. All non-custodial

One permission. Zero approvals. Infinite trades.

💡 The Problem We Solve

Traditional Copy Trading

MetaCow DEX

⏱️ 30-60 second delays

⚡ <5 second execution

🔄 Manual approval per trade

✅ One-time permission

🏦 Centralized custody

🔐 100% non-custodial

🤷 Opaque track records

📊 On-chain reputation

📉 Price slippage losses

📈 Minimal slippage

✨ Key Features

🤖 Automated Copy Trading

  • Set & Forget: Grant permission once with daily limits

  • Lightning Fast: Sub-5 second trade replication

  • Your Keys: Funds never leave your smart account

  • Full Control: Pause or revoke anytime

📱 Social Trading Feed

  • Real-Time: Every trade appears instantly

  • Follow Top Traders: See their moves first

  • Engage: Like, comment, share strategies

  • Transparent: All trades on-chain and verified

💱 Full DEX Functionality

  • Swap: Any token pair, 0.3% fees

  • Liquidity: Earn fees as LP provider

  • Rewards: Claim and auto-reinvest

  • Charts: Live price data powered by Envio

🛠️ Tech Stack

Core Technologies

  • ERC-7715 Advanced Permissions - Delegated transaction execution

  • MetaMask Smart Accounts Kit - Account abstraction (ERC-4337)

  • Envio - Sub-second blockchain indexing

  • Pimlico - ERC-4337 bundler for gas optimization

Stack Details

  • Frontend: Next.js 14, TypeScript, Tailwind CSS, Viem

  • Backend: Railway, Node.js, MongoDB

  • Blockchain: Solidity 0.8.22, OpenZeppelin Upgradeable, UUPS Proxy

  • Network: BNB Testnet (Chain ID: 97)

🔐 Advanced Permissions Usage

MetaCow DEX leverages ERC-7715 Advanced Permissions to enable seamless, non-custodial copy trading. Below are the key implementation links:

1. Requesting Advanced Permissions

Code Link: CopyTradeButton.tsx#L172-L213

// Permission Request Structure
const permissionRequest = {
  chainId: bscTestnet.id,
  expiry: currentTime + 2592000, // 30 days
  signer: {
    type: "account",
    data: { address: sessionAccount.address }
  },
  permission: {
    type: "erc20-token-periodic",
    data: {
      tokenAddress: inputToken,
      periodAmount: parseUnits(dailyLimit, 18),
      periodDuration: 86400, // 1 day
      startTime: currentTime,
      justification: `Allow CopyBot to spend up to ${dailyLimit} ${inputSymbol}/day`
    }
  },
  isAdjustmentAllowed: true
};

// Request via MetaMask Smart Accounts Kit
const grantedPermissions = await walletClient.requestExecutionPermissions([
  permissionRequest
]);

Key Features Implemented:

  • Token-Specific Permissions: Each permission is scoped to a specific ERC-20 token

  • Daily Spending Limits: User-defined periodic limits (e.g., 10 USDC/day)

  • Time-Bounded Security: 30-day expiration with instant revocation capability

  • Session Account Pattern: Backend bot executes via delegated permissions

  • Fine-Grained Control: Separate permissions per trader/token combination

2. Redeeming Advanced Permissions (Trade Execution)

Code Links:

// Step 1: Delegated Token Transfer (User → Session)
const delegatedTransferCall = {
  to: inputToken,
  data: transferCallData,
  permissionsContext, // ERC-7715 permission context
  delegationManager,  // Delegation manager address
};

const transferUserOpHash = await bundlerClient.sendUserOperationWithDelegation({
  account: sessionAccount,
  calls: [delegatedTransferCall],
  publicClient,
  entryPointAddress,
  nonce: currentNonce,
});

// Step 2-4: Session executes approve + swap + return
// All happening automatically without user interaction

4-Step Automated Flow:

  1. Transfer: Delegated transfer from user's smart account to session account

  2. Approve: Session approves DEX pair contract

  3. Swap: Session executes the trade

  4. Return: Session transfers output tokens back to user

3. Wallet Client with ERC-7715 Actions

Code Link: walletClient.ts#L5-L17

import { erc7715ProviderActions } from "@metamask/smart-accounts-kit/actions";

export function createClientWalletClient() {
  return createWalletClient({
    chain: bscTestnet,
    transport: custom(window.ethereum),
  }).extend(erc7715ProviderActions()); // ✅ Adds Advanced Permissions support
}

🚀 Envio Integration

Envio is the critical dependency that makes our sub-5 second copy trading possible. Without Envio's real-time indexing, this feature would not exist.

Why Envio is Essential

Traditional blockchain indexers have 10-30 second delays. MetaCow needs sub-second latency to:

  1. Detect trades instantly when master traders swap

  2. Trigger copy trades before price moves

  3. Update social feed in real-time

  4. Minimize slippage for followers

5 Key Integrations

1. Copy Trade Triggers (Most Critical)

Code Links:

// Poll Envio every 10 seconds for new swaps
const swaps = await fetchLatestSwaps(20);

// Match against active copy permissions
const copiers = activePermissions.filter(
  (p) => 
    p.traderAddress.toLowerCase() === swap.user.toLowerCase() &&
    p.inputToken?.toLowerCase() === swap.inputToken.toLowerCase()
);

// Execute copy trades instantly via ERC-7715
await executeCopyTrade({ permission, swap, amount });

Performance: Sub-1 second indexing enables our <5 second copy trade execution

2. Real-Time Social Feed

Code Link: envioClient.ts#L120-L145

query GetLatestSwaps($limit: Int!) {
  SwapEvent(
    order_by: { timestamp: desc }
    limit: $limit
  ) {
    id
    user
    inputToken
    outputToken
    inputAmount
    timestamp
    txHash
  }
}

Usage: Powers the social feed showing all trades instantly

3. Historical Price Charts

Code Link: envioClient.ts#L68-L98

export async function fetchPairSwaps(
  pairAddress: string,
  limit: number = 50
): Promise<EnvioSwapEvent[]> {
  // Fetch swap history for chart rendering
}

4. Volume & APR Tracking

Code Link: envioClient.ts#L30-L56

export async function getPairInfo(tokenA: string, tokenB: string) {
  // Returns: reserveA, reserveB, totalSwaps, lastSyncAt
  // Used for 24h volume and APR calculations
}

5. User Trade History

Code Link: envioClient.ts#L151-L175

export async function fetchUserSwaps(
  userAddress: string,
  limit: number = 20
): Promise<EnvioSwapEvent[]> {
  // Complete trade history via GraphQL
}

Envio Configuration

Indexer Repository: my-envio-indexer

GraphQL Endpoint: https://indexer.dev.hyperindex.xyz/d335f52/v1/graphql

Performance Metrics

  • Indexing Latency: <1 second from transaction confirmation

  • GraphQL Response Time: 50-200ms average

  • Event Types Indexed: 4 (Swapped, LiquidityAdded, LiquidityRemoved, PairCreated)

  • Polling Frequency: 10 seconds for copy trade monitoring

Copy Trading Flow

  1. Trader swaps on MetaCow DEX

  2. Envio indexes event (<1 second)

  3. Backend bot receives notification via polling

  4. Bot checks copy permissions in MongoDB

  5. Session account executes trade via ERC-7715 delegation

  6. Follower's trade completed (<5 seconds total)

  7. Social feed updates in real-time

📝 Smart Contracts

Core Contracts

  • MiniDexFactoryUpgradeable.sol - Pair creation and reputation management

  • MiniDexPairUpgradeable.sol - AMM logic, swaps, liquidity, rewards

Key Features

  • UUPS Upgradeable - Future-proof without redeployment

  • Constant Product AMM - x * y = k formula

  • 0.3% Trading Fees - Distributed to LP providers

  • LP Rewards - Claimable + auto-reinvest

🚀 Deployment

Live URLs

  • Frontend: metacow.vercel.app

  • Backend: Railway (session accounts + copy bot)

  • Envio: GraphQL + WebSocket endpoint

  • Network: BNB Smart Chain Testnet (Chain ID: 97)

Copy Trading Setup

  1. Find a trader in Social Feed

  2. Click "Auto Copy"

  3. Set daily limit (e.g., 10 USDC)

  4. Approve permission in MetaMask Flask

  5. Done! Future trades auto-copy in <5 seconds

🏆 Hackathon Qualifications

Most Creative Use of Advanced Permissions

Novel Innovation: First-ever automated social copy trading using ERC-7715
Real Problem Solved: Eliminates approval fatigue (10-20 approvals/day → 1 permission)
Session Account Pattern: Backend bot executes trades via delegated permissions
Fine-Grained Control: Daily spend limits per token (e.g., 10 USDC/day)
Time-Bounded Security: 30-day expiration with instant revocation
Production Ready: Fully functional with real blockchain transactions

The Flow: User grants permission → Session account created → Bot monitors Envio → Trader swaps → Bot executes copy in <5s → User earns automatically

Best Use of Envio

Critical Dependency: Copy trading impossible without Envio's speed
5 Key Integrations: Copy triggers, social feed, price charts, volume tracking, user history
Performance: Sub-second indexing enables core feature
Flexibility: GraphQL + WebSockets for maximum versatility
Comprehensive: Indexes 4 event types across all DEX operations

Best Social Media Presence

Active Documentation: Development journey on Twitter @metacowdex
Educational Content: ERC-7715 benefits and use cases
Community Engagement: Regular @MetaMaskDev tags and interactions
Visual Content: Screenshots, demo videos, architecture diagrams

Featured Tweet: Project Showcase

📱 Social Media Presence

As part of the Best Social Media Presence track, I've documented MetaCow DEX's journey on X (Twitter), showcasing how MetaMask Advanced Permissions revolutionized the user experience.

Main Project Thread: https://x.com/dhruvpanch0li/status/2002474906286731412
https://x.com/metacowdex

Key Highlights

🎯 Tagging: All posts tag @MetaMaskDev
📊 Journey Documentation: From concept to deployment
🚀 ERC-7715 Benefits: How Advanced Permissions enable copy trading
💡 User Experience: Before/after comparison of approval flows
🎥 Visual Content: Demo videos, architecture diagrams, UI screenshots

What the Journey Showcases

  1. Problem Identification: Traditional copy trading requires 10-20 approvals/day

  2. Solution Design: ERC-7715 enables one permission for infinite trades

  3. Implementation: Building session accounts with delegated permissions

  4. Integration: Combining with Envio for <5 second execution

  5. Results: Production-ready social DEX with automated copy trading

👨‍💻 Team

Dhruv Pancholi - Solo Developer

🔗 Resources

📊 Project Status

  • Status: ✅ Live on BNB Testnet

  • Build Progress: 95% Complete

  • Hackathon: MetaMask Advanced Permissions Dev Cook-Off

  • Last Updated: December 26, 2024

  • Version: 1.0.0


Built with ❤️ for the MetaMask Advanced Permissions Dev Cook-Off

Trade Smarter, Not Harder 🐮

 

本次黑客松进展

95% build is done

融资状态

50$ in Fair3hackathon
队长
DDhruv Pancholi
项目链接
赛道
DeFiSocialFiOther