Skip to content

TopTrenDev/bnb-fourmeme-smart-contract

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Four.meme Fork Smart Contract

License: MIT Solidity Hardhat BNB Chain

A complete, production-ready Four.meme fork smart contract system for BNB Chain that enables users to create, launch, swap, and migrate meme tokens with advanced security features, fair launch mechanics, and comprehensive migration capabilities.

✨ Key Features

🎯 Core Functionality

  • πŸͺ™ No-Code Token Creation: Create meme tokens through smart contracts
  • πŸš€ Fair Launch Mechanics: No pre-sales or exclusive allocations
  • πŸ”„ Token Swapping: Direct token-to-token swapping with real-time quotes
  • πŸ’§ Liquidity Management: Add/remove liquidity with yield farming support
  • πŸ“Š Price Oracle: Real-time price tracking and market data
  • πŸ”„ Migration System: Token and platform migration capabilities

πŸ›‘οΈ Security Features

  • πŸ€– Anti-Bot Protection: Cooldown periods and transaction limits
  • πŸ‹ Anti-Whale Protection: Maximum transaction and wallet limits
  • πŸ”’ ReentrancyGuard: Protection against reentrancy attacks
  • ⏸️ Pausable: Emergency pause functionality
  • πŸ‘‘ Ownable: Admin controls for platform management
  • βœ… Input Validation: Comprehensive parameter validation
  • πŸ” Access Control: Role-based permissions

πŸš€ Advanced Features

  • πŸ’§ Automatic Liquidity: Direct integration with PancakeSwap
  • πŸ”’ Liquidity Locking: Optional liquidity lock periods
  • πŸ”₯ Deflationary Mechanism: Token burning capabilities
  • πŸ“ˆ Migration Support: Token upgrades and platform migrations
  • 🌐 Frontend Integration: Complete Web3 integration and React components

πŸ“ Project Structure

β”œβ”€β”€ contracts/                    # Smart Contracts
β”‚   β”œβ”€β”€ MemeToken.sol            # Standard meme token with security features
β”‚   β”œβ”€β”€ MemeTokenFactory.sol     # Factory for creating tokens
β”‚   β”œβ”€β”€ LaunchPlatform.sol       # Advanced launch platform with liquidity
β”‚   β”œβ”€β”€ TokenSwap.sol            # Direct token-to-token swapping
β”‚   β”œβ”€β”€ LiquidityManager.sol     # Liquidity management and yield farming
β”‚   β”œβ”€β”€ PriceOracle.sol          # Price tracking and market data
β”‚   β”œβ”€β”€ TokenMigration.sol       # Token migration and upgrades
β”‚   └── PlatformMigration.sol    # Platform-wide migration system
β”œβ”€β”€ scripts/                     # Deployment & Interaction Scripts
β”‚   β”œβ”€β”€ deploy.js                # Main deployment script
β”‚   β”œβ”€β”€ createToken.js           # Token creation script
β”‚   β”œβ”€β”€ launchWithLiquidity.js   # Launch with liquidity script
β”‚   β”œβ”€β”€ swapTokens.js            # Token swapping script
β”‚   β”œβ”€β”€ manageLiquidity.js       # Liquidity management script
β”‚   β”œβ”€β”€ migrateTokens.js         # Token migration script
β”‚   └── migratePlatform.js       # Platform migration script
β”œβ”€β”€ test/                        # Comprehensive Test Suite
β”‚   β”œβ”€β”€ MemeToken.test.js        # Token contract tests
β”‚   └── TokenMigration.test.js   # Migration functionality tests
β”œβ”€β”€ frontend-examples/           # Frontend Integration Examples
β”‚   β”œβ”€β”€ web3-integration.js      # Complete Web3 integration class
β”‚   └── react-components.jsx     # Ready-to-use React components
β”œβ”€β”€ deployments/                 # Deployment records
β”œβ”€β”€ tokens/                      # Created token records
β”œβ”€β”€ launches/                    # Launch records
β”œβ”€β”€ swaps/                       # Swap transaction records
β”œβ”€β”€ migrations/                  # Migration records
β”œβ”€β”€ package.json                 # Dependencies and scripts
β”œβ”€β”€ hardhat.config.js           # Hardhat configuration
β”œβ”€β”€ env.example                  # Environment variables template
└── README.md                    # This file

πŸ› οΈ Installation & Setup

Prerequisites

  • Node.js (v16 or higher)
  • npm or yarn
  • Git
  • BNB Chain wallet (MetaMask recommended)

Quick Setup

  1. Clone the repository

    git clone <repository-url>
    cd bnb-fourmeme-fork-smart-contract
  2. Install dependencies

    npm install
    # or
    yarn install
  3. Set up environment variables

    cp env.example .env

    Edit .env with your configuration:

    # Private key for deployment (without 0x prefix)
    PRIVATE_KEY=your_private_key_here
    
    # BSCScan API key for contract verification
    BSCSCAN_API_KEY=your_bscscan_api_key_here
  4. Compile contracts

    npm run compile

πŸš€ Quick Start Guide

1. Deploy the Complete System

Deploy to BSC Testnet:

npm run deploy:testnet

Deploy to BSC Mainnet:

npm run deploy:mainnet

This deploys all contracts:

  • MemeTokenFactory
  • LaunchPlatform
  • TokenSwap
  • LiquidityManager
  • PriceOracle
  • TokenMigration
  • PlatformMigration

2. Create Your First Token

Edit scripts/createToken.js with your token parameters:

const TOKEN_NAME = "MyMemeToken";
const TOKEN_SYMBOL = "MMT";
const TOTAL_SUPPLY = ethers.utils.parseEther("1000000000"); // 1 billion
const MAX_TRANSACTION = ethers.utils.parseEther("10000000"); // 10M (1%)
const MAX_WALLET = ethers.utils.parseEther("50000000"); // 50M (5%)

Run the script:

npx hardhat run scripts/createToken.js --network testnet

3. Launch with Automatic Liquidity

Edit scripts/launchWithLiquidity.js with your parameters:

const BNB_LIQUIDITY = ethers.utils.parseEther("1.0"); // 1 BNB
const LIQUIDITY_PERCENT = 8000; // 80% of tokens
const LOCK_DURATION = 30 * 24 * 60 * 60; // 30 days

Run the script:

npx hardhat run scripts/launchWithLiquidity.js --network testnet

4. Swap Tokens

Edit scripts/swapTokens.js with token addresses:

const TOKEN_IN_ADDRESS = "TOKEN_IN_ADDRESS_HERE";
const TOKEN_OUT_ADDRESS = "TOKEN_OUT_ADDRESS_HERE";
const SWAP_AMOUNT = ethers.utils.parseEther("1000"); // 1000 tokens

Run the script:

npx hardhat run scripts/swapTokens.js --network testnet

5. Manage Liquidity

Edit scripts/manageLiquidity.js with your parameters:

const TOKEN_ADDRESS = "TOKEN_ADDRESS_HERE";
const BNB_AMOUNT = ethers.utils.parseEther("0.5"); // 0.5 BNB
const TOKEN_AMOUNT = ethers.utils.parseEther("1000000"); // 1M tokens
const ACTION = "add"; // "add", "remove", or "create"

Run the script:

npx hardhat run scripts/manageLiquidity.js --network testnet

πŸ“‹ Smart Contract Architecture

πŸͺ™ MemeToken.sol

Standard meme token with advanced security features

  • ERC20 Compliance: Standard token functionality
  • Anti-Bot Protection: 30-second cooldown periods
  • Anti-Whale Protection: Configurable transaction/wallet limits
  • Deflationary Mechanism: Token burning capabilities
  • Trading Controls: Enable/disable trading functionality
  • Excluded Addresses: DEX and contract addresses exempt from limits

🏭 MemeTokenFactory.sol

Token creation factory with spam prevention

  • Token Creation: Standardized token deployment
  • User Limits: Maximum tokens per user (default: 5)
  • Fee Management: Launch fees for platform sustainability
  • Token Tracking: Complete metadata and history storage
  • Admin Controls: Platform management and configuration
  • Trading Enablement: Creator-controlled trading activation

πŸš€ LaunchPlatform.sol

Advanced launch platform with liquidity provision

  • PancakeSwap Integration: Direct DEX integration
  • Fair Launch Mechanics: No pre-sales or exclusive allocations
  • Liquidity Locking: Optional lock periods for security
  • Automatic Listing: Immediate DEX listing
  • Configurable Parameters: Flexible launch configuration
  • LP Token Burning: Optional liquidity token burning

πŸ”„ TokenSwap.sol

Direct token-to-token swapping system

  • Constant Product Formula: AMM-style price calculation
  • Real-Time Quotes: Instant swap price calculation
  • Fee Management: Configurable swap fees
  • Transaction History: Complete swap record tracking
  • Supported Tokens: Whitelist-based token support
  • Anti-Dust Protection: Minimum swap amounts

πŸ’§ LiquidityManager.sol

Advanced liquidity management and yield farming

  • PancakeSwap Integration: Direct liquidity provision
  • Position Tracking: User liquidity position management
  • LP Token Management: Liquidity token handling
  • Yield Farming Ready: Compatible with farming protocols
  • TVL Tracking: Total value locked monitoring
  • Emergency Controls: Emergency withdrawal capabilities

πŸ“Š PriceOracle.sol

Real-time price tracking and market data

  • PancakeSwap Integration: Direct pair data access
  • Price Calculation: Real-time token price in BNB
  • Market Cap Calculation: Token market cap tracking
  • Price Change Tracking: Percentage change monitoring
  • USD Conversion: BNB price-based USD conversion
  • Freshness Validation: Price data freshness checks

πŸ”„ TokenMigration.sol

Token migration and upgrade system

  • Multiple Migration Types: Token upgrade, platform migration, token swap
  • Flexible Ratios: Configurable migration ratios
  • Time Controls: Start/end time management
  • User Tracking: Complete migration history
  • Emergency Controls: Emergency pause and withdrawal
  • Batch Migration: Admin batch migration capabilities

πŸ—οΈ PlatformMigration.sol

Platform-wide migration system

  • Contract Migration: All platform contract upgrades
  • Data Migration: User data, token data, liquidity data
  • Version Control: Platform version tracking
  • Progress Monitoring: Real-time migration progress
  • Emergency Updates: Emergency contract address updates
  • Migration Validation: Comprehensive migration validation

βš™οΈ Configuration & Parameters

πŸͺ™ Token Configuration

Parameter Description Example Default
Name Token name "MyMemeToken" Required
Symbol Token symbol "MMT" Required
Total Supply Total token supply 1,000,000,000 Required
Max Transaction Maximum transaction amount 10,000,000 (1%) Required
Max Wallet Maximum wallet amount 50,000,000 (5%) Required

πŸš€ Launch Configuration

Parameter Description Range Default
Liquidity Percent Percentage of tokens for liquidity 0-100% 80%
BNB Liquidity BNB amount for liquidity > 0 0.5 BNB
Lock Duration Liquidity lock period 0-365 days 30 days
Auto List Automatically list on PancakeSwap true/false true
Burn Liquidity Burn LP tokens after adding true/false true

πŸ’° Fee Configuration

Fee Type Description Default Range
Launch Fee BNB fee for token creation 0.1 BNB 0-1 BNB
Platform Fee Percentage fee on transactions 2.5% 0-10%
Swap Fee Fee for token swaps 1% 0-10%

πŸ”„ Migration Configuration

Parameter Description Options Default
Migration Type Type of migration TokenUpgrade, PlatformMigration, TokenSwap, LiquidityMigration TokenUpgrade
Migration Ratio New tokens per old token Any ratio 1:1
Start Time Migration start time Unix timestamp Required
End Time Migration end time Unix timestamp Required
Max Amount Maximum migration amount Token amount No limit
Burn Old Tokens Burn old tokens after migration true/false true

πŸ”’ Security Features & Best Practices

πŸ€– Anti-Bot Protection

  • Cooldown Period: 30-second cooldown between transactions
  • Transaction Limits: Configurable maximum transaction amounts
  • Wallet Limits: Configurable maximum wallet amounts
  • Excluded Addresses: DEX and contract addresses exempt from limits

πŸ‹ Anti-Whale Protection

  • Max Transaction: Prevents large single transactions (default: 1% of supply)
  • Max Wallet: Prevents single wallet dominance (default: 5% of supply)
  • Dynamic Limits: Admin-adjustable limits based on market conditions
  • Whale Detection: Real-time monitoring of large transactions

πŸ›‘οΈ Platform Security

  • ReentrancyGuard: Protection against reentrancy attacks
  • Pausable: Emergency pause functionality for all contracts
  • Ownable: Multi-level admin controls and ownership management
  • Input Validation: Comprehensive parameter validation and sanitization
  • Access Control: Role-based permissions and authorization
  • Emergency Controls: Emergency withdrawal and migration capabilities

πŸ” Smart Contract Security

  • OpenZeppelin: Industry-standard security libraries
  • Upgradeable: Migration system for contract upgrades
  • Audit Ready: Clean, well-documented code for security audits
  • Gas Optimization: Optimized for gas efficiency and cost reduction

🌐 Network Support & Configuration

πŸ§ͺ BSC Testnet (Recommended for Testing)

Parameter Value
RPC URL https://data-seed-prebsc-1-s1.binance.org:8545/
Chain ID 97
Explorer https://testnet.bscscan.com/
PancakeSwap https://pancake.kiemtienonline360.com/
WBNB 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd

πŸš€ BSC Mainnet (Production)

Parameter Value
RPC URL https://bsc-dataseed.binance.org/
Chain ID 56
Explorer https://bscscan.com/
PancakeSwap https://pancakeswap.finance/
WBNB 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c

πŸ”§ Network Configuration

The system is pre-configured for BNB Chain with:

  • PancakeSwap Router: Automatic DEX integration
  • WBNB Support: Native BNB token wrapping
  • Gas Optimization: Optimized for BSC gas costs
  • Multi-RPC Support: Fallback RPC endpoints

πŸ“Š Usage Examples & Code Snippets

πŸͺ™ Basic Token Creation

const factory = await ethers.getContractAt("MemeTokenFactory", factoryAddress);

await factory.createToken(
  "MyToken",
  "MTK",
  ethers.utils.parseEther("1000000000"), // 1B supply
  ethers.utils.parseEther("10000000"),   // 10M max tx (1%)
  ethers.utils.parseEther("50000000"),   // 50M max wallet (5%)
  { value: ethers.utils.parseEther("0.1") } // 0.1 BNB fee
);

πŸš€ Launch with Automatic Liquidity

const launchPlatform = await ethers.getContractAt("LaunchPlatform", platformAddress);

const config = {
  liquidityPercent: 8000, // 80% of tokens for liquidity
  bnbLiquidity: ethers.utils.parseEther("1.0"), // 1 BNB
  lockDuration: 30 * 24 * 60 * 60, // 30 days
  autoList: true,
  burnLiquidity: true
};

await launchPlatform.launchTokenWithLiquidity(
  "MyToken",
  "MTK",
  ethers.utils.parseEther("1000000000"),
  ethers.utils.parseEther("10000000"),
  ethers.utils.parseEther("50000000"),
  config,
  { value: totalCost }
);

πŸ”„ Token Swapping

const tokenSwap = await ethers.getContractAt("TokenSwap", swapAddress);

// Get swap quote
const [amountOut, fee] = await tokenSwap.getSwapQuote(
  tokenInAddress,
  tokenOutAddress,
  ethers.utils.parseEther("1000")
);

// Execute swap
await tokenSwap.swapTokens(
  tokenInAddress,
  tokenOutAddress,
  ethers.utils.parseEther("1000")
);

πŸ’§ Liquidity Management

const liquidityManager = await ethers.getContractAt("LiquidityManager", liquidityAddress);

// Add liquidity
await liquidityManager.addLiquidity(
  tokenAddress,
  ethers.utils.parseEther("0.5"), // 0.5 BNB
  ethers.utils.parseEther("1000000"), // 1M tokens
  { value: ethers.utils.parseEther("0.5") }
);

// Remove liquidity
await liquidityManager.removeLiquidity(
  tokenAddress,
  ethers.utils.parseEther("100") // 100 LP tokens
);

πŸ”„ Token Migration

const tokenMigration = await ethers.getContractAt("TokenMigration", migrationAddress);

// Create migration
const migrationConfig = {
  oldToken: oldTokenAddress,
  newToken: newTokenAddress,
  migrationRatio: ethers.utils.parseEther("1"), // 1:1 ratio
  startTime: Math.floor(Date.now() / 1000) + 3600, // Start in 1 hour
  endTime: Math.floor(Date.now() / 1000) + 86400, // End in 24 hours
  maxMigrationAmount: ethers.utils.parseEther("1000000"),
  migrationType: 0, // TokenUpgrade
  requiresApproval: true,
  burnOldTokens: true
};

await tokenMigration.createMigration(migrationId, migrationConfig);
await tokenMigration.startMigration(migrationId);

// User migration
await tokenMigration.migrateTokens(migrationId, ethers.utils.parseEther("1000"));

πŸ“Š Price Oracle Usage

const priceOracle = await ethers.getContractAt("PriceOracle", oracleAddress);

// Update token price
await priceOracle.updateTokenPrice(tokenAddress);

// Get token price
const [price, valid] = await priceOracle.getTokenPrice(tokenAddress);

// Get market cap
const [marketCap, valid] = await priceOracle.getTokenMarketCap(
  tokenAddress,
  totalSupply
);

πŸ§ͺ Testing & Development

Running Tests

# Run all tests
npm test

# Run specific test file
npx hardhat test test/MemeToken.test.js

# Run tests with gas reporting
REPORT_GAS=true npm test

Compilation & Deployment

# Compile contracts
npm run compile

# Deploy to testnet
npm run deploy:testnet

# Deploy to mainnet
npm run deploy:mainnet

Contract Verification

# Verify on BSCScan
npx hardhat verify --network mainnet <CONTRACT_ADDRESS>

# Verify with constructor arguments
npx hardhat verify --network mainnet <CONTRACT_ADDRESS> "constructor_arg1" "constructor_arg2"

🌐 Frontend Integration

Web3 Integration

The project includes complete frontend integration examples:

// Import the Web3 integration class
import { FourMemeWeb3 } from './frontend-examples/web3-integration.js';

// Initialize
const web3 = new FourMemeWeb3(provider, signer);

// Create token
const result = await web3.createToken({
  name: "MyToken",
  symbol: "MTK",
  totalSupply: "1000000000",
  maxTransaction: "10000000",
  maxWallet: "50000000"
});

React Components

Ready-to-use React components are available in frontend-examples/react-components.jsx:

  • TokenCreator - Token creation form
  • TokenSwapper - Token swapping interface
  • LiquidityManager - Liquidity management
  • PriceDisplay - Price tracking component

πŸ“ˆ Migration & Upgrades

Token Migration

# Set up token migration
npx hardhat run scripts/migrateTokens.js --network testnet

Platform Migration

# Set up platform migration
npx hardhat run scripts/migratePlatform.js --network testnet

πŸ“ License & Legal

πŸ“„ License

MIT License - see LICENSE file for details.

⚠️ Disclaimer

This is a fork of Four.meme for educational and development purposes. Use at your own risk. Always conduct thorough testing before deploying to mainnet.

πŸ”’ Security Notice

  • Audit Recommended: Have contracts audited before mainnet deployment
  • Test Thoroughly: Use testnet extensively before production
  • Monitor Activity: Keep track of all contract interactions
  • Emergency Procedures: Have emergency pause and migration procedures ready

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and add tests
  4. Run tests: npm test
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Submit a pull request

Contribution Guidelines

  • Follow Solidity style guide
  • Add comprehensive tests for new features
  • Update documentation for API changes
  • Ensure all tests pass before submitting PR

πŸ“ž Support & Community

πŸ†˜ Getting Help

  • GitHub Issues: Create an issue for bugs or feature requests
  • Documentation: Check this README and inline code comments
  • Community: Join our Discord/Telegram for discussions

πŸ› Reporting Issues

When reporting issues, please include:

  • Contract addresses and transaction hashes
  • Network (testnet/mainnet)
  • Steps to reproduce
  • Expected vs actual behavior
  • Screenshots if applicable

πŸ’‘ Feature Requests

We welcome feature requests! Please describe:

  • The problem you're trying to solve
  • Your proposed solution
  • Any alternatives you've considered

🎯 Roadmap

Current Features βœ…

  • Token creation and management
  • Fair launch mechanics
  • Token swapping
  • Liquidity management
  • Price oracle
  • Migration system
  • Frontend integration

Planned Features 🚧

  • Multi-signature wallet support
  • Advanced analytics dashboard
  • Mobile app integration
  • Cross-chain bridge support
  • NFT integration
  • Governance token system

πŸŽ‰ Get Started Today!

Ready to launch your meme token? Follow our Quick Start Guide and have your token live on BNB Chain in minutes!

Happy Meme Token Launching! πŸš€πŸͺ™


⭐ Star this repository if you found it helpful!

GitHub stars GitHub forks

About

BNB Smart Chain Four.meme Fork Smart Contract: BNB Fourmeme Fork smart contract

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors