| Crates.io | cambrian-rust-sdk |
| lib.rs | cambrian-rust-sdk |
| version | 0.1.0 |
| created_at | 2025-04-25 11:47:27.744945+00 |
| updated_at | 2025-04-25 11:47:27.744945+00 |
| description | Rust SDK for building Cambrian payload containers for Actively Validated Services (AVS) |
| homepage | |
| repository | https://github.com/cambrianone/payload-images |
| max_upload_size | |
| id | 1648915 |
| size | 52,326 |
A Rust library for building payload containers that integrate with the Cambrian platform's Actively Validated Services (AVS) ecosystem.
This SDK provides the core types and utilities needed to create Rust-based Cambrian payload containers. It simplifies the process of:
CAMB_INPUT environment variableAdd this crate to your Cargo.toml:
[dependencies]
cambrian-rust-sdk = "0.1.0"
use std::env;
use std::str::FromStr;
use anyhow::{Context, Result};
use cambrian_rust_sdk::{Input, Response};
use solana_program::instruction::{AccountMeta, Instruction};
use solana_program::pubkey::Pubkey;
fn main() -> Result<()> {
// Parse input from environment variable
let input: Input = serde_json::from_str(&env::var("CAMB_INPUT").unwrap_or_default())
.context("Invalid CAMB_INPUT JSON")?;
// Create a Solana instruction (simplified example)
let program_id = Pubkey::from_str("Your_Program_ID_Here")?;
let instruction = Instruction {
program_id,
accounts: vec![
AccountMeta::new(Pubkey::from_str("Account_Address_Here")?, false),
AccountMeta::new_readonly(Pubkey::from_str("ReadOnly_Account_Here")?, true),
],
data: vec![0, 1, 2, 3], // Instruction data
};
// Convert to Cambrian format and output JSON
println!("{}", Response::from(instruction).to_output_ix()?);
Ok(())
}
The SDK provides Rust types that match the Cambrian payload input/output formats:
Input: Parses the JSON structure from CAMB_INPUT environment variableResponse: The complete output format with proposal instructionsProposalInstruction: Represents a single instruction in the outputAccountMeta: Account metadata with address and role informationAccountRole: Enum representing the account role bitflagsThe SDK includes conversions between Solana types and Cambrian payload formats:
From<Instruction> for ProposalInstructionFrom<&Instruction> for ProposalInstructionFrom<Instruction> for ResponseFrom<&Instruction> for ResponseFrom<Vec<Instruction>> for ResponseFrom<&[Instruction]> for ResponseAccount roles are represented using a bitflag system:
0b00 = READONLY (not a signer, not writable)
0b01 = WRITABLE (not a signer, writable)
0b10 = READONLY_SIGNER (signer, not writable)
0b11 = WRITABLE_SIGNER (signer, writable)
The SDK handles this conversion for you with From<(bool, bool)> for AccountRole.
For a complete example of using this SDK, see the check-oracle-rust payload in the Cambrian payload images repository.
This project is licensed under the MIT License - see the LICENSE file for details.