A complete EVM implementation of Pump Fun's functionality, deployed on BSC Testnet. This allows users to create tokens with metadata (image URL, website link, description) and trade them using a bonding curve mechanism.
cd contracts
npm install
cp .env.example .envEdit .env file with your credentials:
BSC_TESTNET_URL=https://data-seed-prebsc-1-s1.binance.org:8545
PRIVATE_KEY=your_private_key_here
BSCSCAN_API_KEY=your_bscscan_api_key_herenpm run compilenpm run deploy:bsctestnetnpm run verify:bsctestnetnpm testnpx hardhat test test/deployment.test.jsnpm run clean
npm run compile- β Token Creation: Create meme tokens with custom metadata (name, symbol, image URL, website link, description)
- β Bonding Curve: Step function bonding curve similar to Pump Fun for fair token pricing
- β Trading: Buy and sell tokens directly through the bonding curve
- β Graduation: Tokens automatically graduate when they reach the market cap threshold
- β Fee Mechanism: 1% trading fee with 0.2% going to token creators
- Standard ERC20 token with additional metadata support
- Functions for minting/burning (only callable by bonding curve)
- Metadata update capabilities for token creators
- Graduation mechanism when token reaches threshold
- 7-step bonding curve similar to Pump Fun:
- 0-1M tokens: 1-2 BNB per billion tokens
- 1-5M tokens: 2-5 BNB per billion tokens
- 5-10M tokens: 5-10 BNB per billion tokens
- 10-50M tokens: 10-25 BNB per billion tokens
- 50-100M tokens: 25-50 BNB per billion tokens
- 100-500M tokens: 50-100 BNB per billion tokens
- 500M-1B tokens: 100-200 BNB per billion tokens
- Buy/Sell functionality with proper price calculations
- Fee mechanism: 1% trading fee (0.8% protocol, 0.2% creator)
- Automatic graduation at 85 BNB threshold
- Real-time price calculations based on supply
- Deploys new token and bonding curve pairs
- Creation fee: 0.01 BNB per token
- Tracks token information and creator relationships
- Manages token activation/deactivation
- Provides token discovery functions
- Single entry point for all user interactions
- Coordinates between factory and bonding curves
- Comprehensive token information retrieval
- Trading functions with proper error handling
- Token discovery and statistics
The bonding curve uses a step function with 7 steps, each with different price progression to ensure fair launch and price discovery.
- Tokens graduate when 85 BNB is collected in the bonding curve
- Upon graduation, tokens are marked as graduated and can be listed on DEXes
- Progress is tracked and displayed in real-time
- Creation Fee: 0.01 BNB to create a new token
- Trading Fee: 1% on all buys and sells
- 0.8% goes to protocol
- 0.2% goes to token creator
After deployment, contract addresses are saved in deployment-bsctestnet.json:
{
"network": "bsctestnet",
"pumpFunFactory": "0x...",
"pumpFunMain": "0x...",
"feeRecipient": "0x...",
"deployer": "0x...",
"timestamp": "2024-01-01T00:00:00.000Z"
}- PumpFun Main: Primary contract for user interactions
- PumpFun Factory: Factory contract for token deployment
- Fee Recipient: Address receiving creation and trading fees
const pumpFunAddress = "0x..."; // Your deployed PumpFun contract address
const pumpFun = await ethers.getContractAt("PumpFun", pumpFunAddress);
// Create a new token
await pumpFun.createToken(
"My Meme Token",
"MEME",
"https://example.com/token-image.png",
"https://mytoken.com",
"The best meme token ever!",
{ value: ethers.utils.parseEther("0.01") }
);const tokenAddress = "0x..."; // Address of the token you want to buy
const bnbAmount = ethers.utils.parseEther("0.1"); // 0.1 BNB
await pumpFun.buyTokens(tokenAddress, { value: bnbAmount });const tokenAddress = "0x...";
const tokenAmount = ethers.utils.parseEther("1000"); // 1000 tokens
await pumpFun.sellTokens(tokenAddress, tokenAmount);const tokenAddress = "0x...";
const summary = await pumpFun.getTokenSummary(tokenAddress);
console.log("Token Name:", summary.name);
console.log("Token Symbol:", summary.symbol);
console.log("Current Price:", summary.currentPrice);
console.log("Total Supply:", summary.totalSupply);
console.log("BNB Collected:", summary.totalBNBCollected);
console.log("Graduated:", summary.graduated);const tokenAddress = "0x...";
const bnbAmount = ethers.utils.parseEther("0.1");
// Get how many tokens you can buy with 0.1 BNB
const tokensToBuy = await pumpFun.getTokensForBNB(tokenAddress, bnbAmount);
// Get cost to buy specific amount of tokens
const buyPrice = await pumpFun.getBuyPrice(tokenAddress, tokensToBuy);
// Get revenue from selling specific amount of tokens
const sellPrice = await pumpFun.getSellPrice(tokenAddress, tokensToBuy.div(2));The contracts are designed to be easily integrated with frontend applications:
- Token Creation:
createToken(name, symbol, imageUri, websiteUrl, tokenDescription) - Buying:
buyTokens(tokenAddress, { value: bnbAmount }) - Selling:
sellTokens(tokenAddress, tokenAmount) - Token Info:
getTokenSummary(tokenAddress) - Price Info:
getBuyPrice(),getSellPrice(),getTokensForBNB() - Token Lists:
getRecentTokens(),getActiveTokens(),getCreatorTokens()
TokenCreatedViaPumpFun: When new tokens are createdTokensPurchased: When tokens are boughtTokensSold: When tokens are soldTokenGraduated: When tokens graduate to DEX
- Initialization: All contracts use proper initialization patterns
- Access Control: Only authorized addresses can call sensitive functions
- Reentrancy Protection: Standard reentrancy guards are used
- Overflow Protection: SafeMath is used for all arithmetic operations
- Fee Distribution: Fees are securely transferred to recipients
contracts/
βββ src/
β βββ PumpFunToken.sol # ERC20 token with metadata
β βββ PumpFunBondingCurve.sol # Bonding curve implementation
β βββ PumpFunFactory.sol # Token deployment factory
β βββ PumpFun.sol # Main user interface
βββ scripts/
β βββ deploy.js # Deployment script
β βββ verify.js # Verification script
β
βββ hardhat.config.js # Hardhat configuration
βββ package.json # Dependencies and scripts
βββ README.md # This file
npm run compile # Compile contracts
npm run deploy:bsctestnet # Deploy to BSC Testnet
npm run verify:bsctestnet # Verify contracts on BscScan
npm run clean # Clean build artifacts-
Compilation Errors
npm run clean npm run compile
-
Deployment Fails
- Check BSC Testnet RPC URL in
.env - Ensure account has sufficient BNB balance
- Verify private key is correct
- Check BSC Testnet RPC URL in
-
Verification Fails
- Ensure BSCSCAN_API_KEY is valid
- Wait for a few blocks after deployment
- Check constructor arguments match deployment
-
Test Failures
npm run clean npm run compile npm test
BSC Testnet
- RPC URL:
https://data-seed-prebsc-1-s1.binance.org:8545 - Chain ID: 97
- Currency: BNB
- Explorer:
https://testnet.bscscan.com
- DEX Integration: Automatic liquidity pool creation on graduation
- Volume Tracking: Track trading volume for trending tokens
- Advanced Metadata: Support for more token metadata
- Multi-chain Support: Deploy on other EVM chains
- Enhanced UI/UX: More sophisticated frontend interfaces
MIT License - see LICENSE file for details
For support and questions:
- Check the troubleshooting section
- Review the test files for usage examples
- Ensure you're using the correct network configuration
- Verify contract addresses after deployment
Happy token creation! π