btc-wallet 0.3.22 → 0.3.23

Sign up to get free protection for your applications and to get access to all the features.
package/esm/index.js CHANGED
@@ -3263,6 +3263,14 @@ function checkGasTokenArrears(debtInfo, isDev, autoDeposit) {
3263
3263
  }
3264
3264
  });
3265
3265
  }
3266
+ function queryGasTokenArrears(isDev) {
3267
+ return __async(this, null, function* () {
3268
+ const config = yield getConfig(isDev || false);
3269
+ const csna = yield getCsnaAccountId(isDev);
3270
+ const accountInfo = yield getAccountInfo(csna, config.accountContractId);
3271
+ return accountInfo == null ? void 0 : accountInfo.debt_info;
3272
+ });
3273
+ }
3266
3274
  function getBtcGasPrice() {
3267
3275
  return __async(this, null, function* () {
3268
3276
  const network = yield getNetwork();
@@ -3338,6 +3346,21 @@ function getDepositAmount(amount, option) {
3338
3346
  };
3339
3347
  });
3340
3348
  }
3349
+ function getCsnaAccountId(isDev) {
3350
+ return __async(this, null, function* () {
3351
+ const config = yield getConfig(isDev || false);
3352
+ const { getPublicKey } = getBtcProvider();
3353
+ const btcPublicKey = yield getPublicKey();
3354
+ const csna = yield nearCall(
3355
+ config.accountContractId,
3356
+ "get_chain_signature_near_account_id",
3357
+ {
3358
+ btc_public_key: btcPublicKey
3359
+ }
3360
+ );
3361
+ return csna;
3362
+ });
3363
+ }
3341
3364
  function executeBTCDepositAndAction(_0) {
3342
3365
  return __async(this, arguments, function* ({
3343
3366
  action,
@@ -3358,13 +3381,7 @@ function executeBTCDepositAndAction(_0) {
3358
3381
  if (!amount && !action) {
3359
3382
  throw new Error("amount or action is required");
3360
3383
  }
3361
- const csna = yield nearCall(
3362
- config.accountContractId,
3363
- "get_chain_signature_near_account_id",
3364
- {
3365
- btc_public_key: btcPublicKey
3366
- }
3367
- );
3384
+ const csna = yield getCsnaAccountId(isDev);
3368
3385
  const rawDepositAmount = (_a = action ? action.amount : amount) != null ? _a : "0";
3369
3386
  if (new Big(rawDepositAmount).lt(0)) {
3370
3387
  throw new Error("amount must be greater than 0");
@@ -3381,11 +3398,18 @@ function executeBTCDepositAndAction(_0) {
3381
3398
  gas: gasLimit
3382
3399
  }));
3383
3400
  }
3384
- if (action) {
3385
- newActions.push(__spreadProps(__spreadValues({}, action), {
3386
- amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3387
- gas: gasLimit
3388
- }));
3401
+ if (action || !action && new Big((accountInfo == null ? void 0 : accountInfo.gas_token[config.token]) || 0).lt(MINIMUM_DEPOSIT_AMOUNT_BASE)) {
3402
+ newActions.push(
3403
+ action ? __spreadProps(__spreadValues({}, action), {
3404
+ amount: (repayAction == null ? void 0 : repayAction.amount) && !fixedAmount ? new Big(receiveAmount).minus(repayAction.amount).toString() : receiveAmount.toString(),
3405
+ gas: gasLimit
3406
+ }) : {
3407
+ receiver_id: config.accountContractId,
3408
+ amount: MINIMUM_DEPOSIT_AMOUNT_BASE.toString(),
3409
+ msg: JSON.stringify("Deposit"),
3410
+ gas: gasLimit
3411
+ }
3412
+ );
3389
3413
  }
3390
3414
  const depositMsg = {
3391
3415
  recipient_id: csna,
@@ -3575,21 +3599,17 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
3575
3599
  }
3576
3600
  function getNearAccountByBtcPublicKey(btcPublicKey) {
3577
3601
  return __async(this, null, function* () {
3578
- const nearAddress = yield nearCall2(
3579
- currentConfig.accountContractId,
3580
- "get_chain_signature_near_account_id",
3581
- { btc_public_key: btcPublicKey }
3582
- );
3602
+ const csna = yield getCsnaAccountId(isDev);
3583
3603
  const nearPublicKey = yield nearCall2(
3584
3604
  currentConfig.accountContractId,
3585
3605
  "get_chain_signature_near_account_public_key",
3586
3606
  { btc_public_key: btcPublicKey }
3587
3607
  );
3588
- state.saveAccount(nearAddress);
3608
+ state.saveAccount(csna);
3589
3609
  state.savePublicKey(nearPublicKey);
3590
3610
  state.saveBtcPublicKey(btcPublicKey);
3591
3611
  return {
3592
- nearAddress,
3612
+ nearAddress: csna,
3593
3613
  nearPublicKey
3594
3614
  };
3595
3615
  });
@@ -3928,7 +3948,7 @@ function setupBTCWallet({
3928
3948
 
3929
3949
  // src/index.ts
3930
3950
  var getVersion = () => {
3931
- return "0.3.22";
3951
+ return "0.3.23";
3932
3952
  };
3933
3953
  if (typeof window !== "undefined") {
3934
3954
  window.__BTC_WALLET_VERSION = getVersion();
@@ -3953,8 +3973,10 @@ export {
3953
3973
  getAccountInfo,
3954
3974
  getBtcBalance,
3955
3975
  getBtcGasPrice,
3976
+ getCsnaAccountId,
3956
3977
  getDepositAmount,
3957
3978
  getVersion,
3979
+ queryGasTokenArrears,
3958
3980
  sendBitcoin,
3959
3981
  setupBTCWallet,
3960
3982
  useAccountContract,