@trustwallet/cli 0.6.8 → 0.6.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"alert.d.ts","sourceRoot":"","sources":["../../src/commands/alert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA6H3D"}
1
+ {"version":3,"file":"alert.d.ts","sourceRoot":"","sources":["../../src/commands/alert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAkBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAuI3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA2f3D"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAshB3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4BpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAmsB5D"}
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA4BpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA+sB5D"}
package/dist/index.js CHANGED
@@ -12606,15 +12606,41 @@ var init_dist5 = __esm({
12606
12606
  query.set("address", params.address);
12607
12607
  if (params.type) query.set("type", params.type);
12608
12608
  if (params.version) query.set("version", params.version.toString());
12609
- return this.client.gateway(
12610
- "GET",
12611
- "/v1/validate",
12612
- void 0,
12613
- query.toString()
12614
- );
12609
+ try {
12610
+ return await this.client.gateway(
12611
+ "GET",
12612
+ "/v1/validate",
12613
+ void 0,
12614
+ query.toString()
12615
+ );
12616
+ } catch (err) {
12617
+ const msg = err instanceof Error ? err.message : String(err);
12618
+ const details = err?.details;
12619
+ const detailsStr = details ? JSON.stringify(details) : "";
12620
+ if (msg.includes("GraphQL") || msg.includes("Failed to decode") || detailsStr.includes("GraphQL") || detailsStr.includes("Failed to decode")) {
12621
+ return { valid: false, message: "Invalid address format" };
12622
+ }
12623
+ throw err;
12624
+ }
12615
12625
  }
12616
12626
  async getAssetInfo(assetId) {
12617
- return this.client.gateway("GET", `/v1/assets/${assetId}`);
12627
+ const info2 = await this.client.gateway("GET", `/v1/assets/${assetId}`);
12628
+ try {
12629
+ const priceResp = await this.client.market(
12630
+ "POST",
12631
+ "/v2/market/tickers",
12632
+ { currency: "USD", assets: [assetId] }
12633
+ );
12634
+ const ticker = priceResp.tickers?.[0];
12635
+ if (ticker) {
12636
+ if (ticker.price != null) info2.priceUsd = ticker.price;
12637
+ if (ticker.change_24h != null) info2.priceChange24h = ticker.change_24h;
12638
+ if (ticker.market_cap != null) info2.marketCapUsd = ticker.market_cap;
12639
+ if (ticker.volume_24h != null) info2.volume24hUsd = ticker.volume_24h;
12640
+ }
12641
+ } catch {
12642
+ }
12643
+ return info2;
12618
12644
  }
12619
12645
  async getTokenHoldings(assets, fromTime = 0) {
12620
12646
  const response = await this.client.gateway("POST", "/v1/assets", {
@@ -12737,7 +12763,15 @@ var init_dist5 = __esm({
12737
12763
  }
12738
12764
  const totalRisks = (security?.contract_security?.num_risks ?? 0) + (security?.honeypot_risk?.num_risks ?? 0);
12739
12765
  const totalWarnings = (security?.contract_security?.num_warnings ?? 0) + (security?.honeypot_risk?.num_warnings ?? 0);
12740
- const riskLevel = totalRisks > 0 ? "high" : totalWarnings > 0 ? "medium" : security ? "low" : void 0;
12766
+ const computedRiskLevel = totalRisks > 0 ? "high" : totalWarnings > 0 ? "medium" : security ? "low" : void 0;
12767
+ let finalRiskLevel = security?.risk_level ?? security?.riskLevel ?? computedRiskLevel;
12768
+ const knownStablecoins = ["USDC", "USDT", "DAI", "BUSD", "TUSD", "USDP", "FRAX", "PYUSD"];
12769
+ const symbol = (asset.symbol ?? raw.symbol ?? "").toUpperCase();
12770
+ let riskContext;
12771
+ if (finalRiskLevel === "medium" && knownStablecoins.includes(symbol) && totalRisks === 0) {
12772
+ riskContext = "Warnings are due to proxy contract pattern, common in audited stablecoins";
12773
+ finalRiskLevel = "low";
12774
+ }
12741
12775
  return {
12742
12776
  assetId,
12743
12777
  name: asset.name ?? raw.name,
@@ -12749,7 +12783,8 @@ var init_dist5 = __esm({
12749
12783
  isHoneypot: isHoneypot ?? security.is_honeypot ?? security.isHoneypot,
12750
12784
  hasAudit: security.has_audit ?? security.hasAudit ?? security.is_scanned,
12751
12785
  auditProvider: security.audit_provider ?? security.auditProvider ?? security.provider,
12752
- riskLevel: security.risk_level ?? security.riskLevel ?? riskLevel,
12786
+ riskLevel: finalRiskLevel,
12787
+ ...riskContext ? { riskContext } : {},
12753
12788
  warnings: warnings.length > 0 ? warnings : security.warnings
12754
12789
  } : void 0,
12755
12790
  solanaSecurityInfo: solanaSecurity ? {
@@ -38862,17 +38897,28 @@ ${qr3}`;
38862
38897
  const kc2 = new KeychainManager();
38863
38898
  const keychainHasPassword = kc2.isAvailable() ? !!await kc2.getWalletPassword() : false;
38864
38899
  const totalChains = Object.keys(CHAINS).length;
38900
+ let createdAt;
38901
+ let addressCount;
38902
+ if (exists) {
38903
+ const config2 = await store.getConfig();
38904
+ createdAt = config2?.createdAt;
38905
+ addressCount = config2?.chains?.length ?? totalChains;
38906
+ }
38865
38907
  const result = {
38866
38908
  agentWallet: exists ? "configured" : "not configured",
38867
38909
  keychainPassword: keychainHasPassword ? "stored" : "not stored",
38868
- chains: totalChains
38910
+ supportedChains: totalChains,
38911
+ ...createdAt ? { createdAt } : {},
38912
+ ...addressCount !== void 0 ? { addressCount } : {}
38869
38913
  };
38870
38914
  if (opts.json) {
38871
38915
  output(result, true);
38872
38916
  } else {
38873
38917
  console.log(` ${import_chalk5.default.dim("Wallet")} ${exists ? import_chalk5.default.green("configured") : import_chalk5.default.yellow("not configured")}`);
38918
+ if (createdAt) console.log(` ${import_chalk5.default.dim("Created")} ${createdAt}`);
38874
38919
  console.log(` ${import_chalk5.default.dim("Keychain")} ${keychainHasPassword ? import_chalk5.default.green("password stored") : import_chalk5.default.yellow("no password")}`);
38875
38920
  console.log(` ${import_chalk5.default.dim("Chains")} ${totalChains} supported`);
38921
+ if (addressCount !== void 0) console.log(` ${import_chalk5.default.dim("Addresses")} ${addressCount}`);
38876
38922
  if (!exists) info("\nRun `twak wallet create --password <pw>` to create a wallet.");
38877
38923
  }
38878
38924
  });
@@ -39102,8 +39148,7 @@ var SwapClient = class {
39102
39148
  return transactions;
39103
39149
  }
39104
39150
  async searchTokens(params) {
39105
- const chains = params.chains || Object.keys(CHAINS);
39106
- const coinIds = chains.map((c3) => getChainById(c3)?.coinId).filter(Boolean).join(",");
39151
+ const coinIds = params.networks ? params.networks : (params.chains || Object.keys(CHAINS)).map((c3) => getChainById(c3)?.coinId).filter((id) => id != null).join(",");
39107
39152
  const queryParams = new URLSearchParams({
39108
39153
  networks: coinIds,
39109
39154
  exactQuery: params.query,
@@ -39726,7 +39771,15 @@ function registerAlertCommand(program3) {
39726
39771
  alert.command("list").description("List all alerts").option("--active", "Show only active alerts").option("--json", "JSON output").action(async (opts) => {
39727
39772
  const alerts = opts.active ? await alertStore.getActive() : await alertStore.list();
39728
39773
  if (opts.json) {
39729
- output(alerts, true);
39774
+ const enriched = alerts.map((a3) => {
39775
+ let chainLabel = a3.chainKey;
39776
+ try {
39777
+ chainLabel = tokenIdToChain(a3.tokenId) ?? a3.chainKey;
39778
+ } catch {
39779
+ }
39780
+ return { ...a3, tokenLabel: resolveTokenLabel(a3.tokenId), chainLabel };
39781
+ });
39782
+ output(enriched, true);
39730
39783
  } else {
39731
39784
  if (alerts.length === 0) {
39732
39785
  info("No alerts found");
@@ -39734,8 +39787,13 @@ function registerAlertCommand(program3) {
39734
39787
  }
39735
39788
  for (const a3 of alerts) {
39736
39789
  const label = resolveTokenLabel(a3.tokenId);
39737
- const chain2 = tokenIdToChain(a3.tokenId);
39738
- const chainHint = chain2 ? ` (${chain2})` : "";
39790
+ let chainHint = "";
39791
+ try {
39792
+ const chain2 = tokenIdToChain(a3.tokenId);
39793
+ chainHint = chain2 ? ` (${chain2})` : "";
39794
+ } catch {
39795
+ chainHint = "";
39796
+ }
39739
39797
  info(`${a3.id} | ${label}${chainHint} | ${a3.condition} $${a3.targetPrice} | ${a3.active ? "active" : "triggered"}`);
39740
39798
  }
39741
39799
  }
@@ -39904,24 +39962,26 @@ function registerQueryCommand(program3) {
39904
39962
  price = results[0].priceUsd;
39905
39963
  }
39906
39964
  }
39965
+ if (price === null) {
39966
+ error(`Token not found: ${token}`);
39967
+ if (opts.json) output({ token: token.toUpperCase(), chain: chain2, priceUsd: null, error: "Token not found" }, true);
39968
+ process.exitCode = 1;
39969
+ return;
39970
+ }
39907
39971
  if (opts.history) {
39908
39972
  const chainInfo = getChainById(chain2);
39909
39973
  if (!chainInfo) throw new Error(`Unknown chain: ${chain2}`);
39910
39974
  const isNative = !tokenInfo.address || tokenInfo.address === NATIVE_TOKEN_ADDRESS || tokenInfo.address === SOLANA_NATIVE_ADDRESS;
39911
39975
  const assetId = isNative ? `c${chainInfo.coinId}` : `c${chainInfo.coinId}_t${tokenInfo.address}`;
39912
- const chartData = await client.market(
39976
+ const chartData = await client.gateway(
39913
39977
  "GET",
39914
- `/v2/market/charts/${encodeURIComponent(assetId)}?currency=USD&period=${opts.history}`
39978
+ `/v1/market/charts/${assetId}`,
39979
+ void 0,
39980
+ `currency=USD&period=${opts.history}`
39915
39981
  );
39916
39982
  output({ token: token.toUpperCase(), chain: chain2, priceUsd: price, history: chartData.prices }, opts.json);
39917
39983
  return;
39918
39984
  }
39919
- if (price === null) {
39920
- error(`Token not found: ${token}`);
39921
- if (opts.json) output({ token: token.toUpperCase(), chain: chain2, priceUsd: null, error: "Token not found" }, true);
39922
- process.exitCode = 1;
39923
- return;
39924
- }
39925
39985
  if (opts.json) {
39926
39986
  output({ token: token.toUpperCase(), chain: chain2, priceUsd: price }, true);
39927
39987
  } else {
@@ -39936,7 +39996,11 @@ function registerQueryCommand(program3) {
39936
39996
  try {
39937
39997
  const client = await getClient();
39938
39998
  const swapClient = new SwapClient(client);
39939
- const result = await swapClient.searchTokens({ query, limit: parseInt(opts.limit, 10) });
39999
+ const result = await swapClient.searchTokens({
40000
+ query,
40001
+ limit: parseInt(opts.limit, 10),
40002
+ ...opts.networks ? { networks: opts.networks } : {}
40003
+ });
39940
40004
  output(result, opts.json);
39941
40005
  } catch (err) {
39942
40006
  handleError(err, opts.json);
@@ -40010,7 +40074,9 @@ function registerQueryCommand(program3) {
40010
40074
  if (opts.json) {
40011
40075
  output(result, true);
40012
40076
  } else if (result.length === 0) {
40013
- info("No transactions found.");
40077
+ const explorer = opts.chain === "ethereum" ? "etherscan.io" : opts.chain === "bsc" ? "bscscan.com" : void 0;
40078
+ const hint = explorer ? ` Check ${explorer} for full history.` : "";
40079
+ info(`No transactions found via API.${hint}`);
40014
40080
  } else {
40015
40081
  output(result, false);
40016
40082
  }
@@ -40065,7 +40131,17 @@ function registerQueryCommand(program3) {
40065
40131
  const coinId = parseInt(opts.coin);
40066
40132
  const chain2 = getChainByCoinId(coinId);
40067
40133
  if (!chain2) throw new Error(`Unknown coin ID: ${coinId}`);
40068
- await ensureTrustSDK();
40134
+ try {
40135
+ await ensureTrustSDK();
40136
+ const { getWalletCore: getWalletCore2, getCoinType: getCoinType2 } = await Promise.resolve().then(() => (init_dist4(), dist_exports2));
40137
+ const wc2 = getWalletCore2();
40138
+ const ct5 = getCoinType2(coinId);
40139
+ if (ct5 && !wc2.CoinTypeExt.validate(ct5, opts.address)) {
40140
+ throw new Error(`Invalid address format for ${chain2.name}`);
40141
+ }
40142
+ } catch (err) {
40143
+ if (err instanceof Error && err.message.startsWith("Invalid address")) throw err;
40144
+ }
40069
40145
  const client = new BlockchainClient();
40070
40146
  const balance = await client.getBalance(`c${coinId}`, opts.address);
40071
40147
  const fmt = (raw) => {
@@ -40114,26 +40190,28 @@ function registerQueryCommand(program3) {
40114
40190
  const wc2 = getWalletCore2();
40115
40191
  const ct5 = getCoinType2(coinId);
40116
40192
  if (ct5) {
40117
- const isValid2 = wc2.AnyAddress.isValid(opts.address, ct5);
40193
+ const isValid2 = wc2.CoinTypeExt.validate(ct5, opts.address);
40118
40194
  if (!isValid2) {
40119
- const result = { status: "error", valid: false, message: `Invalid address format for coin ${coinId}` };
40195
+ const chainInfo = getChainByCoinId(coinId);
40196
+ const label = chainInfo?.name ?? `coin ${coinId}`;
40197
+ const result = { status: "error", valid: false, chain: chainInfo?.id, message: `Invalid address format for ${label}` };
40120
40198
  output(result, opts.json);
40121
40199
  return;
40122
40200
  }
40123
40201
  }
40124
40202
  } catch {
40125
- const isHex = /^0x[0-9a-fA-F]{40}$/.test(opts.address);
40126
- const isEvmCoin = [60, 20000714, 10009e3, 966, 10042221, 10000070, 8453, 137, 250, 10000250, 10000324, 81457, 2e3, 61].includes(coinId);
40127
- if (isEvmCoin && !isHex) {
40128
- output({ status: "error", valid: false, message: `Invalid EVM address format` }, opts.json);
40129
- return;
40130
- }
40131
40203
  }
40132
40204
  }
40133
40205
  const client = await getClient();
40134
40206
  const service = new SecurityService(client);
40135
40207
  const backendResult = await service.validate({ address: opts.address, assetId });
40136
- output(backendResult, opts.json);
40208
+ const chainKey = opts.chain || (assetId ? (() => {
40209
+ const coinIdStr = assetId.replace(/^c/, "").split("_")[0];
40210
+ const coinId = parseInt(coinIdStr, 10);
40211
+ return getChainByCoinId(coinId)?.id;
40212
+ })() : void 0);
40213
+ const enriched = { ...backendResult, ...chainKey ? { chain: chainKey } : {} };
40214
+ output(enriched, opts.json);
40137
40215
  } catch (err) {
40138
40216
  handleError(err, opts.json);
40139
40217
  }
@@ -44345,17 +44423,34 @@ var BalanceActionProvider = class extends ActionProvider {
44345
44423
  getTokenHoldings() {
44346
44424
  return {
44347
44425
  name: "get_token_holdings",
44348
- description: "Get all token holdings for an address",
44426
+ description: "Get ERC-20 token holdings for an address",
44349
44427
  schema: external_exports.object({
44350
44428
  address: external_exports.string().describe("Wallet address"),
44351
44429
  coin: external_exports.coerce.number().describe("SLIP44 coin ID")
44352
44430
  }),
44353
44431
  invoke: async (ctx, input) => {
44354
- return ctx.httpClient.gateway("POST", "/v1/assets", {
44432
+ const response = await ctx.httpClient.gateway("POST", "/v1/assets", {
44355
44433
  version: 2,
44356
44434
  includeDisabledAssets: false,
44357
44435
  assets: [{ address: input.address, coin: input.coin }]
44358
44436
  });
44437
+ const holdings = Array.isArray(response) ? response : response.docs ?? response.data ?? [];
44438
+ const tokens = [];
44439
+ for (const h4 of holdings) {
44440
+ if (Array.isArray(h4.tokens)) {
44441
+ for (const t of h4.tokens) {
44442
+ tokens.push({
44443
+ symbol: t.symbol ?? t.contract,
44444
+ contract: t.contract,
44445
+ decimals: t.decimals ?? 18,
44446
+ balance: t.balance ?? "0",
44447
+ name: t.name,
44448
+ type: t.type
44449
+ });
44450
+ }
44451
+ }
44452
+ }
44453
+ return { address: input.address, coin: input.coin, tokens };
44359
44454
  }
44360
44455
  };
44361
44456
  }
@@ -54257,7 +54352,7 @@ var crypto5 = __toESM(require("crypto"));
54257
54352
  // package.json
54258
54353
  var package_default = {
54259
54354
  name: "@trustwallet/cli",
54260
- version: "0.6.8",
54355
+ version: "0.6.9",
54261
54356
  description: "TWAK CLI \u2014 command-line interface for Trust Wallet Agent Kit",
54262
54357
  main: "dist/index.js",
54263
54358
  types: "dist/index.d.ts",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trustwallet/cli",
3
- "version": "0.6.8",
3
+ "version": "0.6.9",
4
4
  "description": "TWAK CLI — command-line interface for Trust Wallet Agent Kit",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,17 +27,17 @@
27
27
  "ora": "5.4.1",
28
28
  "tsup": "8.5.1",
29
29
  "typescript": "5.7.3",
30
- "@twak/actions": "0.6.8",
31
- "@twak/blockchain": "0.6.8",
32
- "@twak/core": "0.6.8",
33
- "@twak/mcp": "0.6.8",
34
- "@twak/security": "0.6.8",
35
- "@twak/storage": "0.6.8",
36
- "@twak/transactions": "0.6.8",
37
- "@twak/wallet": "0.6.8",
38
- "@twak/wallet-core": "0.6.8",
39
- "@twak/swap": "0.6.8",
40
- "@twak/walletconnect": "0.6.8"
30
+ "@twak/actions": "0.6.9",
31
+ "@twak/blockchain": "0.6.9",
32
+ "@twak/core": "0.6.9",
33
+ "@twak/mcp": "0.6.9",
34
+ "@twak/security": "0.6.9",
35
+ "@twak/storage": "0.6.9",
36
+ "@twak/transactions": "0.6.9",
37
+ "@twak/wallet": "0.6.9",
38
+ "@twak/walletconnect": "0.6.9",
39
+ "@twak/wallet-core": "0.6.9",
40
+ "@twak/swap": "0.6.9"
41
41
  },
42
42
  "publishConfig": {
43
43
  "access": "public"