@sentio/sdk 4.0.0-rc.8 → 4.0.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 (38) hide show
  1. package/lib/eth/eth-plugin.d.ts.map +1 -1
  2. package/lib/eth/eth-plugin.js +2 -1
  3. package/lib/eth/eth-plugin.js.map +1 -1
  4. package/lib/eth/generic-processor.js +1 -1
  5. package/lib/eth/generic-processor.js.map +1 -1
  6. package/lib/eth/index.d.ts +1 -1
  7. package/lib/eth/index.d.ts.map +1 -1
  8. package/lib/eth/index.js +1 -1
  9. package/lib/eth/index.js.map +1 -1
  10. package/lib/eth/provider.d.ts +13 -0
  11. package/lib/eth/provider.d.ts.map +1 -0
  12. package/lib/eth/provider.js +164 -0
  13. package/lib/eth/provider.js.map +1 -0
  14. package/lib/sui/network.d.ts.map +1 -1
  15. package/lib/sui/network.js +17 -5
  16. package/lib/sui/network.js.map +1 -1
  17. package/lib/sui/sui-object-processor.d.ts +2 -2
  18. package/lib/sui/sui-object-processor.d.ts.map +1 -1
  19. package/lib/sui/sui-object-processor.js +7 -7
  20. package/lib/sui/sui-object-processor.js.map +1 -1
  21. package/lib/sui/sui-processor.d.ts +3 -3
  22. package/lib/sui/sui-processor.d.ts.map +1 -1
  23. package/lib/sui/sui-processor.js +5 -4
  24. package/lib/sui/sui-processor.js.map +1 -1
  25. package/lib/sui/to-client-types.d.ts +3 -1
  26. package/lib/sui/to-client-types.d.ts.map +1 -1
  27. package/lib/sui/to-client-types.js +55 -40
  28. package/lib/sui/to-client-types.js.map +1 -1
  29. package/lib/testing/test-processor-server.d.ts.map +1 -1
  30. package/package.json +4 -3
  31. package/src/eth/eth-plugin.ts +2 -9
  32. package/src/eth/generic-processor.ts +1 -1
  33. package/src/eth/index.ts +1 -1
  34. package/src/eth/provider.ts +193 -0
  35. package/src/sui/network.ts +17 -5
  36. package/src/sui/sui-object-processor.ts +12 -20
  37. package/src/sui/sui-processor.ts +8 -7
  38. package/src/sui/to-client-types.ts +57 -39
@@ -16,8 +16,8 @@ import { create } from '@bufbuild/protobuf'
16
16
  import { ListStateStorage } from '@sentio/runtime'
17
17
  import { SuiNetwork } from './network.js'
18
18
  import { SuiAddressContext, SuiContext, SuiObjectChangeContext, SuiObjectContext } from './context.js'
19
- import type { SuiObjectChange } from '@mysten/sui/jsonRpc'
20
19
  import type { GrpcTypes } from '@mysten/sui/grpc'
20
+ import type { SuiClientTypes } from '@mysten/sui/client'
21
21
  import type { SuiMoveObjectInput } from '@typemove/sui'
22
22
  import { ALL_ADDRESS, PromiseOrVoid } from '../core/index.js'
23
23
  import { configure, DEFAULT_FETCH_CONFIG, IndexConfigure, SuiBindOptions } from './sui-processor.js'
@@ -25,7 +25,7 @@ import { CallHandler, TransactionFilter, accountTypeString, ObjectChangeHandler
25
25
  import { ConnectError, Code } from '@connectrpc/connect'
26
26
  import { TypeDescriptor } from '@typemove/move'
27
27
  import { TypedSuiMoveObject } from './models.js'
28
- import { toSuiClientObject } from './to-client-types.js'
28
+ import { toSuiClientChangedObjects, toSuiClientObjects } from './to-client-types.js'
29
29
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
30
30
 
31
31
  export interface SuiObjectBindOptions {
@@ -191,10 +191,7 @@ export class SuiAddressProcessor extends SuiBaseObjectOrAddressProcessorInternal
191
191
  data: Data_SuiObject,
192
192
  ctx: SuiObjectContext
193
193
  ) {
194
- return handler(
195
- data.rawObjects.map((o) => toSuiClientObject(JSON.parse(o))),
196
- ctx
197
- )
194
+ return handler(await toSuiClientObjects(data.rawObjects.map((o) => JSON.parse(o))), ctx)
198
195
  }
199
196
 
200
197
  onTransactionBlock(
@@ -271,8 +268,8 @@ export class SuiObjectProcessor extends SuiBaseObjectOrAddressProcessorInternal<
271
268
  return
272
269
  }
273
270
  return handler(
274
- toSuiClientObject(JSON.parse(data.rawSelf)),
275
- data.rawObjects.map((o) => toSuiClientObject(JSON.parse(o))),
271
+ (await toSuiClientObjects([JSON.parse(data.rawSelf)]))[0],
272
+ await toSuiClientObjects(data.rawObjects.map((o) => JSON.parse(o))),
276
273
  ctx
277
274
  )
278
275
  }
@@ -310,16 +307,14 @@ export class SuiObjectTypeProcessor<T> extends SuiBaseObjectOrAddressProcessor<
310
307
  return
311
308
  }
312
309
  const object = await ctx.coder.filterAndDecodeObjects(this.objectType, [
313
- toSuiClientObject(JSON.parse(data.rawSelf))
310
+ (await toSuiClientObjects([JSON.parse(data.rawSelf)]))[0]
314
311
  ])
315
- return handler(
316
- object[0],
317
- data.rawObjects.map((o) => toSuiClientObject(JSON.parse(o))),
318
- ctx
319
- )
312
+ return handler(object[0], await toSuiClientObjects(data.rawObjects.map((o) => JSON.parse(o))), ctx)
320
313
  }
321
314
 
322
- public onObjectChange(handler: (changes: SuiObjectChange[], ctx: SuiObjectChangeContext) => PromiseOrVoid): this {
315
+ public onObjectChange(
316
+ handler: (changes: SuiClientTypes.ChangedObject[], ctx: SuiObjectChangeContext) => PromiseOrVoid
317
+ ): this {
323
318
  if (this.config.network === SuiNetwork.TEST_NET) {
324
319
  throw new ConnectError('object change not supported in testnet', Code.InvalidArgument)
325
320
  }
@@ -335,7 +330,7 @@ export class SuiObjectTypeProcessor<T> extends SuiBaseObjectOrAddressProcessor<
335
330
  data.txDigest,
336
331
  processor.config.baseLabels
337
332
  )
338
- await handler(data.rawChanges.map((r) => JSON.parse(r)) as SuiObjectChange[], ctx)
333
+ await handler(await toSuiClientChangedObjects(data.rawChanges.map((r) => JSON.parse(r))), ctx)
339
334
  return ctx.stopAndGetResult()
340
335
  },
341
336
  type: [this.objectType.getSignature()]
@@ -408,9 +403,6 @@ export class SuiWrappedObjectProcessor extends SuiBaseObjectOrAddressProcessorIn
408
403
  data: Data_SuiObject,
409
404
  ctx: SuiObjectContext
410
405
  ) {
411
- return handler(
412
- data.rawObjects.map((o) => toSuiClientObject(JSON.parse(o))),
413
- ctx
414
- )
406
+ return handler(await toSuiClientObjects(data.rawObjects.map((o) => JSON.parse(o))), ctx)
415
407
  }
416
408
  }
@@ -11,8 +11,8 @@ import { ListStateStorage } from '@sentio/runtime'
11
11
  import { SuiNetwork } from './network.js'
12
12
  import { ConnectError, Code } from '@connectrpc/connect'
13
13
  import { SuiContext, SuiObjectChangeContext } from './context.js'
14
- import type { SuiObjectChange } from '@mysten/sui/jsonRpc'
15
14
  import type { GrpcTypes } from '@mysten/sui/grpc'
15
+ import type { SuiClientTypes } from '@mysten/sui/client'
16
16
  import type { SuiEventInput } from '@typemove/sui'
17
17
  import {
18
18
  accountAddressString,
@@ -30,7 +30,7 @@ import { ALL_ADDRESS, Labels, PromiseOrVoid } from '../core/index.js'
30
30
  import { Required } from 'utility-types'
31
31
  import { getHandlerName, proxyProcessor } from '../utils/metrics.js'
32
32
  import { HandlerOptions } from './models.js'
33
- import { toSuiClientEvent } from './to-client-types.js'
33
+ import { toSuiClientChangedObjects, toSuiClientEvent } from './to-client-types.js'
34
34
 
35
35
  export const DEFAULT_FETCH_CONFIG: MoveFetchConfig = create(MoveFetchConfigSchema, {
36
36
  resourceChanges: false,
@@ -113,8 +113,9 @@ export class SuiBaseProcessor {
113
113
  const txn = JSON.parse(data.rawTransaction) as GrpcTypes.ExecutedTransaction
114
114
 
115
115
  const evt = toSuiClientEvent(JSON.parse(data.rawEvent))
116
- // gRPC events carry no sequence; index is resolved by the runtime.
117
- const idx = 0
116
+ // gRPC events carry no on-chain sequence; the driver supplies the event's
117
+ // index within the tx via the eventSeq field (mirrors json-rpc's id.eventSeq).
118
+ const idx = data.eventSeq
118
119
 
119
120
  const ctx = new SuiContext(
120
121
  processor.moduleName,
@@ -280,7 +281,7 @@ export class SuiBaseProcessor {
280
281
  }
281
282
 
282
283
  protected onObjectChange(
283
- handler: (changes: SuiObjectChange[], ctx: SuiObjectChangeContext) => PromiseOrVoid,
284
+ handler: (changes: SuiClientTypes.ChangedObject[], ctx: SuiObjectChangeContext) => PromiseOrVoid,
284
285
  type: string | string[]
285
286
  ): this {
286
287
  if (this.config.network === SuiNetwork.TEST_NET) {
@@ -298,7 +299,7 @@ export class SuiBaseProcessor {
298
299
  data.txDigest,
299
300
  processor.config.baseLabels
300
301
  )
301
- await handler(data.rawChanges.map((r) => JSON.parse(r)) as SuiObjectChange[], ctx)
302
+ await handler(await toSuiClientChangedObjects(data.rawChanges.map((r) => JSON.parse(r))), ctx)
302
303
  return ctx.stopAndGetResult()
303
304
  },
304
305
  type
@@ -332,7 +333,7 @@ export class SuiGlobalProcessor extends SuiBaseProcessor {
332
333
 
333
334
  // deprecated,, use object type processor
334
335
  public onObjectChange(
335
- handler: (changes: SuiObjectChange[], ctx: SuiObjectChangeContext) => void,
336
+ handler: (changes: SuiClientTypes.ChangedObject[], ctx: SuiObjectChangeContext) => void,
336
337
  type: string | string[]
337
338
  ): this {
338
339
  return super.onObjectChange(handler, type)
@@ -1,4 +1,5 @@
1
1
  import type { SuiClientTypes } from '@mysten/sui/client'
2
+ import { GrpcCoreClient, GrpcTypes } from '@mysten/sui/grpc'
2
3
  import type { SuiEventInput, SuiMoveObjectInput } from '@typemove/sui'
3
4
 
4
5
  // The Sentio driver delivers Sui objects/events as protojson of the gRPC
@@ -15,54 +16,71 @@ function base64ToBytes(b64: string): Uint8Array {
15
16
  return new Uint8Array(Buffer.from(b64, 'base64'))
16
17
  }
17
18
 
18
- // Mirrors mapOwner in @mysten/sui's grpc core. protojson serializes the
19
- // Owner.OwnerKind enum to its proto value name and uint64 `version` to a string.
20
- function mapOwner(owner: any): SuiClientTypes.ObjectOwner | null {
21
- if (!owner) {
22
- return null
19
+ // protojson `sui.rpc.v2.Object[]` -> unified `SuiClientTypes.Object<{ json: true }>[]`.
20
+ //
21
+ // Same reuse strategy as `toSuiClientChangedObjects`: instead of mirroring the
22
+ // object/owner mapping by hand, drive @mysten/sui's own `getObjects` mapping
23
+ // (which also normalizes the struct tag and owner) through a fake transport, so
24
+ // SDK upgrades stay in lockstep. `getObjects` chunks ids by 50 and calls
25
+ // `ledgerService.batchGetObjects` per chunk reading `{ result: { oneofKind } }`
26
+ // per request, so the fake returns objects keyed by the requested id.
27
+ // `include: { json: true }` leaves content/objectBcs/previousTransaction/display
28
+ // unset, matching the old hand-rolled output.
29
+ // See https://github.com/MystenLabs/ts-sdks/blob/8588da38e0a813f87b345c348e63486a7a766a61/packages/sui/src/grpc/core.ts#L176
30
+ export async function toSuiClientObjects(rawObjects: any[]): Promise<SuiMoveObjectInput[]> {
31
+ if (rawObjects.length === 0) {
32
+ return []
23
33
  }
24
- switch (owner.kind) {
25
- case 'IMMUTABLE':
26
- return { $kind: 'Immutable', Immutable: true }
27
- case 'ADDRESS':
28
- return { $kind: 'AddressOwner', AddressOwner: owner.address }
29
- case 'OBJECT':
30
- return { $kind: 'ObjectOwner', ObjectOwner: owner.address }
31
- case 'SHARED':
32
- return { $kind: 'Shared', Shared: { initialSharedVersion: String(owner.version) } }
33
- case 'CONSENSUS_ADDRESS':
34
- return {
35
- $kind: 'ConsensusAddressOwner',
36
- ConsensusAddressOwner: { startVersion: String(owner.version), owner: owner.address }
34
+ const byId = new Map(rawObjects.map((o) => [o.objectId, GrpcTypes.Object.fromJson(o, { ignoreUnknownFields: true })]))
35
+ const core = new GrpcCoreClient({
36
+ client: {
37
+ ledgerService: {
38
+ batchGetObjects: async ({ requests }: any) => ({
39
+ response: {
40
+ objects: requests.map((r: any) => ({ result: { oneofKind: 'object', object: byId.get(r.objectId) } }))
41
+ }
42
+ })
37
43
  }
38
- default:
39
- return { $kind: 'Unknown' }
40
- }
44
+ }
45
+ } as any)
46
+ const res: any = await core.getObjects({ objectIds: rawObjects.map((o) => o.objectId), include: { json: true } })
47
+ return res.objects as SuiMoveObjectInput[]
41
48
  }
42
49
 
43
- // protojson `sui.rpc.v2.Object` -> unified `SuiClientTypes.Object<{ json: true }>`.
44
- // Already-unified inputs (from `SuiGrpcClient.core`) pass through: `.type` and
45
- // `.json` are read with the gRPC names falling back to the unified ones. With
46
- // `Include = { json: true }` every field except objectId/version/digest/owner/
47
- // type/json is typed `undefined`, so we deliberately leave them unset.
48
- export function toSuiClientObject(o: any): SuiMoveObjectInput {
49
- return {
50
- objectId: o.objectId,
51
- version: o.version,
52
- digest: o.digest,
53
- owner: mapOwner(o.owner)!,
54
- type: o.objectType ?? o.type ?? '',
55
- content: undefined,
56
- previousTransaction: undefined,
57
- objectBcs: undefined,
58
- json: o.json ?? null,
59
- display: undefined
60
- } as SuiMoveObjectInput
50
+ // protojson `sui.rpc.v2.ChangedObject[]` -> unified `SuiClientTypes.ChangedObject[]`.
51
+ //
52
+ // Rather than mirror @mysten/sui's enum/owner mapping by hand, we reuse its own
53
+ // `parseTransactionEffects` so SDK upgrades pick up upstream changes (new enum
54
+ // values, owner kinds, bug fixes) automatically instead of silently drifting.
55
+ // That function isn't exported, so we reach it through its only public caller,
56
+ // `GrpcCoreClient.getTransaction`, fed by an in-memory fake transport that hands
57
+ // back our changes as a protobuf-ts `TransactionEffects` message.
58
+ //
59
+ // Two upstream-internal details this depends on (both asserted by
60
+ // to-client-types.test.ts, which fails loudly if an upgrade changes them):
61
+ // 1. `parseTransactionEffects` dereferences `effects.status.error` unguarded on
62
+ // the non-success path, so a minimal `status: { success: true }` is required.
63
+ // 2. `getTransaction` returns a `{ $kind: 'Transaction', Transaction }` union.
64
+ // See https://github.com/MystenLabs/ts-sdks/blob/8588da38e0a813f87b345c348e63486a7a766a61/packages/sui/src/grpc/core.ts#L1132
65
+ export async function toSuiClientChangedObjects(rawChanges: any[]): Promise<SuiClientTypes.ChangedObject[]> {
66
+ if (rawChanges.length === 0) {
67
+ return []
68
+ }
69
+ const effects = GrpcTypes.TransactionEffects.fromJson(
70
+ { status: { success: true }, changedObjects: rawChanges },
71
+ { ignoreUnknownFields: true }
72
+ )
73
+ const core = new GrpcCoreClient({
74
+ client: { ledgerService: { getTransaction: async () => ({ response: { transaction: { digest: '', effects } } }) } }
75
+ } as any)
76
+ const res: any = await core.getTransaction({ digest: '', include: { effects: true } })
77
+ return (res.Transaction ?? res).effects.changedObjects
61
78
  }
62
79
 
63
80
  // protojson `sui.rpc.v2.Event` -> unified `SuiClientTypes.Event`. The
64
81
  // discriminating fields (`eventType`, `json`) already share names; only the
65
82
  // BCS payload is renamed (`contents` -> `bcs`).
83
+ // Source: https://github.com/MystenLabs/ts-sdks/blob/8588da38e0a813f87b345c348e63486a7a766a61/packages/sui/src/grpc/core.ts#L1279
66
84
  export function toSuiClientEvent(e: any): SuiEventInput {
67
85
  return {
68
86
  packageId: e.packageId,