@sentio/sdk 2.15.7-rc.2 → 2.16.0-rc.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 (35) hide show
  1. package/lib/aptos/aptos-plugin.js +3 -14
  2. package/lib/aptos/aptos-plugin.js.map +1 -1
  3. package/lib/core/template.d.ts +5 -0
  4. package/lib/core/template.js +6 -0
  5. package/lib/core/template.js.map +1 -0
  6. package/lib/eth/base-processor-template.d.ts +1 -4
  7. package/lib/eth/base-processor-template.js +2 -7
  8. package/lib/eth/base-processor-template.js.map +1 -1
  9. package/lib/eth/eth-plugin.js +6 -1
  10. package/lib/eth/eth-plugin.js.map +1 -1
  11. package/lib/sui/index.d.ts +3 -1
  12. package/lib/sui/index.js +5 -1
  13. package/lib/sui/index.js.map +1 -1
  14. package/lib/sui/sui-object-processor.d.ts +54 -0
  15. package/lib/sui/sui-object-processor.js +93 -0
  16. package/lib/sui/sui-object-processor.js.map +1 -0
  17. package/lib/sui/sui-objects-processor-template.d.ts +34 -0
  18. package/lib/sui/sui-objects-processor-template.js +88 -0
  19. package/lib/sui/sui-objects-processor-template.js.map +1 -0
  20. package/lib/sui/sui-plugin.d.ts +1 -1
  21. package/lib/sui/sui-plugin.js +21 -2
  22. package/lib/sui/sui-plugin.js.map +1 -1
  23. package/lib/sui/sui-processor.d.ts +8 -56
  24. package/lib/sui/sui-processor.js +9 -122
  25. package/lib/sui/sui-processor.js.map +1 -1
  26. package/package.json +4 -3
  27. package/src/aptos/aptos-plugin.ts +3 -15
  28. package/src/core/template.ts +6 -0
  29. package/src/eth/base-processor-template.ts +2 -7
  30. package/src/eth/eth-plugin.ts +8 -1
  31. package/src/sui/index.ts +13 -1
  32. package/src/sui/sui-object-processor.ts +186 -0
  33. package/src/sui/sui-objects-processor-template.ts +153 -0
  34. package/src/sui/sui-plugin.ts +29 -2
  35. package/src/sui/sui-processor.ts +14 -196
@@ -0,0 +1,88 @@
1
+ import { ListStateStorage } from '@sentio/runtime';
2
+ import { DEFAULT_FETCH_CONFIG, SuiObjectProcessor, SuiWrappedObjectProcessor, } from './sui-object-processor.js';
3
+ import { TemplateInstanceState } from '../core/template.js';
4
+ class ObjectHandler {
5
+ type;
6
+ versionInterval;
7
+ timeIntervalInMinutes;
8
+ handler;
9
+ fetchConfig;
10
+ }
11
+ class SuiAccountProcessorTemplateState extends ListStateStorage {
12
+ static INSTANCE = new SuiAccountProcessorTemplateState();
13
+ }
14
+ export { SuiAccountProcessorTemplateState };
15
+ export class SuiBaseObjectsProcessorTemplate {
16
+ id;
17
+ objectHandlers = [];
18
+ binds = new Set();
19
+ constructor() {
20
+ this.id = SuiAccountProcessorTemplateState.INSTANCE.getValues().length;
21
+ SuiAccountProcessorTemplateState.INSTANCE.addValue(this);
22
+ }
23
+ bind(options, ctx) {
24
+ options.network = options.network || ctx.network;
25
+ const sig = [options.network, options.objectId].join('_');
26
+ if (this.binds.has(sig)) {
27
+ console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`);
28
+ return;
29
+ }
30
+ this.binds.add(sig);
31
+ const processor = this.createProcessor(options);
32
+ for (const h of this.objectHandlers) {
33
+ processor.onInterval(h.handler, h.timeIntervalInMinutes, h.versionInterval, h.type, h.fetchConfig);
34
+ }
35
+ const config = processor.config;
36
+ ctx._res.states.configUpdated = true;
37
+ TemplateInstanceState.INSTANCE.addValue({
38
+ templateId: this.id,
39
+ contract: {
40
+ name: '',
41
+ chainId: config.network,
42
+ address: config.address,
43
+ abi: '',
44
+ },
45
+ startBlock: config.startCheckpoint,
46
+ endBlock: 0n,
47
+ });
48
+ }
49
+ onInterval(handler, timeInterval, versionInterval, type, fetchConfig) {
50
+ this.objectHandlers.push({
51
+ handler: handler,
52
+ timeIntervalInMinutes: timeInterval,
53
+ versionInterval: versionInterval,
54
+ type,
55
+ fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },
56
+ });
57
+ return this;
58
+ }
59
+ onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240, type, fetchConfig) {
60
+ return this.onInterval(handler, {
61
+ recentInterval: timeIntervalInMinutes,
62
+ backfillInterval: backfillTimeIntervalInMinutes,
63
+ }, undefined, type, fetchConfig);
64
+ }
65
+ onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000, type, fetchConfig) {
66
+ return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval }, type, fetchConfig);
67
+ }
68
+ }
69
+ // export class SuiAddressProcessorTemplate extends SuiBaseObjectsProcessorTemplate<
70
+ // (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
71
+ // SuiBindOptions,
72
+ // SuiAddressProcessor
73
+ // > {
74
+ // bind(options: SuiBindOptions, ctx: SuiContext): SuiAddressProcessor {
75
+ // return this.bindInternal(SuiAddressProcessorTemplate.bind(options), ctx)
76
+ // }
77
+ // }
78
+ export class SuiObjectsProcessorTemplate extends SuiBaseObjectsProcessorTemplate {
79
+ createProcessor(options) {
80
+ return SuiObjectProcessor.bind(options);
81
+ }
82
+ }
83
+ export class SuiWrappedObjectProcessorTemplate extends SuiBaseObjectsProcessorTemplate {
84
+ createProcessor(options) {
85
+ return SuiWrappedObjectProcessor.bind(options);
86
+ }
87
+ }
88
+ //# sourceMappingURL=sui-objects-processor-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sui-objects-processor-template.js","sourceRoot":"","sources":["../../src/sui/sui-objects-processor-template.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAIlD,OAAO,EACL,oBAAoB,EAGpB,kBAAkB,EAClB,yBAAyB,GAC1B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,MAAM,aAAa;IACjB,IAAI,CAAS;IACb,eAAe,CAAiB;IAChC,qBAAqB,CAAiB;IACtC,OAAO,CAAa;IACp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AyE;AACzE,oBAAoB;AACpB,wBAAwB;AACxB,MAAM;AACN,0EAA0E;AAC1E,+EAA+E;AAC/E,MAAM;AACN,IAAI;AAEJ,MAAM,OAAO,2BAA4B,SAAQ,+BAIhD;IACC,eAAe,CAAC,OAA6B;QAC3C,OAAO,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACzC,CAAC;CACF;AAED,MAAM,OAAO,iCAAkC,SAAQ,+BAItD;IACC,eAAe,CAAC,OAA6B;QAC3C,OAAO,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IAChD,CAAC;CACF","sourcesContent":["import { HandleInterval, MoveAccountFetchConfig } from '@sentio/protos'\nimport { ListStateStorage } from '@sentio/runtime'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport { SuiMoveObject } from '@mysten/sui.js'\nimport { PromiseOrVoid } from '../core/index.js'\nimport {\n DEFAULT_FETCH_CONFIG,\n SuiBaseObjectsProcessor,\n SuiObjectBindOptions,\n SuiObjectProcessor,\n SuiWrappedObjectProcessor,\n} from './sui-object-processor.js'\nimport { TemplateInstanceState } from '../core/template.js'\n\nclass ObjectHandler<HandlerType> {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: HandlerType\n fetchConfig: MoveAccountFetchConfig\n}\n\nexport class SuiAccountProcessorTemplateState extends ListStateStorage<SuiBaseObjectsProcessorTemplate<any, any>> {\n static INSTANCE = new SuiAccountProcessorTemplateState()\n}\n\nexport abstract class SuiBaseObjectsProcessorTemplate<\n HandlerType,\n // OptionType,\n ProcessorType extends SuiBaseObjectsProcessor<HandlerType>\n> {\n id: number\n objectHandlers: ObjectHandler<HandlerType>[] = []\n binds = new Set<string>()\n\n protected constructor() {\n this.id = SuiAccountProcessorTemplateState.INSTANCE.getValues().length\n SuiAccountProcessorTemplateState.INSTANCE.addValue(this)\n }\n\n abstract createProcessor(options: SuiObjectBindOptions): ProcessorType\n\n bind(options: SuiObjectBindOptions, ctx: SuiContext): void {\n options.network = options.network || ctx.network\n const sig = [options.network, options.objectId].join('_')\n if (this.binds.has(sig)) {\n console.log(`Same object id can be bind to one template only once, ignore duplicate bind: ${sig}`)\n return\n }\n this.binds.add(sig)\n\n const processor = this.createProcessor(options)\n for (const h of this.objectHandlers) {\n processor.onInterval(h.handler, h.timeIntervalInMinutes, h.versionInterval, h.type, h.fetchConfig)\n }\n const config = processor.config\n\n ctx._res.states.configUpdated = true\n TemplateInstanceState.INSTANCE.addValue({\n templateId: this.id,\n contract: {\n name: '',\n chainId: config.network,\n address: config.address,\n abi: '',\n },\n startBlock: config.startCheckpoint,\n endBlock: 0n,\n })\n }\n\n protected onInterval(\n handler: HandlerType,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined,\n fetchConfig: Partial<MoveAccountFetchConfig> | undefined\n ): this {\n this.objectHandlers.push({\n handler: handler,\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type,\n fetchConfig: { ...DEFAULT_FETCH_CONFIG, ...fetchConfig },\n })\n return this\n }\n\n public onTimeInterval(\n handler: HandlerType,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type,\n fetchConfig\n )\n }\n\n public onSlotInterval(\n handler: HandlerType,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string,\n fetchConfig?: Partial<MoveAccountFetchConfig>\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type,\n fetchConfig\n )\n }\n}\n\n// export class SuiAddressProcessorTemplate extends SuiBaseObjectsProcessorTemplate<\n// (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n// SuiBindOptions,\n// SuiAddressProcessor\n// > {\n// bind(options: SuiBindOptions, ctx: SuiContext): SuiAddressProcessor {\n// return this.bindInternal(SuiAddressProcessorTemplate.bind(options), ctx)\n// }\n// }\n\nexport class SuiObjectsProcessorTemplate extends SuiBaseObjectsProcessorTemplate<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n // SuiObjectBindOptions,\n SuiObjectProcessor\n> {\n createProcessor(options: SuiObjectBindOptions): SuiObjectProcessor {\n return SuiObjectProcessor.bind(options)\n }\n}\n\nexport class SuiWrappedObjectProcessorTemplate extends SuiBaseObjectsProcessorTemplate<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n // SuiObjectBindOptions,\n SuiWrappedObjectProcessor\n> {\n createProcessor(options: SuiObjectBindOptions): SuiWrappedObjectProcessor {\n return SuiWrappedObjectProcessor.bind(options)\n }\n}\n"]}
@@ -8,7 +8,7 @@ interface Handlers {
8
8
  export declare class SuiPlugin extends Plugin {
9
9
  name: string;
10
10
  handlers: Handlers;
11
- start(start: StartRequest): Promise<void>;
11
+ start(request: StartRequest): Promise<void>;
12
12
  configure(config: ProcessConfigResponse): Promise<void>;
13
13
  supportedHandlers: HandlerType[];
14
14
  processSuiEvent(binding: DataBinding): Promise<ProcessResult>;
@@ -1,9 +1,14 @@
1
1
  import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime';
2
2
  import { AccountConfig, ContractConfig, HandlerType, } from '@sentio/protos';
3
3
  import { ServerError, Status } from 'nice-grpc';
4
- import { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js';
4
+ import { SuiProcessorState } from './sui-processor.js';
5
+ import { SuiAccountProcessorState } from './sui-object-processor.js';
5
6
  import { validateAndNormalizeAddress } from './utils.js';
6
7
  import { initCoinList } from './ext/coin.js';
8
+ import { SuiChainId } from '../core/chain.js';
9
+ import { SuiAccountProcessorTemplateState } from './sui-objects-processor-template.js';
10
+ import { SuiNetwork } from './network.js';
11
+ import { SuiContext } from './context.js';
7
12
  export class SuiPlugin extends Plugin {
8
13
  name = 'SuiPlugin';
9
14
  handlers = {
@@ -11,8 +16,20 @@ export class SuiPlugin extends Plugin {
11
16
  suiEventHandlers: [],
12
17
  suiObjectHandlers: [],
13
18
  };
14
- async start(start) {
19
+ async start(request) {
15
20
  await initCoinList();
21
+ const allowedChainIds = new Set(Object.values(SuiChainId));
22
+ for (const instance of request.templateInstances) {
23
+ if (!allowedChainIds.has(instance.contract?.chainId || '')) {
24
+ continue;
25
+ }
26
+ const template = SuiAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId];
27
+ template.bind({
28
+ objectId: instance.contract?.address || '',
29
+ network: instance.contract?.chainId || SuiNetwork.MAIN_NET,
30
+ startCheckpoint: instance.startBlock || 0n,
31
+ }, NoopContext);
32
+ }
16
33
  }
17
34
  async configure(config) {
18
35
  const handlers = {
@@ -83,6 +100,7 @@ export class SuiPlugin extends Plugin {
83
100
  },
84
101
  type: handler.type || '',
85
102
  ownerType: processor.ownerType,
103
+ fetchConfig: undefined,
86
104
  });
87
105
  }
88
106
  config.accountConfigs.push(accountConfig);
@@ -144,4 +162,5 @@ export class SuiPlugin extends Plugin {
144
162
  }
145
163
  }
146
164
  PluginManager.INSTANCE.register(new SuiPlugin());
165
+ const NoopContext = new SuiContext('', SuiChainId.SUI_MAINNET, '', new Date(), 0n, {}, 0, {});
147
166
  //# sourceMappingURL=sui-plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAMZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,M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CAAC,IAAI,SAAS,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiAccountProcessorState, SuiProcessorState } from './sui-processor.js'\nimport { validateAndNormalizeAddress } from './utils.js'\nimport { initCoinList } from './ext/coin.js'\n\ninterface Handlers {\n suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]\n suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]\n suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]\n}\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n async start(start: StartRequest): Promise<void> {\n await initCoinList()\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: suiProcessor.config.network,\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n"]}
1
+ {"version":3,"file":"sui-plugin.js","sourceRoot":"","sources":["../../src/sui/sui-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACzG,OAAO,EACL,aAAa,EACb,cAAc,EAKd,WAAW,GAMZ,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,C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,QAAQ,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC7D,MAAM,IAAI,WAAW,CACnB,MAAM,CAAC,QAAQ,EACf,2BAA2B,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAC7E,CAAA;YACH,CAAC,CAAC,CACH,CAAA;SACF;QACD,OAAO,mBAAmB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAA;IACzD,CAAC;IAED,cAAc,CAAC,OAAoB;QACjC,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,WAAW,CAAC,SAAS;gBACxB,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACtC,KAAK,WAAW,CAAC,QAAQ;gBACvB,OAAO,IAAI,CAAC,sBAAsB,CAAC,OAAO,CAAC,CAAA;YAC7C,KAAK,WAAW,CAAC,UAAU;gBACzB,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;YACvC;gBACE,MAAM,IAAI,WAAW,CAAC,MAAM,CAAC,gBAAgB,EAAE,4BAA4B,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;SACrG;IACH,CAAC;CACF;AAED,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,SAAS,EAAE,CAAC,CAAA;AAEhD,MAAM,WAAW,GAAG,IAAI,UAAU,CAAC,EAAE,EAAE,UAAU,CAAC,WAAW,EAAE,EAAE,EAAE,IAAI,IAAI,EAAE,EAAE,EAAE,EAAE,EAAS,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA","sourcesContent":["import { errorString, mergeProcessResults, Plugin, PluginManager, USER_PROCESSOR } from '@sentio/runtime'\nimport {\n AccountConfig,\n ContractConfig,\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n DataBinding,\n HandlerType,\n MoveCallHandlerConfig,\n MoveEventHandlerConfig,\n ProcessConfigResponse,\n ProcessResult,\n StartRequest,\n} from '@sentio/protos'\n\nimport { ServerError, Status } from 'nice-grpc'\n\nimport { SuiProcessorState } from './sui-processor.js'\nimport { SuiAccountProcessorState } from './sui-object-processor.js'\nimport { validateAndNormalizeAddress } from './utils.js'\nimport { initCoinList } from './ext/coin.js'\nimport { SuiChainId } from '../core/chain.js'\nimport { SuiAccountProcessorTemplateState, SuiBaseObjectsProcessorTemplate } from './sui-objects-processor-template.js'\nimport { SuiNetwork } from './network.js'\nimport { SuiContext } from './context.js'\n\ninterface Handlers {\n suiEventHandlers: ((event: Data_SuiEvent) => Promise<ProcessResult>)[]\n suiCallHandlers: ((func: Data_SuiCall) => Promise<ProcessResult>)[]\n suiObjectHandlers: ((object: Data_SuiObject) => Promise<ProcessResult>)[]\n}\n\nexport class SuiPlugin extends Plugin {\n name: string = 'SuiPlugin'\n handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n async start(request: StartRequest): Promise<void> {\n await initCoinList()\n\n const allowedChainIds = new Set<string>(Object.values(SuiChainId))\n for (const instance of request.templateInstances) {\n if (!allowedChainIds.has(instance.contract?.chainId || '')) {\n continue\n }\n\n const template: SuiBaseObjectsProcessorTemplate<any, any> =\n SuiAccountProcessorTemplateState.INSTANCE.getValues()[instance.templateId]\n\n template.bind(\n {\n objectId: instance.contract?.address || '',\n network: <SuiNetwork>instance.contract?.chainId || SuiNetwork.MAIN_NET,\n startCheckpoint: instance.startBlock || 0n,\n },\n NoopContext\n )\n }\n }\n\n async configure(config: ProcessConfigResponse) {\n const handlers: Handlers = {\n suiCallHandlers: [],\n suiEventHandlers: [],\n suiObjectHandlers: [],\n }\n for (const suiProcessor of SuiProcessorState.INSTANCE.getValues()) {\n const contractConfig = ContractConfig.fromPartial({\n transactionConfig: [],\n processorType: USER_PROCESSOR,\n contract: {\n name: suiProcessor.moduleName,\n chainId: suiProcessor.config.network,\n address: validateAndNormalizeAddress(suiProcessor.config.address),\n abi: '',\n },\n startBlock: suiProcessor.config.startCheckpoint,\n })\n for (const handler of suiProcessor.eventHandlers) {\n const handlerId = handlers.suiEventHandlers.push(handler.handler) - 1\n const eventHandlerConfig: MoveEventHandlerConfig = {\n filters: handler.filters.map((f) => {\n return {\n type: f.type,\n account: f.account || '',\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveEventConfigs.push(eventHandlerConfig)\n }\n for (const handler of suiProcessor.callHandlers) {\n const handlerId = handlers.suiCallHandlers.push(handler.handler) - 1\n const functionHandlerConfig: MoveCallHandlerConfig = {\n filters: handler.filters.map((filter) => {\n return {\n function: filter.function,\n typeArguments: filter.typeArguments || [],\n withTypeArguments: !!filter.typeArguments,\n includeFailed: filter.includeFailed || false,\n }\n }),\n fetchConfig: handler.fetchConfig,\n handlerId,\n }\n contractConfig.moveCallConfigs.push(functionHandlerConfig)\n }\n config.contractConfigs.push(contractConfig)\n }\n\n for (const processor of SuiAccountProcessorState.INSTANCE.getValues()) {\n const accountConfig = AccountConfig.fromPartial({\n address: validateAndNormalizeAddress(processor.config.address),\n chainId: processor.getChainId(),\n startBlock: processor.config.startCheckpoint, // TODO maybe use another field\n })\n for (const handler of processor.objectHandlers) {\n const handlerId = handlers.suiObjectHandlers.push(handler.handler) - 1\n accountConfig.moveIntervalConfigs.push({\n intervalConfig: {\n handlerId: handlerId,\n minutes: 0,\n minutesInterval: handler.timeIntervalInMinutes,\n slot: 0,\n slotInterval: handler.versionInterval,\n fetchConfig: undefined,\n },\n type: handler.type || '',\n ownerType: processor.ownerType,\n fetchConfig: undefined,\n })\n }\n config.accountConfigs.push(accountConfig)\n }\n this.handlers = handlers\n }\n\n supportedHandlers = [HandlerType.SUI_EVENT, HandlerType.SUI_CALL, HandlerType.SUI_OBJECT]\n\n async processSuiEvent(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiEvent) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Event can't be empty\")\n }\n const promises: Promise<ProcessResult>[] = []\n const event = binding.data.suiEvent\n\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiEventHandlers[handlerId](event).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing event: ' + JSON.stringify(event) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiFunctionCall(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiCall) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Call can't be empty\")\n }\n const call = binding.data.suiCall\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n const promise = this.handlers.suiCallHandlers[handlerId](call).catch((e) => {\n throw new ServerError(Status.INTERNAL, 'error processing call: ' + JSON.stringify(call) + '\\n' + errorString(e))\n })\n promises.push(promise)\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n async processSuiObject(binding: DataBinding): Promise<ProcessResult> {\n if (!binding.data?.suiObject) {\n throw new ServerError(Status.INVALID_ARGUMENT, \"Object can't be empty\")\n }\n const object = binding.data.suiObject\n\n const promises: Promise<ProcessResult>[] = []\n for (const handlerId of binding.handlerIds) {\n promises.push(\n this.handlers.suiObjectHandlers[handlerId](object).catch((e) => {\n throw new ServerError(\n Status.INTERNAL,\n 'error processing object: ' + JSON.stringify(object) + '\\n' + errorString(e)\n )\n })\n )\n }\n return mergeProcessResults(await Promise.all(promises))\n }\n\n processBinding(request: DataBinding): Promise<ProcessResult> {\n switch (request.handlerType) {\n case HandlerType.SUI_EVENT:\n return this.processSuiEvent(request)\n case HandlerType.SUI_CALL:\n return this.processSuiFunctionCall(request)\n case HandlerType.SUI_OBJECT:\n return this.processSuiObject(request)\n default:\n throw new ServerError(Status.INVALID_ARGUMENT, 'No handle type registered ' + request.handlerType)\n }\n }\n}\n\nPluginManager.INSTANCE.register(new SuiPlugin())\n\nconst NoopContext = new SuiContext('', SuiChainId.SUI_MAINNET, '', new Date(), 0n, {} as any, 0, {})\n"]}
@@ -1,31 +1,20 @@
1
- import { Data_SuiCall, Data_SuiEvent, Data_SuiObject, HandleInterval, MoveFetchConfig, MoveOnIntervalConfig_OwnerType, ProcessResult } from '@sentio/protos';
1
+ import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig } from '@sentio/protos';
2
2
  import { ListStateStorage } from '@sentio/runtime';
3
3
  import { SuiNetwork } from './network.js';
4
- import { SuiContext, SuiObjectsContext } from './context.js';
5
- import { MoveCallSuiTransaction, SuiEvent, SuiMoveObject } from '@mysten/sui.js';
4
+ import { SuiContext } from './context.js';
5
+ import { MoveCallSuiTransaction, SuiEvent } from '@mysten/sui.js';
6
6
  import { CallHandler, EventFilter, EventHandler, FunctionNameAndCallFilter } from '../move/index.js';
7
7
  import { MoveCoder } from './move-coder.js';
8
- import { Labels, PromiseOrVoid } from '../core/index.js';
9
- declare class IndexConfigure {
10
- address: string;
11
- network: SuiNetwork;
12
- startCheckpoint: bigint;
13
- baseLabels?: Labels;
14
- }
15
- export declare class SuiBindOptions {
8
+ import { Labels } from '../core/index.js';
9
+ import { Required } from 'utility-types';
10
+ export type IndexConfigure = Required<SuiBindOptions, 'startCheckpoint' | 'network'>;
11
+ export declare function configure(options: SuiBindOptions): IndexConfigure;
12
+ export interface SuiBindOptions {
16
13
  address: string;
17
14
  network?: SuiNetwork;
18
15
  startCheckpoint?: bigint;
19
16
  baseLabels?: Labels;
20
17
  }
21
- export declare class SuiObjectBindOptions {
22
- objectId: string;
23
- network?: SuiNetwork;
24
- startCheckpoint?: bigint;
25
- baseLabels?: {
26
- [key: string]: string;
27
- };
28
- }
29
18
  export declare class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {
30
19
  static INSTANCE: SuiProcessorState;
31
20
  }
@@ -40,40 +29,3 @@ export declare class SuiBaseProcessor {
40
29
  onMoveEvent(handler: (event: SuiEvent, ctx: SuiContext) => void, filter: EventFilter | EventFilter[], fetchConfig?: Partial<MoveFetchConfig>): SuiBaseProcessor;
41
30
  onEntryFunctionCall(handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void, filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[], fetchConfig?: Partial<MoveFetchConfig>): SuiBaseProcessor;
42
31
  }
43
- declare class ObjectHandler {
44
- type?: string;
45
- versionInterval?: HandleInterval;
46
- timeIntervalInMinutes?: HandleInterval;
47
- handler: (resource: Data_SuiObject) => Promise<ProcessResult>;
48
- }
49
- export declare class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {
50
- static INSTANCE: SuiAccountProcessorState;
51
- }
52
- declare class SuiObjectsBindOptions extends SuiBindOptions {
53
- ownerType: MoveOnIntervalConfig_OwnerType;
54
- }
55
- declare abstract class SuiBaseObjectsProcessor<HandlerType> {
56
- config: IndexConfigure;
57
- ownerType: MoveOnIntervalConfig_OwnerType;
58
- objectHandlers: ObjectHandler[];
59
- protected constructor(options: SuiObjectsBindOptions);
60
- getChainId(): string;
61
- protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
62
- protected onInterval(handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
63
- timeInterval: HandleInterval | undefined, versionInterval: HandleInterval | undefined, type: string | undefined): this;
64
- onTimeInterval(handler: HandlerType, timeIntervalInMinutes?: number, backfillTimeIntervalInMinutes?: number, type?: string): this;
65
- onSlotInterval(handler: HandlerType, slotInterval?: number, backfillSlotInterval?: number, type?: string): this;
66
- }
67
- export declare class SuiAddressProcessor extends SuiBaseObjectsProcessor<(objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
68
- static bind(options: SuiBindOptions): SuiAddressProcessor;
69
- protected doHandle(handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
70
- }
71
- export declare class SuiObjectProcessor extends SuiBaseObjectsProcessor<(self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
72
- static bind(options: SuiObjectBindOptions): SuiObjectProcessor;
73
- protected doHandle(handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
74
- }
75
- export declare class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<(dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid> {
76
- static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor;
77
- protected doHandle(handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid;
78
- }
79
- export {};
@@ -1,34 +1,23 @@
1
- import { MoveFetchConfig, MoveOnIntervalConfig_OwnerType, } from '@sentio/protos';
1
+ import { MoveFetchConfig } from '@sentio/protos';
2
2
  import { ListStateStorage, mergeProcessResults } from '@sentio/runtime';
3
3
  import { SuiNetwork } from './network.js';
4
4
  import { ServerError, Status } from 'nice-grpc';
5
- import { SuiContext, SuiObjectsContext } from './context.js';
5
+ import { SuiContext } from './context.js';
6
6
  import { getProgrammableTransaction, getTransactionKind, } from '@mysten/sui.js';
7
7
  import { parseMoveType, SPLITTER, } from '../move/index.js';
8
8
  import { getMoveCalls } from './utils.js';
9
9
  import { defaultMoveCoder } from './move-coder.js';
10
- // import { dynamic_field } from './builtin/0x2.js'
11
10
  const DEFAULT_FETCH_CONFIG = {
12
11
  resourceChanges: false,
13
12
  allEvents: true,
14
13
  };
15
- class IndexConfigure {
16
- address;
17
- network;
18
- startCheckpoint;
19
- baseLabels;
20
- }
21
- export class SuiBindOptions {
22
- address;
23
- network;
24
- startCheckpoint;
25
- baseLabels;
26
- }
27
- export class SuiObjectBindOptions {
28
- objectId;
29
- network;
30
- startCheckpoint;
31
- baseLabels;
14
+ export function configure(options) {
15
+ return {
16
+ startCheckpoint: options.startCheckpoint || 0n,
17
+ address: options.address,
18
+ network: options.network || SuiNetwork.MAIN_NET,
19
+ baseLabels: options.baseLabels,
20
+ };
32
21
  }
33
22
  class SuiProcessorState extends ListStateStorage {
34
23
  static INSTANCE = new SuiProcessorState();
@@ -135,106 +124,4 @@ export class SuiBaseProcessor {
135
124
  return this;
136
125
  }
137
126
  }
138
- class ObjectHandler {
139
- type;
140
- versionInterval;
141
- timeIntervalInMinutes;
142
- handler;
143
- }
144
- class SuiAccountProcessorState extends ListStateStorage {
145
- static INSTANCE = new SuiAccountProcessorState();
146
- }
147
- export { SuiAccountProcessorState };
148
- class SuiObjectsBindOptions extends SuiBindOptions {
149
- ownerType;
150
- }
151
- class SuiBaseObjectsProcessor {
152
- config;
153
- ownerType;
154
- objectHandlers = [];
155
- // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {
156
- // return new SuiBaseObjectsProcessor(options)
157
- // }
158
- constructor(options) {
159
- this.config = configure(options);
160
- this.ownerType = options.ownerType;
161
- SuiAccountProcessorState.INSTANCE.addValue(this);
162
- }
163
- getChainId() {
164
- return this.config.network;
165
- }
166
- onInterval(handler, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,
167
- timeInterval, versionInterval, type) {
168
- const processor = this;
169
- this.objectHandlers.push({
170
- handler: async function (data) {
171
- const ctx = new SuiObjectsContext(processor.config.network, processor.config.address, data.slot, data.timestamp || new Date(0), processor.config.baseLabels);
172
- await processor.doHandle(handler, data, ctx);
173
- return ctx.getProcessResult();
174
- },
175
- timeIntervalInMinutes: timeInterval,
176
- versionInterval: versionInterval,
177
- type,
178
- });
179
- return this;
180
- }
181
- onTimeInterval(handler, timeIntervalInMinutes = 60, backfillTimeIntervalInMinutes = 240, type) {
182
- return this.onInterval(handler, {
183
- recentInterval: timeIntervalInMinutes,
184
- backfillInterval: backfillTimeIntervalInMinutes,
185
- }, undefined, type);
186
- }
187
- onSlotInterval(handler, slotInterval = 100000, backfillSlotInterval = 400000, type) {
188
- return this.onInterval(handler, undefined, { recentInterval: slotInterval, backfillInterval: backfillSlotInterval }, type);
189
- }
190
- }
191
- function configure(options) {
192
- return {
193
- startCheckpoint: options.startCheckpoint || 0n,
194
- address: options.address,
195
- network: options.network || SuiNetwork.MAIN_NET,
196
- baseLabels: options.baseLabels,
197
- };
198
- }
199
- export class SuiAddressProcessor extends SuiBaseObjectsProcessor {
200
- static bind(options) {
201
- return new SuiAddressProcessor({ ...options, ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS });
202
- }
203
- doHandle(handler, data, ctx) {
204
- return handler(data.objects, ctx);
205
- }
206
- }
207
- // export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<dynamic_field.Field<any, any>> {
208
- export class SuiObjectProcessor extends SuiBaseObjectsProcessor {
209
- static bind(options) {
210
- return new SuiObjectProcessor({
211
- address: options.objectId,
212
- network: options.network,
213
- startCheckpoint: options.startCheckpoint,
214
- ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,
215
- baseLabels: options.baseLabels,
216
- });
217
- }
218
- doHandle(handler, data, ctx) {
219
- if (!data.self) {
220
- console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`);
221
- return;
222
- }
223
- return handler(data.self, data.objects, ctx);
224
- }
225
- }
226
- export class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor {
227
- static bind(options) {
228
- return new SuiWrappedObjectProcessor({
229
- address: options.objectId,
230
- network: options.network,
231
- startCheckpoint: options.startCheckpoint,
232
- ownerType: MoveOnIntervalConfig_OwnerType.WRAPPED_OBJECT,
233
- baseLabels: options.baseLabels,
234
- });
235
- }
236
- doHandle(handler, data, ctx) {
237
- return handler(data.objects, ctx);
238
- }
239
- }
240
127
  //# sourceMappingURL=sui-processor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../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AAO,CAAC,GAAG,CAAC,6BAA6B,GAAG,CAAC,IAAI,gCAAgC,CAAC,CAAA;YAClF,OAAM;SACP;QACD,OAAO,OAAO,CAAC,IAAI,CAAC,IAAqB,EAAE,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IAClF,CAAC;CACF;AAED,MAAM,OAAO,yBAA0B,SAAQ,uBAE9C;IACC,MAAM,CAAC,IAAI,CAAC,OAA6B;QACvC,OAAO,IAAI,yBAAyB,CAAC;YACnC,OAAO,EAAE,OAAO,CAAC,QAAQ;YACzB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,eAAe,EAAE,OAAO,CAAC,eAAe;YACxC,SAAS,EAAE,8BAA8B,CAAC,cAAc;YACxD,UAAU,EAAE,OAAO,CAAC,UAAU;SAC/B,CAAC,CAAA;IACJ,CAAC;IAES,QAAQ,CAChB,OAAwF,EACxF,IAAoB,EACpB,GAAsB;QAEtB,OAAO,OAAO,CAAC,IAAI,CAAC,OAA0B,EAAE,GAAG,CAAC,CAAA;IACtD,CAAC;CACF","sourcesContent":["import {\n Data_SuiCall,\n Data_SuiEvent,\n Data_SuiObject,\n HandleInterval,\n MoveFetchConfig,\n MoveOnIntervalConfig_OwnerType,\n ProcessResult,\n} from '@sentio/protos'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport { SuiNetwork } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext, SuiObjectsContext } from './context.js'\nimport {\n getProgrammableTransaction,\n getTransactionKind,\n MoveCallSuiTransaction,\n SuiEvent,\n SuiMoveObject,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js'\nimport {\n CallHandler,\n EventFilter,\n EventHandler,\n FunctionNameAndCallFilter,\n parseMoveType,\n SPLITTER,\n} from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { Labels, PromiseOrVoid } from '../core/index.js'\n// import { dynamic_field } from './builtin/0x2.js'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\nclass IndexConfigure {\n address: string\n network: SuiNetwork\n startCheckpoint: bigint\n baseLabels?: Labels\n}\n\nexport class SuiBindOptions {\n address: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: Labels\n}\n\nexport class SuiObjectBindOptions {\n objectId: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: { [key: string]: string }\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n coder: MoveCoder\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n public onMoveEvent(\n handler: (event: SuiEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionBlockResponse\n if (!txn.events || !txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of (txn.events as SuiEvent[]).entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn,\n idx,\n processor.config.baseLabels\n )\n\n const decoded = await processor.coder.decodeEvent<any>(evt)\n await handler(decoded || evt, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n const allFunctionType = new Set(_filters.map((f) => processor.config.address + '::' + f.function))\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionBlockResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx,\n 0,\n processor.config.baseLabels\n )\n if (tx) {\n const calls: MoveCallSuiTransaction[] = getMoveCalls(tx)\n const txKind = getTransactionKind(tx)\n if (!txKind) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected getTransactionKind get empty')\n }\n const programmableTx = getProgrammableTransaction(txKind)\n\n // TODO potential pass index\n for (const call of calls) {\n const functionType = [call.package, call.module, call.function].join(SPLITTER)\n if (!allFunctionType.has(functionType)) {\n continue\n }\n\n // TODO maybe do in parallel\n const decoded = await processor.coder.decodeFunctionPayload(call, programmableTx?.inputs || [])\n await handler(decoded, ctx)\n }\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n\nclass ObjectHandler {\n type?: string\n versionInterval?: HandleInterval\n timeIntervalInMinutes?: HandleInterval\n handler: (resource: Data_SuiObject) => Promise<ProcessResult>\n}\n\nexport class SuiAccountProcessorState extends ListStateStorage<SuiBaseObjectsProcessor<any>> {\n static INSTANCE = new SuiAccountProcessorState()\n}\n\nclass SuiObjectsBindOptions extends SuiBindOptions {\n ownerType: MoveOnIntervalConfig_OwnerType\n}\n\nabstract class SuiBaseObjectsProcessor<HandlerType> {\n config: IndexConfigure\n ownerType: MoveOnIntervalConfig_OwnerType\n\n objectHandlers: ObjectHandler[] = []\n\n // static bind(options: SuiObjectsBindOptions): SuiBaseObjectsProcessor<any> {\n // return new SuiBaseObjectsProcessor(options)\n // }\n\n protected constructor(options: SuiObjectsBindOptions) {\n this.config = configure(options)\n this.ownerType = options.ownerType\n SuiAccountProcessorState.INSTANCE.addValue(this)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n // protected abstract transformObjects(objects: SuiMoveObject[]): SuiMoveObject[]\n\n protected abstract doHandle(handler: HandlerType, data: Data_SuiObject, ctx: SuiObjectsContext): PromiseOrVoid\n\n protected onInterval(\n handler: HandlerType, //(resources: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n timeInterval: HandleInterval | undefined,\n versionInterval: HandleInterval | undefined,\n type: string | undefined\n ): this {\n const processor = this\n this.objectHandlers.push({\n handler: async function (data) {\n const ctx = new SuiObjectsContext(\n processor.config.network,\n processor.config.address,\n data.slot,\n data.timestamp || new Date(0),\n processor.config.baseLabels\n )\n await processor.doHandle(handler, data, ctx)\n return ctx.getProcessResult()\n },\n timeIntervalInMinutes: timeInterval,\n versionInterval: versionInterval,\n type,\n })\n return this\n }\n\n public onTimeInterval(\n handler: HandlerType,\n timeIntervalInMinutes = 60,\n backfillTimeIntervalInMinutes = 240,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n {\n recentInterval: timeIntervalInMinutes,\n backfillInterval: backfillTimeIntervalInMinutes,\n },\n undefined,\n type\n )\n }\n\n public onSlotInterval(\n handler: HandlerType,\n slotInterval = 100000,\n backfillSlotInterval = 400000,\n type?: string\n ): this {\n return this.onInterval(\n handler,\n undefined,\n { recentInterval: slotInterval, backfillInterval: backfillSlotInterval },\n type\n )\n }\n}\n\nfunction configure(options: SuiBindOptions): IndexConfigure {\n return {\n startCheckpoint: options.startCheckpoint || 0n,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n baseLabels: options.baseLabels,\n }\n}\n\nexport class SuiAddressProcessor extends SuiBaseObjectsProcessor<\n (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiBindOptions): SuiAddressProcessor {\n return new SuiAddressProcessor({ ...options, ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS })\n }\n\n protected doHandle(\n handler: (objects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n// export class SuiDynamicFieldObjectsProcessor extends SuiBaseObjectsProcessor<dynamic_field.Field<any, any>> {\nexport class SuiObjectProcessor extends SuiBaseObjectsProcessor<\n (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiObjectProcessor {\n return new SuiObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOnIntervalConfig_OwnerType.OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (self: SuiMoveObject, dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n if (!data.self) {\n console.log(`Sui object not existed in ${ctx.slot}, please specific a start time`)\n return\n }\n return handler(data.self as SuiMoveObject, data.objects as SuiMoveObject[], ctx)\n }\n}\n\nexport class SuiWrappedObjectProcessor extends SuiBaseObjectsProcessor<\n (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid\n> {\n static bind(options: SuiObjectBindOptions): SuiWrappedObjectProcessor {\n return new SuiWrappedObjectProcessor({\n address: options.objectId,\n network: options.network,\n startCheckpoint: options.startCheckpoint,\n ownerType: MoveOnIntervalConfig_OwnerType.WRAPPED_OBJECT,\n baseLabels: options.baseLabels,\n })\n }\n\n protected doHandle(\n handler: (dynamicFieldObjects: SuiMoveObject[], ctx: SuiObjectsContext) => PromiseOrVoid,\n data: Data_SuiObject,\n ctx: SuiObjectsContext\n ): PromiseOrVoid {\n return handler(data.objects as SuiMoveObject[], ctx)\n }\n}\n"]}
1
+ {"version":3,"file":"sui-processor.js","sourceRoot":"","sources":["../../src/sui/sui-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAC7E,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EACL,0BAA0B,EAC1B,kBAAkB,GAInB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAKL,aAAa,EACb,QAAQ,GACT,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,gBAAgB,EAAa,MAAM,iBAAiB,CAAA;AAI7D,MAAM,oBAAoB,GAAoB;IAC5C,eAA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,CAAA;YAC/B,CAAC;YACD,OAAO,EAAE,QAAQ;YACjB,WAAW,EAAE,YAAY;SAC1B,CAAC,CAAA;QACF,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { Data_SuiCall, Data_SuiEvent, MoveFetchConfig } from '@sentio/protos'\nimport { ListStateStorage, mergeProcessResults } from '@sentio/runtime'\nimport { SuiNetwork } from './network.js'\nimport { ServerError, Status } from 'nice-grpc'\nimport { SuiContext } from './context.js'\nimport {\n getProgrammableTransaction,\n getTransactionKind,\n MoveCallSuiTransaction,\n SuiEvent,\n SuiTransactionBlockResponse,\n} from '@mysten/sui.js'\nimport {\n CallHandler,\n EventFilter,\n EventHandler,\n FunctionNameAndCallFilter,\n parseMoveType,\n SPLITTER,\n} from '../move/index.js'\nimport { getMoveCalls } from './utils.js'\nimport { defaultMoveCoder, MoveCoder } from './move-coder.js'\nimport { Labels } from '../core/index.js'\nimport { Required } from 'utility-types'\n\nconst DEFAULT_FETCH_CONFIG: MoveFetchConfig = {\n resourceChanges: false,\n allEvents: true,\n}\n\nexport type IndexConfigure = Required<SuiBindOptions, 'startCheckpoint' | 'network'>\n\nexport function configure(options: SuiBindOptions): IndexConfigure {\n return {\n startCheckpoint: options.startCheckpoint || 0n,\n address: options.address,\n network: options.network || SuiNetwork.MAIN_NET,\n baseLabels: options.baseLabels,\n }\n}\n\nexport interface SuiBindOptions {\n address: string\n network?: SuiNetwork\n startCheckpoint?: bigint\n baseLabels?: Labels\n}\n\nexport class SuiProcessorState extends ListStateStorage<SuiBaseProcessor> {\n static INSTANCE = new SuiProcessorState()\n}\n\nexport class SuiBaseProcessor {\n readonly moduleName: string\n config: IndexConfigure\n\n eventHandlers: EventHandler<Data_SuiEvent>[] = []\n callHandlers: CallHandler<Data_SuiCall>[] = []\n coder: MoveCoder\n\n constructor(name: string, options: SuiBindOptions) {\n this.moduleName = name\n this.config = configure(options)\n SuiProcessorState.INSTANCE.addValue(this)\n this.coder = defaultMoveCoder(this.config.network)\n }\n\n getChainId(): string {\n return this.config.network\n }\n\n public onMoveEvent(\n handler: (event: SuiEvent, ctx: SuiContext) => void,\n filter: EventFilter | EventFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: EventFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n\n const processor = this\n const allEventType = new Set(_filters.map((f) => processor.config.address + '::' + f.type))\n\n this.eventHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'event is null')\n }\n const txn = data.transaction as SuiTransactionBlockResponse\n if (!txn.events || !txn.events.length) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'no event in the transactions')\n }\n\n const processResults = []\n for (const [idx, evt] of (txn.events as SuiEvent[]).entries()) {\n const typeQname = parseMoveType(evt.type).qname\n if (!allEventType.has(typeQname)) {\n continue\n }\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n txn,\n idx,\n processor.config.baseLabels\n )\n\n const decoded = await processor.coder.decodeEvent<any>(evt)\n await handler(decoded || evt, ctx)\n processResults.push(ctx.getProcessResult())\n }\n\n return mergeProcessResults(processResults)\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n\n public onEntryFunctionCall(\n handler: (call: MoveCallSuiTransaction, ctx: SuiContext) => void,\n filter: FunctionNameAndCallFilter | FunctionNameAndCallFilter[],\n fetchConfig?: Partial<MoveFetchConfig>\n ): SuiBaseProcessor {\n let _filters: FunctionNameAndCallFilter[] = []\n const _fetchConfig = MoveFetchConfig.fromPartial({ ...DEFAULT_FETCH_CONFIG, ...fetchConfig })\n\n if (Array.isArray(filter)) {\n _filters = filter\n } else {\n _filters.push(filter)\n }\n\n // const address = this.config.address\n // const moduleName = this.moduleName\n const processor = this\n const allFunctionType = new Set(_filters.map((f) => processor.config.address + '::' + f.function))\n\n this.callHandlers.push({\n handler: async function (data) {\n if (!data.transaction) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'call is null')\n }\n const tx = data.transaction as SuiTransactionBlockResponse\n\n const ctx = new SuiContext(\n processor.moduleName,\n processor.config.network,\n processor.config.address,\n data.timestamp || new Date(0),\n data.slot,\n tx,\n 0,\n processor.config.baseLabels\n )\n if (tx) {\n const calls: MoveCallSuiTransaction[] = getMoveCalls(tx)\n const txKind = getTransactionKind(tx)\n if (!txKind) {\n throw new ServerError(Status.INVALID_ARGUMENT, 'Unexpected getTransactionKind get empty')\n }\n const programmableTx = getProgrammableTransaction(txKind)\n\n // TODO potential pass index\n for (const call of calls) {\n const functionType = [call.package, call.module, call.function].join(SPLITTER)\n if (!allFunctionType.has(functionType)) {\n continue\n }\n\n // TODO maybe do in parallel\n const decoded = await processor.coder.decodeFunctionPayload(call, programmableTx?.inputs || [])\n await handler(decoded, ctx)\n }\n }\n return ctx.getProcessResult()\n },\n filters: _filters,\n fetchConfig: _fetchConfig,\n })\n return this\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentio/sdk",
3
- "version": "2.15.7-rc.2",
3
+ "version": "2.16.0-rc.1",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "exports": {
@@ -69,9 +69,10 @@
69
69
  "superstruct_solana": "npm:superstruct@^0.14.2",
70
70
  "typechain": "^8.0.0",
71
71
  "typedoc": "^0.24.1",
72
+ "utility-types": "^3.10.0",
72
73
  "yaml": "^2.2.1",
73
- "@sentio/protos": "^2.15.7-rc.2",
74
- "@sentio/runtime": "^2.15.7-rc.2"
74
+ "@sentio/protos": "^2.16.0-rc.1",
75
+ "@sentio/runtime": "^2.16.0-rc.1"
75
76
  },
76
77
  "peerDependencies": {
77
78
  "tsup": "npm:@sentio/tsup@^6.7.0"
@@ -9,10 +9,10 @@ import {
9
9
  HandlerType,
10
10
  MoveCallHandlerConfig,
11
11
  MoveEventHandlerConfig,
12
+ MoveOwnerType,
12
13
  ProcessConfigResponse,
13
14
  ProcessResult,
14
15
  StartRequest,
15
- MoveOnIntervalConfig_OwnerType,
16
16
  } from '@sentio/protos'
17
17
 
18
18
  import { ServerError, Status } from 'nice-grpc'
@@ -100,19 +100,6 @@ export class AptosPlugin extends Plugin {
100
100
  })
101
101
  for (const handler of aptosProcessor.resourcesHandlers) {
102
102
  const handlerId = handlers.aptosResourceHandlers.push(handler.handler) - 1
103
- // TODO move to only use moveIntervalConfigs
104
- accountConfig.aptosIntervalConfigs.push({
105
- intervalConfig: {
106
- handlerId: handlerId,
107
- minutes: 0,
108
- minutesInterval: handler.timeIntervalInMinutes,
109
- slot: 0,
110
- slotInterval: handler.versionInterval,
111
- fetchConfig: undefined,
112
- },
113
- type: handler.type || '',
114
- })
115
-
116
103
  accountConfig.moveIntervalConfigs.push({
117
104
  intervalConfig: {
118
105
  handlerId: handlerId,
@@ -123,7 +110,8 @@ export class AptosPlugin extends Plugin {
123
110
  fetchConfig: undefined,
124
111
  },
125
112
  type: handler.type || '',
126
- ownerType: MoveOnIntervalConfig_OwnerType.ADDRESS,
113
+ ownerType: MoveOwnerType.ADDRESS,
114
+ fetchConfig: undefined,
127
115
  })
128
116
  }
129
117
  config.accountConfigs.push(accountConfig)
@@ -0,0 +1,6 @@
1
+ import { ListStateStorage } from '@sentio/runtime'
2
+ import { TemplateInstance } from '@sentio/protos'
3
+
4
+ export class TemplateInstanceState extends ListStateStorage<TemplateInstance> {
5
+ static INSTANCE = new TemplateInstanceState()
6
+ }
@@ -8,6 +8,7 @@ import { ListStateStorage } from '@sentio/runtime'
8
8
  import { BlockParams } from 'ethers/providers'
9
9
  import { DeferredTopicFilter } from 'ethers/contract'
10
10
  import { TypedEvent, TypedCallTrace } from './eth.js'
11
+ import { TemplateInstanceState } from '../core/template.js'
11
12
 
12
13
  export class ProcessorTemplateProcessorState extends ListStateStorage<
13
14
  BaseProcessorTemplate<BaseContract, BoundContractView<BaseContract, any>>
@@ -15,10 +16,6 @@ export class ProcessorTemplateProcessorState extends ListStateStorage<
15
16
  static INSTANCE = new ProcessorTemplateProcessorState()
16
17
  }
17
18
 
18
- export class TemplateInstanceState extends ListStateStorage<TemplateInstance> {
19
- static INSTANCE = new TemplateInstanceState()
20
- }
21
-
22
19
  export abstract class BaseProcessorTemplate<
23
20
  TContract extends BaseContract,
24
21
  TBoundContractView extends BoundContractView<TContract, ContractView<TContract>>
@@ -53,9 +50,7 @@ export abstract class BaseProcessorTemplate<
53
50
  * @param ctx
54
51
  */
55
52
  public bind(options: BindOptions, ctx: EthContext): void {
56
- if (!options.network) {
57
- options.network = ctx.getChainId()
58
- }
53
+ options.network = options.network || ctx.chainId
59
54
  const sig = getOptionsSignature({
60
55
  address: options.address,
61
56
  network: options.network,