What are Atomic Swaps?
Atomic swaps enable trustless token exchanges between different blockchains without intermediaries. The “atomic” property ensures that either both parties receive their tokens, or neither does - there is no possibility of only one party being paid. The 1inch Cross Chain SDK implements atomic swaps using a combination of:- Hash-locked escrows on both chains
- Time-locked refund mechanisms for safety
- Cryptographic secrets for authorization
How Cross-Chain Swaps Work
A cross-chain swap in the 1inch SDK follows this workflow:Step-by-Step Process
-
Order Creation: Maker creates a cross-chain order specifying:
- Source token and amount
- Destination token and amount
- Hash-lock derived from secret(s)
- Time-locks for each stage
- Escrow Deployment: Resolver deploys escrows on both chains with safety deposits
- Secret Revelation: Maker reveals the secret after verifying escrow deployments
- Withdrawal: Resolver uses the secret to withdraw from both escrows
Security Guarantees
The SDK provides multiple layers of security:Atomicity: The swap either completes fully or can be cancelled and refunded on both chains.
Hash-Lock Protection
Funds are locked using a cryptographic hash. Only someone with the original secret can unlock them:Safety Deposits
Resolvers must lock safety deposits in both source and destination escrows. This ensures:- Resolvers are incentivized to complete swaps
- Users can claim safety deposits if resolvers fail
- Economic penalties for malicious behavior
Time-Locked Stages
Each escrow progresses through time-locked stages: Source Chain:Timeout and Refund Mechanisms
Cancellation Windows
If a swap doesn’t complete, funds can be refunded during cancellation periods:- Private Cancellation: Only the maker can cancel and retrieve funds
- Public Cancellation (source chain only): Anyone can trigger cancellation
Rescue Delay
The default rescue delay is 7 days:Refund Process
- Original token amount
- Safety deposit (if resolver failed to complete)
Example: Creating an Atomic Swap Order
The SDK handles most complexity internally. You only need to manage secret generation and revelation timing.
Best Practices
- Always verify escrow deployments before revealing secrets
- Store secrets securely until ready to reveal
- Monitor order status to track swap progress
- Set appropriate time-locks based on chain finality times
- Use sufficient safety deposits to incentivize proper resolver behavior
Related Concepts
- Hash Locks - Cryptographic locking mechanism
- Escrows - Smart contract escrow implementation
- Secrets Management - How to safely handle secrets