btc-wallet 0.3.13 → 0.3.15
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 +4 -2
- package/dist/index.js +37 -17
- package/dist/index.js.map +3 -3
- package/esm/index.js +37 -17
- 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
@@ -9,11 +9,13 @@ export declare function getAccountInfo(csna: string, accountContractId: string):
|
|
9
9
|
gas_token: Record<string, string>;
|
10
10
|
debt_info: DebtInfo;
|
11
11
|
}>;
|
12
|
-
export declare function
|
12
|
+
export declare function checkGasTokenBalance(csna: string, gasToken: string, isDev: boolean): Promise<void>;
|
13
|
+
type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
|
13
14
|
receiver_id: string;
|
14
15
|
amount: string;
|
15
16
|
msg: string;
|
16
|
-
} | undefined
|
17
|
+
} | undefined;
|
18
|
+
export declare function checkGasTokenArrears<T extends boolean>(debtInfo: DebtInfo | undefined, isDev: boolean, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
|
17
19
|
export declare function getBtcGasPrice(): Promise<number>;
|
18
20
|
export declare function getBtcBalance(): Promise<{
|
19
21
|
rawBalance: number;
|
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 = {
|
@@ -3178,6 +3182,8 @@ Dialog.style = `
|
|
3178
3182
|
`;
|
3179
3183
|
|
3180
3184
|
// src/core/btcUtils.ts
|
3185
|
+
var MINIMUM_DEPOSIT_AMOUNT = 5e3;
|
3186
|
+
var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
|
3181
3187
|
function getBtcProvider() {
|
3182
3188
|
if (typeof window === "undefined" || !window.btcContext) {
|
3183
3189
|
throw new Error("BTC Provider is not initialized.");
|
@@ -3215,15 +3221,30 @@ function getAccountInfo(csna, accountContractId) {
|
|
3215
3221
|
return accountInfo;
|
3216
3222
|
});
|
3217
3223
|
}
|
3224
|
+
function checkGasTokenBalance(csna, gasToken, isDev) {
|
3225
|
+
return __async(this, null, function* () {
|
3226
|
+
const amount = yield nearCall(gasToken, "ft_balance_of", { account_id: csna });
|
3227
|
+
console.log("gas token balance:", amount);
|
3228
|
+
if (new import_big.default(amount).lte(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3229
|
+
yield Dialog.confirm({
|
3230
|
+
title: "Gas token balance is insufficient",
|
3231
|
+
message: "Please deposit gas token to continue, will open bridge website."
|
3232
|
+
});
|
3233
|
+
const config = yield getConfig(isDev);
|
3234
|
+
window.open(config.bridgeUrl, "_blank");
|
3235
|
+
throw new Error("Gas token balance is insufficient");
|
3236
|
+
}
|
3237
|
+
});
|
3238
|
+
}
|
3218
3239
|
function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
|
3219
3240
|
return __async(this, null, function* () {
|
3241
|
+
if (!debtInfo)
|
3242
|
+
return;
|
3220
3243
|
const config = yield getConfig(isDev);
|
3221
|
-
const transferAmount = debtInfo.transfer_amount
|
3244
|
+
const transferAmount = debtInfo.transfer_amount;
|
3222
3245
|
console.log("get_account debtInfo:", debtInfo);
|
3223
|
-
if (transferAmount === "0")
|
3224
|
-
return;
|
3225
3246
|
const action = {
|
3226
|
-
receiver_id: config.
|
3247
|
+
receiver_id: config.accountContractId,
|
3227
3248
|
amount: transferAmount,
|
3228
3249
|
msg: JSON.stringify("Deposit")
|
3229
3250
|
};
|
@@ -3291,8 +3312,6 @@ function sendBitcoin(address, amount, feeRate) {
|
|
3291
3312
|
return txHash;
|
3292
3313
|
});
|
3293
3314
|
}
|
3294
|
-
var MINIMUM_DEPOSIT_AMOUNT = 5e3;
|
3295
|
-
var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
|
3296
3315
|
function estimateDepositAmount(amount, option) {
|
3297
3316
|
return __async(this, null, function* () {
|
3298
3317
|
const { receiveAmount } = yield getDepositAmount(amount, __spreadProps(__spreadValues({}, option), { isEstimate: true }));
|
@@ -3349,13 +3368,13 @@ function executeBTCDepositAndAction(_0) {
|
|
3349
3368
|
if (new import_big.default(rawDepositAmount).lt(0)) {
|
3350
3369
|
throw new Error("amount must be greater than 0");
|
3351
3370
|
}
|
3352
|
-
const { depositAmount } = yield getDepositAmount(rawDepositAmount, {
|
3371
|
+
const { depositAmount, receiveAmount } = yield getDepositAmount(rawDepositAmount, {
|
3353
3372
|
isDev
|
3354
3373
|
});
|
3355
3374
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3356
3375
|
const newActions = [];
|
3357
3376
|
const gasLimit = new import_big.default(50).mul(__pow(10, 12)).toFixed(0);
|
3358
|
-
const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev);
|
3377
|
+
const repayAction = yield checkGasTokenArrears(accountInfo.debt_info, isDev, false);
|
3359
3378
|
if (repayAction) {
|
3360
3379
|
newActions.push(__spreadProps(__spreadValues({}, repayAction), {
|
3361
3380
|
gas: gasLimit
|
@@ -3363,7 +3382,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3363
3382
|
}
|
3364
3383
|
if (action) {
|
3365
3384
|
newActions.push(__spreadProps(__spreadValues({}, action), {
|
3366
|
-
amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(
|
3385
|
+
amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
|
3367
3386
|
gas: gasLimit
|
3368
3387
|
}));
|
3369
3388
|
}
|
@@ -3624,6 +3643,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3624
3643
|
const btcContext = window.btcContext;
|
3625
3644
|
const accountId = state.getAccount();
|
3626
3645
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3646
|
+
yield checkGasTokenBalance(accountId, currentConfig.token, isDev);
|
3627
3647
|
yield checkGasTokenArrears(accountInfo.debt_info, isDev, true);
|
3628
3648
|
const trans = [...params.transactions];
|
3629
3649
|
console.log("raw trans:", trans);
|
@@ -3883,7 +3903,7 @@ function setupBTCWallet({
|
|
3883
3903
|
|
3884
3904
|
// src/index.ts
|
3885
3905
|
var getVersion = () => {
|
3886
|
-
return "0.3.
|
3906
|
+
return "0.3.15";
|
3887
3907
|
};
|
3888
3908
|
if (typeof window !== "undefined") {
|
3889
3909
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|