elizaos-plugin-solmachina 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 (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +62 -0
  3. package/index.js +121 -0
  4. package/package.json +25 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SolMachina
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # elizaos-plugin-solmachina
2
+
3
+ Put the **SolMachina financial firewall** in front of an ElizaOS agent's trades — the "Guard Everywhere"
4
+ pattern: before the agent executes a swap/buy, it asks SolMachina and proceeds **only on EXECUTE + policy ALLOW**.
5
+
6
+ One `SOLMACHINA_GUARD` call returns **EXECUTE / REVIEW / REJECT** + a risk index (SMRI) + evidence + a **signed,
7
+ time-boxed authorization** you can verify offline. Paid per call in USDC over **x402** (Solana + Base). No account.
8
+
9
+ ```bash
10
+ npm i elizaos-plugin-solmachina
11
+ ```
12
+
13
+ ## Use it
14
+
15
+ ```js
16
+ import { solmachinaPlugin } from "elizaos-plugin-solmachina";
17
+
18
+ // Wire your agent's x402-capable fetch (built from its Solana/Base wallet) to enable LIVE paid decisions:
19
+ const plugin = solmachinaPlugin({ payFetch, defaultPolicy: "conservative" });
20
+
21
+ // ...register `plugin` in your ElizaOS agent's `plugins: [...]`.
22
+ ```
23
+
24
+ Or the zero-config default (no wallet): the Guard action then returns the exact USDC **payment terms + guidance**
25
+ instead of a decision — it **never fabricates a verdict** without a real, paid answer.
26
+
27
+ ```js
28
+ import solmachina from "elizaos-plugin-solmachina"; // default export, no payFetch
29
+ ```
30
+
31
+ ## What the agent gets
32
+
33
+ The `SOLMACHINA_GUARD` action (similes: `CHECK_TOKEN`, `PRE_TRADE_CHECK`, `SHOULD_I_BUY`, `FINANCIAL_FIREWALL`):
34
+ - extracts the token mint from the message (or `options.mint`),
35
+ - calls `GET /v1/decision?mint=…&policy=…`,
36
+ - replies **✅ EXECUTE · SMRI 92 · ALLOW — safe to proceed** or **⛔ REJECT — do not proceed: <reasons>**,
37
+ - returns structured `data: { allowed, decision, verdict, smri, authorization, evidence }` for your agent logic.
38
+
39
+ A `SOLMACHINA_POLICY` provider injects the rule: *"before any swap/buy/transfer, call SOLMACHINA_GUARD and
40
+ proceed only on EXECUTE + ALLOW."*
41
+
42
+ ## Config (`runtime.getSetting` / .env)
43
+
44
+ | Setting | Meaning |
45
+ |---|---|
46
+ | `SOLMACHINA_BASE_URL` | API base (default `https://api.solmachina.com`) |
47
+ | `SOLMACHINA_POLICY` | named firewall: `conservative` \| `bluechip` \| `anti-rug` \| `degen` |
48
+
49
+ Payment is provided in code via `solmachinaPlugin({ payFetch })` (an x402 `fetch` from your agent's wallet — e.g.
50
+ `wrapFetchWithPayment` from `x402-fetch`). Without it, Guard runs in "terms + guidance" mode.
51
+
52
+ ## Status (honest)
53
+
54
+ Built to ElizaOS's **documented** plugin API (`Plugin` / `Action` / `Provider`, `runtime.getSetting`,
55
+ `HandlerCallback`). The action's logic — mint extraction, verdict formatting, fail-closed "no fabricated verdict"
56
+ behaviour — is covered by tests (`node --test index.test.mjs`, 7/7). **Not yet run inside a live ElizaOS agent
57
+ runtime**: load it in a real agent and confirm the action fires before publishing. Pin your `@elizaos/core`
58
+ version — the plugin API has evolved across major versions.
59
+
60
+ ## Links
61
+ Docs: https://api.solmachina.com/docs · SDK: `solmachina-sdk` · MCP: `https://api.solmachina.com/mcp` ·
62
+ registry: `io.github.imnotamob/solmachina-x402`. Not financial advice.
package/index.js ADDED
@@ -0,0 +1,121 @@
1
+ // @elizaos/plugin-solmachina — put the SolMachina financial firewall in front of an ElizaOS agent's trades.
2
+ //
3
+ // "Guard Everywhere": before an autonomous agent executes a swap/buy, it calls SOLMACHINA_GUARD(mint) and
4
+ // proceeds only on EXECUTE + policy ALLOW. One call returns EXECUTE / REVIEW / REJECT + a risk index + evidence
5
+ // + a signed, time-boxed authorization (verify offline). Paid per call in USDC over x402 (Solana + Base).
6
+ //
7
+ // Built to ElizaOS's documented plugin API (Plugin / Action / Provider, runtime.getSetting). Loadable as ESM.
8
+ // Payment: the real decision is a paid x402 call. Provide an x402-capable fetch (from your agent's wallet) via
9
+ // `solmachinaPlugin({ payFetch })`; without one, the action returns the exact USDC terms + guidance instead of
10
+ // a guessed verdict (honest — never fabricates a decision).
11
+
12
+ const DEFAULT_BASE = "https://api.solmachina.com";
13
+ const B58 = /[1-9A-HJ-NP-Za-km-z]{32,44}/; // first base58-looking run in free text
14
+ const KNOWN_POLICIES = new Set(["conservative", "bluechip", "anti-rug", "degen"]);
15
+
16
+ function decodeTerms(res) {
17
+ try {
18
+ const h = res.headers.get && res.headers.get("payment-required"); if (!h) return null;
19
+ const json = typeof atob === "function" ? atob(h) : Buffer.from(h, "base64").toString("utf8");
20
+ const t = JSON.parse(json);
21
+ return { resource: t?.resource?.url, accepts: (t?.accepts || []).map(a => ({ network: a.network, amount: a.amount, asset: a.asset, payTo: a.payTo })) };
22
+ } catch { return null; }
23
+ }
24
+
25
+ function extractMint(message, options) {
26
+ const fromOpts = options && (options.mint || options.token);
27
+ if (typeof fromOpts === "string" && fromOpts.trim()) return fromOpts.trim();
28
+ const text = (message && message.content && message.content.text) || "";
29
+ const m = String(text).match(B58);
30
+ return m ? m[0] : null;
31
+ }
32
+
33
+ /**
34
+ * Build the plugin. Pass an x402-capable `payFetch` (fetch(url,init) that handles 402→pay→retry, from your
35
+ * agent's Solana/Base wallet) to enable live paid Guard decisions. `baseUrl` and `defaultPolicy` optional.
36
+ * @param {{ payFetch?: Function, baseUrl?: string, defaultPolicy?: string }} [opts]
37
+ */
38
+ export function solmachinaPlugin(opts = {}) {
39
+ const baseUrl = String(opts.baseUrl || DEFAULT_BASE).replace(/\/+$/, "");
40
+
41
+ const guard = {
42
+ name: "SOLMACHINA_GUARD",
43
+ similes: ["CHECK_TOKEN", "PRE_TRADE_CHECK", "TOKEN_DECISION", "FINANCIAL_FIREWALL", "VERIFY_TOKEN", "SHOULD_I_BUY"],
44
+ description: "Before executing a swap/buy on Solana/Base, ask SolMachina whether the token passes your risk policy. Returns EXECUTE/REVIEW/REJECT + risk index + a signed authorization. Proceed only on EXECUTE + ALLOW.",
45
+
46
+ validate: async (runtime, message) => {
47
+ // valid whenever we can find a token mint to assess (options or a base58 run in the text)
48
+ return !!extractMint(message, (message && message.content) || {});
49
+ },
50
+
51
+ handler: async (runtime, message, _state, options, callback) => {
52
+ const mint = extractMint(message, options);
53
+ if (!mint) {
54
+ if (callback) await callback({ text: "SolMachina Guard: no token mint found to assess. Provide a Solana/Base token mint.", actions: ["SOLMACHINA_GUARD"], source: message?.content?.source });
55
+ return { text: "no mint", success: false };
56
+ }
57
+ const policy = (options && options.policy) || runtime.getSetting("SOLMACHINA_POLICY") || opts.defaultPolicy;
58
+ const qs = new URLSearchParams({ mint });
59
+ if (policy && KNOWN_POLICIES.has(String(policy))) qs.set("policy", String(policy));
60
+ const url = `${baseUrl}/v1/decision?${qs.toString()}`;
61
+ const doFetch = typeof opts.payFetch === "function" ? opts.payFetch : (globalThis.fetch);
62
+
63
+ let res;
64
+ try { res = await doFetch(url, { headers: { accept: "application/json" } }); }
65
+ catch (e) {
66
+ const msg = "SolMachina Guard: could not reach the decision service (" + String(e?.message || e) + ").";
67
+ if (callback) await callback({ text: msg, actions: ["SOLMACHINA_GUARD"], source: message?.content?.source });
68
+ return { text: msg, success: false };
69
+ }
70
+
71
+ if (res.status === 402) {
72
+ const terms = decodeTerms(res);
73
+ const msg = `SolMachina Guard is a paid x402 decision (USDC, Solana + Base). Wire your agent's x402 wallet as \`payFetch\` to enable live Guard verdicts.${terms ? ` Terms: pay ${terms.accepts?.[0]?.amount} atomic USDC to ${terms.accepts?.[0]?.payTo} on ${terms.accepts?.[0]?.network}.` : ""}`;
74
+ if (callback) await callback({ text: msg, actions: ["SOLMACHINA_GUARD"], source: message?.content?.source });
75
+ return { text: msg, success: false, data: { paymentRequired: true, terms } };
76
+ }
77
+
78
+ let body = null; try { body = await res.json(); } catch { /* leave null */ }
79
+ if (!res.ok || !body || body.error) {
80
+ const msg = `SolMachina Guard: decision unavailable (${body?.error || ("http " + res.status)}).`;
81
+ if (callback) await callback({ text: msg, actions: ["SOLMACHINA_GUARD"], source: message?.content?.source });
82
+ return { text: msg, success: false, data: body || null };
83
+ }
84
+
85
+ const verdict = body.policy && body.policy.verdict;
86
+ const allowed = body.decision === "EXECUTE" && (verdict == null || verdict === "ALLOW");
87
+ const bits = [`SolMachina ${body.decision}`];
88
+ if (body.smri != null) bits.push(`SMRI ${body.smri}`);
89
+ if (verdict) bits.push(`policy ${verdict}`);
90
+ if (body.reason) bits.push(body.reason);
91
+ const failed = (body.policy && body.policy.failed) || [];
92
+ const line = allowed
93
+ ? `✅ ${bits.join(" · ")} — passes your policy. Safe to proceed (not financial advice; authorization valid until ${body.authorization?.notAfterUtc}).`
94
+ : `⛔ ${bits.join(" · ")} — DO NOT proceed.${failed.length ? " Failed: " + failed.join("; ") : ""}`;
95
+ if (callback) await callback({ text: line, actions: ["SOLMACHINA_GUARD"], source: message?.content?.source });
96
+ return { text: line, success: true, data: { allowed, decision: body.decision, verdict: verdict || null, smri: body.smri, authorization: body.authorization, evidence: body.evidence } };
97
+ },
98
+
99
+ examples: [[
100
+ { name: "{{user}}", content: { text: "Should I buy DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263 ?" } },
101
+ { name: "{{agent}}", content: { text: "Let me run it through the SolMachina firewall first.", actions: ["SOLMACHINA_GUARD"] } },
102
+ ]],
103
+ };
104
+
105
+ const provider = {
106
+ name: "SOLMACHINA_POLICY",
107
+ description: "Reminds the agent to gate financially-sensitive actions through SolMachina Guard.",
108
+ get: async () => "Risk policy: before any swap, buy, or fund transfer on Solana/Base, call SOLMACHINA_GUARD(mint) and proceed ONLY on EXECUTE + policy ALLOW. Treat REVIEW/REJECT as stop.",
109
+ };
110
+
111
+ return {
112
+ name: "solmachina",
113
+ description: "SolMachina financial firewall for autonomous agents: EXECUTE/REVIEW/REJECT + signed authorization before a trade, paid per call in USDC over x402.",
114
+ actions: [guard],
115
+ providers: [provider],
116
+ services: [],
117
+ };
118
+ }
119
+
120
+ export const solmachinaPluginDefault = solmachinaPlugin();
121
+ export default solmachinaPluginDefault;
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "elizaos-plugin-solmachina",
3
+ "version": "0.1.0",
4
+ "description": "SolMachina financial firewall for ElizaOS agents — EXECUTE/REVIEW/REJECT + a signed, time-boxed authorization before a trade, paid per call in USDC over x402 (Solana + Base).",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "module": "index.js",
8
+ "exports": { ".": { "import": "./index.js" } },
9
+ "files": ["index.js", "README.md"],
10
+ "engines": { "node": ">=18" },
11
+ "keywords": ["elizaos", "elizaos-plugin", "eliza", "plugin", "solmachina", "x402", "solana", "base", "usdc", "ai-agents", "agent", "financial-firewall", "decision", "risk", "defi", "trading"],
12
+ "peerDependencies": { "@elizaos/core": ">=1.0.0" },
13
+ "peerDependenciesMeta": { "@elizaos/core": { "optional": true } },
14
+ "agentConfig": {
15
+ "pluginType": "elizaos:plugin:1.0.0",
16
+ "pluginParameters": {
17
+ "SOLMACHINA_BASE_URL": { "type": "string", "description": "SolMachina API base URL (default https://api.solmachina.com)", "required": false },
18
+ "SOLMACHINA_POLICY": { "type": "string", "description": "Named firewall policy: conservative | bluechip | anti-rug | degen", "required": false }
19
+ }
20
+ },
21
+ "homepage": "https://api.solmachina.com/docs",
22
+ "repository": { "type": "git", "url": "git+https://github.com/apisolmachina/elizaos-plugin-solmachina.git" },
23
+ "license": "MIT",
24
+ "author": "SolMachina"
25
+ }