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
@@ -4,4 +4,4 @@ export declare function nearCallFunction<T>(contractId: string, methodName: stri
|
|
4
4
|
network?: string;
|
5
5
|
provider?: ProviderService;
|
6
6
|
}): Promise<T>;
|
7
|
-
export declare function pollTransactionStatuses(network: string, hashes: string[]): Promise<
|
7
|
+
export declare function pollTransactionStatuses(network: string, hashes: string[]): Promise<providers.FinalExecutionOutcome[]>;
|
package/esm/index.js
CHANGED
@@ -2788,10 +2788,10 @@ function pollTransactionStatuses(network, hashes) {
|
|
2788
2788
|
currentAttempt++;
|
2789
2789
|
const promises = Array.from(pendingHashes).map((hash) => __async(this, null, function* () {
|
2790
2790
|
try {
|
2791
|
-
const
|
2792
|
-
if (
|
2793
|
-
console.log(`Transaction ${hash} result:`,
|
2794
|
-
results.set(hash,
|
2791
|
+
const result2 = yield provider.txStatus(hash, "unused", "FINAL");
|
2792
|
+
if (result2 && result2.status) {
|
2793
|
+
console.log(`Transaction ${hash} result:`, result2);
|
2794
|
+
results.set(hash, result2);
|
2795
2795
|
pendingHashes.delete(hash);
|
2796
2796
|
}
|
2797
2797
|
} catch (error) {
|
@@ -2811,7 +2811,8 @@ function pollTransactionStatuses(network, hashes) {
|
|
2811
2811
|
yield delay(1e4);
|
2812
2812
|
}
|
2813
2813
|
}
|
2814
|
-
|
2814
|
+
const result = hashes.map((hash) => results.get(hash)).filter(Boolean);
|
2815
|
+
return result;
|
2815
2816
|
});
|
2816
2817
|
}
|
2817
2818
|
|
@@ -3262,6 +3263,14 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
|
3262
3263
|
}
|
3263
3264
|
});
|
3264
3265
|
}
|
3266
|
+
function queryGasTokenArrears(isDev) {
|
3267
|
+
return __async(this, null, function* () {
|
3268
|
+
const config = yield getConfig(isDev || false);
|
3269
|
+
const csna = yield getCsnaAccountId(isDev);
|
3270
|
+
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3271
|
+
return accountInfo == null ? void 0 : accountInfo.debt_info;
|
3272
|
+
});
|
3273
|
+
}
|
3265
3274
|
function getBtcGasPrice() {
|
3266
3275
|
return __async(this, null, function* () {
|
3267
3276
|
const network = yield getNetwork();
|
@@ -3337,6 +3346,21 @@ function getDepositAmount(amount, option) {
|
|
3337
3346
|
};
|
3338
3347
|
});
|
3339
3348
|
}
|
3349
|
+
function getCsnaAccountId(isDev) {
|
3350
|
+
return __async(this, null, function* () {
|
3351
|
+
const config = yield getConfig(isDev || false);
|
3352
|
+
const { getPublicKey } = getBtcProvider();
|
3353
|
+
const btcPublicKey = yield getPublicKey();
|
3354
|
+
const csna = yield nearCall(
|
3355
|
+
config.accountContractId,
|
3356
|
+
"get_chain_signature_near_account_id",
|
3357
|
+
{
|
3358
|
+
btc_public_key: btcPublicKey
|
3359
|
+
}
|
3360
|
+
);
|
3361
|
+
return csna;
|
3362
|
+
});
|
3363
|
+
}
|
3340
3364
|
function executeBTCDepositAndAction(_0) {
|
3341
3365
|
return __async(this, arguments, function* ({
|
3342
3366
|
action,
|
@@ -3357,13 +3381,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3357
3381
|
if (!amount && !action) {
|
3358
3382
|
throw new Error("amount or action is required");
|
3359
3383
|
}
|
3360
|
-
const csna = yield
|
3361
|
-
config.accountContractId,
|
3362
|
-
"get_chain_signature_near_account_id",
|
3363
|
-
{
|
3364
|
-
btc_public_key: btcPublicKey
|
3365
|
-
}
|
3366
|
-
);
|
3384
|
+
const csna = yield getCsnaAccountId(isDev);
|
3367
3385
|
const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
|
3368
3386
|
if (new Big(rawDepositAmount).lt(0)) {
|
3369
3387
|
throw new Error("amount must be greater than 0");
|
@@ -3380,11 +3398,18 @@ function executeBTCDepositAndAction(_0) {
|
|
3380
3398
|
gas: gasLimit
|
3381
3399
|
}));
|
3382
3400
|
}
|
3383
|
-
if (action) {
|
3384
|
-
newActions.push(
|
3385
|
-
|
3386
|
-
|
3387
|
-
|
3401
|
+
if (action || !action && new Big((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3402
|
+
newActions.push(
|
3403
|
+
action ? __spreadProps(__spreadValues({}, action), {
|
3404
|
+
amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
|
3405
|
+
gas: gasLimit
|
3406
|
+
}) : {
|
3407
|
+
receiver_id: config.accountContractId,
|
3408
|
+
amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
|
3409
|
+
msg: JSON.stringify("Deposit"),
|
3410
|
+
gas: gasLimit
|
3411
|
+
}
|
3412
|
+
);
|
3388
3413
|
}
|
3389
3414
|
const depositMsg = {
|
3390
3415
|
recipient_id: csna,
|
@@ -3574,21 +3599,17 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3574
3599
|
}
|
3575
3600
|
function getNearAccountByBtcPublicKey(btcPublicKey) {
|
3576
3601
|
return __async(this, null, function* () {
|
3577
|
-
const
|
3578
|
-
currentConfig.accountContractId,
|
3579
|
-
"get_chain_signature_near_account_id",
|
3580
|
-
{ btc_public_key: btcPublicKey }
|
3581
|
-
);
|
3602
|
+
const csna = yield getCsnaAccountId(isDev);
|
3582
3603
|
const nearPublicKey = yield nearCall2(
|
3583
3604
|
currentConfig.accountContractId,
|
3584
3605
|
"get_chain_signature_near_account_public_key",
|
3585
3606
|
{ btc_public_key: btcPublicKey }
|
3586
3607
|
);
|
3587
|
-
state.saveAccount(
|
3608
|
+
state.saveAccount(csna);
|
3588
3609
|
state.savePublicKey(nearPublicKey);
|
3589
3610
|
state.saveBtcPublicKey(btcPublicKey);
|
3590
3611
|
return {
|
3591
|
-
nearAddress,
|
3612
|
+
nearAddress: csna,
|
3592
3613
|
nearPublicKey
|
3593
3614
|
};
|
3594
3615
|
});
|
@@ -3927,7 +3948,7 @@ function setupBTCWallet({
|
|
3927
3948
|
|
3928
3949
|
// src/index.ts
|
3929
3950
|
var getVersion = () => {
|
3930
|
-
return "0.3.
|
3951
|
+
return "0.3.23";
|
3931
3952
|
};
|
3932
3953
|
if (typeof window !== "undefined") {
|
3933
3954
|
window.__BTC_WALLET_VERSION = getVersion();
|
@@ -3952,8 +3973,10 @@ export {
|
|
3952
3973
|
getAccountInfo,
|
3953
3974
|
getBtcBalance,
|
3954
3975
|
getBtcGasPrice,
|
3976
|
+
getCsnaAccountId,
|
3955
3977
|
getDepositAmount,
|
3956
3978
|
getVersion,
|
3979
|
+
queryGasTokenArrears,
|
3957
3980
|
sendBitcoin,
|
3958
3981
|
setupBTCWallet,
|
3959
3982
|
useAccountContract,
|