diff --git a/Cargo.lock b/Cargo.lock index 49fa3b0a..e5601588 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1864,6 +1864,25 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "carbon-swig-decoder" +version = "0.11.0" +dependencies = [ + "async-trait", + "base64 0.22.1", + "carbon-core 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "carbon-test-utils 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "juniper", + "serde", + "serde-big-array", + "serde_json", + "solana-account 2.2.1", + "solana-instruction 2.3.0", + "solana-pubkey 2.4.0", + "sqlx", + "sqlx_migrator", +] + [[package]] name = "carbon-system-program-decoder" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index a85c038e..54548179 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,6 +95,7 @@ carbon-stabble-stable-swap-decoder = { path = "decoders/carbon-stabble-stable-sw carbon-stabble-weighted-swap-decoder = { path = "decoders/carbon-stabble-weighted-swap-decoder", version = "0.11.0" } carbon-stake-program-decoder = { path = "decoders/carbon-stake-program-decoder", version = "0.11.0" } carbon-stream-message-datasource = { path = "datasources/stream-message-datasource", version = "0.11.0" } +carbon-swig-decoder = { path = "decoders/swig-decoder", version = "0.11.0" } carbon-system-program-decoder = { path = "decoders/system-program-decoder", version = "0.11.0" } carbon-test-utils = { path = "crates/test-utils", version = "0.11.0" } carbon-token-2022-decoder = { path = "decoders/token-2022-decoder", version = "0.11.0" } diff --git a/README.md b/README.md index 868ed7e5..ea8939c8 100644 --- a/README.md +++ b/README.md @@ -248,7 +248,8 @@ Decoders for most popular Solana programs are published and maintained: | `carbon-solayer-pool-restaking-decoder` | Solayer Pool Restaking Program Decoder | sSo1iU21jBrU9VaJ8PJib1MtorefUV4fzC9GURa2KNn | | `carbon-stabble-stable-swap-decoder` | Stabble Stable Swap Decoder | swapNyd8XiQwJ6ianp9snpu4brUqFxadzvHebnAXjJZ | | `carbon-stabble-weighted-swap-decoder` | Stabble Weighted Swap Decoder | swapFpHZwjELNnjvThjajtiVmkz3yPQEHjLtka2fwHW | -| `carbon-stake-program-decoder` | Stake Program Decoder | Stake11111111111111111111111111111111111111 | +| `carbon-stake-program-decoder` | Stake Program Decoder | swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB | +| `carbon-swig-decoder`. | Swig Program Decoder | Stake11111111111111111111111111111111111111 | | `carbon-system-program-decoder` | System Program Decoder | 11111111111111111111111111111111 | | `carbon-token-2022-decoder` | Token 2022 Program Decoder | TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb | | `carbon-token-program-decoder` | Token Program Decoder | TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA | diff --git a/decoders/swig-decoder/Cargo.toml b/decoders/swig-decoder/Cargo.toml new file mode 100644 index 00000000..760a33bd --- /dev/null +++ b/decoders/swig-decoder/Cargo.toml @@ -0,0 +1,50 @@ +[package] +name = "carbon-swig-decoder" +version = "0.11.0" +edition = "2021" + +[lib] +crate-type = ["rlib"] + +[features] +default = [] +serde = ["dep:serde", "dep:serde-big-array"] +postgres = [ + "carbon-core/postgres", + "dep:sqlx", + "dep:async-trait", + "dep:sqlx_migrator", + "serde", +] +graphql = [ + "carbon-core/graphql", + "dep:juniper", + "dep:base64", + "serde", +] + +[dependencies] +# Core dependencies +carbon-core = { version = "0.11.0", default-features = false } +solana-pubkey = { version = "^2.3.6" } +solana-account = { version = "~2.2" } +solana-instruction = { version = "~2.3", default-features = false } +serde_json = "1.0.138" + +# Serialization (optional) +serde = { version = "1.0.219", features = ["derive"], optional = true } +serde-big-array = { version = "0.5.1", optional = true } + +# Postgres dependencies (optional) +sqlx = { version = "0.8.6", features = ["postgres", "rust_decimal"], optional = true } +async-trait = { version = "0.1", optional = true } +sqlx_migrator = { version = "0.17.0", optional = true } + +# GraphQL dependencies (optional) +juniper = { version = "0.16.1", optional = true } +base64 = { version = "0.22", optional = true } + + +[dev-dependencies] +carbon-test-utils = { version = "0.11.0" } + diff --git a/decoders/swig-decoder/src/graphql/context.rs b/decoders/swig-decoder/src/graphql/context.rs new file mode 100644 index 00000000..2ac70cd9 --- /dev/null +++ b/decoders/swig-decoder/src/graphql/context.rs @@ -0,0 +1,6 @@ +#[derive(Clone)] +pub struct GraphQLContext { + pub pool: std::sync::Arc, +} + +impl juniper::Context for GraphQLContext {} diff --git a/decoders/swig-decoder/src/graphql/mod.rs b/decoders/swig-decoder/src/graphql/mod.rs new file mode 100644 index 00000000..89fa6bd8 --- /dev/null +++ b/decoders/swig-decoder/src/graphql/mod.rs @@ -0,0 +1,4 @@ +pub mod context; +pub mod query; + +pub use query::*; diff --git a/decoders/swig-decoder/src/graphql/query.rs b/decoders/swig-decoder/src/graphql/query.rs new file mode 100644 index 00000000..dbaf4561 --- /dev/null +++ b/decoders/swig-decoder/src/graphql/query.rs @@ -0,0 +1,11 @@ +use juniper::{graphql_object, FieldResult}; +use std::str::FromStr; + +pub struct QueryRoot; + +#[graphql_object(context = crate::graphql::context::GraphQLContext)] +impl QueryRoot { + // Accounts + + // Instructions (per-instruction list and lookup by signature+index) +} diff --git a/decoders/swig-decoder/src/instructions/add_authority_v1.rs b/decoders/swig-decoder/src/instructions/add_authority_v1.rs new file mode 100644 index 00000000..9a0489cc --- /dev/null +++ b/decoders/swig-decoder/src/instructions/add_authority_v1.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct AddAuthorityV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct AddAuthorityV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl AddAuthorityV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[1] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for AddAuthorityV1 { + type ArrangedAccounts = AddAuthorityV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(AddAuthorityV1InstructionAccounts { + swig: swig, + payer: payer, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/create_session_v1.rs b/decoders/swig-decoder/src/instructions/create_session_v1.rs new file mode 100644 index 00000000..19ffc136 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/create_session_v1.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct CreateSessionV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct CreateSessionV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl CreateSessionV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[5] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for CreateSessionV1 { + type ArrangedAccounts = CreateSessionV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(CreateSessionV1InstructionAccounts { + swig: swig, + payer: payer, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/create_sub_account_v1.rs b/decoders/swig-decoder/src/instructions/create_sub_account_v1.rs new file mode 100644 index 00000000..f3cca580 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/create_sub_account_v1.rs @@ -0,0 +1,77 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct CreateSubAccountV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct CreateSubAccountV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub sub_account: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl CreateSubAccountV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[6] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for CreateSubAccountV1 { + type ArrangedAccounts = CreateSubAccountV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let sub_account = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(CreateSubAccountV1InstructionAccounts { + swig: swig, + payer: payer, + sub_account: sub_account, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/create_v1.rs b/decoders/swig-decoder/src/instructions/create_v1.rs new file mode 100644 index 00000000..f3342358 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/create_v1.rs @@ -0,0 +1,77 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct CreateV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct CreateV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub swig_wallet_address: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl CreateV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[0] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for CreateV1 { + type ArrangedAccounts = CreateV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let swig_wallet_address = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(CreateV1InstructionAccounts { + swig: swig, + payer: payer, + swig_wallet_address: swig_wallet_address, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/graphql/mod.rs b/decoders/swig-decoder/src/instructions/graphql/mod.rs new file mode 100644 index 00000000..68c77646 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/graphql/mod.rs @@ -0,0 +1,25 @@ +use juniper::GraphQLObject; + +#[derive(Debug, Clone, GraphQLObject)] +#[graphql(name = "InstructionMetadata")] +pub struct InstructionMetadataGraphQL { + pub signature: String, + pub instruction_index: carbon_core::graphql::primitives::U32, + pub stack_height: carbon_core::graphql::primitives::U32, + pub slot: Option, +} + +impl From for InstructionMetadataGraphQL { + fn from(metadata: carbon_core::postgres::metadata::InstructionRowMetadata) -> Self { + Self { + signature: metadata.signature, + instruction_index: carbon_core::graphql::primitives::U32( + (*metadata.instruction_index) as u32, + ), + stack_height: carbon_core::graphql::primitives::U32((*metadata.stack_height) as u32), + slot: metadata + .slot + .map(|v| carbon_core::graphql::primitives::U64(*v)), + } + } +} diff --git a/decoders/swig-decoder/src/instructions/migrate_to_wallet_address_v1.rs b/decoders/swig-decoder/src/instructions/migrate_to_wallet_address_v1.rs new file mode 100644 index 00000000..8dbf344d --- /dev/null +++ b/decoders/swig-decoder/src/instructions/migrate_to_wallet_address_v1.rs @@ -0,0 +1,80 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct MigrateToWalletAddressV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct MigrateToWalletAddressV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub authority: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub swig_wallet_address: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl MigrateToWalletAddressV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[12] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for MigrateToWalletAddressV1 { + type ArrangedAccounts = MigrateToWalletAddressV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let authority = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let swig_wallet_address = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(MigrateToWalletAddressV1InstructionAccounts { + swig: swig, + authority: authority, + payer: payer, + swig_wallet_address: swig_wallet_address, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/mod.rs b/decoders/swig-decoder/src/instructions/mod.rs new file mode 100644 index 00000000..ae8795d7 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/mod.rs @@ -0,0 +1,213 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +#[cfg(feature = "postgres")] +pub mod postgres; + +#[cfg(feature = "graphql")] +pub mod graphql; + +use crate::{SwigDecoder, PROGRAM_ID}; + +pub mod add_authority_v1; +pub mod create_session_v1; +pub mod create_sub_account_v1; +pub mod create_v1; +pub mod migrate_to_wallet_address_v1; +pub mod remove_authority_v1; +pub mod sign_v1; +pub mod sign_v2; +pub mod sub_account_sign_v1; +pub mod toggle_sub_account_v1; +pub mod transfer_assets_v1; +pub mod update_authority_v1; +pub mod withdraw_from_sub_account_v1; + +pub use self::add_authority_v1::*; +pub use self::create_session_v1::*; +pub use self::create_sub_account_v1::*; +pub use self::create_v1::*; +pub use self::migrate_to_wallet_address_v1::*; +pub use self::remove_authority_v1::*; +pub use self::sign_v1::*; +pub use self::sign_v2::*; +pub use self::sub_account_sign_v1::*; +pub use self::toggle_sub_account_v1::*; +pub use self::transfer_assets_v1::*; +pub use self::update_authority_v1::*; +pub use self::withdraw_from_sub_account_v1::*; + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(tag = "type", content = "data"))] +pub enum SwigInstruction { + AddAuthorityV1(AddAuthorityV1), + CreateSessionV1(CreateSessionV1), + CreateSubAccountV1(CreateSubAccountV1), + CreateV1(CreateV1), + MigrateToWalletAddressV1(MigrateToWalletAddressV1), + RemoveAuthorityV1(RemoveAuthorityV1), + SignV1(SignV1), + SignV2(SignV2), + SubAccountSignV1(SubAccountSignV1), + ToggleSubAccountV1(ToggleSubAccountV1), + TransferAssetsV1(TransferAssetsV1), + UpdateAuthorityV1(UpdateAuthorityV1), + WithdrawFromSubAccountV1(WithdrawFromSubAccountV1), +} + +impl carbon_core::instruction::InstructionDecoder<'_> for SwigDecoder { + type InstructionType = SwigInstruction; + + fn decode_instruction( + &self, + instruction: &solana_instruction::Instruction, + ) -> Option> { + if !instruction.program_id.eq(&PROGRAM_ID) { + return None; + } + + let data = instruction.data.as_slice(); + + // Try to decode CreateV1 + { + if let Some(decoded) = create_v1::CreateV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::CreateV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode AddAuthorityV1 + { + if let Some(decoded) = add_authority_v1::AddAuthorityV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::AddAuthorityV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode RemoveAuthorityV1 + { + if let Some(decoded) = remove_authority_v1::RemoveAuthorityV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::RemoveAuthorityV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode UpdateAuthorityV1 + { + if let Some(decoded) = update_authority_v1::UpdateAuthorityV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::UpdateAuthorityV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode SignV1 + { + if let Some(decoded) = sign_v1::SignV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::SignV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode SignV2 + { + if let Some(decoded) = sign_v2::SignV2::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::SignV2(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode CreateSessionV1 + { + if let Some(decoded) = create_session_v1::CreateSessionV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::CreateSessionV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode CreateSubAccountV1 + { + if let Some(decoded) = create_sub_account_v1::CreateSubAccountV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::CreateSubAccountV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode WithdrawFromSubAccountV1 + { + if let Some(decoded) = + withdraw_from_sub_account_v1::WithdrawFromSubAccountV1::decode(data) + { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::WithdrawFromSubAccountV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode SubAccountSignV1 + { + if let Some(decoded) = sub_account_sign_v1::SubAccountSignV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::SubAccountSignV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode ToggleSubAccountV1 + { + if let Some(decoded) = toggle_sub_account_v1::ToggleSubAccountV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::ToggleSubAccountV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode MigrateToWalletAddressV1 + { + if let Some(decoded) = + migrate_to_wallet_address_v1::MigrateToWalletAddressV1::decode(data) + { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::MigrateToWalletAddressV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + // Try to decode TransferAssetsV1 + { + if let Some(decoded) = transfer_assets_v1::TransferAssetsV1::decode(data) { + return Some(carbon_core::instruction::DecodedInstruction { + program_id: instruction.program_id, + data: SwigInstruction::TransferAssetsV1(decoded), + accounts: instruction.accounts.clone(), + }); + } + } + + None + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/add_authority_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/add_authority_v1_row.rs new file mode 100644 index 00000000..a9726116 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/add_authority_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::AddAuthorityV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct AddAuthorityV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl AddAuthorityV1Row { + pub fn from_parts(_source: AddAuthorityV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for AddAuthorityV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: AddAuthorityV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for AddAuthorityV1 { + fn table() -> &'static str { + "add_authority_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for AddAuthorityV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO add_authority_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 AddAuthorityV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO add_authority_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 AddAuthorityV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM add_authority_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 AddAuthorityV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM add_authority_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct AddAuthorityV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for AddAuthorityV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS add_authority_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS add_authority_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/create_session_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/create_session_v1_row.rs new file mode 100644 index 00000000..988eb459 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/create_session_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::CreateSessionV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct CreateSessionV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl CreateSessionV1Row { + pub fn from_parts(_source: CreateSessionV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for CreateSessionV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: CreateSessionV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for CreateSessionV1 { + fn table() -> &'static str { + "create_session_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for CreateSessionV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO create_session_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 CreateSessionV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO create_session_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 CreateSessionV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM create_session_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 CreateSessionV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM create_session_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct CreateSessionV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for CreateSessionV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS create_session_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS create_session_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/create_sub_account_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/create_sub_account_v1_row.rs new file mode 100644 index 00000000..ef0b8606 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/create_sub_account_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::CreateSubAccountV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct CreateSubAccountV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl CreateSubAccountV1Row { + pub fn from_parts(_source: CreateSubAccountV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for CreateSubAccountV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: CreateSubAccountV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for CreateSubAccountV1 { + fn table() -> &'static str { + "create_sub_account_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for CreateSubAccountV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO create_sub_account_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 CreateSubAccountV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO create_sub_account_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 CreateSubAccountV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM create_sub_account_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 CreateSubAccountV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM create_sub_account_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct CreateSubAccountV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for CreateSubAccountV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS create_sub_account_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS create_sub_account_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/create_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/create_v1_row.rs new file mode 100644 index 00000000..7fb3b5da --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/create_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::CreateV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct CreateV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl CreateV1Row { + pub fn from_parts(_source: CreateV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for CreateV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: CreateV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for CreateV1 { + fn table() -> &'static str { + "create_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for CreateV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO create_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 CreateV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO create_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 CreateV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM create_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 CreateV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM create_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct CreateV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for CreateV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS create_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS create_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/migrate_to_wallet_address_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/migrate_to_wallet_address_v1_row.rs new file mode 100644 index 00000000..e215739f --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/migrate_to_wallet_address_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::MigrateToWalletAddressV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct MigrateToWalletAddressV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl MigrateToWalletAddressV1Row { + pub fn from_parts(_source: MigrateToWalletAddressV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for MigrateToWalletAddressV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: MigrateToWalletAddressV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for MigrateToWalletAddressV1 { + fn table() -> &'static str { + "migrate_to_wallet_address_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for MigrateToWalletAddressV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO migrate_to_wallet_address_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 MigrateToWalletAddressV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO migrate_to_wallet_address_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 MigrateToWalletAddressV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM migrate_to_wallet_address_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 MigrateToWalletAddressV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM migrate_to_wallet_address_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct MigrateToWalletAddressV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for MigrateToWalletAddressV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS migrate_to_wallet_address_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS migrate_to_wallet_address_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/mod.rs b/decoders/swig-decoder/src/instructions/postgres/mod.rs new file mode 100644 index 00000000..280b9fde --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/mod.rs @@ -0,0 +1,301 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +pub mod add_authority_v1_row; +pub mod create_session_v1_row; +pub mod create_sub_account_v1_row; +pub mod create_v1_row; +pub mod migrate_to_wallet_address_v1_row; +pub mod remove_authority_v1_row; +pub mod sign_v1_row; +pub mod sign_v2_row; +pub mod sub_account_sign_v1_row; +pub mod toggle_sub_account_v1_row; +pub mod transfer_assets_v1_row; +pub mod update_authority_v1_row; +pub mod withdraw_from_sub_account_v1_row; + +pub use self::add_authority_v1_row::*; +pub use self::create_session_v1_row::*; +pub use self::create_sub_account_v1_row::*; +pub use self::create_v1_row::*; +pub use self::migrate_to_wallet_address_v1_row::*; +pub use self::remove_authority_v1_row::*; +pub use self::sign_v1_row::*; +pub use self::sign_v2_row::*; +pub use self::sub_account_sign_v1_row::*; +pub use self::toggle_sub_account_v1_row::*; +pub use self::transfer_assets_v1_row::*; +pub use self::update_authority_v1_row::*; +pub use self::withdraw_from_sub_account_v1_row::*; + +use super::SwigInstruction; + +pub struct SwigInstructionsMigration; + +impl sqlx_migrator::Migration for SwigInstructionsMigration { + fn app(&self) -> &str { + "swig" + } + + fn name(&self) -> &str { + "swig_instructions" + } + + fn operations(&self) -> Vec>> { + vec![ + Box::new(AddAuthorityV1MigrationOperation), + Box::new(CreateSessionV1MigrationOperation), + Box::new(CreateSubAccountV1MigrationOperation), + Box::new(CreateV1MigrationOperation), + Box::new(MigrateToWalletAddressV1MigrationOperation), + Box::new(RemoveAuthorityV1MigrationOperation), + Box::new(SignV1MigrationOperation), + Box::new(SignV2MigrationOperation), + Box::new(SubAccountSignV1MigrationOperation), + Box::new(ToggleSubAccountV1MigrationOperation), + Box::new(TransferAssetsV1MigrationOperation), + Box::new(UpdateAuthorityV1MigrationOperation), + Box::new(WithdrawFromSubAccountV1MigrationOperation), + ] + } + + fn parents(&self) -> Vec>> { + vec![] + } +} + +pub struct SwigInstructionWithMetadata( + pub SwigInstruction, + pub carbon_core::instruction::InstructionMetadata, +); + +impl + From<( + SwigInstruction, + carbon_core::instruction::InstructionMetadata, + )> for SwigInstructionWithMetadata +{ + fn from( + value: ( + SwigInstruction, + carbon_core::instruction::InstructionMetadata, + ), + ) -> Self { + SwigInstructionWithMetadata(value.0, value.1) + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for SwigInstructionWithMetadata { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + let SwigInstructionWithMetadata(instruction, metadata) = self; + match instruction { + SwigInstruction::CreateV1(instruction) => { + let row = + create_v1_row::CreateV1Row::from_parts(instruction.clone(), metadata.clone()); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::AddAuthorityV1(instruction) => { + let row = add_authority_v1_row::AddAuthorityV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::RemoveAuthorityV1(instruction) => { + let row = remove_authority_v1_row::RemoveAuthorityV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::UpdateAuthorityV1(instruction) => { + let row = update_authority_v1_row::UpdateAuthorityV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::SignV1(instruction) => { + let row = sign_v1_row::SignV1Row::from_parts(instruction.clone(), metadata.clone()); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::SignV2(instruction) => { + let row = sign_v2_row::SignV2Row::from_parts(instruction.clone(), metadata.clone()); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::CreateSessionV1(instruction) => { + let row = create_session_v1_row::CreateSessionV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::CreateSubAccountV1(instruction) => { + let row = create_sub_account_v1_row::CreateSubAccountV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::WithdrawFromSubAccountV1(instruction) => { + let row = withdraw_from_sub_account_v1_row::WithdrawFromSubAccountV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::SubAccountSignV1(instruction) => { + let row = sub_account_sign_v1_row::SubAccountSignV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::ToggleSubAccountV1(instruction) => { + let row = toggle_sub_account_v1_row::ToggleSubAccountV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::MigrateToWalletAddressV1(instruction) => { + let row = migrate_to_wallet_address_v1_row::MigrateToWalletAddressV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + SwigInstruction::TransferAssetsV1(instruction) => { + let row = transfer_assets_v1_row::TransferAssetsV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.insert(pool).await?; + Ok(()) + } + } + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Upsert for SwigInstructionWithMetadata { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + let SwigInstructionWithMetadata(instruction, metadata) = self; + match instruction { + SwigInstruction::CreateV1(instruction) => { + let row = + create_v1_row::CreateV1Row::from_parts(instruction.clone(), metadata.clone()); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::AddAuthorityV1(instruction) => { + let row = add_authority_v1_row::AddAuthorityV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::RemoveAuthorityV1(instruction) => { + let row = remove_authority_v1_row::RemoveAuthorityV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::UpdateAuthorityV1(instruction) => { + let row = update_authority_v1_row::UpdateAuthorityV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::SignV1(instruction) => { + let row = sign_v1_row::SignV1Row::from_parts(instruction.clone(), metadata.clone()); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::SignV2(instruction) => { + let row = sign_v2_row::SignV2Row::from_parts(instruction.clone(), metadata.clone()); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::CreateSessionV1(instruction) => { + let row = create_session_v1_row::CreateSessionV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::CreateSubAccountV1(instruction) => { + let row = create_sub_account_v1_row::CreateSubAccountV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::WithdrawFromSubAccountV1(instruction) => { + let row = withdraw_from_sub_account_v1_row::WithdrawFromSubAccountV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::SubAccountSignV1(instruction) => { + let row = sub_account_sign_v1_row::SubAccountSignV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::ToggleSubAccountV1(instruction) => { + let row = toggle_sub_account_v1_row::ToggleSubAccountV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::MigrateToWalletAddressV1(instruction) => { + let row = migrate_to_wallet_address_v1_row::MigrateToWalletAddressV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + SwigInstruction::TransferAssetsV1(instruction) => { + let row = transfer_assets_v1_row::TransferAssetsV1Row::from_parts( + instruction.clone(), + metadata.clone(), + ); + row.upsert(pool).await?; + Ok(()) + } + } + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/remove_authority_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/remove_authority_v1_row.rs new file mode 100644 index 00000000..a108ee34 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/remove_authority_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::RemoveAuthorityV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct RemoveAuthorityV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl RemoveAuthorityV1Row { + pub fn from_parts(_source: RemoveAuthorityV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for RemoveAuthorityV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: RemoveAuthorityV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for RemoveAuthorityV1 { + fn table() -> &'static str { + "remove_authority_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for RemoveAuthorityV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO remove_authority_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 RemoveAuthorityV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO remove_authority_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 RemoveAuthorityV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM remove_authority_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 RemoveAuthorityV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM remove_authority_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct RemoveAuthorityV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for RemoveAuthorityV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS remove_authority_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS remove_authority_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/sign_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/sign_v1_row.rs new file mode 100644 index 00000000..5f78d663 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/sign_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::SignV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct SignV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl SignV1Row { + pub fn from_parts(_source: SignV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for SignV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: SignV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for SignV1 { + fn table() -> &'static str { + "sign_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for SignV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO sign_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 SignV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO sign_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 SignV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM sign_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 SignV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM sign_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct SignV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for SignV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS sign_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS sign_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/sign_v2_row.rs b/decoders/swig-decoder/src/instructions/postgres/sign_v2_row.rs new file mode 100644 index 00000000..30a520b7 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/sign_v2_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::SignV2; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct SignV2Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl SignV2Row { + pub fn from_parts(_source: SignV2, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for SignV2 { + type Error = carbon_core::error::Error; + fn try_from(_source: SignV2Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for SignV2 { + fn table() -> &'static str { + "sign_v2_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for SignV2Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO sign_v2_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 SignV2Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO sign_v2_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 SignV2Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM sign_v2_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 SignV2Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM sign_v2_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct SignV2MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for SignV2MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS sign_v2_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS sign_v2_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/sub_account_sign_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/sub_account_sign_v1_row.rs new file mode 100644 index 00000000..e74d1a38 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/sub_account_sign_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::SubAccountSignV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct SubAccountSignV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl SubAccountSignV1Row { + pub fn from_parts(_source: SubAccountSignV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for SubAccountSignV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: SubAccountSignV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for SubAccountSignV1 { + fn table() -> &'static str { + "sub_account_sign_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for SubAccountSignV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO sub_account_sign_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 SubAccountSignV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO sub_account_sign_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 SubAccountSignV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM sub_account_sign_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 SubAccountSignV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM sub_account_sign_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct SubAccountSignV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for SubAccountSignV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS sub_account_sign_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS sub_account_sign_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/toggle_sub_account_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/toggle_sub_account_v1_row.rs new file mode 100644 index 00000000..785a90a3 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/toggle_sub_account_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::ToggleSubAccountV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct ToggleSubAccountV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl ToggleSubAccountV1Row { + pub fn from_parts(_source: ToggleSubAccountV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for ToggleSubAccountV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: ToggleSubAccountV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for ToggleSubAccountV1 { + fn table() -> &'static str { + "toggle_sub_account_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for ToggleSubAccountV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO toggle_sub_account_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 ToggleSubAccountV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO toggle_sub_account_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 ToggleSubAccountV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM toggle_sub_account_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 ToggleSubAccountV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM toggle_sub_account_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct ToggleSubAccountV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for ToggleSubAccountV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS toggle_sub_account_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS toggle_sub_account_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/transfer_assets_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/transfer_assets_v1_row.rs new file mode 100644 index 00000000..00623a44 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/transfer_assets_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::TransferAssetsV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct TransferAssetsV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl TransferAssetsV1Row { + pub fn from_parts(_source: TransferAssetsV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for TransferAssetsV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: TransferAssetsV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for TransferAssetsV1 { + fn table() -> &'static str { + "transfer_assets_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for TransferAssetsV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO transfer_assets_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 TransferAssetsV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO transfer_assets_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 TransferAssetsV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM transfer_assets_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 TransferAssetsV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM transfer_assets_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct TransferAssetsV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for TransferAssetsV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS transfer_assets_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS transfer_assets_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/update_authority_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/update_authority_v1_row.rs new file mode 100644 index 00000000..2245b3ea --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/update_authority_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::UpdateAuthorityV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct UpdateAuthorityV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl UpdateAuthorityV1Row { + pub fn from_parts(_source: UpdateAuthorityV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for UpdateAuthorityV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: UpdateAuthorityV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for UpdateAuthorityV1 { + fn table() -> &'static str { + "update_authority_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for UpdateAuthorityV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO update_authority_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 UpdateAuthorityV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO update_authority_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 UpdateAuthorityV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM update_authority_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 UpdateAuthorityV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM update_authority_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct UpdateAuthorityV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for UpdateAuthorityV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS update_authority_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS update_authority_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/postgres/withdraw_from_sub_account_v1_row.rs b/decoders/swig-decoder/src/instructions/postgres/withdraw_from_sub_account_v1_row.rs new file mode 100644 index 00000000..77a9d096 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/postgres/withdraw_from_sub_account_v1_row.rs @@ -0,0 +1,168 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use crate::instructions::WithdrawFromSubAccountV1; +use carbon_core::instruction::InstructionMetadata; +use carbon_core::postgres::metadata::InstructionRowMetadata; + +#[derive(sqlx::FromRow, Debug, Clone)] +pub struct WithdrawFromSubAccountV1Row { + #[sqlx(flatten)] + pub metadata: InstructionRowMetadata, +} + +impl WithdrawFromSubAccountV1Row { + pub fn from_parts(_source: WithdrawFromSubAccountV1, metadata: InstructionMetadata) -> Self { + Self { + metadata: metadata.into(), + } + } +} + +impl TryFrom for WithdrawFromSubAccountV1 { + type Error = carbon_core::error::Error; + fn try_from(_source: WithdrawFromSubAccountV1Row) -> Result { + Ok(Self {}) + } +} + +impl carbon_core::postgres::operations::Table for WithdrawFromSubAccountV1 { + fn table() -> &'static str { + "withdraw_from_sub_account_v1_instruction" + } + + fn columns() -> Vec<&'static str> { + vec![ + "__signature", + "__instruction_index", + "__stack_height", + "__slot", + ] + } +} + +#[async_trait::async_trait] +impl carbon_core::postgres::operations::Insert for WithdrawFromSubAccountV1Row { + async fn insert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#" + INSERT INTO withdraw_from_sub_account_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 )"#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 WithdrawFromSubAccountV1Row { + async fn upsert(&self, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query(r#"INSERT INTO withdraw_from_sub_account_v1_instruction ( + __signature, __instruction_index, __stack_height, __slot + ) VALUES ( + $1, $2, $3, $4 ) ON CONFLICT ( + __signature, __instruction_index + ) DO UPDATE SET + __instruction_index = EXCLUDED.__instruction_index, + __stack_height = EXCLUDED.__stack_height, + __slot = EXCLUDED.__slot + "#) + .bind(self.metadata.signature.clone()) + .bind(self.metadata.instruction_index.clone()) + .bind(self.metadata.stack_height.clone()) + .bind(self.metadata.slot.clone()) + .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 WithdrawFromSubAccountV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn delete(key: Self::Key, pool: &sqlx::PgPool) -> carbon_core::error::CarbonResult<()> { + sqlx::query( + r#"DELETE FROM withdraw_from_sub_account_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .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 WithdrawFromSubAccountV1Row { + type Key = (String, carbon_core::postgres::primitives::U32); + + async fn lookup( + key: Self::Key, + pool: &sqlx::PgPool, + ) -> carbon_core::error::CarbonResult> { + let row = sqlx::query_as( + r#"SELECT * FROM withdraw_from_sub_account_v1_instruction WHERE + __signature = $1 AND __instruction_index = $2 + "#, + ) + .bind(key.0) + .bind(key.1) + .fetch_optional(pool) + .await + .map_err(|e| carbon_core::error::Error::Custom(e.to_string()))?; + + Ok(row) + } +} + +pub struct WithdrawFromSubAccountV1MigrationOperation; + +#[async_trait::async_trait] +impl sqlx_migrator::Operation for WithdrawFromSubAccountV1MigrationOperation { + async fn up( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query( + r#"CREATE TABLE IF NOT EXISTS withdraw_from_sub_account_v1_instruction ( + -- Instruction data + + -- Instruction metadata + __signature TEXT NOT NULL, + __instruction_index BIGINT NOT NULL, + __stack_height BIGINT NOT NULL, + __slot NUMERIC(20), + + PRIMARY KEY (__signature, __instruction_index) + )"#, + ) + .execute(connection) + .await?; + Ok(()) + } + + async fn down( + &self, + connection: &mut sqlx::PgConnection, + ) -> Result<(), sqlx_migrator::error::Error> { + sqlx::query(r#"DROP TABLE IF EXISTS withdraw_from_sub_account_v1_instruction"#) + .execute(connection) + .await?; + Ok(()) + } +} diff --git a/decoders/swig-decoder/src/instructions/remove_authority_v1.rs b/decoders/swig-decoder/src/instructions/remove_authority_v1.rs new file mode 100644 index 00000000..83e63452 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/remove_authority_v1.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct RemoveAuthorityV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct RemoveAuthorityV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl RemoveAuthorityV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[2] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for RemoveAuthorityV1 { + type ArrangedAccounts = RemoveAuthorityV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(RemoveAuthorityV1InstructionAccounts { + swig: swig, + payer: payer, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/sign_v1.rs b/decoders/swig-decoder/src/instructions/sign_v1.rs new file mode 100644 index 00000000..fff2debf --- /dev/null +++ b/decoders/swig-decoder/src/instructions/sign_v1.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct SignV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SignV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl SignV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[4] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for SignV1 { + type ArrangedAccounts = SignV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(SignV1InstructionAccounts { + swig: swig, + payer: payer, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/sign_v2.rs b/decoders/swig-decoder/src/instructions/sign_v2.rs new file mode 100644 index 00000000..a1182875 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/sign_v2.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct SignV2 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SignV2InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub swig_wallet_address: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl SignV2 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[11] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for SignV2 { + type ArrangedAccounts = SignV2InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let swig_wallet_address = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(SignV2InstructionAccounts { + swig: swig, + swig_wallet_address: swig_wallet_address, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/sub_account_sign_v1.rs b/decoders/swig-decoder/src/instructions/sub_account_sign_v1.rs new file mode 100644 index 00000000..bdab6c2e --- /dev/null +++ b/decoders/swig-decoder/src/instructions/sub_account_sign_v1.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct SubAccountSignV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct SubAccountSignV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub sub_account: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl SubAccountSignV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[9] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for SubAccountSignV1 { + type ArrangedAccounts = SubAccountSignV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let sub_account = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(SubAccountSignV1InstructionAccounts { + swig: swig, + sub_account: sub_account, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/toggle_sub_account_v1.rs b/decoders/swig-decoder/src/instructions/toggle_sub_account_v1.rs new file mode 100644 index 00000000..22b46a51 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/toggle_sub_account_v1.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct ToggleSubAccountV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ToggleSubAccountV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub sub_account: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl ToggleSubAccountV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[10] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for ToggleSubAccountV1 { + type ArrangedAccounts = ToggleSubAccountV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let sub_account = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(ToggleSubAccountV1InstructionAccounts { + swig: swig, + payer: payer, + sub_account: sub_account, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/transfer_assets_v1.rs b/decoders/swig-decoder/src/instructions/transfer_assets_v1.rs new file mode 100644 index 00000000..4aca4e1f --- /dev/null +++ b/decoders/swig-decoder/src/instructions/transfer_assets_v1.rs @@ -0,0 +1,77 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct TransferAssetsV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct TransferAssetsV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub swig_wallet_address: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl TransferAssetsV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[13] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for TransferAssetsV1 { + type ArrangedAccounts = TransferAssetsV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let swig_wallet_address = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(TransferAssetsV1InstructionAccounts { + swig: swig, + swig_wallet_address: swig_wallet_address, + payer: payer, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/update_authority_v1.rs b/decoders/swig-decoder/src/instructions/update_authority_v1.rs new file mode 100644 index 00000000..839a4d76 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/update_authority_v1.rs @@ -0,0 +1,74 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct UpdateAuthorityV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct UpdateAuthorityV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl UpdateAuthorityV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[3] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for UpdateAuthorityV1 { + type ArrangedAccounts = UpdateAuthorityV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(UpdateAuthorityV1InstructionAccounts { + swig: swig, + payer: payer, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/instructions/withdraw_from_sub_account_v1.rs b/decoders/swig-decoder/src/instructions/withdraw_from_sub_account_v1.rs new file mode 100644 index 00000000..c55b2af5 --- /dev/null +++ b/decoders/swig-decoder/src/instructions/withdraw_from_sub_account_v1.rs @@ -0,0 +1,83 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use carbon_core::account_utils::next_account; +use carbon_core::borsh::{self, BorshDeserialize}; +use carbon_core::deserialize::ArrangeAccounts; + +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive( + Debug, + Clone, + carbon_core::borsh::BorshSerialize, + carbon_core::borsh::BorshDeserialize, + PartialEq, +)] +pub struct WithdrawFromSubAccountV1 {} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct WithdrawFromSubAccountV1InstructionAccounts { + pub swig: solana_pubkey::Pubkey, + pub payer: solana_pubkey::Pubkey, + pub sub_account: solana_pubkey::Pubkey, + pub authority: solana_pubkey::Pubkey, + pub swig_wallet_address: solana_pubkey::Pubkey, + pub system_program: solana_pubkey::Pubkey, + pub remaining: Vec, +} + +impl WithdrawFromSubAccountV1 { + pub fn decode(data: &[u8]) -> Option { + if data.len() < 1 { + return None; + } + let discriminator = &data[0..1]; + if discriminator != &[7] { + return None; + } + + let mut data_slice = data; + + data_slice = &data_slice[1..]; + + if let Ok(decoded) = Self::deserialize(&mut data_slice) { + return Some(decoded); + } + + None + } +} + +impl ArrangeAccounts for WithdrawFromSubAccountV1 { + type ArrangedAccounts = WithdrawFromSubAccountV1InstructionAccounts; + + fn arrange_accounts( + accounts: &[solana_instruction::AccountMeta], + ) -> Option { + let mut iter = accounts.iter(); + + let swig = next_account(&mut iter)?; + let payer = next_account(&mut iter)?; + let sub_account = next_account(&mut iter)?; + let authority = next_account(&mut iter)?; + let swig_wallet_address = next_account(&mut iter)?; + let system_program = next_account(&mut iter)?; + + let remaining = iter.as_slice(); + + Some(WithdrawFromSubAccountV1InstructionAccounts { + swig: swig, + payer: payer, + sub_account: sub_account, + authority: authority, + swig_wallet_address: swig_wallet_address, + system_program: system_program, + remaining: remaining.to_vec(), + }) + } +} diff --git a/decoders/swig-decoder/src/lib.rs b/decoders/swig-decoder/src/lib.rs new file mode 100644 index 00000000..41820a5b --- /dev/null +++ b/decoders/swig-decoder/src/lib.rs @@ -0,0 +1,15 @@ +//! This code was AUTOGENERATED using the Codama library. +//! Please DO NOT EDIT THIS FILE, instead use visitors +//! to add features, then rerun Codama to update it. +//! +//! +//! + +use solana_pubkey::Pubkey; +pub struct SwigDecoder; +pub const PROGRAM_ID: Pubkey = + solana_pubkey::Pubkey::from_str_const("swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB"); + +#[cfg(feature = "graphql")] +pub mod graphql; +pub mod instructions; diff --git a/scripts/publish-crate.sh b/scripts/publish-crate.sh index 041deb8c..14be07bd 100644 --- a/scripts/publish-crate.sh +++ b/scripts/publish-crate.sh @@ -70,6 +70,7 @@ workspace_crates=( carbon-stabble-stable-swap-decoder carbon-stabble-weighted-swap-decoder carbon-stake-program-decoder + carbon-swig-decoder carbon-system-program-decoder carbon-token-2022-decoder carbon-token-program-decoder diff --git a/scripts/yank-crates.sh b/scripts/yank-crates.sh index 1d21b815..da28d8e7 100644 --- a/scripts/yank-crates.sh +++ b/scripts/yank-crates.sh @@ -72,6 +72,7 @@ workspace_crates=( carbon-stabble-stable-swap-decoder carbon-stabble-weighted-swap-decoder carbon-stake-program-decoder + carbon-swig-decoder carbon-system-program-decoder carbon-token-2022-decoder carbon-token-program-decoder