Stake Program decoder

Decode Stake Program instructions in Rust with carbon-stake-program-decoder 2.0.0. Program ID Stake11111111111111111111111111111111111111.

On this page

carbon-stake-program-decoder decodes the instructions of the Stake Program program (Stake11111111111111111111111111111111111111): 18 instructions. It decodes no accounts: StakeProgramAccount has no variants. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.

Cratecarbon-stake-program-decoder 2.0.0
Installcargo add carbon-stake-program-decoder@2.0.0
Program IDStake11111111111111111111111111111111111111 (carbon_stake_program_decoder::PROGRAM_ID)
CategoryCore & SPL
Decodercarbon_stake_program_decoder::StakeProgramDecoder
Instruction enuminstructions::StakeProgramInstruction
Account enumaccounts::StakeProgramAccount (no variants)
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-stake-program-decoder/2.0.0
Sourcedecoders/stake-program-decoder

Other core and SPL decoders: Address Lookup Table, Associated Token Account, SPL Memo, SPL Name Service, SPL Token, System Program, Token-2022. To decode several in one pipeline, see core and SPL program decoders.

The serde feature derives Serialize/Deserialize on every type, postgres adds tables and processors for Postgres, and graphql adds a schema for the GraphQL server.

Usage#

This program crawls recent Stake Program transactions from the public RPC and prints every decoded DelegateStake instruction. Add the dependencies:

Terminal
cargo add carbon-core@2.0.0 carbon-stake-program-decoder@2.0.0 carbon-rpc-transaction-crawler-datasource@2.0.0 carbon-log-metrics@2.0.0 env_logger tokio --features tokio/full
src/main.rs
use {
    carbon_core::{
        error::CarbonResult, instruction::InstructionProcessorInputType, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_stake_program_decoder::{
        instructions::StakeProgramInstruction, StakeProgramDecoder, PROGRAM_ID,
    },
    carbon_rpc_transaction_crawler_datasource::{ConnectionConfig, Filters, RpcTransactionCrawler},
    std::sync::Arc,
};

#[tokio::main]
async fn main() -> CarbonResult<()> {
    env_logger::init();

    // Fetches the program's recent transactions over JSON-RPC, newest first.
    let datasource = RpcTransactionCrawler::new(
        "https://api.mainnet-beta.solana.com".to_string(),
        PROGRAM_ID,
        ConnectionConfig::default(),
        Filters::new(None, None, None),
        None,
    );

    Pipeline::builder()
        .datasource(datasource)
        .metrics(Arc::new(LogMetrics::new()))
        .instruction(StakeProgramDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

impl Processor<InstructionProcessorInputType<'_, StakeProgramInstruction>> for InstructionLogger {
    async fn process(
        &mut self,
        input: &InstructionProcessorInputType<'_, StakeProgramInstruction>,
    ) -> CarbonResult<()> {
        let signature = input.metadata.transaction_metadata.signature;
        if let StakeProgramInstruction::DelegateStake { data, accounts, .. } = input.decoded_instruction {
            println!("delegate_stake {signature}: {data:?} stake={}", accounts.stake);
        }
        Ok(())
    }
}
Terminal
RUST_LOG=info cargo run

Each DelegateStake instruction prints one line with the transaction signature and the decoded DelegateStake data. The public endpoint rate-limits requests, so the first lines can take a while; use your own RPC URL for anything beyond a test. See stream with RPC for the crawler options.

Instructions#

Variants of StakeProgramInstruction. Each is StakeProgramInstruction::<Variant> { program_id, data, accounts }, where data and accounts are the types listed under the variant, exported from carbon_stake_program_decoder::instructions. Discriminators are the leading bytes of the instruction data, in hex.

How an instruction decodes. The decoder returns a variant only when all of these hold; otherwise the instruction is skipped and no processor is called:

  1. The instruction's program ID is Stake11111111111111111111111111111111111111.
  2. The data starts with the variant's discriminator, and the rest deserializes into its data type.
  3. The instruction has at least as many accounts as the variant requires (the "Required accounts" count under each variant).

Accounts. They are matched by position, in the order listed. An account marked optional is None only when the instruction ends before it; Anchor programs pass the program ID as a placeholder for an omitted optional account, so check for Some(PROGRAM_ID) too. Accounts after the listed ones are in accounts.remaining as AccountMetas. The decoder doesn't record whether an account signed or was writable: read that from input.raw_instruction.accounts[i].is_signer and .is_writable, which follow the same order. It doesn't check signer, writable, owner or PDA constraints either; the program enforced those when the transaction executed, so a decoded instruction from a successful transaction already satisfied them.

Authorize#

Discriminator 01 · data Authorize · accounts AuthorizeInstructionAccounts.

FieldType
arg0Pubkey
arg1StakeAuthorize

Required accounts: 3 (4 listed); extras go to remaining.

Fields of AuthorizeInstructionAccounts, in account order:

#FieldType
0stakePubkey
1clock_sysvarPubkey
2authorityPubkey
3lockup_authorityOption<Pubkey>
4…remainingVec<AccountMeta>

AuthorizeChecked#

Discriminator 0a · data AuthorizeChecked · accounts AuthorizeCheckedInstructionAccounts.

FieldType
stake_authorizeStakeAuthorize

Required accounts: 4 (5 listed); extras go to remaining.

Fields of AuthorizeCheckedInstructionAccounts, in account order:

#FieldType
0stakePubkey
1clock_sysvarPubkey
2authorityPubkey
3new_authorityPubkey
4lockup_authorityOption<Pubkey>
5…remainingVec<AccountMeta>

AuthorizeCheckedWithSeed#

Discriminator 0b · data AuthorizeCheckedWithSeed · accounts AuthorizeCheckedWithSeedInstructionAccounts.

Required accounts: 4 (5 listed); extras go to remaining.

Fields of AuthorizeCheckedWithSeedInstructionAccounts, in account order:

#FieldType
0stakePubkey
1basePubkey
2clock_sysvarPubkey
3new_authorityPubkey
4lockup_authorityOption<Pubkey>
5…remainingVec<AccountMeta>

AuthorizeWithSeed#

Discriminator 08 · data AuthorizeWithSeed · accounts AuthorizeWithSeedInstructionAccounts.

Required accounts: 3 (4 listed); extras go to remaining.

Fields of AuthorizeWithSeedInstructionAccounts, in account order:

#FieldType
0stakePubkey
1basePubkey
2clock_sysvarPubkey
3lockup_authorityOption<Pubkey>
4…remainingVec<AccountMeta>

Deactivate#

Discriminator 05 · data Deactivate · accounts DeactivateInstructionAccounts.

No data fields.

Required accounts: 3; extras go to remaining.

Fields of DeactivateInstructionAccounts, in account order:

#FieldType
0stakePubkey
1clock_sysvarPubkey
2stake_authorityPubkey
3…remainingVec<AccountMeta>

DeactivateDelinquent#

Discriminator 0e · data DeactivateDelinquent · accounts DeactivateDelinquentInstructionAccounts.

No data fields.

Required accounts: 3; extras go to remaining.

Fields of DeactivateDelinquentInstructionAccounts, in account order:

#FieldType
0stakePubkey
1delinquent_votePubkey
2reference_votePubkey
3…remainingVec<AccountMeta>

DelegateStake#

Discriminator 02 · data DelegateStake · accounts DelegateStakeInstructionAccounts.

No data fields.

Required accounts: 6; extras go to remaining.

Fields of DelegateStakeInstructionAccounts, in account order:

#FieldType
0stakePubkey
1votePubkey
2clock_sysvarPubkey
3stake_historyPubkey
4unusedPubkey
5stake_authorityPubkey
6…remainingVec<AccountMeta>

GetMinimumDelegation#

Discriminator 0d · data GetMinimumDelegation · accounts GetMinimumDelegationInstructionAccounts.

No data fields.

No named accounts.

Initialize#

Discriminator 00 · data Initialize · accounts InitializeInstructionAccounts.

FieldType
arg0Authorized
arg1Lockup

Required accounts: 2; extras go to remaining.

Fields of InitializeInstructionAccounts, in account order:

#FieldType
0stakePubkey
1rent_sysvarPubkey
2…remainingVec<AccountMeta>

InitializeChecked#

Discriminator 09 · data InitializeChecked · accounts InitializeCheckedInstructionAccounts.

No data fields.

Required accounts: 4; extras go to remaining.

Fields of InitializeCheckedInstructionAccounts, in account order:

#FieldType
0stakePubkey
1rent_sysvarPubkey
2stake_authorityPubkey
3withdraw_authorityPubkey
4…remainingVec<AccountMeta>

Merge#

Discriminator 07 · data Merge · accounts MergeInstructionAccounts.

No data fields.

Required accounts: 5; extras go to remaining.

Fields of MergeInstructionAccounts, in account order:

#FieldType
0destination_stakePubkey
1source_stakePubkey
2clock_sysvarPubkey
3stake_historyPubkey
4stake_authorityPubkey
5…remainingVec<AccountMeta>

MoveLamports#

Discriminator 11 · data MoveLamports · accounts MoveLamportsInstructionAccounts.

FieldType
argsu64

Required accounts: 3; extras go to remaining.

Fields of MoveLamportsInstructionAccounts, in account order:

#FieldType
0source_stakePubkey
1destination_stakePubkey
2stake_authorityPubkey
3…remainingVec<AccountMeta>

MoveStake#

Discriminator 10 · data MoveStake · accounts MoveStakeInstructionAccounts.

FieldType
argsu64

Required accounts: 3; extras go to remaining.

Fields of MoveStakeInstructionAccounts, in account order:

#FieldType
0source_stakePubkey
1destination_stakePubkey
2stake_authorityPubkey
3…remainingVec<AccountMeta>

Redelegate#

Discriminator 0f · data Redelegate · accounts RedelegateInstructionAccounts.

No data fields.

No named accounts.

SetLockup#

Discriminator 06 · data SetLockup · accounts SetLockupInstructionAccounts.

FieldType
arg0LockupParams

Required accounts: 2; extras go to remaining.

Fields of SetLockupInstructionAccounts, in account order:

#FieldType
0stakePubkey
1authorityPubkey
2…remainingVec<AccountMeta>

SetLockupChecked#

Discriminator 0c · data SetLockupChecked · accounts SetLockupCheckedInstructionAccounts.

FieldType
arg0LockupCheckedParams

Required accounts: 2 (3 listed); extras go to remaining.

Fields of SetLockupCheckedInstructionAccounts, in account order:

#FieldType
0stakePubkey
1authorityPubkey
2new_authorityOption<Pubkey>
3…remainingVec<AccountMeta>

Split#

Discriminator 03 · data Split · accounts SplitInstructionAccounts.

FieldType
argsu64

Required accounts: 3; extras go to remaining.

Fields of SplitInstructionAccounts, in account order:

#FieldType
0stakePubkey
1split_stakePubkey
2stake_authorityPubkey
3…remainingVec<AccountMeta>

Withdraw#

Discriminator 04 · data Withdraw · accounts WithdrawInstructionAccounts.

FieldType
argsu64

Required accounts: 5 (6 listed); extras go to remaining.

Fields of WithdrawInstructionAccounts, in account order:

#FieldType
0stakePubkey
1recipientPubkey
2clock_sysvarPubkey
3stake_historyPubkey
4withdraw_authorityPubkey
5lockup_authorityOption<Pubkey>
6…remainingVec<AccountMeta>

Types#

Types used by the instructions, accounts and events above, exported from carbon_stake_program_decoder::types.

AuthorizeCheckedWithSeedParams#

Struct types::AuthorizeCheckedWithSeedParams.

FieldType
stake_authorizeStakeAuthorize
authority_seedString
authority_ownerPubkey

Authorized#

Struct types::Authorized.

FieldType
stakerPubkey
withdrawerPubkey

AuthorizeWithSeedParams#

Struct types::AuthorizeWithSeedParams.

FieldType
new_authorized_pubkeyPubkey
stake_authorizeStakeAuthorize
authority_seedString
authority_ownerPubkey

Delegation#

Struct types::Delegation.

FieldType
voter_pubkeyPubkey
stakeu64
activation_epochEpoch
deactivation_epochEpoch
warmup_cooldown_ratef64

Epoch#

Alias types::Epoch = u64.

Lockup#

Struct types::Lockup.

FieldType
unix_timestampUnixTimestamp
epochEpoch
custodianPubkey

LockupCheckedParams#

Struct types::LockupCheckedParams.

FieldType
unix_timestampOption<UnixTimestamp>
epochOption<Epoch>

LockupParams#

Struct types::LockupParams.

FieldType
unix_timestampOption<UnixTimestamp>
epochOption<Epoch>
custodianOption<Pubkey>

Meta#

Struct types::Meta.

FieldType
rent_exempt_reserveu64
authorizedAuthorized
lockupLockup

Stake#

Struct types::Stake.

FieldType
delegationDelegation
credits_observedu64

StakeAuthorize#

Enum types::StakeAuthorize.

Variant
Staker
Withdrawer

StakeFlags#

Struct types::StakeFlags.

FieldType
bitsu8

StakeState#

Enum types::StakeState.

VariantFields
Uninitialized
InitializedMeta
StakeMeta, Stake
RewardsPool

StakeStateV2#

Enum types::StakeStateV2.

VariantFields
Uninitialized
InitializedMeta
StakeMeta, Stake, StakeFlags
RewardsPool

UnixTimestamp#

Alias types::UnixTimestamp = i64.

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.