@msafe/sui3-sdk 1.0.18 → 1.0.19

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/index.js CHANGED
@@ -134,7 +134,7 @@ import {
134
134
  isSameAddress as isSameAddress2
135
135
  } from "@msafe/sui3-utils";
136
136
  import { Transaction as Transaction4 } from "@mysten/sui/transactions";
137
- import { fromHex as fromHex2, normalizeStructTag as normalizeStructTag3, toHex as toHex2 } from "@mysten/sui/utils";
137
+ import { fromHex as fromHex2, normalizeStructTag as normalizeStructTag4, toHex as toHex2 } from "@mysten/sui/utils";
138
138
  import { SUI_MAINNET_CHAIN, SUI_TESTNET_CHAIN } from "@mysten/wallet-standard";
139
139
 
140
140
  // src/simulate/simulator.ts
@@ -142,7 +142,7 @@ import { Transaction as Transaction2 } from "@mysten/sui/transactions";
142
142
 
143
143
  // src/utils/gasFunding.ts
144
144
  import { Transaction } from "@mysten/sui/transactions";
145
- import { normalizeSuiObjectId } from "@mysten/sui/utils";
145
+ import { normalizeStructTag as normalizeStructTag3, normalizeSuiObjectId } from "@mysten/sui/utils";
146
146
 
147
147
  // src/utils/coinReservation.ts
148
148
  import { bcs, TypeTagSerializer } from "@mysten/sui/bcs";
@@ -450,12 +450,37 @@ function collectUsedObjectIds(tx) {
450
450
  return used;
451
451
  }, /* @__PURE__ */ new Set());
452
452
  }
453
+ function txConsumesOwnedSuiCoins(tx) {
454
+ return tx.getData().commands.some((cmd) => {
455
+ if (cmd.$kind !== "$Intent" || cmd.$Intent.name !== "CoinWithBalance") {
456
+ return false;
457
+ }
458
+ const type = cmd.$Intent.data?.type;
459
+ if (!type || type === "gas") {
460
+ return false;
461
+ }
462
+ try {
463
+ return normalizeStructTag3(type) === normalizeStructTag3(SUI_COIN);
464
+ } catch {
465
+ return false;
466
+ }
467
+ });
468
+ }
453
469
  async function loadSuiGasFunding(suiClient, owner, tx) {
454
470
  const usedObjectIds = collectUsedObjectIds(tx);
455
471
  const [coins, balanceRes] = await Promise.all([
456
472
  getAllCoins({ suiClient, owner, coinType: SUI_COIN }),
457
473
  suiClient.getBalance({ owner, coinType: SUI_COIN })
458
474
  ]);
475
+ const addressBalance = BigInt(balanceRes.balance.addressBalance);
476
+ if (txConsumesOwnedSuiCoins(tx)) {
477
+ return {
478
+ paymentCoins: [],
479
+ coinBalance: 0n,
480
+ addressBalance,
481
+ total: addressBalance
482
+ };
483
+ }
459
484
  const paymentCoins = coins.filter((coin) => !usedObjectIds.has(normalizeSuiObjectId(coin.objectId)) && BigInt(coin.balance) > 0n).map((coin) => ({
460
485
  objectId: coin.objectId,
461
486
  version: coin.version,
@@ -463,7 +488,6 @@ async function loadSuiGasFunding(suiClient, owner, tx) {
463
488
  balance: BigInt(coin.balance)
464
489
  }));
465
490
  const coinBalance = paymentCoins.reduce((sum, coin) => sum + coin.balance, 0n);
466
- const addressBalance = BigInt(balanceRes.balance.addressBalance);
467
491
  return {
468
492
  paymentCoins,
469
493
  coinBalance,
@@ -957,7 +981,7 @@ var MSafeAccount = class _MSafeAccount {
957
981
  balances.map(async (balance) => {
958
982
  const meta = await this.coinHelper.getCoinMeta(balance.coinType);
959
983
  return {
960
- type: normalizeStructTag3(balance.coinType),
984
+ type: normalizeStructTag4(balance.coinType),
961
985
  balance: BigInt(balance.addressBalance),
962
986
  metadata: meta
963
987
  };