@agent-shield/plugin-solana-agent-kit 0.1.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +173 -31
  2. package/dist/factory.d.ts +29 -0
  3. package/dist/factory.d.ts.map +1 -0
  4. package/dist/factory.js +47 -0
  5. package/dist/factory.js.map +1 -0
  6. package/dist/index.d.ts +30 -102
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +44 -50
  9. package/dist/index.js.map +1 -1
  10. package/dist/tools/index.d.ts +4 -6
  11. package/dist/tools/index.d.ts.map +1 -1
  12. package/dist/tools/index.js +13 -19
  13. package/dist/tools/index.js.map +1 -1
  14. package/dist/tools/pauseResume.d.ts +12 -0
  15. package/dist/tools/pauseResume.d.ts.map +1 -0
  16. package/dist/tools/pauseResume.js +21 -0
  17. package/dist/tools/pauseResume.js.map +1 -0
  18. package/dist/tools/status.d.ts +6 -0
  19. package/dist/tools/status.d.ts.map +1 -0
  20. package/dist/tools/status.js +35 -0
  21. package/dist/tools/status.js.map +1 -0
  22. package/dist/tools/transactionHistory.d.ts +6 -0
  23. package/dist/tools/transactionHistory.d.ts.map +1 -0
  24. package/dist/tools/transactionHistory.js +40 -0
  25. package/dist/tools/transactionHistory.js.map +1 -0
  26. package/dist/tools/updatePolicy.d.ts +15 -0
  27. package/dist/tools/updatePolicy.d.ts.map +1 -0
  28. package/dist/tools/updatePolicy.js +34 -0
  29. package/dist/tools/updatePolicy.js.map +1 -0
  30. package/dist/types.d.ts +27 -8
  31. package/dist/types.d.ts.map +1 -1
  32. package/dist/types.js +21 -0
  33. package/dist/types.js.map +1 -1
  34. package/package.json +13 -9
  35. package/dist/client-factory.d.ts +0 -4
  36. package/dist/client-factory.d.ts.map +0 -1
  37. package/dist/client-factory.js +0 -23
  38. package/dist/client-factory.js.map +0 -1
  39. package/dist/tools/checkBalance.d.ts +0 -12
  40. package/dist/tools/checkBalance.d.ts.map +0 -1
  41. package/dist/tools/checkBalance.js +0 -38
  42. package/dist/tools/checkBalance.js.map +0 -1
  43. package/dist/tools/checkPolicy.d.ts +0 -12
  44. package/dist/tools/checkPolicy.d.ts.map +0 -1
  45. package/dist/tools/checkPolicy.js +0 -38
  46. package/dist/tools/checkPolicy.js.map +0 -1
  47. package/dist/tools/checkSpending.d.ts +0 -12
  48. package/dist/tools/checkSpending.d.ts.map +0 -1
  49. package/dist/tools/checkSpending.js +0 -63
  50. package/dist/tools/checkSpending.js.map +0 -1
  51. package/dist/tools/closePosition.d.ts +0 -27
  52. package/dist/tools/closePosition.d.ts.map +0 -1
  53. package/dist/tools/closePosition.js +0 -35
  54. package/dist/tools/closePosition.js.map +0 -1
  55. package/dist/tools/openPosition.d.ts +0 -33
  56. package/dist/tools/openPosition.d.ts.map +0 -1
  57. package/dist/tools/openPosition.js +0 -41
  58. package/dist/tools/openPosition.js.map +0 -1
  59. package/dist/tools/swap.d.ts +0 -21
  60. package/dist/tools/swap.d.ts.map +0 -1
  61. package/dist/tools/swap.js +0 -32
  62. package/dist/tools/swap.js.map +0 -1
package/README.md CHANGED
@@ -1,77 +1,219 @@
1
1
  # @agent-shield/plugin-solana-agent-kit
2
2
 
3
- AgentShield plugin for [Solana Agent Kit](https://github.com/sendaifun/solana-agent-kit) — routes agent DeFi actions through permission-guarded vaults with spending limits, token whitelists, and leverage controls.
3
+ AgentShield plugin for [Solana Agent Kit](https://github.com/sendaifun/solana-agent-kit) — adds shield monitoring, management, and transaction history tools to any SAK agent. The shield wraps wallet signing transparently, so SAK's built-in swap/position tools are automatically policy-guarded without any code changes.
4
4
 
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @agent-shield/plugin-solana-agent-kit @agent-shield/sdk
8
+ npm install @agent-shield/plugin-solana-agent-kit @agent-shield/solana
9
9
  ```
10
10
 
11
- Peer dependencies: `solana-agent-kit >=2.0.0`, `@agent-shield/sdk >=0.1.0`, `@solana/web3.js >=1.90.0`, `@coral-xyz/anchor >=0.30.0`
11
+ Peer dependencies: `solana-agent-kit >=2.0.0`, `@agent-shield/solana >=0.1.0`, `@solana/web3.js >=1.90.0`
12
12
 
13
13
  ## Quick Start
14
14
 
15
+ ### Option A: Pre-created ShieldedWallet
16
+
15
17
  ```typescript
18
+ import { shield } from "@agent-shield/solana";
16
19
  import { createAgentShieldPlugin } from "@agent-shield/plugin-solana-agent-kit";
17
20
  import { SolanaAgentKit } from "solana-agent-kit";
18
- import { PublicKey } from "@solana/web3.js";
19
- import { BN } from "@coral-xyz/anchor";
20
21
 
22
+ // 1. Wrap your wallet with spending controls
23
+ const protectedWallet = shield(wallet, { maxSpend: "500 USDC/day" });
24
+
25
+ // 2. Create the plugin (provides monitoring tools)
26
+ const plugin = createAgentShieldPlugin({ wallet: protectedWallet });
27
+
28
+ // 3. Create the agent — all actions are now policy-guarded
29
+ const agent = new SolanaAgentKit(protectedWallet, rpcUrl, {
30
+ plugins: [plugin],
31
+ });
32
+ ```
33
+
34
+ ### Option B: Factory (auto-creates ShieldedWallet)
35
+
36
+ ```typescript
37
+ import { createAgentShieldPlugin } from "@agent-shield/plugin-solana-agent-kit";
38
+
39
+ // Pass a raw wallet + policies — the plugin creates the ShieldedWallet for you
21
40
  const plugin = createAgentShieldPlugin({
22
- vaultOwner: new PublicKey("..."), // vault owner pubkey
23
- vaultId: new BN(1), // vault identifier
41
+ rawWallet: keypairWallet,
42
+ policies: { maxSpend: "500 USDC/day" },
43
+ logger: console,
24
44
  });
25
45
 
26
- const agent = new SolanaAgentKit(wallet, rpcUrl, {
27
- plugins: [plugin],
46
+ // Event callbacks (onDenied, onApproved, onPause, onResume, onPolicyUpdate)
47
+ // are automatically wired to the logger
48
+ ```
49
+
50
+ ### Standalone Factory
51
+
52
+ ```typescript
53
+ import { createShieldedWallet } from "@agent-shield/plugin-solana-agent-kit";
54
+
55
+ const protectedWallet = createShieldedWallet({
56
+ wallet: keypairWallet,
57
+ policies: { maxSpend: "500 USDC/day" },
58
+ logger: console,
59
+ options: {
60
+ onDenied: (err) => alertService.notify(err.message),
61
+ },
28
62
  });
29
63
  ```
30
64
 
31
65
  ## Tools
32
66
 
33
- The plugin registers 6 tools on the agent:
34
-
35
- ### Trading
67
+ The plugin registers 4 monitoring/management tools on the agent:
36
68
 
37
69
  | Tool | Description | Parameters |
38
70
  |------|-------------|------------|
39
- | `shield_swap` | Execute a token swap through Jupiter, routed through the AgentShield vault with policy enforcement | `inputMint`, `outputMint`, `amount`, `slippageBps` |
40
- | `shield_open_position` | Open a leveraged perpetual position on Flash Trade. Enforces leverage limits and position count caps | `collateralMint`, `targetMint`, `collateralAmount`, `side`, `leverage` |
41
- | `shield_close_position` | Close an existing perpetual position on Flash Trade | `positionMint`, `targetMint`, `side` |
71
+ | `shield_status` | Check current spending vs limits, rate limit usage, and enforcement state | *(none)* |
72
+ | `shield_update_policy` | Update spending limits or program blocking at runtime | `maxSpend?`, `blockUnknownPrograms?` |
73
+ | `shield_pause_resume` | Pause or resume policy enforcement | `action: "pause" \| "resume"` |
74
+ | `shield_transaction_history` | View per-token usage percentages and rate limit summary | *(none)* |
42
75
 
43
- ### Read-Only
76
+ ### Tool Details
44
77
 
45
- | Tool | Description | Parameters |
46
- |------|-------------|------------|
47
- | `shield_check_policy` | Read the vault policy: spending caps, allowed tokens/protocols, leverage limits, fee BPS | *(none)* |
48
- | `shield_check_balance` | Read vault balances, status, and statistics (total volume, open positions, fees collected) | *(none)* |
49
- | `shield_check_spending` | Read the rolling 24h spending tracker: per-token spend vs daily cap, recent transaction history | *(none)* |
78
+ #### `shield_status`
79
+
80
+ Returns a formatted status report including:
81
+ - Whether enforcement is paused or active
82
+ - Per-token spending vs limits (with percentage used and window duration)
83
+ - Remaining budget per token
84
+ - Rate limit usage (transaction count vs limit, remaining, window)
85
+
86
+ **Example output:**
87
+ ```
88
+ === AgentShield Status ===
89
+ Paused: false
90
+
91
+ --- Spending Limits ---
92
+ USDC: 200000000 / 500000000 (40% used, 24h window)
93
+ Remaining: 300000000
94
+ SOL: 1000000000 / 10000000000 (10% used, 24h window)
95
+ Remaining: 9000000000
96
+
97
+ --- Rate Limit ---
98
+ Transactions: 5 / 60 (55 remaining)
99
+ Window: 1h
100
+ ```
101
+
102
+ #### `shield_update_policy`
103
+
104
+ Updates shield policies at runtime. Both parameters are optional — only provided fields are changed.
105
+
106
+ **Schema:**
107
+ ```typescript
108
+ {
109
+ maxSpend?: string; // e.g. "1000 USDC/day"
110
+ blockUnknownPrograms?: boolean; // true or false
111
+ }
112
+ ```
113
+
114
+ #### `shield_pause_resume`
115
+
116
+ Toggles enforcement on or off. When paused, transactions pass through without policy checks or spend recording.
117
+
118
+ **Schema:**
119
+ ```typescript
120
+ {
121
+ action: "pause" | "resume";
122
+ }
123
+ ```
124
+
125
+ #### `shield_transaction_history`
126
+
127
+ Returns a detailed per-token usage summary with percentages and rolling window information, plus rate limit status.
128
+
129
+ **Example output:**
130
+ ```
131
+ === AgentShield Transaction History ===
132
+ Enforcement: ACTIVE
133
+
134
+ --- Per-Token Usage ---
135
+ USDC:
136
+ Spent: 200000000 / 500000000
137
+ Usage: 40%
138
+ Remaining: 300000000
139
+ Window: 24h rolling
140
+
141
+ --- Rate Limit ---
142
+ Transactions: 5 / 60
143
+ Remaining: 55
144
+ Window: 1h
145
+ ```
50
146
 
51
147
  ## Configuration
52
148
 
53
149
  ```typescript
54
150
  interface AgentShieldPluginConfig {
55
- /** Vault owner public key */
56
- vaultOwner: PublicKey;
57
- /** Vault identifier (u64) */
58
- vaultId: BN;
59
- /** Optional program ID override (defaults to mainnet deployment) */
60
- programId?: PublicKey;
151
+ // Option A: Pre-created ShieldedWallet
152
+ wallet?: ShieldedWallet;
153
+
154
+ // Option B: Auto-create from raw wallet
155
+ rawWallet?: WalletLike;
156
+ policies?: ShieldPolicies;
157
+ logger?: { info?: Function; warn?: Function };
158
+ options?: ShieldOptions;
61
159
  }
62
160
  ```
63
161
 
64
- The plugin creates an `AgentShieldClient` on initialization using the agent's connection and wallet. The client is cached per agent instance.
162
+ You must provide either `wallet` or `rawWallet`. If both are provided, `wallet` takes precedence.
163
+
164
+ When using `rawWallet`, the factory automatically wires event callbacks to the logger:
165
+ - `onDenied` logs warnings with the denial reason
166
+ - `onApproved`, `onPause`, `onResume`, `onPolicyUpdate` log info messages
167
+ - Any callbacks in `options` are chained after logger callbacks
168
+
169
+ ## Exported Functions
170
+
171
+ | Export | Description |
172
+ |--------|-------------|
173
+ | `createAgentShieldPlugin(config)` | Create the SAK plugin with 4 tools |
174
+ | `createShieldedWallet(config)` | Standalone factory for ShieldedWallet creation |
175
+ | `resolveWallet(config)` | Resolve config to a `{ wallet: ShieldedWallet }` |
176
+ | `status(agent, config, input)` | Status tool handler (for custom use) |
177
+ | `updatePolicy(agent, config, input)` | Update policy tool handler |
178
+ | `pauseResume(agent, config, input)` | Pause/resume tool handler |
179
+ | `transactionHistory(agent, config, input)` | Transaction history tool handler |
180
+
181
+ All Zod schemas are also exported: `statusSchema`, `updatePolicySchema`, `pauseResumeSchema`, `transactionHistorySchema`.
65
182
 
66
183
  ## How It Works
67
184
 
68
- All trading tools (`shield_swap`, `shield_open_position`, `shield_close_position`) build atomic composed transactions:
185
+ The `shield()` wrapper intercepts `signTransaction` and `signAllTransactions` on the wallet. When the agent calls any SAK tool (swap, transfer, open position, etc.), the transaction passes through the shield's policy engine before signing. If a policy is violated (spending cap, rate limit, unknown program, etc.), the transaction is rejected with a descriptive `ShieldDeniedError`.
69
186
 
187
+ The plugin's tools give the agent visibility into spending state and the ability to manage enforcement — no DeFi execution tools are needed since the shield guards signing transparently.
188
+
189
+ ```
190
+ Agent calls swap() → SAK builds transaction → shield() intercepts signTransaction
191
+
192
+ Policy engine evaluates:
193
+ • Spending cap check
194
+ • Rate limit check
195
+ • Protocol allowlist
196
+ • Token allowlist
197
+
198
+ Pass → sign with inner wallet
199
+ Fail → throw ShieldDeniedError
70
200
  ```
71
- [ValidateAndAuthorize, DeFi instruction(s), FinalizeSession]
201
+
202
+ ## Testing
203
+
204
+ ```bash
205
+ npm test
206
+ # Runs 23 tests covering all tools, factory, config resolution, and event wiring
72
207
  ```
73
208
 
74
- The on-chain program checks the agent's action against the vault policy (spending cap, token whitelist, protocol whitelist, leverage limits) before the DeFi instruction executes. If any check fails, the entire transaction reverts.
209
+ ## Related Packages
210
+
211
+ | Package | Description |
212
+ |---------|-------------|
213
+ | [`@agent-shield/solana`](https://www.npmjs.com/package/@agent-shield/solana) | Core wallet wrapper (required) |
214
+ | [`@agent-shield/core`](https://www.npmjs.com/package/@agent-shield/core) | Pure TypeScript policy engine |
215
+ | [`@agent-shield/plugin-elizaos`](https://www.npmjs.com/package/@agent-shield/plugin-elizaos) | ElizaOS integration |
216
+ | [`@agent-shield/sdk`](https://www.npmjs.com/package/@agent-shield/sdk) | On-chain vault SDK |
75
217
 
76
218
  ## License
77
219
 
@@ -0,0 +1,29 @@
1
+ import { type ShieldedWallet, type WalletLike, type ShieldPolicies, type ShieldOptions } from "@agent-shield/solana";
2
+ export interface FactoryConfig {
3
+ /** Raw wallet to wrap with shield(). */
4
+ wallet: WalletLike;
5
+ /** Shield policies (string shorthand or full config). */
6
+ policies?: ShieldPolicies;
7
+ /** Optional logger for shield event callbacks. */
8
+ logger?: {
9
+ info?: (...args: any[]) => void;
10
+ warn?: (...args: any[]) => void;
11
+ };
12
+ /** Additional ShieldOptions (storage, custom callbacks). */
13
+ options?: ShieldOptions;
14
+ }
15
+ /**
16
+ * Convenience factory that creates a ShieldedWallet from a raw wallet.
17
+ * Auto-wires event callbacks to the provided logger.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const wallet = createShieldedWallet({
22
+ * wallet: keypairWallet,
23
+ * policies: { maxSpend: '500 USDC/day' },
24
+ * logger: console,
25
+ * });
26
+ * ```
27
+ */
28
+ export declare function createShieldedWallet(config: FactoryConfig): ShieldedWallet;
29
+ //# sourceMappingURL=factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAC;AAE9B,MAAM,WAAW,aAAa;IAC5B,wCAAwC;IACxC,MAAM,EAAE,UAAU,CAAC;IACnB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,kDAAkD;IAClD,MAAM,CAAC,EAAE;QACP,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QAChC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;KACjC,CAAC;IACF,4DAA4D;IAC5D,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CA8B1E"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createShieldedWallet = createShieldedWallet;
4
+ const solana_1 = require("@agent-shield/solana");
5
+ /**
6
+ * Convenience factory that creates a ShieldedWallet from a raw wallet.
7
+ * Auto-wires event callbacks to the provided logger.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const wallet = createShieldedWallet({
12
+ * wallet: keypairWallet,
13
+ * policies: { maxSpend: '500 USDC/day' },
14
+ * logger: console,
15
+ * });
16
+ * ```
17
+ */
18
+ function createShieldedWallet(config) {
19
+ const log = config.logger ?? console;
20
+ const info = log.info ?? console.info;
21
+ const warn = log.warn ?? console.warn;
22
+ const options = {
23
+ ...config.options,
24
+ onDenied: (error) => {
25
+ warn("[AgentShield] Transaction denied:", error.message);
26
+ config.options?.onDenied?.(error);
27
+ },
28
+ onApproved: (txHash) => {
29
+ info("[AgentShield] Transaction approved", txHash ?? "");
30
+ config.options?.onApproved?.(txHash);
31
+ },
32
+ onPause: () => {
33
+ info("[AgentShield] Enforcement paused");
34
+ config.options?.onPause?.();
35
+ },
36
+ onResume: () => {
37
+ info("[AgentShield] Enforcement resumed");
38
+ config.options?.onResume?.();
39
+ },
40
+ onPolicyUpdate: (policies) => {
41
+ info("[AgentShield] Policies updated");
42
+ config.options?.onPolicyUpdate?.(policies);
43
+ },
44
+ };
45
+ return (0, solana_1.shield)(config.wallet, config.policies, options);
46
+ }
47
+ //# sourceMappingURL=factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":";;AAmCA,oDA8BC;AAjED,iDAM8B;AAgB9B;;;;;;;;;;;;GAYG;AACH,SAAgB,oBAAoB,CAAC,MAAqB;IACxD,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC;IACrC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IACtC,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAEtC,MAAM,OAAO,GAAkB;QAC7B,GAAG,MAAM,CAAC,OAAO;QACjB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,IAAI,CAAC,mCAAmC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;YACzD,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;QACD,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE;YACrB,IAAI,CAAC,oCAAoC,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;YACzD,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,MAAM,CAAC,CAAC;QACvC,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACZ,IAAI,CAAC,kCAAkC,CAAC,CAAC;YACzC,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC;QAC9B,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE;YACb,IAAI,CAAC,mCAAmC,CAAC,CAAC;YAC1C,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC;QAC/B,CAAC;QACD,cAAc,EAAE,CAAC,QAAQ,EAAE,EAAE;YAC3B,IAAI,CAAC,gCAAgC,CAAC,CAAC;YACvC,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,CAAC,QAAQ,CAAC,CAAC;QAC7C,CAAC;KACF,CAAC;IAEF,OAAO,IAAA,eAAM,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACzD,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,21 +1,26 @@
1
1
  import { AgentShieldPluginConfig } from "./types";
2
- export { AgentShieldPluginConfig } from "./types";
3
- export { getOrCreateClient } from "./client-factory";
2
+ export { AgentShieldPluginConfig, ResolvedConfig, resolveWallet, } from "./types";
3
+ export { createShieldedWallet, type FactoryConfig } from "./factory";
4
4
  export * from "./tools";
5
5
  /**
6
6
  * Creates the AgentShield plugin for Solana Agent Kit.
7
7
  *
8
- * Usage:
8
+ * Usage with pre-created wallet:
9
9
  * ```ts
10
- * import { createAgentShieldPlugin } from "@agent-shield/plugin-solana-agent-kit";
10
+ * import { shield } from '@agent-shield/solana';
11
+ * import { createAgentShieldPlugin } from '@agent-shield/plugin-solana-agent-kit';
11
12
  *
12
- * const plugin = createAgentShieldPlugin({
13
- * vaultOwner: ownerPubkey,
14
- * vaultId: new BN(1),
15
- * });
13
+ * const protectedWallet = shield(wallet, { maxSpend: '500 USDC/day' });
14
+ * const plugin = createAgentShieldPlugin({ wallet: protectedWallet });
15
+ * const agent = new SolanaAgentKit(protectedWallet, RPC_URL, { plugins: [plugin] });
16
+ * ```
16
17
  *
17
- * const agent = new SolanaAgentKit(wallet, rpcUrl, {
18
- * plugins: [plugin],
18
+ * Usage with factory (auto-creates ShieldedWallet):
19
+ * ```ts
20
+ * const plugin = createAgentShieldPlugin({
21
+ * rawWallet: keypairWallet,
22
+ * policies: { maxSpend: '500 USDC/day' },
23
+ * logger: console,
19
24
  * });
20
25
  * ```
21
26
  */
@@ -23,118 +28,41 @@ export declare function createAgentShieldPlugin(config: AgentShieldPluginConfig)
23
28
  name: string;
24
29
  description: string;
25
30
  methods: {
26
- shield_swap: {
31
+ shield_status: {
27
32
  description: string;
28
- schema: import("zod").ZodObject<{
29
- inputMint: import("zod").ZodString;
30
- outputMint: import("zod").ZodString;
31
- amount: import("zod").ZodString;
32
- slippageBps: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodNumber>>;
33
- }, "strip", import("zod").ZodTypeAny, {
34
- inputMint: string;
35
- outputMint: string;
36
- amount: string;
37
- slippageBps: number;
38
- }, {
39
- inputMint: string;
40
- outputMint: string;
41
- amount: string;
42
- slippageBps?: number | undefined;
43
- }>;
33
+ schema: import("zod").ZodObject<{}, "strip", import("zod").ZodTypeAny, {}, {}>;
44
34
  handler: (agent: any, input: any) => Promise<string>;
45
35
  };
46
- shield_open_position: {
36
+ shield_update_policy: {
47
37
  description: string;
48
38
  schema: import("zod").ZodObject<{
49
- targetSymbol: import("zod").ZodString;
50
- collateralSymbol: import("zod").ZodString;
51
- collateralAmount: import("zod").ZodString;
52
- sizeAmount: import("zod").ZodString;
53
- side: import("zod").ZodEnum<["long", "short"]>;
54
- leverageBps: import("zod").ZodNumber;
55
- price: import("zod").ZodString;
56
- priceExponent: import("zod").ZodNumber;
39
+ maxSpend: import("zod").ZodOptional<import("zod").ZodString>;
40
+ blockUnknownPrograms: import("zod").ZodOptional<import("zod").ZodBoolean>;
57
41
  }, "strip", import("zod").ZodTypeAny, {
58
- targetSymbol: string;
59
- collateralSymbol: string;
60
- collateralAmount: string;
61
- sizeAmount: string;
62
- side: "long" | "short";
63
- leverageBps: number;
64
- price: string;
65
- priceExponent: number;
42
+ maxSpend?: string | undefined;
43
+ blockUnknownPrograms?: boolean | undefined;
66
44
  }, {
67
- targetSymbol: string;
68
- collateralSymbol: string;
69
- collateralAmount: string;
70
- sizeAmount: string;
71
- side: "long" | "short";
72
- leverageBps: number;
73
- price: string;
74
- priceExponent: number;
45
+ maxSpend?: string | undefined;
46
+ blockUnknownPrograms?: boolean | undefined;
75
47
  }>;
76
48
  handler: (agent: any, input: any) => Promise<string>;
77
49
  };
78
- shield_close_position: {
50
+ shield_pause_resume: {
79
51
  description: string;
80
52
  schema: import("zod").ZodObject<{
81
- targetSymbol: import("zod").ZodString;
82
- collateralSymbol: import("zod").ZodString;
83
- collateralAmount: import("zod").ZodString;
84
- side: import("zod").ZodEnum<["long", "short"]>;
85
- price: import("zod").ZodString;
86
- priceExponent: import("zod").ZodNumber;
53
+ action: import("zod").ZodEnum<["pause", "resume"]>;
87
54
  }, "strip", import("zod").ZodTypeAny, {
88
- targetSymbol: string;
89
- collateralSymbol: string;
90
- collateralAmount: string;
91
- side: "long" | "short";
92
- price: string;
93
- priceExponent: number;
55
+ action: "pause" | "resume";
94
56
  }, {
95
- targetSymbol: string;
96
- collateralSymbol: string;
97
- collateralAmount: string;
98
- side: "long" | "short";
99
- price: string;
100
- priceExponent: number;
57
+ action: "pause" | "resume";
101
58
  }>;
102
59
  handler: (agent: any, input: any) => Promise<string>;
103
60
  };
104
- shield_check_policy: {
61
+ shield_transaction_history: {
105
62
  description: string;
106
- schema: import("zod").ZodObject<{
107
- vaultAddress: import("zod").ZodOptional<import("zod").ZodString>;
108
- }, "strip", import("zod").ZodTypeAny, {
109
- vaultAddress?: string | undefined;
110
- }, {
111
- vaultAddress?: string | undefined;
112
- }>;
113
- handler: (agent: any, input: any) => Promise<string>;
114
- };
115
- shield_check_balance: {
116
- description: string;
117
- schema: import("zod").ZodObject<{
118
- vaultAddress: import("zod").ZodOptional<import("zod").ZodString>;
119
- }, "strip", import("zod").ZodTypeAny, {
120
- vaultAddress?: string | undefined;
121
- }, {
122
- vaultAddress?: string | undefined;
123
- }>;
124
- handler: (agent: any, input: any) => Promise<string>;
125
- };
126
- shield_check_spending: {
127
- description: string;
128
- schema: import("zod").ZodObject<{
129
- vaultAddress: import("zod").ZodOptional<import("zod").ZodString>;
130
- }, "strip", import("zod").ZodTypeAny, {
131
- vaultAddress?: string | undefined;
132
- }, {
133
- vaultAddress?: string | undefined;
134
- }>;
63
+ schema: import("zod").ZodObject<{}, "strip", import("zod").ZodTypeAny, {}, {}>;
135
64
  handler: (agent: any, input: any) => Promise<string>;
136
65
  };
137
66
  };
138
- initialize: (agent: any) => void;
139
67
  };
140
68
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAUlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,cAAc,SAAS,CAAC;AAExB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,uBAAuB;;;;;;;;;;;;;;;;;;;;;;6BAc9C,GAAG,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAOf,GAAG,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;6BAMf,GAAG,SAAS,GAAG;;;;;;;;;;;6BAOf,GAAG,SAAS,GAAG;;;;;;;;;;;6BAOf,GAAG,SAAS,GAAG;;;;;;;;;;;6BAOf,GAAG,SAAS,GAAG;;;wBAIhB,GAAG;EAM1B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAiB,MAAM,SAAS,CAAC;AAYjE,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,oBAAoB,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AACrE,cAAc,SAAS,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,uBAAuB;;;;;;;6BAiB9C,GAAG,SAAS,GAAG;;;;;;;;;;;;;;6BAOf,GAAG,SAAS,GAAG;;;;;;;;;;;6BAQf,GAAG,SAAS,GAAG;;;;;6BAQf,GAAG,SAAS,GAAG;;;EAKvC"}
package/dist/index.js CHANGED
@@ -14,76 +14,70 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getOrCreateClient = void 0;
17
+ exports.createShieldedWallet = exports.resolveWallet = void 0;
18
18
  exports.createAgentShieldPlugin = createAgentShieldPlugin;
19
+ const types_1 = require("./types");
19
20
  const tools_1 = require("./tools");
20
- var client_factory_1 = require("./client-factory");
21
- Object.defineProperty(exports, "getOrCreateClient", { enumerable: true, get: function () { return client_factory_1.getOrCreateClient; } });
21
+ var types_2 = require("./types");
22
+ Object.defineProperty(exports, "resolveWallet", { enumerable: true, get: function () { return types_2.resolveWallet; } });
23
+ var factory_1 = require("./factory");
24
+ Object.defineProperty(exports, "createShieldedWallet", { enumerable: true, get: function () { return factory_1.createShieldedWallet; } });
22
25
  __exportStar(require("./tools"), exports);
23
26
  /**
24
27
  * Creates the AgentShield plugin for Solana Agent Kit.
25
28
  *
26
- * Usage:
29
+ * Usage with pre-created wallet:
27
30
  * ```ts
28
- * import { createAgentShieldPlugin } from "@agent-shield/plugin-solana-agent-kit";
31
+ * import { shield } from '@agent-shield/solana';
32
+ * import { createAgentShieldPlugin } from '@agent-shield/plugin-solana-agent-kit';
29
33
  *
30
- * const plugin = createAgentShieldPlugin({
31
- * vaultOwner: ownerPubkey,
32
- * vaultId: new BN(1),
33
- * });
34
+ * const protectedWallet = shield(wallet, { maxSpend: '500 USDC/day' });
35
+ * const plugin = createAgentShieldPlugin({ wallet: protectedWallet });
36
+ * const agent = new SolanaAgentKit(protectedWallet, RPC_URL, { plugins: [plugin] });
37
+ * ```
34
38
  *
35
- * const agent = new SolanaAgentKit(wallet, rpcUrl, {
36
- * plugins: [plugin],
39
+ * Usage with factory (auto-creates ShieldedWallet):
40
+ * ```ts
41
+ * const plugin = createAgentShieldPlugin({
42
+ * rawWallet: keypairWallet,
43
+ * policies: { maxSpend: '500 USDC/day' },
44
+ * logger: console,
37
45
  * });
38
46
  * ```
39
47
  */
40
48
  function createAgentShieldPlugin(config) {
49
+ const resolved = (0, types_1.resolveWallet)(config);
41
50
  return {
42
51
  name: "agent-shield",
43
- description: "AgentShield — Permission-guarded DeFi vault for AI agents on Solana. " +
44
- "Routes swaps through Jupiter and perp trades through Flash Trade, " +
45
- "enforcing spending caps, token whitelists, and leverage limits.",
52
+ description: "AgentShield — Client-side spending controls for AI agents on Solana. " +
53
+ "Provides monitoring tools to check spending status, update policies, " +
54
+ "pause/resume enforcement, and view transaction history. " +
55
+ "Shield wraps signing transparently.",
46
56
  methods: {
47
- shield_swap: {
48
- description: "Execute a token swap through Jupiter, routed through the AgentShield vault " +
49
- "with permission checks and spending limits enforced.",
50
- schema: tools_1.swapSchema,
51
- handler: (agent, input) => (0, tools_1.swap)(agent, config, input),
52
- },
53
- shield_open_position: {
54
- description: "Open a leveraged perpetual position on Flash Trade through the AgentShield vault. " +
55
- "Enforces leverage limits and position count caps.",
56
- schema: tools_1.openPositionSchema,
57
- handler: (agent, input) => (0, tools_1.openPosition)(agent, config, input),
57
+ shield_status: {
58
+ description: "Check current shield status: spending vs limits, rate limit usage, " +
59
+ "and whether enforcement is paused.",
60
+ schema: tools_1.statusSchema,
61
+ handler: (agent, input) => (0, tools_1.status)(agent, resolved, input),
58
62
  },
59
- shield_close_position: {
60
- description: "Close an existing perpetual position on Flash Trade through the AgentShield vault.",
61
- schema: tools_1.closePositionSchema,
62
- handler: (agent, input) => (0, tools_1.closePosition)(agent, config, input),
63
+ shield_update_policy: {
64
+ description: "Update shield policies at runtime. Can change spending limits " +
65
+ "and unknown program blocking.",
66
+ schema: tools_1.updatePolicySchema,
67
+ handler: (agent, input) => (0, tools_1.updatePolicy)(agent, resolved, input),
63
68
  },
64
- shield_check_policy: {
65
- description: "Read the current vault policy: spending caps, allowed tokens/protocols, " +
66
- "leverage limits, and fee configuration.",
67
- schema: tools_1.checkPolicySchema,
68
- handler: (agent, input) => (0, tools_1.checkPolicy)(agent, config, input),
69
+ shield_pause_resume: {
70
+ description: "Pause or resume shield enforcement. When paused, transactions " +
71
+ "pass through without policy checks or spend recording.",
72
+ schema: tools_1.pauseResumeSchema,
73
+ handler: (agent, input) => (0, tools_1.pauseResume)(agent, resolved, input),
69
74
  },
70
- shield_check_balance: {
71
- description: "Read vault balances, status, and high-level statistics (total volume, " +
72
- "open positions, fees collected).",
73
- schema: tools_1.checkBalanceSchema,
74
- handler: (agent, input) => (0, tools_1.checkBalance)(agent, config, input),
75
+ shield_transaction_history: {
76
+ description: "View recent transaction activity summary — per-token usage " +
77
+ "percentages and rate limit status.",
78
+ schema: tools_1.transactionHistorySchema,
79
+ handler: (agent, input) => (0, tools_1.transactionHistory)(agent, resolved, input),
75
80
  },
76
- shield_check_spending: {
77
- description: "Read the rolling 24-hour spending tracker: per-token spend vs daily cap, " +
78
- "and recent transaction history.",
79
- schema: tools_1.checkSpendingSchema,
80
- handler: (agent, input) => (0, tools_1.checkSpending)(agent, config, input),
81
- },
82
- },
83
- initialize: (agent) => {
84
- // Eagerly create the client so connection errors surface early
85
- const { getOrCreateClient: getClient } = require("./client-factory");
86
- getClient(agent, config);
87
81
  },
88
82
  };
89
83
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA+BA,0DA0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