@t2000/cli 5.4.0 → 5.5.0
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
|
@@ -27808,6 +27808,7 @@ async function buildSendTx({
|
|
|
27808
27808
|
});
|
|
27809
27809
|
return tx;
|
|
27810
27810
|
}
|
|
27811
|
+
init_token_registry();
|
|
27811
27812
|
var SUI_PRICE_FALLBACK = 1;
|
|
27812
27813
|
var _cachedSuiPrice = 0;
|
|
27813
27814
|
var _priceLastFetched = 0;
|
|
@@ -27840,30 +27841,67 @@ async function fetchSuiPrice(client) {
|
|
|
27840
27841
|
}
|
|
27841
27842
|
return _cachedSuiPrice || SUI_PRICE_FALLBACK;
|
|
27842
27843
|
}
|
|
27844
|
+
function safeNorm(coinType) {
|
|
27845
|
+
try {
|
|
27846
|
+
return normalizeStructTag(coinType);
|
|
27847
|
+
} catch {
|
|
27848
|
+
return coinType;
|
|
27849
|
+
}
|
|
27850
|
+
}
|
|
27851
|
+
var SUI_TYPE_NORM = safeNorm(SUPPORTED_ASSETS.SUI.type);
|
|
27852
|
+
var STABLE_BY_NORM = (() => {
|
|
27853
|
+
const m = {};
|
|
27854
|
+
for (const asset of STABLE_ASSETS) m[safeNorm(SUPPORTED_ASSETS[asset].type)] = asset;
|
|
27855
|
+
return m;
|
|
27856
|
+
})();
|
|
27843
27857
|
async function queryBalance(client, address) {
|
|
27844
|
-
const
|
|
27845
|
-
|
|
27846
|
-
|
|
27847
|
-
|
|
27848
|
-
|
|
27849
|
-
|
|
27850
|
-
|
|
27851
|
-
|
|
27858
|
+
const held = [];
|
|
27859
|
+
let cursor;
|
|
27860
|
+
do {
|
|
27861
|
+
const page = await client.core.listBalances({ owner: address, cursor: cursor ?? void 0 });
|
|
27862
|
+
for (const b of page.balances) {
|
|
27863
|
+
const raw = BigInt(b.balance);
|
|
27864
|
+
if (raw > 0n) held.push({ coinType: b.coinType, raw });
|
|
27865
|
+
}
|
|
27866
|
+
cursor = page.hasNextPage ? page.cursor : null;
|
|
27867
|
+
} while (cursor);
|
|
27868
|
+
const suiPriceUsd = await fetchSuiPrice(client);
|
|
27852
27869
|
const stables = {};
|
|
27870
|
+
for (const asset of STABLE_ASSETS) stables[asset] = 0;
|
|
27853
27871
|
let totalStables = 0;
|
|
27854
|
-
|
|
27855
|
-
|
|
27856
|
-
|
|
27872
|
+
let suiAmount = 0;
|
|
27873
|
+
const otherCoins = [];
|
|
27874
|
+
for (const { coinType, raw } of held) {
|
|
27875
|
+
const norm = safeNorm(coinType);
|
|
27876
|
+
if (norm === SUI_TYPE_NORM) {
|
|
27877
|
+
suiAmount = Number(raw) / Number(MIST_PER_SUI);
|
|
27878
|
+
} else if (STABLE_BY_NORM[norm]) {
|
|
27879
|
+
const asset = STABLE_BY_NORM[norm];
|
|
27880
|
+
const amount = Number(raw) / 10 ** SUPPORTED_ASSETS[asset].decimals;
|
|
27881
|
+
stables[asset] = amount;
|
|
27882
|
+
totalStables += amount;
|
|
27883
|
+
} else {
|
|
27884
|
+
otherCoins.push({ coinType, raw });
|
|
27885
|
+
}
|
|
27857
27886
|
}
|
|
27858
|
-
const
|
|
27887
|
+
const tokens = await Promise.all(
|
|
27888
|
+
otherCoins.map(async ({ coinType, raw }) => {
|
|
27889
|
+
const decimals = await resolveCoinDecimals(client, coinType);
|
|
27890
|
+
return {
|
|
27891
|
+
coinType,
|
|
27892
|
+
symbol: resolveSymbol(coinType),
|
|
27893
|
+
amount: Number(raw) / 10 ** decimals,
|
|
27894
|
+
usdValue: null
|
|
27895
|
+
};
|
|
27896
|
+
})
|
|
27897
|
+
);
|
|
27898
|
+
tokens.sort((a, b) => a.symbol.localeCompare(b.symbol));
|
|
27859
27899
|
const suiUsdValue = suiAmount * suiPriceUsd;
|
|
27860
27900
|
return {
|
|
27861
27901
|
stables,
|
|
27862
27902
|
available: totalStables,
|
|
27863
|
-
sui: {
|
|
27864
|
-
|
|
27865
|
-
usdValue: suiUsdValue
|
|
27866
|
-
},
|
|
27903
|
+
sui: { amount: suiAmount, usdValue: suiUsdValue },
|
|
27904
|
+
tokens,
|
|
27867
27905
|
totalUsd: totalStables + suiUsdValue
|
|
27868
27906
|
};
|
|
27869
27907
|
}
|
|
@@ -31333,8 +31371,11 @@ function registerFund(program3) {
|
|
|
31333
31371
|
|
|
31334
31372
|
// src/commands/balance.ts
|
|
31335
31373
|
var import_picocolors3 = __toESM(require_picocolors(), 1);
|
|
31374
|
+
function formatTokenAmount(n) {
|
|
31375
|
+
return n.toLocaleString("en-US", { maximumFractionDigits: 6, useGrouping: false });
|
|
31376
|
+
}
|
|
31336
31377
|
function registerBalance(program3) {
|
|
31337
|
-
program3.command("balance").description("Show
|
|
31378
|
+
program3.command("balance").description("Show all wallet holdings \u2014 USDC / USDsui / SUI (USD-priced) + any other tokens (amount-only)").option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").action(async (opts) => {
|
|
31338
31379
|
try {
|
|
31339
31380
|
const agent = await withAgent({ keyPath: opts.key });
|
|
31340
31381
|
const bal = await agent.balance();
|
|
@@ -31343,6 +31384,7 @@ function registerBalance(program3) {
|
|
|
31343
31384
|
available: bal.available,
|
|
31344
31385
|
stables: bal.stables,
|
|
31345
31386
|
sui: bal.sui,
|
|
31387
|
+
tokens: bal.tokens,
|
|
31346
31388
|
totalUsd: bal.totalUsd
|
|
31347
31389
|
});
|
|
31348
31390
|
return;
|
|
@@ -31358,14 +31400,25 @@ function registerBalance(program3) {
|
|
|
31358
31400
|
printKeyValue(label, formatUsd(amount));
|
|
31359
31401
|
}
|
|
31360
31402
|
}
|
|
31361
|
-
if (bal.sui && bal.sui.
|
|
31403
|
+
if (bal.sui && bal.sui.amount > 0) {
|
|
31362
31404
|
printKeyValue(
|
|
31363
31405
|
"SUI",
|
|
31364
|
-
`${formatUsd(bal.sui.usdValue)} ${import_picocolors3.default.dim(`(${bal.sui.amount.toFixed(4)} SUI \
|
|
31406
|
+
`${formatUsd(bal.sui.usdValue)} ${import_picocolors3.default.dim(`(${bal.sui.amount.toFixed(4)} SUI \xB7 gas)`)}`
|
|
31365
31407
|
);
|
|
31366
31408
|
}
|
|
31409
|
+
const tokens = bal.tokens ?? [];
|
|
31410
|
+
for (const t of tokens) {
|
|
31411
|
+
printKeyValue(t.symbol.padEnd(8), import_picocolors3.default.dim(formatTokenAmount(t.amount)));
|
|
31412
|
+
}
|
|
31367
31413
|
printSeparator();
|
|
31368
|
-
printKeyValue("Wallet total", formatUsd(bal.totalUsd));
|
|
31414
|
+
printKeyValue("Wallet total", `${formatUsd(bal.totalUsd)} ${import_picocolors3.default.dim("(priced holdings)")}`);
|
|
31415
|
+
if (tokens.length > 0) {
|
|
31416
|
+
printLine(
|
|
31417
|
+
import_picocolors3.default.dim(
|
|
31418
|
+
` + ${tokens.length} token${tokens.length === 1 ? "" : "s"} above with no USD price \u2014 not counted in the total`
|
|
31419
|
+
)
|
|
31420
|
+
);
|
|
31421
|
+
}
|
|
31369
31422
|
printBlank();
|
|
31370
31423
|
} catch (error) {
|
|
31371
31424
|
handleError(error);
|
|
@@ -32350,7 +32403,7 @@ function registerMcpStart(parent) {
|
|
|
32350
32403
|
parent.command("start", { isDefault: true }).description("Start MCP server (stdio transport \u2014 for AI client integration)").option("--key <path>", "Custom wallet path (default ~/.t2000/wallet.key)").action(async (opts) => {
|
|
32351
32404
|
let mod2;
|
|
32352
32405
|
try {
|
|
32353
|
-
mod2 = await import("./dist-
|
|
32406
|
+
mod2 = await import("./dist-4JZ33TE5.js");
|
|
32354
32407
|
} catch {
|
|
32355
32408
|
console.error("MCP server not installed. Run:\n npm install -g @t2000/mcp");
|
|
32356
32409
|
process.exit(1);
|