<div align="center">
  <img src="https://raw.githubusercontent.com/arcium-hq/.github/refs/heads/main/profile/arcium.svg" alt="Arcium" width="200"/>

<h1>arcium-anchor</h1>

<p>Anchor integration helpers for Arcium-enabled Solana programs.</p>

[![Crates.io](https://img.shields.io/crates/v/arcium-anchor.svg)](https://crates.io/crates/arcium-anchor)
[![Docs.rs](https://docs.rs/arcium-anchor/badge.svg)](https://docs.rs/arcium-anchor)

**[Developer Docs](https://docs.arcium.com/developers/program)**

</div>

## When To Use

- Queuing Arcium computations from Anchor instructions
- Initializing computation definitions on-chain
- Verifying typed callback outputs inside Anchor programs

For non-Anchor clients, use [`arcium-client`](https://crates.io/crates/arcium-client). For circuit code, use [`arcis`](https://crates.io/crates/arcis).

## Installation

```toml
[dependencies]
anchor-lang = "1.0.2"
arcium-anchor = "0.11.1"
arcium-macros = "0.11.1"
```

Optional features:

```toml
arcium-anchor = { version = "0.11.1", features = ["idl-build"] }
```

| Feature | Description |
|---------|-------------|
| `idl-build` | Include Arcium types in Anchor IDL generation. |
| `multi-tx-callbacks` | Enable multi-transaction callback support for large outputs. |

## Quick Start

```rust
use arcium_anchor::prelude::*;

let args = ArgBuilder::new()
    .plaintext_u64(42)
    .build();

queue_computation(
    &ctx.accounts,
    computation_offset,
    args,
    vec![],
    1, // num_callback_txs
    0, // cu_price_micro
    0, // callback_cu_limit
)?;
```

Verify callback output with:

```rust
let result = output.verify_output(
    &ctx.accounts.cluster_account,
    &ctx.accounts.computation_account,
)?;
```

## Main APIs

| Item | Description |
|------|-------------|
| `queue_computation()` | Queue a computation from an Anchor program. |
| `init_computation_def()` | Initialize a computation definition account. |
| `SignedComputationOutputs<T>` | Typed callback output with signature verification helpers. |
| `RawComputationOutputs<T>` | Raw callback output for manual decoding flows. |
| `ArgBuilder` | Build plaintext, encrypted, and account arguments for queueing. |
| `comp_def_offset()` | Compute the deterministic offset for a circuit name. |

## Macros And PDA Helpers

Most projects use `arcium-anchor` together with [`arcium-macros`](https://crates.io/crates/arcium-macros):

- `#[arcium_program]`
- `#[queue_computation_accounts]`
- `#[callback_accounts]`
- `#[init_computation_definition_accounts]`
- `#[arcium_callback]`

The crate also exposes PDA helpers such as:

- `derive_mxe_pda!`
- `derive_mempool_pda!`
- `derive_execpool_pda!`
- `derive_comp_def_pda!`
- `derive_cluster_pda!`

## See Also

- [`arcium-macros`](https://crates.io/crates/arcium-macros)
- [`arcium-client`](https://crates.io/crates/arcium-client)
- [`arcis`](https://crates.io/crates/arcis)
- [Developer Docs](https://docs.arcium.com/developers/program)
