pump_fun_token_launcher/
instruction.rs

1use crate::constants::*;
2use anchor_lang::prelude::*;
3use solana_sdk::{
4    instruction::Instruction,
5    signature::{Keypair, Signer},
6    system_program::ID as SYSTEM_PROGRAM_ID,
7    sysvar::rent::ID as RENT_ID,
8};
9
10#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug)]
11pub struct CreateLayout {
12    pub name: String,
13    pub symbol: String,
14    pub uri: String,
15}
16
17pub fn get_create_instruction(
18    payer: &Keypair,
19    mint: &Keypair,
20    name: &str,
21    symbol: &str,
22    uri: &str,
23) -> anyhow::Result<Instruction> {
24    let create_layout = CreateLayout {
25        name: name.to_string(),
26        symbol: symbol.to_string(),
27        uri: uri.to_string(),
28    };
29    let mut concatenated_data = Vec::from(CREATE_DISCRIMINATOR);
30    let serialized_data = create_layout.try_to_vec()?;
31    concatenated_data.extend_from_slice(&serialized_data);
32
33    let bonding_curve = Pubkey::find_program_address(
34        &["bonding-curve".as_bytes(), &mint.pubkey().to_bytes()],
35        &PUMPFUN_PROGRAM,
36    )
37    .0;
38
39    let bonding_curve_ata = Pubkey::find_program_address(
40        &[
41            &bonding_curve.to_bytes(),
42            &TOKEN_PROGRAM_ID.to_bytes(),
43            &mint.to_bytes(),
44        ],
45        &ASSOCIATED_TOKEN_PROGRAM_ID,
46    )
47    .0;
48    let metadata = Pubkey::find_program_address(
49        &[
50            "metadata".as_bytes(),
51            &MPL_TOKEN_METADATA.to_bytes(),
52            &mint.pubkey().to_bytes(),
53        ],
54        &MPL_TOKEN_METADATA,
55    )
56    .0;
57
58    let instruction_accounts = vec![
59        AccountMeta::new(mint.pubkey(), true),
60        AccountMeta::new_readonly(PUMPFUN_TOKEN_MINT_AUTHORITY, false),
61        AccountMeta::new(bonding_curve, false),
62        AccountMeta::new(bonding_curve_ata, false),
63        AccountMeta::new_readonly(PUMPFUN_GLOBAL, false),
64        AccountMeta::new_readonly(MPL_TOKEN_METADATA, false),
65        AccountMeta::new(metadata, false),
66        AccountMeta::new(payer.pubkey(), true),
67        AccountMeta::new_readonly(SYSTEM_PROGRAM_ID, false),
68        AccountMeta::new_readonly(TOKEN_PROGRAM_ID, false),
69        AccountMeta::new_readonly(ASSOCIATED_TOKEN_PROGRAM_ID, false),
70        AccountMeta::new_readonly(RENT_ID, false),
71        AccountMeta::new_readonly(PUMPFUN_EVENT_AUTHORITY, false),
72        AccountMeta::new_readonly(PUMPFUN_PROGRAM, false),
73    ];
74
75    let ix_final =
76        Instruction::new_with_bytes(PUMPFUN_PROGRAM, &concatenated_data, instruction_accounts);
77
78    Ok(ix_final)
79}