btc-wallet 0.5.76-beta → 0.5.78-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/connector/gate.d.ts +4 -0
- package/dist/core/btcUtils.d.ts +1 -1
- package/dist/index.js +83 -7
- package/dist/index.js.map +2 -2
- package/dist/utils/satoshi.d.ts +8 -0
- package/esm/index.js +83 -7
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/dist/connector/gate.d.ts
CHANGED
@@ -3,4 +3,8 @@ import { InjectedConnector } from './injected';
|
|
3
3
|
export declare class GateConnector extends InjectedConnector {
|
4
4
|
readonly metadata: WalletMetadata;
|
5
5
|
constructor();
|
6
|
+
sendBitcoin(toAddress: string, satoshis: number, options?: {
|
7
|
+
feeRate: number;
|
8
|
+
}): Promise<string>;
|
9
|
+
signMessage(signStr: string, type?: 'ecdsa' | 'bip322-simple'): Promise<string>;
|
6
10
|
}
|
package/dist/core/btcUtils.d.ts
CHANGED
@@ -40,7 +40,7 @@ export declare function getDepositAmount(amount: string, option?: {
|
|
40
40
|
receiveAmount: number;
|
41
41
|
protocolFee: number;
|
42
42
|
repayAmount: string | number;
|
43
|
-
newAccountMinDepositAmount:
|
43
|
+
newAccountMinDepositAmount: number;
|
44
44
|
minDepositAmount: number;
|
45
45
|
}>;
|
46
46
|
export declare function getCsnaAccountId(env: ENV): Promise<string>;
|
package/dist/index.js
CHANGED
@@ -1213,6 +1213,35 @@ var GateConnector = class extends InjectedConnector {
|
|
1213
1213
|
downloadUrl: "https://www.gate.io/en/web3"
|
1214
1214
|
};
|
1215
1215
|
}
|
1216
|
+
sendBitcoin(toAddress, satoshis, options) {
|
1217
|
+
return __async(this, null, function* () {
|
1218
|
+
const addresses = yield this.getAccounts();
|
1219
|
+
if (addresses.length === 0) {
|
1220
|
+
throw new Error(`${this.metadata.name} not connected!`);
|
1221
|
+
}
|
1222
|
+
const result = yield window.gatewallet.bitcoin.sendBitcoin({
|
1223
|
+
fromAddress: addresses[0],
|
1224
|
+
toAddress,
|
1225
|
+
satoshis,
|
1226
|
+
options
|
1227
|
+
});
|
1228
|
+
console.log("\u{1F680} ~ GateConnector ~ sendBitcoin ~ result:", result);
|
1229
|
+
return result.txhash;
|
1230
|
+
});
|
1231
|
+
}
|
1232
|
+
signMessage(signStr, type) {
|
1233
|
+
return __async(this, null, function* () {
|
1234
|
+
const addresses = yield this.getAccounts();
|
1235
|
+
if (addresses.length === 0) {
|
1236
|
+
throw new Error(`${this.metadata.name} not connected!`);
|
1237
|
+
}
|
1238
|
+
return window.gatewallet.bitcoin.signMessage({
|
1239
|
+
fromAddress: addresses[0],
|
1240
|
+
text: signStr,
|
1241
|
+
type
|
1242
|
+
});
|
1243
|
+
});
|
1244
|
+
}
|
1216
1245
|
};
|
1217
1246
|
|
1218
1247
|
// src/context/index.tsx
|
@@ -3393,6 +3422,26 @@ function receiveDepositMsg(_0) {
|
|
3393
3422
|
return result_data;
|
3394
3423
|
});
|
3395
3424
|
}
|
3425
|
+
function getBridgeTransactions(_0) {
|
3426
|
+
return __async(this, arguments, function* ({
|
3427
|
+
env,
|
3428
|
+
fromChainId = 0,
|
3429
|
+
fromAddress,
|
3430
|
+
page = 1,
|
3431
|
+
pageSize = 10
|
3432
|
+
}) {
|
3433
|
+
try {
|
3434
|
+
const config = getWalletConfig(env);
|
3435
|
+
const { result_data = [] } = yield request(
|
3436
|
+
`${config.base_url}/v1/history?fromChainId=${fromChainId}&fromAddress=${fromAddress}&page=${page}&pageSize=${pageSize}`
|
3437
|
+
);
|
3438
|
+
return result_data;
|
3439
|
+
} catch (error) {
|
3440
|
+
console.error("getBridgeTransactions error:", error);
|
3441
|
+
return [];
|
3442
|
+
}
|
3443
|
+
});
|
3444
|
+
}
|
3396
3445
|
function checkBridgeTransactionStatus(_0) {
|
3397
3446
|
return __async(this, arguments, function* ({
|
3398
3447
|
txHash,
|
@@ -3791,13 +3840,13 @@ var import_coinselect = __toESM(require("coinselect"), 1);
|
|
3791
3840
|
var ecc = __toESM(require("@bitcoinerlab/secp256k1"), 1);
|
3792
3841
|
bitcoin.initEccLib(ecc);
|
3793
3842
|
var NEAR_STORAGE_DEPOSIT_AMOUNT = "1250000000000000000000";
|
3794
|
-
var NBTC_STORAGE_DEPOSIT_AMOUNT =
|
3795
|
-
var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT =
|
3843
|
+
var NBTC_STORAGE_DEPOSIT_AMOUNT = 800;
|
3844
|
+
var NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT = 1e3;
|
3796
3845
|
function getBtcProvider() {
|
3797
|
-
if (typeof window === "undefined" || !window.btcContext) {
|
3846
|
+
if (typeof window === "undefined" || !(window.btcContext || (parent == null ? void 0 : parent.btcContext))) {
|
3798
3847
|
throw new Error("BTC Provider is not initialized.");
|
3799
3848
|
}
|
3800
|
-
return window.btcContext;
|
3849
|
+
return window.btcContext || parent.btcContext;
|
3801
3850
|
}
|
3802
3851
|
function getNetwork() {
|
3803
3852
|
return __async(this, null, function* () {
|
@@ -3829,8 +3878,16 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
|
|
3829
3878
|
return __async(this, null, function* () {
|
3830
3879
|
var _a, _b, _c;
|
3831
3880
|
const accountInfo = yield getAccountInfo({ csna, env });
|
3881
|
+
const { account } = getBtcProvider();
|
3882
|
+
const bridgeTransactions = yield getBridgeTransactions({
|
3883
|
+
env,
|
3884
|
+
fromAddress: account,
|
3885
|
+
page: 1,
|
3886
|
+
pageSize: 1
|
3887
|
+
});
|
3888
|
+
const isNewAccount = !(accountInfo == null ? void 0 : accountInfo.nonce) && bridgeTransactions.length === 0;
|
3832
3889
|
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();
|
3833
|
-
const relayerFeeAmount =
|
3890
|
+
const relayerFeeAmount = isNewAccount ? NBTC_STORAGE_DEPOSIT_AMOUNT : ((_c = accountInfo == null ? void 0 : accountInfo.relayer_fee) == null ? void 0 : _c.amount) || 0;
|
3834
3891
|
const hasDebtArrears = new import_big2.default(debtAmount).gt(0);
|
3835
3892
|
const hasRelayerFeeArrears = new import_big2.default(relayerFeeAmount).gt(0);
|
3836
3893
|
if (!hasDebtArrears && !hasRelayerFeeArrears)
|
@@ -4313,7 +4370,26 @@ function calculateWithdraw(_0) {
|
|
4313
4370
|
satoshis = new import_big2.default(amount).minus(gasLimit).toNumber();
|
4314
4371
|
}
|
4315
4372
|
const brgConfig = yield getBridgeConfig({ env });
|
4316
|
-
const
|
4373
|
+
const { current_utxos_num } = yield nearCallFunction(
|
4374
|
+
config.bridgeContractId,
|
4375
|
+
"get_metadata",
|
4376
|
+
{},
|
4377
|
+
{ network: config.network }
|
4378
|
+
);
|
4379
|
+
const pageSize = 300;
|
4380
|
+
const totalPages = Math.ceil(current_utxos_num / pageSize);
|
4381
|
+
const utxoRequests = Array.from({ length: totalPages }, (_, index) => {
|
4382
|
+
const fromIndex = index * pageSize;
|
4383
|
+
const limit = Math.min(pageSize, current_utxos_num - fromIndex);
|
4384
|
+
return nearCallFunction(
|
4385
|
+
config.bridgeContractId,
|
4386
|
+
"get_utxos_paged",
|
4387
|
+
{ from_index: fromIndex, limit },
|
4388
|
+
{ network: config.network }
|
4389
|
+
);
|
4390
|
+
});
|
4391
|
+
const utxoResults = yield Promise.all(utxoRequests);
|
4392
|
+
const allUTXO = utxoResults.reduce((acc, result) => __spreadValues(__spreadValues({}, acc), result), {});
|
4317
4393
|
if (brgConfig.min_withdraw_amount) {
|
4318
4394
|
if (Number(satoshis) < Number(brgConfig.min_withdraw_amount)) {
|
4319
4395
|
return {
|
@@ -5320,7 +5396,7 @@ function getGroup(state) {
|
|
5320
5396
|
|
5321
5397
|
// src/index.ts
|
5322
5398
|
var getVersion = () => {
|
5323
|
-
return "0.5.
|
5399
|
+
return "0.5.78-beta";
|
5324
5400
|
};
|
5325
5401
|
if (typeof window !== "undefined") {
|
5326
5402
|
window.__BTC_WALLET_VERSION = getVersion();
|