nansen-cli 1.44.2 → 1.45.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.
- package/CHANGELOG.md +68 -0
- package/README.md +4 -1
- package/package.json +1 -1
- package/skills/nansen-wallet-clustering/REFERENCE.md +14 -2
- package/skills/nansen-wallet-clustering/SKILL.md +5 -0
- package/skills/nansen-wallet-profiler/SKILL.md +12 -0
- package/src/api.js +168 -11
- package/src/cli.js +286 -96
- package/src/commands/agent.js +65 -37
- package/src/commands/alerts.js +67 -53
- package/src/commands/mcp.js +6 -0
- package/src/commands/research.js +9 -2
- package/src/cost-cache.js +9 -1
- package/src/limit-order.js +10 -0
- package/src/query-options.js +30 -1
- package/src/schema.json +103 -35
- package/src/trade-validation.js +39 -5
- package/src/trading.js +33 -2
- package/src/update-check.js +9 -3
- package/src/wallet.js +4 -0
- package/src/walletconnect-x402.js +28 -38
- package/src/x402-svm.js +53 -12
package/src/commands/agent.js
CHANGED
|
@@ -66,11 +66,49 @@ export async function consumeSSEStream(response, callbacks = {}) {
|
|
|
66
66
|
const toolCalls = [];
|
|
67
67
|
let conversationId = null;
|
|
68
68
|
let errorPayload = null;
|
|
69
|
+
let done = false;
|
|
69
70
|
|
|
70
71
|
const reader = response.body;
|
|
71
72
|
const decoder = new TextDecoder();
|
|
72
73
|
let buffer = '';
|
|
73
74
|
|
|
75
|
+
const processFrame = (frame) => {
|
|
76
|
+
for (const line of frame.split('\n')) {
|
|
77
|
+
if (!line.startsWith('data: ')) continue;
|
|
78
|
+
const payload = line.slice(6);
|
|
79
|
+
if (payload === '[DONE]') { done = true; return; }
|
|
80
|
+
|
|
81
|
+
let event;
|
|
82
|
+
try {
|
|
83
|
+
event = JSON.parse(payload);
|
|
84
|
+
} catch {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
switch (event.type) {
|
|
89
|
+
case 'delta':
|
|
90
|
+
if (event.text) {
|
|
91
|
+
chunks.push(event.text);
|
|
92
|
+
if (onDelta) onDelta(event.text);
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
case 'tool_call':
|
|
96
|
+
if (event.name) {
|
|
97
|
+
toolCalls.push(event.name);
|
|
98
|
+
if (onToolCall) onToolCall(event.name);
|
|
99
|
+
}
|
|
100
|
+
break;
|
|
101
|
+
case 'finish':
|
|
102
|
+
conversationId = event.conversation_id ?? null;
|
|
103
|
+
break;
|
|
104
|
+
case 'error':
|
|
105
|
+
errorPayload = event;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
outer:
|
|
74
112
|
for await (const raw of reader) {
|
|
75
113
|
buffer += decoder.decode(raw, { stream: true });
|
|
76
114
|
|
|
@@ -79,47 +117,19 @@ export async function consumeSSEStream(response, callbacks = {}) {
|
|
|
79
117
|
|
|
80
118
|
// SSE: split on double-newline boundaries
|
|
81
119
|
let boundary;
|
|
82
|
-
let done = false;
|
|
83
120
|
while ((boundary = buffer.indexOf('\n\n')) !== -1) {
|
|
84
121
|
const frame = buffer.slice(0, boundary);
|
|
85
122
|
buffer = buffer.slice(boundary + 2);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (!line.startsWith('data: ')) continue;
|
|
89
|
-
const payload = line.slice(6);
|
|
90
|
-
if (payload === '[DONE]') { done = true; break; }
|
|
91
|
-
|
|
92
|
-
let event;
|
|
93
|
-
try {
|
|
94
|
-
event = JSON.parse(payload);
|
|
95
|
-
} catch {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
switch (event.type) {
|
|
100
|
-
case 'delta':
|
|
101
|
-
if (event.text) {
|
|
102
|
-
chunks.push(event.text);
|
|
103
|
-
if (onDelta) onDelta(event.text);
|
|
104
|
-
}
|
|
105
|
-
break;
|
|
106
|
-
case 'tool_call':
|
|
107
|
-
if (event.name) {
|
|
108
|
-
toolCalls.push(event.name);
|
|
109
|
-
if (onToolCall) onToolCall(event.name);
|
|
110
|
-
}
|
|
111
|
-
break;
|
|
112
|
-
case 'finish':
|
|
113
|
-
conversationId = event.conversation_id ?? null;
|
|
114
|
-
break;
|
|
115
|
-
case 'error':
|
|
116
|
-
errorPayload = event;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (done) break;
|
|
123
|
+
processFrame(frame);
|
|
124
|
+
if (done) break outer;
|
|
121
125
|
}
|
|
122
|
-
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Flush a trailing unterminated frame (stream closed without \n\n after
|
|
129
|
+
// the last event, e.g. 'finish' or a final 'delta').
|
|
130
|
+
if (!done && buffer.trim() !== '') {
|
|
131
|
+
buffer += decoder.decode(); // flush any pending multi-byte UTF-8 tail
|
|
132
|
+
processFrame(buffer);
|
|
123
133
|
}
|
|
124
134
|
|
|
125
135
|
if (errorPayload) {
|
|
@@ -300,11 +310,27 @@ EXAMPLES:
|
|
|
300
310
|
);
|
|
301
311
|
}
|
|
302
312
|
|
|
313
|
+
// Abort can also fire while reading the SSE body, not just during
|
|
314
|
+
// fetch() — wrap that AbortError the same way for a consistent error.
|
|
315
|
+
const wrapAbortDuringStream = (err) => {
|
|
316
|
+
if (err.name === 'AbortError') {
|
|
317
|
+
throw new NansenError(
|
|
318
|
+
`Request timed out after ${timeoutMs / 1000}s`,
|
|
319
|
+
ErrorCode.TIMEOUT,
|
|
320
|
+
504,
|
|
321
|
+
{ detail: `${modeName} mode timeout (${timeoutMs / 1000}s)` },
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
throw err;
|
|
325
|
+
};
|
|
326
|
+
|
|
303
327
|
// ── JSON mode: buffer everything, return structured data ──
|
|
304
328
|
if (flags.json) {
|
|
305
329
|
let result;
|
|
306
330
|
try {
|
|
307
331
|
result = await consumeSSEStream(response);
|
|
332
|
+
} catch (err) {
|
|
333
|
+
return wrapAbortDuringStream(err); // always throws; return makes intent explicit
|
|
308
334
|
} finally {
|
|
309
335
|
clearTimeout(timer);
|
|
310
336
|
}
|
|
@@ -333,6 +359,8 @@ EXAMPLES:
|
|
|
333
359
|
errorLog(`⚙ ${name}`);
|
|
334
360
|
},
|
|
335
361
|
});
|
|
362
|
+
} catch (err) {
|
|
363
|
+
return wrapAbortDuringStream(err); // always throws; return makes intent explicit
|
|
336
364
|
} finally {
|
|
337
365
|
clearTimeout(timer);
|
|
338
366
|
}
|
package/src/commands/alerts.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { NansenError, ErrorCode } from '../api.js';
|
|
7
|
+
import { parseCsvOption } from '../query-options.js';
|
|
7
8
|
|
|
8
9
|
// ============= Formatting =============
|
|
9
10
|
|
|
@@ -53,10 +54,13 @@ export function formatAlertsTable(alerts) {
|
|
|
53
54
|
* Parse a token string "address:chain" into { address, chain }.
|
|
54
55
|
* Handles single string or array of strings (from repeated --token flags).
|
|
55
56
|
*/
|
|
56
|
-
function parseTokens(tokenArg) {
|
|
57
|
-
if (
|
|
57
|
+
function parseTokens(tokenArg, name) {
|
|
58
|
+
if (tokenArg === undefined || tokenArg === '') return undefined;
|
|
58
59
|
const tokens = Array.isArray(tokenArg) ? tokenArg : [tokenArg];
|
|
59
60
|
return tokens.map(t => {
|
|
61
|
+
if (typeof t !== 'string') {
|
|
62
|
+
throw new NansenError(`--${name} values must be strings`, ErrorCode.INVALID_PARAMS);
|
|
63
|
+
}
|
|
60
64
|
const colonIdx = t.lastIndexOf(':');
|
|
61
65
|
if (colonIdx === -1) throw new NansenError(`Invalid token format: "${t}". Expected address:chain`, ErrorCode.INVALID_PARAMS);
|
|
62
66
|
return { address: t.slice(0, colonIdx), chain: t.slice(colonIdx + 1) };
|
|
@@ -67,10 +71,13 @@ function parseTokens(tokenArg) {
|
|
|
67
71
|
* Parse a subject string "type:value" into { type, value }.
|
|
68
72
|
* Handles single string or array (from repeated --subject flags).
|
|
69
73
|
*/
|
|
70
|
-
function parseSubjects(subjectArg) {
|
|
71
|
-
if (
|
|
74
|
+
function parseSubjects(subjectArg, name) {
|
|
75
|
+
if (subjectArg === undefined || subjectArg === '') return undefined;
|
|
72
76
|
const subjects = Array.isArray(subjectArg) ? subjectArg : [subjectArg];
|
|
73
77
|
return subjects.map(s => {
|
|
78
|
+
if (typeof s !== 'string') {
|
|
79
|
+
throw new NansenError(`--${name} values must be strings`, ErrorCode.INVALID_PARAMS);
|
|
80
|
+
}
|
|
74
81
|
const colonIdx = s.indexOf(':');
|
|
75
82
|
if (colonIdx === -1) throw new NansenError(`Invalid subject format: "${s}". Expected type:value`, ErrorCode.INVALID_PARAMS);
|
|
76
83
|
return { type: s.slice(0, colonIdx), value: s.slice(colonIdx + 1) };
|
|
@@ -102,9 +109,7 @@ function deepMergePlain(target, source) {
|
|
|
102
109
|
* Normalise chains option to array.
|
|
103
110
|
*/
|
|
104
111
|
function parseChains(chainsOpt) {
|
|
105
|
-
|
|
106
|
-
if (Array.isArray(chainsOpt)) return chainsOpt;
|
|
107
|
-
return chainsOpt.split(',').map(s => s.trim()).filter(Boolean);
|
|
112
|
+
return parseCsvOption(chainsOpt, 'chains');
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
/**
|
|
@@ -124,6 +129,30 @@ function parseFiniteNumber(raw, name) {
|
|
|
124
129
|
return n;
|
|
125
130
|
}
|
|
126
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Validate a single-value string filter option (e.g. --chain, --token-address).
|
|
134
|
+
* Empty string/undefined mean "not provided"; any other non-string value
|
|
135
|
+
* (e.g. `--chain true`, from parseArgs' JSON.parse of option values) is
|
|
136
|
+
* rejected instead of crashing on .toLowerCase() or being silently dropped
|
|
137
|
+
* by a falsy check.
|
|
138
|
+
*/
|
|
139
|
+
function parseStringFilter(val, name) {
|
|
140
|
+
if (val === undefined || val === '') return undefined;
|
|
141
|
+
if (typeof val !== 'string') {
|
|
142
|
+
throw new NansenError(`--${name} must be a string`, ErrorCode.INVALID_PARAMS);
|
|
143
|
+
}
|
|
144
|
+
return val;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function parseNonNegativeIntegerOption(raw, name) {
|
|
148
|
+
if (raw === undefined) return undefined;
|
|
149
|
+
const n = Number(raw);
|
|
150
|
+
if (!Number.isInteger(n) || n < 0) {
|
|
151
|
+
throw new NansenError(`--${name} must be a non-negative integer, got "${raw}"`, ErrorCode.INVALID_PARAMS);
|
|
152
|
+
}
|
|
153
|
+
return n;
|
|
154
|
+
}
|
|
155
|
+
|
|
127
156
|
/**
|
|
128
157
|
* Build a { min, max } range object from two option values.
|
|
129
158
|
* Returns undefined if neither is provided.
|
|
@@ -136,14 +165,6 @@ function buildRange(minVal, maxVal, name) {
|
|
|
136
165
|
return r;
|
|
137
166
|
}
|
|
138
167
|
|
|
139
|
-
/**
|
|
140
|
-
* Normalise a repeatable string option to array, or undefined if absent.
|
|
141
|
-
*/
|
|
142
|
-
function normArray(val) {
|
|
143
|
-
if (!val) return undefined;
|
|
144
|
-
return Array.isArray(val) ? val : [val];
|
|
145
|
-
}
|
|
146
|
-
|
|
147
168
|
/**
|
|
148
169
|
* Build the data payload for sm-token-flows alerts from named flags.
|
|
149
170
|
*/
|
|
@@ -162,14 +183,14 @@ export function buildSmTokenFlowsData(options) {
|
|
|
162
183
|
}
|
|
163
184
|
}
|
|
164
185
|
|
|
165
|
-
const tokens = parseTokens(options.token);
|
|
166
|
-
const excludeTokens = parseTokens(options['exclude-token']);
|
|
186
|
+
const tokens = parseTokens(options.token, 'token');
|
|
187
|
+
const excludeTokens = parseTokens(options['exclude-token'], 'exclude-token');
|
|
167
188
|
if (tokens) data.inclusion = { ...data.inclusion, tokens };
|
|
168
189
|
if (excludeTokens) data.exclusion = { ...data.exclusion, tokens: excludeTokens };
|
|
169
190
|
|
|
170
|
-
const sectors =
|
|
191
|
+
const sectors = parseCsvOption(options['token-sector'], 'token-sector');
|
|
171
192
|
if (sectors) data.inclusion = { ...data.inclusion, tokenSectors: sectors };
|
|
172
|
-
const excludeSectors =
|
|
193
|
+
const excludeSectors = parseCsvOption(options['exclude-token-sector'], 'exclude-token-sector');
|
|
173
194
|
if (excludeSectors) data.exclusion = { ...data.exclusion, tokenSectors: excludeSectors };
|
|
174
195
|
|
|
175
196
|
if (options['token-age-max'] !== undefined) {
|
|
@@ -194,9 +215,8 @@ export function buildCommonTokenTransferData(options) {
|
|
|
194
215
|
const chains = parseChains(options.chains);
|
|
195
216
|
if (chains) data.chains = chains;
|
|
196
217
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
218
|
+
const events = parseCsvOption(options.events, 'events');
|
|
219
|
+
if (events) data.events = events;
|
|
200
220
|
|
|
201
221
|
const usdRange = buildRange(options['usd-min'], options['usd-max'], 'usd');
|
|
202
222
|
if (usdRange) data.usdValue = usdRange;
|
|
@@ -204,20 +224,20 @@ export function buildCommonTokenTransferData(options) {
|
|
|
204
224
|
const amountRange = buildRange(options['token-amount-min'], options['token-amount-max'], 'token-amount');
|
|
205
225
|
if (amountRange) data.tokenAmount = amountRange;
|
|
206
226
|
|
|
207
|
-
const subjects = parseSubjects(options.subject);
|
|
227
|
+
const subjects = parseSubjects(options.subject, 'subject');
|
|
208
228
|
if (subjects) data.subjects = subjects;
|
|
209
229
|
|
|
210
|
-
const counterparties = parseSubjects(options.counterparty);
|
|
230
|
+
const counterparties = parseSubjects(options.counterparty, 'counterparty');
|
|
211
231
|
if (counterparties) data.counterparties = counterparties;
|
|
212
232
|
|
|
213
|
-
const tokens = parseTokens(options.token);
|
|
214
|
-
const excludeTokens = parseTokens(options['exclude-token']);
|
|
233
|
+
const tokens = parseTokens(options.token, 'token');
|
|
234
|
+
const excludeTokens = parseTokens(options['exclude-token'], 'exclude-token');
|
|
215
235
|
if (tokens) data.inclusion = { ...data.inclusion, tokens };
|
|
216
236
|
if (excludeTokens) data.exclusion = { ...data.exclusion, tokens: excludeTokens };
|
|
217
237
|
|
|
218
|
-
const sectors =
|
|
238
|
+
const sectors = parseCsvOption(options['token-sector'], 'token-sector');
|
|
219
239
|
if (sectors) data.inclusion = { ...data.inclusion, tokenSectors: sectors };
|
|
220
|
-
const excludeSectors =
|
|
240
|
+
const excludeSectors = parseCsvOption(options['exclude-token-sector'], 'exclude-token-sector');
|
|
221
241
|
if (excludeSectors) data.exclusion = { ...data.exclusion, tokenSectors: excludeSectors };
|
|
222
242
|
|
|
223
243
|
const tokenAgeMin = options['token-age-min'];
|
|
@@ -232,9 +252,9 @@ export function buildCommonTokenTransferData(options) {
|
|
|
232
252
|
const marketCapRange = buildRange(options['market-cap-min'], options['market-cap-max'], 'market-cap');
|
|
233
253
|
if (marketCapRange) data.inclusion = { ...data.inclusion, marketCap: marketCapRange };
|
|
234
254
|
|
|
235
|
-
const excludeFrom = parseSubjects(options['exclude-from']);
|
|
255
|
+
const excludeFrom = parseSubjects(options['exclude-from'], 'exclude-from');
|
|
236
256
|
if (excludeFrom) data.exclusion = { ...data.exclusion, fromTargets: excludeFrom };
|
|
237
|
-
const excludeTo = parseSubjects(options['exclude-to']);
|
|
257
|
+
const excludeTo = parseSubjects(options['exclude-to'], 'exclude-to');
|
|
238
258
|
if (excludeTo) data.exclusion = { ...data.exclusion, toTargets: excludeTo };
|
|
239
259
|
|
|
240
260
|
return data;
|
|
@@ -252,16 +272,13 @@ export function buildSmartContractCallData(options) {
|
|
|
252
272
|
const usdRange = buildRange(options['usd-min'], options['usd-max'], 'usd');
|
|
253
273
|
if (usdRange) data.usdValue = usdRange;
|
|
254
274
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
? options['signature-hash']
|
|
258
|
-
: [options['signature-hash']];
|
|
259
|
-
}
|
|
275
|
+
const signatureHash = parseCsvOption(options['signature-hash'], 'signature-hash');
|
|
276
|
+
if (signatureHash) data.signatureHash = signatureHash;
|
|
260
277
|
|
|
261
|
-
const callers = parseSubjects(options.caller);
|
|
262
|
-
const contracts = parseSubjects(options.contract);
|
|
263
|
-
const excludeCallers = parseSubjects(options['exclude-caller']);
|
|
264
|
-
const excludeContracts = parseSubjects(options['exclude-contract']);
|
|
278
|
+
const callers = parseSubjects(options.caller, 'caller');
|
|
279
|
+
const contracts = parseSubjects(options.contract, 'contract');
|
|
280
|
+
const excludeCallers = parseSubjects(options['exclude-caller'], 'exclude-caller');
|
|
281
|
+
const excludeContracts = parseSubjects(options['exclude-contract'], 'exclude-contract');
|
|
265
282
|
|
|
266
283
|
if (callers) data.inclusion = { ...data.inclusion, caller: callers };
|
|
267
284
|
if (contracts) data.inclusion = { ...data.inclusion, smartContract: contracts };
|
|
@@ -601,6 +618,11 @@ USAGE:
|
|
|
601
618
|
'list': async () => {
|
|
602
619
|
if (flags.enabled && flags.disabled) throw new NansenError('Cannot specify both --enabled and --disabled', ErrorCode.INVALID_PARAMS);
|
|
603
620
|
|
|
621
|
+
const offset = parseNonNegativeIntegerOption(options.offset, 'offset');
|
|
622
|
+
const limit = parseNonNegativeIntegerOption(options.limit, 'limit');
|
|
623
|
+
const tokenAddress = parseStringFilter(options['token-address'], 'token-address');
|
|
624
|
+
const chainFilter = parseStringFilter(options.chain, 'chain');
|
|
625
|
+
|
|
604
626
|
const results = await apiInstance.alertsList();
|
|
605
627
|
let alerts = Array.isArray(results) ? results : results?.alerts ?? results?.data ?? [];
|
|
606
628
|
|
|
@@ -608,15 +630,15 @@ USAGE:
|
|
|
608
630
|
if (options.type) alerts = alerts.filter(a => a.type === options.type);
|
|
609
631
|
if (flags.enabled) alerts = alerts.filter(a => a.isEnabled === true);
|
|
610
632
|
if (flags.disabled) alerts = alerts.filter(a => a.isEnabled === false);
|
|
611
|
-
if (
|
|
612
|
-
const addr =
|
|
633
|
+
if (tokenAddress) {
|
|
634
|
+
const addr = tokenAddress.toLowerCase();
|
|
613
635
|
alerts = alerts.filter(a => {
|
|
614
636
|
const allTokens = [...(a.data?.inclusion?.tokens ?? []), ...(a.data?.exclusion?.tokens ?? [])];
|
|
615
637
|
return allTokens.some(t => t.address?.toLowerCase() === addr);
|
|
616
638
|
});
|
|
617
639
|
}
|
|
618
|
-
if (
|
|
619
|
-
const ch =
|
|
640
|
+
if (chainFilter) {
|
|
641
|
+
const ch = chainFilter.toLowerCase();
|
|
620
642
|
alerts = alerts.filter(a => {
|
|
621
643
|
const chains = a.data?.chains;
|
|
622
644
|
return Array.isArray(chains) && chains.some(c => c.toLowerCase() === ch || c === 'all');
|
|
@@ -635,18 +657,10 @@ USAGE:
|
|
|
635
657
|
// - Negative values (`--offset -1`) were accepted and fed straight
|
|
636
658
|
// into `slice()`, which treats negative indices as "from the end" —
|
|
637
659
|
// silently returning the wrong slice instead of rejecting the input.
|
|
638
|
-
if (
|
|
639
|
-
const offset = Number(options.offset);
|
|
640
|
-
if (!Number.isInteger(offset) || offset < 0) {
|
|
641
|
-
throw new NansenError(`--offset must be a non-negative integer, got "${options.offset}"`, ErrorCode.INVALID_PARAMS);
|
|
642
|
-
}
|
|
660
|
+
if (offset !== undefined) {
|
|
643
661
|
alerts = alerts.slice(offset);
|
|
644
662
|
}
|
|
645
|
-
if (
|
|
646
|
-
const limit = Number(options.limit);
|
|
647
|
-
if (!Number.isInteger(limit) || limit < 0) {
|
|
648
|
-
throw new NansenError(`--limit must be a non-negative integer, got "${options.limit}"`, ErrorCode.INVALID_PARAMS);
|
|
649
|
-
}
|
|
663
|
+
if (limit !== undefined) {
|
|
650
664
|
alerts = alerts.slice(0, limit);
|
|
651
665
|
}
|
|
652
666
|
|
package/src/commands/mcp.js
CHANGED
|
@@ -246,6 +246,12 @@ export function buildMcpCommands(deps = {}) {
|
|
|
246
246
|
if ('url' in options && typeof options.url !== 'string') {
|
|
247
247
|
throw new CommandError('--url must be a single URL string. Usage: nansen mcp verify --url <url>', 'INVALID_PARAMS');
|
|
248
248
|
}
|
|
249
|
+
// An explicit blank value, e.g. `--url "$UNSET_VAR"`, must not fall through
|
|
250
|
+
// to the default endpoint below: the caller would be told the Nansen URL
|
|
251
|
+
// verified while believing they had checked their own.
|
|
252
|
+
if (typeof options.url === 'string' && options.url.trim() === '') {
|
|
253
|
+
throw new CommandError('--url requires a value. Usage: nansen mcp verify --url <url>', 'MISSING_PARAM');
|
|
254
|
+
}
|
|
249
255
|
|
|
250
256
|
const url = options.url || DEFAULT_MCP_URL;
|
|
251
257
|
const checks = await runMcpVerifyChecks({
|
package/src/commands/research.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { NansenError, ErrorCode } from '../api.js';
|
|
8
|
-
import { parseSort } from '../query-options.js';
|
|
8
|
+
import { parseSort, rejectBlankOption } from '../query-options.js';
|
|
9
9
|
|
|
10
10
|
// Research subcommands validate --page strictly. The shared helper in
|
|
11
11
|
// src/query-options.js clamps an invalid page to 1 for the category commands,
|
|
@@ -68,7 +68,7 @@ function resolveDateRange(options) {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
function parseTimeframeDays(value) {
|
|
71
|
-
if (value === undefined || value === null
|
|
71
|
+
if (value === undefined || value === null) return undefined;
|
|
72
72
|
const trimmed = String(value).trim();
|
|
73
73
|
if (!/^[1-9]\d*$/.test(trimmed)) {
|
|
74
74
|
throw new NansenError('--timeframe-days must be a positive integer', ErrorCode.INVALID_PARAMS);
|
|
@@ -245,6 +245,13 @@ export function buildResearchCommands(deps = {}) {
|
|
|
245
245
|
|
|
246
246
|
if (sub === 'token-sectors') return apiInstance.tokenSectors();
|
|
247
247
|
|
|
248
|
+
for (const [name, example] of [
|
|
249
|
+
['chain', 'solana'], ['chains', 'solana'], ['chain-type', 'all'],
|
|
250
|
+
['timeframe', '1d'], ['timeframe-days', '7'],
|
|
251
|
+
]) {
|
|
252
|
+
rejectBlankOption(options[name], name, example);
|
|
253
|
+
}
|
|
254
|
+
|
|
248
255
|
const orderBy = parseSort(options.sort, options['order-by']);
|
|
249
256
|
const pagination = buildPagination(options);
|
|
250
257
|
const filters = options.filters || {};
|
package/src/cost-cache.js
CHANGED
|
@@ -77,13 +77,21 @@ export async function refreshCostMapIfStale() {
|
|
|
77
77
|
let spec;
|
|
78
78
|
try {
|
|
79
79
|
const res = await fetch(OPENAPI_URL, { signal: controller.signal });
|
|
80
|
+
// An error body still parses as JSON. Writing it would stamp fetchedAt
|
|
81
|
+
// fresh, replacing known-good costs with an empty map and suppressing the
|
|
82
|
+
// next attempt for STALE_MS.
|
|
83
|
+
if (!res.ok) return;
|
|
80
84
|
spec = await res.json();
|
|
81
85
|
} finally {
|
|
82
86
|
clearTimeout(timer);
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
// No paths object means this is not the spec. Treat it as a failed fetch
|
|
90
|
+
// rather than as "every endpoint is free".
|
|
91
|
+
if (!spec?.paths || typeof spec.paths !== 'object') return;
|
|
92
|
+
|
|
85
93
|
const costs = {};
|
|
86
|
-
for (const [p, methods] of Object.entries(spec.paths
|
|
94
|
+
for (const [p, methods] of Object.entries(spec.paths)) {
|
|
87
95
|
for (const op of Object.values(methods)) {
|
|
88
96
|
if (op['x-credit-cost']) {
|
|
89
97
|
costs[p] = op['x-credit-cost'];
|
package/src/limit-order.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Zero external dependencies — uses Node.js built-in crypto only.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { rejectBlankOption } from './query-options.js';
|
|
9
10
|
import fs from 'fs';
|
|
10
11
|
import path from 'path';
|
|
11
12
|
import { base58Encode, exportWallet, getWalletConfig, showWallet } from './wallet.js';
|
|
@@ -624,6 +625,8 @@ export function buildLimitOrderCommands(deps = {}) {
|
|
|
624
625
|
|
|
625
626
|
return {
|
|
626
627
|
'create': async (args, apiInstance, flags, options) => {
|
|
628
|
+
rejectBlankOption(options.wallet, 'wallet', '<name>');
|
|
629
|
+
rejectBlankOption(options.expires, 'expires', '7d');
|
|
627
630
|
const fromRaw = options.from || options['from-token'] || args[0];
|
|
628
631
|
const toRaw = options.to || options['to-token'] || args[1];
|
|
629
632
|
const from = resolveTokenAddress(fromRaw, 'solana');
|
|
@@ -885,6 +888,11 @@ EXAMPLES:
|
|
|
885
888
|
},
|
|
886
889
|
|
|
887
890
|
'list': async (args, apiInstance, flags, options) => {
|
|
891
|
+
rejectBlankOption(options.mint, 'mint', 'SOL');
|
|
892
|
+
rejectBlankOption(options.limit, 'limit', '20');
|
|
893
|
+
rejectBlankOption(options.offset, 'offset', '0');
|
|
894
|
+
rejectBlankOption(options.dir, 'dir', 'desc');
|
|
895
|
+
rejectBlankOption(options.wallet, 'wallet', '<name>');
|
|
888
896
|
const walletName = options.wallet;
|
|
889
897
|
const state = options.state;
|
|
890
898
|
const mint = options.mint ? resolveTokenAddress(options.mint, 'solana') : undefined;
|
|
@@ -944,6 +952,7 @@ EXAMPLES:
|
|
|
944
952
|
},
|
|
945
953
|
|
|
946
954
|
'cancel': async (args, apiInstance, flags, options) => {
|
|
955
|
+
rejectBlankOption(options.wallet, 'wallet', '<name>');
|
|
947
956
|
const orderId = options.order || options['order-id'] || args[0];
|
|
948
957
|
const walletName = options.wallet;
|
|
949
958
|
|
|
@@ -1074,6 +1083,7 @@ EXAMPLES:
|
|
|
1074
1083
|
},
|
|
1075
1084
|
|
|
1076
1085
|
'update': async (args, apiInstance, flags, options) => {
|
|
1086
|
+
rejectBlankOption(options.wallet, 'wallet', '<name>');
|
|
1077
1087
|
const orderId = options.order || options['order-id'] || args[0];
|
|
1078
1088
|
const triggerPrice = options['trigger-price'];
|
|
1079
1089
|
const slippageBps = options['slippage-bps'];
|
package/src/query-options.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* implementation without circular imports.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { NansenError, ErrorCode } from './api.js';
|
|
9
|
+
import { NansenError, CommandError, ErrorCode } from './api.js';
|
|
10
10
|
|
|
11
11
|
export function buildPagination(options) {
|
|
12
12
|
if (options.limit === undefined && options.page === undefined) return undefined;
|
|
@@ -30,3 +30,32 @@ export function parseSort(sortOption, orderByOption) {
|
|
|
30
30
|
const direction = (parts[1] || 'desc').toUpperCase();
|
|
31
31
|
return [{ field, direction }];
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Normalise a comma-separated-string-or-array CLI option into an array of
|
|
36
|
+
* strings, or undefined if absent. Accepts either a single "a,b,c" string or
|
|
37
|
+
* an array (parseArgs collects repeated flags, e.g. `--tag a --tag b`, into
|
|
38
|
+
* one), and rejects non-string values/elements (e.g. `--flag true` is
|
|
39
|
+
* parsed by parseArgs as the JSON boolean `true`) with an actionable
|
|
40
|
+
* INVALID_PARAMS error instead of crashing on .split()/.trim().
|
|
41
|
+
*/
|
|
42
|
+
export function parseCsvOption(val, name) {
|
|
43
|
+
if (val === undefined || val === '') return undefined;
|
|
44
|
+
if (Array.isArray(val)) {
|
|
45
|
+
if (!val.every(v => typeof v === 'string')) {
|
|
46
|
+
throw new NansenError(`--${name} values must be strings`, ErrorCode.INVALID_PARAMS);
|
|
47
|
+
}
|
|
48
|
+
return val.map(v => v.trim()).filter(Boolean);
|
|
49
|
+
}
|
|
50
|
+
if (typeof val !== 'string') {
|
|
51
|
+
throw new NansenError(`--${name} must be a string`, ErrorCode.INVALID_PARAMS);
|
|
52
|
+
}
|
|
53
|
+
return val.split(',').map(s => s.trim()).filter(Boolean);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Reject explicit blank strings before a handler selects an omitted-option default. */
|
|
57
|
+
export function rejectBlankOption(value, name, example) {
|
|
58
|
+
if (typeof value === 'string' && value.trim() === '') {
|
|
59
|
+
throw new CommandError(`--${name} requires a value. Usage: --${name} ${example}`, 'MISSING_PARAM');
|
|
60
|
+
}
|
|
61
|
+
}
|