tensor_amm/generated/accounts/
pool.rs1use crate::generated::types::PoolConfig;
9use crate::generated::types::PoolStats;
10use crate::hooked::Currency;
11use crate::hooked::NullableAddress;
12use borsh::BorshDeserialize;
13use borsh::BorshSerialize;
14use solana_program::pubkey::Pubkey;
15
16#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21pub struct Pool {
22 pub discriminator: [u8; 8],
23 pub version: u8,
25 pub bump: [u8; 1],
27 pub pool_id: [u8; 32],
29 pub created_at: i64,
31 pub updated_at: i64,
33 pub expiry: i64,
35 #[cfg_attr(
37 feature = "serde",
38 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
39 )]
40 pub owner: Pubkey,
41 #[cfg_attr(
43 feature = "serde",
44 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
45 )]
46 pub whitelist: Pubkey,
47 #[cfg_attr(
48 feature = "serde",
49 serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
50 )]
51 pub rent_payer: Pubkey,
52 pub currency: Currency,
53 pub amount: u64,
55 pub price_offset: i32,
60 pub nfts_held: u32,
62 pub stats: PoolStats,
64 pub shared_escrow: NullableAddress,
67 pub cosigner: NullableAddress,
70 pub maker_broker: NullableAddress,
73 pub max_taker_sell_count: u32,
75 pub config: PoolConfig,
77 #[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::Bytes>"))]
79 pub reserved: [u8; 100],
80}
81
82impl Pool {
83 pub const LEN: usize = 447;
84
85 pub const PREFIX: &'static [u8] = "pool".as_bytes();
93
94 pub fn create_pda(
95 owner: Pubkey,
96 pool_id: [u8; 32],
97 bump: u8,
98 ) -> Result<solana_program::pubkey::Pubkey, solana_program::pubkey::PubkeyError> {
99 solana_program::pubkey::Pubkey::create_program_address(
100 &["pool".as_bytes(), owner.as_ref(), &pool_id, &[bump]],
101 &crate::TENSOR_AMM_ID,
102 )
103 }
104
105 pub fn find_pda(owner: &Pubkey, pool_id: [u8; 32]) -> (solana_program::pubkey::Pubkey, u8) {
106 solana_program::pubkey::Pubkey::find_program_address(
107 &["pool".as_bytes(), owner.as_ref(), &pool_id],
108 &crate::TENSOR_AMM_ID,
109 )
110 }
111
112 #[inline(always)]
113 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
114 let mut data = data;
115 Self::deserialize(&mut data)
116 }
117}
118
119impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Pool {
120 type Error = std::io::Error;
121
122 fn try_from(
123 account_info: &solana_program::account_info::AccountInfo<'a>,
124 ) -> Result<Self, Self::Error> {
125 let mut data: &[u8] = &(*account_info.data).borrow();
126 Self::deserialize(&mut data)
127 }
128}
129
130#[cfg(feature = "anchor")]
131impl anchor_lang::AccountDeserialize for Pool {
132 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
133 Ok(Self::deserialize(buf)?)
134 }
135}
136
137#[cfg(feature = "anchor")]
138impl anchor_lang::AccountSerialize for Pool {}
139
140#[cfg(feature = "anchor")]
141impl anchor_lang::Owner for Pool {
142 fn owner() -> Pubkey {
143 crate::TENSOR_AMM_ID
144 }
145}
146
147#[cfg(feature = "anchor-idl-build")]
148impl anchor_lang::IdlBuild for Pool {}
149
150#[cfg(feature = "anchor-idl-build")]
151impl anchor_lang::Discriminator for Pool {
152 const DISCRIMINATOR: [u8; 8] = [0; 8];
153}