btc-wallet 0.3.14 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/config.d.ts +1 -0
- package/dist/core/btcUtils.d.ts +3 -2
- package/dist/index.js +49 -20
- package/dist/index.js.map +3 -3
- package/esm/index.js +49 -20
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/esm/index.js
CHANGED
@@ -2686,21 +2686,24 @@ 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"
|
2689
|
+
walletUrl: "https://wallet-dev.satoshibridge.top",
|
2690
|
+
bridgeUrl: "https://dev.satoshibridge.top/"
|
2690
2691
|
},
|
2691
2692
|
testnet: {
|
2692
2693
|
base_url: "https://api.testnet.satoshibridge.top",
|
2693
2694
|
token: "nbtc2-nsp.testnet",
|
2694
|
-
accountContractId: "
|
2695
|
+
accountContractId: "acc2-nsp.testnet",
|
2695
2696
|
bridgeContractId: "brg2-nsp.testnet",
|
2696
|
-
walletUrl: "https://wallet-test.satoshibridge.top"
|
2697
|
+
walletUrl: "https://wallet-test.satoshibridge.top",
|
2698
|
+
bridgeUrl: "https://testnet.satoshibridge.top/"
|
2697
2699
|
},
|
2698
2700
|
mainnet: {
|
2699
2701
|
base_url: "https://api.mainnet.satoshibridge.top",
|
2700
|
-
token: "",
|
2701
|
-
accountContractId: "",
|
2702
|
-
bridgeContractId: "",
|
2703
|
-
walletUrl: "https://wallet.satoshibridge.top"
|
2702
|
+
token: "nbtc.toalice.near",
|
2703
|
+
accountContractId: "acc.toalice.near",
|
2704
|
+
bridgeContractId: "brg.toalice.near",
|
2705
|
+
walletUrl: "https://wallet.satoshibridge.top",
|
2706
|
+
bridgeUrl: "https://www.satoshibridge.top/"
|
2704
2707
|
}
|
2705
2708
|
};
|
2706
2709
|
var nearRpcUrls = {
|
@@ -2828,7 +2831,13 @@ function request(url, options) {
|
|
2828
2831
|
if (options.shouldStopPolling(data)) {
|
2829
2832
|
return data;
|
2830
2833
|
}
|
2831
|
-
|
2834
|
+
if (options.maxPollingAttempts && options.maxPollingAttempts > 0) {
|
2835
|
+
yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
|
2836
|
+
return request(url, __spreadProps(__spreadValues({}, options), {
|
2837
|
+
maxPollingAttempts: options.maxPollingAttempts - 1
|
2838
|
+
}));
|
2839
|
+
}
|
2840
|
+
throw new Error("Polling failed: maximum attempts reached without meeting the condition");
|
2832
2841
|
}
|
2833
2842
|
if (cacheKey) {
|
2834
2843
|
cache.set(cacheKey, { timestamp: Date.now(), data });
|
@@ -3135,6 +3144,8 @@ Dialog.style = `
|
|
3135
3144
|
`;
|
3136
3145
|
|
3137
3146
|
// src/core/btcUtils.ts
|
3147
|
+
var MINIMUM_DEPOSIT_AMOUNT = 5e3;
|
3148
|
+
var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
|
3138
3149
|
function getBtcProvider() {
|
3139
3150
|
if (typeof window === "undefined" || !window.btcContext) {
|
3140
3151
|
throw new Error("BTC Provider is not initialized.");
|
@@ -3169,9 +3180,25 @@ function nearCall(contractId, methodName, args) {
|
|
3169
3180
|
function getAccountInfo(csna, accountContractId) {
|
3170
3181
|
return __async(this, null, function* () {
|
3171
3182
|
const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
|
3183
|
+
console.log("get_account accountInfo:", accountInfo);
|
3172
3184
|
return accountInfo;
|
3173
3185
|
});
|
3174
3186
|
}
|
3187
|
+
function checkGasTokenBalance(csna, gasToken, isDev) {
|
3188
|
+
return __async(this, null, function* () {
|
3189
|
+
const amount = yield nearCall(gasToken, "ft_balance_of", { account_id: csna });
|
3190
|
+
console.log("gas token balance:", amount);
|
3191
|
+
if (new Big(amount).lte(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3192
|
+
yield Dialog.confirm({
|
3193
|
+
title: "Gas token balance is insufficient",
|
3194
|
+
message: "Please deposit gas token to continue, will open bridge website."
|
3195
|
+
});
|
3196
|
+
const config = yield getConfig(isDev);
|
3197
|
+
window.open(config.bridgeUrl, "_blank");
|
3198
|
+
throw new Error("Gas token balance is insufficient");
|
3199
|
+
}
|
3200
|
+
});
|
3201
|
+
}
|
3175
3202
|
function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
3176
3203
|
return __async(this, null, function* () {
|
3177
3204
|
if (!debtInfo)
|
@@ -3224,16 +3251,17 @@ function getBtcBalance() {
|
|
3224
3251
|
}
|
3225
3252
|
const btcRpcUrl = yield getBtcRpcUrl();
|
3226
3253
|
const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
|
3254
|
+
const btcDecimals = 8;
|
3227
3255
|
const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
|
3228
|
-
const balance = rawBalance / __pow(10,
|
3256
|
+
const balance = rawBalance / __pow(10, btcDecimals);
|
3229
3257
|
const feeRate = yield getBtcGasPrice();
|
3230
3258
|
const inputSize = ((utxos == null ? void 0 : utxos.length) || 0) * 66;
|
3231
3259
|
const outputSize = 34;
|
3232
3260
|
const overheadSize = 10;
|
3233
3261
|
const estimatedTxSize = inputSize + outputSize + overheadSize;
|
3234
|
-
const estimatedFee = estimatedTxSize * feeRate
|
3235
|
-
|
3236
|
-
const availableBalance =
|
3262
|
+
const estimatedFee = estimatedTxSize * feeRate;
|
3263
|
+
const availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
|
3264
|
+
const availableBalance = new Big(availableRawBalance).div(__pow(10, btcDecimals)).round(btcDecimals, Big.roundDown).toNumber();
|
3237
3265
|
return {
|
3238
3266
|
rawBalance,
|
3239
3267
|
balance,
|
@@ -3248,8 +3276,6 @@ function sendBitcoin(address, amount, feeRate) {
|
|
3248
3276
|
return txHash;
|
3249
3277
|
});
|
3250
3278
|
}
|
3251
|
-
var MINIMUM_DEPOSIT_AMOUNT = 5e3;
|
3252
|
-
var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
|
3253
3279
|
function estimateDepositAmount(amount, option) {
|
3254
3280
|
return __async(this, null, function* () {
|
3255
3281
|
const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
|
@@ -3312,7 +3338,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3312
3338
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3313
3339
|
const newActions = [];
|
3314
3340
|
const gasLimit = new Big(50).mul(__pow(10, 12)).toFixed(0);
|
3315
|
-
const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev, false);
|
3341
|
+
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, false);
|
3316
3342
|
if (repayAction) {
|
3317
3343
|
newActions.push(__spreadProps(__spreadValues({}, repayAction), {
|
3318
3344
|
gas: gasLimit
|
@@ -3581,10 +3607,11 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3581
3607
|
const btcContext = window.btcContext;
|
3582
3608
|
const accountId = state.getAccount();
|
3583
3609
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3584
|
-
yield
|
3610
|
+
yield checkGasTokenBalance(accountId, currentConfig.token, isDev);
|
3611
|
+
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, true);
|
3585
3612
|
const trans = [...params.transactions];
|
3586
3613
|
console.log("raw trans:", trans);
|
3587
|
-
const gasTokenBalance = accountInfo.gas_token[currentConfig.token] || "0";
|
3614
|
+
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
3588
3615
|
const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy(
|
3589
3616
|
gasTokenBalance,
|
3590
3617
|
trans
|
@@ -3600,7 +3627,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3600
3627
|
trans.map((transaction, index) => convertTransactionToTxHex(transaction, index))
|
3601
3628
|
);
|
3602
3629
|
const nonceFromApi = yield getNonce(currentConfig.base_url, accountId);
|
3603
|
-
const nonce = Number(nonceFromApi) > Number(accountInfo.nonce) ? String(nonceFromApi) : String(accountInfo.nonce);
|
3630
|
+
const nonce = Number(nonceFromApi) > Number(accountInfo == null ? void 0 : accountInfo.nonce) ? String(nonceFromApi) : String(accountInfo == null ? void 0 : accountInfo.nonce);
|
3604
3631
|
const intention = {
|
3605
3632
|
chain_id: "397",
|
3606
3633
|
csna: accountId,
|
@@ -3817,6 +3844,7 @@ function setupBTCWallet({
|
|
3817
3844
|
syncLogOut = true,
|
3818
3845
|
isDev = false
|
3819
3846
|
} = {}) {
|
3847
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion());
|
3820
3848
|
const btcWallet = () => __async(this, null, function* () {
|
3821
3849
|
return {
|
3822
3850
|
id: "btc-wallet",
|
@@ -3840,10 +3868,10 @@ function setupBTCWallet({
|
|
3840
3868
|
|
3841
3869
|
// src/index.ts
|
3842
3870
|
var getVersion = () => {
|
3843
|
-
return "0.3.
|
3871
|
+
return "0.3.16";
|
3844
3872
|
};
|
3845
3873
|
if (typeof window !== "undefined") {
|
3846
|
-
window.
|
3874
|
+
window.__BTC_WALLET_VERSION = getVersion();
|
3847
3875
|
}
|
3848
3876
|
export {
|
3849
3877
|
BaseConnector,
|
@@ -3859,6 +3887,7 @@ export {
|
|
3859
3887
|
WizzConnector,
|
3860
3888
|
XverseConnector,
|
3861
3889
|
checkGasTokenArrears,
|
3890
|
+
checkGasTokenBalance,
|
3862
3891
|
estimateDepositAmount,
|
3863
3892
|
executeBTCDepositAndAction,
|
3864
3893
|
getAccountInfo,
|