btc-wallet 0.3.12 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,14 +5,14 @@ export declare function receiveDepositMsg(url: string, { btcPublicKey, txHash, d
5
5
  btcPublicKey: string;
6
6
  txHash: string;
7
7
  depositType?: number;
8
- postActions: string;
8
+ postActions?: string;
9
9
  extraMsg?: string;
10
10
  }): Promise<any>;
11
11
  export declare function checkBridgeTransactionStatus(url: string, txHash: string): Promise<{
12
- status: number;
12
+ Status: number;
13
13
  ToTxHash: string;
14
14
  }>;
15
15
  export declare function checkBtcTransactionStatus(url: string, sig: string): Promise<{
16
- status: number;
16
+ Status: number;
17
17
  NearHashList: string[];
18
18
  }>;
package/esm/index.js CHANGED
@@ -2686,24 +2686,21 @@ var walletConfig = {
2686
2686
  token: "nbtc-dev.testnet",
2687
2687
  accountContractId: "acc-dev.testnet",
2688
2688
  bridgeContractId: "brg-dev.testnet",
2689
- walletUrl: "https://wallet-dev.satoshibridge.top",
2690
- gasTokenLimit: "3000"
2689
+ walletUrl: "https://wallet-dev.satoshibridge.top"
2691
2690
  },
2692
2691
  testnet: {
2693
2692
  base_url: "https://api.testnet.satoshibridge.top",
2694
2693
  token: "nbtc2-nsp.testnet",
2695
2694
  accountContractId: "dev2-nsp.testnet",
2696
2695
  bridgeContractId: "brg2-nsp.testnet",
2697
- walletUrl: "https://wallet-test.satoshibridge.top",
2698
- gasTokenLimit: "3000"
2696
+ walletUrl: "https://wallet-test.satoshibridge.top"
2699
2697
  },
2700
2698
  mainnet: {
2701
2699
  base_url: "https://api.mainnet.satoshibridge.top",
2702
2700
  token: "",
2703
2701
  accountContractId: "",
2704
2702
  bridgeContractId: "",
2705
- walletUrl: "https://wallet.satoshibridge.top",
2706
- gasTokenLimit: "3000"
2703
+ walletUrl: "https://wallet.satoshibridge.top"
2707
2704
  }
2708
2705
  };
2709
2706
  var nearRpcUrls = {
@@ -2713,9 +2710,7 @@ var nearRpcUrls = {
2713
2710
  "https://free.rpc.fastnear.com",
2714
2711
  "https://near.drpc.org"
2715
2712
  ],
2716
- testnet: [
2717
- "https://rpc.testnet.near.org"
2718
- ]
2713
+ testnet: ["https://rpc.testnet.near.org"]
2719
2714
  };
2720
2715
  var btcRpcUrls = {
2721
2716
  mainnet: "https://mempool.space/api",
@@ -2926,14 +2921,14 @@ function checkBridgeTransactionStatus(url, txHash) {
2926
2921
  const { result_code, result_message, result_data } = yield request(`${url}/v1/bridgeFromTx?fromTxHash=${txHash}&fromChainId=1`, {
2927
2922
  timeout: 3e5,
2928
2923
  pollingInterval: 5e3,
2929
- maxPollingAttempts: 30,
2924
+ maxPollingAttempts: 60,
2930
2925
  shouldStopPolling: (res) => {
2931
2926
  var _a;
2932
- return res.result_code === 0 && [4, 102].includes(((_a = res.result_data) == null ? void 0 : _a.status) || 0);
2927
+ return res.result_code === 0 && [4, 102].includes(((_a = res.result_data) == null ? void 0 : _a.Status) || 0);
2933
2928
  }
2934
2929
  });
2935
2930
  console.log("checkTransactionStatus resp:", { result_code, result_message, result_data });
2936
- if ((result_data == null ? void 0 : result_data.status) !== 4) {
2931
+ if ((result_data == null ? void 0 : result_data.Status) !== 4) {
2937
2932
  throw new Error(result_message);
2938
2933
  }
2939
2934
  return result_data;
@@ -2944,201 +2939,20 @@ function checkBtcTransactionStatus(url, sig) {
2944
2939
  const { result_code, result_message, result_data } = yield request(`${url}/v1/btcTx?sig=${sig}`, {
2945
2940
  timeout: 3e5,
2946
2941
  pollingInterval: 5e3,
2947
- maxPollingAttempts: 30,
2942
+ maxPollingAttempts: 60,
2948
2943
  shouldStopPolling: (res) => {
2949
2944
  var _a;
2950
- return res.result_code === 0 && [3, 101, 102].includes(((_a = res.result_data) == null ? void 0 : _a.status) || 0);
2945
+ return res.result_code === 0 && [3, 101, 102].includes(((_a = res.result_data) == null ? void 0 : _a.Status) || 0);
2951
2946
  }
2952
2947
  });
2953
2948
  console.log("checkBtcTransactionStatus resp:", { result_code, result_message, result_data });
2954
- if ((result_data == null ? void 0 : result_data.status) !== 3) {
2949
+ if ((result_data == null ? void 0 : result_data.Status) !== 3) {
2955
2950
  throw new Error(result_message);
2956
2951
  }
2957
2952
  return result_data;
2958
2953
  });
2959
2954
  }
2960
2955
 
2961
- // src/core/btcUtils.ts
2962
- function getBtcProvider() {
2963
- if (typeof window === "undefined" || !window.btcContext) {
2964
- throw new Error("BTC Provider is not initialized.");
2965
- }
2966
- return window.btcContext;
2967
- }
2968
- function getNetwork() {
2969
- return __async(this, null, function* () {
2970
- const network = yield getBtcProvider().getNetwork();
2971
- console.log("btc network:", network);
2972
- return network === "livenet" ? "mainnet" : "testnet";
2973
- });
2974
- }
2975
- function getBtcRpcUrl() {
2976
- return __async(this, null, function* () {
2977
- const network = yield getNetwork();
2978
- return btcRpcUrls[network];
2979
- });
2980
- }
2981
- function getConfig(isDev) {
2982
- return __async(this, null, function* () {
2983
- const network = yield getNetwork();
2984
- return walletConfig[isDev ? "dev" : network];
2985
- });
2986
- }
2987
- function nearCall(contractId, methodName, args) {
2988
- return __async(this, null, function* () {
2989
- const network = yield getNetwork();
2990
- return nearCallFunction(contractId, methodName, args, { network });
2991
- });
2992
- }
2993
- function getBtcGasPrice() {
2994
- return __async(this, null, function* () {
2995
- const defaultFeeRate = 100;
2996
- try {
2997
- const btcRpcUrl = yield getBtcRpcUrl();
2998
- const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
2999
- const feeRate = res.fastestFee;
3000
- return feeRate || defaultFeeRate;
3001
- } catch (error) {
3002
- return defaultFeeRate;
3003
- }
3004
- });
3005
- }
3006
- function getBtcBalance() {
3007
- return __async(this, null, function* () {
3008
- const { account } = yield retryOperation(getBtcProvider, (res) => !!res.account);
3009
- if (!account) {
3010
- console.error("BTC Account is not available.");
3011
- return { rawBalance: 0, balance: 0, maxSpendableBalance: 0 };
3012
- }
3013
- const btcRpcUrl = yield getBtcRpcUrl();
3014
- const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
3015
- const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
3016
- const balance = rawBalance / __pow(10, 8);
3017
- const feeRate = yield getBtcGasPrice();
3018
- const inputSize = ((utxos == null ? void 0 : utxos.length) || 0) * 66;
3019
- const outputSize = 34;
3020
- const overheadSize = 10;
3021
- const estimatedTxSize = inputSize + outputSize + overheadSize;
3022
- const estimatedFee = estimatedTxSize * feeRate / __pow(10, 8);
3023
- console.log("estimated fee:", estimatedFee);
3024
- const availableBalance = Math.max(0, balance - estimatedFee);
3025
- return {
3026
- rawBalance,
3027
- balance,
3028
- availableBalance
3029
- };
3030
- });
3031
- }
3032
- function sendBitcoin(address, amount, feeRate) {
3033
- return __async(this, null, function* () {
3034
- const { sendBitcoin: sendBitcoin2 } = getBtcProvider();
3035
- const txHash = yield sendBitcoin2(address, amount, { feeRate });
3036
- return txHash;
3037
- });
3038
- }
3039
- function estimateDepositAmount(amount, option) {
3040
- return __async(this, null, function* () {
3041
- const config = yield getConfig((option == null ? void 0 : option.isDev) || false);
3042
- const {
3043
- deposit_bridge_fee: { fee_min, fee_rate }
3044
- } = yield nearCall(
3045
- config.bridgeContractId,
3046
- "get_config",
3047
- {}
3048
- );
3049
- const fee = Math.max(Number(fee_min), Number(amount) * fee_rate);
3050
- return new Big(amount).minus(fee).toFixed(0);
3051
- });
3052
- }
3053
- function executeBTCDepositAndAction(_0) {
3054
- return __async(this, arguments, function* ({
3055
- action,
3056
- feeRate,
3057
- isDev = false
3058
- }) {
3059
- try {
3060
- const { getPublicKey } = getBtcProvider();
3061
- const config = yield getConfig(isDev);
3062
- const btcPublicKey = yield getPublicKey();
3063
- if (!btcPublicKey) {
3064
- throw new Error("BTC Public Key is not available.");
3065
- }
3066
- if (!action.receiver_id) {
3067
- throw new Error("receiver_id is required");
3068
- }
3069
- if (!action.amount) {
3070
- throw new Error("amount is required");
3071
- }
3072
- const csna = yield nearCall(
3073
- config.accountContractId,
3074
- "get_chain_signature_near_account_id",
3075
- {
3076
- btc_public_key: btcPublicKey
3077
- }
3078
- );
3079
- const depositMsg = {
3080
- recipient_id: csna,
3081
- post_actions: [
3082
- __spreadProps(__spreadValues({}, action), {
3083
- gas: new Big(100).mul(__pow(10, 12)).toFixed(0)
3084
- })
3085
- ]
3086
- };
3087
- const storageDepositMsg = {};
3088
- const accountInfo = yield nearCall(
3089
- config.accountContractId,
3090
- "get_account",
3091
- {
3092
- account_id: csna
3093
- }
3094
- );
3095
- if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
3096
- storageDepositMsg.btc_public_key = btcPublicKey;
3097
- }
3098
- const registerRes = yield nearCall(action.receiver_id, "storage_balance_of", {
3099
- account_id: csna
3100
- });
3101
- if (!(registerRes == null ? void 0 : registerRes.available)) {
3102
- storageDepositMsg.storage_deposit_msg = {
3103
- contract_id: action.receiver_id,
3104
- deposit: new Big(0.25).mul(__pow(10, 24)).toFixed(0),
3105
- registration_only: true
3106
- };
3107
- }
3108
- if (Object.keys(storageDepositMsg).length > 0) {
3109
- depositMsg.extra_msg = JSON.stringify(storageDepositMsg);
3110
- }
3111
- console.log("get_user_deposit_address params:", { deposit_msg: depositMsg });
3112
- const userDepositAddress = yield nearCall(
3113
- config.bridgeContractId,
3114
- "get_user_deposit_address",
3115
- { deposit_msg: depositMsg }
3116
- );
3117
- const _feeRate = feeRate || (yield getBtcGasPrice());
3118
- const minDepositAmount = 5e3;
3119
- const sendAmount = Math.max(minDepositAmount, new Big(action.amount).toNumber());
3120
- console.log("user deposit address:", userDepositAddress);
3121
- console.log("send amount:", sendAmount);
3122
- console.log("fee rate:", _feeRate);
3123
- const txHash = yield sendBitcoin(userDepositAddress, sendAmount, _feeRate);
3124
- yield receiveDepositMsg(config.base_url, {
3125
- btcPublicKey,
3126
- txHash,
3127
- postActions: JSON.stringify(depositMsg.post_actions),
3128
- extraMsg: depositMsg.extra_msg
3129
- });
3130
- const checkTransactionStatusRes = yield checkBridgeTransactionStatus(config.base_url, txHash);
3131
- console.log("checkBridgeTransactionStatus resp:", checkTransactionStatusRes);
3132
- const network = yield getNetwork();
3133
- const result = yield pollTransactionStatuses(network, [checkTransactionStatusRes.ToTxHash]);
3134
- return result;
3135
- } catch (error) {
3136
- console.error("executeBTCDepositAndAction error:", error);
3137
- throw error;
3138
- }
3139
- });
3140
- }
3141
-
3142
2956
  // src/utils/Dialog.ts
3143
2957
  var Dialog = class {
3144
2958
  static injectStyles() {
@@ -3320,6 +3134,249 @@ Dialog.style = `
3320
3134
  }
3321
3135
  `;
3322
3136
 
3137
+ // src/core/btcUtils.ts
3138
+ function getBtcProvider() {
3139
+ if (typeof window === "undefined" || !window.btcContext) {
3140
+ throw new Error("BTC Provider is not initialized.");
3141
+ }
3142
+ return window.btcContext;
3143
+ }
3144
+ function getNetwork() {
3145
+ return __async(this, null, function* () {
3146
+ const network = yield getBtcProvider().getNetwork();
3147
+ console.log("btc network:", network);
3148
+ return network === "livenet" ? "mainnet" : "testnet";
3149
+ });
3150
+ }
3151
+ function getBtcRpcUrl() {
3152
+ return __async(this, null, function* () {
3153
+ const network = yield getNetwork();
3154
+ return btcRpcUrls[network];
3155
+ });
3156
+ }
3157
+ function getConfig(isDev) {
3158
+ return __async(this, null, function* () {
3159
+ const network = yield getNetwork();
3160
+ return walletConfig[isDev ? "dev" : network];
3161
+ });
3162
+ }
3163
+ function nearCall(contractId, methodName, args) {
3164
+ return __async(this, null, function* () {
3165
+ const network = yield getNetwork();
3166
+ return nearCallFunction(contractId, methodName, args, { network });
3167
+ });
3168
+ }
3169
+ function getAccountInfo(csna, accountContractId) {
3170
+ return __async(this, null, function* () {
3171
+ const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
3172
+ return accountInfo;
3173
+ });
3174
+ }
3175
+ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
3176
+ return __async(this, null, function* () {
3177
+ if (!debtInfo)
3178
+ return;
3179
+ const config = yield getConfig(isDev);
3180
+ const transferAmount = debtInfo.transfer_amount;
3181
+ console.log("get_account debtInfo:", debtInfo);
3182
+ const action = {
3183
+ receiver_id: config.accountContractId,
3184
+ amount: transferAmount,
3185
+ msg: JSON.stringify("Deposit")
3186
+ };
3187
+ if (!autoDeposit)
3188
+ return action;
3189
+ const confirmed = yield Dialog.confirm({
3190
+ title: "Has gas token arrears",
3191
+ message: "You have gas token arrears, please deposit gas token to continue."
3192
+ });
3193
+ if (confirmed) {
3194
+ yield executeBTCDepositAndAction({ action, isDev });
3195
+ yield Dialog.alert({
3196
+ title: "Deposit success",
3197
+ message: "Deposit success, will continue to execute transaction."
3198
+ });
3199
+ } else {
3200
+ throw new Error("Deposit failed, please deposit gas token first.");
3201
+ }
3202
+ });
3203
+ }
3204
+ function getBtcGasPrice() {
3205
+ return __async(this, null, function* () {
3206
+ const network = yield getNetwork();
3207
+ const defaultFeeRate = network === "mainnet" ? 5 : 2500;
3208
+ try {
3209
+ const btcRpcUrl = yield getBtcRpcUrl();
3210
+ const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
3211
+ const feeRate = res.fastestFee;
3212
+ return feeRate || defaultFeeRate;
3213
+ } catch (error) {
3214
+ return defaultFeeRate;
3215
+ }
3216
+ });
3217
+ }
3218
+ function getBtcBalance() {
3219
+ return __async(this, null, function* () {
3220
+ const { account } = yield retryOperation(getBtcProvider, (res) => !!res.account);
3221
+ if (!account) {
3222
+ console.error("BTC Account is not available.");
3223
+ return { rawBalance: 0, balance: 0, maxSpendableBalance: 0 };
3224
+ }
3225
+ const btcRpcUrl = yield getBtcRpcUrl();
3226
+ const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
3227
+ const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
3228
+ const balance = rawBalance / __pow(10, 8);
3229
+ const feeRate = yield getBtcGasPrice();
3230
+ const inputSize = ((utxos == null ? void 0 : utxos.length) || 0) * 66;
3231
+ const outputSize = 34;
3232
+ const overheadSize = 10;
3233
+ const estimatedTxSize = inputSize + outputSize + overheadSize;
3234
+ const estimatedFee = estimatedTxSize * feeRate / __pow(10, 8);
3235
+ console.log("estimated fee:", estimatedFee);
3236
+ const availableBalance = Math.max(0, balance - estimatedFee);
3237
+ return {
3238
+ rawBalance,
3239
+ balance,
3240
+ availableBalance
3241
+ };
3242
+ });
3243
+ }
3244
+ function sendBitcoin(address, amount, feeRate) {
3245
+ return __async(this, null, function* () {
3246
+ const { sendBitcoin: sendBitcoin2 } = getBtcProvider();
3247
+ const txHash = yield sendBitcoin2(address, amount, { feeRate });
3248
+ return txHash;
3249
+ });
3250
+ }
3251
+ var MINIMUM_DEPOSIT_AMOUNT = 5e3;
3252
+ var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
3253
+ function estimateDepositAmount(amount, option) {
3254
+ return __async(this, null, function* () {
3255
+ const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
3256
+ return receiveAmount;
3257
+ });
3258
+ }
3259
+ function getDepositAmount(amount, option) {
3260
+ return __async(this, null, function* () {
3261
+ const config = yield getConfig((option == null ? void 0 : option.isDev) || false);
3262
+ const {
3263
+ deposit_bridge_fee: { fee_min, fee_rate }
3264
+ } = yield nearCall(
3265
+ config.bridgeContractId,
3266
+ "get_config",
3267
+ {}
3268
+ );
3269
+ const depositAmount = (option == null ? void 0 : option.isEstimate) ? Number(amount) : Math.max(MINIMUM_DEPOSIT_AMOUNT + MINIMUM_DEPOSIT_AMOUNT_BASE, Number(amount));
3270
+ const fee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3271
+ const receiveAmount = new Big(depositAmount).minus(fee).round(0, Big.roundDown).toNumber();
3272
+ return {
3273
+ depositAmount,
3274
+ receiveAmount: Math.max(receiveAmount, 0),
3275
+ fee
3276
+ };
3277
+ });
3278
+ }
3279
+ function executeBTCDepositAndAction(_0) {
3280
+ return __async(this, arguments, function* ({
3281
+ action,
3282
+ amount,
3283
+ feeRate,
3284
+ fixedAmount = true,
3285
+ isDev = false
3286
+ }) {
3287
+ var _a;
3288
+ try {
3289
+ const { getPublicKey } = getBtcProvider();
3290
+ const config = yield getConfig(isDev);
3291
+ const btcPublicKey = yield getPublicKey();
3292
+ if (!btcPublicKey) {
3293
+ throw new Error("BTC Public Key is not available.");
3294
+ }
3295
+ if (!amount && !action) {
3296
+ throw new Error("amount or action is required");
3297
+ }
3298
+ const csna = yield nearCall(
3299
+ config.accountContractId,
3300
+ "get_chain_signature_near_account_id",
3301
+ {
3302
+ btc_public_key: btcPublicKey
3303
+ }
3304
+ );
3305
+ const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3306
+ if (new Big(rawDepositAmount).lt(0)) {
3307
+ throw new Error("amount must be greater than 0");
3308
+ }
3309
+ const { depositAmount, receiveAmount } = yield getDepositAmount(rawDepositAmount, {
3310
+ isDev
3311
+ });
3312
+ const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3313
+ const newActions = [];
3314
+ const gasLimit = new Big(50).mul(__pow(10, 12)).toFixed(0);
3315
+ const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev, false);
3316
+ if (repayAction) {
3317
+ newActions.push(__spreadProps(__spreadValues({}, repayAction), {
3318
+ gas: gasLimit
3319
+ }));
3320
+ }
3321
+ if (action) {
3322
+ newActions.push(__spreadProps(__spreadValues({}, action), {
3323
+ amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3324
+ gas: gasLimit
3325
+ }));
3326
+ }
3327
+ const depositMsg = {
3328
+ recipient_id: csna,
3329
+ post_actions: newActions.length > 0 ? newActions : void 0
3330
+ };
3331
+ const storageDepositMsg = {};
3332
+ if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
3333
+ storageDepositMsg.btc_public_key = btcPublicKey;
3334
+ }
3335
+ const registerRes = yield nearCall((action == null ? void 0 : action.receiver_id) || config.token, "storage_balance_of", {
3336
+ account_id: csna
3337
+ });
3338
+ if (!(registerRes == null ? void 0 : registerRes.available)) {
3339
+ storageDepositMsg.storage_deposit_msg = {
3340
+ contract_id: (action == null ? void 0 : action.receiver_id) || config.token,
3341
+ deposit: new Big(0.25).mul(__pow(10, 24)).toFixed(0),
3342
+ registration_only: true
3343
+ };
3344
+ }
3345
+ if (Object.keys(storageDepositMsg).length > 0) {
3346
+ depositMsg.extra_msg = JSON.stringify(storageDepositMsg);
3347
+ }
3348
+ console.log("get_user_deposit_address params:", { deposit_msg: depositMsg });
3349
+ const userDepositAddress = yield nearCall(
3350
+ config.bridgeContractId,
3351
+ "get_user_deposit_address",
3352
+ { deposit_msg: depositMsg }
3353
+ );
3354
+ const _feeRate = feeRate || (yield getBtcGasPrice());
3355
+ const sendAmount = (repayAction == null ? void 0 : repayAction.amount) && fixedAmount ? new Big(depositAmount).plus((repayAction == null ? void 0 : repayAction.amount) || 0).toString() : depositAmount;
3356
+ console.log("user deposit address:", userDepositAddress);
3357
+ console.log("send amount:", sendAmount);
3358
+ console.log("fee rate:", _feeRate);
3359
+ const txHash = yield sendBitcoin(userDepositAddress, Number(sendAmount), _feeRate);
3360
+ const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
3361
+ yield receiveDepositMsg(config.base_url, {
3362
+ btcPublicKey,
3363
+ txHash,
3364
+ depositType: postActionsStr || depositMsg.extra_msg ? 1 : 0,
3365
+ postActions: postActionsStr,
3366
+ extraMsg: depositMsg.extra_msg
3367
+ });
3368
+ const checkTransactionStatusRes = yield checkBridgeTransactionStatus(config.base_url, txHash);
3369
+ console.log("checkBridgeTransactionStatus resp:", checkTransactionStatusRes);
3370
+ const network = yield getNetwork();
3371
+ const result = yield pollTransactionStatuses(network, [checkTransactionStatusRes.ToTxHash]);
3372
+ return result;
3373
+ } catch (error) {
3374
+ console.error("executeBTCDepositAndAction error:", error);
3375
+ throw error;
3376
+ }
3377
+ });
3378
+ }
3379
+
3323
3380
  // src/core/setupBTCWallet.ts
3324
3381
  var { transfer, functionCall } = actionCreators;
3325
3382
  var state = {
@@ -3523,8 +3580,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3523
3580
  return __async(this, null, function* () {
3524
3581
  const btcContext = window.btcContext;
3525
3582
  const accountId = state.getAccount();
3526
- const accountInfo = yield getAccountInfo();
3527
- yield checkGasTokenArrears(accountInfo.debt_info);
3583
+ const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
3584
+ yield checkGasTokenArrears(accountInfo.debt_info, isDev, true);
3528
3585
  const trans = [...params.transactions];
3529
3586
  console.log("raw trans:", trans);
3530
3587
  const gasTokenBalance = accountInfo.gas_token[currentConfig.token] || "0";
@@ -3567,39 +3624,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3567
3624
  return result;
3568
3625
  });
3569
3626
  }
3570
- function checkGasTokenArrears(debtInfo) {
3571
- return __async(this, null, function* () {
3572
- const transferAmount = (debtInfo == null ? void 0 : debtInfo.transfer_amount) || "0";
3573
- console.log("get_account debtInfo:", debtInfo);
3574
- if (transferAmount === "0")
3575
- return;
3576
- const confirmed = yield Dialog.confirm({
3577
- title: "Has gas token arrears",
3578
- message: "You have gas token arrears, please deposit gas token to continue."
3579
- });
3580
- if (confirmed) {
3581
- const action = {
3582
- receiver_id: currentConfig.token,
3583
- amount: transferAmount,
3584
- msg: JSON.stringify("Deposit")
3585
- };
3586
- yield executeBTCDepositAndAction({ action, isDev });
3587
- yield Dialog.alert({
3588
- title: "Deposit success",
3589
- message: "Deposit success, will continue to execute transaction."
3590
- });
3591
- } else {
3592
- throw new Error("Deposit failed, please deposit gas token first.");
3593
- }
3594
- });
3595
- }
3596
- function getAccountInfo() {
3597
- return __async(this, null, function* () {
3598
- const accountId = state.getAccount();
3599
- const accountInfo = yield nearCall2(currentConfig.accountContractId, "get_account", { account_id: accountId });
3600
- return accountInfo;
3601
- });
3602
- }
3603
3627
  function createGasTokenTransfer(accountId, amount) {
3604
3628
  return __async(this, null, function* () {
3605
3629
  return {
@@ -3667,6 +3691,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3667
3691
  transactions2.map((transaction, index) => convertTransactionToTxHex(transaction, index))
3668
3692
  );
3669
3693
  if (availableBalance > 0.2) {
3694
+ console.log("near balance is enough, get the protocol fee of each transaction");
3670
3695
  const gasTokens = yield nearCall2(
3671
3696
  currentConfig.accountContractId,
3672
3697
  "list_gas_token",
@@ -3815,7 +3840,7 @@ function setupBTCWallet({
3815
3840
 
3816
3841
  // src/index.ts
3817
3842
  var getVersion = () => {
3818
- return "0.3.12";
3843
+ return "0.3.14";
3819
3844
  };
3820
3845
  if (typeof window !== "undefined") {
3821
3846
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
@@ -3833,10 +3858,13 @@ export {
3833
3858
  UnisatConnector,
3834
3859
  WizzConnector,
3835
3860
  XverseConnector,
3861
+ checkGasTokenArrears,
3836
3862
  estimateDepositAmount,
3837
3863
  executeBTCDepositAndAction,
3864
+ getAccountInfo,
3838
3865
  getBtcBalance,
3839
3866
  getBtcGasPrice,
3867
+ getDepositAmount,
3840
3868
  getVersion,
3841
3869
  sendBitcoin,
3842
3870
  setupBTCWallet,