feat(examples): update bonding curve buy instructions

This commit is contained in:
smypmsa
2025-08-01 05:05:55 +00:00
parent 9bfbb7f4eb
commit 4fd3181612
2 changed files with 46 additions and 0 deletions
+23
View File
@@ -104,6 +104,27 @@ def _find_creator_vault(creator: Pubkey) -> Pubkey:
return derived_address
def _find_global_volume_accumulator() -> Pubkey:
derived_address, _ = Pubkey.find_program_address(
[
b"global_volume_accumulator"
],
PUMP_PROGRAM,
)
return derived_address
def _find_user_volume_accumulator(user: Pubkey) -> Pubkey:
derived_address, _ = Pubkey.find_program_address(
[
b"user_volume_accumulator",
bytes(user)
],
PUMP_PROGRAM,
)
return derived_address
async def buy_token(
mint: Pubkey,
bonding_curve: Pubkey,
@@ -153,6 +174,8 @@ async def buy_token(
pubkey=PUMP_EVENT_AUTHORITY, is_signer=False, is_writable=False
),
AccountMeta(pubkey=PUMP_PROGRAM, is_signer=False, is_writable=False),
AccountMeta(pubkey=_find_global_volume_accumulator(), is_signer=False, is_writable=True),
AccountMeta(pubkey=_find_user_volume_accumulator(payer.pubkey()), is_signer=False, is_writable=True),
]
discriminator = struct.pack("<Q", 16927863322537952870)
+23
View File
@@ -101,6 +101,27 @@ def find_creator_vault(creator: Pubkey) -> Pubkey:
return derived_address
def _find_global_volume_accumulator() -> Pubkey:
derived_address, _ = Pubkey.find_program_address(
[
b"global_volume_accumulator"
],
PUMP_PROGRAM,
)
return derived_address
def _find_user_volume_accumulator(user: Pubkey) -> Pubkey:
derived_address, _ = Pubkey.find_program_address(
[
b"user_volume_accumulator",
bytes(user)
],
PUMP_PROGRAM,
)
return derived_address
def create_pump_create_instruction(
mint: Pubkey,
mint_authority: Pubkey,
@@ -177,6 +198,8 @@ def create_buy_instruction(
AccountMeta(pubkey=creator_vault, is_signer=False, is_writable=True),
AccountMeta(pubkey=PUMP_EVENT_AUTHORITY, is_signer=False, is_writable=False),
AccountMeta(pubkey=PUMP_PROGRAM, is_signer=False, is_writable=False),
AccountMeta(pubkey=_find_global_volume_accumulator(), is_signer=False, is_writable=True),
AccountMeta(pubkey=_find_user_volume_accumulator(user), is_signer=False, is_writable=True),
]
data = (