Skip to main content

stellar_xdr/generated/
liquidity_pool_entry.rs

1#[allow(unused_imports, clippy::wildcard_imports)]
2use super::*;
3
4/// LiquidityPoolEntry is an XDR Struct defined as:
5///
6/// ```text
7/// struct LiquidityPoolEntry
8/// {
9///     PoolID liquidityPoolID;
10///
11///     union switch (LiquidityPoolType type)
12///     {
13///     case LIQUIDITY_POOL_CONSTANT_PRODUCT:
14///         struct
15///         {
16///             LiquidityPoolConstantProductParameters params;
17///
18///             int64 reserveA;        // amount of A in the pool
19///             int64 reserveB;        // amount of B in the pool
20///             int64 totalPoolShares; // total number of pool shares issued
21///             int64 poolSharesTrustLineCount; // number of trust lines for the
22///                                             // associated pool shares
23///         } constantProduct;
24///     }
25///     body;
26/// };
27/// ```
28///
29#[cfg_attr(feature = "alloc", derive(Default))]
30#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
31#[cfg_attr(feature = "serde", cfg_eval::cfg_eval)]
32#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
33#[cfg_attr(
34    all(feature = "serde", feature = "alloc"),
35    serde_with::serde_as,
36    derive(serde::Serialize, serde::Deserialize),
37    serde(rename_all = "snake_case")
38)]
39#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
40pub struct LiquidityPoolEntry {
41    pub liquidity_pool_id: PoolId,
42    pub body: LiquidityPoolEntryBody,
43}
44
45impl ReadXdr for LiquidityPoolEntry {
46    #[cfg(feature = "std")]
47    fn read_xdr<R: Read>(r: &mut Limited<R>) -> Result<Self, Error> {
48        r.with_limited_depth(|r| {
49            Ok(Self {
50                liquidity_pool_id: PoolId::read_xdr(r)?,
51                body: LiquidityPoolEntryBody::read_xdr(r)?,
52            })
53        })
54    }
55}
56
57impl WriteXdr for LiquidityPoolEntry {
58    #[cfg(feature = "std")]
59    fn write_xdr<W: Write>(&self, w: &mut Limited<W>) -> Result<(), Error> {
60        w.with_limited_depth(|w| {
61            self.liquidity_pool_id.write_xdr(w)?;
62            self.body.write_xdr(w)?;
63            Ok(())
64        })
65    }
66}