carbon-jupiter-lend-decoder 2.0.0

Jupiter Lend Liquidity Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use {
    crate::types::graphql::TransferTypeGraphQL,
    carbon_core::graphql::primitives::{Pubkey, I128},
    juniper::GraphQLObject,
    serde_json,
};

#[derive(Debug, Clone, GraphQLObject)]
#[graphql(name = "Operate")]
pub struct OperateGraphQL {
    pub instruction_metadata: crate::instructions::graphql::InstructionMetadataGraphQL,
    pub supply_amount: I128,
    pub borrow_amount: I128,
    pub withdraw_to: Pubkey,
    pub borrow_to: Pubkey,
    pub transfer_type: TransferTypeGraphQL,
    pub accounts: carbon_core::graphql::primitives::Json,
}

impl TryFrom<crate::instructions::postgres::OperateRow> for OperateGraphQL {
    type Error = carbon_core::error::Error;
    fn try_from(row: crate::instructions::postgres::OperateRow) -> Result<Self, Self::Error> {
        Ok(Self {
            instruction_metadata: row.instruction_metadata.into(),
            supply_amount: carbon_core::graphql::primitives::I128(*row.supply_amount),
            borrow_amount: carbon_core::graphql::primitives::I128(*row.borrow_amount),
            withdraw_to: carbon_core::graphql::primitives::Pubkey(row.withdraw_to.0),
            borrow_to: carbon_core::graphql::primitives::Pubkey(row.borrow_to.0),
            transfer_type: row.transfer_type.0.into(),
            accounts: carbon_core::graphql::primitives::Json(
                serde_json::to_value(&row.accounts.0)
                    .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?,
            ),
        })
    }
}