@net-protocol/cli 0.2.0 → 0.2.1
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/dist/cli/index.mjs +151 -1
- package/dist/cli/index.mjs.map +1 -1
- package/dist/upvote/index.d.ts +3 -1
- package/dist/upvote/index.mjs +152 -2
- package/dist/upvote/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -22,7 +22,7 @@ import { BazaarClient } from '@net-protocol/bazaar';
|
|
|
22
22
|
import * as os from 'os';
|
|
23
23
|
import { homedir } from 'os';
|
|
24
24
|
import * as readline from 'readline';
|
|
25
|
-
import { discoverTokenPool, PURE_ALPHA_STRATEGY, UNIV234_POOLS_STRATEGY, encodePoolKey, DYNAMIC_SPLIT_STRATEGY, getTokenScoreKey, UPVOTE_PRICE_ETH, UPVOTE_APP, ScoreClient, ALL_STRATEGY_ADDRESSES, NULL_ADDRESS as NULL_ADDRESS$1, UserUpvoteClient, calculateUpvoteCost, USER_UPVOTE_CONTRACT } from '@net-protocol/score';
|
|
25
|
+
import { discoverTokenPool, PURE_ALPHA_STRATEGY, UNIV234_POOLS_STRATEGY, encodePoolKey, DYNAMIC_SPLIT_STRATEGY, getTokenScoreKey, UPVOTE_PRICE_ETH, UPVOTE_APP, ScoreClient, ALL_STRATEGY_ADDRESSES, NULL_ADDRESS as NULL_ADDRESS$1, UserUpvoteClient, calculateUpvoteCost, USER_UPVOTE_CONTRACT, getTokenRankings } from '@net-protocol/score';
|
|
26
26
|
import { RELAY_ACCESS_KEY, generateAgentChatTopic, AgentClient, isAgentChatTopic, parseAgentAddressFromTopic, buildSessionTypedData, NET_API_URL, exchangeSessionSignature, buildConversationAuthTypedData, NET_TESTNET_API_URL } from '@net-protocol/agents';
|
|
27
27
|
|
|
28
28
|
var DEFAULT_CHAIN_ID = 8453;
|
|
@@ -8280,6 +8280,155 @@ function registerGetUserUpvotesCommand(parent, commandName = "user-info") {
|
|
|
8280
8280
|
await executeGetUserUpvotes(options);
|
|
8281
8281
|
});
|
|
8282
8282
|
}
|
|
8283
|
+
var VALID_SORTS = ["trending", "recent", "top"];
|
|
8284
|
+
function formatNumber(n, digits = 2) {
|
|
8285
|
+
if (n == null || !Number.isFinite(n)) return "-";
|
|
8286
|
+
if (n >= 1e9) return `${(n / 1e9).toFixed(digits)}B`;
|
|
8287
|
+
if (n >= 1e6) return `${(n / 1e6).toFixed(digits)}M`;
|
|
8288
|
+
if (n >= 1e3) return `${(n / 1e3).toFixed(digits)}K`;
|
|
8289
|
+
return n.toFixed(digits);
|
|
8290
|
+
}
|
|
8291
|
+
function formatPrice(price) {
|
|
8292
|
+
if (price == null || !Number.isFinite(price)) return "-";
|
|
8293
|
+
if (price < 1e-6) return price.toExponential(2);
|
|
8294
|
+
if (price < 1) return `$${price.toFixed(6)}`;
|
|
8295
|
+
return `$${price.toFixed(4)}`;
|
|
8296
|
+
}
|
|
8297
|
+
async function executeRankings(options) {
|
|
8298
|
+
const sort = (options.sort ?? "trending").toLowerCase();
|
|
8299
|
+
if (!VALID_SORTS.includes(sort)) {
|
|
8300
|
+
exitWithError(
|
|
8301
|
+
`Invalid --sort "${options.sort}". Must be one of: ${VALID_SORTS.join(", ")}`
|
|
8302
|
+
);
|
|
8303
|
+
return;
|
|
8304
|
+
}
|
|
8305
|
+
const limit = options.limit ?? 10;
|
|
8306
|
+
if (!Number.isFinite(limit) || limit < 1 || limit > 100) {
|
|
8307
|
+
exitWithError("Invalid --limit. Must be an integer between 1 and 100.");
|
|
8308
|
+
return;
|
|
8309
|
+
}
|
|
8310
|
+
const optionalPositiveInt = (value, name, { allowZero = false } = {}) => {
|
|
8311
|
+
if (value === void 0) return void 0;
|
|
8312
|
+
if (!Number.isFinite(value) || (allowZero ? value < 0 : value < 1)) {
|
|
8313
|
+
exitWithError(
|
|
8314
|
+
`Invalid ${name}. Must be a ${allowZero ? "non-negative" : "positive"} integer.`
|
|
8315
|
+
);
|
|
8316
|
+
}
|
|
8317
|
+
return value;
|
|
8318
|
+
};
|
|
8319
|
+
const scanWindow = optionalPositiveInt(options.scanWindow, "--scan-window");
|
|
8320
|
+
const minUpvotes = optionalPositiveInt(options.minUpvotes, "--min-upvotes", {
|
|
8321
|
+
allowZero: true
|
|
8322
|
+
});
|
|
8323
|
+
const minMarketCap = optionalPositiveInt(
|
|
8324
|
+
options.minMarketCap,
|
|
8325
|
+
"--min-market-cap",
|
|
8326
|
+
{ allowZero: true }
|
|
8327
|
+
);
|
|
8328
|
+
const recencyHours = optionalPositiveInt(
|
|
8329
|
+
options.recencyHours,
|
|
8330
|
+
"--recency-hours",
|
|
8331
|
+
{ allowZero: true }
|
|
8332
|
+
);
|
|
8333
|
+
if (options.chainId !== void 0 && !Number.isFinite(options.chainId)) {
|
|
8334
|
+
exitWithError("Invalid --chain-id. Must be an integer.");
|
|
8335
|
+
return;
|
|
8336
|
+
}
|
|
8337
|
+
const readOnlyOptions = parseReadOnlyOptionsWithDefault({
|
|
8338
|
+
chainId: options.chainId,
|
|
8339
|
+
rpcUrl: options.rpcUrl
|
|
8340
|
+
});
|
|
8341
|
+
try {
|
|
8342
|
+
const tokens = await getTokenRankings({
|
|
8343
|
+
chainId: readOnlyOptions.chainId,
|
|
8344
|
+
sort,
|
|
8345
|
+
maxTokens: limit,
|
|
8346
|
+
messageScanWindow: scanWindow,
|
|
8347
|
+
thresholds: minUpvotes != null || minMarketCap != null || recencyHours != null ? {
|
|
8348
|
+
minUpvotes,
|
|
8349
|
+
minMarketCap,
|
|
8350
|
+
recencyHours
|
|
8351
|
+
} : void 0,
|
|
8352
|
+
rpcUrl: readOnlyOptions.rpcUrl
|
|
8353
|
+
});
|
|
8354
|
+
if (options.json) {
|
|
8355
|
+
console.log(
|
|
8356
|
+
JSON.stringify(
|
|
8357
|
+
{
|
|
8358
|
+
chainId: readOnlyOptions.chainId,
|
|
8359
|
+
sort,
|
|
8360
|
+
count: tokens.length,
|
|
8361
|
+
tokens: tokens.map((t) => ({
|
|
8362
|
+
...t,
|
|
8363
|
+
url: tokenUrl(readOnlyOptions.chainId, t.address)
|
|
8364
|
+
}))
|
|
8365
|
+
},
|
|
8366
|
+
null,
|
|
8367
|
+
2
|
|
8368
|
+
)
|
|
8369
|
+
);
|
|
8370
|
+
return;
|
|
8371
|
+
}
|
|
8372
|
+
if (tokens.length === 0) {
|
|
8373
|
+
console.log(chalk4.yellow("No tokens found."));
|
|
8374
|
+
return;
|
|
8375
|
+
}
|
|
8376
|
+
console.log(
|
|
8377
|
+
chalk4.white(
|
|
8378
|
+
`Top ${tokens.length} tokens by ${sort} on chain ${readOnlyOptions.chainId}:`
|
|
8379
|
+
)
|
|
8380
|
+
);
|
|
8381
|
+
console.log();
|
|
8382
|
+
tokens.forEach((t, i) => {
|
|
8383
|
+
const rank = chalk4.dim(`#${(i + 1).toString().padStart(2, " ")}`);
|
|
8384
|
+
const symbol = chalk4.cyan((t.symbol || "?").padEnd(10, " "));
|
|
8385
|
+
const upvotes = chalk4.white(`${t.upvotes} upvotes`.padEnd(18, " "));
|
|
8386
|
+
const fdv = chalk4.dim(`FDV ${formatNumber(t.fdv)}`.padEnd(14, " "));
|
|
8387
|
+
const price = chalk4.dim(`${formatPrice(t.priceInUsdc)}`.padEnd(14, " "));
|
|
8388
|
+
console.log(`${rank} ${symbol} ${upvotes} ${fdv} ${price} ${t.address}`);
|
|
8389
|
+
});
|
|
8390
|
+
} catch (error) {
|
|
8391
|
+
exitWithError(
|
|
8392
|
+
`Failed to fetch token rankings: ${error instanceof Error ? error.message : String(error)}`
|
|
8393
|
+
);
|
|
8394
|
+
}
|
|
8395
|
+
}
|
|
8396
|
+
function registerRankingsCommand(parent, commandName = "rankings") {
|
|
8397
|
+
parent.command(commandName).description(
|
|
8398
|
+
"List tokens ranked by upvote activity (trending / recent / top)"
|
|
8399
|
+
).option(
|
|
8400
|
+
"--sort <sort>",
|
|
8401
|
+
`Ranking strategy: ${VALID_SORTS.join(" | ")} (default: trending)`,
|
|
8402
|
+
"trending"
|
|
8403
|
+
).option(
|
|
8404
|
+
"--limit <n>",
|
|
8405
|
+
"Number of tokens to return (1-100, default: 50)",
|
|
8406
|
+
(v) => parseInt(v, 10),
|
|
8407
|
+
50
|
|
8408
|
+
).option(
|
|
8409
|
+
"--scan-window <n>",
|
|
8410
|
+
"Messages to scan per contract (default: 150)",
|
|
8411
|
+
(v) => parseInt(v, 10)
|
|
8412
|
+
).option(
|
|
8413
|
+
"--min-upvotes <n>",
|
|
8414
|
+
"Floor for two-tier filter (default: 500)",
|
|
8415
|
+
(v) => parseInt(v, 10)
|
|
8416
|
+
).option(
|
|
8417
|
+
"--min-market-cap <n>",
|
|
8418
|
+
"FDV floor in USDC (default: 40000)",
|
|
8419
|
+
(v) => parseInt(v, 10)
|
|
8420
|
+
).option(
|
|
8421
|
+
"--recency-hours <n>",
|
|
8422
|
+
"Drop below-floor tokens with no upvote within N hours (default: 48)",
|
|
8423
|
+
(v) => parseInt(v, 10)
|
|
8424
|
+
).option(
|
|
8425
|
+
"--chain-id <id>",
|
|
8426
|
+
"Chain ID (default: 8453 for Base)",
|
|
8427
|
+
(v) => parseInt(v, 10)
|
|
8428
|
+
).option("--rpc-url <url>", "Custom RPC URL").option("--json", "Output in JSON format").action(async (options) => {
|
|
8429
|
+
await executeRankings(options);
|
|
8430
|
+
});
|
|
8431
|
+
}
|
|
8283
8432
|
|
|
8284
8433
|
// src/commands/upvote/index.ts
|
|
8285
8434
|
function registerUpvoteCommand(program2) {
|
|
@@ -8288,6 +8437,7 @@ function registerUpvoteCommand(program2) {
|
|
|
8288
8437
|
registerGetUpvotesCommand(upvoteCommand);
|
|
8289
8438
|
registerUpvoteUserCommand(upvoteCommand);
|
|
8290
8439
|
registerGetUserUpvotesCommand(upvoteCommand);
|
|
8440
|
+
registerRankingsCommand(upvoteCommand);
|
|
8291
8441
|
}
|
|
8292
8442
|
var VALID_RUN_MODES = ["auto", "feeds", "chats"];
|
|
8293
8443
|
function addAuthOptions(cmd) {
|