Technical Integration Guide
Protocol Overview
The Panda factory Protocol implements a novel token launch mechanism using bonding curves with automatic liquidity provision. This guide will help you understand and integrate with the protocol's smart contracts.
Core Architecture
The protocol is built on three primary components that work together to provide token launch and trading functionality:
1. PandaFactory
The factory contract is the main entry point for deploying new tokens and pools. It:
Manages protocol configurations
Controls implementation versions
Handles deployment permissions
Manages protocol fees and incentives
â ī¸ Important
Always check if your implementation contract is approved by the factory using
isImplementationAllowed()
before attempting deployment.
2. PandaToken
Extends standard ERC20 functionality with bonding curve mechanics. Key features:
ERC20 compliance with permit functionality
Integrated bonding curve trading
Automatic graduation to DEX trading
Transfer restrictions pre-graduation
đĄ Note on Transfers
Transfers to the DEX pair address are blocked until graduation to maintain price curve integrity.
3. PandaPool
Implements the core bonding curve mechanics:
Single-sided liquidity provisioning
Price discovery mechanism
Trading functionality
Graduation handling
Protocol Mechanics
Bonding Curve Mechanism
The protocol uses a square root price model similar to Uniswap V3, but simplified for single-sided liquidity provision. The curve is defined by:
Price Range
sqrtPa
: Lower bound of price rangesqrtPb
: Upper bound of price rangeCurrent price moves between these bounds
Token Distribution
tokensInPool
: Tokens available for bonding curvetokensForLp
: Tokens reserved for DEX liquidityDistribution must satisfy pool share constraints
âšī¸ Mathematical Model
The price calculation follows: P = (sqrtP)² where sqrtP ranges from sqrtPa to sqrtPb Liquidity (L) remains constant: L = tokensInPool * (sqrtPa * sqrtPb) / (sqrtPb - sqrtPa)
Graduation Process
Graduation is the automatic transition from bonding curve to DEX trading. This occurs when:
Remaining tokens in pool ⤠0.25% of initial pool tokens
Final price is used to set DEX pool ratio
Remaining tokens plus LP tokens are added to DEX
â ī¸ Critical
After graduation:
Trading switches to DEX pair
Bonding curve functions are disabled
Transfer restrictions are lifted
Getting Started
Prerequisites
Before integrating with the protocol, ensure you have:
Development Environment
Solidity compiler v0.8.19
Web3 provider
Access to Berachain RPC
Required Permissions
Access to approved implementation contracts
Sufficient base tokens for deployment
Required approvals for trading
Base Token Requirements
Base tokens must:
Be ERC20 compliant
Return boolean for transfers/approvals
Have sufficient decimals (18 recommended)
â ī¸ Base Token Warning
Non-standard ERC20 tokens (e.g., fee-on-transfer, rebasing) are not supported and may cause unexpected behavior.
Network Requirements
Gas Limit
Standard EVM operations
Chain ID
Berachain Mainnet/Testnet
RPC Support
Standard Web3 endpoints
Key Concepts
Price Configuration
The protocol enforces strict bounds on price ranges to ensure proper functioning.
Price Range Requirements
These translate to:
Minimum price range: 1.21x (1.1² x)
Maximum price range: 100x (10² x)
đĄ Price Range Tip
Choose price ranges that make sense for your token's economics. Wider ranges allow more price discovery but require more capital to complete.
Example Price Calculations
Token Distribution Parameters
The protocol enforces constraints on token distribution to ensure proper liquidity.
Pool Share Requirements
Distribution visualization:
âšī¸ Pool Share Information
Pool tokens: Available for bonding curve trading
LP tokens: Reserved for DEX liquidity after graduation
Ratios affect final DEX liquidity depth
Fee Structure
The protocol implements a comprehensive fee structure:
Fee considerations:
Buy/Sell Fees
Taken in base token
Calculated on input amount
Sent to treasury
Graduation Fee
Taken from final base token balance
Split between treasury and deployer
Affects final DEX liquidity
đĄ Fee Calculation Tip
When calculating required inputs, account for fees:
Integration Guide
1. Token Deployment
Deploying a new token requires careful preparation and parameter selection.
Pre-Deployment Checklist
Deployment Process
Calculate Parameters
Deploy Token
â ī¸ Deployment Warning
Verify all parameters before deployment
Deployment cannot be reversed
Parameters cannot be changed after deployment
2. Trading Integration
Pre-Trading Requirements
Base token approvals
Minimum trade size check
Price impact calculations
Slippage protection
Trading Functions
Buy Tokens
Sell Tokens
đĄ Trading Tips
Always use getAmountOut functions to estimate outputs
Include reasonable slippage tolerance
Monitor price impact on larger trades
Price Monitoring
3. Graduation Handling
Graduation Detection
Event Monitoring
State Checking
Post-Graduation Integration
After graduation:
Switch to DEX pair for trading
Update price feeds
Remove pre-graduation restrictions
âšī¸ Graduation Information
Graduation is permanent and irreversible. Always check graduated() state before operations.
Error Handling
Common Errors
INVALID_IMPLEMENTATION
Implementation not allowed
Verify implementation address
PRICES_TOO_CLOSE
Invalid price range
Increase price range
PRICES_TOO_FAR
Invalid price range
Decrease price range
INSUFFICIENT_OUTPUT_AMOUNT
Slippage check failed
Increase slippage tolerance
TRADE_BELOW_MIN
Trade size too small
Increase trade size
GRADUATED
Pool already graduated
Switch to DEX trading
Error Recovery Strategies
Deployment Failures
Verify all parameters
Check implementation status
Ensure base token configuration
Trading Failures
Refresh price data
Adjust slippage tolerance
Check trade size requirements
Graduation Issues
Monitor graduation events
Handle state transitions
Update integration logic
â ī¸ Error Handling Best Practices
Always wrap interactions in try-catch
Implement proper error recovery
Monitor transaction status
Handle reverted transactions
Security Considerations
Important Checks
Pre-deployment
Implementation verification
Parameter validation
Base token compatibility
Trading
Slippage protection
Price impact monitoring
Balance checks
Post-graduation
State verification
DEX pair validation
Trading updates
â ī¸ Security Warnings
Never expose private keys
Validate all input parameters
Monitor for unexpected state changes
Implement proper access controls
Last updated