btc-wallet 0.5.44-beta → 0.5.46-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 +1 -0
- package/dist/index.js +52 -27
- package/dist/index.js.map +2 -2
- package/esm/index.js +52 -27
- package/esm/index.js.map +2 -2
- package/package.json +1 -1
package/esm/index.js
CHANGED
@@ -3609,6 +3609,9 @@ function getNetwork() {
|
|
3609
3609
|
}
|
3610
3610
|
});
|
3611
3611
|
}
|
3612
|
+
function formatBtcAmount(amount) {
|
3613
|
+
return new Big2(amount).div(__pow(10, 8)).toString();
|
3614
|
+
}
|
3612
3615
|
function getBtcRpcUrl() {
|
3613
3616
|
return __async(this, null, function* () {
|
3614
3617
|
const network = yield getNetwork();
|
@@ -3640,15 +3643,20 @@ function checkGasTokenDebt(csna, env, autoDeposit) {
|
|
3640
3643
|
};
|
3641
3644
|
if (!autoDeposit)
|
3642
3645
|
return action;
|
3646
|
+
console.log("checkGasTokenDebt action:", action);
|
3647
|
+
const { minDepositAmount } = yield getDepositAmount(action.amount, {
|
3648
|
+
env
|
3649
|
+
});
|
3650
|
+
const remainingAmount = new Big2(minDepositAmount).minus(transferAmount).toNumber();
|
3643
3651
|
const confirmed = yield Dialog.confirm({
|
3644
|
-
title: hasDebtArrears ? "
|
3645
|
-
message: hasDebtArrears ?
|
3652
|
+
title: hasDebtArrears ? "Gas Token Arrears" : "Relayer Fee Arrears",
|
3653
|
+
message: hasDebtArrears ? `You have gas token arrears. Minimum deposit amount is ${formatBtcAmount(minDepositAmount)} BTC, of which ${formatBtcAmount(transferAmount)} BTC will be used to repay the debt, and the remaining ${formatBtcAmount(remainingAmount)} BTC will be credited to your account.` : `You have relayer fee arrears. Minimum deposit amount is ${formatBtcAmount(minDepositAmount)} BTC, of which ${formatBtcAmount(transferAmount)} BTC will be used for relayer fee, and the remaining ${formatBtcAmount(remainingAmount)} BTC will be credited to your account.`
|
3646
3654
|
});
|
3647
3655
|
if (confirmed) {
|
3648
|
-
yield executeBTCDepositAndAction({ action, env });
|
3656
|
+
yield executeBTCDepositAndAction({ amount: minDepositAmount.toString(), action, env });
|
3649
3657
|
yield Dialog.alert({
|
3650
|
-
title: "Deposit
|
3651
|
-
message:
|
3658
|
+
title: "Deposit Success",
|
3659
|
+
message: `Deposit successful. ${formatBtcAmount(transferAmount)} BTC has been paid for ${hasDebtArrears ? "debt" : "relayer fee"}, and the remaining ${formatBtcAmount(remainingAmount)} BTC has been credited to your account. Transaction will continue.`
|
3652
3660
|
});
|
3653
3661
|
} else {
|
3654
3662
|
throw new Error("Deposit failed, please deposit gas token first.");
|
@@ -3732,25 +3740,26 @@ function getDepositAmount(amount, option) {
|
|
3732
3740
|
const accountInfo = yield getAccountInfo({ csna, env });
|
3733
3741
|
const debtAction = yield checkGasTokenDebt(csna, env, false);
|
3734
3742
|
const repayAmount = (debtAction == null ? void 0 : debtAction.amount) || 0;
|
3743
|
+
const depositAmount = Number(amount);
|
3735
3744
|
const {
|
3736
3745
|
deposit_bridge_fee: { fee_min, fee_rate },
|
3737
3746
|
min_deposit_amount
|
3738
3747
|
} = yield getBridgeConfig({ env });
|
3739
|
-
const
|
3740
|
-
const protocolFee = Math.max(Number(fee_min), Number(depositAmount) * fee_rate);
|
3748
|
+
const protocolFee = Math.max(Number(fee_min), depositAmount * fee_rate);
|
3741
3749
|
const newAccountMinDepositAmount = !(accountInfo == null ? void 0 : accountInfo.nonce) && _newAccountMinDepositAmount ? NEW_ACCOUNT_MIN_DEPOSIT_AMOUNT : 0;
|
3742
|
-
|
3743
|
-
|
3744
|
-
|
3745
|
-
|
3746
|
-
|
3747
|
-
|
3750
|
+
let receiveAmount = new Big2(depositAmount).minus(protocolFee).minus(repayAmount).round(0, Big2.roundDown).toNumber();
|
3751
|
+
receiveAmount = Math.max(receiveAmount, 0);
|
3752
|
+
const minDepositAmount = new Big2(min_deposit_amount || 0).plus(newAccountMinDepositAmount).plus(protocolFee).plus(repayAmount).round(0, Big2.roundUp).toNumber();
|
3753
|
+
console.log(
|
3754
|
+
`minDepositAmount: ${minDepositAmount} = ${min_deposit_amount} + ${newAccountMinDepositAmount} + ${protocolFee} + ${repayAmount}`
|
3755
|
+
);
|
3748
3756
|
return {
|
3749
3757
|
depositAmount,
|
3750
3758
|
receiveAmount,
|
3751
3759
|
protocolFee,
|
3752
3760
|
repayAmount,
|
3753
|
-
newAccountMinDepositAmount
|
3761
|
+
newAccountMinDepositAmount,
|
3762
|
+
minDepositAmount
|
3754
3763
|
};
|
3755
3764
|
});
|
3756
3765
|
}
|
@@ -3793,9 +3802,16 @@ function executeBTCDepositAndAction(_0) {
|
|
3793
3802
|
newAccountMinDepositAmount,
|
3794
3803
|
registerContractId
|
3795
3804
|
}) {
|
3796
|
-
var _a;
|
3797
3805
|
try {
|
3798
|
-
console.log("executeBTCDepositAndAction start",
|
3806
|
+
console.log("executeBTCDepositAndAction start", {
|
3807
|
+
action,
|
3808
|
+
amount,
|
3809
|
+
feeRate,
|
3810
|
+
pollResult,
|
3811
|
+
registerDeposit,
|
3812
|
+
newAccountMinDepositAmount,
|
3813
|
+
registerContractId
|
3814
|
+
});
|
3799
3815
|
checkDepositDisabledAddress();
|
3800
3816
|
const { getPublicKey } = getBtcProvider();
|
3801
3817
|
const config = getWalletConfig(env);
|
@@ -3804,17 +3820,26 @@ function executeBTCDepositAndAction(_0) {
|
|
3804
3820
|
throw new Error("BTC Public Key is not available.");
|
3805
3821
|
}
|
3806
3822
|
if (!amount && !action) {
|
3807
|
-
throw new Error("amount or action is required");
|
3823
|
+
throw new Error("Deposit amount or action is required");
|
3808
3824
|
}
|
3809
3825
|
const csna = yield getCsnaAccountId(env);
|
3810
|
-
const depositAmount = (
|
3811
|
-
|
3812
|
-
|
3826
|
+
const depositAmount = Number(amount || (action == null ? void 0 : action.amount) || 0);
|
3827
|
+
console.log("depositAmount", depositAmount);
|
3828
|
+
if (depositAmount <= 0) {
|
3829
|
+
throw new Error("Invalid deposit amount");
|
3830
|
+
}
|
3831
|
+
const { receiveAmount, protocolFee, repayAmount, minDepositAmount } = yield getDepositAmount(
|
3832
|
+
depositAmount.toString(),
|
3833
|
+
{
|
3834
|
+
env,
|
3835
|
+
newAccountMinDepositAmount
|
3836
|
+
}
|
3837
|
+
);
|
3838
|
+
if (depositAmount < minDepositAmount) {
|
3839
|
+
throw new Error(
|
3840
|
+
`Invalid deposit amount, must be greater than ${formatBtcAmount(minDepositAmount)} BTC`
|
3841
|
+
);
|
3813
3842
|
}
|
3814
|
-
const { receiveAmount, protocolFee, repayAmount } = yield getDepositAmount(depositAmount, {
|
3815
|
-
env,
|
3816
|
-
newAccountMinDepositAmount
|
3817
|
-
});
|
3818
3843
|
const accountInfo = yield getAccountInfo({ csna, env });
|
3819
3844
|
const newActions = [];
|
3820
3845
|
const debtAction = yield checkGasTokenDebt(csna, env, false);
|
@@ -3871,7 +3896,7 @@ function executeBTCDepositAndAction(_0) {
|
|
3871
3896
|
postActions: postActionsStr,
|
3872
3897
|
extraMsg: depositMsg.extra_msg
|
3873
3898
|
});
|
3874
|
-
const txHash = yield sendBitcoin(userDepositAddress,
|
3899
|
+
const txHash = yield sendBitcoin(userDepositAddress, depositAmount, _feeRate);
|
3875
3900
|
yield receiveDepositMsg(config.base_url, {
|
3876
3901
|
btcPublicKey,
|
3877
3902
|
txHash,
|
@@ -4078,7 +4103,7 @@ function calculateWithdraw(_0) {
|
|
4078
4103
|
return {
|
4079
4104
|
withdrawFee: 0,
|
4080
4105
|
isError: true,
|
4081
|
-
errorMsg: `
|
4106
|
+
errorMsg: `Minimum withdraw amount is ${formatBtcAmount(Number(brgConfig.min_withdraw_amount) + Number(gasLimit))} BTC`
|
4082
4107
|
};
|
4083
4108
|
}
|
4084
4109
|
}
|
@@ -4858,7 +4883,7 @@ function getGroup(state) {
|
|
4858
4883
|
|
4859
4884
|
// src/index.ts
|
4860
4885
|
var getVersion = () => {
|
4861
|
-
return "0.5.
|
4886
|
+
return "0.5.46-beta";
|
4862
4887
|
};
|
4863
4888
|
if (typeof window !== "undefined") {
|
4864
4889
|
window.__BTC_WALLET_VERSION = getVersion();
|