# Kamino Farms decoder (Carbon 2.0)

> Decode Kamino Farms instructions and accounts in Rust with carbon-kamino-farms-decoder 2.0.0. Program ID FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr.

`carbon-kamino-farms-decoder` decodes the instructions and accounts of the Kamino Farms program (`FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr`): 26 instructions, 4 account types. 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-kamino-farms-decoder`](https://crates.io/crates/carbon-kamino-farms-decoder/2.0.0) 2.0.0                 |
| Install          | `cargo add carbon-kamino-farms-decoder@2.0.0`                                                                     |
| Program ID       | `FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr` (`carbon_kamino_farms_decoder::PROGRAM_ID`)                        |
| Category         | [Other](https://carbon.sevenlabs.org/decoders/other.md)                                                           |
| Decoder          | `carbon_kamino_farms_decoder::KaminoFarmsDecoder`                                                                 |
| Instruction enum | `instructions::KaminoFarmsInstruction`                                                                            |
| Account enum     | `accounts::KaminoFarmsAccount`                                                                                    |
| Features         | `serde`, `postgres`, `graphql` (none enabled by default)                                                          |
| API docs         | [docs.rs/carbon-kamino-farms-decoder/2.0.0](https://docs.rs/carbon-kamino-farms-decoder/2.0.0)                    |
| Source           | [decoders/kamino-farms-decoder](https://github.com/sevenlabs-hq/carbon/tree/v2.0.0/decoders/kamino-farms-decoder) |

More program decoders without a category: [Jupiter DCA](https://carbon.sevenlabs.org/decoders/jupiter-dca.md), [Pump Fees](https://carbon.sevenlabs.org/decoders/pump-fees.md), [Raydium Liquidity Locking](https://carbon.sevenlabs.org/decoders/raydium-liquidity-locking.md), [Swig](https://carbon.sevenlabs.org/decoders/swig.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 Kamino Farms transactions from the public RPC and prints every decoded `AddRewards` instruction. Add the dependencies:

```sh
cargo add carbon-core@2.0.0 carbon-kamino-farms-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_kamino_farms_decoder::{
        instructions::KaminoFarmsInstruction, KaminoFarmsDecoder, 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(KaminoFarmsDecoder, InstructionLogger)
        .build()?
        .run()
        .await
}

struct InstructionLogger;

impl Processor<InstructionProcessorInputType<'_, KaminoFarmsInstruction>> for InstructionLogger {
    async fn process(
        &mut self,
        input: &InstructionProcessorInputType<'_, KaminoFarmsInstruction>,
    ) -> CarbonResult<()> {
        let signature = input.metadata.transaction_metadata.signature;
        if let KaminoFarmsInstruction::AddRewards { data, accounts, .. } = input.decoded_instruction {
            println!("add_rewards {signature}: {data:?} payer={}", accounts.payer);
        }
        Ok(())
    }
}
```

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

Each `AddRewards` instruction prints one line with the transaction signature and the decoded `AddRewards` 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.

### 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:

```sh
cargo add carbon-rpc-program-subscribe-datasource@2.0.0 solana-client@4.2.2
```

`src/main.rs`:

```rust
use {
    carbon_core::{
        account::AccountProcessorInputType, error::CarbonResult, pipeline::Pipeline,
        processor::Processor,
    },
    carbon_log_metrics::LogMetrics,
    carbon_kamino_farms_decoder::{accounts::KaminoFarmsAccount, KaminoFarmsDecoder, 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(KaminoFarmsDecoder, AccountLogger)
        .build()?
        .run()
        .await
}

struct AccountLogger;

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

```sh
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](https://carbon.sevenlabs.org/guides/load-account-state.md).

## Instructions

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

### `AddRewards`

Discriminator `58ba19e326895117` · data `AddRewards` · accounts `AddRewardsInstructionAccounts`.

| Field          | Type  |
| -------------- | ----- |
| `amount`       | `u64` |
| `reward_index` | `u64` |

Required accounts: 8; extras go to `remaining`.

Fields of `AddRewardsInstructionAccounts`, in account order:

| #  | Field                    | Type               |
| -- | ------------------------ | ------------------ |
| 0  | `payer`                  | `Pubkey`           |
| 1  | `farm_state`             | `Pubkey`           |
| 2  | `reward_mint`            | `Pubkey`           |
| 3  | `reward_vault`           | `Pubkey`           |
| 4  | `farm_vaults_authority`  | `Pubkey`           |
| 5  | `payer_reward_token_ata` | `Pubkey`           |
| 6  | `scope_prices`           | `Option<Pubkey>`   |
| 7  | `token_program`          | `Pubkey`           |
| 8… | `remaining`              | `Vec<AccountMeta>` |

### `DepositToFarmVault`

Discriminator `83a6405e6cd572b7` · data `DepositToFarmVault` · accounts `DepositToFarmVaultInstructionAccounts`.

| Field    | Type  |
| -------- | ----- |
| `amount` | `u64` |

Required accounts: 5; extras go to `remaining`.

Fields of `DepositToFarmVaultInstructionAccounts`, in account order:

| #  | Field           | Type               |
| -- | --------------- | ------------------ |
| 0  | `depositor`     | `Pubkey`           |
| 1  | `farm_state`    | `Pubkey`           |
| 2  | `farm_vault`    | `Pubkey`           |
| 3  | `depositor_ata` | `Pubkey`           |
| 4  | `token_program` | `Pubkey`           |
| 5… | `remaining`     | `Vec<AccountMeta>` |

### `HarvestReward`

Discriminator `44c8e4e9b820e2bc` · data `HarvestReward` · accounts `HarvestRewardInstructionAccounts`.

| Field          | Type  |
| -------------- | ----- |
| `reward_index` | `u64` |

Required accounts: 11; extras go to `remaining`.

Fields of `HarvestRewardInstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `payer`                     | `Pubkey`           |
| 1   | `user_state`                | `Pubkey`           |
| 2   | `farm_state`                | `Pubkey`           |
| 3   | `global_config`             | `Pubkey`           |
| 4   | `reward_mint`               | `Pubkey`           |
| 5   | `user_reward_token_account` | `Pubkey`           |
| 6   | `rewards_vault`             | `Pubkey`           |
| 7   | `rewards_treasury_vault`    | `Pubkey`           |
| 8   | `farm_vaults_authority`     | `Pubkey`           |
| 9   | `scope_prices`              | `Option<Pubkey>`   |
| 10  | `token_program`             | `Pubkey`           |
| 11… | `remaining`                 | `Vec<AccountMeta>` |

### `IdlMissingTypes`

Discriminator `8250269950d4b6fd` · data `IdlMissingTypes` · accounts `IdlMissingTypesInstructionAccounts`.

| Field                       | Type                                        |
| --------------------------- | ------------------------------------------- |
| `global_config_option_kind` | [`GlobalConfigOption`](#globalconfigoption) |
| `farm_config_option_kind`   | [`FarmConfigOption`](#farmconfigoption)     |
| `time_unit`                 | [`TimeUnit`](#timeunit)                     |
| `locking_mode`              | [`LockingMode`](#lockingmode)               |
| `reward_type`               | [`RewardType`](#rewardtype)                 |

Required accounts: 2; extras go to `remaining`.

Fields of `IdlMissingTypesInstructionAccounts`, in account order:

| #  | Field           | Type               |
| -- | --------------- | ------------------ |
| 0  | `global_admin`  | `Pubkey`           |
| 1  | `global_config` | `Pubkey`           |
| 2… | `remaining`     | `Vec<AccountMeta>` |

### `InitializeFarm`

Discriminator `fc1cb9acf44a75a5` · data `InitializeFarm` · accounts `InitializeFarmInstructionAccounts`.

No data fields.

Required accounts: 9; extras go to `remaining`.

Fields of `InitializeFarmInstructionAccounts`, in account order:

| #  | Field                   | Type               |
| -- | ----------------------- | ------------------ |
| 0  | `farm_admin`            | `Pubkey`           |
| 1  | `farm_state`            | `Pubkey`           |
| 2  | `global_config`         | `Pubkey`           |
| 3  | `farm_vault`            | `Pubkey`           |
| 4  | `farm_vaults_authority` | `Pubkey`           |
| 5  | `token_mint`            | `Pubkey`           |
| 6  | `token_program`         | `Pubkey`           |
| 7  | `system_program`        | `Pubkey`           |
| 8  | `rent`                  | `Pubkey`           |
| 9… | `remaining`             | `Vec<AccountMeta>` |

### `InitializeFarmDelegated`

Discriminator `fa546519334dcc5b` · data `InitializeFarmDelegated` · accounts `InitializeFarmDelegatedInstructionAccounts`.

No data fields.

Required accounts: 7; extras go to `remaining`.

Fields of `InitializeFarmDelegatedInstructionAccounts`, in account order:

| #  | Field                   | Type               |
| -- | ----------------------- | ------------------ |
| 0  | `farm_admin`            | `Pubkey`           |
| 1  | `farm_delegate`         | `Pubkey`           |
| 2  | `farm_state`            | `Pubkey`           |
| 3  | `global_config`         | `Pubkey`           |
| 4  | `farm_vaults_authority` | `Pubkey`           |
| 5  | `system_program`        | `Pubkey`           |
| 6  | `rent`                  | `Pubkey`           |
| 7… | `remaining`             | `Vec<AccountMeta>` |

### `InitializeGlobalConfig`

Discriminator `71d87a83e1d11637` · data `InitializeGlobalConfig` · accounts `InitializeGlobalConfigInstructionAccounts`.

No data fields.

Required accounts: 4; extras go to `remaining`.

Fields of `InitializeGlobalConfigInstructionAccounts`, in account order:

| #  | Field                       | Type               |
| -- | --------------------------- | ------------------ |
| 0  | `global_admin`              | `Pubkey`           |
| 1  | `global_config`             | `Pubkey`           |
| 2  | `treasury_vaults_authority` | `Pubkey`           |
| 3  | `system_program`            | `Pubkey`           |
| 4… | `remaining`                 | `Vec<AccountMeta>` |

### `InitializeReward`

Discriminator `5f87c0c4f281e644` · data `InitializeReward` · accounts `InitializeRewardInstructionAccounts`.

No data fields.

Required accounts: 11; extras go to `remaining`.

Fields of `InitializeRewardInstructionAccounts`, in account order:

| #   | Field                       | Type               |
| --- | --------------------------- | ------------------ |
| 0   | `farm_admin`                | `Pubkey`           |
| 1   | `farm_state`                | `Pubkey`           |
| 2   | `global_config`             | `Pubkey`           |
| 3   | `reward_mint`               | `Pubkey`           |
| 4   | `reward_vault`              | `Pubkey`           |
| 5   | `reward_treasury_vault`     | `Pubkey`           |
| 6   | `farm_vaults_authority`     | `Pubkey`           |
| 7   | `treasury_vaults_authority` | `Pubkey`           |
| 8   | `token_program`             | `Pubkey`           |
| 9   | `system_program`            | `Pubkey`           |
| 10  | `rent`                      | `Pubkey`           |
| 11… | `remaining`                 | `Vec<AccountMeta>` |

### `InitializeUser`

Discriminator `6f11b9fa3c7a26fe` · data `InitializeUser` · accounts `InitializeUserInstructionAccounts`.

No data fields.

Required accounts: 8; extras go to `remaining`.

Fields of `InitializeUserInstructionAccounts`, in account order:

| #  | Field            | Type               |
| -- | ---------------- | ------------------ |
| 0  | `authority`      | `Pubkey`           |
| 1  | `payer`          | `Pubkey`           |
| 2  | `owner`          | `Pubkey`           |
| 3  | `delegatee`      | `Pubkey`           |
| 4  | `user_state`     | `Pubkey`           |
| 5  | `farm_state`     | `Pubkey`           |
| 6  | `system_program` | `Pubkey`           |
| 7  | `rent`           | `Pubkey`           |
| 8… | `remaining`      | `Vec<AccountMeta>` |

### `RefreshFarm`

Discriminator `d6838ab790c2ac2a` · data `RefreshFarm` · accounts `RefreshFarmInstructionAccounts`.

No data fields.

Required accounts: 1 (2 listed); extras go to `remaining`.

Fields of `RefreshFarmInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `farm_state`   | `Pubkey`           |
| 1  | `scope_prices` | `Option<Pubkey>`   |
| 2… | `remaining`    | `Vec<AccountMeta>` |

### `RefreshUserState`

Discriminator `01870c3ef38c4d6c` · data `RefreshUserState` · accounts `RefreshUserStateInstructionAccounts`.

No data fields.

Required accounts: 2 (3 listed); extras go to `remaining`.

Fields of `RefreshUserStateInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `user_state`   | `Pubkey`           |
| 1  | `farm_state`   | `Pubkey`           |
| 2  | `scope_prices` | `Option<Pubkey>`   |
| 3… | `remaining`    | `Vec<AccountMeta>` |

### `RewardUserOnce`

Discriminator `db8939165eba6072` · data `RewardUserOnce` · accounts `RewardUserOnceInstructionAccounts`.

| Field                              | Type  |
| ---------------------------------- | ----- |
| `reward_index`                     | `u64` |
| `amount`                           | `u64` |
| `expected_reward_issued_unclaimed` | `u64` |

Required accounts: 3; extras go to `remaining`.

Fields of `RewardUserOnceInstructionAccounts`, in account order:

| #  | Field                | Type               |
| -- | -------------------- | ------------------ |
| 0  | `delegate_authority` | `Pubkey`           |
| 1  | `farm_state`         | `Pubkey`           |
| 2  | `user_state`         | `Pubkey`           |
| 3… | `remaining`          | `Vec<AccountMeta>` |

### `SetStakeDelegated`

Discriminator `49abb84b1e38c6df` · data `SetStakeDelegated` · accounts `SetStakeDelegatedInstructionAccounts`.

| Field        | Type  |
| ------------ | ----- |
| `new_amount` | `u64` |

Required accounts: 3; extras go to `remaining`.

Fields of `SetStakeDelegatedInstructionAccounts`, in account order:

| #  | Field                | Type               |
| -- | -------------------- | ------------------ |
| 0  | `delegate_authority` | `Pubkey`           |
| 1  | `user_state`         | `Pubkey`           |
| 2  | `farm_state`         | `Pubkey`           |
| 3… | `remaining`          | `Vec<AccountMeta>` |

### `Stake`

Discriminator `ceb0ca12c8d1b36c` · data `Stake` · accounts `StakeInstructionAccounts`.

| Field    | Type  |
| -------- | ----- |
| `amount` | `u64` |

Required accounts: 8; extras go to `remaining`.

Fields of `StakeInstructionAccounts`, in account order:

| #  | Field           | Type               |
| -- | --------------- | ------------------ |
| 0  | `owner`         | `Pubkey`           |
| 1  | `user_state`    | `Pubkey`           |
| 2  | `farm_state`    | `Pubkey`           |
| 3  | `farm_vault`    | `Pubkey`           |
| 4  | `user_ata`      | `Pubkey`           |
| 5  | `token_mint`    | `Pubkey`           |
| 6  | `scope_prices`  | `Option<Pubkey>`   |
| 7  | `token_program` | `Pubkey`           |
| 8… | `remaining`     | `Vec<AccountMeta>` |

### `TransferOwnership`

Discriminator `41b1d749352d632f` · data `TransferOwnership` · accounts `TransferOwnershipInstructionAccounts`.

No data fields.

Required accounts: 9; extras go to `remaining`.

Fields of `TransferOwnershipInstructionAccounts`, in account order:

| #  | Field            | Type               |
| -- | ---------------- | ------------------ |
| 0  | `old_owner`      | `Pubkey`           |
| 1  | `payer`          | `Pubkey`           |
| 2  | `new_owner`      | `Pubkey`           |
| 3  | `old_user_state` | `Pubkey`           |
| 4  | `new_user_state` | `Pubkey`           |
| 5  | `farm_state`     | `Pubkey`           |
| 6  | `scope_prices`   | `Option<Pubkey>`   |
| 7  | `system_program` | `Pubkey`           |
| 8  | `rent`           | `Pubkey`           |
| 9… | `remaining`      | `Vec<AccountMeta>` |

### `Unstake`

Discriminator `5a5f6b2acd7c32e1` · data `Unstake` · accounts `UnstakeInstructionAccounts`.

| Field                 | Type   |
| --------------------- | ------ |
| `stake_shares_scaled` | `u128` |

Required accounts: 3 (4 listed); extras go to `remaining`.

Fields of `UnstakeInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `owner`        | `Pubkey`           |
| 1  | `user_state`   | `Pubkey`           |
| 2  | `farm_state`   | `Pubkey`           |
| 3  | `scope_prices` | `Option<Pubkey>`   |
| 4… | `remaining`    | `Vec<AccountMeta>` |

### `UpdateFarmAdmin`

Discriminator `142588137aef2482` · data `UpdateFarmAdmin` · accounts `UpdateFarmAdminInstructionAccounts`.

No data fields.

Required accounts: 2; extras go to `remaining`.

Fields of `UpdateFarmAdminInstructionAccounts`, in account order:

| #  | Field                | Type               |
| -- | -------------------- | ------------------ |
| 0  | `pending_farm_admin` | `Pubkey`           |
| 1  | `farm_state`         | `Pubkey`           |
| 2… | `remaining`          | `Vec<AccountMeta>` |

### `UpdateFarmConfig`

Discriminator `d6b0bcf4cb3be6cf` · data `UpdateFarmConfig` · accounts `UpdateFarmConfigInstructionAccounts`.

| Field  | Type      |
| ------ | --------- |
| `mode` | `u16`     |
| `data` | `Vec<u8>` |

Required accounts: 2 (3 listed); extras go to `remaining`.

Fields of `UpdateFarmConfigInstructionAccounts`, in account order:

| #  | Field          | Type               |
| -- | -------------- | ------------------ |
| 0  | `signer`       | `Pubkey`           |
| 1  | `farm_state`   | `Pubkey`           |
| 2  | `scope_prices` | `Option<Pubkey>`   |
| 3… | `remaining`    | `Vec<AccountMeta>` |

### `UpdateGlobalConfig`

Discriminator `a45482bd6f3afac8` · data `UpdateGlobalConfig` · accounts `UpdateGlobalConfigInstructionAccounts`.

| Field   | Type       |
| ------- | ---------- |
| `mode`  | `u8`       |
| `value` | `[u8; 32]` |

Required accounts: 2; extras go to `remaining`.

Fields of `UpdateGlobalConfigInstructionAccounts`, in account order:

| #  | Field           | Type               |
| -- | --------------- | ------------------ |
| 0  | `global_admin`  | `Pubkey`           |
| 1  | `global_config` | `Pubkey`           |
| 2… | `remaining`     | `Vec<AccountMeta>` |

### `UpdateGlobalConfigAdmin`

Discriminator `b85717c19ceeaf77` · data `UpdateGlobalConfigAdmin` · accounts `UpdateGlobalConfigAdminInstructionAccounts`.

No data fields.

Required accounts: 2; extras go to `remaining`.

Fields of `UpdateGlobalConfigAdminInstructionAccounts`, in account order:

| #  | Field                  | Type               |
| -- | ---------------------- | ------------------ |
| 0  | `pending_global_admin` | `Pubkey`           |
| 1  | `global_config`        | `Pubkey`           |
| 2… | `remaining`            | `Vec<AccountMeta>` |

### `UpdateSecondDelegatedAuthority`

Discriminator `7f1a06b5cbf87540` · data `UpdateSecondDelegatedAuthority` · accounts `UpdateSecondDelegatedAuthorityInstructionAccounts`.

No data fields.

Required accounts: 4; extras go to `remaining`.

Fields of `UpdateSecondDelegatedAuthorityInstructionAccounts`, in account order:

| #  | Field                            | Type               |
| -- | -------------------------------- | ------------------ |
| 0  | `global_admin`                   | `Pubkey`           |
| 1  | `farm_state`                     | `Pubkey`           |
| 2  | `global_config`                  | `Pubkey`           |
| 3  | `new_second_delegated_authority` | `Pubkey`           |
| 4… | `remaining`                      | `Vec<AccountMeta>` |

### `WithdrawFromFarmVault`

Discriminator `165280fa564f7c4e` · data `WithdrawFromFarmVault` · accounts `WithdrawFromFarmVaultInstructionAccounts`.

| Field    | Type  |
| -------- | ----- |
| `amount` | `u64` |

Required accounts: 6; extras go to `remaining`.

Fields of `WithdrawFromFarmVaultInstructionAccounts`, in account order:

| #  | Field                      | Type               |
| -- | -------------------------- | ------------------ |
| 0  | `withdraw_authority`       | `Pubkey`           |
| 1  | `farm_state`               | `Pubkey`           |
| 2  | `withdrawer_token_account` | `Pubkey`           |
| 3  | `farm_vault`               | `Pubkey`           |
| 4  | `farm_vaults_authority`    | `Pubkey`           |
| 5  | `token_program`            | `Pubkey`           |
| 6… | `remaining`                | `Vec<AccountMeta>` |

### `WithdrawReward`

Discriminator `bfbbb0890919bbf4` · data `WithdrawReward` · accounts `WithdrawRewardInstructionAccounts`.

| Field          | Type  |
| -------------- | ----- |
| `amount`       | `u64` |
| `reward_index` | `u64` |

Required accounts: 8; extras go to `remaining`.

Fields of `WithdrawRewardInstructionAccounts`, in account order:

| #  | Field                    | Type               |
| -- | ------------------------ | ------------------ |
| 0  | `farm_admin`             | `Pubkey`           |
| 1  | `farm_state`             | `Pubkey`           |
| 2  | `reward_mint`            | `Pubkey`           |
| 3  | `reward_vault`           | `Pubkey`           |
| 4  | `farm_vaults_authority`  | `Pubkey`           |
| 5  | `admin_reward_token_ata` | `Pubkey`           |
| 6  | `scope_prices`           | `Option<Pubkey>`   |
| 7  | `token_program`          | `Pubkey`           |
| 8… | `remaining`              | `Vec<AccountMeta>` |

### `WithdrawSlashedAmount`

Discriminator `cad9434aac168cd8` · data `WithdrawSlashedAmount` · accounts `WithdrawSlashedAmountInstructionAccounts`.

No data fields.

Required accounts: 6; extras go to `remaining`.

Fields of `WithdrawSlashedAmountInstructionAccounts`, in account order:

| #  | Field                          | Type               |
| -- | ------------------------------ | ------------------ |
| 0  | `crank`                        | `Pubkey`           |
| 1  | `farm_state`                   | `Pubkey`           |
| 2  | `slashed_amount_spill_address` | `Pubkey`           |
| 3  | `farm_vault`                   | `Pubkey`           |
| 4  | `farm_vaults_authority`        | `Pubkey`           |
| 5  | `token_program`                | `Pubkey`           |
| 6… | `remaining`                    | `Vec<AccountMeta>` |

### `WithdrawTreasury`

Discriminator `283f7a9e90d85360` · data `WithdrawTreasury` · accounts `WithdrawTreasuryInstructionAccounts`.

| Field    | Type  |
| -------- | ----- |
| `amount` | `u64` |

Required accounts: 7; extras go to `remaining`.

Fields of `WithdrawTreasuryInstructionAccounts`, in account order:

| #  | Field                                | Type               |
| -- | ------------------------------------ | ------------------ |
| 0  | `global_admin`                       | `Pubkey`           |
| 1  | `global_config`                      | `Pubkey`           |
| 2  | `reward_mint`                        | `Pubkey`           |
| 3  | `reward_treasury_vault`              | `Pubkey`           |
| 4  | `treasury_vault_authority`           | `Pubkey`           |
| 5  | `withdraw_destination_token_account` | `Pubkey`           |
| 6  | `token_program`                      | `Pubkey`           |
| 7… | `remaining`                          | `Vec<AccountMeta>` |

### `WithdrawUnstakedDeposits`

Discriminator `2466bb31dc248443` · data `WithdrawUnstakedDeposits` · accounts `WithdrawUnstakedDepositsInstructionAccounts`.

No data fields.

Required accounts: 7; extras go to `remaining`.

Fields of `WithdrawUnstakedDepositsInstructionAccounts`, in account order:

| #  | Field                   | Type               |
| -- | ----------------------- | ------------------ |
| 0  | `owner`                 | `Pubkey`           |
| 1  | `user_state`            | `Pubkey`           |
| 2  | `farm_state`            | `Pubkey`           |
| 3  | `user_ata`              | `Pubkey`           |
| 4  | `farm_vault`            | `Pubkey`           |
| 5  | `farm_vaults_authority` | `Pubkey`           |
| 6  | `token_program`         | `Pubkey`           |
| 7… | `remaining`             | `Vec<AccountMeta>` |

## Accounts

Variants of `KaminoFarmsAccount`. Each wraps a boxed struct from `carbon_kamino_farms_decoder::accounts::<module>`. `decode_account` only considers accounts owned by `PROGRAM_ID` and returns the first variant that matches.

### `FarmState`

Discriminator `c666d84a3f42a3be` · `accounts::farm_state::FarmState`.

| Field                                  | Type                              | Description                                                                                                                                                    |
| -------------------------------------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `farm_admin`                           | `Pubkey`                          |                                                                                                                                                                |
| `global_config`                        | `Pubkey`                          |                                                                                                                                                                |
| `token`                                | [`TokenInfo`](#tokeninfo)         |                                                                                                                                                                |
| `reward_infos`                         | [`[RewardInfo; 10]`](#rewardinfo) |                                                                                                                                                                |
| `num_reward_tokens`                    | `u64`                             |                                                                                                                                                                |
| `num_users`                            | `u64`                             | Data used to calculate the rewards of the user                                                                                                                 |
| `total_staked_amount`                  | `u64`                             | The number of token in the `farm_vault` staked (getting rewards and fees) Set such as `farm_vault.amount = total_staked_amount + total_pending_amount`         |
| `farm_vault`                           | `Pubkey`                          |                                                                                                                                                                |
| `farm_vaults_authority`                | `Pubkey`                          |                                                                                                                                                                |
| `farm_vaults_authority_bump`           | `u64`                             |                                                                                                                                                                |
| `delegate_authority`                   | `Pubkey`                          | Only used for delegate farms Set to `default()` otherwise                                                                                                      |
| `time_unit`                            | `u8`                              | Raw representation of a `TimeUnit` Seconds = 0, Slots = 1                                                                                                      |
| `is_farm_frozen`                       | `u8`                              | Automatically set to true in case of a full authority withdrawal If true, the farm is frozen and no more deposits are allowed                                  |
| `is_farm_delegated`                    | `u8`                              | Indicates if the farm is a delegate farm If true, the farm is a delegate farm and the `delegate_authority` is set\*                                            |
| `is_reward_user_once_enabled`          | `u8`                              | If set to 1, indicates that the "reward user once" feature is enabled                                                                                          |
| `is_harvesting_permissionless`         | `u8`                              |                                                                                                                                                                |
| `padding0`                             | `[u8; 3]`                         |                                                                                                                                                                |
| `withdraw_authority`                   | `Pubkey`                          | Withdraw authority for the farm, allowed to lock deposited funds and withdraw them Set to `default()` if unused (only the depositors can withdraw their funds) |
| `deposit_warmup_period`                | `u32`                             | Delay between a user deposit and the moment it is considered as staked 0 if unused                                                                             |
| `withdrawal_cooldown_period`           | `u32`                             | Delay between a user unstake and the ability to withdraw his deposit.                                                                                          |
| `total_active_stake_scaled`            | `u128`                            | Total active stake of tokens in the farm (scaled from `Decimal` representation).                                                                               |
| `total_pending_stake_scaled`           | `u128`                            | Total pending stake of tokens in the farm (scaled from `Decimal` representation). (can be used by `withdraw_authority` but don't get rewards or fees)          |
| `total_pending_amount`                 | `u64`                             | Total pending amount of tokens in the farm                                                                                                                     |
| `slashed_amount_current`               | `u64`                             | Slashed amounts from early withdrawal                                                                                                                          |
| `slashed_amount_cumulative`            | `u64`                             |                                                                                                                                                                |
| `slashed_amount_spill_address`         | `Pubkey`                          |                                                                                                                                                                |
| `locking_mode`                         | `u64`                             | Locking stake                                                                                                                                                  |
| `locking_start_timestamp`              | `u64`                             |                                                                                                                                                                |
| `locking_duration`                     | `u64`                             |                                                                                                                                                                |
| `locking_early_withdrawal_penalty_bps` | `u64`                             |                                                                                                                                                                |
| `deposit_cap_amount`                   | `u64`                             |                                                                                                                                                                |
| `scope_prices`                         | `Pubkey`                          |                                                                                                                                                                |
| `scope_oracle_price_id`                | `u64`                             |                                                                                                                                                                |
| `scope_oracle_max_age`                 | `u64`                             |                                                                                                                                                                |
| `pending_farm_admin`                   | `Pubkey`                          |                                                                                                                                                                |
| `strategy_id`                          | `Pubkey`                          |                                                                                                                                                                |
| `delegated_rps_admin`                  | `Pubkey`                          |                                                                                                                                                                |
| `vault_id`                             | `Pubkey`                          |                                                                                                                                                                |
| `second_delegated_authority`           | `Pubkey`                          |                                                                                                                                                                |
| `padding`                              | `[u64; 74]`                       |                                                                                                                                                                |

### `GlobalConfig`

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

| Field                            | Type          |
| -------------------------------- | ------------- |
| `global_admin`                   | `Pubkey`      |
| `treasury_fee_bps`               | `u64`         |
| `treasury_vaults_authority`      | `Pubkey`      |
| `treasury_vaults_authority_bump` | `u64`         |
| `pending_global_admin`           | `Pubkey`      |
| `padding1`                       | `[u128; 126]` |

### `OraclePrices`

Discriminator `598076dd0648b492` · `accounts::oracle_prices::OraclePrices`.

| Field             | Type                               |
| ----------------- | ---------------------------------- |
| `oracle_mappings` | `Pubkey`                           |
| `prices`          | [`[DatedPrice; 512]`](#datedprice) |

### `UserState`

Discriminator `48b155f94ca7ba7e` · `accounts::user_state::UserState`.

| Field                               | Type         | Description                                                                                                                                                                                                                                   |
| ----------------------------------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `user_id`                           | `u64`        |                                                                                                                                                                                                                                               |
| `farm_state`                        | `Pubkey`     |                                                                                                                                                                                                                                               |
| `owner`                             | `Pubkey`     |                                                                                                                                                                                                                                               |
| `is_farm_delegated`                 | `u8`         | Indicate if this user state is part of a delegated farm                                                                                                                                                                                       |
| `padding0`                          | `[u8; 7]`    |                                                                                                                                                                                                                                               |
| `rewards_tally_scaled`              | `[u128; 10]` | Rewards tally used for computation of gained rewards (scaled from `Decimal` representation).                                                                                                                                                  |
| `rewards_issued_unclaimed`          | `[u64; 10]`  | Number of reward tokens ready for claim                                                                                                                                                                                                       |
| `last_claim_ts`                     | `[u64; 10]`  |                                                                                                                                                                                                                                               |
| `active_stake_scaled`               | `u128`       | User stake deposited and usable, generating rewards and fees. (scaled from `Decimal` representation).                                                                                                                                         |
| `pending_deposit_stake_scaled`      | `u128`       | User stake deposited but not usable and not generating rewards yet. (scaled from `Decimal` representation).                                                                                                                                   |
| `pending_deposit_stake_ts`          | `u64`        | After this timestamp, pending user stake can be moved to user stake Initialized to now() + delayed user stake period                                                                                                                          |
| `pending_withdrawal_unstake_scaled` | `u128`       | User deposits unstaked, pending for withdrawal, not usable and not generating rewards. (scaled from `Decimal` representation).                                                                                                                |
| `pending_withdrawal_unstake_ts`     | `u64`        | After this timestamp, user can withdraw their deposit.                                                                                                                                                                                        |
| `bump`                              | `u64`        | User bump used for account address validation                                                                                                                                                                                                 |
| `delegatee`                         | `Pubkey`     | Delegatee used for initialisation - useful to check against                                                                                                                                                                                   |
| `last_stake_ts`                     | `u64`        |                                                                                                                                                                                                                                               |
| `rewards_issued_cumulative`         | `[u64; 10]`  | Cumulative rewards issued to the user - ONLY used for stats/analytics DO NOT USE IN ANY CALCULATIONS Old userStates will have this field populated only from the point of release not reflecting any historical data before this was released |
| `padding1`                          | `[u64; 40]`  |                                                                                                                                                                                                                                               |

## Types

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

### `DatedPrice`

Struct `types::DatedPrice`.

| Field               | Type              |
| ------------------- | ----------------- |
| `price`             | [`Price`](#price) |
| `last_updated_slot` | `u64`             |
| `unix_timestamp`    | `u64`             |
| `reserved`          | `[u64; 2]`        |
| `reserved2`         | `[u16; 3]`        |
| `index`             | `u16`             |

### `FarmConfigOption`

Enum `types::FarmConfigOption`.

| Variant                            |
| ---------------------------------- |
| `UpdateRewardRps`                  |
| `UpdateRewardMinClaimDuration`     |
| `WithdrawAuthority`                |
| `DepositWarmupPeriod`              |
| `WithdrawCooldownPeriod`           |
| `RewardType`                       |
| `RpsDecimals`                      |
| `LockingMode`                      |
| `LockingStartTimestamp`            |
| `LockingDuration`                  |
| `LockingEarlyWithdrawalPenaltyBps` |
| `DepositCapAmount`                 |
| `SlashedAmountSpillAddress`        |
| `ScopePricesAccount`               |
| `ScopeOraclePriceId`               |
| `ScopeOracleMaxAge`                |
| `UpdateRewardScheduleCurvePoints`  |
| `UpdatePendingFarmAdmin`           |
| `UpdateStrategyId`                 |
| `UpdateDelegatedRpsAdmin`          |
| `UpdateVaultId`                    |
| `UpdateExtraDelegatedAuthority`    |
| `UpdateIsRewardUserOnceEnabled`    |
| `UpdateDelegatedAuthority`         |
| `UpdateIsHarvestingPermissionless` |

### `GlobalConfigOption`

Enum `types::GlobalConfigOption`.

| Variant                 |
| ----------------------- |
| `SetPendingGlobalAdmin` |
| `SetTreasuryFeeBps`     |

### `LockingMode`

Enum `types::LockingMode`.

| Variant      |
| ------------ |
| `None`       |
| `Continuous` |
| `WithExpiry` |

### `Price`

Struct `types::Price`.

| Field   | Type  |
| ------- | ----- |
| `value` | `u64` |
| `exp`   | `u64` |

### `RewardInfo`

Struct `types::RewardInfo`.

| Field                         | Type                                          |
| ----------------------------- | --------------------------------------------- |
| `token`                       | [`TokenInfo`](#tokeninfo)                     |
| `rewards_vault`               | `Pubkey`                                      |
| `rewards_available`           | `u64`                                         |
| `reward_schedule_curve`       | [`RewardScheduleCurve`](#rewardschedulecurve) |
| `min_claim_duration_seconds`  | `u64`                                         |
| `last_issuance_ts`            | `u64`                                         |
| `rewards_issued_unclaimed`    | `u64`                                         |
| `rewards_issued_cumulative`   | `u64`                                         |
| `reward_per_share_scaled`     | `u128`                                        |
| `placeholder0`                | `u64`                                         |
| `reward_type`                 | `u8`                                          |
| `rewards_per_second_decimals` | `u8`                                          |
| `padding0`                    | `[u8; 6]`                                     |
| `padding1`                    | `[u64; 20]`                                   |

### `RewardPerTimeUnitPoint`

Struct `types::RewardPerTimeUnitPoint`.

| Field                  | Type  |
| ---------------------- | ----- |
| `ts_start`             | `u64` |
| `reward_per_time_unit` | `u64` |

### `RewardScheduleCurve`

Struct `types::RewardScheduleCurve`.

| Field    | Type                                                      | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| -------- | --------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `points` | [`[RewardPerTimeUnitPoint; 20]`](#rewardpertimeunitpoint) | This is a stepwise function, meaning that each point represents how many rewards are issued per time unit since the beginning of that point until the beginning of the next point. This is not a linear curve, there is no interpolation going on. A curve can be \[\[t0, 100], \[t1, 50], \[t2, 0]] meaning that from t0 to t1, 100 rewards are issued per time unit, from t1 to t2, 50 rewards are issued per time unit, and after t2 it stops Another curve, can be \[\[t0, 100], \[u64::max, 0]] meaning that from t0 to u64::max, 100 rewards are issued per time unit |

### `RewardType`

Enum `types::RewardType`.

| Variant        |
| -------------- |
| `Proportional` |
| `Constant`     |

### `TimeUnit`

Enum `types::TimeUnit`.

| Variant   |
| --------- |
| `Seconds` |
| `Slots`   |

### `TokenInfo`

Struct `types::TokenInfo`.

| Field           | Type       |
| --------------- | ---------- |
| `mint`          | `Pubkey`   |
| `decimals`      | `u64`      |
| `token_program` | `Pubkey`   |
| `padding`       | `[u64; 6]` |

---

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