Stabble Stable Swap decoder
Decode Stabble Stable Swap instructions, accounts and events in Rust with the carbon-stabble-stable-swap-decoder crate.
On this page
carbon-stabble-stable-swap-decoder decodes the instructions, accounts and events of the Stabble Stable Swap program (swapNyd8XiQwJ6ianp9snpu4brUqFxadzvHebnAXjJZ): 19 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.
| Crate | carbon-stabble-stable-swap-decoder 2.0.0 |
| Install | cargo add carbon-stabble-stable-swap-decoder@2. |
| Program ID | swapNyd8XiQwJ6ianp9snpu4brUqFxadzvHebnAXjJZ (carbon_) |
| Category | DEX & AMM |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: |
| Event enum | instructions:: |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-stabble-stable-swap-decoder/2.0.0 |
| Source | decoders/stabble-stable-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 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 Stabble Stable Swap transactions from the public RPC and prints every decoded Swap instruction. Add the dependencies:
cargo add carbon-core@2.0.0 carbon-stabble-stable-swap-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_stabble_stable_swap_decoder::{
instructions::StabbleStableSwapInstruction, StabbleStableSwapDecoder, 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(StabbleStableSwapDecoder, InstructionLogger)
.build()?
.run()
.await
}
struct InstructionLogger;
impl Processor<InstructionProcessorInputType<'_, StabbleStableSwapInstruction>> for InstructionLogger {
async fn process(
&mut self,
input: &InstructionProcessorInputType<'_, StabbleStableSwapInstruction>,
) -> CarbonResult<()> {
let signature = input.metadata.transaction_metadata.signature;
if let StabbleStableSwapInstruction::Swap { data, accounts, .. } = input.decoded_instruction {
println!("swap {signature}: {data:?} user={}", accounts.user);
}
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.
Events published with Anchor's emit_cpi! arrive as the CpiEvent instruction. Match them with StabbleStableSwapInstruction:: (import instructions::); see Events. If CpiEvent never arrives, the program logs its events with emit! instead: decode them with decode_.
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:
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_stabble_stable_swap_decoder::{
accounts::StabbleStableSwapAccount, StabbleStableSwapDecoder, 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(StabbleStableSwapDecoder, AccountLogger)
.build()?
.run()
.await
}
struct AccountLogger;
impl Processor<AccountProcessorInputType<'_, StabbleStableSwapAccount>> for AccountLogger {
async fn process(
&mut self,
input: &AccountProcessorInputType<'_, StabbleStableSwapAccount>,
) -> CarbonResult<()> {
if let StabbleStableSwapAccount::Pool(pool) = &input.decoded_account.data {
println!("pool {}: {pool:?}", input.metadata.pubkey);
}
Ok(())
}
}RUST_LOG=info cargo runEach 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 StabbleStableSwapInstruction. Each is StabbleStableSwapInstruction::, 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
swapNyd8XiQwJ6ianp9snpu4brUqFxadzvHebnAXjJZ. - 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.
AcceptOwner#
Discriminator b017291c176f0804 · data AcceptOwner · accounts AcceptOwnerInstructionAccounts.
No data fields.
Required accounts: 2; extras go to remaining.
Fields of AcceptOwnerInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | pending_ | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
ApproveStrategy#
Discriminator 078da23c47731a92 · data ApproveStrategy · accounts ApproveStrategyInstructionAccounts.
No data fields.
Required accounts: 4; extras go to remaining.
Fields of ApproveStrategyInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | pool | Pubkey |
| 1 | vault | Pubkey |
| 2 | admin | Pubkey |
| 3 | strategy | Pubkey |
| 4… | remaining | Vec< |
ChangeAmpFactor#
Discriminator 38eebd23c89d2a42 · data ChangeAmpFactor · accounts ChangeAmpFactorInstructionAccounts.
| Field | Type |
|---|---|
new_ | u16 |
ramp_ | u32 |
Required accounts: 3; extras go to remaining.
Fields of ChangeAmpFactorInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | pool | Pubkey |
| 1 | vault | Pubkey |
| 2 | admin | Pubkey |
| 3… | remaining | Vec< |
ChangeMaxSupply#
Discriminator 5db000cd453f5750 · data ChangeMaxSupply · accounts ChangeMaxSupplyInstructionAccounts.
| Field | Type |
|---|---|
new_ | u64 |
Required accounts: 2; extras go to remaining.
Fields of ChangeMaxSupplyInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
ChangeSwapFee#
Discriminator e70f843384a540aa · data ChangeSwapFee · accounts ChangeSwapFeeInstructionAccounts.
| Field | Type |
|---|---|
new_ | u64 |
Required accounts: 2; extras go to remaining.
Fields of ChangeSwapFeeInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
ChangeSwapFeePrivileged#
Discriminator 9bc80e5b6926dc77 · data ChangeSwapFeePrivileged · accounts ChangeSwapFeePrivilegedInstructionAccounts.
| Field | Type |
|---|---|
new_ | u64 |
Required accounts: 3; extras go to remaining.
Fields of ChangeSwapFeePrivilegedInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | pool | Pubkey |
| 1 | vault | Pubkey |
| 2 | admin | Pubkey |
| 3… | remaining | Vec< |
CloseStrategy#
Discriminator 38f7aaf659dd86c8 · data CloseStrategy · accounts CloseStrategyInstructionAccounts.
No data fields.
Required accounts: 4; extras go to remaining.
Fields of CloseStrategyInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2 | strategy | Pubkey |
| 3 | rent_ | Pubkey |
| 4… | remaining | Vec< |
CreateStrategy#
Discriminator 98a06b94f5be7fe0 · data CreateStrategy · accounts CreateStrategyInstructionAccounts.
| Field | Type |
|---|---|
amp_ | u16 |
amp_ | u16 |
ramp_ | u16 |
ramp_ | u16 |
ramp_ | u32 |
ramp_ | u32 |
Required accounts: 3; extras go to remaining.
Fields of CreateStrategyInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2 | strategy | Pubkey |
| 3… | remaining | Vec< |
Deposit#
From the program's IDL:
add liquidity
Discriminator f223c68952e1f2b6 · data Deposit · accounts DepositInstructionAccounts.
| Field | Type |
|---|---|
amounts | Vec<u64> |
minimum_ | u64 |
Required accounts: 9; extras go to remaining.
Fields of DepositInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | user | Pubkey |
| 1 | user_ | Pubkey |
| 2 | mint | Pubkey |
| 3 | pool | Pubkey |
| 4 | pool_ | Pubkey |
| 5 | vault | Pubkey |
| 6 | vault_ | Pubkey |
| 7 | token_ | Pubkey |
| 8 | token_ | Pubkey |
| 9… | remaining | Vec< |
ExecStrategy#
Discriminator f92e37391f263d1b · data ExecStrategy · accounts ExecStrategyInstructionAccounts.
| Field | Type |
|---|---|
ramp_step | u16 |
ramp_ | u32 |
Required accounts: 2; extras go to remaining.
Fields of ExecStrategyInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | strategy | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
Initialize#
From the program's IDL:
initialize a pool
Discriminator afaf6d1f0d989bed · data Initialize · accounts InitializeInstructionAccounts.
| Field | Type |
|---|---|
amp_factor | u16 |
swap_fee | u64 |
max_caps | Vec<u64> |
Required accounts: 6; extras go to remaining.
Fields of InitializeInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | mint | Pubkey |
| 2 | pool | Pubkey |
| 3 | pool_ | Pubkey |
| 4 | withdraw_ | Pubkey |
| 5 | vault | Pubkey |
| 6… | remaining | Vec< |
Pause#
Discriminator d316ddfb4a79c12f · data Pause · accounts PauseInstructionAccounts.
No data fields.
Required accounts: 2; extras go to remaining.
Fields of PauseInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
RejectOwner#
Discriminator eecec6d733b285e4 · data RejectOwner · accounts RejectOwnerInstructionAccounts.
No data fields.
Required accounts: 2; extras go to remaining.
Fields of RejectOwnerInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | pending_ | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
Swap#
From the program's IDL:
swap
Discriminator f8c69e91e17587c8 · data Swap · accounts SwapInstructionAccounts.
| Field | Type |
|---|---|
amount_in | Option<u64> |
minimum_ | u64 |
Required accounts: 12; extras go to remaining.
Fields of SwapInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | user | Pubkey |
| 1 | user_ | Pubkey |
| 2 | user_ | Pubkey |
| 3 | vault_ | Pubkey |
| 4 | vault_ | Pubkey |
| 5 | beneficiary_ | Pubkey |
| 6 | pool | Pubkey |
| 7 | withdraw_ | Pubkey |
| 8 | vault | Pubkey |
| 9 | vault_ | Pubkey |
| 10 | vault_ | Pubkey |
| 11 | token_ | Pubkey |
| 12… | remaining | Vec< |
SwapV2#
Discriminator 2b04ed0b1ac91e62 · data SwapV2 · accounts SwapV2InstructionAccounts.
| Field | Type |
|---|---|
amount_in | Option<u64> |
minimum_ | u64 |
Required accounts: 15; extras go to remaining.
Fields of SwapV2InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | user | Pubkey |
| 1 | mint_in | Pubkey |
| 2 | mint_out | Pubkey |
| 3 | user_ | Pubkey |
| 4 | user_ | Pubkey |
| 5 | vault_ | Pubkey |
| 6 | vault_ | Pubkey |
| 7 | beneficiary_ | Pubkey |
| 8 | pool | Pubkey |
| 9 | withdraw_ | Pubkey |
| 10 | vault | Pubkey |
| 11 | vault_ | Pubkey |
| 12 | vault_ | Pubkey |
| 13 | token_ | Pubkey |
| 14 | token2022_ | Pubkey |
| 15… | remaining | Vec< |
TransferOwner#
Discriminator f519ddaf6ae5e12d · data TransferOwner · accounts TransferOwnerInstructionAccounts.
| Field | Type |
|---|---|
new_owner | Pubkey |
Required accounts: 2; extras go to remaining.
Fields of TransferOwnerInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
Unpause#
Discriminator a99004260a8dbcff · data Unpause · accounts UnpauseInstructionAccounts.
No data fields.
Required accounts: 2; extras go to remaining.
Fields of UnpauseInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | owner | Pubkey |
| 1 | pool | Pubkey |
| 2… | remaining | Vec< |
Withdraw#
From the program's IDL:
remove liquidity
Discriminator b712469c946da122 · data Withdraw · accounts WithdrawInstructionAccounts.
| Field | Type |
|---|---|
amount | u64 |
minimum_ | Vec<u64> |
Required accounts: 10; extras go to remaining.
Fields of WithdrawInstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | user | Pubkey |
| 1 | user_ | Pubkey |
| 2 | mint | Pubkey |
| 3 | pool | Pubkey |
| 4 | withdraw_ | Pubkey |
| 5 | vault | Pubkey |
| 6 | vault_ | Pubkey |
| 7 | vault_ | Pubkey |
| 8 | token_ | Pubkey |
| 9 | token_ | Pubkey |
| 10… | remaining | Vec< |
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:
| # | Field | Type |
|---|---|---|
| 0 | program | Pubkey |
| 1 | event_ | Pubkey |
| 2… | remaining | Vec< |
Accounts#
Variants of StabbleStableSwapAccount. Each wraps a boxed struct from carbon_. decode_ only considers accounts owned by PROGRAM_ID and returns the first variant that matches.
Pool#
Discriminator f19a6d0411b16dbc · accounts::.
| Field | Type |
|---|---|
owner | Pubkey |
vault | Pubkey |
mint | Pubkey |
authority_ | u8 |
is_active | bool |
amp_ | u16 |
amp_ | u16 |
ramp_ | i64 |
ramp_ | i64 |
swap_fee | u64 |
tokens | Vec< |
pending_ | Option< |
max_supply | u64 |
Strategy#
Discriminator ae6e2777526aa966 · accounts::.
| Field | Type |
|---|---|
pool | Pubkey |
is_active | bool |
amp_ | u16 |
amp_ | u16 |
ramp_ | u16 |
ramp_ | u16 |
ramp_ | u32 |
ramp_ | u32 |
Vault#
Discriminator d308e82b02987577 · accounts::.
| Field | Type | Description |
|---|---|---|
admin | Pubkey | |
withdraw_ | Pubkey | PDA of pool programs seeded by vault address |
withdraw_ | u8 | bump seed of withdraw_authority PDA |
authority_ | u8 | bump seed of vault_authority PDA |
is_active | bool | |
beneficiary | Pubkey | |
beneficiary_ | u64 | |
pending_ | Option< |
Events#
Variants of instructions::, decoded from the CpiEvent instruction. Each wraps a struct from carbon_. The discriminator is the 8-byte event discriminator that follows the e445a52e51cb9a1d CPI-event tag.
PoolBalanceUpdatedEvent#
Discriminator ac5272cf1b67d304 · events::.
| Field | Type |
|---|---|
pubkey | Pubkey |
data | PoolBalanceUpdatedData |
PoolUpdatedEvent#
Discriminator 80275edde6de7f8d · events::.
| Field | Type |
|---|---|
pubkey | Pubkey |
data | PoolUpdatedData |
Types#
Types used by the instructions, accounts and events above, exported from carbon_.
PoolBalanceUpdatedData#
Struct types::.
| Field | Type |
|---|---|
balances | Vec<u64> |
PoolBalanceUpdatedEvent#
Struct types::. Same fields as the PoolBalanceUpdatedEvent event.
PoolToken#
Struct types::.
| Field | Type |
|---|---|
mint | Pubkey |
decimals | u8 |
scaling_up | bool |
scaling_ | u64 |
balance | u64 |
PoolUpdatedData#
Struct types::.
| Field | Type |
|---|---|
is_active | bool |
amp_ | u16 |
amp_ | u16 |
ramp_ | i64 |
ramp_ | i64 |
swap_fee | u64 |
max_supply | u64 |
PoolUpdatedEvent#
Struct types::. Same fields as the PoolUpdatedEvent event.