@t2000/cli 5.6.0 → 5.7.0

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.
@@ -38,7 +38,6 @@ import {
38
38
  parse,
39
39
  picklist,
40
40
  pipe,
41
- promiseWithResolvers,
42
41
  pureBcsSchemaFromTypeName,
43
42
  record,
44
43
  replaceNames,
@@ -48,7 +47,7 @@ import {
48
47
  tuple,
49
48
  union,
50
49
  unknown
51
- } from "./chunk-MPXYF2CX.js";
50
+ } from "./chunk-X6ON6NN5.js";
52
51
  import {
53
52
  fromBase58,
54
53
  fromBase64,
@@ -63,12 +62,6 @@ import {
63
62
  } from "./chunk-I2DCISQP.js";
64
63
 
65
64
  // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/Commands.mjs
66
- var UpgradePolicy = /* @__PURE__ */ (function(UpgradePolicy$1) {
67
- UpgradePolicy$1[UpgradePolicy$1["COMPATIBLE"] = 0] = "COMPATIBLE";
68
- UpgradePolicy$1[UpgradePolicy$1["ADDITIVE"] = 128] = "ADDITIVE";
69
- UpgradePolicy$1[UpgradePolicy$1["DEP_ONLY"] = 192] = "DEP_ONLY";
70
- return UpgradePolicy$1;
71
- })({});
72
65
  var TransactionCommands = {
73
66
  MoveCall(input) {
74
67
  const [pkg, mod = "", fn = ""] = "target" in input ? input.target.split("::") : [
@@ -215,121 +208,6 @@ var Inputs = {
215
208
  }
216
209
  };
217
210
 
218
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/serializer.mjs
219
- function parseTypeName(typeName) {
220
- const parts = typeName.split("::");
221
- if (parts.length !== 3) throw new Error(`Invalid type name format: ${typeName}`);
222
- return {
223
- package: parts[0],
224
- module: parts[1],
225
- name: parts[2]
226
- };
227
- }
228
- function isTxContext(param) {
229
- if (param.body.$kind !== "datatype") return false;
230
- const { package: pkg, module, name } = parseTypeName(param.body.datatype.typeName);
231
- return normalizeSuiAddress(pkg) === SUI_FRAMEWORK_ADDRESS && module === "tx_context" && name === "TxContext";
232
- }
233
- function getPureBcsSchema(typeSignature) {
234
- switch (typeSignature.$kind) {
235
- case "address":
236
- return suiBcs.Address;
237
- case "bool":
238
- return suiBcs.Bool;
239
- case "u8":
240
- return suiBcs.U8;
241
- case "u16":
242
- return suiBcs.U16;
243
- case "u32":
244
- return suiBcs.U32;
245
- case "u64":
246
- return suiBcs.U64;
247
- case "u128":
248
- return suiBcs.U128;
249
- case "u256":
250
- return suiBcs.U256;
251
- case "vector": {
252
- if (typeSignature.vector.$kind === "u8") return suiBcs.byteVector().transform({
253
- input: (val) => typeof val === "string" ? new TextEncoder().encode(val) : val,
254
- output: (val) => val
255
- });
256
- const type = getPureBcsSchema(typeSignature.vector);
257
- return type ? suiBcs.vector(type) : null;
258
- }
259
- case "datatype": {
260
- const { package: pkg, module, name } = parseTypeName(typeSignature.datatype.typeName);
261
- const normalizedPkg = normalizeSuiAddress(pkg);
262
- if (normalizedPkg === MOVE_STDLIB_ADDRESS) {
263
- if (module === "ascii" && name === "String") return suiBcs.String;
264
- if (module === "string" && name === "String") return suiBcs.String;
265
- if (module === "option" && name === "Option") {
266
- const type = getPureBcsSchema(typeSignature.datatype.typeParameters[0]);
267
- return type ? suiBcs.vector(type) : null;
268
- }
269
- }
270
- if (normalizedPkg === SUI_FRAMEWORK_ADDRESS) {
271
- if (module === "object" && name === "ID") return suiBcs.Address;
272
- }
273
- return null;
274
- }
275
- case "typeParameter":
276
- case "unknown":
277
- return null;
278
- }
279
- }
280
- function normalizedTypeToMoveTypeSignature(type) {
281
- if (typeof type === "object" && "Reference" in type) return {
282
- reference: "immutable",
283
- body: normalizedTypeToMoveTypeSignatureBody(type.Reference)
284
- };
285
- if (typeof type === "object" && "MutableReference" in type) return {
286
- reference: "mutable",
287
- body: normalizedTypeToMoveTypeSignatureBody(type.MutableReference)
288
- };
289
- return {
290
- reference: null,
291
- body: normalizedTypeToMoveTypeSignatureBody(type)
292
- };
293
- }
294
- function normalizedTypeToMoveTypeSignatureBody(type) {
295
- if (typeof type === "string") switch (type) {
296
- case "Address":
297
- return { $kind: "address" };
298
- case "Bool":
299
- return { $kind: "bool" };
300
- case "U8":
301
- return { $kind: "u8" };
302
- case "U16":
303
- return { $kind: "u16" };
304
- case "U32":
305
- return { $kind: "u32" };
306
- case "U64":
307
- return { $kind: "u64" };
308
- case "U128":
309
- return { $kind: "u128" };
310
- case "U256":
311
- return { $kind: "u256" };
312
- default:
313
- throw new Error(`Unexpected type ${type}`);
314
- }
315
- if ("Vector" in type) return {
316
- $kind: "vector",
317
- vector: normalizedTypeToMoveTypeSignatureBody(type.Vector)
318
- };
319
- if ("Struct" in type) return {
320
- $kind: "datatype",
321
- datatype: {
322
- typeName: `${type.Struct.address}::${type.Struct.module}::${type.Struct.name}`,
323
- typeParameters: type.Struct.typeArguments.map(normalizedTypeToMoveTypeSignatureBody)
324
- }
325
- };
326
- if ("TypeParameter" in type) return {
327
- $kind: "typeParameter",
328
- index: type.TypeParameter
329
- };
330
- throw new Error(`Unexpected type ${JSON.stringify(type)}`);
331
- }
332
-
333
211
  // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/intents/CoinWithBalance.mjs
334
212
  var COIN_WITH_BALANCE = "CoinWithBalance";
335
213
  var SUI_TYPE = normalizeStructTag("0x2::sui::SUI");
@@ -763,6 +641,69 @@ function createCoinReservationRef(reservedBalance, owner, chainIdentifier, epoch
763
641
  });
764
642
  }
765
643
 
644
+ // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/serializer.mjs
645
+ function parseTypeName(typeName) {
646
+ const parts = typeName.split("::");
647
+ if (parts.length !== 3) throw new Error(`Invalid type name format: ${typeName}`);
648
+ return {
649
+ package: parts[0],
650
+ module: parts[1],
651
+ name: parts[2]
652
+ };
653
+ }
654
+ function isTxContext(param) {
655
+ if (param.body.$kind !== "datatype") return false;
656
+ const { package: pkg, module, name } = parseTypeName(param.body.datatype.typeName);
657
+ return normalizeSuiAddress(pkg) === SUI_FRAMEWORK_ADDRESS && module === "tx_context" && name === "TxContext";
658
+ }
659
+ function getPureBcsSchema(typeSignature) {
660
+ switch (typeSignature.$kind) {
661
+ case "address":
662
+ return suiBcs.Address;
663
+ case "bool":
664
+ return suiBcs.Bool;
665
+ case "u8":
666
+ return suiBcs.U8;
667
+ case "u16":
668
+ return suiBcs.U16;
669
+ case "u32":
670
+ return suiBcs.U32;
671
+ case "u64":
672
+ return suiBcs.U64;
673
+ case "u128":
674
+ return suiBcs.U128;
675
+ case "u256":
676
+ return suiBcs.U256;
677
+ case "vector": {
678
+ if (typeSignature.vector.$kind === "u8") return suiBcs.byteVector().transform({
679
+ input: (val) => typeof val === "string" ? new TextEncoder().encode(val) : val,
680
+ output: (val) => val
681
+ });
682
+ const type = getPureBcsSchema(typeSignature.vector);
683
+ return type ? suiBcs.vector(type) : null;
684
+ }
685
+ case "datatype": {
686
+ const { package: pkg, module, name } = parseTypeName(typeSignature.datatype.typeName);
687
+ const normalizedPkg = normalizeSuiAddress(pkg);
688
+ if (normalizedPkg === MOVE_STDLIB_ADDRESS) {
689
+ if (module === "ascii" && name === "String") return suiBcs.String;
690
+ if (module === "string" && name === "String") return suiBcs.String;
691
+ if (module === "option" && name === "Option") {
692
+ const type = getPureBcsSchema(typeSignature.datatype.typeParameters[0]);
693
+ return type ? suiBcs.vector(type) : null;
694
+ }
695
+ }
696
+ if (normalizedPkg === SUI_FRAMEWORK_ADDRESS) {
697
+ if (module === "object" && name === "ID") return suiBcs.Address;
698
+ }
699
+ return null;
700
+ }
701
+ case "typeParameter":
702
+ case "unknown":
703
+ return null;
704
+ }
705
+ }
706
+
766
707
  // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/client/core-resolver.mjs
767
708
  var MAX_OBJECTS_PER_FETCH = 50;
768
709
  var GAS_SAFE_OVERHEAD = 1000n;
@@ -1690,719 +1631,8 @@ var Transaction = class Transaction2 {
1690
1631
  }
1691
1632
  };
1692
1633
 
1693
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/ObjectCache.mjs
1694
- var AsyncCache = class {
1695
- async getObject(id) {
1696
- const [owned, shared] = await Promise.all([this.get("OwnedObject", id), this.get("SharedOrImmutableObject", id)]);
1697
- return owned ?? shared ?? null;
1698
- }
1699
- async getObjects(ids) {
1700
- return Promise.all(ids.map((id) => this.getObject(id)));
1701
- }
1702
- async addObject(object2) {
1703
- if (object2.owner) await this.set("OwnedObject", object2.objectId, object2);
1704
- else await this.set("SharedOrImmutableObject", object2.objectId, object2);
1705
- return object2;
1706
- }
1707
- async addObjects(objects) {
1708
- await Promise.all(objects.map(async (object2) => this.addObject(object2)));
1709
- }
1710
- async deleteObject(id) {
1711
- await Promise.all([this.delete("OwnedObject", id), this.delete("SharedOrImmutableObject", id)]);
1712
- }
1713
- async deleteObjects(ids) {
1714
- await Promise.all(ids.map((id) => this.deleteObject(id)));
1715
- }
1716
- async getMoveFunctionDefinition(ref) {
1717
- const functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;
1718
- return this.get("MoveFunction", functionName);
1719
- }
1720
- async addMoveFunctionDefinition(functionEntry) {
1721
- const pkg = normalizeSuiAddress(functionEntry.package);
1722
- const functionName = `${pkg}::${functionEntry.module}::${functionEntry.function}`;
1723
- const entry = {
1724
- ...functionEntry,
1725
- package: pkg
1726
- };
1727
- await this.set("MoveFunction", functionName, entry);
1728
- return entry;
1729
- }
1730
- async deleteMoveFunctionDefinition(ref) {
1731
- const functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;
1732
- await this.delete("MoveFunction", functionName);
1733
- }
1734
- async getCustom(key) {
1735
- return this.get("Custom", key);
1736
- }
1737
- async setCustom(key, value) {
1738
- return this.set("Custom", key, value);
1739
- }
1740
- async deleteCustom(key) {
1741
- return this.delete("Custom", key);
1742
- }
1743
- };
1744
- var InMemoryCache = class extends AsyncCache {
1745
- #caches = {
1746
- OwnedObject: /* @__PURE__ */ new Map(),
1747
- SharedOrImmutableObject: /* @__PURE__ */ new Map(),
1748
- MoveFunction: /* @__PURE__ */ new Map(),
1749
- Custom: /* @__PURE__ */ new Map()
1750
- };
1751
- async get(type, key) {
1752
- return this.#caches[type].get(key) ?? null;
1753
- }
1754
- async set(type, key, value) {
1755
- this.#caches[type].set(key, value);
1756
- }
1757
- async delete(type, key) {
1758
- this.#caches[type].delete(key);
1759
- }
1760
- async clear(type) {
1761
- if (type) this.#caches[type].clear();
1762
- else for (const cache of Object.values(this.#caches)) cache.clear();
1763
- }
1764
- };
1765
- var ObjectCache = class {
1766
- #cache;
1767
- #onEffects;
1768
- constructor({ cache = new InMemoryCache(), onEffects }) {
1769
- this.#cache = cache;
1770
- this.#onEffects = onEffects;
1771
- }
1772
- asPlugin() {
1773
- return async (transactionData, _options, next) => {
1774
- const unresolvedObjects = transactionData.inputs.filter((input) => input.UnresolvedObject).map((input) => input.UnresolvedObject.objectId);
1775
- const cached = (await this.#cache.getObjects(unresolvedObjects)).filter((obj) => obj !== null);
1776
- const byId = new Map(cached.map((obj) => [obj.objectId, obj]));
1777
- for (const input of transactionData.inputs) {
1778
- if (!input.UnresolvedObject) continue;
1779
- const cached$1 = byId.get(input.UnresolvedObject.objectId);
1780
- if (!cached$1) continue;
1781
- if (cached$1.initialSharedVersion && !input.UnresolvedObject.initialSharedVersion) input.UnresolvedObject.initialSharedVersion = cached$1.initialSharedVersion;
1782
- else {
1783
- if (cached$1.version && !input.UnresolvedObject.version) input.UnresolvedObject.version = cached$1.version;
1784
- if (cached$1.digest && !input.UnresolvedObject.digest) input.UnresolvedObject.digest = cached$1.digest;
1785
- }
1786
- }
1787
- await Promise.all(transactionData.commands.map(async (commands) => {
1788
- if (commands.MoveCall) {
1789
- const def = await this.getMoveFunctionDefinition({
1790
- package: commands.MoveCall.package,
1791
- module: commands.MoveCall.module,
1792
- function: commands.MoveCall.function
1793
- });
1794
- if (def) commands.MoveCall._argumentTypes = def.parameters;
1795
- }
1796
- }));
1797
- await next();
1798
- await Promise.all(transactionData.commands.map(async (commands) => {
1799
- if (commands.MoveCall?._argumentTypes) await this.#cache.addMoveFunctionDefinition({
1800
- package: commands.MoveCall.package,
1801
- module: commands.MoveCall.module,
1802
- function: commands.MoveCall.function,
1803
- parameters: commands.MoveCall._argumentTypes
1804
- });
1805
- }));
1806
- };
1807
- }
1808
- async clear() {
1809
- await this.#cache.clear();
1810
- }
1811
- async getMoveFunctionDefinition(ref) {
1812
- return this.#cache.getMoveFunctionDefinition(ref);
1813
- }
1814
- async getObjects(ids) {
1815
- return this.#cache.getObjects(ids);
1816
- }
1817
- async deleteObjects(ids) {
1818
- return this.#cache.deleteObjects(ids);
1819
- }
1820
- async clearOwnedObjects() {
1821
- await this.#cache.clear("OwnedObject");
1822
- }
1823
- async clearCustom() {
1824
- await this.#cache.clear("Custom");
1825
- }
1826
- async getCustom(key) {
1827
- return this.#cache.getCustom(key);
1828
- }
1829
- async setCustom(key, value) {
1830
- return this.#cache.setCustom(key, value);
1831
- }
1832
- async deleteCustom(key) {
1833
- return this.#cache.deleteCustom(key);
1834
- }
1835
- async applyEffects(effects) {
1836
- if (!effects.V2) throw new Error(`Unsupported transaction effects version ${effects.$kind}`);
1837
- const { lamportVersion, changedObjects } = effects.V2;
1838
- const deletedIds = [];
1839
- const addedObjects = [];
1840
- changedObjects.forEach(([id, change]) => {
1841
- if (change.outputState.NotExist) deletedIds.push(id);
1842
- else if (change.outputState.ObjectWrite) {
1843
- const [digest, owner] = change.outputState.ObjectWrite;
1844
- addedObjects.push({
1845
- objectId: id,
1846
- digest,
1847
- version: lamportVersion,
1848
- owner: owner.AddressOwner ?? owner.ObjectOwner ?? null,
1849
- initialSharedVersion: owner.Shared?.initialSharedVersion ?? null
1850
- });
1851
- }
1852
- });
1853
- await Promise.all([
1854
- this.#cache.addObjects(addedObjects),
1855
- this.#cache.deleteObjects(deletedIds),
1856
- this.#onEffects?.(effects)
1857
- ]);
1858
- }
1859
- };
1860
-
1861
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/caching.mjs
1862
- var CachingTransactionExecutor = class {
1863
- #client;
1864
- #lastDigest = null;
1865
- constructor({ client, ...options }) {
1866
- this.#client = client;
1867
- this.cache = new ObjectCache(options);
1868
- }
1869
- /**
1870
- * Clears all Owned objects
1871
- * Immutable objects, Shared objects, and Move function definitions will be preserved
1872
- */
1873
- async reset() {
1874
- await Promise.all([
1875
- this.cache.clearOwnedObjects(),
1876
- this.cache.clearCustom(),
1877
- this.waitForLastTransaction()
1878
- ]);
1879
- }
1880
- async buildTransaction({ transaction, ...options }) {
1881
- transaction.addBuildPlugin(this.cache.asPlugin());
1882
- transaction.addBuildPlugin(coreClientResolveTransactionPlugin);
1883
- return transaction.build({
1884
- client: this.#client,
1885
- ...options
1886
- });
1887
- }
1888
- async executeTransaction({ transaction, signatures, include }) {
1889
- const bytes = isTransaction(transaction) ? await this.buildTransaction({ transaction }) : transaction;
1890
- const results = await this.#client.core.executeTransaction({
1891
- transaction: bytes,
1892
- signatures,
1893
- include: {
1894
- ...include,
1895
- effects: true
1896
- }
1897
- });
1898
- const tx = results.$kind === "Transaction" ? results.Transaction : results.FailedTransaction;
1899
- if (tx.effects?.bcs) {
1900
- const effects = suiBcs.TransactionEffects.parse(tx.effects.bcs);
1901
- await this.applyEffects(effects);
1902
- }
1903
- return results;
1904
- }
1905
- async signAndExecuteTransaction({ include, transaction, signer }) {
1906
- transaction.setSenderIfNotSet(signer.toSuiAddress());
1907
- const bytes = await this.buildTransaction({ transaction });
1908
- const { signature } = await signer.signTransaction(bytes);
1909
- return this.executeTransaction({
1910
- transaction: bytes,
1911
- signatures: [signature],
1912
- include
1913
- });
1914
- }
1915
- async applyEffects(effects) {
1916
- this.#lastDigest = effects.V2?.transactionDigest ?? null;
1917
- await this.cache.applyEffects(effects);
1918
- }
1919
- async waitForLastTransaction() {
1920
- if (this.#lastDigest) {
1921
- await this.#client.core.waitForTransaction({ digest: this.#lastDigest });
1922
- this.#lastDigest = null;
1923
- }
1924
- }
1925
- };
1926
-
1927
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/queue.mjs
1928
- var SerialQueue = class {
1929
- #queue = [];
1930
- async runTask(task) {
1931
- return new Promise((resolve, reject) => {
1932
- this.#queue.push(() => {
1933
- task().finally(() => {
1934
- this.#queue.shift();
1935
- if (this.#queue.length > 0) this.#queue[0]();
1936
- }).then(resolve, reject);
1937
- });
1938
- if (this.#queue.length === 1) this.#queue[0]();
1939
- });
1940
- }
1941
- };
1942
- var ParallelQueue = class {
1943
- #queue = [];
1944
- constructor(maxTasks) {
1945
- this.activeTasks = 0;
1946
- this.maxTasks = maxTasks;
1947
- }
1948
- runTask(task) {
1949
- return new Promise((resolve, reject) => {
1950
- if (this.activeTasks < this.maxTasks) {
1951
- this.activeTasks++;
1952
- task().finally(() => {
1953
- if (this.#queue.length > 0) this.#queue.shift()();
1954
- else this.activeTasks--;
1955
- }).then(resolve, reject);
1956
- } else this.#queue.push(() => {
1957
- task().finally(() => {
1958
- if (this.#queue.length > 0) this.#queue.shift()();
1959
- else this.activeTasks--;
1960
- }).then(resolve, reject);
1961
- });
1962
- });
1963
- }
1964
- };
1965
-
1966
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/serial.mjs
1967
- var EPOCH_BOUNDARY_WINDOW = 6e4;
1968
- var SerialTransactionExecutor = class {
1969
- #queue = new SerialQueue();
1970
- #signer;
1971
- #client;
1972
- #cache;
1973
- #defaultGasBudget;
1974
- #gasMode;
1975
- #epochInfo = null;
1976
- #epochInfoPromise = null;
1977
- constructor(options) {
1978
- const { signer, defaultGasBudget = 50000000n, client, cache } = options;
1979
- this.#signer = signer;
1980
- this.#client = client;
1981
- this.#defaultGasBudget = defaultGasBudget;
1982
- this.#gasMode = options.gasMode ?? "coins";
1983
- this.#cache = new CachingTransactionExecutor({
1984
- client,
1985
- cache,
1986
- onEffects: (effects) => this.#cacheGasCoin(effects)
1987
- });
1988
- }
1989
- async applyEffects(effects) {
1990
- return this.#cache.applyEffects(effects);
1991
- }
1992
- #cacheGasCoin = async (effects) => {
1993
- if (this.#gasMode === "addressBalance" || !effects.V2) return;
1994
- const gasCoin = getGasCoinFromEffects(effects).ref;
1995
- if (gasCoin) this.#cache.cache.setCustom("gasCoin", gasCoin);
1996
- else this.#cache.cache.deleteCustom("gasCoin");
1997
- };
1998
- async buildTransaction(transaction) {
1999
- return this.#queue.runTask(() => this.#buildTransaction(transaction));
2000
- }
2001
- #buildTransaction = async (transaction) => {
2002
- await transaction.prepareForSerialization({
2003
- client: this.#client,
2004
- supportedIntents: ["CoinWithBalance"]
2005
- });
2006
- const copy = Transaction.from(transaction);
2007
- if (this.#gasMode === "addressBalance") {
2008
- copy.setGasPayment([]);
2009
- copy.setExpiration(await this.#getValidDuringExpiration());
2010
- } else {
2011
- const gasCoin = await this.#cache.cache.getCustom("gasCoin");
2012
- if (gasCoin) copy.setGasPayment([gasCoin]);
2013
- }
2014
- copy.setGasBudgetIfNotSet(this.#defaultGasBudget);
2015
- copy.setSenderIfNotSet(this.#signer.toSuiAddress());
2016
- return this.#cache.buildTransaction({ transaction: copy });
2017
- };
2018
- async #getValidDuringExpiration() {
2019
- await this.#ensureEpochInfo();
2020
- const currentEpoch = BigInt(this.#epochInfo.epoch);
2021
- return { ValidDuring: {
2022
- minEpoch: String(currentEpoch),
2023
- maxEpoch: String(currentEpoch + 1n),
2024
- minTimestamp: null,
2025
- maxTimestamp: null,
2026
- chain: this.#epochInfo.chainIdentifier,
2027
- nonce: Math.random() * 4294967296 >>> 0
2028
- } };
2029
- }
2030
- async #ensureEpochInfo() {
2031
- if (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) return;
2032
- if (this.#epochInfoPromise) {
2033
- await this.#epochInfoPromise;
2034
- return;
2035
- }
2036
- this.#epochInfoPromise = this.#fetchEpochInfo();
2037
- try {
2038
- await this.#epochInfoPromise;
2039
- } finally {
2040
- this.#epochInfoPromise = null;
2041
- }
2042
- }
2043
- async #fetchEpochInfo() {
2044
- const [{ systemState }, { chainIdentifier }] = await Promise.all([this.#client.core.getCurrentSystemState(), this.#client.core.getChainIdentifier()]);
2045
- this.#epochInfo = {
2046
- epoch: systemState.epoch,
2047
- expiration: Number(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),
2048
- chainIdentifier
2049
- };
2050
- }
2051
- resetCache() {
2052
- return this.#cache.reset();
2053
- }
2054
- waitForLastTransaction() {
2055
- return this.#cache.waitForLastTransaction();
2056
- }
2057
- executeTransaction(transaction, include, additionalSignatures = []) {
2058
- return this.#queue.runTask(async () => {
2059
- const bytes = isTransaction(transaction) ? await this.#buildTransaction(transaction) : transaction;
2060
- const { signature } = await this.#signer.signTransaction(bytes);
2061
- return this.#cache.executeTransaction({
2062
- signatures: [signature, ...additionalSignatures],
2063
- transaction: bytes,
2064
- include
2065
- }).catch(async (error) => {
2066
- await this.resetCache();
2067
- throw error;
2068
- });
2069
- });
2070
- }
2071
- };
2072
- function getGasCoinFromEffects(effects) {
2073
- if (!effects.V2) throw new Error("Unexpected effects version");
2074
- const gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex];
2075
- if (!gasObjectChange) throw new Error("Gas object not found in effects");
2076
- const [objectId, { outputState }] = gasObjectChange;
2077
- if (!outputState.ObjectWrite) throw new Error("Unexpected gas object state");
2078
- const [digest, owner] = outputState.ObjectWrite;
2079
- return {
2080
- ref: {
2081
- objectId,
2082
- digest,
2083
- version: effects.V2.lamportVersion
2084
- },
2085
- owner: owner.AddressOwner || owner.ObjectOwner
2086
- };
2087
- }
2088
-
2089
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/parallel.mjs
2090
- var PARALLEL_EXECUTOR_DEFAULTS = {
2091
- coinBatchSize: 20,
2092
- initialCoinBalance: 200000000n,
2093
- minimumCoinBalance: 50000000n,
2094
- maxPoolSize: 50
2095
- };
2096
- var EPOCH_BOUNDARY_WINDOW2 = 6e4;
2097
- var ParallelTransactionExecutor = class {
2098
- #signer;
2099
- #client;
2100
- #gasMode;
2101
- #coinBatchSize;
2102
- #initialCoinBalance;
2103
- #minimumCoinBalance;
2104
- #defaultGasBudget;
2105
- #maxPoolSize;
2106
- #sourceCoins;
2107
- #coinPool = [];
2108
- #cache;
2109
- #objectIdQueues = /* @__PURE__ */ new Map();
2110
- #buildQueue = new SerialQueue();
2111
- #executeQueue;
2112
- #lastDigest = null;
2113
- #cacheLock = null;
2114
- #pendingTransactions = 0;
2115
- #epochInfo = null;
2116
- #epochInfoPromise = null;
2117
- constructor(options) {
2118
- this.#signer = options.signer;
2119
- this.#client = options.client;
2120
- this.#gasMode = options.gasMode ?? "coins";
2121
- if (this.#gasMode === "coins") {
2122
- const coinOptions = options;
2123
- this.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;
2124
- this.#initialCoinBalance = coinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;
2125
- this.#minimumCoinBalance = coinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;
2126
- this.#sourceCoins = coinOptions.sourceCoins ? new Map(coinOptions.sourceCoins.map((id) => [id, null])) : null;
2127
- } else {
2128
- this.#coinBatchSize = 0;
2129
- this.#initialCoinBalance = 0n;
2130
- this.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;
2131
- this.#sourceCoins = null;
2132
- }
2133
- this.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;
2134
- this.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;
2135
- this.#cache = new CachingTransactionExecutor({
2136
- client: options.client,
2137
- cache: options.cache
2138
- });
2139
- this.#executeQueue = new ParallelQueue(this.#maxPoolSize);
2140
- }
2141
- resetCache() {
2142
- this.#epochInfo = null;
2143
- return this.#updateCache(() => this.#cache.reset());
2144
- }
2145
- async waitForLastTransaction() {
2146
- await this.#updateCache(() => this.#waitForLastDigest());
2147
- }
2148
- async executeTransaction(transaction, include, additionalSignatures = []) {
2149
- const { promise, resolve, reject } = promiseWithResolvers();
2150
- const usedObjects = await this.#getUsedObjects(transaction);
2151
- const execute = () => {
2152
- this.#executeQueue.runTask(() => {
2153
- return this.#execute(transaction, usedObjects, include, additionalSignatures).then(resolve, reject);
2154
- });
2155
- };
2156
- const conflicts = /* @__PURE__ */ new Set();
2157
- usedObjects.forEach((objectId) => {
2158
- if (this.#objectIdQueues.get(objectId)) {
2159
- conflicts.add(objectId);
2160
- this.#objectIdQueues.get(objectId).push(() => {
2161
- conflicts.delete(objectId);
2162
- if (conflicts.size === 0) execute();
2163
- });
2164
- } else this.#objectIdQueues.set(objectId, []);
2165
- });
2166
- if (conflicts.size === 0) execute();
2167
- return promise;
2168
- }
2169
- async #getUsedObjects(transaction) {
2170
- const usedObjects = /* @__PURE__ */ new Set();
2171
- let serialized = false;
2172
- transaction.addSerializationPlugin(async (blockData, _options, next) => {
2173
- await next();
2174
- if (serialized) return;
2175
- serialized = true;
2176
- blockData.inputs.forEach((input) => {
2177
- if (input.Object?.ImmOrOwnedObject?.objectId) usedObjects.add(input.Object.ImmOrOwnedObject.objectId);
2178
- else if (input.Object?.Receiving?.objectId) usedObjects.add(input.Object.Receiving.objectId);
2179
- else if (input.UnresolvedObject?.objectId && !input.UnresolvedObject.initialSharedVersion) usedObjects.add(input.UnresolvedObject.objectId);
2180
- });
2181
- });
2182
- await transaction.prepareForSerialization({ client: this.#client });
2183
- return usedObjects;
2184
- }
2185
- async #execute(transaction, usedObjects, include, additionalSignatures = []) {
2186
- let gasCoin = null;
2187
- try {
2188
- transaction.setSenderIfNotSet(this.#signer.toSuiAddress());
2189
- await this.#buildQueue.runTask(async () => {
2190
- if (!transaction.getData().gasData.price) transaction.setGasPrice(await this.#getGasPrice());
2191
- transaction.setGasBudgetIfNotSet(this.#defaultGasBudget);
2192
- await this.#updateCache();
2193
- this.#pendingTransactions++;
2194
- if (this.#gasMode === "addressBalance") {
2195
- transaction.setGasPayment([]);
2196
- transaction.setExpiration(await this.#getValidDuringExpiration());
2197
- } else {
2198
- gasCoin = await this.#getGasCoin();
2199
- transaction.setGasPayment([{
2200
- objectId: gasCoin.id,
2201
- version: gasCoin.version,
2202
- digest: gasCoin.digest
2203
- }]);
2204
- }
2205
- await this.#cache.buildTransaction({
2206
- transaction,
2207
- onlyTransactionKind: true
2208
- });
2209
- });
2210
- const bytes = await transaction.build({ client: this.#client });
2211
- const { signature } = await this.#signer.signTransaction(bytes);
2212
- const results = await this.#cache.executeTransaction({
2213
- transaction: bytes,
2214
- signatures: [signature, ...additionalSignatures],
2215
- include
2216
- });
2217
- const tx = results.$kind === "Transaction" ? results.Transaction : results.FailedTransaction;
2218
- const effects = tx.effects;
2219
- const gasObject = effects.gasObject;
2220
- const gasUsed = effects.gasUsed;
2221
- if (gasCoin && gasUsed && gasObject) {
2222
- const coin = gasCoin;
2223
- if ((gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner) === this.#signer.toSuiAddress()) {
2224
- const totalUsed = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
2225
- const remainingBalance = coin.balance - totalUsed;
2226
- let usesGasCoin = false;
2227
- new TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {
2228
- if (arg.$kind === "GasCoin") usesGasCoin = true;
2229
- return arg;
2230
- });
2231
- const gasRef = {
2232
- objectId: gasObject.objectId,
2233
- version: gasObject.outputVersion,
2234
- digest: gasObject.outputDigest
2235
- };
2236
- if (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) this.#coinPool.push({
2237
- id: gasRef.objectId,
2238
- version: gasRef.version,
2239
- digest: gasRef.digest,
2240
- balance: remainingBalance
2241
- });
2242
- else {
2243
- if (!this.#sourceCoins) this.#sourceCoins = /* @__PURE__ */ new Map();
2244
- this.#sourceCoins.set(gasRef.objectId, gasRef);
2245
- }
2246
- }
2247
- }
2248
- this.#lastDigest = tx.digest;
2249
- return results;
2250
- } catch (error) {
2251
- if (gasCoin) {
2252
- if (!this.#sourceCoins) this.#sourceCoins = /* @__PURE__ */ new Map();
2253
- this.#sourceCoins.set(gasCoin.id, null);
2254
- }
2255
- await this.#updateCache(async () => {
2256
- await Promise.all([this.#cache.cache.deleteObjects([...usedObjects]), this.#waitForLastDigest()]);
2257
- });
2258
- throw error;
2259
- } finally {
2260
- usedObjects.forEach((objectId) => {
2261
- const queue = this.#objectIdQueues.get(objectId);
2262
- if (queue && queue.length > 0) queue.shift()();
2263
- else if (queue) this.#objectIdQueues.delete(objectId);
2264
- });
2265
- this.#pendingTransactions--;
2266
- }
2267
- }
2268
- /** Helper for synchronizing cache updates, by ensuring only one update happens at a time. This can also be used to wait for any pending cache updates */
2269
- async #updateCache(fn) {
2270
- if (this.#cacheLock) await this.#cacheLock;
2271
- this.#cacheLock = fn?.().then(() => {
2272
- this.#cacheLock = null;
2273
- }, () => {
2274
- }) ?? null;
2275
- }
2276
- async #waitForLastDigest() {
2277
- const digest = this.#lastDigest;
2278
- if (digest) {
2279
- this.#lastDigest = null;
2280
- await this.#client.core.waitForTransaction({ digest });
2281
- }
2282
- }
2283
- async #getGasCoin() {
2284
- if (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) await this.#refillCoinPool();
2285
- if (this.#coinPool.length === 0) throw new Error("No coins available");
2286
- return this.#coinPool.shift();
2287
- }
2288
- async #getGasPrice() {
2289
- await this.#ensureEpochInfo();
2290
- return this.#epochInfo.price;
2291
- }
2292
- async #getValidDuringExpiration() {
2293
- await this.#ensureEpochInfo();
2294
- const currentEpoch = BigInt(this.#epochInfo.epoch);
2295
- return { ValidDuring: {
2296
- minEpoch: String(currentEpoch),
2297
- maxEpoch: String(currentEpoch + 1n),
2298
- minTimestamp: null,
2299
- maxTimestamp: null,
2300
- chain: this.#epochInfo.chainIdentifier,
2301
- nonce: Math.random() * 4294967296 >>> 0
2302
- } };
2303
- }
2304
- async #ensureEpochInfo() {
2305
- if (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW2 - Date.now() > 0) return;
2306
- if (this.#epochInfoPromise) {
2307
- await this.#epochInfoPromise;
2308
- return;
2309
- }
2310
- this.#epochInfoPromise = this.#fetchEpochInfo();
2311
- try {
2312
- await this.#epochInfoPromise;
2313
- } finally {
2314
- this.#epochInfoPromise = null;
2315
- }
2316
- }
2317
- async #fetchEpochInfo() {
2318
- const [{ systemState }, { chainIdentifier }] = await Promise.all([this.#client.core.getCurrentSystemState(), this.#client.core.getChainIdentifier()]);
2319
- this.#epochInfo = {
2320
- epoch: systemState.epoch,
2321
- price: BigInt(systemState.referenceGasPrice),
2322
- expiration: Number(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),
2323
- chainIdentifier
2324
- };
2325
- }
2326
- async #refillCoinPool() {
2327
- const batchSize = Math.min(this.#coinBatchSize, this.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1);
2328
- if (batchSize === 0) return;
2329
- const txb = new Transaction();
2330
- const address = this.#signer.toSuiAddress();
2331
- txb.setSender(address);
2332
- if (this.#sourceCoins) {
2333
- const refs = [];
2334
- const ids = [];
2335
- for (const [id, ref] of this.#sourceCoins) if (ref) refs.push(ref);
2336
- else ids.push(id);
2337
- if (ids.length > 0) {
2338
- const { objects } = await this.#client.core.getObjects({ objectIds: ids });
2339
- refs.push(...objects.filter((obj) => !(obj instanceof Error)).map((obj) => ({
2340
- objectId: obj.objectId,
2341
- version: obj.version,
2342
- digest: obj.digest
2343
- })));
2344
- }
2345
- txb.setGasPayment(refs);
2346
- this.#sourceCoins = /* @__PURE__ */ new Map();
2347
- }
2348
- const amounts = new Array(batchSize).fill(this.#initialCoinBalance);
2349
- const splitResults = txb.splitCoins(txb.gas, amounts);
2350
- const coinResults = [];
2351
- for (let i = 0; i < amounts.length; i++) coinResults.push(splitResults[i]);
2352
- txb.transferObjects(coinResults, address);
2353
- await this.waitForLastTransaction();
2354
- txb.addBuildPlugin(coreClientResolveTransactionPlugin);
2355
- const bytes = await txb.build({ client: this.#client });
2356
- const { signature } = await this.#signer.signTransaction(bytes);
2357
- const result = await this.#client.core.executeTransaction({
2358
- transaction: bytes,
2359
- signatures: [signature],
2360
- include: { effects: true }
2361
- });
2362
- const tx = result.$kind === "Transaction" ? result.Transaction : result.FailedTransaction;
2363
- const effects = tx.effects;
2364
- effects.changedObjects.forEach((changedObj) => {
2365
- if (changedObj.objectId === effects.gasObject?.objectId || changedObj.outputState !== "ObjectWrite") return;
2366
- this.#coinPool.push({
2367
- id: changedObj.objectId,
2368
- version: changedObj.outputVersion,
2369
- digest: changedObj.outputDigest,
2370
- balance: BigInt(this.#initialCoinBalance)
2371
- });
2372
- });
2373
- if (!this.#sourceCoins) this.#sourceCoins = /* @__PURE__ */ new Map();
2374
- const gasObject = effects.gasObject;
2375
- this.#sourceCoins.set(gasObject.objectId, {
2376
- objectId: gasObject.objectId,
2377
- version: gasObject.outputVersion,
2378
- digest: gasObject.outputDigest
2379
- });
2380
- await this.#client.core.waitForTransaction({ digest: tx.digest });
2381
- }
2382
- };
2383
-
2384
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/Arguments.mjs
2385
- var Arguments = {
2386
- pure: createPure((value) => (tx) => tx.pure(value)),
2387
- object: createObjectMethods((value) => (tx) => tx.object(value)),
2388
- sharedObjectRef: (...args) => (tx) => tx.sharedObjectRef(...args),
2389
- objectRef: (...args) => (tx) => tx.objectRef(...args),
2390
- receivingRef: (...args) => (tx) => tx.receivingRef(...args)
2391
- };
2392
-
2393
1634
  export {
2394
- UpgradePolicy,
2395
- TransactionCommands,
2396
- Inputs,
2397
- getPureBcsSchema,
2398
- normalizedTypeToMoveTypeSignature,
2399
1635
  coinWithBalance,
2400
- isTransaction,
2401
- Transaction,
2402
- AsyncCache,
2403
- ObjectCache,
2404
- SerialTransactionExecutor,
2405
- ParallelTransactionExecutor,
2406
- Arguments
1636
+ Transaction
2407
1637
  };
2408
- //# sourceMappingURL=chunk-ITIKLNK5.js.map
1638
+ //# sourceMappingURL=chunk-TP3M7BAU.js.map