Skip to main content

sendfun_sdk/dex/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::dex::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 pool: 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 quote_mint: Address,
53	pub quote_decimals: u8,
54	#[cfg_attr(
55		feature = "serde",
56		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
57	)]
58	pub coin_creator: Address,
59	pub creator_platform: String,
60	pub creator_id: String,
61	#[cfg_attr(
62		feature = "serde",
63		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
64	)]
65	pub creator_fee_config: Address,
66	#[cfg_attr(
67		feature = "serde",
68		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
69	)]
70	pub platform_config: Address,
71	pub name: String,
72	pub symbol: String,
73	pub uri: String,
74	#[cfg_attr(
75		feature = "serde",
76		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
77	)]
78	pub partner: Address,
79	pub is_partner: bool,
80	#[cfg_attr(
81		feature = "serde",
82		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
83	)]
84	pub creation_fee: u64,
85	#[cfg_attr(
86		feature = "serde",
87		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
88	)]
89	pub base_reserves: u64,
90	#[cfg_attr(
91		feature = "serde",
92		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
93	)]
94	pub quote_reserves: u64,
95	#[cfg_attr(
96		feature = "serde",
97		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
98	)]
99	pub timestamp: i64,
100}
101
102pub const TOKEN_CREATE_EVENT_DISCRIMINATOR: [u8; 8] =
103	[152, 16, 194, 59, 171, 105, 172, 45];
104
105impl TokenCreateEvent {
106	/// Anchor discriminators are derived from names alone, so identical bytes recur across
107	/// programs and the bytes alone cannot tell this event from a foreign one.
108	#[inline(always)]
109	pub fn matches(program_id: &solana_address::Address, data: &[u8]) -> bool {
110		program_id == &crate::dex::generated::SEND_DEX_ID
111			&& data.get(..ANCHOR_EVENT_CPI_DISCRIMINATOR.len())
112				== Some(&ANCHOR_EVENT_CPI_DISCRIMINATOR[..])
113			&& data.get(8..16) == Some(&TOKEN_CREATE_EVENT_DISCRIMINATOR[..])
114	}
115
116	/// `None` when [`Self::matches`] is false; `Some(Err(_))` when it matches but the body fails
117	/// to deserialize. Use [`Option::transpose`] to propagate the failure with `?`.
118	#[inline(always)]
119	pub fn try_parse(
120		program_id: &solana_address::Address,
121		data: &[u8],
122	) -> Option<Result<Self, std::io::Error>> {
123		if !Self::matches(program_id, data) {
124			return None;
125		}
126		// ANCHOR_EVENT_CPI_DISCRIMINATOR (8) + TOKEN_CREATE_EVENT_DISCRIMINATOR (8)
127		let mut data = &data[16..];
128		Some(Self::deserialize(&mut data))
129	}
130}