xflows 1.3.0 → 1.3.2

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 (2) hide show
  1. package/dist/index.js +38 -11
  2. package/package.json +1 -1
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);
@@ -17626,7 +17644,6 @@ class Mnemonic {
17626
17644
  return false;
17627
17645
  }
17628
17646
  }
17629
-
17630
17647
  // node_modules/aes-js/lib.esm/aes.js
17631
17648
  /*! MIT License. Copyright 2015-2022 Richard Moore <me@ricmoo.com>. See LICENSE.txt. */
17632
17649
  var __classPrivateFieldGet = function(receiver, state, kind, f2) {
@@ -18667,7 +18684,7 @@ import * as readline from "readline";
18667
18684
  // package.json
18668
18685
  var package_default = {
18669
18686
  name: "xflows",
18670
- version: "1.3.0",
18687
+ version: "1.3.2",
18671
18688
  description: "CLI tool for Wanchain XFlows cross-chain bridge - wallet management, quote queries, and cross-chain transactions",
18672
18689
  type: "module",
18673
18690
  bin: {
@@ -19201,16 +19218,26 @@ Building transaction...`);
19201
19218
  process.exit(1);
19202
19219
  }
19203
19220
  const NATIVE_ADDRESS = "0x0000000000000000000000000000000000000000";
19204
- if (opts.fromToken.toLowerCase() !== NATIVE_ADDRESS && tx.approvalAddress) {
19221
+ const spender = tx.approvalAddress || tx.to;
19222
+ if (opts.fromToken.toLowerCase() !== NATIVE_ADDRESS && spender) {
19205
19223
  console.log(`
19206
- Checking token approval for ${tx.approvalAddress}...`);
19224
+ Checking token approval for ${spender}...`);
19207
19225
  const tokenContract = new Contract(opts.fromToken, ERC20_ABI, signer);
19208
- const currentAllowance = await tokenContract.allowance(wallet.address, tx.approvalAddress);
19209
- const requiredAmount = BigInt(tx.value || 0) > 0n ? BigInt(tx.value) : parseUnits(opts.amount, 18);
19226
+ const currentAllowance = await tokenContract.allowance(wallet.address, spender);
19227
+ const decimals = await tokenContract.decimals();
19228
+ const requiredAmount = parseUnits(opts.amount, decimals);
19210
19229
  if (currentAllowance < requiredAmount) {
19211
- console.log("Approving token spend...");
19212
- const maxApproval = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
19213
- const approveTx = await tokenContract.approve(tx.approvalAddress, maxApproval);
19230
+ console.log(`Approving ${opts.amount} tokens for ${spender}...`);
19231
+ try {
19232
+ await tokenContract.approve.estimateGas(spender, requiredAmount);
19233
+ } catch {
19234
+ console.log("Approve estimate failed, resetting allowance to 0 first...");
19235
+ const resetTx = await tokenContract.approve(spender, 0n);
19236
+ console.log(`Reset tx: ${resetTx.hash}`);
19237
+ await resetTx.wait();
19238
+ console.log("Allowance reset to 0.");
19239
+ }
19240
+ const approveTx = await tokenContract.approve(spender, requiredAmount);
19214
19241
  console.log(`Approval tx: ${approveTx.hash}`);
19215
19242
  await approveTx.wait();
19216
19243
  console.log("Approval confirmed.");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xflows",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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": {