btc-wallet 0.3.21 → 0.3.23
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/core/btcUtils.d.ts +2 -0
- package/dist/index.js +48 -25
- package/dist/index.js.map +3 -3
- package/dist/utils/nearUtils.d.ts +1 -1
- package/esm/index.js +48 -25
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/core/btcUtils.d.ts
CHANGED
@@ -17,6 +17,7 @@ type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void :
|
|
17
17
|
msg: string;
|
18
18
|
} | undefined;
|
19
19
|
export declare function checkGasTokenArrears<T extends boolean>(debtInfo: DebtInfo | undefined, isDev: boolean, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
|
20
|
+
export declare function queryGasTokenArrears(isDev?: boolean): Promise<DebtInfo | undefined>;
|
20
21
|
export declare function getBtcGasPrice(): Promise<number>;
|
21
22
|
export declare function getBtcBalance(): Promise<{
|
22
23
|
rawBalance: number;
|
@@ -41,6 +42,7 @@ export declare function getDepositAmount(amount: string, option?: {
|
|
41
42
|
receiveAmount: number;
|
42
43
|
fee: number;
|
43
44
|
}>;
|
45
|
+
export declare function getCsnaAccountId(isDev?: boolean): Promise<string>;
|
44
46
|
interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
|
45
47
|
action?: {
|
46
48
|
receiver_id: string;
|
package/dist/index.js
CHANGED
@@ -97,8 +97,10 @@ __export(src_exports, {
|
|
97
97
|
getAccountInfo: () => getAccountInfo,
|
98
98
|
getBtcBalance: () => getBtcBalance,
|
99
99
|
getBtcGasPrice: () => getBtcGasPrice,
|
100
|
+
getCsnaAccountId: () => getCsnaAccountId,
|
100
101
|
getDepositAmount: () => getDepositAmount,
|
101
102
|
getVersion: () => getVersion,
|
103
|
+
queryGasTokenArrears: () => queryGasTokenArrears,
|
102
104
|
sendBitcoin: () => sendBitcoin,
|
103
105
|
setupBTCWallet: () => setupBTCWallet,
|
104
106
|
useAccountContract: () => useAccountContract,
|
@@ -2832,10 +2834,10 @@ function pollTransactionStatuses(network, hashes) {
|
|
2832
2834
|
currentAttempt++;
|
2833
2835
|
const promises = Array.from(pendingHashes).map((hash) => __async(this, null, function* () {
|
2834
2836
|
try {
|
2835
|
-
const
|
2836
|
-
if (
|
2837
|
-
console.log(`Transaction ${hash} result:`,
|
2838
|
-
results.set(hash,
|
2837
|
+
const result2 = yield provider.txStatus(hash, "unused", "FINAL");
|
2838
|
+
if (result2 && result2.status) {
|
2839
|
+
console.log(`Transaction ${hash} result:`, result2);
|
2840
|
+
results.set(hash, result2);
|
2839
2841
|
pendingHashes.delete(hash);
|
2840
2842
|
}
|
2841
2843
|
} catch (error) {
|
@@ -2855,7 +2857,8 @@ function pollTransactionStatuses(network, hashes) {
|
|
2855
2857
|
yield delay(1e4);
|
2856
2858
|
}
|
2857
2859
|
}
|
2858
|
-
|
2860
|
+
const result = hashes.map((hash) => results.get(hash)).filter(Boolean);
|
2861
|
+
return result;
|
2859
2862
|
});
|
2860
2863
|
}
|
2861
2864
|
|
@@ -3306,6 +3309,14 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
|
3306
3309
|
}
|
3307
3310
|
});
|
3308
3311
|
}
|
3312
|
+
function queryGasTokenArrears(isDev) {
|
3313
|
+
return __async(this, null, function* () {
|
3314
|
+
const config = yield getConfig(isDev || false);
|
3315
|
+
const csna = yield getCsnaAccountId(isDev);
|
3316
|
+
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3317
|
+
return accountInfo == null ? void 0 : accountInfo.debt_info;
|
3318
|
+
});
|
3319
|
+
}
|
3309
3320
|
function getBtcGasPrice() {
|
3310
3321
|
return __async(this, null, function* () {
|
3311
3322
|
const network = yield getNetwork();
|
@@ -3381,6 +3392,21 @@ function getDepositAmount(amount, option) {
|
|
3381
3392
|
};
|
3382
3393
|
});
|
3383
3394
|
}
|
3395
|
+
function getCsnaAccountId(isDev) {
|
3396
|
+
return __async(this, null, function* () {
|
3397
|
+
const config = yield getConfig(isDev || false);
|
3398
|
+
const { getPublicKey } = getBtcProvider();
|
3399
|
+
const btcPublicKey = yield getPublicKey();
|
3400
|
+
const csna = yield nearCall(
|
3401
|
+
config.accountContractId,
|
3402
|
+
"get_chain_signature_near_account_id",
|
3403
|
+
{
|
3404
|
+
btc_public_key: btcPublicKey
|
3405
|
+
}
|
3406
|
+
);
|
3407
|
+
return csna;
|
3408
|
+
});
|
3409
|
+
}
|
3384
3410
|
function executeBTCDepositAndAction(_0) {
|
3385
3411
|
return __async(this, arguments, function* ({
|
3386
3412
|
action,
|
@@ -3401,13 +3427,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3401
3427
|
if (!amount && !action) {
|
3402
3428
|
throw new Error("amount or action is required");
|
3403
3429
|
}
|
3404
|
-
const csna = yield
|
3405
|
-
config.accountContractId,
|
3406
|
-
"get_chain_signature_near_account_id",
|
3407
|
-
{
|
3408
|
-
btc_public_key: btcPublicKey
|
3409
|
-
}
|
3410
|
-
);
|
3430
|
+
const csna = yield getCsnaAccountId(isDev);
|
3411
3431
|
const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
|
3412
3432
|
if (new import_big.default(rawDepositAmount).lt(0)) {
|
3413
3433
|
throw new Error("amount must be greater than 0");
|
@@ -3424,11 +3444,18 @@ function executeBTCDepositAndAction(_0) {
|
|
3424
3444
|
gas: gasLimit
|
3425
3445
|
}));
|
3426
3446
|
}
|
3427
|
-
if (action) {
|
3428
|
-
newActions.push(
|
3429
|
-
|
3430
|
-
|
3431
|
-
|
3447
|
+
if (action || !action && new import_big.default((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3448
|
+
newActions.push(
|
3449
|
+
action ? __spreadProps(__spreadValues({}, action), {
|
3450
|
+
amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
|
3451
|
+
gas: gasLimit
|
3452
|
+
}) : {
|
3453
|
+
receiver_id: config.accountContractId,
|
3454
|
+
amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
|
3455
|
+
msg: JSON.stringify("Deposit"),
|
3456
|
+
gas: gasLimit
|
3457
|
+
}
|
3458
|
+
);
|
3432
3459
|
}
|
3433
3460
|
const depositMsg = {
|
3434
3461
|
recipient_id: csna,
|
@@ -3618,21 +3645,17 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3618
3645
|
}
|
3619
3646
|
function getNearAccountByBtcPublicKey(btcPublicKey) {
|
3620
3647
|
return __async(this, null, function* () {
|
3621
|
-
const
|
3622
|
-
currentConfig.accountContractId,
|
3623
|
-
"get_chain_signature_near_account_id",
|
3624
|
-
{ btc_public_key: btcPublicKey }
|
3625
|
-
);
|
3648
|
+
const csna = yield getCsnaAccountId(isDev);
|
3626
3649
|
const nearPublicKey = yield nearCall2(
|
3627
3650
|
currentConfig.accountContractId,
|
3628
3651
|
"get_chain_signature_near_account_public_key",
|
3629
3652
|
{ btc_public_key: btcPublicKey }
|
3630
3653
|
);
|
3631
|
-
state.saveAccount(
|
3654
|
+
state.saveAccount(csna);
|
3632
3655
|
state.savePublicKey(nearPublicKey);
|
3633
3656
|
state.saveBtcPublicKey(btcPublicKey);
|
3634
3657
|
return {
|
3635
|
-
nearAddress,
|
3658
|
+
nearAddress: csna,
|
3636
3659
|
nearPublicKey
|
3637
3660
|
};
|
3638
3661
|
});
|
@@ -3971,7 +3994,7 @@ function setupBTCWallet({
|
|
3971
3994
|
|
3972
3995
|
// src/index.ts
|
3973
3996
|
var getVersion = () => {
|
3974
|
-
return "0.3.
|
3997
|
+
return "0.3.23";
|
3975
3998
|
};
|
3976
3999
|
if (typeof window !== "undefined") {
|
3977
4000
|
window.__BTC_WALLET_VERSION = getVersion();
|