Solayer Restaking decoder

Decode Solayer Restaking instructions and accounts in Rust with the carbon-solayer-restaking-program-decoder crate.

On this page

carbon-solayer-restaking-program-decoder decodes the instructions and accounts of the Solayer Restaking program (sSo1iU21jBrU9VaJ8PJib1MtorefUV4fzC9GURa2KNn): 4 instructions, 1 account type. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.

Cratecarbon-solayer-restaking-program-decoder 2.0.0
Installcargo add carbon-solayer-restaking-program-decoder@2.0.0
Program IDsSo1iU21jBrU9VaJ8PJib1MtorefUV4fzC9GURa2KNn (carbon_solayer_restaking_program_decoder::PROGRAM_ID)
CategoryLiquid staking & restaking
Decodercarbon_solayer_restaking_program_decoder::SolayerRestakingProgramDecoder
Instruction enuminstructions::SolayerRestakingProgramInstruction
Account enumaccounts::SolayerRestakingProgramAccount
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-solayer-restaking-program-decoder/2.0.0
Sourcedecoders/solayer-restaking-program-decoder

Other liquid staking and restaking decoders: Marinade Finance. To decode several in one pipeline, see liquid staking and restaking 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 Solayer Restaking transactions from the public RPC and prints every decoded Initialize instruction. Add the dependencies:

Terminal
cargo add carbon-core@2.0.0 carbon-solayer-restaking-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_solayer_restaking_program_decoder::{
        instructions::SolayerRestakingProgramInstruction, SolayerRestakingProgramDecoder,
        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(SolayerRestakingProgramDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

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

Each Initialize instruction prints one line with the transaction signature and the decoded Initialize 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.

Decode accounts#

The transaction crawler emits transactions only. To decode accounts, use a datasource that emits account updates. This program subscribes to the program's accounts with programSubscribe on the public WebSocket endpoint and prints every decoded RestakingPool account as it changes. Add the datasource and the Solana RPC types it takes:

Terminal
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2
src/main.rs
use {
    carbon_core::{
        account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_solayer_restaking_program_decoder::{
        accounts::SolayerRestakingProgramAccount, SolayerRestakingProgramDecoder, PROGRAM_ID,
    },
    carbon_rpc_program_subscribe_datasource::{Filters, RpcProgramSubscribe},
    solana_client::rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig, UiAccountEncoding},
    std::sync::Arc,
};

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

    // Streams every change to an account owned by the program (programSubscribe).
    let config = RpcProgramAccountsConfig {
        account_config: RpcAccountInfoConfig {
            encoding: Some(UiAccountEncoding::Base64),
            ..Default::default()
        },
        ..Default::default()
    };
    let datasource = RpcProgramSubscribe::new(
        "wss://api.mainnet-beta.solana.com".to_string(),
        Filters::new(PROGRAM_ID, Some(config)),
    );

    Pipeline::builder()
        .datasource(datasource)
        .metrics(Arc::new(LogMetrics::new()))
        .account(SolayerRestakingProgramDecoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

impl Processor<AccountProcessorInputType<'_, SolayerRestakingProgramAccount>> for AccountLogger {
    async fn process(
        &mut self,
        input: &AccountProcessorInputType<'_, SolayerRestakingProgramAccount>,
    ) -> CarbonResult<()> {
        let SolayerRestakingProgramAccount::RestakingPool(restaking_pool) = &input.decoded_account.data;
        println!("restaking_pool {}: {restaking_pool:?}", input.metadata.pubkey);
        Ok(())
    }
}
Terminal
RUST_LOG=info cargo run

Each update to a RestakingPool account prints its address and decoded fields; the program runs until you stop it. Cargo resolves solana-client to 4.2.2, the exact version the datasource pins, so both use the same RpcProgramAccountsConfig type. To load every existing account once instead of streaming changes, see load account state.

Instructions#

Variants of SolayerRestakingProgramInstruction. Each is SolayerRestakingProgramInstruction::<Variant> { program_id, data, accounts }, where data and accounts are the types listed under the variant, exported from carbon_solayer_restaking_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 sSo1iU21jBrU9VaJ8PJib1MtorefUV4fzC9GURa2KNn.
  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.

BatchThawLstAccounts#

Discriminator b7ae4d28b686cad5 · data BatchThawLstAccounts · accounts BatchThawLstAccountsInstructionAccounts.

No data fields.

Required accounts: 8; extras go to remaining.

Fields of BatchThawLstAccountsInstructionAccounts, in account order:

#FieldType
0signerPubkey
1solayer_adminPubkey
2lst_mintPubkey
3rst_mintPubkey
4poolPubkey
5associated_token_programPubkey
6token_programPubkey
7system_programPubkey
8…remainingVec<AccountMeta>

Initialize#

Discriminator afaf6d1f0d989bed · data Initialize · accounts InitializeInstructionAccounts.

No data fields.

Required accounts: 9; extras go to remaining.

Fields of InitializeInstructionAccounts, in account order:

#FieldType
0signerPubkey
1solayer_adminPubkey
2lst_mintPubkey
3lst_vaultPubkey
4rst_mintPubkey
5poolPubkey
6associated_token_programPubkey
7token_programPubkey
8system_programPubkey
9…remainingVec<AccountMeta>

Restake#

Discriminator 61a1f1a70620d535 · data Restake · accounts RestakeInstructionAccounts.

FieldType
amountu64

Required accounts: 10; extras go to remaining.

Fields of RestakeInstructionAccounts, in account order:

#FieldType
0signerPubkey
1lst_mintPubkey
2lst_ataPubkey
3rst_ataPubkey
4rst_mintPubkey
5vaultPubkey
6poolPubkey
7associated_token_programPubkey
8token_programPubkey
9system_programPubkey
10…remainingVec<AccountMeta>

Unrestake#

Discriminator 0ab1a1eefa257818 · data Unrestake · accounts UnrestakeInstructionAccounts.

FieldType
amountu64

Required accounts: 10; extras go to remaining.

Fields of UnrestakeInstructionAccounts, in account order:

#FieldType
0signerPubkey
1lst_mintPubkey
2lst_ataPubkey
3rst_ataPubkey
4rst_mintPubkey
5vaultPubkey
6poolPubkey
7associated_token_programPubkey
8token_programPubkey
9system_programPubkey
10…remainingVec<AccountMeta>

Accounts#

Variants of SolayerRestakingProgramAccount. Each wraps a boxed struct from carbon_solayer_restaking_program_decoder::accounts::<module>. decode_account only considers accounts owned by PROGRAM_ID and returns the first variant that matches.

RestakingPool#

Discriminator 0c05648f7d5e1ad6 · accounts::restaking_pool::RestakingPool.

FieldType
lst_mintPubkey
rst_mintPubkey
bumpu8

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.