Kamino Limit Order decoder

Decode Kamino Limit Order instructions, accounts and events in Rust with the carbon-kamino-limit-order-decoder crate.

On this page

carbon-kamino-limit-order-decoder decodes the instructions, accounts and events of the Kamino Limit Order program (LiMoM9rMhrdYrfzUCxQppvxCSG1FcrUK9G8uLq4A1GF): 15 instructions, 3 account types, 2 events. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.

Cratecarbon-kamino-limit-order-decoder 2.0.0
Installcargo add carbon-kamino-limit-order-decoder@2.0.0
Program IDLiMoM9rMhrdYrfzUCxQppvxCSG1FcrUK9G8uLq4A1GF (carbon_kamino_limit_order_decoder::PROGRAM_ID)
CategoryDEX & AMM
Decodercarbon_kamino_limit_order_decoder::KaminoLimitOrderDecoder
Instruction enuminstructions::KaminoLimitOrderInstruction
Account enumaccounts::KaminoLimitOrderAccount
Event enuminstructions::CpiEvent
Featuresserde, postgres, graphql (none enabled by default)
API docsdocs.rs/carbon-kamino-limit-order-decoder/2.0.0
Sourcedecoders/kamino-limit-order-decoder

Other DEX and AMM decoders: BonkSwap, FluxBeam, Gavel, Heaven, Jupiter Limit Order, Jupiter Limit Order v2, 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, Stabble Weighted 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 Kamino Limit Order transactions from the public RPC and prints every decoded AssertUserSwapBalancesEnd instruction. Add the dependencies:

Terminal
cargo add carbon-core@2.0.0 carbon-kamino-limit-order-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_kamino_limit_order_decoder::{
        instructions::KaminoLimitOrderInstruction, KaminoLimitOrderDecoder, 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(KaminoLimitOrderDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

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

Each AssertUserSwapBalancesEnd instruction prints one line with the transaction signature and the decoded AssertUserSwapBalancesEnd 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 KaminoLimitOrderInstruction::CpiEvent { data: CpiEvent::OrderDisplay(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 GlobalConfig 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_kamino_limit_order_decoder::{
        accounts::KaminoLimitOrderAccount, KaminoLimitOrderDecoder, 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(KaminoLimitOrderDecoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

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

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

AssertUserSwapBalancesEnd#

Discriminator a39dae5d1c7ffa88 · data AssertUserSwapBalancesEnd · accounts AssertUserSwapBalancesEndInstructionAccounts.

FieldType
max_input_amount_changeu64
min_output_amount_changeu64

Required accounts: 7; extras go to remaining.

Fields of AssertUserSwapBalancesEndInstructionAccounts, in account order:

#FieldType
0makerPubkey
1input_taPubkey
2output_taPubkey
3user_swap_balance_statePubkey
4system_programPubkey
5rentPubkey
6sysvar_instructionsPubkey
7…remainingVec<AccountMeta>

AssertUserSwapBalancesStart#

Discriminator 5ff1e2c1d6af8e8b · data AssertUserSwapBalancesStart · accounts AssertUserSwapBalancesStartInstructionAccounts.

No data fields.

Required accounts: 7; extras go to remaining.

Fields of AssertUserSwapBalancesStartInstructionAccounts, in account order:

#FieldType
0makerPubkey
1input_taPubkey
2output_taPubkey
3user_swap_balance_statePubkey
4system_programPubkey
5rentPubkey
6sysvar_instructionsPubkey
7…remainingVec<AccountMeta>

CloseOrderAndClaimTip#

Discriminator f41b0ce22df7e62b · data CloseOrderAndClaimTip · accounts CloseOrderAndClaimTipInstructionAccounts.

No data fields.

Required accounts: 12; extras go to remaining.

Fields of CloseOrderAndClaimTipInstructionAccounts, in account order:

#FieldType
0makerPubkey
1orderPubkey
2global_configPubkey
3pda_authorityPubkey
4input_mintPubkey
5output_mintPubkey
6maker_input_ataPubkey
7input_vaultPubkey
8input_token_programPubkey
9system_programPubkey
10event_authorityPubkey
11programPubkey
12…remainingVec<AccountMeta>

CreateOrder#

Discriminator 8d3625cfedd2fad7 · data CreateOrder · accounts CreateOrderInstructionAccounts.

FieldType
input_amountu64
output_amountu64
order_typeu8

Required accounts: 13; extras go to remaining.

Fields of CreateOrderInstructionAccounts, in account order:

#FieldType
0makerPubkey
1global_configPubkey
2pda_authorityPubkey
3orderPubkey
4input_mintPubkey
5output_mintPubkey
6maker_ataPubkey
7input_vaultPubkey
8input_token_programPubkey
9output_token_programPubkey
10system_programPubkey
11event_authorityPubkey
12programPubkey
13…remainingVec<AccountMeta>

FlashTakeOrderEnd#

Discriminator cef2d7bb8621e094 · data FlashTakeOrderEnd · accounts FlashTakeOrderEndInstructionAccounts.

FieldType
input_amountu64
min_output_amountu64
tip_amount_permissionless_takingu64

Required accounts: 23; extras go to remaining.

Fields of FlashTakeOrderEndInstructionAccounts, in account order:

#FieldType
0takerPubkey
1makerPubkey
2global_configPubkey
3pda_authorityPubkey
4orderPubkey
5input_mintPubkey
6output_mintPubkey
7input_vaultPubkey
8taker_input_ataPubkey
9taker_output_ataPubkey
10intermediary_output_token_accountOption<Pubkey>
11maker_output_ataOption<Pubkey>
12express_relayPubkey
13express_relay_metadataPubkey
14sysvar_instructionsPubkey
15permissionOption<Pubkey>
16config_routerPubkey
17input_token_programPubkey
18output_token_programPubkey
19system_programPubkey
20rentPubkey
21event_authorityPubkey
22programPubkey
23…remainingVec<AccountMeta>

FlashTakeOrderStart#

Discriminator 7e35b00f276761f3 · data FlashTakeOrderStart · accounts FlashTakeOrderStartInstructionAccounts.

FieldType
input_amountu64
min_output_amountu64
tip_amount_permissionless_takingu64

Required accounts: 23; extras go to remaining.

Fields of FlashTakeOrderStartInstructionAccounts, in account order:

#FieldType
0takerPubkey
1makerPubkey
2global_configPubkey
3pda_authorityPubkey
4orderPubkey
5input_mintPubkey
6output_mintPubkey
7input_vaultPubkey
8taker_input_ataPubkey
9taker_output_ataPubkey
10intermediary_output_token_accountOption<Pubkey>
11maker_output_ataOption<Pubkey>
12express_relayPubkey
13express_relay_metadataPubkey
14sysvar_instructionsPubkey
15permissionOption<Pubkey>
16config_routerPubkey
17input_token_programPubkey
18output_token_programPubkey
19system_programPubkey
20rentPubkey
21event_authorityPubkey
22programPubkey
23…remainingVec<AccountMeta>

InitializeGlobalConfig#

Discriminator 71d87a83e1d11637 · data InitializeGlobalConfig · accounts InitializeGlobalConfigInstructionAccounts.

No data fields.

Required accounts: 3; extras go to remaining.

Fields of InitializeGlobalConfigInstructionAccounts, in account order:

#FieldType
0admin_authorityPubkey
1pda_authorityPubkey
2global_configPubkey
3…remainingVec<AccountMeta>

InitializeVault#

Discriminator 30bfa32c47813fa4 · data InitializeVault · accounts InitializeVaultInstructionAccounts.

No data fields.

Required accounts: 7; extras go to remaining.

Fields of InitializeVaultInstructionAccounts, in account order:

#FieldType
0payerPubkey
1global_configPubkey
2pda_authorityPubkey
3mintPubkey
4vaultPubkey
5token_programPubkey
6system_programPubkey
7…remainingVec<AccountMeta>

LogUserSwapBalancesEnd#

Discriminator 8c2ac65293902c71 · data LogUserSwapBalancesEnd · accounts LogUserSwapBalancesEndInstructionAccounts.

FieldType
simulated_swap_amount_outu64
simulated_tsu64
minimum_amount_outu64
swap_amount_inu64
simulated_amount_out_next_bestu64
aggregatoru8
next_best_aggregatoru8
padding[u8; 2]

Required accounts: 13; extras go to remaining.

Fields of LogUserSwapBalancesEndInstructionAccounts, in account order:

#FieldType
0makerPubkey
1input_mintPubkey
2output_mintPubkey
3input_taPubkey
4output_taPubkey
5pda_referrerOption<Pubkey>
6swap_program_idPubkey
7user_swap_balance_statePubkey
8system_programPubkey
9rentPubkey
10sysvar_instructionsPubkey
11event_authorityPubkey
12programPubkey
13…remainingVec<AccountMeta>

LogUserSwapBalancesStart#

Discriminator 856c170fe2d7b05f · data LogUserSwapBalancesStart · accounts LogUserSwapBalancesStartInstructionAccounts.

No data fields.

Required accounts: 13; extras go to remaining.

Fields of LogUserSwapBalancesStartInstructionAccounts, in account order:

#FieldType
0makerPubkey
1input_mintPubkey
2output_mintPubkey
3input_taPubkey
4output_taPubkey
5pda_referrerOption<Pubkey>
6swap_program_idPubkey
7user_swap_balance_statePubkey
8system_programPubkey
9rentPubkey
10sysvar_instructionsPubkey
11event_authorityPubkey
12programPubkey
13…remainingVec<AccountMeta>

TakeOrder#

Discriminator a3d014acdf41ffe4 · data TakeOrder · accounts TakeOrderInstructionAccounts.

FieldType
input_amountu64
min_output_amountu64
tip_amount_permissionless_takingu64

Required accounts: 23; extras go to remaining.

Fields of TakeOrderInstructionAccounts, in account order:

#FieldType
0takerPubkey
1makerPubkey
2global_configPubkey
3pda_authorityPubkey
4orderPubkey
5input_mintPubkey
6output_mintPubkey
7input_vaultPubkey
8taker_input_ataPubkey
9taker_output_ataPubkey
10intermediary_output_token_accountOption<Pubkey>
11maker_output_ataOption<Pubkey>
12express_relayPubkey
13express_relay_metadataPubkey
14sysvar_instructionsPubkey
15permissionOption<Pubkey>
16config_routerPubkey
17input_token_programPubkey
18output_token_programPubkey
19rentPubkey
20system_programPubkey
21event_authorityPubkey
22programPubkey
23…remainingVec<AccountMeta>

UpdateGlobalConfig#

Discriminator a45482bd6f3afac8 · data UpdateGlobalConfig · accounts UpdateGlobalConfigInstructionAccounts.

FieldType
modeu16
value[u8; 128]

Required accounts: 2; extras go to remaining.

Fields of UpdateGlobalConfigInstructionAccounts, in account order:

#FieldType
0admin_authorityPubkey
1global_configPubkey
2…remainingVec<AccountMeta>

UpdateGlobalConfigAdmin#

Discriminator b85717c19ceeaf77 · data UpdateGlobalConfigAdmin · accounts UpdateGlobalConfigAdminInstructionAccounts.

No data fields.

Required accounts: 2; extras go to remaining.

Fields of UpdateGlobalConfigAdminInstructionAccounts, in account order:

#FieldType
0admin_authority_cachedPubkey
1global_configPubkey
2…remainingVec<AccountMeta>

UpdateOrder#

Discriminator 3608d0cf2286efa8 · data UpdateOrder · accounts UpdateOrderInstructionAccounts.

FieldType
modeu16
valueVec<u8>

Required accounts: 3; extras go to remaining.

Fields of UpdateOrderInstructionAccounts, in account order:

#FieldType
0makerPubkey
1global_configPubkey
2orderPubkey
3…remainingVec<AccountMeta>

WithdrawHostTip#

Discriminator 8cf669a550558f12 · data WithdrawHostTip · accounts WithdrawHostTipInstructionAccounts.

No data fields.

Required accounts: 4; extras go to remaining.

Fields of WithdrawHostTipInstructionAccounts, in account order:

#FieldType
0admin_authorityPubkey
1global_configPubkey
2pda_authorityPubkey
3system_programPubkey
4…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 KaminoLimitOrderAccount. Each wraps a boxed struct from carbon_kamino_limit_order_decoder::accounts::<module>. decode_account only considers accounts owned by PROGRAM_ID and returns the first variant that matches.

GlobalConfig#

Discriminator 95089ccaa0fcb0d9 · accounts::global_config::GlobalConfig.

FieldTypeDescription
emergency_modeu8
flash_take_order_blockedu8
new_orders_blockedu8
orders_taking_blockedu8
host_fee_bpsu16
padding0[u8; 2]
order_close_delay_secondsu64The number of seconds after an order has been updated before it can be closed
padding1[u64; 9]
pda_authority_previous_lamports_balanceu64The total amount of lamports that were present in the pda_authority last time a program instructions which alters the pda_authority account was executed
total_tip_amountu64The total amount of tips that have been paid out - should be at least as much as the total lamports present in the pda_authority account
host_tip_amountu64The amount of tips the host is due to receive - in lamports, stored in the pda_authority account
pda_authorityPubkey
pda_authority_bumpu64
admin_authorityPubkey
admin_authority_cachedPubkey
txn_fee_costu64
ata_creation_costu64
padding2[u64; 241]

Order#

Discriminator 86addfb94d561c33 · accounts::order::Order.

FieldTypeDescription
global_configPubkey
makerPubkey
input_mintPubkey
input_mint_program_idPubkey
output_mintPubkey
output_mint_program_idPubkey
initial_input_amountu64The amount of input token the maker wants to swap
expected_output_amountu64The amount of output token the maker wants to receive
remaining_input_amountu64The amount of input token remaining to be swapped
filled_output_amountu64The amount of output token that the maker has received so far
tip_amountu64The amount of tips the maker is due to receive for this order - in lamports, stored in the pda_authority account
number_of_fillsu64The number of times the order has been filled
order_typeu8
statusu8
in_vault_bumpu8
flash_ix_locku8This is normally set to 0, but can be set to 1 to indicate that the order is part of a flash operation, in whcih case the order can not be modified until the flash operation is completed.
permissionlessu8
padding0[u8; 3]
last_updated_timestampu64
flash_start_taker_output_balanceu64This is only used for flash operations, and is set to the blanance on the start operation, and than back to 0 on the end operation. It is used to compute the difference between start and end balances in order to compute the amount received from a potential swap
counterpartyPubkey
padding[u64; 15]

UserSwapBalancesState#

Discriminator 8ce4983ee71bf5c6 · accounts::user_swap_balances_state::UserSwapBalancesState.

FieldType
user_lamportsu64
input_ta_balanceu64
output_ta_balanceu64

Events#

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

OrderDisplay#

Discriminator 5c65069ef898f13c · events::order_display::OrderDisplayEvent.

FieldType
initial_input_amountu64
expected_output_amountu64
remaining_input_amountu64
filled_output_amountu64
tip_amountu64
number_of_fillsu64
on_event_output_amount_filledu64
on_event_tip_amountu64
order_typeu8
statusu8
last_updated_timestampu64

UserSwapBalanceDiffs#

Discriminator 8bcb231f19083e8f · events::user_swap_balance_diffs::UserSwapBalanceDiffsEvent.

FieldType
user_lamports_beforeu64
input_ta_balance_beforeu64
output_ta_balance_beforeu64
user_lamports_afteru64
input_ta_balance_afteru64
output_ta_balance_afteru64
swap_programPubkey
simulated_swap_amount_outu64
simulated_tsu64
minimum_amount_outu64
swap_amount_inu64
simulated_amount_out_next_bestu64
aggregatoru8
next_best_aggregatoru8

Types#

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

OrderDisplay#

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

OrderStatus#

Enum types::OrderStatus.

Variant
Active
Filled
Cancelled

OrderType#

Enum types::OrderType.

Variant
Vanilla

UpdateGlobalConfigMode#

Enum types::UpdateGlobalConfigMode.

Variant
UpdateEmergencyMode
UpdateFlashTakeOrderBlocked
UpdateBlockNewOrders
UpdateBlockOrderTaking
UpdateHostFeeBps
UpdateAdminAuthorityCached
UpdateOrderTakingPermissionless
UpdateOrderCloseDelaySeconds
UpdateTxnFeeCost
UpdateAtaCreationCost

UpdateGlobalConfigValue#

Enum types::UpdateGlobalConfigValue.

VariantFields
Boolbool
U16u16
U64u64
PubkeyPubkey

UpdateOrderMode#

Enum types::UpdateOrderMode.

Variant
UpdatePermissionless
UpdateCounterparty

UserSwapBalanceDiffs#

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