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