btc-wallet 0.3.15 → 0.3.16
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core/btcUtils.d.ts +2 -2
- package/dist/index.js +20 -11
- package/dist/index.js.map +2 -2
- package/esm/index.js +20 -11
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/dist/core/btcUtils.d.ts
CHANGED
@@ -7,8 +7,8 @@ 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
12
|
export declare function checkGasTokenBalance(csna: string, gasToken: string, isDev: boolean): Promise<void>;
|
13
13
|
type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
|
14
14
|
receiver_id: string;
|
package/dist/index.js
CHANGED
@@ -2875,7 +2875,13 @@ function request(url, options) {
|
|
2875
2875
|
if (options.shouldStopPolling(data)) {
|
2876
2876
|
return data;
|
2877
2877
|
}
|
2878
|
-
|
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");
|
2879
2885
|
}
|
2880
2886
|
if (cacheKey) {
|
2881
2887
|
cache.set(cacheKey, { timestamp: Date.now(), data });
|
@@ -3218,6 +3224,7 @@ function nearCall(contractId, methodName, args) {
|
|
3218
3224
|
function getAccountInfo(csna, accountContractId) {
|
3219
3225
|
return __async(this, null, function* () {
|
3220
3226
|
const accountInfo = yield nearCall(accountContractId, "get_account", { account_id: csna });
|
3227
|
+
console.log("get_account accountInfo:", accountInfo);
|
3221
3228
|
return accountInfo;
|
3222
3229
|
});
|
3223
3230
|
}
|
@@ -3288,16 +3295,17 @@ function getBtcBalance() {
|
|
3288
3295
|
}
|
3289
3296
|
const btcRpcUrl = yield getBtcRpcUrl();
|
3290
3297
|
const utxos = yield fetch(`${btcRpcUrl}/address/${account}/utxo`).then((res) => res.json());
|
3298
|
+
const btcDecimals = 8;
|
3291
3299
|
const rawBalance = (utxos == null ? void 0 : utxos.reduce((acc, cur) => acc + cur.value, 0)) || 0;
|
3292
|
-
const balance = rawBalance / __pow(10,
|
3300
|
+
const balance = rawBalance / __pow(10, btcDecimals);
|
3293
3301
|
const feeRate = yield getBtcGasPrice();
|
3294
3302
|
const inputSize = ((utxos == null ? void 0 : utxos.length) || 0) * 66;
|
3295
3303
|
const outputSize = 34;
|
3296
3304
|
const overheadSize = 10;
|
3297
3305
|
const estimatedTxSize = inputSize + outputSize + overheadSize;
|
3298
|
-
const estimatedFee = estimatedTxSize * feeRate
|
3299
|
-
|
3300
|
-
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();
|
3301
3309
|
return {
|
3302
3310
|
rawBalance,
|
3303
3311
|
balance,
|
@@ -3374,7 +3382,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3374
3382
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3375
3383
|
const newActions = [];
|
3376
3384
|
const gasLimit = new import_big.default(50).mul(__pow(10, 12)).toFixed(0);
|
3377
|
-
const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev, false);
|
3385
|
+
const repayAction = yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, false);
|
3378
3386
|
if (repayAction) {
|
3379
3387
|
newActions.push(__spreadProps(__spreadValues({}, repayAction), {
|
3380
3388
|
gas: gasLimit
|
@@ -3644,10 +3652,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3644
3652
|
const accountId = state.getAccount();
|
3645
3653
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3646
3654
|
yield checkGasTokenBalance(accountId, currentConfig.token, isDev);
|
3647
|
-
yield checkGasTokenArrears(accountInfo.debt_info, isDev, true);
|
3655
|
+
yield checkGasTokenArrears(accountInfo == null ? void 0 : accountInfo.debt_info, isDev, true);
|
3648
3656
|
const trans = [...params.transactions];
|
3649
3657
|
console.log("raw trans:", trans);
|
3650
|
-
const gasTokenBalance = accountInfo.gas_token[currentConfig.token] || "0";
|
3658
|
+
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
3651
3659
|
const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy(
|
3652
3660
|
gasTokenBalance,
|
3653
3661
|
trans
|
@@ -3663,7 +3671,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3663
3671
|
trans.map((transaction, index) => convertTransactionToTxHex(transaction, index))
|
3664
3672
|
);
|
3665
3673
|
const nonceFromApi = yield getNonce(currentConfig.base_url, accountId);
|
3666
|
-
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);
|
3667
3675
|
const intention = {
|
3668
3676
|
chain_id: "397",
|
3669
3677
|
csna: accountId,
|
@@ -3880,6 +3888,7 @@ function setupBTCWallet({
|
|
3880
3888
|
syncLogOut = true,
|
3881
3889
|
isDev = false
|
3882
3890
|
} = {}) {
|
3891
|
+
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion());
|
3883
3892
|
const btcWallet = () => __async(this, null, function* () {
|
3884
3893
|
return {
|
3885
3894
|
id: "btc-wallet",
|
@@ -3903,9 +3912,9 @@ function setupBTCWallet({
|
|
3903
3912
|
|
3904
3913
|
// src/index.ts
|
3905
3914
|
var getVersion = () => {
|
3906
|
-
return "0.3.
|
3915
|
+
return "0.3.16";
|
3907
3916
|
};
|
3908
3917
|
if (typeof window !== "undefined") {
|
3909
|
-
window.
|
3918
|
+
window.__BTC_WALLET_VERSION = getVersion();
|
3910
3919
|
}
|
3911
3920
|
//# sourceMappingURL=index.js.map
|