@mysten/sui 1.44.0 → 1.45.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/transactions/Arguments.d.ts +2 -2
  3. package/dist/cjs/transactions/Transaction.d.ts +88 -88
  4. package/dist/cjs/transactions/TransactionData.d.ts +14 -7
  5. package/dist/cjs/transactions/TransactionData.js +93 -11
  6. package/dist/cjs/transactions/TransactionData.js.map +2 -2
  7. package/dist/cjs/transactions/data/internal.d.ts +107 -105
  8. package/dist/cjs/transactions/data/internal.js +6 -4
  9. package/dist/cjs/transactions/data/internal.js.map +2 -2
  10. package/dist/cjs/transactions/data/v1.d.ts +95 -92
  11. package/dist/cjs/transactions/data/v2.d.ts +15 -147
  12. package/dist/cjs/transactions/utils.d.ts +2 -1
  13. package/dist/cjs/transactions/utils.js +64 -1
  14. package/dist/cjs/transactions/utils.js.map +2 -2
  15. package/dist/cjs/version.d.ts +2 -2
  16. package/dist/cjs/version.js +2 -2
  17. package/dist/cjs/version.js.map +1 -1
  18. package/dist/esm/transactions/Arguments.d.ts +2 -2
  19. package/dist/esm/transactions/Transaction.d.ts +88 -88
  20. package/dist/esm/transactions/TransactionData.d.ts +14 -7
  21. package/dist/esm/transactions/TransactionData.js +94 -12
  22. package/dist/esm/transactions/TransactionData.js.map +2 -2
  23. package/dist/esm/transactions/data/internal.d.ts +107 -105
  24. package/dist/esm/transactions/data/internal.js +6 -4
  25. package/dist/esm/transactions/data/internal.js.map +2 -2
  26. package/dist/esm/transactions/data/v1.d.ts +95 -92
  27. package/dist/esm/transactions/data/v2.d.ts +15 -147
  28. package/dist/esm/transactions/utils.d.ts +2 -1
  29. package/dist/esm/transactions/utils.js +64 -1
  30. package/dist/esm/transactions/utils.js.map +2 -2
  31. package/dist/esm/version.d.ts +2 -2
  32. package/dist/esm/version.js +2 -2
  33. package/dist/esm/version.js.map +1 -1
  34. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +2 -2
  37. package/src/transactions/TransactionData.ts +137 -15
  38. package/src/transactions/data/internal.ts +21 -14
  39. package/src/transactions/utils.ts +70 -1
  40. package/src/version.ts +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mysten/sui.js
2
2
 
3
+ ## 1.45.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e3811f1: update valibot
8
+
9
+ ## 1.45.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 88bdbac: Add TranasctionData.insertTransaction method
14
+
3
15
  ## 1.44.0
4
16
 
5
17
  ### Minor Changes
@@ -29,8 +29,8 @@ export declare const Arguments: {
29
29
  type?: "object";
30
30
  };
31
31
  objectRef: (args_0: {
32
- version: string | number;
33
32
  objectId: string;
33
+ version: string | number;
34
34
  digest: string;
35
35
  }) => (tx: Transaction) => {
36
36
  $kind: "Input";
@@ -38,8 +38,8 @@ export declare const Arguments: {
38
38
  type?: "object";
39
39
  };
40
40
  receivingRef: (args_0: {
41
- version: string | number;
42
41
  objectId: string;
42
+ version: string | number;
43
43
  digest: string;
44
44
  }) => (tx: Transaction) => {
45
45
  $kind: "Input";
@@ -80,29 +80,47 @@ export declare class Transaction {
80
80
  /** @deprecated Use `getData()` instead. */
81
81
  get blockData(): {
82
82
  version: 1;
83
+ sender?: string | undefined;
84
+ expiration?: {
85
+ Epoch: number;
86
+ } | {
87
+ None: true | null;
88
+ } | null | undefined;
89
+ gasConfig: {
90
+ budget?: string | number | bigint | undefined;
91
+ price?: string | number | bigint | undefined;
92
+ payment?: {
93
+ digest: string;
94
+ objectId: string;
95
+ version: string | number | bigint;
96
+ }[] | undefined;
97
+ owner?: string | undefined;
98
+ };
83
99
  inputs: ({
84
100
  kind: "Input";
85
- value: unknown;
86
101
  index: number;
102
+ value: unknown;
87
103
  type?: "object" | undefined;
88
104
  } | {
89
- type: "pure";
90
105
  kind: "Input";
91
- value: unknown;
92
106
  index: number;
107
+ value: unknown;
108
+ type: "pure";
93
109
  })[];
94
110
  transactions: ({
111
+ kind: "MoveCall";
112
+ target: `${string}::${string}::${string}`;
95
113
  typeArguments: string[];
96
114
  arguments: ({
97
115
  kind: "Input";
98
- value: unknown;
99
116
  index: number;
117
+ value: unknown;
100
118
  type?: "object" | undefined;
101
119
  } | {
102
- type: "pure";
103
120
  kind: "Input";
104
- value: unknown;
105
121
  index: number;
122
+ value: unknown;
123
+ type: "pure";
106
124
  } | {
107
125
  kind: "GasCoin";
108
126
  } | {
@@ -113,19 +131,18 @@ export declare class Transaction {
113
131
  index: number;
114
132
  resultIndex: number;
115
133
  })[];
116
- kind: "MoveCall";
117
- target: `${string}::${string}::${string}`;
118
134
  } | {
119
- address: {
135
+ kind: "TransferObjects";
136
+ objects: ({
120
137
  kind: "Input";
121
- value: unknown;
122
138
  index: number;
139
+ value: unknown;
123
140
  type?: "object" | undefined;
124
141
  } | {
125
- type: "pure";
126
142
  kind: "Input";
127
- value: unknown;
128
143
  index: number;
144
+ value: unknown;
145
+ type: "pure";
129
146
  } | {
130
147
  kind: "GasCoin";
131
148
  } | {
@@ -135,17 +152,17 @@ export declare class Transaction {
135
152
  kind: "NestedResult";
136
153
  index: number;
137
154
  resultIndex: number;
138
- };
139
- objects: ({
155
+ })[];
156
+ address: {
140
157
  kind: "Input";
141
- value: unknown;
142
158
  index: number;
159
+ value: unknown;
143
160
  type?: "object" | undefined;
144
161
  } | {
145
- type: "pure";
146
162
  kind: "Input";
147
- value: unknown;
148
163
  index: number;
164
+ value: unknown;
165
+ type: "pure";
149
166
  } | {
150
167
  kind: "GasCoin";
151
168
  } | {
@@ -155,19 +172,19 @@ export declare class Transaction {
155
172
  kind: "NestedResult";
156
173
  index: number;
157
174
  resultIndex: number;
158
- })[];
159
- kind: "TransferObjects";
175
+ };
160
176
  } | {
177
+ kind: "SplitCoins";
161
178
  coin: {
162
179
  kind: "Input";
163
- value: unknown;
164
180
  index: number;
181
+ value: unknown;
165
182
  type?: "object" | undefined;
166
183
  } | {
167
- type: "pure";
168
184
  kind: "Input";
169
- value: unknown;
170
185
  index: number;
186
+ value: unknown;
187
+ type: "pure";
171
188
  } | {
172
189
  kind: "GasCoin";
173
190
  } | {
@@ -180,14 +197,14 @@ export declare class Transaction {
180
197
  };
181
198
  amounts: ({
182
199
  kind: "Input";
183
- value: unknown;
184
200
  index: number;
201
+ value: unknown;
185
202
  type?: "object" | undefined;
186
203
  } | {
187
- type: "pure";
188
204
  kind: "Input";
189
- value: unknown;
190
205
  index: number;
206
+ value: unknown;
207
+ type: "pure";
191
208
  } | {
192
209
  kind: "GasCoin";
193
210
  } | {
@@ -198,18 +215,18 @@ export declare class Transaction {
198
215
  index: number;
199
216
  resultIndex: number;
200
217
  })[];
201
- kind: "SplitCoins";
202
218
  } | {
219
+ kind: "MergeCoins";
203
220
  destination: {
204
221
  kind: "Input";
205
- value: unknown;
206
222
  index: number;
223
+ value: unknown;
207
224
  type?: "object" | undefined;
208
225
  } | {
209
- type: "pure";
210
226
  kind: "Input";
211
- value: unknown;
212
227
  index: number;
228
+ value: unknown;
229
+ type: "pure";
213
230
  } | {
214
231
  kind: "GasCoin";
215
232
  } | {
@@ -222,14 +239,14 @@ export declare class Transaction {
222
239
  };
223
240
  sources: ({
224
241
  kind: "Input";
225
- value: unknown;
226
242
  index: number;
243
+ value: unknown;
227
244
  type?: "object" | undefined;
228
245
  } | {
229
- type: "pure";
230
246
  kind: "Input";
231
- value: unknown;
232
247
  index: number;
248
+ value: unknown;
249
+ type: "pure";
233
250
  } | {
234
251
  kind: "GasCoin";
235
252
  } | {
@@ -240,18 +257,23 @@ export declare class Transaction {
240
257
  index: number;
241
258
  resultIndex: number;
242
259
  })[];
243
- kind: "MergeCoins";
244
260
  } | {
261
+ kind: "MakeMoveVec";
262
+ type: {
263
+ Some: import("../bcs/types.js").TypeTag;
264
+ } | {
265
+ None: true | null;
266
+ };
245
267
  objects: ({
246
268
  kind: "Input";
247
- value: unknown;
248
269
  index: number;
270
+ value: unknown;
249
271
  type?: "object" | undefined;
250
272
  } | {
251
- type: "pure";
252
273
  kind: "Input";
253
- value: unknown;
254
274
  index: number;
275
+ value: unknown;
276
+ type: "pure";
255
277
  } | {
256
278
  kind: "GasCoin";
257
279
  } | {
@@ -262,29 +284,25 @@ export declare class Transaction {
262
284
  index: number;
263
285
  resultIndex: number;
264
286
  })[];
265
- type: {
266
- Some: import("../bcs/types.js").TypeTag;
267
- } | {
268
- None: true | null;
269
- };
270
- kind: "MakeMoveVec";
271
287
  } | {
288
+ kind: "Publish";
272
289
  modules: number[][];
273
290
  dependencies: string[];
274
- kind: "Publish";
275
291
  } | {
292
+ kind: "Upgrade";
276
293
  modules: number[][];
277
294
  dependencies: string[];
295
+ packageId: string;
278
296
  ticket: {
279
297
  kind: "Input";
280
- value: unknown;
281
298
  index: number;
299
+ value: unknown;
282
300
  type?: "object" | undefined;
283
301
  } | {
284
- type: "pure";
285
302
  kind: "Input";
286
- value: unknown;
287
303
  index: number;
304
+ value: unknown;
305
+ type: "pure";
288
306
  } | {
289
307
  kind: "GasCoin";
290
308
  } | {
@@ -295,34 +313,31 @@ export declare class Transaction {
295
313
  index: number;
296
314
  resultIndex: number;
297
315
  };
298
- kind: "Upgrade";
299
- packageId: string;
300
316
  })[];
301
- gasConfig: {
302
- owner?: string | undefined;
303
- payment?: {
304
- version: string | number | bigint;
305
- objectId: string;
306
- digest: string;
307
- }[] | undefined;
308
- price?: string | number | bigint | undefined;
309
- budget?: string | number | bigint | undefined;
310
- };
311
- sender?: string | undefined;
312
- expiration?: {
313
- Epoch: number;
314
- } | {
315
- None: true | null;
316
- } | null | undefined;
317
317
  };
318
318
  /** Get a snapshot of the transaction data, in JSON form: */
319
319
  getData(): {
320
320
  version: 2;
321
+ sender?: string | null | undefined;
322
+ expiration?: import("@mysten/bcs").EnumOutputShapeWithKeys<{
323
+ None: true;
324
+ Epoch: string | number;
325
+ }, "None" | "Epoch"> | null | undefined;
326
+ gasData: {
327
+ budget: string | number | null;
328
+ price: string | number | null;
329
+ owner: string | null;
330
+ payment: {
331
+ objectId: string;
332
+ version: string | number;
333
+ digest: string;
334
+ }[] | null;
335
+ };
321
336
  inputs: import("@mysten/bcs").EnumOutputShapeWithKeys<{
322
337
  Object: import("@mysten/bcs").EnumOutputShapeWithKeys<{
323
338
  ImmOrOwnedObject: {
324
- version: string | number;
325
339
  objectId: string;
340
+ version: string | number;
326
341
  digest: string;
327
342
  };
328
343
  SharedObject: {
@@ -331,8 +346,8 @@ export declare class Transaction {
331
346
  mutable: boolean;
332
347
  };
333
348
  Receiving: {
334
- version: string | number;
335
349
  objectId: string;
350
+ version: string | number;
336
351
  digest: string;
337
352
  };
338
353
  }, "ImmOrOwnedObject" | "SharedObject" | "Receiving">;
@@ -352,9 +367,9 @@ export declare class Transaction {
352
367
  }, "Pure" | "Object" | "UnresolvedPure" | "UnresolvedObject">[];
353
368
  commands: import("@mysten/bcs").EnumOutputShapeWithKeys<{
354
369
  MoveCall: {
355
- function: string;
356
- module: string;
357
370
  package: string;
371
+ module: string;
372
+ function: string;
358
373
  typeArguments: string[];
359
374
  arguments: ({
360
375
  $kind: "GasCoin";
@@ -380,7 +395,7 @@ export declare class Transaction {
380
395
  }[] | null | undefined;
381
396
  };
382
397
  TransferObjects: {
383
- address: {
398
+ objects: ({
384
399
  $kind: "GasCoin";
385
400
  GasCoin: true;
386
401
  } | {
@@ -397,8 +412,8 @@ export declare class Transaction {
397
412
  } | {
398
413
  $kind: "NestedResult";
399
414
  NestedResult: [number, number];
400
- };
401
- objects: ({
415
+ })[];
416
+ address: {
402
417
  $kind: "GasCoin";
403
418
  GasCoin: true;
404
419
  } | {
@@ -415,7 +430,7 @@ export declare class Transaction {
415
430
  } | {
416
431
  $kind: "NestedResult";
417
432
  NestedResult: [number, number];
418
- })[];
433
+ };
419
434
  };
420
435
  SplitCoins: {
421
436
  coin: {
@@ -519,9 +534,9 @@ export declare class Transaction {
519
534
  })[];
520
535
  };
521
536
  Upgrade: {
522
- package: string;
523
537
  modules: string[];
524
538
  dependencies: string[];
539
+ package: string;
525
540
  ticket: {
526
541
  $kind: "GasCoin";
527
542
  GasCoin: true;
@@ -585,21 +600,6 @@ export declare class Transaction {
585
600
  };
586
601
  };
587
602
  }, "MoveCall" | "TransferObjects" | "SplitCoins" | "MergeCoins" | "Publish" | "MakeMoveVec" | "Upgrade" | "$Intent">[];
588
- gasData: {
589
- owner: string | null;
590
- payment: {
591
- version: string | number;
592
- objectId: string;
593
- digest: string;
594
- }[] | null;
595
- price: string | number | null;
596
- budget: string | number | null;
597
- };
598
- sender?: string | null | undefined;
599
- expiration?: import("@mysten/bcs").EnumOutputShapeWithKeys<{
600
- None: true;
601
- Epoch: string | number;
602
- }, "None" | "Epoch"> | null | undefined;
603
603
  };
604
604
  get pure(): ReturnType<typeof createPure<Argument>>;
605
605
  constructor();
@@ -2,6 +2,7 @@ import type { InferInput } from 'valibot';
2
2
  import type { Argument, CallArg, Command, GasData, TransactionExpiration, TransactionData } from './data/internal.js';
3
3
  import type { SerializedTransactionDataV1 } from './data/v1.js';
4
4
  import type { SerializedTransactionDataV2Schema } from './data/v2.js';
5
+ import type { TransactionResult } from './Transaction.js';
5
6
  export declare class TransactionDataBuilder implements TransactionData {
6
7
  static fromKindBytes(bytes: Uint8Array): TransactionDataBuilder;
7
8
  static fromBytes(bytes: Uint8Array): TransactionDataBuilder;
@@ -14,24 +15,24 @@ export declare class TransactionDataBuilder implements TransactionData {
14
15
  */
15
16
  static getDigestFromBytes(bytes: Uint8Array): string;
16
17
  get gasConfig(): {
18
+ budget: string | number | null;
19
+ price: string | number | null;
17
20
  owner: string | null;
18
21
  payment: {
19
- version: string | number;
20
22
  objectId: string;
23
+ version: string | number;
21
24
  digest: string;
22
25
  }[] | null;
23
- price: string | number | null;
24
- budget: string | number | null;
25
26
  };
26
27
  set gasConfig(value: {
28
+ budget: string | number | null;
29
+ price: string | number | null;
27
30
  owner: string | null;
28
31
  payment: {
29
- version: string | number;
30
32
  objectId: string;
33
+ version: string | number;
31
34
  digest: string;
32
35
  }[] | null;
33
- price: string | number | null;
34
- budget: string | number | null;
35
36
  });
36
37
  version: 2;
37
38
  sender: string | null;
@@ -58,7 +59,13 @@ export declare class TransactionDataBuilder implements TransactionData {
58
59
  getInputUses(index: number, fn: (arg: Argument, command: Command) => void): void;
59
60
  mapCommandArguments(index: number, fn: (arg: Argument, command: Command, commandIndex: number) => Argument): void;
60
61
  mapArguments(fn: (arg: Argument, command: Command, commandIndex: number) => Argument): void;
61
- replaceCommand(index: number, replacement: Command | Command[], resultIndex?: number): void;
62
+ replaceCommand(index: number, replacement: Command | Command[], resultIndex?: number | {
63
+ Result: number;
64
+ } | {
65
+ NestedResult: [number, number];
66
+ }): void;
67
+ replaceCommandWithTransaction(index: number, otherTransaction: TransactionData, result: TransactionResult): void;
68
+ insertTransaction(atCommandIndex: number, otherTransaction: TransactionData): void;
62
69
  getDigest(): string;
63
70
  snapshot(): TransactionData;
64
71
  shallowClone(): TransactionDataBuilder;
@@ -28,6 +28,7 @@ var import_sui_types = require("../utils/sui-types.js");
28
28
  var import_internal = require("./data/internal.js");
29
29
  var import_v1 = require("./data/v1.js");
30
30
  var import_hash = require("./hash.js");
31
+ var import_utils = require("./utils.js");
31
32
  function prepareSuiAddress(address) {
32
33
  return (0, import_sui_types.normalizeSuiAddress)(address).replace("0x", "");
33
34
  }
@@ -229,26 +230,107 @@ class TransactionDataBuilder {
229
230
  return;
230
231
  }
231
232
  const sizeDiff = replacement.length - 1;
232
- this.commands.splice(index, 1, ...replacement);
233
- if (sizeDiff !== 0) {
233
+ this.commands.splice(index, 1, ...structuredClone(replacement));
234
+ this.mapArguments((arg, _command, commandIndex) => {
235
+ if (commandIndex < index + replacement.length) {
236
+ return arg;
237
+ }
238
+ if (typeof resultIndex !== "number") {
239
+ if (arg.$kind === "Result" && arg.Result === index || arg.$kind === "NestedResult" && arg.NestedResult[0] === index) {
240
+ if (!("NestedResult" in arg) || arg.NestedResult[1] === 0) {
241
+ return (0, import_valibot.parse)(import_internal.ArgumentSchema, structuredClone(resultIndex));
242
+ } else {
243
+ throw new Error(
244
+ `Cannot replace command ${index} with a specific result type: NestedResult[${index}, ${arg.NestedResult[1]}] references a nested element that cannot be mapped to the replacement result`
245
+ );
246
+ }
247
+ }
248
+ }
249
+ switch (arg.$kind) {
250
+ case "Result":
251
+ if (arg.Result === index && typeof resultIndex === "number") {
252
+ arg.Result = resultIndex;
253
+ }
254
+ if (arg.Result > index) {
255
+ arg.Result += sizeDiff;
256
+ }
257
+ break;
258
+ case "NestedResult":
259
+ if (arg.NestedResult[0] === index && typeof resultIndex === "number") {
260
+ return {
261
+ $kind: "NestedResult",
262
+ NestedResult: [resultIndex, arg.NestedResult[1]]
263
+ };
264
+ }
265
+ if (arg.NestedResult[0] > index) {
266
+ arg.NestedResult[0] += sizeDiff;
267
+ }
268
+ break;
269
+ }
270
+ return arg;
271
+ });
272
+ }
273
+ replaceCommandWithTransaction(index, otherTransaction, result) {
274
+ if (result.$kind !== "Result" && result.$kind !== "NestedResult") {
275
+ throw new Error("Result must be of kind Result or NestedResult");
276
+ }
277
+ this.insertTransaction(index, otherTransaction);
278
+ this.replaceCommand(
279
+ index + otherTransaction.commands.length,
280
+ [],
281
+ "Result" in result ? { NestedResult: [result.Result + index, 0] } : {
282
+ NestedResult: [
283
+ result.NestedResult[0] + index,
284
+ result.NestedResult[1]
285
+ ]
286
+ }
287
+ );
288
+ }
289
+ insertTransaction(atCommandIndex, otherTransaction) {
290
+ const inputMapping = /* @__PURE__ */ new Map();
291
+ const commandMapping = /* @__PURE__ */ new Map();
292
+ for (let i = 0; i < otherTransaction.inputs.length; i++) {
293
+ const otherInput = otherTransaction.inputs[i];
294
+ const id = (0, import_utils.getIdFromCallArg)(otherInput);
295
+ let existingIndex = -1;
296
+ if (id !== void 0) {
297
+ existingIndex = this.inputs.findIndex((input) => (0, import_utils.getIdFromCallArg)(input) === id);
298
+ if (existingIndex !== -1 && this.inputs[existingIndex].Object?.SharedObject && otherInput.Object?.SharedObject) {
299
+ this.inputs[existingIndex].Object.SharedObject.mutable = this.inputs[existingIndex].Object.SharedObject.mutable || otherInput.Object.SharedObject.mutable;
300
+ }
301
+ }
302
+ if (existingIndex !== -1) {
303
+ inputMapping.set(i, existingIndex);
304
+ } else {
305
+ const newIndex = this.inputs.length;
306
+ this.inputs.push(otherInput);
307
+ inputMapping.set(i, newIndex);
308
+ }
309
+ }
310
+ for (let i = 0; i < otherTransaction.commands.length; i++) {
311
+ commandMapping.set(i, atCommandIndex + i);
312
+ }
313
+ const remappedCommands = [];
314
+ for (let i = 0; i < otherTransaction.commands.length; i++) {
315
+ const command = structuredClone(otherTransaction.commands[i]);
316
+ (0, import_utils.remapCommandArguments)(command, inputMapping, commandMapping);
317
+ remappedCommands.push(command);
318
+ }
319
+ this.commands.splice(atCommandIndex, 0, ...remappedCommands);
320
+ const sizeDiff = remappedCommands.length;
321
+ if (sizeDiff > 0) {
234
322
  this.mapArguments((arg, _command, commandIndex) => {
235
- if (commandIndex < index + replacement.length) {
323
+ if (commandIndex >= atCommandIndex && commandIndex < atCommandIndex + remappedCommands.length) {
236
324
  return arg;
237
325
  }
238
326
  switch (arg.$kind) {
239
327
  case "Result":
240
- if (arg.Result === index) {
241
- arg.Result = resultIndex;
242
- }
243
- if (arg.Result > index) {
328
+ if (arg.Result >= atCommandIndex) {
244
329
  arg.Result += sizeDiff;
245
330
  }
246
331
  break;
247
332
  case "NestedResult":
248
- if (arg.NestedResult[0] === index) {
249
- arg.NestedResult[0] = resultIndex;
250
- }
251
- if (arg.NestedResult[0] > index) {
333
+ if (arg.NestedResult[0] >= atCommandIndex) {
252
334
  arg.NestedResult[0] += sizeDiff;
253
335
  }
254
336
  break;