Skip to content

panditdhamdhere/FlowSwap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

84 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

FlowSwap - Decentralized Exchange on Flow Blockchain

A production-ready decentralized exchange (DEX) built on Flow using Cadence smart contracts and React frontend.

πŸš€ Built on Flow

This project is built on the Flow blockchain and utilizes:

  • Cadence smart contracts for on-chain logic
  • Flow Client Library (FCL) for blockchain interaction
  • Flow testnet for deployment and testing
  • Flow-compatible wallets for user authentication

πŸ“‹ Deployed Contract Addresses (Flow Testnet)

Contract Address Description
FlowDEX 0x18f0d1d9cfa52c6d Main DEX contract with AMM functionality
TestToken 0x18f0d1d9cfa52c6d Test token (FLOW demo)
TestToken2 0x0ea4b4ea56a1260c Test token (USDC demo)
FungibleToken 0x9a0766d93b6608b7 Flow standard fungible token interface

πŸ”— View on Flowscan:

Features

  • Automated Market Maker (AMM): Constant product formula for price discovery
  • Liquidity Pools: Add and remove liquidity from trading pairs
  • Token Swaps: Swap between different tokens with slippage protection
  • Modern UI: Beautiful, responsive interface with animations
  • Flow Integration: Built with Flow Client Library (FCL)

Architecture

Smart Contracts (Cadence)

  • FlowDEX.cdc: Main DEX contract with liquidity and swap functionality
  • TestToken.cdc: Test fungible token for development
  • TestToken2.cdc: Second test token for trading pairs

Frontend (React + TypeScript)

  • Modern React application with TypeScript
  • Flow Client Library (FCL) for blockchain interaction
  • Tailwind CSS for styling
  • Framer Motion for animations
  • Zustand for state management

Project Structure

β”œβ”€β”€ cadence/
β”‚   β”œβ”€β”€ contracts/          # Smart contracts
β”‚   β”œβ”€β”€ transactions/       # Transaction templates
β”‚   └── scripts/           # Query scripts
β”œβ”€β”€ web/                   # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ hooks/         # Custom hooks
β”‚   β”‚   β”œβ”€β”€ transactions.ts # FCL transaction functions
β”‚   β”‚   └── fclConfig.ts   # Flow configuration
β”‚   └── package.json
β”œβ”€β”€ flow.json             # Flow project configuration
└── deploy.sh            # Deployment script

Getting Started

Prerequisites

  • Node.js 16+
  • Flow CLI
  • Git

Installation

  1. Clone the repository:
git clone https://github.com/panditdhamdhere/FlowSwap.git
cd FlowSwap
  1. Install frontend dependencies:
cd web
npm install
  1. Start the development server:
npm run dev

Deployment

βœ… Deployed to Flow Testnet

The contracts are already deployed to Flow testnet! You can interact with them using the addresses above.

Deploy to Flow Mainnet

  1. Update flow.json with mainnet addresses
  2. Ensure your account has sufficient FLOW tokens
  3. Deploy:
flow project deploy --network mainnet

Manual Deployment (if needed)

To deploy contracts manually to testnet:

# Deploy TestToken
flow accounts add-contract --network testnet --signer <account> ./cadence/contracts/TestToken.cdc

# Deploy TestToken2  
flow accounts add-contract --network testnet --signer <account> ./cadence/contracts/TestToken2.cdc

# Deploy FlowDEX
flow accounts add-contract --network testnet --signer <account> ./cadence/contracts/FlowDEX.cdc

Configuration

Flow Configuration (flow.json)

  • Contract addresses and aliases
  • Network endpoints (emulator, testnet, mainnet)
  • Account configurations
  • Deployment settings

Frontend Configuration (web/src/fclConfig.ts)

  • Network selection (emulator/testnet/mainnet)
  • Access node endpoints
  • Wallet discovery settings

Contract Details

All contracts are deployed on Flow testnet and can be verified using the links above. The contracts implement the Flow blockchain standards and are fully compatible with the Flow ecosystem.

Smart Contract Details

FlowDEX Contract

  • addLiquidity: Add liquidity to the pool
  • getReserveA/getReserveB: Get current reserves
  • getQuoteAtoB/getQuoteBtoA: On-chain quote helpers with 0.3% fee
  • swapAForB/swapBForA: On-chain swaps adjusting reserves (demo, no token vault ops)
  • Events: LiquidityAdded, Swap

Security Features

  • Input validation with pre-conditions
  • Slippage protection
  • Reentrancy protection
  • Access control

Frontend Features

Wallet Integration

  • Connect with Flow-compatible wallets
  • Account management
  • Transaction signing

Trading Interface

  • Add/remove liquidity
  • Token swaps
  • Real-time price updates
  • Balance display

UI/UX

  • Responsive design
  • Dark/light theme support
  • Smooth animations
  • Error handling and notifications

Development

Local Development

  1. Start Flow emulator:
flow emulator --contracts --persist
  1. Deploy contracts to emulator:
flow project deploy --network emulator
  1. Start frontend:
cd web && npm run dev

Testing

  • Smart contract testing with Flow CLI
  • Frontend testing with Jest/React Testing Library
  • Integration testing with testnet

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

MIT License - see LICENSE file for details

Support

For questions or issues:

Roadmap

  • Multi-token support
  • Advanced trading features
  • Governance token
  • Mobile app
  • Analytics dashboard
  • Cross-chain bridges

About

This is dex project on Flow Network

Resources

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published