btc-wallet 0.3.14 → 0.3.16
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 +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/dist/config.d.ts
CHANGED
package/dist/core/btcUtils.d.ts
CHANGED
@@ -7,8 +7,9 @@ export interface DebtInfo {
|
|
7
7
|
export declare function getAccountInfo(csna: string, accountContractId: string): Promise<{
|
8
8
|
nonce: string;
|
9
9
|
gas_token: Record<string, string>;
|
10
|
-
debt_info
|
11
|
-
}>;
|
10
|
+
debt_info?: DebtInfo;
|
11
|
+
} | undefined>;
|
12
|
+
export declare function checkGasTokenBalance(csna: string, gasToken: string, isDev: boolean): Promise<void>;
|
12
13
|
type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
|
13
14
|
receiver_id: string;
|
14
15
|
amount: string;
|
package/dist/index.js
CHANGED
@@ -91,6 +91,7 @@ __export(src_exports, {
|
|
91
91
|
WizzConnector: () => WizzConnector,
|
92
92
|
XverseConnector: () => XverseConnector,
|
93
93
|
checkGasTokenArrears: () => checkGasTokenArrears,
|
94
|
+
checkGasTokenBalance: () => checkGasTokenBalance,
|
94
95
|
estimateDepositAmount: () => estimateDepositAmount,
|
95
96
|
executeBTCDepositAndAction: () => executeBTCDepositAndAction,
|
96
97
|
getAccountInfo: () => getAccountInfo,
|
@@ -2729,21 +2730,24 @@ var walletConfig = {
|
|
2729
2730
|
token: "nbtc-dev.testnet",
|
2730
2731
|
accountContractId: "acc-dev.testnet",
|
2731
2732
|
bridgeContractId: "brg-dev.testnet",
|
2732
|
-
walletUrl: "https://wallet-dev.satoshibridge.top"
|
2733
|
+
walletUrl: "https://wallet-dev.satoshibridge.top",
|
2734
|
+
bridgeUrl: "https://dev.satoshibridge.top/"
|
2733
2735
|
},
|
2734
2736
|
testnet: {
|
2735
2737
|
base_url: "https://api.testnet.satoshibridge.top",
|
2736
2738
|
token: "nbtc2-nsp.testnet",
|
2737
|
-
accountContractId: "
|
2739
|
+
accountContractId: "acc2-nsp.testnet",
|
2738
2740
|
bridgeContractId: "brg2-nsp.testnet",
|
2739
|
-
walletUrl: "https://wallet-test.satoshibridge.top"
|
2741
|
+
walletUrl: "https://wallet-test.satoshibridge.top",
|
2742
|
+
bridgeUrl: "https://testnet.satoshibridge.top/"
|
2740
2743
|
},
|
2741
2744
|
mainnet: {
|
2742
2745
|
base_url: "https://api.mainnet.satoshibridge.top",
|
2743
|
-
token: "",
|
2744
|
-
accountContractId: "",
|
2745
|
-
bridgeContractId: "",
|
2746
|
-
walletUrl: "https://wallet.satoshibridge.top"
|
2746
|
+
token: "nbtc.toalice.near",
|
2747
|
+
accountContractId: "acc.toalice.near",
|
2748
|
+
bridgeContractId: "brg.toalice.near",
|
2749
|
+
walletUrl: "https://wallet.satoshibridge.top",
|
2750
|
+
bridgeUrl: "https://www.satoshibridge.top/"
|
2747
2751
|
}
|
2748
2752
|
};
|
2749
2753
|
var nearRpcUrls = {
|
@@ -2871,7 +2875,13 @@ function request(url, options) {
|
|
2871
2875
|
if (options.shouldStopPolling(data)) {
|
2872
2876
|
return data;
|
2873
2877
|
}
|
2874
|
-
|
2878
|
+
if (options.maxPollingAttempts && options.maxPollingAttempts > 0) {
|
2879
|
+
yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
|
2880
|
+
return request(url, __spreadProps(__spreadValues({}, options), {
|
2881
|
+
maxPollingAttempts: options.maxPollingAttempts - 1
|
2882
|
+
}));
|
2883
|
+
}
|
2884
|
+
throw new Error("Polling failed: maximum attempts reached without meeting the condition");
|
2875
2885
|
}
|
2876
2886
|
if (cacheKey) {
|
2877
2887
|
cache.set(cacheKey, { timestamp: Date.now(), data });
|
@@ -3178,6 +3188,8 @@ Dialog.style = `
|
|
3178
3188
|
`;
|
3179
3189
|
|
3180
3190
|
// src/core/btcUtils.ts
|
3191
|
+
var MINIMUM_DEPOSIT_AMOUNT = 5e3;
|
3192
|
+
var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
|
3181
3193
|
function getBtcProvider() {
|
3182
3194
|
if (typeof window === "undefined" || !window.btcContext) {
|
3183
3195
|
throw new Error("BTC Provider is not initialized.");
|
@@ -3212,9 +3224,25 @@ function nearCall(contractId, methodName, args) {
|
|
3212
3224
|
function getAccountInfo(csna, accountContractId) {
|
3213
3225
|
return __async(this, null, function* () {
|
3214
3226
|
const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
|
3227
|
+
console.log("get_account accountInfo:", accountInfo);
|
3215
3228
|
return accountInfo;
|
3216
3229
|
});
|
3217
3230
|
}
|
3231
|
+
function checkGasTokenBalance(csna, gasToken, isDev) {
|
3232
|
+
return __async(this, null, function* () {
|
3233
|
+
const amount = yield nearCall(gasToken, "ft_balance_of", { account_id: csna });
|
3234
|
+
console.log("gas token balance:", amount);
|
3235
|
+
if (new import_big.default(amount).lte(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3236
|
+
yield Dialog.confirm({
|
3237
|
+
title: "Gas token balance is insufficient",
|
3238
|
+
message: "Please deposit gas token to continue, will open bridge website."
|
3239
|
+
});
|
3240
|
+
const config = yield getConfig(isDev);
|
3241
|
+
window.open(config.bridgeUrl, "_blank");
|
3242
|
+
throw new Error("Gas token balance is insufficient");
|
3243
|
+
}
|
3244
|
+
});
|
3245
|
+
}
|
3218
3246
|
function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
3219
3247
|
return __async(this, null, function* () {
|
3220
3248
|
if (!debtInfo)
|
@@ -3267,16 +3295,17 @@ function getBtcBalance() {
|
|
3267
3295
|
}
|
3268
3296
|
const btcRpcUrl = yield getBtcRpcUrl();
|
3269
3297
|
const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
|
3298
|
+
const btcDecimals = 8;
|
3270
3299
|
const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
|
3271
|
-
const balance = rawBalance / __pow(10,
|
3300
|
+
const balance = rawBalance / __pow(10, btcDecimals);
|
3272
3301
|
const feeRate = yield getBtcGasPrice();
|
3273
3302
|
const inputSize = ((utxos == null ? void 0 : utxos.length) || 0) * 66;
|
3274
3303
|
const outputSize = 34;
|
3275
3304
|
const overheadSize = 10;
|
3276
3305
|
const estimatedTxSize = inputSize + outputSize + overheadSize;
|
3277
|
-
const estimatedFee = estimatedTxSize * feeRate
|
3278
|
-
|
3279
|
-
const availableBalance =
|
3306
|
+
const estimatedFee = estimatedTxSize * feeRate;
|
3307
|
+
const availableRawBalance = (rawBalance - estimatedFee).toFixed(0);
|
3308
|
+
const availableBalance = new import_big.default(availableRawBalance).div(__pow(10, btcDecimals)).round(btcDecimals, import_big.default.roundDown).toNumber();
|
3280
3309
|
return {
|
3281
3310
|
rawBalance,
|
3282
3311
|
balance,
|
@@ -3291,8 +3320,6 @@ function sendBitcoin(address, amount, feeRate) {
|
|
3291
3320
|
return txHash;
|
3292
3321
|
});
|
3293
3322
|
}
|
3294
|
-
var MINIMUM_DEPOSIT_AMOUNT = 5e3;
|
3295
|
-
var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
|
3296
3323
|
function estimateDepositAmount(amount, option) {
|
3297
3324
|
return __async(this, null, function* () {
|
3298
3325
|
const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
|
@@ -3355,7 +3382,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3355
3382
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3356
3383
|
const newActions = [];
|
3357
3384
|
const gasLimit = new import_big.default(50).mul(__pow(10, 12)).toFixed(0);
|
3358
|
-
const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev, false);
|
3385
|
+
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, false);
|
3359
3386
|
if (repayAction) {
|
3360
3387
|
newActions.push(__spreadProps(__spreadValues({}, repayAction), {
|
3361
3388
|
gas: gasLimit
|
@@ -3624,10 +3651,11 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3624
3651
|
const btcContext = window.btcContext;
|
3625
3652
|
const accountId = state.getAccount();
|
3626
3653
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3627
|
-
yield
|
3654
|
+
yield checkGasTokenBalance(accountId, currentConfig.token, isDev);
|
3655
|
+
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, true);
|
3628
3656
|
const trans = [...params.transactions];
|
3629
3657
|
console.log("raw trans:", trans);
|
3630
|
-
const gasTokenBalance = accountInfo.gas_token[currentConfig.token] || "0";
|
3658
|
+
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
3631
3659
|
const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy(
|
3632
3660
|
gasTokenBalance,
|
3633
3661
|
trans
|
@@ -3643,7 +3671,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3643
3671
|
trans.map((transaction, index) => convertTransactionToTxHex(transaction, index))
|
3644
3672
|
);
|
3645
3673
|
const nonceFromApi = yield getNonce(currentConfig.base_url, accountId);
|
3646
|
-
const nonce = Number(nonceFromApi) > Number(accountInfo.nonce) ? String(nonceFromApi) : String(accountInfo.nonce);
|
3674
|
+
const nonce = Number(nonceFromApi) > Number(accountInfo == null ? void 0 : accountInfo.nonce) ? String(nonceFromApi) : String(accountInfo == null ? void 0 : accountInfo.nonce);
|
3647
3675
|
const intention = {
|
3648
3676
|
chain_id: "397",
|
3649
3677
|
csna: accountId,
|
@@ -3860,6 +3888,7 @@ function setupBTCWallet({
|
|
3860
3888
|
syncLogOut = true,
|
3861
3889
|
isDev = false
|
3862
3890
|
} = {}) {
|
3891
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion());
|
3863
3892
|
const btcWallet = () => __async(this, null, function* () {
|
3864
3893
|
return {
|
3865
3894
|
id: "btc-wallet",
|
@@ -3883,9 +3912,9 @@ function setupBTCWallet({
|
|
3883
3912
|
|
3884
3913
|
// src/index.ts
|
3885
3914
|
var getVersion = () => {
|
3886
|
-
return "0.3.
|
3915
|
+
return "0.3.16";
|
3887
3916
|
};
|
3888
3917
|
if (typeof window !== "undefined") {
|
3889
|
-
window.
|
3918
|
+
window.__BTC_WALLET_VERSION = getVersion();
|
3890
3919
|
}
|
3891
3920
|
//# sourceMappingURL=index.js.map
|