carbon-zeta-decoder 2.0.0

Zeta Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{AnchorDecimalGraphQL, ProductGreeksGraphQL},
    carbon_core::graphql::primitives::{Pubkey, I64, U64, U8},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Greeks")]
pub struct GreeksGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub nonce: U8,
    pub mark_prices: Vec<U64>,
    pub mark_prices_padding: Vec<U64>,
    pub perp_mark_price: U64,
    pub product_greeks: Vec<ProductGreeksGraphQL>,
    pub product_greeks_padding: Vec<ProductGreeksGraphQL>,
    pub update_timestamp: Vec<U64>,
    pub update_timestamp_padding: Vec<U64>,
    pub retreat_expiration_timestamp: Vec<U64>,
    pub retreat_expiration_timestamp_padding: Vec<U64>,
    pub interest_rate: Vec<I64>,
    pub interest_rate_padding: Vec<I64>,
    pub nodes: Vec<U64>,
    pub volatility: Vec<U64>,
    pub volatility_padding: Vec<U64>,
    pub node_keys: Vec<Pubkey>,
    pub halt_force_pricing: Vec<bool>,
    pub perp_update_timestamp: U64,
    pub perp_funding_delta: AnchorDecimalGraphQL,
    pub perp_latest_funding_rate: AnchorDecimalGraphQL,
    pub perp_latest_midpoint: U64,
    pub padding: Vec<U8>,
}

impl TryFrom<crate::accounts::postgres::GreeksRow> for GreeksGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::GreeksRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            nonce: carbon_core::graphql::primitives::U8((*row.nonce) as u8),
            mark_prices: row
                .mark_prices
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            mark_prices_padding: row
                .mark_prices_padding
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            perp_mark_price: carbon_core::graphql::primitives::U64(*row.perp_mark_price),
            product_greeks: row
                .product_greeks
                .0
                .into_iter()
                .map(|item| item.into())
                .collect(),
            product_greeks_padding: row
                .product_greeks_padding
                .0
                .into_iter()
                .map(|item| item.into())
                .collect(),
            update_timestamp: row
                .update_timestamp
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            update_timestamp_padding: row
                .update_timestamp_padding
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            retreat_expiration_timestamp: row
                .retreat_expiration_timestamp
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            retreat_expiration_timestamp_padding: row
                .retreat_expiration_timestamp_padding
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            interest_rate: row
                .interest_rate
                .into_iter()
                .map(carbon_core::graphql::primitives::I64)
                .collect(),
            interest_rate_padding: row
                .interest_rate_padding
                .into_iter()
                .map(carbon_core::graphql::primitives::I64)
                .collect(),
            nodes: row
                .nodes
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            volatility: row
                .volatility
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            volatility_padding: row
                .volatility_padding
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            node_keys: row
                .node_keys
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::Pubkey(item.0))
                .collect(),
            halt_force_pricing: row.halt_force_pricing.to_vec(),
            perp_update_timestamp: carbon_core::graphql::primitives::U64(
                *row.perp_update_timestamp,
            ),
            perp_funding_delta: row.perp_funding_delta.0.into(),
            perp_latest_funding_rate: row.perp_latest_funding_rate.0.into(),
            perp_latest_midpoint: carbon_core::graphql::primitives::U64(*row.perp_latest_midpoint),
            padding: row
                .padding
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
        })
    }
}