tensor_amm/generated/accounts/
pool.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use 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/// `Pool` is the main state account in the AMM program and represents the AMM pool where trades can happen.
17/// `Pool` accounts are Program Derived Addresses derived  from the seeds: `"pool"`, `owner`, and `identifier`.
18
19#[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    /// Pool version, used to control upgrades.
24    pub version: u8,
25    /// Bump seed for the pool PDA.
26    pub bump: [u8; 1],
27    /// Owner-chosen identifier for the pool
28    pub pool_id: [u8; 32],
29    /// Unix timestamp of the pool creation, in seconds.
30    pub created_at: i64,
31    /// Unix timestamp of the last time the pool has been updated, in seconds.
32    pub updated_at: i64,
33    /// Unix timestamp of when the pool expires, in seconds.
34    pub expiry: i64,
35    /// The owner of the pool.
36    #[cfg_attr(
37        feature = "serde",
38        serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
39    )]
40    pub owner: Pubkey,
41    /// The whitelist of the pool, determining which NFTs can be deposited or sold into the pool.
42    #[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    /// The amount of currency held in the pool.
54    pub amount: u64,
55    /// The difference between the number of buys and sells
56    /// where a postive number indicates the taker has BOUGHT more NFTs than sold
57    /// and a negative number indicates the taker has SOLD more NFTs than bought.
58    /// This is used to calculate the current price of the pool.
59    pub price_offset: i32,
60    /// The number of NFTs currently held in the pool.
61    pub nfts_held: u32,
62    /// Various stats about the pool, including the number of buys and sells.
63    pub stats: PoolStats,
64    /// If an escrow account is present, it means it's a shared-escrow pool where liquidity is shared with other pools.
65    /// Default pubkey is interpreted as no value.
66    pub shared_escrow: NullableAddress,
67    /// An offchain actor that signs off to make sure an offchain condition is met (eg trait present).
68    /// Default pubkey is interpreted as no value.
69    pub cosigner: NullableAddress,
70    /// Maker broker fees will be sent to this address if populated.
71    /// Default pubkey is interpreted as no value.
72    pub maker_broker: NullableAddress,
73    /// Limit how many buys a pool can execute - useful for shared escrow pools, else keeps buying into infinity.
74    pub max_taker_sell_count: u32,
75    /// Pool configuration values.
76    pub config: PoolConfig,
77    /// Reserved space for future upgrades.
78    #[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    /// Prefix values used to generate a PDA for this account.
86    ///
87    /// Values are positional and appear in the following order:
88    ///
89    ///   0. `Pool::PREFIX`
90    ///   1. owner (`Pubkey`)
91    ///   2. pool_id (`[u8; 32]`)
92    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}