@t2000/cli 0.13.1 → 0.14.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/index.js CHANGED
@@ -274,6 +274,14 @@ function registerBalance(program2) {
274
274
  const borrowApy = borrows.length > 0 ? borrows.reduce((sum, p) => sum + p.amount * p.apy, 0) / borrows.reduce((sum, p) => sum + p.amount, 0) : 0;
275
275
  printKeyValue("Credit", `${pc3.red(`-${formatUsd2(bal.debt)}`)} ${pc3.dim(`(${borrowApy.toFixed(2)}% APY)`)}`);
276
276
  }
277
+ if (bal.investment > 0.01) {
278
+ const pnlColor = bal.investmentPnL >= 0 ? pc3.green : pc3.red;
279
+ const pnlSign = bal.investmentPnL >= 0 ? "+" : "";
280
+ const pnlPct = bal.investment > 0 ? bal.investmentPnL / (bal.investment - bal.investmentPnL) * 100 : 0;
281
+ printKeyValue("Investment", `${formatUsd2(bal.investment)} ${pnlColor(`(${pnlSign}${pnlPct.toFixed(1)}%)`)}`);
282
+ } else {
283
+ printKeyValue("Investment", pc3.dim("\u2014"));
284
+ }
277
285
  printKeyValue("Gas", `${bal.gasReserve.sui.toFixed(2)} SUI ${pc3.dim(`(~${formatUsd2(bal.gasReserve.usdEquiv)})`)}`);
278
286
  printSeparator();
279
287
  printKeyValue("Total", `${formatUsd2(bal.total)}`);
@@ -285,6 +293,14 @@ function registerBalance(program2) {
285
293
  printKeyValue("Credit", `${pc3.red(`-${formatUsd2(bal.debt)}`)}`);
286
294
  }
287
295
  printKeyValue("Savings", `${formatUsd2(bal.savings)}`);
296
+ if (bal.investment > 0.01) {
297
+ const pnlColor = bal.investmentPnL >= 0 ? pc3.green : pc3.red;
298
+ const pnlSign = bal.investmentPnL >= 0 ? "+" : "";
299
+ const pnlPct = bal.investment > 0 ? bal.investmentPnL / (bal.investment - bal.investmentPnL) * 100 : 0;
300
+ printKeyValue("Investment", `${formatUsd2(bal.investment)} ${pnlColor(`(${pnlSign}${pnlPct.toFixed(1)}%)`)}`);
301
+ } else {
302
+ printKeyValue("Investment", pc3.dim("\u2014"));
303
+ }
288
304
  printKeyValue("Gas", `${bal.gasReserve.sui.toFixed(2)} SUI ${pc3.dim(`(~${formatUsd2(bal.gasReserve.usdEquiv)})`)}`);
289
305
  printSeparator();
290
306
  printKeyValue("Total", `${formatUsd2(bal.total)}`);
@@ -814,7 +830,7 @@ import { homedir as homedir3 } from "os";
814
830
  import { SafeguardEnforcer } from "@t2000/sdk";
815
831
  var CONFIG_DIR = join(homedir3(), ".t2000");
816
832
  var CONFIG_PATH = join(CONFIG_DIR, "config.json");
817
- var SAFEGUARD_KEYS = /* @__PURE__ */ new Set(["locked", "maxPerTx", "maxDailySend", "dailyUsed", "dailyResetDate", "alertThreshold"]);
833
+ var SAFEGUARD_KEYS = /* @__PURE__ */ new Set(["locked", "maxPerTx", "maxDailySend", "dailyUsed", "dailyResetDate", "alertThreshold", "maxLeverage", "maxPositionSize"]);
818
834
  function loadConfig() {
819
835
  try {
820
836
  return JSON.parse(readFileSync(CONFIG_PATH, "utf-8"));
@@ -1343,8 +1359,8 @@ function registerLock(program2) {
1343
1359
  if (!pin) {
1344
1360
  throw new Error("PIN required to unlock agent");
1345
1361
  }
1346
- const { T2000: T200024 } = await import("@t2000/sdk");
1347
- await T200024.create({ pin });
1362
+ const { T2000: T200026 } = await import("@t2000/sdk");
1363
+ await T200026.create({ pin });
1348
1364
  const enforcer = new SafeguardEnforcer2(CONFIG_DIR3);
1349
1365
  enforcer.load();
1350
1366
  enforcer.unlock();
@@ -1771,7 +1787,7 @@ function registerMcp(program2) {
1771
1787
  mcp.command("start", { isDefault: true }).description("Start MCP server (stdio transport)").option("--key <path>", "Key file path").action(async (opts) => {
1772
1788
  let mod;
1773
1789
  try {
1774
- mod = await import("./dist-QGTOSQO3.js");
1790
+ mod = await import("./dist-4YM7JZSI.js");
1775
1791
  } catch {
1776
1792
  console.error(
1777
1793
  "MCP server not installed. Run:\n npm install -g @t2000/mcp"
@@ -1922,6 +1938,142 @@ function registerContacts(program2) {
1922
1938
  });
1923
1939
  }
1924
1940
 
1941
+ // src/commands/invest.ts
1942
+ import pc13 from "picocolors";
1943
+ import { T2000 as T200024, formatUsd as formatUsd15, formatAssetAmount } from "@t2000/sdk";
1944
+ function registerInvest(program2) {
1945
+ const investCmd = program2.command("invest").description("Buy or sell investment assets");
1946
+ investCmd.command("buy <amount> <asset>").description("Invest USD amount in an asset").option("--key <path>", "Key file path").option("--slippage <pct>", "Max slippage percent", "3").action(async (amount, asset, opts) => {
1947
+ try {
1948
+ const parsed = parseFloat(amount);
1949
+ if (isNaN(parsed) || parsed <= 0 || !isFinite(parsed)) {
1950
+ console.error(pc13.red(" \u2717 Amount must be greater than $0"));
1951
+ process.exitCode = 1;
1952
+ return;
1953
+ }
1954
+ const pin = await resolvePin();
1955
+ const agent = await T200024.create({ pin, keyPath: opts.key });
1956
+ const result = await agent.investBuy({
1957
+ asset: asset.toUpperCase(),
1958
+ usdAmount: parsed,
1959
+ maxSlippage: parseFloat(opts.slippage) / 100
1960
+ });
1961
+ if (isJsonMode()) {
1962
+ printJson(result);
1963
+ return;
1964
+ }
1965
+ printBlank();
1966
+ const sym = asset.toUpperCase();
1967
+ printSuccess(`Bought ${formatAssetAmount(result.amount, sym)} ${sym} at ${formatUsd15(result.price)}`);
1968
+ printKeyValue("Invested", formatUsd15(result.usdValue));
1969
+ printKeyValue("Portfolio", `${formatAssetAmount(result.position.totalAmount, sym)} ${sym} (avg ${formatUsd15(result.position.avgPrice)})`);
1970
+ printKeyValue("Tx", explorerUrl(result.tx));
1971
+ printBlank();
1972
+ } catch (error) {
1973
+ handleError(error);
1974
+ }
1975
+ });
1976
+ investCmd.command("sell <amount> <asset>").description('Sell USD amount of an asset (or "all")').option("--key <path>", "Key file path").option("--slippage <pct>", "Max slippage percent", "3").action(async (amount, asset, opts) => {
1977
+ try {
1978
+ const isAll = amount.toLowerCase() === "all";
1979
+ if (!isAll) {
1980
+ const parsed = parseFloat(amount);
1981
+ if (isNaN(parsed) || parsed <= 0 || !isFinite(parsed)) {
1982
+ console.error(pc13.red(" \u2717 Amount must be greater than $0"));
1983
+ process.exitCode = 1;
1984
+ return;
1985
+ }
1986
+ }
1987
+ const pin = await resolvePin();
1988
+ const agent = await T200024.create({ pin, keyPath: opts.key });
1989
+ const usdAmount = isAll ? "all" : parseFloat(amount);
1990
+ const result = await agent.investSell({
1991
+ asset: asset.toUpperCase(),
1992
+ usdAmount,
1993
+ maxSlippage: parseFloat(opts.slippage) / 100
1994
+ });
1995
+ if (isJsonMode()) {
1996
+ printJson(result);
1997
+ return;
1998
+ }
1999
+ printBlank();
2000
+ const sym = asset.toUpperCase();
2001
+ printSuccess(`Sold ${formatAssetAmount(result.amount, sym)} ${sym} at ${formatUsd15(result.price)}`);
2002
+ printKeyValue("Proceeds", formatUsd15(result.usdValue));
2003
+ if (result.realizedPnL !== void 0) {
2004
+ const pnlColor = result.realizedPnL >= 0 ? pc13.green : pc13.red;
2005
+ const pnlSign = result.realizedPnL >= 0 ? "+" : "";
2006
+ printKeyValue("Realized P&L", pnlColor(`${pnlSign}${formatUsd15(result.realizedPnL)}`));
2007
+ }
2008
+ if (result.position.totalAmount > 0) {
2009
+ printKeyValue("Remaining", `${formatAssetAmount(result.position.totalAmount, sym)} ${sym} (avg ${formatUsd15(result.position.avgPrice)})`);
2010
+ }
2011
+ printKeyValue("Tx", explorerUrl(result.tx));
2012
+ printBlank();
2013
+ } catch (error) {
2014
+ handleError(error);
2015
+ }
2016
+ });
2017
+ }
2018
+
2019
+ // src/commands/portfolio.ts
2020
+ import pc14 from "picocolors";
2021
+ import { T2000 as T200025, formatUsd as formatUsd16, formatAssetAmount as formatAssetAmount2 } from "@t2000/sdk";
2022
+ function registerPortfolio(program2) {
2023
+ program2.command("portfolio").description("Show investment portfolio").option("--key <path>", "Key file path").action(async (opts) => {
2024
+ try {
2025
+ const pin = await resolvePin();
2026
+ const agent = await T200025.create({ pin, keyPath: opts.key });
2027
+ const portfolio = await agent.getPortfolio();
2028
+ if (isJsonMode()) {
2029
+ printJson(portfolio);
2030
+ return;
2031
+ }
2032
+ printBlank();
2033
+ if (portfolio.positions.length === 0) {
2034
+ printInfo("No investments yet. Try: t2000 invest buy 100 SUI");
2035
+ printBlank();
2036
+ return;
2037
+ }
2038
+ printHeader("Investment Portfolio");
2039
+ printSeparator();
2040
+ for (const pos of portfolio.positions) {
2041
+ if (pos.currentPrice === 0 && pos.totalAmount > 0) {
2042
+ printKeyValue(
2043
+ pos.asset,
2044
+ `${formatAssetAmount2(pos.totalAmount, pos.asset)} Avg: ${formatUsd16(pos.avgPrice)} Now: ${pc14.yellow("unavailable")}`
2045
+ );
2046
+ } else {
2047
+ const pnlColor = pos.unrealizedPnL >= 0 ? pc14.green : pc14.red;
2048
+ const pnlSign = pos.unrealizedPnL >= 0 ? "+" : "";
2049
+ printKeyValue(
2050
+ pos.asset,
2051
+ `${formatAssetAmount2(pos.totalAmount, pos.asset)} Avg: ${formatUsd16(pos.avgPrice)} Now: ${formatUsd16(pos.currentPrice)} ${pnlColor(`${pnlSign}${formatUsd16(pos.unrealizedPnL)} (${pnlSign}${pos.unrealizedPnLPct.toFixed(1)}%)`)}`
2052
+ );
2053
+ }
2054
+ }
2055
+ printSeparator();
2056
+ const hasPriceUnavailable = portfolio.positions.some((p) => p.currentPrice === 0 && p.totalAmount > 0);
2057
+ if (hasPriceUnavailable) {
2058
+ printInfo(pc14.yellow("\u26A0 Price data unavailable for some assets. Values may be inaccurate."));
2059
+ }
2060
+ printKeyValue("Total invested", formatUsd16(portfolio.totalInvested));
2061
+ printKeyValue("Current value", formatUsd16(portfolio.totalValue));
2062
+ const upnlColor = portfolio.unrealizedPnL >= 0 ? pc14.green : pc14.red;
2063
+ const upnlSign = portfolio.unrealizedPnL >= 0 ? "+" : "";
2064
+ printKeyValue("Unrealized P&L", upnlColor(`${upnlSign}${formatUsd16(portfolio.unrealizedPnL)} (${upnlSign}${portfolio.unrealizedPnLPct.toFixed(1)}%)`));
2065
+ if (portfolio.realizedPnL !== 0) {
2066
+ const rpnlColor = portfolio.realizedPnL >= 0 ? pc14.green : pc14.red;
2067
+ const rpnlSign = portfolio.realizedPnL >= 0 ? "+" : "";
2068
+ printKeyValue("Realized P&L", rpnlColor(`${rpnlSign}${formatUsd16(portfolio.realizedPnL)}`));
2069
+ }
2070
+ printBlank();
2071
+ } catch (error) {
2072
+ handleError(error);
2073
+ }
2074
+ });
2075
+ }
2076
+
1925
2077
  // src/program.ts
1926
2078
  var require2 = createRequire(import.meta.url);
1927
2079
  var { version: CLI_VERSION } = require2("../package.json");
@@ -1958,6 +2110,8 @@ function createProgram() {
1958
2110
  registerExchange(program2);
1959
2111
  registerMcp(program2);
1960
2112
  registerContacts(program2);
2113
+ registerInvest(program2);
2114
+ registerPortfolio(program2);
1961
2115
  return program2;
1962
2116
  }
1963
2117