sendfun-sdk 3.0.0

Rust SDK for send.fun programs
Documentation
#![allow(
	clippy::all,
	clippy::pedantic,
	clippy::nursery,
	clippy::expect_used,
	clippy::unwrap_used,
	clippy::indexing_slicing,
	clippy::allow_attributes,
	clippy::allow_attributes_without_reason,
	clippy::mem_forget,
	unfulfilled_lint_expectations,
	unexpected_cfgs,
	unused_imports
)]

//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use crate::launchpad::generated::events::ANCHOR_EVENT_CPI_DISCRIMINATOR;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_address::Address;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct MigrateEvent {
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub bonding_curve: Address,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub base_mint: Address,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub quote_mint: Address,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub pool: Address,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub coin_creator: Address,
	pub padding0: [u64; 4],
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub platform_config: Address,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub base_amount: u64,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub quote_amount: u64,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub real_quote_reserves: u64,
	#[cfg_attr(
		feature = "serde",
		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
	)]
	pub timestamp: i64,
}

pub const MIGRATE_EVENT_DISCRIMINATOR: [u8; 8] =
	[216, 175, 231, 95, 45, 98, 108, 21];

impl MigrateEvent {
	/// Anchor discriminators are derived from names alone, so identical bytes recur across
	/// programs and the bytes alone cannot tell this event from a foreign one.
	#[inline(always)]
	pub fn matches(program_id: &solana_address::Address, data: &[u8]) -> bool {
		program_id == &crate::launchpad::generated::SEND_LAUNCHPAD_ID
			&& data.get(..ANCHOR_EVENT_CPI_DISCRIMINATOR.len())
				== Some(&ANCHOR_EVENT_CPI_DISCRIMINATOR[..])
			&& data.get(8..16) == Some(&MIGRATE_EVENT_DISCRIMINATOR[..])
	}

	/// `None` when [`Self::matches`] is false; `Some(Err(_))` when it matches but the body fails
	/// to deserialize. Use [`Option::transpose`] to propagate the failure with `?`.
	#[inline(always)]
	pub fn try_parse(
		program_id: &solana_address::Address,
		data: &[u8],
	) -> Option<Result<Self, std::io::Error>> {
		if !Self::matches(program_id, data) {
			return None;
		}
		// ANCHOR_EVENT_CPI_DISCRIMINATOR (8) + MIGRATE_EVENT_DISCRIMINATOR (8)
		let mut data = &data[16..];
		Some(Self::deserialize(&mut data))
	}
}