Important
Please see the Demo video
Secure Cross-Chain Atomic Swaps between EVM Chains and NEAR Protocol
1Prime Protocol enables trustless, atomic swaps between EVM-compatible blockchains (Ethereum, Base, BSC, Polygon, Arbitrum) and NEAR Protocol using a sophisticated relayer-resolver architecture built on 1inch Fusion+ technology.
- Cross-Chain Compatibility: Seamless swaps between EVM chains ↔ NEAR Protocol
- Atomic Security: All-or-nothing execution prevents partial completion risks
- On-Chain Verification: Independent escrow verification before secret revelation
- Real-Time Updates: WebSocket-powered live order tracking
- 1inch Fusion+ Integration: Built on proven 1inch technology with NEAR extensions
- User-Friendly: Simple frontend interface with Apple Shortcuts integration
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend │ │ Relayer │ │ Resolver │
│ (Web + iOS) │◄──►│ (Orchestrator)│◄──►│ (Executioner) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Cross-Chain SDK │ │ EVM Contracts │ │ NEAR Contracts │
│ (TypeScript) │ │ (Solidity) │ │ (Rust) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Package | Purpose | Technology |
---|---|---|
1prime-website |
Frontend web application | Next.js, React, TailwindCSS |
cross-chain-sdk |
TypeScript SDK for cross-chain operations | TypeScript, 1inch Fusion+ SDK |
relayer |
Central orchestration service | Node.js, TypeScript, PostgreSQL |
resolver |
Order execution service | Node.js, TypeScript, Web3 |
evm-contracts |
Smart contracts for EVM chains | Solidity, Hardhat |
near-contracts |
Smart contracts for NEAR Protocol | Rust, near-sdk |
shortcut-auth |
Apple Shortcuts authentication | Swift, iOS Shortcuts |
The following diagram illustrates the complete flow of a cross-chain atomic swap:
- Secret Generation: Frontend generates a cryptographically secure random number
- Hash Creation: Secret is hashed using Keccak-256 to create
secretHash
- Order Preparation: Frontend calls
POST /orders/prepare
with:userSrcAddress
&userDstAddress
(source and destination addresses)amount
,fromToken
,toToken
(swap parameters)fromChain
,toChain
(blockchain identifiers)secretHash
(hashed secret for atomic locks)
- Fusion+ Order Creation: Relayer creates a 1inch Fusion+ order using patched SDK
- Order Return: Unsigned order with
orderHash
returned to frontend - User Signature: User signs the Fusion+ order with their wallet
- Order Submission: Signed order submitted via
POST /orders/submit
- Resolver Polling: Resolvers continuously poll
GET /orders
for new orders - Order Claiming: Resolver claims order via
POST /orders/{hash}/claim
- Order transitions to
claimed
phase - Resolver becomes
assignedResolver
- Order transitions to
- Escrow Deployment: Resolver deploys escrow contracts on both chains
- Deployment Confirmation:
POST /orders/{hash}/escrow-deployed
with:- Contract addresses, transaction hashes, block numbers
- On-chain verification automatically performed:
- ✅ Contract existence verification
- ✅ Transaction hash validation
- ✅ USDC balance confirmation
- ✅ Block number matching
- Safety Verification: Frontend calls
GET /orders/{hash}/verify-escrows
- Independent verification that escrows are safe for secret revelation
- Prevents fund loss from malicious or incorrectly configured escrows
- Secret Submission: Once verified safe, frontend calls
POST /orders/{hash}/reveal-secret
- Submits the original random number (not the hash)
- Secret stored in database for resolver access
- Secret Broadcasting: Relayer broadcasts secret to all resolvers via WebSocket
- Atomic Completion: Resolver uses secret to unlock funds on both chains simultaneously
- Contract Validation: Verifies escrow contracts exist and are properly deployed
- Transaction Verification: Confirms deployment transactions using block explorers
- Balance Verification: Ensures escrows contain required USDC amounts
- Cross-Chain APIs: Uses native blockchain APIs (Etherscan, NearBlocks) for verification
- Hash Locks: Secret hash locks prevent premature fund access
- Time Locks: Cancellation timeouts protect against stuck transactions
- All-or-Nothing: Either both sides complete or both sides can recover funds
- Resolver Assignment: Only assigned resolver can deploy escrows for an order
- Verification Gates: Multiple verification steps before secret revelation
- WebSocket Security: Real-time updates without exposing sensitive data
- Node.js 18+
- pnpm 8+
- PostgreSQL 14+
- Rust (for NEAR contracts)
- Solidity compiler (for EVM contracts)
# Clone the repository
git clone https://github.com/unite-defi/1prime-protocol.git
cd 1prime-protocol
# Quick setup (installs dependencies and copies environment files)
pnpm setup
# Build all packages
pnpm build:all
# Start the relayer service
pnpm dev:relayer
# For production deployment
pnpm start:relayer
The pnpm setup
command automatically copies environment template files. Update them with your values:
DATABASE_URL=postgresql://user:password@localhost:5432/relayer
ETHERSCAN_API_KEY=your_etherscan_key
NEARBLOCKS_API_KEY=your_nearblocks_key
ETHEREUM_RPC_URL=https://eth-mainnet.alchemyapi.io/v2/your-key
NEAR_RPC_URL=https://rpc.mainnet.near.org
NEXT_PUBLIC_RELAYER_URL=http://localhost:3000
NEXT_PUBLIC_CHAIN_ENV=testnet
- Frontend Documentation - Web interface and user experience
- Cross-Chain SDK - TypeScript SDK for developers
- Relayer Service - Central orchestration service
- Resolver Service - Order execution and settlement
- EVM Contracts - Ethereum-compatible smart contracts
- NEAR Contracts - NEAR Protocol smart contracts
- Apple Shortcuts - iOS integration
- Relayer REST API - Complete OpenAPI specification
- WebSocket Events - Real-time update documentation
- Apple Shortcuts API - iOS Shortcuts integration
- Ethereum Mainnet (Chain ID: 1)
- Ethereum Sepolia (Chain ID: 11155111) - Testnet
- Base (Chain ID: 8453)
- BNB Smart Chain (Chain ID: 56)
- Polygon (Chain ID: 137)
- Arbitrum One (Chain ID: 42161)
- NEAR Mainnet (Chain ID: mainnet)
- NEAR Testnet (Chain ID: 398) - Testnet
- USDC ↔ NEAR/USDC (Primary focus)
- ETH ↔ NEAR (Native tokens)
- WETH ↔ NEAR (Wrapped tokens)
# Quick Setup
pnpm setup # Install dependencies and copy environment files
pnpm setup:env # Copy relayer .env.example to .env
pnpm setup:db # Database setup instructions
# Development
pnpm dev:relayer # Start relayer in development mode
pnpm start:relayer # Start relayer in production mode
# Building
pnpm build:all # Build all packages
pnpm build:relayer # Build relayer service only
pnpm build:cross-chain-sdk # Build SDK only
# Testing
pnpm test:all # Run all tests
pnpm test:relayer # Test relayer service only
# Linting & Formatting
pnpm lint:all # Lint all packages
pnpm format:all # Format all code
# Cleanup
pnpm clean # Remove all node_modules and build artifacts
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes and add tests
- Run the test suite:
pnpm test:all
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Follow TypeScript best practices
- Add comprehensive tests for new features
- Update documentation for API changes
- Ensure all linting passes before submitting
This project is licensed under the MIT License - see the LICENSE file for details.
- Website: https://1prime.io
- Documentation: https://docs.1prime.io
- Discord: https://discord.gg/1prime
- Twitter: @1PrimeProtocol
- GitHub: https://github.com/unite-defi/1prime-protocol
This protocol handles cross-chain value transfers. Please:
- Audit smart contracts before mainnet deployment
- Test thoroughly on testnets before using mainnet
- Report security issues responsibly to security@1prime.io
- Never reveal secrets to unverified escrows
Built with love by the 1Prime Team
Bridging the future of cross-chain DeFi, one atomic swap at a time.