A revolutionary Automated Market Maker (AMM) that enables trading of Token-2022 tokens with active transfer hooks on Solana. This project solves the critical limitation where major AMMs don't support Token-2022 with transfer hooks, unlocking the full potential of programmable tokens for DeFi.
- Transfer Hook Support: Full integration with Token-2022 transfer hooks
- KYC Validation: Built-in KYC compliance through transfer hooks
- Transfer Limits: Configurable daily and per-transaction limits
- Whitelisted Hooks: Secure whitelist system for approved hook programs
- Pool Creation: Create liquidity pools for any Token-2022 token
- Swapping: Token-to-SOL and SOL-to-token swaps with hook validation
- Liquidity Management: Add and remove liquidity with LP token rewards
- Fee System: 0.3% trading fee with proper distribution
- Hook Validation: Every transfer is validated through the hook program
- KYC Enforcement: Users must have valid KYC status to transfer tokens
- Transfer Limits: Prevents abuse through configurable limits
- Authority Management: Secure program authority management
- Modern UI: Beautiful, responsive interface built with Next.js
- Wallet Integration: Support for Phantom, Solflare, and other Solana wallets
- Real-time Updates: Live pool data and transaction status
- Error Handling: Comprehensive error messages and validation
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Frontend │ │ AMM Program │ │ Hook Program │
│ (Next.js) │◄──►│ (Anchor) │◄──►│ (Anchor) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │ │
│ │ │
▼ ▼ ▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Wallet │ │ Token-2022 │ │ KYC Data │
│ Connection │ │ Program │ │ Storage │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Rust (latest stable)
- Solana CLI (latest)
- Anchor CLI (latest)
- Node.js (v18 or later)
- Yarn or npm
git clone <repository-url>
cd token2022-hook-amm# Build all programs
anchor build
# Or build individually
cd programs && anchor build
cd ../hook && anchor build# Deploy AMM program
cd programs
anchor deploy --provider.cluster devnet
# Deploy Hook program
cd ../hook
anchor deploy --provider.cluster devnetUpdate the program IDs in Anchor.toml and hookswap/lib/anchor.ts with the deployed addresses.
cd hook
anchor test --skip-local-validatorcd hookswap
yarn install
yarn devVisit http://localhost:3000 to access the application.
- Connect Wallet: Connect your Solana wallet (Phantom, Solflare, etc.)
- Navigate to "Create Token": Click on the "Create Token" tab
- Fill Token Details:
- Token Name: e.g., "My Awesome Token"
- Token Symbol: e.g., "MAT"
- Decimals: Usually 9 for most tokens
- Initial Supply: Total tokens to mint
- Create Token: Click "Create Hooked Token"
- Verify: The token will be created with transfer hooks enabled
- Navigate to "Create Pool": Click on the "Create Pool" tab
- Select Token: Choose your hooked token from the dropdown
- Add Initial Liquidity: Specify the amount of tokens and SOL to add
- Create Pool: Click "Create Pool"
- Confirm: The pool will be created and you'll receive LP tokens
- Navigate to "Swap": Click on the "Swap" tab
- Select Tokens: Choose the token you want to swap and SOL
- Enter Amount: Specify the amount to swap
- Review: Check the exchange rate and fees
- Swap: Click "Swap" to execute the transaction
- Navigate to "Pool": Click on the "Pool" tab
- Add Liquidity:
- Select your pool
- Enter token and SOL amounts
- Click "Add Liquidity"
- Remove Liquidity:
- Select your pool
- Enter LP token amount
- Click "Remove Liquidity"
token2022-hook-amm/
├── programs/ # AMM Anchor workspace
│ ├── programs/amm/ # AMM program (Rust)
│ ├── tests/ # AMM tests (TypeScript)
│ └── migrations/ # Deployment scripts
├── hook/ # Hook Anchor workspace
│ ├── programs/hook/ # Hook program (Rust)
│ ├── tests/ # Hook tests (TypeScript)
│ └── migrations/ # Deployment scripts
├── hookswap/ # Frontend application
│ ├── app/ # Next.js pages
│ ├── components/ # React components
│ ├── hooks/ # Custom React hooks
│ ├── lib/ # Utility functions
│ └── types/ # TypeScript types
└── README.md # This file
# Test AMM program
cd programs
anchor test
# Test Hook program
cd ../hook
anchor test
# Test frontend (if applicable)
cd ../hookswap
yarn test# Start local validator
solana-test-validator
# In another terminal, build and deploy
anchor build
anchor deploy
# Start frontend
cd hookswap
yarn dev- Every token transfer is validated through the hook program
- KYC status is checked before allowing transfers
- Transfer limits are enforced per user and per mint
- Failed validations prevent the transfer from completing
- Only approved hook programs can be used with the AMM
- Prevents malicious hook programs from being used
- Easy to add new approved programs to the whitelist
- Secure program authority management
- Ability to update authorities when needed
- Timestamp tracking for all authority changes
# Set cluster to devnet
solana config set --url devnet
# Deploy programs
anchor deploy --provider.cluster devnet
# Update program IDs in configuration files# Set cluster to mainnet
solana config set --url mainnet-beta
# Deploy programs (ensure proper testing first)
anchor deploy --provider.cluster mainnet-beta
# Update program IDs and frontend configuration- Transaction Speed: Optimized for fast execution
- Gas Efficiency: Minimal compute units for hook validation
- Scalability: Supports multiple tokens and pools
- Reliability: Robust error handling and recovery
- Fork the repository
- Create a 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
Built with ❤️ for the Solana ecosystem