@msafe/sui3-sdk 1.0.17 → 1.0.18
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 +30 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -6
- package/dist/index.d.ts +0 -6
- package/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/utils/gasFunding.ts +56 -3
package/dist/index.d.cts
CHANGED
|
@@ -366,12 +366,6 @@ declare function selectGasFunding(input: {
|
|
|
366
366
|
owner: string;
|
|
367
367
|
gasBudget: bigint;
|
|
368
368
|
}): Promise<GasFundingResult>;
|
|
369
|
-
/**
|
|
370
|
-
* Estimate gas budget (no storageRebate) using a probe build/simulate.
|
|
371
|
-
* Prefers classic coin gas when coin objects exist so the estimate matches the
|
|
372
|
-
* cheaper payment path. Budget is left unset so Mysten can dry-run with MAX_GAS
|
|
373
|
-
* overrides (avoids locking the full balance away from GasCoin splits).
|
|
374
|
-
*/
|
|
375
369
|
declare function estimateGasBudget(input: {
|
|
376
370
|
tx: Transaction;
|
|
377
371
|
suiClient: SuiGrpcClient;
|
package/dist/index.d.ts
CHANGED
|
@@ -366,12 +366,6 @@ declare function selectGasFunding(input: {
|
|
|
366
366
|
owner: string;
|
|
367
367
|
gasBudget: bigint;
|
|
368
368
|
}): Promise<GasFundingResult>;
|
|
369
|
-
/**
|
|
370
|
-
* Estimate gas budget (no storageRebate) using a probe build/simulate.
|
|
371
|
-
* Prefers classic coin gas when coin objects exist so the estimate matches the
|
|
372
|
-
* cheaper payment path. Budget is left unset so Mysten can dry-run with MAX_GAS
|
|
373
|
-
* overrides (avoids locking the full balance away from GasCoin splits).
|
|
374
|
-
*/
|
|
375
369
|
declare function estimateGasBudget(input: {
|
|
376
370
|
tx: Transaction;
|
|
377
371
|
suiClient: SuiGrpcClient;
|
package/dist/index.js
CHANGED
|
@@ -528,13 +528,33 @@ async function selectGasFunding(input) {
|
|
|
528
528
|
}
|
|
529
529
|
throw new InsufficientGasFundsError(gasBudget, coinBalance, addressBalance);
|
|
530
530
|
}
|
|
531
|
+
function cloneWithClearedGasConfig(tx) {
|
|
532
|
+
const data = structuredClone(tx.getData());
|
|
533
|
+
data.gasData.budget = null;
|
|
534
|
+
data.gasData.price = null;
|
|
535
|
+
data.gasData.payment = null;
|
|
536
|
+
data.expiration = null;
|
|
537
|
+
return Transaction.from(JSON.stringify(data));
|
|
538
|
+
}
|
|
539
|
+
function isPositiveBudget(budget) {
|
|
540
|
+
if (budget == null) {
|
|
541
|
+
return false;
|
|
542
|
+
}
|
|
543
|
+
try {
|
|
544
|
+
return BigInt(budget) > 0n;
|
|
545
|
+
} catch {
|
|
546
|
+
return false;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
531
549
|
async function estimateGasBudget(input) {
|
|
532
550
|
const { tx, suiClient, owner, gasPrice } = input;
|
|
533
551
|
const funding = await loadSuiGasFunding(suiClient, owner, tx);
|
|
534
552
|
if (funding.total <= 0n) {
|
|
535
553
|
throw new InsufficientGasFundsError(0n, funding.coinBalance, funding.addressBalance);
|
|
536
554
|
}
|
|
537
|
-
const
|
|
555
|
+
const { budget, payment } = tx.getData().gasData;
|
|
556
|
+
const mustResetGas = payment != null && payment.length === 0 || budget != null && !isPositiveBudget(budget);
|
|
557
|
+
const probe = mustResetGas ? cloneWithClearedGasConfig(tx) : Transaction.from(tx);
|
|
538
558
|
probe.setSender(owner);
|
|
539
559
|
probe.setGasPrice(gasPrice);
|
|
540
560
|
if (funding.paymentCoins.length > 0) {
|
|
@@ -566,14 +586,21 @@ async function prepareGasFunding(input) {
|
|
|
566
586
|
const { payment, budget: existingBudget } = tx.getData().gasData;
|
|
567
587
|
const bakedAddressBalanceGas = payment != null && payment.length === 0;
|
|
568
588
|
let { gasBudget } = input;
|
|
589
|
+
if (gasBudget != null && gasBudget <= 0n) {
|
|
590
|
+
gasBudget = void 0;
|
|
591
|
+
}
|
|
592
|
+
const existingPositive = isPositiveBudget(existingBudget) ? BigInt(existingBudget) : null;
|
|
569
593
|
if (gasBudget == null) {
|
|
570
|
-
if (bakedAddressBalanceGas ||
|
|
594
|
+
if (bakedAddressBalanceGas || existingPositive == null) {
|
|
571
595
|
gasBudget = await estimateGasBudget({ tx, suiClient, owner, gasPrice });
|
|
572
596
|
} else {
|
|
573
|
-
gasBudget =
|
|
597
|
+
gasBudget = existingPositive;
|
|
574
598
|
}
|
|
575
599
|
}
|
|
576
600
|
tx.setGasBudget(gasBudget);
|
|
601
|
+
if (bakedAddressBalanceGas) {
|
|
602
|
+
tx.setExpiration(null);
|
|
603
|
+
}
|
|
577
604
|
return selectGasFunding({ tx, suiClient, owner, gasBudget });
|
|
578
605
|
}
|
|
579
606
|
async function preferClassicGasPayment(input) {
|