btc-wallet 0.3.7 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/config.d.ts +1 -0
- package/dist/index.js +74 -29
- package/dist/index.js.map +3 -3
- package/esm/index.js +74 -29
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/esm/index.js
CHANGED
@@ -2686,21 +2686,24 @@ var walletConfig = {
|
|
2686
2686
|
token: "nbtc-dev.testnet",
|
2687
2687
|
accountContractId: "acc-dev.testnet",
|
2688
2688
|
bridgeContractId: "brg-dev.testnet",
|
2689
|
-
walletUrl: "https://wallet-dev.satoshibridge.top"
|
2689
|
+
walletUrl: "https://wallet-dev.satoshibridge.top",
|
2690
|
+
gasTokenLimit: "3000"
|
2690
2691
|
},
|
2691
2692
|
testnet: {
|
2692
2693
|
base_url: "https://api.testnet.satoshibridge.top",
|
2693
2694
|
token: "nbtc2-nsp.testnet",
|
2694
2695
|
accountContractId: "dev2-nsp.testnet",
|
2695
2696
|
bridgeContractId: "brg2-nsp.testnet",
|
2696
|
-
walletUrl: "https://wallet-test.satoshibridge.top"
|
2697
|
+
walletUrl: "https://wallet-test.satoshibridge.top",
|
2698
|
+
gasTokenLimit: "3000"
|
2697
2699
|
},
|
2698
2700
|
mainnet: {
|
2699
2701
|
base_url: "https://api.mainnet.satoshibridge.top",
|
2700
2702
|
token: "",
|
2701
2703
|
accountContractId: "",
|
2702
2704
|
bridgeContractId: "",
|
2703
|
-
walletUrl: "https://wallet.satoshibridge.top"
|
2705
|
+
walletUrl: "https://wallet.satoshibridge.top",
|
2706
|
+
gasTokenLimit: "3000"
|
2704
2707
|
}
|
2705
2708
|
};
|
2706
2709
|
var nearRpcUrls = {
|
@@ -2844,6 +2847,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
2844
2847
|
}
|
2845
2848
|
|
2846
2849
|
// src/core/setupBTCWallet.ts
|
2850
|
+
import Big from "big.js";
|
2847
2851
|
var { transfer, functionCall } = actionCreators;
|
2848
2852
|
var state = {
|
2849
2853
|
saveAccount(account) {
|
@@ -3060,6 +3064,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3060
3064
|
currentConfig.base_url,
|
3061
3065
|
accountId
|
3062
3066
|
);
|
3067
|
+
const { transferGasTransaction, useNearPayGas } = yield getGasConfig();
|
3068
|
+
if (!useNearPayGas && transferGasTransaction) {
|
3069
|
+
params.transactions.unshift(transferGasTransaction);
|
3070
|
+
}
|
3063
3071
|
const newTransactions = params.transactions.map((transaction, index) => {
|
3064
3072
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
3065
3073
|
if (nearNonceFromApi) {
|
@@ -3110,19 +3118,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3110
3118
|
csna: accountId,
|
3111
3119
|
near_transactions: newTransactions.map((t) => t.txHex),
|
3112
3120
|
gas_token: currentConfig.token,
|
3113
|
-
gas_limit:
|
3114
|
-
use_near_pay_gas:
|
3121
|
+
gas_limit: currentConfig.gasTokenLimit,
|
3122
|
+
use_near_pay_gas: useNearPayGas,
|
3115
3123
|
nonce
|
3116
3124
|
};
|
3117
|
-
const nearAccount = yield provider.query({
|
3118
|
-
request_type: "view_account",
|
3119
|
-
account_id: accountId,
|
3120
|
-
finality: "final"
|
3121
|
-
});
|
3122
|
-
const availableBalance = parseFloat(nearAccount.amount) / __pow(10, 24);
|
3123
|
-
if (availableBalance > 0.2) {
|
3124
|
-
intention.use_near_pay_gas = true;
|
3125
|
-
}
|
3126
3125
|
const strIntention = JSON.stringify(intention);
|
3127
3126
|
const signature = yield btcContext.signMessage(strIntention);
|
3128
3127
|
const result = yield uploadBTCTx(currentConfig.base_url, {
|
@@ -3140,6 +3139,48 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
3140
3139
|
}
|
3141
3140
|
});
|
3142
3141
|
}
|
3142
|
+
function getGasConfig() {
|
3143
|
+
return __async(this, null, function* () {
|
3144
|
+
const accountId = state.getAccount();
|
3145
|
+
const nearAccount = yield provider.query({
|
3146
|
+
request_type: "view_account",
|
3147
|
+
account_id: accountId,
|
3148
|
+
finality: "final"
|
3149
|
+
});
|
3150
|
+
const availableBalance = parseFloat(nearAccount.amount) / __pow(10, 24);
|
3151
|
+
if (availableBalance > 0.2) {
|
3152
|
+
return { useNearPayGas: true };
|
3153
|
+
} else {
|
3154
|
+
const gasTokenBalance = yield nearCall2(currentConfig.token, "ft_balance_of", {
|
3155
|
+
account_id: accountId
|
3156
|
+
});
|
3157
|
+
if (new Big(gasTokenBalance).gt(currentConfig.gasTokenLimit)) {
|
3158
|
+
const transferGasTransaction = {
|
3159
|
+
signerId: accountId,
|
3160
|
+
receiverId: currentConfig.token,
|
3161
|
+
actions: [
|
3162
|
+
{
|
3163
|
+
type: "FunctionCall",
|
3164
|
+
params: {
|
3165
|
+
methodName: "ft_transfer_call",
|
3166
|
+
args: {
|
3167
|
+
receiver_id: currentConfig.accountContractId,
|
3168
|
+
amount: currentConfig.gasTokenLimit,
|
3169
|
+
msg: "Deposit"
|
3170
|
+
},
|
3171
|
+
gas: new Big(50).mul(__pow(10, 12)).toFixed(0),
|
3172
|
+
deposit: "1"
|
3173
|
+
}
|
3174
|
+
}
|
3175
|
+
]
|
3176
|
+
};
|
3177
|
+
return { transferGasTransaction, useNearPayGas: false };
|
3178
|
+
} else {
|
3179
|
+
throw new Error("No enough gas token balance");
|
3180
|
+
}
|
3181
|
+
}
|
3182
|
+
});
|
3183
|
+
}
|
3143
3184
|
function initWalletButton(network, wallet2) {
|
3144
3185
|
return __async(this, null, function* () {
|
3145
3186
|
const checkAndSetupWalletButton = () => {
|
@@ -3209,7 +3250,7 @@ function toHex(originalString) {
|
|
3209
3250
|
}
|
3210
3251
|
|
3211
3252
|
// src/core/btcUtils.ts
|
3212
|
-
import
|
3253
|
+
import Big2 from "big.js";
|
3213
3254
|
function getBtcProvider() {
|
3214
3255
|
if (typeof window === "undefined" || !window.btcContext) {
|
3215
3256
|
throw new Error("BTC Provider is not initialized.");
|
@@ -3296,7 +3337,7 @@ function getBtcBalance() {
|
|
3296
3337
|
const rawBalance = res == null ? void 0 : res.reduce((acc, cur) => acc + cur.value, 0);
|
3297
3338
|
const balance = rawBalance / __pow(10, 8);
|
3298
3339
|
const feeRate = yield getBtcGasPrice();
|
3299
|
-
const maxGasFee = feeRate *
|
3340
|
+
const maxGasFee = feeRate * 350 / __pow(10, 8);
|
3300
3341
|
const availableBalance = Math.max(0, balance - maxGasFee);
|
3301
3342
|
return {
|
3302
3343
|
rawBalance,
|
@@ -3323,7 +3364,7 @@ function estimateDepositAmount(amount, option) {
|
|
3323
3364
|
{}
|
3324
3365
|
);
|
3325
3366
|
const fee = Math.max(Number(fee_min), Number(amount) * fee_rate);
|
3326
|
-
return new
|
3367
|
+
return new Big2(amount).minus(fee).toFixed(0);
|
3327
3368
|
});
|
3328
3369
|
}
|
3329
3370
|
function executeBTCDepositAndAction(_0) {
|
@@ -3339,7 +3380,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3339
3380
|
const _action = Object.assign(
|
3340
3381
|
{},
|
3341
3382
|
__spreadProps(__spreadValues({}, action), {
|
3342
|
-
gas: new
|
3383
|
+
gas: new Big2(100).mul(__pow(10, 12)).toFixed(0)
|
3343
3384
|
})
|
3344
3385
|
);
|
3345
3386
|
if (!btcPublicKey) {
|
@@ -3352,7 +3393,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3352
3393
|
isDev
|
3353
3394
|
});
|
3354
3395
|
_action.amount = amountWithFee;
|
3355
|
-
if (!_action.amount || !new
|
3396
|
+
if (!_action.amount || !new Big2(_action.amount || 0).gt(0)) {
|
3356
3397
|
throw new Error("action.amount is required or deposit amount is not enough");
|
3357
3398
|
}
|
3358
3399
|
const csna = yield nearCall(
|
@@ -3367,10 +3408,14 @@ function executeBTCDepositAndAction(_0) {
|
|
3367
3408
|
post_actions: [_action]
|
3368
3409
|
};
|
3369
3410
|
const storageDepositMsg = {};
|
3370
|
-
const accountInfo = yield nearCall(
|
3371
|
-
|
3372
|
-
|
3373
|
-
|
3411
|
+
const accountInfo = yield nearCall(
|
3412
|
+
config.accountContractId,
|
3413
|
+
"get_account",
|
3414
|
+
{
|
3415
|
+
account_id: csna
|
3416
|
+
}
|
3417
|
+
);
|
3418
|
+
if (!(accountInfo == null ? void 0 : accountInfo.nonce)) {
|
3374
3419
|
storageDepositMsg.btc_public_key = btcPublicKey;
|
3375
3420
|
}
|
3376
3421
|
const registerRes = yield nearCall(action.receiver_id, "storage_balance_of", {
|
@@ -3379,14 +3424,14 @@ function executeBTCDepositAndAction(_0) {
|
|
3379
3424
|
if (!(registerRes == null ? void 0 : registerRes.available)) {
|
3380
3425
|
storageDepositMsg.storage_deposit_msg = {
|
3381
3426
|
contract_id: action.receiver_id,
|
3382
|
-
deposit: new
|
3427
|
+
deposit: new Big2(0.25).mul(__pow(10, 24)).toFixed(0),
|
3383
3428
|
registration_only: true
|
3384
3429
|
};
|
3385
3430
|
}
|
3386
3431
|
if (Object.keys(storageDepositMsg).length > 0) {
|
3387
3432
|
depositMsg.extra_msg = JSON.stringify(storageDepositMsg);
|
3388
3433
|
}
|
3389
|
-
console.log("
|
3434
|
+
console.log("get_user_deposit_address params:", { deposit_msg: depositMsg });
|
3390
3435
|
const userDepositAddress = yield nearCall(
|
3391
3436
|
config.bridgeContractId,
|
3392
3437
|
"get_user_deposit_address",
|
@@ -3394,12 +3439,12 @@ function executeBTCDepositAndAction(_0) {
|
|
3394
3439
|
);
|
3395
3440
|
const _feeRate = feeRate || (yield getBtcGasPrice());
|
3396
3441
|
console.log("user deposit address:", userDepositAddress);
|
3397
|
-
console.log("deposit amount:", new
|
3398
|
-
console.log("receive amount:", new
|
3442
|
+
console.log("deposit amount:", new Big2(action.amount).toNumber());
|
3443
|
+
console.log("receive amount:", new Big2(_action.amount).toNumber());
|
3399
3444
|
console.log("fee rate:", _feeRate);
|
3400
3445
|
const txHash = yield sendBitcoin(
|
3401
3446
|
userDepositAddress,
|
3402
|
-
new
|
3447
|
+
new Big2(action.amount).toNumber(),
|
3403
3448
|
_feeRate
|
3404
3449
|
);
|
3405
3450
|
yield receiveDepositMsg(config.base_url, {
|
@@ -3420,7 +3465,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3420
3465
|
|
3421
3466
|
// src/index.ts
|
3422
3467
|
var getVersion = () => {
|
3423
|
-
return "0.3.
|
3468
|
+
return "0.3.9";
|
3424
3469
|
};
|
3425
3470
|
if (typeof window !== "undefined") {
|
3426
3471
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|