xflows 1.2.0 → 1.3.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.
Files changed (3) hide show
  1. package/README.md +11 -2
  2. package/dist/index.js +77 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -327,6 +327,9 @@ xflows wallet balance --name alice --chain-id 56
327
327
  # Check WAN balance on Wanchain
328
328
  xflows wallet balance --name alice --chain-id 888
329
329
 
330
+ # Check any address (no wallet needed)
331
+ xflows wallet balance --address 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 --chain-id 1
332
+
330
333
  # Encrypted wallet
331
334
  xflows wallet balance --name alice --chain-id 1 --password mypassword
332
335
 
@@ -336,7 +339,8 @@ xflows wallet balance --name alice --chain-id 1 --rpc https://my-rpc.example.com
336
339
 
337
340
  | Flag | Required | Description |
338
341
  |------|----------|-------------|
339
- | `--name <name>` | Yes | Wallet name |
342
+ | `--name <name>` | One of `--name` or `--address` | Wallet name |
343
+ | `--address <addr>` | One of `--name` or `--address` | Query any address (no wallet needed) |
340
344
  | `--chain-id <id>` | Yes | Chain ID to query balance on |
341
345
  | `--password <pw>` | No | Password for encrypted wallets |
342
346
  | `--rpc <url>` | No | Override default RPC endpoint |
@@ -352,6 +356,10 @@ xflows wallet token-balance --name alice --chain-id 1 \
352
356
  xflows wallet token-balance --name alice --chain-id 56 \
353
357
  --token 0x55d398326f99059fF775485246999027B3197955
354
358
 
359
+ # Check any address's USDC balance (no wallet needed)
360
+ xflows wallet token-balance --address 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 \
361
+ --chain-id 1 --token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
362
+
355
363
  # Check with explicit decimals and custom RPC
356
364
  xflows wallet token-balance --name alice --chain-id 1 \
357
365
  --token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 \
@@ -360,7 +368,8 @@ xflows wallet token-balance --name alice --chain-id 1 \
360
368
 
361
369
  | Flag | Required | Description |
362
370
  |------|----------|-------------|
363
- | `--name <name>` | Yes | Wallet name |
371
+ | `--name <name>` | One of `--name` or `--address` | Wallet name |
372
+ | `--address <addr>` | One of `--name` or `--address` | Query any address (no wallet needed) |
364
373
  | `--chain-id <id>` | Yes | Chain ID to query balance on |
365
374
  | `--token <addr>` | Yes | ERC20 token contract address |
366
375
  | `--decimals <n>` | No | Token decimals (auto-detected if omitted) |
package/dist/index.js CHANGED
@@ -5,25 +5,43 @@ var __getProtoOf = Object.getPrototypeOf;
5
5
  var __defProp = Object.defineProperty;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ function __accessProp(key) {
9
+ return this[key];
10
+ }
11
+ var __toESMCache_node;
12
+ var __toESMCache_esm;
8
13
  var __toESM = (mod, isNodeMode, target) => {
14
+ var canCache = mod != null && typeof mod === "object";
15
+ if (canCache) {
16
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
17
+ var cached = cache.get(mod);
18
+ if (cached)
19
+ return cached;
20
+ }
9
21
  target = mod != null ? __create(__getProtoOf(mod)) : {};
10
22
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
23
  for (let key of __getOwnPropNames(mod))
12
24
  if (!__hasOwnProp.call(to, key))
13
25
  __defProp(to, key, {
14
- get: () => mod[key],
26
+ get: __accessProp.bind(mod, key),
15
27
  enumerable: true
16
28
  });
29
+ if (canCache)
30
+ cache.set(mod, to);
17
31
  return to;
18
32
  };
19
33
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
34
+ var __returnValue = (v) => v;
35
+ function __exportSetter(name, newValue) {
36
+ this[name] = __returnValue.bind(null, newValue);
37
+ }
20
38
  var __export = (target, all) => {
21
39
  for (var name in all)
22
40
  __defProp(target, name, {
23
41
  get: all[name],
24
42
  enumerable: true,
25
43
  configurable: true,
26
- set: (newValue) => all[name] = () => newValue
44
+ set: __exportSetter.bind(all, name)
27
45
  });
28
46
  };
29
47
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
@@ -7241,6 +7259,13 @@ function getCreateAddress(tx) {
7241
7259
  function isAddressable(value) {
7242
7260
  return value && typeof value.getAddress === "function";
7243
7261
  }
7262
+ function isAddress(value) {
7263
+ try {
7264
+ getAddress(value);
7265
+ return true;
7266
+ } catch (error) {}
7267
+ return false;
7268
+ }
7244
7269
  async function checkAddress(target, promise) {
7245
7270
  const result = await promise;
7246
7271
  if (result == null || result === "0x0000000000000000000000000000000000000000") {
@@ -17619,7 +17644,6 @@ class Mnemonic {
17619
17644
  return false;
17620
17645
  }
17621
17646
  }
17622
-
17623
17647
  // node_modules/aes-js/lib.esm/aes.js
17624
17648
  /*! MIT License. Copyright 2015-2022 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */
17625
17649
  var __classPrivateFieldGet = function(receiver, state, kind, f2) {
@@ -18660,7 +18684,7 @@ import * as readline from "readline";
18660
18684
  // package.json
18661
18685
  var package_default = {
18662
18686
  name: "xflows",
18663
- version: "1.2.0",
18687
+ version: "1.3.1",
18664
18688
  description: "CLI tool for Wanchain XFlows cross-chain bridge - wallet management, quote queries, and cross-chain transactions",
18665
18689
  type: "module",
18666
18690
  bin: {
@@ -18945,12 +18969,25 @@ walletCmd.command("balance").description(`Check native token balance on a specif
18945
18969
 
18946
18970
  ` + `Examples:
18947
18971
  ` + ` xflows wallet balance --name myWallet --chain-id 1
18948
- ` + " xflows wallet balance --name myWallet --chain-id 56 --password mysecret").requiredOption("--name <name>", "Wallet name").requiredOption("--chain-id <chainId>", "Chain ID to check balance on").option("--password <password>", "Password to decrypt encrypted wallet").option("--rpc <url>", "Custom RPC URL (overrides default)").action(async (opts) => {
18972
+ ` + ` xflows wallet balance --name myWallet --chain-id 56 --password mysecret
18973
+ ` + " xflows wallet balance --address 0x1234...abcd --chain-id 1").option("--name <name>", "Wallet name").option("--address <address>", "Query balance for any address (no wallet needed)").requiredOption("--chain-id <chainId>", "Chain ID to check balance on").option("--password <password>", "Password to decrypt encrypted wallet").option("--rpc <url>", "Custom RPC URL (overrides default)").action(async (opts) => {
18949
18974
  try {
18950
- const wallet = loadWallet(opts.name, opts.password);
18975
+ if (!opts.name && !opts.address) {
18976
+ throw new Error("Please provide either --name or --address");
18977
+ }
18978
+ let targetAddress;
18979
+ if (opts.address) {
18980
+ if (!isAddress(opts.address)) {
18981
+ throw new Error(`Invalid address: ${opts.address}`);
18982
+ }
18983
+ targetAddress = opts.address;
18984
+ } else {
18985
+ const wallet = loadWallet(opts.name, opts.password);
18986
+ targetAddress = wallet.address;
18987
+ }
18951
18988
  const provider = opts.rpc ? new JsonRpcProvider(opts.rpc) : getProvider2(opts.chainId);
18952
- const balance = await provider.getBalance(wallet.address);
18953
- console.log(`Address: ${wallet.address}`);
18989
+ const balance = await provider.getBalance(targetAddress);
18990
+ console.log(`Address: ${targetAddress}`);
18954
18991
  console.log(`Chain: ${opts.chainId}`);
18955
18992
  console.log(`Balance: ${formatUnits(balance, 18)} (native token)`);
18956
18993
  } catch (e) {
@@ -18965,9 +19002,24 @@ walletCmd.command("token-balance").description(`Check ERC20 token balance on a s
18965
19002
  ` + " xflows wallet token-balance --name alice --chain-id 1 \\\n" + ` --token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
18966
19003
 
18967
19004
  ` + ` # Check USDT balance on BSC with explicit decimals
18968
- ` + " xflows wallet token-balance --name alice --chain-id 56 \\\n" + " --token 0x55d398326f99059fF775485246999027B3197955 --decimals 18").requiredOption("--name <name>", "Wallet name").requiredOption("--chain-id <chainId>", "Chain ID to check balance on").requiredOption("--token <address>", "ERC20 token contract address").option("--decimals <decimals>", "Token decimals (auto-detected if omitted)").option("--password <password>", "Password to decrypt encrypted wallet").option("--rpc <url>", "Custom RPC URL (overrides default)").action(async (opts) => {
19005
+ ` + " xflows wallet token-balance --name alice --chain-id 56 \\\n" + ` --token 0x55d398326f99059fF775485246999027B3197955 --decimals 18
19006
+
19007
+ ` + ` # Check any address's USDC balance (no wallet needed)
19008
+ ` + " xflows wallet token-balance --address 0x1234...abcd --chain-id 1 \\\n" + " --token 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48").option("--name <name>", "Wallet name").option("--address <address>", "Query balance for any address (no wallet needed)").requiredOption("--chain-id <chainId>", "Chain ID to check balance on").requiredOption("--token <address>", "ERC20 token contract address").option("--decimals <decimals>", "Token decimals (auto-detected if omitted)").option("--password <password>", "Password to decrypt encrypted wallet").option("--rpc <url>", "Custom RPC URL (overrides default)").action(async (opts) => {
18969
19009
  try {
18970
- const wallet = loadWallet(opts.name, opts.password);
19010
+ if (!opts.name && !opts.address) {
19011
+ throw new Error("Please provide either --name or --address");
19012
+ }
19013
+ let targetAddress;
19014
+ if (opts.address) {
19015
+ if (!isAddress(opts.address)) {
19016
+ throw new Error(`Invalid address: ${opts.address}`);
19017
+ }
19018
+ targetAddress = opts.address;
19019
+ } else {
19020
+ const wallet = loadWallet(opts.name, opts.password);
19021
+ targetAddress = wallet.address;
19022
+ }
18971
19023
  const provider = opts.rpc ? new JsonRpcProvider(opts.rpc) : getProvider2(opts.chainId);
18972
19024
  const tokenContract = new Contract(opts.token, ERC20_ABI, provider);
18973
19025
  let decimals;
@@ -18984,8 +19036,8 @@ walletCmd.command("token-balance").description(`Check ERC20 token balance on a s
18984
19036
  try {
18985
19037
  symbol = await tokenContract.symbol();
18986
19038
  } catch {}
18987
- const balance = await tokenContract.balanceOf(wallet.address);
18988
- console.log(`Address: ${wallet.address}`);
19039
+ const balance = await tokenContract.balanceOf(targetAddress);
19040
+ console.log(`Address: ${targetAddress}`);
18989
19041
  console.log(`Chain: ${opts.chainId}`);
18990
19042
  console.log(`Token: ${opts.token} (${symbol})`);
18991
19043
  console.log(`Balance: ${formatUnits(balance, decimals)}`);
@@ -19171,11 +19223,20 @@ Building transaction...`);
19171
19223
  Checking token approval for ${tx.approvalAddress}...`);
19172
19224
  const tokenContract = new Contract(opts.fromToken, ERC20_ABI, signer);
19173
19225
  const currentAllowance = await tokenContract.allowance(wallet.address, tx.approvalAddress);
19174
- const requiredAmount = BigInt(tx.value || 0) > 0n ? BigInt(tx.value) : parseUnits(opts.amount, 18);
19226
+ const decimals = await tokenContract.decimals();
19227
+ const requiredAmount = parseUnits(opts.amount, decimals);
19175
19228
  if (currentAllowance < requiredAmount) {
19176
- console.log("Approving token spend...");
19177
- const maxApproval = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
19178
- const approveTx = await tokenContract.approve(tx.approvalAddress, maxApproval);
19229
+ console.log(`Approving ${opts.amount} tokens for ${tx.approvalAddress}...`);
19230
+ try {
19231
+ await tokenContract.approve.estimateGas(tx.approvalAddress, requiredAmount);
19232
+ } catch {
19233
+ console.log("Approve estimate failed, resetting allowance to 0 first...");
19234
+ const resetTx = await tokenContract.approve(tx.approvalAddress, 0n);
19235
+ console.log(`Reset tx: ${resetTx.hash}`);
19236
+ await resetTx.wait();
19237
+ console.log("Allowance reset to 0.");
19238
+ }
19239
+ const approveTx = await tokenContract.approve(tx.approvalAddress, requiredAmount);
19179
19240
  console.log(`Approval tx: ${approveTx.hash}`);
19180
19241
  await approveTx.wait();
19181
19242
  console.log("Approval confirmed.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xflows",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "CLI tool for Wanchain XFlows cross-chain bridge - wallet management, quote queries, and cross-chain transactions",
5
5
  "type": "module",
6
6
  "bin": {