carbon-vertigo-decoder 1.0.0

Vertigo DEX Program Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
pub mod buy_row;
pub mod claim_row;
pub mod cpi_event_row;
pub mod create_row;
pub mod quote_buy_row;
pub mod quote_sell_row;
pub mod sell_row;

pub use self::{
    buy_row::*, claim_row::*, cpi_event_row::*, create_row::*, quote_buy_row::*, quote_sell_row::*,
    sell_row::*,
};
use super::VertigoInstruction;

pub struct VertigoInstructionsMigration;

impl sqlx_migrator::Migration<sqlx::Postgres> for VertigoInstructionsMigration {
    fn app(&self) -> &str {
        "vertigo"
    }

    fn name(&self) -> &str {
        "vertigo_instructions"
    }

    fn operations(&self) -> Vec<Box<dyn sqlx_migrator::Operation<sqlx::Postgres>>> {
        vec![
            Box::new(BuyMigrationOperation),
            Box::new(ClaimMigrationOperation),
            Box::new(CreateMigrationOperation),
            Box::new(QuoteBuyMigrationOperation),
            Box::new(QuoteSellMigrationOperation),
            Box::new(SellMigrationOperation),
            Box::new(CpiEventMigrationOperation),
        ]
    }

    fn parents(&self) -> Vec<Box<dyn sqlx_migrator::Migration<sqlx::Postgres>>> {
        vec![]
    }
}

pub struct VertigoInstructionWithMetadata(
    pub VertigoInstruction,
    pub carbon_core::instruction::InstructionMetadata,
    pub Vec<solana_instruction::AccountMeta>,
);

impl
    From<(
        VertigoInstruction,
        carbon_core::instruction::InstructionMetadata,
        Vec<solana_instruction::AccountMeta>,
    )> for VertigoInstructionWithMetadata
{
    fn from(
        value: (
            VertigoInstruction,
            carbon_core::instruction::InstructionMetadata,
            Vec<solana_instruction::AccountMeta>,
        ),
    ) -> Self {
        VertigoInstructionWithMetadata(value.0, value.1, value.2)
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for VertigoInstructionWithMetadata {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let VertigoInstructionWithMetadata(decoded_instruction, metadata, raw_accounts) = self;
        match decoded_instruction {
            VertigoInstruction::Buy { data, .. } => {
                let row = buy_row::BuyRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            VertigoInstruction::Claim { data, .. } => {
                let row = claim_row::ClaimRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            VertigoInstruction::Create { data, .. } => {
                let row = create_row::CreateRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            VertigoInstruction::QuoteBuy { data, .. } => {
                let row = quote_buy_row::QuoteBuyRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            VertigoInstruction::QuoteSell { data, .. } => {
                let row = quote_sell_row::QuoteSellRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            VertigoInstruction::Sell { data, .. } => {
                let row = sell_row::SellRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
            VertigoInstruction::CpiEvent { data, .. } => {
                let row = cpi_event_row::CpiEventRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.insert(pool).await?;
                Ok(())
            }
        }
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for VertigoInstructionWithMetadata {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        let VertigoInstructionWithMetadata(decoded_instruction, metadata, raw_accounts) = self;
        match decoded_instruction {
            VertigoInstruction::Buy { data, .. } => {
                let row = buy_row::BuyRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            VertigoInstruction::Claim { data, .. } => {
                let row = claim_row::ClaimRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            VertigoInstruction::Create { data, .. } => {
                let row = create_row::CreateRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            VertigoInstruction::QuoteBuy { data, .. } => {
                let row = quote_buy_row::QuoteBuyRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            VertigoInstruction::QuoteSell { data, .. } => {
                let row = quote_sell_row::QuoteSellRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            VertigoInstruction::Sell { data, .. } => {
                let row = sell_row::SellRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
            VertigoInstruction::CpiEvent { data, .. } => {
                let row = cpi_event_row::CpiEventRow::from_parts(
                    data.clone(),
                    metadata.clone(),
                    raw_accounts.clone(),
                );
                row.upsert(pool).await?;
                Ok(())
            }
        }
    }
}