@t2000/cli 0.20.9 → 0.20.11

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
@@ -378,11 +378,11 @@ function registerBalance(program2) {
378
378
  const positions = await agent.positions();
379
379
  const saves = positions.positions.filter((p) => p.type === "save");
380
380
  const borrows = positions.positions.filter((p) => p.type === "borrow");
381
- const weightedApy = saves.length > 0 ? saves.reduce((sum, p) => sum + p.amount * p.apy, 0) / saves.reduce((sum, p) => sum + p.amount, 0) : 0;
381
+ const weightedApy = saves.length > 0 ? saves.reduce((sum, p) => sum + (p.amountUsd ?? p.amount) * p.apy, 0) / saves.reduce((sum, p) => sum + (p.amountUsd ?? p.amount), 0) : 0;
382
382
  const dailyEarning = bal.savings * (weightedApy / 100) / 365;
383
383
  printKeyValue("Savings", `${formatUsd2(bal.savings)} ${pc3.dim(`(earning ${weightedApy.toFixed(2)}% APY)`)}`);
384
384
  if (bal.debt > 0.01) {
385
- const borrowApy = borrows.length > 0 ? borrows.reduce((sum, p) => sum + p.amount * p.apy, 0) / borrows.reduce((sum, p) => sum + p.amount, 0) : 0;
385
+ const borrowApy = borrows.length > 0 ? borrows.reduce((sum, p) => sum + (p.amountUsd ?? p.amount) * p.apy, 0) / borrows.reduce((sum, p) => sum + (p.amountUsd ?? p.amount), 0) : 0;
386
386
  printKeyValue("Credit", `${pc3.red(`-${formatUsd2(bal.debt)}`)} ${pc3.dim(`(${borrowApy.toFixed(2)}% APY)`)}`);
387
387
  }
388
388
  if (bal.investment > 0.01) {
@@ -843,7 +843,7 @@ function registerRates(program2) {
843
843
 
844
844
  // src/commands/positions.ts
845
845
  import pc6 from "picocolors";
846
- import { T2000 as T200015, formatUsd as formatUsd8 } from "@t2000/sdk";
846
+ import { T2000 as T200015, formatUsd as formatUsd8, formatAssetAmount } from "@t2000/sdk";
847
847
  function registerPositions(program2) {
848
848
  program2.command("positions").description("Show savings & borrow positions across all protocols and assets").option("--key <path>", "Key file path").action(async (opts) => {
849
849
  try {
@@ -875,9 +875,10 @@ function registerPositions(program2) {
875
875
  printDivider();
876
876
  for (const pos of saves) {
877
877
  const earning = rewardsByKey.has(`${pos.protocol}:${pos.asset}`) ? ` ${pc6.yellow("+rewards")}` : "";
878
- printKeyValue(pos.protocol, `${formatUsd8(pos.amount)} ${pos.asset} @ ${pos.apy.toFixed(2)}% APY${earning}`);
878
+ const usd = formatUsd8(pos.amountUsd ?? pos.amount);
879
+ printKeyValue(pos.protocol, `${formatAssetAmount(pos.amount, pos.asset)} ${pos.asset} (${usd}) @ ${pos.apy.toFixed(2)}% APY${earning}`);
879
880
  }
880
- const totalSaved = saves.reduce((s, p) => s + p.amount, 0);
881
+ const totalSaved = saves.reduce((s, p) => s + (p.amountUsd ?? p.amount), 0);
881
882
  if (saves.length > 1) {
882
883
  printKeyValue("Total", formatUsd8(totalSaved));
883
884
  }
@@ -890,9 +891,10 @@ function registerPositions(program2) {
890
891
  printLine(pc6.bold("Borrows"));
891
892
  printDivider();
892
893
  for (const pos of borrows) {
893
- printKeyValue(pos.protocol, `${formatUsd8(pos.amount)} ${pos.asset} @ ${pos.apy.toFixed(2)}% APY`);
894
+ const usd = formatUsd8(pos.amountUsd ?? pos.amount);
895
+ printKeyValue(pos.protocol, `${formatAssetAmount(pos.amount, pos.asset)} ${pos.asset} (${usd}) @ ${pos.apy.toFixed(2)}% APY`);
894
896
  }
895
- const totalBorrowed = borrows.reduce((s, p) => s + p.amount, 0);
897
+ const totalBorrowed = borrows.reduce((s, p) => s + (p.amountUsd ?? p.amount), 0);
896
898
  if (borrows.length > 1) {
897
899
  printKeyValue("Total", formatUsd8(totalBorrowed));
898
900
  }
@@ -907,7 +909,7 @@ function registerPositions(program2) {
907
909
 
908
910
  // src/commands/earnings.ts
909
911
  import pc7 from "picocolors";
910
- import { T2000 as T200016, formatUsd as formatUsd9 } from "@t2000/sdk";
912
+ import { T2000 as T200016, formatUsd as formatUsd9, formatAssetAmount as formatAssetAmount2 } from "@t2000/sdk";
911
913
  function registerEarnings(program2) {
912
914
  program2.command("earnings").description("Show yield earned to date").option("--key <path>", "Key file path").action(async (opts) => {
913
915
  try {
@@ -924,7 +926,7 @@ function registerEarnings(program2) {
924
926
  printKeyValue("Total Saved", formatUsd9(result.supplied));
925
927
  if (savePositions.length > 0) {
926
928
  for (const p of savePositions) {
927
- printLine(` ${pc7.dim("\u2022")} ${formatUsd9(p.amount)} ${p.asset} on ${p.protocol} @ ${p.apy.toFixed(2)}% APY`);
929
+ printLine(` ${pc7.dim("\u2022")} ${formatAssetAmount2(p.amount, p.asset)} ${p.asset} (${formatUsd9(p.amountUsd ?? p.amount)}) on ${p.protocol} @ ${p.apy.toFixed(2)}% APY`);
928
930
  }
929
931
  }
930
932
  printKeyValue("Blended APY", `${result.currentApy.toFixed(2)}%`);
@@ -939,7 +941,7 @@ function registerEarnings(program2) {
939
941
 
940
942
  // src/commands/fundStatus.ts
941
943
  import pc8 from "picocolors";
942
- import { T2000 as T200017, formatUsd as formatUsd10 } from "@t2000/sdk";
944
+ import { T2000 as T200017, formatUsd as formatUsd10, formatAssetAmount as formatAssetAmount3 } from "@t2000/sdk";
943
945
  function registerFundStatus(program2) {
944
946
  program2.command("fund-status").description("Full savings summary").option("--key <path>", "Key file path").action(async (opts) => {
945
947
  try {
@@ -962,7 +964,7 @@ function registerFundStatus(program2) {
962
964
  printKeyValue("Total Saved", formatUsd10(result.supplied));
963
965
  if (savePositions.length > 0) {
964
966
  for (const p of savePositions) {
965
- printLine(` ${pc8.dim("\u2022")} ${formatUsd10(p.amount)} ${p.asset} on ${p.protocol} @ ${p.apy.toFixed(2)}% APY`);
967
+ printLine(` ${pc8.dim("\u2022")} ${formatAssetAmount3(p.amount, p.asset)} ${p.asset} (${formatUsd10(p.amountUsd ?? p.amount)}) on ${p.protocol} @ ${p.apy.toFixed(2)}% APY`);
966
968
  }
967
969
  }
968
970
  printKeyValue("Blended APY", `${result.apy.toFixed(2)}%`);
@@ -2202,7 +2204,7 @@ function registerContacts(program2) {
2202
2204
 
2203
2205
  // src/commands/invest.ts
2204
2206
  import pc13 from "picocolors";
2205
- import { T2000 as T200024, formatUsd as formatUsd15, formatAssetAmount, INVESTMENT_ASSETS as INVESTMENT_ASSETS2 } from "@t2000/sdk";
2207
+ import { T2000 as T200024, formatUsd as formatUsd15, formatAssetAmount as formatAssetAmount4, INVESTMENT_ASSETS as INVESTMENT_ASSETS2 } from "@t2000/sdk";
2206
2208
  function registerInvest(program2) {
2207
2209
  const investCmd = program2.command("invest").description("Buy or sell investment assets");
2208
2210
  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) => {
@@ -2226,9 +2228,9 @@ function registerInvest(program2) {
2226
2228
  }
2227
2229
  printBlank();
2228
2230
  const sym = asset.toUpperCase();
2229
- printSuccess(`Bought ${formatAssetAmount(result.amount, sym)} ${sym} at ${formatUsd15(result.price)}`);
2231
+ printSuccess(`Bought ${formatAssetAmount4(result.amount, sym)} ${sym} at ${formatUsd15(result.price)}`);
2230
2232
  printKeyValue("Invested", formatUsd15(result.usdValue));
2231
- printKeyValue("Portfolio", `${formatAssetAmount(result.position.totalAmount, sym)} ${sym} (avg ${formatUsd15(result.position.avgPrice)})`);
2233
+ printKeyValue("Portfolio", `${formatAssetAmount4(result.position.totalAmount, sym)} ${sym} (avg ${formatUsd15(result.position.avgPrice)})`);
2232
2234
  printKeyValue("Tx", explorerUrl(result.tx));
2233
2235
  printBlank();
2234
2236
  } catch (error) {
@@ -2260,7 +2262,7 @@ function registerInvest(program2) {
2260
2262
  }
2261
2263
  printBlank();
2262
2264
  const sym = asset.toUpperCase();
2263
- printSuccess(`Sold ${formatAssetAmount(result.amount, sym)} ${sym} at ${formatUsd15(result.price)}`);
2265
+ printSuccess(`Sold ${formatAssetAmount4(result.amount, sym)} ${sym} at ${formatUsd15(result.price)}`);
2264
2266
  printKeyValue("Proceeds", formatUsd15(result.usdValue));
2265
2267
  if (result.realizedPnL !== void 0) {
2266
2268
  const pnlColor = result.realizedPnL >= 0 ? pc13.green : pc13.red;
@@ -2268,7 +2270,7 @@ function registerInvest(program2) {
2268
2270
  printKeyValue("Realized P&L", pnlColor(`${pnlSign}${formatUsd15(result.realizedPnL)}`));
2269
2271
  }
2270
2272
  if (result.position.totalAmount > 0) {
2271
- printKeyValue("Remaining", `${formatAssetAmount(result.position.totalAmount, sym)} ${sym} (avg ${formatUsd15(result.position.avgPrice)})`);
2273
+ printKeyValue("Remaining", `${formatAssetAmount4(result.position.totalAmount, sym)} ${sym} (avg ${formatUsd15(result.position.avgPrice)})`);
2272
2274
  }
2273
2275
  printKeyValue("Tx", explorerUrl(result.tx));
2274
2276
  printBlank();
@@ -2294,7 +2296,7 @@ function registerInvest(program2) {
2294
2296
  printSuccess(`${sym} is already fully earning via ${result.protocol} (${result.apy.toFixed(1)}% APY)`);
2295
2297
  } else {
2296
2298
  printSuccess(`${sym} deposited into ${result.protocol} (${result.apy.toFixed(1)}% APY)`);
2297
- printKeyValue("Amount", `${formatAssetAmount(result.amount, sym)} ${sym}`);
2299
+ printKeyValue("Amount", `${formatAssetAmount4(result.amount, sym)} ${sym}`);
2298
2300
  printKeyValue("Protocol", result.protocol);
2299
2301
  printKeyValue("APY", `${result.apy.toFixed(2)}%`);
2300
2302
  printKeyValue("Tx", explorerUrl(result.tx));
@@ -2317,7 +2319,7 @@ function registerInvest(program2) {
2317
2319
  }
2318
2320
  printBlank();
2319
2321
  const sym = asset.toUpperCase();
2320
- printSuccess(`Withdrew ${formatAssetAmount(result.amount, sym)} ${sym} from ${result.protocol}`);
2322
+ printSuccess(`Withdrew ${formatAssetAmount4(result.amount, sym)} ${sym} from ${result.protocol}`);
2321
2323
  printKeyValue("Status", `${sym} remains in investment portfolio (locked)`);
2322
2324
  printKeyValue("Tx", explorerUrl(result.tx));
2323
2325
  printBlank();
@@ -2359,7 +2361,7 @@ function registerInvest(program2) {
2359
2361
  printSeparator();
2360
2362
  for (const m of result.moves) {
2361
2363
  printLine(` ${m.asset}: ${m.fromProtocol} (${m.oldApy.toFixed(2)}%) \u2192 ${m.toProtocol} (${m.newApy.toFixed(2)}%)`);
2362
- printKeyValue("Amount", `${formatAssetAmount(m.amount, m.asset)} ${m.asset}`);
2364
+ printKeyValue("Amount", `${formatAssetAmount4(m.amount, m.asset)} ${m.asset}`);
2363
2365
  printKeyValue("APY gain", `+${(m.newApy - m.oldApy).toFixed(2)}%`);
2364
2366
  if (m.txDigests.length > 0) {
2365
2367
  printKeyValue("Tx", explorerUrl(m.txDigests[m.txDigests.length - 1]));
@@ -2428,7 +2430,7 @@ function registerInvest(program2) {
2428
2430
  printHeader(`Strategy: ${name} \u2014 Dry Run (${formatUsd15(parsed)})`);
2429
2431
  printSeparator();
2430
2432
  for (const buy of result.buys) {
2431
- printKeyValue(buy.asset, `${formatUsd15(buy.usdAmount)} \u2192 ~${formatAssetAmount(buy.amount, buy.asset)} ${buy.asset} @ ${formatUsd15(buy.price)}`);
2433
+ printKeyValue(buy.asset, `${formatUsd15(buy.usdAmount)} \u2192 ~${formatAssetAmount4(buy.amount, buy.asset)} ${buy.asset} @ ${formatUsd15(buy.price)}`);
2432
2434
  }
2433
2435
  printSeparator();
2434
2436
  printInfo("Run without --dry-run to execute");
@@ -2438,7 +2440,7 @@ function registerInvest(program2) {
2438
2440
  printSuccess(`Invested ${formatUsd15(parsed)} in ${name} strategy`);
2439
2441
  printSeparator();
2440
2442
  for (const buy of result.buys) {
2441
- printKeyValue(buy.asset, `${formatAssetAmount(buy.amount, buy.asset)} @ ${formatUsd15(buy.price)}`);
2443
+ printKeyValue(buy.asset, `${formatAssetAmount4(buy.amount, buy.asset)} @ ${formatUsd15(buy.price)}`);
2442
2444
  }
2443
2445
  printSeparator();
2444
2446
  printKeyValue("Total invested", formatUsd15(result.totalInvested));
@@ -2470,7 +2472,7 @@ function registerInvest(program2) {
2470
2472
  for (const sell of result.sells) {
2471
2473
  const pnlColor = sell.realizedPnL >= 0 ? pc13.green : pc13.red;
2472
2474
  const pnlSign = sell.realizedPnL >= 0 ? "+" : "";
2473
- printKeyValue(sell.asset, `${formatAssetAmount(sell.amount, sell.asset)} \u2192 ${formatUsd15(sell.usdValue)} ${pnlColor(`${pnlSign}${formatUsd15(sell.realizedPnL)}`)}`);
2475
+ printKeyValue(sell.asset, `${formatAssetAmount4(sell.amount, sell.asset)} \u2192 ${formatUsd15(sell.usdValue)} ${pnlColor(`${pnlSign}${formatUsd15(sell.realizedPnL)}`)}`);
2474
2476
  }
2475
2477
  if (result.failed && result.failed.length > 0) {
2476
2478
  for (const f of result.failed) {
@@ -2511,7 +2513,7 @@ function registerInvest(program2) {
2511
2513
  const pnlSign = pos.unrealizedPnL >= 0 ? "+" : "";
2512
2514
  printKeyValue(
2513
2515
  pos.asset,
2514
- `${formatAssetAmount(pos.totalAmount, pos.asset)} ${formatUsd15(pos.currentValue)} ${pnlColor(`${pnlSign}${formatUsd15(pos.unrealizedPnL)}`)} ${driftColor(`${actual.toFixed(0)}% / ${target}% target`)}`
2516
+ `${formatAssetAmount4(pos.totalAmount, pos.asset)} ${formatUsd15(pos.currentValue)} ${pnlColor(`${pnlSign}${formatUsd15(pos.unrealizedPnL)}`)} ${driftColor(`${actual.toFixed(0)}% / ${target}% target`)}`
2515
2517
  );
2516
2518
  }
2517
2519
  printSeparator();
@@ -2539,7 +2541,7 @@ function registerInvest(program2) {
2539
2541
  printSeparator();
2540
2542
  for (const t of result.trades) {
2541
2543
  const action = t.action === "buy" ? pc13.green("BUY") : pc13.red("SELL");
2542
- printKeyValue(t.asset, `${action} ${formatUsd15(t.usdAmount)} (${formatAssetAmount(t.amount, t.asset)})`);
2544
+ printKeyValue(t.asset, `${action} ${formatUsd15(t.usdAmount)} (${formatAssetAmount4(t.amount, t.asset)})`);
2543
2545
  }
2544
2546
  printSeparator();
2545
2547
  printInfo("Weights: " + Object.entries(result.afterWeights).map(([a, w]) => `${a} ${w.toFixed(0)}%`).join(", "));
@@ -2738,12 +2740,12 @@ function registerInvest(program2) {
2738
2740
 
2739
2741
  // src/commands/portfolio.ts
2740
2742
  import pc14 from "picocolors";
2741
- import { T2000 as T200025, formatUsd as formatUsd16, formatAssetAmount as formatAssetAmount2 } from "@t2000/sdk";
2743
+ import { T2000 as T200025, formatUsd as formatUsd16, formatAssetAmount as formatAssetAmount5 } from "@t2000/sdk";
2742
2744
  function printPositionLine(pos, rewardKeys) {
2743
2745
  if (pos.currentPrice === 0 && pos.totalAmount > 0) {
2744
2746
  printKeyValue(
2745
2747
  pos.asset,
2746
- `${formatAssetAmount2(pos.totalAmount, pos.asset)} Avg: ${formatUsd16(pos.avgPrice)} Now: ${pc14.yellow("unavailable")}`
2748
+ `${formatAssetAmount5(pos.totalAmount, pos.asset)} Avg: ${formatUsd16(pos.avgPrice)} Now: ${pc14.yellow("unavailable")}`
2747
2749
  );
2748
2750
  } else {
2749
2751
  const pnlColor = pos.unrealizedPnL >= 0 ? pc14.green : pc14.red;
@@ -2756,7 +2758,7 @@ function printPositionLine(pos, rewardKeys) {
2756
2758
  }
2757
2759
  printKeyValue(
2758
2760
  pos.asset,
2759
- `${formatAssetAmount2(pos.totalAmount, pos.asset)} Avg: ${formatUsd16(pos.avgPrice)} Now: ${formatUsd16(pos.currentPrice)} ${pnlColor(`${pnlSign}${formatUsd16(pos.unrealizedPnL)} (${pnlSign}${pos.unrealizedPnLPct.toFixed(1)}%)`)}${yieldSuffix}`
2761
+ `${formatAssetAmount5(pos.totalAmount, pos.asset)} Avg: ${formatUsd16(pos.avgPrice)} Now: ${formatUsd16(pos.currentPrice)} ${pnlColor(`${pnlSign}${formatUsd16(pos.unrealizedPnL)} (${pnlSign}${pos.unrealizedPnLPct.toFixed(1)}%)`)}${yieldSuffix}`
2760
2762
  );
2761
2763
  }
2762
2764
  }