carbon-heaven-decoder 2.0.0

Heaven program decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{
        LiquidityPoolMarketCapBasedFeesGraphQL, LiquidityPoolSlotOffsetBasedFeesGraphQL,
    },
    carbon_core::graphql::primitives::{U32, U64, U8},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "ProtocolConfig")]
pub struct ProtocolConfigGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub create_pool_fee: U64,
    pub initial_token_b_amount: f64,
    pub initial_token_a_amount: U64,
    pub unstaked_wsol_reserve: U64,
    pub total_sol_spent: U64,
    pub total_msol_received: U64,
    pub total_realized_profit: U64,
    pub pool_count: U64,
    pub max_supply_per_wallet: U64,
    pub creator_trading_fee_trading_volume_threshold: f64,
    pub market_cap_based_fees: LiquidityPoolMarketCapBasedFeesGraphQL,
    pub buffer_bps: i32,
    pub auto_staking_threshold_bps: i32,
    pub version: i32,
    pub protocol_config_state_bump: U8,
    pub allow_create_pool: U8,
    pub supported_pool_type: U8,
    pub default_leader_slot_window: U8,
    pub auto_staking_enabled: U8,
    pub leader_slot_window: U8,
    pub sandwich_resistence_enabled: U8,
    pub token_a_decimals: U8,
    pub migration_market_cap_threshold: i32,
    pub pad: Vec<U8>,
    pub max_creator_trading_fee: U32,
    pub slot_offset_based_fees: LiquidityPoolSlotOffsetBasedFeesGraphQL,
}

impl TryFrom<crate::accounts::postgres::ProtocolConfigRow> for ProtocolConfigGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::ProtocolConfigRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            create_pool_fee: carbon_core::graphql::primitives::U64(*row.create_pool_fee),
            initial_token_b_amount: row.initial_token_b_amount,
            initial_token_a_amount: carbon_core::graphql::primitives::U64(
                *row.initial_token_a_amount,
            ),
            unstaked_wsol_reserve: carbon_core::graphql::primitives::U64(
                *row.unstaked_wsol_reserve,
            ),
            total_sol_spent: carbon_core::graphql::primitives::U64(*row.total_sol_spent),
            total_msol_received: carbon_core::graphql::primitives::U64(*row.total_msol_received),
            total_realized_profit: carbon_core::graphql::primitives::U64(
                *row.total_realized_profit,
            ),
            pool_count: carbon_core::graphql::primitives::U64(*row.pool_count),
            max_supply_per_wallet: carbon_core::graphql::primitives::U64(
                *row.max_supply_per_wallet,
            ),
            creator_trading_fee_trading_volume_threshold: row
                .creator_trading_fee_trading_volume_threshold,
            market_cap_based_fees: row.market_cap_based_fees.0.into(),
            buffer_bps: *row.buffer_bps,
            auto_staking_threshold_bps: *row.auto_staking_threshold_bps,
            version: *row.version,
            protocol_config_state_bump: carbon_core::graphql::primitives::U8(
                (*row.protocol_config_state_bump) as u8,
            ),
            allow_create_pool: carbon_core::graphql::primitives::U8((*row.allow_create_pool) as u8),
            supported_pool_type: carbon_core::graphql::primitives::U8(
                (*row.supported_pool_type) as u8,
            ),
            default_leader_slot_window: carbon_core::graphql::primitives::U8(
                (*row.default_leader_slot_window) as u8,
            ),
            auto_staking_enabled: carbon_core::graphql::primitives::U8(
                (*row.auto_staking_enabled) as u8,
            ),
            leader_slot_window: carbon_core::graphql::primitives::U8(
                (*row.leader_slot_window) as u8,
            ),
            sandwich_resistence_enabled: carbon_core::graphql::primitives::U8(
                (*row.sandwich_resistence_enabled) as u8,
            ),
            token_a_decimals: carbon_core::graphql::primitives::U8((*row.token_a_decimals) as u8),
            migration_market_cap_threshold: *row.migration_market_cap_threshold,
            pad: row
                .pad
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            max_creator_trading_fee: carbon_core::graphql::primitives::U32(
                (*row.max_creator_trading_fee) as u32,
            ),
            slot_offset_based_fees: row.slot_offset_based_fees.0.into(),
        })
    }
}