use {
crate::types::graphql::{
LiquidityDistributionConfigGraphQL, LiquidityVestingInfoGraphQL,
LockedVestingConfigGraphQL, PoolFeesConfigGraphQL,
},
carbon_core::graphql::primitives::{Pubkey, U128, U64, U8},
juniper::GraphQLObject,
};
#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "PoolConfig")]
pub struct PoolConfigGraphQL {
pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
pub quote_mint: Pubkey,
pub fee_claimer: Pubkey,
pub leftover_receiver: Pubkey,
pub pool_fees: PoolFeesConfigGraphQL,
pub partner_liquidity_vesting_info: LiquidityVestingInfoGraphQL,
pub creator_liquidity_vesting_info: LiquidityVestingInfoGraphQL,
pub padding0: Vec<U8>,
pub padding1: i32,
pub collect_fee_mode: U8,
pub migration_option: U8,
pub activation_type: U8,
pub token_decimal: U8,
pub version: U8,
pub token_type: U8,
pub quote_token_flag: U8,
pub partner_permanent_locked_liquidity_percentage: U8,
pub partner_liquidity_percentage: U8,
pub creator_permanent_locked_liquidity_percentage: U8,
pub creator_liquidity_percentage: U8,
pub migration_fee_option: U8,
pub fixed_token_supply_flag: U8,
pub creator_trading_fee_percentage: U8,
pub token_update_authority: U8,
pub migration_fee_percentage: U8,
pub creator_migration_fee_percentage: U8,
pub padding2: Vec<U8>,
pub swap_base_amount: U64,
pub migration_quote_threshold: U64,
pub migration_base_threshold: U64,
pub migration_sqrt_price: U128,
pub locked_vesting_config: LockedVestingConfigGraphQL,
pub pre_migration_token_supply: U64,
pub post_migration_token_supply: U64,
pub migrated_collect_fee_mode: U8,
pub migrated_dynamic_fee: U8,
pub migrated_pool_fee_bps: i32,
pub migrated_pool_base_fee_mode: U8,
pub enable_first_swap_with_min_fee: U8,
pub migrated_compounding_fee_bps: i32,
pub pool_creation_fee: U64,
pub migrated_pool_base_fee_bytes: Vec<U8>,
pub sqrt_start_price: U128,
pub curve: Vec<LiquidityDistributionConfigGraphQL>,
}
impl TryFrom<crate::accounts::postgres::PoolConfigRow> for PoolConfigGraphQL {
type Error = carbon_core::error::Error;
fn try_from(row: crate::accounts::postgres::PoolConfigRow) -> Result<Self, Self::Error> {
Ok(Self {
account_metadata: row.account_metadata.into(),
quote_mint: carbon_core::graphql::primitives::Pubkey(row.quote_mint.0),
fee_claimer: carbon_core::graphql::primitives::Pubkey(row.fee_claimer.0),
leftover_receiver: carbon_core::graphql::primitives::Pubkey(row.leftover_receiver.0),
pool_fees: row.pool_fees.0.into(),
partner_liquidity_vesting_info: row.partner_liquidity_vesting_info.0.into(),
creator_liquidity_vesting_info: row.creator_liquidity_vesting_info.0.into(),
padding0: row
.padding0
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
padding1: *row.padding1,
collect_fee_mode: carbon_core::graphql::primitives::U8((*row.collect_fee_mode) as u8),
migration_option: carbon_core::graphql::primitives::U8((*row.migration_option) as u8),
activation_type: carbon_core::graphql::primitives::U8((*row.activation_type) as u8),
token_decimal: carbon_core::graphql::primitives::U8((*row.token_decimal) as u8),
version: carbon_core::graphql::primitives::U8((*row.version) as u8),
token_type: carbon_core::graphql::primitives::U8((*row.token_type) as u8),
quote_token_flag: carbon_core::graphql::primitives::U8((*row.quote_token_flag) as u8),
partner_permanent_locked_liquidity_percentage: carbon_core::graphql::primitives::U8(
(*row.partner_permanent_locked_liquidity_percentage) as u8,
),
partner_liquidity_percentage: carbon_core::graphql::primitives::U8(
(*row.partner_liquidity_percentage) as u8,
),
creator_permanent_locked_liquidity_percentage: carbon_core::graphql::primitives::U8(
(*row.creator_permanent_locked_liquidity_percentage) as u8,
),
creator_liquidity_percentage: carbon_core::graphql::primitives::U8(
(*row.creator_liquidity_percentage) as u8,
),
migration_fee_option: carbon_core::graphql::primitives::U8(
(*row.migration_fee_option) as u8,
),
fixed_token_supply_flag: carbon_core::graphql::primitives::U8(
(*row.fixed_token_supply_flag) as u8,
),
creator_trading_fee_percentage: carbon_core::graphql::primitives::U8(
(*row.creator_trading_fee_percentage) as u8,
),
token_update_authority: carbon_core::graphql::primitives::U8(
(*row.token_update_authority) as u8,
),
migration_fee_percentage: carbon_core::graphql::primitives::U8(
(*row.migration_fee_percentage) as u8,
),
creator_migration_fee_percentage: carbon_core::graphql::primitives::U8(
(*row.creator_migration_fee_percentage) as u8,
),
padding2: row
.padding2
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
swap_base_amount: carbon_core::graphql::primitives::U64(*row.swap_base_amount),
migration_quote_threshold: carbon_core::graphql::primitives::U64(
*row.migration_quote_threshold,
),
migration_base_threshold: carbon_core::graphql::primitives::U64(
*row.migration_base_threshold,
),
migration_sqrt_price: carbon_core::graphql::primitives::U128(*row.migration_sqrt_price),
locked_vesting_config: row.locked_vesting_config.0.into(),
pre_migration_token_supply: carbon_core::graphql::primitives::U64(
*row.pre_migration_token_supply,
),
post_migration_token_supply: carbon_core::graphql::primitives::U64(
*row.post_migration_token_supply,
),
migrated_collect_fee_mode: carbon_core::graphql::primitives::U8(
(*row.migrated_collect_fee_mode) as u8,
),
migrated_dynamic_fee: carbon_core::graphql::primitives::U8(
(*row.migrated_dynamic_fee) as u8,
),
migrated_pool_fee_bps: *row.migrated_pool_fee_bps,
migrated_pool_base_fee_mode: carbon_core::graphql::primitives::U8(
(*row.migrated_pool_base_fee_mode) as u8,
),
enable_first_swap_with_min_fee: carbon_core::graphql::primitives::U8(
(*row.enable_first_swap_with_min_fee) as u8,
),
migrated_compounding_fee_bps: *row.migrated_compounding_fee_bps,
pool_creation_fee: carbon_core::graphql::primitives::U64(*row.pool_creation_fee),
migrated_pool_base_fee_bytes: row
.migrated_pool_base_fee_bytes
.into_iter()
.map(carbon_core::graphql::primitives::U8)
.collect(),
sqrt_start_price: carbon_core::graphql::primitives::U128(*row.sqrt_start_price),
curve: row.curve.0.into_iter().map(|item| item.into()).collect(),
})
}
}