Skip to content

Commit 546b94a

Browse files
smypmsaclaude
andauthored
fix(examples): add bonding_curve_v2 to learning examples (#160)
* fix(examples): add bonding_curve_v2 remaining account to learning examples 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> * fix(examples): add bonding_curve_v2 to manual_buy_geyser and manual_buy_cu_optimized Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4a48f54 commit 546b94a

6 files changed

Lines changed: 136 additions & 22 deletions

File tree

learning-examples/manual_buy.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ def _find_fee_config() -> Pubkey:
159159
return derived_address
160160

161161

162+
def _find_bonding_curve_v2(mint: Pubkey) -> Pubkey:
163+
derived_address, _ = Pubkey.find_program_address(
164+
[b"bonding-curve-v2", bytes(mint)],
165+
PUMP_PROGRAM,
166+
)
167+
return derived_address
168+
169+
162170
async def get_fee_recipient(
163171
client: AsyncClient, curve_state: BondingCurveState
164172
) -> Pubkey:
@@ -253,9 +261,7 @@ async def buy_token(
253261
),
254262
AccountMeta(pubkey=payer.pubkey(), is_signer=True, is_writable=True),
255263
AccountMeta(pubkey=SYSTEM_PROGRAM, is_signer=False, is_writable=False),
256-
AccountMeta(
257-
pubkey=token_program, is_signer=False, is_writable=False
258-
),
264+
AccountMeta(pubkey=token_program, is_signer=False, is_writable=False),
259265
AccountMeta(pubkey=creator_vault, is_signer=False, is_writable=True),
260266
AccountMeta(
261267
pubkey=PUMP_EVENT_AUTHORITY, is_signer=False, is_writable=False
@@ -283,6 +289,12 @@ async def buy_token(
283289
is_signer=False,
284290
is_writable=False,
285291
),
292+
# Remaining account: bonding_curve_v2 (readonly, required for all coins)
293+
AccountMeta(
294+
pubkey=_find_bonding_curve_v2(mint),
295+
is_signer=False,
296+
is_writable=False,
297+
),
286298
]
287299

288300
discriminator = struct.pack("<Q", 16927863322537952870)
@@ -433,7 +445,9 @@ async def listen_for_create_transaction():
433445
if discriminator == create_discriminator:
434446
instruction_name = "create"
435447
token_program = SYSTEM_TOKEN_PROGRAM
436-
elif discriminator == create_v2_discriminator:
448+
elif (
449+
discriminator == create_v2_discriminator
450+
):
437451
instruction_name = "create_v2"
438452
token_program = TOKEN_2022_PROGRAM
439453

@@ -457,8 +471,12 @@ async def listen_for_create_transaction():
457471
)
458472
)
459473
# Add token program info to decoded args
460-
decoded_args["token_program"] = str(token_program)
461-
decoded_args["is_token_2022"] = (token_program == TOKEN_2022_PROGRAM)
474+
decoded_args["token_program"] = str(
475+
token_program
476+
)
477+
decoded_args["is_token_2022"] = (
478+
token_program == TOKEN_2022_PROGRAM
479+
)
462480
return decoded_args
463481

464482

@@ -488,13 +506,21 @@ async def main():
488506
slippage = 0.3 # 30% slippage tolerance
489507

490508
print(f"Bonding curve address: {bonding_curve}")
491-
print(f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})")
509+
print(
510+
f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})"
511+
)
492512
print(f"Token price: {token_price_sol:.10f} SOL")
493513
print(
494514
f"Buying {amount:.6f} SOL worth of the new token with {slippage * 100:.1f}% slippage tolerance..."
495515
)
496516
await buy_token(
497-
mint, bonding_curve, associated_bonding_curve, creator_vault, token_program, amount, slippage
517+
mint,
518+
bonding_curve,
519+
associated_bonding_curve,
520+
creator_vault,
521+
token_program,
522+
amount,
523+
slippage,
498524
)
499525

500526

learning-examples/manual_buy_cu_optimized.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ def _find_fee_config() -> Pubkey:
180180
return derived_address
181181

182182

183+
def _find_bonding_curve_v2(mint: Pubkey) -> Pubkey:
184+
derived_address, _ = Pubkey.find_program_address(
185+
[b"bonding-curve-v2", bytes(mint)],
186+
PUMP_PROGRAM,
187+
)
188+
return derived_address
189+
190+
183191
async def get_fee_recipient(
184192
client: AsyncClient, curve_state: BondingCurveState
185193
) -> Pubkey:
@@ -291,9 +299,7 @@ async def buy_token(
291299
),
292300
AccountMeta(pubkey=payer.pubkey(), is_signer=True, is_writable=True),
293301
AccountMeta(pubkey=SYSTEM_PROGRAM, is_signer=False, is_writable=False),
294-
AccountMeta(
295-
pubkey=token_program, is_signer=False, is_writable=False
296-
),
302+
AccountMeta(pubkey=token_program, is_signer=False, is_writable=False),
297303
AccountMeta(pubkey=creator_vault, is_signer=False, is_writable=True),
298304
AccountMeta(
299305
pubkey=PUMP_EVENT_AUTHORITY, is_signer=False, is_writable=False
@@ -321,6 +327,12 @@ async def buy_token(
321327
is_signer=False,
322328
is_writable=False,
323329
),
330+
# Remaining account: bonding_curve_v2 (readonly, required for all coins)
331+
AccountMeta(
332+
pubkey=_find_bonding_curve_v2(mint),
333+
is_signer=False,
334+
is_writable=False,
335+
),
324336
]
325337

326338
discriminator = struct.pack("<Q", 16927863322537952870)
@@ -475,7 +487,9 @@ async def listen_for_create_transaction():
475487
if discriminator == create_discriminator:
476488
instruction_name = "create"
477489
token_program = SYSTEM_TOKEN_PROGRAM
478-
elif discriminator == create_v2_discriminator:
490+
elif (
491+
discriminator == create_v2_discriminator
492+
):
479493
instruction_name = "create_v2"
480494
token_program = TOKEN_2022_PROGRAM
481495

@@ -499,8 +513,12 @@ async def listen_for_create_transaction():
499513
)
500514
)
501515
# Add token program info to decoded args
502-
decoded_args["token_program"] = str(token_program)
503-
decoded_args["is_token_2022"] = (token_program == TOKEN_2022_PROGRAM)
516+
decoded_args["token_program"] = str(
517+
token_program
518+
)
519+
decoded_args["is_token_2022"] = (
520+
token_program == TOKEN_2022_PROGRAM
521+
)
504522
return decoded_args
505523

506524

@@ -529,14 +547,22 @@ async def main():
529547
slippage = 0.3 # 30% slippage tolerance
530548

531549
print(f"Bonding curve address: {bonding_curve}")
532-
print(f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})")
550+
print(
551+
f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})"
552+
)
533553
print(f"Token price: {token_price_sol:.10f} SOL")
534554
print(
535555
f"Buying {amount:.6f} SOL worth of the new token with {slippage * 100:.1f}% slippage tolerance..."
536556
)
537557
print("CU Optimization: Enabled (512KB account data limit)")
538558
await buy_token(
539-
mint, bonding_curve, associated_bonding_curve, creator_vault, token_program, amount, slippage
559+
mint,
560+
bonding_curve,
561+
associated_bonding_curve,
562+
creator_vault,
563+
token_program,
564+
amount,
565+
slippage,
540566
)
541567

542568

learning-examples/manual_buy_geyser.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ def _find_fee_config() -> Pubkey:
172172
return derived_address
173173

174174

175+
def _find_bonding_curve_v2(mint: Pubkey) -> Pubkey:
176+
derived_address, _ = Pubkey.find_program_address(
177+
[b"bonding-curve-v2", bytes(mint)],
178+
PUMP_PROGRAM,
179+
)
180+
return derived_address
181+
182+
175183
async def get_fee_recipient(
176184
client: AsyncClient, curve_state: BondingCurveState
177185
) -> Pubkey:
@@ -328,7 +336,7 @@ async def listen_for_create_transaction_geyser():
328336

329337
# Add token program info to decoded args
330338
token_data["token_program"] = str(token_program)
331-
token_data["is_token_2022"] = (token_program == SYSTEM_TOKEN_2022_PROGRAM)
339+
token_data["is_token_2022"] = token_program == SYSTEM_TOKEN_2022_PROGRAM
332340

333341
signature = base58.b58encode(
334342
bytes(update.transaction.transaction.signature)
@@ -391,9 +399,7 @@ async def buy_token(
391399
),
392400
AccountMeta(pubkey=payer.pubkey(), is_signer=True, is_writable=True),
393401
AccountMeta(pubkey=SYSTEM_PROGRAM, is_signer=False, is_writable=False),
394-
AccountMeta(
395-
pubkey=token_program, is_signer=False, is_writable=False
396-
),
402+
AccountMeta(pubkey=token_program, is_signer=False, is_writable=False),
397403
AccountMeta(pubkey=creator_vault, is_signer=False, is_writable=True),
398404
AccountMeta(
399405
pubkey=PUMP_EVENT_AUTHORITY, is_signer=False, is_writable=False
@@ -421,6 +427,12 @@ async def buy_token(
421427
is_signer=False,
422428
is_writable=False,
423429
),
430+
# Remaining account: bonding_curve_v2 (readonly, required for all coins)
431+
AccountMeta(
432+
pubkey=_find_bonding_curve_v2(mint),
433+
is_signer=False,
434+
is_writable=False,
435+
),
424436
]
425437

426438
discriminator = struct.pack("<Q", 16927863322537952870)
@@ -508,13 +520,21 @@ async def main():
508520
slippage = 0.3 # 30% slippage tolerance
509521

510522
print(f"Bonding curve address: {bonding_curve}")
511-
print(f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})")
523+
print(
524+
f"Token Program: {token_program} ({'Token2022' if token_data['is_token_2022'] else 'Standard Token'})"
525+
)
512526
# print(f"Token price: {token_price_sol:.10f} SOL")
513527
print(
514528
f"Buying {amount:.6f} SOL worth of the new token with {slippage * 100:.1f}% slippage tolerance..."
515529
)
516530
await buy_token(
517-
mint, bonding_curve, associated_bonding_curve, creator_vault, token_program, amount, slippage
531+
mint,
532+
bonding_curve,
533+
associated_bonding_curve,
534+
creator_vault,
535+
token_program,
536+
amount,
537+
slippage,
518538
)
519539

520540

learning-examples/manual_sell.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ def _find_fee_config() -> Pubkey:
147147
return derived_address
148148

149149

150+
def _find_bonding_curve_v2(mint: Pubkey) -> Pubkey:
151+
derived_address, _ = Pubkey.find_program_address(
152+
[b"bonding-curve-v2", bytes(mint)],
153+
PUMP_PROGRAM,
154+
)
155+
return derived_address
156+
157+
150158
async def get_fee_recipient(
151159
client: AsyncClient, curve_state: BondingCurveState
152160
) -> Pubkey:
@@ -312,6 +320,12 @@ async def sell_token(
312320
is_signer=False,
313321
is_writable=False,
314322
),
323+
# Remaining account: bonding_curve_v2 (readonly, required for all coins)
324+
AccountMeta(
325+
pubkey=_find_bonding_curve_v2(mint),
326+
is_signer=False,
327+
is_writable=False,
328+
),
315329
]
316330

317331
discriminator = struct.pack("<Q", 12502976635542562355)

learning-examples/mint_and_buy.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,14 @@ def _find_fee_config() -> Pubkey:
143143
return derived_address
144144

145145

146+
def _find_bonding_curve_v2(mint: Pubkey) -> Pubkey:
147+
derived_address, _ = Pubkey.find_program_address(
148+
[b"bonding-curve-v2", bytes(mint)],
149+
PUMP_PROGRAM,
150+
)
151+
return derived_address
152+
153+
146154
def create_pump_create_instruction(
147155
mint: Pubkey,
148156
mint_authority: Pubkey,
@@ -263,6 +271,12 @@ def create_buy_instruction(
263271
is_signer=False,
264272
is_writable=False,
265273
),
274+
# Remaining account: bonding_curve_v2 (readonly, required for all coins)
275+
AccountMeta(
276+
pubkey=_find_bonding_curve_v2(mint),
277+
is_signer=False,
278+
is_writable=False,
279+
),
266280
]
267281

268282
# Encode OptionBool for track_volume

learning-examples/mint_and_buy_v2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ def _find_fee_config() -> Pubkey:
159159
return derived_address
160160

161161

162+
def _find_bonding_curve_v2(mint: Pubkey) -> Pubkey:
163+
derived_address, _ = Pubkey.find_program_address(
164+
[b"bonding-curve-v2", bytes(mint)],
165+
PUMP_PROGRAM,
166+
)
167+
return derived_address
168+
169+
162170
def create_pump_create_v2_instruction(
163171
mint: Pubkey,
164172
mint_authority: Pubkey,
@@ -307,6 +315,12 @@ def create_buy_instruction(
307315
is_signer=False,
308316
is_writable=False,
309317
),
318+
# Remaining account: bonding_curve_v2 (readonly, required for all coins)
319+
AccountMeta(
320+
pubkey=_find_bonding_curve_v2(mint),
321+
is_signer=False,
322+
is_writable=False,
323+
),
310324
]
311325

312326
# Encode OptionBool for track_volume

0 commit comments

Comments
 (0)