UniSwapX402Arc

AI agent that enables gasless token swaps on Arc Network using X402 & Uniswap v4 Integration

UniSwapX402Arc

Created At

HackMoney 2026

Project Description

An innovative decentralized finance (DeFi) application that leverages token swapping by eliminating the need for users to hold native tokens for gas fees. Built on the Arc Network testnet, this project combines AI-powered agentic commerce with the X402 payment protocol to enable completely gasless token swaps through Uniswap v4. The core innovation lies in its payment architecture, instead of requiring users to pay gas fees in native tokens, UniX402Arc leverages EIP-3009 (transferWithAuthorization) to allow users to pay swap fees directly in USDC through cryptographic signatures. An AI agent acts as an intermediary that receives the payment authorization, verifies it through the PayAI Facilitator, settles the payment onchain, and then executes the swap on behalf of the user. Users simply connect their wallet, specify the tokens and amounts they want to swap, sign a single gasless payment authorization, and the AI agent handles everything else from payment settlement to swap execution on Uniswap v4's singleton architecture. This project demonstrates the future of agentic commerce where AI agents can autonomously perform complex DeFi operations on behalf of users while maintaining complete security and trustlessness through smart contract interactions and cryptographic verification.

How it's Made

Architecture & Implementation

  1. Frontend Layer- (/app/page.tsx):
    • Premium landing page with animated backgrounds, feature cards, and "How It Works" section
    • Interactive swap interface with real-time status updates
    • Wallet connection via Wagmi with MetaMask/injected provider support
    • Responsive design with glassmorphism effects and micro-animations
  2. API Gateway- (/app/api/agent/swap/route.ts):
    • Implements the X402 payment flow (402 challenge → verification → settlement)
    • Validates payment signatures through PayAI Facilitator
    • Triggers the AI agent after successful payment
    • Comprehensive error handling and debugging logs
  3. Payment Infrastructure-(/lib/facilitator.ts):
    • Axios-based client for PayAI Facilitator API
    • Handles /verify and /settle endpoints
    • Type-safe interfaces for payment requirements and responses
  4. AI Swap Agent- (/lib/agent/swap.ts):
    • Implements Uniswap v4 swap execution via SwapRouter contract
    • Uses flash accounting and the unlock/callback pattern
    • Includes slippage protection and transaction simulation
    • Manages agent wallet with private key for autonomous execution
  5. Client-Side Payment- (/lib/x402.ts):
    • Generates EIP-3009 compliant payment signatures
    • Creates base64-encoded payment headers for X402 protocol
    • Uses ethers.js for cryptographic signing

Technical Innovations Arc Network Testnet(Chain ID: 5042002) - Layer 2 blockchain that uses USDC as the native gas token. Arc's unique property of using USDC as the native gas token made this project particularly elegant. Since users are already paying fees in USDC and swapping USDC-based pairs, there's no need for token bridging or complex gas token management.

Uniswap v4: architecture required implementing the unlock/callback pattern. The agent calls PoolManager.unlock(), which triggers a callback where the actual swap occurs. This is more complex than traditional DEX integrations but provides better gas efficiency and composability.V4 is relatively new with limited documentation. We had to study the core contracts and examples to understand the unlock/callback pattern.

Agentic Execution The AI agent is a server-side wallet that autonomously executes swaps after payment verification. It maintains its own USDC balance for gas (since Arc uses USDC as the gas token) and can perform complex multi-step operations without user interaction.

Ethers.js 6:Ethereum library for smart contract interactions and transaction signing Payment Protocol:

X402 Protocol - HTTP 402 Payment Required standard for agentic commerce

EIP-3009 -Ethereum standard for gasless token transfers via cryptographic signatures PayAI Facilitator - Third-party service for verifying and settling X402 payments onchain

Challenges Overcome

  • Uniswap v4 Documentation:V4 is relatively new with limited documentation. We had to study the core contracts and examples to understand the unlock/callback pattern.
  • EIP-3009 Nonce Management: Ensuring unique nonces without a database required using cryptographically random bytes32 values.
  • Cross-Chain RPC Reliability: Arc testnet RPC endpoints occasionally had issues, requiring fallback strategies and comprehensive error handling.
  • Payment Signature Verification: Debugging why signatures failed required deep diving into the EIP-3009 standard and PayAI's expected format.
background image mobile

Join the mailing list

Get the latest news and updates

UniSwapX402Arc | ETHGlobal