Skip to content

fairrustana/multiversx-pumpfun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MultiversX PumpFun Smart Contract

A decentralized token launch platform built on MultiversX network, similar to PumpFun, allowing users to create and trade tokens with bonding curve mechanics.

Features

  • Token Creation: Create new tokens with custom metadata
  • Advanced Bonding Curve Trading: Buy/sell tokens using improved AMM mechanics
  • Fee System: Configurable trading and creator fees
  • Admin Controls: Administrative functions for contract management
  • Pause Functionality: Emergency pause/unpause capabilities
  • Comprehensive Views: Extensive query functions for contract state
  • Event Logging: Comprehensive event system for tracking interactions
  • Input Validation: Robust validation and error handling
  • Security Features: Admin-only functions and proper access controls

Contract Structure

  • src/lib.rs - Main contract entry point
  • src/storage.rs - Storage mappers and state variables
  • src/endpoints.rs - Contract functions and business logic
  • src/events.rs - Event definitions
  • src/types.rs - Custom data structures
  • src/errors.rs - Error constants and messages
  • src/pause.rs - Pause/unpause functionality
  • src/validation.rs - Input validation functions
  • src/bonding_curve.rs - Advanced bonding curve calculations
  • src/views.rs - Comprehensive view functions
  • src/tests.rs - Comprehensive test suite
  • scenarios/ - Scenario test files
  • meta/ - Contract metadata generation
  • wasm/ - WASM compilation setup

Key Functions

Token Management

  • createToken - Create a new token with metadata
  • getTokenInfo - Get detailed token information
  • getTokenCount - Get total number of tokens created

Trading

  • buyTokens - Buy tokens using EGLD
  • sellTokens - Sell tokens for EGLD
  • getUserBalance - Get user's token balance

Admin Functions

  • setAdmin - Set new admin address
  • setFeeCollector - Set fee collection address
  • setTradingFee - Set trading fee percentage
  • setCreatorFee - Set creator fee percentage
  • setActive - Enable/disable contract

Bonding Curve Mechanics

The contract uses a simplified bonding curve formula:

  • Buy: tokens = payment * k / (reserve + payment)
  • Sell: egld = token_amount * reserve / (k + token_amount)

Where:

  • k = bonding curve constant
  • reserve = EGLD reserve in the curve
  • payment = EGLD amount being spent
  • token_amount = tokens being sold

Building and Testing

Prerequisites

  • Rust 1.70+
  • MultiversX CLI tools

Build

multiversx-sc build

Test

multiversx-sc test

Deploy

multiversx-sc deploy --proxy=https://testnet-gateway.multiversx.com --chain=T --init-function init --init-args "admin_address" "fee_collector_address"

Usage Examples

Create a Token

# Send 1 EGLD to create a token
multiversx-sc call <contract-address> createToken \
  --args "MyToken" "MTK" 18 1000000000000000000 "My awesome token" \
  "https://example.com/image.png" "https://example.com" \
  "https://twitter.com/mytoken" "https://t.me/mytoken" \
  --value 1000000000000000000

Buy Tokens

# Buy tokens for token ID 1
multiversx-sc call <contract-address> buyTokens \
  --args 1 \
  --value 500000000000000000

Sell Tokens

# Sell 100 tokens
multiversx-sc call <contract-address> sellTokens \
  --args 1 100000000000000000000

Fee Structure

  • Trading Fee: 1% (configurable by admin)
  • Creator Fee: 0.5% (configurable by admin)
  • Minimum Creation Payment: 1 EGLD

New Features & Improvements

Enhanced Architecture

  • Modular Design: Separated concerns into dedicated modules (validation, bonding curve, views, etc.)
  • Error Handling: Comprehensive error constants and proper error messages
  • Input Validation: Robust validation for all user inputs and parameters
  • Pause Functionality: Emergency pause/unpause capabilities for contract maintenance

Advanced Bonding Curve

  • Improved AMM Mechanics: More sophisticated bonding curve calculations
  • Price Impact Calculation: Tools to calculate price impact and slippage
  • Dynamic Pricing: Real-time price updates based on trading activity
  • Liquidity Management: Better liquidity tracking and management

Comprehensive Views

  • Token Metadata: Complete token information including social links
  • Trading Information: Real-time trading data, volume, and market cap
  • User Positions: Detailed user position tracking with PnL calculations
  • Contract Configuration: View all contract settings and parameters
  • Top Tokens: Query tokens by volume and other metrics

Security Enhancements

  • Admin Controls: Proper admin-only function protection
  • Fee Validation: Fee percentage validation with maximum limits
  • Address Validation: Proper address validation for all inputs
  • State Validation: Contract state validation before operations

Testing & Development

  • Scenario Tests: Comprehensive scenario test files
  • Unit Tests: Updated unit tests with proper initialization
  • Meta Generation: Contract metadata generation setup
  • WASM Compilation: Proper WASM compilation configuration

Security Considerations

  • Admin functions are protected and only callable by the contract admin
  • Fee percentages are capped at 10% maximum
  • Bonding curve calculations prevent division by zero
  • Input validation on all user inputs
  • Pause functionality for emergency situations
  • Proper address validation and state checks

License

MIT License - see LICENSE file for details.

Releases

No releases published

Packages

No packages published