@mysten/sui 2.5.1 → 2.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/CHANGELOG.md +29 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/client/core-resolver.mjs +6 -3
- package/dist/client/core-resolver.mjs.map +1 -1
- package/dist/client/core.d.mts +8 -8
- package/dist/client/core.d.mts.map +1 -1
- package/dist/client/core.mjs +11 -5
- package/dist/client/core.mjs.map +1 -1
- package/dist/client/types.d.mts +73 -18
- package/dist/client/types.d.mts.map +1 -1
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/graphql/client.d.mts +16 -1
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +50 -2
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/graphql/core.d.mts +5 -5
- package/dist/graphql/core.d.mts.map +1 -1
- package/dist/graphql/core.mjs +28 -49
- package/dist/graphql/core.mjs.map +1 -1
- package/dist/graphql/generated/queries.d.mts.map +1 -1
- package/dist/graphql/generated/queries.mjs +25 -7
- package/dist/graphql/generated/queries.mjs.map +1 -1
- package/dist/graphql/generated/tada-env.d.mts +706 -98
- package/dist/grpc/client.d.mts +16 -1
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +42 -2
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts +5 -5
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +18 -35
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/object.d.mts +38 -1
- package/dist/grpc/proto/sui/rpc/v2/object.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/object.mjs +26 -1
- package/dist/grpc/proto/sui/rpc/v2/object.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts +8 -0
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.d.mts.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs +23 -12
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.mjs.map +1 -1
- package/dist/grpc/proto/types.d.mts +2 -2
- package/dist/grpc/proto/types.mjs +2 -1
- package/dist/jsonRpc/core.d.mts +6 -6
- package/dist/jsonRpc/core.d.mts.map +1 -1
- package/dist/jsonRpc/core.mjs +14 -5
- package/dist/jsonRpc/core.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +6 -6
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/executor/caching.mjs.map +1 -1
- package/dist/transactions/executor/parallel.d.mts +1 -1
- package/dist/transactions/executor/parallel.d.mts.map +1 -1
- package/dist/transactions/executor/parallel.mjs.map +1 -1
- package/dist/transactions/executor/serial.d.mts +1 -1
- package/dist/transactions/executor/serial.d.mts.map +1 -1
- package/dist/transactions/executor/serial.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/package.json +1 -1
- package/src/client/core-resolver.ts +9 -8
- package/src/client/core.ts +28 -18
- package/src/client/types.ts +73 -18
- package/src/graphql/client.ts +96 -4
- package/src/graphql/core.ts +43 -88
- package/src/graphql/generated/queries.ts +271 -44
- package/src/graphql/generated/schema.graphql +328 -25
- package/src/graphql/generated/tada-env.ts +779 -58
- package/src/graphql/queries/getDynamicFields.graphql +8 -1
- package/src/graphql/queries/objects.graphql +10 -0
- package/src/graphql/queries/transactions.graphql +1 -3
- package/src/graphql/queries/verifyZkLoginSignature.graphql +0 -1
- package/src/grpc/client.ts +62 -4
- package/src/grpc/core.ts +42 -39
- package/src/grpc/proto/sui/rpc/v2/object.ts +44 -0
- package/src/grpc/proto/sui/rpc/v2/transaction_execution_service.ts +16 -0
- package/src/jsonRpc/core.ts +18 -7
- package/src/transactions/executor/caching.ts +2 -2
- package/src/transactions/executor/parallel.ts +1 -1
- package/src/transactions/executor/serial.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caching.mjs","names":["#client","bcs","#lastDigest"],"sources":["../../../src/transactions/executor/caching.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { SuiClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { BuildTransactionOptions } from '../resolve.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { ObjectCache } from '../ObjectCache.js';\nimport type { Transaction } from '../Transaction.js';\nimport { isTransaction } from '../Transaction.js';\n\nexport interface ExecuteTransactionOptions<Include extends SuiClientTypes.TransactionInclude = {}> {\n\ttransaction: Transaction | Uint8Array;\n\tsignatures: string[];\n\tinclude?: Include;\n}\n\nexport class CachingTransactionExecutor {\n\t#client: ClientWithCoreApi;\n\t#lastDigest: string | null = null;\n\tcache: ObjectCache;\n\n\tconstructor({\n\t\tclient,\n\t\t...options\n\t}: ObjectCacheOptions & {\n\t\tclient: ClientWithCoreApi;\n\t}) {\n\t\tthis.#client = client;\n\t\tthis.cache = new ObjectCache(options);\n\t}\n\n\t/**\n\t * Clears all Owned objects\n\t * Immutable objects, Shared objects, and Move function definitions will be preserved\n\t */\n\tasync reset() {\n\t\tawait Promise.all([\n\t\t\tthis.cache.clearOwnedObjects(),\n\t\t\tthis.cache.clearCustom(),\n\t\t\tthis.waitForLastTransaction(),\n\t\t]);\n\t}\n\n\tasync buildTransaction({\n\t\ttransaction,\n\t\t...options\n\t}: { transaction: Transaction } & BuildTransactionOptions) {\n\t\ttransaction.addBuildPlugin(this.cache.asPlugin());\n\t\ttransaction.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\treturn transaction.build({\n\t\t\tclient: this.#client,\n\t\t\t...options,\n\t\t});\n\t}\n\n\tasync executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>({\n\t\ttransaction,\n\t\tsignatures,\n\t\tinclude,\n\t}: ExecuteTransactionOptions<Include>): Promise<\n\t\tSuiClientTypes.TransactionResult<Include & { effects: true }>\n\t> {\n\t\tconst bytes = isTransaction(transaction)\n\t\t\t? await this.buildTransaction({ transaction })\n\t\t\t: transaction;\n\n\t\tconst results = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures,\n\t\t\tinclude: {\n\t\t\t\t...include,\n\t\t\t\teffects: true,\n\t\t\t},\n\t\t});\n\n\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\tif (tx.effects?.bcs) {\n\t\t\tconst effects = bcs.TransactionEffects.parse(tx.effects.bcs);\n\t\t\tawait this.applyEffects(effects);\n\t\t}\n\n\t\treturn results as SuiClientTypes.TransactionResult<Include & { effects: true }>;\n\t}\n\n\tasync signAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>({\n\t\tinclude,\n\t\ttransaction,\n\t\tsigner,\n\t}: {\n\t\ttransaction: Transaction;\n\t\tsigner: Signer;\n\t\tinclude?: Include;\n\t}): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\ttransaction.setSenderIfNotSet(signer.toSuiAddress());\n\t\tconst bytes = await this.buildTransaction({ transaction });\n\t\tconst { signature } = await signer.signTransaction(bytes);\n\t\treturn this.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude,\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\tthis.#lastDigest = effects.V2?.transactionDigest ?? null;\n\t\tawait this.cache.applyEffects(effects);\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tif (this.#lastDigest) {\n\t\t\tawait this.#client.core.waitForTransaction({ digest: this.#lastDigest });\n\t\t\tthis.#lastDigest = null;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAoBA,IAAa,6BAAb,MAAwC;CACvC;CACA,cAA6B;CAG7B,YAAY,EACX,QACA,GAAG,WAGD;AACF,QAAKA,SAAU;AACf,OAAK,QAAQ,IAAI,YAAY,QAAQ;;;;;;CAOtC,MAAM,QAAQ;AACb,QAAM,QAAQ,IAAI;GACjB,KAAK,MAAM,mBAAmB;GAC9B,KAAK,MAAM,aAAa;GACxB,KAAK,wBAAwB;GAC7B,CAAC;;CAGH,MAAM,iBAAiB,EACtB,aACA,GAAG,WACuD;AAC1D,cAAY,eAAe,KAAK,MAAM,UAAU,CAAC;AACjD,cAAY,eAAe,mCAAmC;AAC9D,SAAO,YAAY,MAAM;GACxB,QAAQ,MAAKA;GACb,GAAG;GACH,CAAC;;CAGH,MAAM,mBAA2E,EAChF,aACA,YACA,WAGC;EACD,MAAM,QAAQ,cAAc,YAAY,GACrC,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC,GAC5C;EAEH,MAAM,UAAU,MAAM,MAAKA,OAAQ,KAAK,mBAAmB;GAC1D,aAAa;GACb;GACA,SAAS;IACR,GAAG;IACH,SAAS;IACT;GACD,CAAC;EAEF,MAAM,KAAK,QAAQ,UAAU,gBAAgB,QAAQ,cAAc,QAAQ;AAC3E,MAAI,GAAG,SAAS,KAAK;GACpB,MAAM,UAAUC,OAAI,mBAAmB,MAAM,GAAG,QAAQ,IAAI;AAC5D,SAAM,KAAK,aAAa,QAAQ;;AAGjC,SAAO;;CAGR,MAAM,0BAAkF,EACvF,SACA,aACA,UAK0E;AAC1E,cAAY,kBAAkB,OAAO,cAAc,CAAC;EACpD,MAAM,QAAQ,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC;EAC1D,MAAM,EAAE,cAAc,MAAM,OAAO,gBAAgB,MAAM;AACzD,SAAO,KAAK,mBAAmB;GAC9B,aAAa;GACb,YAAY,CAAC,UAAU;GACvB;GACA,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,QAAKC,aAAc,QAAQ,IAAI,qBAAqB;AACpD,QAAM,KAAK,MAAM,aAAa,QAAQ;;CAGvC,MAAM,yBAAyB;AAC9B,MAAI,MAAKA,YAAa;AACrB,SAAM,MAAKF,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,MAAKE,YAAa,CAAC;AACxE,SAAKA,aAAc"}
|
|
1
|
+
{"version":3,"file":"caching.mjs","names":["#client","bcs","#lastDigest"],"sources":["../../../src/transactions/executor/caching.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { SuiClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { BuildTransactionOptions } from '../resolve.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { ObjectCache } from '../ObjectCache.js';\nimport type { Transaction } from '../Transaction.js';\nimport { isTransaction } from '../Transaction.js';\n\nexport interface ExecuteTransactionOptions<Include extends SuiClientTypes.TransactionInclude = {}> {\n\ttransaction: Transaction | Uint8Array;\n\tsignatures: string[];\n\tinclude?: Include & SuiClientTypes.TransactionInclude;\n}\n\nexport class CachingTransactionExecutor {\n\t#client: ClientWithCoreApi;\n\t#lastDigest: string | null = null;\n\tcache: ObjectCache;\n\n\tconstructor({\n\t\tclient,\n\t\t...options\n\t}: ObjectCacheOptions & {\n\t\tclient: ClientWithCoreApi;\n\t}) {\n\t\tthis.#client = client;\n\t\tthis.cache = new ObjectCache(options);\n\t}\n\n\t/**\n\t * Clears all Owned objects\n\t * Immutable objects, Shared objects, and Move function definitions will be preserved\n\t */\n\tasync reset() {\n\t\tawait Promise.all([\n\t\t\tthis.cache.clearOwnedObjects(),\n\t\t\tthis.cache.clearCustom(),\n\t\t\tthis.waitForLastTransaction(),\n\t\t]);\n\t}\n\n\tasync buildTransaction({\n\t\ttransaction,\n\t\t...options\n\t}: { transaction: Transaction } & BuildTransactionOptions) {\n\t\ttransaction.addBuildPlugin(this.cache.asPlugin());\n\t\ttransaction.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\treturn transaction.build({\n\t\t\tclient: this.#client,\n\t\t\t...options,\n\t\t});\n\t}\n\n\tasync executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>({\n\t\ttransaction,\n\t\tsignatures,\n\t\tinclude,\n\t}: ExecuteTransactionOptions<Include>): Promise<\n\t\tSuiClientTypes.TransactionResult<Include & { effects: true }>\n\t> {\n\t\tconst bytes = isTransaction(transaction)\n\t\t\t? await this.buildTransaction({ transaction })\n\t\t\t: transaction;\n\n\t\tconst results = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures,\n\t\t\tinclude: {\n\t\t\t\t...include,\n\t\t\t\teffects: true,\n\t\t\t},\n\t\t});\n\n\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\tif (tx.effects?.bcs) {\n\t\t\tconst effects = bcs.TransactionEffects.parse(tx.effects.bcs);\n\t\t\tawait this.applyEffects(effects);\n\t\t}\n\n\t\treturn results as SuiClientTypes.TransactionResult<Include & { effects: true }>;\n\t}\n\n\tasync signAndExecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>({\n\t\tinclude,\n\t\ttransaction,\n\t\tsigner,\n\t}: {\n\t\ttransaction: Transaction;\n\t\tsigner: Signer;\n\t\tinclude?: Include & SuiClientTypes.TransactionInclude;\n\t}): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\ttransaction.setSenderIfNotSet(signer.toSuiAddress());\n\t\tconst bytes = await this.buildTransaction({ transaction });\n\t\tconst { signature } = await signer.signTransaction(bytes);\n\t\treturn this.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude,\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\tthis.#lastDigest = effects.V2?.transactionDigest ?? null;\n\t\tawait this.cache.applyEffects(effects);\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tif (this.#lastDigest) {\n\t\t\tawait this.#client.core.waitForTransaction({ digest: this.#lastDigest });\n\t\t\tthis.#lastDigest = null;\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;AAoBA,IAAa,6BAAb,MAAwC;CACvC;CACA,cAA6B;CAG7B,YAAY,EACX,QACA,GAAG,WAGD;AACF,QAAKA,SAAU;AACf,OAAK,QAAQ,IAAI,YAAY,QAAQ;;;;;;CAOtC,MAAM,QAAQ;AACb,QAAM,QAAQ,IAAI;GACjB,KAAK,MAAM,mBAAmB;GAC9B,KAAK,MAAM,aAAa;GACxB,KAAK,wBAAwB;GAC7B,CAAC;;CAGH,MAAM,iBAAiB,EACtB,aACA,GAAG,WACuD;AAC1D,cAAY,eAAe,KAAK,MAAM,UAAU,CAAC;AACjD,cAAY,eAAe,mCAAmC;AAC9D,SAAO,YAAY,MAAM;GACxB,QAAQ,MAAKA;GACb,GAAG;GACH,CAAC;;CAGH,MAAM,mBAA2E,EAChF,aACA,YACA,WAGC;EACD,MAAM,QAAQ,cAAc,YAAY,GACrC,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC,GAC5C;EAEH,MAAM,UAAU,MAAM,MAAKA,OAAQ,KAAK,mBAAmB;GAC1D,aAAa;GACb;GACA,SAAS;IACR,GAAG;IACH,SAAS;IACT;GACD,CAAC;EAEF,MAAM,KAAK,QAAQ,UAAU,gBAAgB,QAAQ,cAAc,QAAQ;AAC3E,MAAI,GAAG,SAAS,KAAK;GACpB,MAAM,UAAUC,OAAI,mBAAmB,MAAM,GAAG,QAAQ,IAAI;AAC5D,SAAM,KAAK,aAAa,QAAQ;;AAGjC,SAAO;;CAGR,MAAM,0BAAkF,EACvF,SACA,aACA,UAK0E;AAC1E,cAAY,kBAAkB,OAAO,cAAc,CAAC;EACpD,MAAM,QAAQ,MAAM,KAAK,iBAAiB,EAAE,aAAa,CAAC;EAC1D,MAAM,EAAE,cAAc,MAAM,OAAO,gBAAgB,MAAM;AACzD,SAAO,KAAK,mBAAmB;GAC9B,aAAa;GACb,YAAY,CAAC,UAAU;GACvB;GACA,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,QAAKC,aAAc,QAAQ,IAAI,qBAAqB;AACpD,QAAM,KAAK,MAAM,aAAa,QAAQ;;CAGvC,MAAM,yBAAyB;AAC9B,MAAI,MAAKA,YAAa;AACrB,SAAM,MAAKF,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,MAAKE,YAAa,CAAC;AACxE,SAAKA,aAAc"}
|
|
@@ -37,7 +37,7 @@ declare class ParallelTransactionExecutor {
|
|
|
37
37
|
constructor(options: ParallelTransactionExecutorOptions);
|
|
38
38
|
resetCache(): Promise<void>;
|
|
39
39
|
waitForLastTransaction(): Promise<void>;
|
|
40
|
-
executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(transaction: Transaction, include?: Include, additionalSignatures?: string[]): Promise<SuiClientTypes.TransactionResult<Include & {
|
|
40
|
+
executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(transaction: Transaction, include?: Include & SuiClientTypes.TransactionInclude, additionalSignatures?: string[]): Promise<SuiClientTypes.TransactionResult<Include & {
|
|
41
41
|
effects: true;
|
|
42
42
|
}>>;
|
|
43
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.d.mts","names":[],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAwBU,sCAAA,SAA+C,KAAK;UACrD;UACA;EAFC;EAAoD,gBAAA,CAAA,EAAA,MAAA;EACrD;EACA,WAAA,CAAA,EAAA,MAAA;;AAFoD,UAS5C,sCAAA,SAA+C,sCATH,CAAA;EAS5C;EAaA,OAAA,CAAA,EAAA,OAAA;EAML;EAUC,aAAA,CAAA,EAAA,MAAA;EA0BS;EA+BX,kBAAA,CAAA,EAAA,MAAA;EAKkB;EAIa,kBAAe,CAAA,EAAA,MAAA;EAC1C;EACH,WAAA,CAAA,EAAA,MAAA,EAAA;;
|
|
1
|
+
{"version":3,"file":"parallel.d.mts","names":[],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAwBU,sCAAA,SAA+C,KAAK;UACrD;UACA;EAFC;EAAoD,gBAAA,CAAA,EAAA,MAAA;EACrD;EACA,WAAA,CAAA,EAAA,MAAA;;AAFoD,UAS5C,sCAAA,SAA+C,sCATH,CAAA;EAS5C;EAaA,OAAA,CAAA,EAAA,OAAA;EAML;EAUC,aAAA,CAAA,EAAA,MAAA;EA0BS;EA+BX,kBAAA,CAAA,EAAA,MAAA;EAKkB;EAIa,kBAAe,CAAA,EAAA,MAAA;EAC1C;EACH,WAAA,CAAA,EAAA,MAAA,EAAA;;AAEiC,UAtF5B,gDAAA,SAAyD,sCAsF7B,CAAA;EAAjC;EAAR,OAAA,EAAA,gBAAA;;;KAhFQ,kCAAA,GACT,yCACA;cAQU,2BAAA;;uBA0BS;gBA+BX;4BAKkB;qCAIa,cAAA,CAAe,sCAC1C,uBACH,UAAU,cAAA,CAAe,sDAEjC,QAAQ,cAAA,CAAe,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parallel.mjs","names":["#signer","#client","#gasMode","#coinBatchSize","#initialCoinBalance","#minimumCoinBalance","#sourceCoins","#defaultGasBudget","#maxPoolSize","#cache","#executeQueue","#epochInfo","#updateCache","#waitForLastDigest","#getUsedObjects","#execute","#objectIdQueues","#buildQueue","#getGasPrice","#pendingTransactions","#getValidDuringExpiration","#getGasCoin","#coinPool","#lastDigest","#cacheLock","#refillCoinPool","#ensureEpochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { promiseWithResolvers } from '@mysten/utils';\nimport type { SuiObjectRef } from '../../bcs/types.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { SuiClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { TransactionDataBuilder } from '../TransactionData.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n} satisfies Partial<ParallelTransactionExecutorCoinOptions>;\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface ParallelTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\t/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */\n\tdefaultGasBudget?: bigint;\n\t/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */\n\tmaxPoolSize?: number;\n}\n\nexport interface ParallelTransactionExecutorCoinOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use owned coins for gas payments (default) */\n\tgasMode?: 'coins';\n\t/** The number of coins to create in a batch when refilling the gas pool */\n\tcoinBatchSize?: number;\n\t/** The initial balance of each coin created for the gas pool */\n\tinitialCoinBalance?: bigint;\n\t/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */\n\tminimumCoinBalance?: bigint;\n\t/** An initial list of coins used to fund the gas pool, uses all owned SUI coins by default */\n\tsourceCoins?: string[];\n}\n\nexport interface ParallelTransactionExecutorAddressBalanceOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use address balance for gas payments instead of owned coins */\n\tgasMode: 'addressBalance';\n}\n\n/** Options for ParallelTransactionExecutor - discriminated union based on gasMode */\nexport type ParallelTransactionExecutorOptions =\n\t| ParallelTransactionExecutorCoinOptions\n\t| ParallelTransactionExecutorAddressBalanceOptions;\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#defaultGasBudget: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, SuiObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\t#lastDigest: string | null = null;\n\t#cacheLock: Promise<void> | null = null;\n\t#pendingTransactions = 0;\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\tprice: bigint;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\n\t\tif (this.#gasMode === 'coins') {\n\t\t\tconst coinOptions = options as ParallelTransactionExecutorCoinOptions;\n\t\t\tthis.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\t\tthis.#initialCoinBalance =\n\t\t\t\tcoinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\t\tthis.#minimumCoinBalance =\n\t\t\t\tcoinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = coinOptions.sourceCoins\n\t\t\t\t? new Map(coinOptions.sourceCoins.map((id) => [id, null]))\n\t\t\t\t: null;\n\t\t} else {\n\t\t\tthis.#coinBatchSize = 0;\n\t\t\tthis.#initialCoinBalance = 0n;\n\t\t\tthis.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = null;\n\t\t}\n\n\t\tthis.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t}\n\n\tresetCache() {\n\t\tthis.#epochInfo = null;\n\t\treturn this.#updateCache(() => this.#cache.reset());\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tawait this.#updateCache(() => this.#waitForLastDigest());\n\t}\n\n\tasync executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tconst { promise, resolve, reject } =\n\t\t\tpromiseWithResolvers<SuiClientTypes.TransactionResult<Include & { effects: true }>>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects, include, additionalSignatures);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tusedObjects: Set<string>,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tlet gasCoin: CoinWithBalance | null = null;\n\t\ttry {\n\t\t\ttransaction.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\t\tawait this.#buildQueue.runTask(async () => {\n\t\t\t\tconst data = transaction.getData();\n\n\t\t\t\tif (!data.gasData.price) {\n\t\t\t\t\ttransaction.setGasPrice(await this.#getGasPrice());\n\t\t\t\t}\n\n\t\t\t\ttransaction.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\n\t\t\t\tawait this.#updateCache();\n\t\t\t\tthis.#pendingTransactions++;\n\n\t\t\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\t\t\t// Address balance mode: use empty gas payment with ValidDuring expiration\n\t\t\t\t\ttransaction.setGasPayment([]);\n\t\t\t\t\ttransaction.setExpiration(await this.#getValidDuringExpiration());\n\t\t\t\t} else {\n\t\t\t\t\t// Coin mode: use gas coin from pool\n\t\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t\t},\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\t// Resolve cached references\n\t\t\t\tawait this.#cache.buildTransaction({ transaction, onlyTransactionKind: true });\n\t\t\t});\n\n\t\t\tconst bytes = await transaction.build({ client: this.#client });\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\tinclude,\n\t\t\t});\n\n\t\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\t\tconst effects = tx.effects!;\n\t\t\tconst gasObject = effects.gasObject;\n\t\t\tconst gasUsed = effects.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasObject) {\n\t\t\t\tconst coin = gasCoin as CoinWithBalance;\n\t\t\t\tconst gasOwner = gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner;\n\n\t\t\t\tif (gasOwner === this.#signer.toSuiAddress()) {\n\t\t\t\t\tconst totalUsed =\n\t\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\t\t\t\t\tconst remainingBalance = coin.balance - totalUsed;\n\n\t\t\t\t\tlet usesGasCoin = false;\n\t\t\t\t\tnew TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {\n\t\t\t\t\t\tif (arg.$kind === 'GasCoin') {\n\t\t\t\t\t\t\tusesGasCoin = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn arg;\n\t\t\t\t\t});\n\n\t\t\t\t\tconst gasRef = {\n\t\t\t\t\t\tobjectId: gasObject.objectId,\n\t\t\t\t\t\tversion: gasObject.outputVersion!,\n\t\t\t\t\t\tdigest: gasObject.outputDigest!,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) {\n\t\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\t\tid: gasRef.objectId,\n\t\t\t\t\t\t\tversion: gasRef.version,\n\t\t\t\t\t\t\tdigest: gasRef.digest,\n\t\t\t\t\t\t\tbalance: remainingBalance,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#sourceCoins.set(gasRef.objectId, gasRef);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.#lastDigest = tx.digest;\n\n\t\t\treturn results as SuiClientTypes.TransactionResult<Include & { effects: true }>;\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set((gasCoin as CoinWithBalance).id, null);\n\t\t\t}\n\n\t\t\tawait this.#updateCache(async () => {\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tthis.#cache.cache.deleteObjects([...usedObjects]),\n\t\t\t\t\tthis.#waitForLastDigest(),\n\t\t\t\t]);\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.#pendingTransactions--;\n\t\t}\n\t}\n\n\t/** 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 */\n\tasync #updateCache(fn?: () => Promise<void>) {\n\t\tif (this.#cacheLock) {\n\t\t\tawait this.#cacheLock;\n\t\t}\n\n\t\tthis.#cacheLock =\n\t\t\tfn?.().then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#cacheLock = null;\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t) ?? null;\n\t}\n\n\tasync #waitForLastDigest() {\n\t\tconst digest = this.#lastDigest;\n\t\tif (digest) {\n\t\t\tthis.#lastDigest = null;\n\t\t\tawait this.#client.core.waitForTransaction({ digest });\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #getGasPrice(): Promise<bigint> {\n\t\tawait this.#ensureEpochInfo();\n\t\treturn this.#epochInfo!.price;\n\t}\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\tprice: BigInt(systemState.referenceGasPrice),\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toSuiAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst { objects } = await this.#client.core.getObjects({\n\t\t\t\t\tobjectIds: ids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...objects\n\t\t\t\t\t\t.filter((obj): obj is SuiClientTypes.Object => !(obj instanceof Error))\n\t\t\t\t\t\t.map((obj) => ({\n\t\t\t\t\t\t\tobjectId: obj.objectId,\n\t\t\t\t\t\t\tversion: obj.version,\n\t\t\t\t\t\t\tdigest: obj.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst splitResults = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(splitResults[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tawait this.waitForLastTransaction();\n\n\t\ttxb.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\tconst bytes = await txb.build({ client: this.#client });\n\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\tconst result = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude: { effects: true },\n\t\t});\n\n\t\tconst tx = result.$kind === 'Transaction' ? result.Transaction : result.FailedTransaction;\n\t\tconst effects = tx.effects!;\n\n\t\teffects.changedObjects.forEach((changedObj) => {\n\t\t\tif (\n\t\t\t\tchangedObj.objectId === effects.gasObject?.objectId ||\n\t\t\t\tchangedObj.outputState !== 'ObjectWrite'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid: changedObj.objectId,\n\t\t\t\tversion: changedObj.outputVersion!,\n\t\t\t\tdigest: changedObj.outputDigest!,\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = effects.gasObject!;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, {\n\t\t\tobjectId: gasObject.objectId,\n\t\t\tversion: gasObject.outputVersion!,\n\t\t\tdigest: gasObject.outputDigest!,\n\t\t});\n\n\t\tawait this.#client.core.waitForTransaction({ digest: tx.digest });\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BAA6B;CAClC,eAAe;CACf,oBAAoB;CACpB,oBAAoB;CACpB,aAAa;CACb;AAED,MAAM,wBAAwB;AAwC9B,IAAa,8BAAb,MAAyC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,YAA+B,EAAE;CACjC;CACA,kCAAkB,IAAI,KAA6B;CACnD,cAAc,IAAI,aAAa;CAC/B;CACA,cAA6B;CAC7B,aAAmC;CACnC,uBAAuB;CACvB,aAKI;CACJ,oBAA0C;CAE1C,YAAY,SAA6C;AACxD,QAAKA,SAAU,QAAQ;AACvB,QAAKC,SAAU,QAAQ;AACvB,QAAKC,UAAW,QAAQ,WAAW;AAEnC,MAAI,MAAKA,YAAa,SAAS;GAC9B,MAAM,cAAc;AACpB,SAAKC,gBAAiB,YAAY,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,CAAC"}
|
|
1
|
+
{"version":3,"file":"parallel.mjs","names":["#signer","#client","#gasMode","#coinBatchSize","#initialCoinBalance","#minimumCoinBalance","#sourceCoins","#defaultGasBudget","#maxPoolSize","#cache","#executeQueue","#epochInfo","#updateCache","#waitForLastDigest","#getUsedObjects","#execute","#objectIdQueues","#buildQueue","#getGasPrice","#pendingTransactions","#getValidDuringExpiration","#getGasCoin","#coinPool","#lastDigest","#cacheLock","#refillCoinPool","#ensureEpochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/parallel.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { promiseWithResolvers } from '@mysten/utils';\nimport type { SuiObjectRef } from '../../bcs/types.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport { coreClientResolveTransactionPlugin } from '../../client/core-resolver.js';\nimport type { SuiClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/index.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { Transaction } from '../Transaction.js';\nimport { TransactionDataBuilder } from '../TransactionData.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { ParallelQueue, SerialQueue } from './queue.js';\n\nconst PARALLEL_EXECUTOR_DEFAULTS = {\n\tcoinBatchSize: 20,\n\tinitialCoinBalance: 200_000_000n,\n\tminimumCoinBalance: 50_000_000n,\n\tmaxPoolSize: 50,\n} satisfies Partial<ParallelTransactionExecutorCoinOptions>;\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface ParallelTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\t/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `minimumCoinBalance` */\n\tdefaultGasBudget?: bigint;\n\t/** The maximum number of transactions that can be execute in parallel, this also determines the maximum number of gas coins that will be created */\n\tmaxPoolSize?: number;\n}\n\nexport interface ParallelTransactionExecutorCoinOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use owned coins for gas payments (default) */\n\tgasMode?: 'coins';\n\t/** The number of coins to create in a batch when refilling the gas pool */\n\tcoinBatchSize?: number;\n\t/** The initial balance of each coin created for the gas pool */\n\tinitialCoinBalance?: bigint;\n\t/** The minimum balance of a coin that can be reused for future transactions. If the gasCoin is below this value, it will be used when refilling the gasPool */\n\tminimumCoinBalance?: bigint;\n\t/** An initial list of coins used to fund the gas pool, uses all owned SUI coins by default */\n\tsourceCoins?: string[];\n}\n\nexport interface ParallelTransactionExecutorAddressBalanceOptions extends ParallelTransactionExecutorBaseOptions {\n\t/** Gas mode - use address balance for gas payments instead of owned coins */\n\tgasMode: 'addressBalance';\n}\n\n/** Options for ParallelTransactionExecutor - discriminated union based on gasMode */\nexport type ParallelTransactionExecutorOptions =\n\t| ParallelTransactionExecutorCoinOptions\n\t| ParallelTransactionExecutorAddressBalanceOptions;\n\ninterface CoinWithBalance {\n\tid: string;\n\tversion: string;\n\tdigest: string;\n\tbalance: bigint;\n}\nexport class ParallelTransactionExecutor {\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#coinBatchSize: number;\n\t#initialCoinBalance: bigint;\n\t#minimumCoinBalance: bigint;\n\t#defaultGasBudget: bigint;\n\t#maxPoolSize: number;\n\t#sourceCoins: Map<string, SuiObjectRef | null> | null;\n\t#coinPool: CoinWithBalance[] = [];\n\t#cache: CachingTransactionExecutor;\n\t#objectIdQueues = new Map<string, (() => void)[]>();\n\t#buildQueue = new SerialQueue();\n\t#executeQueue: ParallelQueue;\n\t#lastDigest: string | null = null;\n\t#cacheLock: Promise<void> | null = null;\n\t#pendingTransactions = 0;\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\tprice: bigint;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: ParallelTransactionExecutorOptions) {\n\t\tthis.#signer = options.signer;\n\t\tthis.#client = options.client;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\n\t\tif (this.#gasMode === 'coins') {\n\t\t\tconst coinOptions = options as ParallelTransactionExecutorCoinOptions;\n\t\t\tthis.#coinBatchSize = coinOptions.coinBatchSize ?? PARALLEL_EXECUTOR_DEFAULTS.coinBatchSize;\n\t\t\tthis.#initialCoinBalance =\n\t\t\t\tcoinOptions.initialCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.initialCoinBalance;\n\t\t\tthis.#minimumCoinBalance =\n\t\t\t\tcoinOptions.minimumCoinBalance ?? PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = coinOptions.sourceCoins\n\t\t\t\t? new Map(coinOptions.sourceCoins.map((id) => [id, null]))\n\t\t\t\t: null;\n\t\t} else {\n\t\t\tthis.#coinBatchSize = 0;\n\t\t\tthis.#initialCoinBalance = 0n;\n\t\t\tthis.#minimumCoinBalance = PARALLEL_EXECUTOR_DEFAULTS.minimumCoinBalance;\n\t\t\tthis.#sourceCoins = null;\n\t\t}\n\n\t\tthis.#defaultGasBudget = options.defaultGasBudget ?? this.#minimumCoinBalance;\n\t\tthis.#maxPoolSize = options.maxPoolSize ?? PARALLEL_EXECUTOR_DEFAULTS.maxPoolSize;\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient: options.client,\n\t\t\tcache: options.cache,\n\t\t});\n\t\tthis.#executeQueue = new ParallelQueue(this.#maxPoolSize);\n\t}\n\n\tresetCache() {\n\t\tthis.#epochInfo = null;\n\t\treturn this.#updateCache(() => this.#cache.reset());\n\t}\n\n\tasync waitForLastTransaction() {\n\t\tawait this.#updateCache(() => this.#waitForLastDigest());\n\t}\n\n\tasync executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tinclude?: Include & SuiClientTypes.TransactionInclude,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tconst { promise, resolve, reject } =\n\t\t\tpromiseWithResolvers<SuiClientTypes.TransactionResult<Include & { effects: true }>>();\n\t\tconst usedObjects = await this.#getUsedObjects(transaction);\n\n\t\tconst execute = () => {\n\t\t\tthis.#executeQueue.runTask(() => {\n\t\t\t\tconst promise = this.#execute(transaction, usedObjects, include, additionalSignatures);\n\n\t\t\t\treturn promise.then(resolve, reject);\n\t\t\t});\n\t\t};\n\n\t\tconst conflicts = new Set<string>();\n\n\t\tusedObjects.forEach((objectId) => {\n\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\tif (queue) {\n\t\t\t\tconflicts.add(objectId);\n\t\t\t\tthis.#objectIdQueues.get(objectId)!.push(() => {\n\t\t\t\t\tconflicts.delete(objectId);\n\t\t\t\t\tif (conflicts.size === 0) {\n\t\t\t\t\t\texecute();\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tthis.#objectIdQueues.set(objectId, []);\n\t\t\t}\n\t\t});\n\n\t\tif (conflicts.size === 0) {\n\t\t\texecute();\n\t\t}\n\n\t\treturn promise;\n\t}\n\n\tasync #getUsedObjects(transaction: Transaction) {\n\t\tconst usedObjects = new Set<string>();\n\t\tlet serialized = false;\n\n\t\ttransaction.addSerializationPlugin(async (blockData, _options, next) => {\n\t\t\tawait next();\n\n\t\t\tif (serialized) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tserialized = true;\n\n\t\t\tblockData.inputs.forEach((input) => {\n\t\t\t\tif (input.Object?.ImmOrOwnedObject?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.ImmOrOwnedObject.objectId);\n\t\t\t\t} else if (input.Object?.Receiving?.objectId) {\n\t\t\t\t\tusedObjects.add(input.Object.Receiving.objectId);\n\t\t\t\t} else if (\n\t\t\t\t\tinput.UnresolvedObject?.objectId &&\n\t\t\t\t\t!input.UnresolvedObject.initialSharedVersion\n\t\t\t\t) {\n\t\t\t\t\tusedObjects.add(input.UnresolvedObject.objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tawait transaction.prepareForSerialization({ client: this.#client });\n\n\t\treturn usedObjects;\n\t}\n\n\tasync #execute<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction,\n\t\tusedObjects: Set<string>,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\tlet gasCoin: CoinWithBalance | null = null;\n\t\ttry {\n\t\t\ttransaction.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\t\tawait this.#buildQueue.runTask(async () => {\n\t\t\t\tconst data = transaction.getData();\n\n\t\t\t\tif (!data.gasData.price) {\n\t\t\t\t\ttransaction.setGasPrice(await this.#getGasPrice());\n\t\t\t\t}\n\n\t\t\t\ttransaction.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\n\t\t\t\tawait this.#updateCache();\n\t\t\t\tthis.#pendingTransactions++;\n\n\t\t\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\t\t\t// Address balance mode: use empty gas payment with ValidDuring expiration\n\t\t\t\t\ttransaction.setGasPayment([]);\n\t\t\t\t\ttransaction.setExpiration(await this.#getValidDuringExpiration());\n\t\t\t\t} else {\n\t\t\t\t\t// Coin mode: use gas coin from pool\n\t\t\t\t\tgasCoin = await this.#getGasCoin();\n\t\t\t\t\ttransaction.setGasPayment([\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tobjectId: gasCoin.id,\n\t\t\t\t\t\t\tversion: gasCoin.version,\n\t\t\t\t\t\t\tdigest: gasCoin.digest,\n\t\t\t\t\t\t},\n\t\t\t\t\t]);\n\t\t\t\t}\n\n\t\t\t\t// Resolve cached references\n\t\t\t\tawait this.#cache.buildTransaction({ transaction, onlyTransactionKind: true });\n\t\t\t});\n\n\t\t\tconst bytes = await transaction.build({ client: this.#client });\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\t\tconst results = await this.#cache.executeTransaction({\n\t\t\t\ttransaction: bytes,\n\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\tinclude,\n\t\t\t});\n\n\t\t\tconst tx = results.$kind === 'Transaction' ? results.Transaction : results.FailedTransaction;\n\t\t\tconst effects = tx.effects!;\n\t\t\tconst gasObject = effects.gasObject;\n\t\t\tconst gasUsed = effects.gasUsed;\n\n\t\t\tif (gasCoin && gasUsed && gasObject) {\n\t\t\t\tconst coin = gasCoin as CoinWithBalance;\n\t\t\t\tconst gasOwner = gasObject.outputOwner?.AddressOwner ?? gasObject.outputOwner?.ObjectOwner;\n\n\t\t\t\tif (gasOwner === this.#signer.toSuiAddress()) {\n\t\t\t\t\tconst totalUsed =\n\t\t\t\t\t\tBigInt(gasUsed.computationCost) +\n\t\t\t\t\t\tBigInt(gasUsed.storageCost) -\n\t\t\t\t\t\tBigInt(gasUsed.storageRebate);\n\t\t\t\t\tconst remainingBalance = coin.balance - totalUsed;\n\n\t\t\t\t\tlet usesGasCoin = false;\n\t\t\t\t\tnew TransactionDataBuilder(transaction.getData()).mapArguments((arg) => {\n\t\t\t\t\t\tif (arg.$kind === 'GasCoin') {\n\t\t\t\t\t\t\tusesGasCoin = true;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn arg;\n\t\t\t\t\t});\n\n\t\t\t\t\tconst gasRef = {\n\t\t\t\t\t\tobjectId: gasObject.objectId,\n\t\t\t\t\t\tversion: gasObject.outputVersion!,\n\t\t\t\t\t\tdigest: gasObject.outputDigest!,\n\t\t\t\t\t};\n\n\t\t\t\t\tif (!usesGasCoin && remainingBalance >= this.#minimumCoinBalance) {\n\t\t\t\t\t\tthis.#coinPool.push({\n\t\t\t\t\t\t\tid: gasRef.objectId,\n\t\t\t\t\t\t\tversion: gasRef.version,\n\t\t\t\t\t\t\tdigest: gasRef.digest,\n\t\t\t\t\t\t\tbalance: remainingBalance,\n\t\t\t\t\t\t});\n\t\t\t\t\t} else {\n\t\t\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthis.#sourceCoins.set(gasRef.objectId, gasRef);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.#lastDigest = tx.digest;\n\n\t\t\treturn results as SuiClientTypes.TransactionResult<Include & { effects: true }>;\n\t\t} catch (error) {\n\t\t\tif (gasCoin) {\n\t\t\t\tif (!this.#sourceCoins) {\n\t\t\t\t\tthis.#sourceCoins = new Map();\n\t\t\t\t}\n\n\t\t\t\tthis.#sourceCoins.set((gasCoin as CoinWithBalance).id, null);\n\t\t\t}\n\n\t\t\tawait this.#updateCache(async () => {\n\t\t\t\tawait Promise.all([\n\t\t\t\t\tthis.#cache.cache.deleteObjects([...usedObjects]),\n\t\t\t\t\tthis.#waitForLastDigest(),\n\t\t\t\t]);\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tusedObjects.forEach((objectId) => {\n\t\t\t\tconst queue = this.#objectIdQueues.get(objectId);\n\t\t\t\tif (queue && queue.length > 0) {\n\t\t\t\t\tqueue.shift()!();\n\t\t\t\t} else if (queue) {\n\t\t\t\t\tthis.#objectIdQueues.delete(objectId);\n\t\t\t\t}\n\t\t\t});\n\t\t\tthis.#pendingTransactions--;\n\t\t}\n\t}\n\n\t/** 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 */\n\tasync #updateCache(fn?: () => Promise<void>) {\n\t\tif (this.#cacheLock) {\n\t\t\tawait this.#cacheLock;\n\t\t}\n\n\t\tthis.#cacheLock =\n\t\t\tfn?.().then(\n\t\t\t\t() => {\n\t\t\t\t\tthis.#cacheLock = null;\n\t\t\t\t},\n\t\t\t\t() => {},\n\t\t\t) ?? null;\n\t}\n\n\tasync #waitForLastDigest() {\n\t\tconst digest = this.#lastDigest;\n\t\tif (digest) {\n\t\t\tthis.#lastDigest = null;\n\t\t\tawait this.#client.core.waitForTransaction({ digest });\n\t\t}\n\t}\n\n\tasync #getGasCoin() {\n\t\tif (this.#coinPool.length === 0 && this.#pendingTransactions <= this.#maxPoolSize) {\n\t\t\tawait this.#refillCoinPool();\n\t\t}\n\n\t\tif (this.#coinPool.length === 0) {\n\t\t\tthrow new Error('No coins available');\n\t\t}\n\n\t\tconst coin = this.#coinPool.shift()!;\n\t\treturn coin;\n\t}\n\n\tasync #getGasPrice(): Promise<bigint> {\n\t\tawait this.#ensureEpochInfo();\n\t\treturn this.#epochInfo!.price;\n\t}\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\tprice: BigInt(systemState.referenceGasPrice),\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tasync #refillCoinPool() {\n\t\tconst batchSize = Math.min(\n\t\t\tthis.#coinBatchSize,\n\t\t\tthis.#maxPoolSize - (this.#coinPool.length + this.#pendingTransactions) + 1,\n\t\t);\n\n\t\tif (batchSize === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst txb = new Transaction();\n\t\tconst address = this.#signer.toSuiAddress();\n\t\ttxb.setSender(address);\n\n\t\tif (this.#sourceCoins) {\n\t\t\tconst refs = [];\n\t\t\tconst ids = [];\n\t\t\tfor (const [id, ref] of this.#sourceCoins) {\n\t\t\t\tif (ref) {\n\t\t\t\t\trefs.push(ref);\n\t\t\t\t} else {\n\t\t\t\t\tids.push(id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (ids.length > 0) {\n\t\t\t\tconst { objects } = await this.#client.core.getObjects({\n\t\t\t\t\tobjectIds: ids,\n\t\t\t\t});\n\t\t\t\trefs.push(\n\t\t\t\t\t...objects\n\t\t\t\t\t\t.filter((obj): obj is SuiClientTypes.Object => !(obj instanceof Error))\n\t\t\t\t\t\t.map((obj) => ({\n\t\t\t\t\t\t\tobjectId: obj.objectId,\n\t\t\t\t\t\t\tversion: obj.version,\n\t\t\t\t\t\t\tdigest: obj.digest,\n\t\t\t\t\t\t})),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\ttxb.setGasPayment(refs);\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst amounts = new Array(batchSize).fill(this.#initialCoinBalance);\n\t\tconst splitResults = txb.splitCoins(txb.gas, amounts);\n\t\tconst coinResults = [];\n\t\tfor (let i = 0; i < amounts.length; i++) {\n\t\t\tcoinResults.push(splitResults[i]);\n\t\t}\n\t\ttxb.transferObjects(coinResults, address);\n\n\t\tawait this.waitForLastTransaction();\n\n\t\ttxb.addBuildPlugin(coreClientResolveTransactionPlugin);\n\t\tconst bytes = await txb.build({ client: this.#client });\n\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\n\t\tconst result = await this.#client.core.executeTransaction({\n\t\t\ttransaction: bytes,\n\t\t\tsignatures: [signature],\n\t\t\tinclude: { effects: true },\n\t\t});\n\n\t\tconst tx = result.$kind === 'Transaction' ? result.Transaction : result.FailedTransaction;\n\t\tconst effects = tx.effects!;\n\n\t\teffects.changedObjects.forEach((changedObj) => {\n\t\t\tif (\n\t\t\t\tchangedObj.objectId === effects.gasObject?.objectId ||\n\t\t\t\tchangedObj.outputState !== 'ObjectWrite'\n\t\t\t) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.#coinPool.push({\n\t\t\t\tid: changedObj.objectId,\n\t\t\t\tversion: changedObj.outputVersion!,\n\t\t\t\tdigest: changedObj.outputDigest!,\n\t\t\t\tbalance: BigInt(this.#initialCoinBalance),\n\t\t\t});\n\t\t});\n\n\t\tif (!this.#sourceCoins) {\n\t\t\tthis.#sourceCoins = new Map();\n\t\t}\n\n\t\tconst gasObject = effects.gasObject!;\n\t\tthis.#sourceCoins!.set(gasObject.objectId, {\n\t\t\tobjectId: gasObject.objectId,\n\t\t\tversion: gasObject.outputVersion!,\n\t\t\tdigest: gasObject.outputDigest!,\n\t\t});\n\n\t\tawait this.#client.core.waitForTransaction({ digest: tx.digest });\n\t}\n}\n"],"mappings":";;;;;;;;AAeA,MAAM,6BAA6B;CAClC,eAAe;CACf,oBAAoB;CACpB,oBAAoB;CACpB,aAAa;CACb;AAED,MAAM,wBAAwB;AAwC9B,IAAa,8BAAb,MAAyC;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,YAA+B,EAAE;CACjC;CACA,kCAAkB,IAAI,KAA6B;CACnD,cAAc,IAAI,aAAa;CAC/B;CACA,cAA6B;CAC7B,aAAmC;CACnC,uBAAuB;CAC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AI,KAAK;EAG9B,MAAM,YAAY,QAAQ;AAC1B,QAAKA,YAAc,IAAI,UAAU,UAAU;GAC1C,UAAU,UAAU;GACpB,SAAS,UAAU;GACnB,QAAQ,UAAU;GAClB,CAAC;AAEF,QAAM,MAAKL,OAAQ,KAAK,mBAAmB,EAAE,QAAQ,GAAG,QAAQ,CAAC"}
|
|
@@ -25,7 +25,7 @@ declare class SerialTransactionExecutor {
|
|
|
25
25
|
buildTransaction(transaction: Transaction): Promise<Uint8Array<ArrayBuffer>>;
|
|
26
26
|
resetCache(): Promise<void>;
|
|
27
27
|
waitForLastTransaction(): Promise<void>;
|
|
28
|
-
executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(transaction: Transaction | Uint8Array, include?: Include, additionalSignatures?: string[]): Promise<SuiClientTypes.TransactionResult<Include & {
|
|
28
|
+
executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(transaction: Transaction | Uint8Array, include?: Include & SuiClientTypes.TransactionInclude, additionalSignatures?: string[]): Promise<SuiClientTypes.TransactionResult<Include & {
|
|
29
29
|
effects: true;
|
|
30
30
|
}>>;
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serial.d.mts","names":[],"sources":["../../../src/transactions/executor/serial.ts"],"sourcesContent":[],"mappings":";;;;;;;;UAcU,oCAAA,SAA6C,KAAK;UACnD;EADC,MAAA,EAED,MAFC;EAAkD,gBAAA,CAAA,EAAA,MAAA;;AAEnD,UAIQ,oCAAA,SAA6C,oCAJrD,CAAA;EAF8C,OAAA,CAAA,EAAA,OAAA;;AAMtC,UAIA,8CAAA,SAAuD,oCAJ0B,CAAA;EAIjF,OAAA,EAAA,gBAAA;AAIjB;AAIa,KAJD,gCAAA,GACT,oCAGmC,GAFnC,8CAEmC;AAchB,cAdT,yBAAA,CAcS;EAac,CAAA,OAAI;EAA6B,WAAA,CAAA,OAAA,EAb/C,gCAa+C;EAiBhC,YAAA,CAAA,OAAA,EAAA,OAjBD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,WAAA,CAAA,CAAA;EAAA,UAAA,CAAA,CAAA,EAgFrC,OAhFqC,CAAA,IAAA,CAAA;EAAA,sBAAA,CAAA,CAAA,EAoFzB,OApFyB,CAAA,IAAA,CAAA;EAgFrC,kBAAA,CAAA,gBAQyB,cAAA,CAAe,kBARxC,GAAA,CAAA,CAAA,CAAA,CAAA,WAAA,EASI,WATJ,GASkB,UATlB,EAAA,OAAA,CAAA,EAUC,OAVD,GAUW,cAAA,CAAe,kBAV1B,EAAA,oBAAA,CAAA,EAAA,MAAA,EAAA,CAAA,EAYP,OAZO,CAYC,cAAA,CAAe,iBAZhB,CAYkC,OAZlC,GAAA;IAIY,OAAA,EAAA,IAAA;EAIa,CAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serial.mjs","names":["#signer","#client","#defaultGasBudget","#gasMode","#cache","#cacheGasCoin","#queue","#buildTransaction","#getValidDuringExpiration","#ensureEpochInfo","#epochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/serial.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport type { SuiClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { isTransaction, Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { SerialQueue } from './queue.js';\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface SerialTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\tdefaultGasBudget?: bigint;\n}\n\nexport interface SerialTransactionExecutorCoinOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode?: 'coins';\n}\n\nexport interface SerialTransactionExecutorAddressBalanceOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode: 'addressBalance';\n}\n\nexport type SerialTransactionExecutorOptions =\n\t| SerialTransactionExecutorCoinOptions\n\t| SerialTransactionExecutorAddressBalanceOptions;\n\nexport class SerialTransactionExecutor {\n\t#queue = new SerialQueue();\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#cache: CachingTransactionExecutor;\n\t#defaultGasBudget: bigint;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: SerialTransactionExecutorOptions) {\n\t\tconst { signer, defaultGasBudget = 50_000_000n, client, cache } = options;\n\t\tthis.#signer = signer;\n\t\tthis.#client = client;\n\t\tthis.#defaultGasBudget = defaultGasBudget;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient,\n\t\t\tcache,\n\t\t\tonEffects: (effects) => this.#cacheGasCoin(effects),\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\treturn this.#cache.applyEffects(effects);\n\t}\n\n\t#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {\n\t\tif (this.#gasMode === 'addressBalance' || !effects.V2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst gasCoin = getGasCoinFromEffects(effects).ref;\n\t\tif (gasCoin) {\n\t\t\tthis.#cache.cache.setCustom('gasCoin', gasCoin);\n\t\t} else {\n\t\t\tthis.#cache.cache.deleteCustom('gasCoin');\n\t\t}\n\t};\n\n\tasync buildTransaction(transaction: Transaction) {\n\t\treturn this.#queue.runTask(() => this.#buildTransaction(transaction));\n\t}\n\n\t#buildTransaction = async (transaction: Transaction) => {\n\t\tawait transaction.prepareForSerialization({\n\t\t\tclient: this.#client,\n\t\t\tsupportedIntents: ['CoinWithBalance'],\n\t\t});\n\t\tconst copy = Transaction.from(transaction);\n\n\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\tcopy.setGasPayment([]);\n\t\t\tcopy.setExpiration(await this.#getValidDuringExpiration());\n\t\t} else {\n\t\t\t// Coin mode: use cached gas coin if available\n\t\t\tconst gasCoin = await this.#cache.cache.getCustom<{\n\t\t\t\tobjectId: string;\n\t\t\t\tversion: string;\n\t\t\t\tdigest: string;\n\t\t\t}>('gasCoin');\n\n\t\t\tif (gasCoin) {\n\t\t\t\tcopy.setGasPayment([gasCoin]);\n\t\t\t}\n\t\t}\n\n\t\tcopy.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\t\tcopy.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\treturn this.#cache.buildTransaction({ transaction: copy });\n\t};\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tresetCache() {\n\t\treturn this.#cache.reset();\n\t}\n\n\twaitForLastTransaction() {\n\t\treturn this.#cache.waitForLastTransaction();\n\t}\n\n\texecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction | Uint8Array,\n\t\tinclude?: Include,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\treturn this.#queue.runTask(async () => {\n\t\t\tconst bytes = isTransaction(transaction)\n\t\t\t\t? await this.#buildTransaction(transaction)\n\t\t\t\t: transaction;\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\t\t\treturn this.#cache\n\t\t\t\t.executeTransaction({\n\t\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\t\ttransaction: bytes,\n\t\t\t\t\tinclude,\n\t\t\t\t})\n\t\t\t\t.catch(async (error) => {\n\t\t\t\t\tawait this.resetCache();\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t});\n\t}\n}\n\nexport function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\tif (!effects.V2) {\n\t\tthrow new Error('Unexpected effects version');\n\t}\n\n\tconst gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex!];\n\n\tif (!gasObjectChange) {\n\t\tthrow new Error('Gas object not found in effects');\n\t}\n\n\tconst [objectId, { outputState }] = gasObjectChange;\n\n\tif (!outputState.ObjectWrite) {\n\t\tthrow new Error('Unexpected gas object state');\n\t}\n\n\tconst [digest, owner] = outputState.ObjectWrite;\n\n\treturn {\n\t\tref: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,MAAM,EAAE,cAAc,MAAM,MAAKP,OAAQ,gBAAgB,MAAM;AAC/D,UAAO,MAAKI,MACV,mBAAmB;IACnB,YAAY,CAAC,WAAW,GAAG,qBAAqB;IAChD,aAAa;IACb;IACA,CAAC,CACD,MAAM,OAAO,UAAU;AACvB,UAAM,KAAK,YAAY;AACvB,UAAM;KACL;IACF;;;AAIJ,SAAgB,sBAAsB,SAAmD;AACxF,KAAI,CAAC,QAAQ,GACZ,OAAM,IAAI,MAAM,6BAA6B;CAG9C,MAAM,kBAAkB,QAAQ,GAAG,eAAe,QAAQ,GAAG;AAE7D,KAAI,CAAC,gBACJ,OAAM,IAAI,MAAM,kCAAkC;CAGnD,MAAM,CAAC,UAAU,EAAE,iBAAiB;AAEpC,KAAI,CAAC,YAAY,YAChB,OAAM,IAAI,MAAM,8BAA8B;CAG/C,MAAM,CAAC,QAAQ,SAAS,YAAY;AAEpC,QAAO;EACN,KAAK;GACJ;GACA;GACA,SAAS,QAAQ,GAAG;GACpB;EACD,OAAO,MAAM,gBAAgB,MAAM;EACnC"}
|
|
1
|
+
{"version":3,"file":"serial.mjs","names":["#signer","#client","#defaultGasBudget","#gasMode","#cache","#cacheGasCoin","#queue","#buildTransaction","#getValidDuringExpiration","#ensureEpochInfo","#epochInfo","#epochInfoPromise","#fetchEpochInfo"],"sources":["../../../src/transactions/executor/serial.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { bcs } from '../../bcs/index.js';\nimport type { ClientWithCoreApi } from '../../client/core.js';\nimport type { SuiClientTypes } from '../../client/types.js';\nimport type { Signer } from '../../cryptography/keypair.js';\nimport type { ObjectCacheOptions } from '../ObjectCache.js';\nimport { isTransaction, Transaction } from '../Transaction.js';\nimport { CachingTransactionExecutor } from './caching.js';\nimport { SerialQueue } from './queue.js';\n\nconst EPOCH_BOUNDARY_WINDOW = 60_000;\n\ninterface SerialTransactionExecutorBaseOptions extends Omit<ObjectCacheOptions, 'address'> {\n\tclient: ClientWithCoreApi;\n\tsigner: Signer;\n\tdefaultGasBudget?: bigint;\n}\n\nexport interface SerialTransactionExecutorCoinOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode?: 'coins';\n}\n\nexport interface SerialTransactionExecutorAddressBalanceOptions extends SerialTransactionExecutorBaseOptions {\n\tgasMode: 'addressBalance';\n}\n\nexport type SerialTransactionExecutorOptions =\n\t| SerialTransactionExecutorCoinOptions\n\t| SerialTransactionExecutorAddressBalanceOptions;\n\nexport class SerialTransactionExecutor {\n\t#queue = new SerialQueue();\n\t#signer: Signer;\n\t#client: ClientWithCoreApi;\n\t#cache: CachingTransactionExecutor;\n\t#defaultGasBudget: bigint;\n\t#gasMode: 'coins' | 'addressBalance';\n\t#epochInfo: null | {\n\t\tepoch: string;\n\t\texpiration: number;\n\t\tchainIdentifier: string;\n\t} = null;\n\t#epochInfoPromise: Promise<void> | null = null;\n\n\tconstructor(options: SerialTransactionExecutorOptions) {\n\t\tconst { signer, defaultGasBudget = 50_000_000n, client, cache } = options;\n\t\tthis.#signer = signer;\n\t\tthis.#client = client;\n\t\tthis.#defaultGasBudget = defaultGasBudget;\n\t\tthis.#gasMode = options.gasMode ?? 'coins';\n\t\tthis.#cache = new CachingTransactionExecutor({\n\t\t\tclient,\n\t\t\tcache,\n\t\t\tonEffects: (effects) => this.#cacheGasCoin(effects),\n\t\t});\n\t}\n\n\tasync applyEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\t\treturn this.#cache.applyEffects(effects);\n\t}\n\n\t#cacheGasCoin = async (effects: typeof bcs.TransactionEffects.$inferType) => {\n\t\tif (this.#gasMode === 'addressBalance' || !effects.V2) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst gasCoin = getGasCoinFromEffects(effects).ref;\n\t\tif (gasCoin) {\n\t\t\tthis.#cache.cache.setCustom('gasCoin', gasCoin);\n\t\t} else {\n\t\t\tthis.#cache.cache.deleteCustom('gasCoin');\n\t\t}\n\t};\n\n\tasync buildTransaction(transaction: Transaction) {\n\t\treturn this.#queue.runTask(() => this.#buildTransaction(transaction));\n\t}\n\n\t#buildTransaction = async (transaction: Transaction) => {\n\t\tawait transaction.prepareForSerialization({\n\t\t\tclient: this.#client,\n\t\t\tsupportedIntents: ['CoinWithBalance'],\n\t\t});\n\t\tconst copy = Transaction.from(transaction);\n\n\t\tif (this.#gasMode === 'addressBalance') {\n\t\t\tcopy.setGasPayment([]);\n\t\t\tcopy.setExpiration(await this.#getValidDuringExpiration());\n\t\t} else {\n\t\t\t// Coin mode: use cached gas coin if available\n\t\t\tconst gasCoin = await this.#cache.cache.getCustom<{\n\t\t\t\tobjectId: string;\n\t\t\t\tversion: string;\n\t\t\t\tdigest: string;\n\t\t\t}>('gasCoin');\n\n\t\t\tif (gasCoin) {\n\t\t\t\tcopy.setGasPayment([gasCoin]);\n\t\t\t}\n\t\t}\n\n\t\tcopy.setGasBudgetIfNotSet(this.#defaultGasBudget);\n\t\tcopy.setSenderIfNotSet(this.#signer.toSuiAddress());\n\n\t\treturn this.#cache.buildTransaction({ transaction: copy });\n\t};\n\n\tasync #getValidDuringExpiration() {\n\t\tawait this.#ensureEpochInfo();\n\t\tconst currentEpoch = BigInt(this.#epochInfo!.epoch);\n\t\treturn {\n\t\t\tValidDuring: {\n\t\t\t\tminEpoch: String(currentEpoch),\n\t\t\t\tmaxEpoch: String(currentEpoch + 1n),\n\t\t\t\tminTimestamp: null,\n\t\t\t\tmaxTimestamp: null,\n\t\t\t\tchain: this.#epochInfo!.chainIdentifier,\n\t\t\t\tnonce: (Math.random() * 0x100000000) >>> 0,\n\t\t\t},\n\t\t};\n\t}\n\n\tasync #ensureEpochInfo(): Promise<void> {\n\t\tif (this.#epochInfo && this.#epochInfo.expiration - EPOCH_BOUNDARY_WINDOW - Date.now() > 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (this.#epochInfoPromise) {\n\t\t\tawait this.#epochInfoPromise;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.#epochInfoPromise = this.#fetchEpochInfo();\n\t\ttry {\n\t\t\tawait this.#epochInfoPromise;\n\t\t} finally {\n\t\t\tthis.#epochInfoPromise = null;\n\t\t}\n\t}\n\n\tasync #fetchEpochInfo(): Promise<void> {\n\t\tconst [{ systemState }, { chainIdentifier }] = await Promise.all([\n\t\t\tthis.#client.core.getCurrentSystemState(),\n\t\t\tthis.#client.core.getChainIdentifier(),\n\t\t]);\n\n\t\tthis.#epochInfo = {\n\t\t\tepoch: systemState.epoch,\n\t\t\texpiration:\n\t\t\t\tNumber(systemState.epochStartTimestampMs) + Number(systemState.parameters.epochDurationMs),\n\t\t\tchainIdentifier,\n\t\t};\n\t}\n\n\tresetCache() {\n\t\treturn this.#cache.reset();\n\t}\n\n\twaitForLastTransaction() {\n\t\treturn this.#cache.waitForLastTransaction();\n\t}\n\n\texecuteTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(\n\t\ttransaction: Transaction | Uint8Array,\n\t\tinclude?: Include & SuiClientTypes.TransactionInclude,\n\t\tadditionalSignatures: string[] = [],\n\t): Promise<SuiClientTypes.TransactionResult<Include & { effects: true }>> {\n\t\treturn this.#queue.runTask(async () => {\n\t\t\tconst bytes = isTransaction(transaction)\n\t\t\t\t? await this.#buildTransaction(transaction)\n\t\t\t\t: transaction;\n\n\t\t\tconst { signature } = await this.#signer.signTransaction(bytes);\n\t\t\treturn this.#cache\n\t\t\t\t.executeTransaction({\n\t\t\t\t\tsignatures: [signature, ...additionalSignatures],\n\t\t\t\t\ttransaction: bytes,\n\t\t\t\t\tinclude,\n\t\t\t\t})\n\t\t\t\t.catch(async (error) => {\n\t\t\t\t\tawait this.resetCache();\n\t\t\t\t\tthrow error;\n\t\t\t\t});\n\t\t});\n\t}\n}\n\nexport function getGasCoinFromEffects(effects: typeof bcs.TransactionEffects.$inferType) {\n\tif (!effects.V2) {\n\t\tthrow new Error('Unexpected effects version');\n\t}\n\n\tconst gasObjectChange = effects.V2.changedObjects[effects.V2.gasObjectIndex!];\n\n\tif (!gasObjectChange) {\n\t\tthrow new Error('Gas object not found in effects');\n\t}\n\n\tconst [objectId, { outputState }] = gasObjectChange;\n\n\tif (!outputState.ObjectWrite) {\n\t\tthrow new Error('Unexpected gas object state');\n\t}\n\n\tconst [digest, owner] = outputState.ObjectWrite;\n\n\treturn {\n\t\tref: {\n\t\t\tobjectId,\n\t\t\tdigest,\n\t\t\tversion: effects.V2.lamportVersion,\n\t\t},\n\t\towner: owner.AddressOwner || owner.ObjectOwner!,\n\t};\n}\n"],"mappings":";;;;;AAYA,MAAM,wBAAwB;AAoB9B,IAAa,4BAAb,MAAuC;CACtC,SAAS,IAAI,aAAa;CAC1B;CACA;CACA;CACA;CACA;CACA,aAII;CACJ,oBAA0C;CAE1C,YAAY,SAA2C;EACtD,MAAM,EAAE,QAAQ,mBAAmB,WAAa,QAAQ,UAAU;AAClE,QAAKA,SAAU;AACf,QAAKC,SAAU;AACf,QAAKC,mBAAoB;AACzB,QAAKC,UAAW,QAAQ,WAAW;AACnC,QAAKC,QAAS,IAAI,2BAA2B;GAC5C;GACA;GACA,YAAY,YAAY,MAAKC,aAAc,QAAQ;GACnD,CAAC;;CAGH,MAAM,aAAa,SAAmD;AACrE,SAAO,MAAKD,MAAO,aAAa,QAAQ;;CAGzC,gBAAgB,OAAO,YAAsD;AAC5E,MAAI,MAAKD,YAAa,oBAAoB,CAAC,QAAQ,GAClD;EAGD,MAAM,UAAU,sBAAsB,QAAQ,CAAC;AAC/C,MAAI,QACH,OAAKC,MAAO,MAAM,UAAU,WAAW,QAAQ;MAE/C,OAAKA,MAAO,MAAM,aAAa,UAAU;;CAI3C,MAAM,iBAAiB,aAA0B;AAChD,SAAO,MAAKE,MAAO,cAAc,MAAKC,iBAAkB,YAAY,CAAC;;CAGtE,oBAAoB,OAAO,gBAA6B;AACvD,QAAM,YAAY,wBAAwB;GACzC,QAAQ,MAAKN;GACb,kBAAkB,CAAC,kBAAkB;GACrC,CAAC;EACF,MAAM,OAAO,YAAY,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3B,yBAAyB;AACxB,SAAO,MAAKA,MAAO,wBAAwB;;CAG5C,mBACC,aACA,SACA,uBAAiC,EAAE,EACsC;AACzE,SAAO,MAAKE,MAAO,QAAQ,YAAY;GACtC,MAAM,QAAQ,cAAc,YAAY,GACrC,MAAM,MAAKC,iBAAkB,YAAY,GACzC;GAEH,MAAM,EAAE,cAAc,MAAM,MAAKP,OAAQ,gBAAgB,MAAM;AAC/D,UAAO,MAAKI,MACV,mBAAmB;IACnB,YAAY,CAAC,WAAW,GAAG,qBAAqB;IAChD,aAAa;IACb;IACA,CAAC,CACD,MAAM,OAAO,UAAU;AACvB,UAAM,KAAK,YAAY;AACvB,UAAM;KACL;IACF;;;AAIJ,SAAgB,sBAAsB,SAAmD;AACxF,KAAI,CAAC,QAAQ,GACZ,OAAM,IAAI,MAAM,6BAA6B;CAG9C,MAAM,kBAAkB,QAAQ,GAAG,eAAe,QAAQ,GAAG;AAE7D,KAAI,CAAC,gBACJ,OAAM,IAAI,MAAM,kCAAkC;CAGnD,MAAM,CAAC,UAAU,EAAE,iBAAiB;AAEpC,KAAI,CAAC,YAAY,YAChB,OAAM,IAAI,MAAM,8BAA8B;CAG/C,MAAM,CAAC,QAAQ,SAAS,YAAY;AAEpC,QAAO;EACN,KAAK;GACJ;GACA;GACA,SAAS,QAAQ,GAAG;GACpB;EACD,OAAO,MAAM,gBAAgB,MAAM;EACnC"}
|
package/dist/version.mjs
CHANGED
package/dist/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.
|
|
1
|
+
{"version":3,"file":"version.mjs","names":[],"sources":["../src/version.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\n// This file is generated by genversion.mjs. Do not edit it directly.\n\nexport const PACKAGE_VERSION = '2.7.0';\nexport const TARGETED_RPC_VERSION = '1.68.0';\n"],"mappings":";AAKA,MAAa,kBAAkB;AAC/B,MAAa,uBAAuB"}
|
package/dist/zklogin/bcs.d.mts
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _mysten_bcs810 from "@mysten/bcs";
|
|
2
2
|
import { InferBcsInput } from "@mysten/bcs";
|
|
3
3
|
|
|
4
4
|
//#region src/zklogin/bcs.d.ts
|
|
5
|
-
declare const zkLoginSignature:
|
|
6
|
-
inputs:
|
|
7
|
-
proofPoints:
|
|
8
|
-
a:
|
|
5
|
+
declare const zkLoginSignature: _mysten_bcs810.BcsStruct<{
|
|
6
|
+
inputs: _mysten_bcs810.BcsStruct<{
|
|
7
|
+
proofPoints: _mysten_bcs810.BcsStruct<{
|
|
8
|
+
a: _mysten_bcs810.BcsType<string[], Iterable<string> & {
|
|
9
9
|
length: number;
|
|
10
10
|
}, string>;
|
|
11
|
-
b:
|
|
11
|
+
b: _mysten_bcs810.BcsType<string[][], Iterable<Iterable<string> & {
|
|
12
12
|
length: number;
|
|
13
13
|
}> & {
|
|
14
14
|
length: number;
|
|
15
15
|
}, string>;
|
|
16
|
-
c:
|
|
16
|
+
c: _mysten_bcs810.BcsType<string[], Iterable<string> & {
|
|
17
17
|
length: number;
|
|
18
18
|
}, string>;
|
|
19
19
|
}, string>;
|
|
20
|
-
issBase64Details:
|
|
21
|
-
value:
|
|
22
|
-
indexMod4:
|
|
20
|
+
issBase64Details: _mysten_bcs810.BcsStruct<{
|
|
21
|
+
value: _mysten_bcs810.BcsType<string, string, "string">;
|
|
22
|
+
indexMod4: _mysten_bcs810.BcsType<number, number, "u8">;
|
|
23
23
|
}, string>;
|
|
24
|
-
headerBase64:
|
|
25
|
-
addressSeed:
|
|
24
|
+
headerBase64: _mysten_bcs810.BcsType<string, string, "string">;
|
|
25
|
+
addressSeed: _mysten_bcs810.BcsType<string, string, "string">;
|
|
26
26
|
}, string>;
|
|
27
|
-
maxEpoch:
|
|
28
|
-
userSignature:
|
|
27
|
+
maxEpoch: _mysten_bcs810.BcsType<string, string | number | bigint, "u64">;
|
|
28
|
+
userSignature: _mysten_bcs810.BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
|
|
29
29
|
}, string>;
|
|
30
30
|
type ZkLoginSignature = InferBcsInput<typeof zkLoginSignature>;
|
|
31
31
|
type ZkLoginSignatureInputs = ZkLoginSignature['inputs'];
|
package/package.json
CHANGED
|
@@ -112,7 +112,12 @@ async function setGasBudget(transactionData: TransactionDataBuilder, client: Cli
|
|
|
112
112
|
// The current default is just picking _all_ coins we can which may not be ideal.
|
|
113
113
|
async function setGasPayment(transactionData: TransactionDataBuilder, client: ClientWithCoreApi) {
|
|
114
114
|
if (!transactionData.gasData.payment) {
|
|
115
|
-
const gasPayer = transactionData.gasData.owner ?? transactionData.sender
|
|
115
|
+
const gasPayer = transactionData.gasData.owner ?? transactionData.sender;
|
|
116
|
+
if (!gasPayer) {
|
|
117
|
+
throw new Error('Either a gas owner or sender must be set to determine gas payment.');
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const normalizedGasPayer = normalizeSuiAddress(gasPayer);
|
|
116
121
|
let usesGasCoin = false;
|
|
117
122
|
let withdrawals = 0n;
|
|
118
123
|
|
|
@@ -127,7 +132,7 @@ async function setGasPayment(transactionData: TransactionDataBuilder, client: Cl
|
|
|
127
132
|
? transactionData.sender
|
|
128
133
|
: gasPayer;
|
|
129
134
|
|
|
130
|
-
if (withdrawalOwner ===
|
|
135
|
+
if (withdrawalOwner && normalizeSuiAddress(withdrawalOwner) === normalizedGasPayer) {
|
|
131
136
|
if (input.FundsWithdrawal.reservation.$kind === 'MaxAmountU64') {
|
|
132
137
|
withdrawals += BigInt(input.FundsWithdrawal.reservation.MaxAmountU64);
|
|
133
138
|
}
|
|
@@ -139,13 +144,9 @@ async function setGasPayment(transactionData: TransactionDataBuilder, client: Cl
|
|
|
139
144
|
});
|
|
140
145
|
|
|
141
146
|
const [suiBalance, coins] = await Promise.all([
|
|
142
|
-
usesGasCoin
|
|
143
|
-
? null
|
|
144
|
-
: client.core.getBalance({
|
|
145
|
-
owner: transactionData.gasData.owner,
|
|
146
|
-
}),
|
|
147
|
+
usesGasCoin ? null : client.core.getBalance({ owner: gasPayer }),
|
|
147
148
|
client.core.listCoins({
|
|
148
|
-
owner:
|
|
149
|
+
owner: gasPayer,
|
|
149
150
|
coinType: SUI_TYPE_ARG,
|
|
150
151
|
}),
|
|
151
152
|
]);
|
package/src/client/core.ts
CHANGED
|
@@ -39,11 +39,11 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
abstract getObjects<Include extends SuiClientTypes.ObjectInclude =
|
|
42
|
+
abstract getObjects<Include extends SuiClientTypes.ObjectInclude = {}>(
|
|
43
43
|
options: SuiClientTypes.GetObjectsOptions<Include>,
|
|
44
44
|
): Promise<SuiClientTypes.GetObjectsResponse<Include>>;
|
|
45
45
|
|
|
46
|
-
async getObject<Include extends SuiClientTypes.ObjectInclude =
|
|
46
|
+
async getObject<Include extends SuiClientTypes.ObjectInclude = {}>(
|
|
47
47
|
options: SuiClientTypes.GetObjectOptions<Include>,
|
|
48
48
|
): Promise<SuiClientTypes.GetObjectResponse<Include>> {
|
|
49
49
|
const { objectId } = options;
|
|
@@ -64,7 +64,7 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
|
|
|
64
64
|
options: SuiClientTypes.ListCoinsOptions,
|
|
65
65
|
): Promise<SuiClientTypes.ListCoinsResponse>;
|
|
66
66
|
|
|
67
|
-
abstract listOwnedObjects<Include extends SuiClientTypes.ObjectInclude =
|
|
67
|
+
abstract listOwnedObjects<Include extends SuiClientTypes.ObjectInclude = {}>(
|
|
68
68
|
options: SuiClientTypes.ListOwnedObjectsOptions<Include>,
|
|
69
69
|
): Promise<SuiClientTypes.ListOwnedObjectsResponse<Include>>;
|
|
70
70
|
|
|
@@ -80,15 +80,15 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
|
|
|
80
80
|
options: SuiClientTypes.GetCoinMetadataOptions,
|
|
81
81
|
): Promise<SuiClientTypes.GetCoinMetadataResponse>;
|
|
82
82
|
|
|
83
|
-
abstract getTransaction<Include extends SuiClientTypes.TransactionInclude =
|
|
83
|
+
abstract getTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
|
|
84
84
|
options: SuiClientTypes.GetTransactionOptions<Include>,
|
|
85
85
|
): Promise<SuiClientTypes.TransactionResult<Include>>;
|
|
86
86
|
|
|
87
|
-
abstract executeTransaction<Include extends SuiClientTypes.TransactionInclude =
|
|
87
|
+
abstract executeTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
|
|
88
88
|
options: SuiClientTypes.ExecuteTransactionOptions<Include>,
|
|
89
89
|
): Promise<SuiClientTypes.TransactionResult<Include>>;
|
|
90
90
|
|
|
91
|
-
abstract simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude =
|
|
91
|
+
abstract simulateTransaction<Include extends SuiClientTypes.SimulateTransactionInclude = {}>(
|
|
92
92
|
options: SuiClientTypes.SimulateTransactionOptions<Include>,
|
|
93
93
|
): Promise<SuiClientTypes.SimulateTransactionResult<Include>>;
|
|
94
94
|
|
|
@@ -151,8 +151,22 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
|
|
|
151
151
|
const fieldType = parseStructTag(fieldObject.type);
|
|
152
152
|
const content = await fieldObject.content;
|
|
153
153
|
|
|
154
|
+
const nameTypeParam = fieldType.typeParams[0];
|
|
155
|
+
const isDynamicObject =
|
|
156
|
+
typeof nameTypeParam !== 'string' &&
|
|
157
|
+
nameTypeParam.module === 'dynamic_object_field' &&
|
|
158
|
+
nameTypeParam.name === 'Wrapper';
|
|
159
|
+
|
|
160
|
+
const valueBcs = content.slice(SUI_ADDRESS_LENGTH + options.name.bcs.length);
|
|
161
|
+
|
|
162
|
+
const valueType =
|
|
163
|
+
typeof fieldType.typeParams[1] === 'string'
|
|
164
|
+
? fieldType.typeParams[1]
|
|
165
|
+
: normalizeStructTag(fieldType.typeParams[1]);
|
|
166
|
+
|
|
154
167
|
return {
|
|
155
168
|
dynamicField: {
|
|
169
|
+
$kind: isDynamicObject ? 'DynamicObject' : 'DynamicField',
|
|
156
170
|
fieldId: fieldObject.objectId,
|
|
157
171
|
digest: fieldObject.digest,
|
|
158
172
|
version: fieldObject.version,
|
|
@@ -160,23 +174,19 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
|
|
|
160
174
|
previousTransaction: fieldObject.previousTransaction,
|
|
161
175
|
name: {
|
|
162
176
|
type:
|
|
163
|
-
typeof
|
|
164
|
-
? fieldType.typeParams[0]
|
|
165
|
-
: normalizeStructTag(fieldType.typeParams[0]),
|
|
177
|
+
typeof nameTypeParam === 'string' ? nameTypeParam : normalizeStructTag(nameTypeParam),
|
|
166
178
|
bcs: options.name.bcs,
|
|
167
179
|
},
|
|
168
180
|
value: {
|
|
169
|
-
type:
|
|
170
|
-
|
|
171
|
-
? fieldType.typeParams[1]
|
|
172
|
-
: normalizeStructTag(fieldType.typeParams[1]),
|
|
173
|
-
bcs: content.slice(SUI_ADDRESS_LENGTH + options.name.bcs.length),
|
|
181
|
+
type: valueType,
|
|
182
|
+
bcs: valueBcs,
|
|
174
183
|
},
|
|
175
|
-
|
|
184
|
+
childId: isDynamicObject ? bcs.Address.parse(valueBcs) : undefined,
|
|
185
|
+
} as SuiClientTypes.GetDynamicFieldResponse['dynamicField'],
|
|
176
186
|
};
|
|
177
187
|
}
|
|
178
188
|
|
|
179
|
-
async getDynamicObjectField<Include extends SuiClientTypes.ObjectInclude =
|
|
189
|
+
async getDynamicObjectField<Include extends SuiClientTypes.ObjectInclude = {}>(
|
|
180
190
|
options: SuiClientTypes.GetDynamicObjectFieldOptions<Include>,
|
|
181
191
|
): Promise<SuiClientTypes.GetDynamicObjectFieldResponse<Include>> {
|
|
182
192
|
const resolvedNameType = (
|
|
@@ -196,7 +206,7 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
|
|
|
196
206
|
});
|
|
197
207
|
|
|
198
208
|
const { object } = await this.getObject({
|
|
199
|
-
objectId:
|
|
209
|
+
objectId: dynamicField.childId!,
|
|
200
210
|
signal: options.signal,
|
|
201
211
|
include: options.include,
|
|
202
212
|
});
|
|
@@ -204,7 +214,7 @@ export abstract class CoreClient extends BaseClient implements SuiClientTypes.Tr
|
|
|
204
214
|
return { object };
|
|
205
215
|
}
|
|
206
216
|
|
|
207
|
-
async waitForTransaction<Include extends SuiClientTypes.TransactionInclude =
|
|
217
|
+
async waitForTransaction<Include extends SuiClientTypes.TransactionInclude = {}>(
|
|
208
218
|
options: SuiClientTypes.WaitForTransactionOptions<Include>,
|
|
209
219
|
): Promise<SuiClientTypes.TransactionResult<Include>> {
|
|
210
220
|
const { signal, timeout = 60 * 1000, include } = options;
|