use {
crate::types::graphql::WhirlpoolRewardInfoGraphQL,
carbon_core::graphql::primitives::{Pubkey, U128, U64, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Whirlpool")]
pub struct WhirlpoolGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub whirlpools_config: Pubkey,
pub whirlpool_bump: Vec<U8>,
pub tick_spacing: i32,
pub fee_tier_index_seed: Vec<U8>,
pub fee_rate: i32,
pub protocol_fee_rate: i32,
pub liquidity: U128,
pub sqrt_price: U128,
pub tick_current_index: i32,
pub protocol_fee_owed_a: U64,
pub protocol_fee_owed_b: U64,
pub token_mint_a: Pubkey,
pub token_vault_a: Pubkey,
pub fee_growth_global_a: U128,
pub token_mint_b: Pubkey,
pub token_vault_b: Pubkey,
pub fee_growth_global_b: U128,
pub reward_last_updated_timestamp: U64,
pub reward_infos: Vec<WhirlpoolRewardInfoGraphQL>,
}
impl TryFrom<crate::accounts::postgres::WhirlpoolRow> for WhirlpoolGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::WhirlpoolRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
whirlpools_config: carbon_core::graphql::primitives::Pubkey(row.whirlpools_config.0),
whirlpool_bump: row
.whirlpool_bump
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
tick_spacing: *row.tick_spacing,
fee_tier_index_seed: row
.fee_tier_index_seed
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
fee_rate: *row.fee_rate,
protocol_fee_rate: *row.protocol_fee_rate,
liquidity: carbon_core::graphql::primitives::U128(*row.liquidity),
sqrt_price: carbon_core::graphql::primitives::U128(*row.sqrt_price),
tick_current_index: row.tick_current_index,
protocol_fee_owed_a: carbon_core::graphql::primitives::U64(*row.protocol_fee_owed_a),
protocol_fee_owed_b: carbon_core::graphql::primitives::U64(*row.protocol_fee_owed_b),
token_mint_a: carbon_core::graphql::primitives::Pubkey(row.token_mint_a.0),
token_vault_a: carbon_core::graphql::primitives::Pubkey(row.token_vault_a.0),
fee_growth_global_a: carbon_core::graphql::primitives::U128(*row.fee_growth_global_a),
token_mint_b: carbon_core::graphql::primitives::Pubkey(row.token_mint_b.0),
token_vault_b: carbon_core::graphql::primitives::Pubkey(row.token_vault_b.0),
fee_growth_global_b: carbon_core::graphql::primitives::U128(*row.fee_growth_global_b),
reward_last_updated_timestamp: carbon_core::graphql::primitives::U64(
*row.reward_last_updated_timestamp,
),
reward_infos: row
.reward_infos
.0
.into_iter()
.map(|item| item.into())
.collect(),
})
}
}