@mysten/sui 1.27.0 → 1.28.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 (60) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -1
  3. package/dist/cjs/experimental/client.d.ts +3 -2
  4. package/dist/cjs/experimental/client.js.map +2 -2
  5. package/dist/cjs/experimental/types.d.ts +1 -5
  6. package/dist/cjs/experimental/types.js.map +1 -1
  7. package/dist/cjs/faucet/faucet.d.ts +23 -0
  8. package/dist/cjs/faucet/faucet.js +34 -7
  9. package/dist/cjs/faucet/faucet.js.map +2 -2
  10. package/dist/cjs/faucet/index.d.ts +1 -1
  11. package/dist/cjs/faucet/index.js +2 -1
  12. package/dist/cjs/faucet/index.js.map +2 -2
  13. package/dist/cjs/transactions/data/internal.d.ts +3 -5
  14. package/dist/cjs/transactions/data/internal.js.map +2 -2
  15. package/dist/cjs/transactions/data/v2.js.map +2 -2
  16. package/dist/cjs/transactions/executor/parallel.js +2 -10
  17. package/dist/cjs/transactions/executor/parallel.js.map +2 -2
  18. package/dist/cjs/transactions/intents/CoinWithBalance.d.ts +2 -2
  19. package/dist/cjs/transactions/intents/CoinWithBalance.js +6 -1
  20. package/dist/cjs/transactions/intents/CoinWithBalance.js.map +2 -2
  21. package/dist/cjs/transactions/json-rpc-resolver.js +2 -7
  22. package/dist/cjs/transactions/json-rpc-resolver.js.map +3 -3
  23. package/dist/cjs/version.d.ts +2 -2
  24. package/dist/cjs/version.js +2 -2
  25. package/dist/cjs/version.js.map +1 -1
  26. package/dist/esm/experimental/client.d.ts +3 -2
  27. package/dist/esm/experimental/client.js.map +2 -2
  28. package/dist/esm/experimental/types.d.ts +1 -5
  29. package/dist/esm/faucet/faucet.d.ts +23 -0
  30. package/dist/esm/faucet/faucet.js +34 -7
  31. package/dist/esm/faucet/faucet.js.map +2 -2
  32. package/dist/esm/faucet/index.d.ts +1 -1
  33. package/dist/esm/faucet/index.js +3 -1
  34. package/dist/esm/faucet/index.js.map +2 -2
  35. package/dist/esm/transactions/data/internal.d.ts +3 -5
  36. package/dist/esm/transactions/data/internal.js.map +2 -2
  37. package/dist/esm/transactions/data/v2.js.map +2 -2
  38. package/dist/esm/transactions/executor/parallel.js +1 -9
  39. package/dist/esm/transactions/executor/parallel.js.map +2 -2
  40. package/dist/esm/transactions/intents/CoinWithBalance.d.ts +2 -2
  41. package/dist/esm/transactions/intents/CoinWithBalance.js +6 -1
  42. package/dist/esm/transactions/intents/CoinWithBalance.js.map +2 -2
  43. package/dist/esm/transactions/json-rpc-resolver.js +1 -6
  44. package/dist/esm/transactions/json-rpc-resolver.js.map +2 -2
  45. package/dist/esm/version.d.ts +2 -2
  46. package/dist/esm/version.js +2 -2
  47. package/dist/esm/version.js.map +1 -1
  48. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  49. package/dist/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +3 -2
  51. package/src/experimental/client.ts +15 -21
  52. package/src/experimental/types.ts +4 -11
  53. package/src/faucet/faucet.ts +68 -9
  54. package/src/faucet/index.ts +1 -0
  55. package/src/transactions/data/internal.ts +3 -4
  56. package/src/transactions/data/v2.ts +2 -3
  57. package/src/transactions/executor/parallel.ts +1 -13
  58. package/src/transactions/intents/CoinWithBalance.ts +11 -3
  59. package/src/transactions/json-rpc-resolver.ts +1 -6
  60. package/src/version.ts +2 -2
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Mysten Labs <build@mystenlabs.com>",
4
4
  "description": "Sui TypeScript API(Work in Progress)",
5
5
  "homepage": "https://sdk.mystenlabs.com",
6
- "version": "1.27.0",
6
+ "version": "1.28.0",
7
7
  "license": "Apache-2.0",
8
8
  "sideEffects": false,
9
9
  "files": [
@@ -145,7 +145,8 @@
145
145
  "graphql": "^16.9.0",
146
146
  "poseidon-lite": "^0.2.0",
147
147
  "valibot": "^0.36.0",
148
- "@mysten/bcs": "1.6.0"
148
+ "@mysten/bcs": "1.6.0",
149
+ "@mysten/utils": "0.0.0"
149
150
  },
150
151
  "scripts": {
151
152
  "clean": "rm -rf tsconfig.tsbuildinfo ./dist",
@@ -2,14 +2,13 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  /* eslint-disable @typescript-eslint/ban-types */
4
4
 
5
+ import type { Simplify, UnionToIntersection } from '@mysten/utils';
5
6
  import { ClientCache } from './cache.js';
6
7
  import type { Experimental_CoreClient } from './core.js';
7
8
  import type {
8
9
  ClientWithExtensions,
9
10
  Experimental_SuiClientTypes,
10
- Simplify,
11
11
  SuiClientRegistration,
12
- UnionToIntersection,
13
12
  } from './types.js';
14
13
 
15
14
  export abstract class Experimental_BaseClient {
@@ -38,26 +37,21 @@ export abstract class Experimental_BaseClient {
38
37
  ),
39
38
  ) as ClientWithExtensions<
40
39
  Simplify<
41
- Omit<
40
+ UnionToIntersection<
42
41
  {
43
- [K in keyof this]: this[K];
44
- },
45
- keyof Experimental_BaseClient
46
- > &
47
- UnionToIntersection<
48
- {
49
- [K in keyof Registrations]: Registrations[K] extends SuiClientRegistration<
50
- this,
51
- infer Name extends string,
52
- infer Extension
53
- >
54
- ? {
55
- [K2 in Name]: Extension;
56
- }
57
- : never;
58
- }[number]
59
- >
60
- >
42
+ [K in keyof Registrations]: Registrations[K] extends SuiClientRegistration<
43
+ this,
44
+ infer Name extends string,
45
+ infer Extension
46
+ >
47
+ ? {
48
+ [K2 in Name]: Extension;
49
+ }
50
+ : never;
51
+ }[number]
52
+ >
53
+ >,
54
+ this
61
55
  >;
62
56
  }
63
57
  }
@@ -26,17 +26,10 @@ export interface SelfRegisteringClientExtension<
26
26
  };
27
27
  }
28
28
 
29
- export type Simplify<T> = {
30
- [K in keyof T]: T[K];
31
- } & {};
32
-
33
- export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
34
- k: infer I,
35
- ) => void
36
- ? I
37
- : never;
38
-
39
- export type ClientWithExtensions<T> = Experimental_BaseClient & T;
29
+ export type ClientWithExtensions<
30
+ T,
31
+ Base extends Experimental_BaseClient = Experimental_BaseClient,
32
+ > = Base & T;
40
33
 
41
34
  export namespace Experimental_SuiClientTypes {
42
35
  export type Network = 'mainnet' | 'testnet' | 'devnet' | 'localnet' | (string & {});
@@ -29,6 +29,17 @@ type BatchStatusFaucetResponse = {
29
29
  error?: string | null;
30
30
  };
31
31
 
32
+ type FaucetResponseV2 = {
33
+ status: 'Success' | FaucetFailure;
34
+ coin_sent: FaucetCoinInfo | null;
35
+ };
36
+
37
+ type FaucetFailure = {
38
+ Failure: {
39
+ internal: string;
40
+ };
41
+ };
42
+
32
43
  type FaucetRequest = {
33
44
  host: string;
34
45
  path: string;
@@ -37,7 +48,7 @@ type FaucetRequest = {
37
48
  method: 'GET' | 'POST';
38
49
  };
39
50
 
40
- async function faucetRequest({ host, path, body, headers, method }: FaucetRequest) {
51
+ async function faucetRequest<T>({ host, path, body, headers, method }: FaucetRequest): Promise<T> {
41
52
  const endpoint = new URL(path, host).toString();
42
53
  const res = await fetch(endpoint, {
43
54
  method,
@@ -56,10 +67,7 @@ async function faucetRequest({ host, path, body, headers, method }: FaucetReques
56
67
 
57
68
  try {
58
69
  const parsed = await res.json();
59
- if (parsed.error) {
60
- throw new Error(`Faucet returns error: ${parsed.error}`);
61
- }
62
- return parsed;
70
+ return parsed as T;
63
71
  } catch (e) {
64
72
  throw new Error(
65
73
  `Encountered error when parsing response from faucet, error: ${e}, status ${res.status}, response ${res}`,
@@ -67,12 +75,15 @@ async function faucetRequest({ host, path, body, headers, method }: FaucetReques
67
75
  }
68
76
  }
69
77
 
78
+ /**
79
+ * @deprecated("Use requestSuiFromFaucetV2 instead")
80
+ */
70
81
  export async function requestSuiFromFaucetV0(input: {
71
82
  host: string;
72
83
  recipient: string;
73
84
  headers?: HeadersInit;
74
85
  }): Promise<FaucetResponse> {
75
- return faucetRequest({
86
+ const response = await faucetRequest<FaucetResponse>({
76
87
  host: input.host,
77
88
  path: '/gas',
78
89
  body: {
@@ -83,14 +94,23 @@ export async function requestSuiFromFaucetV0(input: {
83
94
  headers: input.headers,
84
95
  method: 'POST',
85
96
  });
97
+
98
+ if (response.error) {
99
+ throw new Error(`Faucet request failed: ${response.error}`);
100
+ }
101
+
102
+ return response;
86
103
  }
87
104
 
105
+ /**
106
+ * @deprecated("Use requestSuiFromFaucetV2 instead")
107
+ */
88
108
  export async function requestSuiFromFaucetV1(input: {
89
109
  host: string;
90
110
  recipient: string;
91
111
  headers?: HeadersInit;
92
112
  }): Promise<BatchFaucetResponse> {
93
- return faucetRequest({
113
+ const response = await faucetRequest<BatchFaucetResponse>({
94
114
  host: input.host,
95
115
  path: '/v1/gas',
96
116
  body: {
@@ -101,19 +121,58 @@ export async function requestSuiFromFaucetV1(input: {
101
121
  headers: input.headers,
102
122
  method: 'POST',
103
123
  });
124
+
125
+ if (response.error) {
126
+ throw new Error(`Faucet request failed: ${response.error}`);
127
+ }
128
+
129
+ return response;
130
+ }
131
+
132
+ export async function requestSuiFromFaucetV2(input: {
133
+ host: string;
134
+ recipient: string;
135
+ headers?: HeadersInit;
136
+ }) {
137
+ const response = await faucetRequest<FaucetResponseV2>({
138
+ host: input.host,
139
+ path: '/v2/gas',
140
+ body: {
141
+ FixedAmountRequest: {
142
+ recipient: input.recipient,
143
+ },
144
+ },
145
+ headers: input.headers,
146
+ method: 'POST',
147
+ });
148
+
149
+ if (response.status !== 'Success') {
150
+ throw new Error(`Faucet request failed: ${response.status.Failure.internal}`);
151
+ }
152
+
153
+ return response;
104
154
  }
105
155
 
156
+ /**
157
+ * @deprecated("Use requestSuiFromFaucetV2 which returns directly a success or failure status")
158
+ */
106
159
  export async function getFaucetRequestStatus(input: {
107
160
  host: string;
108
161
  taskId: string;
109
162
  headers?: HeadersInit;
110
- }): Promise<BatchStatusFaucetResponse> {
111
- return faucetRequest({
163
+ }) {
164
+ const response = await faucetRequest<BatchStatusFaucetResponse>({
112
165
  host: input.host,
113
166
  path: `/v1/status/${input.taskId}`,
114
167
  headers: input.headers,
115
168
  method: 'GET',
116
169
  });
170
+
171
+ if (response.error) {
172
+ throw new Error(`Faucet request failed: ${response.error}`);
173
+ }
174
+
175
+ return response;
117
176
  }
118
177
 
119
178
  export function getFaucetHost(network: 'testnet' | 'devnet' | 'localnet') {
@@ -4,6 +4,7 @@
4
4
  export {
5
5
  requestSuiFromFaucetV0,
6
6
  requestSuiFromFaucetV1,
7
+ requestSuiFromFaucetV2,
7
8
  getFaucetRequestStatus,
8
9
  getFaucetHost,
9
10
  FaucetRateLimitError,
@@ -25,17 +25,16 @@ import {
25
25
  } from 'valibot';
26
26
 
27
27
  import { isValidSuiAddress, normalizeSuiAddress } from '../../utils/sui-types.js';
28
-
29
- type Merge<T> = T extends object ? { [K in keyof T]: T[K] } : never;
28
+ import type { Simplify } from '@mysten/utils';
30
29
 
31
30
  type EnumSchema<T extends Record<string, GenericSchema<any>>> = GenericSchema<
32
31
  EnumInputShape<
33
- Merge<{
32
+ Simplify<{
34
33
  [K in keyof T]: InferInput<T[K]>;
35
34
  }>
36
35
  >,
37
36
  EnumOutputShape<
38
- Merge<{
37
+ Simplify<{
39
38
  [K in keyof T]: InferOutput<T[K]>;
40
39
  }>
41
40
  >
@@ -22,15 +22,14 @@ import {
22
22
  } from 'valibot';
23
23
 
24
24
  import { BCSBytes, JsonU64, ObjectID, ObjectRef, SuiAddress } from './internal.js';
25
-
26
- type Merge<T> = T extends object ? { [K in keyof T]: T[K] } : never;
25
+ import type { Simplify } from '@mysten/utils';
27
26
 
28
27
  function enumUnion<T extends Record<string, GenericSchema<any>>>(options: T) {
29
28
  return union(
30
29
  Object.entries(options).map(([key, value]) => object({ [key]: value })),
31
30
  ) as GenericSchema<
32
31
  EnumInputShape<
33
- Merge<{
32
+ Simplify<{
34
33
  [K in keyof T]: InferInput<T[K]>;
35
34
  }>
36
35
  >
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { toBase64 } from '@mysten/bcs';
5
-
5
+ import { promiseWithResolvers } from '@mysten/utils';
6
6
  import { bcs } from '../../bcs/index.js';
7
7
  import type { SuiObjectRef } from '../../bcs/types.js';
8
8
  import type {
@@ -456,15 +456,3 @@ export class ParallelTransactionExecutor {
456
456
  await this.#client.waitForTransaction({ digest: result.digest });
457
457
  }
458
458
  }
459
-
460
- function promiseWithResolvers<T>() {
461
- let resolve: (value: T) => void;
462
- let reject: (reason: any) => void;
463
-
464
- const promise = new Promise<T>((_resolve, _reject) => {
465
- resolve = _resolve;
466
- reject = _reject;
467
- });
468
-
469
- return { promise, resolve: resolve!, reject: reject! };
470
- }
@@ -12,7 +12,7 @@ import type { Argument } from '../data/internal.js';
12
12
  import { Inputs } from '../Inputs.js';
13
13
  import type { BuildTransactionOptions } from '../json-rpc-resolver.js';
14
14
  import { getClient } from '../json-rpc-resolver.js';
15
- import type { Transaction } from '../Transaction.js';
15
+ import type { Transaction, TransactionResult } from '../Transaction.js';
16
16
  import type { TransactionDataBuilder } from '../TransactionData.js';
17
17
 
18
18
  const COIN_WITH_BALANCE = 'CoinWithBalance';
@@ -26,12 +26,18 @@ export function coinWithBalance({
26
26
  balance: bigint | number;
27
27
  type?: string;
28
28
  useGasCoin?: boolean;
29
- }) {
29
+ }): (tx: Transaction) => TransactionResult {
30
+ let coinResult: TransactionResult | null = null;
31
+
30
32
  return (tx: Transaction) => {
33
+ if (coinResult) {
34
+ return coinResult;
35
+ }
36
+
31
37
  tx.addIntentResolver(COIN_WITH_BALANCE, resolveCoinBalance);
32
38
  const coinType = type === 'gas' ? type : normalizeStructTag(type);
33
39
 
34
- return tx.add(
40
+ coinResult = tx.add<TransactionResult>(
35
41
  Commands.Intent({
36
42
  name: COIN_WITH_BALANCE,
37
43
  inputs: {},
@@ -41,6 +47,8 @@ export function coinWithBalance({
41
47
  } satisfies InferInput<typeof CoinWithBalanceData>,
42
48
  }),
43
49
  );
50
+
51
+ return coinResult;
44
52
  };
45
53
  }
46
54
 
@@ -12,6 +12,7 @@ import type { Argument, CallArg, Command, OpenMoveTypeSignature } from './data/i
12
12
  import { Inputs } from './Inputs.js';
13
13
  import { getPureBcsSchema, isTxContext, normalizedTypeToMoveTypeSignature } from './serializer.js';
14
14
  import type { TransactionDataBuilder } from './TransactionData.js';
15
+ import { chunk } from '@mysten/utils';
15
16
 
16
17
  // The maximum objects that can be fetched at once using multiGetObjects.
17
18
  const MAX_OBJECTS_PER_FETCH = 50;
@@ -479,9 +480,3 @@ export function getClient(options: BuildTransactionOptions): SuiClient {
479
480
 
480
481
  return options.client;
481
482
  }
482
-
483
- function chunk<T>(arr: T[], size: number): T[][] {
484
- return Array.from({ length: Math.ceil(arr.length / size) }, (_, i) =>
485
- arr.slice(i * size, i * size + size),
486
- );
487
- }
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 = '1.27.0';
7
- export const TARGETED_RPC_VERSION = '1.47.0';
6
+ export const PACKAGE_VERSION = '1.28.0';
7
+ export const TARGETED_RPC_VERSION = '1.48.0';