@mysten/sui 2.2.0 → 2.3.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.
Files changed (52) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/client/client.d.mts.map +1 -1
  3. package/dist/client/client.mjs +3 -2
  4. package/dist/client/client.mjs.map +1 -1
  5. package/dist/client/core-resolver.d.mts.map +1 -1
  6. package/dist/client/core-resolver.mjs +6 -2
  7. package/dist/client/core-resolver.mjs.map +1 -1
  8. package/dist/client/errors.d.mts +15 -0
  9. package/dist/client/errors.d.mts.map +1 -0
  10. package/dist/client/errors.mjs +7 -1
  11. package/dist/client/errors.mjs.map +1 -1
  12. package/dist/client/index.d.mts +2 -1
  13. package/dist/client/index.mjs +2 -1
  14. package/dist/client/utils.d.mts.map +1 -1
  15. package/dist/client/utils.mjs +20 -14
  16. package/dist/client/utils.mjs.map +1 -1
  17. package/dist/graphql/client.d.mts.map +1 -1
  18. package/dist/graphql/core.mjs +41 -16
  19. package/dist/graphql/core.mjs.map +1 -1
  20. package/dist/graphql/generated/queries.mjs +20 -0
  21. package/dist/graphql/generated/queries.mjs.map +1 -1
  22. package/dist/grpc/core.mjs +9 -6
  23. package/dist/grpc/core.mjs.map +1 -1
  24. package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
  25. package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
  26. package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
  27. package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
  28. package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
  29. package/dist/grpc/proto/sui/rpc/v2/transaction.d.mts.map +1 -1
  30. package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
  31. package/dist/jsonRpc/core.mjs +1 -1
  32. package/dist/transactions/Transaction.d.mts +7 -7
  33. package/dist/transactions/data/internal.d.mts +109 -109
  34. package/dist/transactions/data/internal.d.mts.map +1 -1
  35. package/dist/transactions/data/v1.d.mts +220 -220
  36. package/dist/transactions/data/v1.d.mts.map +1 -1
  37. package/dist/transactions/data/v2.d.mts +16 -16
  38. package/dist/transactions/data/v2.d.mts.map +1 -1
  39. package/dist/version.mjs +1 -1
  40. package/dist/version.mjs.map +1 -1
  41. package/dist/zklogin/bcs.d.mts +14 -14
  42. package/package.json +3 -3
  43. package/src/client/client.ts +5 -2
  44. package/src/client/core-resolver.ts +7 -7
  45. package/src/client/errors.ts +13 -0
  46. package/src/client/index.ts +2 -0
  47. package/src/client/utils.ts +26 -19
  48. package/src/graphql/core.ts +47 -11
  49. package/src/graphql/generated/queries.ts +21 -1
  50. package/src/graphql/queries/transactions.graphql +20 -0
  51. package/src/grpc/core.ts +20 -4
  52. package/src/version.ts +1 -1
@@ -1,31 +1,31 @@
1
- import * as _mysten_bcs1118 from "@mysten/bcs";
1
+ import * as _mysten_bcs1111 from "@mysten/bcs";
2
2
  import { InferBcsInput } from "@mysten/bcs";
3
3
 
4
4
  //#region src/zklogin/bcs.d.ts
5
- declare const zkLoginSignature: _mysten_bcs1118.BcsStruct<{
6
- inputs: _mysten_bcs1118.BcsStruct<{
7
- proofPoints: _mysten_bcs1118.BcsStruct<{
8
- a: _mysten_bcs1118.BcsType<string[], Iterable<string> & {
5
+ declare const zkLoginSignature: _mysten_bcs1111.BcsStruct<{
6
+ inputs: _mysten_bcs1111.BcsStruct<{
7
+ proofPoints: _mysten_bcs1111.BcsStruct<{
8
+ a: _mysten_bcs1111.BcsType<string[], Iterable<string> & {
9
9
  length: number;
10
10
  }, string>;
11
- b: _mysten_bcs1118.BcsType<string[][], Iterable<Iterable<string> & {
11
+ b: _mysten_bcs1111.BcsType<string[][], Iterable<Iterable<string> & {
12
12
  length: number;
13
13
  }> & {
14
14
  length: number;
15
15
  }, string>;
16
- c: _mysten_bcs1118.BcsType<string[], Iterable<string> & {
16
+ c: _mysten_bcs1111.BcsType<string[], Iterable<string> & {
17
17
  length: number;
18
18
  }, string>;
19
19
  }, string>;
20
- issBase64Details: _mysten_bcs1118.BcsStruct<{
21
- value: _mysten_bcs1118.BcsType<string, string, "string">;
22
- indexMod4: _mysten_bcs1118.BcsType<number, number, "u8">;
20
+ issBase64Details: _mysten_bcs1111.BcsStruct<{
21
+ value: _mysten_bcs1111.BcsType<string, string, "string">;
22
+ indexMod4: _mysten_bcs1111.BcsType<number, number, "u8">;
23
23
  }, string>;
24
- headerBase64: _mysten_bcs1118.BcsType<string, string, "string">;
25
- addressSeed: _mysten_bcs1118.BcsType<string, string, "string">;
24
+ headerBase64: _mysten_bcs1111.BcsType<string, string, "string">;
25
+ addressSeed: _mysten_bcs1111.BcsType<string, string, "string">;
26
26
  }, string>;
27
- maxEpoch: _mysten_bcs1118.BcsType<string, string | number | bigint, "u64">;
28
- userSignature: _mysten_bcs1118.BcsType<Uint8Array<ArrayBufferLike>, Iterable<number>, "vector<u8>">;
27
+ maxEpoch: _mysten_bcs1111.BcsType<string, string | number | bigint, "u64">;
28
+ userSignature: _mysten_bcs1111.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
@@ -3,7 +3,7 @@
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Sui TypeScript API",
5
5
  "homepage": "https://sdk.mystenlabs.com",
6
- "version": "2.2.0",
6
+ "version": "2.3.0",
7
7
  "license": "Apache-2.0",
8
8
  "sideEffects": false,
9
9
  "files": [
@@ -151,8 +151,8 @@
151
151
  "graphql": "^16.12.0",
152
152
  "poseidon-lite": "0.2.1",
153
153
  "valibot": "^1.2.0",
154
- "@mysten/utils": "^0.3.0",
155
- "@mysten/bcs": "^2.0.1"
154
+ "@mysten/bcs": "^2.0.1",
155
+ "@mysten/utils": "^0.3.0"
156
156
  },
157
157
  "scripts": {
158
158
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
@@ -35,12 +35,15 @@ export abstract class BaseClient {
35
35
  const methodCache = new Map<string | symbol, Function>();
36
36
 
37
37
  return new Proxy(this, {
38
- get(target, prop) {
38
+ get(target, prop, receiver) {
39
39
  if (typeof prop === 'string' && prop in extensions) {
40
40
  return extensions[prop];
41
41
  }
42
- const value = Reflect.get(target, prop, target);
42
+ const value = Reflect.get(target, prop, receiver);
43
43
  if (typeof value === 'function') {
44
+ if (prop === '$extend') {
45
+ return value.bind(receiver);
46
+ }
44
47
  if (!methodCache.has(prop)) {
45
48
  methodCache.set(prop, value.bind(target));
46
49
  }
@@ -8,6 +8,7 @@ import type { ClientWithCoreApi } from './core.js';
8
8
  import { ObjectRefSchema } from '../transactions/data/internal.js';
9
9
  import type { CallArg, Command } from '../transactions/data/internal.js';
10
10
  import type { SuiClientTypes } from './types.js';
11
+ import { SimulationError } from './errors.js';
11
12
  import { Inputs } from '../transactions/Inputs.js';
12
13
  import { getPureBcsSchema, isTxContext } from '../transactions/serializer.js';
13
14
  import type { TransactionDataBuilder } from '../transactions/TransactionData.js';
@@ -87,13 +88,12 @@ async function setGasBudget(transactionData: TransactionDataBuilder, client: Cli
87
88
  });
88
89
 
89
90
  if (simulateResult.$kind === 'FailedTransaction') {
90
- const errorMessage = simulateResult.FailedTransaction.status.error?.message ?? 'Unknown error';
91
- throw new Error(
92
- `Simulation failed, could not automatically determine a budget: ${errorMessage}`,
93
- {
94
- cause: simulateResult,
95
- },
96
- );
91
+ const executionError = simulateResult.FailedTransaction.status.error ?? undefined;
92
+ const errorMessage = executionError?.message ?? 'Unknown error';
93
+ throw new SimulationError(`Transaction resolution failed: ${errorMessage}`, {
94
+ cause: simulateResult,
95
+ executionError,
96
+ });
97
97
  }
98
98
 
99
99
  const gasUsed = simulateResult.Transaction.effects!.gasUsed;
@@ -2,9 +2,22 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { ObjectResponseError } from '../jsonRpc/index.js';
5
+ import type { SuiClientTypes } from './types.js';
5
6
 
6
7
  export class SuiClientError extends Error {}
7
8
 
9
+ export class SimulationError extends SuiClientError {
10
+ executionError?: SuiClientTypes.ExecutionError;
11
+
12
+ constructor(
13
+ message: string,
14
+ options?: { cause?: unknown; executionError?: SuiClientTypes.ExecutionError },
15
+ ) {
16
+ super(message, { cause: options?.cause });
17
+ this.executionError = options?.executionError;
18
+ }
19
+ }
20
+
8
21
  export class ObjectError extends SuiClientError {
9
22
  code: string;
10
23
 
@@ -22,5 +22,7 @@ export {
22
22
  type ClientWithCoreApi,
23
23
  };
24
24
 
25
+ export { SimulationError } from './errors.js';
26
+
25
27
  export { ClientCache, type ClientCacheOptions } from './cache.js';
26
28
  export { type NamedPackagesOverrides } from './mvr.js';
@@ -39,13 +39,24 @@ export function formatMoveAbortMessage(options: {
39
39
  const parts: string[] = [];
40
40
 
41
41
  if (command != null) {
42
- parts.push(`Error in ${formatOrdinal(command + 1)} command`);
42
+ parts.push(`MoveAbort in ${formatOrdinal(command + 1)} command`);
43
+ } else {
44
+ parts.push('MoveAbort');
45
+ }
46
+
47
+ if (cleverError?.constantName) {
48
+ const errorStr = cleverError!.value
49
+ ? `'${cleverError!.constantName}': ${cleverError!.value}`
50
+ : `'${cleverError!.constantName}'`;
51
+ parts.push(errorStr);
52
+ } else {
53
+ parts.push(`abort code: ${abortCode}`);
43
54
  }
44
55
 
45
56
  if (location?.package && location?.module) {
46
57
  const pkg = location.package.startsWith('0x') ? location.package : `0x${location.package}`;
47
58
  const locationParts = [pkg, location.module, location.functionName].filter(Boolean);
48
- const locationStr = [`from '${locationParts.join('::')}'`];
59
+ const locationStr = [`in '${locationParts.join('::')}'`];
49
60
 
50
61
  if (cleverError?.lineNumber != null) {
51
62
  locationStr.push(`(line ${cleverError.lineNumber})`);
@@ -56,15 +67,6 @@ export function formatMoveAbortMessage(options: {
56
67
  parts.push(locationStr.join(' '));
57
68
  }
58
69
 
59
- if (cleverError?.constantName) {
60
- const abortStr = cleverError.value
61
- ? `abort '${cleverError.constantName}': ${cleverError.value}`
62
- : `abort '${cleverError.constantName}'`;
63
- parts.push(abortStr);
64
- } else {
65
- parts.push(`abort code: ${abortCode}`);
66
- }
67
-
68
70
  return parts.join(', ');
69
71
  }
70
72
 
@@ -118,19 +120,24 @@ function parseBcsExecutionError(failure: {
118
120
  switch (error.$kind) {
119
121
  case 'MoveAbort': {
120
122
  const [location, abortCode] = error.MoveAbort;
123
+ const moveLocation = {
124
+ package: location.module.address,
125
+ module: location.module.name,
126
+ function: location.function,
127
+ functionName: location.functionName ?? undefined,
128
+ instruction: location.instruction,
129
+ };
121
130
  return {
122
131
  $kind: 'MoveAbort',
123
- message: formatErrorMessage('MoveAbort', error.MoveAbort),
132
+ message: formatMoveAbortMessage({
133
+ command,
134
+ location: moveLocation,
135
+ abortCode: String(abortCode),
136
+ }),
124
137
  command,
125
138
  MoveAbort: {
126
139
  abortCode: String(abortCode),
127
- location: {
128
- package: location.module.address,
129
- module: location.module.name,
130
- function: location.function,
131
- functionName: location.functionName ?? undefined,
132
- instruction: location.instruction,
133
- },
140
+ location: moveLocation,
134
141
  },
135
142
  };
136
143
  }
@@ -34,11 +34,11 @@ import {
34
34
  VerifyZkLoginSignatureDocument,
35
35
  ZkLoginIntentScope,
36
36
  } from './generated/queries.js';
37
- import { ObjectError } from '../client/errors.js';
37
+ import { ObjectError, SimulationError } from '../client/errors.js';
38
38
  import { chunk, fromBase64, toBase64 } from '@mysten/utils';
39
39
  import { normalizeStructTag, normalizeSuiAddress } from '../utils/sui-types.js';
40
40
  import { deriveDynamicFieldID } from '../utils/dynamic-fields.js';
41
- import { parseTransactionEffectsBcs } from '../client/utils.js';
41
+ import { formatMoveAbortMessage, parseTransactionEffectsBcs } from '../client/utils.js';
42
42
  import type { OpenMoveTypeSignatureBody, OpenMoveTypeSignature } from './types.js';
43
43
  import {
44
44
  transactionDataToGrpcTransaction,
@@ -407,8 +407,8 @@ export class GraphQLCoreClient extends CoreClient {
407
407
  (result) => result.simulateTransaction,
408
408
  );
409
409
 
410
- if (result.error) {
411
- throw new Error(result.error);
410
+ if (result.error && !result.effects?.transaction) {
411
+ throw new SimulationError(result.error);
412
412
  }
413
413
 
414
414
  const transactionResult = parseTransaction(result.effects?.transaction!, options.include);
@@ -747,14 +747,27 @@ export class GraphQLCoreClient extends CoreClient {
747
747
  query: ResolveTransactionDocument,
748
748
  variables: {
749
749
  transaction: transactionJson,
750
- doGasSelection: !options.onlyTransactionKind,
750
+ doGasSelection:
751
+ !options.onlyTransactionKind &&
752
+ (snapshot.gasData.budget == null || snapshot.gasData.payment == null),
751
753
  },
752
754
  });
753
755
 
754
756
  handleGraphQLErrors(errors);
755
757
 
756
758
  if (data?.simulateTransaction?.error) {
757
- throw new Error(`Transaction resolution failed: ${data.simulateTransaction.error}`);
759
+ throw new SimulationError(
760
+ `Transaction resolution failed: ${data.simulateTransaction.error}`,
761
+ );
762
+ }
763
+
764
+ const transactionEffects = data?.simulateTransaction?.effects?.transaction?.effects;
765
+ if (!options.onlyTransactionKind && transactionEffects?.status === ExecutionStatus.Failure) {
766
+ const executionError = parseGraphQLExecutionError(transactionEffects.executionError);
767
+ const errorMessage = executionError?.message ?? 'Transaction failed';
768
+ throw new SimulationError(`Transaction resolution failed: ${errorMessage}`, {
769
+ executionError,
770
+ });
758
771
  }
759
772
 
760
773
  const resolvedTransactionBcs =
@@ -966,24 +979,47 @@ function parseNormalizedSuiMoveType(type: OpenMoveTypeSignature): SuiClientTypes
966
979
  function parseGraphQLExecutionError(
967
980
  executionError: GraphQLExecutionError | null | undefined,
968
981
  ): SuiClientTypes.ExecutionError {
969
- const message = executionError?.message ?? 'Transaction failed';
970
982
  const name = mapGraphQLExecutionErrorKind(executionError);
971
983
 
972
984
  if (name === 'MoveAbort' && executionError?.abortCode != null) {
985
+ const location = parseGraphQLMoveLocation(executionError);
986
+ const cleverError = parseGraphQLCleverError(executionError);
987
+ const commandMatch = executionError.message?.match(/in (\d+)\w* command/);
988
+ const command = commandMatch ? parseInt(commandMatch[1], 10) - 1 : undefined;
989
+
973
990
  return {
974
991
  $kind: 'MoveAbort',
975
- message,
992
+ message: formatMoveAbortMessage({
993
+ command,
994
+ location: location
995
+ ? {
996
+ package: location.package,
997
+ module: location.module,
998
+ functionName: location.functionName,
999
+ instruction: location.instruction,
1000
+ }
1001
+ : undefined,
1002
+ abortCode: executionError.abortCode!,
1003
+ cleverError: cleverError
1004
+ ? {
1005
+ lineNumber: cleverError.lineNumber,
1006
+ constantName: cleverError.constantName,
1007
+ value: cleverError.value,
1008
+ }
1009
+ : undefined,
1010
+ }),
1011
+ command,
976
1012
  MoveAbort: {
977
1013
  abortCode: executionError.abortCode!,
978
- location: parseGraphQLMoveLocation(executionError),
979
- cleverError: parseGraphQLCleverError(executionError),
1014
+ location,
1015
+ cleverError,
980
1016
  },
981
1017
  };
982
1018
  }
983
1019
 
984
1020
  return {
985
1021
  $kind: 'Unknown',
986
- message,
1022
+ message: executionError?.message ?? 'Transaction failed',
987
1023
  Unknown: null,
988
1024
  };
989
1025
  }
@@ -4795,7 +4795,7 @@ export type ResolveTransactionQueryVariables = Exact<{
4795
4795
  }>;
4796
4796
 
4797
4797
 
4798
- export type ResolveTransactionQuery = { __typename?: 'Query', simulateTransaction: { __typename?: 'SimulationResult', error?: string | null, effects?: { __typename?: 'TransactionEffects', transaction?: { __typename?: 'Transaction', transactionBcs?: string | null } | null } | null } };
4798
+ export type ResolveTransactionQuery = { __typename?: 'Query', simulateTransaction: { __typename?: 'SimulationResult', error?: string | null, effects?: { __typename?: 'TransactionEffects', transaction?: { __typename?: 'Transaction', transactionBcs?: string | null, effects?: { __typename?: 'TransactionEffects', status?: ExecutionStatus | null, executionError?: { __typename?: 'ExecutionError', message: string, abortCode?: string | null, identifier?: string | null, constant?: string | null, sourceLineNumber?: number | null, instructionOffset?: number | null, module?: { __typename?: 'MoveModule', name: string, package?: { __typename?: 'MovePackage', address: string } | null } | null, function?: { __typename?: 'MoveFunction', name: string } | null } | null } | null } | null } | null } };
4799
4799
 
4800
4800
  export type VerifyZkLoginSignatureQueryVariables = Exact<{
4801
4801
  bytes: Scalars['Base64']['input'];
@@ -5568,6 +5568,26 @@ export const ResolveTransactionDocument = new TypedDocumentString(`
5568
5568
  effects {
5569
5569
  transaction {
5570
5570
  transactionBcs
5571
+ effects {
5572
+ status
5573
+ executionError {
5574
+ message
5575
+ abortCode
5576
+ identifier
5577
+ constant
5578
+ sourceLineNumber
5579
+ instructionOffset
5580
+ module {
5581
+ name
5582
+ package {
5583
+ address
5584
+ }
5585
+ }
5586
+ function {
5587
+ name
5588
+ }
5589
+ }
5590
+ }
5571
5591
  }
5572
5592
  }
5573
5593
  }
@@ -150,6 +150,26 @@ query resolveTransaction($transaction: JSON!, $doGasSelection: Boolean = true) {
150
150
  effects {
151
151
  transaction {
152
152
  transactionBcs
153
+ effects {
154
+ status
155
+ executionError {
156
+ message
157
+ abortCode
158
+ identifier
159
+ constant
160
+ sourceLineNumber
161
+ instructionOffset
162
+ module {
163
+ name
164
+ package {
165
+ address
166
+ }
167
+ }
168
+ function {
169
+ name
170
+ }
171
+ }
172
+ }
153
173
  }
154
174
  }
155
175
  }
package/src/grpc/core.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import type { CoreClientOptions, SuiClientTypes } from '../client/index.js';
5
- import { CoreClient, formatMoveAbortMessage } from '../client/index.js';
5
+ import { CoreClient, formatMoveAbortMessage, SimulationError } from '../client/index.js';
6
6
  import type { SuiGrpcClient } from './client.js';
7
7
  import type { Owner } from './proto/sui/rpc/v2/owner.js';
8
8
  import { Owner_OwnerKind } from './proto/sui/rpc/v2/owner.js';
@@ -733,13 +733,16 @@ export class GrpcCoreClient extends CoreClient {
733
733
  try {
734
734
  const result = await client.transactionExecutionService.simulateTransaction({
735
735
  transaction: grpcTransaction,
736
- doGasSelection: !options.onlyTransactionKind,
736
+ doGasSelection:
737
+ !options.onlyTransactionKind &&
738
+ (snapshot.gasData.budget == null || snapshot.gasData.payment == null),
737
739
  readMask: {
738
740
  paths: [
739
741
  'transaction.transaction.sender',
740
742
  'transaction.transaction.gas_payment',
741
743
  'transaction.transaction.expiration',
742
744
  'transaction.transaction.kind',
745
+ 'transaction.effects.status',
743
746
  ],
744
747
  },
745
748
  });
@@ -747,12 +750,25 @@ export class GrpcCoreClient extends CoreClient {
747
750
  } catch (error) {
748
751
  // https://github.com/timostamm/protobuf-ts/pull/739
749
752
  if (error instanceof Error && error.message) {
750
- const decodedMessage = decodeURIComponent(error.message);
751
- throw new Error(decodedMessage, { cause: error });
753
+ throw new SimulationError(decodeURIComponent(error.message), { cause: error });
752
754
  }
753
755
  throw error;
754
756
  }
755
757
 
758
+ if (
759
+ !options.onlyTransactionKind &&
760
+ response.transaction?.effects?.status &&
761
+ !response.transaction.effects.status.success
762
+ ) {
763
+ const executionError = response.transaction.effects.status.error
764
+ ? parseGrpcExecutionError(response.transaction.effects.status.error)
765
+ : undefined;
766
+ const errorMessage = executionError?.message ?? 'Transaction failed';
767
+ throw new SimulationError(`Transaction resolution failed: ${errorMessage}`, {
768
+ executionError,
769
+ });
770
+ }
771
+
756
772
  if (!response.transaction?.transaction) {
757
773
  throw new Error('simulateTransaction did not return resolved transaction data');
758
774
  }
package/src/version.ts CHANGED
@@ -3,5 +3,5 @@
3
3
 
4
4
  // This file is generated by genversion.mjs. Do not edit it directly.
5
5
 
6
- export const PACKAGE_VERSION = '2.2.0';
6
+ export const PACKAGE_VERSION = '2.3.0';
7
7
  export const TARGETED_RPC_VERSION = '1.66.0';