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.
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
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:
Trader swaps
Envio indexes in <1 second
Your trade executes automatically
All non-custodial
One permission. Zero approvals. Infinite trades.
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 |
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
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
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
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
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)
MetaCow DEX leverages ERC-7715 Advanced Permissions to enable seamless, non-custodial copy trading. Below are the key implementation links:
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
Code Links:
Session Account Creation: sessionAccount.ts#L10-L35
Delegation Execution: tradeExecutor.ts#L160-L180
Bundler Client Setup: bundlerClient.ts#L27-L34
// 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 interaction4-Step Automated Flow:
Transfer: Delegated transfer from user's smart account to session account
Approve: Session approves DEX pair contract
Swap: Session executes the trade
Return: Session transfers output tokens back to user
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 is the critical dependency that makes our sub-5 second copy trading possible. Without Envio's real-time indexing, this feature would not exist.
Traditional blockchain indexers have 10-30 second delays. MetaCow needs sub-second latency to:
Detect trades instantly when master traders swap
Trigger copy trades before price moves
Update social feed in real-time
Minimize slippage for followers
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
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
Code Link: envioClient.ts#L68-L98
export async function fetchPairSwaps(
pairAddress: string,
limit: number = 50
): Promise<EnvioSwapEvent[]> {
// Fetch swap history for chart rendering
}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
}Code Link: envioClient.ts#L151-L175
export async function fetchUserSwaps(
userAddress: string,
limit: number = 20
): Promise<EnvioSwapEvent[]> {
// Complete trade history via GraphQL
}Indexer Repository: my-envio-indexer
GraphQL Endpoint: https://indexer.dev.hyperindex.xyz/d335f52/v1/graphql
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
Trader swaps on MetaCow DEX
Envio indexes event (<1 second)
Backend bot receives notification via polling
Bot checks copy permissions in MongoDB
Session account executes trade via ERC-7715 delegation
Follower's trade completed (<5 seconds total)
Social feed updates in real-time
MiniDexFactoryUpgradeable.sol - Pair creation and reputation management
MiniDexPairUpgradeable.sol - AMM logic, swaps, liquidity, rewards
✅ 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
Frontend: metacow.vercel.app
Backend: Railway (session accounts + copy bot)
Envio: GraphQL + WebSocket endpoint
Network: BNB Smart Chain Testnet (Chain ID: 97)
Find a trader in Social Feed
Click "Auto Copy"
Set daily limit (e.g., 10 USDC)
Approve permission in MetaMask Flask
Done! Future trades auto-copy in <5 seconds
✅ 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
✅ 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
✅ 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
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
🎯 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
Problem Identification: Traditional copy trading requires 10-20 approvals/day
Solution Design: ERC-7715 enables one permission for infinite trades
Implementation: Building session accounts with delegated permissions
Integration: Combining with Envio for <5 second execution
Results: Production-ready social DEX with automated copy trading
Dhruv Pancholi - Solo Developer
GitHub: @dhruv457457
Twitter: @dhruvpanch0li
Project: MetaCow DEX
Documentation: MetaMask Smart Accounts Kit
ERC-7715 Spec: Ethereum Improvement Proposals
Envio Docs: Envio Documentation
Repository: GitHub
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 🐮