Skip to main content

Crate a2a_swap_sdk

Crate a2a_swap_sdk 

Source
Expand description

A2A-Swap Rust SDK

Agent-native constant-product AMM client for Solana. Any Rust agent can swap, provide liquidity, and query pool state with zero boilerplate — no Anchor dependency required.

§Quick Start

use a2a_swap_sdk::{A2ASwapClient, SimulateParams, SwapParams};
use solana_sdk::{pubkey::Pubkey, signature::Keypair};
use std::str::FromStr;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = A2ASwapClient::devnet();
    let keypair = Keypair::new(); // use your agent's funded keypair

    let sol  = Pubkey::from_str("So11111111111111111111111111111111111111112")?;
    let usdc = Pubkey::from_str("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v")?;

    // 1. Simulate first to check the trade
    let sim = client.simulate(SimulateParams {
        mint_in: sol, mint_out: usdc, amount_in: 1_000_000_000,
    }).await?;
    println!("Estimated out: {}  price_impact: {:.2}%", sim.estimated_out, sim.price_impact_pct);

    // 2. Execute with 0.5% max slippage
    let result = client.convert(&keypair, SwapParams {
        mint_in:          sol,
        mint_out:         usdc,
        amount_in:        1_000_000_000,
        max_slippage_bps: 50,
    }).await?;
    println!("Swapped! tx: {}", result.signature);

    Ok(())
}

§Feature Overview

MethodDescription
A2ASwapClient::create_poolCreate a new pool for a mint pair
A2ASwapClient::provide_liquidityDeposit tokens, receive LP shares
A2ASwapClient::convertAtomic token swap
A2ASwapClient::simulateOff-chain fee + slippage breakdown
A2ASwapClient::pool_infoPool reserves, price, fee rate
A2ASwapClient::my_positionsAll LP positions for an owner
A2ASwapClient::my_feesAggregated claimable fees

Re-exports§

pub use client::A2ASwapClient;
pub use error::Error;
pub use error::Result;
pub use types::*;

Modules§

client
A2ASwapClient — the main entry point for agent integrations.
error
SDK error type.
instructions
Low-level Anchor instruction builders.
math
Fee constants and simulation math.
state
On-chain account deserialization.
types
Parameter and result types for every SDK operation.