@msafe/sui3-sdk 1.0.22 → 1.0.24
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 +28 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/simulate/simulator.ts +2 -1
- package/src/utils/gasFunding.ts +43 -6
package/dist/index.d.cts
CHANGED
|
@@ -334,6 +334,8 @@ declare class InvitationSDK {
|
|
|
334
334
|
updateMSafeStatus(msafeAddress: string, status: UserMSafeStatus): Promise<void>;
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
/** Protocol cap: a transaction may smash at most this many gas payment objects. */
|
|
338
|
+
declare const MAX_GAS_PAYMENT_OBJECTS = 256;
|
|
337
339
|
type GasFundingMode = 'classic' | 'addressBalance' | 'mixedTopUp';
|
|
338
340
|
interface GasFundingResult {
|
|
339
341
|
mode: GasFundingMode;
|
|
@@ -352,6 +354,19 @@ declare class InsufficientGasFundsError extends Error {
|
|
|
352
354
|
* storageRebate is refunded after execution and must not reduce the budget.
|
|
353
355
|
*/
|
|
354
356
|
declare function computeGasBudget(gasUsed: Pick<SuiClientTypes.GasCostSummary, 'computationCost' | 'storageCost'>, gasPrice: bigint): bigint;
|
|
357
|
+
type PaymentCoinRef = {
|
|
358
|
+
objectId: string;
|
|
359
|
+
version: string;
|
|
360
|
+
digest: string;
|
|
361
|
+
balance: bigint;
|
|
362
|
+
};
|
|
363
|
+
/**
|
|
364
|
+
* Pick the fewest large SUI coins that cover `cover`, capped at 256.
|
|
365
|
+
* Never attach every owned coin — accounts with hundreds of SUI objects
|
|
366
|
+
* exceed max_gas_payment_objects and trip gasless estimate
|
|
367
|
+
* ("gas_budget must be 0 for gasless transactions").
|
|
368
|
+
*/
|
|
369
|
+
declare function pickGasPaymentCoins(coins: PaymentCoinRef[], cover: bigint): PaymentCoinRef[];
|
|
355
370
|
/** Object IDs a built payload already pins (inputs + gas payment). */
|
|
356
371
|
declare function collectPayloadObjectIds(payload: string | Uint8Array): string[];
|
|
357
372
|
/**
|
|
@@ -643,4 +658,4 @@ declare function getIntentionContent(intention: unknown): unknown;
|
|
|
643
658
|
*/
|
|
644
659
|
declare function transactionFromContent(content: unknown): Transaction;
|
|
645
660
|
|
|
646
|
-
export { AddressBookSDK, COIN_RESERVATION_MAGIC, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeInfo, DEV_API_URL, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, type GasFundingMode, type GasFundingResult, type GasObjectReference, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, InfoTypeEnabledDto, InfoTypeKey, InsufficientGasFundsError, LOCAL_API_URL, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnabledDto, MSafeEnv, MSafeGlobals, type NotificationData, type NotificationInfo, NotificationSubscribeDto, NotificationUpdateDto, PREV_API_URL, PROD_API_URL, type Pagination, type PendingTx, type PendingVote, type ProposeIntention, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulateDryRunResponse, type SimulationFailedResult, type SimulationOption, type SimulationResult, type SimulationSuccessResult, TESTNET_RPC_URL, Uint8ArrayToHex, addPrefix, collectPayloadObjectIds, collectQueueExcludeObjectIds, computeGasBudget, createCoinReservationRef, estimateGasBudget, getAllCoins, getIntentionContent, getMSafeConfig, getPublicKeyFromChain, httpUrlToGrpcBaseUrl, isCoinReservationDigest, msafeChainToSuiNetwork, parkedPayloadHex, preferClassicGasPayment, prepareGasFunding, selectGasFunding, stringToBuffer, toSuiTransaction, transactionFromContent };
|
|
661
|
+
export { AddressBookSDK, COIN_RESERVATION_MAGIC, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeInfo, DEV_API_URL, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, type GasFundingMode, type GasFundingResult, type GasObjectReference, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, InfoTypeEnabledDto, InfoTypeKey, InsufficientGasFundsError, LOCAL_API_URL, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MAX_GAS_PAYMENT_OBJECTS, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnabledDto, MSafeEnv, MSafeGlobals, type NotificationData, type NotificationInfo, NotificationSubscribeDto, NotificationUpdateDto, PREV_API_URL, PROD_API_URL, type Pagination, type PaymentCoinRef, type PendingTx, type PendingVote, type ProposeIntention, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulateDryRunResponse, type SimulationFailedResult, type SimulationOption, type SimulationResult, type SimulationSuccessResult, TESTNET_RPC_URL, Uint8ArrayToHex, addPrefix, collectPayloadObjectIds, collectQueueExcludeObjectIds, computeGasBudget, createCoinReservationRef, estimateGasBudget, getAllCoins, getIntentionContent, getMSafeConfig, getPublicKeyFromChain, httpUrlToGrpcBaseUrl, isCoinReservationDigest, msafeChainToSuiNetwork, parkedPayloadHex, pickGasPaymentCoins, preferClassicGasPayment, prepareGasFunding, selectGasFunding, stringToBuffer, toSuiTransaction, transactionFromContent };
|
package/dist/index.d.ts
CHANGED
|
@@ -334,6 +334,8 @@ declare class InvitationSDK {
|
|
|
334
334
|
updateMSafeStatus(msafeAddress: string, status: UserMSafeStatus): Promise<void>;
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
+
/** Protocol cap: a transaction may smash at most this many gas payment objects. */
|
|
338
|
+
declare const MAX_GAS_PAYMENT_OBJECTS = 256;
|
|
337
339
|
type GasFundingMode = 'classic' | 'addressBalance' | 'mixedTopUp';
|
|
338
340
|
interface GasFundingResult {
|
|
339
341
|
mode: GasFundingMode;
|
|
@@ -352,6 +354,19 @@ declare class InsufficientGasFundsError extends Error {
|
|
|
352
354
|
* storageRebate is refunded after execution and must not reduce the budget.
|
|
353
355
|
*/
|
|
354
356
|
declare function computeGasBudget(gasUsed: Pick<SuiClientTypes.GasCostSummary, 'computationCost' | 'storageCost'>, gasPrice: bigint): bigint;
|
|
357
|
+
type PaymentCoinRef = {
|
|
358
|
+
objectId: string;
|
|
359
|
+
version: string;
|
|
360
|
+
digest: string;
|
|
361
|
+
balance: bigint;
|
|
362
|
+
};
|
|
363
|
+
/**
|
|
364
|
+
* Pick the fewest large SUI coins that cover `cover`, capped at 256.
|
|
365
|
+
* Never attach every owned coin — accounts with hundreds of SUI objects
|
|
366
|
+
* exceed max_gas_payment_objects and trip gasless estimate
|
|
367
|
+
* ("gas_budget must be 0 for gasless transactions").
|
|
368
|
+
*/
|
|
369
|
+
declare function pickGasPaymentCoins(coins: PaymentCoinRef[], cover: bigint): PaymentCoinRef[];
|
|
355
370
|
/** Object IDs a built payload already pins (inputs + gas payment). */
|
|
356
371
|
declare function collectPayloadObjectIds(payload: string | Uint8Array): string[];
|
|
357
372
|
/**
|
|
@@ -643,4 +658,4 @@ declare function getIntentionContent(intention: unknown): unknown;
|
|
|
643
658
|
*/
|
|
644
659
|
declare function transactionFromContent(content: unknown): Transaction;
|
|
645
660
|
|
|
646
|
-
export { AddressBookSDK, COIN_RESERVATION_MAGIC, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeInfo, DEV_API_URL, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, type GasFundingMode, type GasFundingResult, type GasObjectReference, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, InfoTypeEnabledDto, InfoTypeKey, InsufficientGasFundsError, LOCAL_API_URL, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnabledDto, MSafeEnv, MSafeGlobals, type NotificationData, type NotificationInfo, NotificationSubscribeDto, NotificationUpdateDto, PREV_API_URL, PROD_API_URL, type Pagination, type PendingTx, type PendingVote, type ProposeIntention, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulateDryRunResponse, type SimulationFailedResult, type SimulationOption, type SimulationResult, type SimulationSuccessResult, TESTNET_RPC_URL, Uint8ArrayToHex, addPrefix, collectPayloadObjectIds, collectQueueExcludeObjectIds, computeGasBudget, createCoinReservationRef, estimateGasBudget, getAllCoins, getIntentionContent, getMSafeConfig, getPublicKeyFromChain, httpUrlToGrpcBaseUrl, isCoinReservationDigest, msafeChainToSuiNetwork, parkedPayloadHex, preferClassicGasPayment, prepareGasFunding, selectGasFunding, stringToBuffer, toSuiTransaction, transactionFromContent };
|
|
661
|
+
export { AddressBookSDK, COIN_RESERVATION_MAGIC, COIN_TYPE_ARG_REGEX, Coin, CoinHelper, CreateHelper, type CreateMSafeInfo, DEV_API_URL, DEV_SYNCING_URL, ENV_CONFIGS, Formatter, type FutureIntention, type GasFundingMode, type GasFundingResult, type GasObjectReference, HexToUint8Array, type HistorySendTx, type HistoryVote, type IWallet, InfoTypeEnabledDto, InfoTypeKey, InsufficientGasFundsError, LOCAL_API_URL, LOCAL_SYNCING_URL, MAINNET_RPC_URL, MAX_GAS_PAYMENT_OBJECTS, MSafeAccount, MSafeClient, type MSafeConfig, type MSafeConfigOptions, MSafeEnabledDto, MSafeEnv, MSafeGlobals, type NotificationData, type NotificationInfo, NotificationSubscribeDto, NotificationUpdateDto, PREV_API_URL, PROD_API_URL, type Pagination, type PaymentCoinRef, type PendingTx, type PendingVote, type ProposeIntention, type ReceiveTransaction, SUI_COIN, SignatureVerifier, type SimulateDryRunResponse, type SimulationFailedResult, type SimulationOption, type SimulationResult, type SimulationSuccessResult, TESTNET_RPC_URL, Uint8ArrayToHex, addPrefix, collectPayloadObjectIds, collectQueueExcludeObjectIds, computeGasBudget, createCoinReservationRef, estimateGasBudget, getAllCoins, getIntentionContent, getMSafeConfig, getPublicKeyFromChain, httpUrlToGrpcBaseUrl, isCoinReservationDigest, msafeChainToSuiNetwork, parkedPayloadHex, pickGasPaymentCoins, preferClassicGasPayment, prepareGasFunding, selectGasFunding, stringToBuffer, toSuiTransaction, transactionFromContent };
|
package/dist/index.js
CHANGED
|
@@ -416,6 +416,8 @@ async function getAllCoins(input) {
|
|
|
416
416
|
|
|
417
417
|
// src/utils/gasFunding.ts
|
|
418
418
|
var GAS_SAFE_OVERHEAD = 1000n;
|
|
419
|
+
var MAX_GAS_PAYMENT_OBJECTS = 256;
|
|
420
|
+
var ESTIMATE_GAS_COVER = 1000000000n;
|
|
419
421
|
var InsufficientGasFundsError = class extends Error {
|
|
420
422
|
gasBudget;
|
|
421
423
|
coinBalance;
|
|
@@ -436,6 +438,25 @@ function computeGasBudget(gasUsed, gasPrice) {
|
|
|
436
438
|
const safeOverhead = GAS_SAFE_OVERHEAD * gasPrice;
|
|
437
439
|
return BigInt(computationCost) + BigInt(storageCost) + safeOverhead;
|
|
438
440
|
}
|
|
441
|
+
function pickGasPaymentCoins(coins, cover) {
|
|
442
|
+
if (cover <= 0n) {
|
|
443
|
+
return [];
|
|
444
|
+
}
|
|
445
|
+
const sorted = [...coins].filter((coin) => coin.balance > 0n).sort((a, b) => a.balance === b.balance ? 0 : a.balance < b.balance ? 1 : -1);
|
|
446
|
+
const selected = [];
|
|
447
|
+
let sum = 0n;
|
|
448
|
+
for (const coin of sorted) {
|
|
449
|
+
if (selected.length >= MAX_GAS_PAYMENT_OBJECTS) {
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
selected.push(coin);
|
|
453
|
+
sum += coin.balance;
|
|
454
|
+
if (sum >= cover) {
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return selected;
|
|
459
|
+
}
|
|
439
460
|
function collectUsedObjectIds(tx) {
|
|
440
461
|
const used = tx.getData().inputs.reduce((acc, input) => {
|
|
441
462
|
const immOrOwned = input.Object?.ImmOrOwnedObject?.objectId;
|
|
@@ -580,7 +601,7 @@ async function selectGasFunding(input) {
|
|
|
580
601
|
throw new InsufficientGasFundsError(gasBudget, coinBalance, addressBalance);
|
|
581
602
|
}
|
|
582
603
|
if (paymentCoins.length > 0 && coinBalance >= gasBudget) {
|
|
583
|
-
tx.setGasPayment(toObjectRefs(paymentCoins));
|
|
604
|
+
tx.setGasPayment(toObjectRefs(pickGasPaymentCoins(paymentCoins, gasBudget)));
|
|
584
605
|
return { mode: "classic", gasBudget, coinBalance, addressBalance };
|
|
585
606
|
}
|
|
586
607
|
if (paymentCoins.length > 0 && total >= gasBudget) {
|
|
@@ -589,7 +610,7 @@ async function selectGasFunding(input) {
|
|
|
589
610
|
tx,
|
|
590
611
|
suiClient,
|
|
591
612
|
owner,
|
|
592
|
-
paymentCoins,
|
|
613
|
+
paymentCoins: pickGasPaymentCoins(paymentCoins, 1n),
|
|
593
614
|
topUpAmount
|
|
594
615
|
});
|
|
595
616
|
return { mode: "mixedTopUp", gasBudget, coinBalance, addressBalance };
|
|
@@ -635,7 +656,7 @@ async function estimateGasBudget(input) {
|
|
|
635
656
|
probe.setSender(owner);
|
|
636
657
|
probe.setGasPrice(gasPrice);
|
|
637
658
|
if (funding.paymentCoins.length > 0) {
|
|
638
|
-
probe.setGasPayment(toObjectRefs(funding.paymentCoins));
|
|
659
|
+
probe.setGasPayment(toObjectRefs(pickGasPaymentCoins(funding.paymentCoins, ESTIMATE_GAS_COVER)));
|
|
639
660
|
}
|
|
640
661
|
let built;
|
|
641
662
|
try {
|
|
@@ -710,7 +731,7 @@ async function preferClassicGasPayment(input) {
|
|
|
710
731
|
if (funding.paymentCoins.length === 0) {
|
|
711
732
|
return false;
|
|
712
733
|
}
|
|
713
|
-
tx.setGasPayment(toObjectRefs(funding.paymentCoins));
|
|
734
|
+
tx.setGasPayment(toObjectRefs(pickGasPaymentCoins(funding.paymentCoins, ESTIMATE_GAS_COVER)));
|
|
714
735
|
return true;
|
|
715
736
|
}
|
|
716
737
|
|
|
@@ -720,7 +741,7 @@ function formatExecutionError(error) {
|
|
|
720
741
|
}
|
|
721
742
|
function gasObjectToReference(gas) {
|
|
722
743
|
if (!gas?.objectId) {
|
|
723
|
-
|
|
744
|
+
return { objectId: "0x0", version: "0", digest: "" };
|
|
724
745
|
}
|
|
725
746
|
const version = gas.outputVersion ?? gas.inputVersion ?? "0";
|
|
726
747
|
const digest = gas.outputDigest ?? gas.inputDigest ?? "";
|
|
@@ -2107,6 +2128,7 @@ export {
|
|
|
2107
2128
|
LOCAL_API_URL,
|
|
2108
2129
|
LOCAL_SYNCING_URL,
|
|
2109
2130
|
MAINNET_RPC_URL,
|
|
2131
|
+
MAX_GAS_PAYMENT_OBJECTS,
|
|
2110
2132
|
MSafeAccount,
|
|
2111
2133
|
MSafeClient,
|
|
2112
2134
|
MSafeEnabledDto,
|
|
@@ -2134,6 +2156,7 @@ export {
|
|
|
2134
2156
|
isCoinReservationDigest,
|
|
2135
2157
|
msafeChainToSuiNetwork,
|
|
2136
2158
|
parkedPayloadHex,
|
|
2159
|
+
pickGasPaymentCoins,
|
|
2137
2160
|
preferClassicGasPayment,
|
|
2138
2161
|
prepareGasFunding,
|
|
2139
2162
|
selectGasFunding,
|