btc-wallet 0.3.5 → 0.3.6

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/config.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export declare const walletConfig: Record<string, {
2
2
  base_url: string;
3
3
  token: string;
4
- contractId: string;
4
+ accountContractId: string;
5
+ bridgeContractId: string;
5
6
  walletUrl: string;
6
7
  }>;
7
8
  export declare const nearRpcUrls: {
@@ -3,14 +3,23 @@ export declare function getBtcBalance(): Promise<{
3
3
  rawBalance: any;
4
4
  balance: number;
5
5
  }>;
6
- export declare function sendBitcoin(address: string, amount: string, feeRate: number): Promise<string>;
7
- interface ExecuteBurrowSupplyParams {
8
- /** btc amount, e.g. 0.01 */
9
- amount: string;
6
+ export declare function sendBitcoin(address: string, amount: number, feeRate: number): Promise<string>;
7
+ interface ExecuteBTCDepositAndActionParams {
8
+ action: {
9
+ receiver_id: string;
10
+ amount: string;
11
+ msg: string;
12
+ };
10
13
  /** fee rate, if not provided, will use the recommended fee rate from the btc node */
11
14
  feeRate?: number;
12
15
  /** is dev environment */
13
16
  isDev?: boolean;
14
17
  }
15
- export declare function executeBurrowSupply({ amount, feeRate, isDev, }: ExecuteBurrowSupplyParams): Promise<void>;
18
+ export declare function executeBTCDepositAndAction({ action, feeRate, isDev, }: ExecuteBTCDepositAndActionParams): Promise<{
19
+ result: string;
20
+ error?: undefined;
21
+ } | {
22
+ result: string;
23
+ error: any;
24
+ }>;
16
25
  export {};
@@ -4,10 +4,10 @@ export declare function BtcWalletSelectorContextProvider({ children, }: {
4
4
  autoConnect?: boolean;
5
5
  }): import("react/jsx-runtime").JSX.Element;
6
6
  export declare function useBtcWalletSelector(): {
7
- login: () => Promise<string | null>;
7
+ login: () => Promise<string>;
8
8
  autoConnect: () => Promise<void>;
9
9
  logout: () => void;
10
- account: string | null;
10
+ account: string;
11
11
  getPublicKey: () => any;
12
12
  signMessage: (msg: string) => any;
13
13
  getContext: () => any;
package/dist/index.js CHANGED
@@ -90,7 +90,7 @@ __export(src_exports, {
90
90
  UnisatConnector: () => UnisatConnector,
91
91
  WizzConnector: () => WizzConnector,
92
92
  XverseConnector: () => XverseConnector,
93
- executeBurrowSupply: () => executeBurrowSupply,
93
+ executeBTCDepositAndAction: () => executeBTCDepositAndAction,
94
94
  getBtcBalance: () => getBtcBalance,
95
95
  getBtcGasPrice: () => getBtcGasPrice,
96
96
  getVersion: () => getVersion,
@@ -2497,7 +2497,7 @@ function useBtcWalletSelector() {
2497
2497
  publicKey.current = res;
2498
2498
  });
2499
2499
  }
2500
- }, [provider]);
2500
+ }, [getPublicKey, provider]);
2501
2501
  (0, import_react11.useEffect)(() => {
2502
2502
  signMessageFn.current = signMessage;
2503
2503
  }, [signMessage]);
@@ -2519,18 +2519,15 @@ function useBtcWalletSelector() {
2519
2519
  connector.removeListener("accountsChanged", fn);
2520
2520
  }
2521
2521
  };
2522
- }, [connector]);
2522
+ }, [connector, context, getPublicKey]);
2523
2523
  const hook = (0, import_react11.useMemo)(() => {
2524
2524
  return {
2525
2525
  login: () => __async(this, null, function* () {
2526
- const account = accounts && accounts.length ? accounts[0] : null;
2527
- if (account) {
2528
- return account;
2529
- }
2530
- if (openConnectModal) {
2531
- yield openConnectModal();
2526
+ const account = accounts == null ? void 0 : accounts[0];
2527
+ if (!account) {
2528
+ openConnectModal == null ? void 0 : openConnectModal();
2532
2529
  }
2533
- return null;
2530
+ return account;
2534
2531
  }),
2535
2532
  autoConnect: () => __async(this, null, function* () {
2536
2533
  requestDirectAccount(connectorRef.current).catch((e) => {
@@ -2538,13 +2535,13 @@ function useBtcWalletSelector() {
2538
2535
  });
2539
2536
  }),
2540
2537
  logout: () => {
2541
- const accountId = accounts && accounts.length ? accounts[0] : null;
2538
+ const accountId = accounts == null ? void 0 : accounts[0];
2542
2539
  if (!accountId)
2543
2540
  return;
2544
2541
  disconnect == null ? void 0 : disconnect();
2545
2542
  context.emit("btcLogOut");
2546
2543
  },
2547
- account: accounts && accounts.length ? accounts[0] : null,
2544
+ account: accounts == null ? void 0 : accounts[0],
2548
2545
  getPublicKey: () => {
2549
2546
  return publicKey.current;
2550
2547
  },
@@ -2570,7 +2567,7 @@ function useBtcWalletSelector() {
2570
2567
  }
2571
2568
 
2572
2569
  // src/core/setupBTCWallet.ts
2573
- var import_near_api_js = require("near-api-js");
2570
+ var import_near_api_js2 = require("near-api-js");
2574
2571
  var import_transactions = require("@near-js/transactions");
2575
2572
  var import_key_pair = require("near-api-js/lib/utils/key_pair");
2576
2573
  var import_transaction = require("near-api-js/lib/transaction");
@@ -2725,20 +2722,23 @@ function removeWalletButton() {
2725
2722
  var walletConfig = {
2726
2723
  dev: {
2727
2724
  base_url: "https://api.dev.satoshibridge.top",
2728
- token: "nbtc1-nsp.testnet",
2729
- contractId: "dev1-nsp.testnet",
2725
+ token: "nbtc-dev.testnet",
2726
+ accountContractId: "acc-dev.testnet",
2727
+ bridgeContractId: "brg-dev.testnet",
2730
2728
  walletUrl: "https://wallet-dev.satoshibridge.top"
2731
2729
  },
2732
2730
  testnet: {
2733
2731
  base_url: "https://api.testnet.satoshibridge.top",
2734
2732
  token: "nbtc2-nsp.testnet",
2735
- contractId: "dev2-nsp.testnet",
2733
+ accountContractId: "dev2-nsp.testnet",
2734
+ bridgeContractId: "brg2-nsp.testnet",
2736
2735
  walletUrl: "https://wallet-test.satoshibridge.top"
2737
2736
  },
2738
2737
  mainnet: {
2739
2738
  base_url: "https://api.mainnet.satoshibridge.top",
2740
2739
  token: "",
2741
- contractId: "",
2740
+ accountContractId: "",
2741
+ bridgeContractId: "",
2742
2742
  walletUrl: "https://wallet.satoshibridge.top"
2743
2743
  }
2744
2744
  };
@@ -2750,8 +2750,8 @@ var nearRpcUrls = {
2750
2750
  "https://near.drpc.org"
2751
2751
  ],
2752
2752
  testnet: [
2753
- "https://near-testnet.lava.build",
2754
2753
  "https://rpc.testnet.near.org",
2754
+ "https://near-testnet.lava.build",
2755
2755
  "https://near-testnet.drpc.org"
2756
2756
  ]
2757
2757
  };
@@ -2830,6 +2830,58 @@ function request(url, options) {
2830
2830
  });
2831
2831
  }
2832
2832
 
2833
+ // src/utils/nearUtils.ts
2834
+ var import_near_api_js = require("near-api-js");
2835
+ function nearCallFunction(contractId, methodName, args, options) {
2836
+ return __async(this, null, function* () {
2837
+ const nearProvider = (options == null ? void 0 : options.provider) || new import_near_api_js.providers.FailoverRpcProvider(
2838
+ nearRpcUrls[options == null ? void 0 : options.network].map(
2839
+ (url) => new import_near_api_js.providers.JsonRpcProvider({ url })
2840
+ )
2841
+ );
2842
+ const res = yield nearProvider.query({
2843
+ request_type: "call_function",
2844
+ account_id: contractId,
2845
+ method_name: methodName,
2846
+ args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
2847
+ finality: "final"
2848
+ });
2849
+ return JSON.parse(Buffer.from(res.result).toString());
2850
+ });
2851
+ }
2852
+ function pollTransactionStatuses(network, hashes) {
2853
+ return __async(this, null, function* () {
2854
+ const provider = new import_near_api_js.providers.FailoverRpcProvider(
2855
+ Object.values(nearRpcUrls[network]).map(
2856
+ (url) => new import_near_api_js.providers.JsonRpcProvider({ url })
2857
+ )
2858
+ );
2859
+ const maxAttempts = 3;
2860
+ const pollStatus = (hash) => __async(this, null, function* () {
2861
+ let attempt = 0;
2862
+ while (attempt < maxAttempts) {
2863
+ attempt++;
2864
+ try {
2865
+ const result = yield provider.txStatus(hash, "unused", "FINAL");
2866
+ if (result && result.status) {
2867
+ console.log(`Transaction ${hash} result:`, result);
2868
+ return result;
2869
+ }
2870
+ } catch (error) {
2871
+ console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
2872
+ }
2873
+ if (attempt === maxAttempts) {
2874
+ throw new Error(`Transaction not found after max attempts: ${hash}`);
2875
+ }
2876
+ yield delay(1e4);
2877
+ console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
2878
+ }
2879
+ });
2880
+ const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
2881
+ return results;
2882
+ });
2883
+ }
2884
+
2833
2885
  // src/core/setupBTCWallet.ts
2834
2886
  var { transfer, functionCall } = import_transactions.actionCreators;
2835
2887
  var state = {
@@ -2927,28 +2979,23 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
2927
2979
  }
2928
2980
  }), 500);
2929
2981
  }
2930
- function viewMethod(_02) {
2931
- return __async(this, arguments, function* ({ method, args = {} }) {
2932
- const res = yield provider.query({
2933
- request_type: "call_function",
2934
- account_id: currentConfig.contractId,
2935
- method_name: method,
2936
- args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
2937
- finality: "optimistic"
2938
- });
2939
- return JSON.parse(Buffer.from(res.result).toString());
2982
+ function nearCall2(contractId, methodName, args) {
2983
+ return __async(this, null, function* () {
2984
+ return nearCallFunction(contractId, methodName, args, { provider });
2940
2985
  });
2941
2986
  }
2942
2987
  function getNearAccountByBtcPublicKey(btcPublicKey) {
2943
2988
  return __async(this, null, function* () {
2944
- const nearTempAddress = yield viewMethod({
2945
- method: "get_chain_signature_near_account",
2946
- args: { btc_public_key: btcPublicKey }
2947
- });
2948
- const nearTempPublicKey = yield viewMethod({
2949
- method: "get_chain_signature_near_account_public_key",
2950
- args: { btc_public_key: btcPublicKey }
2951
- });
2989
+ const nearTempAddress = yield nearCall2(
2990
+ currentConfig.accountContractId,
2991
+ "get_chain_signature_near_account_id",
2992
+ { btc_public_key: btcPublicKey }
2993
+ );
2994
+ const nearTempPublicKey = yield nearCall2(
2995
+ currentConfig.accountContractId,
2996
+ "get_chain_signature_near_account_public_key",
2997
+ { btc_public_key: btcPublicKey }
2998
+ );
2952
2999
  state.saveAccount(nearTempAddress);
2953
3000
  state.savePublicKey(nearTempPublicKey);
2954
3001
  state.saveBtcPublicKey(btcPublicKey);
@@ -3048,11 +3095,14 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3048
3095
  nonce: BigInt(rawAccessKey.nonce || 0)
3049
3096
  });
3050
3097
  const publicKeyFormat = import_key_pair.PublicKey.from(publicKey);
3051
- const nearNonceApi = yield getNearNonceFromApi(currentConfig.base_url, accountId);
3098
+ const { result_data: nearNonceFromApi } = yield getNearNonceFromApi(
3099
+ currentConfig.base_url,
3100
+ accountId
3101
+ );
3052
3102
  const newTransactions = params.transactions.map((transaction, index) => {
3053
3103
  let nearNonceNumber = accessKey.nonce + BigInt(1);
3054
- if (nearNonceApi) {
3055
- nearNonceNumber = BigInt(nearNonceApi.result_data) > nearNonceNumber ? BigInt(nearNonceApi.result_data) : nearNonceNumber;
3104
+ if (nearNonceFromApi) {
3105
+ nearNonceNumber = BigInt(nearNonceFromApi) > nearNonceNumber ? BigInt(nearNonceFromApi) : nearNonceNumber;
3056
3106
  }
3057
3107
  const newActions = transaction.actions.map((action) => {
3058
3108
  switch (action.type) {
@@ -3067,7 +3117,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3067
3117
  return transfer(BigInt(action.params.deposit));
3068
3118
  }
3069
3119
  }).filter(Boolean);
3070
- const _transaction = import_near_api_js.transactions.createTransaction(
3120
+ const _transaction = import_near_api_js2.transactions.createTransaction(
3071
3121
  accountId,
3072
3122
  publicKeyFormat,
3073
3123
  transaction.receiverId,
@@ -3084,20 +3134,34 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3084
3134
  const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
3085
3135
  return { txBytes, txHex, hash };
3086
3136
  });
3087
- const accountInfo = yield viewMethod({
3088
- method: "get_account",
3089
- args: { account_id: accountId }
3090
- });
3091
- const nonceApi = yield getNonceFromApi(currentConfig.base_url, accountId);
3092
- const nonce = Number(nonceApi == null ? void 0 : nonceApi.result_data) > Number(accountInfo.nonce) ? String(nonceApi == null ? void 0 : nonceApi.result_data) : String(accountInfo.nonce);
3137
+ const accountInfo = yield nearCall2(
3138
+ currentConfig.accountContractId,
3139
+ "get_account",
3140
+ { account_id: accountId }
3141
+ );
3142
+ const { result_data: nonceFromApi } = yield getNonceFromApi(
3143
+ currentConfig.base_url,
3144
+ accountId
3145
+ );
3146
+ const nonce = Number(nonceFromApi) > Number(accountInfo.nonce) ? String(nonceFromApi) : String(accountInfo.nonce);
3093
3147
  const intention = {
3094
3148
  chain_id: "397",
3095
3149
  csna: accountId,
3096
3150
  near_transactions: newTransactions.map((t) => t.txHex),
3097
3151
  gas_token: currentConfig.token,
3098
3152
  gas_limit: "3000",
3153
+ use_near_pay_gas: false,
3099
3154
  nonce
3100
3155
  };
3156
+ const nearAccount = yield provider.query({
3157
+ request_type: "view_account",
3158
+ account_id: accountId,
3159
+ finality: "final"
3160
+ });
3161
+ const availableBalance = parseFloat(nearAccount.amount) / __pow(10, 24);
3162
+ if (availableBalance > 0.2) {
3163
+ intention.use_near_pay_gas = true;
3164
+ }
3101
3165
  const strIntention = JSON.stringify(intention);
3102
3166
  const signature = yield btcContext.signMessage(strIntention);
3103
3167
  const result = yield uploadBTCTx(currentConfig.base_url, {
@@ -3182,41 +3246,8 @@ function toHex(originalString) {
3182
3246
  hexString = hexString.replace(/(^0+)/g, "");
3183
3247
  return hexString;
3184
3248
  }
3185
- function pollTransactionStatuses(network, hashes) {
3186
- return __async(this, null, function* () {
3187
- const provider = new import_near_api_js.providers.FailoverRpcProvider(
3188
- Object.values(nearRpcUrls[network]).map(
3189
- (url) => new import_near_api_js.providers.JsonRpcProvider({ url })
3190
- )
3191
- );
3192
- const maxAttempts = 3;
3193
- const pollStatus = (hash) => __async(this, null, function* () {
3194
- let attempt = 0;
3195
- while (attempt < maxAttempts) {
3196
- attempt++;
3197
- try {
3198
- const result = yield provider.txStatus(hash, "unused", "FINAL");
3199
- if (result && result.status) {
3200
- console.log(`Transaction ${hash} result:`, result);
3201
- return result;
3202
- }
3203
- } catch (error) {
3204
- console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
3205
- }
3206
- if (attempt === maxAttempts) {
3207
- throw new Error(`Transaction not found after max attempts: ${hash}`);
3208
- }
3209
- yield delay(1e4);
3210
- console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
3211
- }
3212
- });
3213
- const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
3214
- return results;
3215
- });
3216
- }
3217
3249
 
3218
3250
  // src/core/btcUtils.ts
3219
- var import_near_api_js2 = require("near-api-js");
3220
3251
  var import_big = __toESM(require("big.js"), 1);
3221
3252
  function getBtcProvider() {
3222
3253
  if (typeof window === "undefined" || !window.btcContext) {
@@ -3237,55 +3268,39 @@ function getBtcRpcUrl() {
3237
3268
  return btcRpcUrls[network];
3238
3269
  });
3239
3270
  }
3240
- function nearViewMethod(contractId, methodName, args) {
3271
+ function nearCall(contractId, methodName, args) {
3241
3272
  return __async(this, null, function* () {
3242
3273
  const network = yield getNetwork();
3243
- const nearProvider = new import_near_api_js2.providers.FailoverRpcProvider(
3244
- nearRpcUrls[network].map(
3245
- (url) => new import_near_api_js2.providers.JsonRpcProvider({ url })
3246
- )
3247
- );
3248
- const res = yield nearProvider.query({
3249
- request_type: "call_function",
3250
- account_id: contractId,
3251
- method_name: methodName,
3252
- args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
3253
- finality: "optimistic"
3254
- });
3255
- return JSON.parse(Buffer.from(res.result).toString());
3256
- });
3257
- }
3258
- function getDepositAddress(btcPublicKey, contractId) {
3259
- return __async(this, null, function* () {
3260
- const res = yield nearViewMethod(contractId, "get_user_dapp_deposit_address", {
3261
- deposit_type: {
3262
- BtcPublicKey: { btc_public_key: btcPublicKey, dapp_operation: "Burrowland->Supply" }
3263
- }
3264
- });
3265
- return res;
3274
+ return nearCallFunction(contractId, methodName, args, { network });
3266
3275
  });
3267
3276
  }
3268
3277
  function receiveDepositMsg(_0, _1) {
3269
3278
  return __async(this, arguments, function* (baseUrl, {
3270
3279
  btcPublicKey,
3271
3280
  txHash,
3272
- depositType = 1
3281
+ depositType = 1,
3282
+ postActions,
3283
+ extraMsg
3273
3284
  }) {
3274
3285
  const res = yield request(`${baseUrl}/v1/receiveDepositMsg`, {
3275
3286
  method: "POST",
3276
- body: { btcPublicKey, txHash, depositType }
3287
+ body: { btcPublicKey, txHash, depositType, postActions, extraMsg }
3277
3288
  });
3289
+ console.log("receiveDepositMsg resp:", res);
3278
3290
  return res;
3279
3291
  });
3280
3292
  }
3281
3293
  function checkTransactionStatus(baseUrl, txHash) {
3282
3294
  return __async(this, null, function* () {
3283
- const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`, {
3284
- timeout: 6e4,
3285
- pollingInterval: 5e3,
3286
- maxPollingAttempts: 10,
3287
- shouldStopPolling: (res2) => res2.result_code === 0
3288
- });
3295
+ const res = yield request(
3296
+ `${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}&fromChainId=1`,
3297
+ {
3298
+ timeout: 6e4,
3299
+ pollingInterval: 5e3,
3300
+ maxPollingAttempts: 10,
3301
+ shouldStopPolling: (res2) => res2.result_code === 0
3302
+ }
3303
+ );
3289
3304
  return res;
3290
3305
  });
3291
3306
  }
@@ -3304,7 +3319,6 @@ function getBtcGasPrice() {
3304
3319
  }
3305
3320
  function getBtcBalance() {
3306
3321
  return __async(this, null, function* () {
3307
- var _a;
3308
3322
  const { account } = yield retryOperation(getBtcProvider, (res2) => !!res2.account);
3309
3323
  if (!account) {
3310
3324
  console.error("BTC Account is not available.");
@@ -3312,10 +3326,7 @@ function getBtcBalance() {
3312
3326
  }
3313
3327
  const btcRpcUrl = yield getBtcRpcUrl();
3314
3328
  const res = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res2) => res2.json());
3315
- const rawBalance = (_a = res.filter((item) => {
3316
- var _a2;
3317
- return (_a2 = item == null ? void 0 : item.status) == null ? void 0 : _a2.confirmed;
3318
- })) == null ? void 0 : _a.reduce((acc, cur) => acc + cur.value, 0);
3329
+ const rawBalance = res == null ? void 0 : res.reduce((acc, cur) => acc + cur.value, 0);
3319
3330
  const balance = rawBalance / __pow(10, 8);
3320
3331
  return { rawBalance, balance };
3321
3332
  });
@@ -3323,14 +3334,13 @@ function getBtcBalance() {
3323
3334
  function sendBitcoin(address, amount, feeRate) {
3324
3335
  return __async(this, null, function* () {
3325
3336
  const { sendBitcoin: sendBitcoin2 } = getBtcProvider();
3326
- const satoshis = new import_big.default(amount).mul(__pow(10, 8)).toNumber();
3327
- const txHash = yield sendBitcoin2(address, satoshis, { feeRate });
3337
+ const txHash = yield sendBitcoin2(address, amount, { feeRate });
3328
3338
  return txHash;
3329
3339
  });
3330
3340
  }
3331
- function executeBurrowSupply(_0) {
3341
+ function executeBTCDepositAndAction(_0) {
3332
3342
  return __async(this, arguments, function* ({
3333
- amount,
3343
+ action,
3334
3344
  feeRate,
3335
3345
  isDev = false
3336
3346
  }) {
@@ -3339,26 +3349,75 @@ function executeBurrowSupply(_0) {
3339
3349
  const network = yield getNetwork();
3340
3350
  const config = walletConfig[isDev ? "dev" : network];
3341
3351
  const btcPublicKey = yield getPublicKey();
3352
+ const _action = Object.assign({}, action);
3342
3353
  if (!btcPublicKey) {
3343
3354
  throw new Error("BTC Public Key is not available.");
3344
3355
  }
3345
- const address = yield getDepositAddress(btcPublicKey, config.contractId);
3356
+ if (!_action.receiver_id) {
3357
+ throw new Error("action.receiver_id is required");
3358
+ }
3359
+ if (!_action.amount || !new import_big.default(_action.amount || 0).gt(0)) {
3360
+ throw new Error("action.amount is required and must be greater than 0");
3361
+ }
3362
+ const csna = yield nearCall(
3363
+ config.accountContractId,
3364
+ "get_chain_signature_near_account_id",
3365
+ {
3366
+ btc_public_key: btcPublicKey
3367
+ }
3368
+ );
3369
+ _action.amount = new import_big.default(_action.amount).toString();
3370
+ _action.gas = new import_big.default(100).mul(__pow(10, 12)).toFixed(0);
3371
+ const depositMsg = {
3372
+ recipient_id: csna,
3373
+ post_actions: [_action]
3374
+ };
3375
+ const registerRes = yield nearCall(action.receiver_id, "storage_balance_of", {
3376
+ account_id: csna
3377
+ });
3378
+ if (!(registerRes == null ? void 0 : registerRes.available)) {
3379
+ const storageDepositMsg = {
3380
+ storage_deposit_msg: {
3381
+ contract_id: action.receiver_id,
3382
+ deposit: new import_big.default(0.25).mul(__pow(10, 24)).toFixed(0),
3383
+ registration_only: true
3384
+ },
3385
+ btc_public_key: btcPublicKey
3386
+ };
3387
+ depositMsg.extra_msg = JSON.stringify(storageDepositMsg);
3388
+ }
3389
+ console.log("depositMsg", depositMsg);
3390
+ const userDepositAddress = yield nearCall(
3391
+ config.bridgeContractId,
3392
+ "get_user_deposit_address",
3393
+ { deposit_msg: depositMsg }
3394
+ );
3395
+ console.log("userDepositAddress", userDepositAddress);
3346
3396
  const _feeRate = feeRate || (yield getBtcGasPrice());
3347
- console.log("feeRate", _feeRate);
3348
- const txHash = yield sendBitcoin(address, amount, _feeRate);
3349
- const receiveDepositMsgRes = yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
3350
- console.log("receiveDepositMsg resp:", receiveDepositMsgRes);
3397
+ const txHash = yield sendBitcoin(
3398
+ userDepositAddress,
3399
+ new import_big.default(action.amount).toNumber(),
3400
+ _feeRate
3401
+ );
3402
+ yield receiveDepositMsg(config.base_url, {
3403
+ btcPublicKey,
3404
+ txHash,
3405
+ postActions: JSON.stringify(depositMsg.post_actions),
3406
+ extraMsg: depositMsg.extra_msg || ""
3407
+ });
3351
3408
  const checkTransactionStatusRes = yield checkTransactionStatus(config.base_url, txHash);
3352
3409
  console.log("checkTransactionStatus resp:", checkTransactionStatusRes);
3410
+ return checkTransactionStatusRes.result_code === 0 ? { result: "success" } : { result: "failed", error: checkTransactionStatusRes.result_message };
3353
3411
  } catch (error) {
3354
3412
  console.error("Error executing Bridge+BurrowSupply:", error);
3413
+ return { result: "failed", error: error.message };
3355
3414
  }
3356
3415
  });
3357
3416
  }
3358
3417
 
3359
3418
  // src/index.ts
3360
3419
  var getVersion = () => {
3361
- return "0.3.5";
3420
+ return "0.3.6";
3362
3421
  };
3363
3422
  if (typeof window !== "undefined") {
3364
3423
  window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();