@agent-shield/plugin-elizaos 0.1.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 (53) hide show
  1. package/dist/actions/closePosition.d.ts +27 -0
  2. package/dist/actions/closePosition.d.ts.map +1 -0
  3. package/dist/actions/closePosition.js +86 -0
  4. package/dist/actions/closePosition.js.map +1 -0
  5. package/dist/actions/index.d.ts +4 -0
  6. package/dist/actions/index.d.ts.map +1 -0
  7. package/dist/actions/index.js +10 -0
  8. package/dist/actions/index.js.map +1 -0
  9. package/dist/actions/openPosition.d.ts +31 -0
  10. package/dist/actions/openPosition.d.ts.map +1 -0
  11. package/dist/actions/openPosition.js +91 -0
  12. package/dist/actions/openPosition.js.map +1 -0
  13. package/dist/actions/swap.d.ts +25 -0
  14. package/dist/actions/swap.d.ts.map +1 -0
  15. package/dist/actions/swap.js +82 -0
  16. package/dist/actions/swap.js.map +1 -0
  17. package/dist/client-factory.d.ts +19 -0
  18. package/dist/client-factory.d.ts.map +1 -0
  19. package/dist/client-factory.js +75 -0
  20. package/dist/client-factory.js.map +1 -0
  21. package/dist/evaluators/index.d.ts +2 -0
  22. package/dist/evaluators/index.d.ts.map +1 -0
  23. package/dist/evaluators/index.js +6 -0
  24. package/dist/evaluators/index.js.map +1 -0
  25. package/dist/evaluators/policyCheck.d.ts +25 -0
  26. package/dist/evaluators/policyCheck.d.ts.map +1 -0
  27. package/dist/evaluators/policyCheck.js +71 -0
  28. package/dist/evaluators/policyCheck.js.map +1 -0
  29. package/dist/index.d.ts +9 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +23 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/plugin.d.ts +136 -0
  34. package/dist/plugin.d.ts.map +1 -0
  35. package/dist/plugin.js +42 -0
  36. package/dist/plugin.js.map +1 -0
  37. package/dist/providers/index.d.ts +3 -0
  38. package/dist/providers/index.d.ts.map +1 -0
  39. package/dist/providers/index.js +8 -0
  40. package/dist/providers/index.js.map +1 -0
  41. package/dist/providers/spendTracking.d.ts +26 -0
  42. package/dist/providers/spendTracking.d.ts.map +1 -0
  43. package/dist/providers/spendTracking.js +61 -0
  44. package/dist/providers/spendTracking.js.map +1 -0
  45. package/dist/providers/vaultStatus.d.ts +30 -0
  46. package/dist/providers/vaultStatus.d.ts.map +1 -0
  47. package/dist/providers/vaultStatus.js +53 -0
  48. package/dist/providers/vaultStatus.js.map +1 -0
  49. package/dist/types.d.ts +24 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +20 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +34 -0
@@ -0,0 +1,27 @@
1
+ export declare const closePositionAction: {
2
+ name: string;
3
+ description: string;
4
+ similes: string[];
5
+ validate: (runtime: any, message: any) => Promise<boolean>;
6
+ handler: (runtime: any, message: any, _state: any, _options: any, callback: (response: any) => void) => Promise<void>;
7
+ examples: ({
8
+ user: string;
9
+ content: {
10
+ text: string;
11
+ targetSymbol: string;
12
+ collateralSymbol: string;
13
+ collateralAmount: string;
14
+ side: string;
15
+ };
16
+ } | {
17
+ user: string;
18
+ content: {
19
+ text: string;
20
+ targetSymbol?: undefined;
21
+ collateralSymbol?: undefined;
22
+ collateralAmount?: undefined;
23
+ side?: undefined;
24
+ };
25
+ })[][];
26
+ };
27
+ //# sourceMappingURL=closePosition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"closePosition.d.ts","sourceRoot":"","sources":["../../src/actions/closePosition.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB;;;;wBAYJ,GAAG,WAAW,GAAG,KAAG,OAAO,CAAC,OAAO,CAAC;uBAanD,GAAG,WACH,GAAG,UACJ,GAAG,YACD,GAAG,YACH,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;CAgEpC,CAAC"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closePositionAction = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const client_factory_1 = require("../client-factory");
6
+ exports.closePositionAction = {
7
+ name: "SHIELD_CLOSE_POSITION",
8
+ description: "Close an existing perpetual position on Flash Trade through the AgentShield vault.",
9
+ similes: [
10
+ "close my position",
11
+ "close the long",
12
+ "close the short",
13
+ "exit position through shield",
14
+ "close leveraged trade",
15
+ ],
16
+ validate: async (runtime, message) => {
17
+ try {
18
+ (0, client_factory_1.getOrCreateClient)(runtime);
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ const text = (message.content?.text || "").toLowerCase();
24
+ const keywords = ["close position", "close long", "close short", "exit position"];
25
+ return keywords.some((kw) => text.includes(kw));
26
+ },
27
+ handler: async (runtime, message, _state, _options, callback) => {
28
+ try {
29
+ const { client, vaultOwner, vaultId, agentKey } = (0, client_factory_1.getOrCreateClient)(runtime);
30
+ const params = message.content;
31
+ if (!params.targetSymbol || !params.collateralSymbol || !params.collateralAmount || !params.side) {
32
+ callback({
33
+ text: "Missing required fields: targetSymbol, collateralSymbol, collateralAmount, and side are required.",
34
+ error: true,
35
+ });
36
+ return;
37
+ }
38
+ const sideObj = params.side === "long" ? { long: {} } : { short: {} };
39
+ const result = await client.flashTradeClose({
40
+ owner: vaultOwner,
41
+ vaultId,
42
+ agent: agentKey,
43
+ targetSymbol: params.targetSymbol,
44
+ collateralSymbol: params.collateralSymbol,
45
+ collateralAmount: new anchor_1.BN(params.collateralAmount),
46
+ side: sideObj,
47
+ priceWithSlippage: {
48
+ price: new anchor_1.BN(params.price || "0"),
49
+ exponent: params.priceExponent || -8,
50
+ },
51
+ });
52
+ const txSig = await client.executeFlashTrade(result, agentKey);
53
+ callback({
54
+ text: `Position closed through AgentShield vault.\nSide: ${params.side}\nTarget: ${params.targetSymbol}\nTransaction: ${txSig}`,
55
+ data: { txSig },
56
+ });
57
+ }
58
+ catch (error) {
59
+ callback({
60
+ text: `Close position failed: ${error.message}`,
61
+ error: true,
62
+ });
63
+ }
64
+ },
65
+ examples: [
66
+ [
67
+ {
68
+ user: "{{user1}}",
69
+ content: {
70
+ text: "Close my long SOL position",
71
+ targetSymbol: "SOL",
72
+ collateralSymbol: "USDC",
73
+ collateralAmount: "100000000",
74
+ side: "long",
75
+ },
76
+ },
77
+ {
78
+ user: "{{agent}}",
79
+ content: {
80
+ text: "Position closed through AgentShield vault.\nSide: long\nTarget: SOL\nTransaction: 7dEf...",
81
+ },
82
+ },
83
+ ],
84
+ ],
85
+ };
86
+ //# sourceMappingURL=closePosition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"closePosition.js","sourceRoot":"","sources":["../../src/actions/closePosition.ts"],"names":[],"mappings":";;;AAAA,8CAAuC;AACvC,sDAAsD;AAEzC,QAAA,mBAAmB,GAAG;IACjC,IAAI,EAAE,uBAAuB;IAC7B,WAAW,EACT,oFAAoF;IACtF,OAAO,EAAE;QACP,mBAAmB;QACnB,gBAAgB;QAChB,iBAAiB;QACjB,8BAA8B;QAC9B,uBAAuB;KACxB;IAED,QAAQ,EAAE,KAAK,EAAE,OAAY,EAAE,OAAY,EAAoB,EAAE;QAC/D,IAAI,CAAC;YACH,IAAA,kCAAiB,EAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACzD,MAAM,QAAQ,GAAG,CAAC,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;QAClF,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IAClD,CAAC;IAED,OAAO,EAAE,KAAK,EACZ,OAAY,EACZ,OAAY,EACZ,MAAW,EACX,QAAa,EACb,QAAiC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M,CAAC,YAAY,kBAAkB,KAAK,EAAE;gBAC/H,IAAI,EAAE,EAAE,KAAK,EAAE;aAChB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,QAAQ,CAAC;gBACP,IAAI,EAAE,0BAA0B,KAAK,CAAC,OAAO,EAAE;gBAC/C,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,QAAQ,EAAE;QACR;YACE;gBACE,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP,IAAI,EAAE,4BAA4B;oBAClC,YAAY,EAAE,KAAK;oBACnB,gBAAgB,EAAE,MAAM;oBACxB,gBAAgB,EAAE,WAAW;oBAC7B,IAAI,EAAE,MAAM;iBACb;aACF;YACD;gBACE,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP,IAAI,EAAE,2FAA2F;iBAClG;aACF;SACF;KACF;CACF,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { swapAction } from "./swap";
2
+ export { openPositionAction } from "./openPosition";
3
+ export { closePositionAction } from "./closePosition";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closePositionAction = exports.openPositionAction = exports.swapAction = void 0;
4
+ var swap_1 = require("./swap");
5
+ Object.defineProperty(exports, "swapAction", { enumerable: true, get: function () { return swap_1.swapAction; } });
6
+ var openPosition_1 = require("./openPosition");
7
+ Object.defineProperty(exports, "openPositionAction", { enumerable: true, get: function () { return openPosition_1.openPositionAction; } });
8
+ var closePosition_1 = require("./closePosition");
9
+ Object.defineProperty(exports, "closePositionAction", { enumerable: true, get: function () { return closePosition_1.closePositionAction; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/actions/index.ts"],"names":[],"mappings":";;;AAAA,+BAAoC;AAA3B,kGAAA,UAAU,OAAA;AACnB,+CAAoD;AAA3C,kHAAA,kBAAkB,OAAA;AAC3B,iDAAsD;AAA7C,oHAAA,mBAAmB,OAAA"}
@@ -0,0 +1,31 @@
1
+ export declare const openPositionAction: {
2
+ name: string;
3
+ description: string;
4
+ similes: string[];
5
+ validate: (runtime: any, message: any) => Promise<boolean>;
6
+ handler: (runtime: any, message: any, _state: any, _options: any, callback: (response: any) => void) => Promise<void>;
7
+ examples: ({
8
+ user: string;
9
+ content: {
10
+ text: string;
11
+ targetSymbol: string;
12
+ collateralSymbol: string;
13
+ collateralAmount: string;
14
+ sizeAmount: string;
15
+ side: string;
16
+ leverageBps: number;
17
+ };
18
+ } | {
19
+ user: string;
20
+ content: {
21
+ text: string;
22
+ targetSymbol?: undefined;
23
+ collateralSymbol?: undefined;
24
+ collateralAmount?: undefined;
25
+ sizeAmount?: undefined;
26
+ side?: undefined;
27
+ leverageBps?: undefined;
28
+ };
29
+ })[][];
30
+ };
31
+ //# sourceMappingURL=openPosition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openPosition.d.ts","sourceRoot":"","sources":["../../src/actions/openPosition.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,kBAAkB;;;;wBAaH,GAAG,WAAW,GAAG,KAAG,OAAO,CAAC,OAAO,CAAC;uBAanD,GAAG,WACH,GAAG,UACJ,GAAG,YACD,GAAG,YACH,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI;;;;;;;;;;;;;;;;;;;;;;;;CAoEpC,CAAC"}
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openPositionAction = void 0;
4
+ const anchor_1 = require("@coral-xyz/anchor");
5
+ const client_factory_1 = require("../client-factory");
6
+ exports.openPositionAction = {
7
+ name: "SHIELD_OPEN_POSITION",
8
+ description: "Open a leveraged perpetual position on Flash Trade through the AgentShield vault. " +
9
+ "Enforces leverage limits, position count caps, and spending policy.",
10
+ similes: [
11
+ "open a long position",
12
+ "open a short position",
13
+ "go long through shield",
14
+ "go short through shield",
15
+ "open leveraged trade",
16
+ ],
17
+ validate: async (runtime, message) => {
18
+ try {
19
+ (0, client_factory_1.getOrCreateClient)(runtime);
20
+ }
21
+ catch {
22
+ return false;
23
+ }
24
+ const text = (message.content?.text || "").toLowerCase();
25
+ const keywords = ["open position", "go long", "go short", "open long", "open short", "leverage"];
26
+ return keywords.some((kw) => text.includes(kw));
27
+ },
28
+ handler: async (runtime, message, _state, _options, callback) => {
29
+ try {
30
+ const { client, vaultOwner, vaultId, agentKey } = (0, client_factory_1.getOrCreateClient)(runtime);
31
+ const params = message.content;
32
+ if (!params.targetSymbol || !params.collateralSymbol || !params.collateralAmount || !params.sizeAmount || !params.side) {
33
+ callback({
34
+ text: "Missing required fields: targetSymbol, collateralSymbol, collateralAmount, sizeAmount, and side are required.",
35
+ error: true,
36
+ });
37
+ return;
38
+ }
39
+ const sideObj = params.side === "long" ? { long: {} } : { short: {} };
40
+ const result = await client.flashTradeOpen({
41
+ owner: vaultOwner,
42
+ vaultId,
43
+ agent: agentKey,
44
+ targetSymbol: params.targetSymbol,
45
+ collateralSymbol: params.collateralSymbol,
46
+ collateralAmount: new anchor_1.BN(params.collateralAmount),
47
+ sizeAmount: new anchor_1.BN(params.sizeAmount),
48
+ side: sideObj,
49
+ priceWithSlippage: {
50
+ price: new anchor_1.BN(params.price || "0"),
51
+ exponent: params.priceExponent || -8,
52
+ },
53
+ leverageBps: params.leverageBps || 10000,
54
+ });
55
+ const txSig = await client.executeFlashTrade(result, agentKey);
56
+ callback({
57
+ text: `Position opened through AgentShield vault.\nSide: ${params.side}\nTarget: ${params.targetSymbol}\nLeverage: ${((params.leverageBps || 10000) / 10000).toFixed(1)}x\nTransaction: ${txSig}`,
58
+ data: { txSig },
59
+ });
60
+ }
61
+ catch (error) {
62
+ callback({
63
+ text: `Open position failed: ${error.message}`,
64
+ error: true,
65
+ });
66
+ }
67
+ },
68
+ examples: [
69
+ [
70
+ {
71
+ user: "{{user1}}",
72
+ content: {
73
+ text: "Open a 2x long SOL position with 100 USDC collateral",
74
+ targetSymbol: "SOL",
75
+ collateralSymbol: "USDC",
76
+ collateralAmount: "100000000",
77
+ sizeAmount: "200000000",
78
+ side: "long",
79
+ leverageBps: 20000,
80
+ },
81
+ },
82
+ {
83
+ user: "{{agent}}",
84
+ content: {
85
+ text: "Position opened through AgentShield vault.\nSide: long\nTarget: SOL\nLeverage: 2.0x\nTransaction: 4aBc...",
86
+ },
87
+ },
88
+ ],
89
+ ],
90
+ };
91
+ //# sourceMappingURL=openPosition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"openPosition.js","sourceRoot":"","sources":["../../src/actions/openPosition.ts"],"names":[],"mappings":";;;AAAA,8CAAuC;AACvC,sDAAsD;AAEzC,QAAA,kBAAkB,GAAG;IAChC,IAAI,EAAE,sBAAsB;IAC5B,WAAW,EACT,oFAAoF;QACpF,qEAAqE;IACvE,OAAO,EAAE;QACP,sBAAsB;QACtB,uBAAuB;QACvB,wBAAwB;QACxB,yBAAyB;QACzB,sBAAsB;KACvB;IAED,QAAQ,EAAE,KAAK,EAAE,OAAY,EAAE,OAAY,EAAoB,EAAE;QAC/D,IAAI,CAAC;YACH,IAAA,kCAAiB,EAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACzD,MAAM,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
+ name: string;
3
+ description: string;
4
+ similes: string[];
5
+ validate: (runtime: any, message: any) => Promise<boolean>;
6
+ handler: (runtime: any, message: any, _state: any, _options: any, callback: (response: any) => void) => Promise<void>;
7
+ examples: ({
8
+ user: string;
9
+ content: {
10
+ text: string;
11
+ inputMint: string;
12
+ outputMint: string;
13
+ amount: string;
14
+ };
15
+ } | {
16
+ user: string;
17
+ content: {
18
+ text: string;
19
+ inputMint?: undefined;
20
+ outputMint?: undefined;
21
+ amount?: undefined;
22
+ };
23
+ })[][];
24
+ };
25
+ //# sourceMappingURL=swap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../src/actions/swap.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU;;;;wBAYK,GAAG,WAAW,GAAG,KAAG,OAAO,CAAC,OAAO,CAAC;uBAenD,GAAG,WACH,GAAG,UACJ,GAAG,YACD,GAAG,YACH,CAAC,QAAQ,EAAE,GAAG,KAAK,IAAI;;;;;;;;;;;;;;;;;;CAuDpC,CAAC"}
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.swapAction = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const anchor_1 = require("@coral-xyz/anchor");
6
+ const client_factory_1 = require("../client-factory");
7
+ exports.swapAction = {
8
+ name: "SHIELD_SWAP",
9
+ description: "Execute a token swap through Jupiter, routed through the AgentShield vault " +
10
+ "with permission checks and spending limits enforced on-chain.",
11
+ similes: [
12
+ "swap tokens through shield",
13
+ "exchange tokens safely",
14
+ "shielded swap",
15
+ "protected token swap",
16
+ ],
17
+ validate: async (runtime, message) => {
18
+ // Check required config exists
19
+ try {
20
+ (0, client_factory_1.getOrCreateClient)(runtime);
21
+ }
22
+ catch {
23
+ return false;
24
+ }
25
+ // Check message matches swap intent
26
+ const text = (message.content?.text || "").toLowerCase();
27
+ const swapKeywords = ["swap", "exchange", "trade", "convert"];
28
+ return swapKeywords.some((kw) => text.includes(kw));
29
+ },
30
+ handler: async (runtime, message, _state, _options, callback) => {
31
+ try {
32
+ const { client, vaultOwner, vaultId, agentKey } = (0, client_factory_1.getOrCreateClient)(runtime);
33
+ const params = message.content;
34
+ if (!params.inputMint || !params.outputMint || !params.amount) {
35
+ callback({
36
+ text: "Missing required fields: inputMint, outputMint, and amount are required for a swap.",
37
+ error: true,
38
+ });
39
+ return;
40
+ }
41
+ const txSig = await client.executeJupiterSwap({
42
+ owner: vaultOwner,
43
+ vaultId,
44
+ agent: agentKey,
45
+ inputMint: new web3_js_1.PublicKey(params.inputMint),
46
+ outputMint: new web3_js_1.PublicKey(params.outputMint),
47
+ amount: new anchor_1.BN(params.amount),
48
+ slippageBps: params.slippageBps || 50,
49
+ });
50
+ callback({
51
+ text: `Swap executed successfully through AgentShield vault.\nTransaction: ${txSig}`,
52
+ data: { txSig },
53
+ });
54
+ }
55
+ catch (error) {
56
+ callback({
57
+ text: `Swap failed: ${error.message}`,
58
+ error: true,
59
+ });
60
+ }
61
+ },
62
+ examples: [
63
+ [
64
+ {
65
+ user: "{{user1}}",
66
+ content: {
67
+ text: "Swap 1 SOL for USDC through the shield vault",
68
+ inputMint: "So11111111111111111111111111111111111111112",
69
+ outputMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
70
+ amount: "1000000000",
71
+ },
72
+ },
73
+ {
74
+ user: "{{agent}}",
75
+ content: {
76
+ text: "Swap executed successfully through AgentShield vault.\nTransaction: 5xYz...",
77
+ },
78
+ },
79
+ ],
80
+ ],
81
+ };
82
+ //# sourceMappingURL=swap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/actions/swap.ts"],"names":[],"mappings":";;;AAAA,6CAA4C;AAC5C,8CAAuC;AACvC,sDAAsD;AAEzC,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,aAAa;IACnB,WAAW,EACT,6EAA6E;QAC7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QAAQ;gBACf,SAAS,EAAE,IAAI,mBAAS,CAAC,MAAM,CAAC,SAAS,CAAC;gBAC1C,UAAU,EAAE,IAAI,mBAAS,CAAC,MAAM,CAAC,UAAU,CAAC;gBAC5C,MAAM,EAAE,IAAI,WAAE,CAAC,MAAM,CAAC,MAAM,CAAC;gBAC7B,WAAW,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE;aACtC,CAAC,CAAC;YAEH,QAAQ,CAAC;gBACP,IAAI,EAAE,uEAAuE,KAAK,EAAE;gBACpF,IAAI,EAAE,EAAE,KAAK,EAAE;aAChB,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,QAAQ,CAAC;gBACP,IAAI,EAAE,gBAAgB,KAAK,CAAC,OAAO,EAAE;gBACrC,KAAK,EAAE,IAAI;aACZ,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,QAAQ,EAAE;QACR;YACE;gBACE,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP,IAAI,EAAE,8CAA8C;oBACpD,SAAS,EAAE,6CAA6C;oBACxD,UAAU,EAAE,8CAA8C;oBAC1D,MAAM,EAAE,YAAY;iBACrB;aACF;YACD;gBACE,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE;oBACP,IAAI,EAAE,6EAA6E;iBACpF;aACF;SACF;KACF;CACF,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ import { BN } from "@coral-xyz/anchor";
3
+ import { AgentShieldClient } from "@agent-shield/sdk";
4
+ import { AgentShieldElizaConfig } from "./types";
5
+ /**
6
+ * Reads AgentShield config from ElizaOS runtime settings.
7
+ */
8
+ export declare function getConfig(runtime: any): AgentShieldElizaConfig;
9
+ /**
10
+ * Gets or creates an AgentShieldClient for the given ElizaOS runtime.
11
+ * Cached per runtime instance via WeakMap.
12
+ */
13
+ export declare function getOrCreateClient(runtime: any): {
14
+ client: AgentShieldClient;
15
+ vaultOwner: PublicKey;
16
+ vaultId: BN;
17
+ agentKey: PublicKey;
18
+ };
19
+ //# sourceMappingURL=client-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-factory.d.ts","sourceRoot":"","sources":["../src/client-factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjE,OAAO,EAAE,EAAE,EAAU,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAY,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAI3D;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,GAAG,GAAG,sBAAsB,CAc9D;AAmBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,GAAG,GAAG;IAC/C,MAAM,EAAE,iBAAiB,CAAC;IAC1B,UAAU,EAAE,SAAS,CAAC;IACtB,OAAO,EAAE,EAAE,CAAC;IACZ,QAAQ,EAAE,SAAS,CAAC;CACrB,CA8BA"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfig = getConfig;
4
+ exports.getOrCreateClient = getOrCreateClient;
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const anchor_1 = require("@coral-xyz/anchor");
7
+ const sdk_1 = require("@agent-shield/sdk");
8
+ const types_1 = require("./types");
9
+ const clientCache = new WeakMap();
10
+ /**
11
+ * Reads AgentShield config from ElizaOS runtime settings.
12
+ */
13
+ function getConfig(runtime) {
14
+ const get = (key) => {
15
+ const val = runtime.getSetting(key);
16
+ if (!val)
17
+ throw new Error(`AgentShield: missing required setting '${key}'`);
18
+ return val;
19
+ };
20
+ return {
21
+ vaultOwner: get(types_1.ENV_KEYS.VAULT_OWNER),
22
+ vaultId: get(types_1.ENV_KEYS.VAULT_ID),
23
+ programId: runtime.getSetting(types_1.ENV_KEYS.PROGRAM_ID) || undefined,
24
+ rpcUrl: get(types_1.ENV_KEYS.RPC_URL),
25
+ walletPrivateKey: get(types_1.ENV_KEYS.WALLET_PRIVATE_KEY),
26
+ };
27
+ }
28
+ /**
29
+ * Parses a private key from either base58 or JSON array format.
30
+ */
31
+ function parseKeypair(raw) {
32
+ try {
33
+ const parsed = JSON.parse(raw);
34
+ if (Array.isArray(parsed)) {
35
+ return web3_js_1.Keypair.fromSecretKey(Uint8Array.from(parsed));
36
+ }
37
+ }
38
+ catch {
39
+ // Not JSON — try base58
40
+ }
41
+ // base58 secret key (64 bytes)
42
+ const bs58 = require("bs58");
43
+ return web3_js_1.Keypair.fromSecretKey(bs58.decode(raw));
44
+ }
45
+ /**
46
+ * Gets or creates an AgentShieldClient for the given ElizaOS runtime.
47
+ * Cached per runtime instance via WeakMap.
48
+ */
49
+ function getOrCreateClient(runtime) {
50
+ const cached = clientCache.get(runtime);
51
+ const config = getConfig(runtime);
52
+ if (cached) {
53
+ return {
54
+ client: cached,
55
+ vaultOwner: new web3_js_1.PublicKey(config.vaultOwner),
56
+ vaultId: new anchor_1.BN(config.vaultId),
57
+ agentKey: parseKeypair(config.walletPrivateKey).publicKey,
58
+ };
59
+ }
60
+ const connection = new web3_js_1.Connection(config.rpcUrl, "confirmed");
61
+ const keypair = parseKeypair(config.walletPrivateKey);
62
+ const wallet = new anchor_1.Wallet(keypair);
63
+ const programId = config.programId
64
+ ? new web3_js_1.PublicKey(config.programId)
65
+ : undefined;
66
+ const client = new sdk_1.AgentShieldClient(connection, wallet, programId);
67
+ clientCache.set(runtime, client);
68
+ return {
69
+ client,
70
+ vaultOwner: new web3_js_1.PublicKey(config.vaultOwner),
71
+ vaultId: new anchor_1.BN(config.vaultId),
72
+ agentKey: keypair.publicKey,
73
+ };
74
+ }
75
+ //# sourceMappingURL=client-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client-factory.js","sourceRoot":"","sources":["../src/client-factory.ts"],"names":[],"mappings":";;AAUA,8BAcC;AAuB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from "./policyCheck";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/evaluators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.policyCheckEvaluator = void 0;
4
+ var policyCheck_1 = require("./policyCheck");
5
+ Object.defineProperty(exports, "policyCheckEvaluator", { enumerable: true, get: function () { return policyCheck_1.policyCheckEvaluator; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/evaluators/index.ts"],"names":[],"mappings":";;;AAAA,6CAAqD;AAA5C,mHAAA,oBAAoB,OAAA"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Policy Check Evaluator — runs after SHIELD actions and warns
3
+ * if the vault is approaching its daily spending cap.
4
+ */
5
+ export declare const policyCheckEvaluator: {
6
+ name: string;
7
+ description: string;
8
+ similes: string[];
9
+ validate: (_runtime: any, message: any) => Promise<boolean>;
10
+ handler: (runtime: any, _message: any) => Promise<{
11
+ text: string;
12
+ action: string;
13
+ } | null>;
14
+ examples: {
15
+ context: string;
16
+ messages: {
17
+ user: string;
18
+ content: {
19
+ text: string;
20
+ };
21
+ }[];
22
+ outcome: string;
23
+ }[];
24
+ };
25
+ //# sourceMappingURL=policyCheck.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policyCheck.d.ts","sourceRoot":"","sources":["../../src/evaluators/policyCheck.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,oBAAoB;;;;yBAOJ,GAAG,WAAW,GAAG,KAAG,OAAO,CAAC,OAAO,CAAC;uBAUtC,GAAG,YAAY,GAAG;;;;;;;;;;;;;;CAyD5C,CAAC"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.policyCheckEvaluator = void 0;
4
+ const client_factory_1 = require("../client-factory");
5
+ /**
6
+ * Policy Check Evaluator — runs after SHIELD actions and warns
7
+ * if the vault is approaching its daily spending cap.
8
+ */
9
+ exports.policyCheckEvaluator = {
10
+ name: "AGENT_SHIELD_POLICY_CHECK",
11
+ description: "Post-action evaluator that checks spending against the daily cap " +
12
+ "and warns if usage exceeds 80%.",
13
+ similes: ["check spending limits", "policy warning"],
14
+ validate: async (_runtime, message) => {
15
+ // Only evaluate after shield actions
16
+ const text = (message.content?.text || "").toLowerCase();
17
+ return (text.includes("agentshield") ||
18
+ text.includes("shield vault") ||
19
+ text.includes("transaction:"));
20
+ },
21
+ handler: async (runtime, _message) => {
22
+ try {
23
+ const { client, vaultOwner, vaultId } = (0, client_factory_1.getOrCreateClient)(runtime);
24
+ const [vaultPda] = client.getVaultPDA(vaultOwner, vaultId);
25
+ const tracker = await client.fetchTracker(vaultPda);
26
+ const policy = await client.fetchPolicy(vaultPda);
27
+ const now = Math.floor(Date.now() / 1000);
28
+ const windowStart = now - 24 * 60 * 60;
29
+ let totalSpent = BigInt(0);
30
+ for (const entry of tracker.rollingSpends) {
31
+ if (entry.timestamp.toNumber() >= windowStart) {
32
+ totalSpent += BigInt(entry.amountSpent.toString());
33
+ }
34
+ }
35
+ const cap = BigInt(policy.dailySpendingCap.toString());
36
+ if (cap === BigInt(0))
37
+ return null;
38
+ const usagePct = Number((totalSpent * BigInt(100)) / cap);
39
+ if (usagePct >= 80) {
40
+ const remaining = cap > totalSpent ? cap - totalSpent : BigInt(0);
41
+ return {
42
+ text: `WARNING: AgentShield vault has used ${usagePct}% of the daily spending cap. ` +
43
+ `Remaining budget: ${remaining.toString()} lamports. ` +
44
+ `Consider reducing trade sizes or waiting for the rolling window to reset.`,
45
+ action: "POLICY_WARNING",
46
+ };
47
+ }
48
+ return null;
49
+ }
50
+ catch {
51
+ // Silently fail — evaluators should not block the agent
52
+ return null;
53
+ }
54
+ },
55
+ examples: [
56
+ {
57
+ context: "Agent just executed a swap that pushed spending to 85% of daily cap",
58
+ messages: [
59
+ {
60
+ user: "{{agent}}",
61
+ content: {
62
+ text: "Swap executed successfully through AgentShield vault.\nTransaction: 5xYz...",
63
+ },
64
+ },
65
+ ],
66
+ outcome: "WARNING: AgentShield vault has used 85% of the daily spending cap. " +
67
+ "Remaining budget: 150000000 lamports.",
68
+ },
69
+ ],
70
+ };
71
+ //# sourceMappingURL=policyCheck.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policyCheck.js","sourceRoot":"","sources":["../../src/evaluators/policyCheck.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AAEtD;;;GAGG;AACU,QAAA,oBAAoB,GAAG;IAClC,IAAI,EAAE,2BAA2B;IACjC,WAAW,EACT,mEAAmE;QACnE,iCAAiC;IACnC,OAAO,EAAE,CAAC,uBAAuB,EAAE,gBAAgB,CAAC;IAEpD,QAAQ,EAAE,KAAK,EAAE,QAAa,EAAE,OAAY,EAAoB,EAAE;QAChE,qCAAqC;QACrC,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QACzD,OAAO,CACL,IAAI,CAAC,QAAQ,CAAC,aAAa,CAAC;YAC5B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC;YAC7B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAC9B,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAY,EAAE,QAAa,EAAE,EAAE;QAC7C,IAAI,CAAC;YACH,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAA,kCAAiB,EAAC,OAAO,CAAC,CAAC;YACnE,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,WAAW,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YAE3D,MAAM,OAAO,GAA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ACd,CAAC;QAAC,MAAM,CAAC;YACP,wDAAwD;YACxD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,QAAQ,EAAE;QACR;YACE,OAAO,EAAE,qEAAqE;YAC9E,QAAQ,EAAE;gBACR;oBACE,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE;wBACP,IAAI,EAAE,6EAA6E;qBACpF;iBACF;aACF;YACD,OAAO,EACL,qEAAqE;gBACrE,uCAAuC;SAC1C;KACF;CACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ export { agentShieldPlugin } from "./plugin";
2
+ export { ENV_KEYS, type AgentShieldElizaConfig } from "./types";
3
+ export { getOrCreateClient, getConfig } from "./client-factory";
4
+ export { swapAction, openPositionAction, closePositionAction } from "./actions";
5
+ export { vaultStatusProvider, spendTrackingProvider } from "./providers";
6
+ export { policyCheckEvaluator } from "./evaluators";
7
+ import { agentShieldPlugin } from "./plugin";
8
+ export default agentShieldPlugin;
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,KAAK,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,eAAe,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.policyCheckEvaluator = exports.spendTrackingProvider = exports.vaultStatusProvider = exports.closePositionAction = exports.openPositionAction = exports.swapAction = exports.getConfig = exports.getOrCreateClient = exports.ENV_KEYS = exports.agentShieldPlugin = void 0;
4
+ var plugin_1 = require("./plugin");
5
+ Object.defineProperty(exports, "agentShieldPlugin", { enumerable: true, get: function () { return plugin_1.agentShieldPlugin; } });
6
+ var types_1 = require("./types");
7
+ Object.defineProperty(exports, "ENV_KEYS", { enumerable: true, get: function () { return types_1.ENV_KEYS; } });
8
+ var client_factory_1 = require("./client-factory");
9
+ Object.defineProperty(exports, "getOrCreateClient", { enumerable: true, get: function () { return client_factory_1.getOrCreateClient; } });
10
+ Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return client_factory_1.getConfig; } });
11
+ var actions_1 = require("./actions");
12
+ Object.defineProperty(exports, "swapAction", { enumerable: true, get: function () { return actions_1.swapAction; } });
13
+ Object.defineProperty(exports, "openPositionAction", { enumerable: true, get: function () { return actions_1.openPositionAction; } });
14
+ Object.defineProperty(exports, "closePositionAction", { enumerable: true, get: function () { return actions_1.closePositionAction; } });
15
+ var providers_1 = require("./providers");
16
+ Object.defineProperty(exports, "vaultStatusProvider", { enumerable: true, get: function () { return providers_1.vaultStatusProvider; } });
17
+ Object.defineProperty(exports, "spendTrackingProvider", { enumerable: true, get: function () { return providers_1.spendTrackingProvider; } });
18
+ var evaluators_1 = require("./evaluators");
19
+ Object.defineProperty(exports, "policyCheckEvaluator", { enumerable: true, get: function () { return evaluators_1.policyCheckEvaluator; } });
20
+ // Default export for ElizaOS plugin loader
21
+ const plugin_2 = require("./plugin");
22
+ exports.default = plugin_2.agentShieldPlugin;
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA6C;AAApC,2GAAA,iBAAiB,OAAA;AAC1B,iCAAgE;AAAvD,iGAAA,QAAQ,OAAA;AACjB,mDAAgE;AAAvD,mHAAA,iBAAiB,OAAA;AAAE,2GAAA,SAAS,OAAA;AACrC,qCAAgF;AAAvE,qGAAA,UAAU,OAAA;AAAE,6GAAA,kBAAkB,OAAA;AAAE,8GAAA,mBAAmB,OAAA;AAC5D,yCAAyE;AAAhE,gHAAA,mBAAmB,OAAA;AAAE,kHAAA,qBAAqB,OAAA;AACnD,2CAAoD;AAA3C,kHAAA,oBAAoB,OAAA;AAE7B,2CAA2C;AAC3C,qCAA6C;AAC7C,kBAAe,0BAAiB,CAAC"}
@@ -0,0 +1,136 @@
1
+ /**
2
+ * AgentShield Plugin for ElizaOS.
3
+ *
4
+ * Provides:
5
+ * - Actions: SHIELD_SWAP, SHIELD_OPEN_POSITION, SHIELD_CLOSE_POSITION
6
+ * - Providers: vault status, spend tracking (injected into agent context)
7
+ * - Evaluators: policy cap warning (runs after shield actions)
8
+ *
9
+ * Required environment variables:
10
+ * - AGENT_SHIELD_VAULT_OWNER — vault owner public key
11
+ * - AGENT_SHIELD_VAULT_ID — vault identifier
12
+ * - SOLANA_RPC_URL — Solana RPC endpoint
13
+ * - SOLANA_WALLET_PRIVATE_KEY — agent wallet key
14
+ *
15
+ * Optional:
16
+ * - AGENT_SHIELD_PROGRAM_ID — custom program ID override
17
+ */
18
+ export declare const agentShieldPlugin: {
19
+ name: string;
20
+ description: string;
21
+ actions: ({
22
+ name: string;
23
+ description: string;
24
+ similes: string[];
25
+ validate: (runtime: any, message: any) => Promise<boolean>;
26
+ handler: (runtime: any, message: any, _state: any, _options: any, callback: (response: any) => void) => Promise<void>;
27
+ examples: ({
28
+ user: string;
29
+ content: {
30
+ text: string;
31
+ inputMint: string;
32
+ outputMint: string;
33
+ amount: string;
34
+ };
35
+ } | {
36
+ user: string;
37
+ content: {
38
+ text: string;
39
+ inputMint?: undefined;
40
+ outputMint?: undefined;
41
+ amount?: undefined;
42
+ };
43
+ })[][];
44
+ } | {
45
+ name: string;
46
+ description: string;
47
+ similes: string[];
48
+ validate: (runtime: any, message: any) => Promise<boolean>;
49
+ handler: (runtime: any, message: any, _state: any, _options: any, callback: (response: any) => void) => Promise<void>;
50
+ examples: ({
51
+ user: string;
52
+ content: {
53
+ text: string;
54
+ targetSymbol: string;
55
+ collateralSymbol: string;
56
+ collateralAmount: string;
57
+ side: string;
58
+ };
59
+ } | {
60
+ user: string;
61
+ content: {
62
+ text: string;
63
+ targetSymbol?: undefined;
64
+ collateralSymbol?: undefined;
65
+ collateralAmount?: undefined;
66
+ side?: undefined;
67
+ };
68
+ })[][];
69
+ })[];
70
+ providers: ({
71
+ name: string;
72
+ description: string;
73
+ get: (runtime: any, _message: any, _state: any) => Promise<{
74
+ text: string;
75
+ values: {
76
+ vaultAddress: string;
77
+ vaultStatus: string;
78
+ dailySpendingCap: string;
79
+ maxTransactionSize: string;
80
+ openPositions: string;
81
+ maxPositions: string;
82
+ };
83
+ } | {
84
+ text: string;
85
+ values: {
86
+ vaultAddress?: undefined;
87
+ vaultStatus?: undefined;
88
+ dailySpendingCap?: undefined;
89
+ maxTransactionSize?: undefined;
90
+ openPositions?: undefined;
91
+ maxPositions?: undefined;
92
+ };
93
+ }>;
94
+ } | {
95
+ name: string;
96
+ description: string;
97
+ get: (runtime: any, _message: any, _state: any) => Promise<{
98
+ text: string;
99
+ values: {
100
+ totalSpent24h: string;
101
+ dailyCap: string;
102
+ remainingBudget: string;
103
+ usagePercent: string;
104
+ };
105
+ } | {
106
+ text: string;
107
+ values: {
108
+ totalSpent24h?: undefined;
109
+ dailyCap?: undefined;
110
+ remainingBudget?: undefined;
111
+ usagePercent?: undefined;
112
+ };
113
+ }>;
114
+ })[];
115
+ evaluators: {
116
+ name: string;
117
+ description: string;
118
+ similes: string[];
119
+ validate: (_runtime: any, message: any) => Promise<boolean>;
120
+ handler: (runtime: any, _message: any) => Promise<{
121
+ text: string;
122
+ action: string;
123
+ } | null>;
124
+ examples: {
125
+ context: string;
126
+ messages: {
127
+ user: string;
128
+ content: {
129
+ text: string;
130
+ };
131
+ }[];
132
+ outcome: string;
133
+ }[];
134
+ }[];
135
+ };
136
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqB7B,CAAC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agentShieldPlugin = void 0;
4
+ const actions_1 = require("./actions");
5
+ const providers_1 = require("./providers");
6
+ const evaluators_1 = require("./evaluators");
7
+ /**
8
+ * AgentShield Plugin for ElizaOS.
9
+ *
10
+ * Provides:
11
+ * - Actions: SHIELD_SWAP, SHIELD_OPEN_POSITION, SHIELD_CLOSE_POSITION
12
+ * - Providers: vault status, spend tracking (injected into agent context)
13
+ * - Evaluators: policy cap warning (runs after shield actions)
14
+ *
15
+ * Required environment variables:
16
+ * - AGENT_SHIELD_VAULT_OWNER — vault owner public key
17
+ * - AGENT_SHIELD_VAULT_ID — vault identifier
18
+ * - SOLANA_RPC_URL — Solana RPC endpoint
19
+ * - SOLANA_WALLET_PRIVATE_KEY — agent wallet key
20
+ *
21
+ * Optional:
22
+ * - AGENT_SHIELD_PROGRAM_ID — custom program ID override
23
+ */
24
+ exports.agentShieldPlugin = {
25
+ name: "agent-shield",
26
+ description: "AgentShield — Permission-guarded DeFi vault for AI agents. " +
27
+ "Routes swaps through Jupiter and perp trades through Flash Trade " +
28
+ "with on-chain spending caps, token whitelists, and leverage limits.",
29
+ actions: [
30
+ actions_1.swapAction,
31
+ actions_1.openPositionAction,
32
+ actions_1.closePositionAction,
33
+ ],
34
+ providers: [
35
+ providers_1.vaultStatusProvider,
36
+ providers_1.spendTrackingProvider,
37
+ ],
38
+ evaluators: [
39
+ evaluators_1.policyCheckEvaluator,
40
+ ],
41
+ };
42
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":";;;AAAA,uCAAgF;AAChF,2CAAyE;AACzE,6CAAoD;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACU,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,cAAc;IACpB,WAAW,EACT,6DAA6D;QAC7D,mEAAmE;QACnE,qEAAqE;IAEvE,OAAO,EAAE;QACP,oBAAU;QACV,4BAAkB;QAClB,6BAAmB;KACpB;IAED,SAAS,EAAE;QACT,+BAAmB;QACnB,iCAAqB;KACtB;IAED,UAAU,EAAE;QACV,iCAAoB;KACrB;CACF,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { vaultStatusProvider } from "./vaultStatus";
2
+ export { spendTrackingProvider } from "./spendTracking";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spendTrackingProvider = exports.vaultStatusProvider = void 0;
4
+ var vaultStatus_1 = require("./vaultStatus");
5
+ Object.defineProperty(exports, "vaultStatusProvider", { enumerable: true, get: function () { return vaultStatus_1.vaultStatusProvider; } });
6
+ var spendTracking_1 = require("./spendTracking");
7
+ Object.defineProperty(exports, "spendTrackingProvider", { enumerable: true, get: function () { return spendTracking_1.spendTrackingProvider; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AAA3C,kHAAA,mBAAmB,OAAA;AAC5B,iDAAwD;AAA/C,sHAAA,qBAAqB,OAAA"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Spend Tracking Provider — injects rolling 24h spend data and
3
+ * remaining budget into agent context.
4
+ */
5
+ export declare const spendTrackingProvider: {
6
+ name: string;
7
+ description: string;
8
+ get: (runtime: any, _message: any, _state: any) => Promise<{
9
+ text: string;
10
+ values: {
11
+ totalSpent24h: string;
12
+ dailyCap: string;
13
+ remainingBudget: string;
14
+ usagePercent: string;
15
+ };
16
+ } | {
17
+ text: string;
18
+ values: {
19
+ totalSpent24h?: undefined;
20
+ dailyCap?: undefined;
21
+ remainingBudget?: undefined;
22
+ usagePercent?: undefined;
23
+ };
24
+ }>;
25
+ };
26
+ //# sourceMappingURL=spendTracking.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spendTracking.d.ts","sourceRoot":"","sources":["../../src/providers/spendTracking.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,qBAAqB;;;mBAIX,GAAG,YAAY,GAAG,UAAU,GAAG;;;;;;;;;;;;;;;;;CAuDrD,CAAC"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.spendTrackingProvider = void 0;
4
+ const client_factory_1 = require("../client-factory");
5
+ /**
6
+ * Spend Tracking Provider — injects rolling 24h spend data and
7
+ * remaining budget into agent context.
8
+ */
9
+ exports.spendTrackingProvider = {
10
+ name: "AGENT_SHIELD_SPEND_TRACKING",
11
+ description: "Provides rolling 24h spending data and remaining budget for the AgentShield vault",
12
+ get: async (runtime, _message, _state) => {
13
+ try {
14
+ const { client, vaultOwner, vaultId } = (0, client_factory_1.getOrCreateClient)(runtime);
15
+ const [vaultPda] = client.getVaultPDA(vaultOwner, vaultId);
16
+ const tracker = await client.fetchTracker(vaultPda);
17
+ const policy = await client.fetchPolicy(vaultPda);
18
+ const now = Math.floor(Date.now() / 1000);
19
+ const windowStart = now - 24 * 60 * 60;
20
+ // Sum active spends within the 24h window
21
+ let totalSpent = BigInt(0);
22
+ const spendByToken = new Map();
23
+ for (const entry of tracker.rollingSpends) {
24
+ if (entry.timestamp.toNumber() >= windowStart) {
25
+ const amount = BigInt(entry.amountSpent.toString());
26
+ totalSpent += amount;
27
+ const mint = entry.tokenMint.toBase58();
28
+ spendByToken.set(mint, (spendByToken.get(mint) || BigInt(0)) + amount);
29
+ }
30
+ }
31
+ const cap = BigInt(policy.dailySpendingCap.toString());
32
+ const remaining = cap > totalSpent ? cap - totalSpent : BigInt(0);
33
+ const usagePct = cap > BigInt(0) ? Number((totalSpent * BigInt(100)) / cap) : 0;
34
+ const lines = [
35
+ `AgentShield Spending (24h rolling):`,
36
+ ` Total Spent: ${totalSpent.toString()} / ${cap.toString()} lamports (${usagePct}%)`,
37
+ ` Remaining Budget: ${remaining.toString()} lamports`,
38
+ ];
39
+ for (const [mint, spent] of spendByToken.entries()) {
40
+ lines.push(` ${mint.slice(0, 8)}...: ${spent.toString()} lamports`);
41
+ }
42
+ const text = lines.join("\n");
43
+ return {
44
+ text,
45
+ values: {
46
+ totalSpent24h: totalSpent.toString(),
47
+ dailyCap: cap.toString(),
48
+ remainingBudget: remaining.toString(),
49
+ usagePercent: usagePct.toString(),
50
+ },
51
+ };
52
+ }
53
+ catch (error) {
54
+ return {
55
+ text: `AgentShield: Unable to fetch spend data — ${error.message}`,
56
+ values: {},
57
+ };
58
+ }
59
+ },
60
+ };
61
+ //# sourceMappingURL=spendTracking.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spendTracking.js","sourceRoot":"","sources":["../../src/providers/spendTracking.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AAEtD;;;GAGG;AACU,QAAA,qBAAqB,GAAG;I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AAI,EAAE,6CAA6C,KAAK,CAAC,OAAO,EAAE;gBAClE,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Vault Status Provider — injects vault status and policy summary
3
+ * into every agent conversation turn.
4
+ */
5
+ export declare const vaultStatusProvider: {
6
+ name: string;
7
+ description: string;
8
+ get: (runtime: any, _message: any, _state: any) => Promise<{
9
+ text: string;
10
+ values: {
11
+ vaultAddress: string;
12
+ vaultStatus: string;
13
+ dailySpendingCap: string;
14
+ maxTransactionSize: string;
15
+ openPositions: string;
16
+ maxPositions: string;
17
+ };
18
+ } | {
19
+ text: string;
20
+ values: {
21
+ vaultAddress?: undefined;
22
+ vaultStatus?: undefined;
23
+ dailySpendingCap?: undefined;
24
+ maxTransactionSize?: undefined;
25
+ openPositions?: undefined;
26
+ maxPositions?: undefined;
27
+ };
28
+ }>;
29
+ };
30
+ //# sourceMappingURL=vaultStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vaultStatus.d.ts","sourceRoot":"","sources":["../../src/providers/vaultStatus.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,mBAAmB;;;mBAIT,GAAG,YAAY,GAAG,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;CA2CrD,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.vaultStatusProvider = void 0;
4
+ const client_factory_1 = require("../client-factory");
5
+ /**
6
+ * Vault Status Provider — injects vault status and policy summary
7
+ * into every agent conversation turn.
8
+ */
9
+ exports.vaultStatusProvider = {
10
+ name: "AGENT_SHIELD_VAULT_STATUS",
11
+ description: "Provides current AgentShield vault status, owner, agent, and policy summary",
12
+ get: async (runtime, _message, _state) => {
13
+ try {
14
+ const { client, vaultOwner, vaultId } = (0, client_factory_1.getOrCreateClient)(runtime);
15
+ const [vaultPda] = client.getVaultPDA(vaultOwner, vaultId);
16
+ const vault = await client.fetchVaultByAddress(vaultPda);
17
+ const policy = await client.fetchPolicy(vaultPda);
18
+ const status = Object.keys(vault.status)[0];
19
+ const tokenCount = policy.allowedTokens.length;
20
+ const protocolCount = policy.allowedProtocols.length;
21
+ const text = [
22
+ `AgentShield Vault: ${vaultPda.toBase58()}`,
23
+ `Status: ${status}`,
24
+ `Owner: ${vault.owner.toBase58()}`,
25
+ `Agent: ${vault.agent.toBase58()}`,
26
+ `Daily Cap: ${policy.dailySpendingCap.toString()} lamports`,
27
+ `Max Tx Size: ${policy.maxTransactionSize.toString()} lamports`,
28
+ `Whitelisted: ${tokenCount} tokens, ${protocolCount} protocols`,
29
+ `Max Leverage: ${(policy.maxLeverageBps / 100).toFixed(1)}x`,
30
+ `Positions: ${vault.openPositions}/${policy.maxConcurrentPositions}`,
31
+ `Fee: ${(policy.feeBps / 100).toFixed(2)}%`,
32
+ ].join("\n");
33
+ return {
34
+ text,
35
+ values: {
36
+ vaultAddress: vaultPda.toBase58(),
37
+ vaultStatus: status,
38
+ dailySpendingCap: policy.dailySpendingCap.toString(),
39
+ maxTransactionSize: policy.maxTransactionSize.toString(),
40
+ openPositions: vault.openPositions.toString(),
41
+ maxPositions: policy.maxConcurrentPositions.toString(),
42
+ },
43
+ };
44
+ }
45
+ catch (error) {
46
+ return {
47
+ text: `AgentShield: Unable to fetch vault status — ${error.message}`,
48
+ values: {},
49
+ };
50
+ }
51
+ },
52
+ };
53
+ //# sourceMappingURL=vaultStatus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vaultStatus.js","sourceRoot":"","sources":["../../src/providers/vaultStatus.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AAEtD;;;GAGG;AACU,QAAA,mBAAmB,GAAG;IACjC,IAAI,EAAE,2BAA2B;IACjC,WAAW,EAAE,6EAA6E;IAE1F,GAAG,EAAE,KAAK,EAAE,OAAY,EAAE,QAAa,EAAE,MAAW,EAAE,EAAE;QAC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,CAAC,CAAC;YAEb,OAAO;gBACL,IAAI;gBACJ,MAAM,EAAE;oBACN,YAAY,EAAE,QAAQ,CAAC,QAAQ,EAAE;oBACjC,WAAW,EAAE,MAAM;oBACnB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,CAAC,QAAQ,EAAE;oBACpD,kBAAkB,EAAE,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE;oBACxD,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,QAAQ,EAAE;oBAC7C,YAAY,EAAE,MAAM,CAAC,sBAAsB,CAAC,QAAQ,EAAE;iBACvD;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,OAAO;gBACL,IAAI,EAAE,+CAA+C,KAAK,CAAC,OAAO,EAAE;gBACpE,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Environment variable keys used by the AgentShield ElizaOS plugin.
3
+ * Configure these in your ElizaOS `.env` or character settings.
4
+ */
5
+ export declare const ENV_KEYS: {
6
+ /** Vault owner public key (base58) */
7
+ readonly VAULT_OWNER: "AGENT_SHIELD_VAULT_OWNER";
8
+ /** Vault ID (u64 as string) */
9
+ readonly VAULT_ID: "AGENT_SHIELD_VAULT_ID";
10
+ /** Optional AgentShield program ID override */
11
+ readonly PROGRAM_ID: "AGENT_SHIELD_PROGRAM_ID";
12
+ /** Solana RPC URL */
13
+ readonly RPC_URL: "SOLANA_RPC_URL";
14
+ /** Solana wallet private key (base58 or JSON array) */
15
+ readonly WALLET_PRIVATE_KEY: "SOLANA_WALLET_PRIVATE_KEY";
16
+ };
17
+ export interface AgentShieldElizaConfig {
18
+ vaultOwner: string;
19
+ vaultId: string;
20
+ programId?: string;
21
+ rpcUrl: string;
22
+ walletPrivateKey: string;
23
+ }
24
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,QAAQ;IACnB,sCAAsC;;IAEtC,+BAA+B;;IAE/B,+CAA+C;;IAE/C,qBAAqB;;IAErB,uDAAuD;;CAE/C,CAAC;AAEX,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,EAAE,MAAM,CAAC;CAC1B"}
package/dist/types.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENV_KEYS = void 0;
4
+ /**
5
+ * Environment variable keys used by the AgentShield ElizaOS plugin.
6
+ * Configure these in your ElizaOS `.env` or character settings.
7
+ */
8
+ exports.ENV_KEYS = {
9
+ /** Vault owner public key (base58) */
10
+ VAULT_OWNER: "AGENT_SHIELD_VAULT_OWNER",
11
+ /** Vault ID (u64 as string) */
12
+ VAULT_ID: "AGENT_SHIELD_VAULT_ID",
13
+ /** Optional AgentShield program ID override */
14
+ PROGRAM_ID: "AGENT_SHIELD_PROGRAM_ID",
15
+ /** Solana RPC URL */
16
+ RPC_URL: "SOLANA_RPC_URL",
17
+ /** Solana wallet private key (base58 or JSON array) */
18
+ WALLET_PRIVATE_KEY: "SOLANA_WALLET_PRIVATE_KEY",
19
+ };
20
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,QAAQ,GAAG;IACtB,sCAAsC;IACtC,WAAW,EAAE,0BAA0B;IACvC,+BAA+B;IAC/B,QAAQ,EAAE,uBAAuB;IACjC,+CAA+C;IAC/C,UAAU,EAAE,yBAAyB;IACrC,qBAAqB;IACrB,OAAO,EAAE,gBAAgB;IACzB,uDAAuD;IACvD,kBAAkB,EAAE,2BAA2B;CACvC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@agent-shield/plugin-elizaos",
3
+ "version": "0.1.0",
4
+ "description": "AgentShield plugin for ElizaOS — provides DeFi actions, vault providers, and policy evaluators",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "clean": "rm -rf dist",
10
+ "prepublishOnly": "npm run build"
11
+ },
12
+ "files": [
13
+ "dist/**/*"
14
+ ],
15
+ "peerDependencies": {
16
+ "@elizaos/core": ">=0.1.0",
17
+ "@agent-shield/sdk": ">=0.1.0",
18
+ "@solana/web3.js": ">=1.90.0",
19
+ "@coral-xyz/anchor": ">=0.30.0"
20
+ },
21
+ "devDependencies": {
22
+ "typescript": "^5.3.0",
23
+ "@elizaos/core": "^0.1.0",
24
+ "@agent-shield/sdk": "0.1.0",
25
+ "@solana/web3.js": "^1.95.0",
26
+ "@coral-xyz/anchor": "^0.32.0"
27
+ },
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/agent-shield/agent-shield",
32
+ "directory": "plugins/elizaos"
33
+ }
34
+ }