Swig decoder
Decode Swig instructions in Rust with carbon-swig-decoder 2.0.0. Program ID swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB.
On this page
carbon-swig-decoder decodes the instructions of the Swig program (swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB): 15 instructions. It decodes no accounts: SwigAccount has no variants. It is generated with Codama from the program's IDL; see decoders for how decoders plug into a pipeline.
| Crate | carbon-swig-decoder 2.0.0 |
| Install | cargo add carbon-swig-decoder@2. |
| Program ID | swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB (carbon_) |
| Category | Other |
| Decoder | carbon_ |
| Instruction enum | instructions:: |
| Account enum | accounts:: (no variants) |
| Features | serde, postgres, graphql (none enabled by default) |
| API docs | docs.rs/carbon-swig-decoder/2.0.0 |
| Source | decoders/swig-decoder |
More program decoders without a category: Jupiter DCA, Kamino Farms, Pump Fees, Raydium Liquidity Locking. To decode several in one pipeline, see other program 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 Swig transactions from the public RPC and prints every decoded AddAuthorityV1 instruction. Add the dependencies:
cargo add carbon-core@2.0.0 carbon-swig-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_swig_decoder::{instructions::SwigInstruction, SwigDecoder, 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(SwigDecoder, InstructionLogger)
.build()?
.run()
.await
}
struct InstructionLogger;
impl Processor<InstructionProcessorInputType<'_, SwigInstruction>> for InstructionLogger {
async fn process(
&mut self,
input: &InstructionProcessorInputType<'_, SwigInstruction>,
) -> CarbonResult<()> {
let signature = input.metadata.transaction_metadata.signature;
if let SwigInstruction::AddAuthorityV1 { data, accounts, .. } = input.decoded_instruction {
println!("add_authority_v1 {signature}: {data:?} swig={}", accounts.swig);
}
Ok(())
}
}RUST_LOG=info cargo runEach AddAuthorityV1 instruction prints one line with the transaction signature and the decoded AddAuthorityV1 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.
Instructions#
Variants of SwigInstruction. Each is SwigInstruction::, 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
swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB. - 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.
AddAuthorityV1#
Discriminator 01 · data AddAuthorityV1 · accounts AddAuthorityV1InstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of AddAuthorityV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | system_ | Pubkey |
| 3… | remaining | Vec< |
CloseSwigV1#
Discriminator 0f · data CloseSwigV1 · accounts CloseSwigV1InstructionAccounts.
No data fields.
Required accounts: 4; extras go to remaining.
Fields of CloseSwigV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | swig_ | Pubkey |
| 2 | destination | Pubkey |
| 3 | system_ | Pubkey |
| 4… | remaining | Vec< |
CloseTokenAccountV1#
Discriminator 0e · data CloseTokenAccountV1 · accounts CloseTokenAccountV1InstructionAccounts.
No data fields.
Required accounts: 4; extras go to remaining.
Fields of CloseTokenAccountV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | swig_ | Pubkey |
| 2 | destination | Pubkey |
| 3 | token_ | Pubkey |
| 4… | remaining | Vec< |
CreateSessionV1#
Discriminator 05 · data CreateSessionV1 · accounts CreateSessionV1InstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of CreateSessionV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | system_ | Pubkey |
| 3… | remaining | Vec< |
CreateSubAccountV1#
Discriminator 06 · data CreateSubAccountV1 · accounts CreateSubAccountV1InstructionAccounts.
No data fields.
Required accounts: 4; extras go to remaining.
Fields of CreateSubAccountV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | sub_account | Pubkey |
| 3 | system_ | Pubkey |
| 4… | remaining | Vec< |
CreateV1#
Discriminator 00 · data CreateV1 · accounts CreateV1InstructionAccounts.
No data fields.
Required accounts: 4; extras go to remaining.
Fields of CreateV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | swig_ | Pubkey |
| 3 | system_ | Pubkey |
| 4… | remaining | Vec< |
DeprecatedSignV1#
Discriminator 04 · data DeprecatedSignV1 · accounts DeprecatedSignV1InstructionAccounts.
No data fields.
Required accounts: 1; extras go to remaining.
Fields of DeprecatedSignV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | deprecated | Pubkey |
| 1… | remaining | Vec< |
MigrateToWalletAddressV1#
Discriminator 0c · data MigrateToWalletAddressV1 · accounts MigrateToWalletAddressV1InstructionAccounts.
No data fields.
Required accounts: 5; extras go to remaining.
Fields of MigrateToWalletAddressV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | authority | Pubkey |
| 2 | payer | Pubkey |
| 3 | swig_ | Pubkey |
| 4 | system_ | Pubkey |
| 5… | remaining | Vec< |
RemoveAuthorityV1#
Discriminator 02 · data RemoveAuthorityV1 · accounts RemoveAuthorityV1InstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of RemoveAuthorityV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | system_ | Pubkey |
| 3… | remaining | Vec< |
SignV2#
Discriminator 0b · data SignV2 · accounts SignV2InstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of SignV2InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | swig_ | Pubkey |
| 2 | system_ | Pubkey |
| 3… | remaining | Vec< |
SubAccountSignV1#
Discriminator 09 · data SubAccountSignV1 · accounts SubAccountSignV1InstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of SubAccountSignV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | sub_account | Pubkey |
| 2 | system_ | Pubkey |
| 3… | remaining | Vec< |
ToggleSubAccountV1#
Discriminator 0a · data ToggleSubAccountV1 · accounts ToggleSubAccountV1InstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of ToggleSubAccountV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | sub_account | Pubkey |
| 3… | remaining | Vec< |
TransferAssetsV1#
Discriminator 0d · data TransferAssetsV1 · accounts TransferAssetsV1InstructionAccounts.
No data fields.
Required accounts: 4; extras go to remaining.
Fields of TransferAssetsV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | swig_ | Pubkey |
| 2 | payer | Pubkey |
| 3 | system_ | Pubkey |
| 4… | remaining | Vec< |
UpdateAuthorityV1#
Discriminator 03 · data UpdateAuthorityV1 · accounts UpdateAuthorityV1InstructionAccounts.
No data fields.
Required accounts: 3; extras go to remaining.
Fields of UpdateAuthorityV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | system_ | Pubkey |
| 3… | remaining | Vec< |
WithdrawFromSubAccountV1#
Discriminator 07 · data WithdrawFromSubAccountV1 · accounts WithdrawFromSubAccountV1InstructionAccounts.
No data fields.
Required accounts: 6; extras go to remaining.
Fields of WithdrawFromSubAccountV1InstructionAccounts, in account order:
| # | Field | Type |
|---|---|---|
| 0 | swig | Pubkey |
| 1 | payer | Pubkey |
| 2 | sub_account | Pubkey |
| 3 | authority_ | Pubkey |
| 4 | swig_ | Pubkey |
| 5 | system_ | Pubkey |
| 6… | remaining | Vec< |