|
| 1 | +import { Command } from "commander" |
| 2 | +import type { OpenSeaClient } from "../client.js" |
| 3 | +import type { OutputFormat } from "../output.js" |
| 4 | +import { formatOutput } from "../output.js" |
| 5 | +import { parseIntOption } from "../parse.js" |
| 6 | + |
| 7 | +type TokenGroup = Record<string, unknown> |
| 8 | + |
| 9 | +export function tokenGroupsCommand( |
| 10 | + getClient: () => OpenSeaClient, |
| 11 | + getFormat: () => OutputFormat, |
| 12 | +): Command { |
| 13 | + const cmd = new Command("token-groups").description( |
| 14 | + "Query token groups (equivalent currencies across chains, e.g. 'eth')", |
| 15 | + ) |
| 16 | + |
| 17 | + cmd |
| 18 | + .command("list") |
| 19 | + .description("List token groups sorted by market cap descending") |
| 20 | + .option("--limit <limit>", "Number of results (max 100, default 50)", "50") |
| 21 | + .option("--next <cursor>", "Pagination cursor") |
| 22 | + .action(async (options: { limit: string; next?: string }) => { |
| 23 | + const client = getClient() |
| 24 | + const result = await client.get<{ |
| 25 | + token_groups: TokenGroup[] |
| 26 | + next?: string |
| 27 | + }>("/api/v2/token-groups", { |
| 28 | + limit: parseIntOption(options.limit, "--limit"), |
| 29 | + // Token Groups API uses "cursor" instead of "next" as the query param |
| 30 | + cursor: options.next, |
| 31 | + }) |
| 32 | + console.log(formatOutput(result, getFormat())) |
| 33 | + }) |
| 34 | + |
| 35 | + cmd |
| 36 | + .command("get") |
| 37 | + .description("Get a single token group by slug") |
| 38 | + .argument("<slug>", "Token group slug (e.g. 'eth')") |
| 39 | + .action(async (slug: string) => { |
| 40 | + const client = getClient() |
| 41 | + const result = await client.get<TokenGroup>( |
| 42 | + `/api/v2/token-groups/${slug}`, |
| 43 | + ) |
| 44 | + console.log(formatOutput(result, getFormat())) |
| 45 | + }) |
| 46 | + |
| 47 | + return cmd |
| 48 | +} |
0 commit comments