carbon-drift-v2-decoder 1.0.0

Drift v2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{
        AssetTierGraphQL, HistoricalIndexDataGraphQL, HistoricalOracleDataGraphQL,
        InsuranceFundGraphQL, MarketStatusGraphQL, OracleSourceGraphQL, PoolBalanceGraphQL,
    },
    carbon_core::graphql::primitives::{Pubkey, I64, U128, U32, U64, U8},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "SpotMarket")]
pub struct SpotMarketGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub pubkey: Pubkey,
    pub oracle: Pubkey,
    pub mint: Pubkey,
    pub vault: Pubkey,
    pub name: Vec<U8>,
    pub historical_oracle_data: HistoricalOracleDataGraphQL,
    pub historical_index_data: HistoricalIndexDataGraphQL,
    pub revenue_pool: PoolBalanceGraphQL,
    pub spot_fee_pool: PoolBalanceGraphQL,
    pub insurance_fund: InsuranceFundGraphQL,
    pub total_spot_fee: U128,
    pub deposit_balance: U128,
    pub borrow_balance: U128,
    pub cumulative_deposit_interest: U128,
    pub cumulative_borrow_interest: U128,
    pub total_social_loss: U128,
    pub total_quote_social_loss: U128,
    pub withdraw_guard_threshold: U64,
    pub max_token_deposits: U64,
    pub deposit_token_twap: U64,
    pub borrow_token_twap: U64,
    pub utilization_twap: U64,
    pub last_interest_ts: U64,
    pub last_twap_ts: U64,
    pub expiry_ts: I64,
    pub order_step_size: U64,
    pub order_tick_size: U64,
    pub min_order_size: U64,
    pub max_position_size: U64,
    pub next_fill_record_id: U64,
    pub next_deposit_record_id: U64,
    pub initial_asset_weight: U32,
    pub maintenance_asset_weight: U32,
    pub initial_liability_weight: U32,
    pub maintenance_liability_weight: U32,
    pub imf_factor: U32,
    pub liquidator_fee: U32,
    pub if_liquidation_fee: U32,
    pub optimal_utilization: U32,
    pub optimal_borrow_rate: U32,
    pub max_borrow_rate: U32,
    pub decimals: U32,
    pub market_index: i32,
    pub orders_enabled: bool,
    pub oracle_source: OracleSourceGraphQL,
    pub status: MarketStatusGraphQL,
    pub asset_tier: AssetTierGraphQL,
    pub paused_operations: U8,
    pub if_paused_operations: U8,
    pub fee_adjustment: i32,
    pub max_token_borrows_fraction: i32,
    pub flash_loan_amount: U64,
    pub flash_loan_initial_token_amount: U64,
    pub total_swap_fee: U64,
    pub scale_initial_asset_weight_start: U64,
    pub min_borrow_rate: U8,
    pub fuel_boost_deposits: U8,
    pub fuel_boost_borrows: U8,
    pub fuel_boost_taker: U8,
    pub fuel_boost_maker: U8,
    pub fuel_boost_insurance: U8,
    pub token_program_flag: U8,
    pub pool_id: U8,
    pub padding: Vec<U8>,
}

impl TryFrom<crate::accounts::postgres::SpotMarketRow> for SpotMarketGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::SpotMarketRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            pubkey: carbon_core::graphql::primitives::Pubkey(row.pubkey.0),
            oracle: carbon_core::graphql::primitives::Pubkey(row.oracle.0),
            mint: carbon_core::graphql::primitives::Pubkey(row.mint.0),
            vault: carbon_core::graphql::primitives::Pubkey(row.vault.0),
            name: row
                .name
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            historical_oracle_data: row.historical_oracle_data.0.into(),
            historical_index_data: row.historical_index_data.0.into(),
            revenue_pool: row.revenue_pool.0.into(),
            spot_fee_pool: row.spot_fee_pool.0.into(),
            insurance_fund: row.insurance_fund.0.into(),
            total_spot_fee: carbon_core::graphql::primitives::U128(*row.total_spot_fee),
            deposit_balance: carbon_core::graphql::primitives::U128(*row.deposit_balance),
            borrow_balance: carbon_core::graphql::primitives::U128(*row.borrow_balance),
            cumulative_deposit_interest: carbon_core::graphql::primitives::U128(
                *row.cumulative_deposit_interest,
            ),
            cumulative_borrow_interest: carbon_core::graphql::primitives::U128(
                *row.cumulative_borrow_interest,
            ),
            total_social_loss: carbon_core::graphql::primitives::U128(*row.total_social_loss),
            total_quote_social_loss: carbon_core::graphql::primitives::U128(
                *row.total_quote_social_loss,
            ),
            withdraw_guard_threshold: carbon_core::graphql::primitives::U64(
                *row.withdraw_guard_threshold,
            ),
            max_token_deposits: carbon_core::graphql::primitives::U64(*row.max_token_deposits),
            deposit_token_twap: carbon_core::graphql::primitives::U64(*row.deposit_token_twap),
            borrow_token_twap: carbon_core::graphql::primitives::U64(*row.borrow_token_twap),
            utilization_twap: carbon_core::graphql::primitives::U64(*row.utilization_twap),
            last_interest_ts: carbon_core::graphql::primitives::U64(*row.last_interest_ts),
            last_twap_ts: carbon_core::graphql::primitives::U64(*row.last_twap_ts),
            expiry_ts: carbon_core::graphql::primitives::I64(row.expiry_ts),
            order_step_size: carbon_core::graphql::primitives::U64(*row.order_step_size),
            order_tick_size: carbon_core::graphql::primitives::U64(*row.order_tick_size),
            min_order_size: carbon_core::graphql::primitives::U64(*row.min_order_size),
            max_position_size: carbon_core::graphql::primitives::U64(*row.max_position_size),
            next_fill_record_id: carbon_core::graphql::primitives::U64(*row.next_fill_record_id),
            next_deposit_record_id: carbon_core::graphql::primitives::U64(
                *row.next_deposit_record_id,
            ),
            initial_asset_weight: carbon_core::graphql::primitives::U32(
                (*row.initial_asset_weight) as u32,
            ),
            maintenance_asset_weight: carbon_core::graphql::primitives::U32(
                (*row.maintenance_asset_weight) as u32,
            ),
            initial_liability_weight: carbon_core::graphql::primitives::U32(
                (*row.initial_liability_weight) as u32,
            ),
            maintenance_liability_weight: carbon_core::graphql::primitives::U32(
                (*row.maintenance_liability_weight) as u32,
            ),
            imf_factor: carbon_core::graphql::primitives::U32((*row.imf_factor) as u32),
            liquidator_fee: carbon_core::graphql::primitives::U32((*row.liquidator_fee) as u32),
            if_liquidation_fee: carbon_core::graphql::primitives::U32(
                (*row.if_liquidation_fee) as u32,
            ),
            optimal_utilization: carbon_core::graphql::primitives::U32(
                (*row.optimal_utilization) as u32,
            ),
            optimal_borrow_rate: carbon_core::graphql::primitives::U32(
                (*row.optimal_borrow_rate) as u32,
            ),
            max_borrow_rate: carbon_core::graphql::primitives::U32((*row.max_borrow_rate) as u32),
            decimals: carbon_core::graphql::primitives::U32((*row.decimals) as u32),
            market_index: *row.market_index,
            orders_enabled: row.orders_enabled,
            oracle_source: row.oracle_source.0.into(),
            status: row.status.0.into(),
            asset_tier: row.asset_tier.0.into(),
            paused_operations: carbon_core::graphql::primitives::U8((*row.paused_operations) as u8),
            if_paused_operations: carbon_core::graphql::primitives::U8(
                (*row.if_paused_operations) as u8,
            ),
            fee_adjustment: row.fee_adjustment as i32,
            max_token_borrows_fraction: *row.max_token_borrows_fraction,
            flash_loan_amount: carbon_core::graphql::primitives::U64(*row.flash_loan_amount),
            flash_loan_initial_token_amount: carbon_core::graphql::primitives::U64(
                *row.flash_loan_initial_token_amount,
            ),
            total_swap_fee: carbon_core::graphql::primitives::U64(*row.total_swap_fee),
            scale_initial_asset_weight_start: carbon_core::graphql::primitives::U64(
                *row.scale_initial_asset_weight_start,
            ),
            min_borrow_rate: carbon_core::graphql::primitives::U8((*row.min_borrow_rate) as u8),
            fuel_boost_deposits: carbon_core::graphql::primitives::U8(
                (*row.fuel_boost_deposits) as u8,
            ),
            fuel_boost_borrows: carbon_core::graphql::primitives::U8(
                (*row.fuel_boost_borrows) as u8,
            ),
            fuel_boost_taker: carbon_core::graphql::primitives::U8((*row.fuel_boost_taker) as u8),
            fuel_boost_maker: carbon_core::graphql::primitives::U8((*row.fuel_boost_maker) as u8),
            fuel_boost_insurance: carbon_core::graphql::primitives::U8(
                (*row.fuel_boost_insurance) as u8,
            ),
            token_program_flag: carbon_core::graphql::primitives::U8(
                (*row.token_program_flag) as u8,
            ),
            pool_id: carbon_core::graphql::primitives::U8((*row.pool_id) as u8),
            padding: row
                .padding
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
        })
    }
}