@exodus/sui-api 0.1.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 (44) hide show
  1. package/README.md +20 -0
  2. package/package.json +53 -0
  3. package/src/api.js +198 -0
  4. package/src/balances.js +22 -0
  5. package/src/basic-account-state.js +11 -0
  6. package/src/create-unsigned-tx.js +60 -0
  7. package/src/get-fee-async.js +62 -0
  8. package/src/get-fee.js +10 -0
  9. package/src/index.js +9 -0
  10. package/src/sui-no-history-monitor.js +277 -0
  11. package/src/transform-tx.js +100 -0
  12. package/src/tx-send.js +249 -0
  13. package/src/vendors/client/client.js +891 -0
  14. package/src/vendors/client/errors.js +38 -0
  15. package/src/vendors/client/http-transport.js +108 -0
  16. package/src/vendors/client/index.js +1 -0
  17. package/src/vendors/client/rpc-websocket-client.js +178 -0
  18. package/src/vendors/experimental/cache.js +89 -0
  19. package/src/vendors/experimental/client.js +27 -0
  20. package/src/vendors/experimental/core.js +105 -0
  21. package/src/vendors/experimental/errors.js +32 -0
  22. package/src/vendors/experimental/index.js +5 -0
  23. package/src/vendors/experimental/mvr.js +443 -0
  24. package/src/vendors/experimental/transports/json-rpc-resolver.js +359 -0
  25. package/src/vendors/experimental/transports/jsonRPC.js +504 -0
  26. package/src/vendors/experimental/transports/utils.js +90 -0
  27. package/src/vendors/transactions/Arguments.js +22 -0
  28. package/src/vendors/transactions/Commands.js +108 -0
  29. package/src/vendors/transactions/Inputs.js +59 -0
  30. package/src/vendors/transactions/ObjectCache.js +272 -0
  31. package/src/vendors/transactions/Transaction.js +843 -0
  32. package/src/vendors/transactions/TransactionData.js +293 -0
  33. package/src/vendors/transactions/data/internal.js +218 -0
  34. package/src/vendors/transactions/data/v1.js +538 -0
  35. package/src/vendors/transactions/data/v2.js +119 -0
  36. package/src/vendors/transactions/hash.js +12 -0
  37. package/src/vendors/transactions/index.js +1 -0
  38. package/src/vendors/transactions/object.js +22 -0
  39. package/src/vendors/transactions/plugins/NamedPackagesPlugin.js +49 -0
  40. package/src/vendors/transactions/pure.js +40 -0
  41. package/src/vendors/transactions/resolve.js +95 -0
  42. package/src/vendors/transactions/serializer.js +203 -0
  43. package/src/vendors/transactions/utils.js +67 -0
  44. package/src/vendors/valibot.js +7920 -0
@@ -0,0 +1,891 @@
1
+ /* eslint-disable unicorn/no-await-expression-member */
2
+ /* eslint-disable no-return-await */
3
+ /* eslint-disable camelcase */
4
+ import { vendorLib } from '@exodus/sui-lib'
5
+
6
+ import { Experimental_BaseClient } from '../experimental/client.js'
7
+ import { hasMvrName } from '../experimental/mvr.js'
8
+ import { JSONRpcTransport } from '../experimental/transports/jsonRPC.js'
9
+ import { isTransaction } from '../transactions/Transaction.js'
10
+ import { SuiHTTPTransport } from './http-transport.js'
11
+
12
+ const { fromBase58, toBase64, toHex } = vendorLib.utils
13
+
14
+ const {
15
+ isValidSuiAddress,
16
+ isValidSuiObjectId,
17
+ isValidTransactionDigest,
18
+ normalizeSuiAddress,
19
+ normalizeSuiObjectId,
20
+ } = vendorLib.utils
21
+
22
+ const { isValidNamedPackage, normalizeSuiNSName } = vendorLib.utils
23
+
24
+ class Signer {
25
+ toSuiAddress() {
26
+ return this.getPublicKey().toSuiAddress()
27
+ }
28
+ }
29
+ const SUI_CLIENT_BRAND = Symbol.for('@mysten/SuiClient')
30
+
31
+ function isSuiClient(client) {
32
+ return typeof client === 'object' && client !== null && client[SUI_CLIENT_BRAND] === true
33
+ }
34
+
35
+ class SuiClient extends Experimental_BaseClient {
36
+ /**
37
+ * Establish a connection to a Sui RPC endpoint
38
+ *
39
+ * @param options configuration options for the API Client
40
+ */
41
+ constructor(options) {
42
+ super({ network: options.network ?? 'unknown' })
43
+ this.jsonRpc = this
44
+ this.transport = options.transport ?? new SuiHTTPTransport({ url: options.url })
45
+ this.core = new JSONRpcTransport({
46
+ jsonRpcClient: this,
47
+ mvr: options.mvr,
48
+ })
49
+ }
50
+
51
+ get [SUI_CLIENT_BRAND]() {
52
+ return true
53
+ }
54
+
55
+ async getRpcApiVersion({ signal } = Object.create(null)) {
56
+ const resp = await this.transport.request({
57
+ method: 'rpc.discover',
58
+ params: [],
59
+ signal,
60
+ })
61
+ return resp.info.version
62
+ }
63
+
64
+ /**
65
+ * Get all Coin<`coin_type`> objects owned by an address.
66
+ */
67
+ async getCoins({ coinType, owner, cursor, limit, signal }) {
68
+ if (!owner || !isValidSuiAddress(normalizeSuiAddress(owner))) {
69
+ throw new Error('Invalid Sui address')
70
+ }
71
+
72
+ if (coinType && hasMvrName(coinType)) {
73
+ coinType = (
74
+ await this.core.mvr.resolveType({
75
+ type: coinType,
76
+ })
77
+ ).type
78
+ }
79
+
80
+ return await this.transport.request({
81
+ method: 'suix_getCoins',
82
+ params: [owner, coinType, cursor, limit],
83
+ signal,
84
+ })
85
+ }
86
+
87
+ /**
88
+ * Get all Coin objects owned by an address.
89
+ */
90
+ async getAllCoins(input) {
91
+ if (!input.owner || !isValidSuiAddress(normalizeSuiAddress(input.owner))) {
92
+ throw new Error('Invalid Sui address')
93
+ }
94
+
95
+ return await this.transport.request({
96
+ method: 'suix_getAllCoins',
97
+ params: [input.owner, input.cursor, input.limit],
98
+ signal: input.signal,
99
+ })
100
+ }
101
+
102
+ /**
103
+ * Get the total coin balance for one coin type, owned by the address owner.
104
+ */
105
+ async getBalance({ owner, coinType, signal }) {
106
+ if (!owner || !isValidSuiAddress(normalizeSuiAddress(owner))) {
107
+ throw new Error('Invalid Sui address')
108
+ }
109
+
110
+ if (coinType && hasMvrName(coinType)) {
111
+ coinType = (
112
+ await this.core.mvr.resolveType({
113
+ type: coinType,
114
+ })
115
+ ).type
116
+ }
117
+
118
+ return await this.transport.request({
119
+ method: 'suix_getBalance',
120
+ params: [owner, coinType],
121
+ signal,
122
+ })
123
+ }
124
+
125
+ /**
126
+ * Get the total coin balance for all coin types, owned by the address owner.
127
+ */
128
+ async getAllBalances(input) {
129
+ if (!input.owner || !isValidSuiAddress(normalizeSuiAddress(input.owner))) {
130
+ throw new Error('Invalid Sui address')
131
+ }
132
+
133
+ return await this.transport.request({
134
+ method: 'suix_getAllBalances',
135
+ params: [input.owner],
136
+ signal: input.signal,
137
+ })
138
+ }
139
+
140
+ /**
141
+ * Fetch CoinMetadata for a given coin type
142
+ */
143
+ async getCoinMetadata({ coinType, signal }) {
144
+ if (coinType && hasMvrName(coinType)) {
145
+ coinType = (
146
+ await this.core.mvr.resolveType({
147
+ type: coinType,
148
+ })
149
+ ).type
150
+ }
151
+
152
+ return await this.transport.request({
153
+ method: 'suix_getCoinMetadata',
154
+ params: [coinType],
155
+ signal,
156
+ })
157
+ }
158
+
159
+ /**
160
+ * Fetch total supply for a coin
161
+ */
162
+ async getTotalSupply({ coinType, signal }) {
163
+ if (coinType && hasMvrName(coinType)) {
164
+ coinType = (
165
+ await this.core.mvr.resolveType({
166
+ type: coinType,
167
+ })
168
+ ).type
169
+ }
170
+
171
+ return await this.transport.request({
172
+ method: 'suix_getTotalSupply',
173
+ params: [coinType],
174
+ signal,
175
+ })
176
+ }
177
+
178
+ /**
179
+ * Invoke any RPC method
180
+ * @param method the method to be invoked
181
+ * @param args the arguments to be passed to the RPC request
182
+ */
183
+ async call(method, params, { signal } = Object.create(null)) {
184
+ return await this.transport.request({ method, params, signal })
185
+ }
186
+
187
+ /**
188
+ * Get Move function argument types like read, write and full access
189
+ */
190
+ async getMoveFunctionArgTypes({ package: pkg, module, function: fn, signal }) {
191
+ if (pkg && isValidNamedPackage(pkg)) {
192
+ pkg = (
193
+ await this.core.mvr.resolvePackage({
194
+ package: pkg,
195
+ })
196
+ ).package
197
+ }
198
+
199
+ return await this.transport.request({
200
+ method: 'sui_getMoveFunctionArgTypes',
201
+ params: [pkg, module, fn],
202
+ signal,
203
+ })
204
+ }
205
+
206
+ /**
207
+ * Get a map from module name to
208
+ * structured representations of Move modules
209
+ */
210
+ async getNormalizedMoveModulesByPackage({ package: pkg, signal }) {
211
+ if (pkg && isValidNamedPackage(pkg)) {
212
+ pkg = (
213
+ await this.core.mvr.resolvePackage({
214
+ package: pkg,
215
+ })
216
+ ).package
217
+ }
218
+
219
+ return await this.transport.request({
220
+ method: 'sui_getNormalizedMoveModulesByPackage',
221
+ params: [pkg],
222
+ signal,
223
+ })
224
+ }
225
+
226
+ /**
227
+ * Get a structured representation of Move module
228
+ */
229
+ async getNormalizedMoveModule({ package: pkg, module, signal }) {
230
+ if (pkg && isValidNamedPackage(pkg)) {
231
+ pkg = (
232
+ await this.core.mvr.resolvePackage({
233
+ package: pkg,
234
+ })
235
+ ).package
236
+ }
237
+
238
+ return await this.transport.request({
239
+ method: 'sui_getNormalizedMoveModule',
240
+ params: [pkg, module],
241
+ signal,
242
+ })
243
+ }
244
+
245
+ /**
246
+ * Get a structured representation of Move function
247
+ */
248
+ async getNormalizedMoveFunction({ package: pkg, module, function: fn, signal }) {
249
+ if (pkg && isValidNamedPackage(pkg)) {
250
+ pkg = (
251
+ await this.core.mvr.resolvePackage({
252
+ package: pkg,
253
+ })
254
+ ).package
255
+ }
256
+
257
+ return await this.transport.request({
258
+ method: 'sui_getNormalizedMoveFunction',
259
+ params: [pkg, module, fn],
260
+ signal,
261
+ })
262
+ }
263
+
264
+ /**
265
+ * Get a structured representation of Move struct
266
+ */
267
+ async getNormalizedMoveStruct({ package: pkg, module, struct, signal }) {
268
+ if (pkg && isValidNamedPackage(pkg)) {
269
+ pkg = (
270
+ await this.core.mvr.resolvePackage({
271
+ package: pkg,
272
+ })
273
+ ).package
274
+ }
275
+
276
+ return await this.transport.request({
277
+ method: 'sui_getNormalizedMoveStruct',
278
+ params: [pkg, module, struct],
279
+ signal,
280
+ })
281
+ }
282
+
283
+ /**
284
+ * Get all objects owned by an address
285
+ */
286
+ async getOwnedObjects(input) {
287
+ if (!input.owner || !isValidSuiAddress(normalizeSuiAddress(input.owner))) {
288
+ throw new Error('Invalid Sui address')
289
+ }
290
+
291
+ const filter = input.filter
292
+ ? {
293
+ ...input.filter,
294
+ }
295
+ : void 0
296
+ if (filter && 'MoveModule' in filter && isValidNamedPackage(filter.MoveModule.package)) {
297
+ filter.MoveModule = {
298
+ module: filter.MoveModule.module,
299
+ package: (
300
+ await this.core.mvr.resolvePackage({
301
+ package: filter.MoveModule.package,
302
+ })
303
+ ).package,
304
+ }
305
+ } else if (filter && 'StructType' in filter && hasMvrName(filter.StructType)) {
306
+ filter.StructType = (
307
+ await this.core.mvr.resolveType({
308
+ type: filter.StructType,
309
+ })
310
+ ).type
311
+ }
312
+
313
+ return await this.transport.request({
314
+ method: 'suix_getOwnedObjects',
315
+ params: [
316
+ input.owner,
317
+ {
318
+ filter,
319
+ options: input.options,
320
+ },
321
+ input.cursor,
322
+ input.limit,
323
+ ],
324
+ signal: input.signal,
325
+ })
326
+ }
327
+
328
+ /**
329
+ * Get details about an object
330
+ */
331
+ async getObject(input) {
332
+ if (!input.id || !isValidSuiObjectId(normalizeSuiObjectId(input.id))) {
333
+ throw new Error('Invalid Sui Object id')
334
+ }
335
+
336
+ return await this.transport.request({
337
+ method: 'sui_getObject',
338
+ params: [input.id, input.options],
339
+ signal: input.signal,
340
+ })
341
+ }
342
+
343
+ async tryGetPastObject(input) {
344
+ return await this.transport.request({
345
+ method: 'sui_tryGetPastObject',
346
+ params: [input.id, input.version, input.options],
347
+ signal: input.signal,
348
+ })
349
+ }
350
+
351
+ /**
352
+ * Batch get details about a list of objects. If any of the object ids are duplicates the call will fail
353
+ */
354
+ async multiGetObjects(input) {
355
+ input.ids.forEach((id) => {
356
+ if (!id || !isValidSuiObjectId(normalizeSuiObjectId(id))) {
357
+ throw new Error(`Invalid Sui Object id ${id}`)
358
+ }
359
+ })
360
+ const hasDuplicates = input.ids.length !== new Set(input.ids).size
361
+ if (hasDuplicates) {
362
+ throw new Error(`Duplicate object ids in batch call ${input.ids}`)
363
+ }
364
+
365
+ return await this.transport.request({
366
+ method: 'sui_multiGetObjects',
367
+ params: [input.ids, input.options],
368
+ signal: input.signal,
369
+ })
370
+ }
371
+
372
+ /**
373
+ * Get transaction blocks for a given query criteria
374
+ */
375
+ async queryTransactionBlocks({ filter, options, cursor, limit, order, signal }) {
376
+ if (filter && 'MoveFunction' in filter && isValidNamedPackage(filter.MoveFunction.package)) {
377
+ filter = {
378
+ ...filter,
379
+ MoveFunction: {
380
+ package: (
381
+ await this.core.mvr.resolvePackage({
382
+ package: filter.MoveFunction.package,
383
+ })
384
+ ).package,
385
+ },
386
+ }
387
+ }
388
+
389
+ return await this.transport.request({
390
+ method: 'suix_queryTransactionBlocks',
391
+ params: [
392
+ {
393
+ filter,
394
+ options,
395
+ },
396
+ cursor,
397
+ limit,
398
+ (order || 'descending') === 'descending',
399
+ ],
400
+ signal,
401
+ })
402
+ }
403
+
404
+ async getTransactionBlock(input) {
405
+ if (!isValidTransactionDigest(input.digest)) {
406
+ throw new Error('Invalid Transaction digest')
407
+ }
408
+
409
+ return await this.transport.request({
410
+ method: 'sui_getTransactionBlock',
411
+ params: [input.digest, input.options],
412
+ signal: input.signal,
413
+ })
414
+ }
415
+
416
+ async multiGetTransactionBlocks(input) {
417
+ input.digests.forEach((d) => {
418
+ if (!isValidTransactionDigest(d)) {
419
+ throw new Error(`Invalid Transaction digest ${d}`)
420
+ }
421
+ })
422
+ const hasDuplicates = input.digests.length !== new Set(input.digests).size
423
+ if (hasDuplicates) {
424
+ throw new Error(`Duplicate digests in batch call ${input.digests}`)
425
+ }
426
+
427
+ return await this.transport.request({
428
+ method: 'sui_multiGetTransactionBlocks',
429
+ params: [input.digests, input.options],
430
+ signal: input.signal,
431
+ })
432
+ }
433
+
434
+ async executeTransactionBlock({ transactionBlock, signature, options, requestType, signal }) {
435
+ const result = await this.transport.request({
436
+ method: 'sui_executeTransactionBlock',
437
+ params: [
438
+ typeof transactionBlock === 'string' ? transactionBlock : toBase64(transactionBlock),
439
+ Array.isArray(signature) ? signature : [signature],
440
+ options,
441
+ ],
442
+ signal,
443
+ })
444
+ if (requestType === 'WaitForLocalExecution') {
445
+ try {
446
+ await this.waitForTransaction({
447
+ digest: result.digest,
448
+ })
449
+ } catch {}
450
+ }
451
+
452
+ return result
453
+ }
454
+
455
+ async signAndExecuteTransaction({ transaction, signer, ...input }) {
456
+ let transactionBytes
457
+ if (transaction instanceof Uint8Array) {
458
+ transactionBytes = transaction
459
+ } else {
460
+ transaction.setSenderIfNotSet(signer.toSuiAddress())
461
+ transactionBytes = await transaction.build({ client: this })
462
+ }
463
+
464
+ const { signature, bytes } = await signer.signTransaction(transactionBytes)
465
+ return this.executeTransactionBlock({
466
+ transactionBlock: bytes,
467
+ signature,
468
+ ...input,
469
+ })
470
+ }
471
+
472
+ /**
473
+ * Get total number of transactions
474
+ */
475
+ async getTotalTransactionBlocks({ signal } = Object.create(null)) {
476
+ const resp = await this.transport.request({
477
+ method: 'sui_getTotalTransactionBlocks',
478
+ params: [],
479
+ signal,
480
+ })
481
+ return BigInt(resp)
482
+ }
483
+
484
+ /**
485
+ * Getting the reference gas price for the network
486
+ */
487
+ async getReferenceGasPrice({ signal } = Object.create(null)) {
488
+ const resp = await this.transport.request({
489
+ method: 'suix_getReferenceGasPrice',
490
+ params: [],
491
+ signal,
492
+ })
493
+ return BigInt(resp)
494
+ }
495
+
496
+ /**
497
+ * Return the delegated stakes for an address
498
+ */
499
+ async getStakes(input) {
500
+ if (!input.owner || !isValidSuiAddress(normalizeSuiAddress(input.owner))) {
501
+ throw new Error('Invalid Sui address')
502
+ }
503
+
504
+ return await this.transport.request({
505
+ method: 'suix_getStakes',
506
+ params: [input.owner],
507
+ signal: input.signal,
508
+ })
509
+ }
510
+
511
+ /**
512
+ * Return the delegated stakes queried by id.
513
+ */
514
+ async getStakesByIds(input) {
515
+ input.stakedSuiIds.forEach((id) => {
516
+ if (!id || !isValidSuiObjectId(normalizeSuiObjectId(id))) {
517
+ throw new Error(`Invalid Sui Stake id ${id}`)
518
+ }
519
+ })
520
+ return await this.transport.request({
521
+ method: 'suix_getStakesByIds',
522
+ params: [input.stakedSuiIds],
523
+ signal: input.signal,
524
+ })
525
+ }
526
+
527
+ /**
528
+ * Return the latest system state content.
529
+ */
530
+ async getLatestSuiSystemState({ signal } = Object.create(null)) {
531
+ return await this.transport.request({
532
+ method: 'suix_getLatestSuiSystemState',
533
+ params: [],
534
+ signal,
535
+ })
536
+ }
537
+
538
+ /**
539
+ * Get events for a given query criteria
540
+ */
541
+ async queryEvents({ query, cursor, limit, order, signal }) {
542
+ if (query && 'MoveEventType' in query && hasMvrName(query.MoveEventType)) {
543
+ query = {
544
+ ...query,
545
+ MoveEventType: (
546
+ await this.core.mvr.resolveType({
547
+ type: query.MoveEventType,
548
+ })
549
+ ).type,
550
+ }
551
+ }
552
+
553
+ if (query && 'MoveEventModule' in query && isValidNamedPackage(query.MoveEventModule.package)) {
554
+ query = {
555
+ ...query,
556
+ MoveEventModule: {
557
+ module: query.MoveEventModule.module,
558
+ package: (
559
+ await this.core.mvr.resolvePackage({
560
+ package: query.MoveEventModule.package,
561
+ })
562
+ ).package,
563
+ },
564
+ }
565
+ }
566
+
567
+ if ('MoveModule' in query && isValidNamedPackage(query.MoveModule.package)) {
568
+ query = {
569
+ ...query,
570
+ MoveModule: {
571
+ module: query.MoveModule.module,
572
+ package: (
573
+ await this.core.mvr.resolvePackage({
574
+ package: query.MoveModule.package,
575
+ })
576
+ ).package,
577
+ },
578
+ }
579
+ }
580
+
581
+ return await this.transport.request({
582
+ method: 'suix_queryEvents',
583
+ params: [query, cursor, limit, (order || 'descending') === 'descending'],
584
+ signal,
585
+ })
586
+ }
587
+
588
+ /**
589
+ * Subscribe to get notifications whenever an event matching the filter occurs
590
+ *
591
+ * @deprecated
592
+ */
593
+ async subscribeEvent(input) {
594
+ return this.transport.subscribe({
595
+ method: 'suix_subscribeEvent',
596
+ unsubscribe: 'suix_unsubscribeEvent',
597
+ params: [input.filter],
598
+ onMessage: input.onMessage,
599
+ signal: input.signal,
600
+ })
601
+ }
602
+
603
+ /**
604
+ * @deprecated
605
+ */
606
+ async subscribeTransaction(input) {
607
+ return this.transport.subscribe({
608
+ method: 'suix_subscribeTransaction',
609
+ unsubscribe: 'suix_unsubscribeTransaction',
610
+ params: [input.filter],
611
+ onMessage: input.onMessage,
612
+ signal: input.signal,
613
+ })
614
+ }
615
+
616
+ /**
617
+ * Runs the transaction block in dev-inspect mode. Which allows for nearly any
618
+ * transaction (or Move call) with any arguments. Detailed results are
619
+ * provided, including both the transaction effects and any return values.
620
+ */
621
+ async devInspectTransactionBlock(input) {
622
+ let devInspectTxBytes
623
+ if (isTransaction(input.transactionBlock)) {
624
+ input.transactionBlock.setSenderIfNotSet(input.sender)
625
+ devInspectTxBytes = toBase64(
626
+ await input.transactionBlock.build({
627
+ client: this,
628
+ onlyTransactionKind: true,
629
+ })
630
+ )
631
+ } else if (typeof input.transactionBlock === 'string') {
632
+ devInspectTxBytes = input.transactionBlock
633
+ } else if (input.transactionBlock instanceof Uint8Array) {
634
+ devInspectTxBytes = toBase64(input.transactionBlock)
635
+ } else {
636
+ throw new TypeError('Unknown transaction block format.')
637
+ }
638
+
639
+ input.signal?.throwIfAborted()
640
+ return await this.transport.request({
641
+ method: 'sui_devInspectTransactionBlock',
642
+ params: [input.sender, devInspectTxBytes, input.gasPrice?.toString(), input.epoch],
643
+ signal: input.signal,
644
+ })
645
+ }
646
+
647
+ /**
648
+ * Dry run a transaction block and return the result.
649
+ */
650
+ async dryRunTransactionBlock(input) {
651
+ return await this.transport.request({
652
+ method: 'sui_dryRunTransactionBlock',
653
+ params: [
654
+ typeof input.transactionBlock === 'string'
655
+ ? input.transactionBlock
656
+ : toBase64(input.transactionBlock),
657
+ ],
658
+ })
659
+ }
660
+
661
+ /**
662
+ * Return the list of dynamic field objects owned by an object
663
+ */
664
+ async getDynamicFields(input) {
665
+ if (!input.parentId || !isValidSuiObjectId(normalizeSuiObjectId(input.parentId))) {
666
+ throw new Error('Invalid Sui Object id')
667
+ }
668
+
669
+ return await this.transport.request({
670
+ method: 'suix_getDynamicFields',
671
+ params: [input.parentId, input.cursor, input.limit],
672
+ signal: input.signal,
673
+ })
674
+ }
675
+
676
+ /**
677
+ * Return the dynamic field object information for a specified object
678
+ */
679
+ async getDynamicFieldObject(input) {
680
+ return await this.transport.request({
681
+ method: 'suix_getDynamicFieldObject',
682
+ params: [input.parentId, input.name],
683
+ signal: input.signal,
684
+ })
685
+ }
686
+
687
+ /**
688
+ * Get the sequence number of the latest checkpoint that has been executed
689
+ */
690
+ async getLatestCheckpointSequenceNumber({ signal } = Object.create(null)) {
691
+ const resp = await this.transport.request({
692
+ method: 'sui_getLatestCheckpointSequenceNumber',
693
+ params: [],
694
+ signal,
695
+ })
696
+ return String(resp)
697
+ }
698
+
699
+ /**
700
+ * Returns information about a given checkpoint
701
+ */
702
+ async getCheckpoint(input) {
703
+ return await this.transport.request({
704
+ method: 'sui_getCheckpoint',
705
+ params: [input.id],
706
+ signal: input.signal,
707
+ })
708
+ }
709
+
710
+ /**
711
+ * Returns historical checkpoints paginated
712
+ */
713
+ async getCheckpoints(input) {
714
+ return await this.transport.request({
715
+ method: 'sui_getCheckpoints',
716
+ params: [input.cursor, input?.limit, input.descendingOrder],
717
+ signal: input.signal,
718
+ })
719
+ }
720
+
721
+ /**
722
+ * Return the committee information for the asked epoch
723
+ */
724
+ async getCommitteeInfo(input) {
725
+ return await this.transport.request({
726
+ method: 'suix_getCommitteeInfo',
727
+ params: [input?.epoch],
728
+ signal: input?.signal,
729
+ })
730
+ }
731
+
732
+ async getNetworkMetrics({ signal } = Object.create(null)) {
733
+ return await this.transport.request({
734
+ method: 'suix_getNetworkMetrics',
735
+ params: [],
736
+ signal,
737
+ })
738
+ }
739
+
740
+ async getAddressMetrics({ signal } = Object.create(null)) {
741
+ return await this.transport.request({
742
+ method: 'suix_getLatestAddressMetrics',
743
+ params: [],
744
+ signal,
745
+ })
746
+ }
747
+
748
+ async getEpochMetrics(input) {
749
+ return await this.transport.request({
750
+ method: 'suix_getEpochMetrics',
751
+ params: [input?.cursor, input?.limit, input?.descendingOrder],
752
+ signal: input?.signal,
753
+ })
754
+ }
755
+
756
+ async getAllEpochAddressMetrics(input) {
757
+ return await this.transport.request({
758
+ method: 'suix_getAllEpochAddressMetrics',
759
+ params: [input?.descendingOrder],
760
+ signal: input?.signal,
761
+ })
762
+ }
763
+
764
+ /**
765
+ * Return the committee information for the asked epoch
766
+ */
767
+ async getEpochs(input) {
768
+ return await this.transport.request({
769
+ method: 'suix_getEpochs',
770
+ params: [input?.cursor, input?.limit, input?.descendingOrder],
771
+ signal: input?.signal,
772
+ })
773
+ }
774
+
775
+ /**
776
+ * Returns list of top move calls by usage
777
+ */
778
+ async getMoveCallMetrics({ signal } = Object.create(null)) {
779
+ return await this.transport.request({
780
+ method: 'suix_getMoveCallMetrics',
781
+ params: [],
782
+ signal,
783
+ })
784
+ }
785
+
786
+ /**
787
+ * Return the committee information for the asked epoch
788
+ */
789
+ async getCurrentEpoch({ signal } = Object.create(null)) {
790
+ return await this.transport.request({
791
+ method: 'suix_getCurrentEpoch',
792
+ params: [],
793
+ signal,
794
+ })
795
+ }
796
+
797
+ /**
798
+ * Return the Validators APYs
799
+ */
800
+ async getValidatorsApy({ signal } = Object.create(null)) {
801
+ return await this.transport.request({
802
+ method: 'suix_getValidatorsApy',
803
+ params: [],
804
+ signal,
805
+ })
806
+ }
807
+
808
+ // TODO: Migrate this to `sui_getChainIdentifier` once it is widely available.
809
+ async getChainIdentifier({ signal } = Object.create(null)) {
810
+ const checkpoint = await this.getCheckpoint({ id: '0', signal })
811
+ const bytes = fromBase58(checkpoint.digest)
812
+ return toHex(bytes.slice(0, 4))
813
+ }
814
+
815
+ async resolveNameServiceAddress(input) {
816
+ return await this.transport.request({
817
+ method: 'suix_resolveNameServiceAddress',
818
+ params: [input.name],
819
+ signal: input.signal,
820
+ })
821
+ }
822
+
823
+ async resolveNameServiceNames({ format = 'dot', ...input }) {
824
+ const { nextCursor, hasNextPage, data } = await this.transport.request({
825
+ method: 'suix_resolveNameServiceNames',
826
+ params: [input.address, input.cursor, input.limit],
827
+ signal: input.signal,
828
+ })
829
+ return {
830
+ hasNextPage,
831
+ nextCursor,
832
+ data: data.map((name) => normalizeSuiNSName(name, format)),
833
+ }
834
+ }
835
+
836
+ async getProtocolConfig(input) {
837
+ return await this.transport.request({
838
+ method: 'sui_getProtocolConfig',
839
+ params: [input?.version],
840
+ signal: input?.signal,
841
+ })
842
+ }
843
+
844
+ async verifyZkLoginSignature(input) {
845
+ return await this.transport.request({
846
+ method: 'sui_verifyZkLoginSignature',
847
+ params: [input.bytes, input.signature, input.intentScope, input.author],
848
+ signal: input.signal,
849
+ })
850
+ }
851
+
852
+ /**
853
+ * Wait for a transaction block result to be available over the API.
854
+ * This can be used in conjunction with `executeTransactionBlock` to wait for the transaction to
855
+ * be available via the API.
856
+ * This currently polls the `getTransactionBlock` API to check for the transaction.
857
+ */
858
+ async waitForTransaction({ signal, timeout = 60 * 1e3, pollInterval = 2 * 1e3, ...input }) {
859
+ const timeoutSignal = AbortSignal.timeout(timeout)
860
+ // eslint-disable-next-line promise/param-names
861
+ const timeoutPromise = new Promise((_, reject) => {
862
+ timeoutSignal.addEventListener('abort', () => reject(timeoutSignal.reason))
863
+ })
864
+ timeoutPromise.catch(() => {})
865
+ while (!timeoutSignal.aborted) {
866
+ signal?.throwIfAborted()
867
+ try {
868
+ return await this.getTransactionBlock(input)
869
+ } catch {
870
+ await Promise.race([
871
+ new Promise((resolve) => setTimeout(resolve, pollInterval)),
872
+ timeoutPromise,
873
+ ])
874
+ }
875
+ }
876
+
877
+ timeoutSignal.throwIfAborted()
878
+ throw new Error('Unexpected error while waiting for transaction block.')
879
+ }
880
+
881
+ experimental_asClientExtension() {
882
+ return {
883
+ name: 'jsonRPC',
884
+ register: () => {
885
+ return this
886
+ },
887
+ }
888
+ }
889
+ }
890
+ export { Signer, SuiClient, isSuiClient }
891
+ // # sourceMappingURL=client.js.map