Skip to content

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

  1. User initiates minting process (Basic: 2 TON, Premium: 10 TON)
  2. Backend prepares mint parameters
  3. Frontend constructs transaction
  4. User signs via TON Connect
  5. Transaction sent to blockchain
  6. System splits fee (Basic: 1 TON liquidity/1 TON platform, Premium: 6 TON liquidity/4 TON platform)
  7. Metadata stored in database
  8. UI updates with new coin

AMM Trading Flow

  1. User selects swap amount and direction
  2. System calculates expected output and fees (0.2% standard, 0.1% trend)
  3. System calculates 5% token burn
  4. Frontend constructs swap transaction
  5. User signs transaction
  6. Transaction sent to blockchain
  7. Fees distributed (0.15%/0.075% to liquidity, 0.05%/0.025% to platform)
  8. Tokens burned (5% of transaction)
  9. UI updates with new balances
  10. Transaction recorded in history

Fixed-Price Trading Flow

  1. User selects buy/sell amount
  2. System calculates price (24h AMM average ±10%)
  3. System checks 5% pool limit
  4. System calculates 5% token burn
  5. Frontend constructs transaction with 0.1 TON fee
  6. User signs transaction
  7. Transaction sent to blockchain
  8. Fee added to Reserve Pool
  9. Tokens burned (5% of transaction)
  10. UI updates with new balances
  11. Transaction recorded in history

HODL Club Flow

  1. User pays 1 TON monthly membership
  2. System registers membership
  3. Fee split (0.5 TON to rewards pool, 0.5 TON to platform)
  4. System checks for eligible rewards (hold >100 tokens for >30 days)
  5. System processes 1 TON rewards (once per coin)
  6. 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

MemeMint - Hackathon Project