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.
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.
| Program | Crate | Program ID | Instructions | Accounts | Events |
|---|---|---|---|---|---|
| Drift v2 | carbon-drift-v2-decoder | dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH | 249 | 27 | 26 |
| Jupiter Perpetuals | carbon-jupiter-perpetuals-decoder | PERPHjGBqRHArX4DySjwM6UJHiR3sWAatqfdBS2qQJu | 59 | 8 | 25 |
| Zeta Markets | carbon-zeta-decoder | ZETAxsqBRek56DhiGXrn75yj2NHU3aYUnxvHXpkf3aD | 107 | 23 | 8 |
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:
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.0Register 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):
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()
.awaitEach 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.