carbon-zeta-decoder 2.0.0

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

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "MarginAccount")]
pub struct MarginAccountGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub authority: Pubkey,
    pub nonce: U8,
    pub balance: U64,
    pub force_cancel_flag: bool,
    pub open_orders_nonce: Vec<U8>,
    pub series_expiry: Vec<U64>,
    pub series_expiry_padding: U64,
    pub product_ledgers: Vec<ProductLedgerGraphQL>,
    pub product_ledgers_padding: Vec<ProductLedgerGraphQL>,
    pub perp_product_ledger: ProductLedgerGraphQL,
    pub rebalance_amount: I64,
    pub asset: AssetGraphQL,
    pub account_type: MarginAccountTypeGraphQL,
    pub last_funding_delta: AnchorDecimalGraphQL,
    pub delegated_pubkey: Pubkey,
    pub padding: Vec<U8>,
}

impl TryFrom<crate::accounts::postgres::MarginAccountRow> for MarginAccountGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::MarginAccountRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            authority: carbon_core::graphql::primitives::Pubkey(row.authority.0),
            nonce: carbon_core::graphql::primitives::U8((*row.nonce) as u8),
            balance: carbon_core::graphql::primitives::U64(*row.balance),
            force_cancel_flag: row.force_cancel_flag,
            open_orders_nonce: row
                .open_orders_nonce
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            series_expiry: row
                .series_expiry
                .into_iter()
                .map(|item| carbon_core::graphql::primitives::U64(*item))
                .collect(),
            series_expiry_padding: carbon_core::graphql::primitives::U64(
                *row.series_expiry_padding,
            ),
            product_ledgers: row
                .product_ledgers
                .0
                .into_iter()
                .map(|item| item.into())
                .collect(),
            product_ledgers_padding: row
                .product_ledgers_padding
                .0
                .into_iter()
                .map(|item| item.into())
                .collect(),
            perp_product_ledger: row.perp_product_ledger.0.into(),
            rebalance_amount: carbon_core::graphql::primitives::I64(row.rebalance_amount),
            asset: row.asset.0.into(),
            account_type: row.account_type.0.into(),
            last_funding_delta: row.last_funding_delta.0.into(),
            delegated_pubkey: carbon_core::graphql::primitives::Pubkey(row.delegated_pubkey.0),
            padding: row
                .padding
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
        })
    }
}