contracts for swift
Smart contracts for SwiftBridge - A Telegram-based crypto bridge enabling offramp, onramp, swaps, and P2P transfers on Base network.
- UserRegistry.sol - Maps Telegram usernames to wallet addresses
- EscrowManager.sol - Handles buy/sell escrow for fiat on/offramp
- P2PTransfer.sol - Enables P2P transfers via Telegram username
- SwapRouter.sol - Token swaps via Uniswap V3 on Base
- β Username-based transfers (send crypto to @username)
- β Escrow system for fiat on/offramp
- β Token swaps with multiple pool fee tiers
- β Pending transfer claims for unregistered users
- β Dispute resolution mechanism
- β Pausable for emergency stops
- β Fee collection system
# Clone the repository
git clone https://github.com/your-org/swiftbridge-contracts
cd swiftbridge-contracts
# Install dependencies
npm install
# Copy environment file
cp .env.example .env
# Edit .env with your values
nano .envUpdate .env file with your settings:
PRIVATE_KEY=your_private_key_without_0x
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
BASESCAN_API_KEY=your_basescan_api_key
FEE_COLLECTOR_ADDRESS=your_fee_collector_addressnpm run compilenpm testnpm run deploy:testnetnpm run verifynpm run deploy:mainnetAddresses will be saved to deployments/84532.json after deployment.
- Router: 0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4
- Quoter: 0xC5290058841028F1614F3A6F0F5816cAd0df5E27
- WETH: 0x4200000000000000000000000000000000000006
// User registers their Telegram username
userRegistry.registerUsername("myusername");// Bot creates escrow when user wants to buy crypto
escrowManager.createBuyEscrow(
    userAddress,
    usdtAddress,
    100 * 10**6, // 100 USDT
    160000, // 160,000 Naira
    "PAY-REF-12345"
);// Send 50 USDT to @friend
p2pTransfer.sendToUsername(
    "friend",
    usdtAddress,
    50 * 10**6,
    "Thanks for dinner!"
);// Swap 100 USDC for ETH
swapRouter.swapExactTokensForETH(
    usdcAddress,
    100 * 10**6,
    0.01 ether, // minimum ETH out
    3000 // 0.3% pool fee
);Run the full test suite:
npm testRun specific test file:
npx hardhat test test/UserRegistry.test.tsGenerate coverage report:
npm run coverageEnable gas reporting in .env:
REPORT_GAS=true
COINMARKETCAP_API_KEY=your_api_keyThen run tests:
npm test- Uses OpenZeppelin audited contracts
- ReentrancyGuard on all state-changing functions
- Pausable for emergency stops
- Access control with Ownable pattern
- Custom errors for gas efficiency
- SafeERC20 for token transfers
Maps Telegram usernames to wallet addresses with the following features:
- Username validation (5-32 characters, alphanumeric + underscore)
- 7-day cooldown for username updates
- Username removal functionality
- Pausable registration
Manages escrow for buy/sell operations:
- BUY: User pays Naira β Bot locks crypto β Release on confirmation
- SELL: User locks crypto β Bot pays Naira β Release on confirmation
- 24-hour timeout with auto-refund capability
- Dispute resolution system
- Operator management for trusted bots
Peer-to-peer transfers using Telegram usernames:
- Instant transfer if username registered
- Pending transfers for unregistered users
- Batch transfers to multiple recipients
- Claim pending transfers after registration
- Transfer history tracking
Token swaps via Uniswap V3:
- Multiple pool fee tiers (0.05%, 0.3%, 1%)
- ETH β Token swaps
- Token β Token swaps
- Quote functionality
- Auto-select best pool fee
- Slippage protection
swiftbridge-contracts/
βββ contracts/
β   βββ core/
β   β   βββ UserRegistry.sol
β   β   βββ EscrowManager.sol
β   β   βββ P2PTransfer.sol
β   β   βββ SwapRouter.sol
β   βββ interfaces/
β   βββ mocks/
βββ test/
β   βββ UserRegistry.test.ts
βββ scripts/
β   βββ deploy.ts
β   βββ verify.ts
βββ deployments/
βββ hardhat.config.ts
βββ package.json
Create test files in test/ directory following the pattern:
import { expect } from "chai";
import { ethers } from "hardhat";
describe("ContractName", function () {
  // Your tests here
});- Fork the repository
- Create your feature branch (git checkout -b feature/amazing-feature)
- Commit your changes (git commit -m 'Add amazing feature')
- Push to the branch (git push origin feature/amazing-feature)
- Open a Pull Request
This project is licensed under the MIT License.
This software is provided "as is", without warranty of any kind. Use at your own risk. Always conduct thorough testing and security audits before deploying to mainnet.
For questions and support, please open an issue in the GitHub repository.