Stabble Weighted Swap decoder

Decode Stabble Weighted Swap instructions, accounts and events in Rust with the carbon-stabble-weighted-swap-decoder crate.

On this page

carbon-stabble-weighted-swap-decoder decodes the instructions, accounts and events of the Stabble Weighted Swap program (swapFpHZwjELNnjvThjajtiVmkz3yPQEHjLtka2fwHW): 13 instructions, 2 account types, 2 events. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.

Cratecarbon-stabble-weighted-swap-decoder 2.0.0
Installcargo add carbon-stabble-weighted-swap-decoder@2.0.0
Program IDswapFpHZwjELNnjvThjajtiVmkz3yPQEHjLtka2fwHW (carbon_stabble_weighted_swap_decoder::PROGRAM_ID)
CategoryDEX & AMM
Decodercarbon_stabble_weighted_swap_decoder::StabbleWeightedSwapDecoder
Instruction enuminstructions::StabbleWeightedSwapInstruction
Account enumaccounts::StabbleWeightedSwapAccount
Event enuminstructions::CpiEvent
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-stabble-weighted-swap-decoder/2.0.0
Sourcedecoders/stabble-weighted-swap-decoder

Other DEX and AMM decoders: BonkSwap, FluxBeam, Gavel, Heaven, Jupiter Limit Order, Jupiter Limit Order v2, Kamino Limit Order, Lifinity AMM v2, Meteora DAMM v2, Meteora DLMM, Meteora Pools, OpenBook v2, Orca Whirlpools, PancakeSwap, Phoenix v1, PumpSwap, Raydium AMM v4, Raydium CLMM, Raydium CPMM, Raydium Stable Swap, Stabble Stable Swap. To decode several in one pipeline, see dEX and AMM 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 Stabble Weighted Swap transactions from the public RPC and prints every decoded Swap instruction. Add the dependencies:

Terminal
cargo add carbon-core@2.0.0 carbon-stabble-weighted-swap-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_stabble_weighted_swap_decoder::{
        instructions::StabbleWeightedSwapInstruction, StabbleWeightedSwapDecoder, 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(StabbleWeightedSwapDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

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

Each Swap instruction prints one line with the transaction signature and the decoded Swap 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 StabbleWeightedSwapInstruction::CpiEvent { data: CpiEvent::PoolBalanceUpdatedEvent(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 Pool 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_stabble_weighted_swap_decoder::{
        accounts::StabbleWeightedSwapAccount, StabbleWeightedSwapDecoder, 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(StabbleWeightedSwapDecoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

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

Each update to a Pool 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 StabbleWeightedSwapInstruction. Each is StabbleWeightedSwapInstruction::<Variant> { program_id, data, accounts }, where data and accounts are the types listed under the variant, exported from carbon_stabble_weighted_swap_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 swapFpHZwjELNnjvThjajtiVmkz3yPQEHjLtka2fwHW.
  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.

AcceptOwner#

Discriminator b017291c176f0804 · data AcceptOwner · accounts AcceptOwnerInstructionAccounts.

No data fields.

Required accounts: 2; extras go to remaining.

Fields of AcceptOwnerInstructionAccounts, in account order:

#FieldType
0pending_ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

ChangeMaxSupply#

Discriminator 5db000cd453f5750 · data ChangeMaxSupply · accounts ChangeMaxSupplyInstructionAccounts.

FieldType
new_max_supplyu64

Required accounts: 2; extras go to remaining.

Fields of ChangeMaxSupplyInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

ChangeSwapFee#

Discriminator e70f843384a540aa · data ChangeSwapFee · accounts ChangeSwapFeeInstructionAccounts.

FieldType
new_swap_feeu64

Required accounts: 2; extras go to remaining.

Fields of ChangeSwapFeeInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

Deposit#

From the program's IDL:

add liquidity

Discriminator f223c68952e1f2b6 · data Deposit · accounts DepositInstructionAccounts.

FieldType
amountsVec<u64>
minimum_amount_outu64

Required accounts: 9; extras go to remaining.

Fields of DepositInstructionAccounts, in account order:

#FieldType
0userPubkey
1user_pool_tokenPubkey
2mintPubkey
3poolPubkey
4pool_authorityPubkey
5vaultPubkey
6vault_authorityPubkey
7token_programPubkey
8token_program2022Pubkey
9…remainingVec<AccountMeta>

Initialize#

From the program's IDL:

initialize a pool

Discriminator afaf6d1f0d989bed · data Initialize · accounts InitializeInstructionAccounts.

FieldType
swap_feeu64
weightsVec<u64>
max_capsVec<u64>

Required accounts: 6; extras go to remaining.

Fields of InitializeInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1mintPubkey
2poolPubkey
3pool_authorityPubkey
4withdraw_authorityPubkey
5vaultPubkey
6…remainingVec<AccountMeta>

Pause#

Discriminator d316ddfb4a79c12f · data Pause · accounts PauseInstructionAccounts.

No data fields.

Required accounts: 2; extras go to remaining.

Fields of PauseInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

RejectOwner#

Discriminator eecec6d733b285e4 · data RejectOwner · accounts RejectOwnerInstructionAccounts.

No data fields.

Required accounts: 2; extras go to remaining.

Fields of RejectOwnerInstructionAccounts, in account order:

#FieldType
0pending_ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

Shutdown#

From the program's IDL:

shutdown the zero-liquidity pool

Discriminator 92ccf1d55615fdd3 · data Shutdown · accounts ShutdownInstructionAccounts.

No data fields.

Required accounts: 2; extras go to remaining.

Fields of ShutdownInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

Swap#

From the program's IDL:

swap

Discriminator f8c69e91e17587c8 · data Swap · accounts SwapInstructionAccounts.

FieldType
amount_inOption<u64>
minimum_amount_outu64

Required accounts: 12; extras go to remaining.

Fields of SwapInstructionAccounts, in account order:

#FieldType
0userPubkey
1user_token_inPubkey
2user_token_outPubkey
3vault_token_inPubkey
4vault_token_outPubkey
5beneficiary_token_outPubkey
6poolPubkey
7withdraw_authorityPubkey
8vaultPubkey
9vault_authorityPubkey
10vault_programPubkey
11token_programPubkey
12…remainingVec<AccountMeta>

SwapV2#

Discriminator 2b04ed0b1ac91e62 · data SwapV2 · accounts SwapV2InstructionAccounts.

FieldType
amount_inOption<u64>
minimum_amount_outu64

Required accounts: 15; extras go to remaining.

Fields of SwapV2InstructionAccounts, in account order:

#FieldType
0userPubkey
1mint_inPubkey
2mint_outPubkey
3user_token_inPubkey
4user_token_outPubkey
5vault_token_inPubkey
6vault_token_outPubkey
7beneficiary_token_outPubkey
8poolPubkey
9withdraw_authorityPubkey
10vaultPubkey
11vault_authorityPubkey
12vault_programPubkey
13token_programPubkey
14token2022_programPubkey
15…remainingVec<AccountMeta>

TransferOwner#

Discriminator f519ddaf6ae5e12d · data TransferOwner · accounts TransferOwnerInstructionAccounts.

FieldType
new_ownerPubkey

Required accounts: 2; extras go to remaining.

Fields of TransferOwnerInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

Unpause#

Discriminator a99004260a8dbcff · data Unpause · accounts UnpauseInstructionAccounts.

No data fields.

Required accounts: 2; extras go to remaining.

Fields of UnpauseInstructionAccounts, in account order:

#FieldType
0ownerPubkey
1poolPubkey
2…remainingVec<AccountMeta>

Withdraw#

From the program's IDL:

remove liquidity

Discriminator b712469c946da122 · data Withdraw · accounts WithdrawInstructionAccounts.

FieldType
amountu64
minimum_amounts_outVec<u64>

Required accounts: 10; extras go to remaining.

Fields of WithdrawInstructionAccounts, in account order:

#FieldType
0userPubkey
1user_pool_tokenPubkey
2mintPubkey
3poolPubkey
4withdraw_authorityPubkey
5vaultPubkey
6vault_authorityPubkey
7vault_programPubkey
8token_programPubkey
9token_program2022Pubkey
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 StabbleWeightedSwapAccount. Each wraps a boxed struct from carbon_stabble_weighted_swap_decoder::accounts::<module>. decode_account only considers accounts owned by PROGRAM_ID and returns the first variant that matches.

Pool#

Discriminator f19a6d0411b16dbc · accounts::pool::Pool.

FieldType
ownerPubkey
vaultPubkey
mintPubkey
authority_bumpu8
is_activebool
invariantu64
swap_feeu64
tokensVec<PoolToken>
pending_ownerOption<Pubkey>
max_supplyu64

Vault#

Discriminator d308e82b02987577 · accounts::vault::Vault.

FieldTypeDescription
adminPubkey
withdraw_authorityPubkeyPDA of pool programs seeded by vault address
withdraw_authority_bumpu8bump seed of withdraw_authority PDA
authority_bumpu8bump seed of vault_authority PDA
is_activebool
beneficiaryPubkey
beneficiary_feeu64
pending_adminOption<Pubkey>

Events#

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

PoolBalanceUpdatedEvent#

Discriminator ac5272cf1b67d304 · events::pool_balance_updated_event::PoolBalanceUpdatedEventEvent.

FieldType
pubkeyPubkey
dataPoolBalanceUpdatedData

PoolUpdatedEvent#

Discriminator 80275edde6de7f8d · events::pool_updated_event::PoolUpdatedEventEvent.

FieldType
pubkeyPubkey
dataPoolUpdatedData

Types#

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

PoolBalanceUpdatedData#

Struct types::PoolBalanceUpdatedData.

FieldType
balancesVec<u64>

PoolBalanceUpdatedEvent#

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

PoolToken#

Struct types::PoolToken.

FieldType
mintPubkey
decimalsu8
scaling_upbool
scaling_factoru64
balanceu64
weightu64

PoolUpdatedData#

Struct types::PoolUpdatedData.

FieldType
is_activebool
swap_feeu64
max_supplyu64

PoolUpdatedEvent#

Struct types::PoolUpdatedEvent. Same fields as the PoolUpdatedEvent 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.