@msafe/sui3-sdk 1.0.18 → 1.0.20
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 +25 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -12
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/MSafeAccount.ts +2 -8
- package/src/utils/gasFunding.ts +36 -2
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,
|
|
@@ -1253,14 +1277,6 @@ var MSafeAccount = class _MSafeAccount {
|
|
|
1253
1277
|
throw new Error("Already rejected");
|
|
1254
1278
|
}
|
|
1255
1279
|
const rejectTxb = toSuiTransaction((0, import_sui3_utils4.buildRejectTxb)(this.address));
|
|
1256
|
-
rejectTxb.setGasPrice(input.gasPrice);
|
|
1257
|
-
await prepareGasFunding({
|
|
1258
|
-
tx: rejectTxb,
|
|
1259
|
-
suiClient: this.suiClient,
|
|
1260
|
-
owner: this.address,
|
|
1261
|
-
gasPrice: input.gasPrice,
|
|
1262
|
-
gasBudget: input.gasBudget
|
|
1263
|
-
});
|
|
1264
1280
|
const digest = await rejectTxb.getDigest({ client: this.suiClient });
|
|
1265
1281
|
const payload = await rejectTxb.build({ client: this.suiClient });
|
|
1266
1282
|
const signature = await this.wallet.signTransactionBlock({ transactionBlock: payload });
|