@net-protocol/cli 0.1.34 → 0.1.35
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 +165 -3
- package/dist/cli/index.mjs.map +1 -1
- package/dist/upvote/index.d.ts +5 -1
- package/dist/upvote/index.mjs +166 -4
- package/dist/upvote/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import chalk4 from 'chalk';
|
|
|
7
7
|
import * as fs6 from 'fs';
|
|
8
8
|
import { readFileSync, existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
9
9
|
import { OPTIMAL_CHUNK_SIZE, StorageClient, detectFileTypeFromBase64, base64ToDataUri, shouldSuggestXmlStorage, getStorageKeyBytes, encodeStorageKeyForUrl, chunkDataForStorage, CHUNKED_STORAGE_CONTRACT, STORAGE_CONTRACT as STORAGE_CONTRACT$1 } from '@net-protocol/storage';
|
|
10
|
-
import { stringToHex, createWalletClient, http, hexToString, parseEther, encodeFunctionData, publicActions, concat, defineChain, createPublicClient } from 'viem';
|
|
10
|
+
import { stringToHex, createWalletClient, http, hexToString, parseEther, encodeFunctionData, publicActions, concat, defineChain, createPublicClient, formatEther } from 'viem';
|
|
11
11
|
import { privateKeyToAccount } from 'viem/accounts';
|
|
12
12
|
import { getNetContract, getChainName, getPublicClient, getChainRpcUrls, getBaseDataSuffix, NetClient, toBytes32, NULL_ADDRESS } from '@net-protocol/core';
|
|
13
13
|
import { createRelayX402Client, createRelaySession, checkBackendWalletBalance, fundBackendWallet, batchTransactions, submitTransactionsViaRelay, waitForConfirmations, retryFailedTransactions as retryFailedTransactions$1 } from '@net-protocol/relay';
|
|
@@ -21,7 +21,7 @@ import { BazaarClient } from '@net-protocol/bazaar';
|
|
|
21
21
|
import * as os from 'os';
|
|
22
22
|
import { homedir } from 'os';
|
|
23
23
|
import * as readline from 'readline';
|
|
24
|
-
import { discoverTokenPool, PURE_ALPHA_STRATEGY, UNIV234_POOLS_STRATEGY, encodePoolKey, DYNAMIC_SPLIT_STRATEGY, getTokenScoreKey, UPVOTE_PRICE_ETH, UPVOTE_APP, ScoreClient, ALL_STRATEGY_ADDRESSES } from '@net-protocol/score';
|
|
24
|
+
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
25
|
|
|
26
26
|
var DEFAULT_CHAIN_ID = 8453;
|
|
27
27
|
function getRequiredChainId(optionValue) {
|
|
@@ -7155,12 +7155,174 @@ function registerGetUpvotesCommand(parent, commandName = "info") {
|
|
|
7155
7155
|
await executeGetUpvotes(options);
|
|
7156
7156
|
});
|
|
7157
7157
|
}
|
|
7158
|
+
async function executeUpvoteUser(options) {
|
|
7159
|
+
const count = parseInt(options.count, 10);
|
|
7160
|
+
if (isNaN(count) || count <= 0) {
|
|
7161
|
+
exitWithError("Count must be a positive integer");
|
|
7162
|
+
return;
|
|
7163
|
+
}
|
|
7164
|
+
const userAddress = options.address;
|
|
7165
|
+
if (!userAddress.startsWith("0x") || userAddress.length !== 42) {
|
|
7166
|
+
exitWithError(
|
|
7167
|
+
"Invalid address format (must be 0x-prefixed, 42 characters)"
|
|
7168
|
+
);
|
|
7169
|
+
return;
|
|
7170
|
+
}
|
|
7171
|
+
const token = options.token ?? NULL_ADDRESS$1;
|
|
7172
|
+
const feeTier = options.feeTier ? parseInt(options.feeTier, 10) : 0;
|
|
7173
|
+
const readOnlyOptions = parseReadOnlyOptionsWithDefault({
|
|
7174
|
+
chainId: options.chainId,
|
|
7175
|
+
rpcUrl: options.rpcUrl
|
|
7176
|
+
});
|
|
7177
|
+
const client = new UserUpvoteClient({
|
|
7178
|
+
chainId: readOnlyOptions.chainId,
|
|
7179
|
+
overrides: readOnlyOptions.rpcUrl ? { rpcUrls: [readOnlyOptions.rpcUrl] } : void 0
|
|
7180
|
+
});
|
|
7181
|
+
let upvotePrice;
|
|
7182
|
+
try {
|
|
7183
|
+
upvotePrice = await client.getUpvotePrice();
|
|
7184
|
+
} catch (error) {
|
|
7185
|
+
exitWithError(
|
|
7186
|
+
`Failed to fetch upvote price: ${error instanceof Error ? error.message : String(error)}`
|
|
7187
|
+
);
|
|
7188
|
+
return;
|
|
7189
|
+
}
|
|
7190
|
+
const totalCost = calculateUpvoteCost(count, upvotePrice);
|
|
7191
|
+
if (options.encodeOnly) {
|
|
7192
|
+
const txConfig = {
|
|
7193
|
+
to: USER_UPVOTE_CONTRACT.address,
|
|
7194
|
+
abi: USER_UPVOTE_CONTRACT.abi,
|
|
7195
|
+
functionName: "upvoteUser",
|
|
7196
|
+
args: [userAddress, token, BigInt(count), BigInt(feeTier)],
|
|
7197
|
+
value: totalCost
|
|
7198
|
+
};
|
|
7199
|
+
const encoded = encodeTransaction(txConfig, readOnlyOptions.chainId);
|
|
7200
|
+
console.log(JSON.stringify(encoded, null, 2));
|
|
7201
|
+
return;
|
|
7202
|
+
}
|
|
7203
|
+
const commonOptions = parseCommonOptionsWithDefault(
|
|
7204
|
+
{
|
|
7205
|
+
privateKey: options.privateKey,
|
|
7206
|
+
chainId: options.chainId,
|
|
7207
|
+
rpcUrl: options.rpcUrl
|
|
7208
|
+
},
|
|
7209
|
+
true
|
|
7210
|
+
);
|
|
7211
|
+
const walletClient = createWallet(
|
|
7212
|
+
commonOptions.privateKey,
|
|
7213
|
+
commonOptions.chainId,
|
|
7214
|
+
commonOptions.rpcUrl
|
|
7215
|
+
);
|
|
7216
|
+
console.log(
|
|
7217
|
+
chalk4.blue(`Submitting ${count} profile upvote(s) for ${userAddress}...`)
|
|
7218
|
+
);
|
|
7219
|
+
try {
|
|
7220
|
+
const hash = await client.upvoteUser({
|
|
7221
|
+
walletClient,
|
|
7222
|
+
userToUpvote: userAddress,
|
|
7223
|
+
token,
|
|
7224
|
+
numUpvotes: count,
|
|
7225
|
+
feeTier,
|
|
7226
|
+
value: totalCost
|
|
7227
|
+
});
|
|
7228
|
+
console.log(chalk4.green("Profile upvote submitted successfully!"));
|
|
7229
|
+
console.log(chalk4.white(` Transaction: ${hash}`));
|
|
7230
|
+
console.log(chalk4.white(` User: ${userAddress}`));
|
|
7231
|
+
console.log(chalk4.white(` Count: ${count}`));
|
|
7232
|
+
console.log(chalk4.white(` Value: ${formatEther(totalCost)} ETH`));
|
|
7233
|
+
if (token !== NULL_ADDRESS$1) {
|
|
7234
|
+
console.log(chalk4.white(` Token: ${token}`));
|
|
7235
|
+
}
|
|
7236
|
+
} catch (error) {
|
|
7237
|
+
exitWithError(
|
|
7238
|
+
`Failed to submit profile upvote: ${error instanceof Error ? error.message : String(error)}`
|
|
7239
|
+
);
|
|
7240
|
+
}
|
|
7241
|
+
}
|
|
7242
|
+
function registerUpvoteUserCommand(parent, commandName = "user") {
|
|
7243
|
+
parent.command(commandName).description("Upvote a user's profile on Net Protocol").requiredOption("--address <address>", "User address to upvote").requiredOption("--count <n>", "Number of upvotes").option("--token <address>", "Token address (default: null address)").option("--fee-tier <tier>", "Fee tier (default: 0)").option(
|
|
7244
|
+
"--chain-id <id>",
|
|
7245
|
+
"Chain ID (default: 8453 for Base)",
|
|
7246
|
+
(value) => parseInt(value, 10)
|
|
7247
|
+
).option("--rpc-url <url>", "Custom RPC URL").option("--private-key <key>", "Private key (0x-prefixed)").option(
|
|
7248
|
+
"--encode-only",
|
|
7249
|
+
"Output transaction data as JSON instead of executing"
|
|
7250
|
+
).action(async (options) => {
|
|
7251
|
+
await executeUpvoteUser(options);
|
|
7252
|
+
});
|
|
7253
|
+
}
|
|
7254
|
+
async function executeGetUserUpvotes(options) {
|
|
7255
|
+
const userAddress = options.address;
|
|
7256
|
+
if (!userAddress.startsWith("0x") || userAddress.length !== 42) {
|
|
7257
|
+
exitWithError(
|
|
7258
|
+
"Invalid address format (must be 0x-prefixed, 42 characters)"
|
|
7259
|
+
);
|
|
7260
|
+
return;
|
|
7261
|
+
}
|
|
7262
|
+
const readOnlyOptions = parseReadOnlyOptionsWithDefault({
|
|
7263
|
+
chainId: options.chainId,
|
|
7264
|
+
rpcUrl: options.rpcUrl
|
|
7265
|
+
});
|
|
7266
|
+
const client = new UserUpvoteClient({
|
|
7267
|
+
chainId: readOnlyOptions.chainId,
|
|
7268
|
+
overrides: readOnlyOptions.rpcUrl ? { rpcUrls: [readOnlyOptions.rpcUrl] } : void 0
|
|
7269
|
+
});
|
|
7270
|
+
try {
|
|
7271
|
+
const [given, received, upvotePrice] = await Promise.all([
|
|
7272
|
+
client.getUserUpvotesGiven({
|
|
7273
|
+
user: userAddress
|
|
7274
|
+
}),
|
|
7275
|
+
client.getUserUpvotesReceived({
|
|
7276
|
+
user: userAddress
|
|
7277
|
+
}),
|
|
7278
|
+
client.getUpvotePrice()
|
|
7279
|
+
]);
|
|
7280
|
+
if (options.json) {
|
|
7281
|
+
console.log(
|
|
7282
|
+
JSON.stringify(
|
|
7283
|
+
{
|
|
7284
|
+
address: userAddress,
|
|
7285
|
+
chainId: readOnlyOptions.chainId,
|
|
7286
|
+
upvotesGiven: Number(given),
|
|
7287
|
+
upvotesReceived: Number(received),
|
|
7288
|
+
upvotePriceWei: upvotePrice.toString(),
|
|
7289
|
+
upvotePriceEth: formatEther(upvotePrice)
|
|
7290
|
+
},
|
|
7291
|
+
null,
|
|
7292
|
+
2
|
|
7293
|
+
)
|
|
7294
|
+
);
|
|
7295
|
+
} else {
|
|
7296
|
+
console.log(chalk4.white(`Profile upvotes for ${userAddress}:`));
|
|
7297
|
+
console.log(chalk4.cyan(` Upvotes Given: ${given}`));
|
|
7298
|
+
console.log(chalk4.cyan(` Upvotes Received: ${received}`));
|
|
7299
|
+
console.log(
|
|
7300
|
+
chalk4.white(` Upvote Price: ${formatEther(upvotePrice)} ETH`)
|
|
7301
|
+
);
|
|
7302
|
+
}
|
|
7303
|
+
} catch (error) {
|
|
7304
|
+
exitWithError(
|
|
7305
|
+
`Failed to fetch user upvotes: ${error instanceof Error ? error.message : String(error)}`
|
|
7306
|
+
);
|
|
7307
|
+
}
|
|
7308
|
+
}
|
|
7309
|
+
function registerGetUserUpvotesCommand(parent, commandName = "user-info") {
|
|
7310
|
+
parent.command(commandName).description("Get profile upvote stats for a user").requiredOption("--address <address>", "User address to look up").option(
|
|
7311
|
+
"--chain-id <id>",
|
|
7312
|
+
"Chain ID (default: 8453 for Base)",
|
|
7313
|
+
(value) => parseInt(value, 10)
|
|
7314
|
+
).option("--rpc-url <url>", "Custom RPC URL").option("--json", "Output in JSON format").action(async (options) => {
|
|
7315
|
+
await executeGetUserUpvotes(options);
|
|
7316
|
+
});
|
|
7317
|
+
}
|
|
7158
7318
|
|
|
7159
7319
|
// src/commands/upvote/index.ts
|
|
7160
7320
|
function registerUpvoteCommand(program2) {
|
|
7161
|
-
const upvoteCommand = program2.command("upvote").description("Upvote tokens on Net Protocol");
|
|
7321
|
+
const upvoteCommand = program2.command("upvote").description("Upvote tokens and users on Net Protocol");
|
|
7162
7322
|
registerUpvoteTokenCommand(upvoteCommand);
|
|
7163
7323
|
registerGetUpvotesCommand(upvoteCommand);
|
|
7324
|
+
registerUpvoteUserCommand(upvoteCommand);
|
|
7325
|
+
registerGetUserUpvotesCommand(upvoteCommand);
|
|
7164
7326
|
}
|
|
7165
7327
|
var CACHE_DIR = join(homedir(), ".netp");
|
|
7166
7328
|
var CACHE_FILE = join(CACHE_DIR, "update-check.json");
|