use {
crate::types::graphql::PositionRewardInfoGraphQL,
carbon_core::graphql::primitives::{Pubkey, U128, U64},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Position")]
pub struct PositionGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub whirlpool: Pubkey,
pub position_mint: Pubkey,
pub liquidity: U128,
pub tick_lower_index: i32,
pub tick_upper_index: i32,
pub fee_growth_checkpoint_a: U128,
pub fee_owed_a: U64,
pub fee_growth_checkpoint_b: U128,
pub fee_owed_b: U64,
pub reward_infos: Vec<PositionRewardInfoGraphQL>,
}
impl TryFrom<crate::accounts::postgres::PositionRow> for PositionGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::PositionRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
whirlpool: carbon_core::graphql::primitives::Pubkey(row.whirlpool.0),
position_mint: carbon_core::graphql::primitives::Pubkey(row.position_mint.0),
liquidity: carbon_core::graphql::primitives::U128(*row.liquidity),
tick_lower_index: row.tick_lower_index,
tick_upper_index: row.tick_upper_index,
fee_growth_checkpoint_a: carbon_core::graphql::primitives::U128(
*row.fee_growth_checkpoint_a,
),
fee_owed_a: carbon_core::graphql::primitives::U64(*row.fee_owed_a),
fee_growth_checkpoint_b: carbon_core::graphql::primitives::U128(
*row.fee_growth_checkpoint_b,
),
fee_owed_b: carbon_core::graphql::primitives::U64(*row.fee_owed_b),
reward_infos: row
.reward_infos
.0
.into_iter()
.map(|item| item.into())
.collect(),
})
}
}