-
Notifications
You must be signed in to change notification settings - Fork 310
Add pump fun buy example with optimized CUs #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughA new Solana token-purchase module added with compute unit optimization and simulation. Includes price calculation via bonding curves, transaction building, WebSocket monitoring for token creation, buy simulation without on-chain execution, and optimized token acquisition with CU accounting. Changes
Sequence Diagram(s)sequenceDiagram
participant Main
participant WebSocket
participant RPC
participant Program as On-Chain Program
Main->>WebSocket: listen_for_create_transaction()
WebSocket->>WebSocket: Subscribe to block notifications
activate WebSocket
Note over WebSocket: Wait for pump program transaction
WebSocket-->>Main: Decoded token creation data
deactivate WebSocket
Main->>RPC: get_pump_curve_state(curve_address)
RPC->>Program: Fetch account data
Program-->>RPC: Curve state (reserves, decimals)
RPC-->>Main: BondingCurveState
Main->>Main: calculate_pump_curve_price(curve_state)
Note over Main: Price = virtual_token_reserves /<br/>virtual_sol_reserves
Main->>Main: simulate_buy(token_amount)
activate Main
Note over Main: Build tx with compute budget<br/>Simulate without sending
Main->>RPC: simulateTransaction()
RPC->>Program: Execute in simulation
Program-->>RPC: Result with CU consumed
RPC-->>Main: Estimated CUs
deactivate Main
Main->>Main: buy_token (with CU optimization)
activate Main
Note over Main: Insert preflight CU limit<br/>Build buy instruction
Main->>RPC: sendTransaction()
RPC->>Program: Execute buy on-chain
Program-->>RPC: Transaction signature
RPC-->>Main: CU consumed from details
deactivate Main
Main->>Main: Report CU consumption & savings
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Unfortunately, this method didn't show significant improvements in the CU consumed. The screenshot above is misleading since it shows a decrease due to already existing ATA ... Didn't notice that. I will update this example. |
|
Except for spamming multiple transactions and checking the results, it seems there is no way of proving the actual impact. But theoretically, it should improve transaction priority. Clarifying comments to the example will be provided in the next few commits. |
Added example of CU consumed by a transaction using
setLoadedAccountsDataSizeLimit.https://www.anza.xyz/blog/cu-optimization-with-setloadedaccountsdatasizelimit
Summary by CodeRabbit