btc-wallet 0.5.79-beta → 0.5.81-beta
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/core/btcUtils.d.ts +7 -1
- package/dist/index.js +30 -38
- package/dist/index.js.map +2 -2
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/satoshi.d.ts +3 -7
- package/esm/index.js +30 -38
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/dist/core/btcUtils.d.ts
CHANGED
@@ -7,7 +7,12 @@ type CheckGasTokenDebtReturnType<T extends boolean> = T extends true ? void : {
|
|
7
7
|
amount: string;
|
8
8
|
msg: string;
|
9
9
|
} | undefined;
|
10
|
-
export declare function checkGasTokenDebt<T extends boolean>(csna
|
10
|
+
export declare function checkGasTokenDebt<T extends boolean>({ csna, btcAccount, env, autoDeposit, }: {
|
11
|
+
csna: string;
|
12
|
+
btcAccount: string;
|
13
|
+
env: ENV;
|
14
|
+
autoDeposit?: T;
|
15
|
+
}): Promise<CheckGasTokenDebtReturnType<T>>;
|
11
16
|
export declare function getBtcGasPrice(): Promise<number>;
|
12
17
|
export declare function getBtcUtxos(account: string): Promise<{
|
13
18
|
value: number;
|
@@ -32,6 +37,7 @@ export declare function estimateDepositAmount(amount: string, option?: {
|
|
32
37
|
}): Promise<string>;
|
33
38
|
export declare function getDepositAmount(amount: string, option?: {
|
34
39
|
csna?: string;
|
40
|
+
btcAccount?: string;
|
35
41
|
env?: ENV;
|
36
42
|
/** default is true, if true, new account minimum deposit amount 1000sat, otherwise 0 */
|
37
43
|
newAccountMinDepositAmount?: boolean;
|
package/dist/index.js
CHANGED
@@ -3060,12 +3060,7 @@ function getWalletConfig(env) {
|
|
3060
3060
|
});
|
3061
3061
|
}
|
3062
3062
|
var nearRpcUrls = {
|
3063
|
-
mainnet: [
|
3064
|
-
"https://near.lava.build",
|
3065
|
-
"https://rpc.mainnet.near.org",
|
3066
|
-
"https://free.rpc.fastnear.com",
|
3067
|
-
"https://near.drpc.org"
|
3068
|
-
],
|
3063
|
+
mainnet: ["https://near.lava.build", "https://free.rpc.fastnear.com"],
|
3069
3064
|
testnet: ["https://rpc.testnet.near.org"]
|
3070
3065
|
};
|
3071
3066
|
var btcRpcUrls = {
|
@@ -3423,23 +3418,17 @@ function receiveDepositMsg(_0) {
|
|
3423
3418
|
return result_data;
|
3424
3419
|
});
|
3425
3420
|
}
|
3426
|
-
function
|
3427
|
-
return __async(this, arguments, function* ({
|
3428
|
-
env,
|
3429
|
-
fromChainId = 0,
|
3430
|
-
fromAddress,
|
3431
|
-
page = 1,
|
3432
|
-
pageSize = 10
|
3433
|
-
}) {
|
3421
|
+
function hasBridgeTransaction(_0) {
|
3422
|
+
return __async(this, arguments, function* ({ env, btcAccount }) {
|
3434
3423
|
try {
|
3435
3424
|
const config = getWalletConfig(env);
|
3436
3425
|
const { result_data = [] } = yield request(
|
3437
|
-
`${config.base_url}/v1/history?fromChainId
|
3426
|
+
`${config.base_url}/v1/history?fromChainId=0&fromAddress=${btcAccount}&page=1&pageSize=1`
|
3438
3427
|
);
|
3439
|
-
return result_data;
|
3428
|
+
return (result_data == null ? void 0 : result_data.length) > 0;
|
3440
3429
|
} catch (error) {
|
3441
|
-
console.error("
|
3442
|
-
return
|
3430
|
+
console.error("hasBridgeTransaction error:", error);
|
3431
|
+
return false;
|
3443
3432
|
}
|
3444
3433
|
});
|
3445
3434
|
}
|
@@ -3844,10 +3833,10 @@ var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
|
|
3844
3833
|
var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
|
3845
3834
|
var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
|
3846
3835
|
function getBtcProvider() {
|
3847
|
-
if (typeof window === "undefined" || !
|
3836
|
+
if (typeof window === "undefined" || !window.btcContext) {
|
3848
3837
|
throw new Error("BTC Provider is not initialized.");
|
3849
3838
|
}
|
3850
|
-
return window.btcContext
|
3839
|
+
return window.btcContext;
|
3851
3840
|
}
|
3852
3841
|
function getNetwork() {
|
3853
3842
|
return __async(this, null, function* () {
|
@@ -3875,18 +3864,20 @@ function nearCall(contractId, methodName, args) {
|
|
3875
3864
|
return nearCallFunction(contractId, methodName, args, { network });
|
3876
3865
|
});
|
3877
3866
|
}
|
3878
|
-
function checkGasTokenDebt(
|
3879
|
-
return __async(this,
|
3867
|
+
function checkGasTokenDebt(_0) {
|
3868
|
+
return __async(this, arguments, function* ({
|
3869
|
+
csna,
|
3870
|
+
btcAccount,
|
3871
|
+
env,
|
3872
|
+
autoDeposit
|
3873
|
+
}) {
|
3880
3874
|
var _a, _b, _c;
|
3881
3875
|
const accountInfo = yield getAccountInfo({ csna, env });
|
3882
|
-
const
|
3883
|
-
const bridgeTransactions = yield getBridgeTransactions({
|
3876
|
+
const bridgeTransactions = yield hasBridgeTransaction({
|
3884
3877
|
env,
|
3885
|
-
|
3886
|
-
page: 1,
|
3887
|
-
pageSize: 1
|
3878
|
+
btcAccount
|
3888
3879
|
});
|
3889
|
-
const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && bridgeTransactions
|
3880
|
+
const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && !bridgeTransactions;
|
3890
3881
|
const debtAmount = new import_big2.default(((_a = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _a.near_gas_debt_amount) || 0).plus(((_b = accountInfo == null ? void 0 : accountInfo.debt_info) == null ? void 0 : _b.protocol_fee_debt_amount) || 0).toString();
|
3891
3882
|
const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
|
3892
3883
|
const hasDebtArrears = new import_big2.default(debtAmount).gt(0);
|
@@ -4004,8 +3995,9 @@ function getDepositAmount(amount, option) {
|
|
4004
3995
|
const env = (option == null ? void 0 : option.env) || "mainnet";
|
4005
3996
|
const _newAccountMinDepositAmount = (_a = option == null ? void 0 : option.newAccountMinDepositAmount) != null ? _a : true;
|
4006
3997
|
const csna = (option == null ? void 0 : option.csna) || (yield getCsnaAccountId(env));
|
3998
|
+
const btcAccount = (option == null ? void 0 : option.btcAccount) || getBtcProvider().account;
|
4007
3999
|
const accountInfo = yield getAccountInfo({ csna, env });
|
4008
|
-
const debtAction = yield checkGasTokenDebt(csna, env, false);
|
4000
|
+
const debtAction = yield checkGasTokenDebt({ csna, btcAccount, env, autoDeposit: false });
|
4009
4001
|
const repayAmount = (debtAction == null ? void 0 : debtAction.amount) || 0;
|
4010
4002
|
const depositAmount = Number(amount);
|
4011
4003
|
const {
|
@@ -4082,7 +4074,7 @@ function executeBTCDepositAndAction(_0) {
|
|
4082
4074
|
registerContractId
|
4083
4075
|
});
|
4084
4076
|
checkDepositDisabledAddress();
|
4085
|
-
const { getPublicKey } = getBtcProvider();
|
4077
|
+
const { getPublicKey, account: btcAccount } = getBtcProvider();
|
4086
4078
|
const config = getWalletConfig(env);
|
4087
4079
|
const btcPublicKey = yield getPublicKey();
|
4088
4080
|
if (!btcPublicKey) {
|
@@ -4111,7 +4103,7 @@ function executeBTCDepositAndAction(_0) {
|
|
4111
4103
|
}
|
4112
4104
|
const accountInfo = yield getAccountInfo({ csna, env });
|
4113
4105
|
const newActions = [];
|
4114
|
-
const debtAction = yield checkGasTokenDebt(csna, env, false);
|
4106
|
+
const debtAction = yield checkGasTokenDebt({ csna, btcAccount, env, autoDeposit: false });
|
4115
4107
|
if (debtAction) {
|
4116
4108
|
newActions.push(__spreadProps(__spreadValues({}, debtAction), {
|
4117
4109
|
gas: "30000000000000"
|
@@ -4152,11 +4144,11 @@ function executeBTCDepositAndAction(_0) {
|
|
4152
4144
|
const _feeRate = feeRate || (yield getBtcGasPrice());
|
4153
4145
|
console.table({
|
4154
4146
|
"User Deposit Address": userDepositAddress,
|
4155
|
-
"Deposit Amount": depositAmount,
|
4156
|
-
"Protocol Fee": protocolFee,
|
4157
|
-
"Repay Amount": repayAmount,
|
4158
|
-
"Receive Amount": receiveAmount,
|
4159
|
-
"Fee Rate": _feeRate
|
4147
|
+
"Deposit Amount": Number(depositAmount),
|
4148
|
+
"Protocol Fee": Number(protocolFee),
|
4149
|
+
"Repay Amount": Number(repayAmount),
|
4150
|
+
"Receive Amount": Number(receiveAmount),
|
4151
|
+
"Fee Rate": Number(_feeRate)
|
4160
4152
|
});
|
4161
4153
|
const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
|
4162
4154
|
yield preReceiveDepositMsg({
|
@@ -5156,7 +5148,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
5156
5148
|
const btcContext = window.btcContext;
|
5157
5149
|
const csna = state_default.getAccount();
|
5158
5150
|
const accountInfo = yield getAccountInfo({ csna, env });
|
5159
|
-
yield checkGasTokenDebt(csna, env, true);
|
5151
|
+
yield checkGasTokenDebt({ csna, env, btcAccount: btcContext.account, autoDeposit: true });
|
5160
5152
|
const trans = [...params.transactions];
|
5161
5153
|
console.log("signAndSendTransactions raw trans:", trans);
|
5162
5154
|
const { transferGasTransaction, useNearPayGas, gasLimit } = yield calculateGasStrategy({
|
@@ -5398,7 +5390,7 @@ function getGroup(state) {
|
|
5398
5390
|
|
5399
5391
|
// src/index.ts
|
5400
5392
|
var getVersion = () => {
|
5401
|
-
return "0.5.
|
5393
|
+
return "0.5.81-beta";
|
5402
5394
|
};
|
5403
5395
|
if (typeof window !== "undefined") {
|
5404
5396
|
window.__BTC_WALLET_VERSION = getVersion();
|