Gavel decoder
Decode Gavel instructions and accounts in Rust with carbon-gavel-decoder 2.0.0. Program ID srAMMzfVHVAtgSJc8iH6CfKzuWuUTzLHVCE81QU1rgi.
On this page
carbon-gavel-decoder decodes the instructions and accounts of the Gavel program (srAMMzfVHVAtgSJc8iH6CfKzuWuUTzLHVCE81QU1rgi): 10 instructions, 2 account types. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.
| Crate | carbon-gavel-decoder 2.0.0 |
| Install | cargo add carbon-gavel-decoder@2. |
| Program ID | srAMMzfVHVAtgSJc8iH6CfKzuWuUTzLHVCE81QU1rgi (carbon_) |
| Category | DEX & AMM |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-gavel-decoder/2.0.0 |
| Source | decoders/gavel-decoder |
Other DEX and AMM decoders: BonkSwap, FluxBeam, 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, 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 Gavel transactions from the public RPC and prints every decoded Swap instruction. Add the dependencies:
cargo add carbon-core@2.0.0 carbon-gavel-decoder@2.0.0 carbon-rpc-transaction-crawler-datasource@2.0.0 carbon-log-metrics@2.0.0 env_logger tokio --features tokio/fulluse {
carbon_core::{
error::CarbonResult, instruction::InstructionProcessorInputType, pipeline::Pipeline,
processor::Processor,
},
carbon_log_metrics::LogMetrics,
carbon_gavel_decoder::{instructions::GavelInstruction, GavelDecoder, 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(GavelDecoder, InstructionLogger)
.build()?
.run()
.await
}
struct InstructionLogger;
impl Processor<InstructionProcessorInputType<'_, GavelInstruction>> for InstructionLogger {
async fn process(
&mut self,
input: &InstructionProcessorInputType<'_, GavelInstruction>,
) -> CarbonResult<()> {
let signature = input.metadata.transaction_metadata.signature;
if let GavelInstruction::Swap { data, accounts, .. } = input.decoded_instruction {
println!("swap {signature}: {data:?} plasma_program={}", accounts.plasma_program);
}
Ok(())
}
}RUST_LOG=info cargo runEach 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.
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 LpPositionAccount account as it changes. Add the datasource and the Solana RPC types it takes:
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2use {
carbon_core::{
account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
processor::Processor,
},
carbon_log_metrics::LogMetrics,
carbon_gavel_decoder::{accounts::GavelAccount, GavelDecoder, 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(GavelDecoder, AccountLogger)
.build()?
.run()
.await
}
struct AccountLogger;
impl Processor<AccountProcessorInputType<'_, GavelAccount>> for AccountLogger {
async fn process(
&mut self,
input: &AccountProcessorInputType<'_, GavelAccount>,
) -> CarbonResult<()> {
if let GavelAccount::LpPositionAccount(lp_position_account) = &input.decoded_account.data {
println!("lp_position_account {}: {lp_position_account:?}", input.metadata.pubkey);
}
Ok(())
}
}RUST_LOG=info cargo runEach update to a LpPositionAccount 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 GavelInstruction. Each is GavelInstruction::, where data and accounts are the types listed under the variant, exported from carbon_. 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:
- The instruction's program ID is
srAMMzfVHVAtgSJc8iH6CfKzuWuUTzLHVCE81QU1rgi. - The data starts with the variant's discriminator, and the rest deserializes into its data type.
- 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_ too. Accounts after the listed ones are in accounts. as AccountMetas. The decoder doesn't record whether an account signed or was writable: read that from input. and ., 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.
AddLiquidity#
Discriminator 01 · data AddLiquidity · accounts AddLiquidityInstructionAccounts.
| Field | Type |
|---|---|
params | AddLiquidityIxParams |
Required accounts: 10; extras go to remaining.
Fields of AddLiquidityInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | trader | Pubkey |
| 4 | lp_position | Pubkey |
| 5 | base_ | Pubkey |
| 6 | quote_ | Pubkey |
| 7 | base_vault | Pubkey |
| 8 | quote_vault | Pubkey |
| 9 | token_ | Pubkey |
| 10… | remaining | Vec< |
InitializeLpPosition#
Discriminator 05 · data InitializeLpPosition · accounts InitializeLpPositionInstructionAccounts.
No data fields.
Required accounts: 7; extras go to remaining.
Fields of InitializeLpPositionInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | payer | Pubkey |
| 4 | lp_ | Pubkey |
| 5 | lp_position | Pubkey |
| 6 | system_ | Pubkey |
| 7… | remaining | Vec< |
InitializePool#
Discriminator 06 · data InitializePool · accounts InitializePoolInstructionAccounts.
| Field | Type |
|---|---|
params | InitializePoolIxParams |
Required accounts: 10; extras go to remaining.
Fields of InitializePoolInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | pool_ | Pubkey |
| 4 | base_mint | Pubkey |
| 5 | quote_mint | Pubkey |
| 6 | base_vault | Pubkey |
| 7 | quote_vault | Pubkey |
| 8 | system_ | Pubkey |
| 9 | token_ | Pubkey |
| 10… | remaining | Vec< |
Log#
Discriminator 08 · data Log · accounts LogInstructionAccounts.
No data fields.
Required accounts: 1; extras go to remaining.
Fields of LogInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | log_ | Pubkey |
| 1… | remaining | Vec< |
RemoveLiquidity#
Discriminator 02 · data RemoveLiquidity · accounts RemoveLiquidityInstructionAccounts.
| Field | Type |
|---|---|
params | RemoveLiquidityIxParams |
Required accounts: 10; extras go to remaining.
Fields of RemoveLiquidityInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | trader | Pubkey |
| 4 | lp_position | Pubkey |
| 5 | base_ | Pubkey |
| 6 | quote_ | Pubkey |
| 7 | base_vault | Pubkey |
| 8 | quote_vault | Pubkey |
| 9 | token_ | Pubkey |
| 10… | remaining | Vec< |
RenounceLiquidity#
Discriminator 03 · data RenounceLiquidity · accounts RenounceLiquidityInstructionAccounts.
| Field | Type |
|---|---|
params | RenounceLiquidityIxParams |
Required accounts: 5; extras go to remaining.
Fields of RenounceLiquidityInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | trader | Pubkey |
| 4 | lp_position | Pubkey |
| 5… | remaining | Vec< |
Swap#
Discriminator 00 · data Swap · accounts SwapInstructionAccounts.
| Field | Type |
|---|---|
params | SwapIxParams |
Required accounts: 9; extras go to remaining.
Fields of SwapInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | trader | Pubkey |
| 4 | base_ | Pubkey |
| 5 | quote_ | Pubkey |
| 6 | base_vault | Pubkey |
| 7 | quote_vault | Pubkey |
| 8 | token_ | Pubkey |
| 9… | remaining | Vec< |
TransferLiquidity#
Discriminator 09 · data TransferLiquidity · accounts TransferLiquidityInstructionAccounts.
No data fields.
Required accounts: 6; extras go to remaining.
Fields of TransferLiquidityInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | trader | Pubkey |
| 4 | src_ | Pubkey |
| 5 | dst_ | Pubkey |
| 6… | remaining | Vec< |
WithdrawLpFees#
Discriminator 04 · data WithdrawLpFees · accounts WithdrawLpFeesInstructionAccounts.
No data fields.
Required accounts: 9; extras go to remaining.
Fields of WithdrawLpFeesInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | trader | Pubkey |
| 4 | lp_ | Pubkey |
| 5 | lp_position | Pubkey |
| 6 | quote_ | Pubkey |
| 7 | quote_vault | Pubkey |
| 8 | token_ | Pubkey |
| 9… | remaining | Vec< |
WithdrawProtocolFees#
Discriminator 07 · data WithdrawProtocolFees · accounts WithdrawProtocolFeesInstructionAccounts.
No data fields.
Required accounts: 7; extras go to remaining.
Fields of WithdrawProtocolFeesInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | plasma_ | Pubkey |
| 1 | log_ | Pubkey |
| 2 | pool | Pubkey |
| 3 | protocol_ | Pubkey |
| 4 | quote_ | Pubkey |
| 5 | quote_vault | Pubkey |
| 6 | token_ | Pubkey |
| 7… | remaining | Vec< |
Accounts#
Variants of GavelAccount. Each wraps a boxed struct from carbon_. decode_ only considers accounts owned by PROGRAM_ID and returns the first variant that matches.
LpPositionAccount#
No discriminator (matched by Borsh layout) · accounts::.
| Field | Type |
|---|---|
authority | Pubkey |
pool | Pubkey |
status | u64 |
lp_position | LpPosition |
PoolAccount#
No discriminator (matched by Borsh layout) · accounts::.
| Field | Type |
|---|---|
pool_header | PoolHeader |
amm | Amm |
Types#
Types used by the instructions, accounts and events above, exported from carbon_.
AddLiquidityEvent#
Struct types::.
| Field | Type |
|---|---|
pool_ | u64 |
pool_ | u64 |
pool_ | u64 |
snapshot_ | u64 |
snapshot_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
AddLiquidityIxParams#
Struct types::.
| Field | Type |
|---|---|
desired_ | u64 |
desired_ | u64 |
initial_ | Option<u64> |
Amm#
Struct types::Amm.
| Field | Type |
|---|---|
fee_in_bps | u32 |
protocol_ | u32 |
lp_ | u64 |
reward_ | u128 |
total_ | u64 |
slot_ | u64 |
base_ | u64 |
quote_ | u64 |
base_ | u64 |
quote_ | u64 |
cumulative_ | u64 |
cumulative_ | u64 |
InitializeLpPositionEvent#
Struct types::.
| Field | Type |
|---|---|
owner | Pubkey |
InitializePoolEvent#
Struct types::.
| Field | Type |
|---|---|
lp_ | u64 |
protocol_ | u64 |
fee_ | [ProtocolFeeRecipientParams; 3] |
InitializePoolIxParams#
Struct types::.
| Field | Type |
|---|---|
lp_ | u64 |
protocol_ | u64 |
fee_ | [ProtocolFeeRecipientParams; 3] |
num_ | Option<u64> |
LpPosition#
Struct types::.
| Field | Type |
|---|---|
reward_ | u128 |
lp_shares | u64 |
withdrawable_ | u64 |
uncollected_ | u64 |
collected_ | u64 |
pending_ | PendingSharesToVest |
PendingSharesToVest#
Struct types::.
| Field | Type |
|---|---|
deposit_ | u64 |
lp_ | u64 |
PlasmaEvent#
Enum types::.
| Variant | Fields |
|---|---|
Swap | header: PlasmaEventHeader, event: SwapEvent |
AddLiquidity | header: PlasmaEventHeader, event: AddLiquidityEvent |
RemoveLiquidity | header: PlasmaEventHeader, event: RemoveLiquidityEvent |
RenounceLiquidity | header: PlasmaEventHeader, event: RenounceLiquidityEvent |
WithdrawLpFees | header: PlasmaEventHeader, event: WithdrawLpFeesEvent |
InitializeLpPosition | header: PlasmaEventHeader, event: InitializeLpPositionEvent |
InitializePool | header: PlasmaEventHeader, event: InitializePoolEvent |
WithdrawProtocolFees | header: PlasmaEventHeader, event: WithdrawProtocolFeesEvent |
PlasmaEventHeader#
Struct types::.
| Field | Type |
|---|---|
sequence_ | u64 |
slot | u64 |
timestamp | i64 |
pool | Pubkey |
signer | Pubkey |
base_ | u8 |
quote_ | u8 |
PoolHeader#
Struct types::.
| Field | Type |
|---|---|
sequence_ | u64 |
base_params | TokenParams |
quote_ | TokenParams |
fee_ | ProtocolFeeRecipients |
swap_ | u64 |
padding | [u64; 12] |
ProtocolFeeRecipient#
Struct types::.
| Field | Type |
|---|---|
recipient | Pubkey |
shares | u64 |
total_ | u64 |
collected_ | u64 |
ProtocolFeeRecipientParams#
Struct types::.
| Field | Type |
|---|---|
recipient | Pubkey |
shares | u64 |
ProtocolFeeRecipients#
Struct types::.
| Field | Type |
|---|---|
recipients | [ProtocolFeeRecipient; 3] |
padding | [u64; 12] |
RemoveLiquidityEvent#
Struct types::.
| Field | Type |
|---|---|
pool_ | u64 |
pool_ | u64 |
pool_ | u64 |
snapshot_ | u64 |
snapshot_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
user_ | u64 |
RemoveLiquidityIxParams#
Struct types::.
| Field | Type |
|---|---|
lp_shares | u64 |
RenounceLiquidityEvent#
Struct types::.
| Field | Type |
|---|---|
allow_ | bool |
RenounceLiquidityIxParams#
Struct types::.
| Field | Type |
|---|---|
allow_ | bool |
Side#
Enum types::Side.
| Variant |
|---|
Buy |
Sell |
SwapEvent#
Struct types::.
| Field | Type |
|---|---|
swap_ | u64 |
pre_ | u64 |
pre_ | u64 |
post_ | u64 |
post_ | u64 |
snapshot_ | u64 |
snapshot_ | u64 |
swap_result | SwapResult |
SwapIxParams#
Struct types::.
SwapResult#
Struct types::.
| Field | Type |
|---|---|
side | Side |
base_ | u64 |
quote_ | u64 |
base_ | u64 |
quote_ | u64 |
base_ | u64 |
quote_ | u64 |
fee_ | u64 |
SwapType#
Enum types::.
| Variant | Fields |
|---|---|
ExactIn | amount_in: u64, min_: u64 |
ExactOut | amount_out: u64, max_: u64 |
TokenParams#
Struct types::.
| Field | Type |
|---|---|
decimals | u32 |
vault_bump | u32 |
mint_key | Pubkey |
vault_key | Pubkey |
WithdrawLpFeesEvent#
Struct types::.
| Field | Type |
|---|---|
fees_ | u64 |
WithdrawProtocolFeesEvent#
Struct types::.
| Field | Type |
|---|---|
protocol_ | Pubkey |
fees_ | u64 |