@t2000/mcp 5.6.0 → 5.6.1

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/bin.js CHANGED
@@ -14750,9 +14750,6 @@ function getIdFromCallArg(arg) {
14750
14750
  }
14751
14751
  if (arg.UnresolvedObject) return normalizeSuiAddress(arg.UnresolvedObject.objectId);
14752
14752
  }
14753
- function isArgument(value) {
14754
- return is(ArgumentSchema, value);
14755
- }
14756
14753
  function remapCommandArguments(command, inputMapping, commandMapping) {
14757
14754
  const remapArg = (arg) => {
14758
14755
  switch (arg.$kind) {
@@ -14817,8 +14814,6 @@ function remapCommandArguments(command, inputMapping, commandMapping) {
14817
14814
  var init_utils4 = __esm({
14818
14815
  "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/utils.mjs"() {
14819
14816
  init_sui_types();
14820
- init_internal();
14821
- init_dist3();
14822
14817
  }
14823
14818
  });
14824
14819
 
@@ -15389,19 +15384,13 @@ var init_TransactionData = __esm({
15389
15384
  });
15390
15385
 
15391
15386
  // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/Commands.mjs
15392
- var UpgradePolicy, TransactionCommands;
15387
+ var TransactionCommands;
15393
15388
  var init_Commands = __esm({
15394
15389
  "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/Commands.mjs"() {
15395
15390
  init_sui_types();
15396
15391
  init_internal();
15397
15392
  init_dist2();
15398
15393
  init_dist3();
15399
- UpgradePolicy = /* @__PURE__ */ (function(UpgradePolicy$1) {
15400
- UpgradePolicy$1[UpgradePolicy$1["COMPATIBLE"] = 0] = "COMPATIBLE";
15401
- UpgradePolicy$1[UpgradePolicy$1["ADDITIVE"] = 128] = "ADDITIVE";
15402
- UpgradePolicy$1[UpgradePolicy$1["DEP_ONLY"] = 192] = "DEP_ONLY";
15403
- return UpgradePolicy$1;
15404
- })({});
15405
15394
  TransactionCommands = {
15406
15395
  MoveCall(input) {
15407
15396
  const [pkg, mod3 = "", fn = ""] = "target" in input ? input.target.split("::") : [
@@ -15619,58 +15608,6 @@ function getPureBcsSchema(typeSignature) {
15619
15608
  return null;
15620
15609
  }
15621
15610
  }
15622
- function normalizedTypeToMoveTypeSignature(type) {
15623
- if (typeof type === "object" && "Reference" in type) return {
15624
- reference: "immutable",
15625
- body: normalizedTypeToMoveTypeSignatureBody(type.Reference)
15626
- };
15627
- if (typeof type === "object" && "MutableReference" in type) return {
15628
- reference: "mutable",
15629
- body: normalizedTypeToMoveTypeSignatureBody(type.MutableReference)
15630
- };
15631
- return {
15632
- reference: null,
15633
- body: normalizedTypeToMoveTypeSignatureBody(type)
15634
- };
15635
- }
15636
- function normalizedTypeToMoveTypeSignatureBody(type) {
15637
- if (typeof type === "string") switch (type) {
15638
- case "Address":
15639
- return { $kind: "address" };
15640
- case "Bool":
15641
- return { $kind: "bool" };
15642
- case "U8":
15643
- return { $kind: "u8" };
15644
- case "U16":
15645
- return { $kind: "u16" };
15646
- case "U32":
15647
- return { $kind: "u32" };
15648
- case "U64":
15649
- return { $kind: "u64" };
15650
- case "U128":
15651
- return { $kind: "u128" };
15652
- case "U256":
15653
- return { $kind: "u256" };
15654
- default:
15655
- throw new Error(`Unexpected type ${type}`);
15656
- }
15657
- if ("Vector" in type) return {
15658
- $kind: "vector",
15659
- vector: normalizedTypeToMoveTypeSignatureBody(type.Vector)
15660
- };
15661
- if ("Struct" in type) return {
15662
- $kind: "datatype",
15663
- datatype: {
15664
- typeName: `${type.Struct.address}::${type.Struct.module}::${type.Struct.name}`,
15665
- typeParameters: type.Struct.typeArguments.map(normalizedTypeToMoveTypeSignatureBody)
15666
- }
15667
- };
15668
- if ("TypeParameter" in type) return {
15669
- $kind: "typeParameter",
15670
- index: type.TypeParameter
15671
- };
15672
- throw new Error(`Unexpected type ${JSON.stringify(type)}`);
15673
- }
15674
15611
  var init_serializer = __esm({
15675
15612
  "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/serializer.mjs"() {
15676
15613
  init_sui_types();
@@ -16208,24 +16145,6 @@ var init_chunk = __esm({
16208
16145
  }
16209
16146
  });
16210
16147
 
16211
- // ../../node_modules/.pnpm/@mysten+utils@0.3.3/node_modules/@mysten/utils/dist/with-resolver.mjs
16212
- function promiseWithResolvers() {
16213
- let resolver;
16214
- let rejecter;
16215
- return {
16216
- promise: new Promise((resolve2, reject) => {
16217
- resolver = resolve2;
16218
- rejecter = reject;
16219
- }),
16220
- resolve: resolver,
16221
- reject: rejecter
16222
- };
16223
- }
16224
- var init_with_resolver = __esm({
16225
- "../../node_modules/.pnpm/@mysten+utils@0.3.3/node_modules/@mysten/utils/dist/with-resolver.mjs"() {
16226
- }
16227
- });
16228
-
16229
16148
  // ../../node_modules/.pnpm/@mysten+utils@0.3.3/node_modules/@mysten/utils/dist/dataloader.mjs
16230
16149
  function getCurrentBatch(loader) {
16231
16150
  const existingBatch = loader._batch;
@@ -16457,7 +16376,6 @@ var init_dist4 = __esm({
16457
16376
  "../../node_modules/.pnpm/@mysten+utils@0.3.3/node_modules/@mysten/utils/dist/index.mjs"() {
16458
16377
  init_b642();
16459
16378
  init_chunk();
16460
- init_with_resolver();
16461
16379
  init_dataloader();
16462
16380
  }
16463
16381
  });
@@ -17688,784 +17606,11 @@ var init_Transaction = __esm({
17688
17606
  }
17689
17607
  });
17690
17608
 
17691
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/ObjectCache.mjs
17692
- var AsyncCache, InMemoryCache, ObjectCache;
17693
- var init_ObjectCache = __esm({
17694
- "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/ObjectCache.mjs"() {
17695
- init_sui_types();
17696
- AsyncCache = class {
17697
- async getObject(id) {
17698
- const [owned, shared] = await Promise.all([this.get("OwnedObject", id), this.get("SharedOrImmutableObject", id)]);
17699
- return owned ?? shared ?? null;
17700
- }
17701
- async getObjects(ids) {
17702
- return Promise.all(ids.map((id) => this.getObject(id)));
17703
- }
17704
- async addObject(object4) {
17705
- if (object4.owner) await this.set("OwnedObject", object4.objectId, object4);
17706
- else await this.set("SharedOrImmutableObject", object4.objectId, object4);
17707
- return object4;
17708
- }
17709
- async addObjects(objects) {
17710
- await Promise.all(objects.map(async (object4) => this.addObject(object4)));
17711
- }
17712
- async deleteObject(id) {
17713
- await Promise.all([this.delete("OwnedObject", id), this.delete("SharedOrImmutableObject", id)]);
17714
- }
17715
- async deleteObjects(ids) {
17716
- await Promise.all(ids.map((id) => this.deleteObject(id)));
17717
- }
17718
- async getMoveFunctionDefinition(ref) {
17719
- const functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;
17720
- return this.get("MoveFunction", functionName);
17721
- }
17722
- async addMoveFunctionDefinition(functionEntry) {
17723
- const pkg = normalizeSuiAddress(functionEntry.package);
17724
- const functionName = `${pkg}::${functionEntry.module}::${functionEntry.function}`;
17725
- const entry = {
17726
- ...functionEntry,
17727
- package: pkg
17728
- };
17729
- await this.set("MoveFunction", functionName, entry);
17730
- return entry;
17731
- }
17732
- async deleteMoveFunctionDefinition(ref) {
17733
- const functionName = `${normalizeSuiAddress(ref.package)}::${ref.module}::${ref.function}`;
17734
- await this.delete("MoveFunction", functionName);
17735
- }
17736
- async getCustom(key) {
17737
- return this.get("Custom", key);
17738
- }
17739
- async setCustom(key, value) {
17740
- return this.set("Custom", key, value);
17741
- }
17742
- async deleteCustom(key) {
17743
- return this.delete("Custom", key);
17744
- }
17745
- };
17746
- InMemoryCache = class extends AsyncCache {
17747
- #caches = {
17748
- OwnedObject: /* @__PURE__ */ new Map(),
17749
- SharedOrImmutableObject: /* @__PURE__ */ new Map(),
17750
- MoveFunction: /* @__PURE__ */ new Map(),
17751
- Custom: /* @__PURE__ */ new Map()
17752
- };
17753
- async get(type, key) {
17754
- return this.#caches[type].get(key) ?? null;
17755
- }
17756
- async set(type, key, value) {
17757
- this.#caches[type].set(key, value);
17758
- }
17759
- async delete(type, key) {
17760
- this.#caches[type].delete(key);
17761
- }
17762
- async clear(type) {
17763
- if (type) this.#caches[type].clear();
17764
- else for (const cache of Object.values(this.#caches)) cache.clear();
17765
- }
17766
- };
17767
- ObjectCache = class {
17768
- #cache;
17769
- #onEffects;
17770
- constructor({ cache = new InMemoryCache(), onEffects }) {
17771
- this.#cache = cache;
17772
- this.#onEffects = onEffects;
17773
- }
17774
- asPlugin() {
17775
- return async (transactionData, _options, next) => {
17776
- const unresolvedObjects = transactionData.inputs.filter((input) => input.UnresolvedObject).map((input) => input.UnresolvedObject.objectId);
17777
- const cached2 = (await this.#cache.getObjects(unresolvedObjects)).filter((obj) => obj !== null);
17778
- const byId = new Map(cached2.map((obj) => [obj.objectId, obj]));
17779
- for (const input of transactionData.inputs) {
17780
- if (!input.UnresolvedObject) continue;
17781
- const cached$1 = byId.get(input.UnresolvedObject.objectId);
17782
- if (!cached$1) continue;
17783
- if (cached$1.initialSharedVersion && !input.UnresolvedObject.initialSharedVersion) input.UnresolvedObject.initialSharedVersion = cached$1.initialSharedVersion;
17784
- else {
17785
- if (cached$1.version && !input.UnresolvedObject.version) input.UnresolvedObject.version = cached$1.version;
17786
- if (cached$1.digest && !input.UnresolvedObject.digest) input.UnresolvedObject.digest = cached$1.digest;
17787
- }
17788
- }
17789
- await Promise.all(transactionData.commands.map(async (commands) => {
17790
- if (commands.MoveCall) {
17791
- const def = await this.getMoveFunctionDefinition({
17792
- package: commands.MoveCall.package,
17793
- module: commands.MoveCall.module,
17794
- function: commands.MoveCall.function
17795
- });
17796
- if (def) commands.MoveCall._argumentTypes = def.parameters;
17797
- }
17798
- }));
17799
- await next();
17800
- await Promise.all(transactionData.commands.map(async (commands) => {
17801
- if (commands.MoveCall?._argumentTypes) await this.#cache.addMoveFunctionDefinition({
17802
- package: commands.MoveCall.package,
17803
- module: commands.MoveCall.module,
17804
- function: commands.MoveCall.function,
17805
- parameters: commands.MoveCall._argumentTypes
17806
- });
17807
- }));
17808
- };
17809
- }
17810
- async clear() {
17811
- await this.#cache.clear();
17812
- }
17813
- async getMoveFunctionDefinition(ref) {
17814
- return this.#cache.getMoveFunctionDefinition(ref);
17815
- }
17816
- async getObjects(ids) {
17817
- return this.#cache.getObjects(ids);
17818
- }
17819
- async deleteObjects(ids) {
17820
- return this.#cache.deleteObjects(ids);
17821
- }
17822
- async clearOwnedObjects() {
17823
- await this.#cache.clear("OwnedObject");
17824
- }
17825
- async clearCustom() {
17826
- await this.#cache.clear("Custom");
17827
- }
17828
- async getCustom(key) {
17829
- return this.#cache.getCustom(key);
17830
- }
17831
- async setCustom(key, value) {
17832
- return this.#cache.setCustom(key, value);
17833
- }
17834
- async deleteCustom(key) {
17835
- return this.#cache.deleteCustom(key);
17836
- }
17837
- async applyEffects(effects) {
17838
- if (!effects.V2) throw new Error(`Unsupported transaction effects version ${effects.$kind}`);
17839
- const { lamportVersion, changedObjects } = effects.V2;
17840
- const deletedIds = [];
17841
- const addedObjects = [];
17842
- changedObjects.forEach(([id, change]) => {
17843
- if (change.outputState.NotExist) deletedIds.push(id);
17844
- else if (change.outputState.ObjectWrite) {
17845
- const [digest, owner] = change.outputState.ObjectWrite;
17846
- addedObjects.push({
17847
- objectId: id,
17848
- digest,
17849
- version: lamportVersion,
17850
- owner: owner.AddressOwner ?? owner.ObjectOwner ?? null,
17851
- initialSharedVersion: owner.Shared?.initialSharedVersion ?? null
17852
- });
17853
- }
17854
- });
17855
- await Promise.all([
17856
- this.#cache.addObjects(addedObjects),
17857
- this.#cache.deleteObjects(deletedIds),
17858
- this.#onEffects?.(effects)
17859
- ]);
17860
- }
17861
- };
17862
- }
17863
- });
17864
-
17865
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/caching.mjs
17866
- var CachingTransactionExecutor;
17867
- var init_caching = __esm({
17868
- "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/caching.mjs"() {
17869
- init_bcs3();
17870
- init_core_resolver();
17871
- init_Transaction();
17872
- init_ObjectCache();
17873
- CachingTransactionExecutor = class {
17874
- #client;
17875
- #lastDigest = null;
17876
- constructor({ client, ...options }) {
17877
- this.#client = client;
17878
- this.cache = new ObjectCache(options);
17879
- }
17880
- /**
17881
- * Clears all Owned objects
17882
- * Immutable objects, Shared objects, and Move function definitions will be preserved
17883
- */
17884
- async reset() {
17885
- await Promise.all([
17886
- this.cache.clearOwnedObjects(),
17887
- this.cache.clearCustom(),
17888
- this.waitForLastTransaction()
17889
- ]);
17890
- }
17891
- async buildTransaction({ transaction, ...options }) {
17892
- transaction.addBuildPlugin(this.cache.asPlugin());
17893
- transaction.addBuildPlugin(coreClientResolveTransactionPlugin);
17894
- return transaction.build({
17895
- client: this.#client,
17896
- ...options
17897
- });
17898
- }
17899
- async executeTransaction({ transaction, signatures, include }) {
17900
- const bytes = isTransaction(transaction) ? await this.buildTransaction({ transaction }) : transaction;
17901
- const results = await this.#client.core.executeTransaction({
17902
- transaction: bytes,
17903
- signatures,
17904
- include: {
17905
- ...include,
17906
- effects: true
17907
- }
17908
- });
17909
- const tx = results.$kind === "Transaction" ? results.Transaction : results.FailedTransaction;
17910
- if (tx.effects?.bcs) {
17911
- const effects = suiBcs.TransactionEffects.parse(tx.effects.bcs);
17912
- await this.applyEffects(effects);
17913
- }
17914
- return results;
17915
- }
17916
- async signAndExecuteTransaction({ include, transaction, signer }) {
17917
- transaction.setSenderIfNotSet(signer.toSuiAddress());
17918
- const bytes = await this.buildTransaction({ transaction });
17919
- const { signature } = await signer.signTransaction(bytes);
17920
- return this.executeTransaction({
17921
- transaction: bytes,
17922
- signatures: [signature],
17923
- include
17924
- });
17925
- }
17926
- async applyEffects(effects) {
17927
- this.#lastDigest = effects.V2?.transactionDigest ?? null;
17928
- await this.cache.applyEffects(effects);
17929
- }
17930
- async waitForLastTransaction() {
17931
- if (this.#lastDigest) {
17932
- await this.#client.core.waitForTransaction({ digest: this.#lastDigest });
17933
- this.#lastDigest = null;
17934
- }
17935
- }
17936
- };
17937
- }
17938
- });
17939
-
17940
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/queue.mjs
17941
- var SerialQueue, ParallelQueue;
17942
- var init_queue = __esm({
17943
- "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/queue.mjs"() {
17944
- SerialQueue = class {
17945
- #queue = [];
17946
- async runTask(task) {
17947
- return new Promise((resolve2, reject) => {
17948
- this.#queue.push(() => {
17949
- task().finally(() => {
17950
- this.#queue.shift();
17951
- if (this.#queue.length > 0) this.#queue[0]();
17952
- }).then(resolve2, reject);
17953
- });
17954
- if (this.#queue.length === 1) this.#queue[0]();
17955
- });
17956
- }
17957
- };
17958
- ParallelQueue = class {
17959
- #queue = [];
17960
- constructor(maxTasks) {
17961
- this.activeTasks = 0;
17962
- this.maxTasks = maxTasks;
17963
- }
17964
- runTask(task) {
17965
- return new Promise((resolve2, reject) => {
17966
- if (this.activeTasks < this.maxTasks) {
17967
- this.activeTasks++;
17968
- task().finally(() => {
17969
- if (this.#queue.length > 0) this.#queue.shift()();
17970
- else this.activeTasks--;
17971
- }).then(resolve2, reject);
17972
- } else this.#queue.push(() => {
17973
- task().finally(() => {
17974
- if (this.#queue.length > 0) this.#queue.shift()();
17975
- else this.activeTasks--;
17976
- }).then(resolve2, reject);
17977
- });
17978
- });
17979
- }
17980
- };
17981
- }
17982
- });
17983
-
17984
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/serial.mjs
17985
- function getGasCoinFromEffects(effects) {
17986
- if (!effects.V2) throw new Error("Unexpected effects version");
17987
- const gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex];
17988
- if (!gasObjectChange) throw new Error("Gas object not found in effects");
17989
- const [objectId, { outputState }] = gasObjectChange;
17990
- if (!outputState.ObjectWrite) throw new Error("Unexpected gas object state");
17991
- const [digest, owner] = outputState.ObjectWrite;
17992
- return {
17993
- ref: {
17994
- objectId,
17995
- digest,
17996
- version: effects.V2.lamportVersion
17997
- },
17998
- owner: owner.AddressOwner || owner.ObjectOwner
17999
- };
18000
- }
18001
- var EPOCH_BOUNDARY_WINDOW, SerialTransactionExecutor;
18002
- var init_serial = __esm({
18003
- "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/serial.mjs"() {
18004
- init_Transaction();
18005
- init_caching();
18006
- init_queue();
18007
- EPOCH_BOUNDARY_WINDOW = 6e4;
18008
- SerialTransactionExecutor = class {
18009
- #queue = new SerialQueue();
18010
- #signer;
18011
- #client;
18012
- #cache;
18013
- #defaultGasBudget;
18014
- #gasMode;
18015
- #epochInfo = null;
18016
- #epochInfoPromise = null;
18017
- constructor(options) {
18018
- const { signer, defaultGasBudget = 50000000n, client, cache } = options;
18019
- this.#signer = signer;
18020
- this.#client = client;
18021
- this.#defaultGasBudget = defaultGasBudget;
18022
- this.#gasMode = options.gasMode ?? "coins";
18023
- this.#cache = new CachingTransactionExecutor({
18024
- client,
18025
- cache,
18026
- onEffects: (effects) => this.#cacheGasCoin(effects)
18027
- });
18028
- }
18029
- async applyEffects(effects) {
18030
- return this.#cache.applyEffects(effects);
18031
- }
18032
- #cacheGasCoin = async (effects) => {
18033
- if (this.#gasMode === "addressBalance" || !effects.V2) return;
18034
- const gasCoin = getGasCoinFromEffects(effects).ref;
18035
- if (gasCoin) this.#cache.cache.setCustom("gasCoin", gasCoin);
18036
- else this.#cache.cache.deleteCustom("gasCoin");
18037
- };
18038
- async buildTransaction(transaction) {
18039
- return this.#queue.runTask(() => this.#buildTransaction(transaction));
18040
- }
18041
- #buildTransaction = async (transaction) => {
18042
- await transaction.prepareForSerialization({
18043
- client: this.#client,
18044
- supportedIntents: ["CoinWithBalance"]
18045
- });
18046
- const copy2 = Transaction.from(transaction);
18047
- if (this.#gasMode === "addressBalance") {
18048
- copy2.setGasPayment([]);
18049
- copy2.setExpiration(await this.#getValidDuringExpiration());
18050
- } else {
18051
- const gasCoin = await this.#cache.cache.getCustom("gasCoin");
18052
- if (gasCoin) copy2.setGasPayment([gasCoin]);
18053
- }
18054
- copy2.setGasBudgetIfNotSet(this.#defaultGasBudget);
18055
- copy2.setSenderIfNotSet(this.#signer.toSuiAddress());
18056
- return this.#cache.buildTransaction({ transaction: copy2 });
18057
- };
18058
- async #getValidDuringExpiration() {
18059
- await this.#ensureEpochInfo();
18060
- const currentEpoch = BigInt(this.#epochInfo.epoch);
18061
- return { ValidDuring: {
18062
- minEpoch: String(currentEpoch),
18063
- maxEpoch: String(currentEpoch + 1n),
18064
- minTimestamp: null,
18065
- maxTimestamp: null,
18066
- chain: this.#epochInfo.chainIdentifier,
18067
- nonce: Math.random() * 4294967296 >>> 0
18068
- } };
18069
- }
18070
- async #ensureEpochInfo() {
18071
- if (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) return;
18072
- if (this.#epochInfoPromise) {
18073
- await this.#epochInfoPromise;
18074
- return;
18075
- }
18076
- this.#epochInfoPromise = this.#fetchEpochInfo();
18077
- try {
18078
- await this.#epochInfoPromise;
18079
- } finally {
18080
- this.#epochInfoPromise = null;
18081
- }
18082
- }
18083
- async #fetchEpochInfo() {
18084
- const [{ systemState }, { chainIdentifier }] = await Promise.all([this.#client.core.getCurrentSystemState(), this.#client.core.getChainIdentifier()]);
18085
- this.#epochInfo = {
18086
- epoch: systemState.epoch,
18087
- expiration: Number(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),
18088
- chainIdentifier
18089
- };
18090
- }
18091
- resetCache() {
18092
- return this.#cache.reset();
18093
- }
18094
- waitForLastTransaction() {
18095
- return this.#cache.waitForLastTransaction();
18096
- }
18097
- executeTransaction(transaction, include, additionalSignatures = []) {
18098
- return this.#queue.runTask(async () => {
18099
- const bytes = isTransaction(transaction) ? await this.#buildTransaction(transaction) : transaction;
18100
- const { signature } = await this.#signer.signTransaction(bytes);
18101
- return this.#cache.executeTransaction({
18102
- signatures: [signature, ...additionalSignatures],
18103
- transaction: bytes,
18104
- include
18105
- }).catch(async (error2) => {
18106
- await this.resetCache();
18107
- throw error2;
18108
- });
18109
- });
18110
- }
18111
- };
18112
- }
18113
- });
18114
-
18115
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/parallel.mjs
18116
- var PARALLEL_EXECUTOR_DEFAULTS, EPOCH_BOUNDARY_WINDOW2, ParallelTransactionExecutor;
18117
- var init_parallel = __esm({
18118
- "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/executor/parallel.mjs"() {
18119
- init_TransactionData();
18120
- init_core_resolver();
18121
- init_Transaction();
18122
- init_caching();
18123
- init_queue();
18124
- init_dist4();
18125
- PARALLEL_EXECUTOR_DEFAULTS = {
18126
- coinBatchSize: 20,
18127
- initialCoinBalance: 200000000n,
18128
- minimumCoinBalance: 50000000n,
18129
- maxPoolSize: 50
18130
- };
18131
- EPOCH_BOUNDARY_WINDOW2 = 6e4;
18132
- ParallelTransactionExecutor = class {
18133
- #signer;
18134
- #client;
18135
- #gasMode;
18136
- #coinBatchSize;
18137
- #initialCoinBalance;
18138
- #minimumCoinBalance;
18139
- #defaultGasBudget;
18140
- #maxPoolSize;
18141
- #sourceCoins;
18142
- #coinPool = [];
18143
- #cache;
18144
- #objectIdQueues = /* @__PURE__ */ new Map();
18145
- #buildQueue = new SerialQueue();
18146
- #executeQueue;
18147
- #lastDigest = null;
18148
- #cacheLock = null;
18149
- #pendingTransactions = 0;
18150
- #epochInfo = null;
18151
- #epochInfoPromise = null;
18152
- constructor(options) {
18153
- this.#signer = options.signer;
18154
- this.#client = options.client;
18155
- this.#gasMode = options.gasMode ?? "coins";
18156
- if (this.#gasMode === "coins") {
18157
- const coinOptions = options;
18158
- this.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;
18159
- this.#initialCoinBalance = coinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;
18160
- this.#minimumCoinBalance = coinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;
18161
- this.#sourceCoins = coinOptions.sourceCoins ? new Map(coinOptions.sourceCoins.map((id) => [id, null])) : null;
18162
- } else {
18163
- this.#coinBatchSize = 0;
18164
- this.#initialCoinBalance = 0n;
18165
- this.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;
18166
- this.#sourceCoins = null;
18167
- }
18168
- this.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;
18169
- this.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;
18170
- this.#cache = new CachingTransactionExecutor({
18171
- client: options.client,
18172
- cache: options.cache
18173
- });
18174
- this.#executeQueue = new ParallelQueue(this.#maxPoolSize);
18175
- }
18176
- resetCache() {
18177
- this.#epochInfo = null;
18178
- return this.#updateCache(() => this.#cache.reset());
18179
- }
18180
- async waitForLastTransaction() {
18181
- await this.#updateCache(() => this.#waitForLastDigest());
18182
- }
18183
- async executeTransaction(transaction, include, additionalSignatures = []) {
18184
- const { promise, resolve: resolve2, reject } = promiseWithResolvers();
18185
- const usedObjects = await this.#getUsedObjects(transaction);
18186
- const execute = () => {
18187
- this.#executeQueue.runTask(() => {
18188
- return this.#execute(transaction, usedObjects, include, additionalSignatures).then(resolve2, reject);
18189
- });
18190
- };
18191
- const conflicts = /* @__PURE__ */ new Set();
18192
- usedObjects.forEach((objectId) => {
18193
- if (this.#objectIdQueues.get(objectId)) {
18194
- conflicts.add(objectId);
18195
- this.#objectIdQueues.get(objectId).push(() => {
18196
- conflicts.delete(objectId);
18197
- if (conflicts.size === 0) execute();
18198
- });
18199
- } else this.#objectIdQueues.set(objectId, []);
18200
- });
18201
- if (conflicts.size === 0) execute();
18202
- return promise;
18203
- }
18204
- async #getUsedObjects(transaction) {
18205
- const usedObjects = /* @__PURE__ */ new Set();
18206
- let serialized = false;
18207
- transaction.addSerializationPlugin(async (blockData, _options, next) => {
18208
- await next();
18209
- if (serialized) return;
18210
- serialized = true;
18211
- blockData.inputs.forEach((input) => {
18212
- if (input.Object?.ImmOrOwnedObject?.objectId) usedObjects.add(input.Object.ImmOrOwnedObject.objectId);
18213
- else if (input.Object?.Receiving?.objectId) usedObjects.add(input.Object.Receiving.objectId);
18214
- else if (input.UnresolvedObject?.objectId && !input.UnresolvedObject.initialSharedVersion) usedObjects.add(input.UnresolvedObject.objectId);
18215
- });
18216
- });
18217
- await transaction.prepareForSerialization({ client: this.#client });
18218
- return usedObjects;
18219
- }
18220
- async #execute(transaction, usedObjects, include, additionalSignatures = []) {
18221
- let gasCoin = null;
18222
- try {
18223
- transaction.setSenderIfNotSet(this.#signer.toSuiAddress());
18224
- await this.#buildQueue.runTask(async () => {
18225
- if (!transaction.getData().gasData.price) transaction.setGasPrice(await this.#getGasPrice());
18226
- transaction.setGasBudgetIfNotSet(this.#defaultGasBudget);
18227
- await this.#updateCache();
18228
- this.#pendingTransactions++;
18229
- if (this.#gasMode === "addressBalance") {
18230
- transaction.setGasPayment([]);
18231
- transaction.setExpiration(await this.#getValidDuringExpiration());
18232
- } else {
18233
- gasCoin = await this.#getGasCoin();
18234
- transaction.setGasPayment([{
18235
- objectId: gasCoin.id,
18236
- version: gasCoin.version,
18237
- digest: gasCoin.digest
18238
- }]);
18239
- }
18240
- await this.#cache.buildTransaction({
18241
- transaction,
18242
- onlyTransactionKind: true
18243
- });
18244
- });
18245
- const bytes = await transaction.build({ client: this.#client });
18246
- const { signature } = await this.#signer.signTransaction(bytes);
18247
- const results = await this.#cache.executeTransaction({
18248
- transaction: bytes,
18249
- signatures: [signature, ...additionalSignatures],
18250
- include
18251
- });
18252
- const tx = results.$kind === "Transaction" ? results.Transaction : results.FailedTransaction;
18253
- const effects = tx.effects;
18254
- const gasObject = effects.gasObject;
18255
- const gasUsed = effects.gasUsed;
18256
- if (gasCoin && gasUsed && gasObject) {
18257
- const coin = gasCoin;
18258
- if ((gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner) === this.#signer.toSuiAddress()) {
18259
- const totalUsed = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
18260
- const remainingBalance = coin.balance - totalUsed;
18261
- let usesGasCoin = false;
18262
- new TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {
18263
- if (arg.$kind === "GasCoin") usesGasCoin = true;
18264
- return arg;
18265
- });
18266
- const gasRef = {
18267
- objectId: gasObject.objectId,
18268
- version: gasObject.outputVersion,
18269
- digest: gasObject.outputDigest
18270
- };
18271
- if (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) this.#coinPool.push({
18272
- id: gasRef.objectId,
18273
- version: gasRef.version,
18274
- digest: gasRef.digest,
18275
- balance: remainingBalance
18276
- });
18277
- else {
18278
- if (!this.#sourceCoins) this.#sourceCoins = /* @__PURE__ */ new Map();
18279
- this.#sourceCoins.set(gasRef.objectId, gasRef);
18280
- }
18281
- }
18282
- }
18283
- this.#lastDigest = tx.digest;
18284
- return results;
18285
- } catch (error2) {
18286
- if (gasCoin) {
18287
- if (!this.#sourceCoins) this.#sourceCoins = /* @__PURE__ */ new Map();
18288
- this.#sourceCoins.set(gasCoin.id, null);
18289
- }
18290
- await this.#updateCache(async () => {
18291
- await Promise.all([this.#cache.cache.deleteObjects([...usedObjects]), this.#waitForLastDigest()]);
18292
- });
18293
- throw error2;
18294
- } finally {
18295
- usedObjects.forEach((objectId) => {
18296
- const queue = this.#objectIdQueues.get(objectId);
18297
- if (queue && queue.length > 0) queue.shift()();
18298
- else if (queue) this.#objectIdQueues.delete(objectId);
18299
- });
18300
- this.#pendingTransactions--;
18301
- }
18302
- }
18303
- /** 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 */
18304
- async #updateCache(fn) {
18305
- if (this.#cacheLock) await this.#cacheLock;
18306
- this.#cacheLock = fn?.().then(() => {
18307
- this.#cacheLock = null;
18308
- }, () => {
18309
- }) ?? null;
18310
- }
18311
- async #waitForLastDigest() {
18312
- const digest = this.#lastDigest;
18313
- if (digest) {
18314
- this.#lastDigest = null;
18315
- await this.#client.core.waitForTransaction({ digest });
18316
- }
18317
- }
18318
- async #getGasCoin() {
18319
- if (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) await this.#refillCoinPool();
18320
- if (this.#coinPool.length === 0) throw new Error("No coins available");
18321
- return this.#coinPool.shift();
18322
- }
18323
- async #getGasPrice() {
18324
- await this.#ensureEpochInfo();
18325
- return this.#epochInfo.price;
18326
- }
18327
- async #getValidDuringExpiration() {
18328
- await this.#ensureEpochInfo();
18329
- const currentEpoch = BigInt(this.#epochInfo.epoch);
18330
- return { ValidDuring: {
18331
- minEpoch: String(currentEpoch),
18332
- maxEpoch: String(currentEpoch + 1n),
18333
- minTimestamp: null,
18334
- maxTimestamp: null,
18335
- chain: this.#epochInfo.chainIdentifier,
18336
- nonce: Math.random() * 4294967296 >>> 0
18337
- } };
18338
- }
18339
- async #ensureEpochInfo() {
18340
- if (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW2 - Date.now() > 0) return;
18341
- if (this.#epochInfoPromise) {
18342
- await this.#epochInfoPromise;
18343
- return;
18344
- }
18345
- this.#epochInfoPromise = this.#fetchEpochInfo();
18346
- try {
18347
- await this.#epochInfoPromise;
18348
- } finally {
18349
- this.#epochInfoPromise = null;
18350
- }
18351
- }
18352
- async #fetchEpochInfo() {
18353
- const [{ systemState }, { chainIdentifier }] = await Promise.all([this.#client.core.getCurrentSystemState(), this.#client.core.getChainIdentifier()]);
18354
- this.#epochInfo = {
18355
- epoch: systemState.epoch,
18356
- price: BigInt(systemState.referenceGasPrice),
18357
- expiration: Number(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),
18358
- chainIdentifier
18359
- };
18360
- }
18361
- async #refillCoinPool() {
18362
- const batchSize = Math.min(this.#coinBatchSize, this.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1);
18363
- if (batchSize === 0) return;
18364
- const txb = new Transaction();
18365
- const address = this.#signer.toSuiAddress();
18366
- txb.setSender(address);
18367
- if (this.#sourceCoins) {
18368
- const refs = [];
18369
- const ids = [];
18370
- for (const [id, ref] of this.#sourceCoins) if (ref) refs.push(ref);
18371
- else ids.push(id);
18372
- if (ids.length > 0) {
18373
- const { objects } = await this.#client.core.getObjects({ objectIds: ids });
18374
- refs.push(...objects.filter((obj) => !(obj instanceof Error)).map((obj) => ({
18375
- objectId: obj.objectId,
18376
- version: obj.version,
18377
- digest: obj.digest
18378
- })));
18379
- }
18380
- txb.setGasPayment(refs);
18381
- this.#sourceCoins = /* @__PURE__ */ new Map();
18382
- }
18383
- const amounts = new Array(batchSize).fill(this.#initialCoinBalance);
18384
- const splitResults = txb.splitCoins(txb.gas, amounts);
18385
- const coinResults = [];
18386
- for (let i = 0; i < amounts.length; i++) coinResults.push(splitResults[i]);
18387
- txb.transferObjects(coinResults, address);
18388
- await this.waitForLastTransaction();
18389
- txb.addBuildPlugin(coreClientResolveTransactionPlugin);
18390
- const bytes = await txb.build({ client: this.#client });
18391
- const { signature } = await this.#signer.signTransaction(bytes);
18392
- const result = await this.#client.core.executeTransaction({
18393
- transaction: bytes,
18394
- signatures: [signature],
18395
- include: { effects: true }
18396
- });
18397
- const tx = result.$kind === "Transaction" ? result.Transaction : result.FailedTransaction;
18398
- const effects = tx.effects;
18399
- effects.changedObjects.forEach((changedObj) => {
18400
- if (changedObj.objectId === effects.gasObject?.objectId || changedObj.outputState !== "ObjectWrite") return;
18401
- this.#coinPool.push({
18402
- id: changedObj.objectId,
18403
- version: changedObj.outputVersion,
18404
- digest: changedObj.outputDigest,
18405
- balance: BigInt(this.#initialCoinBalance)
18406
- });
18407
- });
18408
- if (!this.#sourceCoins) this.#sourceCoins = /* @__PURE__ */ new Map();
18409
- const gasObject = effects.gasObject;
18410
- this.#sourceCoins.set(gasObject.objectId, {
18411
- objectId: gasObject.objectId,
18412
- version: gasObject.outputVersion,
18413
- digest: gasObject.outputDigest
18414
- });
18415
- await this.#client.core.waitForTransaction({ digest: tx.digest });
18416
- }
18417
- };
18418
- }
18419
- });
18420
-
18421
- // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/Arguments.mjs
18422
- var Arguments;
18423
- var init_Arguments = __esm({
18424
- "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/Arguments.mjs"() {
18425
- init_object();
18426
- init_pure2();
18427
- Arguments = {
18428
- pure: createPure((value) => (tx) => tx.pure(value)),
18429
- object: createObjectMethods((value) => (tx) => tx.object(value)),
18430
- sharedObjectRef: (...args) => (tx) => tx.sharedObjectRef(...args),
18431
- objectRef: (...args) => (tx) => tx.objectRef(...args),
18432
- receivingRef: (...args) => (tx) => tx.receivingRef(...args)
18433
- };
18434
- }
18435
- });
18436
-
18437
17609
  // ../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/index.mjs
18438
- var transactions_exports = {};
18439
- __export(transactions_exports, {
18440
- Arguments: () => Arguments,
18441
- AsyncCache: () => AsyncCache,
18442
- Inputs: () => Inputs,
18443
- ObjectCache: () => ObjectCache,
18444
- ParallelTransactionExecutor: () => ParallelTransactionExecutor,
18445
- SerialTransactionExecutor: () => SerialTransactionExecutor,
18446
- Transaction: () => Transaction,
18447
- TransactionCommands: () => TransactionCommands,
18448
- TransactionDataBuilder: () => TransactionDataBuilder,
18449
- UpgradePolicy: () => UpgradePolicy,
18450
- coinWithBalance: () => coinWithBalance,
18451
- getPureBcsSchema: () => getPureBcsSchema,
18452
- isArgument: () => isArgument,
18453
- isTransaction: () => isTransaction,
18454
- normalizedTypeToMoveTypeSignature: () => normalizedTypeToMoveTypeSignature
18455
- });
18456
17610
  var init_transactions = __esm({
18457
17611
  "../../node_modules/.pnpm/@mysten+sui@2.17.0_typescript@5.9.3/node_modules/@mysten/sui/dist/transactions/index.mjs"() {
18458
- init_utils4();
18459
- init_TransactionData();
18460
- init_Commands();
18461
- init_Inputs();
18462
- init_serializer();
18463
17612
  init_CoinWithBalance();
18464
17613
  init_Transaction();
18465
- init_ObjectCache();
18466
- init_serial();
18467
- init_parallel();
18468
- init_Arguments();
18469
17614
  }
18470
17615
  });
18471
17616
 
@@ -78768,6 +77913,7 @@ var init_token_registry = __esm2({
78768
77913
  });
78769
77914
  var coinSelection_exports = {};
78770
77915
  __export2(coinSelection_exports, {
77916
+ buildCoinToAddressBalanceMigration: () => buildCoinToAddressBalanceMigration,
78771
77917
  fetchAllCoins: () => fetchAllCoins,
78772
77918
  selectAndSplitCoin: () => selectAndSplitCoin,
78773
77919
  selectSuiCoin: () => selectSuiCoin
@@ -78882,6 +78028,32 @@ async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowS
78882
78028
  });
78883
78029
  return { coin, effectiveAmount, swapAll };
78884
78030
  }
78031
+ function buildCoinToAddressBalanceMigration(args) {
78032
+ const { coins, coinType, owner, minAmount } = args;
78033
+ const sorted = [...coins].filter((c) => c.balance > 0n).sort((a, b) => b.balance > a.balance ? 1 : b.balance < a.balance ? -1 : 0);
78034
+ const selected = [];
78035
+ let migratedRaw = 0n;
78036
+ for (const c of sorted) {
78037
+ if (migratedRaw >= minAmount) break;
78038
+ selected.push(c);
78039
+ migratedRaw += c.balance;
78040
+ }
78041
+ if (migratedRaw < minAmount) {
78042
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient ${coinType} coin objects to migrate`, {
78043
+ available: migratedRaw.toString(),
78044
+ required: minAmount.toString()
78045
+ });
78046
+ }
78047
+ const tx = new Transaction();
78048
+ for (const c of selected) {
78049
+ tx.moveCall({
78050
+ target: "0x2::coin::send_funds",
78051
+ typeArguments: [coinType],
78052
+ arguments: [tx.object(c.objectId), tx.pure.address(owner)]
78053
+ });
78054
+ }
78055
+ return { tx, migratedRaw };
78056
+ }
78885
78057
  async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext, mergeCache) {
78886
78058
  if (sponsoredContext) {
78887
78059
  const { SUI_TYPE: SUI_TYPE22 } = await Promise.resolve().then(() => (init_token_registry(), token_registry_exports));
@@ -79611,40 +78783,26 @@ async function ensureAddressBalanceCovers(args) {
79611
78783
  required: amountRaw.toString()
79612
78784
  });
79613
78785
  }
78786
+ const coins = [];
79614
78787
  let coinSum = 0n;
79615
78788
  let cursor;
79616
78789
  let hasNext = true;
79617
78790
  while (hasNext) {
79618
78791
  const page = await client.core.listCoins({ owner, coinType: asset, cursor: cursor ?? void 0 });
79619
- for (const c of page.objects) coinSum += BigInt(c.balance);
78792
+ for (const c of page.objects) {
78793
+ coins.push({ objectId: c.objectId, balance: BigInt(c.balance) });
78794
+ coinSum += BigInt(c.balance);
78795
+ }
79620
78796
  cursor = page.cursor;
79621
78797
  hasNext = page.hasNextPage;
79622
78798
  }
79623
78799
  const addressBalance = total - coinSum;
79624
78800
  if (addressBalance >= amountRaw) return 0;
79625
78801
  const shortfall = amountRaw - addressBalance;
79626
- const { Transaction: Transaction6 } = await Promise.resolve().then(() => (init_transactions(), transactions_exports));
79627
- const { selectAndSplitCoin: selectAndSplitCoin2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
78802
+ const { buildCoinToAddressBalanceMigration: buildCoinToAddressBalanceMigration2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
79628
78803
  const grpcClient = await makeGrpcBuildClient(client);
79629
- const migration = await executeTx(
79630
- client,
79631
- signer,
79632
- async () => {
79633
- const tx = new Transaction6();
79634
- const { coin } = await selectAndSplitCoin2(tx, client, owner, asset, shortfall, {
79635
- sponsoredContext: true,
79636
- // coin-objects-only — never the address balance
79637
- allowSwapAll: false
79638
- });
79639
- tx.moveCall({
79640
- target: "0x2::coin::send_funds",
79641
- typeArguments: [asset],
79642
- arguments: [coin, tx.pure.address(owner)]
79643
- });
79644
- return tx;
79645
- },
79646
- { buildClient: grpcClient }
79647
- );
78804
+ const { tx } = buildCoinToAddressBalanceMigration2({ coins, coinType: asset, owner, minAmount: shortfall });
78805
+ const migration = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
79648
78806
  return migration.gasCostSui;
79649
78807
  }
79650
78808
  async function finalize(response, opts) {
@@ -81180,7 +80338,7 @@ CRITICAL: When the user asks to use any external or paid API, names a provider (
81180
80338
  Spending is the user's own USDC and every t2000_pay call is bounded by maxPrice. For larger or multi-step spends, state the estimated cost first and proceed once the user is happy. Use t2000_balance to check funds. The v4 wallet is payments-only; savings / lending live on audric.ai.`;
81181
80339
 
81182
80340
  // src/index.ts
81183
- var PKG_VERSION = "5.6.0" ;
80341
+ var PKG_VERSION = "5.6.1" ;
81184
80342
  console.log = (...args) => console.error("[log]", ...args);
81185
80343
  console.warn = (...args) => console.error("[warn]", ...args);
81186
80344
  async function startMcpServer(opts) {