# Swig decoder (Carbon 2.0)

> Decode Swig instructions in Rust with carbon-swig-decoder 2.0.0. Program ID swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB.

`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](https://carbon.sevenlabs.org/concepts/decoders.md) for how decoders plug into a pipeline.

|                  |                                                                                                   |
| ---------------- | ------------------------------------------------------------------------------------------------- |
| Crate            | [`carbon-swig-decoder`](https://crates.io/crates/carbon-swig-decoder/2.0.0) 2.0.0                 |
| Install          | `cargo add carbon-swig-decoder@2.0.0`                                                             |
| Program ID       | `swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB` (`carbon_swig_decoder::PROGRAM_ID`)                 |
| Category         | [Other](https://carbon.sevenlabs.org/decoders/other.md)                                           |
| Decoder          | `carbon_swig_decoder::SwigDecoder`                                                                |
| Instruction enum | `instructions::SwigInstruction`                                                                   |
| Account enum     | `accounts::SwigAccount` (no variants)                                                             |
| Features         | `serde`, `postgres`, `graphql` (none enabled by default)                                          |
| API docs         | [docs.rs/carbon-swig-decoder/2.0.0](https://docs.rs/carbon-swig-decoder/2.0.0)                    |
| Source           | [decoders/swig-decoder](https://github.com/sevenlabs-hq/carbon/tree/v2.0.0/decoders/swig-decoder) |

More program decoders without a category: [Jupiter DCA](https://carbon.sevenlabs.org/decoders/jupiter-dca.md), [Kamino Farms](https://carbon.sevenlabs.org/decoders/kamino-farms.md), [Pump Fees](https://carbon.sevenlabs.org/decoders/pump-fees.md), [Raydium Liquidity Locking](https://carbon.sevenlabs.org/decoders/raydium-liquidity-locking.md). To decode several in one pipeline, see [other program decoders](https://carbon.sevenlabs.org/decoders/other.md).

The `serde` feature derives `Serialize`/`Deserialize` on every type, `postgres` adds tables and processors for [Postgres](https://carbon.sevenlabs.org/guides/postgres.md), and `graphql` adds a schema for the [GraphQL server](https://carbon.sevenlabs.org/guides/graphql.md).

## Usage

This program crawls recent Swig transactions from the public RPC and prints every decoded `AddAuthorityV1` instruction. Add the dependencies:

```sh
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/full
```

`src/main.rs`:

```rust
use {
    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(())
    }
}
```

```sh
RUST_LOG=info cargo run
```

Each `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](https://carbon.sevenlabs.org/guides/stream-with-rpc.md) for the crawler options.

## Instructions

Variants of `SwigInstruction`. Each is `SwigInstruction::<Variant> { program_id, data, accounts }`, where `data` and `accounts` are the types listed under the variant, exported from `carbon_swig_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 `swigypWHEksbC64pWKwah1WTeh9JXwx8H1rJHLdbQMB`.
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 `AccountMeta`s. 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.

### `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_program` | `Pubkey`           |
| 3… | `remaining`      | `Vec<AccountMeta>` |

### `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_wallet_address` | `Pubkey`           |
| 2  | `destination`         | `Pubkey`           |
| 3  | `system_program`      | `Pubkey`           |
| 4… | `remaining`           | `Vec<AccountMeta>` |

### `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_wallet_address` | `Pubkey`           |
| 2  | `destination`         | `Pubkey`           |
| 3  | `token_program`       | `Pubkey`           |
| 4… | `remaining`           | `Vec<AccountMeta>` |

### `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_program` | `Pubkey`           |
| 3… | `remaining`      | `Vec<AccountMeta>` |

### `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_program` | `Pubkey`           |
| 4… | `remaining`      | `Vec<AccountMeta>` |

### `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_wallet_address` | `Pubkey`           |
| 3  | `system_program`      | `Pubkey`           |
| 4… | `remaining`           | `Vec<AccountMeta>` |

### `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<AccountMeta>` |

### `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_wallet_address` | `Pubkey`           |
| 4  | `system_program`      | `Pubkey`           |
| 5… | `remaining`           | `Vec<AccountMeta>` |

### `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_program` | `Pubkey`           |
| 3… | `remaining`      | `Vec<AccountMeta>` |

### `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_wallet_address` | `Pubkey`           |
| 2  | `system_program`      | `Pubkey`           |
| 3… | `remaining`           | `Vec<AccountMeta>` |

### `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_program` | `Pubkey`           |
| 3… | `remaining`      | `Vec<AccountMeta>` |

### `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<AccountMeta>` |

### `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_wallet_address` | `Pubkey`           |
| 2  | `payer`               | `Pubkey`           |
| 3  | `system_program`      | `Pubkey`           |
| 4… | `remaining`           | `Vec<AccountMeta>` |

### `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_program` | `Pubkey`           |
| 3… | `remaining`      | `Vec<AccountMeta>` |

### `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_context`   | `Pubkey`           |
| 4  | `swig_wallet_address` | `Pubkey`           |
| 5  | `system_program`      | `Pubkey`           |
| 6… | `remaining`           | `Vec<AccountMeta>` |

---

Carbon 2.0.0 documentation · Web: https://carbon.sevenlabs.org/decoders/swig · Last updated 2026-11-09 · Index of all pages: https://carbon.sevenlabs.org/llms.txt
