btc-wallet 0.5.19-beta → 0.5.21-beta

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 CHANGED
@@ -24,6 +24,18 @@ var __spreadValues = (a, b) => {
24
24
  return a;
25
25
  };
26
26
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ var __objRest = (source, exclude) => {
28
+ var target = {};
29
+ for (var prop in source)
30
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
31
+ target[prop] = source[prop];
32
+ if (source != null && __getOwnPropSymbols)
33
+ for (var prop of __getOwnPropSymbols(source)) {
34
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
35
+ target[prop] = source[prop];
36
+ }
37
+ return target;
38
+ };
27
39
  var __export = (target, all) => {
28
40
  for (var name in all)
29
41
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -3013,7 +3025,6 @@ function request(url, options) {
3013
3025
  }
3014
3026
  return data;
3015
3027
  } catch (err) {
3016
- console.error(err);
3017
3028
  if (retryCount > 0) {
3018
3029
  console.log(`Retrying... attempts left: ${retryCount}`);
3019
3030
  return request(url, __spreadProps(__spreadValues({}, options), { retryCount: retryCount - 1 }));
@@ -3027,6 +3038,7 @@ function request(url, options) {
3027
3038
  }));
3028
3039
  }
3029
3040
  }
3041
+ console.error(err);
3030
3042
  return Promise.reject(err);
3031
3043
  }
3032
3044
  });
@@ -3199,6 +3211,7 @@ var state_default = {
3199
3211
  };
3200
3212
 
3201
3213
  // src/utils/satoshi.ts
3214
+ var import_coinselect = __toESM(require("coinselect"), 1);
3202
3215
  function getNonce(url, accountId) {
3203
3216
  return __async(this, null, function* () {
3204
3217
  const { result_code, result_message, result_data } = yield request(
@@ -3276,12 +3289,13 @@ function checkBridgeTransactionStatus(url, txHash) {
3276
3289
  maxPollingAttempts: 60,
3277
3290
  shouldStopPolling: (res) => {
3278
3291
  var _a;
3279
- return res.result_code === 0 && [4, 102].includes(((_a = res.result_data) == null ? void 0 : _a.Status) || 0);
3292
+ const status = ((_a = res.result_data) == null ? void 0 : _a.Status) || 0;
3293
+ return res.result_code === 0 && (status === 4 || status >= 50);
3280
3294
  }
3281
3295
  });
3282
3296
  console.log("checkTransactionStatus resp:", { result_code, result_message, result_data });
3283
3297
  if ((result_data == null ? void 0 : result_data.Status) !== 4) {
3284
- throw new Error(result_message);
3298
+ throw new Error(result_message || `Transaction failed, status: ${result_data == null ? void 0 : result_data.Status}`);
3285
3299
  }
3286
3300
  return result_data;
3287
3301
  });
@@ -3294,12 +3308,13 @@ function checkBtcTransactionStatus(url, sig) {
3294
3308
  maxPollingAttempts: 60,
3295
3309
  shouldStopPolling: (res) => {
3296
3310
  var _a;
3297
- return res.result_code === 0 && [3, 101, 102].includes(((_a = res.result_data) == null ? void 0 : _a.Status) || 0);
3311
+ const status = ((_a = res.result_data) == null ? void 0 : _a.Status) || 0;
3312
+ return res.result_code === 0 && (status === 3 || status >= 10);
3298
3313
  }
3299
3314
  });
3300
3315
  console.log("checkBtcTransactionStatus resp:", { result_code, result_message, result_data });
3301
3316
  if ((result_data == null ? void 0 : result_data.Status) !== 3) {
3302
- throw new Error(result_message);
3317
+ throw new Error(result_message || `Transaction failed, status: ${result_data == null ? void 0 : result_data.Status}`);
3303
3318
  }
3304
3319
  return result_data;
3305
3320
  });
@@ -3326,10 +3341,16 @@ function getAccountInfo(_0) {
3326
3341
  ).catch((error) => {
3327
3342
  return void 0;
3328
3343
  });
3329
- console.log("get_account accountInfo:", accountInfo);
3330
3344
  return accountInfo;
3331
3345
  });
3332
3346
  }
3347
+ function getBridgeConfig(_0) {
3348
+ return __async(this, arguments, function* ({ env }) {
3349
+ const config = getWalletConfig(env);
3350
+ const bridgeConfig = yield nearCallFunction(config.bridgeContractId, "get_config", {}, { network: config.network });
3351
+ return bridgeConfig;
3352
+ });
3353
+ }
3333
3354
  function getTokenBalance(_0) {
3334
3355
  return __async(this, arguments, function* ({
3335
3356
  csna,
@@ -3628,11 +3649,196 @@ function getPredictedGasAmount(_0) {
3628
3649
  return gasAmount.toString();
3629
3650
  });
3630
3651
  }
3652
+ function calculateWithdraw(_0) {
3653
+ return __async(this, arguments, function* ({
3654
+ amount,
3655
+ feeRate,
3656
+ csna,
3657
+ btcAddress,
3658
+ env
3659
+ }) {
3660
+ console.log("calculateWithdraw feeRate:", feeRate);
3661
+ try {
3662
+ const config = getWalletConfig(env);
3663
+ const gasLimit = yield calculateGasLimit({
3664
+ csna,
3665
+ transactions: [
3666
+ {
3667
+ signerId: "",
3668
+ receiverId: config.btcToken,
3669
+ actions: [
3670
+ {
3671
+ type: "FunctionCall",
3672
+ params: {
3673
+ methodName: "ft_transfer_call",
3674
+ args: {
3675
+ receiver_id: config.btcToken,
3676
+ amount: "100",
3677
+ msg: ""
3678
+ },
3679
+ gas: "300000000000000",
3680
+ deposit: "1"
3681
+ }
3682
+ }
3683
+ ]
3684
+ }
3685
+ ],
3686
+ env
3687
+ });
3688
+ let satoshis = Number(amount);
3689
+ if (Number(gasLimit) > 0) {
3690
+ satoshis = new import_big.default(amount).minus(gasLimit).toNumber();
3691
+ }
3692
+ const brgConfig = yield getBridgeConfig({ env });
3693
+ const allUTXO = yield nearCallFunction(config.bridgeContractId, "get_utxos_paged", {}, { network: config.network });
3694
+ if (brgConfig.min_withdraw_amount) {
3695
+ if (Number(satoshis) < Number(brgConfig.min_withdraw_amount)) {
3696
+ return {
3697
+ withdrawFee: 0,
3698
+ isError: true,
3699
+ errorMsg: "Mini withdraw amount is " + (Number(brgConfig.min_withdraw_amount) + Number(gasLimit))
3700
+ };
3701
+ }
3702
+ }
3703
+ const feePercent = Number(brgConfig.withdraw_bridge_fee.fee_rate) * Number(satoshis);
3704
+ const withdrawFee = feePercent > Number(brgConfig.withdraw_bridge_fee.fee_min) ? feePercent : Number(brgConfig.withdraw_bridge_fee.fee_min);
3705
+ const withdrawChangeAddress = brgConfig.change_address;
3706
+ const utxos = Object.keys(allUTXO).map((key) => {
3707
+ const txid = key.split("@");
3708
+ return {
3709
+ txid: txid[0],
3710
+ vout: allUTXO[key].vout,
3711
+ value: Number(allUTXO[key].balance),
3712
+ script: allUTXO[key].script
3713
+ };
3714
+ }).filter((utxo) => utxo.value > Number(brgConfig.min_change_amount));
3715
+ if (!utxos || utxos.length === 0) {
3716
+ return {
3717
+ withdrawFee,
3718
+ isError: true,
3719
+ errorMsg: "The network is busy, please try again later."
3720
+ };
3721
+ }
3722
+ const userSatoshis = Number(satoshis);
3723
+ const maxBtcFee = Number(brgConfig.max_btc_gas_fee);
3724
+ const { inputs, outputs, fee } = (0, import_coinselect.default)(
3725
+ utxos,
3726
+ [{ address: btcAddress, value: userSatoshis }],
3727
+ Math.ceil(feeRate || 0)
3728
+ );
3729
+ const newInputs = inputs;
3730
+ let newOutputs = outputs;
3731
+ let newFee = fee;
3732
+ if (!newOutputs || newOutputs.length === 0) {
3733
+ return {
3734
+ withdrawFee,
3735
+ isError: true,
3736
+ errorMsg: "The network is busy, please try again later."
3737
+ };
3738
+ }
3739
+ let userOutput, noUserOutput;
3740
+ for (let i = 0; i < newOutputs.length; i++) {
3741
+ const output = newOutputs[i];
3742
+ if (output.value.toString() === userSatoshis.toString()) {
3743
+ userOutput = output;
3744
+ } else {
3745
+ noUserOutput = output;
3746
+ }
3747
+ if (!output.address) {
3748
+ output.address = withdrawChangeAddress;
3749
+ }
3750
+ }
3751
+ let dis = 0;
3752
+ if (newFee > maxBtcFee) {
3753
+ dis = newFee - maxBtcFee;
3754
+ newFee = maxBtcFee;
3755
+ return {
3756
+ gasFee: newFee,
3757
+ withdrawFee,
3758
+ isError: true,
3759
+ errorMsg: "Gas exceeds maximum value"
3760
+ };
3761
+ }
3762
+ userOutput.value = new import_big.default(userOutput.value).minus(newFee).minus(withdrawFee).toNumber();
3763
+ if (userOutput.value < 0) {
3764
+ return {
3765
+ gasFee: newFee,
3766
+ withdrawFee,
3767
+ isError: true,
3768
+ errorMsg: "Not enough gas"
3769
+ };
3770
+ }
3771
+ if (noUserOutput) {
3772
+ if (!noUserOutput.address) {
3773
+ noUserOutput.address = withdrawChangeAddress;
3774
+ }
3775
+ noUserOutput.value = new import_big.default(noUserOutput.value).plus(newFee).plus(withdrawFee).plus(dis).toNumber();
3776
+ } else {
3777
+ noUserOutput = {
3778
+ address: withdrawChangeAddress,
3779
+ value: new import_big.default(newFee).plus(withdrawFee).plus(dis).toNumber()
3780
+ };
3781
+ newOutputs.push(noUserOutput);
3782
+ }
3783
+ let minValue = Math.min(...newInputs.map((input) => input.value));
3784
+ let totalNoUserOutputValue = noUserOutput.value;
3785
+ while (totalNoUserOutputValue >= minValue && minValue > 0 && newInputs.length > 0) {
3786
+ totalNoUserOutputValue -= minValue;
3787
+ noUserOutput.value = totalNoUserOutputValue;
3788
+ const minValueIndex = newInputs.findIndex((input) => input.value === minValue);
3789
+ if (minValueIndex > -1) {
3790
+ newInputs.splice(minValueIndex, 1);
3791
+ }
3792
+ minValue = Math.min(...newInputs.map((input) => input.value));
3793
+ }
3794
+ let gasMore = 0;
3795
+ if (noUserOutput.value === 0) {
3796
+ newOutputs = newOutputs.filter((item) => item.value !== 0);
3797
+ } else if (noUserOutput.value < Number(brgConfig.min_change_amount)) {
3798
+ gasMore = Number(brgConfig.min_change_amount) - noUserOutput.value;
3799
+ userOutput.value -= gasMore;
3800
+ noUserOutput.value = Number(brgConfig.min_change_amount);
3801
+ }
3802
+ const insufficientOutput = newOutputs.some((item) => item.value < 0);
3803
+ if (insufficientOutput) {
3804
+ return {
3805
+ gasFee: newFee,
3806
+ withdrawFee,
3807
+ isError: true,
3808
+ errorMsg: "Not enough gas"
3809
+ };
3810
+ }
3811
+ const inputSum = newInputs.reduce((sum, cur) => sum + Number(cur.value), 0);
3812
+ const outputSum = newOutputs.reduce((sum, cur) => sum + Number(cur.value), 0);
3813
+ if (newFee + outputSum !== inputSum) {
3814
+ return {
3815
+ withdrawFee,
3816
+ isError: true,
3817
+ errorMsg: "Service busy, please try again later"
3818
+ };
3819
+ }
3820
+ return {
3821
+ withdrawFee: new import_big.default(withdrawFee).plus(gasLimit).plus(gasMore).toNumber(),
3822
+ gasFee: new import_big.default(newFee).toNumber(),
3823
+ inputs: newInputs,
3824
+ outputs: newOutputs,
3825
+ fromAmount: satoshis,
3826
+ receiveAmount: userOutput.value,
3827
+ isError: false
3828
+ };
3829
+ } catch (error) {
3830
+ return {
3831
+ withdrawFee: 0,
3832
+ isError: true,
3833
+ errorMsg: error.message
3834
+ };
3835
+ }
3836
+ });
3837
+ }
3631
3838
 
3632
3839
  // src/core/btcUtils.ts
3633
3840
  var import_bitcoinjs_lib = __toESM(require("bitcoinjs-lib"), 1);
3634
3841
  var ecc = __toESM(require("@bitcoinerlab/secp256k1"), 1);
3635
- var import_coinselect = __toESM(require("coinselect"), 1);
3636
3842
  import_bitcoinjs_lib.default.initEccLib(ecc);
3637
3843
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3638
3844
  var NBTC_STORAGE_DEPOSIT_AMOUNT = "3000";
@@ -3756,7 +3962,6 @@ function getDepositAmount(amount, option) {
3756
3962
  var _a;
3757
3963
  const env = (option == null ? void 0 : option.env) || "mainnet";
3758
3964
  const _newAccountMinDepositAmount = (_a = option == null ? void 0 : option.newAccountMinDepositAmount) != null ? _a : true;
3759
- const config = getWalletConfig(env);
3760
3965
  const csna = yield getCsnaAccountId(env);
3761
3966
  const accountInfo = yield getAccountInfo({ csna, env });
3762
3967
  const debtAction = yield checkGasTokenDebt(csna, env, false);
@@ -3764,7 +3969,7 @@ function getDepositAmount(amount, option) {
3764
3969
  const {
3765
3970
  deposit_bridge_fee: { fee_min, fee_rate },
3766
3971
  min_deposit_amount
3767
- } = yield nearCall(config.bridgeContractId, "get_config", {});
3972
+ } = yield getBridgeConfig({ env });
3768
3973
  const depositAmount = Math.max(Number(min_deposit_amount), Number(amount));
3769
3974
  const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3770
3975
  const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
@@ -3956,190 +4161,52 @@ function getWithdrawTransaction(_0) {
3956
4161
  feeRate,
3957
4162
  env = "mainnet"
3958
4163
  }) {
3959
- console.log("=== Start getWithdrawTransaction ===");
4164
+ const config = getWalletConfig(env);
3960
4165
  const provider = getBtcProvider();
3961
4166
  const btcAddress = provider.account;
3962
- const config = getWalletConfig(env);
3963
4167
  const csna = yield getCsnaAccountId(env);
3964
- const brgConfig = yield nearCall(config.bridgeContractId, "get_config", {});
3965
- if (brgConfig.min_withdraw_amount) {
3966
- if (Number(amount) < Number(brgConfig.min_withdraw_amount)) {
3967
- throw new Error("Mini withdraw amount is " + brgConfig.min_withdraw_amount);
3968
- }
3969
- }
3970
- const feePercent = Number(brgConfig.withdraw_bridge_fee.fee_rate) * Number(amount);
3971
- const withdrawFee = feePercent > Number(brgConfig.withdraw_bridge_fee.fee_min) ? feePercent : Number(brgConfig.withdraw_bridge_fee.fee_min);
3972
- console.log("Withdrawal Fee:", {
3973
- feePercent,
3974
- withdrawFee,
3975
- minFee: brgConfig.withdraw_bridge_fee.fee_min
3976
- });
3977
- const gasLimit = yield calculateGasLimit({
4168
+ const _feeRate = feeRate || (yield getBtcGasPrice());
4169
+ const _a = yield calculateWithdraw({
4170
+ amount,
4171
+ feeRate: _feeRate,
3978
4172
  csna,
3979
- transactions: [
3980
- {
3981
- signerId: "",
3982
- receiverId: config.btcToken,
3983
- actions: [
3984
- {
3985
- type: "FunctionCall",
3986
- params: {
3987
- methodName: "ft_transfer_call",
3988
- args: {
3989
- receiver_id: config.btcToken,
3990
- amount: "100",
3991
- msg: ""
3992
- },
3993
- gas: "300000000000000",
3994
- deposit: "1"
3995
- }
3996
- }
3997
- ]
3998
- }
3999
- ],
4173
+ btcAddress,
4000
4174
  env
4001
- });
4002
- const finalAmount = Number(gasLimit) > 0 ? Number(amount) - Number(gasLimit) : Number(amount);
4003
- const allUTXO = yield nearCall(config.bridgeContractId, "get_utxos_paged", {});
4004
- console.log("All UTXOs:", allUTXO);
4005
- if (!allUTXO || Object.keys(allUTXO).length === 0) {
4006
- throw new Error("The network is busy, please try again later.");
4175
+ }), { inputs, outputs, isError, errorMsg } = _a, rest = __objRest(_a, ["inputs", "outputs", "isError", "errorMsg"]);
4176
+ if (isError || !inputs || !outputs) {
4177
+ throw new Error(errorMsg);
4007
4178
  }
4008
- const utxos = Object.keys(allUTXO).map((key) => {
4009
- const txid = key.split("@");
4010
- return {
4011
- txid: txid[0],
4012
- vout: allUTXO[key].vout,
4013
- value: Number(allUTXO[key].balance),
4014
- script: allUTXO[key].script
4015
- };
4016
- });
4017
- console.log("Formatted UTXOs:", utxos);
4018
- const _feeRate = feeRate || (yield getBtcGasPrice());
4019
- console.log("Fee Rate:", _feeRate);
4020
- const coinSelectResult = (0, import_coinselect.default)(
4021
- utxos,
4022
- [{ address: btcAddress, value: Number(finalAmount) }],
4023
- Math.ceil(_feeRate)
4179
+ console.log("inputs:", JSON.stringify(inputs));
4180
+ console.log("outputs:", JSON.stringify(outputs));
4181
+ console.log("inputs - outputs = gas");
4182
+ console.log(
4183
+ `(${inputs.map((item) => item.value).join(" + ")}) - (${outputs.map((item) => item.value).join(" + ")}) = ${rest.gasFee}`
4024
4184
  );
4025
- console.log("Coinselect Result:", coinSelectResult);
4026
- const { inputs, outputs, fee } = coinSelectResult;
4027
- if (!outputs || !inputs) {
4028
- throw new Error("The network is busy, please try again later.");
4029
- }
4030
- const maxBtcFee = Number(brgConfig.max_btc_gas_fee);
4031
- const transactionFee = fee;
4032
- console.log("Transaction Fee:", { transactionFee, maxBtcFee });
4033
- if (transactionFee > maxBtcFee) {
4034
- throw new Error("Gas exceeds maximum value");
4035
- }
4036
- let recipientOutput, changeOutput;
4037
- for (let i = 0; i < outputs.length; i++) {
4038
- const output = outputs[i];
4039
- if (output.value.toString() === finalAmount.toString()) {
4040
- recipientOutput = output;
4041
- } else {
4042
- changeOutput = output;
4043
- }
4044
- if (!output.address) {
4045
- output.address = brgConfig.change_address;
4046
- }
4047
- }
4048
- console.log("Initial Outputs:", { recipientOutput, changeOutput });
4049
- recipientOutput.value = new import_big2.default(recipientOutput.value).minus(transactionFee).minus(withdrawFee).toNumber();
4050
- if (changeOutput) {
4051
- changeOutput.value = new import_big2.default(changeOutput.value).plus(transactionFee).plus(withdrawFee).toNumber();
4052
- const remainingInputs = [...inputs];
4053
- let smallestInput = Math.min.apply(
4054
- null,
4055
- remainingInputs.map((input) => input.value)
4056
- );
4057
- let remainingChangeAmount = changeOutput.value;
4058
- console.log("Initial Change Processing:", { smallestInput, remainingChangeAmount });
4059
- while (remainingChangeAmount >= smallestInput && smallestInput > 0 && remainingInputs.length > 0) {
4060
- remainingChangeAmount -= smallestInput;
4061
- changeOutput.value = remainingChangeAmount;
4062
- const smallestInputIndex = remainingInputs.findIndex(
4063
- (input) => input.value === smallestInput
4064
- );
4065
- if (smallestInputIndex > -1) {
4066
- remainingInputs.splice(smallestInputIndex, 1);
4067
- }
4068
- smallestInput = Math.min.apply(
4069
- null,
4070
- remainingInputs.map((input) => input.value)
4071
- );
4072
- console.log("Change Processing Loop:", {
4073
- remainingChangeAmount,
4074
- smallestInput,
4075
- remainingInputsCount: remainingInputs.length
4076
- });
4077
- }
4078
- const minChangeAmount = Number(brgConfig.min_change_amount);
4079
- let additionalFee = 0;
4080
- console.log("Checking minimum change amount:", {
4081
- changeValue: changeOutput.value,
4082
- minChangeAmount
4083
- });
4084
- let finalOutputs = [...outputs];
4085
- if (changeOutput.value === 0) {
4086
- finalOutputs = finalOutputs.filter((output) => output.value !== 0);
4087
- console.log("Removed zero-value change output", finalOutputs);
4088
- } else if (changeOutput.value < minChangeAmount) {
4089
- additionalFee = minChangeAmount - changeOutput.value;
4090
- recipientOutput.value -= additionalFee;
4091
- changeOutput.value = minChangeAmount;
4092
- console.log("Adjusted for minimum change amount:", {
4093
- additionalFee,
4094
- newRecipientValue: recipientOutput.value,
4095
- newChangeValue: changeOutput.value
4096
- });
4097
- }
4098
- } else {
4099
- changeOutput = {
4100
- address: brgConfig.change_address,
4101
- value: new import_big2.default(transactionFee).plus(withdrawFee).toNumber()
4102
- };
4103
- outputs.push(changeOutput);
4104
- console.log("Created new change output:", changeOutput);
4105
- }
4106
- const insufficientOutput = outputs.some((item) => item.value < 0);
4107
- if (insufficientOutput) {
4108
- console.error("Negative output value detected");
4109
- throw new Error("Not enough gas");
4110
- }
4111
- const inputSum = inputs.reduce((sum, cur) => sum + Number(cur.value), 0);
4112
- const outputSum = outputs.reduce((sum, cur) => sum + Number(cur.value), 0);
4113
- console.log("Balance verification:", { inputSum, outputSum, transactionFee });
4114
- if (transactionFee + outputSum !== inputSum) {
4115
- console.error("Balance mismatch:", { inputSum, outputSum, transactionFee });
4116
- throw new Error("compute error");
4117
- }
4118
4185
  const network = yield getNetwork();
4119
4186
  const btcNetwork = network === "mainnet" ? import_bitcoinjs_lib.default.networks.bitcoin : import_bitcoinjs_lib.default.networks.testnet;
4120
4187
  const psbt = new import_bitcoinjs_lib.default.Psbt({ network: btcNetwork });
4121
4188
  const btcRpcUrl = yield getBtcRpcUrl();
4122
- for (let i = 0; i < inputs.length; i++) {
4123
- const input = inputs[i];
4124
- const txData = yield fetch(`${btcRpcUrl}/tx/${input.txid}`).then((res) => res.json());
4125
- const inputOptions = {
4126
- hash: input.txid,
4127
- index: input.vout,
4128
- sequence: 4294967293,
4129
- witnessUtxo: {
4130
- script: Buffer.from(txData.vout[input.vout].scriptpubkey, "hex"),
4131
- value: input.value
4132
- }
4133
- };
4134
- psbt.addInput(inputOptions);
4135
- }
4189
+ Promise.all(
4190
+ inputs.map((input) => __async(this, null, function* () {
4191
+ const txData = yield fetch(`${btcRpcUrl}/tx/${input.txid}`).then((res) => res.json());
4192
+ const inputOptions = {
4193
+ hash: input.txid,
4194
+ index: input.vout,
4195
+ sequence: 4294967293,
4196
+ witnessUtxo: {
4197
+ script: Buffer.from(txData.vout[input.vout].scriptpubkey, "hex"),
4198
+ value: input.value
4199
+ }
4200
+ };
4201
+ psbt.addInput(inputOptions);
4202
+ }))
4203
+ );
4136
4204
  outputs.forEach((output) => {
4137
4205
  psbt.addOutput({
4138
4206
  address: output.address,
4139
4207
  value: output.value
4140
4208
  });
4141
4209
  });
4142
- console.log("outputs:", JSON.stringify(outputs));
4143
4210
  const _inputs = inputs.map((item) => {
4144
4211
  return `${item.txid}:${item.vout}`;
4145
4212
  });
@@ -4623,6 +4690,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
4623
4690
  const btcContext = window.btcContext;
4624
4691
  const csna = state_default.getAccount();
4625
4692
  const accountInfo = yield getAccountInfo({ csna, env });
4693
+ yield checkGasTokenDebt(csna, env, true);
4626
4694
  const trans = [...params.transactions];
4627
4695
  console.log("signAndSendTransactions raw trans:", trans);
4628
4696
  const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
@@ -4723,7 +4791,7 @@ function setupBTCWallet({
4723
4791
 
4724
4792
  // src/index.ts
4725
4793
  var getVersion = () => {
4726
- return "0.5.19-beta";
4794
+ return "0.5.21-beta";
4727
4795
  };
4728
4796
  if (typeof window !== "undefined") {
4729
4797
  window.__BTC_WALLET_VERSION = getVersion();