carbon-marginfi-v2-decoder 1.0.0

MarginfiV2 Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::{RiskTierGraphQL, WrappedI80F48GraphQL},
    carbon_core::graphql::primitives::{Pubkey, U64, U8},
    juniper::GraphQLObject,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "StakedSettings")]
pub struct StakedSettingsGraphQL {
    pub account_metadata: crate::accounts::graphql::AccountMetadataGraphQL,
    pub key: Pubkey,
    pub marginfi_group: Pubkey,
    pub oracle: Pubkey,
    pub asset_weight_init: WrappedI80F48GraphQL,
    pub asset_weight_maint: WrappedI80F48GraphQL,
    pub deposit_limit: U64,
    pub total_asset_value_init_limit: U64,
    pub oracle_max_age: i32,
    pub risk_tier: RiskTierGraphQL,
    pub pad0: Vec<U8>,
    pub reserved0: Vec<U8>,
    pub reserved1: Vec<U8>,
    pub reserved2: Vec<U8>,
}

impl TryFrom<crate::accounts::postgres::StakedSettingsRow> for StakedSettingsGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::accounts::postgres::StakedSettingsRow) -> Result<Self, Self::Error> {
        Ok(Self {
            account_metadata: row.account_metadata.into(),
            key: carbon_core::graphql::primitives::Pubkey(row.key.0),
            marginfi_group: carbon_core::graphql::primitives::Pubkey(row.marginfi_group.0),
            oracle: carbon_core::graphql::primitives::Pubkey(row.oracle.0),
            asset_weight_init: row.asset_weight_init.0.into(),
            asset_weight_maint: row.asset_weight_maint.0.into(),
            deposit_limit: carbon_core::graphql::primitives::U64(*row.deposit_limit),
            total_asset_value_init_limit: carbon_core::graphql::primitives::U64(
                *row.total_asset_value_init_limit,
            ),
            oracle_max_age: *row.oracle_max_age,
            risk_tier: row.risk_tier.0.into(),
            pad0: row
                .pad0
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            reserved0: row
                .reserved0
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            reserved1: row
                .reserved1
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
            reserved2: row
                .reserved2
                .into_iter()
                .map(carbon_core::graphql::primitives::U8)
                .collect(),
        })
    }
}