@spectratools/defillama-cli 0.4.0 → 0.4.2
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/README.md +101 -0
- package/dist/cli.js +30 -9
- package/dist/index.js +28 -8
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# @spectratools/defillama-cli
|
|
2
|
+
|
|
3
|
+
Query DefiLlama API data from the command line — TVL, volume, fees, and token prices.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -g @spectratools/defillama-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## LLM / Agent Discovery
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
# Emit machine-readable command metadata
|
|
15
|
+
defillama-cli --llms
|
|
16
|
+
|
|
17
|
+
# Register as a reusable local skill for agent runtimes
|
|
18
|
+
defillama-cli skills add
|
|
19
|
+
|
|
20
|
+
# Register as an MCP server entry
|
|
21
|
+
defillama-cli mcp add
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
No API key required — DefiLlama is a free, public API.
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Top 10 protocols by TVL
|
|
30
|
+
defillama-cli tvl protocols --limit 10
|
|
31
|
+
|
|
32
|
+
# Top chains by TVL
|
|
33
|
+
defillama-cli tvl chains --limit 10
|
|
34
|
+
|
|
35
|
+
# Protocol detail with chain breakdown
|
|
36
|
+
defillama-cli tvl protocol aave
|
|
37
|
+
|
|
38
|
+
# TVL history for a protocol
|
|
39
|
+
defillama-cli tvl history aave --days 7
|
|
40
|
+
|
|
41
|
+
# Top DEXes by 24h volume
|
|
42
|
+
defillama-cli volume dexs --limit 10
|
|
43
|
+
|
|
44
|
+
# Volume for a specific DEX
|
|
45
|
+
defillama-cli volume protocol uniswap
|
|
46
|
+
|
|
47
|
+
# DEX aggregators ranked by volume
|
|
48
|
+
defillama-cli volume aggregators --limit 10
|
|
49
|
+
|
|
50
|
+
# Top protocols by fees
|
|
51
|
+
defillama-cli fees overview --limit 10
|
|
52
|
+
|
|
53
|
+
# Fee detail for a protocol
|
|
54
|
+
defillama-cli fees protocol aave
|
|
55
|
+
|
|
56
|
+
# Current token price
|
|
57
|
+
defillama-cli prices current ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7
|
|
58
|
+
|
|
59
|
+
# Historical token price
|
|
60
|
+
defillama-cli prices historical ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7 --date 2025-01-01
|
|
61
|
+
|
|
62
|
+
# Price chart
|
|
63
|
+
defillama-cli prices chart ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7 --start 2025-01-01 --period 1d
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Command Groups
|
|
67
|
+
|
|
68
|
+
| Group | Description |
|
|
69
|
+
|-------|-------------|
|
|
70
|
+
| `tvl` | Total value locked — protocols, chains, protocol detail, history |
|
|
71
|
+
| `volume` | DEX trading volume — dexs, protocol detail, aggregators |
|
|
72
|
+
| `fees` | Protocol fees and revenue — overview, protocol detail |
|
|
73
|
+
| `prices` | Token prices — current, historical, chart |
|
|
74
|
+
|
|
75
|
+
## Chain Filtering
|
|
76
|
+
|
|
77
|
+
Several commands support `--chain` to filter by blockchain:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
defillama-cli tvl protocols --chain ethereum --limit 10
|
|
81
|
+
defillama-cli volume dexs --chain abstract --limit 10
|
|
82
|
+
defillama-cli fees overview --chain base --limit 10
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Output Modes
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Human-readable table output (default)
|
|
89
|
+
defillama-cli tvl protocols --limit 5
|
|
90
|
+
|
|
91
|
+
# JSON output for pipelines
|
|
92
|
+
defillama-cli tvl protocols --limit 5 --json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Documentation
|
|
96
|
+
|
|
97
|
+
Full documentation: [spectratools.dev/defillama](https://spectratools.dev/defillama/)
|
|
98
|
+
|
|
99
|
+
## License
|
|
100
|
+
|
|
101
|
+
MIT
|
package/dist/cli.js
CHANGED
|
@@ -306,9 +306,12 @@ var pricesCli = Cli2.create("prices", {
|
|
|
306
306
|
description: "Token price queries via coins.llama.fi."
|
|
307
307
|
});
|
|
308
308
|
var COIN_ID_RE = /^[a-zA-Z0-9_-]+:0x[a-fA-F0-9]{1,}$/;
|
|
309
|
+
function normalizeCoinArgs(raw) {
|
|
310
|
+
return Array.isArray(raw) ? raw : [raw];
|
|
311
|
+
}
|
|
309
312
|
function parseCoins(raw) {
|
|
310
313
|
const coins = [];
|
|
311
|
-
for (const arg of raw) {
|
|
314
|
+
for (const arg of normalizeCoinArgs(raw)) {
|
|
312
315
|
for (const part of arg.split(",")) {
|
|
313
316
|
const trimmed = part.trim();
|
|
314
317
|
if (trimmed.length === 0) continue;
|
|
@@ -337,10 +340,11 @@ function parseTimestamp(value) {
|
|
|
337
340
|
}
|
|
338
341
|
return Math.floor(ms / 1e3);
|
|
339
342
|
}
|
|
343
|
+
var coinsArgsSchema = z3.string().describe("Coin identifiers (chainName:0xAddress)");
|
|
340
344
|
pricesCli.command("current", {
|
|
341
345
|
description: "Get current prices for one or more tokens.",
|
|
342
346
|
args: z3.object({
|
|
343
|
-
coins:
|
|
347
|
+
coins: coinsArgsSchema
|
|
344
348
|
}),
|
|
345
349
|
options: z3.object({
|
|
346
350
|
"search-width": z3.string().default("4h").describe("Timestamp search width (e.g. 4h, 6h)")
|
|
@@ -358,7 +362,7 @@ pricesCli.command("current", {
|
|
|
358
362
|
}),
|
|
359
363
|
examples: [
|
|
360
364
|
{
|
|
361
|
-
args: { coins:
|
|
365
|
+
args: { coins: "ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7" },
|
|
362
366
|
description: "Current price of USDT on Ethereum"
|
|
363
367
|
}
|
|
364
368
|
],
|
|
@@ -382,7 +386,7 @@ pricesCli.command("current", {
|
|
|
382
386
|
pricesCli.command("historical", {
|
|
383
387
|
description: "Get token prices at a specific point in time.",
|
|
384
388
|
args: z3.object({
|
|
385
|
-
coins:
|
|
389
|
+
coins: coinsArgsSchema
|
|
386
390
|
}),
|
|
387
391
|
options: z3.object({
|
|
388
392
|
timestamp: z3.string().optional().describe("Unix timestamp in seconds"),
|
|
@@ -401,7 +405,7 @@ pricesCli.command("historical", {
|
|
|
401
405
|
}),
|
|
402
406
|
examples: [
|
|
403
407
|
{
|
|
404
|
-
args: { coins:
|
|
408
|
+
args: { coins: "ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7" },
|
|
405
409
|
options: { date: "2025-01-01" },
|
|
406
410
|
description: "USDT price on 2025-01-01"
|
|
407
411
|
}
|
|
@@ -430,7 +434,7 @@ pricesCli.command("historical", {
|
|
|
430
434
|
pricesCli.command("chart", {
|
|
431
435
|
description: "Get a price chart over a time range.",
|
|
432
436
|
args: z3.object({
|
|
433
|
-
coins:
|
|
437
|
+
coins: coinsArgsSchema
|
|
434
438
|
}),
|
|
435
439
|
options: z3.object({
|
|
436
440
|
start: z3.string().optional().describe("Start timestamp or ISO date"),
|
|
@@ -455,7 +459,7 @@ pricesCli.command("chart", {
|
|
|
455
459
|
}),
|
|
456
460
|
examples: [
|
|
457
461
|
{
|
|
458
|
-
args: { coins:
|
|
462
|
+
args: { coins: "ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7" },
|
|
459
463
|
options: { start: "2025-01-01", period: "1d" },
|
|
460
464
|
description: "USDT daily price chart since 2025-01-01"
|
|
461
465
|
}
|
|
@@ -861,6 +865,22 @@ cli.command(tvlCli);
|
|
|
861
865
|
cli.command(volumeCli);
|
|
862
866
|
cli.command(feesCli);
|
|
863
867
|
cli.command(pricesCli);
|
|
868
|
+
var PRICE_SUBCOMMANDS = /* @__PURE__ */ new Set(["current", "historical", "chart"]);
|
|
869
|
+
function normalizePricesArgv(argv) {
|
|
870
|
+
if (argv[0] !== "prices") return argv;
|
|
871
|
+
const subcommand = argv[1];
|
|
872
|
+
if (!subcommand || !PRICE_SUBCOMMANDS.has(subcommand)) return argv;
|
|
873
|
+
let i = 2;
|
|
874
|
+
const coins = [];
|
|
875
|
+
while (i < argv.length) {
|
|
876
|
+
const token = argv[i];
|
|
877
|
+
if (!token || token.startsWith("-")) break;
|
|
878
|
+
coins.push(token);
|
|
879
|
+
i += 1;
|
|
880
|
+
}
|
|
881
|
+
if (coins.length <= 1) return argv;
|
|
882
|
+
return [...argv.slice(0, 2), coins.join(","), ...argv.slice(i)];
|
|
883
|
+
}
|
|
864
884
|
var isMain = (() => {
|
|
865
885
|
const entrypoint = process.argv[1];
|
|
866
886
|
if (!entrypoint) {
|
|
@@ -873,8 +893,9 @@ var isMain = (() => {
|
|
|
873
893
|
}
|
|
874
894
|
})();
|
|
875
895
|
if (isMain) {
|
|
876
|
-
cli.serve();
|
|
896
|
+
cli.serve(normalizePricesArgv(process.argv.slice(2)));
|
|
877
897
|
}
|
|
878
898
|
export {
|
|
879
|
-
cli
|
|
899
|
+
cli,
|
|
900
|
+
normalizePricesArgv
|
|
880
901
|
};
|
package/dist/index.js
CHANGED
|
@@ -317,9 +317,12 @@ var pricesCli = Cli2.create("prices", {
|
|
|
317
317
|
description: "Token price queries via coins.llama.fi."
|
|
318
318
|
});
|
|
319
319
|
var COIN_ID_RE = /^[a-zA-Z0-9_-]+:0x[a-fA-F0-9]{1,}$/;
|
|
320
|
+
function normalizeCoinArgs(raw) {
|
|
321
|
+
return Array.isArray(raw) ? raw : [raw];
|
|
322
|
+
}
|
|
320
323
|
function parseCoins(raw) {
|
|
321
324
|
const coins = [];
|
|
322
|
-
for (const arg of raw) {
|
|
325
|
+
for (const arg of normalizeCoinArgs(raw)) {
|
|
323
326
|
for (const part of arg.split(",")) {
|
|
324
327
|
const trimmed = part.trim();
|
|
325
328
|
if (trimmed.length === 0) continue;
|
|
@@ -348,10 +351,11 @@ function parseTimestamp(value) {
|
|
|
348
351
|
}
|
|
349
352
|
return Math.floor(ms / 1e3);
|
|
350
353
|
}
|
|
354
|
+
var coinsArgsSchema = z3.string().describe("Coin identifiers (chainName:0xAddress)");
|
|
351
355
|
pricesCli.command("current", {
|
|
352
356
|
description: "Get current prices for one or more tokens.",
|
|
353
357
|
args: z3.object({
|
|
354
|
-
coins:
|
|
358
|
+
coins: coinsArgsSchema
|
|
355
359
|
}),
|
|
356
360
|
options: z3.object({
|
|
357
361
|
"search-width": z3.string().default("4h").describe("Timestamp search width (e.g. 4h, 6h)")
|
|
@@ -369,7 +373,7 @@ pricesCli.command("current", {
|
|
|
369
373
|
}),
|
|
370
374
|
examples: [
|
|
371
375
|
{
|
|
372
|
-
args: { coins:
|
|
376
|
+
args: { coins: "ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7" },
|
|
373
377
|
description: "Current price of USDT on Ethereum"
|
|
374
378
|
}
|
|
375
379
|
],
|
|
@@ -393,7 +397,7 @@ pricesCli.command("current", {
|
|
|
393
397
|
pricesCli.command("historical", {
|
|
394
398
|
description: "Get token prices at a specific point in time.",
|
|
395
399
|
args: z3.object({
|
|
396
|
-
coins:
|
|
400
|
+
coins: coinsArgsSchema
|
|
397
401
|
}),
|
|
398
402
|
options: z3.object({
|
|
399
403
|
timestamp: z3.string().optional().describe("Unix timestamp in seconds"),
|
|
@@ -412,7 +416,7 @@ pricesCli.command("historical", {
|
|
|
412
416
|
}),
|
|
413
417
|
examples: [
|
|
414
418
|
{
|
|
415
|
-
args: { coins:
|
|
419
|
+
args: { coins: "ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7" },
|
|
416
420
|
options: { date: "2025-01-01" },
|
|
417
421
|
description: "USDT price on 2025-01-01"
|
|
418
422
|
}
|
|
@@ -441,7 +445,7 @@ pricesCli.command("historical", {
|
|
|
441
445
|
pricesCli.command("chart", {
|
|
442
446
|
description: "Get a price chart over a time range.",
|
|
443
447
|
args: z3.object({
|
|
444
|
-
coins:
|
|
448
|
+
coins: coinsArgsSchema
|
|
445
449
|
}),
|
|
446
450
|
options: z3.object({
|
|
447
451
|
start: z3.string().optional().describe("Start timestamp or ISO date"),
|
|
@@ -466,7 +470,7 @@ pricesCli.command("chart", {
|
|
|
466
470
|
}),
|
|
467
471
|
examples: [
|
|
468
472
|
{
|
|
469
|
-
args: { coins:
|
|
473
|
+
args: { coins: "ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7" },
|
|
470
474
|
options: { start: "2025-01-01", period: "1d" },
|
|
471
475
|
description: "USDT daily price chart since 2025-01-01"
|
|
472
476
|
}
|
|
@@ -872,6 +876,22 @@ cli.command(tvlCli);
|
|
|
872
876
|
cli.command(volumeCli);
|
|
873
877
|
cli.command(feesCli);
|
|
874
878
|
cli.command(pricesCli);
|
|
879
|
+
var PRICE_SUBCOMMANDS = /* @__PURE__ */ new Set(["current", "historical", "chart"]);
|
|
880
|
+
function normalizePricesArgv(argv) {
|
|
881
|
+
if (argv[0] !== "prices") return argv;
|
|
882
|
+
const subcommand = argv[1];
|
|
883
|
+
if (!subcommand || !PRICE_SUBCOMMANDS.has(subcommand)) return argv;
|
|
884
|
+
let i = 2;
|
|
885
|
+
const coins = [];
|
|
886
|
+
while (i < argv.length) {
|
|
887
|
+
const token = argv[i];
|
|
888
|
+
if (!token || token.startsWith("-")) break;
|
|
889
|
+
coins.push(token);
|
|
890
|
+
i += 1;
|
|
891
|
+
}
|
|
892
|
+
if (coins.length <= 1) return argv;
|
|
893
|
+
return [...argv.slice(0, 2), coins.join(","), ...argv.slice(i)];
|
|
894
|
+
}
|
|
875
895
|
var isMain = (() => {
|
|
876
896
|
const entrypoint = process.argv[1];
|
|
877
897
|
if (!entrypoint) {
|
|
@@ -884,7 +904,7 @@ var isMain = (() => {
|
|
|
884
904
|
}
|
|
885
905
|
})();
|
|
886
906
|
if (isMain) {
|
|
887
|
-
cli.serve();
|
|
907
|
+
cli.serve(normalizePricesArgv(process.argv.slice(2)));
|
|
888
908
|
}
|
|
889
909
|
export {
|
|
890
910
|
DEFILLAMA_HOSTS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spectratools/defillama-cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"description": "DefiLlama API CLI for spectra-the-bot",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"incur": "^0.3.0",
|
|
22
|
-
"@spectratools/cli-shared": "0.
|
|
22
|
+
"@spectratools/cli-shared": "0.4.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"typescript": "5.7.3",
|