Thanks to visit codestin.com
Credit goes to github.com

Skip to content

anshuman008/solana-transaction-optimizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Solana Transaction Optimizer

A comprehensive TypeScript project demonstrating the efficiency benefits of using Solana Address Lookup Tables (ALTs) for transaction optimization, specifically focused on PumpFun token purchases and bundle transactions.

🎯 Project Overview

This project showcases how Solana Address Lookup Tables can significantly reduce transaction sizes and improve network efficiency. It provides practical implementations for:

  • Single token purchases with and without lookup tables
  • Bundle transactions for multiple buyers
  • Performance comparison and analysis tools
  • Real-world PumpFun integration examples

πŸš€ Key Features

πŸ“Š Transaction Size Optimization

  • Automatic comparison between normal and lookup table transactions
  • Detailed analytics showing byte savings and efficiency gains
  • Performance metrics with percentage reductions and compression ratios

πŸ”§ Multiple Transaction Types

  • Single buyer transactions - Individual token purchases
  • Bundle transactions - Multiple buyers in one transaction
  • Lookup table creation - Automated ALT setup and management

πŸ› οΈ Developer Tools

  • Transaction executor with simulation and retry logic
  • Comprehensive logging with detailed transaction analysis
  • Error handling and recovery mechanisms

πŸ“ Project Structure

solana-transaction-optimizer/
β”œβ”€β”€ index.ts                    # Main entry point with single buyer examples
β”œβ”€β”€ bundle_buys.ts             # Bundle transaction implementations
β”œβ”€β”€ single_buy_comparison.ts   # Detailed comparison analysis
β”œβ”€β”€ createLookupTable.ts       # Lookup table creation utilities
β”œβ”€β”€ txsExecutor.ts            # Transaction execution helper
β”œβ”€β”€ buyersKeys.ts             # Configuration for multiple buyers
β”œβ”€β”€ package.json              # Dependencies and scripts
└── tsconfig.json            # TypeScript configuration

πŸ› οΈ Installation

  1. Clone the repository

    git clone <repository-url>
    cd solana-transaction-optimizer
  2. Install dependencies

    npm install
  3. Environment setup Create a .env file with your configuration:

    SIGNER_KEY=your_base58_encoded_private_key

πŸ”§ Configuration

Required Environment Variables

  • SIGNER_KEY: Your wallet's private key in base58 format

Key Configuration Constants

The project uses several hardcoded addresses that you may need to update:

// Main configuration in index.ts and other files
const lookup_address = new PublicKey("E4b5B9C3hapUZY7qfbLXTsPdaRzUT1HbT7uGRS19DXyL");
const program_id = new PublicKey("6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P");
const mint = new PublicKey("9rwU5ex3PAp6TZ4PQ68nnGHtcRmnD5Hyo4QzYWZVpump");
const creator = new PublicKey("Gqd1HsMwhNMHtqL1iZ2M23DriBPJdnbJR8PEBUCPDvB");

Multiple Buyers Setup

Edit buyersKeys.ts to add wallet private keys for bundle transactions:

export const privateKeys = [
  "wallet1_private_key_base58",
  "wallet2_private_key_base58",
  // Add more wallets as needed
];

πŸš€ Usage

1. Single Buyer Comparison

Run the main comparison analysis:

npx ts-node single_buy_comparison.ts

This will:

  • Create a normal transaction without lookup table
  • Create the same transaction with lookup table
  • Display detailed comparison metrics
  • Show efficiency gains and recommendations

2. Bundle Transactions

Execute bundle purchases with multiple buyers:

npx ts-node bundle_buys.ts

3. Individual Functions

Run specific functions from index.ts:

npx ts-node index.ts

πŸ“Š Performance Analysis

The project provides comprehensive performance metrics with real-world examples:

Real-World Transaction Results

Single Buyer Transaction

TRANSACTION SIZES:
   Normal Transaction:     660 bytes
   With Lookup Table:      353 bytes
   Absolute Savings:       307 bytes

EFFICIENCY METRICS:
   Size Reduction:         46.5%
   Efficiency Gain:        87.0%
   Compression Ratio:      1.87:1

Bundle Transaction (Multiple Buyers)

TRANSACTION SIZES:
   Normal Bundle:          1536+ bytes (FAILED - exceeds 1232 byte limit)
   With Lookup Table:      871 bytes (SUCCESS)
   Absolute Savings:       665+ bytes

EFFICIENCY METRICS:
   Size Reduction:         43.3%+
   Status:                 From FAILED to SUCCESS
   Network Impact:         Enables complex bundle transactions

Live Transaction Examples

Bundle Transaction Success: View on Solscan

  • This transaction demonstrates successful bundle execution using lookup tables
  • Multiple buyers in a single transaction that would otherwise fail due to size limits

Analysis Categories

  • EXCELLENT: >50% reduction - Highly effective
  • GOOD: 30-50% reduction - Solid benefits
  • MODERATE: 15-30% reduction - Decent improvement
  • MINIMAL: <15% reduction - May not justify complexity

πŸš€ Key Benefits Highlight

Address Lookup Tables can reduce transaction sizes by 40-90%, making them essential for:

  • Bundle Transactions: Enabling multiple operations that would otherwise fail due to size limits
  • Complex DeFi Operations: Reducing costs and improving success rates
  • High-Frequency Trading: Optimizing transaction throughput
  • Gaming Applications: Supporting complex in-game transactions

πŸ” Technical Details

Dependencies

  • @solana/web3.js: Core Solana blockchain interaction
  • @solana/spl-token: Token program utilities
  • latest-pumpfun-sdk: PumpFun protocol integration
  • bn.js: Big number handling
  • bs58: Base58 encoding/decoding
  • dotenv: Environment variable management

Key Components

Address Lookup Table Creation

const createLUT = async (mainKP: Keypair, connection: Connection) => {
  // Creates lookup table with retry logic
  // Includes compute budget optimization
  // Handles slot-based creation
}

Transaction Execution

const createAndSendV0Tx = async (
  txInstructions: TransactionInstruction[], 
  kp: Keypair, 
  connection: Connection
) => {
  // Versioned transaction creation
  // Simulation and error handling
  // Automatic retry mechanism
}

Bundle Transaction Logic

  • Supports multiple buyers in single transaction
  • Automatic ATA (Associated Token Account) management
  • Optimized lookup table population
  • Comprehensive error handling

🎯 Use Cases

1. DeFi Applications

  • DEX aggregators reducing transaction sizes by 40-90%
  • Yield farming with multiple token operations
  • Liquidity provision with complex account structures
  • Bundle swaps across multiple protocols

2. NFT Marketplaces

  • Bundle purchases of multiple NFTs in single transaction
  • Bulk operations with reduced transaction costs
  • Marketplace efficiency improvements
  • Collection-wide operations (listing, delisting, transfers)

3. Gaming Applications

  • In-game transactions with multiple assets
  • Player actions requiring multiple account interactions
  • Economy optimization for better user experience
  • Batch operations for inventory management

4. Bundle Trading & MEV

  • Multi-buyer transactions (as demonstrated in our examples)
  • Arbitrage opportunities requiring multiple operations
  • Liquidity provision across multiple pools
  • Complex trading strategies that exceed normal size limits

⚠️ Important Considerations

Security

  • Never commit private keys to version control
  • Use environment variables for sensitive data
  • Test on devnet before mainnet deployment

Network Considerations

  • Lookup table creation requires ~15 seconds to activate
  • Account rent costs for lookup table storage
  • Authority management for table updates

Limitations

  • Maximum 256 addresses per lookup table
  • Immutable once created (addresses cannot be removed)
  • Slot-based creation timing requirements

πŸ”§ Customization

Adding New Account Types

To include additional accounts in your lookup table:

// Add to the accounts array in your lookup table creation
accounts.push(
  new PublicKey("your_new_account_address"),
  // Add more accounts as needed
);

Modifying Transaction Logic

Update the transaction creation logic in the respective files:

  • index.ts for single buyer transactions
  • bundle_buys.ts for multiple buyer transactions
  • single_buy_comparison.ts for analysis functions

πŸ“ˆ Performance Tips

  1. Batch Operations: Group related transactions to maximize lookup table efficiency
  2. Account Reuse: Include frequently used accounts in lookup tables
  3. Monitor Usage: Track lookup table effectiveness for your specific use case
  4. Optimize Timing: Create lookup tables during low-traffic periods
  5. Bundle Strategy: Use lookup tables for bundle transactions to avoid size limit failures
  6. Size Monitoring: Track transaction sizes to identify optimization opportunities

Real-World Impact

  • Bundle transactions that previously failed (1536+ bytes) now succeed (871 bytes)
  • Single transactions reduced from 660 to 353 bytes (46.5% reduction)
  • Network efficiency improved through reduced bandwidth usage
  • User experience enhanced with faster, more reliable transactions

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

πŸ“„ License

This project is open source and available under the MIT License.

πŸ†˜ Support

For questions, issues, or contributions:

  • Create an issue in the repository
  • Check existing documentation
  • Review Solana's official lookup table documentation

πŸ”— Related Resources


Note: This project is for educational and development purposes. Always test thoroughly on devnet before using on mainnet, and ensure you understand the implications of lookup table usage for your specific application.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published