@exodus/sui-api 1.0.1 → 1.0.3

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.
@@ -2,16 +2,10 @@
2
2
 
3
3
  import { vendorLib } from '@exodus/sui-lib'
4
4
 
5
- import { Transaction } from '../../transactions/Transaction.js'
6
- import { TransactionDataBuilder } from '../../transactions/TransactionData.js'
7
5
  import { Experimental_CoreClient } from '../core.js'
8
- import { ObjectError } from '../errors.js'
9
6
  import { suiClientResolveTransactionPlugin } from './json-rpc-resolver.js'
10
- import { parseTransactionBcs, parseTransactionEffectsBcs } from './utils.js'
11
7
 
12
8
  const { bcs } = vendorLib
13
- const { chunk } = vendorLib.utils
14
- const { fromBase64 } = vendorLib.bcs
15
9
 
16
10
  export class JSONRpcTransport extends Experimental_CoreClient {
17
11
  #jsonRpcClient
@@ -21,62 +15,6 @@ export class JSONRpcTransport extends Experimental_CoreClient {
21
15
  this.#jsonRpcClient = jsonRpcClient
22
16
  }
23
17
 
24
- async getObjects(options) {
25
- const batches = chunk(options.objectIds, 50)
26
- const results = []
27
-
28
- for (const batch of batches) {
29
- const objects = await this.#jsonRpcClient.multiGetObjects({
30
- ids: batch,
31
- options: {
32
- showOwner: true,
33
- showType: true,
34
- showBcs: true,
35
- },
36
- signal: options.signal,
37
- })
38
-
39
- for (const [idx, object] of objects.entries()) {
40
- if (object.error) {
41
- results.push(ObjectError.fromResponse(object.error, batch[idx]))
42
- } else {
43
- results.push(parseObject(object.data))
44
- }
45
- }
46
- }
47
-
48
- return {
49
- objects: results,
50
- }
51
- }
52
-
53
- async getOwnedObjects(options) {
54
- const objects = await this.#jsonRpcClient.getOwnedObjects({
55
- owner: options.address,
56
- limit: options.limit,
57
- cursor: options.cursor,
58
- options: {
59
- showOwner: true,
60
- showType: true,
61
- showBcs: true,
62
- },
63
- filter: options.type ? { StructType: options.type } : null,
64
- signal: options.signal,
65
- })
66
-
67
- return {
68
- objects: objects.data.map((result) => {
69
- if (result.error) {
70
- throw ObjectError.fromResponse(result.error, options.address)
71
- }
72
-
73
- return parseObject(result.data)
74
- }),
75
- hasNextPage: objects.hasNextPage,
76
- cursor: objects.nextCursor ?? null,
77
- }
78
- }
79
-
80
18
  async getCoins(options) {
81
19
  const coins = await this.#jsonRpcClient.getCoins({
82
20
  owner: options.address,
@@ -144,67 +82,6 @@ export class JSONRpcTransport extends Experimental_CoreClient {
144
82
  }
145
83
  }
146
84
 
147
- async getTransaction(options) {
148
- const transaction = await this.#jsonRpcClient.getTransactionBlock({
149
- digest: options.digest,
150
- options: {
151
- showRawInput: true,
152
- showObjectChanges: true,
153
- showRawEffects: true,
154
- showEvents: true,
155
- showEffects: true,
156
- },
157
- signal: options.signal,
158
- })
159
-
160
- return {
161
- transaction: parseTransaction(transaction),
162
- }
163
- }
164
-
165
- async executeTransaction(options) {
166
- const transaction = await this.#jsonRpcClient.executeTransactionBlock({
167
- transactionBlock: options.transaction,
168
- signature: options.signatures,
169
- options: {
170
- showRawEffects: true,
171
- showEvents: true,
172
- showObjectChanges: true,
173
- showRawInput: true,
174
- showEffects: true,
175
- },
176
- signal: options.signal,
177
- })
178
-
179
- return {
180
- transaction: parseTransaction(transaction),
181
- }
182
- }
183
-
184
- async dryRunTransaction(options) {
185
- const tx = Transaction.from(options.transaction)
186
- const result = await this.#jsonRpcClient.dryRunTransactionBlock({
187
- transactionBlock: options.transaction,
188
- signal: options.signal,
189
- })
190
-
191
- const { effects, objectTypes } = parseTransactionEffectsJson({
192
- effects: result.effects,
193
- objectChanges: result.objectChanges,
194
- })
195
-
196
- return {
197
- transaction: {
198
- digest: await tx.getDigest(),
199
- epoch: null,
200
- effects,
201
- objectTypes: Promise.resolve(objectTypes),
202
- signatures: [],
203
- transaction: parseTransactionBcs(options.transaction),
204
- },
205
- }
206
- }
207
-
208
85
  async getReferenceGasPrice(options) {
209
86
  const referenceGasPrice = await this.#jsonRpcClient.getReferenceGasPrice({
210
87
  signal: options?.signal,
@@ -214,286 +91,11 @@ export class JSONRpcTransport extends Experimental_CoreClient {
214
91
  }
215
92
  }
216
93
 
217
- async getDynamicFields(options) {
218
- const dynamicFields = await this.#jsonRpcClient.getDynamicFields({
219
- parentId: options.parentId,
220
- limit: options.limit,
221
- cursor: options.cursor,
222
- })
223
-
224
- return {
225
- dynamicFields: dynamicFields.data.map((dynamicField) => {
226
- return {
227
- id: dynamicField.objectId,
228
- type: dynamicField.objectType,
229
- name: {
230
- type: dynamicField.name.type,
231
- bcs: fromBase64(dynamicField.bcsName),
232
- },
233
- }
234
- }),
235
- hasNextPage: dynamicFields.hasNextPage,
236
- cursor: dynamicFields.nextCursor,
237
- }
238
- }
239
-
240
- async verifyZkLoginSignature(options) {
241
- const result = await this.#jsonRpcClient.verifyZkLoginSignature({
242
- bytes: options.bytes,
243
- signature: options.signature,
244
- intentScope: options.intentScope,
245
- author: options.author,
246
- })
247
-
248
- return {
249
- success: result.success,
250
- errors: result.errors,
251
- }
252
- }
253
-
254
- resolveNameServiceNames(options) {
255
- return this.#jsonRpcClient.resolveNameServiceNames(options)
256
- }
257
-
258
94
  resolveTransactionPlugin() {
259
95
  return suiClientResolveTransactionPlugin(this.#jsonRpcClient)
260
96
  }
261
97
  }
262
98
 
263
- function parseObject(object) {
264
- return {
265
- id: object.objectId,
266
- version: object.version,
267
- digest: object.digest,
268
- type: object.type,
269
- content: Promise.resolve(
270
- object.bcs?.dataType === 'moveObject' ? fromBase64(object.bcs.bcsBytes) : new Uint8Array()
271
- ),
272
- owner: parseOwner(object.owner),
273
- }
274
- }
275
-
276
- function parseOwner(owner) {
277
- if (owner === 'Immutable') {
278
- return {
279
- $kind: 'Immutable',
280
- Immutable: true,
281
- }
282
- }
283
-
284
- if ('ConsensusAddressOwner' in owner) {
285
- return {
286
- $kind: 'ConsensusAddressOwner',
287
- ConsensusAddressOwner: {
288
- owner: owner.ConsensusAddressOwner.owner,
289
- startVersion: owner.ConsensusAddressOwner.start_version,
290
- },
291
- }
292
- }
293
-
294
- if ('AddressOwner' in owner) {
295
- return {
296
- $kind: 'AddressOwner',
297
- AddressOwner: owner.AddressOwner,
298
- }
299
- }
300
-
301
- if ('ObjectOwner' in owner) {
302
- return {
303
- $kind: 'ObjectOwner',
304
- ObjectOwner: owner.ObjectOwner,
305
- }
306
- }
307
-
308
- if ('Shared' in owner) {
309
- return {
310
- $kind: 'Shared',
311
- Shared: {
312
- initialSharedVersion: owner.Shared.initial_shared_version,
313
- },
314
- }
315
- }
316
-
317
- throw new Error(`Unknown owner type: ${JSON.stringify(owner)}`)
318
- }
319
-
320
- function parseTransaction(transaction) {
321
- const parsedTx = bcs.SenderSignedData.parse(fromBase64(transaction.rawTransaction))[0]
322
- const objectTypes = Object.create(null)
323
-
324
- transaction.objectChanges?.forEach((change) => {
325
- if (change.type !== 'published') {
326
- objectTypes[change.objectId] = change.objectType
327
- }
328
- })
329
-
330
- const bytes = bcs.TransactionData.serialize(parsedTx.intentMessage.value).toBytes()
331
-
332
- const data = TransactionDataBuilder.restore({
333
- version: 2,
334
- sender: parsedTx.intentMessage.value.V1.sender,
335
- expiration: parsedTx.intentMessage.value.V1.expiration,
336
- gasData: parsedTx.intentMessage.value.V1.gasData,
337
- inputs: parsedTx.intentMessage.value.V1.kind.ProgrammableTransaction.inputs,
338
- commands: parsedTx.intentMessage.value.V1.kind.ProgrammableTransaction.commands,
339
- })
340
-
341
- return {
342
- digest: transaction.digest,
343
- epoch: transaction.effects?.executedEpoch ?? null,
344
- effects: parseTransactionEffectsBcs(new Uint8Array(transaction.rawEffects)),
345
- objectTypes: Promise.resolve(objectTypes),
346
- transaction: {
347
- ...data,
348
- bcs: bytes,
349
- },
350
- signatures: parsedTx.txSignatures,
351
- }
352
- }
353
-
354
- function parseTransactionEffectsJson({ bytes, effects, objectChanges }) {
355
- const changedObjects = []
356
- const unchangedSharedObjects = []
357
- const objectTypes = Object.create(null)
358
-
359
- objectChanges?.forEach((change) => {
360
- switch (change.type) {
361
- case 'published':
362
- changedObjects.push({
363
- id: change.packageId,
364
- inputState: 'DoesNotExist',
365
- inputVersion: null,
366
- inputDigest: null,
367
- inputOwner: null,
368
- outputState: 'PackageWrite',
369
- outputVersion: change.version,
370
- outputDigest: change.digest,
371
- outputOwner: null,
372
- idOperation: 'Created',
373
- })
374
- break
375
- case 'transferred':
376
- changedObjects.push({
377
- id: change.objectId,
378
- inputState: 'Exists',
379
- inputVersion: change.version,
380
- inputDigest: change.digest,
381
- inputOwner: {
382
- $kind: 'AddressOwner',
383
- AddressOwner: change.sender,
384
- },
385
- outputState: 'ObjectWrite',
386
- outputVersion: change.version,
387
- outputDigest: change.digest,
388
- outputOwner: parseOwner(change.recipient),
389
- idOperation: 'None',
390
- })
391
- objectTypes[change.objectId] = change.objectType
392
- break
393
- case 'mutated':
394
- changedObjects.push({
395
- id: change.objectId,
396
- inputState: 'Exists',
397
- inputVersion: change.previousVersion,
398
- inputDigest: null,
399
- inputOwner: parseOwner(change.owner),
400
- outputState: 'ObjectWrite',
401
- outputVersion: change.version,
402
- outputDigest: change.digest,
403
- outputOwner: parseOwner(change.owner),
404
- idOperation: 'None',
405
- })
406
- objectTypes[change.objectId] = change.objectType
407
- break
408
- case 'deleted':
409
- changedObjects.push({
410
- id: change.objectId,
411
- inputState: 'Exists',
412
- inputVersion: change.version,
413
- inputDigest: effects.deleted?.find((d) => d.objectId === change.objectId)?.digest ?? null,
414
- inputOwner: null,
415
- outputState: 'DoesNotExist',
416
- outputVersion: null,
417
- outputDigest: null,
418
- outputOwner: null,
419
- idOperation: 'Deleted',
420
- })
421
- objectTypes[change.objectId] = change.objectType
422
- break
423
- case 'wrapped':
424
- changedObjects.push({
425
- id: change.objectId,
426
- inputState: 'Exists',
427
- inputVersion: change.version,
428
- inputDigest: null,
429
- inputOwner: {
430
- $kind: 'AddressOwner',
431
- AddressOwner: change.sender,
432
- },
433
- outputState: 'ObjectWrite',
434
- outputVersion: change.version,
435
- outputDigest:
436
- effects.wrapped?.find((w) => w.objectId === change.objectId)?.digest ?? null,
437
- outputOwner: {
438
- $kind: 'ObjectOwner',
439
- ObjectOwner: change.sender,
440
- },
441
- idOperation: 'None',
442
- })
443
- objectTypes[change.objectId] = change.objectType
444
- break
445
- case 'created':
446
- changedObjects.push({
447
- id: change.objectId,
448
- inputState: 'DoesNotExist',
449
- inputVersion: null,
450
- inputDigest: null,
451
- inputOwner: null,
452
- outputState: 'ObjectWrite',
453
- outputVersion: change.version,
454
- outputDigest: change.digest,
455
- outputOwner: parseOwner(change.owner),
456
- idOperation: 'Created',
457
- })
458
- objectTypes[change.objectId] = change.objectType
459
- break
460
- }
461
- })
462
-
463
- return {
464
- objectTypes,
465
- effects: {
466
- bcs: bytes ?? null,
467
- digest: effects.transactionDigest,
468
- version: 2,
469
- status:
470
- effects.status.status === 'success'
471
- ? { success: true, error: null }
472
- : { success: false, error: effects.status.error },
473
- gasUsed: effects.gasUsed,
474
- transactionDigest: effects.transactionDigest,
475
- gasObject: {
476
- id: effects.gasObject?.reference.objectId,
477
- inputState: 'Exists',
478
- inputVersion: null,
479
- inputDigest: null,
480
- inputOwner: null,
481
- outputState: 'ObjectWrite',
482
- outputVersion: effects.gasObject.reference.version,
483
- outputDigest: effects.gasObject.reference.digest,
484
- outputOwner: parseOwner(effects.gasObject.owner),
485
- idOperation: 'None',
486
- },
487
- eventsDigest: effects.eventsDigest ?? null,
488
- dependencies: effects.dependencies ?? [],
489
- lamportVersion: effects.gasObject.reference.version,
490
- changedObjects,
491
- unchangedSharedObjects,
492
- auxiliaryDataDigest: null,
493
- },
494
- }
495
- }
496
-
497
99
  const Balance = bcs.struct('Balance', {
498
100
  value: bcs.u64(),
499
101
  })
@@ -6,12 +6,6 @@ import { Argument } from './data/internal.js'
6
6
 
7
7
  const { toBase64, normalizeSuiObjectId } = vendorLib.utils
8
8
 
9
- var UpgradePolicy = /* @__PURE__ */ ((UpgradePolicy2) => {
10
- UpgradePolicy2[(UpgradePolicy2['COMPATIBLE'] = 0)] = 'COMPATIBLE'
11
- UpgradePolicy2[(UpgradePolicy2['ADDITIVE'] = 128)] = 'ADDITIVE'
12
- UpgradePolicy2[(UpgradePolicy2['DEP_ONLY'] = 192)] = 'DEP_ONLY'
13
- return UpgradePolicy2
14
- })(Object.create(null))
15
9
  const Commands = {
16
10
  MoveCall(input) {
17
11
  const [pkg, mod = '', fn = ''] =
@@ -104,5 +98,5 @@ const Commands = {
104
98
  },
105
99
  }
106
100
 
107
- export { Commands, UpgradePolicy }
101
+ export { Commands }
108
102
  // # sourceMappingURL=Commands.js.map
@@ -5,7 +5,6 @@ import { vendorLib } from '@exodus/sui-lib'
5
5
  import { is, parse } from '../valibot.js'
6
6
  import { Commands } from './Commands.js'
7
7
  import { Argument, NormalizedCallArg, ObjectRef, TransactionExpiration } from './data/internal.js'
8
- import { serializeV1TransactionData } from './data/v1.js'
9
8
  import { SerializedTransactionDataV2 } from './data/v2.js'
10
9
  import { Inputs } from './Inputs.js'
11
10
  import { createObjectMethods } from './object.js'
@@ -321,11 +320,6 @@ const _Transaction = class _Transaction {
321
320
  )
322
321
  }
323
322
 
324
- /** @deprecated Use `getData()` instead. */
325
- get blockData() {
326
- return serializeV1TransactionData(__privateGet(this, _data).snapshot())
327
- }
328
-
329
323
  /** Get a snapshot of the transaction data, in JSON form: */
330
324
  getData() {
331
325
  return __privateGet(this, _data).snapshot()
@@ -519,14 +513,6 @@ const _Transaction = class _Transaction {
519
513
  )
520
514
  }
521
515
 
522
- /**
523
- * @deprecated Use toJSON instead.
524
- * For synchronous serialization, you can use `getData()`
525
- */
526
- serialize() {
527
- return JSON.stringify(serializeV1TransactionData(__privateGet(this, _data).snapshot()))
528
- }
529
-
530
516
  async toJSON(options = Object.create(null)) {
531
517
  await this.prepareForSerialization(options)
532
518
  const fullyResolved = this.isFullyResolved()
@@ -77,13 +77,6 @@ const GasData = object({
77
77
  owner: nullable(SuiAddress),
78
78
  payment: nullable(array(ObjectRef)),
79
79
  })
80
- const StructTag = object({
81
- address: string(),
82
- module: string(),
83
- name: string(),
84
- // type_params in rust, should be updated to use camelCase
85
- typeParams: array(string()),
86
- })
87
80
  const OpenMoveTypeSignatureBody = union([
88
81
  literal('address'),
89
82
  literal('bool'),
@@ -197,19 +190,12 @@ const TransactionData = object({
197
190
  })
198
191
 
199
192
  export {
200
- $Intent,
201
193
  Argument,
202
194
  BCSBytes,
203
- Command,
204
- GasData,
205
195
  JsonU64,
206
196
  NormalizedCallArg,
207
- ObjectArg,
208
197
  ObjectID,
209
198
  ObjectRef,
210
- OpenMoveTypeSignature,
211
- OpenMoveTypeSignatureBody,
212
- StructTag,
213
199
  SuiAddress,
214
200
  TransactionData,
215
201
  TransactionExpiration,