xflows 1.3.1 → 1.3.3

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 +35 -11
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -18684,7 +18684,7 @@ import * as readline from "readline";
18684
18684
  // package.json
18685
18685
  var package_default = {
18686
18686
  name: "xflows",
18687
- version: "1.3.1",
18687
+ version: "1.3.3",
18688
18688
  description: "CLI tool for Wanchain XFlows cross-chain bridge - wallet management, quote queries, and cross-chain transactions",
18689
18689
  type: "module",
18690
18690
  bin: {
@@ -19193,13 +19193,19 @@ program2.command("send").description(`Build and send a cross-chain transaction
19193
19193
  if (quote.nativeFees?.length) {
19194
19194
  console.log(`Native fees:`);
19195
19195
  for (const f2 of quote.nativeFees) {
19196
- console.log(` ${f2.amount} ${f2.symbol}`);
19196
+ const amount = f2.nativeFeeAmount ?? f2.amount;
19197
+ const symbol = f2.nativeFeeSymbol ?? f2.symbol;
19198
+ const decimals = f2.nativeFeeDecimals ?? f2.decimals ?? 18;
19199
+ console.log(` ${formatUnits(amount, decimals)} ${symbol}`);
19197
19200
  }
19198
19201
  }
19199
19202
  if (quote.tokenFees?.length) {
19200
19203
  console.log(`Token fees:`);
19201
19204
  for (const f2 of quote.tokenFees) {
19202
- console.log(` ${f2.amount} ${f2.symbol}`);
19205
+ const amount = f2.tokenFeeAmount ?? f2.amount;
19206
+ const symbol = f2.tokenFeeSymbol ?? f2.symbol;
19207
+ const decimals = f2.tokenFeeDecimals ?? f2.decimals ?? 18;
19208
+ console.log(` ${formatUnits(amount, decimals)} ${symbol}`);
19203
19209
  }
19204
19210
  }
19205
19211
  console.log(`
@@ -19218,25 +19224,26 @@ Building transaction...`);
19218
19224
  process.exit(1);
19219
19225
  }
19220
19226
  const NATIVE_ADDRESS = "0x0000000000000000000000000000000000000000";
19221
- if (opts.fromToken.toLowerCase() !== NATIVE_ADDRESS && tx.approvalAddress) {
19227
+ const spender = tx.approvalAddress || tx.to;
19228
+ if (opts.fromToken.toLowerCase() !== NATIVE_ADDRESS && spender) {
19222
19229
  console.log(`
19223
- Checking token approval for ${tx.approvalAddress}...`);
19230
+ Checking token approval for ${spender}...`);
19224
19231
  const tokenContract = new Contract(opts.fromToken, ERC20_ABI, signer);
19225
- const currentAllowance = await tokenContract.allowance(wallet.address, tx.approvalAddress);
19232
+ const currentAllowance = await tokenContract.allowance(wallet.address, spender);
19226
19233
  const decimals = await tokenContract.decimals();
19227
19234
  const requiredAmount = parseUnits(opts.amount, decimals);
19228
19235
  if (currentAllowance < requiredAmount) {
19229
- console.log(`Approving ${opts.amount} tokens for ${tx.approvalAddress}...`);
19236
+ console.log(`Approving ${opts.amount} tokens for ${spender}...`);
19230
19237
  try {
19231
- await tokenContract.approve.estimateGas(tx.approvalAddress, requiredAmount);
19238
+ await tokenContract.approve.estimateGas(spender, requiredAmount);
19232
19239
  } catch {
19233
19240
  console.log("Approve estimate failed, resetting allowance to 0 first...");
19234
- const resetTx = await tokenContract.approve(tx.approvalAddress, 0n);
19241
+ const resetTx = await tokenContract.approve(spender, 0n);
19235
19242
  console.log(`Reset tx: ${resetTx.hash}`);
19236
19243
  await resetTx.wait();
19237
19244
  console.log("Allowance reset to 0.");
19238
19245
  }
19239
- const approveTx = await tokenContract.approve(tx.approvalAddress, requiredAmount);
19246
+ const approveTx = await tokenContract.approve(spender, requiredAmount);
19240
19247
  console.log(`Approval tx: ${approveTx.hash}`);
19241
19248
  await approveTx.wait();
19242
19249
  console.log("Approval confirmed.");
@@ -19272,7 +19279,24 @@ Checking token approval for ${tx.approvalAddress}...`);
19272
19279
  return;
19273
19280
  }
19274
19281
  console.log(`
19275
- Sending transaction...`);
19282
+ Estimating gas...`);
19283
+ try {
19284
+ const estimatedGas = await provider.estimateGas({
19285
+ ...txRequest,
19286
+ from: wallet.address
19287
+ });
19288
+ if (!txRequest.gasLimit) {
19289
+ txRequest.gasLimit = estimatedGas * 120n / 100n;
19290
+ }
19291
+ console.log(`Estimated gas: ${estimatedGas.toString()}`);
19292
+ } catch (err) {
19293
+ const reason = err.reason || err.shortMessage || err.message;
19294
+ console.error(`
19295
+ Transaction will fail: ${reason}`);
19296
+ console.error("The transaction was NOT sent.");
19297
+ process.exit(1);
19298
+ }
19299
+ console.log("Sending transaction...");
19276
19300
  const sentTx = await signer.sendTransaction(txRequest);
19277
19301
  console.log(`Transaction hash: ${sentTx.hash}`);
19278
19302
  console.log("Waiting for confirmation...");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xflows",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
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": {