Skip to content

SwiftBridge/swiftbridge-contracts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

swiftbridge-contracts

contracts for swift

SwiftBridge Contracts

Smart contracts for SwiftBridge - A Telegram-based crypto bridge enabling offramp, onramp, swaps, and P2P transfers on Base network.

πŸ—οΈ Architecture

Core Contracts

  1. UserRegistry.sol - Maps Telegram usernames to wallet addresses
  2. EscrowManager.sol - Handles buy/sell escrow for fiat on/offramp
  3. P2PTransfer.sol - Enables P2P transfers via Telegram username
  4. SwapRouter.sol - Token swaps via Uniswap V3 on Base

Features

  • βœ… 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

πŸ“¦ Installation

# 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 .env

πŸ”§ Configuration

Update .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_address

πŸš€ Deployment

Compile Contracts

npm run compile

Run Tests

npm test

Deploy to Base Sepolia Testnet

npm run deploy:testnet

Verify Contracts

npm run verify

Deploy to Base Mainnet

npm run deploy:mainnet

πŸ“ Contract Addresses

Base Sepolia Testnet

Addresses will be saved to deployments/84532.json after deployment.

Uniswap V3 on Base Sepolia

  • Router: 0x94cC0AaC535CCDB3C01d6787D6413C739ae12bc4
  • Quoter: 0xC5290058841028F1614F3A6F0F5816cAd0df5E27
  • WETH: 0x4200000000000000000000000000000000000006

🎯 Usage Examples

Register Username

// User registers their Telegram username
userRegistry.registerUsername("myusername");

Create Buy Escrow (Bot/Operator)

// 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 to Username

// Send 50 USDT to @friend
p2pTransfer.sendToUsername(
    "friend",
    usdtAddress,
    50 * 10**6,
    "Thanks for dinner!"
);

Swap Tokens

// Swap 100 USDC for ETH
swapRouter.swapExactTokensForETH(
    usdcAddress,
    100 * 10**6,
    0.01 ether, // minimum ETH out
    3000 // 0.3% pool fee
);

πŸ§ͺ Testing

Run the full test suite:

npm test

Run specific test file:

npx hardhat test test/UserRegistry.test.ts

Generate coverage report:

npm run coverage

πŸ“Š Gas Reporting

Enable gas reporting in .env:

REPORT_GAS=true
COINMARKETCAP_API_KEY=your_api_key

Then run tests:

npm test

πŸ” Security

  • 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

Audit Status

⚠️ NOT AUDITED - These contracts have not been professionally audited. Use at your own risk.

πŸ“– Contract Documentation

UserRegistry

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

EscrowManager

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

P2PTransfer

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

SwapRouter

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

πŸ› οΈ Development

Project Structure

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

Adding New Tests

Create test files in test/ directory following the pattern:

import { expect } from "chai";
import { ethers } from "hardhat";

describe("ContractName", function () {
  // Your tests here
});

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License.

πŸ”— Links

⚠️ Disclaimer

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.

πŸ“ž Support

For questions and support, please open an issue in the GitHub repository.

About

contracts for swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •