solana_central/pumpfun/
from_account_info.rs

1use crate::constants::PUMP_CONSTANTS;
2use crate::protocol_idls::pumpfun::PfBondingCurveIdl;
3use crate::pumpfun::derive_bonding_curve::derive_bonding_curve;
4use crate::types::pf_bonding_curve::PfBondingCurve;
5use borsh::BorshDeserialize;
6use solana_sdk::pubkey::Pubkey;
7use spl_associated_token_account::get_associated_token_address;
8
9impl PfBondingCurve {
10  /**
11  This function takes in the TOKEN ADDRESS that the bonding curve is for, as well as the raw bonding
12  curve data. When you call the this function, fetch the data for the derived bonding curve address
13  from the token address using derive_bonding_curve.
14  
15  USAGE:
16  ```rust
17  let token_address = Pubkey::from_str_const("ERHiB4WJQX1WQXc88hXXcie3uCStYH5Uzz3MPJW4rwKe");
18  let bonding_curve_address = derive_bonding_curve(&token_address);
19  let pf_bonding_curve = PfBondingCurve::from_account_info(
20    token_address,
21    &context
22      .json_rpc_client
23      .get_account(&bonding_curve_address)
24      .unwrap()
25      .data,
26  );
27  println!("{:?}", pf_bonding_curve);
28  ```
29  */
30  pub fn from_account_info(token_address: Pubkey, account_buffer: &[u8]) -> Self {
31    let decoded_layout = PfBondingCurveIdl::try_from_slice(account_buffer)
32      .expect("Failed to deserialize Pf Bonding Curve account");
33
34    let (creator_vault_address, _) = Pubkey::find_program_address(
35      &[b"creator-vault", decoded_layout.creator.as_array()],
36      &PUMP_CONSTANTS.bonding_curve_program,
37    );
38    let bonding_curve_address = derive_bonding_curve(&token_address);
39
40    Self {
41      virtual_sol_reserves: decoded_layout.virtual_sol_reserves,
42      virtual_token_reserves: decoded_layout.virtual_token_reserves,
43      complete: decoded_layout.complete,
44      token_address,
45      bonding_curve_address,
46      bonding_curve_associated_token_account_address: get_associated_token_address(
47        &bonding_curve_address,
48        &token_address,
49      ),
50      creator_vault_address,
51    }
52  }
53}