Skip to main content

sendfun_sdk/launchpad/generated/events/
token_create_event.rs

1#![allow(
2	clippy::all,
3	clippy::pedantic,
4	clippy::nursery,
5	clippy::expect_used,
6	clippy::unwrap_used,
7	clippy::indexing_slicing,
8	clippy::allow_attributes,
9	clippy::allow_attributes_without_reason,
10	clippy::mem_forget,
11	unfulfilled_lint_expectations,
12	unexpected_cfgs,
13	unused_imports
14)]
15
16//! This code was AUTOGENERATED using the codama library.
17//! Please DO NOT EDIT THIS FILE, instead use visitors
18//! to add features, then rerun codama to update it.
19//!
20//! <https://github.com/codama-idl/codama>
21//!
22
23use crate::launchpad::generated::events::ANCHOR_EVENT_CPI_DISCRIMINATOR;
24use borsh::BorshDeserialize;
25use borsh::BorshSerialize;
26use solana_address::Address;
27
28#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
29#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
30#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
31pub struct TokenCreateEvent {
32	#[cfg_attr(
33		feature = "serde",
34		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
35	)]
36	pub bonding_curve: Address,
37	#[cfg_attr(
38		feature = "serde",
39		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
40	)]
41	pub base_mint: Address,
42	pub base_decimals: u8,
43	#[cfg_attr(
44		feature = "serde",
45		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
46	)]
47	pub base_supply: u64,
48	#[cfg_attr(
49		feature = "serde",
50		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
51	)]
52	pub initial_virtual_base: u64,
53	#[cfg_attr(
54		feature = "serde",
55		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
56	)]
57	pub initial_virtual_quote: u64,
58	#[cfg_attr(
59		feature = "serde",
60		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
61	)]
62	pub initial_real_base: u64,
63	#[cfg_attr(
64		feature = "serde",
65		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
66	)]
67	pub quote_mint: Address,
68	pub quote_decimals: u8,
69	#[cfg_attr(
70		feature = "serde",
71		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
72	)]
73	pub coin_creator: Address,
74	pub padding0: [u64; 5],
75	#[cfg_attr(
76		feature = "serde",
77		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
78	)]
79	pub platform_config: Address,
80	pub name: String,
81	pub symbol: String,
82	pub uri: String,
83	#[cfg_attr(
84		feature = "serde",
85		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
86	)]
87	pub partner: Address,
88	pub is_partner: bool,
89	#[cfg_attr(
90		feature = "serde",
91		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
92	)]
93	pub creation_fee: u64,
94	#[cfg_attr(
95		feature = "serde",
96		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
97	)]
98	pub virtual_base_reserves: u64,
99	#[cfg_attr(
100		feature = "serde",
101		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
102	)]
103	pub virtual_quote_reserves: u64,
104	#[cfg_attr(
105		feature = "serde",
106		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
107	)]
108	pub real_base_reserves: u64,
109	#[cfg_attr(
110		feature = "serde",
111		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
112	)]
113	pub real_quote_reserves: u64,
114	#[cfg_attr(
115		feature = "serde",
116		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
117	)]
118	pub timestamp: i64,
119	pub creator_fee_mode: u8,
120	pub creator_fee_bps: u16,
121	pub dex_creator_fee_bps: u16,
122}
123
124pub const TOKEN_CREATE_EVENT_DISCRIMINATOR: [u8; 8] =
125	[152, 16, 194, 59, 171, 105, 172, 45];
126
127impl TokenCreateEvent {
128	/// Anchor discriminators are derived from names alone, so identical bytes recur across
129	/// programs and the bytes alone cannot tell this event from a foreign one.
130	#[inline(always)]
131	pub fn matches(program_id: &solana_address::Address, data: &[u8]) -> bool {
132		program_id == &crate::launchpad::generated::SEND_LAUNCHPAD_ID
133			&& data.get(..ANCHOR_EVENT_CPI_DISCRIMINATOR.len())
134				== Some(&ANCHOR_EVENT_CPI_DISCRIMINATOR[..])
135			&& data.get(8..16) == Some(&TOKEN_CREATE_EVENT_DISCRIMINATOR[..])
136	}
137
138	/// `None` when [`Self::matches`] is false; `Some(Err(_))` when it matches but the body fails
139	/// to deserialize. Use [`Option::transpose`] to propagate the failure with `?`.
140	#[inline(always)]
141	pub fn try_parse(
142		program_id: &solana_address::Address,
143		data: &[u8],
144	) -> Option<Result<Self, std::io::Error>> {
145		if !Self::matches(program_id, data) {
146			return None;
147		}
148		// ANCHOR_EVENT_CPI_DISCRIMINATOR (8) + TOKEN_CREATE_EVENT_DISCRIMINATOR (8)
149		let mut data = &data[16..];
150		Some(Self::deserialize(&mut data))
151	}
152}