A technical demo for Solana Native Subscriptions and Allowances showing how an AI agent can operate with a bounded budget instead of direct wallet custody.
The user grants a fixed or recurring allowance to an agent-controlled delegate. The agent can propose actions such as API calls, swaps, or content purchases, but the local guard checks:
- cap remaining
- expiration
- per-action maximum
- allowed merchant/program category
- suspicious approval flags
Only safe actions are converted into an execution plan. Risky or out-of-policy actions are rejected before any on-chain transfer attempt.
This aligns with the official primitive:
- Solana describes allowances as fixed delegation with a cap and optional expiration, suitable for autonomous agents operating inside a budget.
- The official
solana-foundation/subscriptionsREADME documents fixed delegation, recurring delegation, subscription plans, and@solana/subscriptionsclient methods such ascreateFixedDelegation,transferFixed,createRecurringDelegation, andtransferRecurring.
src/agentAllowanceGuard.ts: runnable TypeScript-style demo logic with sample decisions.src/subscriptionsAdapter.ts: adapter boundary showing where the official@solana/subscriptionsSDK calls fit.sample-output.json: expected output from the demo scenario.
A Canadian analytics agent receives a 25 USDC fixed allowance for pay-per-call data tasks. It tries four actions:
- Pay 3.50 USDC for an approved API call: allowed.
- Pay 6.00 USDC for a second approved API call: allowed.
- Attempt 18.00 USDC swap on an unknown program: rejected for merchant/category risk.
- Attempt 30.00 USDC spend: rejected because it exceeds both per-action max and remaining allowance.
The demo shows how subscriptions and allowances let a user separate permission from custody. An AI agent can be productive, but it cannot exceed the user's pre-authorized budget or merchant scope.
npm install
npm run demoThis gist is intentionally offline-safe: it does not require private keys, wallets, RPC calls, or funds. The adapter file marks the exact place where a production implementation would call the official Solana subscriptions client.