btc-wallet 0.3.29 → 0.3.31
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/README.md +3 -4
- package/dist/core/btcUtils.d.ts +10 -6
- package/dist/index.js +25 -28
- package/dist/index.js.map +2 -2
- package/esm/index.js +25 -28
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
@@ -75,11 +75,10 @@ interface ExecuteBTCDepositAndActionParams<T extends boolean = true> {
|
|
75
75
|
// Example 1: dApp one-click BTC deposit
|
76
76
|
await executeBTCDepositAndAction({
|
77
77
|
action: {
|
78
|
-
receiver_id: '
|
79
|
-
amount: '1000000',
|
80
|
-
msg: '
|
78
|
+
receiver_id: 'token.near',
|
79
|
+
amount: '1000000',
|
80
|
+
msg: 'ft_transfer_call message' // ft_transfer_call message
|
81
81
|
},
|
82
|
-
feeRate: 5,
|
83
82
|
registerDeposit: '100000000000000000000000', // default 0.000125 NEAR, you can set it according to your needs
|
84
83
|
});
|
85
84
|
|
package/dist/core/btcUtils.d.ts
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
import type { ENV } from '../config';
|
2
2
|
import type { FinalExecutionOutcome } from '@near-wallet-selector/core';
|
3
|
+
export interface AccountInfo {
|
4
|
+
nonce: string;
|
5
|
+
gas_token: Record<string, string>;
|
6
|
+
debt_info?: DebtInfo;
|
7
|
+
relayer_fee?: {
|
8
|
+
amount?: string;
|
9
|
+
};
|
10
|
+
}
|
3
11
|
export interface DebtInfo {
|
4
12
|
gas_token_id: string;
|
5
13
|
transfer_amount: string;
|
6
14
|
near_gas_debt_amount: string;
|
7
15
|
protocol_fee_debt_amount: string;
|
8
16
|
}
|
9
|
-
export declare function getAccountInfo(csna: string, accountContractId: string): Promise<
|
10
|
-
nonce: string;
|
11
|
-
gas_token: Record<string, string>;
|
12
|
-
debt_info?: DebtInfo;
|
13
|
-
} | undefined>;
|
17
|
+
export declare function getAccountInfo(csna: string, accountContractId: string): Promise<AccountInfo>;
|
14
18
|
export declare function checkGasTokenBalance(csna: string, gasToken: string, minAmount: string, env: ENV): Promise<void>;
|
15
19
|
type CheckGasTokenArrearsReturnType<T extends boolean> = T extends true ? void : {
|
16
20
|
receiver_id: string;
|
17
21
|
amount: string;
|
18
22
|
msg: string;
|
19
23
|
} | undefined;
|
20
|
-
export declare function checkGasTokenArrears<T extends boolean>(
|
24
|
+
export declare function checkGasTokenArrears<T extends boolean>(accountInfo: AccountInfo | undefined, env: ENV, autoDeposit?: T): Promise<CheckGasTokenArrearsReturnType<T>>;
|
21
25
|
export declare function queryGasTokenArrears(env: ENV): Promise<DebtInfo | undefined>;
|
22
26
|
export declare function getBtcGasPrice(): Promise<number>;
|
23
27
|
export declare function getBtcBalance(): Promise<{
|
package/dist/index.js
CHANGED
@@ -2271,7 +2271,6 @@ var ConnectProvider = ({
|
|
2271
2271
|
})
|
2272
2272
|
})
|
2273
2273
|
);
|
2274
|
-
console.log("walletEntryPlugin init");
|
2275
2274
|
}
|
2276
2275
|
}, [options, evmSupportChainIds, accountContract]);
|
2277
2276
|
(0, import_react10.useEffect)(() => {
|
@@ -2280,7 +2279,6 @@ var ConnectProvider = ({
|
|
2280
2279
|
import_wallet.walletEntryPlugin.setWalletCore({
|
2281
2280
|
ethereum: smartAccount.provider
|
2282
2281
|
});
|
2283
|
-
console.log("walletEntryPlugin setWalletCore");
|
2284
2282
|
}
|
2285
2283
|
}, [smartAccount, options]);
|
2286
2284
|
(0, import_react10.useEffect)(() => {
|
@@ -2288,10 +2286,8 @@ var ConnectProvider = ({
|
|
2288
2286
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2289
2287
|
if (evmAccount) {
|
2290
2288
|
import_wallet.walletEntryPlugin.walletEntryCreate();
|
2291
|
-
console.log("walletEntryPlugin walletEntryCreate");
|
2292
2289
|
} else {
|
2293
2290
|
import_wallet.walletEntryPlugin.walletEntryDestroy();
|
2294
|
-
console.log("walletEntryPlugin walletEntryDestroy");
|
2295
2291
|
}
|
2296
2292
|
}
|
2297
2293
|
}, [evmAccount, smartAccount, options]);
|
@@ -3228,8 +3224,7 @@ Dialog.style = `
|
|
3228
3224
|
`;
|
3229
3225
|
|
3230
3226
|
// src/core/btcUtils.ts
|
3231
|
-
var
|
3232
|
-
var MINIMUM_DEPOSIT_AMOUNT_BASE = 1e3;
|
3227
|
+
var MINIMUM_DEPOSIT_AMOUNT_BASE = 0;
|
3233
3228
|
var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
|
3234
3229
|
var NBTC_STORAGE_DEPOSIT_AMOUNT = 3e3;
|
3235
3230
|
var GAS_LIMIT = "50000000000000";
|
@@ -3265,7 +3260,9 @@ function nearCall(contractId, methodName, args) {
|
|
3265
3260
|
}
|
3266
3261
|
function getAccountInfo(csna, accountContractId) {
|
3267
3262
|
return __async(this, null, function* () {
|
3268
|
-
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3263
|
+
const accountInfo = yield nearCall(accountContractId, "get_account", {
|
3264
|
+
account_id: csna
|
3265
|
+
});
|
3269
3266
|
console.log("get_account accountInfo:", accountInfo);
|
3270
3267
|
return accountInfo;
|
3271
3268
|
});
|
@@ -3285,23 +3282,25 @@ function checkGasTokenBalance(csna, gasToken, minAmount, env) {
|
|
3285
3282
|
}
|
3286
3283
|
});
|
3287
3284
|
}
|
3288
|
-
function checkGasTokenArrears(
|
3285
|
+
function checkGasTokenArrears(accountInfo, env, autoDeposit) {
|
3289
3286
|
return __async(this, null, function* () {
|
3290
|
-
|
3287
|
+
var _a, _b, _c, _d;
|
3288
|
+
if (!((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.transfer_amount) || !((_b = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _b.amount))
|
3291
3289
|
return;
|
3292
3290
|
const config = yield getConfig(env);
|
3293
|
-
const
|
3294
|
-
|
3291
|
+
const arrearsType = accountInfo.debt_info.transfer_amount ? "Deposit" : ((_c = accountInfo.relayer_fee) == null ? void 0 : _c.amount) ? "RelayerFee" : void 0;
|
3292
|
+
const transferAmount = arrearsType === "Deposit" ? accountInfo.debt_info.transfer_amount : (_d = accountInfo.relayer_fee) == null ? void 0 : _d.amount;
|
3293
|
+
console.log("get_account:", accountInfo);
|
3295
3294
|
const action = {
|
3296
3295
|
receiver_id: config.accountContractId,
|
3297
3296
|
amount: transferAmount,
|
3298
|
-
msg: JSON.stringify(
|
3297
|
+
msg: JSON.stringify(arrearsType)
|
3299
3298
|
};
|
3300
3299
|
if (!autoDeposit)
|
3301
3300
|
return action;
|
3302
3301
|
const confirmed = yield Dialog.confirm({
|
3303
|
-
title: "Has gas token arrears",
|
3304
|
-
message: "You have gas token arrears, please deposit gas token to continue."
|
3302
|
+
title: arrearsType === "Deposit" ? "Has gas token arrears" : "Has relayer fee arrears",
|
3303
|
+
message: arrearsType === "Deposit" ? "You have gas token arrears, please deposit gas token to continue." : "You have relayer fee arrears, please deposit relayer fee to continue."
|
3305
3304
|
});
|
3306
3305
|
if (confirmed) {
|
3307
3306
|
yield executeBTCDepositAndAction({ action, env });
|
@@ -3380,13 +3379,10 @@ function getDepositAmount(amount, option) {
|
|
3380
3379
|
return __async(this, null, function* () {
|
3381
3380
|
const config = yield getConfig((option == null ? void 0 : option.env) || "mainnet");
|
3382
3381
|
const {
|
3383
|
-
deposit_bridge_fee: { fee_min, fee_rate }
|
3384
|
-
|
3385
|
-
|
3386
|
-
|
3387
|
-
{}
|
3388
|
-
);
|
3389
|
-
const depositAmount = (option == null ? void 0 : option.isEstimate) ? Number(amount) : Math.max(MINIMUM_DEPOSIT_AMOUNT + MINIMUM_DEPOSIT_AMOUNT_BASE, Number(amount));
|
3382
|
+
deposit_bridge_fee: { fee_min, fee_rate },
|
3383
|
+
min_deposit_amount
|
3384
|
+
} = yield nearCall(config.bridgeContractId, "get_config", {});
|
3385
|
+
const depositAmount = (option == null ? void 0 : option.isEstimate) ? Number(amount) : Math.max(Number(min_deposit_amount) + MINIMUM_DEPOSIT_AMOUNT_BASE, Number(amount));
|
3390
3386
|
const fee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
|
3391
3387
|
const receiveAmount = new import_big.default(depositAmount).minus(fee).minus(MINIMUM_DEPOSIT_AMOUNT_BASE).round(0, import_big.default.roundDown).toNumber();
|
3392
3388
|
console.log("getDepositAmount:", { depositAmount, receiveAmount, fee });
|
@@ -3443,16 +3439,16 @@ function executeBTCDepositAndAction(_0) {
|
|
3443
3439
|
});
|
3444
3440
|
const accountInfo = yield getAccountInfo(csna, config.accountContractId);
|
3445
3441
|
const newActions = [];
|
3446
|
-
const
|
3447
|
-
if (
|
3448
|
-
newActions.push(__spreadProps(__spreadValues({},
|
3442
|
+
const arrearsAction = yield checkGasTokenArrears(accountInfo, env, false);
|
3443
|
+
if (arrearsAction) {
|
3444
|
+
newActions.push(__spreadProps(__spreadValues({}, arrearsAction), {
|
3449
3445
|
gas: GAS_LIMIT
|
3450
3446
|
}));
|
3451
3447
|
}
|
3452
3448
|
if (action || !action && new import_big.default((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
|
3453
3449
|
newActions.push(
|
3454
3450
|
action ? __spreadProps(__spreadValues({}, action), {
|
3455
|
-
amount: (
|
3451
|
+
amount: (arrearsAction == null ? void 0 : arrearsAction.amount) && !fixedAmount ? new import_big.default(receiveAmount).minus(arrearsAction.amount).toString() : receiveAmount.toString(),
|
3456
3452
|
gas: GAS_LIMIT
|
3457
3453
|
}) : {
|
3458
3454
|
receiver_id: config.accountContractId,
|
@@ -3494,7 +3490,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3494
3490
|
{ deposit_msg: depositMsg }
|
3495
3491
|
);
|
3496
3492
|
const _feeRate = feeRate || (yield getBtcGasPrice());
|
3497
|
-
const sendAmount = (
|
3493
|
+
const sendAmount = (arrearsAction == null ? void 0 : arrearsAction.amount) && fixedAmount ? new import_big.default(depositAmount).plus((arrearsAction == null ? void 0 : arrearsAction.amount) || 0).toString() : depositAmount;
|
3498
3494
|
console.log("user deposit address:", userDepositAddress);
|
3499
3495
|
console.log("send amount:", sendAmount);
|
3500
3496
|
console.log("fee rate:", _feeRate);
|
@@ -3592,6 +3588,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3592
3588
|
const accountId = state.getAccount();
|
3593
3589
|
const btcContext = window.btcContext;
|
3594
3590
|
if (accountId && btcContext.account) {
|
3591
|
+
removeWalletButton();
|
3595
3592
|
setupWalletButton(env, wallet, btcContext);
|
3596
3593
|
} else {
|
3597
3594
|
removeWalletButton();
|
@@ -3743,7 +3740,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3743
3740
|
const btcContext = window.btcContext;
|
3744
3741
|
const accountId = state.getAccount();
|
3745
3742
|
const accountInfo = yield getAccountInfo(accountId, currentConfig.accountContractId);
|
3746
|
-
yield checkGasTokenArrears(accountInfo
|
3743
|
+
yield checkGasTokenArrears(accountInfo, env, true);
|
3747
3744
|
const trans = [...params.transactions];
|
3748
3745
|
console.log("raw trans:", trans);
|
3749
3746
|
const gasTokenBalance = (accountInfo == null ? void 0 : accountInfo.gas_token[currentConfig.token]) || "0";
|
@@ -4001,7 +3998,7 @@ function setupBTCWallet({
|
|
4001
3998
|
|
4002
3999
|
// src/index.ts
|
4003
4000
|
var getVersion = () => {
|
4004
|
-
return "0.3.
|
4001
|
+
return "0.3.31";
|
4005
4002
|
};
|
4006
4003
|
if (typeof window !== "undefined") {
|
4007
4004
|
window.__BTC_WALLET_VERSION = getVersion();
|