@t2000/cli 0.22.16 → 0.22.18
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/index.js +97 -31
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1155,7 +1155,7 @@ var require_command = __commonJS({
|
|
|
1155
1155
|
var childProcess = __require("child_process");
|
|
1156
1156
|
var path = __require("path");
|
|
1157
1157
|
var fs = __require("fs");
|
|
1158
|
-
var
|
|
1158
|
+
var process3 = __require("process");
|
|
1159
1159
|
var { Argument: Argument2, humanReadableArgName } = require_argument();
|
|
1160
1160
|
var { CommanderError: CommanderError2 } = require_error();
|
|
1161
1161
|
var { Help: Help2, stripColor } = require_help();
|
|
@@ -1202,13 +1202,13 @@ var require_command = __commonJS({
|
|
|
1202
1202
|
this._showSuggestionAfterError = true;
|
|
1203
1203
|
this._savedState = null;
|
|
1204
1204
|
this._outputConfiguration = {
|
|
1205
|
-
writeOut: (str) =>
|
|
1206
|
-
writeErr: (str) =>
|
|
1205
|
+
writeOut: (str) => process3.stdout.write(str),
|
|
1206
|
+
writeErr: (str) => process3.stderr.write(str),
|
|
1207
1207
|
outputError: (str, write) => write(str),
|
|
1208
|
-
getOutHelpWidth: () =>
|
|
1209
|
-
getErrHelpWidth: () =>
|
|
1210
|
-
getOutHasColors: () => useColor() ?? (
|
|
1211
|
-
getErrHasColors: () => useColor() ?? (
|
|
1208
|
+
getOutHelpWidth: () => process3.stdout.isTTY ? process3.stdout.columns : void 0,
|
|
1209
|
+
getErrHelpWidth: () => process3.stderr.isTTY ? process3.stderr.columns : void 0,
|
|
1210
|
+
getOutHasColors: () => useColor() ?? (process3.stdout.isTTY && process3.stdout.hasColors?.()),
|
|
1211
|
+
getErrHasColors: () => useColor() ?? (process3.stderr.isTTY && process3.stderr.hasColors?.()),
|
|
1212
1212
|
stripColor: (str) => stripColor(str)
|
|
1213
1213
|
};
|
|
1214
1214
|
this._hidden = false;
|
|
@@ -1591,7 +1591,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1591
1591
|
if (this._exitCallback) {
|
|
1592
1592
|
this._exitCallback(new CommanderError2(exitCode, code, message));
|
|
1593
1593
|
}
|
|
1594
|
-
|
|
1594
|
+
process3.exit(exitCode);
|
|
1595
1595
|
}
|
|
1596
1596
|
/**
|
|
1597
1597
|
* Register callback `fn` for the command.
|
|
@@ -1989,16 +1989,16 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
1989
1989
|
}
|
|
1990
1990
|
parseOptions = parseOptions || {};
|
|
1991
1991
|
if (argv === void 0 && parseOptions.from === void 0) {
|
|
1992
|
-
if (
|
|
1992
|
+
if (process3.versions?.electron) {
|
|
1993
1993
|
parseOptions.from = "electron";
|
|
1994
1994
|
}
|
|
1995
|
-
const execArgv =
|
|
1995
|
+
const execArgv = process3.execArgv ?? [];
|
|
1996
1996
|
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
|
|
1997
1997
|
parseOptions.from = "eval";
|
|
1998
1998
|
}
|
|
1999
1999
|
}
|
|
2000
2000
|
if (argv === void 0) {
|
|
2001
|
-
argv =
|
|
2001
|
+
argv = process3.argv;
|
|
2002
2002
|
}
|
|
2003
2003
|
this.rawArgs = argv.slice();
|
|
2004
2004
|
let userArgs;
|
|
@@ -2009,7 +2009,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2009
2009
|
userArgs = argv.slice(2);
|
|
2010
2010
|
break;
|
|
2011
2011
|
case "electron":
|
|
2012
|
-
if (
|
|
2012
|
+
if (process3.defaultApp) {
|
|
2013
2013
|
this._scriptPath = argv[1];
|
|
2014
2014
|
userArgs = argv.slice(2);
|
|
2015
2015
|
} else {
|
|
@@ -2196,11 +2196,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2196
2196
|
}
|
|
2197
2197
|
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
2198
2198
|
let proc;
|
|
2199
|
-
if (
|
|
2199
|
+
if (process3.platform !== "win32") {
|
|
2200
2200
|
if (launchWithNode) {
|
|
2201
2201
|
args.unshift(executableFile);
|
|
2202
|
-
args = incrementNodeInspectorPort(
|
|
2203
|
-
proc = childProcess.spawn(
|
|
2202
|
+
args = incrementNodeInspectorPort(process3.execArgv).concat(args);
|
|
2203
|
+
proc = childProcess.spawn(process3.argv[0], args, { stdio: "inherit" });
|
|
2204
2204
|
} else {
|
|
2205
2205
|
proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
2206
2206
|
}
|
|
@@ -2211,13 +2211,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2211
2211
|
subcommand._name
|
|
2212
2212
|
);
|
|
2213
2213
|
args.unshift(executableFile);
|
|
2214
|
-
args = incrementNodeInspectorPort(
|
|
2215
|
-
proc = childProcess.spawn(
|
|
2214
|
+
args = incrementNodeInspectorPort(process3.execArgv).concat(args);
|
|
2215
|
+
proc = childProcess.spawn(process3.execPath, args, { stdio: "inherit" });
|
|
2216
2216
|
}
|
|
2217
2217
|
if (!proc.killed) {
|
|
2218
2218
|
const signals = ["SIGUSR1", "SIGUSR2", "SIGTERM", "SIGINT", "SIGHUP"];
|
|
2219
2219
|
signals.forEach((signal) => {
|
|
2220
|
-
|
|
2220
|
+
process3.on(signal, () => {
|
|
2221
2221
|
if (proc.killed === false && proc.exitCode === null) {
|
|
2222
2222
|
proc.kill(signal);
|
|
2223
2223
|
}
|
|
@@ -2228,7 +2228,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2228
2228
|
proc.on("close", (code) => {
|
|
2229
2229
|
code = code ?? 1;
|
|
2230
2230
|
if (!exitCallback) {
|
|
2231
|
-
|
|
2231
|
+
process3.exit(code);
|
|
2232
2232
|
} else {
|
|
2233
2233
|
exitCallback(
|
|
2234
2234
|
new CommanderError2(
|
|
@@ -2250,7 +2250,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2250
2250
|
throw new Error(`'${executableFile}' not executable`);
|
|
2251
2251
|
}
|
|
2252
2252
|
if (!exitCallback) {
|
|
2253
|
-
|
|
2253
|
+
process3.exit(1);
|
|
2254
2254
|
} else {
|
|
2255
2255
|
const wrappedError = new CommanderError2(
|
|
2256
2256
|
1,
|
|
@@ -2745,13 +2745,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
2745
2745
|
*/
|
|
2746
2746
|
_parseOptionsEnv() {
|
|
2747
2747
|
this.options.forEach((option) => {
|
|
2748
|
-
if (option.envVar && option.envVar in
|
|
2748
|
+
if (option.envVar && option.envVar in process3.env) {
|
|
2749
2749
|
const optionKey = option.attributeName();
|
|
2750
2750
|
if (this.getOptionValue(optionKey) === void 0 || ["default", "config", "env"].includes(
|
|
2751
2751
|
this.getOptionValueSource(optionKey)
|
|
2752
2752
|
)) {
|
|
2753
2753
|
if (option.required || option.optional) {
|
|
2754
|
-
this.emit(`optionEnv:${option.name()}`,
|
|
2754
|
+
this.emit(`optionEnv:${option.name()}`, process3.env[option.envVar]);
|
|
2755
2755
|
} else {
|
|
2756
2756
|
this.emit(`optionEnv:${option.name()}`);
|
|
2757
2757
|
}
|
|
@@ -3206,7 +3206,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3206
3206
|
*/
|
|
3207
3207
|
help(contextOptions) {
|
|
3208
3208
|
this.outputHelp(contextOptions);
|
|
3209
|
-
let exitCode = Number(
|
|
3209
|
+
let exitCode = Number(process3.exitCode ?? 0);
|
|
3210
3210
|
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
|
|
3211
3211
|
exitCode = 1;
|
|
3212
3212
|
}
|
|
@@ -3296,9 +3296,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
|
|
|
3296
3296
|
});
|
|
3297
3297
|
}
|
|
3298
3298
|
function useColor() {
|
|
3299
|
-
if (
|
|
3299
|
+
if (process3.env.NO_COLOR || process3.env.FORCE_COLOR === "0" || process3.env.FORCE_COLOR === "false")
|
|
3300
3300
|
return false;
|
|
3301
|
-
if (
|
|
3301
|
+
if (process3.env.FORCE_COLOR || process3.env.CLICOLOR_FORCE !== void 0)
|
|
3302
3302
|
return true;
|
|
3303
3303
|
return void 0;
|
|
3304
3304
|
}
|
|
@@ -3403,6 +3403,9 @@ var require_picocolors = __commonJS({
|
|
|
3403
3403
|
}
|
|
3404
3404
|
});
|
|
3405
3405
|
|
|
3406
|
+
// src/index.ts
|
|
3407
|
+
import process2 from "process";
|
|
3408
|
+
|
|
3406
3409
|
// ../../node_modules/.pnpm/commander@13.1.0/node_modules/commander/esm.mjs
|
|
3407
3410
|
var import_index = __toESM(require_commander(), 1);
|
|
3408
3411
|
var {
|
|
@@ -3819,6 +3822,9 @@ function registerBalance(program3) {
|
|
|
3819
3822
|
} else {
|
|
3820
3823
|
printKeyValue("Investment", import_picocolors3.default.dim("\u2014"));
|
|
3821
3824
|
}
|
|
3825
|
+
if (bal.gasReserve && bal.gasReserve.usdEquiv >= 0.01) {
|
|
3826
|
+
printKeyValue("Gas reserve", `${formatUsd(bal.gasReserve.usdEquiv)} ${import_picocolors3.default.dim(`(${bal.gasReserve.sui.toFixed(2)} SUI)`)}`);
|
|
3827
|
+
}
|
|
3822
3828
|
printSeparator();
|
|
3823
3829
|
printKeyValue("Total", `${formatUsd(bal.total)}`);
|
|
3824
3830
|
if (dailyEarning >= 5e-3) {
|
|
@@ -3849,6 +3855,9 @@ function registerBalance(program3) {
|
|
|
3849
3855
|
} else {
|
|
3850
3856
|
printKeyValue("Investment", import_picocolors3.default.dim("\u2014"));
|
|
3851
3857
|
}
|
|
3858
|
+
if (bal.gasReserve && bal.gasReserve.usdEquiv >= 0.01) {
|
|
3859
|
+
printKeyValue("Gas reserve", `${formatUsd(bal.gasReserve.usdEquiv)} ${import_picocolors3.default.dim(`(${bal.gasReserve.sui.toFixed(2)} SUI)`)}`);
|
|
3860
|
+
}
|
|
3852
3861
|
printSeparator();
|
|
3853
3862
|
printKeyValue("Total", `${formatUsd(bal.total)}`);
|
|
3854
3863
|
}
|
|
@@ -8371,18 +8380,68 @@ function registerSwap(program3) {
|
|
|
8371
8380
|
if (isNaN(parsedAmount) || parsedAmount <= 0) {
|
|
8372
8381
|
throw new Error("Amount must be a positive number");
|
|
8373
8382
|
}
|
|
8374
|
-
|
|
8383
|
+
const resolved = resolveAssetName2(asset);
|
|
8384
|
+
if (resolved in INVESTMENT_ASSETS) {
|
|
8385
|
+
const pin = await resolvePin();
|
|
8386
|
+
const agent = await T2000.create({ pin, keyPath: opts.key });
|
|
8387
|
+
const result = await agent.investBuy({
|
|
8388
|
+
asset: resolved,
|
|
8389
|
+
usdAmount: parsedAmount,
|
|
8390
|
+
maxSlippage: parseFloat(opts.slippage ?? "3") / 100
|
|
8391
|
+
});
|
|
8392
|
+
if (isJsonMode()) {
|
|
8393
|
+
printJson(result);
|
|
8394
|
+
return;
|
|
8395
|
+
}
|
|
8396
|
+
const display = SUPPORTED_ASSETS[resolved]?.displayName ?? resolved;
|
|
8397
|
+
printBlank();
|
|
8398
|
+
printSuccess(`Bought ${fmtTokenAmount(result.amount, resolved)} ${display} for ${formatUsd(parsedAmount)}`);
|
|
8399
|
+
printKeyValue("Tx", explorerUrl(result.tx));
|
|
8400
|
+
printBlank();
|
|
8401
|
+
} else {
|
|
8402
|
+
await executeSwap("USDC", asset, parsedAmount, opts, "Bought");
|
|
8403
|
+
}
|
|
8375
8404
|
} catch (error) {
|
|
8376
8405
|
handleError(error);
|
|
8377
8406
|
}
|
|
8378
8407
|
});
|
|
8379
|
-
program3.command("sell <amount> <asset>").description("Sell an asset for USDC (e.g. sell 0.001 BTC)").option("--key <path>", "Key file path").option("--slippage <pct>", "Max slippage percentage (default: 3)", "3").action(async (amount, asset, opts) => {
|
|
8408
|
+
program3.command("sell <amount> <asset>").description("Sell an asset for USDC (e.g. sell 0.001 BTC, sell all SUI)").option("--key <path>", "Key file path").option("--slippage <pct>", "Max slippage percentage (default: 3)", "3").action(async (amount, asset, opts) => {
|
|
8380
8409
|
try {
|
|
8381
|
-
const
|
|
8382
|
-
|
|
8383
|
-
|
|
8410
|
+
const resolved = resolveAssetName2(asset);
|
|
8411
|
+
const isAll = amount.toLowerCase() === "all";
|
|
8412
|
+
if (resolved in INVESTMENT_ASSETS) {
|
|
8413
|
+
const pin = await resolvePin();
|
|
8414
|
+
const agent = await T2000.create({ pin, keyPath: opts.key });
|
|
8415
|
+
const usdAmount = isAll ? "all" : parseFloat(amount);
|
|
8416
|
+
if (usdAmount !== "all" && (isNaN(usdAmount) || usdAmount <= 0)) {
|
|
8417
|
+
throw new Error('Amount must be a positive number or "all"');
|
|
8418
|
+
}
|
|
8419
|
+
const result = await agent.investSell({
|
|
8420
|
+
asset: resolved,
|
|
8421
|
+
usdAmount,
|
|
8422
|
+
maxSlippage: parseFloat(opts.slippage ?? "3") / 100
|
|
8423
|
+
});
|
|
8424
|
+
if (isJsonMode()) {
|
|
8425
|
+
printJson(result);
|
|
8426
|
+
return;
|
|
8427
|
+
}
|
|
8428
|
+
const display = SUPPORTED_ASSETS[resolved]?.displayName ?? resolved;
|
|
8429
|
+
printBlank();
|
|
8430
|
+
printSuccess(`Sold ${fmtTokenAmount(result.amount, resolved)} ${display} at ${formatUsd(result.price)}`);
|
|
8431
|
+
printKeyValue("Proceeds", formatUsd(result.usdValue));
|
|
8432
|
+
if (result.realizedPnL !== void 0) {
|
|
8433
|
+
const pnlSign = result.realizedPnL >= 0 ? "+" : "";
|
|
8434
|
+
printKeyValue("Realized P&L", `${pnlSign}${formatUsd(result.realizedPnL)}`);
|
|
8435
|
+
}
|
|
8436
|
+
printKeyValue("Tx", explorerUrl(result.tx));
|
|
8437
|
+
printBlank();
|
|
8438
|
+
} else {
|
|
8439
|
+
const parsedAmount = parseFloat(amount);
|
|
8440
|
+
if (isNaN(parsedAmount) || parsedAmount <= 0) {
|
|
8441
|
+
throw new Error("Amount must be a positive number");
|
|
8442
|
+
}
|
|
8443
|
+
await executeSwap(asset, "USDC", parsedAmount, opts, "Sold");
|
|
8384
8444
|
}
|
|
8385
|
-
await executeSwap(asset, "USDC", parsedAmount, opts, "Sold");
|
|
8386
8445
|
} catch (error) {
|
|
8387
8446
|
handleError(error);
|
|
8388
8447
|
}
|
|
@@ -9377,6 +9436,13 @@ Examples:
|
|
|
9377
9436
|
}
|
|
9378
9437
|
|
|
9379
9438
|
// src/index.ts
|
|
9439
|
+
var _origEmit = process2.emit;
|
|
9440
|
+
process2.emit = function(event, ...args) {
|
|
9441
|
+
if (event === "warning" && typeof args[0] === "object" && args[0] !== null && args[0].name === "DeprecationWarning" && args[0].code === "DEP0169") {
|
|
9442
|
+
return false;
|
|
9443
|
+
}
|
|
9444
|
+
return _origEmit.apply(this, [event, ...args]);
|
|
9445
|
+
};
|
|
9380
9446
|
var program2 = createProgram();
|
|
9381
9447
|
program2.parse();
|
|
9382
9448
|
//# sourceMappingURL=index.js.map
|