btc-wallet 0.3.23 → 0.3.26
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +78 -33
- package/dist/config.d.ts +2 -1
- package/dist/core/btcUtils.d.ts +9 -8
- package/dist/core/setupBTCWallet.d.ts +3 -2
- package/dist/index.js +83 -83
- package/dist/index.js.map +4 -4
- package/dist/utils/initWalletButton.d.ts +2 -1
- package/esm/index.js +83 -83
- package/esm/index.js.map +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,29 +1,44 @@
|
|
1
1
|
# BTC Wallet
|
2
2
|
|
3
|
-
BTC Wallet is a toolkit that enables
|
4
|
-
|
5
|
-
## Features
|
6
|
-
|
7
|
-
- **NEAR Integration**: Leverage the Satoshi protocol to use Bitcoin on the NEAR blockchain.
|
3
|
+
BTC Wallet is a toolkit that enables Bitcoin usage on the NEAR blockchain through the Satoshi protocol.
|
8
4
|
|
9
5
|
## Installation
|
10
6
|
|
11
|
-
Install `btc-wallet` using npm or yarn:
|
12
|
-
|
13
7
|
```bash
|
14
8
|
pnpm install btc-wallet
|
15
|
-
or
|
9
|
+
# or
|
16
10
|
yarn add btc-wallet
|
17
11
|
```
|
18
12
|
|
19
|
-
##
|
13
|
+
## API Reference
|
20
14
|
|
21
|
-
###
|
15
|
+
### `BtcWalletSelectorContextProvider` and `setupBTCWallet`
|
22
16
|
|
23
|
-
|
17
|
+
Initialize and integrate BTC wallet with NEAR wallet selector.
|
18
|
+
|
19
|
+
```typescript
|
20
|
+
// 1. Setup wallet selector with BTC wallet module
|
21
|
+
import { setupWalletSelector } from '@near-wallet-selector/core';
|
22
|
+
import { setupBTCWallet } from 'btc-wallet';
|
23
|
+
|
24
|
+
const selector = await setupWalletSelector({
|
25
|
+
network: 'mainnet', // or 'testnet'
|
26
|
+
debug: true,
|
27
|
+
modules: [
|
28
|
+
setupBTCWallet({
|
29
|
+
iconUrl?: string, // optional: custom wallet icon URL
|
30
|
+
deprecated?: boolean, // optional: mark as deprecated
|
31
|
+
autoConnect?: boolean, // optional: enable auto-connect, defaults to true
|
32
|
+
syncLogOut?: boolean, // optional: sync logout across tabs, defaults to true
|
33
|
+
env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev' // optional: defaults to NEAR network environment
|
34
|
+
}),
|
35
|
+
// setup other wallets...
|
36
|
+
],
|
37
|
+
});
|
38
|
+
|
39
|
+
// 2. Wrap your app with BtcWalletSelectorContextProvider
|
40
|
+
import { BtcWalletSelectorContextProvider } from 'btc-wallet';
|
24
41
|
|
25
|
-
```javascript
|
26
|
-
import BtcWalletSelectorContextProvider from 'btc-wallet';
|
27
42
|
function App() {
|
28
43
|
return (
|
29
44
|
<BtcWalletSelectorContextProvider>
|
@@ -33,31 +48,61 @@ function App() {
|
|
33
48
|
}
|
34
49
|
```
|
35
50
|
|
36
|
-
###
|
51
|
+
### `executeBTCDepositAndAction`
|
52
|
+
|
53
|
+
Execute a native BTC deposit to receive corresponding BTC tokens on NEAR through the Satoshi bridge. You must provide either `action` or `amount`, but not both.
|
54
|
+
|
55
|
+
```typescript
|
56
|
+
interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
|
57
|
+
// Option 1: For dApp one-click BTC deposit and action
|
58
|
+
action?: {
|
59
|
+
receiver_id: string; // receiver account on NEAR
|
60
|
+
amount: string; // amount to deposit
|
61
|
+
msg: string; // message for the transaction
|
62
|
+
};
|
63
|
+
|
64
|
+
// Option 2: For direct Satoshi bridge deposit
|
65
|
+
amount?: string; // amount to deposit to Satoshi bridge
|
66
|
+
|
67
|
+
// Common optional parameters
|
68
|
+
feeRate?: number; // optional: custom fee rate for the BTC transaction
|
69
|
+
fixedAmount?: boolean; // optional: whether to use fixed amount
|
70
|
+
env?: 'mainnet' | 'testnet' | 'private_mainnet' | 'dev'; // optional: defaults to NEAR network environment
|
71
|
+
pollResult?: T; // optional: whether to poll for transaction result
|
72
|
+
}
|
37
73
|
|
38
|
-
|
74
|
+
// Example 1: dApp one-click BTC deposit
|
75
|
+
await executeBTCDepositAndAction({
|
76
|
+
action: {
|
77
|
+
receiver_id: 'account.near',
|
78
|
+
amount: '1000000', // in smallest units
|
79
|
+
msg: 'Deposit'
|
80
|
+
},
|
81
|
+
feeRate: 5
|
82
|
+
});
|
39
83
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
network: 'mainnet', // or 'testnet'
|
45
|
-
modules: [setupBTCWallet()],
|
84
|
+
// Example 2: Direct Satoshi bridge deposit
|
85
|
+
await executeBTCDepositAndAction({
|
86
|
+
amount: '1000000', // amount to deposit to Satoshi bridge
|
87
|
+
feeRate: 5
|
46
88
|
});
|
47
89
|
```
|
48
90
|
|
49
|
-
###
|
91
|
+
### `getBtcBalance`
|
50
92
|
|
51
|
-
|
93
|
+
Get the native BTC balance for a given Bitcoin address.
|
52
94
|
|
53
|
-
```
|
54
|
-
import {
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
}).then(() => {
|
59
|
-
console.log('Burrow supply executed successfully');
|
60
|
-
}).catch((error) => {
|
61
|
-
console.error('Error executing Burrow supply:', error);
|
62
|
-
});
|
95
|
+
```typescript
|
96
|
+
import { getBtcBalance } from 'btc-wallet';
|
97
|
+
|
98
|
+
const balance = await getBtcBalance(address: string);
|
99
|
+
// Returns balance in satoshis
|
63
100
|
```
|
101
|
+
|
102
|
+
## Requirements
|
103
|
+
|
104
|
+
- React 17.0.0 or higher
|
105
|
+
|
106
|
+
## License
|
107
|
+
|
108
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
package/dist/config.d.ts
CHANGED
package/dist/core/btcUtils.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import type { ENV } from '../config';
|
1
2
|
import type { FinalExecutionOutcome } from '@near-wallet-selector/core';
|
2
3
|
export interface DebtInfo {
|
3
4
|
gas_token_id: string;
|
@@ -10,14 +11,14 @@ export declare function getAccountInfo(csna: string, accountContractId: string):
|
|
10
11
|
gas_token: Record<string, string>;
|
11
12
|
debt_info?: DebtInfo;
|
12
13
|
} | undefined>;
|
13
|
-
export declare function checkGasTokenBalance(csna: string, gasToken: string, minAmount: string,
|
14
|
+
export declare function checkGasTokenBalance(csna: string, gasToken: string, minAmount: string, env: ENV): Promise<void>;
|
14
15
|
type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
|
15
16
|
receiver_id: string;
|
16
17
|
amount: string;
|
17
18
|
msg: string;
|
18
19
|
} | undefined;
|
19
|
-
export declare function checkGasTokenArrears<T extends boolean>(debtInfo: DebtInfo | undefined,
|
20
|
-
export declare function queryGasTokenArrears(
|
20
|
+
export declare function checkGasTokenArrears<T extends boolean>(debtInfo: DebtInfo | undefined, env: ENV, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
|
21
|
+
export declare function queryGasTokenArrears(env: ENV): Promise<DebtInfo | undefined>;
|
21
22
|
export declare function getBtcGasPrice(): Promise<number>;
|
22
23
|
export declare function getBtcBalance(): Promise<{
|
23
24
|
rawBalance: number;
|
@@ -32,17 +33,17 @@ export declare function getBtcBalance(): Promise<{
|
|
32
33
|
}>;
|
33
34
|
export declare function sendBitcoin(address: string, amount: number, feeRate: number): Promise<string>;
|
34
35
|
export declare function estimateDepositAmount(amount: string, option?: {
|
35
|
-
|
36
|
+
env?: ENV;
|
36
37
|
}): Promise<number>;
|
37
38
|
export declare function getDepositAmount(amount: string, option?: {
|
38
39
|
isEstimate?: boolean;
|
39
|
-
|
40
|
+
env?: ENV;
|
40
41
|
}): Promise<{
|
41
42
|
depositAmount: number;
|
42
43
|
receiveAmount: number;
|
43
44
|
fee: number;
|
44
45
|
}>;
|
45
|
-
export declare function getCsnaAccountId(
|
46
|
+
export declare function getCsnaAccountId(env: ENV): Promise<string>;
|
46
47
|
interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
|
47
48
|
action?: {
|
48
49
|
receiver_id: string;
|
@@ -52,12 +53,12 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
|
|
52
53
|
amount?: string;
|
53
54
|
feeRate?: number;
|
54
55
|
fixedAmount?: boolean;
|
55
|
-
|
56
|
+
env?: ENV;
|
56
57
|
pollResult?: T;
|
57
58
|
}
|
58
59
|
/**
|
59
60
|
* @param T - if true, return the poll result, otherwise return the btcTxHash
|
60
61
|
*/
|
61
62
|
type ExecuteBTCDepositAndActionReturn<T extends boolean> = T extends true ? FinalExecutionOutcome[] : string;
|
62
|
-
export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, fixedAmount, pollResult,
|
63
|
+
export declare function executeBTCDepositAndAction<T extends boolean = true>({ action, amount, feeRate, fixedAmount, pollResult, env, }: ExecuteBTCDepositAndActionParams<T>): Promise<ExecuteBTCDepositAndActionReturn<T>>;
|
63
64
|
export {};
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { InjectedWallet, WalletModuleFactory } from '@near-wallet-selector/core';
|
2
2
|
import type { useBtcWalletSelector } from './btcWalletSelectorContext';
|
3
|
+
import type { ENV } from '../config';
|
3
4
|
declare global {
|
4
5
|
interface Window {
|
5
6
|
btcContext: ReturnType<typeof useBtcWalletSelector>;
|
@@ -10,9 +11,9 @@ interface BTCWalletParams {
|
|
10
11
|
deprecated?: boolean;
|
11
12
|
autoConnect?: boolean;
|
12
13
|
syncLogOut?: boolean;
|
13
|
-
|
14
|
+
env?: ENV;
|
14
15
|
}
|
15
|
-
export declare function setupBTCWallet({ iconUrl, deprecated, autoConnect, syncLogOut,
|
16
|
+
export declare function setupBTCWallet({ iconUrl, deprecated, autoConnect, syncLogOut, env, }?: BTCWalletParams | undefined): WalletModuleFactory<InjectedWallet>;
|
16
17
|
declare const _default: {
|
17
18
|
setupBTCWallet: typeof setupBTCWallet;
|
18
19
|
};
|
package/dist/index.js
CHANGED
@@ -2616,19 +2616,63 @@ var import_utils7 = require("@near-js/utils");
|
|
2616
2616
|
var import_bs58 = __toESM(require("bs58"), 1);
|
2617
2617
|
var import_js_sha256 = require("js-sha256");
|
2618
2618
|
|
2619
|
-
// src/
|
2620
|
-
var
|
2621
|
-
dev:
|
2622
|
-
|
2623
|
-
|
2619
|
+
// src/config.ts
|
2620
|
+
var walletConfig = {
|
2621
|
+
dev: {
|
2622
|
+
base_url: "https://api.dev.satoshibridge.top",
|
2623
|
+
token: "nbtc-dev.testnet",
|
2624
|
+
accountContractId: "acc-dev.testnet",
|
2625
|
+
bridgeContractId: "brg-dev.testnet",
|
2626
|
+
walletUrl: "https://wallet-dev.satoshibridge.top",
|
2627
|
+
bridgeUrl: "https://dev.satoshibridge.top/"
|
2628
|
+
},
|
2629
|
+
testnet: {
|
2630
|
+
base_url: "https://api.testnet.satoshibridge.top",
|
2631
|
+
token: "nbtc2-nsp.testnet",
|
2632
|
+
accountContractId: "acc2-nsp.testnet",
|
2633
|
+
bridgeContractId: "brg2-nsp.testnet",
|
2634
|
+
walletUrl: "https://wallet-test.satoshibridge.top",
|
2635
|
+
bridgeUrl: "https://testnet.satoshibridge.top/"
|
2636
|
+
},
|
2637
|
+
private_mainnet: {
|
2638
|
+
base_url: "https://api.stg.satoshibridge.top",
|
2639
|
+
token: "nbtc.toalice.near",
|
2640
|
+
accountContractId: "acc.toalice.near",
|
2641
|
+
bridgeContractId: "brg.toalice.near",
|
2642
|
+
walletUrl: "https://wallet-stg.satoshibridge.top",
|
2643
|
+
bridgeUrl: "https://stg.satoshibridge.top/"
|
2644
|
+
},
|
2645
|
+
mainnet: {
|
2646
|
+
base_url: "https://api.mainnet.satoshibridge.top",
|
2647
|
+
token: "nbtc.toalice.near",
|
2648
|
+
accountContractId: "acc.toalice.near",
|
2649
|
+
bridgeContractId: "brg.toalice.near",
|
2650
|
+
walletUrl: "https://wallet.satoshibridge.top",
|
2651
|
+
bridgeUrl: "https://www.satoshibridge.top/"
|
2652
|
+
}
|
2653
|
+
};
|
2654
|
+
var nearRpcUrls = {
|
2655
|
+
mainnet: [
|
2656
|
+
"https://near.lava.build",
|
2657
|
+
"https://rpc.mainnet.near.org",
|
2658
|
+
"https://free.rpc.fastnear.com",
|
2659
|
+
"https://near.drpc.org"
|
2660
|
+
],
|
2661
|
+
testnet: ["https://rpc.testnet.near.org"]
|
2662
|
+
};
|
2663
|
+
var btcRpcUrls = {
|
2664
|
+
mainnet: "https://mempool.space/api",
|
2665
|
+
testnet: "https://mempool.space/testnet/api"
|
2624
2666
|
};
|
2625
|
-
|
2667
|
+
|
2668
|
+
// src/utils/initWalletButton.ts
|
2669
|
+
function setupWalletButton(env, wallet, originalWallet) {
|
2626
2670
|
console.log("setupWalletButton");
|
2627
2671
|
if (document.getElementById("satoshi-wallet-button")) {
|
2628
2672
|
return;
|
2629
2673
|
}
|
2630
2674
|
const iframe = createIframe({
|
2631
|
-
iframeUrl:
|
2675
|
+
iframeUrl: walletConfig[env].walletUrl,
|
2632
2676
|
iframeStyle: { width: "400px", height: "650px" }
|
2633
2677
|
});
|
2634
2678
|
iframe.addEventListener("mouseenter", () => {
|
@@ -2759,47 +2803,6 @@ function removeWalletButton() {
|
|
2759
2803
|
iframe == null ? void 0 : iframe.remove();
|
2760
2804
|
}
|
2761
2805
|
|
2762
|
-
// src/config.ts
|
2763
|
-
var walletConfig = {
|
2764
|
-
dev: {
|
2765
|
-
base_url: "https://api.dev.satoshibridge.top",
|
2766
|
-
token: "nbtc-dev.testnet",
|
2767
|
-
accountContractId: "acc-dev.testnet",
|
2768
|
-
bridgeContractId: "brg-dev.testnet",
|
2769
|
-
walletUrl: "https://wallet-dev.satoshibridge.top",
|
2770
|
-
bridgeUrl: "https://dev.satoshibridge.top/"
|
2771
|
-
},
|
2772
|
-
testnet: {
|
2773
|
-
base_url: "https://api.testnet.satoshibridge.top",
|
2774
|
-
token: "nbtc2-nsp.testnet",
|
2775
|
-
accountContractId: "acc2-nsp.testnet",
|
2776
|
-
bridgeContractId: "brg2-nsp.testnet",
|
2777
|
-
walletUrl: "https://wallet-test.satoshibridge.top",
|
2778
|
-
bridgeUrl: "https://testnet.satoshibridge.top/"
|
2779
|
-
},
|
2780
|
-
mainnet: {
|
2781
|
-
base_url: "https://api.mainnet.satoshibridge.top",
|
2782
|
-
token: "nbtc.toalice.near",
|
2783
|
-
accountContractId: "acc.toalice.near",
|
2784
|
-
bridgeContractId: "brg.toalice.near",
|
2785
|
-
walletUrl: "https://wallet.satoshibridge.top",
|
2786
|
-
bridgeUrl: "https://www.satoshibridge.top/"
|
2787
|
-
}
|
2788
|
-
};
|
2789
|
-
var nearRpcUrls = {
|
2790
|
-
mainnet: [
|
2791
|
-
"https://near.lava.build",
|
2792
|
-
"https://rpc.mainnet.near.org",
|
2793
|
-
"https://free.rpc.fastnear.com",
|
2794
|
-
"https://near.drpc.org"
|
2795
|
-
],
|
2796
|
-
testnet: ["https://rpc.testnet.near.org"]
|
2797
|
-
};
|
2798
|
-
var btcRpcUrls = {
|
2799
|
-
mainnet: "https://mempool.space/api",
|
2800
|
-
testnet: "https://mempool.space/testnet/api"
|
2801
|
-
};
|
2802
|
-
|
2803
2806
|
// src/utils/nearUtils.ts
|
2804
2807
|
var import_near_api_js = require("near-api-js");
|
2805
2808
|
function nearCallFunction(contractId, methodName, args, options) {
|
@@ -3246,10 +3249,9 @@ function getBtcRpcUrl() {
|
|
3246
3249
|
return btcRpcUrls[network];
|
3247
3250
|
});
|
3248
3251
|
}
|
3249
|
-
function getConfig(
|
3252
|
+
function getConfig(env) {
|
3250
3253
|
return __async(this, null, function* () {
|
3251
|
-
|
3252
|
-
return walletConfig[isDev ? "dev" : network];
|
3254
|
+
return walletConfig[env];
|
3253
3255
|
});
|
3254
3256
|
}
|
3255
3257
|
function nearCall(contractId, methodName, args) {
|
@@ -3265,7 +3267,7 @@ function getAccountInfo(csna, accountContractId) {
|
|
3265
3267
|
return accountInfo;
|
3266
3268
|
});
|
3267
3269
|
}
|
3268
|
-
function checkGasTokenBalance(csna, gasToken, minAmount,
|
3270
|
+
function checkGasTokenBalance(csna, gasToken, minAmount, env) {
|
3269
3271
|
return __async(this, null, function* () {
|
3270
3272
|
const amount = yield nearCall(gasToken, "ft_balance_of", { account_id: csna });
|
3271
3273
|
console.log("gas token balance:", amount);
|
@@ -3274,17 +3276,17 @@ function checkGasTokenBalance(csna, gasToken, minAmount, isDev) {
|
|
3274
3276
|
title: "Gas token balance is insufficient",
|
3275
3277
|
message: "Please deposit gas token to continue, will open bridge website."
|
3276
3278
|
});
|
3277
|
-
const config = yield getConfig(
|
3279
|
+
const config = yield getConfig(env);
|
3278
3280
|
window.open(config.bridgeUrl, "_blank");
|
3279
3281
|
throw new Error("Gas token balance is insufficient");
|
3280
3282
|
}
|
3281
3283
|
});
|
3282
3284
|
}
|
3283
|
-
function checkGasTokenArrears(debtInfo,
|
3285
|
+
function checkGasTokenArrears(debtInfo, env, autoDeposit) {
|
3284
3286
|
return __async(this, null, function* () {
|
3285
3287
|
if (!debtInfo)
|
3286
3288
|
return;
|
3287
|
-
const config = yield getConfig(
|
3289
|
+
const config = yield getConfig(env);
|
3288
3290
|
const transferAmount = debtInfo.transfer_amount;
|
3289
3291
|
console.log("get_account debtInfo:", debtInfo);
|
3290
3292
|
const action = {
|
@@ -3299,7 +3301,7 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
|
3299
3301
|
message: "You have gas token arrears, please deposit gas token to continue."
|
3300
3302
|
});
|
3301
3303
|
if (confirmed) {
|
3302
|
-
yield executeBTCDepositAndAction({ action,
|
3304
|
+
yield executeBTCDepositAndAction({ action, env });
|
3303
3305
|
yield Dialog.alert({
|
3304
3306
|
title: "Deposit success",
|
3305
3307
|
message: "Deposit success, will continue to execute transaction."
|
@@ -3309,10 +3311,10 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
|
3309
3311
|
}
|
3310
3312
|
});
|
3311
3313
|
}
|
3312
|
-
function queryGasTokenArrears(
|
3314
|
+
function queryGasTokenArrears(env) {
|
3313
3315
|
return __async(this, null, function* () {
|
3314
|
-
const config = yield getConfig(
|
3315
|
-
const csna = yield getCsnaAccountId(
|
3316
|
+
const config = yield getConfig(env);
|
3317
|
+
const csna = yield getCsnaAccountId(env);
|
3316
3318
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3317
3319
|
return accountInfo == null ? void 0 : accountInfo.debt_info;
|
3318
3320
|
});
|
@@ -3373,7 +3375,7 @@ function estimateDepositAmount(amount, option) {
|
|
3373
3375
|
}
|
3374
3376
|
function getDepositAmount(amount, option) {
|
3375
3377
|
return __async(this, null, function* () {
|
3376
|
-
const config = yield getConfig((option == null ? void 0 : option.
|
3378
|
+
const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
|
3377
3379
|
const {
|
3378
3380
|
deposit_bridge_fee: { fee_min, fee_rate }
|
3379
3381
|
} = yield nearCall(
|
@@ -3392,9 +3394,9 @@ function getDepositAmount(amount, option) {
|
|
3392
3394
|
};
|
3393
3395
|
});
|
3394
3396
|
}
|
3395
|
-
function getCsnaAccountId(
|
3397
|
+
function getCsnaAccountId(env) {
|
3396
3398
|
return __async(this, null, function* () {
|
3397
|
-
const config = yield getConfig(
|
3399
|
+
const config = yield getConfig(env);
|
3398
3400
|
const { getPublicKey } = getBtcProvider();
|
3399
3401
|
const btcPublicKey = yield getPublicKey();
|
3400
3402
|
const csna = yield nearCall(
|
@@ -3414,12 +3416,12 @@ function executeBTCDepositAndAction(_0) {
|
|
3414
3416
|
feeRate,
|
3415
3417
|
fixedAmount = true,
|
3416
3418
|
pollResult = true,
|
3417
|
-
|
3419
|
+
env = "mainnet"
|
3418
3420
|
}) {
|
3419
3421
|
var _a;
|
3420
3422
|
try {
|
3421
3423
|
const { getPublicKey } = getBtcProvider();
|
3422
|
-
const config = yield getConfig(
|
3424
|
+
const config = yield getConfig(env);
|
3423
3425
|
const btcPublicKey = yield getPublicKey();
|
3424
3426
|
if (!btcPublicKey) {
|
3425
3427
|
throw new Error("BTC Public Key is not available.");
|
@@ -3427,18 +3429,18 @@ function executeBTCDepositAndAction(_0) {
|
|
3427
3429
|
if (!amount && !action) {
|
3428
3430
|
throw new Error("amount or action is required");
|
3429
3431
|
}
|
3430
|
-
const csna = yield getCsnaAccountId(
|
3432
|
+
const csna = yield getCsnaAccountId(env);
|
3431
3433
|
const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
|
3432
3434
|
if (new import_big.default(rawDepositAmount).lt(0)) {
|
3433
3435
|
throw new Error("amount must be greater than 0");
|
3434
3436
|
}
|
3435
3437
|
const { depositAmount, receiveAmount } = yield getDepositAmount(rawDepositAmount, {
|
3436
|
-
|
3438
|
+
env
|
3437
3439
|
});
|
3438
3440
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3439
3441
|
const newActions = [];
|
3440
3442
|
const gasLimit = new import_big.default(50).mul(__pow(10, 12)).toFixed(0);
|
3441
|
-
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info,
|
3443
|
+
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, false);
|
3442
3444
|
if (repayAction) {
|
3443
3445
|
newActions.push(__spreadProps(__spreadValues({}, repayAction), {
|
3444
3446
|
gas: gasLimit
|
@@ -3562,7 +3564,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3562
3564
|
id,
|
3563
3565
|
provider
|
3564
3566
|
}) {
|
3565
|
-
var _a;
|
3566
3567
|
const wallet = {
|
3567
3568
|
signIn,
|
3568
3569
|
signOut,
|
@@ -3573,9 +3574,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3573
3574
|
signAndSendTransaction,
|
3574
3575
|
signAndSendTransactions
|
3575
3576
|
};
|
3576
|
-
const
|
3577
|
-
const currentConfig =
|
3578
|
-
const walletNetwork =
|
3577
|
+
const env = metadata.env || options.network.networkId || "mainnet";
|
3578
|
+
const currentConfig = walletConfig[env];
|
3579
|
+
const walletNetwork = ["mainnet", "private_mainnet"].includes(env) ? "mainnet" : "testnet";
|
3579
3580
|
yield initBtcContext();
|
3580
3581
|
function setupBtcContextListeners() {
|
3581
3582
|
return __async(this, null, function* () {
|
@@ -3584,7 +3585,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3584
3585
|
const accountId = state.getAccount();
|
3585
3586
|
const btcContext = window.btcContext;
|
3586
3587
|
if (accountId && btcContext.account) {
|
3587
|
-
setupWalletButton(
|
3588
|
+
setupWalletButton(env, wallet, btcContext);
|
3588
3589
|
} else {
|
3589
3590
|
removeWalletButton();
|
3590
3591
|
setTimeout(() => {
|
@@ -3645,7 +3646,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3645
3646
|
}
|
3646
3647
|
function getNearAccountByBtcPublicKey(btcPublicKey) {
|
3647
3648
|
return __async(this, null, function* () {
|
3648
|
-
const csna = yield getCsnaAccountId(
|
3649
|
+
const csna = yield getCsnaAccountId(env);
|
3649
3650
|
const nearPublicKey = yield nearCall2(
|
3650
3651
|
currentConfig.accountContractId,
|
3651
3652
|
"get_chain_signature_near_account_public_key",
|
@@ -3735,7 +3736,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3735
3736
|
const btcContext = window.btcContext;
|
3736
3737
|
const accountId = state.getAccount();
|
3737
3738
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3738
|
-
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info,
|
3739
|
+
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, true);
|
3739
3740
|
const trans = [...params.transactions];
|
3740
3741
|
console.log("raw trans:", trans);
|
3741
3742
|
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
@@ -3746,7 +3747,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3746
3747
|
console.log("transferGasTransaction:", transferGasTransaction);
|
3747
3748
|
console.log("useNearPayGas:", useNearPayGas);
|
3748
3749
|
console.log("gasLimit:", gasLimit);
|
3749
|
-
yield checkGasTokenBalance(accountId, currentConfig.token, gasLimit,
|
3750
|
+
yield checkGasTokenBalance(accountId, currentConfig.token, gasLimit, env);
|
3750
3751
|
if (transferGasTransaction) {
|
3751
3752
|
trans.unshift(transferGasTransaction);
|
3752
3753
|
}
|
@@ -3832,7 +3833,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3832
3833
|
}
|
3833
3834
|
function calculateGasStrategy(gasTokenBalance, transactions2) {
|
3834
3835
|
return __async(this, null, function* () {
|
3835
|
-
var
|
3836
|
+
var _a;
|
3836
3837
|
const accountId = state.getAccount();
|
3837
3838
|
const nearAccount = yield provider.query({
|
3838
3839
|
request_type: "view_account",
|
@@ -3854,7 +3855,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3854
3855
|
);
|
3855
3856
|
console.log("list_gas_token gas tokens:", gasTokens);
|
3856
3857
|
const perTxFee = Math.max(
|
3857
|
-
Number(((
|
3858
|
+
Number(((_a = gasTokens[currentConfig.token]) == null ? void 0 : _a.per_tx_protocol_fee) || 0),
|
3858
3859
|
100
|
3859
3860
|
);
|
3860
3861
|
console.log("perTxFee:", perTxFee);
|
@@ -3943,9 +3944,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3943
3944
|
if (!btcContext.account)
|
3944
3945
|
return;
|
3945
3946
|
const btcNetwork = yield btcContext.getNetwork();
|
3946
|
-
console.log("btcNetwork:", btcNetwork, network);
|
3947
3947
|
const networkMap = {
|
3948
|
-
livenet: ["mainnet"],
|
3948
|
+
livenet: ["mainnet", "private_mainnet"],
|
3949
3949
|
testnet: ["testnet", "dev"]
|
3950
3950
|
};
|
3951
3951
|
if (!networkMap[btcNetwork].includes(network)) {
|
@@ -3968,9 +3968,9 @@ function setupBTCWallet({
|
|
3968
3968
|
deprecated = false,
|
3969
3969
|
autoConnect = true,
|
3970
3970
|
syncLogOut = true,
|
3971
|
-
|
3971
|
+
env = "mainnet"
|
3972
3972
|
} = {}) {
|
3973
|
-
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion());
|
3973
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
|
3974
3974
|
const btcWallet = () => __async(this, null, function* () {
|
3975
3975
|
return {
|
3976
3976
|
id: "btc-wallet",
|
@@ -3984,7 +3984,7 @@ function setupBTCWallet({
|
|
3984
3984
|
available: true,
|
3985
3985
|
autoConnect,
|
3986
3986
|
syncLogOut,
|
3987
|
-
|
3987
|
+
env
|
3988
3988
|
},
|
3989
3989
|
init: BTCWallet
|
3990
3990
|
};
|
@@ -3994,7 +3994,7 @@ function setupBTCWallet({
|
|
3994
3994
|
|
3995
3995
|
// src/index.ts
|
3996
3996
|
var getVersion = () => {
|
3997
|
-
return "0.3.
|
3997
|
+
return "0.3.26";
|
3998
3998
|
};
|
3999
3999
|
if (typeof window !== "undefined") {
|
4000
4000
|
window.__BTC_WALLET_VERSION = getVersion();
|