@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.cjs
CHANGED
|
@@ -592,13 +592,33 @@ async function selectGasFunding(input) {
|
|
|
592
592
|
}
|
|
593
593
|
throw new InsufficientGasFundsError(gasBudget, coinBalance, addressBalance);
|
|
594
594
|
}
|
|
595
|
+
function cloneWithClearedGasConfig(tx) {
|
|
596
|
+
const data = structuredClone(tx.getData());
|
|
597
|
+
data.gasData.budget = null;
|
|
598
|
+
data.gasData.price = null;
|
|
599
|
+
data.gasData.payment = null;
|
|
600
|
+
data.expiration = null;
|
|
601
|
+
return import_transactions.Transaction.from(JSON.stringify(data));
|
|
602
|
+
}
|
|
603
|
+
function isPositiveBudget(budget) {
|
|
604
|
+
if (budget == null) {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
try {
|
|
608
|
+
return BigInt(budget) > 0n;
|
|
609
|
+
} catch {
|
|
610
|
+
return false;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
595
613
|
async function estimateGasBudget(input) {
|
|
596
614
|
const { tx, suiClient, owner, gasPrice } = input;
|
|
597
615
|
const funding = await loadSuiGasFunding(suiClient, owner, tx);
|
|
598
616
|
if (funding.total <= 0n) {
|
|
599
617
|
throw new InsufficientGasFundsError(0n, funding.coinBalance, funding.addressBalance);
|
|
600
618
|
}
|
|
601
|
-
const
|
|
619
|
+
const { budget, payment } = tx.getData().gasData;
|
|
620
|
+
const mustResetGas = payment != null && payment.length === 0 || budget != null && !isPositiveBudget(budget);
|
|
621
|
+
const probe = mustResetGas ? cloneWithClearedGasConfig(tx) : import_transactions.Transaction.from(tx);
|
|
602
622
|
probe.setSender(owner);
|
|
603
623
|
probe.setGasPrice(gasPrice);
|
|
604
624
|
if (funding.paymentCoins.length > 0) {
|
|
@@ -630,14 +650,21 @@ async function prepareGasFunding(input) {
|
|
|
630
650
|
const { payment, budget: existingBudget } = tx.getData().gasData;
|
|
631
651
|
const bakedAddressBalanceGas = payment != null && payment.length === 0;
|
|
632
652
|
let { gasBudget } = input;
|
|
653
|
+
if (gasBudget != null && gasBudget <= 0n) {
|
|
654
|
+
gasBudget = void 0;
|
|
655
|
+
}
|
|
656
|
+
const existingPositive = isPositiveBudget(existingBudget) ? BigInt(existingBudget) : null;
|
|
633
657
|
if (gasBudget == null) {
|
|
634
|
-
if (bakedAddressBalanceGas ||
|
|
658
|
+
if (bakedAddressBalanceGas || existingPositive == null) {
|
|
635
659
|
gasBudget = await estimateGasBudget({ tx, suiClient, owner, gasPrice });
|
|
636
660
|
} else {
|
|
637
|
-
gasBudget =
|
|
661
|
+
gasBudget = existingPositive;
|
|
638
662
|
}
|
|
639
663
|
}
|
|
640
664
|
tx.setGasBudget(gasBudget);
|
|
665
|
+
if (bakedAddressBalanceGas) {
|
|
666
|
+
tx.setExpiration(null);
|
|
667
|
+
}
|
|
641
668
|
return selectGasFunding({ tx, suiClient, owner, gasBudget });
|
|
642
669
|
}
|
|
643
670
|
async function preferClassicGasPayment(input) {
|