Skip to content

feat: AI agent trade confinement via slippage oracle + ProgramExec - #142

Draft
zmanian wants to merge 8 commits into
anagrambuild:mainfrom
zmanian:feat/ai-agent-confinement
Draft

feat: AI agent trade confinement via slippage oracle + ProgramExec#142
zmanian wants to merge 8 commits into
anagrambuild:mainfrom
zmanian:feat/ai-agent-confinement

Conversation

@zmanian

@zmanian zmanian commented Mar 7, 2026

Copy link
Copy Markdown

Summary

  • Add slippage-oracle on-chain program that validates trade input/output ratios using basis points, enabling ratio-based slippage enforcement before Swig SignV2 execution
  • Add AgentRoleConfig SDK helper that composes ProgramExec authority + spending limits + program permissions into a single builder for confined AI agent roles
  • Add SignV2Instruction::new_program_exec unit tests for the interface constructor
  • Integration tests covering the full confinement model: oracle validation, SOL spending limits, and ProgramExec authentication
  • Documentation covering the three-layer defense model (oracle + spending limits + hash integrity)

Design

Three-layer confinement for AI agents doing trades:

  1. Slippage oracle -- validates min_output_amount >= (input_amount * min_bps) / 10000 before Swig executes
  2. Spending limits -- Swig's post-execution TokenLimit/SolLimit caps absolute loss
  3. Hash integrity -- Swig's post-execution SHA256 check prevents unauthorized state mutations

The agent holds a ProgramExec authority bound to the oracle. It must call the oracle first (which validates trade parameters), and that successful call authenticates the subsequent SignV2.

Test Plan

  • Oracle unit tests: ratio pass, ratio fail, missing accounts, min_bps=0 edge case, input_amount=0 edge case
  • SDK unit tests: 5 AgentRoleConfig builder tests
  • Interface unit tests: 4 new_program_exec tests
  • Integration tests: agent within limits, SOL limit exceeded, bad slippage rejected, missing oracle ix rejected
  • E2E SDK test: role creation with AgentRoleConfig
  • Full SBF build + on-chain integration tests (requires cargo build-sbf)

🤖 Generated with Claude Code

zmanian and others added 8 commits March 7, 2026 13:44
Add a new on-chain Solana program for validating trade parameters
(slippage ratios) as part of AI agent confinement. Uses pinocchio 0.9
consistent with the rest of the workspace. Includes stub processor
with VALIDATE_TRADE discriminator and error types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add unit tests for the existing new_program_exec, new_program_exec_with_ix_index,
and build_program_exec_authority_payload functions. Tests verify that the
instructions sysvar account is correctly included in the transaction accounts
and that the authority payload is correctly formatted for both the default
(current_index - 1) and explicit target instruction index cases.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…Exec + limits

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a high-level builder that produces ProgramExec/ProgramExecSession
authority data and ClientAction permissions for trade-confined agent
roles with SOL/token spending limits and program access controls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add comment explaining why oracle doesn't validate Swig accounts
- Document reserved InvalidSwigAccount error variant
- Clarify session_max_length is not encoded in authority_data
- Add edge case tests: min_bps=0 and input_amount=0

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant