xflows 1.3.1 → 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.
- package/dist/index.js +9 -8
- 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.
|
|
18687
|
+
version: "1.3.2",
|
|
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: {
|
|
@@ -19218,25 +19218,26 @@ Building transaction...`);
|
|
|
19218
19218
|
process.exit(1);
|
|
19219
19219
|
}
|
|
19220
19220
|
const NATIVE_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
19221
|
-
|
|
19221
|
+
const spender = tx.approvalAddress || tx.to;
|
|
19222
|
+
if (opts.fromToken.toLowerCase() !== NATIVE_ADDRESS && spender) {
|
|
19222
19223
|
console.log(`
|
|
19223
|
-
Checking token approval for ${
|
|
19224
|
+
Checking token approval for ${spender}...`);
|
|
19224
19225
|
const tokenContract = new Contract(opts.fromToken, ERC20_ABI, signer);
|
|
19225
|
-
const currentAllowance = await tokenContract.allowance(wallet.address,
|
|
19226
|
+
const currentAllowance = await tokenContract.allowance(wallet.address, spender);
|
|
19226
19227
|
const decimals = await tokenContract.decimals();
|
|
19227
19228
|
const requiredAmount = parseUnits(opts.amount, decimals);
|
|
19228
19229
|
if (currentAllowance < requiredAmount) {
|
|
19229
|
-
console.log(`Approving ${opts.amount} tokens for ${
|
|
19230
|
+
console.log(`Approving ${opts.amount} tokens for ${spender}...`);
|
|
19230
19231
|
try {
|
|
19231
|
-
await tokenContract.approve.estimateGas(
|
|
19232
|
+
await tokenContract.approve.estimateGas(spender, requiredAmount);
|
|
19232
19233
|
} catch {
|
|
19233
19234
|
console.log("Approve estimate failed, resetting allowance to 0 first...");
|
|
19234
|
-
const resetTx = await tokenContract.approve(
|
|
19235
|
+
const resetTx = await tokenContract.approve(spender, 0n);
|
|
19235
19236
|
console.log(`Reset tx: ${resetTx.hash}`);
|
|
19236
19237
|
await resetTx.wait();
|
|
19237
19238
|
console.log("Allowance reset to 0.");
|
|
19238
19239
|
}
|
|
19239
|
-
const approveTx = await tokenContract.approve(
|
|
19240
|
+
const approveTx = await tokenContract.approve(spender, requiredAmount);
|
|
19240
19241
|
console.log(`Approval tx: ${approveTx.hash}`);
|
|
19241
19242
|
await approveTx.wait();
|
|
19242
19243
|
console.log("Approval confirmed.");
|