Rust SDK
High-performance Rust SDK for AUTONEX. Ideal for production agents requiring maximum performance and native Solana integration.
Installation
Add to your Cargo.toml:
[dependencies]
autonex-sdk = "0.1.0"
solana-sdk = "1.18"
tokio = { version = "1", features = ["full"] }Quick Start
Initialize Client
use autonex_sdk::{Client, Config};
use solana_sdk::signature::Keypair;
#[tokio::main]
async fn main() -> Result<()> {
// Initialize client
let config = Config {
rpc_url: env::var("SOLANA_RPC_URL")?,
agent_keypair: Keypair::from_bytes(&keypair_bytes)?,
policy_set: "my-agent-policy".to_string(),
network: Network::MainnetBeta,
};
let client = Client::new(config).await?;
Ok(())
}Submit Intent
use autonex_sdk::{Intent, SwapParams, Token};
// Create swap intent
let intent = Intent::Swap(SwapParams {
from: Token::SOL,
amount: 5_000_000_000, // lamports
to: Token::USDC,
max_slippage_bps: 200, // 2%
deadline: SystemTime::now() + Duration::from_secs(60),
});
// Execute
let receipt = client.execute(intent).await?;
println!("Transaction: {}", receipt.signature);
println!("Amount out: {}", receipt.execution.amount_out);
println!("Slippage: {:.2}%", receipt.execution.actual_slippage * 100.0);API Reference
Client
Main client struct for AUTONEX operations.
Methods
execute(&self, intent: Intent): Execute an intentsimulate(&self, intent: Intent): Simulate executionget_receipt(&self, signature: Signature): Fetch receiptget_policy(&self, name: &str): Get policy configurationdeploy_policy(&self, policy: Policy): Deploy policy
Intent Enum
All supported intent types:
Intent::Swap(SwapParams)Intent::Transfer(TransferParams)Intent::Stake(StakeParams)Intent::Lend(LendParams)Intent::YieldFarm(YieldParams)
Policy Management
Create and deploy policies with the builder pattern:
use autonex_sdk::{PolicyBuilder, PolicyRule};
// Build policy
let policy = PolicyBuilder::new("trading-agent")
.add_rule(PolicyRule::TransactionLimit {
amount: 10_000_000_000, // 10 SOL
token: Token::SOL,
period: Period::Daily,
})
.add_rule(PolicyRule::SlippageProtection {
max_slippage_bps: 200,
})
.add_rule(PolicyRule::WhitelistPrograms {
programs: vec![
jupiter_program_id,
orca_program_id,
],
})
.build()?;
// Deploy on-chain
client.deploy_policy(policy).await?;Error Handling
The SDK uses the Result type with custom error enum:
Error::IntentValidation(String)Error::PolicyRejection(PolicyResult)Error::Execution(ExecutionError)Error::Network(NetworkError)
Performance
The Rust SDK is optimized for high throughput:
- Zero-copy deserialization where possible
- Async/await with Tokio runtime
- Connection pooling for RPC calls
- Parallel intent execution
Safety
The SDK leverages Rust's type system for safety:
- Compile-time intent validation
- No null pointer exceptions
- Memory safety guarantees
- Thread safety with Send/Sync
Examples
See the examples directory for complete implementations:
- Basic trading agent
- High-frequency strategy
- Multi-threaded agent pool
- Custom policy deployment