@sentio/sdk 2.15.7-rc.2 → 2.16.0-rc.2
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.
- package/lib/aptos/aptos-plugin.js +3 -14
- package/lib/aptos/aptos-plugin.js.map +1 -1
- package/lib/core/core-plugin.js +3 -0
- package/lib/core/core-plugin.js.map +1 -1
- package/lib/core/template.d.ts +5 -0
- package/lib/core/template.js +6 -0
- package/lib/core/template.js.map +1 -0
- package/lib/eth/base-processor-template.d.ts +1 -4
- package/lib/eth/base-processor-template.js +2 -7
- package/lib/eth/base-processor-template.js.map +1 -1
- package/lib/eth/eth-plugin.js +6 -3
- package/lib/eth/eth-plugin.js.map +1 -1
- package/lib/sui/context.d.ts +7 -1
- package/lib/sui/context.js +12 -2
- package/lib/sui/context.js.map +1 -1
- package/lib/sui/ext/move-dex.d.ts +2 -2
- package/lib/sui/ext/move-dex.js.map +1 -1
- package/lib/sui/index.d.ts +3 -1
- package/lib/sui/index.js +5 -1
- package/lib/sui/index.js.map +1 -1
- package/lib/sui/sui-object-processor-template.d.ts +34 -0
- package/lib/sui/sui-object-processor-template.js +88 -0
- package/lib/sui/sui-object-processor-template.js.map +1 -0
- package/lib/sui/sui-object-processor.d.ts +54 -0
- package/lib/sui/sui-object-processor.js +93 -0
- package/lib/sui/sui-object-processor.js.map +1 -0
- package/lib/sui/sui-plugin.d.ts +1 -1
- package/lib/sui/sui-plugin.js +21 -2
- package/lib/sui/sui-plugin.js.map +1 -1
- package/lib/sui/sui-processor.d.ts +8 -56
- package/lib/sui/sui-processor.js +9 -122
- package/lib/sui/sui-processor.js.map +1 -1
- package/package.json +4 -3
- package/src/aptos/aptos-plugin.ts +3 -15
- package/src/core/core-plugin.ts +4 -0
- package/src/core/template.ts +6 -0
- package/src/eth/base-processor-template.ts +2 -7
- package/src/eth/eth-plugin.ts +8 -3
- package/src/sui/context.ts +15 -2
- package/src/sui/ext/move-dex.ts +2 -2
- package/src/sui/index.ts +13 -1
- package/src/sui/sui-object-processor-template.ts +153 -0
- package/src/sui/sui-object-processor.ts +186 -0
- package/src/sui/sui-plugin.ts +32 -2
- package/src/sui/sui-processor.ts +14 -196
package/src/sui/sui-plugin.ts
CHANGED
@@ -16,9 +16,17 @@ import {
|
|
16
16
|
|
17
17
|
import { ServerError, Status } from 'nice-grpc'
|
18
18
|
|
19
|
-
import {
|
19
|
+
import { SuiProcessorState } from './sui-processor.js'
|
20
|
+
import { SuiAccountProcessorState } from './sui-object-processor.js'
|
20
21
|
import { validateAndNormalizeAddress } from './utils.js'
|
21
22
|
import { initCoinList } from './ext/coin.js'
|
23
|
+
import { SuiChainId } from '../core/chain.js'
|
24
|
+
import {
|
25
|
+
SuiAccountProcessorTemplateState,
|
26
|
+
SuiObjectOrAddressProcessorTemplate,
|
27
|
+
} from './sui-object-processor-template.js'
|
28
|
+
import { SuiNetwork } from './network.js'
|
29
|
+
import { SuiContext } from './context.js'
|
22
30
|
|
23
31
|
interface Handlers {
|
24
32
|
suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]
|
@@ -33,8 +41,27 @@ export class SuiPlugin extends Plugin {
|
|
33
41
|
suiEventHandlers: [],
|
34
42
|
suiObjectHandlers: [],
|
35
43
|
}
|
36
|
-
async start(
|
44
|
+
async start(request: StartRequest): Promise<void> {
|
37
45
|
await initCoinList()
|
46
|
+
|
47
|
+
const allowedChainIds = new Set<string>(Object.values(SuiChainId))
|
48
|
+
for (const instance of request.templateInstances) {
|
49
|
+
if (!allowedChainIds.has(instance.contract?.chainId || '')) {
|
50
|
+
continue
|
51
|
+
}
|
52
|
+
|
53
|
+
const template: SuiObjectOrAddressProcessorTemplate<any, any> =
|
54
|
+
SuiAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId]
|
55
|
+
|
56
|
+
template.bind(
|
57
|
+
{
|
58
|
+
objectId: instance.contract?.address || '',
|
59
|
+
network: <SuiNetwork>instance.contract?.chainId || SuiNetwork.MAIN_NET,
|
60
|
+
startCheckpoint: instance.startBlock || 0n,
|
61
|
+
},
|
62
|
+
NoopContext
|
63
|
+
)
|
64
|
+
}
|
38
65
|
}
|
39
66
|
|
40
67
|
async configure(config: ProcessConfigResponse) {
|
@@ -107,6 +134,7 @@ export class SuiPlugin extends Plugin {
|
|
107
134
|
},
|
108
135
|
type: handler.type || '',
|
109
136
|
ownerType: processor.ownerType,
|
137
|
+
fetchConfig: undefined,
|
110
138
|
})
|
111
139
|
}
|
112
140
|
config.accountConfigs.push(accountConfig)
|
@@ -187,3 +215,5 @@ export class SuiPlugin extends Plugin {
|
|
187
215
|
}
|
188
216
|
|
189
217
|
PluginManager.INSTANCE.register(new SuiPlugin())
|
218
|
+
|
219
|
+
const NoopContext = new SuiContext('', SuiChainId.SUI_MAINNET, '', new Date(), 0n, {} as any, 0, {})
|
package/src/sui/sui-processor.ts
CHANGED
@@ -1,22 +1,13 @@
|
|
1
|
-
import {
|
2
|
-
Data_SuiCall,
|
3
|
-
Data_SuiEvent,
|
4
|
-
Data_SuiObject,
|
5
|
-
HandleInterval,
|
6
|
-
MoveFetchConfig,
|
7
|
-
MoveOnIntervalConfig_OwnerType,
|
8
|
-
ProcessResult,
|
9
|
-
} from '@sentio/protos'
|
1
|
+
import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig } from '@sentio/protos'
|
10
2
|
import { ListStateStorage, mergeProcessResults } from '@sentio/runtime'
|
11
3
|
import { SuiNetwork } from './network.js'
|
12
4
|
import { ServerError, Status } from 'nice-grpc'
|
13
|
-
import { SuiContext
|
5
|
+
import { SuiContext } from './context.js'
|
14
6
|
import {
|
15
7
|
getProgrammableTransaction,
|
16
8
|
getTransactionKind,
|
17
9
|
MoveCallSuiTransaction,
|
18
10
|
SuiEvent,
|
19
|
-
SuiMoveObject,
|
20
11
|
SuiTransactionBlockResponse,
|
21
12
|
} from '@mysten/sui.js'
|
22
13
|
import {
|
@@ -29,35 +20,32 @@ import {
|
|
29
20
|
} from '../move/index.js'
|
30
21
|
import { getMoveCalls } from './utils.js'
|
31
22
|
import { defaultMoveCoder, MoveCoder } from './move-coder.js'
|
32
|
-
import { Labels
|
33
|
-
|
23
|
+
import { Labels } from '../core/index.js'
|
24
|
+
import { Required } from 'utility-types'
|
34
25
|
|
35
26
|
const DEFAULT_FETCH_CONFIG: MoveFetchConfig = {
|
36
27
|
resourceChanges: false,
|
37
28
|
allEvents: true,
|
38
29
|
}
|
39
30
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
export type IndexConfigure = Required<SuiBindOptions, 'startCheckpoint' | 'network'>
|
32
|
+
|
33
|
+
export function configure(options: SuiBindOptions): IndexConfigure {
|
34
|
+
return {
|
35
|
+
startCheckpoint: options.startCheckpoint || 0n,
|
36
|
+
address: options.address,
|
37
|
+
network: options.network || SuiNetwork.MAIN_NET,
|
38
|
+
baseLabels: options.baseLabels,
|
39
|
+
}
|
45
40
|
}
|
46
41
|
|
47
|
-
export
|
42
|
+
export interface SuiBindOptions {
|
48
43
|
address: string
|
49
44
|
network?: SuiNetwork
|
50
45
|
startCheckpoint?: bigint
|
51
46
|
baseLabels?: Labels
|
52
47
|
}
|
53
48
|
|
54
|
-
export class SuiObjectBindOptions {
|
55
|
-
objectId: string
|
56
|
-
network?: SuiNetwork
|
57
|
-
startCheckpoint?: bigint
|
58
|
-
baseLabels?: { [key: string]: string }
|
59
|
-
}
|
60
|
-
|
61
49
|
export class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
|
62
50
|
static INSTANCE = new SuiProcessorState()
|
63
51
|
}
|
@@ -206,173 +194,3 @@ export class SuiBaseProcessor {
|
|
206
194
|
return this
|
207
195
|
}
|
208
196
|
}
|
209
|
-
|
210
|
-
class ObjectHandler {
|
211
|
-
type?: string
|
212
|
-
versionInterval?: HandleInterval
|
213
|
-
timeIntervalInMinutes?: HandleInterval
|
214
|
-
handler: (resource: Data_SuiObject) => Promise<ProcessResult>
|
215
|
-
}
|
216
|
-
|
217
|
-
export class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {
|
218
|
-
static INSTANCE = new SuiAccountProcessorState()
|
219
|
-
}
|
220
|
-
|
221
|
-
class SuiObjectsBindOptions extends SuiBindOptions {
|
222
|
-
ownerType: MoveOnIntervalConfig_OwnerType
|
223
|
-
}
|
224
|
-
|
225
|
-
abstract class SuiBaseObjectsProcessor<HandlerType> {
|
226
|
-
config: IndexConfigure
|
227
|
-
ownerType: MoveOnIntervalConfig_OwnerType
|
228
|
-
|
229
|
-
objectHandlers: ObjectHandler[] = []
|
230
|
-
|
231
|
-
// static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {
|
232
|
-
// return new SuiBaseObjectsProcessor(options)
|
233
|
-
// }
|
234
|
-
|
235
|
-
protected constructor(options: SuiObjectsBindOptions) {
|
236
|
-
this.config = configure(options)
|
237
|
-
this.ownerType = options.ownerType
|
238
|
-
SuiAccountProcessorState.INSTANCE.addValue(this)
|
239
|
-
}
|
240
|
-
|
241
|
-
getChainId(): string {
|
242
|
-
return this.config.network
|
243
|
-
}
|
244
|
-
|
245
|
-
// protected abstract transformObjects(objects: SuiMoveObject[]): SuiMoveObject[]
|
246
|
-
|
247
|
-
protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid
|
248
|
-
|
249
|
-
protected onInterval(
|
250
|
-
handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
251
|
-
timeInterval: HandleInterval | undefined,
|
252
|
-
versionInterval: HandleInterval | undefined,
|
253
|
-
type: string | undefined
|
254
|
-
): this {
|
255
|
-
const processor = this
|
256
|
-
this.objectHandlers.push({
|
257
|
-
handler: async function (data) {
|
258
|
-
const ctx = new SuiObjectsContext(
|
259
|
-
processor.config.network,
|
260
|
-
processor.config.address,
|
261
|
-
data.slot,
|
262
|
-
data.timestamp || new Date(0),
|
263
|
-
processor.config.baseLabels
|
264
|
-
)
|
265
|
-
await processor.doHandle(handler, data, ctx)
|
266
|
-
return ctx.getProcessResult()
|
267
|
-
},
|
268
|
-
timeIntervalInMinutes: timeInterval,
|
269
|
-
versionInterval: versionInterval,
|
270
|
-
type,
|
271
|
-
})
|
272
|
-
return this
|
273
|
-
}
|
274
|
-
|
275
|
-
public onTimeInterval(
|
276
|
-
handler: HandlerType,
|
277
|
-
timeIntervalInMinutes = 60,
|
278
|
-
backfillTimeIntervalInMinutes = 240,
|
279
|
-
type?: string
|
280
|
-
): this {
|
281
|
-
return this.onInterval(
|
282
|
-
handler,
|
283
|
-
{
|
284
|
-
recentInterval: timeIntervalInMinutes,
|
285
|
-
backfillInterval: backfillTimeIntervalInMinutes,
|
286
|
-
},
|
287
|
-
undefined,
|
288
|
-
type
|
289
|
-
)
|
290
|
-
}
|
291
|
-
|
292
|
-
public onSlotInterval(
|
293
|
-
handler: HandlerType,
|
294
|
-
slotInterval = 100000,
|
295
|
-
backfillSlotInterval = 400000,
|
296
|
-
type?: string
|
297
|
-
): this {
|
298
|
-
return this.onInterval(
|
299
|
-
handler,
|
300
|
-
undefined,
|
301
|
-
{ recentInterval: slotInterval, backfillInterval: backfillSlotInterval },
|
302
|
-
type
|
303
|
-
)
|
304
|
-
}
|
305
|
-
}
|
306
|
-
|
307
|
-
function configure(options: SuiBindOptions): IndexConfigure {
|
308
|
-
return {
|
309
|
-
startCheckpoint: options.startCheckpoint || 0n,
|
310
|
-
address: options.address,
|
311
|
-
network: options.network || SuiNetwork.MAIN_NET,
|
312
|
-
baseLabels: options.baseLabels,
|
313
|
-
}
|
314
|
-
}
|
315
|
-
|
316
|
-
export class SuiAddressProcessor extends SuiBaseObjectsProcessor<
|
317
|
-
(objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid
|
318
|
-
> {
|
319
|
-
static bind(options: SuiBindOptions): SuiAddressProcessor {
|
320
|
-
return new SuiAddressProcessor({ ...options, ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS })
|
321
|
-
}
|
322
|
-
|
323
|
-
protected doHandle(
|
324
|
-
handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
325
|
-
data: Data_SuiObject,
|
326
|
-
ctx: SuiObjectsContext
|
327
|
-
): PromiseOrVoid {
|
328
|
-
return handler(data.objects as SuiMoveObject[], ctx)
|
329
|
-
}
|
330
|
-
}
|
331
|
-
// export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<dynamic_field.Field<any, any>> {
|
332
|
-
export class SuiObjectProcessor extends SuiBaseObjectsProcessor<
|
333
|
-
(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid
|
334
|
-
> {
|
335
|
-
static bind(options: SuiObjectBindOptions): SuiObjectProcessor {
|
336
|
-
return new SuiObjectProcessor({
|
337
|
-
address: options.objectId,
|
338
|
-
network: options.network,
|
339
|
-
startCheckpoint: options.startCheckpoint,
|
340
|
-
ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,
|
341
|
-
baseLabels: options.baseLabels,
|
342
|
-
})
|
343
|
-
}
|
344
|
-
|
345
|
-
protected doHandle(
|
346
|
-
handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
347
|
-
data: Data_SuiObject,
|
348
|
-
ctx: SuiObjectsContext
|
349
|
-
): PromiseOrVoid {
|
350
|
-
if (!data.self) {
|
351
|
-
console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`)
|
352
|
-
return
|
353
|
-
}
|
354
|
-
return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)
|
355
|
-
}
|
356
|
-
}
|
357
|
-
|
358
|
-
export class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<
|
359
|
-
(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid
|
360
|
-
> {
|
361
|
-
static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor {
|
362
|
-
return new SuiWrappedObjectProcessor({
|
363
|
-
address: options.objectId,
|
364
|
-
network: options.network,
|
365
|
-
startCheckpoint: options.startCheckpoint,
|
366
|
-
ownerType: MoveOnIntervalConfig_OwnerType.WRAPPED_OBJECT,
|
367
|
-
baseLabels: options.baseLabels,
|
368
|
-
})
|
369
|
-
}
|
370
|
-
|
371
|
-
protected doHandle(
|
372
|
-
handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
|
373
|
-
data: Data_SuiObject,
|
374
|
-
ctx: SuiObjectsContext
|
375
|
-
): PromiseOrVoid {
|
376
|
-
return handler(data.objects as SuiMoveObject[], ctx)
|
377
|
-
}
|
378
|
-
}
|