AI agent that enables gasless token swaps on Arc Network using X402 & Uniswap v4 Integration
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.
Architecture & Implementation
/app/page.tsx):
/app/api/agent/swap/route.ts):
/lib/facilitator.ts):
/verify and /settle endpoints/lib/agent/swap.ts):
/lib/x402.ts):
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

