btc-wallet 0.4.4-beta → 0.4.6-beta

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -66,7 +66,6 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
66
66
 
67
67
  // Common optional parameters
68
68
  feeRate?: number; // optional: custom fee rate for the BTC transaction
69
- fixedAmount?: boolean; // optional: whether to use fixed amount
70
69
  env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev'; // optional: defaults to NEAR network environment
71
70
  pollResult?: T; // optional: whether to poll for transaction result
72
71
  registerDeposit?: string; // optional: whether to register deposit,default 0.000125 NEAR
@@ -1,27 +1,25 @@
1
1
  import type { ENV } from '../config';
2
- import type { FinalExecutionOutcome } from '@near-wallet-selector/core';
2
+ import type { FinalExecutionOutcome, Transaction } from '@near-wallet-selector/core';
3
3
  export interface AccountInfo {
4
4
  nonce: string;
5
5
  gas_token: Record<string, string>;
6
- debt_info?: DebtInfo;
6
+ debt_info?: {
7
+ gas_token_id: string;
8
+ near_gas_debt_amount: string;
9
+ protocol_fee_debt_amount: string;
10
+ };
7
11
  relayer_fee?: {
8
12
  amount?: string;
9
13
  };
10
14
  }
11
- export interface DebtInfo {
12
- gas_token_id: string;
13
- near_gas_debt_amount: string;
14
- protocol_fee_debt_amount: string;
15
- }
16
15
  export declare function getAccountInfo(csna: string, accountContractId: string): Promise<AccountInfo | undefined>;
17
16
  export declare function checkGasTokenBalance(csna: string, gasToken: string, minAmount: string, env: ENV): Promise<void>;
18
- type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
17
+ type CheckGasTokenDebtReturnType<T extends boolean> = T extends true ? void : {
19
18
  receiver_id: string;
20
19
  amount: string;
21
20
  msg: string;
22
21
  } | undefined;
23
- export declare function checkGasTokenArrears<T extends boolean>(accountInfo: AccountInfo | undefined, env: ENV, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
24
- export declare function queryGasTokenArrears(env: ENV): Promise<DebtInfo | undefined>;
22
+ export declare function checkGasTokenDebt<T extends boolean>(accountInfo: AccountInfo | undefined, env: ENV, autoDeposit?: T): Promise<CheckGasTokenDebtReturnType<T>>;
25
23
  export declare function getBtcGasPrice(): Promise<number>;
26
24
  export declare function getBtcBalance(): Promise<{
27
25
  rawBalance: number;
@@ -34,17 +32,24 @@ export declare function getBtcBalance(): Promise<{
34
32
  availableBalance: number;
35
33
  maxSpendableBalance?: undefined;
36
34
  }>;
35
+ export declare function getNBTCBalance(address: string, env?: ENV): Promise<{
36
+ balance: number;
37
+ availableBalance: number;
38
+ rawBalance: string;
39
+ rawAvailableBalance: number;
40
+ }>;
37
41
  export declare function sendBitcoin(address: string, amount: number, feeRate: number): Promise<string>;
42
+ /** estimate deposit receive amount, deduct protocol fee and repay amount */
38
43
  export declare function estimateDepositAmount(amount: string, option?: {
39
44
  env?: ENV;
40
- }): Promise<number>;
45
+ }): Promise<string>;
41
46
  export declare function getDepositAmount(amount: string, option?: {
42
- isEstimate?: boolean;
43
47
  env?: ENV;
44
48
  }): Promise<{
45
49
  depositAmount: number;
46
- receiveAmount: number;
47
- fee: number;
50
+ totalDepositAmount: number;
51
+ protocolFee: number;
52
+ repayAmount: string | number;
48
53
  }>;
49
54
  export declare function getCsnaAccountId(env: ENV): Promise<string>;
50
55
  interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
@@ -57,7 +62,6 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
57
62
  /** if registerDeposit is true, It will consume the deposit, otherwise it will be 0.000125 NEAR */
58
63
  registerDeposit?: string;
59
64
  feeRate?: number;
60
- fixedAmount?: boolean;
61
65
  env?: ENV;
62
66
  pollResult?: T;
63
67
  }
@@ -65,6 +69,12 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
65
69
  * @param T - if true, return the poll result, otherwise return the btcTxHash
66
70
  */
67
71
  type ExecuteBTCDepositAndActionReturn<T extends boolean> = T extends true ? FinalExecutionOutcome[] : string;
68
- export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, fixedAmount, pollResult, registerDeposit, env, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
72
+ export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, pollResult, registerDeposit, env, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
69
73
  export declare function checkSatoshiWhitelist(btcAccountId: string, env?: ENV): Promise<void>;
74
+ interface WithdrawParams {
75
+ amount: string | number;
76
+ feeRate?: number;
77
+ env?: ENV;
78
+ }
79
+ export declare function getWithdrawTransaction({ amount, feeRate, env, }: WithdrawParams): Promise<Transaction>;
70
80
  export {};
package/dist/index.js CHANGED
@@ -90,8 +90,8 @@ __export(src_exports, {
90
90
  UnisatConnector: () => UnisatConnector,
91
91
  WizzConnector: () => WizzConnector,
92
92
  XverseConnector: () => XverseConnector,
93
- checkGasTokenArrears: () => checkGasTokenArrears,
94
93
  checkGasTokenBalance: () => checkGasTokenBalance,
94
+ checkGasTokenDebt: () => checkGasTokenDebt,
95
95
  checkSatoshiWhitelist: () => checkSatoshiWhitelist,
96
96
  estimateDepositAmount: () => estimateDepositAmount,
97
97
  executeBTCDepositAndAction: () => executeBTCDepositAndAction,
@@ -100,8 +100,9 @@ __export(src_exports, {
100
100
  getBtcGasPrice: () => getBtcGasPrice,
101
101
  getCsnaAccountId: () => getCsnaAccountId,
102
102
  getDepositAmount: () => getDepositAmount,
103
+ getNBTCBalance: () => getNBTCBalance,
103
104
  getVersion: () => getVersion,
104
- queryGasTokenArrears: () => queryGasTokenArrears,
105
+ getWithdrawTransaction: () => getWithdrawTransaction,
105
106
  sendBitcoin: () => sendBitcoin,
106
107
  setupBTCWallet: () => setupBTCWallet,
107
108
  useAccountContract: () => useAccountContract,
@@ -2401,6 +2402,7 @@ function BtcWalletSelectorContextProvider({
2401
2402
  const [isProcessing, setIsProcessing] = (0, import_react11.useState)(false);
2402
2403
  const connectors = [
2403
2404
  new UnisatConnector(),
2405
+ new XverseConnector(),
2404
2406
  new OKXConnector(),
2405
2407
  new BitgetConnector()
2406
2408
  ];
@@ -3240,9 +3242,10 @@ Dialog.style = `
3240
3242
  `;
3241
3243
 
3242
3244
  // src/core/btcUtils.ts
3243
- var MINIMUM_DEPOSIT_AMOUNT_BASE = 0;
3245
+ var import_bitcoinjs_lib = __toESM(require("bitcoinjs-lib"), 1);
3246
+ var import_coinselect = __toESM(require("coinselect"), 1);
3244
3247
  var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
3245
- var NBTC_STORAGE_DEPOSIT_AMOUNT = 3e3;
3248
+ var NBTC_STORAGE_DEPOSIT_AMOUNT = "3000";
3246
3249
  var GAS_LIMIT = "50000000000000";
3247
3250
  function getBtcProvider() {
3248
3251
  if (typeof window === "undefined" || !window.btcContext) {
@@ -3300,11 +3303,11 @@ function checkGasTokenBalance(csna, gasToken, minAmount, env) {
3300
3303
  }
3301
3304
  });
3302
3305
  }
3303
- function checkGasTokenArrears(accountInfo, env, autoDeposit) {
3306
+ function checkGasTokenDebt(accountInfo, env, autoDeposit) {
3304
3307
  return __async(this, null, function* () {
3305
3308
  var _a, _b, _c;
3306
3309
  const debtAmount = new import_big.default(((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.near_gas_debt_amount) || 0).plus(((_b = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _b.protocol_fee_debt_amount) || 0).toString();
3307
- const relayerFeeAmount = ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || "0";
3310
+ const relayerFeeAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
3308
3311
  const hasDebtArrears = new import_big.default(debtAmount).gt(0);
3309
3312
  const hasRelayerFeeArrears = new import_big.default(relayerFeeAmount).gt(0);
3310
3313
  if (!hasDebtArrears && !hasRelayerFeeArrears)
@@ -3314,7 +3317,7 @@ function checkGasTokenArrears(accountInfo, env, autoDeposit) {
3314
3317
  console.log("get_account:", accountInfo);
3315
3318
  const action = {
3316
3319
  receiver_id: config.accountContractId,
3317
- amount: transferAmount,
3320
+ amount: transferAmount.toString(),
3318
3321
  msg: JSON.stringify(hasDebtArrears ? "Repay" : "RelayerFee")
3319
3322
  };
3320
3323
  if (!autoDeposit)
@@ -3334,14 +3337,6 @@ function checkGasTokenArrears(accountInfo, env, autoDeposit) {
3334
3337
  }
3335
3338
  });
3336
3339
  }
3337
- function queryGasTokenArrears(env) {
3338
- return __async(this, null, function* () {
3339
- const config = yield getConfig(env);
3340
- const csna = yield getCsnaAccountId(env);
3341
- const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3342
- return accountInfo == null ? void 0 : accountInfo.debt_info;
3343
- });
3344
- }
3345
3340
  function getBtcGasPrice() {
3346
3341
  return __async(this, null, function* () {
3347
3342
  const network = yield getNetwork();
@@ -3383,6 +3378,18 @@ function getBtcBalance() {
3383
3378
  };
3384
3379
  });
3385
3380
  }
3381
+ function getNBTCBalance(address, env) {
3382
+ return __async(this, null, function* () {
3383
+ const config = yield getConfig(env || "mainnet");
3384
+ const rawBalance = yield nearCall(config.token, "ft_balance_of", {
3385
+ account_id: address
3386
+ });
3387
+ const balance = new import_big.default(rawBalance).div(__pow(10, 8)).round(8, import_big.default.roundDown).toNumber();
3388
+ const rawAvailableBalance = new import_big.default(rawBalance).minus(1e3).toNumber();
3389
+ const availableBalance = new import_big.default(rawAvailableBalance).div(__pow(10, 8)).round(8, import_big.default.roundDown).toNumber();
3390
+ return { balance, availableBalance, rawBalance, rawAvailableBalance };
3391
+ });
3392
+ }
3386
3393
  function sendBitcoin(address, amount, feeRate) {
3387
3394
  return __async(this, null, function* () {
3388
3395
  const { sendBitcoin: sendBitcoin2 } = getBtcProvider();
@@ -3392,28 +3399,29 @@ function sendBitcoin(address, amount, feeRate) {
3392
3399
  }
3393
3400
  function estimateDepositAmount(amount, option) {
3394
3401
  return __async(this, null, function* () {
3395
- const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
3396
- const csna = yield getCsnaAccountId((option == null ? void 0 : option.env) || "mainnet");
3397
- const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3398
- const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
3399
- return (accountInfo == null ? void 0 : accountInfo.nonce) ? receiveAmount : new import_big.default(receiveAmount).minus(NBTC_STORAGE_DEPOSIT_AMOUNT).round(0, import_big.default.roundDown).toNumber();
3402
+ return amount;
3400
3403
  });
3401
3404
  }
3402
3405
  function getDepositAmount(amount, option) {
3403
3406
  return __async(this, null, function* () {
3404
- const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
3407
+ const env = (option == null ? void 0 : option.env) || "mainnet";
3408
+ const config = yield getConfig(env);
3409
+ const csna = yield getCsnaAccountId(env);
3410
+ const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3411
+ const debtAction = yield checkGasTokenDebt(accountInfo, env, false);
3412
+ const repayAmount = (debtAction == null ? void 0 : debtAction.amount) || 0;
3405
3413
  const {
3406
3414
  deposit_bridge_fee: { fee_min, fee_rate },
3407
3415
  min_deposit_amount
3408
3416
  } = yield nearCall(config.bridgeContractId, "get_config", {});
3409
- const depositAmount = (option == null ? void 0 : option.isEstimate) ? Number(amount) : Math.max(Number(min_deposit_amount) + MINIMUM_DEPOSIT_AMOUNT_BASE, Number(amount));
3410
- const fee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3411
- const receiveAmount = new import_big.default(depositAmount).minus(fee).minus(MINIMUM_DEPOSIT_AMOUNT_BASE).round(0, import_big.default.roundDown).toNumber();
3412
- console.log("getDepositAmount:", { depositAmount, receiveAmount, fee });
3417
+ const depositAmount = Math.max(Number(min_deposit_amount), Number(amount));
3418
+ const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
3419
+ const totalDepositAmount = new import_big.default(depositAmount).plus(protocolFee).plus(repayAmount).round(0, import_big.default.roundDown).toNumber();
3413
3420
  return {
3414
3421
  depositAmount,
3415
- receiveAmount: Math.max(receiveAmount, 0),
3416
- fee
3422
+ totalDepositAmount,
3423
+ protocolFee,
3424
+ repayAmount
3417
3425
  };
3418
3426
  });
3419
3427
  }
@@ -3437,7 +3445,6 @@ function executeBTCDepositAndAction(_0) {
3437
3445
  action,
3438
3446
  amount,
3439
3447
  feeRate,
3440
- fixedAmount = true,
3441
3448
  pollResult = true,
3442
3449
  registerDeposit,
3443
3450
  env = "mainnet"
@@ -3454,24 +3461,23 @@ function executeBTCDepositAndAction(_0) {
3454
3461
  throw new Error("amount or action is required");
3455
3462
  }
3456
3463
  const csna = yield getCsnaAccountId(env);
3457
- const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3458
- if (new import_big.default(rawDepositAmount).lt(0)) {
3464
+ const depositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3465
+ if (new import_big.default(depositAmount).lt(0)) {
3459
3466
  throw new Error("amount must be greater than 0");
3460
3467
  }
3461
- const { depositAmount, receiveAmount } = yield getDepositAmount(rawDepositAmount, {
3468
+ const { totalDepositAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
3462
3469
  env
3463
3470
  });
3464
3471
  const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3465
3472
  const newActions = [];
3466
- const arrearsAction = yield checkGasTokenArrears(accountInfo, env, false);
3467
- if (arrearsAction) {
3468
- newActions.push(__spreadProps(__spreadValues({}, arrearsAction), {
3473
+ const debtAction = yield checkGasTokenDebt(accountInfo, env, false);
3474
+ if (debtAction) {
3475
+ newActions.push(__spreadProps(__spreadValues({}, debtAction), {
3469
3476
  gas: GAS_LIMIT
3470
3477
  }));
3471
3478
  }
3472
3479
  if (action) {
3473
3480
  newActions.push(__spreadProps(__spreadValues({}, action), {
3474
- amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
3475
3481
  gas: GAS_LIMIT
3476
3482
  }));
3477
3483
  }
@@ -3488,12 +3494,6 @@ function executeBTCDepositAndAction(_0) {
3488
3494
  }
3489
3495
  if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
3490
3496
  storageDepositMsg.btc_public_key = btcPublicKey;
3491
- newActions.push({
3492
- receiver_id: config.accountContractId,
3493
- amount: NBTC_STORAGE_DEPOSIT_AMOUNT.toString(),
3494
- msg: JSON.stringify("RelayerFee"),
3495
- gas: GAS_LIMIT
3496
- });
3497
3497
  }
3498
3498
  const depositMsg = {
3499
3499
  recipient_id: csna,
@@ -3507,10 +3507,14 @@ function executeBTCDepositAndAction(_0) {
3507
3507
  { deposit_msg: depositMsg }
3508
3508
  );
3509
3509
  const _feeRate = feeRate || (yield getBtcGasPrice());
3510
- const sendAmount = (arrearsAction == null ? void 0 : arrearsAction.amount) && fixedAmount ? new import_big.default(depositAmount).plus((arrearsAction == null ? void 0 : arrearsAction.amount) || 0).toString() : depositAmount;
3511
- console.log("user deposit address:", userDepositAddress);
3512
- console.log("send amount:", sendAmount);
3513
- console.log("fee rate:", _feeRate);
3510
+ console.table({
3511
+ "User Deposit Address": userDepositAddress,
3512
+ "Deposit Amount": depositAmount,
3513
+ "Protocol Fee": protocolFee,
3514
+ "Repay Amount": repayAmount,
3515
+ "Total Deposit Amount": totalDepositAmount,
3516
+ "Fee Rate": _feeRate
3517
+ });
3514
3518
  const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
3515
3519
  yield preReceiveDepositMsg(config.base_url, {
3516
3520
  btcPublicKey,
@@ -3518,7 +3522,7 @@ function executeBTCDepositAndAction(_0) {
3518
3522
  postActions: postActionsStr,
3519
3523
  extraMsg: depositMsg.extra_msg
3520
3524
  });
3521
- const txHash = yield sendBitcoin(userDepositAddress, Number(sendAmount), _feeRate);
3525
+ const txHash = yield sendBitcoin(userDepositAddress, totalDepositAmount, _feeRate);
3522
3526
  yield receiveDepositMsg(config.base_url, {
3523
3527
  btcPublicKey,
3524
3528
  txHash,
@@ -3563,6 +3567,148 @@ Sign up now: <a style="color: #ff7a00; text-decoration: underline;" href="https:
3563
3567
  }
3564
3568
  });
3565
3569
  }
3570
+ function getWithdrawTransaction(_0) {
3571
+ return __async(this, arguments, function* ({
3572
+ amount,
3573
+ feeRate,
3574
+ env = "mainnet"
3575
+ }) {
3576
+ const provider = getBtcProvider();
3577
+ const btcAddress = yield provider.account;
3578
+ const config = yield getConfig(env);
3579
+ const brgConfig = yield nearCall(config.bridgeContractId, "get_config", {});
3580
+ if (brgConfig.min_withdraw_amount) {
3581
+ if (Number(amount) < Number(brgConfig.min_withdraw_amount)) {
3582
+ throw new Error("Mini withdraw amount is " + brgConfig.min_withdraw_amount);
3583
+ }
3584
+ }
3585
+ const feePercent = Number(brgConfig.withdraw_bridge_fee.fee_rate) * Number(amount);
3586
+ const withdrawFee = feePercent > Number(brgConfig.withdraw_bridge_fee.fee_min) ? feePercent : Number(brgConfig.withdraw_bridge_fee.fee_min);
3587
+ const allUTXO = yield nearCall(config.bridgeContractId, "get_utxos_paged", {});
3588
+ if (!allUTXO || Object.keys(allUTXO).length === 0) {
3589
+ throw new Error("The network is busy, please try again later.");
3590
+ }
3591
+ const utxos = Object.keys(allUTXO).map((key) => {
3592
+ const txid = key.split("@");
3593
+ return {
3594
+ txid: txid[0],
3595
+ vout: allUTXO[key].vout,
3596
+ value: Number(allUTXO[key].balance),
3597
+ script: allUTXO[key].script
3598
+ };
3599
+ });
3600
+ const _feeRate = feeRate || (yield getBtcGasPrice());
3601
+ const { inputs, outputs, fee } = (0, import_coinselect.default)(
3602
+ utxos,
3603
+ [{ address: btcAddress, value: Number(amount) }],
3604
+ Math.ceil(_feeRate)
3605
+ );
3606
+ if (!outputs || !inputs) {
3607
+ throw new Error("The network is busy, please try again later.");
3608
+ }
3609
+ const maxBtcFee = Number(brgConfig.max_btc_gas_fee);
3610
+ const newFee = fee;
3611
+ const withdrawChangeAddress = brgConfig.change_address;
3612
+ if (newFee > maxBtcFee) {
3613
+ throw new Error("Gas exceeds maximum value");
3614
+ }
3615
+ let userOutput, noUserOutput;
3616
+ for (let i = 0; i < outputs.length; i++) {
3617
+ const output = outputs[i];
3618
+ if (output.value.toString() === amount.toString()) {
3619
+ userOutput = output;
3620
+ } else {
3621
+ noUserOutput = output;
3622
+ }
3623
+ if (!output.address) {
3624
+ output.address = withdrawChangeAddress;
3625
+ }
3626
+ }
3627
+ userOutput.value = new import_big.default(userOutput.value).minus(newFee).minus(withdrawFee).toNumber();
3628
+ if (noUserOutput) {
3629
+ noUserOutput.value = new import_big.default(noUserOutput.value).plus(newFee).plus(withdrawFee).toNumber();
3630
+ } else {
3631
+ noUserOutput = {
3632
+ address: withdrawChangeAddress,
3633
+ value: new import_big.default(newFee).plus(withdrawFee).toNumber()
3634
+ };
3635
+ outputs.push(noUserOutput);
3636
+ }
3637
+ const insufficientOutput = outputs.some((item) => item.value < 0);
3638
+ if (insufficientOutput) {
3639
+ throw new Error("Not enough gas");
3640
+ }
3641
+ const inputSum = inputs.reduce((sum, cur) => sum + Number(cur.value), 0);
3642
+ const outputSum = outputs.reduce((sum, cur) => sum + Number(cur.value), 0);
3643
+ if (newFee + outputSum !== inputSum) {
3644
+ throw new Error("compute error");
3645
+ }
3646
+ const network = yield getNetwork();
3647
+ const btcNetwork = network === "mainnet" ? import_bitcoinjs_lib.default.networks.bitcoin : import_bitcoinjs_lib.default.networks.testnet;
3648
+ const psbt = new import_bitcoinjs_lib.default.Psbt({ network: btcNetwork });
3649
+ const btcRpcUrl = yield getBtcRpcUrl();
3650
+ for (let i = 0; i < inputs.length; i++) {
3651
+ const input = inputs[i];
3652
+ const txData = yield fetch(`${btcRpcUrl}/tx/${input.txid}`).then((res) => res.json());
3653
+ const inputOptions = {
3654
+ hash: input.txid,
3655
+ index: input.vout,
3656
+ sequence: 4294967293,
3657
+ witnessUtxo: {
3658
+ script: Buffer.from(txData.vout[input.vout].scriptpubkey, "hex"),
3659
+ value: input.value
3660
+ }
3661
+ };
3662
+ psbt.addInput(inputOptions);
3663
+ }
3664
+ outputs.forEach((output) => {
3665
+ psbt.addOutput({
3666
+ address: output.address,
3667
+ value: output.value
3668
+ });
3669
+ });
3670
+ const _inputs = inputs.map((item) => {
3671
+ return `${item.txid}:${item.vout}`;
3672
+ });
3673
+ const txOutputs = psbt.txOutputs.map((item) => {
3674
+ return {
3675
+ script_pubkey: uint8ArrayToHex(item.script),
3676
+ value: item.value
3677
+ };
3678
+ });
3679
+ const msg = {
3680
+ Withdraw: {
3681
+ target_btc_address: btcAddress,
3682
+ input: _inputs,
3683
+ output: txOutputs
3684
+ }
3685
+ };
3686
+ const csna = yield getCsnaAccountId(env);
3687
+ const transaction = {
3688
+ receiverId: config.token,
3689
+ signerId: csna,
3690
+ actions: [
3691
+ {
3692
+ type: "FunctionCall",
3693
+ params: {
3694
+ methodName: "ft_transfer_call",
3695
+ args: {
3696
+ receiver_id: config.bridgeContractId,
3697
+ amount: amount.toString(),
3698
+ msg: JSON.stringify(msg)
3699
+ },
3700
+ gas: "300000000000000",
3701
+ deposit: "1"
3702
+ }
3703
+ }
3704
+ ]
3705
+ };
3706
+ return transaction;
3707
+ });
3708
+ }
3709
+ function uint8ArrayToHex(uint8Array) {
3710
+ return Array.from(uint8Array).map((byte) => byte.toString(16).padStart(2, "0")).join("");
3711
+ }
3566
3712
 
3567
3713
  // src/core/setupBTCWallet.ts
3568
3714
  var { transfer, functionCall } = import_transactions.actionCreators;
@@ -3788,7 +3934,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3788
3934
  const btcContext = window.btcContext;
3789
3935
  const accountId = state.getAccount();
3790
3936
  const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
3791
- yield checkGasTokenArrears(accountInfo, env, true);
3937
+ yield checkGasTokenDebt(accountInfo, env, true);
3792
3938
  const trans = [...params.transactions];
3793
3939
  console.log("raw trans:", trans);
3794
3940
  const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
@@ -3997,7 +4143,7 @@ function setupBTCWallet({
3997
4143
  if (!hasShownNotice) {
3998
4144
  Dialog.alert({
3999
4145
  title: "Notice",
4000
- message: "You are currently using Satoshi Private Mainnet. This is a private version for testing. Please try a small amount of assets in Bridge"
4146
+ message: "You are currently using Satoshi Private Mainnet. This is a private version for testing. Please try a small amount of assets in Ramp"
4001
4147
  });
4002
4148
  localStorage.setItem("satoshi_private_mainnet_notice", "true");
4003
4149
  }
@@ -4026,7 +4172,7 @@ function setupBTCWallet({
4026
4172
 
4027
4173
  // src/index.ts
4028
4174
  var getVersion = () => {
4029
- return "0.4.4-beta";
4175
+ return "0.4.6-beta";
4030
4176
  };
4031
4177
  if (typeof window !== "undefined") {
4032
4178
  window.__BTC_WALLET_VERSION = getVersion();