project screenshot 1
project screenshot 2
project screenshot 3
project screenshot 4
project screenshot 5
project screenshot 6

Swapsage AI Oracle

SwapSage-AI is an AI-powered cross-chain DeFi assistant that simplifies token swaps across networks

Swapsage AI Oracle

Created At

Unite Defi

Project Description

SwapSage AI Oracle is a production-ready cross-chain platform that enables atomic swaps between Polygon and Stellar in both directions. Users can securely exchange tokens like MATIC, USDC, or XLM across these networks without needing a centralized bridge. It uses Hash Time Lock Contracts (HTLCs) to ensure that tokens are either swapped on both chains or refunded if one side fails. The platform supports two-way communication by locking tokens on one chain and releasing equivalent value on the other using shared cryptographic secrets. An AI assistant powered by GPT-4 allows users to initiate swaps through simple language commands and provides real-time insights and routing advice. SwapSage also integrates 1inch Fusion to offer optimal pricing and MEV protection. Stellar accounts are created automatically and funded with 1 XLM when needed. The frontend is built with React and Tailwind CSS, and the backend connects to both blockchains, 1inch APIs, and OpenAI. This system simplifies and secures cross-chain DeFi for users, developers, and institutions.

How it's Made

The system is deployed on Polygon mainnet with live smart contracts handling actual token swaps. Initially, we started development on testnets for cost-effective testing, but we quickly realized that 1inch API doesn't support testnets - they only provide real quotes on mainnet. This forced us to deploy directly to Polygon mainnet to access live 1inch functionality, which actually worked out great since Polygon gas fees are incredibly low (around $0.01-0.05 per deployment). The Tech Stack We Used Frontend - Modern React Stack We went with React 18 + TypeScript because, well, we're not savages. Added Vite for that lightning-fast development experience (seriously, it's like night and day compared to Create React App). For styling, we used Tailwind CSS with a custom space-themed design system - think neon cyan, purple gradients, and floating animations. It looks like something out of a sci-fi movie. The Blockchain Layer Here's where it gets interesting. We're not just connecting to one blockchain - we're bridging Polygon (Ethereum L2) and Stellar (completely different consensus mechanism). This is like trying to make a phone call between someone using a rotary phone and someone using a smartphone. Polygon side: We deployed our core smart contracts on mainnet:

SwapSageOracle (0xfB92409880a6c04FeDb1d4FD5a498699D48a5492): Price oracle with Chainlink integration for accurate cross-chain pricing SwapSageHTLC (0xc6e0eF2453f08C0fbeC4b6a038d23f4D3A00E1B1): Main Hash Time Lock Contract for atomic swap security SwapSageExecutor: Handles swap execution and coordination

Stellar side: We're using their native SDK and built-in DEX functionality. We also created a dedicated Stellar wallet that we pre-funded with XLM tokens to act as our bridge account. This wallet handles the Stellar side of all cross-chain transactions and maintains liquidity for smooth swaps. Stellar is actually perfect for this because it has atomic swaps and claimable balances built into the protocol itself. The Really Cool Stuff We Built

  1. 1inch Fusion Integration This is where it gets really interesting. We integrated with 1inch's Fusion API for MEV-protected swaps. This means users get the best possible rates without getting front-run by bots. The Fusion API is like having a personal trading assistant that finds the optimal route across all DEXs.
  2. Bridge Wallet Infrastructure Here's a crucial piece of our architecture. We created a dedicated Stellar wallet and funded it with XLM tokens to serve as our bridge account. This wallet acts as the liquidity provider on the Stellar side, enabling seamless cross-chain swaps. When someone wants to swap from Polygon to Stellar, our bridge wallet handles the Stellar transaction execution. We also handle the complexity of Stellar account creation - when users don't have Stellar accounts, we automatically create them as part of the swap process.
  3. HTLC Implementation We implemented Hash Time Lock Contracts for atomic swaps. This is the security mechanism that ensures either both sides of the swap happen or neither does. It's like a digital escrow service. The really clever part is that we implemented HTLC on both chains:

Polygon: Using Solidity smart contracts Stellar: Using their native claimable balances with hash predicates

  1. AI-Powered Natural Language Interface This is what makes SwapSage unique. We integrated Hugging Face GPT models for natural language processing, allowing users to interact with DeFi through simple conversation. Users can literally chat with the AI about their swaps:

"Swap 1 ETH to XLM" "Bridge 100 USDC to Stellar" "What's the best rate for MATIC to XLM?"

The AI parses user intent, extracts parameters (token amounts, source/destination chains), validates the request, and executes the appropriate cross-chain atomic swap. This eliminates the need for users to understand complex DeFi mechanics, liquidity pools, or cross-chain bridge protocols. SwapSage Oracle: The Price Intelligence Engine One of our key innovations is the SwapSageOracle contract. This isn't just a simple price feed - it's an intelligent pricing system that: Multi-Source Price Aggregation:

Integrates with Chainlink price feeds for reliable base prices Pulls real-time data from 1inch API for DEX rates Aggregates Stellar DEX pricing through their native orderbook Provides fallback pricing mechanisms for network failures

Cross-Chain Rate Calculations:

Calculates optimal exchange rates between Polygon and Stellar tokens Accounts for slippage, gas fees, and bridge costs Updates pricing dynamically based on liquidity conditions Enables users to get accurate quotes before committing to swaps

Use Cases:

Real-time Quotes: "What's the current MATIC to XLM rate?" Cost Estimation: Total swap cost including gas and bridge fees Arbitrage Detection: Identifying profitable cross-chain opportunities Risk Assessment: Slippage and price impact calculations

Production Deployment Strategy We initially began development on testnets (Sepolia for Polygon, Stellar testnet) for cost-effective development and testing. However, we discovered that 1inch API only provides real quotes and functionality on mainnet - testnets simply aren't supported. This was actually a blessing in disguise because it forced us to deploy to production early. Since Polygon gas fees are extremely low (around 25 gwei, costing only $0.01-0.05 total for deployment), we were able to deploy our entire contract suite to Polygon mainnet without breaking the budget. This gave us access to real 1inch quotes, live DEX data, and actual token liquidity. Currently Supported Swap Pairs:

MATIC ↔ XLM: Polygon to Stellar Lumens USDC ↔ XLM: USD Coin to Stellar Lumens USDT ↔ XLM: Tether to Stellar Lumens DAI ↔ XLM: Dai Stablecoin to Stellar Lumens

The Technical Challenges We Solved

  1. CORS Proxy System The 1inch API has CORS restrictions when called from browsers, so we implemented a proxy rotation system that tries multiple endpoints until one works. Not the most elegant solution, but it ensures reliability.
  2. Bridge Wallet Management We created and manage a dedicated Stellar bridge wallet that's pre-funded with XLM. This wallet acts as the liquidity source for all Stellar-side transactions. The wallet's seed is securely managed (though for development purposes, we use a dedicated test wallet).
  3. Multi-Layer Fallback System We built a robust fallback system for price feeds:

Primary: 1inch API for live market rates Secondary: Our oracle contracts for backup pricing Tertiary: Hardcoded fallback rates for emergency situations Final: User-estimated pricing as last resort

The UI/UX Innovation We didn't just build a functional bridge - we made it look amazing. The space-themed design with neon colors and floating animations makes it feel like you're trading in the future. We used Shadcn/ui components for consistency and accessibility. What Actually Works

Real transactions on Polygon mainnet Live 1inch quotes with MEV protection Automatic Stellar account creation HTLC-based atomic swaps AI-powered chat interface Production deployment with real contracts

What We Accomplished This is a production-ready cross-chain bridge that:

Handles real transactions on Polygon mainnet Integrates with live 1inch APIs for optimal routing Manages cross-chain liquidity through our bridge wallet Provides enterprise-grade security with HTLC atomic swaps Offers an intuitive AI-powered user experience Successfully bridges two completely different blockchain architectures

The technical achievement of connecting an EVM-compatible L2 (Polygon) with a non-EVM blockchain (Stellar) while integrating 1inch Fusion for MEV protection and adding natural language AI features represents a significant advancement in cross-chain DeFi accessibility.

background image mobile

Join the mailing list

Get the latest news and updates