1. Decoders

Perpetuals and derivatives decoders

Decode 3 Solana perpetuals and derivatives programs in Rust, including Drift v2, Jupiter Perpetuals and Zeta Markets, with Carbon decoder crates.

On this page

Carbon 2.0.0 has decoder crates for 3 perpetuals and derivatives programs on Solana: 415 instructions, 58 account types and 59 events in all. Use them to index orders, fills, positions, funding and liquidations as typed Rust values instead of parsing raw bytes. Each program's page lists every instruction with its discriminator, data fields and accounts, every account and event, and a complete program that runs against the public RPC.

Programs#

Program IDs are the mainnet addresses compiled into each crate as PROGRAM_ID. Instruction counts exclude the CpiEvent wrapper.

ProgramCrateProgram IDInstructionsAccountsEvents
Drift v2carbon-drift-v2-decoderdRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH2492726
Jupiter Perpetualscarbon-jupiter-perpetuals-decoderPERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu59825
Zeta Marketscarbon-zeta-decoderZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD107238

Decode several in one pipeline#

Add carbon-core and the decoder crates you need, all at the same version. For every program in this category:

Terminal
cargo add carbon-core@2.0.0 carbon-drift-v2-decoder@2.0.0 carbon-jupiter-perpetuals-decoder@2.0.0 carbon-zeta-decoder@2.0.0

Register each decoder with a processor for its instruction enum. This fragment goes in your pipeline setup; the processors are yours, one per program, each implementing Processor for that program's instruction input (see processors):

Rust
use carbon_drift_v2_decoder::DriftV2Decoder;
use carbon_jupiter_perpetuals_decoder::JupiterPerpetualsDecoder;
use carbon_zeta_decoder::ZetaDecoder;

Pipeline::builder()
    .datasource(datasource) // a datasource that emits these programs' transactions
    .instruction(DriftV2Decoder, DriftV2Processor)
    .instruction(JupiterPerpetualsDecoder, JupiterPerpetualsProcessor)
    .instruction(ZetaDecoder, ZetaProcessor)
    .build()?
    .run()
    .await

Each decoder only returns instructions whose program ID matches its own PROGRAM_ID, so one pipeline can hold all of them. For datasource filters that follow several programs, and one processor that sees every program's instructions in a transaction, see index multiple programs.

A program that is not listed#

Generate a decoder from the program's Anchor or Codama IDL with the Carbon CLI: see generate a decoder. Every crate above was generated the same way. The full catalog lists decoders in every category.

Generated from the crate’s source at Carbon v2.0.0, so it always matches the published code. Spotted a problem? Report it; edits to this page itself are overwritten on the next release.

Your endpoints

Code samples use these instead of the placeholders, so you can copy and run them as they are. They’re stored only in this browser and never sent anywhere.