Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 24 additions & 24 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,27 @@ borsh = { version = "1.5.1" }
borsh-derive-internal = "0.10.3"
bs58 = { version = "0.5.1", default-features = false }

# decoders
carbon-address-lookup-table-decoder = { path = "decoders/address-lookup-table-decoder", version = "0.9.1" }
carbon-associated-token-account-decoder = { path = "decoders/associated-token-account-decoder", version = "0.9.1" }
carbon-boop-decoder = { path = "decoders/boop-decoder", version = "0.9.1" }

# main
carbon-cli = { path = "crates/cli", version = "0.9.1" }
carbon-core = { path = "crates/core", version = "0.9.1" }
carbon-macros = { path = "crates/macros", version = "0.9.1" }
carbon-proc-macros = { path = "crates/proc-macros", version = "0.9.1" }
carbon-test-utils = { path = "crates/test-utils", version = "0.9.1" }
carbon-drift-v2-decoder = { path = "decoders/drift-v2-decoder", version = "0.9.1" }
carbon-fluxbeam-decoder = { path = "decoders/fluxbeam-decoder", version = "0.9.1" }
carbon-gavel-decoder = { path = "decoders/gavel-decoder", version = "0.9.1" }

# storage and api
carbon-gql-server = { path = "crates/gql-server", version = "0.9.1" }
carbon-postgres-client = { path = "crates/postgres-client", version = "0.9.1" }

# datasources
carbon-helius-atlas-ws-datasource = { path = "datasources/helius-atlas-ws-datasource", version = "0.9.1" }
carbon-jito-shredstream-grpc-datasource = { path = "datasources/jito-shredstream-grpc-datasource", version = "0.9.1" }
carbon-rpc-block-crawler-datasource = { path = "datasources/rpc-block-crawler-datasource", version = "0.9.1" }
carbon-rpc-block-subscribe-datasource = { path = "datasources/rpc-block-subscribe-datasource", version = "0.9.1" }
carbon-rpc-program-subscribe-datasource = { path = "datasources/rpc-program-subscribe-datasource", version = "0.9.1" }
carbon-rpc-transaction-crawler-datasource = { path = "datasources/rpc-transaction-crawler-datasource", version = "0.9.1" }
carbon-yellowstone-grpc-datasource = { path = "datasources/yellowstone-grpc-datasource", version = "0.9.1" }

# metrics
carbon-log-metrics = { path = "metrics/log-metrics", version = "0.9.1" }
carbon-prometheus-metrics = { path = "metrics/prometheus-metrics", version = "0.9.1" }

# decoders
carbon-address-lookup-table-decoder = { path = "decoders/address-lookup-table-decoder", version = "0.9.1" }
carbon-associated-token-account-decoder = { path = "decoders/associated-token-account-decoder", version = "0.9.1" }
carbon-boop-decoder = { path = "decoders/boop-decoder", version = "0.9.1" }
carbon-drift-v2-decoder = { path = "decoders/drift-v2-decoder", version = "0.9.1" }
carbon-fluxbeam-decoder = { path = "decoders/fluxbeam-decoder", version = "0.9.1" }
carbon-gavel-decoder = { path = "decoders/gavel-decoder", version = "0.9.1" }
# vendor
carbon-jito-protos = { path = "misc/jito-protos", version = "0.2.4" }
carbon-jito-shredstream-grpc-datasource = { path = "datasources/jito-shredstream-grpc-datasource", version = "0.9.1" }
carbon-jupiter-dca-decoder = { path = "decoders/jupiter-dca-decoder", version = "0.9.1" }
carbon-jupiter-limit-order-2-decoder = { path = "decoders/jupiter-limit-order-2-decoder", version = "0.9.1" }
carbon-jupiter-limit-order-decoder = { path = "decoders/jupiter-limit-order-decoder", version = "0.9.1" }
Expand All @@ -64,6 +54,10 @@ carbon-kamino-lending-decoder = { path = "decoders/kamino-lending-decoder", vers
carbon-kamino-limit-order-decoder = { path = "decoders/kamino-limit-order-decoder", version = "0.9.1" }
carbon-kamino-vault-decoder = { path = "decoders/kamino-vault-decoder", version = "0.9.1" }
carbon-lifinity-amm-v2-decoder = { path = "decoders/lifinity-amm-v2-decoder", version = "0.9.1" }

# metrics
carbon-log-metrics = { path = "metrics/log-metrics", version = "0.9.1" }
carbon-macros = { path = "crates/macros", version = "0.9.1" }
carbon-marginfi-v2-decoder = { path = "decoders/marginfi-v2-decoder", version = "0.9.1" }
carbon-marinade-finance-decoder = { path = "decoders/marinade-finance-decoder", version = "0.9.1" }
carbon-memo-program-decoder = { path = "decoders/memo-program-decoder", version = "0.9.1" }
Expand All @@ -78,6 +72,9 @@ carbon-okx-dex-decoder = { path = "decoders/okx-dex-decoder", version = "0.9.1"
carbon-openbook-v2-decoder = { path = "decoders/openbook-v2-decoder", version = "0.9.1" }
carbon-orca-whirlpool-decoder = { path = "decoders/orca-whirlpool-decoder", version = "0.9.1" }
carbon-phoenix-v1-decoder = { path = "decoders/phoenix-v1-decoder", version = "0.9.1" }
carbon-postgres-client = { path = "crates/postgres-client", version = "0.9.1" }
carbon-proc-macros = { path = "crates/proc-macros", version = "0.9.1" }
carbon-prometheus-metrics = { path = "metrics/prometheus-metrics", version = "0.9.1" }
carbon-pump-swap-decoder = { path = "decoders/pump-swap-decoder", version = "0.9.1" }
carbon-pumpfun-decoder = { path = "decoders/pumpfun-decoder", version = "0.9.1" }
carbon-raydium-amm-v4-decoder = { path = "decoders/raydium-amm-v4-decoder", version = "0.9.1" }
Expand All @@ -86,21 +83,24 @@ carbon-raydium-cpmm-decoder = { path = "decoders/raydium-cpmm-decoder", version
carbon-raydium-launchpad-decoder = { path = "decoders/raydium-launchpad-decoder", version = "0.9.1" }
carbon-raydium-liquidity-locking-decoder = { path = "decoders/carbon-raydium-liquidity-locking-decoder", version = "0.9.1" }
carbon-raydium-stable-swap-decoder = { path = "decoders/raydium-stable-swap-decoder", version = "0.9.1" }
carbon-rpc-block-crawler-datasource = { path = "datasources/rpc-block-crawler-datasource", version = "0.9.1" }
carbon-rpc-block-subscribe-datasource = { path = "datasources/rpc-block-subscribe-datasource", version = "0.9.1" }
carbon-rpc-program-subscribe-datasource = { path = "datasources/rpc-program-subscribe-datasource", version = "0.9.1" }
carbon-rpc-transaction-crawler-datasource = { path = "datasources/rpc-transaction-crawler-datasource", version = "0.9.1" }
carbon-sharky-decoder = { path = "decoders/sharky-decoder", version = "0.9.1" }
carbon-solayer-restaking-program-decoder = { path = "decoders/solayer-restaking-program-decoder", version = "0.9.1" }
carbon-stabble-stable-swap-decoder = { path = "decoders/carbon-stabble-stable-swap-decoder", version = "0.9.1" }
carbon-stabble-weighted-swap-decoder = { path = "decoders/carbon-stabble-weighted-swap-decoder", version = "0.9.1" }
carbon-stake-program-decoder = { path = "decoders/carbon-stake-program-decoder", version = "0.9.1" }
carbon-system-program-decoder = { path = "decoders/system-program-decoder", version = "0.9.1" }
carbon-test-utils = { path = "crates/test-utils", version = "0.9.1" }
carbon-token-2022-decoder = { path = "decoders/token-2022-decoder", version = "0.9.1" }
carbon-token-program-decoder = { path = "decoders/token-program-decoder", version = "0.9.1" }
carbon-virtual-curve-decoder = { path = "decoders/virtual-curve-decoder", version = "0.9.1" }
carbon-virtuals-decoder = { path = "decoders/virtuals-decoder", version = "0.9.1" }
carbon-yellowstone-grpc-datasource = { path = "datasources/yellowstone-grpc-datasource", version = "0.9.1" }
carbon-zeta-decoder = { path = "decoders/zeta-decoder", version = "0.9.1" }

# vendor
carbon-jito-protos = { path = "misc/jito-protos", version = "0.2.4" }

# misc
chrono = { version = "0.4.40", features = ["serde"] }
clap = { version = "4.5.30", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/legacy_idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub struct LegacyIdlInstructionAccount {
pub is_mut: bool,
#[serde(default)]
pub is_signer: bool,
#[serde(default)]
#[serde(default, alias = "optional", alias = "IsOptional")]
pub is_optional: Option<bool>,
#[serde(default)]
pub docs: Option<Vec<String>>,
Expand Down
24 changes: 12 additions & 12 deletions crates/cli/templates/instructions_struct.askama
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::super::types::*;
{%- endif %}
{% raw %}
use carbon_core::{CarbonDeserialize, borsh};
use carbon_core::{CarbonDeserialize, borsh, account_utils::next_account};
{% endraw %}

#[derive(CarbonDeserialize, Debug, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Hash)]
Expand All @@ -16,27 +16,27 @@ pub struct {{ instruction.struct_name }}{
#[derive(Debug, PartialEq, Eq, Clone, Hash, serde::Serialize, serde::Deserialize)]
pub struct {{ instruction.struct_name }}InstructionAccounts {
{%- for account in instruction.accounts %}
pub {{ account.name }}: solana_pubkey::Pubkey,
pub {{ account.name }}: {% if account.is_optional %}Option<solana_pubkey::Pubkey>{% else %}solana_pubkey::Pubkey{% endif %},
{%- endfor %}
}

impl carbon_core::deserialize::ArrangeAccounts for {{ instruction.struct_name }} {
type ArrangedAccounts = {{ instruction.struct_name }}InstructionAccounts;

fn arrange_accounts(accounts: &[solana_instruction::AccountMeta]) -> Option<Self::ArrangedAccounts> {
let [
{%- for i in (0..instruction.accounts.len()) %}
{{ instruction.accounts[i].name }},
{%- endfor %}
_remaining @ ..
] = accounts else {
return None;
};

let mut iter = accounts.iter();

{%- for account in instruction.accounts %}
{%- if account.is_optional %}
let {{ account.name }} = next_account(&mut iter);
{%- else %}
let {{ account.name }} = next_account(&mut iter)?;
{%- endif %}
{%- endfor %}

Some({{ instruction.struct_name }}InstructionAccounts {
{%- for account in instruction.accounts %}
{{ account.name }}: {{ account.name }}.pubkey,
{{ account.name }},
{%- endfor %}
})
}
Expand Down
26 changes: 26 additions & 0 deletions crates/core/src/account_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use solana_instruction::AccountMeta;
use solana_pubkey::Pubkey;

/// Returns the next account's pubkey from the iterator, or `None` if there are no more accounts.
///
/// # Usage
/// - Use with `?` to indicate the account is required:
/// ```ignore
/// let required = next_account(&mut iter)?;
/// ```
/// This will propagate `None` if the account is missing.
/// - Use without `?` to handle optional accounts:
/// ```ignore
/// let optional = next_account(&mut iter);
/// ```
/// This returns `Option<Pubkey>` that you can match or use directly.
///
/// # Example
/// ```ignore
/// let mut iter = accounts.iter();
/// let required = next_account(&mut iter)?; // required account
/// let optional = next_account(&mut iter); // optional account
/// ```
pub fn next_account<'a>(iter: &mut impl Iterator<Item = &'a AccountMeta>) -> Option<Pubkey> {
Some(iter.next()?.pubkey)
}
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

pub mod account;
pub mod account_deletion;
pub mod account_utils;
mod block_details;
pub mod collection;
pub mod datasource;
Expand Down
7 changes: 5 additions & 2 deletions decoders/mpl-token-metadata-decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ crate-type = ["rlib"]

[dependencies]
carbon-core = { workspace = true }
serde = { workspace = true }
solana-account = { workspace = true }
solana-instruction = { workspace = true, default-features = false }
solana-instruction = { workspace = true }
solana-pubkey = { workspace = true }
serde = { workspace = true }

[dev-dependencies]
carbon-test-utils = { workspace = true }
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0x9c306c1fd4db64a8")]
pub struct CollectionAuthorityRecord {
pub key: Key,
pub bump: u8,
Expand Down
7 changes: 3 additions & 4 deletions decoders/mpl-token-metadata-decoder/src/accounts/edition.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0xea75f94a0763eba7")]
pub struct Edition {
pub key: Key,
pub parent: solana_pubkey::Pubkey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0xe90a12e681ac25ea")]
pub struct EditionMarker {
pub key: Key,
pub ledger: [u8; 31],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0x837b3cfb2d02546e")]
pub struct EditionMarkerV2 {
pub key: Key,
pub ledger: Vec<u8>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0x64e843a0effc0637")]
pub struct HolderDelegateRecord {
pub key: Key,
pub bump: u8,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0x4fa529a7b4bf8db9")]
pub struct MasterEditionV1 {
pub key: Key,
pub supply: u64,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0x653ba3cfee10aa9f")]
pub struct MasterEditionV2 {
pub key: Key,
pub supply: u64,
Expand Down
7 changes: 3 additions & 4 deletions decoders/mpl-token-metadata-decoder/src/accounts/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0x480b791a6fb5555d")]
pub struct Metadata {
pub key: Key,
pub update_authority: solana_pubkey::Pubkey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0xb994256b776af3ec")]
pub struct MetadataDelegateRecord {
pub key: Key,
pub bump: u8,
Expand Down
13 changes: 4 additions & 9 deletions decoders/mpl-token-metadata-decoder/src/accounts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use {
super::TokenMetadataDecoder,
crate::PROGRAM_ID,
carbon_core::{account::AccountDecoder, deserialize::CarbonDeserialize},
};
use carbon_core::account::AccountDecoder;
use carbon_core::deserialize::CarbonDeserialize;

use super::TokenMetadataDecoder;
pub mod collection_authority_record;
pub mod edition;
pub mod edition_marker;
Expand Down Expand Up @@ -41,10 +40,6 @@ impl AccountDecoder<'_> for TokenMetadataDecoder {
&self,
account: &solana_account::Account,
) -> Option<carbon_core::account::DecodedAccount<Self::AccountType>> {
if !account.owner.eq(&PROGRAM_ID) {
return None;
}

if let Some(decoded_account) =
collection_authority_record::CollectionAuthorityRecord::deserialize(
account.data.as_slice(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0xef4f0cce7499018c")]
pub struct ReservationListV1 {
pub key: Key,
pub master_edition: solana_pubkey::Pubkey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use {
super::super::types::*,
carbon_core::{borsh, CarbonDeserialize},
};
use super::super::types::*;
use carbon_core::{borsh, CarbonDeserialize};

#[derive(
CarbonDeserialize, Debug, serde::Deserialize, serde::Serialize, PartialEq, Eq, Clone, Hash,
)]
#[carbon(discriminator = "0xc1e96137f58767da")]
pub struct ReservationListV2 {
pub key: Key,
pub master_edition: solana_pubkey::Pubkey,
Expand Down
Loading
Loading