Skip to content

Commit

Permalink
chore: update anda_icp document
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Jan 22, 2025
1 parent 727bc0b commit 97f1390
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/anda_icp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "anda_icp"
description = "Anda agent tools offers integration with the Internet Computer (ICP)."
repository = "https://github.com/ldclabs/anda/tree/main/tools/anda_icp"
publish = true
version = "0.2.0"
version = "0.2.1"
edition.workspace = true
keywords.workspace = true
categories.workspace = true
Expand Down
9 changes: 6 additions & 3 deletions tools/anda_icp/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# `anda_icp`
# `anda_icp` - Enables AI Agent to interact with ICP blockchain

[![Crates.io](https://img.shields.io/crates/v/anda_icp)](https://crates.io/crates/anda_icp)
[![Documentation](https://docs.rs/anda_icp/badge.svg)](https://docs.rs/anda_icp)
![License](https://img.shields.io/crates/l/anda_icp.svg)
[![Crates.io](https://img.shields.io/crates/d/anda_icp.svg)](https://crates.io/crates/anda_icp)
[![Test](https://github.com/ldclabs/anda/actions/workflows/test.yml/badge.svg)](https://github.com/ldclabs/anda/actions/workflows/test.yml)
[![Docs.rs](https://docs.rs/anda_icp/badge.svg)](https://docs.rs/anda_icp)
[![Latest Version](https://img.shields.io/crates/v/anda_icp.svg)](https://crates.io/crates/anda_icp)

`anda_icp` provides integration between the Anda agent framework and the Internet Computer (ICP) blockchain, enabling AI Agents to directly interact with ICP blockchain functionalities. Current features include:

Expand Down
7 changes: 7 additions & 0 deletions tools/anda_icp/src/ledger/balance.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
//! Enables AI Agent to query the balance of an account for a ICP token
//!
//! This module provides functionality for querying account balances on the ICP network.
//! It implements the `Tool` trait to enable AI agents to interact with ICP ledgers.
use anda_core::{BoxError, FunctionDefinition, Tool};
use anda_engine::context::BaseCtx;
use candid::Nat;
Expand Down Expand Up @@ -37,6 +42,8 @@ impl BalanceOfTool {
}
}

/// Implementation of the Tool trait for BalanceOfTool
/// Enables AI Agent to query the balance of an account for a ICP token
impl Tool<BaseCtx> for BalanceOfTool {
const CONTINUE: bool = true;
type Args = BalanceOfArgs;
Expand Down
27 changes: 26 additions & 1 deletion tools/anda_icp/src/ledger/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
//! Module for interacting with ICP Ledgers using ICRC-1 standard
//!
//! This module provides functionality for:
//! - Loading and managing multiple ICP ledger canisters
//! - Transferring tokens between accounts
//! - Querying account balances
//!
//! The implementation supports:
//! - Multiple token symbols (though primarily designed for ICP)
//! - Configurable subaccount usage for transfers
//! - ICRC-1 standard compliant operations
//!
//! # Examples
//! ```rust
//! use anda_icp::ledger::ICPLedgers;
//! use anda_core::CanisterCaller;
//! use std::collections::BTreeSet;
//!
//! async fn example(ctx: &impl CanisterCaller) {
//! let canisters = BTreeSet::from([Principal::from_text("ryjl3-tyaaa-aaaaa-aaaba-cai").unwrap()]);
//! let ledgers = ICPLedgers::load(ctx, canisters, false).await.unwrap();
//! // Use ledgers for transfers or balance queries
//! }
//! ```
use anda_core::{BoxError, CanisterCaller};
use candid::{Nat, Principal};
use icrc_ledger_types::{
Expand Down Expand Up @@ -27,7 +52,7 @@ pub struct ICPLedgers {

impl ICPLedgers {
/// Creates a new ICPLedgerTransfer instance
///
///
/// # Arguments
/// * `ctx` - Canister caller context
/// * `ledger_canisters` - Set of 1 to N ICP token ledger canister IDs
Expand Down
13 changes: 12 additions & 1 deletion tools/anda_icp/src/ledger/transfer.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
//! Enables AI Agent to perform ICP token transfers
//!
//! Provides functionality for transferring tokens between accounts on the Internet Computer Protocol (ICP) network.
//! Supports:
//! - Multiple token types (e.g., ICP, PANDA)
//! - Memo fields for transaction identification
//! - Integration with ICP ledger standards
//! - Atomic transfers with proper error handling
use anda_core::{BoxError, FunctionDefinition, Tool};
use anda_engine::context::BaseCtx;
use candid::Nat;
Expand All @@ -21,7 +30,7 @@ pub struct TransferToArgs {
pub memo: Option<String>,
}

/// ICP Ledger Transfer tool implementation
/// Implementation of the ICP Ledger Transfer tool
#[derive(Debug, Clone)]
pub struct TransferTool {
ledgers: Arc<ICPLedgers>,
Expand All @@ -40,6 +49,8 @@ impl TransferTool {
}
}

/// Implementation of the Tool trait for TransferTool
/// Enables AI Agent to perform ICP token transfers
impl Tool<BaseCtx> for TransferTool {
const CONTINUE: bool = true;
type Args = TransferToArgs;
Expand Down

0 comments on commit 97f1390

Please sign in to comment.