btc-wallet 0.3.23 → 0.3.26
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/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
@@ -1,8 +1,9 @@
|
|
1
1
|
import type { Wallet } from '@near-wallet-selector/core';
|
2
|
+
import { type ENV } from '../config';
|
2
3
|
interface OriginalWallet {
|
3
4
|
account: string | null;
|
4
5
|
getPublicKey: () => Promise<string>;
|
5
6
|
}
|
6
|
-
export declare function setupWalletButton(
|
7
|
+
export declare function setupWalletButton(env: ENV, wallet: Wallet, originalWallet: OriginalWallet): void;
|
7
8
|
export declare function removeWalletButton(): void;
|
8
9
|
export {};
|
package/esm/index.js
CHANGED
@@ -2570,19 +2570,63 @@ import { baseDecode } from "@near-js/utils";
|
|
2570
2570
|
import bs58 from "bs58";
|
2571
2571
|
import { sha256 } from "js-sha256";
|
2572
2572
|
|
2573
|
-
// src/
|
2574
|
-
var
|
2575
|
-
dev:
|
2576
|
-
|
2577
|
-
|
2573
|
+
// src/config.ts
|
2574
|
+
var walletConfig = {
|
2575
|
+
dev: {
|
2576
|
+
base_url: "https://api.dev.satoshibridge.top",
|
2577
|
+
token: "nbtc-dev.testnet",
|
2578
|
+
accountContractId: "acc-dev.testnet",
|
2579
|
+
bridgeContractId: "brg-dev.testnet",
|
2580
|
+
walletUrl: "https://wallet-dev.satoshibridge.top",
|
2581
|
+
bridgeUrl: "https://dev.satoshibridge.top/"
|
2582
|
+
},
|
2583
|
+
testnet: {
|
2584
|
+
base_url: "https://api.testnet.satoshibridge.top",
|
2585
|
+
token: "nbtc2-nsp.testnet",
|
2586
|
+
accountContractId: "acc2-nsp.testnet",
|
2587
|
+
bridgeContractId: "brg2-nsp.testnet",
|
2588
|
+
walletUrl: "https://wallet-test.satoshibridge.top",
|
2589
|
+
bridgeUrl: "https://testnet.satoshibridge.top/"
|
2590
|
+
},
|
2591
|
+
private_mainnet: {
|
2592
|
+
base_url: "https://api.stg.satoshibridge.top",
|
2593
|
+
token: "nbtc.toalice.near",
|
2594
|
+
accountContractId: "acc.toalice.near",
|
2595
|
+
bridgeContractId: "brg.toalice.near",
|
2596
|
+
walletUrl: "https://wallet-stg.satoshibridge.top",
|
2597
|
+
bridgeUrl: "https://stg.satoshibridge.top/"
|
2598
|
+
},
|
2599
|
+
mainnet: {
|
2600
|
+
base_url: "https://api.mainnet.satoshibridge.top",
|
2601
|
+
token: "nbtc.toalice.near",
|
2602
|
+
accountContractId: "acc.toalice.near",
|
2603
|
+
bridgeContractId: "brg.toalice.near",
|
2604
|
+
walletUrl: "https://wallet.satoshibridge.top",
|
2605
|
+
bridgeUrl: "https://www.satoshibridge.top/"
|
2606
|
+
}
|
2607
|
+
};
|
2608
|
+
var nearRpcUrls = {
|
2609
|
+
mainnet: [
|
2610
|
+
"https://near.lava.build",
|
2611
|
+
"https://rpc.mainnet.near.org",
|
2612
|
+
"https://free.rpc.fastnear.com",
|
2613
|
+
"https://near.drpc.org"
|
2614
|
+
],
|
2615
|
+
testnet: ["https://rpc.testnet.near.org"]
|
2616
|
+
};
|
2617
|
+
var btcRpcUrls = {
|
2618
|
+
mainnet: "https://mempool.space/api",
|
2619
|
+
testnet: "https://mempool.space/testnet/api"
|
2578
2620
|
};
|
2579
|
-
|
2621
|
+
|
2622
|
+
// src/utils/initWalletButton.ts
|
2623
|
+
function setupWalletButton(env, wallet, originalWallet) {
|
2580
2624
|
console.log("setupWalletButton");
|
2581
2625
|
if (document.getElementById("satoshi-wallet-button")) {
|
2582
2626
|
return;
|
2583
2627
|
}
|
2584
2628
|
const iframe = createIframe({
|
2585
|
-
iframeUrl:
|
2629
|
+
iframeUrl: walletConfig[env].walletUrl,
|
2586
2630
|
iframeStyle: { width: "400px", height: "650px" }
|
2587
2631
|
});
|
2588
2632
|
iframe.addEventListener("mouseenter", () => {
|
@@ -2713,47 +2757,6 @@ function removeWalletButton() {
|
|
2713
2757
|
iframe == null ? void 0 : iframe.remove();
|
2714
2758
|
}
|
2715
2759
|
|
2716
|
-
// src/config.ts
|
2717
|
-
var walletConfig = {
|
2718
|
-
dev: {
|
2719
|
-
base_url: "https://api.dev.satoshibridge.top",
|
2720
|
-
token: "nbtc-dev.testnet",
|
2721
|
-
accountContractId: "acc-dev.testnet",
|
2722
|
-
bridgeContractId: "brg-dev.testnet",
|
2723
|
-
walletUrl: "https://wallet-dev.satoshibridge.top",
|
2724
|
-
bridgeUrl: "https://dev.satoshibridge.top/"
|
2725
|
-
},
|
2726
|
-
testnet: {
|
2727
|
-
base_url: "https://api.testnet.satoshibridge.top",
|
2728
|
-
token: "nbtc2-nsp.testnet",
|
2729
|
-
accountContractId: "acc2-nsp.testnet",
|
2730
|
-
bridgeContractId: "brg2-nsp.testnet",
|
2731
|
-
walletUrl: "https://wallet-test.satoshibridge.top",
|
2732
|
-
bridgeUrl: "https://testnet.satoshibridge.top/"
|
2733
|
-
},
|
2734
|
-
mainnet: {
|
2735
|
-
base_url: "https://api.mainnet.satoshibridge.top",
|
2736
|
-
token: "nbtc.toalice.near",
|
2737
|
-
accountContractId: "acc.toalice.near",
|
2738
|
-
bridgeContractId: "brg.toalice.near",
|
2739
|
-
walletUrl: "https://wallet.satoshibridge.top",
|
2740
|
-
bridgeUrl: "https://www.satoshibridge.top/"
|
2741
|
-
}
|
2742
|
-
};
|
2743
|
-
var nearRpcUrls = {
|
2744
|
-
mainnet: [
|
2745
|
-
"https://near.lava.build",
|
2746
|
-
"https://rpc.mainnet.near.org",
|
2747
|
-
"https://free.rpc.fastnear.com",
|
2748
|
-
"https://near.drpc.org"
|
2749
|
-
],
|
2750
|
-
testnet: ["https://rpc.testnet.near.org"]
|
2751
|
-
};
|
2752
|
-
var btcRpcUrls = {
|
2753
|
-
mainnet: "https://mempool.space/api",
|
2754
|
-
testnet: "https://mempool.space/testnet/api"
|
2755
|
-
};
|
2756
|
-
|
2757
2760
|
// src/utils/nearUtils.ts
|
2758
2761
|
import { providers } from "near-api-js";
|
2759
2762
|
function nearCallFunction(contractId, methodName, args, options) {
|
@@ -3200,10 +3203,9 @@ function getBtcRpcUrl() {
|
|
3200
3203
|
return btcRpcUrls[network];
|
3201
3204
|
});
|
3202
3205
|
}
|
3203
|
-
function getConfig(
|
3206
|
+
function getConfig(env) {
|
3204
3207
|
return __async(this, null, function* () {
|
3205
|
-
|
3206
|
-
return walletConfig[isDev ? "dev" : network];
|
3208
|
+
return walletConfig[env];
|
3207
3209
|
});
|
3208
3210
|
}
|
3209
3211
|
function nearCall(contractId, methodName, args) {
|
@@ -3219,7 +3221,7 @@ function getAccountInfo(csna, accountContractId) {
|
|
3219
3221
|
return accountInfo;
|
3220
3222
|
});
|
3221
3223
|
}
|
3222
|
-
function checkGasTokenBalance(csna, gasToken, minAmount,
|
3224
|
+
function checkGasTokenBalance(csna, gasToken, minAmount, env) {
|
3223
3225
|
return __async(this, null, function* () {
|
3224
3226
|
const amount = yield nearCall(gasToken, "ft_balance_of", { account_id: csna });
|
3225
3227
|
console.log("gas token balance:", amount);
|
@@ -3228,17 +3230,17 @@ function checkGasTokenBalance(csna, gasToken, minAmount, isDev) {
|
|
3228
3230
|
title: "Gas token balance is insufficient",
|
3229
3231
|
message: "Please deposit gas token to continue, will open bridge website."
|
3230
3232
|
});
|
3231
|
-
const config = yield getConfig(
|
3233
|
+
const config = yield getConfig(env);
|
3232
3234
|
window.open(config.bridgeUrl, "_blank");
|
3233
3235
|
throw new Error("Gas token balance is insufficient");
|
3234
3236
|
}
|
3235
3237
|
});
|
3236
3238
|
}
|
3237
|
-
function checkGasTokenArrears(debtInfo,
|
3239
|
+
function checkGasTokenArrears(debtInfo, env, autoDeposit) {
|
3238
3240
|
return __async(this, null, function* () {
|
3239
3241
|
if (!debtInfo)
|
3240
3242
|
return;
|
3241
|
-
const config = yield getConfig(
|
3243
|
+
const config = yield getConfig(env);
|
3242
3244
|
const transferAmount = debtInfo.transfer_amount;
|
3243
3245
|
console.log("get_account debtInfo:", debtInfo);
|
3244
3246
|
const action = {
|
@@ -3253,7 +3255,7 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
|
3253
3255
|
message: "You have gas token arrears, please deposit gas token to continue."
|
3254
3256
|
});
|
3255
3257
|
if (confirmed) {
|
3256
|
-
yield executeBTCDepositAndAction({ action,
|
3258
|
+
yield executeBTCDepositAndAction({ action, env });
|
3257
3259
|
yield Dialog.alert({
|
3258
3260
|
title: "Deposit success",
|
3259
3261
|
message: "Deposit success, will continue to execute transaction."
|
@@ -3263,10 +3265,10 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
|
3263
3265
|
}
|
3264
3266
|
});
|
3265
3267
|
}
|
3266
|
-
function queryGasTokenArrears(
|
3268
|
+
function queryGasTokenArrears(env) {
|
3267
3269
|
return __async(this, null, function* () {
|
3268
|
-
const config = yield getConfig(
|
3269
|
-
const csna = yield getCsnaAccountId(
|
3270
|
+
const config = yield getConfig(env);
|
3271
|
+
const csna = yield getCsnaAccountId(env);
|
3270
3272
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3271
3273
|
return accountInfo == null ? void 0 : accountInfo.debt_info;
|
3272
3274
|
});
|
@@ -3327,7 +3329,7 @@ function estimateDepositAmount(amount, option) {
|
|
3327
3329
|
}
|
3328
3330
|
function getDepositAmount(amount, option) {
|
3329
3331
|
return __async(this, null, function* () {
|
3330
|
-
const config = yield getConfig((option == null ? void 0 : option.
|
3332
|
+
const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
|
3331
3333
|
const {
|
3332
3334
|
deposit_bridge_fee: { fee_min, fee_rate }
|
3333
3335
|
} = yield nearCall(
|
@@ -3346,9 +3348,9 @@ function getDepositAmount(amount, option) {
|
|
3346
3348
|
};
|
3347
3349
|
});
|
3348
3350
|
}
|
3349
|
-
function getCsnaAccountId(
|
3351
|
+
function getCsnaAccountId(env) {
|
3350
3352
|
return __async(this, null, function* () {
|
3351
|
-
const config = yield getConfig(
|
3353
|
+
const config = yield getConfig(env);
|
3352
3354
|
const { getPublicKey } = getBtcProvider();
|
3353
3355
|
const btcPublicKey = yield getPublicKey();
|
3354
3356
|
const csna = yield nearCall(
|
@@ -3368,12 +3370,12 @@ function executeBTCDepositAndAction(_0) {
|
|
3368
3370
|
feeRate,
|
3369
3371
|
fixedAmount = true,
|
3370
3372
|
pollResult = true,
|
3371
|
-
|
3373
|
+
env = "mainnet"
|
3372
3374
|
}) {
|
3373
3375
|
var _a;
|
3374
3376
|
try {
|
3375
3377
|
const { getPublicKey } = getBtcProvider();
|
3376
|
-
const config = yield getConfig(
|
3378
|
+
const config = yield getConfig(env);
|
3377
3379
|
const btcPublicKey = yield getPublicKey();
|
3378
3380
|
if (!btcPublicKey) {
|
3379
3381
|
throw new Error("BTC Public Key is not available.");
|
@@ -3381,18 +3383,18 @@ function executeBTCDepositAndAction(_0) {
|
|
3381
3383
|
if (!amount && !action) {
|
3382
3384
|
throw new Error("amount or action is required");
|
3383
3385
|
}
|
3384
|
-
const csna = yield getCsnaAccountId(
|
3386
|
+
const csna = yield getCsnaAccountId(env);
|
3385
3387
|
const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
|
3386
3388
|
if (new Big(rawDepositAmount).lt(0)) {
|
3387
3389
|
throw new Error("amount must be greater than 0");
|
3388
3390
|
}
|
3389
3391
|
const { depositAmount, receiveAmount } = yield getDepositAmount(rawDepositAmount, {
|
3390
|
-
|
3392
|
+
env
|
3391
3393
|
});
|
3392
3394
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3393
3395
|
const newActions = [];
|
3394
3396
|
const gasLimit = new Big(50).mul(__pow(10, 12)).toFixed(0);
|
3395
|
-
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info,
|
3397
|
+
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, false);
|
3396
3398
|
if (repayAction) {
|
3397
3399
|
newActions.push(__spreadProps(__spreadValues({}, repayAction), {
|
3398
3400
|
gas: gasLimit
|
@@ -3516,7 +3518,6 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3516
3518
|
id,
|
3517
3519
|
provider
|
3518
3520
|
}) {
|
3519
|
-
var _a;
|
3520
3521
|
const wallet = {
|
3521
3522
|
signIn,
|
3522
3523
|
signOut,
|
@@ -3527,9 +3528,9 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3527
3528
|
signAndSendTransaction,
|
3528
3529
|
signAndSendTransactions
|
3529
3530
|
};
|
3530
|
-
const
|
3531
|
-
const currentConfig =
|
3532
|
-
const walletNetwork =
|
3531
|
+
const env = metadata.env || options.network.networkId || "mainnet";
|
3532
|
+
const currentConfig = walletConfig[env];
|
3533
|
+
const walletNetwork = ["mainnet", "private_mainnet"].includes(env) ? "mainnet" : "testnet";
|
3533
3534
|
yield initBtcContext();
|
3534
3535
|
function setupBtcContextListeners() {
|
3535
3536
|
return __async(this, null, function* () {
|
@@ -3538,7 +3539,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3538
3539
|
const accountId = state.getAccount();
|
3539
3540
|
const btcContext = window.btcContext;
|
3540
3541
|
if (accountId && btcContext.account) {
|
3541
|
-
setupWalletButton(
|
3542
|
+
setupWalletButton(env, wallet, btcContext);
|
3542
3543
|
} else {
|
3543
3544
|
removeWalletButton();
|
3544
3545
|
setTimeout(() => {
|
@@ -3599,7 +3600,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3599
3600
|
}
|
3600
3601
|
function getNearAccountByBtcPublicKey(btcPublicKey) {
|
3601
3602
|
return __async(this, null, function* () {
|
3602
|
-
const csna = yield getCsnaAccountId(
|
3603
|
+
const csna = yield getCsnaAccountId(env);
|
3603
3604
|
const nearPublicKey = yield nearCall2(
|
3604
3605
|
currentConfig.accountContractId,
|
3605
3606
|
"get_chain_signature_near_account_public_key",
|
@@ -3689,7 +3690,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3689
3690
|
const btcContext = window.btcContext;
|
3690
3691
|
const accountId = state.getAccount();
|
3691
3692
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3692
|
-
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info,
|
3693
|
+
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, env, true);
|
3693
3694
|
const trans = [...params.transactions];
|
3694
3695
|
console.log("raw trans:", trans);
|
3695
3696
|
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
@@ -3700,7 +3701,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3700
3701
|
console.log("transferGasTransaction:", transferGasTransaction);
|
3701
3702
|
console.log("useNearPayGas:", useNearPayGas);
|
3702
3703
|
console.log("gasLimit:", gasLimit);
|
3703
|
-
yield checkGasTokenBalance(accountId, currentConfig.token, gasLimit,
|
3704
|
+
yield checkGasTokenBalance(accountId, currentConfig.token, gasLimit, env);
|
3704
3705
|
if (transferGasTransaction) {
|
3705
3706
|
trans.unshift(transferGasTransaction);
|
3706
3707
|
}
|
@@ -3786,7 +3787,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3786
3787
|
}
|
3787
3788
|
function calculateGasStrategy(gasTokenBalance, transactions2) {
|
3788
3789
|
return __async(this, null, function* () {
|
3789
|
-
var
|
3790
|
+
var _a;
|
3790
3791
|
const accountId = state.getAccount();
|
3791
3792
|
const nearAccount = yield provider.query({
|
3792
3793
|
request_type: "view_account",
|
@@ -3808,7 +3809,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3808
3809
|
);
|
3809
3810
|
console.log("list_gas_token gas tokens:", gasTokens);
|
3810
3811
|
const perTxFee = Math.max(
|
3811
|
-
Number(((
|
3812
|
+
Number(((_a = gasTokens[currentConfig.token]) == null ? void 0 : _a.per_tx_protocol_fee) || 0),
|
3812
3813
|
100
|
3813
3814
|
);
|
3814
3815
|
console.log("perTxFee:", perTxFee);
|
@@ -3897,9 +3898,8 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3897
3898
|
if (!btcContext.account)
|
3898
3899
|
return;
|
3899
3900
|
const btcNetwork = yield btcContext.getNetwork();
|
3900
|
-
console.log("btcNetwork:", btcNetwork, network);
|
3901
3901
|
const networkMap = {
|
3902
|
-
livenet: ["mainnet"],
|
3902
|
+
livenet: ["mainnet", "private_mainnet"],
|
3903
3903
|
testnet: ["testnet", "dev"]
|
3904
3904
|
};
|
3905
3905
|
if (!networkMap[btcNetwork].includes(network)) {
|
@@ -3922,9 +3922,9 @@ function setupBTCWallet({
|
|
3922
3922
|
deprecated = false,
|
3923
3923
|
autoConnect = true,
|
3924
3924
|
syncLogOut = true,
|
3925
|
-
|
3925
|
+
env = "mainnet"
|
3926
3926
|
} = {}) {
|
3927
|
-
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion());
|
3927
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
|
3928
3928
|
const btcWallet = () => __async(this, null, function* () {
|
3929
3929
|
return {
|
3930
3930
|
id: "btc-wallet",
|
@@ -3938,7 +3938,7 @@ function setupBTCWallet({
|
|
3938
3938
|
available: true,
|
3939
3939
|
autoConnect,
|
3940
3940
|
syncLogOut,
|
3941
|
-
|
3941
|
+
env
|
3942
3942
|
},
|
3943
3943
|
init: BTCWallet
|
3944
3944
|
};
|
@@ -3948,7 +3948,7 @@ function setupBTCWallet({
|
|
3948
3948
|
|
3949
3949
|
// src/index.ts
|
3950
3950
|
var getVersion = () => {
|
3951
|
-
return "0.3.
|
3951
|
+
return "0.3.26";
|
3952
3952
|
};
|
3953
3953
|
if (typeof window !== "undefined") {
|
3954
3954
|
window.__BTC_WALLET_VERSION = getVersion();
|