Blockchain Integration
TON Blockchain Overview
The MemeMint platform leverages the TON (The Open Network) blockchain for its high throughput, low fees, and Telegram integration. For the PoC, we'll focus on essential blockchain functionality while keeping complexity manageable.
Smart Contract Architecture
Core Contracts
1. JettonMaster Contract
The central contract for meme coin creation and management.
Key Functionality:
- Mint new Jetton tokens (meme coins)
- Store metadata (name, symbol, image URL)
- Track owner/creator information
- Manage initial supply distribution
Implementation Notes:
- Use standard TON Jetton contract as base
- Add custom metadata for meme-specific information
- Implement creator fee collection mechanism
2. JettonWallet Contract
Individual wallet contracts for each coin type.
Key Functionality:
- Hold balance information
- Process transfers
- Implement burn mechanism
- Calculate and distribute fees
3. AMM Exchange Contract
Handles the automated market maker functionality.
Key Functionality:
- Provide liquidity (token + TON pairs)
- Calculate swap prices based on bonding curve
- Process swap transactions
- Collect and distribute trading fees
- Implement token burns (5% of every trade)
Implementation Notes:
- Start with simplified x*y=k formula for PoC
- Implement bonding curve transition (50 TON cap for Basic, 500 TON for Premium)
- Add fee collection (0.2% standard - 0.15% to liquidity, 0.05% to platform)
- Add reduced fees for trend coins (0.1% - 0.075% to liquidity, 0.025% to platform)
- Implement automatic 5% token burn on all transactions
Smart Contract Interfaces (Simplified)
JettonMaster
func
;; Get jetton data
() get_jetton_data() method_id {
;; Returns minting_wallet, total_supply, content, creator, etc
}
;; Mint new jetton
() mint(slice to_address, int amount, int ton_amount) method_id {
;; Creates new tokens, requires proper fees
}
;; Get wallet address for owner
() get_wallet_address(slice owner_address) method_id {
;; Returns address of specific wallet
}AMM Pool
func
;; Add liquidity
() add_liquidity(int min_lp_out) method_id {
;; Adds TON + tokens to pool based on attached values
}
;; Swap TON to jetton
() swap_ton_to_jetton(int min_jetton_out, slice jetton_address, slice owner, int is_trend_coin) method_id {
;; Swaps TON for tokens based on price curve
;; Applies appropriate fee (0.2% standard, 0.1% trend)
;; Burns 5% of tokens from the swap
}
;; Swap jetton to TON
() swap_jetton_to_ton(int jetton_amount, int min_ton_out, int is_trend_coin) method_id {
;; Swaps tokens for TON based on price curve
;; Applies appropriate fee (0.2% standard, 0.1% trend)
;; Burns 5% of tokens from the swap
}
;; Check and transition from bonding curve to AMM if cap reached
() check_cap_and_transition(int tier_type) method_id {
;; Checks if cap is reached (50 TON Basic, 500 TON Premium)
;; Locks liquidity (10 TON Basic, 100 TON Premium + tokens)
;; Transitions to AMM trading
;; Pays creator rewards
}
;; Fixed price buy function
() fixed_price_buy(slice jetton_address, slice owner) method_id {
;; Buys tokens at 24h AMM average price + 10%
;; Charges 0.1 TON fee to Reserve Pool
;; Burns 5% of tokens from the purchase
}
;; Fixed price sell function
() fixed_price_sell(int jetton_amount, slice jetton_address) method_id {
;; Sells tokens at 24h AMM average price - 10%
;; Charges 0.1 TON fee to Reserve Pool
;; Burns 5% of tokens from the sale
}Wallet Integration
TON Connect 2.0
For the PoC, implement TON Connect 2.0 for wallet connections:
Key Features:
- QR code and deep link connections
- Session management
- Transaction signing
- Balance checking
Implementation Pattern:
javascript
// Example initialization code
import TonConnect from '@tonconnect/sdk';
const connector = new TonConnect({
manifestUrl: 'https://memecoin.app/tonconnect-manifest.json'
});
// Connect wallet
const connectWallet = async () => {
const walletsList = await connector.getWallets();
connector.connect({jsBridgeKey: 'tonconnect'});
};
// Send transaction
const sendTransaction = async (transaction) => {
if (!connector.connected) return;
const result = await connector.sendTransaction({
validUntil: Math.floor(Date.now() / 1000) + 600, // 10 min
messages: [transaction]
});
return result;
};Transaction Flows
Coin Creation Flow
- User initiates minting process (Basic: 2 TON, Premium: 10 TON)
- Backend prepares mint parameters
- Frontend constructs transaction
- User signs via TON Connect
- Transaction sent to blockchain
- System splits fee (Basic: 1 TON liquidity/1 TON platform, Premium: 6 TON liquidity/4 TON platform)
- Metadata stored in database
- UI updates with new coin
AMM Trading Flow
- User selects swap amount and direction
- System calculates expected output and fees (0.2% standard, 0.1% trend)
- System calculates 5% token burn
- Frontend constructs swap transaction
- User signs transaction
- Transaction sent to blockchain
- Fees distributed (0.15%/0.075% to liquidity, 0.05%/0.025% to platform)
- Tokens burned (5% of transaction)
- UI updates with new balances
- Transaction recorded in history
Fixed-Price Trading Flow
- User selects buy/sell amount
- System calculates price (24h AMM average ±10%)
- System checks 5% pool limit
- System calculates 5% token burn
- Frontend constructs transaction with 0.1 TON fee
- User signs transaction
- Transaction sent to blockchain
- Fee added to Reserve Pool
- Tokens burned (5% of transaction)
- UI updates with new balances
- Transaction recorded in history
HODL Club Flow
- User pays 1 TON monthly membership
- System registers membership
- Fee split (0.5 TON to rewards pool, 0.5 TON to platform)
- System checks for eligible rewards (hold >100 tokens for >30 days)
- System processes 1 TON rewards (once per coin)
- System schedules weekly 24h spotlights for member coins
Data Synchronization
On-Chain to Off-Chain Bridge
Requirements:
- Monitor blockchain for relevant events
- Update database with on-chain state
- Reconcile discrepancies
Implementation Approach:
- Use TON HTTP API for blockchain data
- Implement webhook notifications
- Set up recurring synchronization jobs
Metadata Storage
On-Chain Data:
- Token supply information
- Owner/creator addresses
- Basic parameters
Off-Chain Data:
- Detailed coin information
- Trading history and statistics
- User preferences and settings
- Image files (IPFS)
TON-Specific Optimizations
Fee Management
- Estimate and display gas fees
- Implement message value calculation
- Handle bounced transactions
Performance Considerations
- Batch reads when possible
- Use lightweight events for updates
- Implement caching layer for frequent data
Testing Environment
TON Testnet Configuration
Setup Requirements:
- Testnet endpoints configuration
- Faucet integration for test TON
- Separate contract deployments
Testing Tools:
- TON development tools (ton-dev)
- Contract testing frameworks
- Transaction simulation tools
Security Considerations
Smart Contract Security
- Input validation
- Access control mechanisms
- Emergency pause functionality
- Rate limiting for sensitive operations
Transaction Security
- Transaction confirmation UI
- Clear fee disclosures
- Receipt verification
- Failure recovery mechanisms
Post-Hackathon Enhancements
Phase 1 (PoC Minimum)
- Basic Jetton contract deployment
- Simple AMM implementation
- TON Connect wallet integration
- Basic transaction flows
Phase 2 (Enhanced PoC)
- Fee distribution implementation
- Creator rewards mechanism
- Advanced AMM features
- Transaction history tracking
Phase 3 (Post-Hackathon)
- Circuit breaker mechanisms
- Advanced price curve implementation
- Comprehensive fee ecosystem
- Cross-chain bridge considerations