Skip to content

feat : Implemented Solana Agentic Autopay Suite#135

Open
Terry3nty wants to merge 1 commit into
zeroclaw-labs:mainfrom
Terry3nty:main
Open

feat : Implemented Solana Agentic Autopay Suite#135
Terry3nty wants to merge 1 commit into
zeroclaw-labs:mainfrom
Terry3nty:main

Conversation

@Terry3nty

Copy link
Copy Markdown

Solana Agentic Autopay (SAA) Protocol Suite

This PR introduces the Solana Agentic Autopay (SAA) protocol suite to ZeroClaw plugins, providing a non-custodial "Direct Debit" payment system for autonomous AI agents on Solana via native SPL Token Delegation.

Included Plugins & Modules

  1. plugins/solana-plugin-core (Shared Substrate - Track E):

    • Pure-Rust lightweight crate for Base58, Pubkey, Instruction/Message/Transaction serialization.
    • Offline deterministic PDA and Associated Token Account (ATA) address derivation.
    • Decoupled HttpRequester trait for clean host testing and sandboxed waki WASM execution.
  2. plugins/autopay-delegate (T1 Tool Plugin):

    • Generates an unsigned Base64 SPL Token Approve transaction for the owner to delegate spending allowance to the agent.
    • Zero permissions required (permissions = []).
  3. plugins/autopay-charge (T2 Tool Plugin):

    • Autonomously signs and submits SPL Token transfer payments using the agent's delegated spending power.
    • Security Guardrails: Enforces delegated balance checks and plugin-level daily spend caps by querying RPC transaction history over the last 24 hours.
    • Fail-Closed Security: Rejects signatures and blocks transactions if daily caps or allowances are exceeded (resisting prompt injection attacks).

Verification & Testing

  • Host Tests: All 7 host unit and integration tests (cargo test) pass cleanly across all crates without live network dependency.
  • WASM Component Compilation: Both autopay-delegate and autopay-charge build cleanly targeting wasm32-wasip2 in release mode.

Copilot AI review requested due to automatic review settings July 22, 2026 17:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the Solana Agentic Autopay (SAA) suite to the ZeroClaw plugins repo: a shared Rust core for Solana serialization/RPC helpers plus two tool plugins for building an SPL Token delegation approval transaction (T1) and executing delegated token transfers with a daily spend cap (T2).

Changes:

  • Introduces solana-plugin-core with Pubkey/PDA+ATA derivation, legacy transaction/message serialization, and JSON-RPC helper utilities.
  • Adds autopay-delegate tool plugin to generate an unsigned SPL Token Approve transaction.
  • Adds autopay-charge tool plugin to sign/submit delegated SPL Token transfers and enforce a daily cap via RPC history scanning.

Reviewed changes

Copilot reviewed 14 out of 17 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
plugins/solana-plugin-core/src/lib.rs Implements Solana primitives (Pubkey, PDA/ATA, message/tx serialization) and RPC helpers used by the autopay tools.
plugins/solana-plugin-core/Cargo.toml Defines the new shared core crate and its dependencies.
plugins/solana-plugin-core/Cargo.lock Locks dependencies for deterministic builds of the core crate.
plugins/autopay-delegate/src/lib.rs WASM tool-plugin component wrapper and argument parsing for the delegate transaction builder.
plugins/autopay-delegate/src/delegate.rs Builds the unsigned SPL Token Approve transaction and returns it base64-encoded.
plugins/autopay-delegate/tests/delegate.rs Adds a basic host test for building the delegate transaction.
plugins/autopay-delegate/README.md Documents the T1 delegate plugin behavior, usage, and threat model.
plugins/autopay-delegate/manifest.toml Declares plugin metadata/capabilities/permissions for autopay-delegate.
plugins/autopay-delegate/Cargo.toml Defines the autopay-delegate crate configuration and dependencies.
plugins/autopay-delegate/Cargo.lock Locks dependencies for deterministic builds of the delegate plugin.
plugins/autopay-charge/src/lib.rs WASM tool-plugin component wrapper and config parsing for autonomous charges.
plugins/autopay-charge/src/charge.rs Implements the delegated transfer execution flow and daily-cap enforcement.
plugins/autopay-charge/tests/charge.rs Adds host tests for success, insufficient allowance, and daily-cap exceeded cases.
plugins/autopay-charge/README.md Documents the T2 charge plugin behavior, usage, and threat model.
plugins/autopay-charge/manifest.toml Declares plugin metadata/capabilities/permissions for autopay-charge.
plugins/autopay-charge/Cargo.toml Defines the autopay-charge crate configuration and dependencies (incl. wasm-only HTTP).
plugins/autopay-charge/Cargo.lock Locks dependencies for deterministic builds of the charge plugin.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +62 to +74
pub fn find_program_address(seeds: &[&[u8]], program_id: &Pubkey) -> Option<(Pubkey, u8)> {
let mut bump = 255u8;
while bump > 0 {
let mut seeds_with_bump = seeds.to_vec();
let bump_slice = [bump];
seeds_with_bump.push(&bump_slice);
if let Some(addr) = create_program_address(&seeds_with_bump, program_id) {
return Some((addr, bump));
}
bump -= 1;
}
None
}
Comment on lines +323 to +332
pub fn sign(&mut self, keypairs: &[ed25519_dalek::SigningKey]) {
let message_bytes = self.message.serialize();
for (i, key) in keypairs.iter().enumerate() {
if i < self.signatures.len() {
use ed25519_dalek::Signer;
let sig = key.sign(&message_bytes);
self.signatures[i] = sig.to_bytes();
}
}
}
Comment on lines +548 to +551
let result = &parsed["result"];
if result.is_null() {
return Ok(0);
}
Comment on lines +53 to +56
// 3. Enforce Daily Cap (scan transactions in the last 24 hours)
let sigs = get_signatures_for_address(requester, rpc_url, &agent_pubkey, 20)
.map_err(|e| format!("Failed to query transaction history: {e}"))?;

Comment on lines +74 to +78
// Query transaction details to see how much was spent from user_ata
let amt = get_transaction_transfer_amount(requester, rpc_url, &sig.signature, &user_ata)
.unwrap_or(0); // If query fails, fail safe or log (we assume 0 for simplicity or we can fail closed)

spent_24h += amt;
Part of the **Solana Agentic Autopay (SAA)** suite. A T1 (Build) tool plugin that constructs an unsigned transaction for the owner to delegate SPL Token spending power to the agent.

## What It Does
Generates an unsigned transaction in Base58 legacy format that authorizes the agent's public key to spend up to a specific limit of SPL tokens (e.g., USDC) from the user's wallet. The user signs this transaction via their browser wallet or phone interface. The agent never gains access to the user's private key.

## Threat Model & Security Guardrails
* **Threat 1: Prompt Injection / Compromised LLM**
* *Attack*: An attacker tricks the agent into transfering all user funds to their account.
Comment on lines +6 to +9
let owner = Pubkey::from_string("DBD8hAwLDRQkTsu6EqviaYNGKPnsAMmQonxf7AH8ZcFY").unwrap();
let delegate = Pubkey::from_string("4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU").unwrap();
let mint = Pubkey::from_string("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL").unwrap();
let amount = 50_000_000u64; // 50 USDC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants