-
Notifications
You must be signed in to change notification settings - Fork 312
Fix/mint buy example #141
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
Fix/mint buy example #141
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ | |
| load_dotenv() | ||
|
|
||
| TOKEN_MINT_ADDRESS = Pubkey.from_string( | ||
| "MYcq5mUyoAtCfyDWYAWvioou3cgnYjnCvFd7U6fspot" | ||
| "YOUR_TOKEN_MINT_ADDRESS_HERE" | ||
| ) # Replace with actual token mint address | ||
|
Comment on lines
42
to
44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix import-time crash: lazily parse TOKEN_MINT from env Same issue as the other script. Don’t call Pubkey.from_string at module import. Apply this diff here: -TOKEN_MINT_ADDRESS = Pubkey.from_string(
- "YOUR_TOKEN_MINT_ADDRESS_HERE"
-) # Replace with actual token mint address
+TOKEN_MINT_STR = os.environ.get("TOKEN_MINT", "YOUR_TOKEN_MINT_ADDRESS_HERE")And in main(): try:
token_mint = Pubkey.from_string(TOKEN_MINT_STR)
except ValueError as e:
print(f"Invalid TOKEN_MINT: {e}")
sys.exit(1)
# replace TOKEN_MINT_ADDRESS usages with token_mintBased on learnings. 🤖 Prompt for AI Agents |
||
|
|
||
| # Configuration constants | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,7 @@ | |
| load_dotenv() | ||
|
|
||
| TOKEN_MINT_ADDRESS = Pubkey.from_string( | ||
| "MYcq5mUyoAtCfyDWYAWvioou3cgnYjnCvFd7U6fspot" | ||
| "YOUR_TOKEN_MINT_ADDRESS_HERE" | ||
| ) # Replace with actual token mint address | ||
|
Comment on lines
42
to
44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix import-time crash: lazily parse TOKEN_MINT from env Calling Pubkey.from_string on a placeholder raises ValueError at import time; the script never reaches main(). Parse lazily and validate. Apply this diff here: -TOKEN_MINT_ADDRESS = Pubkey.from_string(
- "YOUR_TOKEN_MINT_ADDRESS_HERE"
-) # Replace with actual token mint address
+TOKEN_MINT_STR = os.environ.get("TOKEN_MINT", "YOUR_TOKEN_MINT_ADDRESS_HERE")Then inside main(), parse and use a local variable: # inside main(), before first use
try:
token_mint = Pubkey.from_string(TOKEN_MINT_STR)
except ValueError as e:
print(f"Invalid TOKEN_MINT: {e}")
sys.exit(1)
# replace all TOKEN_MINT_ADDRESS usages with token_mint🤖 Prompt for AI Agents |
||
|
|
||
| # Configuration constants | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,9 @@ | |
| # Discriminators | ||
| CREATE_DISCRIMINATOR: Final[bytes] = struct.pack("<Q", 8576854823835016728) | ||
| BUY_DISCRIMINATOR: Final[bytes] = struct.pack("<Q", 16927863322537952870) | ||
| EXTEND_ACCOUNT_DISCRIMINATOR: Final[bytes] = bytes( | ||
| [234, 102, 194, 203, 150, 72, 62, 229] | ||
| ) | ||
|
|
||
| # From environment | ||
| RPC_ENDPOINT = os.environ.get("SOLANA_NODE_RPC_ENDPOINT") | ||
|
|
@@ -194,6 +197,25 @@ def encode_pubkey(pubkey: Pubkey) -> bytes: | |
| return Instruction(PUMP_PROGRAM, data, accounts) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Instruction() arguments are in wrong order solders.instruction.Instruction expects (program_id, accounts, data). Code passes (program_id, data, accounts), which will corrupt the instruction and fail at runtime. Apply this diff: - return Instruction(PUMP_PROGRAM, data, accounts)
+ return Instruction(PUMP_PROGRAM, accounts, data)Repeat the same fix for:
Also applies to: 216-217, 279-279 🤖 Prompt for AI Agents |
||
|
|
||
|
|
||
| def create_extend_account_instruction( | ||
| bonding_curve: Pubkey, | ||
| user: Pubkey, | ||
| ) -> Instruction: | ||
| """Create the extend_account instruction to expand bonding curve account size.""" | ||
| accounts = [ | ||
| AccountMeta(pubkey=bonding_curve, is_signer=False, is_writable=True), | ||
| AccountMeta(pubkey=user, is_signer=True, is_writable=True), | ||
| AccountMeta(pubkey=SYSTEM_PROGRAM, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=PUMP_EVENT_AUTHORITY, is_signer=False, is_writable=False), | ||
| AccountMeta(pubkey=PUMP_PROGRAM, is_signer=False, is_writable=False), | ||
| ] | ||
|
|
||
| # No arguments for extend_account instruction | ||
| data = EXTEND_ACCOUNT_DISCRIMINATOR | ||
|
|
||
| return Instruction(PUMP_PROGRAM, data, accounts) | ||
|
|
||
|
|
||
| def create_buy_instruction( | ||
| global_state: Pubkey, | ||
| fee_recipient: Pubkey, | ||
|
|
@@ -205,6 +227,7 @@ def create_buy_instruction( | |
| creator_vault: Pubkey, | ||
| token_amount: int, | ||
| max_sol_cost: int, | ||
| track_volume: bool = True, | ||
| ) -> Instruction: | ||
| """Create the buy instruction.""" | ||
| accounts = [ | ||
|
|
@@ -242,10 +265,15 @@ def create_buy_instruction( | |
| ), | ||
| ] | ||
|
|
||
| # Encode OptionBool for track_volume | ||
| # OptionBool: [0] = None, [1, 0] = Some(false), [1, 1] = Some(true) | ||
| track_volume_bytes = bytes([1, 1 if track_volume else 0]) | ||
|
|
||
| data = ( | ||
| BUY_DISCRIMINATOR | ||
| + struct.pack("<Q", token_amount) | ||
| + struct.pack("<Q", max_sol_cost) | ||
| + track_volume_bytes | ||
| ) | ||
|
|
||
| return Instruction(PUMP_PROGRAM, data, accounts) | ||
|
|
@@ -317,6 +345,11 @@ async def main(): | |
| symbol=TOKEN_SYMBOL, | ||
| uri=TOKEN_URI, | ||
| ), | ||
| # Extend bonding curve account (required for frontend visibility) | ||
| create_extend_account_instruction( | ||
| bonding_curve=bonding_curve, | ||
| user=payer.pubkey(), | ||
| ), | ||
| # Create user ATA | ||
| create_idempotent_associated_token_account( | ||
| payer.pubkey(), | ||
|
|
@@ -336,6 +369,7 @@ async def main(): | |
| creator_vault=creator_vault, | ||
| token_amount=expected_tokens, | ||
| max_sol_cost=max_sol_cost, | ||
| track_volume=True, | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Load CURVE_ADDRESS from env and validate
Avoid hardcoded placeholder; read from env and fail fast if unset/placeholder.
Apply this diff:
Add early check:
Run as per guidelines:
🏁 Script executed:
Length of output: 40
🏁 Script executed:
Length of output: 2544
Load CURVE_ADDRESS from env and validate
Replace the hardcoded placeholder at learning-examples/fetch_price.py:15 with an environment lookup and fail fast if it’s unset or still using the placeholder:
Then verify the change by running:
🤖 Prompt for AI Agents