solana-agent-kit-plugin-madeonsol 0.2.0 → 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.
@@ -1,57 +1,126 @@
1
- /**
2
- * Tool functions — pure logic that calls MadeOnSol x402 API.
3
- * These are called by Action handlers and can also be used directly via agent.methods.
4
- */
5
- const BASE_URL = "https://madeonsol.com";
6
- async function query(paidFetch, path, params) {
7
- const url = new URL(path, BASE_URL);
8
- if (params) {
9
- for (const [k, v] of Object.entries(params)) {
10
- if (v !== undefined)
11
- url.searchParams.set(k, String(v));
12
- }
13
- }
14
- const res = await paidFetch(url.toString());
15
- if (!res.ok) {
16
- const body = await res.text().catch(() => "");
17
- throw new Error(`MadeOnSol API error ${res.status}: ${body}`);
18
- }
19
- return res.json();
20
- }
21
- let _paidFetch = null;
22
- export async function initPaidFetch(agent) {
23
- if (_paidFetch)
24
- return _paidFetch;
25
- const privateKey = agent.config?.SVM_PRIVATE_KEY || agent.config?.OTHER_API_KEYS?.SVM_PRIVATE_KEY;
26
- if (!privateKey) {
27
- console.warn("[madeonsol] No SVM_PRIVATE_KEY in agent config — x402 payments disabled");
28
- _paidFetch = fetch;
29
- return _paidFetch;
30
- }
31
- const { wrapFetchWithPayment } = await import("@x402/fetch");
32
- const { x402Client } = await import("@x402/core/client");
33
- const { ExactSvmScheme } = await import("@x402/svm/exact/client");
34
- const { createKeyPairSignerFromBytes } = await import("@solana/kit");
35
- const { base58 } = await import("@scure/base");
36
- const signer = await createKeyPairSignerFromBytes(base58.decode(privateKey));
37
- const client = new x402Client();
38
- client.register("solana:*", new ExactSvmScheme(signer));
39
- _paidFetch = wrapFetchWithPayment(fetch, client);
40
- return _paidFetch;
41
- }
42
- export async function kolFeed(agent, params = {}) {
43
- const f = await initPaidFetch(agent);
44
- return query(f, "/api/x402/kol/feed", params);
45
- }
46
- export async function kolCoordination(agent, params = {}) {
47
- const f = await initPaidFetch(agent);
48
- return query(f, "/api/x402/kol/coordination", params);
49
- }
50
- export async function kolLeaderboard(agent, params = {}) {
51
- const f = await initPaidFetch(agent);
52
- return query(f, "/api/x402/kol/leaderboard", params);
53
- }
54
- export async function deployerAlerts(agent, params = {}) {
55
- const f = await initPaidFetch(agent);
56
- return query(f, "/api/x402/deployer-hunter/alerts", params);
57
- }
1
+ /**
2
+ * Tool functions — pure logic that calls MadeOnSol API.
3
+ * Auth priority: MADEONSOL_API_KEY > RAPIDAPI_KEY > SVM_PRIVATE_KEY (x402).
4
+ * These are called by Action handlers and can also be used directly via agent.methods.
5
+ */
6
+ const BASE_URL = "https://madeonsol.com";
7
+ const RAPIDAPI_HOST = "madeonsol-solana-kol-tracker-tools-api.p.rapidapi.com";
8
+ let _authMode = null;
9
+ let _authHeaders = {};
10
+ let _paidFetch = null;
11
+ function getConfig(agent, key) {
12
+ return agent.config?.[key] || agent.config?.OTHER_API_KEYS?.[key];
13
+ }
14
+ export async function initAuth(agent) {
15
+ if (_authMode)
16
+ return;
17
+ const apiKey = getConfig(agent, "MADEONSOL_API_KEY");
18
+ const rapidApiKey = getConfig(agent, "RAPIDAPI_KEY");
19
+ const privateKey = getConfig(agent, "SVM_PRIVATE_KEY");
20
+ if (apiKey) {
21
+ _authMode = "madeonsol";
22
+ _authHeaders = { Authorization: `Bearer ${apiKey}` };
23
+ _paidFetch = fetch;
24
+ console.log("[madeonsol] Using MadeOnSol API key (Bearer auth)");
25
+ }
26
+ else if (rapidApiKey) {
27
+ _authMode = "rapidapi";
28
+ _authHeaders = { "x-rapidapi-key": rapidApiKey, "x-rapidapi-host": RAPIDAPI_HOST };
29
+ _paidFetch = fetch;
30
+ console.log("[madeonsol] Using RapidAPI key");
31
+ }
32
+ else if (privateKey) {
33
+ const { wrapFetchWithPayment } = await import("@x402/fetch");
34
+ const { x402Client } = await import("@x402/core/client");
35
+ const { ExactSvmScheme } = await import("@x402/svm/exact/client");
36
+ const { createKeyPairSignerFromBytes } = await import("@solana/kit");
37
+ const { base58 } = await import("@scure/base");
38
+ const signer = await createKeyPairSignerFromBytes(base58.decode(privateKey));
39
+ const client = new x402Client();
40
+ client.register("solana:*", new ExactSvmScheme(signer));
41
+ _paidFetch = wrapFetchWithPayment(fetch, client);
42
+ _authMode = "x402";
43
+ console.log(`[madeonsol] x402 payments enabled, wallet: ${signer.address}`);
44
+ }
45
+ else {
46
+ _authMode = "none";
47
+ _paidFetch = fetch;
48
+ console.warn("[madeonsol] No auth configured. Set MADEONSOL_API_KEY (free at madeonsol.com/developer), RAPIDAPI_KEY, or SVM_PRIVATE_KEY.");
49
+ }
50
+ }
51
+ /** @deprecated Use initAuth instead */
52
+ export async function initPaidFetch(agent) {
53
+ await initAuth(agent);
54
+ return _paidFetch;
55
+ }
56
+ async function query(path, params) {
57
+ const apiPath = _authMode === "x402" || _authMode === "none"
58
+ ? path
59
+ : path.replace("/api/x402/", "/api/v1/");
60
+ const url = new URL(apiPath, BASE_URL);
61
+ if (params) {
62
+ for (const [k, v] of Object.entries(params)) {
63
+ if (v !== undefined)
64
+ url.searchParams.set(k, String(v));
65
+ }
66
+ }
67
+ const res = _authMode === "x402"
68
+ ? await _paidFetch(url.toString())
69
+ : await fetch(url.toString(), { headers: _authHeaders });
70
+ if (!res.ok) {
71
+ const body = await res.text().catch(() => "");
72
+ throw new Error(`MadeOnSol API error ${res.status}: ${body}`);
73
+ }
74
+ return res.json();
75
+ }
76
+ export async function kolFeed(agent, params = {}) {
77
+ await initAuth(agent);
78
+ return query("/api/x402/kol/feed", params);
79
+ }
80
+ export async function kolCoordination(agent, params = {}) {
81
+ await initAuth(agent);
82
+ return query("/api/x402/kol/coordination", params);
83
+ }
84
+ export async function kolLeaderboard(agent, params = {}) {
85
+ await initAuth(agent);
86
+ return query("/api/x402/kol/leaderboard", params);
87
+ }
88
+ export async function deployerAlerts(agent, params = {}) {
89
+ await initAuth(agent);
90
+ return query("/api/x402/deployer-hunter/alerts", params);
91
+ }
92
+ // ── Webhook & Streaming (requires API key or RapidAPI key) ──
93
+ async function restQuery(agent, method, path, body) {
94
+ await initAuth(agent);
95
+ if (_authMode !== "madeonsol" && _authMode !== "rapidapi") {
96
+ throw new Error("API key or RapidAPI key required for webhook/streaming features. Get a free key at madeonsol.com/developer");
97
+ }
98
+ const res = await fetch(`${BASE_URL}/api/v1${path}`, {
99
+ method,
100
+ headers: {
101
+ "Content-Type": "application/json",
102
+ ..._authHeaders,
103
+ },
104
+ ...(body ? { body: JSON.stringify(body) } : {}),
105
+ });
106
+ if (!res.ok) {
107
+ const text = await res.text().catch(() => "");
108
+ throw new Error(`MadeOnSol API error ${res.status}: ${text}`);
109
+ }
110
+ return res.json();
111
+ }
112
+ export async function createWebhook(agent, params) {
113
+ return restQuery(agent, "POST", "/webhooks", params);
114
+ }
115
+ export async function listWebhooks(agent) {
116
+ return restQuery(agent, "GET", "/webhooks");
117
+ }
118
+ export async function deleteWebhook(agent, params) {
119
+ return restQuery(agent, "DELETE", `/webhooks/${params.id}`);
120
+ }
121
+ export async function testWebhook(agent, params) {
122
+ return restQuery(agent, "POST", "/webhooks/test", params);
123
+ }
124
+ export async function getStreamToken(agent) {
125
+ return restQuery(agent, "POST", "/stream/token");
126
+ }
package/package.json CHANGED
@@ -1,16 +1,26 @@
1
1
  {
2
2
  "name": "solana-agent-kit-plugin-madeonsol",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Solana Agent Kit plugin for MadeOnSol — KOL intelligence and deployer analytics via x402 micropayments",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
- "files": ["dist", "README.md"],
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
9
12
  "scripts": {
10
13
  "build": "tsc",
11
14
  "prepublishOnly": ""
12
15
  },
13
- "keywords": ["solana", "agent-kit", "x402", "kol", "trading", "madeonsol"],
16
+ "keywords": [
17
+ "solana",
18
+ "agent-kit",
19
+ "x402",
20
+ "kol",
21
+ "trading",
22
+ "madeonsol"
23
+ ],
14
24
  "license": "MIT",
15
25
  "repository": {
16
26
  "type": "git",
package/LICENSE DELETED
@@ -1 +0,0 @@
1
- MIT License