carbon-pump-swap-decoder 1.0.0

PumpSwap Decoder
Documentation
//! This code was AUTOGENERATED using the Codama library.
use carbon_core::{
    instruction::InstructionMetadata,
    postgres::{metadata::InstructionRowMetadata, primitives::U64},
};

#[derive(sqlx::FromRow, Debug, Clone)]
pub struct AdminUpdateTokenIncentivesRow {
    #[sqlx(flatten)]
    pub instruction_metadata: InstructionRowMetadata,
    pub start_time: i64,
    pub end_time: i64,
    pub seconds_in_a_day: i64,
    pub day_number: U64,
    pub token_supply_per_day: U64,
    #[sqlx(rename = "__accounts")]
    pub accounts: sqlx::types::Json<Vec<solana_instruction::AccountMeta>>,
}

impl AdminUpdateTokenIncentivesRow {
    pub fn from_parts(
        source: crate::instructions::admin_update_token_incentives::AdminUpdateTokenIncentives,
        metadata: InstructionMetadata,
        accounts: Vec<solana_instruction::AccountMeta>,
    ) -> Self {
        Self {
            instruction_metadata: metadata.into(),
            start_time: source.start_time,
            end_time: source.end_time,
            seconds_in_a_day: source.seconds_in_a_day,
            day_number: source.day_number.into(),
            token_supply_per_day: source.token_supply_per_day.into(),
            accounts: sqlx::types::Json(accounts),
        }
    }
}

impl TryFrom<AdminUpdateTokenIncentivesRow>
    for crate::instructions::admin_update_token_incentives::AdminUpdateTokenIncentives
{
    type Error = carbon_core::error::Error;
    fn try_from(source: AdminUpdateTokenIncentivesRow) -> Result<Self, Self::Error> {
        Ok(Self {
            start_time: source.start_time,
            end_time: source.end_time,
            seconds_in_a_day: source.seconds_in_a_day,
            day_number: *source.day_number,
            token_supply_per_day: *source.token_supply_per_day,
        })
    }
}

impl carbon_core::postgres::operations::Table
    for crate::instructions::admin_update_token_incentives::AdminUpdateTokenIncentives
{
    fn table() -> &'static str {
        "admin_update_token_incentives_instruction"
    }

    fn columns() -> Vec<&'static str> {
        vec![
            "__signature",
            "__instruction_index",
            "__stack_height",
            "__slot",
            "start_time",
            "end_time",
            "seconds_in_a_day",
            "day_number",
            "token_supply_per_day",
            "__accounts",
        ]
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Insert for AdminUpdateTokenIncentivesRow {
    async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        sqlx::query(
            r#"
            INSERT INTO admin_update_token_incentives_instruction (
                "start_time",
                "end_time",
                "seconds_in_a_day",
                "day_number",
                "token_supply_per_day",
                __signature, __instruction_index, __stack_height, __slot, __accounts
            ) VALUES (
                $1, $2, $3, $4, $5, $6, $7, $8, $9, $10
            )"#,
        )
        .bind(self.start_time)
        .bind(self.end_time)
        .bind(self.seconds_in_a_day)
        .bind(&self.day_number)
        .bind(&self.token_supply_per_day)
        .bind(&self.instruction_metadata.signature)
        .bind(self.instruction_metadata.instruction_index)
        .bind(self.instruction_metadata.stack_height)
        .bind(&self.instruction_metadata.slot)
        .bind(&self.accounts)
        .execute(pool)
        .await
        .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
        Ok(())
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Upsert for AdminUpdateTokenIncentivesRow {
    async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        sqlx::query(
            r#"INSERT INTO admin_update_token_incentives_instruction (
                "start_time",
                "end_time",
                "seconds_in_a_day",
                "day_number",
                "token_supply_per_day",
                __signature, __instruction_index, __stack_height, __slot, __accounts
            ) VALUES (
                $1, $2, $3, $4, $5, $6, $7, $8, $9, $10
            ) ON CONFLICT (
                __signature, __instruction_index, __stack_height
            ) DO UPDATE SET
                "start_time" = EXCLUDED."start_time",
                "end_time" = EXCLUDED."end_time",
                "seconds_in_a_day" = EXCLUDED."seconds_in_a_day",
                "day_number" = EXCLUDED."day_number",
                "token_supply_per_day" = EXCLUDED."token_supply_per_day",
                __instruction_index = EXCLUDED.__instruction_index,
                __stack_height = EXCLUDED.__stack_height,
                __slot = EXCLUDED.__slot,
                __accounts = EXCLUDED.__accounts
            "#,
        )
        .bind(self.start_time)
        .bind(self.end_time)
        .bind(self.seconds_in_a_day)
        .bind(&self.day_number)
        .bind(&self.token_supply_per_day)
        .bind(&self.instruction_metadata.signature)
        .bind(self.instruction_metadata.instruction_index)
        .bind(self.instruction_metadata.stack_height)
        .bind(&self.instruction_metadata.slot)
        .bind(&self.accounts)
        .execute(pool)
        .await
        .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
        Ok(())
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Delete for AdminUpdateTokenIncentivesRow {
    type Key = (
        String,
        carbon_core::postgres::primitives::U32,
        carbon_core::postgres::primitives::U32,
    );

    async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> {
        sqlx::query(
            r#"DELETE FROM admin_update_token_incentives_instruction WHERE
                __signature = $1 AND __instruction_index = $2 AND __stack_height = $3
            "#,
        )
        .bind(key.0)
        .bind(key.1)
        .bind(key.2)
        .execute(pool)
        .await
        .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
        Ok(())
    }
}

#[async_trait::async_trait]
impl carbon_core::postgres::operations::Lookup for AdminUpdateTokenIncentivesRow {
    type Key = (
        String,
        carbon_core::postgres::primitives::U32,
        carbon_core::postgres::primitives::U32,
    );

    async fn lookup(
        key: Self::Key,
        pool: &sqlx::PgPool,
    ) -> carbon_core::error::CarbonResult<Option<Self>> {
        let row = sqlx::query_as(
            r#"SELECT * FROM admin_update_token_incentives_instruction WHERE
                __signature = $1 AND __instruction_index = $2 AND __stack_height = $3
            "#,
        )
        .bind(key.0)
        .bind(key.1)
        .bind(key.2)
        .fetch_optional(pool)
        .await
        .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?;
        Ok(row)
    }
}

pub struct AdminUpdateTokenIncentivesMigrationOperation;

#[async_trait::async_trait]
impl sqlx_migrator::Operation<sqlx::Postgres> for AdminUpdateTokenIncentivesMigrationOperation {
    async fn up(
        &self,
        connection: &mut sqlx::PgConnection,
    ) -> Result<(), sqlx_migrator::error::Error> {
        sqlx::query(
            r#"CREATE TABLE IF NOT EXISTS admin_update_token_incentives_instruction (
                -- Instruction data
                "start_time" INT8 NOT NULL,
                "end_time" INT8 NOT NULL,
                "seconds_in_a_day" INT8 NOT NULL,
                "day_number" NUMERIC(20) NOT NULL,
                "token_supply_per_day" NUMERIC(20) NOT NULL,
                -- Instruction metadata
                __signature TEXT NOT NULL,
                __instruction_index BIGINT NOT NULL,
                __stack_height BIGINT NOT NULL,
                __slot NUMERIC(20),
                __accounts JSONB NOT NULL,
                PRIMARY KEY (__signature, __instruction_index, __stack_height)
            )"#,
        )
        .execute(connection)
        .await?;
        Ok(())
    }

    async fn down(
        &self,
        connection: &mut sqlx::PgConnection,
    ) -> Result<(), sqlx_migrator::error::Error> {
        sqlx::query(r#"DROP TABLE IF EXISTS admin_update_token_incentives_instruction"#)
            .execute(connection)
            .await?;
        Ok(())
    }
}