Virtuals decoder

Decode Virtuals instructions, accounts and events in Rust with carbon-virtuals-decoder 2.0.0. Program ID 5U3EU2ubXtK84QcRjWVmYt9RaDyA8gKxdUrPFXmZyaki.

On this page

carbon-virtuals-decoder decodes the instructions, accounts and events of the Virtuals program (5U3EU2ubXtK84QcRjWVmYt9RaDyA8gKxdUrPFXmZyaki): 8 instructions, 1 account type, 4 events. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.

Cratecarbon-virtuals-decoder 2.0.0
Installcargo add carbon-virtuals-decoder@2.0.0
Program ID5U3EU2ubXtK84QcRjWVmYt9RaDyA8gKxdUrPFXmZyaki (carbon_virtuals_decoder::PROGRAM_ID)
CategoryLaunchpads
Decodercarbon_virtuals_decoder::VirtualsDecoder
Instruction enuminstructions::VirtualsInstruction
Account enumaccounts::VirtualsAccount
Event enuminstructions::CpiEvent
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-virtuals-decoder/2.0.0
Sourcedecoders/virtuals-decoder

Other launchpad decoders: Boop, Meteora DBC, Moonshot, Pump.fun, Raydium Launchpad, Vertigo, Wavebreak. To decode several in one pipeline, see launchpad 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 Virtuals transactions from the public RPC and prints every decoded Buy instruction. Add the dependencies:

Terminal
cargo add carbon-core@2.0.0 carbon-virtuals-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_virtuals_decoder::{instructions::VirtualsInstruction, VirtualsDecoder, 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(VirtualsDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

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

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

Events published with Anchor's emit_cpi! arrive as the CpiEvent instruction. Match them with VirtualsInstruction::CpiEvent { data: CpiEvent::BuyEvent(event), .. } (import instructions::CpiEvent); see Events. If CpiEvent never arrives, the program logs its events with emit! instead: decode them with decode_log_events.

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 VirtualsPool 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_virtuals_decoder::{accounts::VirtualsAccount, VirtualsDecoder, 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(VirtualsDecoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

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

Each update to a VirtualsPool 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 VirtualsInstruction. Each is VirtualsInstruction::<Variant> { program_id, data, accounts }, where data and accounts are the types listed under the variant, exported from carbon_virtuals_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 5U3EU2ubXtK84QcRjWVmYt9RaDyA8gKxdUrPFXmZyaki.
  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.

Buy#

Discriminator 66063d1201daebea · data Buy · accounts BuyInstructionAccounts.

FieldType
amountu64
max_amount_outu64

Required accounts: 10; extras go to remaining.

Fields of BuyInstructionAccounts, in account order:

#FieldType
0userPubkey
1vpoolPubkey
2token_mintPubkey
3user_virtuals_ataPubkey
4user_token_ataPubkey
5vpool_token_ataPubkey
6platform_prototypePubkey
7platform_prototype_virtuals_ataPubkey
8vpool_virtuals_ataPubkey
9token_programPubkey
10…remainingVec<AccountMeta>

ClaimFees#

Discriminator 52fbe99c0c34b8ca · data ClaimFees · accounts ClaimFeesInstructionAccounts.

No data fields.

Required accounts: 28; extras go to remaining.

Fields of ClaimFeesInstructionAccounts, in account order:

#FieldType
0payerPubkey
1vpoolPubkey
2virtuals_mintPubkey
3token_mintPubkey
4vpool_virtuals_ataPubkey
5vpool_token_ataPubkey
6platformPubkey
7platform_virtuals_ataPubkey
8platform_token_ataPubkey
9creator_virtuals_ataPubkey
10creator_token_ataPubkey
11poolPubkey
12lp_mintPubkey
13lock_escrowPubkey
14escrow_vaultPubkey
15token_programPubkey
16virtuals_vaultPubkey
17token_vaultPubkey
18virtuals_token_vaultPubkey
19token_token_vaultPubkey
20virtuals_vault_lp_mintPubkey
21token_vault_lp_mintPubkey
22virtuals_vault_lpPubkey
23token_vault_lpPubkey
24vault_programPubkey
25associated_token_programPubkey
26system_programPubkey
27dynamic_amm_programPubkey
28…remainingVec<AccountMeta>

CreateMeteoraPool#

Discriminator f6fe2125e1b029e8 · data CreateMeteoraPool · accounts CreateMeteoraPoolInstructionAccounts.

No data fields.

Required accounts: 36; extras go to remaining.

Fields of CreateMeteoraPoolInstructionAccounts, in account order:

#FieldType
0vpoolPubkey
1meteora_deployerPubkey
2meteora_deployer_virtuals_ataPubkey
3meteora_deployer_token_ataPubkey
4vpool_virtuals_ataPubkey
5vpool_token_ataPubkey
6lock_escrowPubkey
7escrow_vaultPubkey
8poolPubkey
9configPubkey
10lp_mintPubkey
11virtuals_mintPubkey
12token_mintPubkey
13virtuals_vaultPubkey
14token_vaultPubkey
15virtuals_token_vaultPubkey
16token_token_vaultPubkey
17virtuals_vault_lp_mintPubkey
18token_vault_lp_mintPubkey
19virtuals_vault_lpPubkey
20token_vault_lpPubkey
21pool_virtuals_ataPubkey
22pool_token_ataPubkey
23meteora_deployer_pool_lpPubkey
24protocol_virtuals_feePubkey
25protocol_token_feePubkey
26payerPubkey
27token_metadataPubkey
28rentPubkey
29mint_metadataPubkey
30metadata_programPubkey
31vault_programPubkey
32token_programPubkey
33associated_token_programPubkey
34system_programPubkey
35dynamic_amm_programPubkey
36…remainingVec<AccountMeta>

Initialize#

From the program's IDL:

Initialize Pool

This is where Virtuals creates a new mint address and pool and mints the initial 1,000,000,000 tokens. This enabels Virtuals to premine addresses and
\ sell\ them to customers without any delays of mining the address. While this instruction could be permissioned, it is currently permissionless. As such, we make sure to handle all the necessary checks such as: address suffix, zero supply, 6 decimals, correct mint authority.

Discriminator afaf6d1f0d989bed · data Initialize · accounts InitializeInstructionAccounts.

No data fields.

Required accounts: 9; extras go to remaining.

Fields of InitializeInstructionAccounts, in account order:

#FieldType
0payerPubkey
1virtuals_mintPubkey
2token_mintPubkey
3vpool_virtuals_ataPubkey
4vpool_token_ataPubkey
5vpoolPubkey
6token_programPubkey
7associated_token_programPubkey
8system_programPubkey
9…remainingVec<AccountMeta>

InitializeMeteoraAccounts#

Discriminator 350c769efdefb9d6 · data InitializeMeteoraAccounts · accounts InitializeMeteoraAccountsInstructionAccounts.

No data fields.

Required accounts: 36; extras go to remaining.

Fields of InitializeMeteoraAccountsInstructionAccounts, in account order:

#FieldType
0vpoolPubkey
1meteora_deployerPubkey
2meteora_deployer_virtuals_ataPubkey
3meteora_deployer_token_ataPubkey
4vpool_virtuals_ataPubkey
5vpool_token_ataPubkey
6lock_escrowPubkey
7escrow_vaultPubkey
8poolPubkey
9configPubkey
10lp_mintPubkey
11virtuals_mintPubkey
12token_mintPubkey
13virtuals_vaultPubkey
14token_vaultPubkey
15virtuals_token_vaultPubkey
16token_token_vaultPubkey
17virtuals_vault_lp_mintPubkey
18token_vault_lp_mintPubkey
19virtuals_vault_lpPubkey
20token_vault_lpPubkey
21pool_virtuals_ataPubkey
22pool_token_ataPubkey
23meteora_deployer_pool_lpPubkey
24protocol_virtuals_feePubkey
25protocol_token_feePubkey
26payerPubkey
27token_metadataPubkey
28rentPubkey
29mint_metadataPubkey
30metadata_programPubkey
31vault_programPubkey
32token_programPubkey
33associated_token_programPubkey
34system_programPubkey
35dynamic_amm_programPubkey
36…remainingVec<AccountMeta>

Launch#

From the program's IDL:

This is where a user comes along and purchases a mint address and pool. The user will provide a name, symbol and URI containing offchain metadata. The contract will initialize a new onchain metadata account containing these values, then revoke the mint authority.

Discriminator 99f15de116454a3d · data Launch · accounts LaunchInstructionAccounts.

FieldType
symbolString
nameString
uriString

Required accounts: 12; extras go to remaining.

Fields of LaunchInstructionAccounts, in account order:

#FieldType
0creatorPubkey
1creator_virtuals_ataPubkey
2token_mintPubkey
3platform_prototypePubkey
4platform_prototype_virtuals_ataPubkey
5vpoolPubkey
6token_metadataPubkey
7metadata_programPubkey
8token_programPubkey
9associated_token_programPubkey
10system_programPubkey
11rentPubkey
12…remainingVec<AccountMeta>

Sell#

Discriminator 33e685a4017f83ad · data Sell · accounts SellInstructionAccounts.

FieldType
amountu64
min_amount_outu64

Required accounts: 10; extras go to remaining.

Fields of SellInstructionAccounts, in account order:

#FieldType
0userPubkey
1vpoolPubkey
2token_mintPubkey
3user_virtuals_ataPubkey
4user_token_ataPubkey
5vpool_token_ataPubkey
6platform_prototypePubkey
7platform_prototype_virtuals_ataPubkey
8vpool_virtuals_ataPubkey
9token_programPubkey
10…remainingVec<AccountMeta>

UpdatePoolCreator#

Discriminator 71e1a6b95ee7601c · data UpdatePoolCreator · accounts UpdatePoolCreatorInstructionAccounts.

No data fields.

Required accounts: 10; extras go to remaining.

Fields of UpdatePoolCreatorInstructionAccounts, in account order:

#FieldType
0creatorPubkey
1new_creatorPubkey
2virtuals_mintPubkey
3token_mintPubkey
4new_creator_virtuals_ataPubkey
5new_creator_token_ataPubkey
6vpoolPubkey
7token_programPubkey
8associated_token_programPubkey
9system_programPubkey
10…remainingVec<AccountMeta>

CpiEvent#

Anchor self-CPI that carries one of the program's events. data is the CpiEvent enum.

Discriminator e445a52e51cb9a1d · data CpiEvent · accounts CpiEventInstructionAccounts.

Required accounts: 2; extras go to remaining.

Fields of CpiEventInstructionAccounts, in account order:

#FieldType
0programPubkey
1event_authorityPubkey
2…remainingVec<AccountMeta>

Accounts#

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

VirtualsPool#

Discriminator 477605cb05628774 · accounts::virtuals_pool::VirtualsPool.

FieldType
creatorPubkey
mintPubkey
virtual_yu64
graduation_xu64
statePoolState
bumpu8

Events#

Variants of instructions::CpiEvent, decoded from the CpiEvent instruction. Each wraps a struct from carbon_virtuals_decoder::events::<module>. The discriminator is the 8-byte event discriminator that follows the e445a52e51cb9a1d CPI-event tag.

BuyEvent#

Discriminator 67f4521f2cf57777 · events::buy_event::BuyEventEvent.

FieldType
buy_amountu64
virtuals_amountu64

GraduationEvent#

Discriminator 0af6df7f30629537 · events::graduation_event::GraduationEventEvent.

FieldType
vpoolPubkey
mintPubkey
balanceu64

LaunchEvent#

Discriminator 1bc12f82735cef5e · events::launch_event::LaunchEventEvent.

FieldType
vpoolPubkey
mintPubkey
creatorPubkey

SellEvent#

Discriminator 3e2f370aa503dc2a · events::sell_event::SellEventEvent.

FieldType
sell_amountu64
virtuals_amountu64

Types#

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

BuyEvent#

Struct types::BuyEvent. Same fields as the BuyEvent event.

GraduationEvent#

Struct types::GraduationEvent. Same fields as the GraduationEvent event.

LaunchEvent#

Struct types::LaunchEvent. Same fields as the LaunchEvent event.

PoolState#

Enum types::PoolState.

Variant
Initialized
Active
Graduated
Migrated

SellEvent#

Struct types::SellEvent. Same fields as the SellEvent event.

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.