@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.cjs CHANGED
@@ -514,12 +514,37 @@ function collectUsedObjectIds(tx) {
514
514
  return used;
515
515
  }, /* @__PURE__ */ new Set());
516
516
  }
517
+ function txConsumesOwnedSuiCoins(tx) {
518
+ return tx.getData().commands.some((cmd) => {
519
+ if (cmd.$kind !== "$Intent" || cmd.$Intent.name !== "CoinWithBalance") {
520
+ return false;
521
+ }
522
+ const type = cmd.$Intent.data?.type;
523
+ if (!type || type === "gas") {
524
+ return false;
525
+ }
526
+ try {
527
+ return (0, import_utils4.normalizeStructTag)(type) === (0, import_utils4.normalizeStructTag)(SUI_COIN);
528
+ } catch {
529
+ return false;
530
+ }
531
+ });
532
+ }
517
533
  async function loadSuiGasFunding(suiClient, owner, tx) {
518
534
  const usedObjectIds = collectUsedObjectIds(tx);
519
535
  const [coins, balanceRes] = await Promise.all([
520
536
  getAllCoins({ suiClient, owner, coinType: SUI_COIN }),
521
537
  suiClient.getBalance({ owner, coinType: SUI_COIN })
522
538
  ]);
539
+ const addressBalance = BigInt(balanceRes.balance.addressBalance);
540
+ if (txConsumesOwnedSuiCoins(tx)) {
541
+ return {
542
+ paymentCoins: [],
543
+ coinBalance: 0n,
544
+ addressBalance,
545
+ total: addressBalance
546
+ };
547
+ }
523
548
  const paymentCoins = coins.filter((coin) => !usedObjectIds.has((0, import_utils4.normalizeSuiObjectId)(coin.objectId)) && BigInt(coin.balance) > 0n).map((coin) => ({
524
549
  objectId: coin.objectId,
525
550
  version: coin.version,
@@ -527,7 +552,6 @@ async function loadSuiGasFunding(suiClient, owner, tx) {
527
552
  balance: BigInt(coin.balance)
528
553
  }));
529
554
  const coinBalance = paymentCoins.reduce((sum, coin) => sum + coin.balance, 0n);
530
- const addressBalance = BigInt(balanceRes.balance.addressBalance);
531
555
  return {
532
556
  paymentCoins,
533
557
  coinBalance,