Skip to content

fix(examples): add bonding_curve_v2 to learning examples#160

Merged
smypmsa merged 2 commits intomainfrom
fix/learning-examples-bonding-curve-v2
Feb 27, 2026
Merged

fix(examples): add bonding_curve_v2 to learning examples#160
smypmsa merged 2 commits intomainfrom
fix/learning-examples-bonding-curve-v2

Conversation

@smypmsa
Copy link
Member

@smypmsa smypmsa commented Feb 27, 2026

Summary

  • Add bonding_curve_v2 PDA derivation and remaining account to buy/sell instructions in 4 learning examples: manual_buy.py, manual_sell.py, mint_and_buy.py, mint_and_buy_v2.py
  • Without this, these standalone scripts would fail on-chain after the pump.fun program upgrade

Closes #158

Test plan

  • Verified all 4 files have _find_bonding_curve_v2() helper and append it as remaining account after fee_program
  • ruff format passes on all files

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Buy and sell workflows now include support for the bonding-curve-v2 account across all learning examples.
    • Sell flow gains dynamic mayhem-mode fee recipient resolution with fallback behavior.
  • Style

    • Minor formatting and print/output formatting improvements for readability.

…mples

Add the required bonding_curve_v2 PDA as a remaining account to buy/sell
instructions in manual_buy, manual_sell, mint_and_buy, and mint_and_buy_v2
learning examples, matching the pump.fun program upgrade.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aee1928 and 5bbdab8.

📒 Files selected for processing (2)
  • learning-examples/manual_buy_cu_optimized.py
  • learning-examples/manual_buy_geyser.py

📝 Walkthrough

Walkthrough

Added a bonding-curve-v2 PDA derivation helper across multiple learning examples and included the derived bonding_curve_v2 as a readonly remaining account in buy/sell instruction account lists; manual_sell.py (and related examples) also adjust fee-recipient selection to handle mayhem-mode via Global account data.

Changes

Cohort / File(s) Summary
Buy-related examples
learning-examples/manual_buy.py, learning-examples/manual_buy_cu_optimized.py, learning-examples/manual_buy_geyser.py, learning-examples/mint_and_buy.py, learning-examples/mint_and_buy_v2.py
Added _find_bonding_curve_v2(mint: Pubkey) helper (PDA seed ["bonding-curve-v2", mint]); appended bonding_curve_v2 as a readonly, non-writable AccountMeta to buy instruction accounts. Minor formatting and print reflow changes in some files.
Sell example
learning-examples/manual_sell.py
Added _find_bonding_curve_v2(mint: Pubkey) helper; included bonding_curve_v2 readonly AccountMeta in sell_token accounts; updated get_fee_recipient() to return reserved_fee_recipient from Global account (offset 483) when curve is in mayhem mode, with fallback to PUMP_FEE. Minor control-flow adjustments to reflect fee logic.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Client
participant Offchain as Off-chain code (examples)
participant PUMP as PUMP_PROGRAM (on-chain)
participant Global as Global account (on-chain)
Client->>Offchain: build instruction (mint)
Offchain->>Offchain: derive bonding_curve_v2 = PDA(["bonding-curve-v2", mint])
Offchain->>PUMP: send tx with accounts: bonding_curve_v2 (readonly), other accounts
PUMP->>Global: (if mayhem) read Global account data for reserved_fee_recipient
Global-->>PUMP: reserved_fee_recipient (or missing)
PUMP-->>Client: execute buy/sell using chosen fee recipient

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

bug

Poem

🐰
I dug a PDA in moonlit dew,
Bonding curve v2, now in view,
Accounts aligned, mayhem checked with care,
A tiny hop, a transaction fair,
Hooray — on-chain carrots everywhere! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding bonding_curve_v2 account to learning example scripts to fix failing transactions.
Linked Issues check ✅ Passed The PR successfully addresses issue #158 by adding bonding_curve_v2 account to all example scripts, which resolves the on-chain transaction failures without the required account.
Out of Scope Changes check ✅ Passed All changes are in-scope: the _find_bonding_curve_v2() helper and bonding_curve_v2 account additions are directly required to fix the transaction failures in issue #158.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/learning-examples-bonding-curve-v2

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

…uy_cu_optimized

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
learning-examples/manual_buy.py (1)

292-297: Please run a minimal-amount buy/sell smoke test before merge.

Because this is an on-chain account-ordering change, confirm with tiny amounts in manual_buy.py and manual_sell.py on a safe environment before production usage.

Based on learnings: Test changes using manual_buy.py and manual_sell.py with minimal amounts before production use.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@learning-examples/manual_buy.py` around lines 292 - 297, This change affects
on-chain account ordering for the bonding_curve_v2 AccountMeta (see AccountMeta
and _find_bonding_curve_v2 in manual_buy.py), so before merging run a
minimal-amount smoke test: in a safe/test environment run manual_buy.py and
manual_sell.py using testnet/devnet credentials and very small amounts (e.g.,
minimum token units) to ensure transactions succeed and expected account
ordering succeeds; verify both buy and sell flows complete without
signature/account-order errors, inspect returned transaction logs for any
"account not found" or "invalid account order" errors, and if failures occur
adjust the AccountMeta ordering or the call site that uses
_find_bonding_curve_v2 until the smoke tests pass.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@learning-examples/manual_buy.py`:
- Around line 509-511: The long f-string in the print call exceeds style limits
and uses single quotes; change it by computing the token type into a short
variable (e.g., token_type = "Token2022" if token_data["is_token_2022"] else
"Standard Token") and then use a shorter print statement like print(f"Token
Program: {token_program} ({token_type})") so no line exceeds 88 characters and
double quotes are used consistently; update the print call that references
token_program and token_data["is_token_2022"] accordingly.

---

Nitpick comments:
In `@learning-examples/manual_buy.py`:
- Around line 292-297: This change affects on-chain account ordering for the
bonding_curve_v2 AccountMeta (see AccountMeta and _find_bonding_curve_v2 in
manual_buy.py), so before merging run a minimal-amount smoke test: in a
safe/test environment run manual_buy.py and manual_sell.py using testnet/devnet
credentials and very small amounts (e.g., minimum token units) to ensure
transactions succeed and expected account ordering succeeds; verify both buy and
sell flows complete without signature/account-order errors, inspect returned
transaction logs for any "account not found" or "invalid account order" errors,
and if failures occur adjust the AccountMeta ordering or the call site that uses
_find_bonding_curve_v2 until the smoke tests pass.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a48f54 and aee1928.

📒 Files selected for processing (4)
  • learning-examples/manual_buy.py
  • learning-examples/manual_sell.py
  • learning-examples/mint_and_buy.py
  • learning-examples/mint_and_buy_v2.py

Comment on lines +509 to +511
print(
f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})"
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Split the long f-string to satisfy style constraints.

This line likely exceeds the 88-char limit and can be made cleaner by extracting the label first.

✂️ Suggested cleanup
-    print(
-        f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})"
-    )
+    token_program_label = (
+        "Token2022" if token_data["is_token_2022"] else "Standard Token"
+    )
+    print(f"Token Program: {token_program} ({token_program_label})")

As per coding guidelines: Limit lines to 88 characters and use double quotes for strings consistently.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print(
f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})"
)
token_program_label = (
"Token2022" if token_data["is_token_2022"] else "Standard Token"
)
print(f"Token Program: {token_program} ({token_program_label})")
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@learning-examples/manual_buy.py` around lines 509 - 511, The long f-string in
the print call exceeds style limits and uses single quotes; change it by
computing the token type into a short variable (e.g., token_type = "Token2022"
if token_data["is_token_2022"] else "Standard Token") and then use a shorter
print statement like print(f"Token Program: {token_program} ({token_type})") so
no line exceeds 88 characters and double quotes are used consistently; update
the print call that references token_program and token_data["is_token_2022"]
accordingly.

@smypmsa smypmsa merged commit 546b94a into main Feb 27, 2026
2 checks passed
@smypmsa smypmsa deleted the fix/learning-examples-bonding-curve-v2 branch February 27, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

All buy transaction fail - Overflow error

1 participant